import{Q as U,a as k,b as B}from"./QCard-7tL_iMin.js";import{Q as v}from"./QSeparator-DxYvf5Mr.js";import{Q as D}from"./QInput-CHJgTrNd.js";import{r,F as S,o as V,B as $,L as y,D as m,I as s,E as d,M as i,P as Q,N as G,Y as L,J as C,C as N,Z as A}from"./index-CoQ-x5A8.js";import{u as E}from"./use-quasar-D2Dr8mCf.js";import{P as w}from"./LocalStorage-Cw9j6RTB.js";import{a as n}from"./axios-BPt4fYpj.js";import"./use-dark-dqtTUvyg.js";import"./use-key-composition-DhHSCGmF.js";import"./use-id-G4Q8n9zP.js";import"./focus-manager-BJWzFvJg.js";const F={class:"q-pa-md flex flex-center"},M={class:"text-subtitle2 text-black"},z={class:"text-subtitle2 text-black"},J={class:"row items-center q-gutter-sm full-width q-pa-sm"},te={__name:"createLocalGamePage",setup(Y){const u=S(),t=E(),o=r(),h=r(null),x=r([]),p=r({username:"",id:0}),l=r(null);var _=!1;const g=w.getItem("user");g?(console.log(g),p.value=g):u.push("/user/username");const f=w.getItem("gameID");f?(console.log(f),o.value=f,n.get(`/api/games/${o.value}`).then(function(e){console.log(e),h.value=e.data.creator,_=!0}).catch(function(e){console.log(e),t.notify({type:"negative",message:e.response.data.error})})):u.push("/");async function q(){if(console.log(l.value),!l.value){t.notify({type:"negative",message:"Please enter a username!"});return}n.post("/api/users",{username:l.value}).then(function(e){console.log(e),n.post(`/api/games/${o.value}/players`,{user:e.data.id}).then(function(a){console.log(a),t.notify({type:"positive",message:"Success!"})}).catch(function(a){console.log(a),t.notify({type:"negative",message:a.response.data.error})})}).catch(function(e){console.log(e),t.notify({type:"negative",message:e.response.data.error})})}async function I(){_&&(n.get(`/api/games/${o.value}/players`).then(function(e){x.value=e.data}).catch(function(e){console.log(e),t.notify({type:"negative",message:e.response.data.error})}),n.get(`/api/games/${o.value}`).then(function(e){e.data.is_open||u.push("/game")}).catch(function(e){console.log(e),t.notify({type:"negative",message:e.response.data.error})}))}async function P(){n.patch(`/api/games/${o.value}/lock`,{user:p.value.id}).then(function(e){console.log(e),t.notify({type:"positive",message:"Success!"}),u.push("/game")}).catch(function(e){console.log(e),t.notify({type:"negative",message:e.response.data.error})})}let b=null;return V(()=>{I(),b=setInterval(I,1e3)}),$(()=>{clearInterval(b)}),(e,a)=>(m(),y("div",F,[s(U,{class:"q-pa-lg shadow-3",style:{width:"400px","max-width":"90vw","border-radius":"16px"}},{default:d(()=>[s(k,null,{default:d(()=>[a[1]||(a[1]=i("div",{class:"text-h6 q-mt-md"},"Local Game",-1)),i("div",M," Game ID: "+Q(o.value),1)]),_:1}),s(v),s(k,null,{default:d(()=>[a[2]||(a[2]=i("div",{class:"text-h6 q-mt-md"},"Players:",-1)),(m(!0),y(G,null,L(x.value,c=>(m(),y("li",{key:c.username},[i("div",z,Q(c.username),1)]))),128))]),_:1}),s(v),i("div",J,[s(D,{modelValue:l.value,"onUpdate:modelValue":a[0]||(a[0]=c=>l.value=c),filled:"",label:"Username",maxlength:"32",counter:"",dense:"",style:{"border-radius":"6px"}},null,8,["modelValue"]),s(C,{label:"Add",color:"secondary",onClick:q,rounded:"",unelevated:""})]),s(v),s(B,{align:"center"},{default:d(()=>[h.value===p.value.id?(m(),N(C,{key:0,label:"Start Game!",color:"primary",onClick:P,rounded:"",unelevated:"",size:"lg",class:"full-width"})):A("",!0)]),_:1})]),_:1})]))}};export{te as default};
