PageSourceSearch

https://pblfg.com/assets/Brackets-MF8SsH4s.js

js pblfg.com collected 2026-09-24 14:49:57 UTC 106,432 bytes, 16 lines download raw bytes

1import{r as c,j as e,k as Dr,L as rs}from"./react-vendor-Q2BSRknM.js";import{af as Or,d8 as Wr,d9 as $r,da as Ur,db as zr,dc as Kr,dd as er,C as ht,c as W,aZ as mt,aY as ls,bp as qs,X as As,Y as Ds,h as Ie,Z as Os,de as Qr,df as tr,bt as sr,dg as Hr,dh as Gr,s as le,di as Vr,aX as Yr,dj as Jr,dk as Xr,dl as Ws,q as rr,dm as Zr,a0 as nr,T as ft,dn as ar,aU as ds,aR as or,dp as lr,cS as en,dq as tn,bl as ns,dr as $s,a8 as ge,cI as sn,ds as ir,u as rn,a1 as nn,bT as an,bK as on,ad as te,dt as ln,bF as cn,at as dn,du as un,a4 as mn,a3 as fn,D as hn,j as pn,dv as Us,J as gn,K as xn,N as bn,O as ut,dw as yn,W as as,dx as wn,B as kn,b4 as vn,cH as _n,dy as jn,d0 as Nn,bO as Sn,d1 as Cn,d2 as Tn,d3 as Mn,bM as Pn}from"./index-CuraQpvj.js";import{u as ke,a as Rn}from"./query-BLOP9k_M.js";import{o as Ft,u as Ln,C as cr,a as dr,k as ur,L as En,B as Bn,n as In,a0 as Fn,E as qn,s as zs,R as Ks,p as An,X as Dn}from"./lucide-DhlFjs1-.js";import{L as On}from"./LazyNotificationSettings-ByWfdphH.js";import{C as Bt}from"./capacitor-DSpR9wll.js";import"./ui-radix-DzQ_orwq.js";import"./supabase-DoZmW4Yf.js";import"./date-utils-DaNoSKVa.js";import"./TeamAvatar--uUa1PRy.js";import"./useTeamAvatarCache-DnynuOLF.js";const us=({team1:s,team2:a,winner:h,score:x,status:l,size:_="md",isMobile:j=!1,onClick:y,isHighlighted:b=!1,onTeamClick:f,details:u,isOnWinnerPath:M=!1,isChampionship:U=!1,isBronzeMedal:m=!1,round:w,isUpset:o=!1,advancedToMainDraw:v,event:N,watchUrl:R,matchId:T,time:d,tournament:k,court:L,topBadge:I})=>{const{isMonochromeTheme:A}=Or(),se=Wr(k||""),F=$r(),K=l==="upcoming"&&d&&F?Ur(d,se,l):null;l==="upcoming"&&d&&F&&zr(d,se);const J=Kr(s||[],a||[],N||"",u,l!=="completed"&&!!(s!=null&&s.length)&&!!(a!=null&&a.length)&&!s.some(i=>/^tbd/i.test(i))&&!a.some(i=>/^tbd/i.test(i)),u==null?void 0:u.officialWinProbability),X=c.useRef(null),re=c.useRef(!1),He=j?{sm:"min-w-[155px]",md:"min-w-[190px]",lg:"min-w-[240px]"}:{sm:"min-w-[180px]",md:"min-w-[220px]",lg:"min-w-[280px]"},Ne=l==="live",ee=l==="upcoming",xe=U&&!!h&&l==="completed",Se=m&&!!h&&l==="completed",ce=j?"text-xs":"text-sm",ue=(x==null?void 0:x.toLowerCase().includes("w.o."))||(x==null?void 0:x.toLowerCase().includes("forfeit"))||(x==null?void 0:x.toLowerCase().includes("walkover"))||(u==null?void 0:u.forfeit)===!0,fe=()=>{if(re.current){re.current=!1;return}y&&y()},Xe=i=>{const B=i.touches[0];X.current={x:B.clientX,y:B.clientY},re.current=!1},Fe=i=>{if(!X.current)return;const B=i.touches[0],S=Math.abs(B.clientX-X.current.x),Q=Math.abs(B.clientY-X.current.y);(S>10||Q>10)&&(re.current=!0)},Ze=()=>{X.current=null},Te=(i,B)=>{B&&f&&(i.stopPropagation(),f(B,l))},We=er({status:l,details:u,winner:h,games:void 0});return e.jsx(ht,{className:W("transition-all duration-300 hover:scale-[1.02] hover:shadow-lg relative overflow-hidden outline-none focus:outline-none focus-visible:outline-none focus:ring-0 focus-visible:ring-0 active:outline-none",h&&l==="completed"?"border-2 border-border/40":"border border-border/20",j?"p-2":"p-3",He[_],Ne&&!U&&!m&&"border-live",ee&&"border-dashed border-muted-foreground/20",y&&"cursor-pointer hover:border-primary/50 hover:shadow-xl",M&&!b&&"border-winner-path/40",U&&"border-gold/50",m&&"border-amber-600/50",xe&&"animate-championship-glow",Se&&"shadow-[0_0_15px_rgba(180,83,9,0.3)]",h&&l==="completed"&&!xe&&!Se&&"shadow-[0_0_20px_hsl(var(--primary)/0.2)]"),style:{background:"var(--gradient-match-card)",boxShadow:h&&l==="completed"?"0 4px 20px rgba(var(--primary-rgb), 0.25)":"0 2px 8px rgba(0, 0, 0, 0.1)"},onClick:fe,onTouchStart:Xe,onTouchMove:Fe,onTouchEnd:Ze,children:e.jsxs("div",{className:"space-y-0.5",children:[I&&e.jsx("div",{className:"flex w-full justify-center pb-1",children:I}),e.jsxs("div",{className:W("flex items-center justify-between py-0.5 px-2 rounded",h===1&&"bg-primary/10",f&&s&&"cursor-pointer hover:bg-primary/20"),onClick:i=>Te(i,s),children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[(u==null?void 0:u.team1Seeds)&&u.team1Seeds.length>0&&e.jsx("div",{className:"flex-shrink-0 w-6 text-center",children:e.jsx("span",{className:W("text-xs font-semibold transition-all",A?u.team1Seeds[0]<=5?"text-foreground font-bold":"text-muted-foreground":u.team1Seeds[0]===1?"text-[hsl(45,93%,58%)] font-bold":u.team1Seeds[0]===2?"text-[hsl(45,85%,54%)] font-bold":u.team1Seeds[0]===3?"text-[hsl(45,75%,50%)] font-semibold":u.team1Seeds[0]===4?"text-[hsl(45,65%,46%)] font-medium":u.team1Seeds[0]===5?"text-[hsl(45,55%,42%)]":"text-muted-foreground"),children:u.team1Seeds[0]})}),(()=>{const i=!s||s.length===0||!s.some(Boolean)||s.every(S=>/^tbd/i.test(S||"")),B=/doubles|mixed/i.test(N||"")||s&&s.length>1||a&&a.length>1;return i?e.jsxs(e.Fragment,{children:[e.jsx(mt,{name:"TBD",className:"w-6 h-6 border border-background",disableTooltip:!0,isDoublesPlaceholder:!!B}),e.jsx("span",{className:W(ce,"text-muted-foreground"),children:"TBD"})]}
1):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex -space-x-1",children:s.map(S=>e.jsx(mt,{name:S||"TBD",className:"w-6 h-6 border border-background"},S||"tbd1"))}),e.jsx("span",{className:W(ce,"truncate font-medium text-foreground",h===1&&"text-primary font-semibold"),children:s.length>1?s.map(ls).join(" / "):s[0]||"TBD"})]})})()]}),h===1&&l==="completed"&&e.jsx(Ft,{className:"w-4 h-4 text-primary shrink-0"}),v===1&&l==="completed"&&e.jsx(qs,{children:e.jsxs(As,{children:[e.jsx(Ds,{asChild:!0,children:e.jsx(Ie,{className:"ml-1 bg-emerald-500/20 text-emerald-400 border border-emerald-500/40 text-[10px] font-bold px-2 py-0.5 h-5 tracking-wide",children:"Q"})}),e.jsx(Os,{side:"top",children:e.jsx("p",{className:"text-xs",children:"Qualified for Main Draw"})})]})})]}),e.jsxs("div",{className:W("flex items-center justify-between py-0.5 px-2 rounded",h===2&&"bg-primary/10",f&&a&&"cursor-pointer hover:bg-primary/20"),onClick:i=>Te(i,a),children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[(u==null?void 0:u.team2Seeds)&&u.team2Seeds.length>0&&e.jsx("div",{className:"flex-shrink-0 w-6 text-center",children:e.jsx("span",{className:W("text-xs font-semibold transition-all",A?u.team2Seeds[0]<=5?"text-foreground font-bold":"text-muted-foreground":u.team2Seeds[0]===1?"text-[hsl(45,93%,58%)] font-bold":u.team2Seeds[0]===2?"text-[hsl(45,85%,54%)] font-bold":u.team2Seeds[0]===3?"text-[hsl(45,75%,50%)] font-semibold":u.team2Seeds[0]===4?"text-[hsl(45,65%,46%)] font-medium":u.team2Seeds[0]===5?"text-[hsl(45,55%,42%)]":"text-muted-foreground"),children:u.team2Seeds[0]})}),(()=>{const i=!a||a.length===0||!a.some(Boolean)||a.every(S=>/^tbd/i.test(S||"")),B=/doubles|mixed/i.test(N||"")||s&&s.length>1||a&&a.length>1;return i?e.jsxs(e.Fragment,{children:[e.jsx(mt,{name:"TBD",className:"w-6 h-6 border border-background",disableTooltip:!0,isDoublesPlaceholder:!!B}),e.jsx("span",{className:W(ce,"text-muted-foreground"),children:"TBD"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex -space-x-1",children:a.map(S=>e.jsx(mt,{name:S||"TBD",className:"w-6 h-6 border border-background"},S||"tbd2"))}),e.jsx("span",{className:W(ce,"truncate font-medium text-foreground",h===2&&"text-primary font-semibold"),children:a.length>1?a.map(ls).join(" / "):a[0]||"TBD"})]})})()]}),h===2&&l==="completed"&&e.jsx(Ft,{className:"w-4 h-4 text-primary shrink-0"}),v===2&&l==="completed"&&e.jsx(qs,{children:e.jsxs(As,{children:[e.jsx(Ds,{asChild:!0,children:e.jsx(Ie,{className:"ml-1 bg-emerald-500/20 text-emerald-400 border border-emerald-500/40 text-[10px] font-bold px-2 py-0.5 h-5 tracking-wide",children:"Q"})}),e.jsx(Os,{side:"top",children:e.jsx("p",{className:"text-xs",children:"Qualified for Main Draw"})})]})})]}),J&&l!=="completed"||l==="upcoming"&&(K||L||T)?(()=>{const i=l==="upcoming"&&(L||K||T),B="flex shrink-0 items-center justify-end gap-2 text-scalable-sm leading-none",S="inline-flex items-center gap-1 shrink-0 leading-none",Q="h-2.5 w-2.5 shrink-0 text-muted-foreground",V=J?e.jsx(Qr,{team1Probability:J.team1,team2Probability:J.team2,compact:!0,className:"shrink-0 self-center leading-none"}):null,H=i?e.jsxs("div",{className:B,children:[L&&e.jsxs("span",{className:W(S,"text-foreground font-score font-semibold"),children:[e.jsx(tr,{className:Q}),e.jsx("span",{className:"leading-none",children:sr(L)})]}),K&&e.jsxs("span",{className:W(S,"text-foreground font-score font-semibold"),children:[e.jsx(Ln,{className:Q}),e.jsx("span",{className:"leading-none",children:K})]}),T&&e.jsx("span",{className:"inline-flex shrink-0 items-center",children:e.jsx(Hr,{matchId:T,teamPlayers:[...s||[],...a||[]],size:"sm"})})]}):Ne?e.jsx(Ie,{className:"bg-live text-live-foreground text-[8px] leading-none px-1.5 py-0.5 h-4 shrink-0",children:"LIVE"}):null;return e.jsx("div",{className:"pt-0.5 border-t border-border/5",children:e.jsx("div",{className:W("flex items-center gap-3",H?"justify-between":"justify-center"),children:H?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:V}),e.jsx("div",{className:"flex shrink-0 items-center",children:H})]}):V}
1)})})():Ne?e.jsx("div",{className:"pt-0.5 border-t border-border/5 flex items-center justify-end min-h-[16px]",children:e.jsx(Ie,{className:"bg-live text-live-foreground text-[8px] leading-none px-1.5 py-0.5 h-4 shrink-0",children:"LIVE"})}):null,x&&!ue&&l!=="upcoming"&&(()=>{const i=x.split(",").map(S=>{const[Q,V]=S.trim().split("-").map(H=>parseInt(H.trim()));return{team1Score:Q,team2Score:V}}).filter(S=>!isNaN(S.team1Score)&&!isNaN(S.team2Score)),B=i.some(S=>S.team1Score>0||S.team2Score>0);return i.length>0&&B?e.jsxs("div",{className:W("pt-0.5 border-t border-border/5 relative"),children:[e.jsx("div",{className:"flex items-center gap-1 overflow-x-auto scrollbar-hide justify-center",children:i.map((S,Q)=>{const V=S.team1Score>S.team2Score,H=S.team2Score>S.team1Score;return e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx(Ie,{variant:"outline",className:"h-3.5 w-3.5 rounded-full p-0 flex items-center justify-center text-[7px] font-medium font-score bg-transparent text-foreground/60 border border-foreground
1/30",children:Q+1}),e.jsx("span",{className:W("text-[10px] font-score",V?"text-foreground font-semibold":"text-muted-foreground"),children:S.team1Score}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"-"}),e.jsx("span",{className:W("text-[10px] font-score",H?"text-foreground font-semibold":"text-muted-foreground"),children:S.team2Score})]},Q)})}),We&&e.jsx(Ie,{className:"absolute right-0 top-1/2 -translate-y-1/2 uppercase tracking-wide text-[7px] px-1 py-0 h-3.5 bg-upset-indicator/15 text-upset-indicator border border-upset-indicator/40 shrink-0",children:"UPSET"})]}):null})(),ue&&(()=>{const i=u==null?void 0:u.withdrawingTeam,B=u==null?void 0:u.matchCompletedType,S=((u==null?void 0:u.notes)||"").toLowerCase(),Q=i||S.includes("withdrawal")||S.includes("withdrew")||S.includes("wd"),V=S.includes("disqualif")||S.includes("dq");let H="W.O.";return B===7?H="NOT PLAYED":V?H="DQ":Q&&(H="W/D"),e.jsx("div",{className:W("flex items-center justify-center gap-2 text-xs pt-1 border-t border-border/5 font-semibold",A?"text-foreground":"text-amber-500"),children:e.jsx("span",{children:H})})})(),R&&l==="completed"&&e.jsx("div",{className:"pt-0.5 border-t border-border/5 flex justify-center",children:e.jsx(Gr,{url:R,status:"completed",variant:"bracket"})})]})})},is=({rounds:s,selectedRound:a,onRoundChange:h,compact:x=!1})=>e.jsx("div",{className:W("flex px-1",x?"gap-1":"gap-1.5"),children:s.map(l=>{const _=a===l.key,j=l.key==="F";return e.jsx("button",{onClick:()=>h(l.key),className:W("flex-1 font-score uppercase tracking-wider transition-all duration-200 flex items-center justify-center",x?"min-h-7 py-1 rounded-md text-scalable-xs":"py-2 rounded-lg text-scalable-sm",_?"bg-primary text-primary-foreground shadow-md":"bg-muted/50 text-muted-foreground hover:bg-muted"),children:j?e.jsx(Ft,{className:x?"w-3.5 h-3.5":"w-4 h-4"}):l.label},l.key)})}),Qs=s=>(s||"").toLowerCase().replace(/[^a-z0-9]/g,"");function mr(s){const a=ke({queryKey:["mlp_pool_team_clinches",s],enabled:!!s,staleTime:6e4,refetchInterval:6e4,queryFn:async()=>{const{data:j,error:y}=await le.from("mlp_pool_team_clinches").select("tournament_id,team_uuid,team_name,pool_label,state").eq("tournament_id",s);if(y)throw y;return j||[]}}),h=new Map,x=new Map;for(const j of a.data||[])j.team_name&&h.set(Qs(j.team_name),j.state),j.team_uuid&&x.set(j.team_uuid,j.state);return{lookup:j=>h.get(Qs(j))||null,lookupByUuid:j=>j&&x.get(j)||null,isLoading:a.isLoading}}function ye(s){return s.filter(a=>a&&a!=="TBD").sort().join("|").toLowerCase()}function fr(s){const a=new Map,h=new Map;for(const j of s){const y=ye(j.team1),b=ye(j.team2);!y||!b||(h.set(y,j.team1),h.set(b,j.team2),a.has(y)||a.set(y,[]),a.has(b)||a.set(b,[]),a.get(y).push(j.team2),a.get(b).push(j.team1))}const x=new Set,l=[],_="ABCDEFGH";for(const[j]of a){if(x.has(j))continue;const y=new Set,b=[j];for(;b.length>0;){const v=b.shift();if(y.has(v))continue;y.add(v),x.add(v);const N=a.get(v)||[];for(const R of N){const T=ye(R);y.has(T)||b.push(T)}}const f=Array.from(y).map(v=>h.get(v)).filter(Boolean),u=s.filter(v=>{const N=ye(v.team1),R=ye(v.team2);return y.has(N)&&y.has(R)}),M=new Map;for(const v of f)M.set(ye(v),{team:v,wins:0,losses:0,gamesWon:0,gamesLost:0,pointDiff:0,h2hWinsOver:new Set});for(const v of u){if(v.status!=="completed"||!v.winner)continue;const N=ye(v.team1),R=ye(v.team2),T=M.get(N),d=M.get(R);if(T&&d){v.winner===1?(T.wins++,d.losses++,T.h2hWinsOver.add(R)):(d.wins++,T.losses++,d.h2hWinsOver.add(N));for(const k of v.games||[]){const L=k.team1Score||0,I=k.team2Score||0;L===0&&I===0||(T.gamesWon+=L>I?1:0,T.gamesLost+=I>L?1:0,d.gamesWon+=I>L?1:0,d.gamesLost+=L>I?1:0,T.pointDiff+=L-I,d.pointDiff+=I-L)}}}const m=[...Array.from(M.values())].sort((v,N)=>N.wins-v.wins),w=[];let o=0;for(;o<m.length;){let v=o;for(;v<m.length&&m[v].wins===m[o].wins;)v++;const N=m.slice(o,v);if(N.length===1)w.push(N[0]);else{const R=new Map;for(const T of N){let d=0;const k=ye(T.team);for(const L of N){const I=ye(L.team);I!==k&&T.h2hWinsOver.has(I)&&d++}R.set(k,d)}N.sort((T,d)=>{const k=R.get(ye(T.team))??0,L=R.get(ye(d.team))??0;if(k!==L)return L-k;const I=T.gamesWon-T.gamesLost,A=d.gamesWon-d.gamesLost;return I!==A?A-I:d.pointDiff!==T.pointDiff?d.pointDiff-T.pointDiff:0}),w.push(...N)}o=v}l.push({label:_[l.length]||`${l.length+1}
1`,teams:f,matches:u.sort((v,N)=>(v.time||"").localeCompare(N.time||"")),standings:w})}return l.sort((j,y)=>j.label.localeCompare(y.label))}function Wn(s){const a=s.trim().split(/\s+/);return a.length<2?s:`${a[0][0]}. ${a[a.length-1]}`}function $n({matches:s,isMobile:a,onMatchClick:h,displayTournamentName:x,tournamentDateLabel:l,filterPoolLabel:_,tournamentId:j}){const y=c.useMemo(()=>fr(s),[s]),b=_?y.filter(m=>m.label===_):y,{lookup:f}=Vr(j),{lookup:u}=mr(j),{resolveTeam:M}=Yr(),U={clinched_1st:{row:"bg-amber-500/10 border-l-2 border-l-amber-400/70",chipBg:"bg-amber-500/15 ring-1 ring-amber-400/40",chipText:"text-amber-300",icon:e.jsx(ur,{className:"h-3 w-3"}),label:"Clinched 1st"},clinched_playoff:{row:"bg-emerald-500/5 border-l-2 border-l-emerald-400/60",chipBg:"bg-emerald-500/15 ring-1 ring-emerald-400/40",chipText:"text-emerald-300",icon:e.jsx(dr,{className:"h-3 w-3"}),label:"Clinched playoff"},eliminated:{row:"opacity-60",chipBg:"bg-rose-500/15 ring-1 ring-rose-400/40",chipText:"text-rose-300",icon:e.jsx(cr,{className:"h-3 w-3"}),label:"Eliminated"}};return b.length===0?null:e.jsxs("div",{className:W("relative",a&&"mt-[1px]",!a&&"mt-6 max-w-2xl mx-auto"),children:[e.jsxs("div",{className:"px-2 pt-1 pb-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsxs("h3",{className:"text-lg font-score text-foreground tracking-wide uppercase",children:[e.jsx("span",{children:"Pool Play"}),x&&e.jsxs("span",{className:"text-muted-foreground",children:[": ",x]})]}),l&&e.jsx("span",{className:"font-player text-[10px] tracking-wider uppercase text-muted-foreground/70 whitespace-nowrap bg-muted/50 px-2 py-0.5 rounded-full border border-border/30",children:l})]}),e.jsx("div",{className:"h-0.5 bg-primary/30 mt-2 rounded-full"})]}),e.jsx("div",{className:"space-y-6 px-2 pb-5",children:b.map(m=>e.jsxs("div",{className:"space-y-3",children:[!_&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs font-score uppercase tracking-widest text-primary bg-primary/10 px-2.5 py-1 rounded-md",children:["Pool ",m.label]}),e.jsx("div",{className:"flex-1 h-px bg-border/30"})]}),e.jsx("div",{className:"rounded-lg border border-border/50 overflow-hidden bg-muted/20",children:e.jsxs("table",{className:"w-full text-xs table-fixed",children:[e.jsxs("colgroup",{children:[e.jsx("col",{className:"w-12"}),e.jsx("col",{}),e.jsx("col",{className:"w-[13%]"}),e.jsx("col",{className:"w-[13%]"}),e.jsx("col",{className:"w-[16%]"})]}),e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border/30 text-muted-foreground",children:[e.jsx("th",{className:"text-left py-1.5 px-2 font-semibold",children:"#"}),e.jsx("th",{className:"text-left py-1.5 px-2 font-semibold",children:"Team"}),e.jsx("th",{className:"text-center py-1.5 px-1 font-semibold",children:"W"}),e.jsx("th",{className:"text-center py-1.5 px-1 font-semibold",children:"L"}),e.jsx("th",{className:"text-center py-1.5 px-1 font-semibold",children:"PD"})]})}),e.jsx("tbody",{children:m.standings.map((w,o)=>{var T;const v=((T=M(w.team))==null?void 0:T.team_title)||null,N=u(v),R=N?U[N]:null;return e.jsxs("tr",{className:W("border-b border-border/20 last:border-0",!R&&o<4&&"bg-primary/5",R==null?void 0:R.row),children:[e.jsx("td",{className:"py-1.5 pl-2 pr-1 text-muted-foreground font-score whitespace-nowrap",children:e.jsxs("span",{className:"inline-flex items-center gap-1 align-middle",children:[e.jsx("span",{className:"inline-block w-4 text-center tabular-nums",children:o+1}),e.jsx("span",{className:W("inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full",R?[R.chipBg,R.chipText]:"invisible"),title:R==null?void 0:R.label,"aria-label":R==null?void 0:R.label,children:(R==null?void 0:R.icon)??e.jsx("span",{className:"block h-3 w-3"})})]})}),e.jsx("td",{className:"py-1.5 px-2 font-medium text-foreground",children:w.team.map(Wn).join(" / ")}),e.jsx("td",{className:"text-center py-1.5 px-1 font-score text-green-500",children:w.wins}),e.jsx("td",{className:"text-center py-1.5 px-1 font-score text-red-400",children:w.losses}),e.jsx("td",{className:"text-center py-1.5 px-1 font-score text-muted-foreground",children:w.pointDiff>0?`+${w.pointDiff}`:w.pointDiff})]},ye(w.team))})})]})}),e.jsx("div",{className:"flex flex-col gap-2",children:m.matches.map(w=>{var T,d,k,L;const o=((T=M(w.team1))==null?void 0:T.team_title)||((d=w.team1)==null?void 0:d[0])||null,v=((k=M(w.team2))==null?void 0:k.team_title)||((L=w.team2)==null?void 0:L[0])||null,N=f(o,v),R=N&&(N.team1||N.team2)?e.jsx(Jr,{team1:N.team1,team2:N.team2,team1Label:o||"Team 1",team2Label:v||"Team 2"}):null;return e.jsx("div",{children:e.jsx(us,{team1:w.team1,team2:w.team2,winner:w.winner,score:w.score,status:w.status,size:"sm",isMobile:a,onClick:()=>h(w),isHighlighted:!1,isOnWinnerPath:!1,isChampionship:!1,isBronzeMedal:!1,round:"Pool Play",isUpset:er(w),details:w.details,event:w.event,matchId:w.id,time:w.time,tournament:w.tournament,court:w.court,topBadge:R})},w.id)})})]},m.label))})]})}const Hs="bracket_bronze_name_allowlist",os=["asia"];function Un(){const{data:s=os}=ke({queryKey:["app-setting",Hs],queryFn:async()=>{const{data:a}=await le.from("app_settings").select("value").eq("key",Hs).maybeSingle();if(!(a!=null&&a.value))return os;try{const h=JSON.parse(a.value);if(Array.isArray(h))return h.map(l=>
1String(l).toLowerCase().trim()).filter(Boolean)}catch{return a.value.split(",").map(h=>h.toLowerCase().trim()).filter(Boolean)}return os},staleTime:6e4});return s}function zn(s){const a=Un(),h=(s||"").toLowerCase();return h?a.some(x=>h.includes(x)):!1}function Je(s){const a=!!s,h=ke({queryKey:["mlp-event-meta",s],enabled:a,staleTime:5*60*1e3,queryFn:async()=>{const{data:f,error:u}=await le.from("mlp_event_meta").select("format, data_source, is_visible, mlp_tournament_uuid, season, notes, playoff_label, broadcast_url, broadcast_provider, bracket_format, bracket_config").eq("tournament_id",s).maybeSingle();if(u)throw u;return f?{...f,bracket_format:f.bracket_format||"team_pool",bracket_config:f.bracket_config||{}}:null}}),x=ke({queryKey:["mlp-event-matchups-curated",s],enabled:a,staleTime:20*1e3,refetchInterval:f=>(f.state.data||[]).some(M=>M.status==="in_progress")?20*1e3:!1,queryFn:async()=>{const{data:f,error:u}=await le.from("mlp_event_matchups").select("*").eq("tournament_id",s).order("stage",{ascending:!0}).order("match_order",{ascending:!0});if(u)throw u;return(f||[]).map(M=>({...M,source:"curated"}))}}),l=h.data||null,_=!!l&&l.data_source!=="curated"&&!!l.mlp_tournament_uuid,j=ke({queryKey:["mlp-event-bracket-api",s,l==null?void 0:l.mlp_tournament_uuid,Xr()||"global"],enabled:a&&_,staleTime:60*1e3,retry:0,queryFn:async()=>{var w,o,v,N,R;if(!(l!=null&&l.mlp_tournament_uuid))return[];const[f,u]=await Promise.all([le.functions.invoke("team-leagues-proxy",{body:Ws({action:"tournamentPools",tournament_uuid:l.mlp_tournament_uuid})}),le.functions.invoke("team-leagues-proxy",{body:Ws({action:"tournamentDetail",tournament_uuid:l.mlp_tournament_uuid})})]),M=[];return(((w=f==null?void 0:f.data)==null?void 0:w.pools)||((o=f==null?void 0:f.data)==null?void 0:o.tournament_pools)||[]).forEach((T,d)=>{(T.matchups||T.pool_matchups||[]).forEach((L,I)=>{M.push(Gs(L,"pool",T.title||T.name||`Pool ${d+1}`,I))})}),(((v=u==null?void 0:u.data)==null?void 0:v.matchup_groups)||((R=(N=u==null?void 0:u.data)==null?void 0:N.tournament)==null?void 0:R.matchup_groups)||[]).forEach(T=>{const d=T.matchups||[],k=/pool/i.test(T.title||T.type||"")?"pool":/playoff|final|semi|quarter|bracket/i.test(T.title||T.type||"")?"playoff":l.format==="regular"?"regular":"playoff";d.forEach((L,I)=>{M.push(Gs(L,k,T.title||null,I))})}),M}}),y=Kn(x.data||[],_?j.data||[]:[]),b={regular:y.filter(f=>f.stage==="regular"),pool:y.filter(f=>f.stage==="pool"),playoff:y.filter(f=>f.stage==="playoff"),double_elim:y.filter(f=>f.stage==="double_elim")};return{meta:l,matchups:y,byStage:b,hasCurated:(x.data||[]).length>0,hasApi:_&&(j.data||[]).length>0,isLoading:h.isLoading||x.isLoading||_&&j.isLoading,error:h.error||x.error||j.error}}function Gs(s,a,h,x){const l=s.home_team||s.team1||s.team_a||{},_=s.away_team||s.team2||s.team_b||{},j=s.home_score??s.team1_score??l.score??null,y=s.away_score??s.team2_score??_.score??null,b=s.uuid||s.id||null;return{id:`api:${b||`${a}-${x}`}`,stage:a,pool_label:h,round_label:s.round_title||s.round||null,match_order:typeof s.match_order=="number"?s.match_order:x,team1_uuid:l.uuid||null,team2_uuid:_.uuid||null,team1_name:l.title||l.name||l.team_title||null,team2_name:_.title||_.name||_.team_title||null,team1_score:j!=null?Number(j):null,team2_score:y!=null?Number(y):null,winner_uuid:s.winner_uuid||s.winning_team_uuid||null,status:s.status==="completed"||s.is_completed?"completed":s.status==="in_progress"||s.is_live?"in_progress":"upcoming",scheduled_at:s.scheduled_at||s.start_time||null,source:"api",lineup_matchup_uuid:b}}function Kn(s,a){const h=l=>`${l.stage}|${l.pool_label||""}|${l.match_order}`,x=new Map;for(const l of a)x.set(h(l),l);for(const l of s)x.set(h(l),l);return Array.from(x.values()).sort((l,_)=>{const j={regular:0,pool:1,playoff:2,double_elim:3},y=j[l.stage]-j[_.stage];return y!==0?y:(l.pool_label||"")!==(_.pool_label||"")?(l.pool_label||"").localeCompare(_.pool_label||""):l.match_order-_.match_order})}function Qn(s){return ke({queryKey:["mlp-pool-standing-overrides",s],enabled:!!s,staleTime:6e4,queryFn:async()=>{const{data:a,error:h}=await le.from("mlp_pool_standings_overrides").select("tournament_id, pool_key, ranked_team_uuids, concluded, notes").eq("tournament_id",s);if(h)throw h;const x=new Map;for(const l of a||[])x.set(l.pool_key,l);return x}})}function Hn(s,a,h,x){const l=(x&&x.display_round_label||"").toString().trim();if(l)return/^f(inal)?s?$/i.test(l)?"FINAL":l.toUpperCase();const j=["F","SF","QF","R16","R32","R64"][s]??`R${a}`,y=(h||"").trim();if(y){const b=y.replace(/^(wb|lb|winners?|losers?)\s+/i,"").trim();if(b&&!/^R\d+$/i.test(b))return b.toUpperCase()}return j}
1function Gn(s,a){return{F:"Final",SF:"Semifinal",QF:"Quarterfinal",R16:"Round of 16",R32:"Round of 32",R64:"Round of 64",R1:"Round 1",R2:"Round 2",R3:"Round 3",R4:"Round 4",R5:"Round 5",R6:"Round 6",GF1:"Grand Final",GF2:"Bracket Reset",FINAL:"Final",FINALS:"Final"}[s.toUpperCase()]??s}function Vs(s){const a=new Map;for(const h of s){const x=h.round_number??0;a.has(x)||a.set(x,[]),a.get(x).push(h)}return Array.from(a.entries()).sort((h,x)=>h[0]-x[0]).map(([,h])=>h.sort((x,l)=>x.match_order-l.match_order))}function Vn(s,a){const h=a.find(x=>x.match_code===s);return(h==null?void 0:h.winner_uuid)||null}function Yn(s){var N,R;const{meta:a,matchups:h}=Je(s||""),x=!!a&&a.bracket_format==="team_de",l=((N=a==null?void 0:a.bracket_config)==null?void 0:N.if_necessary_visible)!==!1,{wb:_,lb:j,gf:y}=c.useMemo(()=>{const T=h.filter(k=>k.stage==="double_elim"),d=k=>!(k.match_code&&String(k.match_code).startsWith("PICKEM-SEED"))&&!(k.status==="completed"&&(!k.team1_uuid||!k.team2_uuid))&&!(k.status==="placeholder"&&!!k.team1_uuid!=!!k.team2_uuid);return{wb:Vs(T.filter(k=>k.bracket==="WB").filter(d)),lb:Vs(T.filter(k=>k.bracket==="LB").filter(d)),gf:T.filter(k=>k.bracket==="GF").filter(d).sort((k,L)=>(k.round_number||0)-(L.round_number||0)||k.match_order-L.match_order)}},[h]),b=c.useMemo(()=>{if(!l)return y.filter(L=>!L.if_necessary);const T=y.find(L=>!L.if_necessary);return y.find(L=>L.if_necessary)?!T||T.status!=="completed"||!T.winner_uuid?y.filter(L=>!L.if_necessary):!!T.feeder_winner_code&&T.winner_uuid===Vn(T.feeder_winner_code,h)?y.filter(L=>!L.if_necessary):y:y},[y,h,l]),f=c.useMemo(()=>{const T=(k,L)=>{const I=L.length,A=L.map((se,F)=>{const K=se[0],J=I-1-F,X=Hn(J,(K==null?void 0:K.round_number)??F+1,K==null?void 0:K.round_label,K==null?void 0:K.details),re=/^(CHAMPIONSHIP|FINAL|FINALS|GRAND FINAL)$/i.test(X);return{key:`${k}-${(K==null?void 0:K.round_number)??F}`,label:X,fullLabel:re?"Championship":Gn(X),matchCount:se.length,isChampionship:re,matches:se}});return k==="WB"&&b.length&&A.push({key:"GF",label:"GF",fullLabel:"Grand Final",matchCount:b.length,isGF:!0,matches:b}),A},d=[];return _.length&&d.push({key:"WB",label:"Winner's",rounds:T("WB",_)}),j.length&&d.push({key:"LB",label:"Loser's",rounds:T("LB",j)}),d},[_,j,b]),[u,M]=c.useState("WB");c.useEffect(()=>{f.length&&!f.find(T=>T.key===u)&&M(f[0].key)},[f,u]);const U=f.find(T=>T.key===u)||f[0],m=(U==null?void 0:U.rounds)||[],[w,o]=c.useState("");c.useEffect(()=>{if(!m.length){o("");return}if(m.find(I=>I.key===w))return;const T=m.find(I=>I.matches.some(A=>A.status==="in_progress")),d=m.find(I=>I.matches.some(A=>A.status==="upcoming")),k=m.find(I=>I.isGF),L=m[m.length-1];o((T==null?void 0:T.key)||(d==null?void 0:d.key)||(k==null?void 0:k.key)||L.key)},[m,w]);const v=((R=m.find(T=>T.key===w))==null?void 0:R.matches)||[];return{isDe:x,sides:f,side:u,setSide:M,selectedRoundKey:w,setSelectedRoundKey:o,visibleMatches:v,visibleGf:b}}const hr=c.createContext(null);function Jn({tournamentId:s,children:a}){const h=Yn(s);return e.jsx(hr.Provider,{value:h,children:a})}function pr(){const s=c.useContext(hr);if(!s)throw new Error("useMlpDeControlsContext must be used inside MlpDeControlsProvider");return s}function Xn(s){const{meta:a}=Je(s||"");return!!a&&a.bracket_format==="team_de"}function Zn({startDate:s,checkBackText:a,tournamentId:h}){const{userId:x}=rr(),{isSubscribed:l,isLoading:_,toggle:j}=Zr(x),y=nr();(()=>{if(a)return a;if(!s)return"Check back the week of the tournament";const f=new Date(s+"T00:00:00"),u=f.toLocaleDateString("en-US",{weekday:"long"}),M=f.toLocaleDateString("en-US",{month:"long",day:"numeric"});return`Check back ${u}, ${M}`})();const b=f=>{if(f.stopPropagation(),!x){y();return}j()};return e.jsxs("div",{className:"mx-4 mt-16 sm:mt-20 relative overflow-hidden rounded-2xl border border-border/40 bg-card shadow-lg",children:[e.jsxs("div",{className:"pointer-events-none absolute inset-0 opacity-60",children:[e.jsx("div",{className:"absolute -top-16 left-1/2 -translate-x-1/2 w-64 h-64 rounded-full bg-primary/20 blur-3xl"}),e.jsx("div",{className:"absolute -bottom-20 right-0 w-48 h-48 rounded-full bg-primary/10 blur-3xl"})]}),e.jsxs("div",{className:"relative px-6 pt-8 pb-6 flex flex-col items-center text-center",children:[e.jsxs("div",{className:"relative mb-5",children:[e.jsx("div",{className:"absolute inset-0 rounded-2xl bg-primary/20 blur-xl"}),e.jsx("div",{className:"relative w-16 h-16 rounded-2xl bg-gradient-to-br from-primary/25 to-primary/5 border border-primary/30 flex items-center justify-center",children:e.jsx(ft,{className:"w-8 h-8 text-primary",strokeWidth:2.5})})]}),e.jsx("h3",{className:"font-player text-3xl uppercase tracking-wide text-foreground leading-tight",children:"Brackets Drop Soon"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground max-w-xs",children:"Draws are being prepared by tournament organizers. Check back soon."}),e.jsx("button",{onClick:b,disabled:_,className:W("mt-6 inline-flex items-center gap-2 rounded-full px-5 py-2.5 text-sm font-semibold transition-all duration-200",l?"bg-primary/15 text-primary border border-primary/30 hover:bg-primary/25":"bg-primary text-primary-foreground hover:opacity-90 shadow-md shadow-primary/20",_&&"opacity-50 pointer-events-none"),"aria-label":l?"Remove bracket alert":"Get notified when brackets are available",children:_?e.jsx(En,{className:"h-4 w-4 animate-spin"}):l?e.jsxs(e.Fragment,{children:[e.jsx(Bn,{className:"h-4 w-4",strokeWidth:2.5}),"Alerts On"]}):e.jsxs(e.Fragment,{children:[e.jsx(In,{className:"h-4 w-4"}),"Get Notified"]})})]})]})}function ea({tournamentId:s,tournamentName:a,tournamentDateLabel:h,broadcastUrl:x,broadcastProvider:l,sponsors:_,standingsLookup:j,onMatchClick:y}
1){const{sides:b,side:f,selectedRoundKey:u,visibleMatches:M}=pr(),{tournaments:U}=ar(),m=U.find(d=>d.id===s),o=b.flatMap(d=>d.rounds.flatMap(k=>k.matches)).some(d=>d.status!=="placeholder"&&!!d.team1_uuid&&!!d.team2_uuid);if(!b.length||!o)return e.jsx(Zn,{startDate:m==null?void 0:m.start_date,tournamentId:s});const v=b.find(d=>d.key===f)||b[0],N=(v==null?void 0:v.rounds.find(d=>d.key===u))||(v==null?void 0:v.rounds[0]),R=(N==null?void 0:N.fullLabel)||(N==null?void 0:N.label)||"",T=d=>({...d,tournament_id:s,tournament_name:a,broadcast_url:x??null,broadcast_provider:l??null});return e.jsxs("div",{className:"space-y-3",children:[R&&e.jsxs("div",{className:"px-2 pt-1 pb-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("h3",{className:"text-lg font-score text-foreground tracking-wide uppercase leading-none",children:[e.jsx("span",{children:R}),a&&e.jsxs("span",{className:"text-muted-foreground",children:[": ",a]})]}),h&&e.jsx("span",{className:"text-[10px] font-semibold tracking-wider uppercase text-muted-foreground/70 whitespace-nowrap bg-muted/50 px-2 py-0.5 rounded-full border border-border/30",children:h})]}),e.jsx("div",{className:"h-0.5 bg-primary/30 mt-1.5 rounded-full"})]}),M.map(d=>e.jsx(ds,{row:T(d),sponsors:_,standingsLookup:j,onMatchClick:y?k=>y(k):void 0},d.id))]})}function ta({className:s}){const{sides:a,side:h,setSide:x,selectedRoundKey:l,setSelectedRoundKey:_}=pr();if(!a.length)return null;const j=a.find(b=>b.key===h)||a[0],y=(j==null?void 0:j.rounds)||[];return e.jsxs("div",{className:W("space-y-1.5",s),children:[a.length>1&&e.jsx("div",{className:"flex gap-1.5 px-1",children:a.map(b=>{const f=b.key===h;return e.jsx("button",{onClick:()=>x(b.key),className:W("flex-1 py-1.5 rounded-lg font-score uppercase tracking-wide text-scalable-xs transition-all",f?"bg-primary text-primary-foreground shadow-md":"bg-muted/50 text-muted-foreground hover:bg-muted"),children:b.label},b.key)})}),y.length>1&&e.jsx("div",{className:"flex gap-1 px-1",children:y.map(b=>{const f=l===b.key;return b.isGF||b.isChampionship?e.jsxs("button",{onClick:()=>_(b.key),className:W("flex-1 min-h-7 py-1 rounded-md font-score uppercase tracking-wide text-scalable-xs transition-all flex items-center justify-center gap-1 border",f?"bg-[hsl(var(--pickem-gold)/0.18)] border-[hsl(var(--pickem-gold))] text-[hsl(var(--pickem-gold))] shadow-[0_0_12px_hsl(var(--pickem-gold)/0.45)]":"bg-[hsl(var(--pickem-gold)/0.08)] border-[hsl(var(--pickem-gold)/0.45)] text-[hsl(var(--pickem-gold))] hover:bg-[hsl(var(--pickem-gold)/0.15)]"),children:[e.jsx(Ft,{className:"w-3.5 h-3.5"}),b.label]},b.key):e.jsx("button",{onClick:()=>_(b.key),className:W("flex-1 min-h-7 py-1 rounded-md font-score uppercase tracking-wide text-scalable-xs transition-all",f?"bg-primary text-primary-foreground shadow-md":"bg-muted/50 text-muted-foreground hover:bg-muted"),children:b.label},b.key)})})]})}function gr(s){const{meta:a,matchups:h,byStage:x}=Je(s||"");return{rounds:c.useMemo(()=>{if(!a)return[];const _=[],y=[...x.pool,...x.regular,...h].filter((f,u,M)=>M.findIndex(U=>U.id===f.id)===u).filter(f=>!!f.pool_label);if(a.format==="regular"&&y.length===0){const f=x.regular.length>0?x.regular:h;return _.push({key:"PP-regular",label:"POOL PLAY",matchCount:f.length,matchups:f}),_}const b=new Map;for(const f of y){const u=f.pool_label||"Pool";b.has(u)||b.set(u,[]),b.get(u).push(f)}if(Array.from(b.entries()).sort(([f],[u])=>f.localeCompare(u)).forEach(([f,u])=>{_.push({key:`PP-${f}`,label:f,matchCount:u.length,matchups:u})}),x.playoff.length>0){const f=a.playoff_label||"Playoffs";_.push({key:"playoff",label:f,matchCount:x.playoff.length,matchups:x.playoff})}return _},[a,x,h])}}function sa({viewMode:s}){return s==="order"?e.jsx("div",{className:"space-y-4",children:[0,1,2,3,4].map(a=>e.jsx(Ys,{showCourt:!0},a))}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"px-2 pt-1 pb-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx(ge,{className:"h-5 w-56"}),e.jsx(ge,{className:"h-4 w-20 rounded-full"})]}),e.jsx("div",{className:"h-0.5 bg-primary/20 mt-2 rounded-full"})]}),e.jsx("div",{className:"space-y-3",children:[0,1,2,3,4].map(a=>e.jsx(Ys,{},a))})]})}
1function Ys({showCourt:s=!1}){return e.jsxs("div",{className:"rounded-xl border border-border/40 p-3 space-y-2.5",style:{background:"var(--gradient-match-card)"},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ge,{className:"h-3 w-16"}),s&&e.jsx(ge,{className:"h-4 w-14 rounded"})]}),e.jsx(ge,{className:"h-4 w-12 rounded-full"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ge,{className:"h-9 w-9 rounded-full"}),e.jsx(ge,{className:"h-4 flex-1 max-w-[160px]"}),e.jsx(ge,{className:"h-6 w-6 rounded"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ge,{className:"h-9 w-9 rounded-full"}),e.jsx(ge,{className:"h-4 flex-1 max-w-[140px]"}),e.jsx(ge,{className:"h-6 w-6 rounded"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[e.jsx(ge,{className:"h-3 w-24"}),e.jsx(ge,{className:"h-7 w-20 rounded-md"})]})]})}function ra({tournamentId:s,tournamentName:a,selectedRound:h,onRoundChange:x,tournamentDateLabel:l,onMatchClick:_,viewMode:j="bracket",activeCourtKey:y,onActiveCourtChange:b,hideCourtToggle:f}){var se;const{meta:u,matchups:M,isLoading:U,error:m}=Je(s),{rounds:w}=gr(s),o=or(),{teamStandings:v}=en({enabled:!!s}),N=c.useMemo(()=>tn(v),[v]),R=typeof h=="string"&&!!x,[T,d]=c.useState(""),k=R?h:T;c.useEffect(()=>{if(!R&&!T&&w.length>0){const F=w.find(X=>X.matchups.some(re=>re.status==="in_progress")),K=w.find(X=>X.key==="playoff"),J=[...w].reverse().find(X=>X.matchups.some(re=>re.status==="upcoming"||re.status==="in_progress"));d((F==null?void 0:F.key)||(K==null?void 0:K.key)||(J==null?void 0:J.key)||w[0].key)}},[w,T,R]);const[L,I]=c.useState(null);if(c.useEffect(()=>{const F=K=>{const J=K.detail;J&&I(J)};return window.addEventListener("mlp-open-team",F),()=>window.removeEventListener("mlp-open-team",F)},[]),U)return e.jsx(sa,{viewMode:j});if(m||!u)return e.jsxs(ht,{className:"border-destructive/50 p-4 flex items-center gap-3",children:[e.jsx(Fn,{className:"h-5 w-5 text-destructive shrink-0"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"font-medium",children:"MLP event data unavailable"}),e.jsx("div",{className:"text-muted-foreground text-xs",children:u?"Failed to load matchups.":"No MLP metadata configured for this event."})]})]});if(M.length===0)return e.jsxs(ht,{className:"p-8 text-center text-sm text-muted-foreground",children:["Schedule not yet released for ",a,"."]});if(u.bracket_format==="team_de"&&j!=="order")return e.jsxs(e.Fragment,{children:[e.jsx(ea,{tournamentId:s,tournamentName:a,tournamentDateLabel:l,broadcastUrl:u.broadcast_url,broadcastProvider:u.broadcast_provider,sponsors:o,standingsLookup:N,onMatchClick:_?F=>_({...F,tournament_id:s,tournament_name:a}):void 0}),e.jsx(ns,{team:L,open:!!L,onOpenChange:F=>{F||I(null)}})]});if(j==="order")return e.jsxs(e.Fragment,{children:[e.jsx(ia,{matchups:M.filter(F=>$s(F)),tournamentId:s,tournamentName:a,broadcastUrl:u.broadcast_url,broadcastProvider:u.broadcast_provider,sponsors:o,onMatchClick:_,standingsLookup:N,activeCourtKey:y,onActiveCourtChange:b,hideCourtToggle:f}),e.jsx(ns,{team:L,open:!!L,onOpenChange:F=>{F||I(null)}})]});const A=w.find(F=>F.key===k)||w[0];return e.jsxs("div",{className:"space-y-4",children:[!R&&w.length>1&&e.jsx(is,{rounds:w.map(F=>({key:F.key,label:F.label,matchCount:F.matchCount})),selectedRound:k||w[0].key,onRoundChange:d}),A&&e.jsxs("div",{className:"px-2 pt-1 pb-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-lg font-score text-foreground tracking-wide uppercase leading-none",children:e.jsx("span",{children:A.label})}),l&&e.jsx("span",{className:"text-[10px] font-semibold tracking-wider uppercase text-muted-foreground/70 whitespace-nowrap bg-muted/50 px-2 py-0.5 rounded-full border border-border/30",children:l})]}),e.jsx("div",{className:"h-0.5 bg-primary/30 mt-1.5 rounded-full"})]}),A&&A.key.startsWith("PP")&&e.jsx(na,{matchups:A.matchups,tournamentId:s,poolKey:A.key,advanceCutoff:Number((se=u.bracket_config)==null?void 0:se.advance_cutoff)||4}),e.jsx("div",{className:"space-y-3",children:(()=>{const F=((A==null?void 0:A.matchups)||[]).filter(ee=>$s(ee)),K=!!A&&A.key.startsWith("PP"),J=ee=>ee==="in_progress"?0:ee==="completed"?2:1,X=[...F].sort((ee,xe)=>{const Se=J(ee.status),ce=J(xe.status);if(Se!==ce)return Se-ce;const ue=ee.scheduled_at?new Date(ee.scheduled_at).getTime():0,fe=xe.scheduled_at?new Date(xe.scheduled_at).getTime():0;return Se===2?!ue&&!fe?xe.match_order-ee.match_order:ue?fe?fe-ue:-1:1:!ue&&!fe?ee.match_order-xe.match_order:ue?fe?ue-fe:-1:1}),re=F.some(ee=>ee.status==="in_progress"||ee.status==="completed"),He=F.some(ee=>!!ee.scheduled_at);return(K||re||He?X:F).map(ee=>e.jsx(ds,{row:{...ee,tournament_id:s,tournament_name:a,broadcast_url:u.broadcast_url,broadcast_provider:u.broadcast_provider},sponsors:o,onMatchClick:_,standingsLookup:N},ee.id))})()}),e.jsx(ns,{team:L,open:!!L,onOpenChange:F=>{F||I(null)}})]})}function na({matchups:s,tournamentId:a,poolKey:h,advanceCutoff:x=4}){const{data:l}=Qn(a),_=(l==null?void 0:l.get(h))??null,{lookupByUuid:j}=mr(a),y=c.useMemo(()=>{var R,T;const m=new Map,w=(d,k)=>{d&&(m.has(d)?k&&m.get(d).name==="TBD"&&(m.get(d).name=k):m.set(d,{uuid:d,name:k||"TBD",wins:0,losses:0,gameDiff:0,pointDiff:0}))};for(const d of s)w(d.team1_uuid,d.team1_name),w(d.team2_uuid,d.team2_name);for(const d of s){if(d.status!=="completed"||!d.winner_uuid)continue;
1const k=d.team1_uuid?m.get(d.team1_uuid):null,L=d.team2_uuid?m.get(d.team2_uuid):null;if(!k||!L)continue;const I=d.team1_score??0,A=d.team2_score??0;k.gameDiff+=I-A,L.gameDiff+=A-I,d.winner_uuid===k.uuid?(k.wins++,L.losses++):d.winner_uuid===L.uuid&&(L.wins++,k.losses++);const se=Array.isArray((R=d.details)==null?void 0:R.games)?d.details.games:[];for(const F of se){const K=typeof(F==null?void 0:F.team1)=="number"?F.team1:0,J=typeof(F==null?void 0:F.team2)=="number"?F.team2:0;K===0&&J===0||(k.pointDiff+=K-J,L.pointDiff+=J-K)}}const o=(d,k)=>{for(const L of s){if(L.status!=="completed"||!L.winner_uuid)continue;const I=[L.team1_uuid,L.team2_uuid];if(I.includes(d)&&I.includes(k))return L.winner_uuid}return null},v=new Map;for(const d of m.values())v.set(d.wins,(v.get(d.wins)??0)+1);const N=Array.from(m.values()).sort((d,k)=>{if(k.wins!==d.wins)return k.wins-d.wins;if((v.get(d.wins)??0)===2){const L=o(d.uuid,k.uuid);if(L===d.uuid)return-1;if(L===k.uuid)return 1}return k.gameDiff!==d.gameDiff?k.gameDiff-d.gameDiff:k.pointDiff!==d.pointDiff?k.pointDiff-d.pointDiff:d.name.localeCompare(k.name)});if((T=_==null?void 0:_.ranked_team_uuids)!=null&&T.length){const d=new Map;return _.ranked_team_uuids.forEach((k,L)=>d.set(k,L)),[...N].sort((k,L)=>{const I=d.has(k.uuid)?d.get(k.uuid):Number.POSITIVE_INFINITY,A=d.has(L.uuid)?d.get(L.uuid):Number.POSITIVE_INFINITY;return I!==A?I-A:0})}return N},[s,_]);if(y.length===0)return null;const b=s.length>0&&s.every(m=>m.status==="completed");_==null||_.concluded;const f=(m,w)=>w===0?"—":m>0?`+${m}`:`${m}`,u=(m,w)=>w===0?"—":`${m}`,M=m=>m>=x?"":m===0?"bg-amber-400/10 border-l-2 border-l-amber-400/70":m===1?"bg-slate-300/10 border-l-2 border-l-slate-300/70":m===2?"bg-orange-700/10 border-l-2 border-l-orange-600/60":m===3?"bg-zinc-500/10 border-l-2 border-l-zinc-400/50":"",U={clinched_1st:{row:"bg-amber-500/15 border-l-2 border-l-amber-400",chipBg:"bg-amber-500/20 ring-1 ring-amber-400/50",chipText:"text-amber-300",icon:e.jsx(ur,{className:"h-2.5 w-2.5"}),label:"Clinched 1st"},clinched_playoff:{row:"bg-emerald-500/10 border-l-2 border-l-emerald-400/70",chipBg:"bg-emerald-500/20 ring-1 ring-emerald-400/50",chipText:"text-emerald-300",icon:e.jsx(dr,{className:"h-2.5 w-2.5"}),label:"Clinched playoff"},eliminated:{row:"opacity-55",chipBg:"bg-rose-500/20 ring-1 ring-rose-400/50",chipText:"text-rose-300",icon:e.jsx(cr,{className:"h-2.5 w-2.5"}),label:"Eliminated"}};return e.jsx("div",{className:"px-2 space-y-1.5",children:e.jsx("div",{className:"rounded-lg border border-border/50 overflow-hidden bg-muted/20",children:e.jsxs("table",{className:"w-full text-xs table-fixed",children:[e.jsxs("colgroup",{children:[e.jsx("col",{className:"w-12"}),e.jsx("col",{}),e.jsx("col",{className:"w-[12%]"}),e.jsx("col",{className:"w-[12%]"}),e.jsx("col",{className:"w-[12%]"}),e.jsx("col",{className:"w-[12%]"})]}),e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border/30 text-muted-foreground",children:[e.jsx("th",{className:"text-left py-1.5 px-2 font-semibold",children:"#"}),e.jsx("th",{className:"text-left py-1.5 px-2 font-semibold",children:"Team"}),e.jsx("th",{className:"text-center py-1.5 px-1 font-semibold",children:"W"}),e.jsx("th",{className:"text-center py-1.5 px-1 font-semibold",children:"L"}),e.jsx("th",{className:"text-center py-1.5 px-1 font-semibold",children:"GD"}),e.jsx("th",{className:"text-center py-1.5 px-1 font-semibold",children:"PD"})]})}),e.jsx("tbody",{children:y.map((m,w)=>{const o=j(m.uuid),v=o?U[o]:null;return e.jsxs("tr",{className:W("border-b border-border/20 last:border-0",v?v.row:M(w)),children:[e.jsx("td",{className:"py-1.5 pl-2 pr-1 text-muted-foreground font-score whitespace-nowrap",children:e.jsxs("span",{className:"inline-flex items-center gap-1 align-middle",children:[e.jsx("span",{className:"inline-block w-4 text-center tabular-nums",children:w+1}),e.jsx("span",{className:W("inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full",v?[v.chipBg,v.chipText]:"invisible"),title:v==null?void 0:v.label,"aria-label":v==null?void 0:v.label,children:(v==null?void 0:v.icon)??e.jsx("span",{className:"block h-2.5 w-2.5"})})]})}),e.jsx("td",{className:"py-1.5 px-2 font-medium text-foreground truncate",children:e.jsxs("button",{type:"button",onClick:()=>{window.dispatchEvent(new CustomEvent("mlp-open-team",{detail:{team_uuid:m.uuid,team_title:m.name}}))},className:"flex items-center gap-2 -my-0.5 py-0.5 text-left hover:text-primary transition-colors active:opacity-70 w-full min-w-0",children:[e.jsx(sn,{teamName:m.name,size:"sm",className:"h-4 w-4 shrink-0 ring-0 text-[8px]"}),e.jsx("span",{className:"truncate",children:aa(m.name)})]})}),e.jsx("td",{className:"text-center py-1.5 px-1 font-score text-green-500 tabular-nums",children:u(m.wins,m.
1wins+m.losses)}),e.jsx("td",{className:"text-center py-1.5 px-1 font-score text-red-400 tabular-nums",children:u(m.losses,m.wins+m.losses)}),e.jsx("td",{className:"text-center py-1.5 px-1 font-score text-muted-foreground tabular-nums",children:f(m.gameDiff,m.wins+m.losses)}),e.jsx("td",{className:"text-center py-1.5 px-1 font-score text-muted-foreground tabular-nums",children:f(m.pointDiff,m.wins+m.losses)})]},m.uuid)})})]})})})}const Js={"atlanta bouncers":"Atlanta","bay area breakers":"Bay Area","brooklyn pickleball team":"Brooklyn","california black bears":"California","carolina hogs":"Carolina","chicago slice":"Chicago","columbus sliders":"Columbus","dallas flash":"Dallas","florida smash":"Florida","las vegas night owls":"Las Vegas","los angeles mad drops":"Los Angeles","miami pickleball club":"Miami","new jersey 5s":"New Jersey","orlando squeeze":"Orlando","palm beach royals":"Palm Beach","phoenix flames":"Phoenix","so cal hard 8s":"SoCal","socal hard eights":"SoCal","so cal hard eights":"SoCal","carolina pickleball 5s":"Carolina","new jersey 5's":"New Jersey","d.c. pickleball team":"D.C.","st. louis shock":"St. Louis","texas ranchers":"Texas","utah black diamonds":"Utah"};function aa(s){if(!s)return"TBD";const a=s.trim().toLowerCase();if(Js[a])return Js[a];const h=s.trim().split(/\s+/);return h.length>1?h.slice(0,-1).join(" "):s}const oa="all",cs=s=>(s||"").toUpperCase();function la(s){const{matchups:a}=Je(s||""),h=or();return{courts:c.useMemo(()=>{var y;const l=new Map;for(const b of a){if(b.status==="completed"||b.status==="placeholder")continue;const f=((y=b.details)==null?void 0:y.court)||null,M=(f?lr(f,s||"",h):null)||"Unassigned",U=M.toLowerCase();l.has(U)||l.set(U,M)}const _=b=>{const f=b.toUpperCase();return f==="CC"?0:f==="GS"?1:f==="UNASSIGNED"?99:50},j=Array.from(l.entries()).sort(([,b],[,f])=>{const u=_(b),M=_(f);return u!==M?u-M:b.localeCompare(f)}).map(([b,f])=>({key:b,label:f,fullLabel:cs(f)}));return j.length>1?[{key:oa,label:"ALL",fullLabel:"ALL"},...j]:j},[a,h,s])}}function ia({matchups:s,tournamentId:a,tournamentName:h,broadcastUrl:x,broadcastProvider:l,sponsors:_,onMatchClick:j,standingsLookup:y,activeCourtKey:b,onActiveCourtChange:f,hideCourtToggle:u}){const M=c.useMemo(()=>{var L;const R=new Map;for(const I of s){if(I.status==="completed"||I.status==="placeholder")continue;const A=((L=I.details)==null?void 0:L.court)||null,F=(A?lr(A,a,_):null)||"Unassigned",K=F.toLowerCase();R.has(K)||R.set(K,{label:F,rows:[]}),R.get(K).rows.push(I)}const T=(I,A)=>{var X,re;const se=I.scheduled_at?new Date(I.scheduled_at).getTime():Number.POSITIVE_INFINITY,F=A.scheduled_at?new Date(A.scheduled_at).getTime():Number.POSITIVE_INFINITY;if(se!==F)return se-F;const K=I.match_number??((X=I.details)==null?void 0:X.match_number)??0,J=A.match_number??((re=A.details)==null?void 0:re.match_number)??0;return K-J};for(const I of R.values())I.rows.sort(T);const d=Array.from(R.values()),k=I=>{const A=I.toUpperCase();return A==="CC"?0:A==="GS"?1:A==="UNASSIGNED"?99:50};if(d.sort((I,A)=>{const se=k(I.label),F=k(A.label);return se!==F?se-F:I.label.localeCompare(A.label)}),d.length>1){const I=d.flatMap(A=>A.rows).slice().sort(T);d.unshift({label:"ALL",rows:I})}return d},[s,_,a]),U=typeof b=="string",[m,w]=c.useState(""),o=U?b:m;if(c.useEffect(()=>{U||M.length!==0&&(!m||!M.some(R=>R.label.toLowerCase()===m))&&w(M[0].label.toLowerCase())},[M,m,U]),M.length===0)return e.jsx(ht,{className:"p-8 text-center text-sm text-muted-foreground",children:"No matches scheduled yet."});const v=M.find(R=>R.label.toLowerCase()===o)||M[0],N=R=>{U?f==null||f(R):w(R)};return e.jsxs("div",{className:"space-y-3",children:[!u&&M.length>1&&e.jsx("div",{className:"grid w-full rounded-full bg-muted/40 border border-border/40 p-0.5",style:{gridTemplateColumns:`repeat(${M.length}, minmax(0, 1fr))`},children:M.map(R=>{const T=R.label.toLowerCase(),d=T===v.label.toLowerCase();return e.jsx("button",{type:"button",onClick:()=>N(T),className:W("px-3 py-1.5 rounded-full text-[11px] font-player uppercase tracking-wider transition-colors whitespace-nowrap truncate",d?"bg-primary text-primary-foreground":"text-muted-foreground"),children:cs(R.label)},T)})}),!u&&M.length===1&&e.jsxs("div",{className:"px-2 flex items-center justify-center gap-2 py-1",children:[e.jsx(tr,{className:"h-3.5 w-3.5 text-muted-foreground"}
1),e.jsx("h4",{className:"font-score text-sm tracking-wider uppercase text-foreground leading-none",children:cs(v.label)})]}),e.jsx("div",{className:"space-y-2",children:v.rows.map(R=>e.jsx(ds,{row:{...R,tournament_id:a,tournament_name:h,broadcast_url:x,broadcast_provider:l},sponsors:_,viewMode:"compact",onMatchClick:j,standingsLookup:y},R.id))})]})}const qt="all";function ca(){const{data:s}=ke({queryKey:["app_settings","ppa_schedule_enabled"],staleTime:3e5,queryFn:async()=>{const{data:a}=await le.from("app_settings").select("value").eq("key","ppa_schedule_enabled").maybeSingle();return a?(a.value||"").toString().toLowerCase()!=="false":!0}});return s??!1}const Xs=s=>{const a=s.time?new Date(s.time).getTime():NaN;return Number.isFinite(a)?a:Number.POSITIVE_INFINITY};function xr(s,a=!0){const{data:h,isLoading:x}=ke({queryKey:["ppa-schedule-matches",s],enabled:!!s&&s!=="most_recent"&&a,staleTime:6e4,refetchInterval:6e4,queryFn:async()=>{const{data:l,error:_}=await le.from("brackets").select("id").eq("tournament_id",s);if(_)throw _;const j=(l||[]).map(f=>f.id);if(j.length===0)return[];const{data:y,error:b}=await le.from("matches").select("id, tournament, round, event, team1, team2, games, current_game, best_of, court, status, time, details, is_qualifier, is_challenger").in("bracket_id",j).neq("status","completed");if(b)throw b;return y||[]}});return{matches:h||[],isLoading:x}}const At=s=>{const a=s.toUpperCase();if(a==="CC")return 0;if(a==="GS")return 1;if(a==="UNASSIGNED")return 99;const h=a.match(/(\d+)/);return h?10+Number(h[1]):50},It=s=>sr(s.court)||"Unassigned";function br(s,a=!0){const{matches:h}=xr(s,a);return{courts:c.useMemo(()=>{const l=new Map;for(const j of h){const y=It(j),b=y.toLowerCase();l.has(b)||l.set(b,y)}const _=Array.from(l.entries()).sort(([,j],[,y])=>{const b=At(j),f=At(y);return b!==f?b-f:j.localeCompare(y)}).map(([j,y])=>({key:j,label:y,fullLabel:y.toUpperCase()}));return _.length>1?[{key:qt,label:"ALL",fullLabel:"ALL"},..._]:_},[h])}}function da({tournamentId:s,activeCourtKey:a,onMatchClick:h,tournamentDateLabel:x,tierLabel:l}){var U,m;const{matches:_,isLoading:j}=xr(s),{courts:y}=br(s),b=a||((U=y[0])==null?void 0:U.key)||qt,{liveRows:f,rows:u}=c.useMemo(()=>{const w=b===qt?_:_.filter(v=>It(v).toLowerCase()===b),o=(v,N)=>{const R=Xs(v),T=Xs(N);return R!==T?R-T:At(It(v))-At(It(N))};return{liveRows:w.filter(v=>v.status==="live").sort(o),rows:w.filter(v=>v.status!=="live").sort(o)}},[_,b]);if(!j&&_.length===0)return e.jsx(ht,{className:"p-8 text-center text-sm text-muted-foreground",children:"No matches scheduled yet."});const M=((m=y.find(w=>w.key===b))==null?void 0:m.fullLabel)||"SCHEDULE";return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"px-2 pt-4 pb-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground tracking-wider uppercase",children:M==="ALL"?"Order of Play":M}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[l&&e.jsx("span",{title:l,className:"text-[10px] font-semibold tracking-wider uppercase whitespace-nowrap bg-accent text-accent-foreground px-2 py-0.5 rounded-full",children:l}),x&&e.jsx("span",{className:"text-[10px] font-semibold tracking-wider uppercase text-muted-foreground/70 whitespace-nowrap bg-muted/50 px-2 py-0.5 rounded-full border border-border/30",children:x})]})]}),e.jsx("div",{className:"h-0.5 bg-primary/30 mt-2 rounded-full"})]}),f.length>0&&e.jsxs("div",{className:"flex flex-col gap-2 px-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary animate-pulse"}),e.jsx("span",{className:"text-[10px] font-semibold tracking-wider uppercase text-muted-foreground",children:"On Court Now"})]}),f.map(w=>e.jsx(ir,{match:w,onClick:()=>h==null?void 0:h(w)},w.id))]}),e.jsxs("div",{className:"flex flex-col gap-2 px-1 pb-5",children:[f.length>0&&u.length>0&&e.jsx("span",{className:"px-1 text-[10px] font-semibold tracking-wider uppercase text-muted-foreground
1/70",children:"Up Next"}),u.map(w=>e.jsx(us,{team1:w.team1,team2:w.team2,status:"upcoming",size:"sm",isMobile:!0,round:w.round,event:w.event,matchId:w.id,time:w.time,tournament:w.tournament,court:w.court,details:w.details,onClick:()=>h==null?void 0:h(w)},w.id))]})]})}try{sessionStorage.removeItem("brackets_cold_open_synced"),sessionStorage.removeItem("brackets_selectedTournament")}catch{}function ua(s,a,h,x){return s&&s.includes("brackets.pickleballtournaments.com")?s:h&&a?`https://brackets.pickleballtournaments.com/tournaments/${h}/events/${a.toUpperCase()}/overview`:s}let Zs=!1,Ye=null;const ma=(s,a=!1)=>{var fe,Xe,Fe,Ze,Te,We;if(!s||!Array.isArray(s)||s.length===0)return null;const h=i=>!i||i.length===0?!0:i.every(B=>!B||B.toUpperCase()==="TBD");let x=s;if(a){const i=s.filter(B=>!(h(B.team1)&&h(B.team2)));x=i.length>0?i:s}const l=x.filter(i=>{var B;return((B=i.round)==null?void 0:B.startsWith("Pool Play"))||i.round==="Round Robin"}),_=x.filter(i=>i.round==="R128"||i.round==="Round 128"||i.round==="Round of 128"),j=x.filter(i=>i.round==="R64"||i.round==="Round 64"||i.round==="Round of 64"),y=x.filter(i=>i.round==="R32"||i.round==="Round 32"||i.round==="Round of 32"),b=x.filter(i=>i.round==="R16"||i.round==="Round 16"||i.round==="Round of 16"),f=x.filter(i=>i.round==="Quarterfinals"||i.round==="QF"),u=x.filter(i=>i.round==="Semifinals"||i.round==="SF"),M=x.filter(i=>i.round==="Finals"||i.round==="Gold Medal"||i.round==="F"),U=x.filter(i=>i.round==="Bronze Medal"||i.round==="Third Place"||i.round==="BR"),m=new Set([128,64,32,16]),w=x.filter(i=>{const B=(i.round||"").match(/^Round (\d+)$/);if(!B)return!1;const S=parseInt(B[1]);return!m.has(S)});let o=null;if(w.length>0){const i=Math.max(...w.map(B=>{var S;
1return parseInt(((S=B.round)==null?void 0:S.replace("Round ",""))||"0")}));if(i>=5){const B=w.filter(S=>S.round===`Round ${i}`);o=B.find(S=>S.status==="completed")||B[0]}}let v=null,N=null;const R=M.filter(i=>{var B,S;return i.status==="completed"&&((B=i.team1)==null?void 0:B.length)>0&&((S=i.team2)==null?void 0:S.length)>0}),T=M.filter(i=>{var B,S;return i.status!=="completed"||!((B=i.team1)!=null&&B.length)||!((S=i.team2)!=null&&S.length)}),k=(()=>{const i=[];return u.forEach(B=>{var S,Q,V;if(B.status==="completed"&&((S=B.games)==null?void 0:S.length)>0){let H=0,oe=0;B.games.forEach(be=>{(be.team1Score||0)>(be.team2Score||0)?H++:(be.team2Score||0)>(be.team1Score||0)&&oe++}),H>oe&&((Q=B.team1)==null?void 0:Q.length)>0?i.push(B.team1):oe>H&&((V=B.team2)==null?void 0:V.length)>0&&i.push(B.team2)}}),i})(),L=i=>{if(!k.length)return!1;const B=[...i.team1||[],...i.team2||[]];return k.some(S=>S.every(Q=>B.includes(Q)))},I=[...R,...T],A=I.find(L),se=I.find(i=>!L(i));if(A?(v=A,N=se||null):I.length>=1&&(v=I[0],N=I[1]||null),!N||!((fe=N.team1)!=null&&fe.length)||!((Xe=N.team2)!=null&&Xe.length)||N.status==="upcoming"){if(U.length>0){const B=U.find(S=>{var Q,V;return S.status==="completed"&&((Q=S.team1)==null?void 0:Q.length)>0&&((V=S.team2)==null?void 0:V.length)>0});if(B)N=B;else{const S=U.find(Q=>{var V,H;return((V=Q.team1)==null?void 0:V.length)>0&&((H=Q.team2)==null?void 0:H.length)>0&&!h(Q.team1)&&!h(Q.team2)});S&&(N=S)}}(!N||!((Fe=N.team1)!=null&&Fe.length)||!((Ze=N.team2)!=null&&Ze.length)||N.status==="upcoming"&&(h(N.team1)||h(N.team2)))&&o&&((Te=o.team1)==null?void 0:Te.length)>0&&((We=o.team2)==null?void 0:We.length)>0&&(N=o)}let K=0;const J=()=>({id:`empty-placeholder-${++K}`,team1:[],team2:[],winner:void 0,score:"",status:"upcoming",tournament:"",round:"",event:"",games:[],current_game:null,best_of:3,court:"",time:"",details:null}),X=()=>{let i=0,B=0,S=0,Q=0,V=0,H=0;return _.length>0?(i=j.length>0?j.length:Math.ceil(_.length/2),B=y.length>0?y.length:Math.ceil(i/2),S=b.length>0?b.length:Math.ceil(B/2),Q=f.length>0?f.length:Math.ceil(S/2),V=u.length>0?u.length:2,H=1):j.length>0?(B=y.length>0?y.length:Math.ceil(j.length/2),S=b.length>0?b.length:Math.ceil(B/2),Q=f.length>0?f.length:Math.ceil(S/2),V=u.length>0?u.length:2,H=1):y.length>0?(B=y.length,S=b.length>0?b.length:Math.ceil(y.length/2),Q=f.length>0?f.length:Math.ceil(S/2),V=u.length>0?u.length:2,H=1):b.length>0?(S=b.length,Q=f.length>0?f.length:Math.ceil(b.length/2),V=u.length>0?u.length:2,H=1):f.length>0?(Q=f.length,V=u.length>0?u.length:2,H=1):u.length>0&&(V=u.length,H=1),{r64Count:i,r32Count:B,r16Count:S,qfCount:Q,sfCount:V,fCount:H}},{r64Count:re,r32Count:He,r16Count:Ne,qfCount:ee,sfCount:xe,fCount:Se}=X(),ce=i=>{var be,pt,Dt,ve,Me,et,gt;if(!i)return null;const B=((be=i.details)==null?void 0:be.forfeit)===!0;let S;if(B)(pt=i.details)!=null&&pt.winner?S=i.details.winner:(Dt=i.details)!=null&&Dt.winnerTeam?S=i.details.winnerTeam:((ve=i.details)==null?void 0:ve.withdrawingTeam)==="team1"?S=2:((Me=i.details)==null?void 0:Me.withdrawingTeam)==="team2"&&(S=1);else{const ne=(et=i.games)==null?void 0:et.reduce((xt,qe)=>({team1:xt.team1+(qe.team1Score>qe.team2Score?1:0),team2:xt.team2+(qe.team2Score>qe.team1Score?1:0)}),{team1:0,team2:0});S=(ne==null?void 0:ne.team1)>(ne==null?void 0:ne.team2)?1:(ne==null?void 0:ne.team2)>(ne==null?void 0:ne.team1)?2:void 0}const Q=Array.isArray(i.games)&&i.games.length>0,V=B&&S!==void 0,H=B&&!V&&!Q&&i.status==="completed"?"upcoming":i.status,oe=V?"W.O.":((gt=i.games)==null?void 0:gt.map(ne=>`${ne.team1Score}-${ne.team2Score}`).join(", "))||"";return{id:i.id,team1:i.team1,team2:i.team2,winner:S,score:oe,status:H,tournament:i.tournament,round:i.round,event:i.event,games:i.games,current_game:i.current_game,best_of:i.best_of,court:i.court,time:i.time,details:i.details}},ue=(i,B)=>{const S=[...i.map(ce)];for(;S.length<B;)S.push(J());return S};return{poolPlay:l.map(ce),r128:_.map(ce),r64:ue(j,re),r32:ue(y,He),r16:ue(b,Ne),quarterfinals:ue(f,ee),semifinals:ue(u,xe),final:v||Se>0?v?ce(v):J():null,thirdPlace:(()=>{var B,S;return l.length>0?!!N&&((B=N.team1)==null?void 0:B.length)>0&&((S=N.team2)==null?void 0:S.length)>
10&&!h(N.team1)&&!h(N.team2)&&(N.round==="BR"||N.round==="Bronze Medal"||N.round==="Third Place"||N.status==="completed")?ce(N):null:N||Se>0?N?ce(N):J():null})()}},ja=()=>{var Ls,Es,Bs,Is,Fs;const s=rn(),{userId:a}=rr(),x=Dr().pathname==="/brackets",l=Bt.isNativePlatform()&&Bt.getPlatform()==="ios",_=Bt.isNativePlatform()&&Bt.getPlatform()==="android",j=typeof navigator<"u"&&(/iPad/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1),y=nn(),b=c.useRef(null),f=c.useRef(null),u=c.useRef(null),[M,U]=c.useState(()=>typeof window<"u"&&sessionStorage.getItem("brackets_selectedEventType")||"Men's Doubles"),[m,w]=c.useState(()=>{if(typeof window<"u"){const t=sessionStorage.getItem("brackets_selectedBracketType");return t==="main"||t==="qualifier"?t:"main"}return"main"}),[o,v]=c.useState(()=>{if(typeof window<"u"){const t=sessionStorage.getItem("brackets_selectedTournament");if(t&&t!=="most_recent")return t}return"most_recent"}),[N,R]=c.useState(()=>typeof window<"u"&&sessionStorage.getItem("brackets_selectedTournamentName")||null),[T,d]=c.useState(()=>{if(typeof window<"u"){const t=sessionStorage.getItem("brackets_lastIsMlp");if(t==="true")return!0;if(t==="false")return!1}return null}),[k,L]=c.useState(!1),[I,A]=c.useState(null),[se,F]=c.useState(!1),[K,J]=c.useState(!1),[X,re]=c.useState(!1),[He,Ne]=c.useState(!1),[ee,xe]=c.useState({atStart:!0,atEnd:!1}),[Se,ce]=c.useState(null),[ue,fe]=c.useState(!1),[Xe,Fe]=c.useState(!1),[Ze,Te]=c.useState(!1),[We,i]=c.useState(!1),[B,S]=c.useState(null),[Q,V]=c.useState(!1),H=nr(),[oe,be]=c.useState(null),[pt,Dt]=c.useState(!1),[ve,Me]=c.useState(()=>typeof window<"u"&&sessionStorage.getItem("brackets_selectedRound")||null),[et,gt]=c.useState(88),ne=an(N||""),xt=on(oe?[oe]:[]);c.useEffect(()=>{(async()=>{var r;try{const n=typeof window<"u"&&!sessionStorage.getItem("brackets_selectedTournament"),[P,p,g,E,z,$]=await Promise.all([te.getItem("brackets_selectedEventType"),te.getItem("brackets_selectedBracketType"),te.getItem("brackets_selectedTournament"),te.getItem("brackets_selectedTournamentName"),te.getItem("brackets_lastIsMlp"),n?le.from("app_settings").select("value").eq("key","brackets_default_tournament_id").maybeSingle():Promise.resolve(null)]),Y=(((r=$==null?void 0:$.data)==null?void 0:r.value)||"").trim()||null;P&&U(P),(p==="main"||p==="qualifier")&&w(p),n&&Y?(v(Y),R(null)):(g&&g!=="most_recent"&&v(g),E&&R(E)),z==="true"?d(!0):z==="false"&&d(!1),console.log("[Brackets] Loaded persisted selections:",{storedEvent:P,storedBracket:p,storedTournament:g,storedTournamentName:E})}catch(n){console.error("[Brackets] Failed to load persisted selections:",n)}finally{L(!0)}})()},[]),c.useEffect(()=>{k&&(sessionStorage.setItem("brackets_selectedEventType",M),te.setItem("brackets_selectedEventType",M))},[M,k]),c.useEffect(()=>{k&&(sessionStorage.setItem("brackets_selectedBracketType",m),te.setItem("brackets_selectedBracketType",m))},[m,k]),c.useEffect(()=>{k&&ve&&sessionStorage.setItem("brackets_selectedRound",ve)},[ve,k]),c.useEffect(()=>{k&&(o&&o!=="most_recent"&&(sessionStorage.setItem("brackets_selectedTournament",o),te.setItem("brackets_selectedTournament",o)),N&&(sessionStorage.setItem("brackets_selectedTournamentName",N),te.setItem("brackets_selectedTournamentName",N)))},[o,N,k]);const{data:qe}=ln(),{didDragRef:yr}=cn(f,{enabled:_,threshold:8,dominanceRatio:1.1}),$e=Rn(),{mostRecentTournament:G,getTournamentById:ms,isLoading:fs}=ar(),D=c.useMemo(()=>{if(!o||o==="most_recent")return null;const t=ms(o);return t?{name:t.name,start_date:t.start_date,end_date:t.end_date??null,is_mlp:!!t.is_mlp,mlp_format:t.mlp_format??null}:null},[o,ms]),Ot=c.useMemo(()=>{const t=ne||(D==null?void 0:D.name)||null;if(!k||!G)return t;if(!o||o==="most_recent")return G.name;if(o===G.id)return t||G.name;let r=!1;try{r=sessionStorage.getItem("brackets_cold_open_synced")==="1"}catch{}if(r)return t;const n=D==null?void 0:D.start_date,P=D==null?void 0:D.end_date;if(n&&P){const p=new Date().toISOString().slice(0,10);if(n<=p&&P>=p)return t}return G.name},[ne,D,k,G,o]),hs=zn((D==null?void 0:D.name)||Ot),O=D?!!D.is_mlp:T??!1;c.useEffect(()=>{if(!D)return;const t=D.is_mlp?"true":"false";try{sessionStorage.setItem("brackets_lastIsMlp",t)}catch{}te.setItem("brackets_lastIsMlp",t),d(!!D.is_mlp)},[D]);const{rounds:he}=gr(O?o:null),[tt,bt]=c.useState("");c.useEffect(()=>
1{if(!O||he.length===0||tt&&he.some(P=>P.key===tt))return;const t=he.find(P=>P.matchups.some(p=>p.status==="in_progress")),r=he.find(P=>P.key==="playoff"),n=[...he].reverse().find(P=>P.matchups.some(p=>p.status==="upcoming"||p.status==="in_progress"));bt((t==null?void 0:t.key)||(r==null?void 0:r.key)||(n==null?void 0:n.key)||he[0].key)},[O,he,tt]),c.useEffect(()=>{bt("")},[o]);const[we,yt]=c.useState("bracket");c.useEffect(()=>{yt("bracket")},[o]);const{courts:Pe}=la(O?o:null),[st,wt]=c.useState("");c.useEffect(()=>{wt("")},[o]),c.useEffect(()=>{!O||we!=="order"||Pe.length!==0&&(!st||!Pe.some(t=>t.key===st))&&wt(Pe[0].key)},[O,we,Pe,st]);const kt=c.useMemo(()=>{if(!O||he.length===0)return!1;const t=he.flatMap(r=>r.matchups);return t.length===0?!1:t.every(r=>r.status==="completed")},[O,he]),Wt=Pe.length>0;c.useEffect(()=>{(kt||!Wt)&&we==="order"&&yt("bracket")},[kt,Wt,we]);const $t=O&&!kt&&Wt,rt=Xn(O?o:null),{matchups:ps}=Je(O&&rt?o:""),wr=c.useMemo(()=>!O||!rt?!1:ps.some(t=>t.stage==="double_elim"&&t.status!=="placeholder"&&!!t.team1_uuid&&!!t.team2_uuid),[O,rt,ps]),gs=O&&rt&&we==="bracket"&&wr,Ut=O&&!rt&&he.length>1&&we==="bracket",zt=O&&!kt&&we==="order"&&Pe.length>1,vt=gs?124:Ut||zt?82:38,Kt=ca(),[Ue,_t]=c.useState("bracket");c.useEffect(()=>{_t("bracket")},[o]);const{courts:Re}=br(!O&&Kt?o:null,!O&&Kt),[nt,Qt]=c.useState("");c.useEffect(()=>{Qt("")},[o]),c.useEffect(()=>{O||Ue!=="order"||Re.length!==0&&(!nt||!Re.some(t=>t.key===nt))&&Qt(Re[0].key)},[O,Ue,Re,nt]);const jt=!O&&Kt&&Re.length>0;c.useEffect(()=>{!jt&&Ue==="order"&&_t("bracket")},[jt,Ue]);const _e=!O&&Ue==="order"&&jt,Ht=_e&&Re.length>1,ze=!O&&_e?Ht?-14:-50:0,at=c.useMemo(()=>{const t=D==null?void 0:D.start_date;if(!t)return null;try{const r=new Date(t+"T00:00:00"),n=r.toLocaleString("en-US",{month:"short"}),P=String(r.getFullYear()).slice(2);return`${n} '${P}`}catch{return null}},[D==null?void 0:D.start_date]),{data:je}=ke({queryKey:["available-brackets",o],queryFn:async()=>{if(!o||o==="most_recent")return null;const{data:t,error:r}=await le.from("brackets").select("event_type, is_qualifier, has_matches").eq("tournament_id",o).eq("has_matches",!0);if(r)throw r;return t},enabled:x&&!!o&&o!=="most_recent",staleTime:5*60*1e3}),Gt=["Men's Doubles","Women's Doubles","Mixed Doubles","Men's Singles","Women's Singles"],Ae=c.useRef(null);c.useEffect(()=>{G&&o==="most_recent"&&(console.log("[Brackets] Auto-selecting most recent tournament:",G.name),v(G.id),R(G.name),sessionStorage.setItem("brackets_selectedTournament",G.id),sessionStorage.setItem("brackets_selectedTournamentName",G.name))},[G,o]),c.useEffect(()=>{if(!k||!G||!o||o==="most_recent")return;try{if(sessionStorage.getItem("brackets_cold_open_synced")==="1")return}catch{}if(o===G.id){try{sessionStorage.setItem("brackets_cold_open_synced","1")}catch{}return}const t=D==null?void 0:D.start_date,r=D==null?void 0:D.end_date,n=new Date().toISOString().slice(0,10),P=!!r&&r<n,p=!!t&&t>n;if(t&&r){const g=t<=n,E=r>=n;if(g&&E)return}if(p){const g=G.start_date;if(!(!!g&&!!t&&g<t)){try{sessionStorage.setItem("brackets_cold_open_synced","1")}catch{}return}}else if(P)try{sessionStorage.setItem("brackets_cold_open_synced","1")}catch{}else{try{sessionStorage.setItem("brackets_cold_open_synced","1")}catch{}return}console.log("[Brackets] Cold-open sync: switching from",N,"to current tournament",G.name),v(G.id),R(G.name),Ae.current=null,sessionStorage.setItem("brackets_selectedTournament",G.id),sessionStorage.setItem("brackets_selectedTournamentName",G.name),te.setItem("brackets_selectedTournament",G.id),te.setItem("brackets_selectedTournamentName",G.name)},[k,G,o,N,D==null?void 0:D.start_date,D==null?void 0:D.end_date]),c.useEffect(()=>{G&&(!o||o==="most_recent"||o!==G.id&&(O||je!=null&&je.length===0&&(console.log("[Brackets] Persisted tournament has no brackets, falling back to most recent:",G.name),v(G.id),R(G.name),Ae.current=null,sessionStorage.setItem("brackets_selectedTournament",G.id),sessionStorage.setItem("brackets_selectedTournamentName",G.name))))},[je,o,G,O]);const xs=(t,r)=>{try{sessionStorage.setItem("brackets_cold_open_synced","1")}catch{}v(t),R(r??null)};c.useEffect(()=>{if(!je||je.length===0||!o||o==="most_recent"||!k||Ae.current===o)return;if(M==="MLP"?O&&je.some(g=>g.event_type==="MLP"):je.some(g=>g.event_type===M&&g.is_qualifier===(m==="qualifier"))){console.log("[Brackets] Respecting user persisted selection:",M,m),Ae.current=o;return}const r=je.filter(g=>!g.is_qualifier),n=je.filter(g=>g.is_qualifier);for(const g of Gt)if(r.some(E=>E.event_type===g)){console.log("[Brackets] Auto-selecting event type (main):",g),U(g),w("main"),Ae.current=o;return}for(const g of Gt)if(n.some(E=>E.event_type===g)){console.log("[Brackets] Auto-selecting event type (qualifier):",g),U(g),w("qualifier"),Ae.current=o;return}const P=r.filter(g=>g.event_type!=="MLP"),p=n.filter(g=>g.event_type!=="MLP");P.length>0?(console.log("[Brackets] Fallback to first main bracket:",P[0].event_type),U(P[0].event_type),w("main")):p.length>0?(console.log("[Brackets] Fallback to first qualifier bracket:",p[0].event_type),U(p[0].event_type),w("qualifier")):O&&r.length>0&&(U(r[0].event_type),w("main")),Ae.current=o},[je,o,k,M,m,O]);const bs=c.useRef(o);c.useEffect(()=>{re(!1),J(!1),bs.current!==o&&(Ae.current=null,bs.current=o)},[o,M,m]),c.useEffect(()=>{let t,r;return(async()=>{s&&(await te.getItem("bracket-scroll-hint-seen")||(await te.setItem("bracket-scroll-hint-seen","true"),t=setTimeout(()=>{Ne(!0)},1e3),r=setTimeout(()=>{Ne(!1)},6e3)))})(),()=>{t&&clearTimeout(t),r&&clearTimeout(r)}},[s]),c.useEffect(()=>{if(!s)return;const t=()=>{const r=window.scrollY;fe(r<=10)};return window.addEventListener("scroll",t,{passive:!0}),fe(!1),()=>window.removeEventListener("scroll",t)},[s]);const Nt=c.useRef(!1),ot=c.useRef(null),ys=c.useRef(0),kr=c.useRef(!1);c.useEffect(()=>{const t=f.current;if(!t||!s)return;const r=()=>{Nt.current=!0,kr.current=!0,ot.current&&clearTimeout(ot.current)},n=()=>{ot.current=setTimeout(()=>{Nt.current=!1},150)};return t.addEventListener("touchstart",r,{passive:!0}),t.addEventListener("touchend",n,{passive:!0}),t.addEventListener("wheel",r,{passive:!0}),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",n),t.removeEventListener("wheel",r),ot.current&&clearTimeout(ot.current)}},[s]);const ws=t=>{const r=t.scrollLeft+t.clientWidth/2,n=Array.from(t.querySelectorAll("[data-round-index]"));let P=null,p=Number.POSITIVE_INFINITY;for(const g of n){const E=Number(g.dataset.roundIndex);if(!Number.isFinite(E))continue;const z=g.offsetLeft+g.offsetWidth/2,$=Math.abs(z-r);$<p&&(p=$,P=E)}return P};c.useEffect(()=>{const t=f.current;if(!t||!s)return;const r=()=>{_&&Nt.current&&(ys.current=Date.now()),!K&&Nt.current&&(J(!0),Ne(!1));const{scrollLeft:E,scrollWidth:z,clientWidth:$}=t;xe({atStart:E===0,atEnd:E+$>=z-1});const Y=ws(t);Y!==null&&ce(Y)};t.addEventListener("scroll",r);const{scrollLeft:n,scrollWidth:P,clientWidth:p}=t;xe({atStart:n===0,atEnd:n+p>=P-1});const g=ws(t);return g!==null&&ce(g),()=>t.removeEventListener("scroll",r)},[K,s,_]);const[Ke,ks]=c.useState(()=>{var t,r,n,P,p;if(typeof window>"u")return null;try{const g=window.localStorage.getItem("bracket-data-cache");if(!g)return null;const E=JSON.parse(g),z=((t=E==null?void 0:E.bracket)==null?void 0:t.tournament_name)??((n=(r=E==null?void 0:E.bracket)==null?void 0:r.tournaments)==null?void 0:n.name)??((p=(P=E==null?void 0:E.matches)==null?void 0:P[0])==null?void 0:p.tournament)??null;if(z)try{sessionStorage.setItem("brackets_selectedTournamentName",z)}catch{}return E}catch{return null}}),[St,Vt]=c.useState(()=>{if(typeof window>"u")return!1;try{return!!window.localStorage.getItem("bracket-data-cache")}catch{return!1}}),[vs,Yt]=c.useState(()=>{if(typeof window>"u")return null;try{const t=window.localStorage.getItem("bracket-cache-timestamp");return t?parseInt(t,10):null}catch{return null}});c.useEffect(()=>{if(Ke)return;(async()=>{var P,p,g,E,z;const[r,n]=await Promise.all([te.getItem("bracket-data-cache"),te.getItem("bracket-cache-timestamp")]);if(r)try{const $=JSON.parse(r);ks($),Vt(!0),Yt(n?parseInt(n,10):null);const Y=((P=$==null?void 0:$.bracket)==null?void 0:P.tournament_name)??((g=(p=$==null?void 0:$.bracket)==null?void 0:p.tournaments)==null?void 0:g.name)??((z=(E=$==null?void 0:$.matches)==null?void 0:E[0])==null?void 0:z.tournament)??null;Y&&R(Y);try{window.localStorage.setItem("bracket-data-cache",r),n&&window.localStorage.setItem("bracket-cache-timestamp",n)}catch{}console.log("[Brackets] Loaded cached data for instant display")}catch($){console.error("[Brackets] Failed to parse cached data:",$)}})()}
1,[Ke]);const vr=vs&&Date.now()-vs<6e4,{data:Le}=ke({queryKey:["bracket-version-check",o],queryFn:async()=>{if(!o||o==="most_recent")return null;const{data:t,error:r}=await le.from("brackets").select("id, is_qualifier, event_type").eq("tournament_id",o);if(r)throw r;return t?`${t.length}-${t.map(P=>`${P.event_type}:${P.is_qualifier}`).sort().join(",")}`:"empty"},enabled:x&&!vr&&!!o&&o!=="most_recent",staleTime:6e4,refetchOnWindowFocus:!1});c.useEffect(()=>{(async()=>{if(!Le||!Ke)return;const r=await te.getItem("bracket-cache-version");if(r&&r!==Le){console.log("[Brackets] Cache invalidated - new brackets detected:",{cached:r,current:Le}),ks(null),Vt(!1),Yt(null);try{window.localStorage.removeItem("bracket-data-cache"),window.localStorage.removeItem("bracket-cache-version"),window.localStorage.removeItem("bracket-cache-timestamp")}catch{}await Promise.all([te.removeItem("bracket-data-cache"),te.removeItem("bracket-cache-version"),te.removeItem("bracket-cache-timestamp")])}})()},[Le,Ke]);const _s=!!o&&o!=="most_recent",Jt=!_s&&!G,[_r,Xt]=c.useState(!1),De=c.useRef(null),{data:q,isLoading:Ee,error:Ce,refetch:Ct,isFetching:Be}=ke({queryKey:["bracket",M,o,m],enabled:x&&_s,retry:1,retryDelay:500,staleTime:30*60*1e3,gcTime:60*60*1e3,refetchOnWindowFocus:!1,refetchOnMount:!1,queryFn:async()=>{var r,n,P,p,g;const t=performance.now();console.log("[Brackets Query] START",{eventType:M,tournamentId:o,bracketType:m,timestamp:new Date().toISOString()});try{const{data:E,error:z}=await le.from("brackets").select("*, tournaments!inner(name, tournament_tier, pblfg_tournament_uuid, tournament_slug)").eq("event_type",M).eq("tournament_id",o);if(z)throw console.error("[Brackets Query] Bracket fetch error:",z),z;console.log("[Brackets Query] Found brackets:",(E==null?void 0:E.length)??0,"in",Math.round(performance.now()-t),"ms");const $=(E??[]).filter(Oe=>Oe.has_matches!==!1),Y=new globalThis.Map;if($.length>1){const{data:Oe,error:Ge}=await le.from("matches").select("bracket_id").in("bracket_id",$.map(Ve=>Ve.id));Ge?console.warn("[Brackets Query] Bracket match-count check failed:",Ge.message):(Oe||[]).forEach(Ve=>{Y.set(Ve.bracket_id,(Y.get(Ve.bracket_id)||0)+1)})}const Mt=Oe=>$.filter(Ge=>Ge.is_qualifier===Oe).sort((Ge,Ve)=>(Y.get(Ve.id)||0)-(Y.get(Ge.id)||0))[0];let ct=m,de=Mt(m==="qualifier");if(!de&&m==="main"){const Oe=Mt(!0);Oe&&(de=Oe,ct="qualifier",console.log("[Brackets Query] Fell back to qualifier bracket"))}if(!de)return console.log("[Brackets Query] No populated bracket found for",M,"- returning empty"),{bracket:null,matches:[],tournamentId:o,eventType:M,bracketTypeUsed:ct};const Pt=((r=de.tournaments)==null?void 0:r.tournament_tier)||null,ss=((n=de.tournaments)==null?void 0:n.name)||null,Rt=((P=de.tournaments)==null?void 0:P.pblfg_tournament_uuid)||null,Lt=((p=de.tournaments)==null?void 0:p.tournament_slug)||null,Et=performance.now(),{data:pe,error:dt}=await le.from("matches").select(`
2            id,
3            tournament,
4            round,
5            event,
6            team1,
7            team2,
8            games,
9            current_game,
10            best_of,
11            court,
12            status,
13            time,
14            details,
15            is_qualifier
16          `).eq("bracket_id",de.id);if(dt)throw console.error("[Brackets Query] Match fetch error:",dt),dt;const Fr=Math.round(performance.now()-t);console.log("[Brackets Query] COMPLETE:",{matchCount:(pe==null?void 0:pe.length)??0,payloadSize:pe?JSON.stringify(pe).length:0,totalMs:Fr,matchQueryMs:Math.round(performance.now()-Et)});const qr=ss||(((g=pe==null?void 0:pe[0])==null?void 0:g.tournament)??null),Ar=ua(de.url,de.event_id,Rt,Lt);return{bracket:{...de,tournament_tier:Pt,tournament_name:qr,viewUrl:Ar},matches:pe,tournamentId:de.tournament_id,eventType:M,bracketTypeUsed:ct}}catch(E){throw console.error("[Brackets Query] FAILED after",Math.round(performance.now()-t),"ms:",E),E}}}),{data:lt}=ke({queryKey:["main-bracket-teams",o,M],queryFn:async()=>{if(!o||o==="most_recent")return null;const{data:t,error:r}=await le.from("brackets").select("id").eq("tournament_id",o).eq("event_type",M).eq("is_qualifier",!1).maybeSingle();if(r||!t)return null;const{data:n,error:P}=await le.from("matches").select("team1, team2").eq("bracket_id",t.id);if(P||!n)return null;const p=new Set;
16return n.forEach(g=>{var E,z;(E=g.team1)==null||E.forEach($=>$&&$!=="TBD"&&p.add($)),(z=g.team2)==null||z.forEach($=>$&&$!=="TBD"&&p.add($))}),console.log("[Brackets] Main bracket teams for qualifier cross-reference:",p.size,"players"),p},enabled:x&&m==="qualifier"&&!!o&&o!=="most_recent",staleTime:6e4});c.useEffect(()=>{if(q&&!Ce){const t=Date.now(),r=JSON.stringify(q);Promise.all([te.setItem("bracket-data-cache",r),te.setItem("bracket-cache-timestamp",t.toString()),Le?te.setItem("bracket-cache-version",Le):Promise.resolve()]);try{window.localStorage.setItem("bracket-data-cache",r),window.localStorage.setItem("bracket-cache-timestamp",t.toString()),Le&&window.localStorage.setItem("bracket-cache-version",Le)}catch{}Yt(t),Vt(!1),console.log("[Brackets] Cached bracket data for offline use")}},[q,Ce,Le]),c.useEffect(()=>{if(!x||s||!q||!o||o==="most_recent")return;const t=setTimeout(()=>{Gt.forEach(r=>{r!==M&&["main","qualifier"].forEach(n=>{const P=["bracket",r,o,n];$e.getQueryData(P)||(console.log("[Brackets] Prefetching event:",r,n),$e.prefetchQuery({queryKey:P,staleTime:30*60*1e3,queryFn:async()=>{var Rt,Lt,Et;const{data:g,error:E}=await le.from("brackets").select("*, tournaments!inner(name, tournament_tier)").eq("event_type",r).eq("tournament_id",o);if(E)throw E;const z=n==="qualifier";let $=n,Y=g==null?void 0:g.find(pe=>pe.is_qualifier===z);if(!Y&&n==="main"){const pe=g==null?void 0:g.find(dt=>dt.is_qualifier===!0);pe&&(Y=pe,$="qualifier")}if(!Y)return{bracket:null,matches:[],tournamentId:o,eventType:r,bracketTypeUsed:$};const Mt=((Rt=Y.tournaments)==null?void 0:Rt.tournament_tier)||null,ct=((Lt=Y.tournaments)==null?void 0:Lt.name)||null,{data:de,error:Pt}=await le.from("matches").select("id, tournament, round, event, team1, team2, games, current_game, best_of, court, status, time, details, is_qualifier").eq("bracket_id",Y.id);if(Pt)throw Pt;const ss=ct||(((Et=de==null?void 0:de[0])==null?void 0:Et.tournament)??null);return{bracket:{...Y,tournament_tier:Mt,tournament_name:ss},matches:de,tournamentId:Y.tournament_id,eventType:r,bracketTypeUsed:$}}}))})})},300);return()=>clearTimeout(t)},[x,s,q,M,o,$e]),c.useEffect(()=>{var t;q!=null&&q.tournamentId&&o!==q.tournamentId&&o!=="lakeland"&&(console.log("[Brackets] Syncing tournament from query:",q.tournamentId),v(q.tournamentId)),(t=q==null?void 0:q.bracket)!=null&&t.tournament_name&&q.bracket.tournament_name!==N&&R(q.bracket.tournament_name),q!=null&&q.bracketTypeUsed&&q.bracketTypeUsed!==m&&w(q.bracketTypeUsed)},[q==null?void 0:q.tournamentId,q==null?void 0:q.bracketTypeUsed,(Ls=q==null?void 0:q.bracket)==null?void 0:Ls.tournament_name,o,N,m]),c.useEffect(()=>{let t,r,n;return Ee||Be||Jt?(Fe(!1),Te(!1),t=setTimeout(()=>{Fe(!0)},8e3),r=setTimeout(()=>{Te(!0)},2e4),n=setTimeout(()=>{console.log("[Brackets] Forcing refetch after timeout"),$e.cancelQueries({queryKey:["bracket",M,o,m]}),Ct()},15e3)):(Fe(!1),Te(!1),i(!1)),()=>{t&&clearTimeout(t),r&&clearTimeout(r),n&&clearTimeout(n)}},[Ee,Be,Jt,Ct,$e,M,o,m]),c.useEffect(()=>{const t=document.documentElement.getAttribute("data-theme");t&&dn(t)},[Be,Ee]);const jr=Be&&!Ee,ae=St&&Ke?Ke:q,Zt=((ae==null?void 0:ae.tournamentId)===o||(ae==null?void 0:ae.tournamentId)&&o==="most_recent")&&(ae==null?void 0:ae.eventType)===M,js=jr&&!St,C=c.useMemo(()=>{var P,p;if(!(ae&&!js&&Zt))return null;const t=((P=ae.bracket)==null?void 0:P.is_complete)??!1,r=`${ae.tournamentId}:${ae.eventType}:${ae.bracketTypeUsed}:${(p=ae.matches)==null?void 0:p.length}:${t}`;if((Ye==null?void 0:Ye.key)===r&&Ye.result)return console.log("[Brackets] Using cached organization for:",r),Ye.result;console.log("[Brackets] Computing organization for:",r);const n=ma(ae.matches,t);return Ye={key:r,result:n},n},[ae,js,Zt]),me=!!C&&(C.poolPlay.length>0||C.r128.length>0||C.r64.length>0||C.r32.length>0||C.r16.length>0||C.quarterfinals.length>0||C.semifinals.length>0||!!C.final||!!C.thirdPlace);c.useEffect(()=>{!Zs&&me&&(Zs=!0,console.log("[Brackets] Initial data loaded - skeleton disabled for session"))},[me]),c.useEffect(()=>(Be&&me?(Xt(!0),De.current&&clearTimeout(De.current),De.current=setTimeout(()=>{Xt(!1)},5e3)):(Xt(!1),De.current&&(clearTimeout(De.current),De.current=null)),()=>{De.current&&clearTimeout(De.current)}),[Be,me]),c.useEffect(()=>{var t,r,n,P,p,g,E;console.log("[BRACKET DEBUG] Component State:",{isLoading:Ee,isLoadingTournament:fs,isShowingCached:St,hasMatches:me,error:Ce==null?void 0:Ce.message,bracketDataExists:!!ae,matchCount:(t=ae==null?void 0:ae.matches)==null?void 0:t.length,tournamentDataExists:!!C,tournamentDataStructure:C?{r128:((r=C.r128)==null?void 0:r.length)||0,r64:((n=C.r64)==null?void 0:n.length)||0,r32:((P=C.r32)==null?void 0:P.length)||0,r16:((p=C.r16)==null?void 0:p.length)||0,qf:((g=C.quarterfinals)==null?void 0:g.length)||0,sf:((E=C.semifinals)==null?void 0:E.length)||0,final:!!C.final,thirdPlace:!!C.thirdPlace}:null,selectedTournament:o,selectedEventType:M})},[Ee,fs,St,me,Ce,ae,C,o,M]),c.useEffect(()=>{if(C!=null&&C.final&&C.final.winner&&C.final.status==="completed"){const t=C.final.winner===1?C.final.team1:C.final.team2;t&&t.length>0&&S(t[0]||null)}else S(null)},[C]),c.useEffect(()=>
16{!C||X||(re(!0),ce(0))},[C,X]);const Nr=async()=>{$e.invalidateQueries({queryKey:["brackets"]}),$e.invalidateQueries({queryKey:["bracket-matches"]}),Ct()},it=t=>{t&&(_&&(yr.current||Date.now()-ys.current<200)||(console.log("[Brackets] Match clicked:",{id:t.id,team1:t.team1,team2:t.team2,round:t.round,event:t.event,score:t.score}),A(t),F(!0)))},Ns=(t,r)=>!r||!t?!1:r.some(n=>(n==null?void 0:n.toLowerCase().includes(t.toLowerCase()))||t.toLowerCase().includes(n==null?void 0:n.toLowerCase())),Sr=t=>B?Ns(B,t.team1)||Ns(B,t.team2):!1,Cr=t=>{var p,g;if(!((p=t.details)!=null&&p.team1Seeds)||!((g=t.details)!=null&&g.team2Seeds)||t.status!=="completed"||!t.winner)return!1;const r=t.details.team1Seeds[0],n=t.details.team2Seeds[0],P=Math.abs(r-n);return t.winner===1&&r>n&&P>=5||t.winner===2&&n>r&&P>=5},Ss=t=>t.some(r=>Tr(r)),Tr=t=>t?t.team1&&t.team1.length>0&&t.team1[0]||t.team2&&t.team2.length>0&&t.team2[0]:!1,Mr=t=>t.some(r=>(r==null?void 0:r.status)==="completed"&&(r==null?void 0:r.winner)),Pr=t=>t.some(r=>{var p,g;const n=(p=r==null?void 0:r.team1)==null?void 0:p.some(E=>E&&E!=="TBD"&&E.trim()),P=(g=r==null?void 0:r.team2)==null?void 0:g.some(E=>E&&E!=="TBD"&&E.trim());return n||P}),Qe=(t,r,n)=>{if(!t||t.length===0)return!1;if(m==="qualifier")return Mr(t)||Pr(t);if(Ss(t))return!0;const P=[{key:"r128",data:n==null?void 0:n.r128},{key:"r64",data:n==null?void 0:n.r64},{key:"r32",data:n==null?void 0:n.r32},{key:"r16",data:n==null?void 0:n.r16},{key:"quarterfinals",data:n==null?void 0:n.quarterfinals},{key:"semifinals",data:n==null?void 0:n.semifinals},{key:"finals",data:n!=null&&n.final?[n.final]:[]}];let p=-1;for(let g=0;g<P.length;g++){const E=P[g].data;if(E&&E.length>0&&Ss(E)){p=g;break}}return p===-1?!1:r>=p},Z=c.useMemo(()=>{var n,P;if(!C)return[];const t=[];if(C.poolPlay.length>0){const p=fr(C.poolPlay);p.length>1?p.forEach(g=>{t.push({key:`PP-${g.label}`,label:`Pool ${g.label}`,matchCount:g.matches.length,matches:g.matches})}):t.push({key:"PP",label:"PP",matchCount:C.poolPlay.length,matches:C.poolPlay})}C.r128.length>0&&Qe(C.r128,0,C)&&t.push({key:"R128",label:"R128",matchCount:C.r128.length,matches:C.r128}),C.r64.length>0&&Qe(C.r64,1,C)&&t.push({key:"R64",label:"R64",matchCount:C.r64.length,matches:C.r64}),C.r32.length>0&&Qe(C.r32,2,C)&&t.push({key:"R32",label:"R32",matchCount:C.r32.length,matches:C.r32}),C.r16.length>0&&Qe(C.r16,3,C)&&t.push({key:"R16",label:"R16",matchCount:C.r16.length,matches:C.r16}),C.quarterfinals.length>0&&Qe(C.quarterfinals,4,C)&&t.push({key:"QF",label:"QF",matchCount:C.quarterfinals.length,matches:C.quarterfinals}),C.semifinals.length>0&&Qe(C.semifinals,5,C)&&t.push({key:"SF",label:"SF",matchCount:C.semifinals.length,matches:C.semifinals});const r=[];if(C.final&&r.push({...C.final,_isChampionship:!0}),C.thirdPlace){const p=C.thirdPlace,g=z=>!z||z.length===0||z.every($=>!$||$==="TBD"||$==="BYE"),E=((n=p.team1)==null?void 0:n.length)>0&&((P=p.team2)==null?void 0:P.length)>0&&!g(p.team1)&&!g(p.team2);(hs||E)&&r.push({...p,_isBronze:!0})}return r.length>0&&Qe(C.final?[C.final]:[],6,C)&&t.push({key:"F",label:"Finals",matchCount:r.length,matches:r}),t},[C,m,hs]);c.useEffect(()=>{if(Z.length>0&&!ve){const t=p=>{const g=(p||"").trim().toUpperCase();return g&&g!=="TBD"&&g!=="BYE"},r=p=>{var z,$;const g=(z=p.team1)==null?void 0:z.some(Y=>t(Y)),E=($=p.team2)==null?void 0:$.some(Y=>t(Y));return g&&E},n=p=>p.matches.length>0&&p.matches.every(g=>r(g));let P=null;for(let p=Z.length-1;p>=0;p--){const g=Z[p];if(g.matches.some(z=>(z.status==="live"||z.status==="in_progress"||z.status==="playing")&&r(z))){P=g.key;break}}if(!P)for(let p=Z.length-1;p>=0;p--){const g=Z[p];if(n(g)){P=g.key;break}}if(!P)for(let p=Z.length-1;p>=0;p--){const g=Z[p];if(g.matches.some(z=>r(z))){P=g.key;break}}Me(P||Z[0].key)}else Z.length>0&&ve&&(Z.some(r=>r.key===ve)||Me(null))},[Z,ve]),c.useLayoutEffect(()=>{const t=()=>{const n=u.current;if(!n)return;if(s&&l||!s&&j){const p=Math.max(n.offsetHeight,0);gt(g=>Math.abs(g-p)>1?p:g)}const P=n.getBoundingClientRect().bottom;document.documentElement.style.setProperty("--brackets-header-bottom",`${Math.max(P,0)}px`)};t();const r=requestAnimationFrame(t);return window.addEventListener("resize",t),window.addEventListener("orientationchange",t),window.addEventListener("scroll",t,{passive:!0}),()=>{cancelAnimationFrame(r),window.removeEventListener("resize",t),window.removeEventListener("orientationchange",t),window.removeEventListener("scroll",t),document.documentElement.style.removeProperty("--brackets-header-bottom")}},[s,l,j,me,Z.length,M,m,o,O,Ut,zt,we,Pe.length,he.length,y,_e,Ht,Re.length]);const Cs=c.useRef(o),Ts=c.useRef(M),Ms=c.useRef(m);c.useEffect(()=>{const t=Cs.current!==o,r=Ts.current!==M,n=Ms.current!==m;Cs.current=o,Ts.current=M,Ms.current=m,(t||r||n)&&(Me(null),sessionStorage.removeItem("brackets_selectedRound"))},[o,M,m]);const ie=ve||(Z.length>0?Z[0].key:null),Ps=c.useMemo(()=>
16{if(!ie||!Z.length)return[];const t=Z.find(p=>p.key===ie),r=(t==null?void 0:t.matches)||[];if(ie==="F"||ie.startsWith("PP"))return r;const n=p=>{var E,z;return(((E=p.team1)==null?void 0:E.length)||0)>0&&(((z=p.team2)==null?void 0:z.length)||0)>0?p.status==="live"?0:p.status==="completed"?1:2:3},P=p=>{const g=p.time?new Date(p.time).getTime():NaN;return Number.isFinite(g)?g:Number.POSITIVE_INFINITY};return[...r].sort((p,g)=>{const E=n(p),z=n(g);if(E!==z)return E-z;const $=P(p),Y=P(g);return $===Y?0:E===1?Y-$:$-Y})},[ie,Z]),es=c.useRef(ie);es.current=ie;const ts=c.useRef(Z);ts.current=Z;const{handleTouchStart:Rr,handleTouchMove:Lr,handleTouchEnd:Er,handleTouchCancel:Br}=un({onSwipeLeft:c.useCallback(()=>{const t=ts.current,r=t.findIndex(n=>n.key===es.current);r<t.length-1&&Me(t[r+1].key)},[]),onSwipeRight:c.useCallback(()=>{const t=ts.current,r=t.findIndex(n=>n.key===es.current);r>0&&Me(t[r-1].key)},[]),threshold:50,velocityThreshold:.25,minSwipeDistance:70}),Ir=(t,r)=>!t||t.length===0||!r||r.size===0?!1:t.every(n=>n&&n!=="TBD"&&r.has(n)),Rs=(t,r)=>{if(!t||t.status!=="completed"||!t.winner)return null;const n=t.winner===1?t.team1:t.team2;return Ir(n,r)?t.winner:null},Tt=c.useMemo(()=>{if(m!=="qualifier"||!lt||lt.size===0||!C)return[];const t=[...C.r128,...C.r64,...C.r32,...C.r16,...C.quarterfinals,...C.semifinals,...C.final?[C.final]:[]].filter(n=>(n==null?void 0:n.status)==="completed"&&(n==null?void 0:n.winner)),r=[];return t.forEach(n=>{const P=Rs(n,lt);if(P!==null){const p=P===1?n.team1:n.team2;p&&p.length>0&&r.push({team:p,matchRound:n.round||""})}}),r},[m,lt,C]);return Tt.length,e.jsx(Jn,{tournamentId:O?o:null,children:e.jsxs("div",{ref:b,className:W("min-h-screen pb-safe pl-safe pr-safe overflow-x-hidden",l&&"pt-safe"),style:{background:"var(--gradient-header)"},children:[s&&l&&e.jsx("div",{className:"fixed top-0 left-0 right-0 z-[997] pointer-events-none",style:{height:"env(safe-area-inset-top)",background:"var(--gradient-header)"}}),s&&_&&e.jsx("div",{className:"fixed top-0 left-0 right-0 z-[997] pointer-events-none",style:{height:"24px",background:"var(--gradient-header)"}}),s&&(()=>{const t=O?vt:128+ze;return e.jsx("div",{className:"fixed left-0 right-0 z-[25] pointer-events-none",style:{top:l?"env(safe-area-inset-top)":_?"24px":"0",height:l?y?`calc(64px + ${t}px)`:`${t}px`:_?y?`calc(64px + ${t}px)`:`${t}px`:y?`calc(64px + ${t}px)`:`${t}px`,background:"var(--gradient-header)",transition:"height 150ms ease-out"}})})(),!s&&e.jsx(mn,{onRefresh:Nr,onNotificationsClick:()=>V(!0),lastRefreshTime:null,isRefreshing:pt,isRateLimited:qe==null?void 0:qe.isRateLimited,onAuthClick:()=>H()}),!s&&e.jsx("div",{className:"h-14 md:h-16"}),s&&e.jsx(fn,{onAuthClick:()=>H()}),e.jsx(hn,{open:Q,onOpenChange:V,children:e.jsx(pn,{className:"max-w-2xl max-h-[80vh] overflow-y-auto pr-8",style:{background:"var(--gradient-match-card)"},children:e.jsx(On,{onRequestAuth:()=>{V(!1),H()}})})}),e.jsx("div",{ref:u,className:W("z-30 border-b border-border/10 transition-all duration-150 ease-out","fixed left-0 right-0"),style:{background:s?"transparent":"var(--gradient-header)",...s&&l?{top:y?"calc(4rem + env(safe-area-inset-top))":"env(safe-area-inset-top)"}:s&&_?{top:y?"88px":"24px"}:s?{top:y?"4rem":"0"}:{top:"calc(4rem + env(safe-area-inset-top))"}},children:e.jsxs("div",{className:W("container px-4",s?O?"pt-2 pb-0":"pt-2 pb-2":"py-3"),children:[e.jsxs("div",{className:W("flex gap-3",s?"flex-col":"flex-row items-center justify-between"),children:[e.jsxs("div",{className:"space-y-1 min-w-0 
16w-full md:w-auto md:flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-full flex-nowrap",children:[O?e.jsx(Us,{selectedTournament:o,onTournamentChange:xs,compact:!0,className:"min-w-0 shrink",compactTriggerContent:e.jsxs("span",{className:"text-lg md:text-3xl font-score uppercase tracking-wide flex items-center gap-2 min-w-0 shrink leading-none",children:[e.jsx(ft,{className:"w-5 h-5 md:w-6 md:h-6 text-gold shrink-0",strokeWidth:2.5}),e.jsx("span",{className:"truncate",children:Ot||"MLP"})]})}):e.jsxs("h1",{className:"text-lg md:text-3xl font-score uppercase tracking-wide flex items-center gap-2 min-w-0 shrink leading-none",children:[e.jsx(ft,{className:"w-5 h-5 md:w-6 md:h-6 text-gold shrink-0",strokeWidth:2.5}),e.jsx("span",{className:"truncate",children:M==="MLP"?Ot||"Brackets":`Pro ${M}`})]}),$t&&e.jsxs("div",{className:"ml-auto inline-flex rounded-full bg-muted/40 border border-border/40 p-[2px] shrink-0 flex-nowrap",children:[e.jsx("button",{type:"button",onClick:()=>yt("bracket"),className:W("px-2 py-[2px] rounded-full text-[9px] font-semibold uppercase tracking-wider transition-colors whitespace-nowrap leading-none",we==="bracket"?"bg-primary text-primary-foreground":"text-muted-foreground"),children:"Brackets"}),e.jsx("button",{type:"button",onClick:()=>yt("order"),className:W("px-2 py-[2px] rounded-full text-[9px] font-semibold uppercase tracking-wider transition-colors whitespace-nowrap leading-none",we==="order"?"bg-primary text-primary-foreground":"text-muted-foreground"),children:"Schedule"})]}),jt&&e.jsxs("div",{className:"ml-auto inline-flex rounded-full bg-muted/40 border border-border/40 p-[2px] shrink-0 flex-nowrap",children:[e.jsx("button",{type:"button",onClick:()=>_t("bracket"),className:W("px-2 py-[2px] rounded-full text-[9px] font-semibold uppercase tracking-wider transition-colors whitespace-nowrap leading-none",Ue==="bracket"?"bg-primary text-primary-foreground":"text-muted-foreground"),children:"Brackets"}),e.jsx("button",{type:"button",onClick:()=>_t("order"),className:W("px-2 py-[2px] rounded-full text-[9px] font-semibold uppercase tracking-wider transition-colors whitespace-nowrap leading-none",Ue==="order"?"bg-primary text-primary-foreground":"text-muted-foreground"),children:"Schedule"})]}),!O&&!$t&&((Es=q==null?void 0:q.bracket)==null?void 0:Es.is_challenger)&&e.jsx(Ie,{title:"PPA Challenger Tour",className:"bg-rose-700 text-white border-0 text-[7px] md:text-[9px] px-1 py-0.5 uppercase tracking-wide shrink-0 translate-y-[1px]",children:"CHALLENGER"}),!O&&!$t&&m==="qualifier"&&e.jsx(Ie,{title:"Qualifying Round",className:"bg-muted text-muted-foreground border-0 text-[7px] md:text-[9px] px-1 py-0.5 uppercase tracking-wide shrink-0 translate-y-[1px] font-semibold flex items-center leading-none",children:"QUALIFIER"}),!O&&((Bs=q==null?void 0:q.bracket)==null?void 0:Bs.viewUrl)&&e.jsx("a",{href:q.bracket.viewUrl,target:"_blank",rel:"noopener noreferrer",className:"shrink-0 text-muted-foreground hover:text-primary transition-colors",title:"Official Bracket",children:e.jsx(qn,{className:"w-3.5 h-3.5"})})]}),!s&&!O&&e.jsxs("div",{className:"text-xs md:text-sm text-muted-foreground flex items-center gap-2 flex-wrap",children:[e.jsx(zs,{className:"w-3.5 h-3.5"}),ne?e.jsx("span",{children:ne}):e.jsx(ge,{className:"h-4 w-40"})]})]}),!O&&e.jsxs("div",{className:"flex gap-2 flex-shrink-0 w-full md:w-auto",children:[e.jsx(Us,{selectedTournament:o,onTournamentChange:xs,className:"flex-[3] min-w-0 md:w-56 md:flex-none"}),e.jsxs(gn,{value:M,onValueChange:U,children:[e.jsx(xn,{className:"flex-[2] min-w-0 md:w-36 md:flex-none h-7 md:h-9 text-xs md:text-sm bg-background/50 border-border/50 hover:bg-accent hover:text-accent-foreground transition-colors",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(zs,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{children:"Event"})]})}),e.jsxs(bn,{className:"bg-background border-border",children:[e.jsx("div",{className:"px-2 py-1.5 border-b border-border/50 mb-1",children:e.jsxs("div",{className:"flex h-6 rounded-md border border-border/50 overflow-hidden",children:[e.jsx("button",{onClick:t=>{t.preventDefault(),t.stopPropagation(),w("main")},className:W("flex-1 px-2 text-xs transition-colors",m==="main"?"bg-primary text-primary-foreground":"bg-background/50 text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:"Main"}),e.jsx("button",{onClick:t=>{t.preventDefault(),t.stopPropagation(),w("qualifier")},className:W("flex-1 px-2 text-xs transition-colors",m==="qualifier"?"bg-qualifier text-qualifier-foreground":"bg-background/50 text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:"Qualifier"})]})}),e.jsx(ut,{value:"Men's Doubles",children:"Men's Doubles"}),e.jsx(ut,{value:"Women's Doubles",children:"Women's Doubles"}),e.jsx(ut,{value:"Mixed Doubles",children:"Mixed Doubles"}),e.jsx(ut,{value:"Men's Singles",children:"Men's Singles"}),e.jsx(ut,{value:"Women's Singles",children:"Women's Singles"})]})]})]})]}),!O&&!_e&&me&&Z.length>0&&e.jsx("div",{className:"pt-2",children:e.jsx(is,{rounds:Z,selectedRound:ie||"",onRoundChange:Me})}),gs&&e.jsx("div",{className:"pt-2",children:e.jsx(ta,{})}),Ut&&e.jsx("div",{className:"pt-2",children:e.jsx(is,{rounds:he.map(t=>({key:t.key,label:t.label,matchCount:t.matchCount})),selectedRound:tt||he[0].key,onRoundChange:bt,compact:!0})}),zt&&e.jsx("div",{className:"pt-2",children:e.jsx("div",{className:"flex w-full gap-1 px-1",children:Pe.map(t=>{var P;const r=t.key===(st||((P=Pe[0])==null?void 0:P.key)),n=t.key==="all";return e.jsx("button",{type:"button",onClick:()=>wt(t.key),className:W("py-1.5 px-3 rounded-md text-[11px] font-score uppercase tracking-wider transition-colors whitespace-nowrap border",n?"flex-none":"flex-1 min-w-0 truncate",r?"bg-primary text-primary-foreground border-primary":"bg-muted/40 text-muted-foreground border-border/40"),children:t.fullLabel},t.key)})})}),Ht&&e.jsx("div",{className:"pt-2",children:e.jsx("div",{className:"flex w-full gap-1 px-1 overflow-x-auto no-scrollbar snap-x",children:Re.map(t=>{var n;const r=t.key===(nt||((n=Re[0])==null?void 0:n.key));return e.jsx("button",{type:"button",onClick:()=>Qt(t.key),className:W("shrink-0 py-1.5 px-3 rounded-md text-[11px] font-score uppercase tracking-wider transition-colors whitespace-nowrap border snap-start",r?"bg-primary text-primary-foreground border-primary":"bg-muted/40 text-muted-foreground border-border/40"),children:t.key===qt?"ALL":t.fullLabel},t.key)})})})]})}),s&&e.jsx("div",{className:"transition-none",style:{height:l?`${et+(O?we==="order"?16:9:0)}px`:_?y?O?`${64+vt}px`:me&&Z.length>0?`${188+ze}px`:`${132+ze}px`:O?`${vt}px`:me&&Z.length>0?`${124+ze}px`:`${76+ze}px`:O?`${64+vt}px`:me&&Z.length>0?`${192+ze}px`:`${140+ze}px`}}),!s&&e.jsx("div",{style:{height:j?et:0}}),_r&&e.jsxs("div",{className:"fixed bottom-24 right-3 z-50 flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-primary text-primary-foreground shadow-lg font-score animate-in fade-in duration-300",children:[e.jsx(Ks,{className:"w-3.5 h-3.5 animate-spin"}),e.jsx("span",{className:"text-xs font-bold uppercase tracking-wide",children:"Updating"})]}),e.jsxs("main",{className:W("container px-4 scroll-mt-[140px]",s?"pb-20":j?"pb-8":"pb-8 pt-8"),children:[e.jsx("div",{className:W("pb-3",s?"pt-1":"pt-0"),children:e.jsx(yn,{slot:"brackets"})}),O&&o&&e.jsx("div",{className:W(s?"mt-0":"mt-4"),children:e.jsx(ra,{tournamentId:o,tournamentName:ne||(D==null?void 0:D.name)||"",selectedRound:tt,onRoundChange:bt,tournamentDateLabel:at,onMatchClick:it,viewMode:we,activeCourtKey:st,onActiveCourtChange:wt,hideCourtToggle:!0})}),_e&&o&&e.jsx("div",{className:W(s?"mt-0":"mt-4",!s&&"max-w-2xl mx-auto"),children:e.jsx(da,{tournamentId:o,activeCourtKey:nt,onMatchClick:it,tournamentDateLabel:at,tierLabel:!O&&!((Is=q==null?void 0:q.bracket)!=null&&Is.is_challenger)&&((Fs=q==null?void 0:q.bracket)!=null&&Fs.tournament_tier)?`PPA ${as(q.bracket.tournament_tier,D==null?void 0:D.start_date)}`:null})}),!O&&!_e&&!me&&!Ce&&(Ee||Jt||Be||!q&&!Ke)&&e.jsx(wn,{className:W(s?l?"mt-0":"mt-16":"mt-24")}),!O&&!_e&&Ce&&!Ee&&!Be&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 space-y-5 animate-fade-in",children:[e.jsx("div",{className:"w-28 h-28 rounded-full bg-gradient-to-br from-primary/15 to-primary/5 ring-1 ring-primary/20 flex items-center justify-center",children:e.jsx(ft,{className:"w-14 h-14 text-primary/50",strokeWidth:2.5})}),e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:"No Bracket Available"}),e.jsx("p",{className:"text-sm text-muted-foreground text-center max-w-xs",children:"Choose a different event or try again"}),e.jsxs(kn,{onClick:()=>{console.log("[Brackets] Retrying after error:",Ce),i(!0),Ct()},variant:"outline",size:"sm",className:"gap-2",disabled:We,children:[e.jsx(Ks,{className:W("w-4 h-4",We&&"animate-spin")}),"Retry"]})]}),!O&&!_e&&!Ee&&!Be&&!Ce&&!me&&q&&Zt&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 space-y-5 animate-fade-in",children:[e.jsx("div",{className:"w-28 h-28 rounded-full bg-gradient-to-br from-primary/15 to-primary/5 ring-1 ring-primary/20 flex items-center justify-center",children:e.jsx(ft,{className:"w-14 h-14 text-primary/50",strokeWidth:2.5})}),e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:"No Bracket Available"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose a different event"})]}),!_e&&me&&(ie==null?void 0:ie.startsWith("PP"))&&(C==null?void 0:C.poolPlay)&&C.poolPlay.length>0&&e.jsx($n,{matches:C.poolPlay,isMobile:s,onMatchClick:it,displayTournamentName:ne,tournamentDateLabel:at,filterPoolLabel:ie.startsWith("PP-")?ie.replace("PP-",""):void 0,tournamentId:o}),!_e&&me&&ie&&!ie.startsWith("PP")&&Ps.length>0&&e.jsxs("div",{onTouchStart:Rr,onTouchMove:Lr,onTouchEnd:Er,onTouchCancel:Br,className:W("relative",s&&"mt-[1px]",!s&&"mt-6 max-w-2xl mx-auto",(l||_)&&"relative z-10 mt-[6px]"),children:[(()=>{var n,P,p;const t=ie||((n=Z[0])==null?void 0:n.key),r=t==="R128"?"Round of 128":t==="R64"?"Round of 64":t==="R32"?"Round of 32":t==="R16"?"Round of 16":t==="QF"?"Quarterfinals":t==="SF"?"Semifinals":t==="F"?"Finals":"";return e.jsxs("div",{className:"px-2 pt-1 pb-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground tracking-wider up
16percase",children:r&&e.jsx("span",{children:r})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[!O&&!((P=q==null?void 0:q.bracket)!=null&&P.is_challenger)&&((p=q==null?void 0:q.bracket)==null?void 0:p.tournament_tier)&&e.jsxs("span",{title:`PPA ${as(q.bracket.tournament_tier,D==null?void 0:D.start_date)}`,className:"text-[10px] font-semibold tracking-wider uppercase whitespace-nowrap bg-accent text-accent-foreground px-2 py-0.5 rounded-full",children:["PPA ",as(q.bracket.tournament_tier,D==null?void 0:D.start_date)]}),at&&e.jsx("span",{className:"text-[10px] font-semibold tracking-wider uppercase text-muted-foreground/70 whitespace-nowrap bg-muted/50 px-2 py-0.5 rounded-full border border-border/30",children:at})]})]}),e.jsx("div",{className:"h-0.5 bg-primary/30 mt-2 rounded-full"})]})})(),e.jsx("div",{className:"flex flex-col gap-3 px-2 pb-5",children:Ps.map(t=>{var g,E;const r=t._isChampionship===!0,n=t._isBronze===!0,P=Sr(t),p=(((g=t.team1)==null?void 0:g.length)||0)>0&&(((E=t.team2)==null?void 0:E.length)||0)>0;return e.jsxs("div",{children:[r&&e.jsx("div",{className:"text-xs font-semibold text-muted-foreground text-center mb-2 uppercase",children:"Gold Medal"}),n&&e.jsx("div",{className:"text-xs font-semibold text-muted-foreground text-center mb-2 mt-4 uppercase",children:"Bronze Medal"}),p?e.jsx(ir,{match:{...t,is_qualifier:m==="qualifier"},onClick:()=>it(t)}):e.jsx(us,{team1:t.team1,team2:t.team2,winner:t.winner,score:t.score,status:t.status,size:r?"lg":n?"md":"sm",isMobile:s,onClick:()=>it(t),isHighlighted:!1,isOnWinnerPath:P,isChampionship:r,isBronzeMedal:n,round:r?"Finals":n?"Bronze Medal":ie==="QF"?"Quarterfinals":ie==="SF"?"Semifinals":ie||"",isUpset:Cr(t),details:t.details,advancedToMainDraw:m==="qualifier"?Rs(t,lt):null,event:t.event,matchId:t.id,time:t.time,tournament:t.tournament,court:t.court})]},t.id)})})]}),!_e&&me&&!s&&m==="qualifier"&&Tt.length>0&&e.jsxs("div",{className:"mt-6 max-w-2xl mx-auto px-2",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx("div",{className:"px-6 py-2.5 rounded-lg border border-emerald-500/30 border-l-4 border-l-emerald-500/50 shadow-md transition-all duration-300",style:{background:"var(--gradient-match-card)"},children:e.jsxs("h3",{className:"text-base font-semibold text-emerald-400 uppercase flex items-center gap-2",children:[e.jsx(An,{className:"w-4 h-4"}),"Qualified (",Tt.length,")"]})})}),e.jsx("div",{className:"flex flex-col gap-2",children:Tt.map((t,r)=>e.jsx("div",{className:"p-3 rounded-lg border border-emerald-500/20 bg-emerald-500/5",style:{background:"var(--gradient-match-card)"},children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex -space-x-1",children:t.team.map(n=>e.jsx("button",{onClick:()=>be(n),className:"focus:outline-none hover:z-10 transition-transform hover:scale-110",children:e.jsx(mt,{name:n,className:"w-6 h-6 border border-background cursor-pointer"})},n))}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("div",{className:"flex flex-wrap gap-x-1",children:t.team.map((n,P)=>e.jsxs("button",{onClick:()=>be(n),className:"text-sm font-medium text-foreground hover:text-primary hover:underline transition-colors cursor-pointer focus:outline-none",children:[ls(n),P<t.team.length-1?" /":""]},n))})}),e.jsx(Ie,{className:"bg-emerald-500/20 text-emerald-400 border border-emerald-500/40 text-[10px] font-bold px-2 py-0.5",children:"Q"})]})},r))})]}),!a&&e.jsx("footer",{className:W("text-center pt-3",_?"pb-2":"pb-1"),children:e.jsxs("p",{className:"text-[9px] text-muted-foreground/60",children:[e.jsx(rs,{to:"/support",className:"hover:text-muted-foreground underline-offset-2 hover:underline",children:"Contact Us"})," · ",e.jsx(rs,{to:"/privacy-policy",className:"hover:text-muted-foreground underline-offset-2 hover:underline",children:"Privacy Policy"})," · ",e.jsx(rs,{to:"/terms-of-service",className:"hover:text-muted-foreground underline-offset-2 hover:underline",children:"Terms of Use"})]})})]}),e.jsx(vn,{match:I,open:se,onOpenChange:F}),e.jsxs(_n,{open:!!oe,onOpenChange:t=>!t&&be(null),title:"Player profile",desktopClassName:"sm:max-w-md flex flex-col sm:h-[82vh]",mobileClassName:"h-[82dvh] flex flex-col",children:[e.jsxs("div",{className:"shrink-0 z-10 bg-background px-4 -mt-4 pt-8 pb-1 relative sm:mt-0 sm:pt-4",children:[e.jsx(jn,{playerName:oe}),oe&&e.jsxs("div",{className:"absolute right-2 top-4 z-30 flex items-center gap-0",children:[e.jsxs("button",{type:"button",onClick:()=>void Sn(oe),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-transparent p-0 text-foreground
16/80 transition-colors hover:bg-muted/60 hover:text-foreground",style:{WebkitTapHighlightColor:"transparent"},children:[e.jsx(Nn,{size:16,className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Share profile"})]}),e.jsxs("button",{type:"button",onClick:()=>be(null),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-transparent p-0 text-foreground/80 transition-colors hover:bg-muted/60 hover:text-foreground",style:{WebkitTapHighlightColor:"transparent"},children:[e.jsx(Dn,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]}),e.jsx("div",{className:"flex min-w-0 items-start overflow-x-hidden overflow-y-visible",children:e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col items-center gap-0.5 overflow-visible px-4",children:[e.jsx(Cn,{name:oe||"",className:"w-20 h-20"}),oe?e.jsx(Tn,{playerName:oe,className:"w-full"}):null]})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain touch-pan-y overflow-x-hidden px-4 pb-8",style:{WebkitOverflowScrolling:"touch"},children:[oe&&e.jsx("div",{className:"flex items-center justify-center gap-2 pb-2",children:e.jsx(Mn,{playerName:oe})}),oe&&e.jsx(Pn,{playerName:oe,stats:xt[oe],compact:!0,onPlayerOpen:t=>be(t)})]})]})]})})};export{ja 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.