1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ShareVictoryCard-C5sjnCTF.js","assets/index-DMRgbZm2.js","assets/index-BQxymgTF.css","assets/share-2-WZc9L-Tc.js"])))=>i.map(i=>d[i]); 2import{c as La,r as l,j as e,A as Y,m as g,f as za,g as Ht,i as qa,y as Ua,b as ye,z as Wt,s as N,u as Ba,n as Be,D as Fa,E as Ha,a as Wa,F as Xa,I as Ja,_ as Dt,L as Ka,t as ie,J as Qa,K as Ya,v as Za}from"./index-DMRgbZm2.js";import{c as Ga,P as Te,i as es,g as ts,s as as,a as ss,p as rs,u as ns,b as It,d as os,e as is,f as Vt,h as ls,j as cs,k as ds,l as us,m as ms,n as at,o as ps}from"./sounds-D8OBr31j.js";import{T as xs,u as gs,E as fs}from"./EmoteWheel-CgZXB80u.js";import{E as hs}from"./eye-off-ZoGlujq-.js";import{i as be,a as Pe,b as bs,c as Ot,d as Me,e as ys,f as vs,h as st,r as js,j as Ns,n as ws,S as qe,k as rt,Q as _s}from"./truco-DTCEwY2D.js";import{g as he}from"./index-DZualLqL.js";import{c as Xt,b as Ss,O as Ts,W as ks,C as Cs,T as As,D as Ms,a as Jt,P as Es,R as Rs}from"./index-Ba4C_T1S.js";import{A as $t}from"./achievements-qHXN0PNg.js";import{u as Kt}from"./useVip-DV3vOPpX.js";import{u as Ps,s as Ds,p as Is,a as Vs}from"./soundManager-qrbTfcPi.js";import{A as Os}from"./arrow-left-k_C7nB0y.js";import{V as $s,a as Lt}from"./volume-x-DAnXPene.js";import{M as zt}from"./mic-D89YRyTW.js";import{C as Ls}from"./clock-DKyDjhh9.js";import{M as zs}from"./message-circle-Bix0COOS.js";import{S as qs}from"./send-D-Lw4uxC.js";import{g as Qt}from"./emoteAssets-CzFtICTt.js";import{u as Us,G as Bs}from"./GuestWarningDialog-BnWFC_zH.js";import{i as Fs,s as Hs,c as Ws}from"./useGuestGameCounter-CJt0WaLg.js";import"./popover-CLMVRS1B.js";import"./index-BUTuhxzg.js";import"./dialog-CTJ4xC4l.js";import"./check-BVvbnuq-.js";import"./settings-CJZ9ISIn.js";import"./lock-B32r3OMw.js";import"./coins-CxLZpWqs.js";import"./history-CJIG3TKM.js";import"./medal-Qkl0tjqK.js";/** 3 * @license lucide-react v0.462.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const Xs=La("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]),qt={Truco:{emoji:"ð",bg:"from-amber-600 via-yellow-500 to-amber-600",text:"TRUCO!!!",shake:8},Seis:{emoji:"ð¥",bg:"from-orange-600 via-red-500 to-orange-600",text:"SEIS VALENDO!!!",shake:12},Nove:{emoji:"ð",bg:"from-red-700 via-red-500 to-red-700",text:"NOVE!!!",shake:16},Doze:{emoji:"â¡",bg:"from-purple-700 via-fuchsia-500 to-purple-700",text:"DOZE!!!",shake:20}},Js=({level:r,callerName:s,callerAvatar:d,isMyTeam:c,onComplete:m})=>{const[h,p]=l.useState(!0),j=qt[r]||qt.Truco,b=l.useRef(m);return b.current=m,l.useEffect(()=>{const M=setTimeout(()=>{var _;p(!1),(_=b.current)==null||_.call(b)},1800);return()=>clearTimeout(M)},[]),e.jsx(Y,{children:h&&e.jsxs(g.div,{initial:{opacity:0}
7,animate:{opacity:1},exit:{opacity:0,scale:.8},className:"fixed inset-0 z-[100] flex items-center justify-center pointer-events-none",children:[e.jsx(g.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-black/60"}),e.jsx(g.div,{initial:{scale:0,rotate:0},animate:{scale:[0,3],rotate:[0,45],opacity:[.8,0]},transition:{duration:1.5,ease:"easeOut"},className:`absolute w-64 h-64 bg-gradient-radial ${j.bg} rounded-full blur-3xl`}),e.jsxs(g.div,{initial:{scale:0,rotate:-15},animate:{scale:[0,1.3,1],rotate:[-15,5,0],x:[0,-j.shake,j.shake,-j.shake/2,j.shake/2,0]},transition:{scale:{duration:.5,times:[0,.6,1]},rotate:{duration:.5},x:{duration:.6,delay:.4,ease:"easeInOut"}},className:"relative flex flex-col items-center gap-3",children:[e.jsx(g.div,{animate:{scale:[1,1.3,1],rotate:[0,10,-10,0]},transition:{repeat:2,duration:.4},className:"text-7xl drop-shadow-[0_0_30px_rgba(255,200,0,0.6)]",children:j.emoji}),e.jsx(g.h1,{animate:{textShadow:["0 0 20px rgba(255,200,0,0.8)","0 0 60px rgba(255,200,0,0.4)","0 0 20px rgba(255,200,0,0.8)"]},transition:{repeat:1/0,duration:1},className:"font-display text-6xl md:text-7xl text-white tracking-wider text-center",style:{WebkitTextStroke:"2px rgba(0,0,0,0.3)",textShadow:"0 0 40px rgba(255,200,0,0.6), 0 4px 8px rgba(0,0,0,0.5)"},children:j.text}),e.jsxs(g.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.5},className:`flex items-center gap-2 px-4 py-2 rounded-full backdrop-blur-md border 8 ${c?"bg-emerald-500/20 border-emerald-400/40 text-emerald-200":"bg-red-500/20 border-red-400/40 text-red-200"}`,children:[e.jsx("span",{className:"text-2xl",children:d}),e.jsx("span",{className:"font-bold text-lg",children:s})]}),Array.from({length:4}).map((M,_)=>e.jsx(g.span,{initial:{x:0,y:0,opacity:1,scale:.5},animate:{x:(Math.random()-.5)*300,y:(Math.random()-.5)*300,opacity:0,scale:1+Math.random()},transition:{duration:1,delay:.2+_*.1,ease:"easeOut"},className:"absolute text-3xl pointer-events-none",children:j.emoji},_))]})]})})},Ks={top:"absolute top-0 sm:top-3 left-1/2 -translate-x-1/2",left:"absolute left-0 sm:left-3 top-[15%] sm:top-1/2 -translate-y-1/2",right:"absolute right-0 sm:right-3 top-[15%] sm:top-1/2 -translate-y-1/2"},Ue=l.memo(({player:r,position:s,isCurrent:d,isTeammate:c,secretSignal:m})=>e.jsxs("div",{className:`${Ks[s]} flex flex-col items-center gap-0.5 sm:gap-1.5 z-10`,children:[e.jsx(Y,{children:c&&m&&!m.fromMe&&s==="top"&&e.jsxs(g.div,{initial:{scale:0,y:10,opacity:0},animate:{scale:1,y:0,opacity:1},exit:{scale:0,y:-10,opacity:0},className:"fixed top-2 left-1/2 -translate-x-1/2 z-[100] flex flex-col items-center",children:[e.jsxs("div",{className:"bg-card border-2 border-primary/60 rounded-2xl px-4 py-2.5 shadow-xl flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:m.emoji}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[9px] text-muted-foreground uppercase tracking-wider font-semibold",children:"Sinal do Parceiro"}),e.jsx("span",{className:"text-sm text-gold font-bold whitespace-nowrap",children:m.meaning})]})]}),e.jsx("div",{className:"w-3 h-3 bg-card border-r-2 border-b-2 border-primary/60 rotate-45 -mt-1.5"})]})}),e.jsx(Y,{children:c&&m&&m.fromMe&&s==="top"&&e.jsx(g.div,{initial:{scale:0,y:40,opacity:0},animate:{scale:1,y:0,opacity:1},exit:{scale:0,opacity:0},transition:{type:"spring",damping:12},className:"absolute -bottom-8 sm:-bottom-10 left-1/2 -translate-x-1/2 z-50",children:e.jsxs("div",{className:"bg-primary/20 backdrop-blur-md border border-primary/30 rounded-full px-2.5 py-1 shadow-lg flex items-center gap-1",children:[e.jsx("span",{className:"text-lg",children:m.emoji}),e.jsx("span",{className:"text-[9px] text-primary-foreground/70 font-semibold",children:"ð¤«"})]})})}),e.jsxs("div",{className:`flex items-center gap-1 sm:gap-2 px-1.5 sm:px-3 py-0.5 sm:py-1.5 rounded-full 9 ${c?"bg-emerald-500/20 border-emerald-500/40":"bg-red-500/15 border-red-500/30"} 10 backdrop-blur-md border shadow-lg`,children:[e.jsx("span",{className:"text-sm sm:text-lg",children:r.avatar}),e.jsx("span",{className:"text-[9px] sm:text-xs font-bold text-foreground max-w-[50px] sm:max-w-none truncate",children:r.name}),d&&e.jsx(g.span,{animate:{scale:[1,1.4,1],opacity:[1,.6,1]},transition:{repeat:1/0,duration:.8},className:"w-1.5 h-1.5 sm:w-2.5 sm:h-2.5 rounded-full bg-primary shadow-gold"})]}),e.jsx("div",{className:`flex ${s==="left"||s==="right"?"flex-col":"flex-row"} gap-0.5 sm:gap-1`,children:r.hand.map((h,p)=>e.jsx("div",{className:`${s==="left"||s==="right"?"w-7 h-5 sm:w-10 sm:h-7 md:w-12 md:h-9":"w-6 h-9 sm:w-8 sm:h-12 md:w-10 md:h-[60px]"} 11 rounded-md sm:rounded-lg overflow-hidden shadow-card`,children:e.jsx("img",{src:Ga,alt:"",className:"w-full h-full object-cover",loading:"lazy"})},`${r.id}-card-${p}`))})]}));Ue.displayName="PlayerSeat";const Re=l.memo(({play:r,direction:s})=>{if(!r)return e.jsx("div",{className:"w-[52px] h-[76px] md:w-[68px] md:h-[100px] lg:w-[76px] lg:h-[110px] rounded-xl border border-foreground
11/5"});const d=r.card??null;return e.jsx(g.div,{initial:{...s,opacity:0,rotate:(s.rotate??0)*1.4,scale:.5},animate:{x:0,y:0,opacity:1,rotate:s.rotate??0,scale:1},transition:{type:"spring",damping:14,stiffness:190},children:d?e.jsx(Te,{card:d,disabled:!0,small:!0}):e.jsx("div",{className:"w-[52px] h-[76px] md:w-[68px] md:h-[100px] lg:w-[76px] lg:h-[110px] bg-muted/80 rounded-xl flex items-center justify-center backdrop-blur-sm border border-border/30",children:e.jsx(hs,{size:16,className:"text-muted-foreground"})})})});Re.displayName="PlayedCardSlot";const Yt=l.memo(({myTeamScore:r,theirScore:s,roundWinners:d,myTeam:c,className:m})=>e.jsxs("div",{className:`relative flex justify-center items-center gap-4 sm:gap-6 py-1 sm:py-2 bg-background/60 backdrop-blur-sm ${m||""}`,children:[e.jsxs("div",{className:"text-center",children:[e.jsx("span",{className:"text-[9px] sm:text-[10px] text-gold/80 uppercase font-bold tracking-widest",children:"Nós"}),e.jsx("p",{className:"text-2xl sm:text-3xl font-display text-gold drop-shadow-lg leading-none",children:r})]}),e.jsx("div",{className:"flex flex-col items-center gap-1",children:e.jsxs("div",{className:"flex gap-1.5",children:[d.map((h,p)=>e.jsx("div",{className:`w-4 h-4 rounded-full border-2 ${h===c?"bg-primary border-primary shadow-gold":h===-1?"bg-muted-foreground/50 border-muted-foreground":"bg-accent border-accent"}`},p)),Array.from({length:3-d.length}).map((h,p)=>e.jsx("div",{className:"w-4 h-4 rounded-full border-2 border-muted/30 bg-muted/20"},`e-${p}`))]})}),e.jsxs("div",{className:"text-center",children:[e.jsx("span",{className:"text-[9px] sm:text-[10px] text-foreground/50 uppercase font-bold tracking-widest",children:"Eles"}),e.jsx("p",{className:"text-2xl sm:text-3xl font-display text-foreground drop-shadow-lg leading-none",children:s})]})]}));Yt.displayName="Scoreboard";function Qs(){const r=["provocador","calmo","engracado","blefador","quieto","emocionado"];return r[Math.floor(Math.random()*r.length)]}const Ys={provocador:1.4,calmo:.7,engracado:1.2,blefador:1.1,quieto:.3,emocionado:1.3},Zs={provocacao:["aà sim hein","corre não","segura essa","tá sentindo aÃ?","quero ver agora","chama mais","pede outra","essa mesa tá minha","hoje não hein","veio fraco demais","já era","vou nem comemorar","tá fácil","sem chance","pode ir embora","vai querer mais?","de boa né","só lamento","eita","faltou carta aÃ","chora não","partiu próxima","quer desistir?","essa doeu né","veio seco?"],comemoracao:["boaaa ð¥","é isso aÃ!","aà sim!","toma!","demais!","limpo!","essa foi bonita","fechou!","linda jogada","show!","dale!","boa parceiro!","mandou bem!","perfeito","é nóis!","assim que faz","essa foi cirúrgica","que isso","olha só","vamo que vamo","tô on fire ð¥","simbora","essa veio forte"],blefe:["confia no pai","pode vir","tô carregado","essa mão veio boa","xi... vai ser feio","nem preciso pensar","mão de ouro","tô tranquilo","essa aqui tá garantida","vem que tem","preparado pra essa?","vai chorar","sem dó","olha o zap","cuida
11do hein","não duvida não","tô com tudo","vai nessa"],defesa:["hmmm","calma lá","tá difÃcil","eita lascou","complicou","pô, essa não","rapaz...","vixe","ai ai","tenso","tá osso","que mão hein","segura aÃ","vamo ver","respira","tudo bem... tudo bem","paciência"],surpresa:["eita!","opa!","caramba","que isso?!","ixi","misericórdia","não acredito","como assim","sério isso?","ué","puts","o quê??","olha só","ih rapaz","virou o jogo","credo"],confianca:["suave","tranquilo","de boa","tá no papo","sem estresse","fácil demais","essa é minha","relax","tá safe","jogo controlado","na mão","tudo sob controle","sem pressa","vai assim mesmo","sossega","desce que desce"],ironia:["que jogada hein...","mandou bem... ð","interessante","bonito bonito","parabéns pelo erro","genial","magnÃfico","espetacular...","aceitou por quê?","entregou","foi bonito","adorei essa estratégia","tá indo bem... ð
","continue assim","ótima decisão","nota 10","uau","tava cantado"],pressao_truco:["truco neles!","bora ver quem aguenta","aceita se for homem","vem com tudo","vai correr?","mostra que tem","tá com medo?","pediu agora aguenta","segura firme","corre não","vamo aumentar","sobe mais","quero ver a cara"],pos_vitoria:["fechou! ð","é isso aÃ!","ganhou merecido","boa partida","obrigado pela partida","valeu!","gg","foi boa","mais uma!","tamo junto","dominamos","sem chance"],pos_derrota:["boa...","tá bom vai","na próxima","essa passou","faz parte","acontece","sorte deles","veio tudo pra eles","mão ruim demais","não deu","jogo injusto kk","afe"],mao_ruim:["mão ruim da peste","que mão horrÃvel","deus me livre","socorro","tô sem nada","pior impossÃvel","lascou","essas cartas...","nem acredito nessa mão"],adversario_correu:["correuuu","foi embora kk","não aguentou a pressão","caiu na pressão","era blefe mas correu ð","fraco demais","nem tentou","sabia!","valeu os pontos","tÃmido demais","já era amigo","ficou com medo"],partida_apertada:["agora complica","tá apertado","jogo duro","vai dar ruim","nervoso aqui","quem piscar perde","decisão","tá no fio da navalha","concentra","agora é pra valer","tá pegando fogo","tensão pura"]},Gs={provocador:{provocacao:["vai chorar é?","humilhação total","fraquÃssimo","sem piedade"],pressao_truco:["corre logo","perdeu mané","nem tenta"]},engracado:{comemoracao:["kkkk demais","hahaha","rindo alto aqui","kkkkk"],surpresa:["meu deus do céu kk","socorro kkk","morri"],ironia:["genial kkkk","adorei ð"]},blefador:{blefe:["essa aqui é braba","melhor correr...","zap na mão ð","tô pesado"],confianca:["nem preciso das outras","uma carta resolve"]},emocionado:{comemoracao:["VAMOOO!!","SIIIIM!","BOAAA DEMAIS!","INCRÃVEL!"],pos_derrota:["NÃAAO!","impossÃvel!","não acredito nisso!"],surpresa:["CARAMBA!","QUE ISSO?!","EITAAAA!"]}},er={played_strong_card:{chance:.12,categories:["confianca","provocacao"]},played_manilha:{chance:.18,categories:["confianca","provocacao","comemoracao"]},won_round:{chance:.15,categories:["comemoracao","provocacao","confianca"]},lost_round:{chance:.1,categories:["defesa","surpresa","ironia"]},called_truco:{chance:.3,categories:["pressao_truco","blefe","confianca"]},accepted_truco:{chance:.22,categories:["confianca","provocacao","blefe"]},opponent_ran:{chance:.35,categories:["adversario_correu","provocacao","ironia"]},game_winning:{chance:.12,categories:["confianca","comemoracao"]},game_losing:{chance:.08,categories:["defesa","partida_apertada"]},tight_game:{chance:.1,categories:["partida_apertada","confianca"]},bad_hand:{chance:.06,categories:["mao_ruim","defesa"]},good_hand:{chance:.05,categories:["blefe","confianca"]},round_tied:{chance:.08,categories:["surpresa","ironia"]},bluffing:{chance:.15,categories:["blefe","confianca","provocacao"]},partner_won_round:{chance:.12,categories:["comemoracao"]},opponent_played_manilha:{chance:.1,categories:["surpresa","defesa"]}};function tr(r){return{recentPhrases:[],lastMessageTime:0,messagesThisHand:0,currentHandNumber:0,personality:r??Qs()}}const ar=8e3,sr=2,rr=12;function nr(r,s,d){let c={...s};if(d!==c.currentHandNumber&&(c.messagesThisHand=0,c.currentHandNumber=d),c.messagesThisHand>=sr)return{message:null,memory:c};const m=Date.now();if(m-c.lastMessageTime<ar)return{message:null,memory:c};const h=er[r],p=Ys[c.personality],j=h.chance*p;if(Math.random()>j)return{message:null,memory:c};const b=or(h.categories,c);return b?(c.lastMessageTime=m,c.messagesThisHand+=1,c.recentPhrases=[b,...c.recentPhrases].slice(0,rr),{message:b,memory:c}):{message:null,memory:c}}function or(r,s){var m;const d=s.personality;let c=[];for(const h of r){c.push(...Zs[h]);const p=(m=Gs[d])==null?void 0:m[h];p&&c.push(...p)}return c=[...new Set(c)],c=c.filter(h=>!s.recentPhrases.includes(h)),c.length===0?null:c[Math.floor(Math.random()*c.length)]}function ir(r,s,d){const c=[],m=s.vira;if(!m)return c;const h=be(r,m,s.variant),p=Pe(r,m,s.suitRankingEnabled,s.variant);h?c.push("played_manilha"):p>=9&&c.push("played_strong_card");const[j,b]=s.teamScores;Math.abs(j-b)<=2&&j>=6&&b>
11=6&&c.push("tight_game");const _=s.teamScores[d],V=s.teamScores[d===0?1:0];return _>=9&&_>V&&c.push("game_winning"),V>=9&&V>_&&c.push("game_losing"),c}function lr(r,s){return r===-1?["round_tied"]:r===s?["won_round"]:["lost_round"]}function Ee(r,s){switch(r){case"called":return["called_truco"];case"accepted":return["accepted_truco"];case"ran":return["opponent_ran"]}}function cr(r,s){if(!s.vira)return[];const d=r.filter(m=>be(m,s.vira,s.variant)).length,c=r.filter(m=>Pe(m,s.vira,s.suitRankingEnabled,s.variant)>=9).length;return d>=2||d>=1&&c>=2?["good_hand"]:d===0&&c===0&&r.reduce((h,p)=>h+Pe(p,s.vira,s.suitRankingEnabled,s.variant),0)<=12?["bad_hand"]:[]}var Zt="AlertDialog",[dr,mn]=za(Zt,[Xt]),ue=Xt(),Gt=r=>{const{__scopeAlertDialog:s,...d}=r,c=ue(s);return e.jsx(Rs,{...c,...d,modal:!0})};Gt.displayName=Zt;var ur="AlertDialogTrigger",ea=l.forwardRef((r,s)=>{const{__scopeAlertDialog:d,...c}=r,m=ue(d);return e.jsx(Ss,{...m,...c,ref:s})});ea.displayName=ur;var mr="AlertDialogPortal",ta=r=>{const{__scopeAlertDialog:s,...d}=r,c=ue(s);return e.jsx(Es,{...c,...d})};ta.displayName=mr;var pr="AlertDialogOverlay",aa=l.forwardRef((r,s)=>{const{__scopeAlertDialog:d,...c}
11=r,m=ue(d);return e.jsx(Ts,{...m,...c,ref:s})});aa.displayName=pr;var ke="AlertDialogContent",[xr,gr]=dr(ke),fr=Ua("AlertDialogContent"),sa=l.forwardRef((r,s)=>{const{__scopeAlertDialog:d,children:c,...m}=r,h=ue(d),p=l.useRef(null),j=Ht(s,p),b=l.useRef(null);return e.jsx(ks,{contentName:ke,titleName:ra,docsSlug:"alert-dialog",children:e.jsx(xr,{scope:d,cancelRef:b,children:e.jsxs(Cs,{role:"alertdialog",...h,...m,ref:j,onOpenAutoFocus:qa(m.onOpenAutoFocus,M=>{var _;M.preventDefault(),(_=b.current)==null||_.focus({preventScroll:!0})}),onPointerDownOutside:M=>M.preventDefault(),onInteractOutside:M=>M.preventDefault(),children:[e.jsx(fr,{children:c}),e.jsx(br,{contentRef:p})]})})})});sa.displayName=ke;var ra="AlertDialogTitle",na=l.forwardRef((r,s)=>{const{__scopeAlertDialog:d,...c}=r,m=ue(d);return e.jsx(As,{...m,...c,ref:s})});na.displayName=ra;var oa="AlertDialogDescription",ia=l.forwardRef((r,s)=>{const{__scopeAlertDialog:d,...c}=r,m=ue(d);return e.jsx(Ms,{...m,...c,ref:s})});ia.displayName=oa;var hr="AlertDialogAction",la=l.forwardRef((r,s)=>{const{__scopeAlertDialog:d,...c}
11=r,m=ue(d);return e.jsx(Jt,{...m,...c,ref:s})});la.displayName=hr;var ca="AlertDialogCancel",da=l.forwardRef((r,s)=>{const{__scopeAlertDialog:d,...c}=r,{cancelRef:m}=gr(ca,d),h=ue(d),p=Ht(s,m);return e.jsx(Jt,{...h,...c,ref:p})});da.displayName=ca;var br=({contentRef:r})=>{const s=`\`${ke}\` requires a description for the component to be accessible for screen reader users. 12 13You can add a description to the \`${ke}\` by passing a \`${oa}\` component as a child, which also benefits sighted users by adding visible context to the dialog. 14 15Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${ke}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component. 16 17For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return l.useEffect(()=>{var c;document.getElementById((c=r.current)==null?void 0:c.getAttribute("aria-describedby"))||console.warn(s)},[s,r]),null},yr=Gt,vr=ea,jr=ta,ua=aa,ma=sa,pa=la,xa=da,ga=na,fa=ia;const Nr=yr,wr=vr,_r=jr,ha=l.forwardRef(({className:r,...s},d)=>e.jsx(ua,{className:ye("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",r),...s,ref:d}));ha.displayName=ua.displayName;const ba=l.forwardRef(({className:r,...s},d)=>e.jsxs(_r,{children:[e.jsx(ha,{}),e.jsx(ma,{ref:d,className:ye("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",r),...s})]}));ba.displayName=ma.displayName;const ya=({className:r,...s})=>e.jsx("div",{className:ye("flex flex-col space-y-2 text-center sm:text-left",r),...s});ya.displayName="AlertDialogHeader";const va=({className:r,...s})=>e.jsx("div",{className:ye("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",r),...s});va.displayName="AlertDialogFooter";const ja=l.forwardRef(({className:r,...s},d)=>e.jsx(ga,{ref:d,className:ye("text-lg font-semibold",r),...s}));ja.displayName=ga.displayName;const Na=l.forwardRef(({className:r,...s},d)=>e.jsx(fa,{ref:d,className:ye("text-sm text-muted-foreground",r),...s}));Na.displayName=fa.displayName;const wa=l.forwardRef(({className:r,...s},d)=>e.jsx(pa,{ref:d,className:ye(Wt(),r),...s}));wa.displayName=pa.displayName;const _a=l.forwardRef(({className:r,...s},d)=>e.jsx(xa,{ref:d,className:ye(Wt({variant:"outline"}),"mt-2 sm:mt-0",r),...s}));_a.displayName=xa.displayName;async function Sr(r){const{data:s}=await N.from("games").select("*").eq("lobby_id",r).maybeSingle();return s}async function Tr(r){const{data:s}=await N.from("lobby_players").select("*, profiles(display_name, avatar)").eq("lobby_id",r).order("joined_at");return s}function Ut(r){return new Promise(s=>setTimeout(s,r))}function kr(r,s){const[d,c]=l.useState(null),[m,h]=l.useState(0),[p,j]=l.useState(null),[b,M]=l.useState(!0),_=l.useRef(!1);l.useEffect(()=>{if(!r||!s||_.current)return;_.current=!0,(async()=>{for(let $=0;$<5;$++){const E=await Sr(r);if(E){j(E.id);const A=E.player_map;
17h(A[s.id]??0),c(E.state),M(!1);return}if($===0){const A=await Tr(r);if(!A||A.length<2){await Ut(1500);continue}const K={},Ne=A.map((q,Z)=>{var ae,le;return K[q.profile_id]=Z,{id:`p${Z}`,name:((ae=q.profiles)==null?void 0:ae.display_name)||"Jogador",avatar:((le=q.profiles)==null?void 0:le.avatar)||"ð",team:q.team??Z%2,hand:[],isBot:!1}}),i=bs(Ne),{data:D,error:L}=await N.from("games").insert({lobby_id:r,player_map:K,state:i}).select().single();if(!L&&D){j(D.id);const q=D.player_map;h(q[s.id]??0),c(D.state),M(!1);return}console.log("[useMultiplayerGame] Insert failed, will retry fetch:",L==null?void 0:L.message)}await Ut(1e3)}console.error("[useMultiplayerGame] Could not find or create game after retries"),M(!1)})()},[r,s]),l.useEffect(()=>{if(!p)return;const x=N.channel(`game-rt-${p}`).on("postgres_changes",{event:"UPDATE",schema:"public",table:"games",filter:`id=eq.${p}`},$=>{const E=$.new.state;c(E)}).subscribe();return()=>{N.removeChannel(x)}},[p]);const V=l.useCallback(async x=>{p&&(c(x),queueMicrotask(async()=>{await N.from("games").update({state:x,updated_at:new Date().toISOString()}).eq("id",p)}))},[p]);return{game:d,myPlayerIndex:m,updateGameState:V,gameId:p,loading:b}}function Cr(r){const[s,d]=l.useState(new Set),[c,m]=l.useState(!0);l.useEffect(()=>{if(!r){m(!1);return}(async()=>{const{data:j}=await N.from("player_achievements").select("achievement_key").eq("profile_id",r.id);j&&d(new Set(j.map(b=>b.achievement_key))),m(!1)})()},[r]);const h=l.useCallback(async p=>{if(!r)return;const j=[];for(const _ of $t)s.has(_.key)||_.check(p)&&j.push(_.key);if(j.length===0)return;const b=j.map(_=>({profile_id:r.id,achievement_key:_})),{error:M}=await N.from("player_achievements").upsert(b,{onConflict:"profile_id,achievement_key"});if(!M){d(_=>{const V=new Set(_);return j.forEach(x=>V.add(x)),V});for(const _ of j){const V=$t.find(x=>x.key===_);V&&Ba.success(`${V.emoji} Conquista desbloqueada!`,{description:`${V.name}: ${V.description}`,duration:4e3})}}},[r,s]);return{unlockedKeys:s,loading:c,checkAndUnlock:h}}function Ar(){const{profile:r}=Be(),{isVip:s}=Kt();return{onMatchEnded:l.useCallback(async(c={})=>{const m=await Fa.onMatchEnded((r==null?void 0:r.id)??null,{...c,isVip:s});return m&&await Ha((r==null?void 0:r.id)??null,"impression","interstitial","post_match"),m},[r==null?void 0:r.id,s])}}const Bt=20,Mr=({difficulty:r="medium",mode:s="2v2",lobbyId:d=null,variant:c="paulista",suitRanking:m=!0,tournamentMatchId:h=null,tournamentId:p=null})=>{var Ct,At,Mt,Et,Rt;const j=Wa(),{profile:b,refreshProfile:M}=Be(),{isVip:_}=Kt(),{onMatchEnded:V}=Ar(),x=!!d,$=s==="1v1"?2:4,E=he(c),A=kr(x?d:null,b),[K,Ne]=l.useState(()=>Ot($,c,m)),i=x?A.game:K,D=x?A.myPlayerIndex:0,[L,q]=l.useState(()=>Xa());l.useEffect(()=>{Ja(L).then(a=>{a.tableImg&&a.bgImg&&q(a)})},[L.id]);const[Z,ae]=l.useState(null),[le,se]=l.useState(!1),[Q,me]=l.useState(Bt),ce=l.useRef(null),[ot,Fe]=l.useState(!1),[it,lt]=l.useState(!1);l.useState(null);const[He,ct]=l.useState(null),{checkAndUnlock:Sa}=Cr(b),[G,We]=l.useState(es()),[pe,Ta]=l.useState(ts()),[ka,dt]=l.useState(!1),[Xe,ut]=l.useState(!1),[ve,Je]=l.useState(""),[Ke,De]=l.useState(!1),je=l.useRef(null),Qe=l.useRef([]),[mt,Ca]=l.useState(null),Aa=l.useRef(null),[pt,xt]=l.useState(null),[Ma,gt]=l.useState(null),[Ea,ft]=l.useState(!1),Ie=l.useRef({}),ht=l.useRef(0),bt=l.useCallback(a=>(Ie.current[a]||(Ie.current[a]=tr()),Ie.current[a]),[]),[Ra,Ve]=l.useState(null),[re,ne]=l.useState(null),[Ce,Ye]=l.useState(null),R=l.useCallback(a=>
17{if(x){if(A.game){const o=a(A.game);A.updateGameState(o)}}else Ne(a)},[x,A.game,A.updateGameState]),U=l.useCallback((a,o=2e3)=>{ae(a),setTimeout(()=>ae(null),o)},[]),t=i,xe=(t==null?void 0:t.players.length)??4,z=t==null?void 0:t.players[D],X=t?t.currentPlayerIndex===D&&t.phase==="playing"&&!ot:!1,S=(z==null?void 0:z.team)??0,ee=t?Me(t):E.trucoLevels,ge=l.useCallback((a,o)=>{if(!(x||!t))for(const n of o){const u=bt(a),f=nr(n,u,ht.current);if(Ie.current[a]=f.memory,f.message){setTimeout(()=>{R(v=>({...v,lastChatMessage:{playerId:a,message:f.message,timestamp:Date.now()}}))},400+Math.random()*800);break}}},[x,t,R,bt]);l.useEffect(()=>{(t==null?void 0:t.roundNumber)===1&&(t==null?void 0:t.roundPlays.length)===0&&(ht.current+=1,x||t.players.forEach(a=>{if(a.isBot){const o=cr(a.hand,t);o.length>0&&setTimeout(()=>ge(a.id,o),1500+Math.random()*2e3)}}))},[t==null?void 0:t.roundNumber,t==null?void 0:t.roundPlays.length]);const Ae=a=>(D+a)%xe,Oe=Ae(xe===2?1:2),we=xe===4?Ae(1):-1,_e=xe===4?Ae(3):-1;l.useEffect(()=>(Ps(),as(),Ds(),Is().catch(()=>{}),()=>{ss(),Vs()}),[]);const yt=l.useRef(t==null?void 0:t.roundNumber),vt=l.useRef(t==null?void 0:t.turnValue);l.useEffect(()=>{t&&(t.roundNumber===1&&(yt.current!==1||vt.current!==t.turnValue)&&rs(),yt.current=t.roundNumber,vt.current=t.turnValue)},[t==null?void 0:t.roundNumber,t==null?void 0:t.turnValue]),l.useEffect(()=>{ns()},[pe,G]),l.useEffect(()=>{if(!(!t||!X||t.gameOver))return me(Bt),ce.current=setInterval(()=>{me(a=>{if(a<=1){ce.current&&clearInterval(ce.current);const o=t.players[D].hand;if(o.length>0){const n=o[Math.floor(Math.random()*o.length)];setTimeout(()=>Ge(n,!1),100)}return 0}return a-1})},1e3),()=>{ce.current&&clearInterval(ce.current)}},[X,t==null?void 0:t.gameOver,t==null?void 0:t.roundNumber,t==null?void 0:t.currentPlayerIndex]),l.useEffect(()=>{if(x||!t||t.phase!=="playing"||t.gameOver)return;const a=t.players[t.currentPlayerIndex];if(!a.isBot)return;Fe(!0);const o=setTimeout(()=>{if(t.trucoState!=="called"&&(t.lastTrucoTeam??null)!==a.team&&!t.maoDeOnze&&!t.mao
17DeFerro){const f=ee[ee.length-1].next;if(t.turnValue<f&&ys(a,t,r)){const v=ee.find(T=>T.current===t.turnValue);if(v){Ze(v.name,a.name,a.avatar,a.team===S),et(a.team),ge(a.id,Ee("called",a.team)),Fe(!1);return}}}const{card:n,hide:u}=vs(a,t,r);if(n){Ge(n,t.maoDeFerro?!1:u);const f=ir(n,t,a.team);f.length>0&&ge(a.id,f)}Fe(!1)},800+Math.random()*700);return()=>clearTimeout(o)},[t==null?void 0:t.currentPlayerIndex,t==null?void 0:t.phase,t==null?void 0:t.roundNumber,t==null?void 0:t.gameOver,x]),l.useEffect(()=>{if(x||!t||s!=="2v2"){ne(null);return}if(t.phase!=="truco-called"||t.trucoCallerTeam===null){ne(null);return}if((t.trucoCallerTeam===0?1:0)!==S){ne(null);return}const o=t.players.find(u=>u.team===S&&u.id!==(z==null?void 0:z.id)&&u.isBot);if(!o){ne(null);return}const n=setTimeout(()=>{const u=st(S,t,r);let f=!1;if(u){const O=Me(t),y=O.find(w=>w.current===t.turnValue),I=y?y.next:t.turnValue;if(O.some(w=>w.current===I)&&t.vira){const w=o.hand.filter(H=>be(H,t.vira,t.variant)).length,F=o.hand.filter(H=>Pe(H,t.vira,t.suitRankingEnabled,t.variant)>=8).length;f=w>=2||w>=1&&F>=1}}const v=f?"raise":u?"accept":"run",C={accept:["Aceita! ðª","Pode aceitar! â
","Tô forte, aceita!","Manda ver! ð¥"],run:["Corre! ð","Melhor correr...","Tô fraco, corre!","Não vale a pena ð¬"],raise:["Pede mais! ð¥ð¥","Aumenta! Tô com tudo!","Mete mais! ð£"]}[v],k=C[Math.floor(Math.random()*C.length)];ne({playerName:o.name,playerAvatar:o.avatar,opinion:v,opinionText:k})},600+Math.random()*400);return()=>{clearTimeout(n)}},[t==null?void 0:t.phase,t==null?void 0:t.trucoCallerTeam,x,s]),l.useEffect(()=>{if(x||!t||t.phase!=="truco-called"||t.trucoCallerTeam===null)return;const a=t.trucoCallerTeam===0?1:0;if(a===S)return;const o=s==="2v2"?2500+Math.random()*500:1500+Math.random()*500;let n;if(s==="2v2"){const f=t.players.filter(v=>v.team===a&&v.isBot);if(f.length>=2){const v=f[1];n=setTimeout(()=>{const T=st(a,t,r),C=T?["Aceita! ðª","Pode aceitar! â
","Tô forte!"]:["Corre! ð","Melhor correr...","Tô fraco!"];ne({playerName:v.name,playerAvatar:v.avatar,opinion:T?"accept":"run",opinionText:C[Math.floor(Math.random()*C.length)]})},800)}}const u=setTimeout(()=>{if(ne(null),!st(a,t,r)){$e(!1);const y=t.players.find(I=>I.team===t.trucoCallerTeam&&I.isBot);y&&ge(y.id,Ee("ran",y.team));return}const v=Me(t),T=v.find(y=>y.current===t.turnValue),C=T?T.next:t.turnValue;if(v.some(y=>y.current===C)){const I=t.players.filter(P=>P.team===a).flatMap(P=>P.hand),B=t.suitRankingEnabled,w=I.filter(P=>t.vira&&be(P,t.vira,t.variant)).length,F=I.filter(P=>t.vira&&Pe(P,t.vira,B,t.variant)>=8).length;let H=!1;if(r==="hard"?H=w>=2||w>=1&&F>=1&&t.roundWinners.filter(P=>P===a).length>=1:r==="medium"&&(H=(w>=2||w>=1&&F>=2)&&Math.random()>.4),H){const P=t.players.find(W=>W.team===a&&W.isBot);if(P){Nt(a,P.name,P.avatar,a===S),ge(P.id,Ee("accepted",P.team));return}}}$e(!0);const O=t.players.find(y=>y.team===a&&y.isBot);O&&ge(O.id,Ee("accepted",O.team))},o);return()=>{clearTimeout(u),n&&clearTimeout(n)}},[t==null?void 0:t.phase,t==null?void 0:t.trucoCallerTeam,x,s]);const Ze=l.useCallback((a,o,n,u)=>{Ye({level:a,callerName:o,callerAvatar:n,isMyTeam:u}),It(a)},[]),jt=l.useRef(!1),Ge=l.useCallback((a,o)=>{jt.current||(jt.current=!0),ce.current&&clearInterval(ce.current),os(),R(n=>{const u=n.currentPlayerIndex,f=n.players[u],v=f.hand.filter(w=>w.id!==a.id),T=!n.maoDeFerro&&o&&n.roundNumber>1,C={playerId:f.id,card:T?null:a,hiddenCard:T?a:null,round:n.roundNumber},k=[...n.roundPlays,C],O=n.players.map((w,F)=>F===u?{...w,hand:v}:w),y=k.filter(w=>w.round===n.roundNumber),I=n.players.length;if(y.length===I){const w=js(y,O,n.vira,n.suitRankingEnabled,n.variant),F=[...n.roundWinners,w.winnerTeam],H=Ns(F);if(H!==null||n.roundNumber>=3){const W=H,de=[...n.teamScores];W!==null&&(de[W]+=n.turnValue);const Se=he(n.variant),J=de[0]>=Se.winPoints||de[1]>=Se.winPoints;return{...n,players:O,roundPlays:k,roundWinners:F,teamScores:de,phase:"cards-on-table",gameOver:J,winnerTeam:J?de[0]>=Se.winPoints?0:1:W,_pendingPhase:J?"game-over":"turn-result"}}const P=w.winnerPlayerId?O.findIndex(W=>W.id===w.winnerPlayerId):n.roundStarterIndex;return{...n,players:O,roundPlays:k,roundWinners:F,currentPlayerIndex:P,roundStarterIndex:P,phase:"cards-on-table",_pendingPhase:"round-result",_pendingRoundNumber:n.roundNumber+1}}const B=(u+1)%I;return{...n,players:O,roundPlays:k,currentPlayerIndex:B}})},[R]);l.useEffect(()=>{if(!t||t.phase!=="cards-on-table")return;const a=setTimeout(()=>{R(o=>{const n=o._pendingPhase||"round-result",u=o._pendingRoundNumber,f={...o,phase:n};return u!==void 0&&(f.roundNumber=u),delete f._pendingPhase,delete f._pendingRoundNumber,f})},1800);return()=>clearTimeout(a)},[t==null?void 0:t.phase,R]),l.useEffect(()=>{if(t){if(t.phase==="round-result"){const a=t.roundWinners[t.roundWinners.length-1];
17a===S?is():a!==-1&&Vt(),x||t.players.forEach(n=>{if(n.isBot){const u=lr(a,n.team);ge(n.id,u)}});const o=setTimeout(()=>R(n=>({...n,phase:"playing"})),1500);return()=>clearTimeout(o)}if(t.phase==="turn-result"&&!t.gameOver){const a=setTimeout(()=>R(o=>ws(o)),2e3);return()=>clearTimeout(a)}t.phase==="game-over"&&(t.winnerTeam===S?ls():cs())}},[t==null?void 0:t.phase,t==null?void 0:t.gameOver,R,S]);const Pa=l.useCallback(()=>{if(!t||t.gameOver)return;const a=S===0?1:0;R(o=>{const n=[...o.teamScores];n[a]+=o.turnValue;const u=he(o.variant),f=n[0]>=u.winPoints||n[1]>=u.winPoints;return{...o,teamScores:n,phase:f?"game-over":"turn-result",gameOver:f,winnerTeam:f?n[0]>=u.winPoints?0:1:a,trucoState:"none",trucoCallerTeam:null,lastTrucoTeam:null}}),U(`Desistiu da rodada! -${t.turnValue} pt ð³ï¸`),Vt()},[t,S,R,U]),et=l.useCallback(a=>{R(o=>({...o,phase:"truco-called",trucoState:"called",trucoCallerTeam:a,lastTrucoTeam:a}))},[R]),$e=l.useCallback(a=>{if(R(o=>{if(!a){const v=o.trucoCallerTeam,T=[...o.teamScores],C=he(o.variant);T[v]+=o.turnValue;const k=T[0]>=C.winPoints||T[1]>=C.winPoints;return{...o,teamScores:T,phase:k?"game-over":"turn-result",gameOver:k,winnerTeam:k?T[0]>=C.winPoints?0:1:v,trucoState:"none",trucoCallerTeam:null,lastTrucoTeam:null}}const u=Me(o).find(v=>v.current===o.turnValue),f=u?u.next:o.turnValue;return{...o,turnValue:f,trucoState:"running",phase:"playing",trucoCallerTeam:null,lastTrucoTeam:o.trucoCallerTeam??o.lastTrucoTeam??null}}),a){us();const n=ee.find(u=>u.current===((t==null?void 0:t.turnValue)??E.startingTurnValue));U(`Aceitaram! Vale ${n?n.next:t==null?void 0:t.turnValue}! ðª`)}else{ds();const o=(t==null?void 0:t.turnValue)??1;if(U(`Recusaram! +${o} ponto${o>1?"s":""}`),!x&&(t==null?void 0:t.trucoCallerTeam)!=null){const n=t.players.find(u=>u.team===t.trucoCallerTeam&&u.isBot);n&&ge(n.id,Ee("ran",n.team))}}},[R,U,t==null?void 0:t.turnValue,c,ee,E]),Nt=l.useCallback((a,o,n,u)=>{R(k=>{const O=Me(k),y=O.find(w=>w.current===k.turnValue);if(!y)return k;const I=y.next;return O.find(w=>w.current===I)?{...k,turnValue:I,trucoState:"called",trucoCallerTeam:a,lastTrucoTeam:a,phase:"truco-called"}:k});const f=ee,v=f.find(k=>k.current===((t==null?void 0:t.turnValue)??1)),T=v?v.next:(t==null?void 0:t.turnValue)??1,C=f.find(k=>k.current===T);C&&Ze(C.name,o,n,u)},[R,t==null?void 0:t.turnValue,ee,Ze]),Da=l.useCallback(()=>{if(!t||!X||t.maoDeOnze||t.maoDeFerro)return;const a=ee[ee.length-1].next;if(t.turnValue>=a)return;const o=he(t.variant);if(t.teamScores[S]>=o.maoDeXThreshold){U(`Não pode pedir truco na ${o.maoDeXLabel}! â`);return}const n=ee.find(u=>u.current===t.turnValue);n&&(Ye({level:n.name,callerName:(z==null?void 0:z.name)??"Você",callerAvatar:(z==null?void 0:z.avatar)??"ð",isMyTeam:!0}),requestAnimationFrame(()=>It(n.name)),et(S))},[X,t,S,U,et,z,ee]),Le=l.useCallback(a=>{R(o=>{const n=he(o.variant);if(!a){const u=n.maoDeXThreshold,v=(o.teamScores[0]>=u?0:1)===0?1:0,T=[...o.teamScores];T[v]+=n.startingTurnValue;const C=T[v]>=n.winPoints;return{...o,teamScores:T,maoDeOnzeDecision:"rejected",phase:C?"game-over":"turn-result",gameOver:C,winnerTeam:v}}return{...o,turnValue:n.maoDeXAcceptedValue,maoDeOnzeDecision:"accepted",phase:"playing"}})},[R]);l.useEffect(()=>{if(x||!t||t.phase!=="mao-de-onze")return;const a=he(t.variant);if((t.teamScores[0]>=a.maoDeXThreshold?0:1)===S)return;const n=setTimeout(()=>Le(Math.random()>.3),800);return()=>clearTimeout(n)},[t==null?void 0:t.phase,t==null?void 0:t.teamScores,S,Le,x]);const wt=l.useRef(0);l.useEffect(()=>{var f;if(!(t!=null&&t.lastChatMessage))return;const{playerId:a,message:o,timestamp:n,audioUrl:u}=t.lastChatMessage;if(!(n<=wt.current)&&(wt.current=n,a!==((f=t.players[D])==null?void 0:f.id))){const v=t.players.find(T=>T.id===a);if(U(`${(v==null?void 0:v.name)??"Jogador"}: ${o}`,2500),ms(),u){xt(u),gt((v==null?void 0:v.name)??"Jogador");const T=new Audio(u);T.volume=G?0:pe,T.play().catch(()=>{})}}},[t==null?void 0:t.lastChatMessage,D,U,G,pe]);const tt={piscar:"ð",sobrancelha:"ð¤¨",bochecha:"ð",lingua:"ð"},Ia=l.useCallback(a=>{const o=tt[a],n=rt[a];Ve({fromMe:!0,signal:a,emoji:o,meaning:`${qe[a]} = ${n}`}),setTimeout(()=>Ve(null),2500),R(u=>({...u,lastSignal:{playerId:u.players[D].id,signal:a}}))},[R,D]);l.useEffect(()=>{var n;if(!(t!=null&&t.lastSignal)||xe!==4)return;const a=t.players.findIndex(u=>u.id===t.lastSignal.playerId);if(((n=t.players[a])==null?void 0:n.team)===S&&a!==D){const u=t.lastSignal.signal,f=tt[u],v=rt[u];Ve({fromMe:!1,signal:u,emoji:f,meaning:`${qe[u]} = ${v}`}),setTimeout(()=>Ve(null),2500)}},[t==null?void 0:t.lastSignal]),l.useEffect(()=>{var v,T;if(!i||!i.gameOver||it||!b)return;const a=((v=i.players[D])==null?void 0:v.team)??0,o=i.winnerTeam===a,n=i.teamScores[a],u=i.teamScores[a===0?1:0];if(o)try{const C=((T=i.players.find(k=>k.team!==a))==null?void 0:T.name)||"Oponente";Dt(()=>import("./ShareVictoryCard-C5sjnCTF.js"),__vite__mapDeps([0,1,2,3])).then(k=>k.saveLastVictory({opponent:C,score:`${n} x ${u}`,variant:(i.variant||c)==="mineiro"?"Mineiro":"Paulista",mode:s}))}catch{}if((async()=>{var C;try{d&&await N.from("lobbies").update({status:"finished"}).eq("id",d);const{data:k,error:O}=await N.rpc("record_match_result",{p_profile_id:b.id,p_result:o?"win":"loss",p_mode:`${s}_${i.variant||c}`,p_score_us:n,p_score_them:u});if(!O&&k){const y=k;let I=0;if(y.xp_earned){const{data:B}=await N.rpc("award_vip_xp_bonus",{p_base_xp:y.xp_earned}),w=B;if(I=(w==null?void 0:w.bonus_xp)||0,I>0){y.xp_earned=(y.xp_earned||0)+I,y.total_xp=w.total_xp;const{toast:F}=await Dt(async()=>{const{toast:H}=await import("./index-DMRgbZm2.js").then(P=>P.aB);return{toast:H}},__vite__mapDeps([1,2]));F.success(`ð Bônus VIP: +${I} XP`,{duration:3500})}}ct(y),Sa({wins:y.total_wins||0,losses:y.total_losses||0,totalGames:(y.total_wins||0)+(y.total_losses||0),xp:y.total_xp||0,trucosAccepted:0,trucosCalled:0,maoDeOnzeWins:0,perfectGames:o&&u===0?1:0,comebacks:0})}M();try{await N.rpc("award_match_rewards",{p_profile_id:b.id,p_won:o}),await N.rpc("ensure_daily_missions",{p_profile_id:b.id}),await N.rpc("bump_mission",{p_profile_id:b.id,p_code:"play_5_matches",p_amount:1}
17),o&&await N.rpc("bump_mission",{p_profile_id:b.id,p_code:"win_3_matches",p_amount:1}),await N.rpc("validate_referral_for",{p_invited_id:b.id}),await N.rpc("register_spin_match",{p_won:o})}catch(y){console.warn("[Copa] reward error",y)}if(h){const{data:y}=await N.from("tournament_matches").select("team1_id, team2_id").eq("id",h).single();if(y){const{data:I}=await N.from("tournament_teams").select("id").eq("player1_id",b.id).eq("tournament_id",p),B=(C=I==null?void 0:I[0])==null?void 0:C.id;if(B){const w=y.team1_id===B,F=w?n:u,H=w?u:n,P=o?B:w?y.team2_id:y.team1_id,W=o?w?y.team2_id:y.team1_id:B;if(await N.from("tournament_matches").update({score_team1:F,score_team2:H,winner_id:P,status:"finished",played_at:new Date().toISOString()}).eq("id",h),p){const{data:de}=await N.from("tournament_matches").select("phase").eq("id",h).single(),Se=de==null?void 0:de.phase;if(Se==="league"){const{data:J}=await N.from("tournament_teams").select("group_wins, group_losses, group_points").eq("id",B).single();J&&(o?await N.from("tournament_teams").update({group_wins:J.group_wins+1,group_points:J.group_points+2}).eq("id",B):await N.from("tournament_teams").update({group_losses:J.group_losses+1,group_points:J.group_points}).eq("id",B))}else if(Se==="group"){const{data:J}=await N.from("tournament_teams").select("group_wins, group_points").eq("id",P).single();if(J&&await N.from("tournament_teams").update({group_wins:J.group_wins+1,group_points:J.group_points+2}).eq("id",P),W){const{data:Pt}=await N.from("tournament_teams").select("group_losses, group_points").eq("id",W).single();Pt&&await N.from("tournament_teams").update({group_losses:Pt.group_losses+1}).eq("id",W)}}else W&&await N.from("tournament_teams").update({status:"eliminated",eliminated:!0}).eq("id",W)}}}}}catch(k){console.error("Failed to record match:",k)}})(),lt(!0),window.dispatchEvent(new Event("truco:matchEnded")),!_){const C={isTournament:!!h,isFriendMatch:!!d&&!h};setTimeout(()=>{V(C)},1500)}},[i==null?void 0:i.gameOver,it,b,s,c,M,_,V,h,d]);const ze=l.useMemo(()=>{if(!i)return[];const a=i.phase;if(["cards-on-table","round-result","turn-result","game-over"].includes(a)){const n=i.roundPlays.reduce((u,f)=>Math.max(u,f.round),1);return i.roundPlays.filter(u=>u.round===n)}return i.roundPlays.filter(n=>n.round===i.roundNumber)},[i==null?void 0:i.phase,i==null?void 0:i.roundPlays,i==null?void 0:i.roundNumber]);if(!i||!z)return e.jsxs("div",{className:"min-h-screen bg-background flex items-center justify-center",children:[e.jsx(Ka,{className:"animate-spin text-gold",size:40}),e.jsx("span",{className:"ml-3 text-muted-foreground font-bold",children:"Carregando jogo..."})]});const te=i.variant||c,oe=he(te),fe=oe.trucoLevels,Va=fe[fe.length-1].next,_t=X&&i.turnValue<Va&&!i.maoDeOnze&&!i.maoDeFerro&&i.teamScores[S]<oe.maoDeXThreshold&&i.trucoState!=="called"&&(i.lastTrucoTeam??null)!==S,St=((Ct=fe.find(a=>a.current===i.turnValue))==null?void 0:Ct.name)||"TRUCO";if(i.gameOver){const a=i.winnerTeam===S;return e.jsxs("div",{className:"min-h-screen relative flex items-center justify-center p-4",children:[e.jsx("img",{src:L.bgImg,alt:"",className:"absolute inset-0 w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0 bg-background/70 backdrop-blur-sm"}),e.jsxs(g.div,{initial:{scale:0,rotate:-10},animate:{scale:1,rotate:0},transition:{type:"spring",damping:10},className:"relative text-center p-8 bg-card/95 backdrop-blur rounded-2xl border-2 border-primary shadow-gold w-full max-w-sm",children:[e.jsx("div",{className:"absolute top-3 left-3",children:e.jsx("span",{className:"text-[10px] font-bold px-2 py-1 rounded-full bg-secondary border border-border text-muted-foreground",children:oe.badge})}),a?e.jsx(g.div,{initial:{y:-50,opacity:0},animate:{y:0,opacity:1},transition:{delay:.3},className:"text-7xl mb-3",children:"ð"}):e.jsx(g.div,{initial:{y:-50,opacity:0},animate:{y:0,opacity:1},transition:{delay:.3},className:"text-7xl mb-3",children:"ð¢"}),e.jsx(g.h1,{initial:{y:-20},animate:{y:0},className:"font-display text-6xl text-gold text-shadow-glow mb-4",children:a?"VITÃRIA!":"DERROTA!"}),e.jsxs("div",{className:"flex justify-center gap-8 text-5xl font-display mb-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Nós"}),e.jsx("span",{className:"text-gold",children:i.teamScores[S]})]}),e.jsx("span",{className:"text-muted-foreground self-end text-3xl",children:"Ã"}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Eles"}),e.jsx("span",{className:"text-foreground",children:i.teamScores[S===0?1:0]})]})]}),He&&e.jsxs(g.div,{initial:{opacity:0,y:10}
17,animate:{opacity:1,y:0},transition:{delay:.5},className:"bg-secondary rounded-xl p-4 mb-4",children:[e.jsxs("p",{className:"text-gold font-display text-2xl",children:["+",He.xp_earned," XP"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["XP Total: ",He.total_xp]})]}),e.jsxs("div",{className:"flex gap-3 justify-center mt-6",children:[e.jsx(ie,{onClick:()=>{lt(!1),ct(null),x&&d?j(`/lobby?tab=private&code=${d}`):Ne(Ot(xe,te,i.suitRankingEnabled))},className:"bg-gold-gradient font-bold shadow-gold text-lg px-6 py-3",children:x?"Voltar ao Lobby ð":"Jogar Novamente ð"}),e.jsx(ie,{variant:"outline",onClick:()=>j(p?`/tournaments/${p}`:"/home"),className:"text-lg px-6 py-3",children:p?"Voltar ao Campeonato":"Voltar"})]})]})]})}if(i.phase==="mao-de-onze"&&i.teamScores[S]>=oe.maoDeXThreshold){const a=xe===4?Ae(2):-1,o=a>=0?i.players[a]:null;return e.jsxs("div",{className:"min-h-screen relative flex items-center justify-center p-4",children:[e.jsx("img",{src:L.bgImg,alt:"",className:"absolute inset-0 w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0 bg-background/70 backdrop-blur-sm"}),e.jsxs(g.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"relative bg-card/95 backdrop-blur rounded-2xl border-2 border-primary p-6 w-full max-w-md
17shadow-gold",children:[e.jsxs("h2",{className:"font-display text-4xl text-gold text-center mb-2",children:[oe.maoDeXLabel.toUpperCase(),"!"]}),e.jsx("p",{className:"text-center text-3xl mb-3",children:"ðï¸"}),e.jsx("p",{className:"text-sm text-muted-foreground text-center mb-4",children:o?`Vocês estão com ${oe.maoDeXThreshold}! Veja as cartas do parceiro:`:`Você está com ${oe.maoDeXThreshold}!`}),o&&e.jsxs("div",{className:"text-center mb-4",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-2",children:[o.avatar," ",o.name,":"]}),e.jsx("div",{className:"flex justify-center gap-3",children:o.hand.map(n=>e.jsx(Te,{card:n,disabled:!0,small:!0},n.id))})]}),i.vira&&e.jsxs("div",{className:"text-center mb-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"ð Vira:"}),e.jsx("div",{className:"flex justify-center",children:e.jsx(Te,{card:i.vira,disabled:!0,small:!0})})]}),e.jsxs("div",{className:"text-center mb-5",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"ð Suas cartas:"}),e.jsx("div",{className:"flex justify-center gap-3",children:z.hand.map(n=>e.jsx(Te,{card:n,disabled:!0,small:!0,isManilha:te==="mineiro"?be(n,i.vira,i.variant):i.vira?be(n,i.vira,i.variant):!1},n.id))})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(ie,{onClick:()=>Le(!0),className:"flex-1 bg-gold-gradient font-bold text-lg py-3",children:["Aceitar (vale ",oe.maoDeXAcceptedValue,") ðª"]}),e.jsx(ie,{onClick:()=>Le(!1),variant:"outline",className:"flex-1 text-lg py-3",children:"Recusar ð"})]})]})]})}const Oa=i.players[D].id,$a=i.players[Oe].id,Tt=we>=0?i.players[we].id:null,kt=_e>=0?i.players[_e].id:null;return e.jsxs("div",{className:"h-[100dvh] flex flex-col relative overflow-hidden",children:[e.jsx("img",{src:L.bgImg,alt:"",className:"absolute inset-0 w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0 bg-background/40"}),te==="mineiro"&&e.jsx(xs,{open:Ea,onClose:()=>ft(!1)}),Ce&&e.jsx(Js,{level:Ce.level,value:i.turnValue,callerName:Ce.callerName,callerAvatar:Ce.callerAvatar,isMyTeam:Ce.isMyTeam,onComplete:()=>Ye(null)}),e.jsxs("div",{className:"relative flex items-center justify-between px-2 py-1 sm:px-3 sm:py-2.5 bg-wood border-b-2 border-gold-dark/30 game-header",style:{boxShadow:"0 4px 12px rgba(0,0,0,0.5)",paddingTop:"max(0.25rem, env(safe-area-inset-top))"},children:[e.jsx("button",{onClick:()=>j(p?`/tournaments/${p}`:"/home"),className:"text-foreground/70 hover:text-foreground p-1",children:e.jsx(Os,{size:22})}),e.jsxs("div",{className:"text-center flex-1",children:[e.jsxs("div",{className:"flex items-center justify-center gap-2 sm:gap-3",children:[e.jsxs("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded-full border ${te==="mineiro"?"bg-emerald-500/20 border-emerald-500/40 text-emerald-400":"bg-blue-500/20 border-blue-500/40 text-blue-400"}`,children:[te==="mineiro"?e.jsx("img",{src:Qa,alt:"Pão de queijo",className:"w-4 h-4 inline-block mr-0.5"}):oe.emoji," ",te==="mineiro"?"MINEIRO":"PAULISTA"]}),e.jsxs("span",{className:"text-gold font-display text-base sm:text-xl tracking-wider drop-shadow-lg",children:["VALE ",i.turnValue]}),e.jsx("span",{className:"text-foreground/30",children:"|"}),e.jsxs("span",{className:"text-foreground/70 font-display text-lg tracking-wider",children:["RODADA ",i.roundNumber,"/3"]})]}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-0.5",children:[i.maoDeFerro&&e.jsx("span",{className:"text-accent text-xs animate-pulse font-bold",children:"ð¥ MÃO DE FERRO"}),i.maoDeOnze&&e.jsxs("span",{className:"text-gold text-xs font-bold",children:["ðï¸ ",oe.maoDeXLabel.toUpperCase()]}),te==="mineiro"?e.jsx("span",{className:"text-[10px] text-gold font-semibold",children:"ð§ MANILHAS FIXAS"}):i.vira&&i.manilhaValue?e.jsxs("span",{className:"text-[10px] text-foreground/50",children:["â
Manilha: ",i.manilhaValue]}):null,e.jsx("span",{className:"text-[10px] text-foreground/30",children:L.name})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[te==="mineiro"&&e.jsx("button",{onClick:()=>
17ft(!0),className:"p-1 rounded hover:bg-foreground/10 transition-colors",children:e.jsx(Ya,{size:16,className:"text-foreground/40"})}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>{const a=!G;We(a),at(a)},onContextMenu:a=>{a.preventDefault(),dt(o=>!o)},className:"p-1 rounded hover:bg-foreground/10 transition-colors",children:G?e.jsx($s,{size:18,className:"text-red-400"}):e.jsx(Lt,{size:18,className:"text-foreground/40"})}),e.jsx("button",{onClick:()=>dt(a=>!a),className:"absolute -bottom-1 left-1/2 -translate-x-1/2 text-[8px] text-foreground/30 hover:text-foreground/60",children:"â¼"}),ka&&e.jsxs("div",{className:"absolute top-full right-0 mt-2 bg-card/95 backdrop-blur-md border border-border rounded-lg p-3 shadow-xl z-50 min-w-[140px]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Lt,{size:14,className:"text-foreground/60"}),e.jsx("span",{className:"text-xs text-foreground/60",children:"Volume"})]}),e.jsx("input",{type:"range",min:"0",max:"100",value:G?0:pe*100,onChange:a=>{const o=Number(a.target.value)/100;Ta(o),ps(o),o>0&&G&&(We(!1),at(!1)),o===0&&(We(!0),at(!0))}
17,className:"w-full h-1.5 bg-foreground/20 rounded-full appearance-none cursor-pointer accent-gold"}),e.jsxs("div",{className:"flex justify-between text-[10px] text-foreground/40 mt-1",children:[e.jsx("span",{children:"ð"}),e.jsxs("span",{children:[Math.round((G?0:pe)*100),"%"]}),e.jsx("span",{children:"ð"})]})]})]})]})]}),e.jsx(Yt,{myTeamScore:i.teamScores[S],theirScore:i.teamScores[S===0?1:0],roundWinners:i.roundWinners,myTeam:S,className:"game-scoreboard"}),e.jsx("div",{className:"relative flex-1 flex items-center justify-center min-h-0",children:e.jsxs("div",{className:"relative w-[98%] max-w-[900px] lg:max-w-[1100px] game-table-area aspect-[4/3] sm:aspect-[4/3] rounded-2xl overflow-hidden",style:{boxShadow:"0 8px 40px rgba(0,0,0,0.7), inset 0 2px 8px rgba(0,0,0,0.3)",maxHeight:"calc(100% - 0.5rem)"},children:[e.jsx("img",{src:L.tableImg,alt:"",className:"absolute inset-0 w-full h-full object-cover opacity-60",style:{filter:"blur(2px) saturate(0.75)"}}),e.jsx("div",{className:`absolute inset-0 bg-gradient-to-br ${L.overlayGradient}`}),e.jsx("div",{className:"absolute inset-0 bg-black/40"}),e.jsx("div",{className:`absolute inset-0 rounded-2xl border-[4px] ${L.borderColor}`,style:{boxShadow:"inset 0 0 40px rgba(0,0,0,0.5)"}}),e.jsx(Ue,{player:i.players[Oe],position:"top",isCurrent:i.currentPlayerIndex===Oe,isTeammate:((At=i.players[Oe])==null?void 0:At.team)===S,secretSignal:Ra}),_e>=0&&e.jsx(Ue,{player:i.players[_e],position:"left",isCurrent:i.currentPlayerIndex===_e,isTeammate:((Mt=i.players[_e])==null?void 0:Mt.team)===S,secretSignal:null}),we>=0&&e.jsx(Ue,{player:i.players[we],position:"right",isCurrent:i.currentPlayerIndex===we,isTeammate:((Et=i.players[we])==null?void 0:Et.team)===S,secretSignal:null}),i.vira?e.jsxs("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[5] flex flex-col items-center gap-1",children:[e.jsxs("span",{className:`text-[10px] text-gold uppercase font-bold tracking-[0.2em] drop-shadow-lg 18 bg-background/70 px-3 py-1 rounded-full backdrop-blur-sm border border-gold/20`,children:["VIRA",te==="mineiro"?" (desempate)":""]}),e.jsx(g.div,{initial:{rotateY:180,scale:.3},animate:{rotateY:0,scale:1},transition:{type:"spring",damping:12},className:"shadow-gold rounded-xl",children:e.jsx(Te,{card:i.vira,disabled:!0,small:!0})})]}):null,e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[8]",children:e.jsxs("div",{className:"absolute inset-x-[10%] sm:inset-x-[14%] top-[22%] sm:top-[14%] bottom-[10%] sm:bottom-[14%]",children:[e.jsx("div",{className:"absolute top-0 left-1/2 -translate-x-1/2",children:e.jsx(Re,{play:ze.find(a=>a.playerId===$a),direction:{y:-40,rotate:0}})}),kt&&e.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2",children:e.jsx(Re,{play:ze.find(a=>a.playerId===kt),direction:{x:-40,rotate:-5}})}),Tt&&e.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2",children:e.jsx(Re,{play:ze.find(a=>a.playerId===Tt),direction:{x:40,rotate:5}})}),e.jsx("div",{className:"absolute bottom-0 left-1/2 -translate-x-1/2",children:e.jsx(Re,{play:ze.find(a=>a.playerId===Oa),direction:{y:40,rotate:0}})})]})}),e.jsx("div",{className:"absolute bottom-2 left-3 text-sm opacity-20 select-none",children:L.decorEmojis[0]}),e.jsx("div",{className:"absolute bottom-1.5 right-3 text-xs opacity-15 select-none",children:L.decorEmojis[1]})]})}),e.jsx(Y,{children:pt&&e.jsxs(g.div,{initial:{x:100,opacity:0},animate:{x:0,opacity:1},exit:{x:100,opacity:0},className:"absolute top-28 right-2 z-40 flex items-center gap-1",children:[e.jsxs("button",{onClick:()=>{const a=new Audio(pt);a.volume=G?0:pe,a.play().catch(()=>{})},className:`flex items-center gap-1.5 bg-card/90 backdrop-blur-md border border-primary/30 19 rounded-full px-3 py-1.5 shadow-lg hover:bg-card transition-colors`,children:[e.jsx(zt,{size:12,className:"text-primary"}),e.jsxs("span",{className:"text-[10px] font-bold text-foreground/80",children:["â¶ ",Ma]})]}),e.jsx("button",{onClick:()=>{xt(null),gt(null)},className:`w-5 h-5 rounded-full bg-muted/80 flex items-center justify-center text-muted-foreground 20 hover:bg-muted text-[10px]`,children:"â"})]})}),e.jsx(Y,{children:Z&&e.jsx(g.div,{initial:{scale:0,rotate:-5},animate:{scale:1,rotate:0},exit:{scale:0,opacity:0}
20,className:`absolute top-[38%] left-1/2 -translate-x-1/2 -translate-y-1/2 z-50 21 bg-card/95 backdrop-blur-md border-2 border-primary rounded-2xl px-8 py-5 shadow-gold`,children:e.jsx("p",{className:"font-display text-2xl text-gold text-center",children:Z})})}),i.phase==="truco-called"&&i.trucoCallerTeam!==S&&e.jsxs(g.div,{initial:{y:100,scale:.9},animate:{y:0,scale:1},className:`absolute bottom-40 left-3 right-3 bg-card/95 backdrop-blur-md border-2 border-accent 22 rounded-2xl p-5 z-40 shadow-2xl`,children:[e.jsxs(g.p,{animate:{scale:[1,1.05,1]},transition:{repeat:1/0,duration:1},className:"text-center font-display text-3xl text-accent mb-2",children:[St,"!!! ð¥"]}),e.jsxs("p",{className:"text-center text-sm text-muted-foreground mb-3",children:["Aceitar = vale ",((Rt=fe.find(a=>a.current===i.turnValue))==null?void 0:Rt.next)||i.turnValue," | Correr = -",i.turnValue," pt"]}),e.jsx(Y,{children:re&&s==="2v2"&&e.jsxs(g.div,{initial:{opacity:0,y:10,scale:.8},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.8},className:"flex items-center gap-2 mb-3 px-3 py-2 rounded-xl bg-muted/60 border border-border/50",children:[e.jsx("span",{className:"text-lg",children:re.playerAvatar}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("span",{className:"text-xs font-bold text-muted-foreground",children:[re.playerName," opina:"]}),e.jsx(g.p,{animate:{scale:[1,1.03,1]},transition:{repeat:1/0,duration:1.5},className:`text-sm font-bold ${re.opinion==="accept"||re.opinion==="raise"?"text-primary":"text-destructive"}`,children:re.opinionText})]}),e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"Você decide!"})]})}),e.jsx("p",{className:"text-center text-xs text-muted-foreground mb-2 font-semibold",children:"ð¯ Você tem a decisão final!"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(ie,{onClick:()=>{ne(null),$e(!0)},className:"flex-1 bg-gold-gradient font-bold text-lg py-3 shadow-gold",children:"Aceitar! â "}),e.jsx(ie,{onClick:()=>{ne(null),$e(!1)},variant:"outline",className:"flex-1 text-lg py-3",children:"Correr ð"}),(()=>{const a=fe.find(f=>f.current===i.turnValue),o=a?a.next:i.turnValue,n=fe.find(f=>f.current===o),u=fe[fe.length-1].next;return n&&o<u?e.jsxs(ie,{onClick:()=>{ne(null),Nt(S,z.name,z.avatar,!0)},className:"flex-1 bg-accent text-accent-foreground font-bold text-lg py-3",children:["Pedir ",n.name,"! ð¥"]}):null})()]})]}),e.jsx(Y,{children:i.phase==="truco-called"&&i.trucoCallerTeam===S&&re&&e.jsxs(g.div,{initial:{opacity:0,y:-20,scale:.8},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.8},className:`absolute top-24 left-1/2 -translate-x-1/2 z-40 23 flex items-center gap-2 px-4 py-2 rounded-full bg-card/90 backdrop-blur-md border border-border shadow-lg`,children:[e.jsx("span",{className:"text-lg",children:re.playerAvatar}),e.jsxs("span",{className:"text-xs font-bold text-foreground",children:[re.playerName,":"]}),e.jsx(g.span,{animate:{scale:[1,1.05,1]},transition:{repeat:1/0,duration:1},className:"text-sm font-bold text-accent",children:re.opinionText})]})}),e.jsx(Y,{children:(i.phase==="round-result"||i.phase==="turn-result")&&e.jsx(g.div,{initial:{opacity:0,scale:.7,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,y:-30},className:`absolute top-[35%] left-1/2 -translate-x-1/2 z-40 24 bg-card/95 backdrop-blur-md border-2 border-border rounded-2xl px-6 py-4 shadow-2xl`,children:e.jsx("p",{className:"text-lg font-bold text-foreground text-center",children:i.phase==="turn-result"?`${i.winnerTeam===S?"ð Nós ganhamos":"ð¢ Eles ganharam"}! +${i.turnValue} pt`:`Rodada ${i.roundNumber-1}: ${i.roundWinners[i.roundWinners.length-1]===S?"â Nós!":i.roundWinners[i.roundWinners.length-1]===-1?"ð¤ Empate!":"â Eles!"}`})})}),e.jsxs("div",{className:"relative bg-wood border-t-2 border-gold-dark/30 px-2 sm:px-3 py-1.5 sm:py-3 game-action-bar",style:{boxShadow:"0 -4px 16px rgba(0,0,0,0.5)",paddingBottom:"calc(max(0.375rem, env(safe-area-inset-bottom)) + 0.125rem)"},children:[e.jsxs("div",{className:"flex justify-center items-center gap-2 sm:gap-3 mb-2 sm:mb-3",children:[X&&e.jsxs(g.div,{animate:Q<=5?{scale:[1,1.1,1]}:{},transition:{repeat:1/0,duration:.5},className:`flex items-center gap-1.5 rounded-full px-3 py-1.5 ${Q<=5?"bg-accent/20 border border-accent/40":"bg-background/30"}`,children:[e.jsx(Ls,{size:14,className:Q<=5?"text-accent":"text-muted-foreground"}),e.jsx("span",{className:`font-display text-xl w-6 text-center ${Q<=5?"text-accent":Q<=10?"text-gold":"text-foreground"}`,children:Q})]}),e.jsx(g.div,{whileHover:{scale:1.05},whileTap:{scale:.95},children:e.jsxs(ie,{size:"lg",onClick:Da,disabled:!_t,className:`font-display text-base sm:text-xl tracking-wider px-5 sm:px-8 py-2 sm:py-3 h-auto rounded-xl 25 ${_t?"bg-gradient-to-r from-red-600 via-red-500 to-orange-500 text-white shadow-[0_0_20px_rgba(239,68,68,0.4)] hover:shadow-[0_0_30px_rgba(239,68,68,0.6)]":"bg-muted text-muted-foreground"} transition-all duration-200`,children:[St.toUpperCase(),"! ð"]})}
25),X&&i.roundNumber>=2&&i.phase==="playing"&&!i.gameOver&&e.jsxs(Nr,{children:[e.jsx(wr,{asChild:!0,children:e.jsx(g.div,{whileHover:{scale:1.05},whileTap:{scale:.95},children:e.jsx(ie,{size:"sm",variant:"outline",className:"border-destructive/40 text-destructive hover:bg-destructive/10 rounded-xl px-3 sm:px-4 py-2 h-auto text-xs sm:text-sm font-bold",children:"ð³ï¸ Desistir"})})}),e.jsxs(ba,{className:"bg-background/95 backdrop-blur-md border-destructive/30",children:[e.jsxs(ya,{children:[e.jsx(ja,{children:"Desistir da rodada?"}),e.jsxs(Na,{children:["Você perderá ",i.turnValue," ponto",i.turnValue>1?"s":""," para o adversário. Tem certeza?"]})]}),e.jsxs(va,{children:[e.jsx(_a,{children:"Cancelar"}),e.jsx(wa,{onClick:Pa,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Sim, desistir"})]})]})]}),e.jsx(ie,{size:"sm",variant:"outline",onClick:()=>se(!le),className:"border-gold/30 rounded-full w-10 h-10 p-0",children:e.jsx(zs,{size:16})}),xe===4&&e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[9px] text-muted-foreground/50 mr-0.5",children:"ð¤«"}),Object.keys(qe).map(a=>e.jsx("button",{onClick:()=>Ia(a),className:`text-base w-8 h-8 rounded-full bg-card/30 hover:bg-card/60 border border-primary/20 hover:border-primary/50 26 flex items-center justify-center transition-all hover:scale-110 active:scale-95`,title:`${qe[a]} = ${rt[a]} (só seu parceiro vê)`,children:tt[a]},a))]})]}),e.jsx("div",{className:"flex justify-end gap-1.5 sm:gap-5 md:gap-8 lg:gap-10 pb-1 pr-1 sm:pr-12 md:pr-20 lg:pr-28 game-hand-cards",children:(()=>{const a=i.maoDeFerro===!0,o=i.roundNumber>1&&!a;return e.jsxs(e.Fragment,{children:[z.hand.map(n=>{const u=te==="mineiro"?be(n,i.vira,i.variant):i.vira?be(n,i.vira,i.variant):!1,f=()=>{if(!X)return;Ge(n,o&&Xe),ut(!1)};return e.jsxs(g.div,{className:"relative",initial:{y:60,opacity:0},animate:{y:0,opacity:1},transition:{type:"spring",damping:15},children:[e.jsx(Te,{card:n,onClick:f,disabled:!X,faceDown:a,isManilha:u}),u&&e.jsx("span",{className:`absolute -top-2 -right-2 text-xs bg-gold text-primary-foreground 27 rounded-full w-5 h-5 flex items-center justify-center font-bold shadow-gold z-10`,children:"â "})]},n.id)}),o&&X&&e.jsxs(g.button,{initial:{scale:0},animate:{scale:1},onClick:()=>ut(n=>!n),className:`self-center ml-1 px-2 py-2 rounded-xl text-[10px] sm:text-xs font-bold transition-all shadow-lg flex flex-col items-center gap-0.5 28 ${Xe?"bg-accent text-white ring-2 ring-accent/60 shadow-accent/30":"bg-card/80 text-muted-foreground hover:bg-card border border-border"}`,children:[e.jsx("span",{className:"text-base",children:"ð"}),e.jsx("span",{children:Xe?"Esconder ON":"Esconder"})]})]})})()}),e.jsx("div",{className:"text-center mt-1",children:e.jsx(g.span,{animate:X?{scale:[1,1.05,1]}:{},transition:{repeat:1/0,duration:1.5},className:`text-xs font-bold px-4 py-1 rounded-full inline-block ${X?"bg-primary/80 text-primary-foreground shadow-gold":"bg-background/30 text-foreground/50"}`,children:X?"ð Sua vez!":ot?"ð¤ Pensando...":"â³ Aguardando..."})})]}),e.jsx(Y,{children:le&&e.jsxs(g.div,{initial:{y:100,opacity:0},animate:{y:0,opacity:1},exit:{y:100,opacity:0},className:`absolute bottom-36 left-3 right-3 bg-card/95 backdrop-blur-md border border-border 29 rounded-2xl p-3 z-30 shadow-2xl max-h-[60vh] overflow-y-auto`,children:[e.jsx("button",{onClick:()=>se(!1),className:`absolute top-2 right-2 text-muted-foreground hover:text-foreground text-lg w-7 h-7 30 flex items-center justify-center rounded-full hover:bg-muted transition-colors`,children:"â"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2 font-bold uppercase tracking-wider",children:"Frases rápidas"}),e.jsx("div",{className:"grid grid-cols-2 gap-2 mb-3",children:_s.map(a=>e.jsx("button",{onClick:()=>{U(a),se(!1),x&&R(o=>({...o,lastChatMessage:{playerId:o.players[D].id,message:a,timestamp:Date.now()}}))},className:`text-sm bg-secondary/80 rounded-xl px-3 py-2 text-secondary-foreground 31 hover:bg-muted transition-all hover:scale-[1.02] active:scale-95`,children:a},a))}),e.jsxs("div",{className:"border-t border-border/50 pt-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1.5 font-bold uppercase tracking-wider",children:"Enviar mensagem"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:ve,onChange:a=>Je(a.target.value.slice(0,30)),onKeyDown:a=>{if(a.key==="Enter"&&ve.trim()){const o=ve.trim();U(o),Je(""),se(!1),x&&R(n=>({...n,lastChatMessage:{playerId:n.players[D].id,message:o,timestamp:Date.now()}}))}},placeholder:"Digite... (max 30)",maxLength:30,className:`flex-1 h-9 rounded-lg border border-border/50 bg-background/50 px-3 text-sm 32 text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),e.jsx("button",{onClick:()=>
32{if(!ve.trim())return;const a=ve.trim();U(a),Je(""),se(!1),x&&R(o=>({...o,lastChatMessage:{playerId:o.players[D].id,message:a,timestamp:Date.now()}}))},disabled:!ve.trim(),className:`h-9 w-9 rounded-lg bg-primary flex items-center justify-center 33 hover:bg-primary/80 transition-colors disabled:opacity-40`,children:e.jsx(qs,{size:14,className:"text-primary-foreground"})})]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground/60 mt-1 text-right",children:[ve.length,"/30"]})]}),e.jsxs("div",{className:"border-t border-border/50 pt-3 mt-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1.5 font-bold uppercase tracking-wider",children:"Mensagem de voz"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onPointerDown:async()=>{try{const a=await navigator.mediaDevices.getUserMedia({audio:!0}),o=new MediaRecorder(a);Qe.current=[],o.ondataavailable=n=>{n.data.size>0&&Qe.current.push(n.data)},o.onstop=async()=>{a.getTracks().forEach(y=>y.stop());const n=new Blob(Qe.current,{type:"audio/webm"}),u=URL.createObjectURL(n);Ca(u);const f=`${(b==null?void 0:b.id)||"anon"}/${Date.now()}.webm`,{data:v,error:T}=await N.storage.from("voice-messages").upload(f,n,{contentType:"audio/webm",upsert:!1});if(T){console.error("Upload error:",T),U("ð¤ Erro ao enviar áudio â",2e3);return}const{data:C}=await N.storage.from("voice-messages").createSignedUrl(v.path,60*60*6),k=(C==null?void 0:C.signedUrl)||u;U("ð¤ Mensagem de voz!",2e3),R(y=>({...y,lastChatMessage:{playerId:y.players[D].id,message:"ð¤ Ãudio",timestamp:Date.now(),audioUrl:k}}));const O=new Audio(u);O.volume=G?0:pe,O.play().catch(()=>{}),Aa.current=O},o.start(),je.current=o,De(!0),setTimeout(()=>{var n;((n=je.current)==null?void 0:n.state)==="recording"&&(je.current.stop(),De(!1))},1e4)}catch{U("Microfone não disponÃvel â")}},onPointerUp:()=>{var a;((a=je.current)==null?void 0:a.state)==="recording"&&(je.current.stop(),De(!1))},onPointerLeave:()=>{var a;((a=je.current)==null?void 0:a.state)==="recording"&&(je.current.stop(),De(!1))},className:`flex items-center gap-2 rounded-xl px-4 py-2.5 font-bold text-sm transition-all select-none ${Ke?"bg-accent text-accent-foreground animate-pulse shadow-lg":"bg-secondary hover:bg-muted text-secondary-foreground"}`,children:Ke?e.jsxs(e.Fragment,{children:[e.jsx(Xs,{size:14,className:"fill-current"}),"Gravando... solte"]}):e.jsxs(e.Fragment,{children:[e.jsx(zt,{size:14}),"Segurar p/ gravar"]})}),mt&&!Ke&&e.jsx("button",{onClick:()=>{const a=new Audio(mt);a.volume=G?0:pe,a.play().catch(()=>{})},className:`text-xs bg-background/50 rounded-lg px-3 py-2 hover:bg-background/80 34 text-foreground/70 transition-colors`,children:"â¶ Ouvir"})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground/60 mt-1",children:"Segure para gravar (máx 10s)"})]})]})})]})};function Er({emoteKey:r,senderName:s}){const d=Qt(r);return e.jsx(Y,{children:d&&e.jsxs(g.div,{initial:{opacity:0,scale:.6,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.8,y:-10},transition:{type:"spring",stiffness:300,damping:18},className:`inline-flex items-center gap-2 px-4 py-2 rounded-2xl shadow-2xl bg-gradient-to-r ${d.color} text-white font-bold border-2 border-white/40`,children:[e.jsx("span",{className:"text-2xl",children:d.emoji}),e.jsx("span",{className:"text-sm",children:d.phrase}),s&&e.jsxs("span",{className:"text-[10px] font-medium opacity-80 ml-1",children:["â ",s]})]})})}function Rr({roomId:r}){var V;const{profile:s}=Be(),{getSlotEmote:d}=gs(),[c,m]=l.useState([]),[h,p]=l.useState(null),j=l.useRef(0),b=l.useRef(null);l.useEffect(()=>{const x=$=>{const E=$.detail,A=E==null?void 0:E.emoteSlot;A&&setTimeout(()=>{const K=d(A);p({slot:A,key:(K==null?void 0:K.asset_key)??null,id:`${Date.now()}`}),setTimeout(()=>p(null),2200)},250)};return window.addEventListener("shop:changed",x),()=>window.removeEventListener("shop:changed",x)},[d]);const M=l.useCallback((x,$)=>{const E=`${Date.now()}-${Math.random().toString(36).slice(2,6)}`;m(A=>[...A.slice(-2),{id:E,key:x,sender:$}]),setTimeout(()=>m(A=>A.filter(K=>K.id!==E)),2500)},[]);l.useEffect(()=>{if(!r)return;const x=N.channel(`emotes:${r}`,{config:{broadcast:{self:!1}}});return x.on("broadcast",{event:"emote"},$=>{const{key:E,sender:A}=$.payload;E&&M(E,A||"Jogador")}).subscribe(),b.current=x,()=>{N.removeChannel(x),b.current=null}},[r,M]);const _=l.useCallback(x=>{var A;const $=Date.now();if($-j.current<1200)return;j.current=$;const E=(s==null?void 0:s.display_name)||"Você";M(x,"Você"),(A=b.current)==null||A.send({type:"broadcast",event:"emote",payload:{key:x,sender:E}})},[s==null?void 0:s.display_name,M]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"pointer-events-none fixed top-24 left-1/2 -translate-x-1/2 z-40 flex flex-col items-center gap-2",children:e.jsx(Y,{children:c.map(x=>e.jsx(g.div,{initial:{opacity:0,y:20,scale:.8}
34,animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-30,scale:.9},children:e.jsx(Er,{emoteKey:x.key,senderName:x.sender})},x.id))})}),e.jsx(Y,{children:h&&e.jsx(g.div,{initial:{opacity:0,y:30,scale:.85},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.9},className:"pointer-events-none fixed bottom-44 left-4 z-50",children:e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-gradient-to-r from-amber-500/95 to-yellow-400/95 text-black shadow-2xl border-2 border-yellow-200",children:[e.jsx("span",{className:"text-2xl",children:h.key?((V=Qt(h.key))==null?void 0:V.emoji)??"ð":"âï¸"}),e.jsxs("div",{className:"text-xs font-bold leading-tight",children:[e.jsxs("div",{children:["Slot ",h.slot]}),e.jsx("div",{className:"text-[10px] opacity-80",children:h.key?"equipado!":"esvaziado"})]})]})},h.id)}),e.jsx("div",{className:"fixed bottom-24 left-4 z-40",children:e.jsx("div",{className:"bg-black/70 backdrop-blur border border-gold/40 rounded-full shadow-xl",children:e.jsx(fs,{onSelect:_})})})]})}const Pr={bronze:{ring:"0 0 32px rgba(245,158,11,0.55)",badge:"from-amber-700 to-amber-400",label:"ð¥ VIP"},gold:{ring:"0 0 40px rgba(250,204,21,0.7)",badge:"from-yellow-500 to-yellow-300",label:"ð¥ VIP"},diamond:{ring:"0 0 45px rgba(34,211,238,0.75)",badge:"from-cyan-400 to-blue-500",label:"ð VIP"}},Dr=["â ","â¥","â¦","â£"];function Ir(){return e.jsx("div",{className:"absolute inset-0 pointer-events-none overflow-hidden",children:Array.from({length:8}).map((r,s)=>{const d=Dr[s%4],c=d==="â¥"||d==="â¦";return e.jsx(g.div,{className:`absolute text-2xl font-bold ${c?"text-red-400/30":"text-white/20"}`,initial:{x:Math.random()>.5?-100:window.innerWidth+100,y:Math.random()*window.innerHeight,rotate:Math.random()*360,opacity:0},animate:{x:window.innerWidth/2+(Math.random()-.5)*300,y:window.innerHeight/2+(Math.random()-.5)*200,rotate:Math.random()*720-360,opacity:[0,.4,.2]},transition:{duration:1.5,delay:s*.12,ease:"easeOut"},children:d},s)})})}function nt({player:r,delay:s,small:d=!1}){const c=r.vipPlan&&r.vipPlan!=="none"?Pr[r.vipPlan]:null;return e.jsxs(g.div,{className:"flex flex-col items-center gap-1.5",initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},transition:{delay:s,type:"spring",stiffness:100},children:[c&&e.jsx(g.div,{className:"text-2xl -mb-1",initial:{y:-8,opacity:0,rotate:-15},animate:{y:0,opacity:1,rotate:0},transition:{delay:s+.2,type:"spring"},children:"ð"}),e.jsx(g.div,{className:`${d?"w-14 h-14 text-2xl":"w-20 h-20 sm:w-24 sm:h-24 text-4xl sm:text-5xl"} rounded-full border-2 flex items-center justify-center shadow-lg`,style:{background:"linear-gradient(135deg, hsl(var(--gold) / 0.2), hsl(var(--gold) / 0.05))",borderColor:c?"rgba(250,204,21,0.9)":"hsl(var(--gold) / 0.6)",boxShadow:c?c.ring:"0 0 25px hsl(var(--gold) / 0.2)"},animate:{boxShadow:c?[c.ring,c.ring.replace("0.55","0.9").replace("0.7","1").replace("0.75","1"),c.ring]:["0 0 15px hsl(var(--gold) / 0.2)","0 0 35px hsl(var(--gold) / 0.4)","0 0 15px hsl(var(--gold) / 0.2)"]},transition:{duration:2,repeat:1/0},children:r.avatar}),e.jsx("p",{className:`${d?"text-sm":"text-base sm:text-lg"} font-bold text-white truncate max-w-[120px]`,children:r.name}),c?e.jsx("div",{className:`px-2 py-0.5 rounded-full text-[10px] font-bold bg-gradient-to-r ${c.badge} text-black shadow-lg`,children:c.label}):e.jsxs("div",{className:"px-2 py-0.5 rounded-full text-[10px] font-semibold",style:{background:"linear-gradient(135deg, hsl(var(--gold) / 0.3), hsl(var(--gold) / 0.1))",color:"hsl(var(--gold))",border:"1px solid hsl(var(--gold) / 0.3)"},children:["NÃvel ",r.level]})]})}function Ft({players:r,side:s,baseDelay:d}){const c=s==="left";return e.jsx(g.div,{className:"flex flex-col items-center gap-4 z-10",initial:{x:c?-200:200,opacity:0},animate:{x:0,opacity:1},transition:{duration:.6,delay:d,type:"spring",stiffness:80},children:r.length===1?e.jsx(nt,{player:r[0],delay:d+.1}):e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(nt,{player:r[0],delay:d+.1}),e.jsx(g.div,{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"hsl(var(--gold) / 0.5)"},initial:{opacity:0}
34,animate:{opacity:1},transition:{delay:d+.4},children:"&"}),e.jsx(nt,{player:r[1],delay:d+.3,small:!0})]})})}function Vr({team1:r,team2:s,variant:d,mode:c,onComplete:m}){const[h,p]=l.useState(!1);l.useEffect(()=>{const M=setTimeout(()=>p(!0),2500),_=setTimeout(m,3200);return()=>{clearTimeout(M),clearTimeout(_)}},[m]);const j=d==="mineiro"?"Truco Mineiro":"Truco Paulista",b=c==="1v1"?"1 vs 1":"2 vs 2";return e.jsxs(g.div,{className:"fixed inset-0 z-50 flex items-center justify-center",initial:{opacity:0},animate:{opacity:h?0:1},transition:{duration:h?.7:.4},children:[e.jsxs("div",{className:"absolute inset-0 bg-[#050f0b]",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_center,_#0f2c23_0%,_#071a14_50%,_#050f0b_100%)]"}),e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_50%_50%,_hsl(var(--gold)/0.08)_0%,_transparent_60%)]"})]}),e.jsx(Ir,{}),e.jsxs("div",{className:"relative flex flex-col items-center gap-5 sm:gap-7 px-4 w-full max-w-xl",children:[e.jsxs("div",{className:"flex items-center justify-center gap-6 sm:gap-10 w-full",children:[e.jsx(Ft,{players:r,side:"left",baseDelay:.2}),e.jsx(g.div,{className:"relative z-10 flex items-center justify-center",initial:{scale:0,rotate:-180},animate:{scale:1,rotate:0},transition:{delay:.6,type:"spring",stiffness:120,damping:10},children:e.jsx(g.span,{className:"text-5xl sm:text-7xl font-black italic tracking-tighter select-none",style:{background:"linear-gradient(180deg, hsl(var(--gold)), #e8d282, hsl(var(--gold)))",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",filter:"drop-shadow(0 0 20px hsl(var(--gold) / 0.5))"},animate:{filter:["drop-shadow(0 0 15px hsl(var(--gold) / 0.4))","drop-shadow(0 0 35px hsl(var(--gold) / 0.8))","drop-shadow(0 0 15px hsl(var(--gold) / 0.4))"]},transition:{duration:1.5,repeat:1/0},children:"VS"})}),e.jsx(Ft,{players:s,side:"right",baseDelay:.4})]}),e.jsx(g.div,{className:"w-full h-px max-w-xs",style:{background:"linear-gradient(90deg, transparent, hsl(var(--gold) / 0.4), transparent)"},initial:{scaleX:0},animate:{scaleX:1},transition:{delay:1,duration:.6}}),e.jsxs(g.div,{className:"flex flex-col items-center gap-2",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:1.2},children:[e.jsx("span",{className:"text-sm font-semibold tracking-widest uppercase",style:{color:"hsl(var(--gold) / 0.8)"},children:j}),e.jsx("span",{className:"text-xs text-white/50 font-medium",children:b})]}),e.jsx(g.div,{className:"w-48 h-1 rounded-full overflow-hidden mt-1",style:{background:"hsl(var(--gold) / 0.15)"},initial:{opacity:0}
34,animate:{opacity:1},transition:{delay:1.4},children:e.jsx(g.div,{className:"h-full rounded-full",style:{background:"linear-gradient(90deg, hsl(var(--gold)), #e8d282)"},initial:{width:"0%"},animate:{width:"100%"},transition:{delay:1.4,duration:1.6,ease:"easeInOut"}})})]})]})}const pn=()=>{const[r]=Za(),{profile:s}=Be(),d=(s==null?void 0:s.is_guest)===!0;l.useEffect(()=>{d&&Fs()},[d]);const{open:c,dismiss:m}=Us(d,"game"),h=r.get("difficulty")||"medium",p=r.get("mode")||"2v2",j=r.get("lobby")||null,b=r.get("variant")||"paulista",M=r.get("suitRanking")!=="false",_=r.get("quickmatch")==="true",V=r.get("tournamentMatchId")||null,x=r.get("tournamentId")||null,$=r.get("opName"),E=r.get("opAvatar"),[A,K]=l.useState(!!_&&!!$),Ne=l.useCallback(()=>K(!1),[]),i=Math.floor(((s==null?void 0:s.xp)??0)/100)+1,{team1:D,team2:L}=l.useMemo(()=>{const q={name:(s==null?void 0:s.display_name)||"Você",avatar:(s==null?void 0:s.avatar)||"ð",level:i,vipPlan:(s==null?void 0:s.vip_plan)||"none"},Z={name:$?decodeURIComponent($):"Oponente",avatar:E?decodeURIComponent(E):"ð¤ ",level:Math.max(1,i+Math.floor(Math.random()*5)-2)};if(p==="2v2"){const ae=r.get("partnerName"),le=r.get("partnerAvatar"),se=r.get("op2Name"),Q=r.get("op2Avatar"),me={name:ae?decodeURIComponent(ae):"Parceiro",avatar:le?decodeURIComponent(le):"ð§",level:Math.max(1,i+Math.floor(Math.random()*5)-2)},ce={name:se?decodeURIComponent(se):"Oponente2",avatar:Q?decodeURIComponent(Q):"ð",level:Math.max(1,i+Math.floor(Math.random()*5)-2)};return{team1:[q,me],team2:[Z,ce]}}return{team1:[q],team2:[Z]}},[]);return l.useEffect(()=>{Hs({url:`/game?${r.toString()}`,mode:p,variant:b});const q=()=>Ws();return window.addEventListener("truco:matchEnded",q),()=>window.removeEventListener("truco:matchEnded",q)},[]),l.useEffect(()=>{if(!s)return;const q=[...D,...L],Z=q.map(me=>me.name),ae=q.map(me=>me.avatar);(async()=>{await N.from("active_sessions").delete().eq("profile_id",s.id),await N.rpc("cleanup_stale_sessions"),await N.from("active_sessions").insert({profile_id:s.id,mode:p,variant:b,lobby_id:j,is_quick_match:_,player_names:Z,player_avatars:ae})})();const se=setInterval(()=>{N.from("active_sessions").update({last_heartbeat:new Date().toISOString()}).eq("profile_id",s.id).then(()=>{})},6e4),Q=()=>{N.from("active_sessions").delete().eq("profile_id",s.id).then(()=>{})};return window.addEventListener("truco:matchEnded",Q),()=>{clearInterval(se),window.removeEventListener("truco:matchEnded",Q)}},[s==null?void 0:s.id]),e.jsxs(e.Fragment,{children:[e.jsx(Bs,{open:c,onClose:m}),A&&e.jsx(Vr,{team1:D,team2:L,variant:b,mode:p,onComplete:Ne}),!A&&e.jsxs(e.Fragment,{children:[e.jsx(Mr,{difficulty:h,mode:p,lobbyId:j,variant:b,suitRanking:M,tournamentMatchId:V,tournamentId:x}),e.jsx(Rr,{roomId:j})]})]})};export{pn 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.