1import{K as e,W as t,o as n}from"./useStore-JOSBexNl.js";import{t as r}from"./useQuery-BRqajixk.js";import{n as i,t as a,v as o}from"./index-Du5O_n-Q.js";import{n as s}from"./trophy-Cs_zUT8W.js";import{n as c}from"./users-B8Rua6_7.js";import{t as l}from"./crown--byMI-Ni.js";import{t as u}from"./loader-circle-ODfrt732.js";import{t as d}from"./lock-C3rqQCjA.js";import{t as f}from"./app-shell-BfJCDRWc.js";import{n as p,t as m}from"./match-status-CAVz-06-.js";var h=s(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),g=e(t()),_=n();function v(){let e=i(),{data:t,isLoading:n}=r({queryKey:[`matches`],queryFn:async()=>{let{data:e,error:t}=await o.from(`matches`).select(`*`).order(`kickoff`,{ascending:!0});if(t)throw t;return e}}),{data:a}=r({queryKey:[`my-predictions`],queryFn:async()=>{let{data:e}=await o.auth.getUser(),t=e.user?.id;if(!t)return[];let{data:n,error:r}=await o.from(`predictions`).select(`match_id, pred_a, pred_b, points`).eq(`user_id`,t);if(r)throw r;return n}}),{data:s}=r({queryKey:[`rodada-winners`],queryFn:async()=>{let{data:e,error:t}=await o.from(`rodada_winners`).select(`fase_ordem, fase, completed, display_name, points`);if(t)throw t;return e}}),d=(0,g.useMemo)(()=>{let e={};return(a??[]).forEach(t=>e[t.match_id]=t),e},[a]),p=(0,g.useMemo)(()=>{let e={};return(s??[]).forEach(t=>{(e[t.fase_ordem]??=[]).push(t)}),e},[s]),h=(0,g.useMemo)(()=>{let e=new Map;return(t??[]).forEach(t=>{let n=t.fase_ordem??0;e.has(n)||e.set(n,{ordem:n,fase:t.fase??`Rodada`,jogos:[]}),e.get(n).jogos.push(t)}),[...e.values()].sort((e,t)=>e.ordem-t.ordem)},[t]),v=(0,g.useMemo)(()=>{for(let e of h)if(!e.jogos.every(e=>e.status===`finished`))return e.ordem;return h.length?h[h.length-1].ordem:0},[h]);return n?(0,_.jsx)(f,{children:(0,_.jsx)(`div`,{className:`flex justify-center py-20`,children:(0,_.jsx)(u,{className:`h-6 w-6 animate-spin text-primary`})})}):(0,_.jsxs)(f,{children:[(0,_.jsxs)(`div`,{className:`mb-8`,children:[(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-2 rounded-full border border-primary/40 bg-primary/10 px-4 py-1.5 text-xs font-semibold uppercase tracking-widest text-primary`,children:[(0,_.jsx)(c,{className:`h-3.5 w-3.5`}),` Faça seu palpite`]}),(0,_.jsxs)(`h1`,{className:`mt-3 font-display text-3xl font-bold tracking-tight`,children:[`Jogos da `,(0,_.jsx)(`span`,{className:`text-gradient`,children:`Copa`})]}),(0,_.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`Palpite em qualquer jogo até 10 minutos antes do inÃcio. Placar exato vale 20 pontos, acertar o vencedor vale 10.`}),(0,_.jsx)(`div`,{className:`mt-3`,children:(0,_.jsx)(m,{})})]}),(!t||t.length===0)&&(0,_.jsx)(`div`,{className:`rounded-2xl border border-border bg-card p-8 text-center text-muted-foreground`,children:`Nenhum jogo cadastrado ainda. Em breve os jogos da Copa aparecerão aqui.`}),(0,_.jsx)(`div`,{className:`space-y-10`,children:h.map(t=>{let n=t.ordem===v,r=(p[t.ordem]??[]).filter(e=>e.completed&&e.display_name),i=t.jogos.every(e=>e.status===`finished`);return t.jogos.filter(e=>d[e.id]).length,(0,_.jsxs)(`section`,{children:[(0,_.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center justify-between gap-3 border-b border-border pb-3`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(`h2`,{className:`font-display text-xl font-bold tracking-tight`,children:t.fase}),n&&(0,_.jsx)(`span`,{className:`rounded-full border border-primary/40 bg-primary/10 px-2.5 py-0.5 text-[11px] font-semibold uppercase tracking-wider text-primary`,children:`Rodada atual`}),!1]}),i&&r.length>0&&(0,_.jsxs)(`div`,{className:`flex items-center gap-2 rounded-full border border-primary/40 bg-primary/10 px-3 py-1 text-sm font-semibold text-primary`,children:[(0,_.jsx)(l,{className:`h-4 w-4`}),`Vencedor: `,r.map(e=>e.display_name).join(`, `),(0,_.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,r[0].points,` pts`]})]})]}),(0,_.jsx)(`div`,{className:`grid gap-5 md:grid-cols-2`,children:t.jogos.map(t=>(0,_.jsx)(b,{match:t,prediction:d[t.id],onSaved:()=>{e.invalidateQueries({queryKey:[`my-predictions`]}
1),e.invalidateQueries({queryKey:[`rodada-winners`]})}},t.id))})]},t.ordem)})})]})}function y({flag:e,alt:t}){return e&&/^https?:\/\//.test(e)?(0,_.jsx)(`img`,{src:e,alt:t,loading:`lazy`,className:`h-9 w-9 rounded-full object-contain`}):(0,_.jsx)(`span`,{className:`text-3xl`,children:e??`ð³ï¸`})}function b({match:e,prediction:t,onSaved:n}){let[r,i]=(0,g.useState)(t?String(t.pred_a):``),[s,l]=(0,g.useState)(t?String(t.pred_b):``),[f,m]=(0,g.useState)(!1);(0,g.useEffect)(()=>{t&&(i(String(t.pred_a)),l(String(t.pred_b)))},[t]);let v=new Date(e.kickoff).getTime()-600*1e3<=Date.now()||e.status!==`scheduled`,b=e.status===`finished`&&e.score_a!=null,x=e.status===`live`&&e.score_a!=null;async function S(){if(r===``||s===``){a.error(`Preencha o placar dos dois times.`);return}m(!0);let{data:t}=await o.auth.getUser(),i=t.user?.id;if(!i){a.error(`Sessão expirada, entre novamente.`),m(!1);return}let{error:c}=await o.from(`predictions`).upsert({user_id:i,match_id:e.id,pred_a:Number(r),pred_b:Number(s)},{onConflict:`user_id,match_id`});if(m(!1),c){a.error(c.message.includes(`bloqueados`)?`O jogo já começou â palpites encerrados.`:c.message);return}a.success(`Palpite salvo! â½`),n()}let C=new Date(e.kickoff),w=C.toLocaleDateString(`pt-BR`,{day:`2-digit`,month:`2-digit`}),T=C.toLocaleTimeString(`pt-BR`,{hour:`2-digit`,minute:`2-digit`});return(0,_.jsxs)(`div`,{className:`rounded-2xl border border-border bg-card p-6`,style:{boxShadow:`var(--shadow-card)`},children:[(0,_.jsxs)(`div`,{className:`mb-4 flex items-center justify-between text-xs font-semibold uppercase tracking-widest text-muted-foreground`,children:[(0,_.jsx)(`span`,{className:`rounded-full border border-primary/30 bg-primary/10 px-2.5 py-1 text-primary`,children:e.grupo??`Copa`}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(p,{status:e.status}),(0,_.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,_.jsx)(c,{className:`h-3.5 w-3.5`}),` `,w,` · `,T]})]})]}),x&&(0,_.jsxs)(`div`,{className:`mb-4 flex items-center justify-center gap-2 rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-center text-sm font-bold text-red-500`,children:[`Placar ao vivo: `,e.score_a,` x `,e.score_b]}),(0,_.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,_.jsxs)(`div`,{className:`flex flex-1 flex-col items-center gap-2`,children:[(0,_.jsx)(y,{flag:e.flag_a,alt:e.team_a}),(0,_.jsx)(`span`,{className:`text-center font-display text-sm font-bold`,children:e.team_a}),(0,_.jsx)(`input`,{inputMode:`numeric`,value:r,disabled:v,onChange:e=>i(e.target.value.replace(/[^0-9]/g,``).slice(0,2)),placeholder:`-`,className:`h-14 w-14 rounded-xl border border-border bg-input text-center font-display text-2xl font-bold outline-none transition-colors focus:border-primary disabled:opacity-60`})]}),(0,_.jsx)(`span`,{className:`font-display text-lg font-bold text-muted-foreground`,children:`VS`}),(0,_.jsxs)(`div`,{className:`flex flex-1 flex-col items-center gap-2`,children:[(0,_.jsx)(y,{flag:e.flag_b,alt:e.team_b}),(0,_.jsx)(`span`,{className:`text-center font-display text-sm font-bold`,children:e.team_b}),(0,_.jsx)(`input`,{inputMode:`numeric`,value:s,disabled:v,onChange:e=>l(e.target.value.replace(/[^0-9]/g,``).slice(0,2)),placeholder:`-`,className:`h-14 w-14 rounded-xl border border-border bg-input text-center font-display text-2xl font-bold outline-none transition-colors focus:border-primary disabled:opacity-60`})]})]}),b&&(0,_.jsxs)(`div`,{className:`mt-4 rounded-lg border border-border bg-secondary/50 px-3 py-2 text-center text-sm`,children:[(0,_.jsxs)(`div`,{children:[`Resultado: `,(0,_.jsxs)(`span`,{className:`font-bold`,children:[e.score_a,` x `,e.score_b]})]}),t&&(0,_.jsxs)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Seu palpite: `,(0,_.jsxs)(`span`,{className:`font-semibold text-foreground`,children:[t.pred_a,` x `,t.pred_b]}),(0,_.jsxs)(`span`,{className:`ml-2 font-semibold text-primary`,children:[`+`,t.points,` pts`]})]})]}),(0,_.jsx)(`div`,{className:`mt-4`,children:v?(0,_.jsxs)(`div`,{className:`flex items-center justify-center gap-2 rounded-lg border border-border py-3 text-sm font-semibold text-muted-foreground`,children:[(0,_.jsx)(d,{className:`h-4 w-4`}),t?`Seu palpite: ${t.pred_a} x ${t.pred_b}`:`Palpites encerrados`]}):(0,_.jsxs)(`button`,{onClick:S,disabled:f,className:`flex w-full items-center justify-center gap-2 rounded-lg py-3 font-display text-sm font-bold uppercase tracking-wider text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-60`,style:{background:`var(--gradient-brand)`},children:[f?(0,_.jsx)(u,{className:`h-4 w-4 animate-spin`}):(0,_.jsx)(h,{className:`h-4 w-4`}),t?`Atualizar palpite`:`Salvar palpite`]})})]})}export{v as component};
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.