var v=Object.defineProperty;var y=(e,t,i)=>t in e?v(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var r=(e,t,i)=>(y(e,typeof t!="symbol"?t+"":t,i),i);import{d as m,U as w,R as I,a as c,b as s,o as d,f as o,u as n,dj as f,cT as P,A as b,g as p,t as h,i as u,df as g,_ as x,r as j,ei as A}from"./jwt-decode.esm.32f71954.js";import{_ as E}from"./AbstraLogo.vue_vue_type_script_setup_true_lang.f0472c1e.js";import{B as R}from"./BaseLayout.fed5adb7.js";import{l as _}from"./fetch.a8fb4ba0.js";import"./router.29e08ea4.js";import{a as T}from"./project.b14b799c.js";import"./tables.94d324c3.js";import"./Logo.c75e45a8.js";import"./index.2400150a.js";import"./record.41c9caee.js";import"./string.ff0b4ef9.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]="4031369f-d41a-4872-9558-80702723d598",e._sentryDebugIdIdentifier="sentry-dbid-4031369f-d41a-4872-9558-80702723d598")}catch{}})();const W=m({__name:"View",props:{controller:{}},setup(e){const t=e,i=t.controller.loadingPercentage();return w(()=>{t.controller.start()}),I(()=>{t.controller.cleanUp()}),(a,l)=>(d(),c(R,null,{content:s(()=>[o(n(f),{align:"center",justify:"center",style:{width:"100vw",height:"100dvh"}},{default:s(()=>[o(n(f),{gap:"large",align:"center",justify:"space-evenly",vertical:"",style:{width:"45%","min-width":"600px",height:"100%"}},{default:s(()=>[o(E,{size:"large"}),o(n(P),{size:[10,10],"show-info":!1,percent:n(i),"stroke-color":"#EA576A"},null,8,["percent"]),o(n(b),{level:3},{default:s(()=>[p(h(n(u).translate("i18n_webeditorview_preparing_environment")),1)]),_:1}),n(i)<100?(d(),c(n(g),{key:0},{default:s(()=>[p(h(n(u).translate("i18n_webeditorview_setting_up")),1)]),_:1})):(d(),c(n(g),{key:1},{default:s(()=>[p(h(n(u).translate("i18n_webeditorview_redirecting_soon")),1)]),_:1}))]),_:1})]),_:1})]),_:1}))}});const k=x(W,[["__scopeId","data-v-5fd653ca"]]);function U(e,t){if(!e)return"";const i=t.toString();if(!i)return e;const l=e.includes("?")?"&":"?";return`${e}${l}${i}`}class D{constructor(t,i,a=_){r(this,"projectId");r(this,"loading");r(this,"fetch",_);r(this,"interval",null);r(this,"urls",null);r(this,"totalWaitTime");r(this,"poolingInterval");r(this,"pingResponded",!1);r(this,"redirectPath");this.projectId=t,this.loading=j(0),this.fetch=a,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=U(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 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=A(),i=t.params.projectId,a=t.query.redirect,l=new D(i,a);return(S,V)=>(d(),c(k,{controller:n(l)},null,8,["controller"]))}});export{J as default};
//# sourceMappingURL=WebEditor.7a1fcb94.js.map
