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