import{e as m,N as _,n as v,f as l,h as c,w as n,m as a,j as i,J as u,bZ as w,ao as y,k as d,t as p,i as h,T as f,aO as b,r as I,an as P}from"./jwt-decode.esm-BJTSBhUK.js";import{_ as x}from"./AbstraLogo.vue_vue_type_script_setup_true_lang-ikKVV7cX.js";import{B as j}from"./BaseLayout-Dyp0CrSy.js";import{l as g}from"./fetch-6ZdEdsKW.js";import"./router-JNJkT0FW.js";import{a as T}from"./project-CNNVe7L3.js";import"./tables-COuMqsTr.js";import"./logo-BiWG9_W5.js";import"./Logo-3Y-n1Ku6.js";import"./ts.worker-_F6qeu5Y.js";import"./record-COWr9r4M.js";import"./string-C1f4nly_.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]="afcbce74-c2a9-4cbb-b13c-5f48b0cc6c48",e._sentryDebugIdIdentifier="sentry-dbid-afcbce74-c2a9-4cbb-b13c-5f48b0cc6c48")}catch{}})();const W=m({__name:"View",props:{controller:{}},setup(e){const t=e,r=t.controller.loadingPercentage();return _(()=>{t.controller.start()}),v(()=>{t.controller.cleanUp()}),(s,o)=>(c(),l(j,null,{content:n(()=>[a(i(u),{align:"center",justify:"center",style:{width:"100vw",height:"100dvh"}},{default:n(()=>[a(i(u),{gap:"large",align:"center",justify:"space-evenly",vertical:"",style:{width:"45%","min-width":"600px",height:"100%"}},{default:n(()=>[a(x,{size:"large"}),a(i(w),{size:[10,10],"show-info":!1,percent:i(r),"stroke-color":"var(--ac-brand-primary)"},null,8,["percent"]),a(i(y),{level:3},{default:n(()=>[d(p(i(h).translate("i18n_webeditorview_preparing_environment")),1)]),_:1}),i(r)<100?(c(),l(i(f),{key:0},{default:n(()=>[d(p(i(h).translate("i18n_webeditorview_setting_up")),1)]),_:1})):(c(),l(i(f),{key:1},{default:n(()=>[d(p(i(h).translate("i18n_webeditorview_redirecting_soon")),1)]),_:1}))]),_:1})]),_:1})]),_:1}))}}),k=b(W,[["__scopeId","data-v-b6b25da5"]]);function E(e,t){if(!e)return"";const r=t.toString();if(!r)return e;const o=e.includes("?")?"&":"?";return`${e}${o}${r}`}class R{projectId;loading;fetch=g;interval=null;urls=null;totalWaitTime;poolingInterval;pingResponded=!1;redirectPath;constructor(t,r,s=g){this.projectId=t,this.loading=I(0),this.fetch=s,this.totalWaitTime=6e4,this.poolingInterval=2500,this.redirectPath=r}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 r=E(this.urls.redirect,t);window.location.replace(r)}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 T.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=m({__name:"WebEditor",setup(e){const t=P(),r=t.params.projectId,s=t.query.redirect,o=new R(r,s);return(D,S)=>(c(),l(k,{controller:i(o)},null,8,["controller"]))}});export{J as default};
//# sourceMappingURL=WebEditor-BxJVvFqq.js.map
