import{a as _,J as m,q as v,b as l,f as c,w as n,h as a,u as r,F as u,c1 as w,ak as y,g as d,t as p,i as h,T as f,aK as I,r as b,ag as P}from"./jwt-decode.esm-Dw_OlTCW.js";import{_ as x}from"./AbstraLogo.vue_vue_type_script_setup_true_lang--TrSji4U.js";import{B as j}from"./BaseLayout-8rFeaZVy.js";import{l as g}from"./fetch-B1nAdsqQ.js";import"./router-DzczyMew.js";import{a as E}from"./project-Dsz7eI6O.js";import"./tables-CkY-LQhC.js";import"./logo-BiWG9_W5.js";import"./Logo-CecBL509.js";import"./ts.worker-5sEEipil.js";import"./record-BTRCUCPd.js";import"./string-BuQ9zSDy.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="d21e63ef-f234-4069-b668-633248375fa8",e._sentryDebugIdIdentifier="sentry-dbid-d21e63ef-f234-4069-b668-633248375fa8")}catch{}})();const T=_({__name:"View",props:{controller:{}},setup(e){const t=e,i=t.controller.loadingPercentage();return m(()=>{t.controller.start()}),v(()=>{t.controller.cleanUp()}),(s,o)=>(c(),l(j,null,{content:n(()=>[a(r(u),{align:"center",justify:"center",style:{width:"100vw",height:"100dvh"}},{default:n(()=>[a(r(u),{gap:"large",align:"center",justify:"space-evenly",vertical:"",style:{width:"45%","min-width":"600px",height:"100%"}},{default:n(()=>[a(x,{size:"large"}),a(r(w),{size:[10,10],"show-info":!1,percent:r(i),"stroke-color":"#EA576A"},null,8,["percent"]),a(r(y),{level:3},{default:n(()=>[d(p(r(h).translate("i18n_webeditorview_preparing_environment")),1)]),_:1}),r(i)<100?(c(),l(r(f),{key:0},{default:n(()=>[d(p(r(h).translate("i18n_webeditorview_setting_up")),1)]),_:1})):(c(),l(r(f),{key:1},{default:n(()=>[d(p(r(h).translate("i18n_webeditorview_redirecting_soon")),1)]),_:1}))]),_:1})]),_:1})]),_:1}))}}),W=I(T,[["__scopeId","data-v-5fd653ca"]]);function k(e,t){if(!e)return"";const i=t.toString();if(!i)return e;const o=e.includes("?")?"&":"?";return`${e}${o}${i}`}class R{projectId;loading;fetch=g;interval=null;urls=null;totalWaitTime;poolingInterval;pingResponded=!1;redirectPath;constructor(t,i,s=g){this.projectId=t,this.loading=b(0),this.fetch=s,this.totalWaitTime=6e4,this.poolingInterval=2500,this.redirectPath=i}increment(){this.loading.value+=100/(this.totalWaitTime/this.poolingInterval)}speedUp(){this.totalWaitTime=5e3,this.poolingInterval=500,this.interval&&clearInterval(this.interval),this.interval=setInterval(async()=>{this.increment(),this.loading.value>=100&&this.navigate()},this.poolingInterval)}navigate(){if(this.urls){const t=new URLSearchParams;this.redirectPath&&t.set("redirect",this.redirectPath);const i=k(this.urls.redirect,t);window.location.replace(i)}this.cleanUp()}async ping(){if(!this.urls)return!1;if(this.pingResponded)return!0;const t=await this.fetch(this.urls.ping,{signal:AbortSignal.timeout(500)});return this.pingResponded=t.status===200,this.pingResponded}async start(){const t=await E.startWebEditor(this.projectId);this.urls=t,this.interval=setInterval(async()=>{this.increment(),this.pingResponded||await this.ping()&&this.speedUp(),this.loading.value>=100&&this.navigate()},this.poolingInterval)}cleanUp(){this.interval&&clearInterval(this.interval)}loadingPercentage(){return this.loading}}const J=_({__name:"WebEditor",setup(e){const t=P(),i=t.params.projectId,s=t.query.redirect,o=new R(i,s);return(A,D)=>(c(),l(W,{controller:r(o)},null,8,["controller"]))}});export{J as default};
//# sourceMappingURL=WebEditor-BqoMFd08.js.map
