import{a as _,D as m,k as v,p as l,e as c,w as n,j as a,u as r,v as u,c3 as w,aj as y,S as d,U as p,af as h,ak as f,aN as I,r as b,ac as P}from"./jwt-decode.esm-DyyavT6h.js";import{_ as x}from"./AbstraLogo.vue_vue_type_script_setup_true_lang-CirEJagM.js";import{B as j}from"./BaseLayout-NniIuGaa.js";import{l as g}from"./fetch-BaAgCW4y.js";import"./router-BhKBgDIv.js";import{P as k}from"./project-DU7AsmUe.js";import"./tables-sMYALme4.js";import"./Logo-BLceuW0a.js";import"./ts.worker-Do44s_XH.js";import"./record-Dva_8M1P.js";import"./string-C33uYcCb.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]="7aa5d41d-ef40-4ac5-b79f-38486c9b596d",e._sentryDebugIdIdentifier="sentry-dbid-7aa5d41d-ef40-4ac5-b79f-38486c9b596d")}catch{}})();const E=_({__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(E,[["__scopeId","data-v-5fd653ca"]]);function R(e,t){if(!e)return"";const i=t.toString();if(!i)return e;const o=e.includes("?")?"&":"?";return`${e}${o}${i}`}class T{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=R(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 k.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 M=_({__name:"WebEditor",setup(e){const t=P(),i=t.params.projectId,s=t.query.redirect,o=new T(i,s);return(D,S)=>(c(),l(W,{controller:r(o)},null,8,["controller"]))}});export{M as default};
//# sourceMappingURL=WebEditor-EbePg5rC.js.map
