import{D as e,Dt as t,H as n,I as r,M as i,N as a,Ot as o,Q as s,S as c,St as l,ct as u,et as d,ft as f,j as p,nt as m,ot as h,pt as g,tt as _,ut as v,xt as y}from"../chunks/ZLGReh43.js";import{a as b,p as x}from"../chunks/BDBSsbMb.js";import{At as S,Tt as C,_t as w,mt as T,n as E,ot as D,t as O,vt as k,yt as A}from"../chunks/BApLQfqY.js";import{c as j,l as M,n as N,o as P,r as F,s as I,t as L}from"../chunks/DfAL3LhV.js";import"../chunks/xihTtKlq.js";import{t as R}from"../chunks/Ctc_6ReW.js";import{n as z}from"../chunks/CmuvbAn5.js";var B=a(`<div class="modal-header"><div class="modal-icon-badge"><span class="i-ic-baseline-check text-primary text-lg"></span></div> <div><h2 class="text-sm font-semibold text-foreground tracking-tight leading-tight">Init project</h2> <p class="text-xs text-muted-foreground mt-0.5">Configure and scaffold your project</p></div></div> <div class="modal-body"><!> <div class="flex flex-col gap-1"><!></div></div> <div class="modal-footer"><!></div>`,1);function V(e,a){l(a,!0);let s=()=>g(k,`$submitting`,x),[x,S]=f(),C=u(!1),w=L({schema:M({language:I([`ts`,`js`]).default(`ts`),multiplayerServer:j().default(!1)}),defaultValues:{language:`ts`,multiplayerServer:!1},onSubmit:async e=>{h(C,!0),await O(`create project`,async()=>{await b(`/dashboard?id=${(await T.complete({...e,gatewayId:a.gatewayId})).id}`)},()=>{h(C,!1)})}}),{submitting:k}=w;var A=i();c(_(A),()=>D,(e,i)=>{i(e,{class:`w-full max-w-lg p-4`,children:(e,i)=>{P(e,{get form(){return w},class:`w-full`,children:(e,i)=>{var a=B(),c=m(_(a),2),l=d(c);F(l,{name:`language`,label:`Language`,classNames:{trigger:`w-40 p-4`,content:`p-2`,item:`p-2`},options:[{value:`ts`,label:`Typescript`},{value:`js`,label:`Javascript`}]});var u=m(l,2);N(d(u),{label:`Multiplayer game`,name:`multiplayerServer`}),o(u),o(c);var f=m(c,2),h=d(f);{let e=v(()=>s()||n(C));E(h,{type:`submit`,size:`lg`,get loading(){return n(e)},class:`btn-primary px-6`,children:(e,n)=>{t(),p(e,r(`Init Project`))},$$slots:{default:!0}})}o(f),p(e,a)},$$slots:{default:!0}})},$$slots:{default:!0}})}),p(e,A),y(),S()}var H=a(`<div class="flex h-100vh w-full items-center justify-center"><!></div>`);function U(t,n){l(n,!0);let r=()=>{if(C().mode===`offline`){let e=R.url.searchParams.get(`path`);return e?{path:e}:null}else{let e=R.url.searchParams.get(`gatewayId`);return e?{gatewayId:e}:null}},a=R.url.searchParams.get(`id`),c=r();s(()=>{if(!a&&!c)throw b(x(`/`)),Error(`No resolvable`)});let u=S(()=>({queryKey:[`load`,`verify`,c?`path`in c?c.path:c.gatewayId:``],queryFn:async()=>{if(!a&&!c)throw Error(`No resolvable`);if(a)try{await b(x(`/dashboard?id=${(await T.loadFromId(a)).id}`))}catch(e){if(e instanceof k&&e.reason===w.Empty_Project&&C().mode===`online`)return e.args[1];console.error(e),A(`Failed to load project from id`,e.message)}if(c)try{return await b(x(`/dashboard?id=${(await(`path`in c?T.loadFromPath(c.path):T.loadFromGatewayId(c.gatewayId))).id}`)),null}catch(e){if(e instanceof k&&e.reason===w.Empty_Project&&C().mode===`online`)return e.args[1];console.error(e),A(`Failed to load project`,e.message)}return await b(x(`/`)),null}}));var f=i(),m=_(f),h=e=>{var t=H();V(d(t),{get gatewayId(){return u.data}}),o(t),p(e,t)},g=e=>{z(e,{})};e(m,e=>{u.isFetched&&!u.isLoading&&u.data?e(h):e(g,-1)}),p(t,f),y()}export{U as component};