import{e as _,n as y,l as w,q as l,g as c,x as n,v as o,s as i,at as f,bk as P,a0 as I,T as p,U as d,K as h,a1 as u,ar as b,r as g,W as E}from"./jwt-decode.esm-CX61wVx3.js";import{_ as R}from"./AbstraLogo.vue_vue_type_script_setup_true_lang-BP-78XpT.js";import{B as T}from"./BaseLayout-BG4TVeXU.js";import{l as m}from"./fetch-BOLOxrH8.js";import{d as D}from"./router-C3xfRTQ9.js";import{P as x}from"./project-BBDdDK81.js";import"./tables-uXC0iev6.js";import{u as S}from"./projectStore-VaavZXIZ.js";import"./logo-BiWG9_W5.js";import"./Logo-Dr2w7cZG.js";import"./ts.worker-DBbJtN2A.js";import"./string-BfaOmKtt.js";import"./member-Mqwx3LJ6.js";import"./organizationSwitcher-BGkTY3e2.js";import"./organization-CGHGUCUV.js";(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[t]="e749a217-7146-4fbc-b77f-b658d1411840",r._sentryDebugIdIdentifier="sentry-dbid-e749a217-7146-4fbc-b77f-b658d1411840")}catch{}})();const A=_({__name:"View",props:{controller:{}},setup(r){const t=r,e=t.controller.loadingPercentage(),s=t.controller.failed();return y(()=>{t.controller.start().catch(()=>{})}),w(()=>{t.controller.cleanUp()}),(a,v)=>(c(),l(T,null,{content:n(()=>[o(i(f),{align:"center",justify:"center",style:{width:"100vw",height:"100dvh"}},{default:n(()=>[o(i(f),{gap:"large",align:"center",justify:"space-evenly",vertical:"",style:{width:"45%","min-width":"600px",height:"100%"}},{default:n(()=>[o(R,{size:"large"}),o(i(P),{size:[10,10],"show-info":!1,percent:i(e),"stroke-color":"var(--ac-brand-primary)"},null,8,["percent"]),o(i(I),{level:3},{default:n(()=>[p(d(i(h).translate("i18n_webeditorview_preparing_environment")),1)]),_:1}),i(s)?(c(),l(i(u),{key:0,type:"danger"},{default:n(()=>[p(d(i(h).translate("i18n_webeditorview_preparation_failed")),1)]),_:1})):i(e)<100?(c(),l(i(u),{key:1},{default:n(()=>[p(d(i(h).translate("i18n_webeditorview_setting_up")),1)]),_:1})):(c(),l(i(u),{key:2},{default:n(()=>[p(d(i(h).translate("i18n_webeditorview_redirecting_soon")),1)]),_:1}))]),_:1})]),_:1})]),_:1}))}}),j=b(A,[["__scopeId","data-v-80a36a07"]]);function W(r,t){if(!r)return"";const e=t.toString();if(!e)return r;const a=r.includes("?")?"&":"?";return`${r}${a}${e}`}const k="template_materialization_pending",U=r=>r instanceof D&&r.code===k,q=r=>new Promise(t=>setTimeout(t,r)),C=30;class N{projectId;loading;failure;fetch=m;interval=null;urls=null;totalWaitTime;poolingInterval;pingResponded=!1;redirectPath;preparingTimeout;preparingRetryDelay;constructor(t,e,s=m,a={}){this.projectId=t,this.loading=g(0),this.failure=g(!1),this.fetch=s,this.totalWaitTime=6e4,this.poolingInterval=2500,this.redirectPath=e,this.preparingTimeout=a.timeout??18e4,this.preparingRetryDelay=a.retryDelay??3e3}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 e=W(this.urls.redirect,t);window.location.replace(e)}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(2e3)});return this.pingResponded=t.status===200,this.pingResponded}startPreparingProgress(){this.interval||(this.interval=setInterval(()=>{this.loading.value=Math.min(C,this.loading.value+1)},this.poolingInterval))}async requestStart(){const t=Date.now()+this.preparingTimeout;for(;;)try{return await x.startWebEditor(this.projectId)}catch(e){if(!U(e)||Date.now()+this.preparingRetryDelay>=t)throw e;this.startPreparingProgress(),await q(this.preparingRetryDelay)}}async start(){let t;try{t=await this.requestStart()}catch(e){throw this.cleanUp(),this.failure.value=!0,e}this.urls=t,this.cleanUp(),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),this.interval=null)}loadingPercentage(){return this.loading}failed(){return this.failure}}const tt=_({__name:"WebEditor",setup(r){const t=E(),e=S(),s=t.query.redirect,a=new N(e.projectId,s);return(v,M)=>(c(),l(j,{controller:i(a)},null,8,["controller"]))}});export{tt as default};
//# sourceMappingURL=WebEditor-MA-FoYJe.js.map
