var _=Object.defineProperty;var m=(t,e,i)=>e in t?_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var n=(t,e,i)=>(m(t,typeof e!="symbol"?e+"":e,i),i);import{d as g,k as v,j as y,a as l,b as s,o as c,f as a,u as r,de as h,cO as w,A as I,g as d,da as u,_ as b,r as P,eb as x}from"./jwt-decode.esm.95147216.js";import{_ as j}from"./AbstraLogo.vue_vue_type_script_setup_true_lang.dffc3ca0.js";import{B as W}from"./BaseLayout.0056f742.js";import{l as f}from"./fetch.a9ee3277.js";import"./router.09c25b35.js";import{a as k}from"./project.47c68ce9.js";import"./tables.7fcaf771.js";import"./Logo.4a9353b0.js";import"./index.574c12ce.js";import"./record.44df96f2.js";import"./string.c6b418fe.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="1fd07b12-d897-41b9-924c-c4739ee32299",t._sentryDebugIdIdentifier="sentry-dbid-1fd07b12-d897-41b9-924c-c4739ee32299")}catch{}})();const A=g({__name:"View",props:{controller:{}},setup(t){const e=t,i=e.controller.loadingPercentage();return v(()=>{e.controller.start()}),y(()=>{e.controller.cleanUp()}),(o,p)=>(c(),l(W,null,{content:s(()=>[a(r(h),{align:"center",justify:"center",style:{width:"100vw",height:"100dvh"}},{default:s(()=>[a(r(h),{gap:"large",align:"center",justify:"space-evenly",vertical:"",style:{width:"45%","min-width":"600px",height:"100%"}},{default:s(()=>[a(j,{size:"large"}),a(r(w),{size:[10,10],"show-info":!1,percent:r(i),"stroke-color":"#EA576A"},null,8,["percent"]),a(r(I),{level:3},{default:s(()=>[d("Preparing your environment")]),_:1}),r(i)<100?(c(),l(r(u),{key:0},{default:s(()=>[d("We are setting things up... This may take up to 1 minute.")]),_:1})):(c(),l(r(u),{key:1},{default:s(()=>[d("You will be redirected soon")]),_:1}))]),_:1})]),_:1})]),_:1}))}});const T=b(A,[["__scopeId","data-v-0794e790"]]);class R{constructor(e,i,o=f){n(this,"projectId");n(this,"loading");n(this,"fetch",f);n(this,"interval",null);n(this,"urls",null);n(this,"totalWaitTime");n(this,"poolingInterval");n(this,"pingResponded",!1);n(this,"redirectPath");this.projectId=e,this.loading=P(0),this.fetch=o,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 e=new URLSearchParams;this.redirectPath&&e.set("redirect",this.redirectPath),window.location.replace(this.urls.redirect+"?"+e.toString())}this.cleanUp()}async ping(){if(!this.urls)return!1;if(this.pingResponded)return!0;const e=await this.fetch(this.urls.ping,{signal:AbortSignal.timeout(500)});return this.pingResponded=e.status===200,this.pingResponded}async start(){const e=await k.startWebEditor(this.projectId);this.urls=e,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 O=g({__name:"WebEditor",setup(t){const e=x(),i=e.params.projectId,o=e.query.redirect,p=new R(i,o);return(U,E)=>(c(),l(T,{controller:r(p)},null,8,["controller"]))}});export{O as default};
//# sourceMappingURL=WebEditor.e7ec1210.js.map
