1import{a as v,v as E,r as s,s as o,j as e,L as f,m as h,a1 as k,t as S,a2 as A,u as c}from"./index-DMRgbZm2.js";const L=()=>{var x;const n=v(),[y]=E(),t=((x=y.get("code"))==null?void 0:x.toUpperCase())||"",[r,b]=s.useState(""),[d,m]=s.useState(!1),[j,w]=s.useState(!0);s.useEffect(()=>{o.auth.getSession().then(({data:{session:a}})=>{a&&!a.user.is_anonymous&&n(`/lobby?code=${t}`,{replace:!0}),w(!1)})},[t,n]);const u=async()=>{var a;if(!r.trim()){c.error("Digite seu nome!");return}if(!t){c.error("Link inválido â sem código de sala!");return}m(!0);try{const{data:i,error:g}=await o.auth.signInAnonymously();if(g)throw g;const l=(a=i.user)==null?void 0:a.id;if(!l)throw new Error("Erro ao criar sessão");const{error:p}=await o.from("profiles").insert({user_id:l,display_name:r.trim(),is_guest:!0});p&&(console.error("Profile insert error:",p),await o.from("profiles").update({display_name:r.trim()}).eq("user_id",l)),await new Promise(N=>setTimeout(N,500)),n(`/lobby?code=${t}`,{replace:!0})}catch(i){console.error("Join error:",i),c.error("Erro ao entrar. Tente novamente."),m(!1)}};return j?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(f,{className:"animate-spin text-gold",size:40})}):e.jsxs("div",{className:"min-h-screen bg-background flex flex-col items-center justify-center p-4",children:[e.jsxs(h.div,{initial:{y:-30,opacity:0},animate:{y:0,opacity:1},className:"flex flex-col items-center mb-8",children:[e.jsx("img",{src:k,alt:"Truco Arena",className:"w-24 h-24 drop-shadow-2xl"}),e.jsx("h1",{className:"font-display text-2xl text-gold text-shadow-glow tracking-wider mt-2",children:"TRUCO ARENA"})]}),e.jsxs(h.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},transition:{delay:.2},className:"bg-card border border-border rounded-2xl p-6 w-full max-w-sm space-y-4",children:[e.jsxs("div",{className:"text-center space-y-1",children:[e.jsx("span",{className:"text-4xl",children:"ð"}),e.jsx("h2",{className:"font-display text-lg text-foreground",children:"Você foi convidado!"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Sala: ",e.jsx("span",{className:"font-mono text-gold font-bold tracking-widest",children:t})]})]}),e.jsx("input",{value:r,onChange:a=>b(a.target.value),placeholder:"Seu nome / apelido",maxLength:20,className:"w-full bg-input border border-border rounded-lg px-4 py-3 text-foreground placeholder:text-muted-foreground text-center text-lg",onKeyDown:a=>a.key==="Enter"&&u(),autoFocus:!0}),e.jsx(S,{onClick:u,disabled:d||!r.trim(),className:"w-full bg-gold-gradient font-bold h-14 text-base shadow-gold",children:d?e.jsx(f,{className:"animate-spin",size:20}):e.jsxs(e.Fragment,{children:[e.jsx(A,{size:20}),"Entrar na Sala"]})}),e.jsx("p",{className:"text-[11px] text-center text-muted-foreground",children:"Você entrará como convidado apenas para esta partida"})]})]})};export{L as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.