import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{Ht as t,In as n,Ir as r,Lr as i,Mr as a,Pr as o,Rt as s,Un as c,Xt as l,Yn as u,Yt as d,Zr as f,_i as p,_r as m,an as h,di as g,ei as _,fi as v,ii as y,ir as b,ln as x,pi as S,qn as C,qt as w,rn as T,sn as ee,sr as E,wr as D}from"./vendor-DkM0BOLc.js";import{n as O,t as k}from"./api--bJYSUUx.js";import{A,C as j,I as te,J as M,K as ne,O as re,_ as ie,a as ae,d as oe,f as se,j as ce,q as le,u as ue,vt as N,w as de}from"./index-CYbEqOJT.js";import{t as P}from"./status-pill-DnoqUkEp.js";import{t as fe}from"./SparkLine-C4kwvgTR.js";import{t as pe}from"./AgentIcon-Juqp0kn6.js";import{t as me}from"./PrefetchLink-D0OR7Deq.js";import{t as he}from"./MatchRow-B4DFEc7W.js";import{t as ge}from"./delta-pill-Dcsd7ZTA.js";import{n as _e,t as ve}from"./seo-helpers-yv5d9z5e.js";import{t as ye}from"./WatchButton-DUBFMJdf.js";import{t as be}from"./useTournament-DPGS9XaB.js";import{t as xe}from"./EntityNotFound-dsgdxwhs.js";var F=e(p(),1);function I(e,t){let n=e.team1?.id===t,r=e.team1Maps??e.stats?.team1Maps??null,i=e.team2Maps??e.stats?.team2Maps??null,a=n?r:i,o=n?i:r;if((a==null||a===0&&o===0)&&e.stats?.seriesScore){let[t,r]=Array.isArray(e.stats.seriesScore)?e.stats.seriesScore:e.stats.seriesScore.split(`-`).map(Number);!isNaN(t)&&!isNaN(r)&&(a=n?t:r,o=n?r:t)}return{teamMaps:a,oppMaps:o}}function Se(e,t){for(let n of e){if(n.team1?.slug===t)return n.team1;if(n.team2?.slug===t)return n.team2}return null}function Ce(e,t){let[n,r]=S(),i=n.get(`team`),a=e=>{r(t=>{let n=new URLSearchParams(t);return n.get(`team`)===e?n.delete(`team`):n.set(`team`,e),n},{replace:!0})},o=()=>{r(e=>{let t=new URLSearchParams(e);return t.delete(`team`),t},{replace:!0})},s=(0,F.useMemo)(()=>{if(!i)return null;let n=Se(e,i);if(!n)return null;let r=n.id,a=e.filter(e=>e.team1?.id===r||e.team2?.id===r).sort((e,t)=>{let n=e.playedAt??e.scheduledAt??``,r=t.playedAt??t.scheduledAt??``;return n.localeCompare(r)});if(a.length===0)return null;let o=0,s=0,c=0,l=0;for(let e of a){if(!e.winner)continue;e.winner.id===r?o++:s++;let{teamMaps:t,oppMaps:n}=I(e,r);c+=t??0,l+=n??0}let u=a.filter(e=>e.winner?.id===r&&e.stats),d=u.length>0?u.reduce((e,t)=>{let{teamMaps:n,oppMaps:i}=I(t,r),a=(n??0)-(i??0),{teamMaps:o,oppMaps:s}=I(e,r);return a>(o??0)-(s??0)?t:e}):null,f=a.filter(e=>e.winner&&e.stats),p=f.length>0?f.reduce((e,t)=>{let{teamMaps:n,oppMaps:i}=I(t,r),a=Math.abs((n??0)-(i??0)),{teamMaps:o,oppMaps:s}=I(e,r);return a<Math.abs((o??0)-(s??0))?t:e}):null,m=[...a].reverse().filter(e=>e.winner),h=m[0]?.winner?.id===r?`W`:`L`,g=0;for(let e of m){let t=e.winner?.id===r;if(t&&h===`W`||!t&&h===`L`)g++;else break}let _=[...a].reverse().find(e=>e.winner),v=_?.winner?.id===r,y=t===`completed`&&v,b=t!==`upcoming`&&!v&&!!_;return{teamId:r,teamName:n.name,teamSlug:i,teamLogoUrl:n.logoUrl??null,matches:a,wins:o,losses:s,mapsWon:c,mapsLost:l,biggestWin:d,closestMatch:p,currentStreak:{type:h,count:g},status:y?`champion`:b?`eliminated`:`active`}},[i,e,t]);return{teamSlug:i,journey:s,teamMatchIds:(0,F.useMemo)(()=>s?new Set(s.matches.map(e=>e.id)):new Set,[s]),selectTeam:a,clearTeam:o}}function we(e,t){let n=e?.length??0,r=new Set((t??[]).map(e=>e.type)),i=[];(r.has(`group`)||r.has(`round_robin`))&&i.push(`Groups`),r.has(`swiss`)&&i.push(`Swiss`),r.has(`playoff`)||r.has(`upper_bracket`)||r.has(`lower_bracket`)||r.has(`grand_final`)?i.push(`Double-Elim`):r.has(`qualifier`)&&i.length===0&&i.push(`Qualifier`);let a=i.length>0?i.join(` + `):null;return n>0&&a?`${n} teams · ${a}`:n>0?`${n} teams`:a||null}function Te(e,t){if(e.length===0)return e;let n=new Map;for(let t of e)n.set(t.id,t.rating);let r=new Set;for(let i of e){if(i.rating!=null){r.add(i.id);continue}for(let e of t){if(!e.team1||!e.team2||!e.playedAt)continue;let t=e.team1.id===i.id,a=e.team2.id===i.id;if(!t&&!a)continue;let o=t?e.team2:e.team1,s=n.get(o.id);if(s===void 0){r.add(i.id);break}if(s!=null){r.add(i.id);break}}}return e.filter(e=>r.has(e.id))}var L=_();function Ee({champion:e,gameSlug:t,size:n=`md`,linked:r=!0}){let i=M(e.tier),a=(0,L.jsxs)(`div`,{className:N(`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5`,`border-[var(--glk-brand)]/30 bg-[var(--glk-brand)]/10 text-zinc-900 dark:text-zinc-100`,n===`sm`&&`px-2 py-1 text-xs`),children:[(0,L.jsx)(w,{size:n===`sm`?12:14,className:`text-[var(--glk-brand)]`,"aria-hidden":!0}),(0,L.jsx)(`span`,{className:`glk-eyebrow text-[var(--glk-brand)]`,children:`Champion`}),(0,L.jsx)(`span`,{className:`font-semibold`,children:e.name}),i&&(0,L.jsx)(`span`,{className:N(`rounded px-1.5 py-0.5 text-[9px] font-bold leading-none`,ne(e.tier)),children:i})]});return r?(0,L.jsx)(me,{to:`/games/${t}/teams/${e.slug}`,className:`inline-block transition-opacity hover:opacity-80`,"aria-label":`Champion: ${e.name}`,children:a}):a}function De(e,t){if(!e)return null;let n=new Date(e).toLocaleDateString(`en-US`,{month:`long`,day:`numeric`});return t?`${n} \u2013 ${new Date(t).toLocaleDateString(`en-US`,{month:`long`,day:`numeric`,year:`numeric`})}`:`${n} \u2013 ongoing`}function Oe({completed:e,total:t,isOngoing:n}){if(t===0)return null;let r=Math.round(e/t*100);return(0,L.jsxs)(`div`,{className:`mt-4`,children:[(0,L.jsxs)(`div`,{className:`mb-1 flex items-center justify-between text-xs text-zinc-400`,children:[(0,L.jsxs)(`span`,{children:[(0,L.jsx)(`span`,{className:`glk-tabular font-semibold text-zinc-700 dark:text-zinc-200`,children:e}),` of `,(0,L.jsx)(`span`,{className:`glk-tabular font-semibold text-zinc-700 dark:text-zinc-200`,children:t}),` matches played`]}),(0,L.jsxs)(`span`,{className:`glk-tabular font-medium`,children:[r,`%`]})]}),(0,L.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700`,role:`progressbar`,"aria-valuenow":e,"aria-valuemin":0,"aria-valuemax":t,"aria-label":`Tournament progress: ${e} of ${t} matches played`,children:(0,L.jsx)(`div`,{className:N(`h-full rounded-full bg-[var(--glk-brand)] transition-all`,n&&`animate-pulse`),style:{width:`${r}%`}})})]})}function ke({tournament:e,matchCount:t,completedCount:r,gameSlug:a}){let o=M(e.tier),s=le(e.tier),l=De(e.startDate,e.endDate),u=e.status===`ongoing`,d=e.status===`completed`,f=e.status===`upcoming`,p=Math.max(t-r,0),h=we(Te(e.participants??[],e.matches??[]),e.stages);return(0,L.jsx)(`div`,{className:N(`glk-card mb-6 overflow-hidden !p-0`,u&&`glk-card-live`,f&&`glk-card-info`),children:(0,L.jsxs)(`div`,{className:`p-5 md:p-6`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u&&(0,L.jsx)(P,{tone:`live`,pulse:!0,children:`Live`}),d&&(0,L.jsx)(P,{tone:`completed`,children:`Final`}),f&&(0,L.jsx)(P,{tone:`info`,children:`Upcoming`}),o&&(0,L.jsx)(`span`,{className:N(`rounded px-2 py-0.5 text-xs font-bold`,ne(e.tier)),children:o}),o&&s&&(0,L.jsx)(`span`,{className:`glk-eyebrow text-zinc-500 dark:text-zinc-400`,children:s})]}),(0,L.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2 text-sm`,children:[e.region&&(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-zinc-200/80 px-3 py-1 dark:bg-zinc-800/80`,children:[(0,L.jsx)(c,{size:14,className:`text-zinc-400`,"aria-hidden":`true`}),(0,L.jsx)(`span`,{className:`font-medium uppercase tracking-wide text-zinc-900 dark:text-zinc-100`,children:e.region})]}),e.prizePool&&!e.prizePool.includes(`TBD`)&&e.prizePool!==`$0 USD`&&(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-zinc-200/80 px-3 py-1 dark:bg-zinc-800/80`,children:[(0,L.jsx)(m,{size:14,className:`text-zinc-400`,"aria-hidden":`true`}),(0,L.jsx)(`span`,{className:`glk-tabular font-semibold text-zinc-900 dark:text-zinc-100`,children:e.prizePool})]}),l?(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-zinc-200/80 px-3 py-1 dark:bg-zinc-800/80`,children:[(0,L.jsx)(i,{size:14,className:`text-zinc-400`,"aria-hidden":`true`}),(0,L.jsx)(`span`,{className:`font-medium text-zinc-900 dark:text-zinc-100`,children:l})]}):(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-zinc-200/80 px-3 py-1 text-zinc-500 dark:bg-zinc-800/80`,children:[(0,L.jsx)(i,{size:14,"aria-hidden":`true`}),`Dates TBD`]}),h&&(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-zinc-200/80 px-3 py-1 dark:bg-zinc-800/80`,children:[(0,L.jsx)(n,{size:14,className:`text-zinc-400`,"aria-hidden":`true`}),(0,L.jsx)(`span`,{className:`font-medium uppercase tracking-wide text-zinc-900 dark:text-zinc-100`,children:h})]})]}),t>0&&(0,L.jsxs)(`div`,{className:`mt-4 grid grid-cols-3 gap-3 border-t border-zinc-200/60 pt-4 dark:border-white/10`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`glk-eyebrow text-zinc-500 dark:text-zinc-400`,children:`Matches`}),(0,L.jsx)(`div`,{className:`glk-metric glk-metric-md mt-0.5 text-zinc-900 dark:text-zinc-100`,children:t})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`glk-eyebrow text-zinc-500 dark:text-zinc-400`,children:`Played`}),(0,L.jsx)(`div`,{className:`glk-metric glk-metric-md mt-0.5 text-zinc-900 dark:text-zinc-100`,children:r})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`glk-eyebrow text-zinc-500 dark:text-zinc-400`,children:d?`Done`:`Remaining`}),(0,L.jsx)(`div`,{className:N(`glk-metric glk-metric-md mt-0.5`,u&&p>0?`text-[var(--glk-brand)]`:`text-zinc-900 dark:text-zinc-100`),children:d?r:p})]})]}),d&&e.champion&&(0,L.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[(0,L.jsx)(Ee,{champion:e.champion,gameSlug:a,size:`md`}),e.championProvenance===`override`&&(0,L.jsx)(`span`,{title:`Champion was manually set by operator.`,className:`inline-flex`,children:(0,L.jsx)(P,{tone:`info`,size:`xs`,children:`Operator-set`})}),e.championAmbiguous&&(0,L.jsx)(`span`,{title:`Multiple possible champions detected — operator review needed.`,className:`inline-flex`,children:(0,L.jsx)(P,{tone:`warning`,size:`xs`,children:`Ambiguous`})})]}),t>0&&(0,L.jsx)(Oe,{completed:r,total:t,isOngoing:u})]})})}function Ae({form:e}){return e.length===0?(0,L.jsx)(`span`,{className:`text-zinc-400`,children:`–`}):(0,L.jsx)(`div`,{className:`flex items-center gap-1`,children:e.map((e,t)=>(0,L.jsx)(`div`,{className:N(`h-2.5 w-2.5 rounded-full`,e===`W`?`bg-emerald-500`:`bg-red-500/70`)},t))})}function je({value:e}){return(0,L.jsx)(`span`,{className:N(`glk-tabular`,e>0&&`text-emerald-500`,e<0&&`text-red-500`,e===0&&`text-zinc-400`),children:e>0?`+${e}`:e})}function Me({entry:e,isQualifying:t,isCutoffRow:n,expanded:r,onToggle:i,gameSlug:a,compact:s}){let c=e.team;return s?(0,L.jsxs)(`tr`,{className:N(t?`border-l-[3px] border-l-emerald-500`:`border-l-[3px] border-l-red-500/60`),children:[(0,L.jsx)(`td`,{className:`py-2 pl-3 pr-2 text-center glk-metric-sm text-zinc-400`,children:e.rank}),(0,L.jsx)(`td`,{className:`py-2 pr-2`,children:(0,L.jsxs)(y,{to:`/${a}/teams/${c.slug}`,className:`flex items-center gap-2 hover:text-zinc-700 dark:hover:text-zinc-300`,children:[(0,L.jsx)(A,{name:c.name,abbreviation:c.abbreviation,logoUrl:c.logoUrl,size:`xs`}),(0,L.jsx)(`span`,{className:`max-w-[120px] truncate text-sm font-medium text-zinc-900 dark:text-zinc-100`,children:c.name})]})}),(0,L.jsxs)(`td`,{className:`py-2 pr-3 text-right text-sm glk-tabular text-zinc-600 dark:text-zinc-300`,children:[(0,L.jsx)(`span`,{className:`font-semibold`,children:e.matchesWon}),(0,L.jsx)(`span`,{className:`text-zinc-400`,children:`-`}),(0,L.jsx)(`span`,{children:e.matchesLost})]})]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`tr`,{onClick:i,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&!e.target.closest(`a, button`)&&(e.preventDefault(),i())},tabIndex:0,"aria-expanded":r,className:N(`cursor-pointer transition-colors hover:bg-zinc-50 dark:hover:bg-zinc-800/50`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--glk-brand)]`,t?`border-l-[3px] border-l-emerald-500`:`border-l-[3px] border-l-red-500/60`),children:[(0,L.jsx)(`td`,{className:`py-2.5 pl-3 pr-2 text-center glk-metric-sm text-zinc-400`,children:e.rank}),(0,L.jsx)(`td`,{className:`py-2.5 pr-2`,children:(0,L.jsxs)(y,{to:`/${a}/teams/${c.slug}`,onClick:e=>e.stopPropagation(),className:`flex items-center gap-2 hover:text-zinc-700 dark:hover:text-zinc-300`,children:[(0,L.jsx)(A,{name:c.name,abbreviation:c.abbreviation,logoUrl:c.logoUrl,size:`xs`}),(0,L.jsx)(`span`,{className:`max-w-[160px] truncate text-sm font-medium text-zinc-900 dark:text-zinc-100`,children:c.name})]})}),(0,L.jsxs)(`td`,{className:`py-2.5 pr-2 text-center text-sm glk-tabular text-zinc-600 dark:text-zinc-300`,children:[(0,L.jsx)(`span`,{className:`font-semibold`,children:e.matchesWon}),(0,L.jsx)(`span`,{className:`text-zinc-400`,children:`-`}),(0,L.jsx)(`span`,{children:e.matchesLost})]}),(0,L.jsx)(`td`,{className:`py-2.5 pr-2 text-center text-sm glk-tabular text-zinc-600 dark:text-zinc-300`,children:e.mapsWon+e.mapsLost>0?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{children:e.mapsWon}),(0,L.jsx)(`span`,{className:`text-zinc-400`,children:`-`}),(0,L.jsx)(`span`,{children:e.mapsLost})]}):(0,L.jsx)(`span`,{className:`text-zinc-400`,children:`–`})}),(0,L.jsx)(`td`,{className:`py-2.5 pr-2 text-center text-sm`,children:e.mapsWon+e.mapsLost>0?(0,L.jsx)(je,{value:e.mapDiff}):(0,L.jsx)(`span`,{className:`text-zinc-400`,children:`–`})}),(0,L.jsx)(`td`,{className:`hidden py-2.5 pr-2 text-center text-sm md:table-cell`,children:e.roundsWon+e.roundsLost>0?(0,L.jsx)(je,{value:e.roundDiff}):(0,L.jsx)(`span`,{className:`text-zinc-400`,children:`–`})}),(0,L.jsx)(`td`,{className:`hidden py-2.5 pr-2 text-center md:table-cell`,children:(0,L.jsx)(Ae,{form:e.recentForm})}),(0,L.jsx)(`td`,{className:`py-2.5 pr-3 text-center`,children:(0,L.jsx)(o,{size:14,className:N(`inline-block text-zinc-400 transition-transform`,r&&`rotate-180`)})})]}),r&&e.tiedWith.length>0&&(0,L.jsx)(`tr`,{className:`bg-zinc-50 dark:bg-zinc-900/50`,children:(0,L.jsx)(`td`,{colSpan:8,className:`border-l-2 border-emerald-500/30 px-4 py-2`,children:(0,L.jsxs)(`p`,{className:`text-xs text-zinc-400`,children:[`Tied with `,e.tiedWith.length,` team`,e.tiedWith.length>1?`s`:``,` — resolved by head-to-head`]})})})]})}function R({standings:e,stageName:t,matchesPlayed:n,matchesTotal:r,qualifyCount:i,compact:a,gameSlug:o}){let[s,c]=(0,F.useState)(null),l=i??Math.max(1,Math.floor(e.length/2)),u=e=>{c(t=>t===e?null:e)};return a?(0,L.jsxs)(`div`,{className:`glk-card !p-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3`,children:[(0,L.jsx)(`h3`,{className:`glk-eyebrow`,children:t}),(0,L.jsxs)(P,{tone:`neutral`,size:`xs`,uppercase:!1,className:`tabular-nums`,children:[n,`/`,r,` in stage`]})]}),(0,L.jsx)(`table`,{className:`w-full`,children:(0,L.jsx)(`tbody`,{children:e.map(e=>(0,L.jsx)(Me,{entry:e,isQualifying:e.rank<=l,isCutoffRow:e.rank===l,expanded:!1,onToggle:()=>{},gameSlug:o,compact:!0},e.team.id))})})]}):(0,L.jsxs)(`div`,{className:`glk-card !p-0 overflow-hidden`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between bg-zinc-100 px-4 py-2.5 dark:bg-zinc-800/50`,children:[(0,L.jsx)(`span`,{className:`glk-eyebrow`,children:t}),(0,L.jsxs)(`span`,{className:`text-xs tabular-nums text-zinc-400`,children:[n,`/`,r,` stage matches played`]})]}),(0,L.jsx)(`div`,{className:`overflow-x-auto`,children:(0,L.jsxs)(`table`,{className:`w-full min-w-[500px]`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`glk-eyebrow border-b border-zinc-200 dark:border-zinc-800`,children:[(0,L.jsx)(`th`,{scope:`col`,className:`py-2 pl-3 pr-2 text-center font-medium`,children:`#`}),(0,L.jsx)(`th`,{scope:`col`,className:`py-2 pr-2 text-left font-medium`,children:`Team`}),(0,L.jsx)(`th`,{scope:`col`,className:`py-2 pr-2 text-center font-medium`,children:`W-L`}),(0,L.jsx)(`th`,{scope:`col`,className:`py-2 pr-2 text-center font-medium`,children:`Maps`}),(0,L.jsx)(`th`,{scope:`col`,className:`py-2 pr-2 text-center font-medium`,children:`+/−`}),(0,L.jsx)(`th`,{scope:`col`,className:`hidden py-2 pr-2 text-center font-medium md:table-cell`,children:`Rd+/−`}),(0,L.jsx)(`th`,{scope:`col`,className:`hidden py-2 pr-2 text-center font-medium md:table-cell`,children:`Form`}),(0,L.jsx)(`th`,{scope:`col`,className:`w-8 py-2 pr-3`})]})}),(0,L.jsx)(`tbody`,{className:`divide-y divide-zinc-100 dark:divide-zinc-800/50`,children:e.map(e=>(0,L.jsx)(Me,{entry:e,isQualifying:e.rank<=l,isCutoffRow:e.rank===l,expanded:s===e.team.id,onToggle:()=>u(e.team.id),gameSlug:o},e.team.id))})]})}),e.length===0&&(0,L.jsx)(`div`,{className:`py-8 text-center text-sm text-zinc-400`,children:`No standings data available yet.`})]})}function z(e,t,n){return j(de.standings,{gameSlug:e,tournamentSlug:t,groupId:n??null},{enabled:!!t})}function Ne({gameSlug:e,tournamentSlug:t,stage:n,compact:r}){let i=n.groups??[];return i.length<=1?(0,L.jsx)(Pe,{gameSlug:e,tournamentSlug:t,stageName:n.name,compact:r}):(0,L.jsx)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:i.map(n=>(0,L.jsx)(Fe,{gameSlug:e,tournamentSlug:t,groupId:n.id,groupName:n.name,compact:r},n.id))})}function Pe({gameSlug:e,tournamentSlug:t,stageName:n,compact:r}){let{data:i,isLoading:a}=z(e,t);if(a)return(0,L.jsx)(Ie,{});let o=i?.stages??[];return o.length===0?(0,L.jsx)(Le,{label:n}):(0,L.jsx)(`div`,{className:`space-y-4`,children:o.map(t=>(0,L.jsx)(R,{standings:t.standings,stageName:t.stageName,matchesPlayed:t.matchesPlayed,matchesTotal:t.matchesTotal,gameSlug:e,compact:r},t.stageId))})}function Fe({gameSlug:e,tournamentSlug:t,groupId:n,groupName:r,compact:i}){let{data:a,isLoading:o}=z(e,t,n);if(o)return(0,L.jsx)(Ie,{});let s=a?.stages?.[0];return s?(0,L.jsx)(R,{standings:s.standings,stageName:s.groupName??r,matchesPlayed:s.matchesPlayed,matchesTotal:s.matchesTotal,gameSlug:e,compact:i}):(0,L.jsx)(Le,{label:r})}function Ie(){return(0,L.jsxs)(`div`,{className:`glk-card`,children:[(0,L.jsx)(`div`,{className:`mb-3 h-4 w-32 animate-pulse rounded bg-zinc-100 dark:bg-zinc-800`}),(0,L.jsx)(`div`,{className:`space-y-2`,children:Array.from({length:4}).map((e,t)=>(0,L.jsx)(`div`,{className:`h-8 w-full animate-pulse rounded bg-zinc-100 dark:bg-zinc-800`},t))})]})}function Le({label:e}){return(0,L.jsxs)(`div`,{className:`rounded-xl border border-dashed border-zinc-200 p-6 text-center text-xs text-zinc-500 dark:border-zinc-800 dark:text-zinc-400`,children:[`No standings yet for `,(0,L.jsx)(`span`,{className:`font-medium`,children:e}),`.`]})}function Re(e,t){return f({queryKey:[`streaks`,e,t],queryFn:()=>O(`/games/${e}/tournaments/${t}/streaks`),enabled:!!t,staleTime:300*1e3})}function ze(e,t){return f({queryKey:[`mapMeta`,e,t],queryFn:()=>O(`/games/${e}/tournaments/${t}/map-meta`),enabled:!!t,staleTime:300*1e3})}function Be(e,t){return j(de.ratingMovers,{gameSlug:e,tournamentSlug:t},{enabled:!!t})}function Ve({streaks:e,gameSlug:t}){if(e.length===0)return null;let n=e.filter(e=>e.streak>0),r=e.filter(e=>e.streak<0);return(0,L.jsxs)(`div`,{className:`glk-card`,children:[(0,L.jsx)(`h3`,{className:`glk-eyebrow mb-3`,children:`Streaks`}),(0,L.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[n.length>0&&(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`mb-2 flex items-center gap-1.5 text-xs font-semibold text-emerald-500`,children:[(0,L.jsx)(E,{size:12}),`Hot`]}),(0,L.jsx)(`div`,{className:`space-y-1.5`,children:n.map(e=>(0,L.jsx)(He,{entry:e},e.team.id))})]}),r.length>0&&(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`mb-2 flex items-center gap-1.5 text-xs font-semibold text-red-500`,children:[(0,L.jsx)(l,{size:12}),`Cold`]}),(0,L.jsx)(`div`,{className:`space-y-1.5`,children:r.map(e=>(0,L.jsx)(He,{entry:e},e.team.id))})]})]})]})}function He({entry:e}){let t=e.streak>0;return(0,L.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md px-2 py-1.5`,children:[(0,L.jsx)(A,{name:e.team.name,abbreviation:e.team.abbreviation,logoUrl:e.team.logoUrl,size:`xs`}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-zinc-900 dark:text-zinc-100`,children:e.team.abbreviation??e.team.name}),(0,L.jsx)(ge,{tone:t?`up`:`down`,icon:!1,children:t?`${e.streak}W`:`${Math.abs(e.streak)}L`}),(0,L.jsx)(`div`,{className:`flex gap-0.5`,children:e.matches.map((e,t)=>(0,L.jsx)(`div`,{title:`${e.won?`W`:`L`} vs ${e.opponentAbbr}`,className:N(`h-2 w-2 rounded-full`,e.won?`bg-emerald-500`:`bg-red-500`)},t))})]})}function Ue({data:e}){let[t,n]=(0,F.useState)(`play`);return e.maps.length===0?null:(0,L.jsxs)(`div`,{className:`glk-card`,children:[(0,L.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,L.jsx)(`h3`,{className:`glk-eyebrow`,children:`Map Meta`}),(0,L.jsxs)(`div`,{className:`flex gap-1 rounded-full bg-zinc-200/80 p-0.5 dark:bg-zinc-800`,children:[(0,L.jsx)(`button`,{onClick:()=>n(`play`),className:N(`rounded-full px-2.5 py-0.5 text-2xs font-medium transition-colors`,t===`play`?`bg-zinc-50 text-zinc-900 shadow-sm dark:bg-zinc-700 dark:text-zinc-100`:`text-zinc-500 hover:text-zinc-700 dark:text-zinc-400`),children:`Play Rates`}),(0,L.jsx)(`button`,{onClick:()=>n(`vetoes`),className:N(`rounded-full px-2.5 py-0.5 text-2xs font-medium transition-colors`,t===`vetoes`?`bg-zinc-50 text-zinc-900 shadow-sm dark:bg-zinc-700 dark:text-zinc-100`:`text-zinc-500 hover:text-zinc-700 dark:text-zinc-400`),children:`Vetoes`})]})]}),t===`play`?(0,L.jsxs)(`div`,{className:`space-y-2`,children:[e.maps.filter(e=>e.playCount>0).map(e=>(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`mb-0.5 flex items-center justify-between text-xs`,children:[(0,L.jsx)(`span`,{className:`font-medium text-zinc-900 dark:text-zinc-100`,children:e.mapName}),(0,L.jsxs)(`span`,{className:`tabular-nums text-zinc-400`,children:[e.playCount,`×`]})]}),(0,L.jsxs)(`div`,{className:`flex h-2 overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700`,children:[(0,L.jsx)(`div`,{className:`bg-amber-500/80`,style:{width:`${e.attackWinRate*100}%`},title:`Attack: ${Math.round(e.attackWinRate*100)}%`}),(0,L.jsx)(`div`,{className:`bg-sky-500/80`,style:{width:`${e.defenseWinRate*100}%`},title:`Defense: ${Math.round(e.defenseWinRate*100)}%`})]})]},e.mapName)),(0,L.jsxs)(`div`,{className:`flex items-center gap-3 pt-1 text-2xs text-zinc-400`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500/80`}),` ATK`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-sky-500/80`}),` DEF`]})]})]}):(0,L.jsxs)(`div`,{className:`space-y-2`,children:[e.maps.filter(e=>e.pickCount+e.banCount+e.deciderCount>0).map(e=>{let t=e.pickCount+e.banCount+e.deciderCount;return(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`mb-0.5 flex items-center justify-between text-xs`,children:[(0,L.jsx)(`span`,{className:`font-medium text-zinc-900 dark:text-zinc-100`,children:e.mapName}),(0,L.jsxs)(`div`,{className:`flex gap-2 tabular-nums text-zinc-400`,children:[e.pickCount>0&&(0,L.jsxs)(`span`,{className:`text-emerald-500`,children:[e.pickCount,`P`]}),e.banCount>0&&(0,L.jsxs)(`span`,{className:`text-red-500`,children:[e.banCount,`B`]}),e.deciderCount>0&&(0,L.jsxs)(`span`,{className:`text-amber-500`,children:[e.deciderCount,`D`]})]})]}),(0,L.jsxs)(`div`,{className:`flex h-2 overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700`,children:[e.pickCount>0&&(0,L.jsx)(`div`,{className:`bg-emerald-500`,style:{width:`${e.pickCount/t*100}%`}}),e.banCount>0&&(0,L.jsx)(`div`,{className:`bg-red-500`,style:{width:`${e.banCount/t*100}%`}}),e.deciderCount>0&&(0,L.jsx)(`div`,{className:`bg-amber-500`,style:{width:`${e.deciderCount/t*100}%`}})]})]},e.mapName)}),e.totalVetoes===0&&(0,L.jsx)(`p`,{className:`py-2 text-center text-xs text-zinc-400`,children:`No veto data yet`})]})]})}function We({data:e,gameSlug:t}){return e.risers.length===0&&e.fallers.length===0?null:(0,L.jsxs)(`div`,{className:`glk-card`,children:[(0,L.jsxs)(`h3`,{className:`glk-eyebrow mb-3 flex items-center gap-1.5`,children:[(0,L.jsx)(d,{size:12,className:`text-emerald-500`}),(0,L.jsx)(l,{size:12,className:`text-red-500`}),`Rating Movers`]}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[e.risers.map(e=>(0,L.jsx)(Ge,{mover:e,direction:`up`},e.team.id)),e.risers.length>0&&e.fallers.length>0&&(0,L.jsx)(`div`,{className:`my-1 border-t border-zinc-200 dark:border-zinc-800`}),e.fallers.map(e=>(0,L.jsx)(Ge,{mover:e,direction:`down`},e.team.id))]})]})}function Ge({mover:e,direction:t}){let n=t===`up`;return(0,L.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md px-2 py-1.5`,children:[(0,L.jsx)(A,{name:e.team.name,abbreviation:e.team.abbreviation,logoUrl:e.team.logoUrl,size:`xs`}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-zinc-900 dark:text-zinc-100`,children:e.team.abbreviation??e.team.name}),(0,L.jsx)(`span`,{className:`text-xs tabular-nums text-zinc-400`,children:e.ratingCurrent}),(0,L.jsxs)(ge,{tone:n?`up`:`down`,children:[n?`+`:``,e.delta]}),e.history.length>=2&&(0,L.jsx)(fe,{data:e.history.map(e=>e.rating),width:40,height:16,color:n?`var(--glk-win)`:`var(--glk-loss)`})]})}function Ke(e,t){let n=e.team1?.id===t,r=e.team1Maps??e.stats?.team1Maps??null,i=e.team2Maps??e.stats?.team2Maps??null,a=n?r:i,o=n?i:r;if((a==null||a===0&&o===0)&&e.stats?.seriesScore){let[t,r]=Array.isArray(e.stats.seriesScore)?e.stats.seriesScore:e.stats.seriesScore.split(`-`).map(Number);!isNaN(t)&&!isNaN(r)&&(a=n?t:r,o=n?r:t)}return{teamMaps:a,oppMaps:o}}function qe(e,t){return e.team1?.id===t?e.team2:e.team1}function Je({journey:e,onClear:t}){let{status:n,currentStreak:r}=e;return(0,L.jsx)(`div`,{className:`glk-card animate-in slide-in-from-top-2 fade-in mb-6 overflow-hidden duration-300 !p-0`,children:(0,L.jsxs)(`div`,{className:`p-4 md:p-5`,children:[(0,L.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(A,{name:e.teamName,logoUrl:e.teamLogoUrl,abbreviation:null,size:`md`}),(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`h2`,{className:`glk-eyebrow text-zinc-900 dark:text-zinc-100`,children:[e.teamName,`'s Tournament`]}),(0,L.jsx)(`p`,{className:`text-xs text-zinc-400`,children:`Team Journey`})]})]}),(0,L.jsx)(`button`,{onClick:t,className:`rounded-md p-1.5 text-zinc-400 transition-colors hover:bg-zinc-200 hover:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`,"aria-label":`Clear team selection`,children:(0,L.jsx)(s,{size:16})})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-4`,children:[(0,L.jsxs)(`div`,{className:`glk-card !p-3 text-center`,children:[(0,L.jsx)(`div`,{className:`glk-eyebrow`,children:`Record`}),(0,L.jsxs)(`div`,{className:`mt-1 glk-metric glk-metric-lg text-zinc-900 dark:text-zinc-100`,children:[(0,L.jsx)(`span`,{className:`text-emerald-500`,children:e.wins}),(0,L.jsx)(`span`,{className:`mx-0.5 text-zinc-300 dark:text-zinc-600`,children:`-`}),(0,L.jsx)(`span`,{className:`text-red-500`,children:e.losses})]})]}),(0,L.jsxs)(`div`,{className:`glk-card !p-3 text-center`,children:[(0,L.jsx)(`div`,{className:`glk-eyebrow`,children:`Maps`}),(0,L.jsxs)(`div`,{className:`mt-1 glk-metric glk-metric-lg text-zinc-900 dark:text-zinc-100`,children:[(0,L.jsx)(`span`,{className:`text-emerald-500`,children:e.mapsWon}),(0,L.jsx)(`span`,{className:`mx-0.5 text-zinc-300 dark:text-zinc-600`,children:`-`}),(0,L.jsx)(`span`,{className:`text-red-500`,children:e.mapsLost})]})]}),(0,L.jsxs)(`div`,{className:`glk-card !p-3 text-center`,children:[(0,L.jsx)(`div`,{className:`glk-eyebrow`,children:`Streak`}),(0,L.jsxs)(`div`,{className:N(`mt-1 flex items-center justify-center gap-1 glk-metric glk-metric-lg`,r.type===`W`?`text-emerald-500`:`text-red-500`),children:[r.type,r.count,r.type===`W`&&r.count>=3&&(0,L.jsx)(E,{size:18,className:`text-amber-500`})]})]}),(0,L.jsxs)(`div`,{className:`glk-card !p-3 text-center`,children:[(0,L.jsx)(`div`,{className:`glk-eyebrow`,children:`Status`}),(0,L.jsxs)(`div`,{className:`mt-1`,children:[n===`active`&&(0,L.jsx)(P,{tone:`success`,pulse:!0,children:`Active`}),n===`eliminated`&&(0,L.jsx)(P,{tone:`danger`,icon:(0,L.jsx)(x,{size:12}),children:`Eliminated`}),n===`champion`&&(0,L.jsx)(P,{tone:`warning`,icon:(0,L.jsx)(w,{size:12}),children:`Champion`})]})]})]}),(e.biggestWin||e.closestMatch)&&(0,L.jsxs)(`div`,{className:`mt-4 border-t border-zinc-200 pt-3 dark:border-zinc-700`,children:[(0,L.jsx)(`div`,{className:`glk-eyebrow`,children:`Notable`}),(0,L.jsxs)(`div`,{className:`mt-1.5 space-y-1`,children:[e.biggestWin&&(()=>{let t=qe(e.biggestWin,e.teamId),{teamMaps:n,oppMaps:r}=Ke(e.biggestWin,e.teamId);return(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-zinc-500 dark:text-zinc-400`,children:[(0,L.jsx)(`span`,{className:`text-xs font-medium text-zinc-400`,children:`Biggest Win`}),(0,L.jsxs)(`span`,{className:`text-zinc-900 dark:text-zinc-100`,children:[`vs `,t?.abbreviation??t?.name??`TBD`]}),n!=null&&r!=null&&(0,L.jsxs)(`span`,{className:`font-bold tabular-nums text-emerald-500`,children:[`(`,n,`-`,r,`)`]})]})})(),e.closestMatch&&e.closestMatch.id!==e.biggestWin?.id&&(()=>{let t=qe(e.closestMatch,e.teamId),{teamMaps:n,oppMaps:r}=Ke(e.closestMatch,e.teamId),i=e.closestMatch.winner?.id===e.teamId;return(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-zinc-500 dark:text-zinc-400`,children:[(0,L.jsx)(`span`,{className:`text-xs font-medium text-zinc-400`,children:`Closest Match`}),(0,L.jsxs)(`span`,{className:`text-zinc-900 dark:text-zinc-100`,children:[`vs `,t?.abbreviation??t?.name??`TBD`]}),n!=null&&r!=null&&(0,L.jsxs)(`span`,{className:N(`font-bold tabular-nums`,i?`text-emerald-500`:`text-red-500`),children:[`(`,n,`-`,r,`)`]})]})})()]})]})]})})}function Ye(e,t){return e.team1?.id===t?e.team2:e.team1}function Xe(e,t){let n=e.team1?.id===t,r=e.team1Maps??e.stats?.team1Maps??null,i=e.team2Maps??e.stats?.team2Maps??null,a=n?r:i,o=n?i:r;if((a==null||a===0&&o===0)&&e.stats?.seriesScore){let[t,r]=Array.isArray(e.stats.seriesScore)?e.stats.seriesScore:e.stats.seriesScore.split(`-`).map(Number);!isNaN(t)&&!isNaN(r)&&(a=n?t:r,o=n?r:t)}return a!=null&&o!=null?`${a}-${o}`:null}function Ze(e){let t=e.playedAt??e.scheduledAt;return t?new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`}):``}function Qe(e){return!e.mapResults||e.mapResults.length===0?null:e.mapResults.map(e=>e.mapName).join(`, `)}function $e({journey:e,gameSlug:t}){let{matches:n,teamId:r}=e;return n.length===0?null:(0,L.jsxs)(`div`,{className:`mb-6`,children:[(0,L.jsx)(`h3`,{className:`glk-eyebrow mb-3`,children:`Match Timeline`}),(0,L.jsx)(`div`,{className:`relative`,children:n.map((i,a)=>{let o=i.winner?.id===r,s=i.winner&&i.winner.id!==r,c=!i.winner,l=a===n.length-1,u=l&&e.status===`champion`&&o,d=Ye(i,r),f=Xe(i,r),p=Ze(i),m=Qe(i);return(0,L.jsxs)(`div`,{className:`relative flex gap-4`,style:{animationDelay:`${a*50}ms`},children:[(0,L.jsxs)(`div`,{className:`flex flex-col items-center`,children:[u?(0,L.jsx)(`div`,{className:`relative z-10 flex h-5 w-5 items-center justify-center`,children:(0,L.jsx)(`div`,{className:`h-4 w-4 rotate-45 rounded-sm bg-amber-500 shadow-[0_0_8px_rgba(245,158,11,0.5)]`})}):(0,L.jsx)(`div`,{className:N(`relative z-10 h-3 w-3 flex-shrink-0 rounded-full mt-1`,o&&`bg-emerald-500 shadow-[0_0_6px_rgba(16,185,129,0.4)]`,s&&`bg-red-500 shadow-[0_0_6px_rgba(239,68,68,0.4)]`,c&&`border-2 border-zinc-500 bg-transparent`)}),!l&&(0,L.jsx)(`div`,{className:N(`w-0.5 flex-1 min-h-[24px]`,o&&`bg-emerald-500/20`,s&&`bg-red-500/20`,c&&`bg-zinc-700`)})]}),(0,L.jsxs)(y,{to:`/${t}/matches/${i.id}`,className:N(`group mb-3 flex-1 rounded-lg border px-3 py-2.5 transition-colors`,`border-zinc-200 bg-zinc-50 hover:border-zinc-300 dark:border-zinc-800 dark:bg-zinc-900 dark:hover:border-zinc-700`,c&&`opacity-60`),children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,L.jsx)(`span`,{className:N(`text-xs font-bold`,o&&`text-emerald-500`,s&&`text-red-500`,c&&`text-zinc-500`),children:o?`Win`:s?`Loss`:`Upcoming`}),(0,L.jsx)(`span`,{className:`text-zinc-300 dark:text-zinc-600`,children:`vs`}),d&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,L.jsx)(A,{name:d.name,abbreviation:d.abbreviation,logoUrl:d.logoUrl,size:`xs`}),(0,L.jsx)(`span`,{className:`truncate text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:d.abbreviation??d.name})]}),f&&(0,L.jsx)(`span`,{className:N(`rounded-md px-1.5 py-0.5 text-xs font-bold tabular-nums`,o&&`bg-emerald-500/10 text-emerald-500`,s&&`bg-red-500/10 text-red-500`),children:f}),u&&(0,L.jsx)(w,{size:14,className:`flex-shrink-0 text-amber-500`})]}),(0,L.jsx)(`span`,{className:`flex-shrink-0 text-xs text-zinc-400`,children:i.stage&&i.stage!==`other`?i.stage:``})]}),(p||m)&&(0,L.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-xs text-zinc-400`,children:[p&&(0,L.jsx)(`span`,{children:p}),p&&m&&(0,L.jsx)(`span`,{className:`text-zinc-300 dark:text-zinc-600`,children:`·`}),m&&(0,L.jsx)(`span`,{className:`truncate`,children:m})]})]})]},i.id)})})]})}function et({participants:e,gameSlug:t}){if(e.length===0)return null;let n=[...e].sort((e,t)=>{let n=e.rating,r=t.rating;if(n!=null&&r!=null){if(r!==n)return r-n}else if(n!=null)return-1;else if(r!=null)return 1;return e.name.localeCompare(t.name)});return(0,L.jsxs)(`div`,{className:`glk-card !p-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3`,children:[(0,L.jsx)(`h3`,{className:`glk-eyebrow`,children:`Field`}),(0,L.jsxs)(`span`,{className:`glk-tabular text-xs text-zinc-500 dark:text-zinc-400`,children:[e.length,` `,e.length===1?`team`:`teams`]})]}),(0,L.jsx)(`ul`,{className:`grid grid-cols-2 gap-1 px-2 pb-2 sm:grid-cols-3`,children:n.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(y,{to:`/${t}/teams/${e.slug}`,className:`group flex items-center gap-2.5 rounded-md px-2 py-1.5 transition-colors hover:bg-zinc-100 dark:hover:bg-zinc-800/50`,children:[(0,L.jsx)(A,{name:e.name,slug:e.slug,abbreviation:e.abbreviation,logoUrl:e.logoUrl,size:`sm`}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-zinc-900 transition-colors group-hover:text-[var(--glk-brand)] dark:text-zinc-100`,children:e.name}),e.rating!=null&&(0,L.jsx)(`span`,{className:`glk-tabular flex-shrink-0 text-xs font-bold text-zinc-500 dark:text-zinc-400`,children:e.rating})]})},e.id))})]})}var tt={primary:`border-l-[var(--glk-brand)]`,info:`border-l-blue-500/70 dark:border-l-blue-400/70`,warning:`border-l-amber-500/70 dark:border-l-amber-400/70`,neutral:`border-l-zinc-400/70 dark:border-l-zinc-500/70`,danger:`border-l-red-500/70 dark:border-l-red-400/70`};function nt({storylines:e}){return e.length===0?null:(0,L.jsxs)(`div`,{className:`glk-card !p-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3`,children:[(0,L.jsx)(ee,{size:14,className:`text-[var(--glk-brand)]`,"aria-hidden":`true`}),(0,L.jsx)(`h3`,{className:`glk-eyebrow`,children:`Storylines`})]}),(0,L.jsx)(`ul`,{className:`space-y-1.5 px-3 pb-3`,children:e.map((e,t)=>(0,L.jsx)(`li`,{className:N(`rounded-md border-l-2 bg-zinc-50 px-3 py-2 text-sm leading-snug text-zinc-700 dark:bg-zinc-900/40 dark:text-zinc-200`,tt[e.tone]??tt.info),children:e.text},t))})]})}function rt(e){return e.isChampion?`text-amber-500`:e.rank<=4?`text-zinc-700 dark:text-zinc-200`:`text-zinc-400`}function it({placements:e,gameSlug:t}){return e.length===0?null:(0,L.jsxs)(`div`,{className:`glk-card !p-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(w,{size:14,className:`text-amber-500`,"aria-hidden":`true`}),(0,L.jsx)(`h3`,{className:`glk-eyebrow`,children:`Final Placements`})]}),(0,L.jsxs)(`span`,{className:`glk-tabular text-xs text-zinc-500 dark:text-zinc-400`,children:[e.length,` `,e.length===1?`team`:`teams`]})]}),(0,L.jsx)(`ol`,{className:`space-y-0.5 px-2 pb-2`,children:e.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(y,{to:`/${t}/teams/${e.team.slug}`,className:N(`group flex items-center gap-2.5 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-zinc-100 dark:hover:bg-zinc-800/50`,e.isChampion&&`bg-amber-500/5`),children:[(0,L.jsx)(`span`,{className:N(`glk-tabular w-12 text-center text-xs font-bold`,rt(e)),"aria-label":`Rank ${e.rankLabel}`,children:e.rankLabel}),(0,L.jsx)(A,{name:e.team.name,slug:e.team.slug,abbreviation:e.team.abbreviation,logoUrl:e.team.logoUrl,size:`sm`}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-semibold text-zinc-900 transition-colors group-hover:text-[var(--glk-brand)] dark:text-zinc-100`,children:e.team.name}),e.isChampion&&(0,L.jsx)(`span`,{className:`glk-eyebrow text-amber-600 dark:text-amber-400`,children:`Champion`})]})},e.team.id))})]})}function at(e,t){let n=e.team1Maps??e.stats?.team1Maps??null,r=e.team2Maps??e.stats?.team2Maps??null,i=t?n:r,a=t?r:n;if((i==null||i===0&&a===0)&&e.stats?.seriesScore){let[n,r]=Array.isArray(e.stats.seriesScore)?e.stats.seriesScore:e.stats.seriesScore.split(`-`).map(Number);!isNaN(n)&&!isNaN(r)&&(i=t?n:r,a=t?r:n)}return{mine:i,theirs:a}}function ot(e){if(!e)return``;let t=e.replace(/^Playoffs:\s*/i,``).replace(/^Group Stage:\s*/i,``).trim(),n=t.toLowerCase();if(n.includes(`grand final`))return`Grand Final`;if(n.includes(`upper final`))return`Upper Final`;if(n.includes(`lower final`))return`Lower Final`;let r=t.match(/upper\s*round\s*(\d+)/i);if(r)return`UR${r[1]}`;let i=t.match(/lower\s*round\s*(\d+)/i);return i?`LR${i[1]}`:t}function st({champion:e,matches:t,gameSlug:n}){let r=(0,F.useMemo)(()=>{let n=t.filter(t=>t.playedAt&&t.winner&&(t.team1?.id===e.id||t.team2?.id===e.id)).sort((e,t)=>new Date(e.playedAt).getTime()-new Date(t.playedAt).getTime()).filter(t=>t.winner?.id===e.id);return n.map((t,r)=>{let i=t.team1?.id===e.id,a=i?t.team2:t.team1;if(!a)return null;let{mine:o,theirs:s}=at(t,i);if(o==null||s==null)return null;let c=o,l=s,u=(i?t.team1?.rating:t.team2?.rating)??null,d=(i?t.team2?.rating:t.team1?.rating)??null,f=u!=null&&d!=null&&d-u>=75,p=Math.abs(c-l)===1&&Math.max(c,l)>=2,m=r===n.length-1,h=ot(t.stage);return h||=m?`Final`:r<Math.ceil(n.length/2)?`Group`:`Playoffs`,m&&/^playoffs?$/i.test(h)&&(h=`Grand Final`),{match:t,opponent:a,opponentRating:d,championMaps:c,opponentMaps:l,isFinal:m,isClutch:p,isUpset:f,stageLabel:h}}).filter(e=>e!==null)},[t,e.id]);return r.length===0?null:(0,L.jsxs)(`section`,{"aria-label":`Champion's path`,className:`glk-card relative overflow-hidden !p-0`,children:[(0,L.jsx)(`div`,{"aria-hidden":!0,className:N(`pointer-events-none absolute inset-0`,`bg-[linear-gradient(115deg,transparent_0%,transparent_45%,color-mix(in_srgb,var(--glk-brand)_4%,transparent)_75%,color-mix(in_srgb,var(--glk-brand)_8%,transparent)_100%)]`)}),(0,L.jsxs)(`header`,{className:`relative flex items-center justify-between gap-3 px-4 py-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(w,{size:14,className:`text-[var(--glk-brand)]`,"aria-hidden":!0}),(0,L.jsx)(`h3`,{className:`glk-eyebrow`,children:`Champion's Path`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-500 dark:text-zinc-400`,children:[(0,L.jsx)(A,{name:e.name,abbreviation:e.abbreviation,logoUrl:e.logoUrl,size:`xs`}),(0,L.jsx)(`span`,{className:`font-semibold text-zinc-900 dark:text-zinc-100`,children:e.name}),(0,L.jsx)(`span`,{"aria-hidden":!0,className:`text-zinc-300 dark:text-zinc-600`,children:`·`}),(0,L.jsxs)(`span`,{className:`tabular-nums`,children:[r.length,`-0 to the trophy`]})]})]}),(0,L.jsx)(`div`,{className:`relative`,children:(0,L.jsx)(`ol`,{className:`glk-stagger flex snap-x snap-mandatory gap-2 overflow-x-auto px-4 pb-4 pt-1 [scrollbar-width:thin]`,"aria-label":`Match-by-match path to the championship`,children:r.map((e,t)=>(0,L.jsxs)(`li`,{className:`flex shrink-0 items-stretch snap-start`,style:{"--glk-stagger-i":t},children:[(0,L.jsx)(ct,{step:e,gameSlug:n}),t<r.length-1&&(0,L.jsx)(`div`,{"aria-hidden":!0,className:`flex w-6 shrink-0 items-center justify-center self-stretch text-zinc-300 dark:text-zinc-700`,children:(0,L.jsx)(a,{size:18})})]},e.match.id))})})]})}function ct({step:e,gameSlug:t}){let{match:n,opponent:r,championMaps:i,opponentMaps:a,isFinal:o,isClutch:s,isUpset:c,stageLabel:l}=e;return(0,L.jsxs)(y,{to:`/${t}/matches/${n.id}`,className:N(`group relative flex w-[156px] flex-col gap-2 rounded-lg border px-3 py-2.5 transition-colors sm:w-[172px]`,`border-zinc-200 bg-white hover:border-[var(--glk-brand)]/40 hover:bg-zinc-50`,`dark:border-zinc-800 dark:bg-zinc-900/60 dark:hover:border-[var(--glk-brand)]/50 dark:hover:bg-zinc-900`,o&&[`border-amber-400/70 bg-gradient-to-br from-amber-50 to-white`,`shadow-[0_0_0_1px_rgba(245,158,11,0.15),0_8px_24px_-12px_rgba(245,158,11,0.35)]`,`dark:border-amber-400/40 dark:from-amber-500/10 dark:to-zinc-900`,`dark:shadow-[0_0_0_1px_rgba(245,158,11,0.18),0_8px_24px_-10px_rgba(245,158,11,0.4)]`]),children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-1`,children:[(0,L.jsx)(`span`,{className:N(`truncate text-[10px] font-bold uppercase tracking-wider`,o?`text-amber-600 dark:text-amber-400`:`text-zinc-400`),children:l}),o&&(0,L.jsx)(w,{size:12,className:`shrink-0 text-amber-500`,"aria-label":`Championship match`}),!o&&c&&(0,L.jsx)(`span`,{className:`shrink-0 rounded-full border border-[var(--glk-brand)]/40 bg-[var(--glk-brand)]/8 px-1.5 py-px text-[9px] font-bold uppercase tracking-wider text-[var(--glk-brand)]`,title:`Champion was lower-rated entering this match`,children:`Upset`}),!o&&!c&&s&&(0,L.jsx)(`span`,{className:`shrink-0 rounded-full border border-amber-500/30 bg-amber-500/8 px-1.5 py-px text-[9px] font-bold uppercase tracking-wider text-amber-600 dark:text-amber-400`,title:`Decided by a single map`,children:`Clutch`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(A,{name:r.name,abbreviation:r.abbreviation,logoUrl:r.logoUrl,size:`xs`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`div`,{className:`truncate text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:r.abbreviation??r.name}),e.opponentRating!=null&&(0,L.jsxs)(`div`,{className:`text-[10px] tabular-nums text-zinc-400`,children:[`Glicko `,Math.round(e.opponentRating)]})]})]}),(0,L.jsxs)(`div`,{className:`flex items-baseline gap-1`,children:[(0,L.jsx)(`span`,{className:N(`glk-metric glk-metric-xl tabular-nums leading-none`,o?`text-amber-500 dark:text-amber-400`:`text-emerald-500 dark:text-emerald-400`),children:i}),(0,L.jsx)(`span`,{className:`text-sm font-bold tabular-nums text-zinc-300 dark:text-zinc-600`,children:`–`}),(0,L.jsx)(`span`,{className:`text-sm font-bold tabular-nums text-zinc-400 dark:text-zinc-500`,children:a}),n.format&&(0,L.jsx)(`span`,{className:`ml-auto self-end text-[10px] uppercase tracking-wider text-zinc-400`,children:n.format})]})]})}function lt({distribution:e,prizePool:t}){let n=(e?.entries.length??0)>0,r=!!t&&!t.includes(`TBD`)&&t!==`$0 USD`;if(!n&&!r)return null;if(!n)return(0,L.jsxs)(`div`,{className:`glk-card !p-0`,"data-testid":`prize-distribution-fallback`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(m,{size:14,className:`text-emerald-500`,"aria-hidden":`true`}),(0,L.jsx)(`h3`,{className:`glk-eyebrow`,children:`Prize Distribution`})]}),(0,L.jsx)(`span`,{className:`glk-tabular text-xs font-semibold text-zinc-900 dark:text-zinc-100`,children:t})]}),(0,L.jsx)(`p`,{className:`px-4 pb-3 text-xs text-zinc-500 dark:text-zinc-400`,children:`Per-place breakdown not published yet.`})]});let i=e.entries;return(0,L.jsxs)(`div`,{className:`glk-card !p-0`,"data-testid":`prize-distribution-table`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(m,{size:14,className:`text-emerald-500`,"aria-hidden":`true`}),(0,L.jsx)(`h3`,{className:`glk-eyebrow`,children:`Prize Distribution`})]}),r&&(0,L.jsx)(`span`,{className:`glk-tabular text-xs font-semibold text-zinc-900 dark:text-zinc-100`,children:t})]}),(0,L.jsx)(`ol`,{className:`space-y-0.5 px-2 pb-2`,children:i.map((e,t)=>(0,L.jsxs)(`li`,{className:N(`flex items-center gap-2.5 rounded-md px-2 py-1.5 text-sm`,t===0&&`bg-amber-500/5`),children:[(0,L.jsx)(`span`,{className:N(`glk-tabular w-16 text-center text-xs font-bold`,t===0?`text-amber-500`:t<=2?`text-zinc-700 dark:text-zinc-200`:`text-zinc-400`),"aria-label":`Place ${e.place}`,children:e.place}),(0,L.jsx)(`span`,{className:`glk-tabular min-w-0 flex-1 font-semibold text-zinc-900 dark:text-zinc-100`,children:e.amount}),e.teamId&&(0,L.jsx)(`span`,{className:`glk-tabular hidden text-xs text-zinc-400 sm:inline`,children:e.teamId})]},`${e.place}-${t}`))})]})}function ut({participants:e,matches:t,championId:n}){let r=new Map;for(let t of e)r.set(t.id,{team:t,lastLossAt:null,lastMatchAt:null,anyLoss:!1});for(let e of t){if(!e.team1||!e.team2||!e.playedAt)continue;let t=new Date(e.playedAt).getTime(),n=e.winner?.id??null;for(let i of[e.team1,e.team2]){let e=r.get(i.id);e&&((e.lastMatchAt==null||t>e.lastMatchAt)&&(e.lastMatchAt=t),n&&n!==i.id&&(e.anyLoss=!0,(e.lastLossAt==null||t>e.lastLossAt)&&(e.lastLossAt=t)))}}let i=e=>{if(e==null)return-1/0;let t=new Date(e);return Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())},a=[...r.values()].sort((e,t)=>{let r=n?e.team.id===n:!e.anyLoss;if(r!==(n?t.team.id===n:!t.anyLoss))return r?-1:1;let a=i(e.lastLossAt),o=i(t.lastLossAt);return a===o?e.team.name.localeCompare(t.team.name):o-a}),o=e=>{if(e==null)return null;let t=new Date(e);return`${t.getUTCFullYear()}-${t.getUTCMonth()}-${t.getUTCDate()}`},s=[],c=0,l=1;for(;c<a.length;){let e=a[c];if(n?e.team.id===n:!e.anyLoss){s.push({rank:1,rankLabel:`1`,team:e.team,lastMatchAt:e.lastMatchAt==null?null:new Date(e.lastMatchAt).toISOString(),isChampion:!0}),l=2,c+=1;continue}let t=o(e.lastLossAt),r=c;for(;r<a.length&&o(a[r].lastLossAt)===t&&(n?a[r].team.id!==n:a[r].anyLoss);)r+=1;let i=r-c,u=l,d=l+i-1,f=i>1?`${u}–${d}`:`${u}`;for(let e=c;e<r;e+=1){let t=a[e];s.push({rank:u,rankLabel:f,team:t.team,lastMatchAt:t.lastMatchAt==null?null:new Date(t.lastMatchAt).toISOString(),isChampion:!1})}l=d+1,c=r}return s}function dt(e){let t=e.team1?.rating,n=e.team2?.rating;return t==null||n==null?0:t+n}function ft(e,t){if(t===`completed`)return[...e].filter(e=>e.playedAt).sort((e,t)=>new Date(t.playedAt).getTime()-new Date(e.playedAt).getTime())[0]??null;let n=new Date,r=e.filter(e=>!e.playedAt&&e.scheduledAt&&new Date(e.scheduledAt)>n&&e.team1&&e.team2).sort((e,t)=>new Date(e.scheduledAt).getTime()-new Date(t.scheduledAt).getTime());if(r.length>0){let e=new Date(r[0].scheduledAt),t=new Date(e.getTime()+10080*60*1e3);return r.filter(e=>new Date(e.scheduledAt)<=t).reduce((e,t)=>e?dt(t)>dt(e)?t:e:t,null)||r[0]}return e.filter(e=>e.playedAt).sort((e,t)=>new Date(t.playedAt).getTime()-new Date(e.playedAt).getTime())[0]??null}function pt(e){let t=new Map;for(let n of e){if(!n.winner||!n.team1||!n.team2)continue;let e=n.winner.id,r=e===n.team1.id?n.team2.id:n.team1.id,i=e===n.team1.id?n.team1:n.team2,a=r===n.team1.id?n.team1:n.team2;t.has(e)||t.set(e,{team:i,wins:0,losses:0}),t.has(r)||t.set(r,{team:a,wins:0,losses:0}),t.get(e).wins++,t.get(r).losses++}return Array.from(t.values()).sort((e,t)=>t.wins-e.wins||e.losses-t.losses).slice(0,6)}function mt(e){let t=e.playedAt??e.scheduledAt;return t?new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`}):``}function ht(e){let t=e.team1Maps??null,n=e.team2Maps??null;if(t==null&&n==null&&(t=e.stats?.team1Maps??null,n=e.stats?.team2Maps??null),(t===0&&n===0||t==null)&&e.stats?.seriesScore){let[r,i]=Array.isArray(e.stats.seriesScore)?e.stats.seriesScore:e.stats.seriesScore.split(`-`).map(Number);!isNaN(r)&&!isNaN(i)&&(t=r,n=i)}return t!=null&&n!=null?{t1:t,t2:n}:null}function gt({match:e,gameSlug:t}){let n=e.team1??{id:``,name:`TBD`,abbreviation:null,logoUrl:null},r=e.team2??{id:``,name:`TBD`,abbreviation:null,logoUrl:null},i=!!e.playedAt||e.status===`completed`,a=e.status===`live`,o=!i&&!a,s=ht(e),c=e.winner?.id===n.id,l=e.winner?.id===r.id;return(0,L.jsx)(y,{to:`/${t}/matches/${e.id}`,className:`glk-card group block overflow-hidden !p-0`,children:(0,L.jsxs)(`div`,{className:`px-5 py-4`,children:[(0,L.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-xs text-zinc-400`,children:[(0,L.jsx)(h,{size:12,className:`text-amber-500`}),(0,L.jsx)(`span`,{className:`glk-eyebrow`,children:`Featured Match`}),e.stage&&e.stage!==`other`&&(0,L.jsx)(P,{tone:`neutral`,size:`xs`,uppercase:!1,children:e.stage}),e.format&&(0,L.jsx)(P,{tone:`neutral`,size:`xs`,children:e.format}),a&&(0,L.jsx)(`span`,{className:`ml-auto`,children:(0,L.jsx)(P,{tone:`live`,size:`xs`,pulse:!0,children:`Live`})})]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-center gap-4 sm:gap-8`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-center`,children:[(0,L.jsx)(A,{name:n.name,abbreviation:n.abbreviation,logoUrl:n.logoUrl,size:`lg`}),(0,L.jsx)(`span`,{className:N(`text-sm font-bold`,i&&c&&`text-[var(--glk-brand)]`,i&&!c&&`text-zinc-400 dark:text-zinc-500`,!i&&`text-zinc-900 dark:text-zinc-100`),children:n.abbreviation??n.name})]}),(0,L.jsx)(`div`,{className:`flex-shrink-0 text-center`,children:i&&s?(0,L.jsxs)(`div`,{className:`glk-metric glk-metric-xl text-zinc-900 dark:text-zinc-100`,children:[s.t1,(0,L.jsx)(`span`,{className:`mx-1 text-zinc-300 dark:text-zinc-600`,children:`-`}),s.t2]}):a?(0,L.jsx)(`div`,{className:`text-lg font-bold text-[var(--glk-brand)]`,children:`LIVE`}):(0,L.jsx)(`div`,{className:`text-lg font-bold text-zinc-400`,children:`vs`})}),(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-center`,children:[(0,L.jsx)(A,{name:r.name,abbreviation:r.abbreviation,logoUrl:r.logoUrl,size:`lg`}),(0,L.jsx)(`span`,{className:N(`text-sm font-bold`,i&&l&&`text-[var(--glk-brand)]`,i&&!l&&`text-zinc-400 dark:text-zinc-500`,!i&&`text-zinc-900 dark:text-zinc-100`),children:r.abbreviation??r.name})]})]}),(0,L.jsxs)(`div`,{className:`mt-4 flex items-center justify-center gap-2 text-xs text-zinc-400`,children:[o&&e.scheduledAt&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(D,{size:12}),(0,L.jsxs)(`span`,{children:[new Date(e.scheduledAt).toLocaleDateString(`en-US`,{weekday:`short`,month:`short`,day:`numeric`}),` at `,new Date(e.scheduledAt).toLocaleTimeString(`en-US`,{hour:`numeric`,minute:`2-digit`})]})]}),i&&(0,L.jsx)(`span`,{children:mt(e)}),(0,L.jsx)(`span`,{className:`text-zinc-300 dark:text-zinc-600`,children:`·`}),(0,L.jsx)(`span`,{className:`font-medium text-zinc-500 transition-colors group-hover:text-[var(--glk-brand)]`,children:`View details →`})]})]})})}function _t({match:e,gameSlug:t}){let n=e.team1??{id:``,name:`TBD`,abbreviation:null,logoUrl:null},r=e.team2??{id:``,name:`TBD`,abbreviation:null,logoUrl:null},i=e.winner?.id===n.id,a=e.winner?.id===r.id,o=ht(e);return(0,L.jsxs)(y,{to:`/${t}/matches/${e.id}`,className:`flex items-center gap-2 rounded-md px-2.5 py-2 text-sm transition-colors hover:bg-zinc-100 dark:hover:bg-zinc-800/50`,children:[(0,L.jsxs)(`div`,{className:N(`flex min-w-0 flex-1 items-center justify-end gap-1.5`,i?`text-zinc-900 dark:text-zinc-100`:`text-zinc-400 dark:text-zinc-500`),children:[(0,L.jsx)(`span`,{className:`hidden truncate text-right font-semibold md:inline`,children:n.name}),(0,L.jsx)(`span`,{className:`truncate text-right font-semibold md:hidden`,children:n.abbreviation??n.name}),(0,L.jsx)(A,{name:n.name,abbreviation:n.abbreviation,logoUrl:n.logoUrl,size:`xs`})]}),o&&(0,L.jsxs)(`span`,{className:`flex-shrink-0 text-center font-bold tabular-nums text-zinc-500 dark:text-zinc-400`,children:[o.t1,`-`,o.t2]}),(0,L.jsxs)(`div`,{className:N(`flex min-w-0 flex-1 items-center gap-1.5`,a?`text-zinc-900 dark:text-zinc-100`:`text-zinc-400 dark:text-zinc-500`),children:[(0,L.jsx)(A,{name:r.name,abbreviation:r.abbreviation,logoUrl:r.logoUrl,size:`xs`}),(0,L.jsx)(`span`,{className:`hidden truncate font-semibold md:inline`,children:r.name}),(0,L.jsx)(`span`,{className:`truncate font-semibold md:hidden`,children:r.abbreviation??r.name})]}),(0,L.jsxs)(`span`,{className:`hidden flex-shrink-0 items-center gap-1.5 text-xs text-zinc-400 lg:flex`,children:[e.stage&&e.stage!==`other`&&(0,L.jsx)(`span`,{children:e.stage}),e.format&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-zinc-300 dark:text-zinc-600`,children:`·`}),(0,L.jsx)(`span`,{children:e.format.toUpperCase()})]})]})]})}function vt({tournament:e,gameSlug:t,journey:n,onSelectTeam:r,onClearTeam:i,activeStageId:a}){let o=e.matches??[],{data:s}=z(t,e.slug),{data:c}=Re(t,e.slug),{data:l}=ze(t,e.slug),{data:u}=Be(t,e.slug),d=a?e.stages?.find(e=>e.id===a):e.stages?.[0],f=(d?.groups?.length??0)>1,p=(0,F.useMemo)(()=>ft(o,e.status),[o,e.status]),m=(0,F.useMemo)(()=>o.filter(e=>e.playedAt).sort((e,t)=>new Date(t.playedAt).getTime()-new Date(e.playedAt).getTime()).slice(0,5),[o]),h=(0,F.useMemo)(()=>pt(o.filter(e=>e.winner)),[o]),g=(s?.stages.length??0)>0,_=e.storylines??[],v=(0,F.useMemo)(()=>Te(e.participants??[],o),[e.participants,o]),y=(0,F.useMemo)(()=>e.status===`completed`?ut({participants:v,matches:o,championId:e.champion?.id??null}):[],[e.status,v,o,e.champion?.id]);return o.length===0?(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-16 text-zinc-400`,children:[(0,L.jsx)(T,{size:40,strokeWidth:1.5}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`Tournament schedule coming soon`}),(0,L.jsx)(`p`,{className:`mt-1 text-xs`,children:`Matches will appear here once the schedule is set.`})]})]}):(0,L.jsxs)(`div`,{className:`space-y-6`,children:[n&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Je,{journey:n,onClear:i}),(0,L.jsx)($e,{journey:n,gameSlug:t})]}),p&&(0,L.jsx)(gt,{match:p,gameSlug:t}),(0,L.jsx)(nt,{storylines:_}),e.status===`completed`&&e.champion&&(0,L.jsx)(st,{champion:e.champion,matches:o,gameSlug:t}),(y.length>0||v.length>0)&&(0,L.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2`,children:[y.length>0&&(0,L.jsx)(it,{placements:y,gameSlug:t}),v.length>0&&(0,L.jsx)(et,{participants:v,gameSlug:t})]}),(0,L.jsx)(lt,{distribution:e.prizeDistribution,prizePool:e.prizePool}),(0,L.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`space-y-4`,children:[m.length>0&&(0,L.jsxs)(`div`,{className:`glk-card`,children:[(0,L.jsx)(`h3`,{className:`glk-eyebrow mb-3`,children:`Recent Results`}),(0,L.jsx)(`div`,{className:`space-y-0.5`,children:m.map(e=>(0,L.jsx)(_t,{match:e,gameSlug:t},e.id))})]}),l&&l.maps.length>0&&(0,L.jsx)(Ue,{data:l})]}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[f&&d?(0,L.jsx)(Ne,{gameSlug:t,tournamentSlug:e.slug,stage:d,compact:!0}):g?(0,L.jsx)(`div`,{className:`space-y-4`,children:s.stages.map(e=>(0,L.jsx)(R,{standings:e.standings,stageName:e.stageName,matchesPlayed:e.matchesPlayed,matchesTotal:e.matchesTotal,compact:!0,gameSlug:t},e.stageId))}):h.length>0?(0,L.jsxs)(`div`,{className:`glk-card bg-zinc-50 dark:bg-zinc-900`,children:[(0,L.jsx)(`h3`,{className:`glk-eyebrow mb-3`,children:`Standings Snapshot`}),(0,L.jsx)(`div`,{className:`space-y-1`,children:h.map((e,t)=>(0,L.jsxs)(`div`,{className:N(`flex items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm`,t===0&&`bg-amber-500/5`),children:[(0,L.jsx)(`span`,{className:N(`w-5 text-center text-xs font-bold tabular-nums`,t===0?`text-amber-500`:`text-zinc-400`),children:t+1}),(0,L.jsx)(A,{name:e.team.name,abbreviation:e.team.abbreviation,logoUrl:e.team.logoUrl,size:`xs`}),(0,L.jsx)(`button`,{onClick:()=>e.team.slug&&r(e.team.slug),className:`min-w-0 flex-1 truncate text-left font-medium text-zinc-900 transition-colors hover:text-[var(--glk-brand)] dark:text-zinc-100`,children:e.team.name}),(0,L.jsxs)(`span`,{className:`flex-shrink-0 text-xs tabular-nums text-zinc-500 dark:text-zinc-400`,children:[(0,L.jsxs)(`span`,{className:`font-semibold text-emerald-600 dark:text-emerald-400`,children:[e.wins,`W`]}),` - `,(0,L.jsxs)(`span`,{className:`text-zinc-400`,children:[e.losses,`L`]})]})]},e.team.id))})]}):null,u&&(u.risers.length>0||u.fallers.length>0)&&(0,L.jsx)(We,{data:u,gameSlug:t})]})]}),c&&c.length>0&&(0,L.jsx)(Ve,{streaks:c,gameSlug:t})]})}var yt={LIVE_NOW:`LIVE NOW`,TODAY:`TODAY`,TOMORROW:`TOMORROW`,THIS_WEEK:`THIS WEEK`,UPCOMING:`UPCOMING`,EARLIER_THIS_WEEK:`EARLIER THIS WEEK`,EARLIER:`EARLIER`,TBD:`DATE TBD`},bt=[`LIVE_NOW`,`TODAY`,`TOMORROW`,`THIS_WEEK`,`UPCOMING`,`EARLIER_THIS_WEEK`,`EARLIER`,`TBD`],xt=new Set([`LIVE_NOW`,`TODAY`,`TOMORROW`,`THIS_WEEK`,`UPCOMING`,`TBD`]);function B(e){let t=e.scheduledAt??e.playedAt;if(!t)return null;let n=new Date(t);return Number.isNaN(n.getTime())?null:n}function V(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function St(e,t){let n=V(e).getTime(),r=V(t).getTime();return Math.round((n-r)/864e5)}function Ct(e,t){let n=St(e,t);return n===0?`TODAY`:n===1?`TOMORROW`:n>1&&n<=7?`THIS_WEEK`:n>7?`UPCOMING`:n<0&&n>=-7?`EARLIER_THIS_WEEK`:`EARLIER`}function wt(e,t=new Date){let n=new Map,r=V(t).toISOString();for(let i of e){let e,a;if(ce(i))e=`LIVE_NOW`,a=r;else{let n=B(i);n?(e=Ct(n,t),a=V(n).toISOString()):(e=`TBD`,a=`tbd`)}n.has(e)||n.set(e,new Map);let o=n.get(e);o.has(a)||o.set(a,[]),o.get(a).push(i)}let i=[];for(let e of bt){let t=n.get(e);if(!t||t.size===0)continue;let r=[];for(let[e,n]of t.entries()){let t=[...n].sort((e,t)=>(B(e)?.getTime()??0)-(B(t)?.getTime()??0));r.push({date:e===`tbd`?null:new Date(e),matches:t})}let a=xt.has(e);r.sort((e,t)=>{let n=e.date?.getTime()??0,r=t.date?.getTime()??0;return a?n-r:r-n}),i.push({bucket:e,label:yt[e],days:r})}return i}function Tt(e){return e.toLocaleDateString(void 0,{weekday:`long`})}function Et(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Dt({day:e,gameSlug:t,teamSlug:n,teamMatchIds:r,stageNameById:i,onSelectTeam:a}){let o=e.matches.filter(e=>e.playedAt).length,s=e.matches.length;return(0,L.jsxs)(`section`,{className:N(`border-t border-zinc-200/60 pt-3 dark:border-white/[0.06]`),"aria-label":e.date?Tt(e.date):`Date TBD`,children:[(0,L.jsxs)(`header`,{className:`mb-2 px-1`,children:[(0,L.jsx)(`div`,{className:`text-base font-semibold leading-tight text-zinc-900 dark:text-zinc-100 sm:text-lg`,style:{fontFamily:`var(--font-display)`,letterSpacing:`-0.01em`},children:e.date?Tt(e.date):`Date TBD`}),e.date&&(0,L.jsxs)(`div`,{className:`glk-eyebrow mt-0.5 text-2xs text-zinc-500 dark:text-zinc-500`,children:[Et(e.date),` · `,s,` `,s===1?`match`:`matches`,o>0&&` · ${o} completed`]}),!e.date&&s>0&&(0,L.jsxs)(`div`,{className:`glk-eyebrow mt-0.5 text-2xs text-zinc-500 dark:text-zinc-500`,children:[s,` `,s===1?`match`:`matches`]})]}),(0,L.jsx)(ae,{className:`gap-0 divide-y divide-zinc-100 py-0 dark:divide-white/[0.04]`,children:e.matches.map(e=>{let o=n&&r&&!r.has(e.id),s=e.stage??(e.stageId?i.get(e.stageId):void 0),c=s===e.stage?e:{...e,stage:s??null};return(0,L.jsx)(`div`,{className:N(`transition-opacity duration-300`,e.status===`tbd`&&!o&&`opacity-40`,o&&`opacity-20`),children:(0,L.jsx)(he,{match:c,gameSlug:t,variant:`schedule`,onTeamClick:a})},e.id)})})]})}function Ot({bucket:e,gameSlug:t,teamSlug:n,teamMatchIds:r,stageNameById:i,onSelectTeam:a}){return(0,L.jsxs)(`section`,{"aria-label":e.label,"data-bucket":e.bucket,children:[(0,L.jsx)(`h3`,{className:`glk-eyebrow mb-3 text-2xs uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:e.label}),(0,L.jsx)(`div`,{className:`space-y-4`,children:e.days.map((e,o)=>(0,L.jsx)(Dt,{day:e,gameSlug:t,teamSlug:n,teamMatchIds:r,stageNameById:i,onSelectTeam:a},e.date?e.date.toISOString():`tbd-${o}`))})]})}function kt({stages:e,allStages:t,gameSlug:n,teamSlug:r,teamMatchIds:i,onSelectTeam:a}){let o=(0,F.useMemo)(()=>{let t=new Set,n=[];for(let r of e)for(let e of r.matches)t.has(e.id)||(t.add(e.id),n.push(e));return n},[e]),s=(0,F.useMemo)(()=>wt(o),[o]),c=(0,F.useMemo)(()=>{let n=new Map;for(let e of t??[])n.set(e.id,e.name);for(let t of e)t.stageId&&!n.has(t.stageId)&&n.set(t.stageId,t.stage);return n},[t,e]);return o.length===0?(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-16 text-zinc-400`,children:[(0,L.jsx)(T,{size:40,strokeWidth:1.5}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`No matches yet`}),(0,L.jsx)(`p`,{className:`mt-1 text-xs`,children:`Matches will appear here once the tournament schedule is set.`})]})]}):(0,L.jsx)(`div`,{className:`space-y-8`,children:s.map(e=>(0,L.jsx)(Ot,{bucket:e,gameSlug:n,teamSlug:r,teamMatchIds:i,stageNameById:c,onSelectTeam:a},e.bucket))})}function At(e,t){let n=e.map(e=>e.name.toLowerCase()),r=e.map(e=>e.type.toLowerCase()),i=n.some(e=>e.includes(`upper`)||e.includes(`winner`))||r.some(e=>e===`upper_bracket`),a=n.some(e=>e.includes(`lower`)||e.includes(`loser`))||r.some(e=>e===`lower_bracket`),o=n.some(e=>e.includes(`grand final`))||r.some(e=>e===`grand_final`);if(i||a||o)return`double_elim`;let s=e.some(Ht),c=t.some(e=>e.team1FromMatchId!=null||e.team2FromMatchId!=null);if(!s&&!c)return`unknown`;let l=U(t,e);if(l.length===0)return`unknown`;let u=l.length;return Yt(u+1)||u>=3&&u<=31?`single_elim`:`unknown`}function jt(e,t){let n=At(t,e);return n===`unknown`?null:e.some(e=>e.team1FromMatchId!=null||e.team2FromMatchId!=null)?Mt(e,t,n):n===`double_elim`?Ft(e,t):Pt(U(e,t))}function Mt(e,t,n){let r=U(e,t);if(r.length===0)return{type:n,upper:[],lower:[],grandFinal:null};let i=new Set;for(let e of r)e.team1FromMatchId&&i.add(e.team1FromMatchId),e.team2FromMatchId&&i.add(e.team2FromMatchId);let a=r.filter(e=>!i.has(e.id)),o=new Map;for(let e of a)o.set(e.id,0);let s=!0;for(;s;){s=!1;for(let e of r){if(o.has(e.id))continue;let t=e.team1FromMatchId?o.get(e.team1FromMatchId):void 0,n=e.team2FromMatchId?o.get(e.team2FromMatchId):void 0;(t!=null||n!=null)&&(o.set(e.id,Math.max(t??0,n??0)+1),s=!0)}}for(let e of r)o.has(e.id)||o.set(e.id,0);let c=Kt(t),l=[],u=[],d=null;for(let e of r){let t=qt(e,c);t===`grand_final`?d=e:t===`lower`?u.push(e):l.push(e)}return{type:n,upper:Nt(l,o,`upper`),lower:Nt(u,o,`lower`),grandFinal:d?W(d,0,0,`grand_final`):null}}function Nt(e,t,n){if(e.length===0)return[];let r=new Map;for(let n of e){let e=t.get(n.id)??0;r.has(e)||r.set(e,[]),r.get(e).push(n)}let i=Array.from(r.keys()).sort((e,t)=>e-t),a=i.length;return i.map((e,t)=>{let i=r.get(e).sort((e,t)=>(e.scheduledAt?new Date(e.scheduledAt).getTime():0)-(t.scheduledAt?new Date(t.scheduledAt).getTime():0));return{label:G(t,a,n),round:t,matches:i.map((e,r)=>W(e,t,r,n))}})}function Pt(e){let t=[...e].sort((e,t)=>(e.scheduledAt?new Date(e.scheduledAt).getTime():0)-(t.scheduledAt?new Date(t.scheduledAt).getTime():0)),n=t.length;if(n===0)return{type:`single_elim`,upper:[],lower:[],grandFinal:null};let r=Xt(n+1),i=[],a=r/2,o=n;for(;a>=1&&o>0;){let e=Math.min(a,o);i.push(e),o-=e,a=Math.floor(a/2)}o>0&&(i[i.length-1]+=o);let s=[],c=0;for(let e=0;e<i.length;e++){let n=t.slice(c,c+i[e]);s.push({label:G(e,i.length,`upper`),round:e,matches:n.map((t,n)=>W(t,e,n,`upper`))}),c+=i[e]}return{type:`single_elim`,upper:s,lower:[],grandFinal:null}}function Ft(e,t){let n=[...U(e,t)].sort((e,t)=>(e.scheduledAt?new Date(e.scheduledAt).getTime():0)-(t.scheduledAt?new Date(t.scheduledAt).getTime():0)),r=Kt(t),i=[],a=[],o=null;for(let e of n){let t=qt(e,r);t===`grand_final`?o=e:t===`lower`?a.push(e):i.push(e)}return{type:`double_elim`,upper:It(i,t,`upper`)??Lt(i,`upper`),lower:It(a,t,`lower`)??Lt(a,`lower`),grandFinal:o?W(o,0,0,`grand_final`):null}}function It(e,t,n){if(e.length===0)return[];let r=new Map(t.map(e=>[e.id,e])),i=Array.from(new Set(e.map(e=>e.stageId).filter(e=>!!e)));if(i.length===0)return null;let a=i.map(e=>r.get(e)).filter(e=>!!e),o=a.filter(e=>H(e.name,n)!==null);if(o.length===0||o.length!==a.length)return null;let s=[...o].sort((e,t)=>{let r=H(e.name,n)??0,i=H(t.name,n)??0;return r===i?e.order-t.order:r-i}),c=s.length,l=new Map;for(let t of e){if(!t.stageId)continue;let e=l.get(t.stageId)??[];e.push(t),l.set(t.stageId,e)}return s.map((e,t)=>{let r=(l.get(e.id)??[]).sort((e,t)=>(e.scheduledAt?new Date(e.scheduledAt).getTime():0)-(t.scheduledAt?new Date(t.scheduledAt).getTime():0));return{label:G(t,c,n),round:t,matches:r.map((e,r)=>W(e,t,r,n))}})}function H(e,t){let n=e.toLowerCase();if(!(t===`upper`&&/\b(upper|winner)\b/.test(n)||t===`lower`&&/\b(lower|loser)\b/.test(n)))return null;if(/grand final/.test(n))return 1e4;if(/\bfinal\b/.test(n))return 200;if(/semifinal/.test(n))return 100;let r=n.match(/round\s+(\d+)/);return r?parseInt(r[1],10):null}function Lt(e,t){if(e.length===0)return[];let n=e.length,r=Xt(n+1),i=[],a=r/2,o=n;for(;a>=1&&o>0;){let e=Math.min(a,o);i.push(e),o-=e,a=Math.floor(a/2)}o>0&&(i[i.length-1]+=o);let s=[],c=0;for(let n=0;n<i.length;n++){let r=e.slice(c,c+i[n]);s.push({label:G(n,i.length,t),round:n,matches:r.map((e,r)=>W(e,n,r,t))}),c+=i[n]}return s}function Rt(e,t=280){let n=[],r=[],i=zt(e.upper,0,t);n.push(...i.nodes),r.push(...i.connectors);let a=i.height;if(e.type===`double_elim`&&e.lower.length>0){let o=a+48,s=zt(e.lower,o,t);if(n.push(...s.nodes),r.push(...s.connectors),a=o+s.height,e.grandFinal){let o=n.length>0?Math.max(...n.map(e=>e.x+e.width))+80:0,c=a/2-72/2;n.push({...e.grandFinal,x:o,y:c,width:t,height:72});let l=i.nodes.filter(e=>e.round===Math.max(...i.nodes.map(e=>e.round)));if(l.length>0){let e=l[0];r.push({fromX:e.x+e.width,fromY:e.y+e.height/2,toX:o,toY:c+72*.33,type:`winner`,highlighted:!1})}let u=s.nodes.filter(e=>e.round===Math.max(...s.nodes.map(e=>e.round)));if(u.length>0){let e=u[0];r.push({fromX:e.x+e.width,fromY:e.y+e.height/2,toX:o,toY:c+72*.67,type:`winner`,highlighted:!1})}a=Math.max(a,c+72)}}return{nodes:n,connectors:r,width:n.length>0?Math.max(...n.map(e=>e.x+e.width)):0,height:a,sections:{upper:{y:0,height:i.height},...e.type===`double_elim`&&e.lower.length>0?{lower:{y:i.height+48,height:a-i.height-48}}:{}}}}function zt(e,t,n){let r=[],i=[];if(e.length===0)return{nodes:r,connectors:i,height:0};let a=Math.max(...e.map(e=>e.matches.length),1)*88-16;for(let i of e){let e=i.round*(n+80),o=i.matches.length,s=o>1?(a-72)/(o-1):0,c=o>1?t:t+a/2-72/2;for(let t=0;t<i.matches.length;t++){let a=o>1?c+t*s:c;r.push({...i.matches[t],x:e,y:a,width:n,height:72})}}for(let t=0;t<e.length-1;t++){let n=e[t].round,a=e[t+1].round,o=r.filter(e=>e.round===n),s=r.filter(e=>e.round===a);for(let e=0;e<o.length;e++){let t=Math.floor(e/2);if(t<s.length){let n=o[e],r=s[t];i.push({fromX:n.x+n.width,fromY:n.y+n.height/2,toX:r.x,toY:r.y+(e%2==0?r.height*.33:r.height*.67),type:`winner`,highlighted:!1})}}}return{nodes:r,connectors:i,height:a}}var Bt=new Set([`playoff`,`upper_bracket`,`lower_bracket`,`grand_final`,`elimination`]),Vt=new Set([`group`,`swiss`,`round robin`,`round-robin`,`round_robin`,`groups`]);function Ht(e){let t=e.type.toLowerCase(),n=e.name.toLowerCase();return Bt.has(t)||n.includes(`playoff`)||n.includes(`bracket`)||n.includes(`elimination`)||n.includes(`grand final`)}function Ut(e){let t=e.name.toLowerCase(),n=e.type.toLowerCase();return Vt.has(n)||t.includes(`group`)||t.includes(`swiss`)||t.includes(`round robin`)}function U(e,t){let n=e.filter(e=>e.canonicalMatchId==null),r=new Set(t.filter(Ht).map(e=>e.id)),i;if(r.size>0)i=n.filter(e=>e.stageId&&r.has(e.stageId));else{let e=new Set(t.filter(Ut).map(e=>e.id));i=n.filter(t=>{if(t.stageId&&e.has(t.stageId))return!1;let n=t.stage?.toLowerCase()??``;return!n.includes(`group`)&&!n.includes(`swiss`)&&!n.includes(`round robin`)})}return Gt(i,t)}var Wt=360*60*1e3;function Gt(e,t){let n=new Map(t.map(e=>[e.id,e])),r=e=>{if(!e.stageId)return 1;let t=n.get(e.stageId);if(!t)return 1;let r=t.type.toLowerCase(),i=t.name.toLowerCase();return r===`upper_bracket`||r===`lower_bracket`||r===`grand_final`||i.includes(`upper`)||i.includes(`lower`)||i.includes(`grand final`)||i.includes(`semifinal`)||i.includes(`quarterfinal`)||/round\s+\d/i.test(t.name)?2:r===`playoff`&&(i===`playoffs`||i===`playoff`)?0:1},i=e=>e.scheduledAt?new Date(e.scheduledAt).getTime():e.playedAt?new Date(e.playedAt).getTime():0,a=new Set;for(let t=0;t<e.length;t++)if(!a.has(e[t].id))for(let n=t+1;n<e.length;n++){if(a.has(e[n].id))continue;let o=e[t],s=e[n],c=o.team1?.id,l=o.team2?.id,u=s.team1?.id,d=s.team2?.id;if(!c||!l||!u||!d||!(c===u&&l===d||c===d&&l===u))continue;let f=i(o),p=i(s);if(f&&p&&Math.abs(f-p)>Wt)continue;let m=r(o),h=r(s);if(m<h){a.add(o.id);break}else h<m&&a.add(s.id)}return e.filter(e=>!a.has(e.id))}function Kt(e){let t=new Map;for(let n of e){let e=n.name.toLowerCase();e.includes(`grand final`)?t.set(n.id,`grand_final`):e.includes(`upper`)||e.includes(`winner`)?t.set(n.id,`upper`):(e.includes(`lower`)||e.includes(`loser`))&&t.set(n.id,`lower`)}return t}function qt(e,t){if(e.stageId){let n=t.get(e.stageId);if(n)return n}let n=(e.stage??``).toLowerCase();return n.includes(`grand final`)?`grand_final`:n.includes(`lower`)||n.includes(`loser`)?`lower`:`upper`}function W(e,t,n,r){let i=e.team1Maps??e.stats?.team1Maps??null,a=e.team2Maps??e.stats?.team2Maps??null,o=i!=null&&a!=null?{team1:i,team2:a}:null;return{id:e.id,round:t,position:n,section:r,team1:e.team1?{id:e.team1.id,name:e.team1.name,abbreviation:e.team1.abbreviation,logoUrl:e.team1.logoUrl??null,slug:e.team1.slug??null}:null,team2:e.team2?{id:e.team2.id,name:e.team2.name,abbreviation:e.team2.abbreviation,logoUrl:e.team2.logoUrl??null,slug:e.team2.slug??null}:null,winnerId:e.winner?.id??null,score:o,status:Jt(e),format:e.format??`bo3`,scheduledAt:e.scheduledAt,matchId:e.id,team1FromMatchId:e.team1FromMatchId??null,team2FromMatchId:e.team2FromMatchId??null}}function Jt(e){return e.status===`live`?`live`:e.status===`tbd`?`tbd`:e.playedAt||e.status===`completed`?`completed`:`upcoming`}function G(e,t,n){if(n===`grand_final`)return`Grand Final`;let r=t-1-e;if(n===`lower`)return r===0?`Lower Final`:`Lower Round ${e+1}`;switch(r){case 0:return t===1?`Final`:`Grand Final`;case 1:return`Finals`;case 2:return`Semifinals`;case 3:return`Quarterfinals`;default:return`Round ${e+1}`}}function Yt(e){return e>0&&(e&e-1)==0}function Xt(e){let t=1;for(;t<e;)t*=2;return t}function Zt(e,t){return e.team1?.id===t||e.team2?.id===t}var K={x:0,y:0,scale:1},Qt=.3,$t=2,q=1e5;function J(e,t,n){return Number.isFinite(e)?Math.min(Math.max(e,t),n):t}function en(e){if(!e)return null;let t=e.split(`,`);if(t.length!==3)return null;let n=Number(t[0]),r=Number(t[1]),i=Number(t[2]);return!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)||i<=0?null:{x:J(Math.round(n),-q,q),y:J(Math.round(r),-q,q),scale:J(Math.round(i*100)/100,Qt,$t)}}function tn(e){let t=Math.round(e.x),n=Math.round(e.y),r=Math.round(e.scale*100)/100;return t===0&&n===0&&nn(r)?null:`${t},${n},${r}`}function nn(e){return Math.abs(e-1)<1e-6}function Y(e){let t=e.startsWith(`#`)?e.slice(1):e,n=t.indexOf(`=`);return n===-1?{tab:t,value:null}:{tab:t.slice(0,n),value:t.slice(n+1)}}function rn(e,t){return e?t==null?`#${e}`:`#${e}=${t}`:``}function an({match:e,highlightedTeamId:t,onMatchClick:n,onTeamClick:r}){let i=t!=null,a=i&&Zt(e,t),o=i&&!a,s=e.team1?.name??`TBD`,c=e.team2?.name??`TBD`;return(0,L.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-label":e.status===`live`?`Live match: ${s} vs ${c}`:e.status===`completed`?`Completed match: ${s} vs ${c}`:`Upcoming match: ${s} vs ${c}`,className:N(`absolute cursor-pointer overflow-hidden rounded-lg border transition-all`,`border-zinc-700 bg-zinc-900 hover:border-zinc-600`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--glk-brand)]`,e.status===`live`&&`ring-2 ring-emerald-500/40`,o&&`opacity-20`),style:{left:e.x,top:e.y,width:e.width,height:e.height},onClick:()=>n(e.matchId),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e.matchId))},children:[(0,L.jsx)(on,{team:e.team1,score:e.score?.team1??null,isWinner:e.winnerId!=null&&e.team1?.id===e.winnerId,isTbd:!e.team1,highlighted:i?e.team1?.id===t:null,onTeamClick:r}),(0,L.jsx)(`div`,{className:`h-px bg-zinc-800`}),(0,L.jsx)(on,{team:e.team2,score:e.score?.team2??null,isWinner:e.winnerId!=null&&e.team2?.id===e.winnerId,isTbd:!e.team2,highlighted:i?e.team2?.id===t:null,onTeamClick:r}),e.status===`live`&&(0,L.jsxs)(`span`,{className:`absolute -right-1 -top-1 flex items-center gap-1 rounded-full bg-emerald-500 px-1.5 py-0.5 text-[9px] font-bold text-white`,children:[(0,L.jsx)(`span`,{className:`h-1.5 w-1.5 animate-pulse rounded-full bg-white`}),`LIVE`]}),e.status===`upcoming`&&!e.score&&(0,L.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,L.jsx)(`span`,{className:`glk-eyebrow`,children:e.format.toUpperCase()})})]})}function on({team:e,score:t,isWinner:n,isTbd:r,highlighted:i,onTeamClick:a}){return(0,L.jsxs)(`div`,{className:N(`flex items-center gap-2 px-2.5 py-1.5 transition-all`,n&&`bg-zinc-800/50`,!n&&t!==null&&`opacity-50`,i===!1&&`opacity-20`),onClick:t=>{e&&(t.stopPropagation(),a(e.id))},children:[e?.logoUrl?(0,L.jsx)(`img`,{src:e.logoUrl,alt:``,className:`h-4 w-4 rounded-sm object-contain`}):(0,L.jsx)(`div`,{className:`flex h-4 w-4 items-center justify-center rounded-sm bg-zinc-700 text-[8px] text-zinc-500`,children:r?`?`:e?.abbreviation?.[0]??`?`}),(0,L.jsx)(`span`,{className:N(`flex-1 truncate text-xs`,r&&`italic text-zinc-600`,n&&`font-bold text-zinc-100`,!n&&!r&&`text-zinc-400`),children:r?`TBD`:e?.abbreviation??e?.name??`TBD`}),t!==null&&(0,L.jsx)(`span`,{className:N(`min-w-[16px] text-right font-mono text-xs tabular-nums`,n&&`font-bold text-emerald-500`,!n&&`text-zinc-500`),children:t})]})}function sn({connectors:e,width:t,height:n}){return t===0||n===0?null:(0,L.jsx)(`svg`,{"data-testid":`bracket-connectors`,"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,width:t,height:n,viewBox:`0 0 ${t} ${n}`,children:e.map((e,t)=>(0,L.jsx)(cn,{connector:e},t))})}function cn({connector:e}){let t=(e.fromX+e.toX)/2;return(0,L.jsx)(`path`,{d:`M ${e.fromX} ${e.fromY} H ${t} V ${e.toY} H ${e.toX}`,fill:`none`,stroke:e.highlighted?`var(--glk-brand)`:`rgb(63 63 70)`,strokeWidth:e.highlighted?2:1,strokeDasharray:e.type===`loser`?`4 4`:void 0,className:`transition-all`})}function ln({rounds:e,nodeWidth:t}){return(0,L.jsx)(L.Fragment,{children:e.map(e=>(0,L.jsx)(`div`,{className:`glk-eyebrow absolute text-center`,style:{left:e.round*(t+80),top:-20,width:t},children:e.label},`label-${e.round}-${e.label}`))})}var X=(0,F.createContext)(null);function un({children:e}){let t=(0,F.useRef)(new Map),n=(0,F.useRef)(new Map),r=(0,F.useMemo)(()=>({register(e,r){if(t.current.set(e,r),n.current.has(e)){let t=n.current.get(e);n.current.delete(e),r.restoreSnapshot(t)}return()=>{t.current.get(e)===r&&t.current.delete(e)}},snapshotLeaving(e){let r=t.current.get(e);r&&n.current.set(e,r.getSnapshot())},hasSnapshot(e){return n.current.has(e)}}),[]);return(0,L.jsx)(X.Provider,{value:r,children:e})}function dn(e,t){let n=(0,F.useContext)(X),r=(0,F.useRef)(t);r.current=t,(0,F.useEffect)(()=>{if(n)return n.register(e,{getSnapshot:()=>r.current.getSnapshot(),restoreSnapshot:e=>{r.current.restoreSnapshot(e)}})},[n,e])}function fn(){let e=(0,F.useContext)(X);if(!e)throw Error(`useTabSnapshotController must be used inside a TabSnapshotProvider`);return e}var Z=`bracket`,pn=200;function mn(){if(typeof window>`u`)return{...K};let{tab:e,value:t}=Y(window.location.hash);return e===Z?en(t)??{...K}:{...K}}function hn(e){if(typeof window>`u`)return;let{tab:t}=Y(window.location.hash);if(t!==Z)return;let n=rn(Z,tn(e)),r=window.location.pathname+window.location.search+n;history.replaceState(null,``,r)}function gn({matches:e,stages:t,gameSlug:n,highlightedTeamId:r,onTeamClick:i}){let a=g(),o=(0,F.useRef)(null),[s,c]=(0,F.useState)(null),l=r??s,[d,f]=(0,F.useState)(()=>mn()),[p,m]=(0,F.useState)(!1),h=(0,F.useRef)({x:0,y:0,tx:0,ty:0}),_=(0,F.useRef)(null),v=(0,F.useRef)(d);v.current=d,dn(Z,{getSnapshot:()=>v.current,restoreSnapshot:e=>f(e)});let[y,x]=(0,F.useState)(!1);(0,F.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`);x(e.matches);let t=e=>x(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let S=y?200:280,C=(0,F.useMemo)(()=>e.some(e=>e.team1FromMatchId!=null||e.team2FromMatchId!=null),[e]),w=(0,F.useMemo)(()=>jt(e,t),[e,t]),T=(0,F.useMemo)(()=>w?Rt(w,S):null,[w,S]),ee=(0,F.useMemo)(()=>{if(!T)return[];if(!l)return T.connectors;let e=new Set(T.nodes.filter(e=>Zt(e,l)).map(e=>e.id));return T.connectors.map(t=>{let n=T.nodes.find(e=>Math.abs(e.x+e.width-t.fromX)<1&&Math.abs(e.y+e.height/2-t.fromY)<20),r=T.nodes.find(e=>Math.abs(e.x-t.toX)<1&&Math.abs(e.y+e.height/2-t.toY)<40),i=!!(n&&r&&e.has(n.id)&&e.has(r.id));return{...t,highlighted:i}})},[T,l]),E=(0,F.useCallback)(e=>{e.preventDefault();let t=e.deltaY>0?.9:1.1;f(e=>({...e,scale:Math.max(.3,Math.min(2,e.scale*t))}))},[]),D=(0,F.useCallback)(e=>{e.button===0&&(m(!0),h.current={x:e.clientX,y:e.clientY,tx:d.x,ty:d.y})},[d.x,d.y]),O=(0,F.useCallback)(e=>{if(!p)return;let t=e.clientX-h.current.x,n=e.clientY-h.current.y;f(e=>({...e,x:h.current.tx+t,y:h.current.ty+n}))},[p]),k=(0,F.useCallback)(()=>{m(!1)},[]);(0,F.useEffect)(()=>{let e=o.current;if(e)return e.addEventListener(`wheel`,E,{passive:!1}),()=>e.removeEventListener(`wheel`,E)},[E]),(0,F.useEffect)(()=>(_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{hn(d)},pn),()=>{_.current&&=(clearTimeout(_.current),null)}),[d]);let A=(0,F.useCallback)(e=>{p||a(`/${n}/matches/${e}`)},[a,n,p]),j=(0,F.useCallback)(e=>{if(i&&T)for(let t of T.nodes){if(t.team1?.id===e&&t.team1.slug){i(t.team1.slug);return}if(t.team2?.id===e&&t.team2.slug){i(t.team2.slug);return}}c(t=>t===e?null:e)},[i,T]);if(!w||!T||T.nodes.length===0)return(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-16 text-zinc-400`,children:[(0,L.jsx)(b,{size:40,strokeWidth:1.5}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`Bracket not available`}),(0,L.jsx)(`p`,{className:`mt-1 text-xs`,children:`Bracket visualization will appear once playoff matches are set.`})]})]});let te=T.width+64,M=T.height+80;return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[!C&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-amber-500/20 bg-amber-500/5 px-3 py-2 text-xs text-amber-400`,children:[(0,L.jsx)(u,{size:14,className:`flex-shrink-0`}),`Bracket structure inferred from match schedule — seeding may not reflect actual bracket`]}),(0,L.jsxs)(`div`,{ref:o,role:`region`,"aria-label":`Tournament bracket — drag to pan, scroll to zoom`,className:`relative overflow-auto rounded-lg border border-zinc-800 bg-zinc-950`,style:{cursor:p?`grabbing`:`grab`},onMouseDown:D,onMouseMove:O,onMouseUp:k,onMouseLeave:k,children:[w.type===`double_elim`&&T.sections.lower&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`glk-eyebrow sticky left-0 z-10 -ml-0 rounded-r bg-zinc-900/80 px-2 py-1 backdrop-blur`,style:{marginTop:8},children:`Upper Bracket`}),(0,L.jsx)(`div`,{className:`glk-eyebrow sticky left-0 z-10 -ml-0 absolute rounded-r bg-zinc-900/80 px-2 py-1 backdrop-blur`,style:{top:T.sections.lower.y*d.scale+d.y+40},children:`Lower Bracket`})]}),(0,L.jsx)(`div`,{style:{width:te*d.scale,height:M*d.scale,minWidth:te,minHeight:Math.min(M,600)},children:(0,L.jsxs)(`div`,{style:{transform:`translate(${d.x+32}px, ${d.y+40}px) scale(${d.scale})`,transformOrigin:`0 0`,position:`relative`,width:T.width,height:T.height},children:[(0,L.jsx)(ln,{rounds:w.upper,nodeWidth:S}),w.lower.length>0&&(0,L.jsx)(ln,{rounds:w.lower,nodeWidth:S}),(0,L.jsx)(sn,{connectors:ee,width:T.width,height:T.height}),T.nodes.map(e=>(0,L.jsx)(an,{match:e,highlightedTeamId:l,onMatchClick:A,onTeamClick:j},e.id))]})})]}),l&&(0,L.jsx)(`div`,{className:`text-center text-xs text-zinc-500`,children:`Click the highlighted team again or click elsewhere to clear`})]})}function _n(e,t){return f({queryKey:[`tournamentAgents`,e,t],queryFn:()=>O(`/games/${e}/tournaments/${t}/agents`),enabled:!!t,staleTime:300*1e3})}function vn({gameSlug:e,tournamentSlug:n}){let{data:r,isLoading:i,isError:a}=_n(e,n);return i?(0,L.jsx)(`div`,{className:`py-20 text-center text-sm text-zinc-400`,children:`Loading agent data…`}):a||!r||r.agents.length===0?(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-20 text-zinc-400`,children:[(0,L.jsx)(`div`,{className:`rounded-xl bg-zinc-100 p-4 dark:bg-zinc-800`,children:(0,L.jsx)(t,{size:32,strokeWidth:1.5})}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium text-zinc-500 dark:text-zinc-400`,children:`No Agent Data`}),(0,L.jsx)(`p`,{className:`mt-1 text-xs`,children:`This tournament doesn't have map-level player stats yet.`})]})]}):(0,L.jsx)(yn,{agents:r.agents,maps:r.maps,totalMaps:r.totals.maps})}function yn({agents:e,maps:t,totalMaps:n}){let r=(0,F.useMemo)(()=>e.slice(0,20),[e]);return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{className:`rounded-lg border border-zinc-200 bg-white p-4 dark:border-zinc-800 dark:bg-zinc-900/60`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-3`,children:[(0,L.jsx)(`h2`,{className:`text-base font-semibold text-zinc-900 dark:text-zinc-100`,children:`Agent Pick Matrix`}),(0,L.jsxs)(`p`,{className:`text-xs text-zinc-500`,children:[r.length,` `,r.length===1?`agent`:`agents`,` ·`,` `,n,` `,n===1?`map`:`maps`,` played`]})]}),(0,L.jsx)(`p`,{className:`mt-1 text-xs text-zinc-500 dark:text-zinc-400`,children:`Per-cell value = share of distinct maps with that name where the agent appeared at least once.`})]}),(0,L.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-zinc-200 dark:border-zinc-800`,children:(0,L.jsxs)(`table`,{className:`w-full border-collapse text-sm`,children:[(0,L.jsx)(`thead`,{className:`bg-zinc-50 text-xs text-zinc-500 dark:bg-zinc-900 dark:text-zinc-400`,children:(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`th`,{scope:`col`,className:`sticky left-0 z-10 bg-zinc-50 px-3 py-2 text-left font-medium dark:bg-zinc-900`,children:`Agent`}),(0,L.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-right font-medium`,children:`Maps`}),(0,L.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-right font-medium`,title:`Share of distinct maps where this agent appeared at least once.`,children:`Presence`}),(0,L.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-right font-medium`,children:`Win %`}),t.map(e=>(0,L.jsx)(`th`,{scope:`col`,className:`px-2 py-2 text-center font-medium`,title:`${e} pick rate`,children:e},e))]})}),(0,L.jsx)(`tbody`,{children:r.map(e=>(0,L.jsxs)(`tr`,{className:`border-t border-zinc-200 hover:bg-zinc-50 dark:border-zinc-800 dark:hover:bg-zinc-900/40`,children:[(0,L.jsx)(`td`,{className:`sticky left-0 z-10 bg-white px-3 py-2 dark:bg-zinc-950`,children:(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(pe,{name:e.agent,size:`sm`}),(0,L.jsx)(`span`,{className:`font-medium text-zinc-900 dark:text-zinc-100`,children:e.agent})]})}),(0,L.jsx)(`td`,{className:`px-3 py-2 text-right tabular-nums text-zinc-700 dark:text-zinc-300`,children:e.mapsPlayed}),(0,L.jsxs)(`td`,{className:`px-3 py-2 text-right tabular-nums text-zinc-700 dark:text-zinc-300`,children:[(e.presenceRate*100).toFixed(0),`%`]}),(0,L.jsx)(`td`,{className:`px-3 py-2 text-right tabular-nums text-zinc-700 dark:text-zinc-300`,children:e.mapsPlayed>0?`${(e.winRate*100).toFixed(0)}%`:`—`}),t.map(t=>{let n=e.byMap[t];return(0,L.jsx)(bn,{cell:n??null},t)})]},e.agent))})]})})]})}function bn({cell:e}){if(!e||e.mapsPlayed===0)return(0,L.jsx)(`td`,{className:`px-2 py-2 text-center text-zinc-300 dark:text-zinc-700`,children:`·`});let t=Math.min(1,e.pickRate),n=(e.pickRate*100).toFixed(0);return(0,L.jsxs)(`td`,{className:N(`px-2 py-2 text-center tabular-nums`,`text-xs`,t>=.7?`text-zinc-900 dark:text-zinc-50`:t>=.3?`text-zinc-700 dark:text-zinc-200`:`text-zinc-500 dark:text-zinc-400`),style:{backgroundColor:`rgba(220, 38, 38, ${t*.32})`},title:`${e.mapsPlayed} ${e.mapsPlayed===1?`pick`:`picks`}`,children:[n,`%`]})}var xn=[{id:`overview`,label:`Overview`,icon:C},{id:`bracket`,label:`Bracket`,icon:b},{id:`matches`,label:`Matches`,icon:T},{id:`standings`,label:`Standings`,icon:r},{id:`agents`,label:`Agents`,icon:t}];function Sn(e,t=`overview`){let n=fn(),[r,i]=(0,F.useState)(()=>{let{tab:n}=Y(window.location.hash);return e.has(n)?n:t}),a=(0,F.useRef)(r);return a.current=r,[r,(0,F.useCallback)(e=>{let t=a.current;if(t===e)return;n.snapshotLeaving(t),i(e),a.current=e;let{tab:r,value:o}=Y(window.location.hash);if(e===`overview`){history.replaceState(null,``,window.location.pathname+window.location.search);return}let s=rn(e,r===e?o:null);history.replaceState(null,``,window.location.pathname+window.location.search+s)},[n])]}function Cn({tournament:e,gameSlug:t,activeStageId:n,activeChildStageIds:i}){let a=(()=>{if(i&&i.size>0){let t=[...i][0];return e.stages?.find(e=>e.id===t)}return n?e.stages?.find(e=>e.id===n):e.stages?.find(e=>(e.groups?.length??0)>0)??e.stages?.[0]})();return a?(0,L.jsx)(Ne,{gameSlug:t,tournamentSlug:e.slug,stage:a}):(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-20 text-zinc-400`,children:[(0,L.jsx)(`div`,{className:`rounded-xl bg-zinc-100 p-4 dark:bg-zinc-800`,children:(0,L.jsx)(r,{size:32,strokeWidth:1.5})}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium text-zinc-500 dark:text-zinc-400`,children:`No Standings`}),(0,L.jsx)(`p`,{className:`mt-1 text-xs`,children:`This tournament doesn't have standings data yet.`})]})]})}function wn(e){return(0,L.jsx)(un,{children:(0,L.jsx)(Tn,{...e})})}function Tn({tournament:e,stages:t,gameSlug:n,journey:r,teamSlug:i,teamMatchIds:a,onSelectTeam:o,onClearTeam:s,activeStageId:c,activeChildStageIds:l}){let u=(0,F.useMemo)(()=>l&&l.size>0?(e.matches??[]).filter(e=>e.stageId&&l.has(e.stageId)):c?(e.matches??[]).filter(e=>e.stageId===c):e.matches??[],[e.matches,c,l]),d=(0,F.useMemo)(()=>l&&l.size>0?t.filter(e=>e.stageId&&l.has(e.stageId)):c?t.filter(e=>e.stageId===c):t,[t,c,l]),f=(0,F.useMemo)(()=>l&&l.size>0?(e.stages??[]).filter(e=>l.has(e.id)):c?(e.stages??[]).filter(e=>e.id===c):e.stages??[],[e.stages,c,l]),p=(0,F.useMemo)(()=>{let t=l&&l.size>0;return jt(t?u:e.matches??[],t?f:e.stages??[])!==null},[e.matches,e.stages,u,f,l]),m=(0,F.useMemo)(()=>xn.filter(e=>e.id!==`bracket`||p),[p]),[h,g]=Sn((0,F.useMemo)(()=>new Set(m.map(e=>e.id)),[m]));return(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`sticky top-0 z-10 -mx-4 border-b border-zinc-200 bg-white/80 backdrop-blur-sm md:-mx-6 dark:border-zinc-800 dark:bg-zinc-950/80`,children:(0,L.jsx)(`div`,{role:`tablist`,"aria-label":`Tournament sections`,onKeyDown:(0,F.useCallback)(e=>{let t=m.findIndex(e=>e.id===h);if(e.key===`ArrowRight`){e.preventDefault();let n=m[(t+1)%m.length];n&&g(n.id)}else if(e.key===`ArrowLeft`){e.preventDefault();let n=m[(t-1+m.length)%m.length];n&&g(n.id)}else if(e.key===`Home`){e.preventDefault();let t=m[0];t&&g(t.id)}else if(e.key===`End`){e.preventDefault();let t=m[m.length-1];t&&g(t.id)}},[m,h,g]),className:`flex overflow-x-auto px-4 md:px-6`,children:m.map(({id:e,label:t,icon:n})=>(0,L.jsxs)(`button`,{role:`tab`,"aria-selected":h===e,"aria-controls":`tournament-tabpanel-${e}`,id:`tournament-tab-${e}`,tabIndex:h===e?0:-1,onClick:()=>g(e),className:N(`flex flex-shrink-0 items-center gap-1.5 border-b-2 px-3 pb-2 pt-1.5 transition-colors`,`glk-eyebrow`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--glk-brand)]`,h===e?`border-[var(--glk-brand)] text-[var(--glk-brand)]`:`border-transparent text-zinc-500 hover:text-zinc-700 dark:text-zinc-400 dark:hover:text-zinc-200`),children:[(0,L.jsx)(n,{size:14}),t]},e))})}),(0,L.jsxs)(`div`,{className:`pt-6`,children:[(0,L.jsx)(`div`,{role:`tabpanel`,id:`tournament-tabpanel-overview`,"aria-labelledby":`tournament-tab-overview`,hidden:h!==`overview`,children:h===`overview`&&(0,L.jsx)(vt,{tournament:e,stages:t,gameSlug:n,journey:r,onSelectTeam:o,onClearTeam:s,activeStageId:c})}),(0,L.jsx)(`div`,{role:`tabpanel`,id:`tournament-tabpanel-bracket`,"aria-labelledby":`tournament-tab-bracket`,hidden:h!==`bracket`,children:h===`bracket`&&(0,L.jsx)(gn,{matches:c?u:e.matches??[],stages:f,gameSlug:n,highlightedTeamId:r?.teamId??null,onTeamClick:o})}),(0,L.jsx)(`div`,{role:`tabpanel`,id:`tournament-tabpanel-matches`,"aria-labelledby":`tournament-tab-matches`,hidden:h!==`matches`,children:h===`matches`&&(0,L.jsx)(kt,{stages:d,allStages:e.stages,gameSlug:n,teamSlug:i,teamMatchIds:a,onSelectTeam:o})}),(0,L.jsx)(`div`,{role:`tabpanel`,id:`tournament-tabpanel-standings`,"aria-labelledby":`tournament-tab-standings`,hidden:h!==`standings`,children:h===`standings`&&(0,L.jsx)(Cn,{tournament:e,gameSlug:n,activeStageId:c,activeChildStageIds:l})}),(0,L.jsx)(`div`,{role:`tabpanel`,id:`tournament-tabpanel-agents`,"aria-labelledby":`tournament-tab-agents`,hidden:h!==`agents`,children:h===`agents`&&(0,L.jsx)(vn,{gameSlug:n,tournamentSlug:e.slug})})]})]})}function En({phases:e}){return e.length?(0,L.jsx)(`div`,{className:`mb-4 grid gap-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4`,children:e.map(e=>{let t=e.total>0?Math.round(e.completed/e.total*100):0,n=e.total>0&&e.completed===e.total,r=e.completed>0&&e.completed<e.total,i=e.completed===0&&e.total>0,a=n?`done`:r?`current`:`upcoming`;return(0,L.jsxs)(`div`,{className:N(`glk-card relative flex flex-col gap-2 !p-3`,r&&`ring-1 ring-[var(--glk-brand)]/60 dark:ring-[var(--glk-brand)]/30`),children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsx)(`span`,{className:`glk-eyebrow truncate`,title:e.name,children:e.name}),(0,L.jsx)(Dn,{status:a})]}),(0,L.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,L.jsx)(`span`,{className:`glk-metric glk-metric-md text-zinc-900 dark:text-zinc-100`,children:e.completed}),(0,L.jsxs)(`span`,{className:`glk-tabular text-xs text-zinc-500 dark:text-zinc-400`,children:[`/ `,e.total]}),(0,L.jsxs)(`span`,{className:`ml-auto glk-tabular text-xs font-semibold text-zinc-600 dark:text-zinc-300`,children:[t,`%`]})]}),e.roundsTotal!=null&&e.roundsTotal>1&&(0,L.jsxs)(`div`,{className:`glk-tabular text-[10px] font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,"data-testid":`phase-rounds-${e.id}`,children:[e.roundsComplete??0,` / `,e.roundsTotal,` rounds complete`]}),(0,L.jsx)(`div`,{className:`relative h-1.5 overflow-hidden rounded-full bg-zinc-200/80 dark:bg-zinc-800`,role:`progressbar`,"aria-label":`${e.name} progress`,"aria-valuenow":e.completed,"aria-valuemin":0,"aria-valuemax":e.total,children:(0,L.jsx)(`div`,{className:N(`absolute inset-y-0 left-0 rounded-full bg-[var(--glk-brand)] transition-[width]`,r&&`animate-pulse`,n&&`bg-emerald-500/90 dark:bg-emerald-400/80`,i&&`bg-zinc-300 dark:bg-zinc-700`),style:{width:`${t}%`,transitionDuration:`var(--duration-normal)`}})})]},e.id)})}):null}function Dn({status:e}){return e===`current`?(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-[var(--glk-brand)]/10 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wider text-[var(--glk-brand)]`,children:[(0,L.jsx)(`span`,{className:`glk-live-dot`,"aria-hidden":`true`}),`Live`]}):e===`done`?(0,L.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-emerald-500/10 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wider text-emerald-700 dark:text-emerald-400`,children:`Done`}):(0,L.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-zinc-200/70 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wider text-zinc-600 dark:bg-zinc-800/60 dark:text-zinc-300`,children:`Soon`})}function On({stages:e,activeStageId:t,onChange:n}){return(0,L.jsx)(`div`,{role:`tablist`,"aria-label":`Tournament stages`,onKeyDown:r=>{let i=e.findIndex(e=>e.id===t);if(r.key===`ArrowRight`){r.preventDefault();let t=e[(i+1)%e.length];t&&n(t.id)}else if(r.key===`ArrowLeft`){r.preventDefault();let t=e[(i-1+e.length)%e.length];t&&n(t.id)}},className:`inline-flex rounded-lg border border-zinc-200 bg-zinc-50 p-0.5 dark:border-zinc-800 dark:bg-zinc-900`,children:e.map(e=>{let r=e.id===t;return(0,L.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":r,tabIndex:r?0:-1,onClick:()=>n(e.id),className:N(`rounded-md px-3 py-1.5 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--glk-brand)] focus-visible:ring-offset-1`,r?`bg-white text-zinc-900 shadow-sm dark:bg-zinc-800 dark:text-zinc-100`:`text-zinc-500 hover:text-zinc-700 dark:text-zinc-400 dark:hover:text-zinc-200`),style:{transitionDuration:`var(--duration-fast)`},children:e.name},e.id)})})}var kn=`Playoffs:`,An=/^Stage\s+\d+\s*[:\-]\s*/i,jn=/\b(upper(?:\s+bracket)?|lower(?:\s+bracket)?|winner['s]?\s+bracket|loser['s]?\s+bracket|grand\s+final|semifinal|quarter\s*final|elimination|playoff)/i;function Q(e){if(e.name.startsWith(kn))return!0;if(An.test(e.name)){let t=e.name.replace(An,``);return jn.test(t)}return!1}function $(e){return jn.test(e)}function Mn(e,t){if(e.type!==`group`&&e.type!==`playoff`)return!1;let n=(e.blocks?.length??0)>0,r=(e.groups?.length??0)>0;return n||r?!1:t.filter(t=>t.stageId===e.id).length===0}function Nn(e,t){let n=[],r=[],i=[],a=e.some(Q),o=e.some(e=>e.type===`other`&&$(e.name)),s=e.some(e=>e.type===`other`&&!$(e.name));for(let c of e){if(c.type===`other`){$(c.name)&&r.push(c);continue}if(Q(c)){r.push(c);continue}if(c.name===`Playoffs`&&c.type===`playoff`&&(a||o)){i.push(c.id);continue}c.name===`Group Stage`&&c.type===`group`&&s&&Mn(c,t)||n.push({id:c.id,name:c.name,type:c.type,order:c.order,childStageIds:[c.id],source:c})}if(r.length>0){let t=[...r].sort((t,n)=>t.order===n.order?e.indexOf(t)-e.indexOf(n):t.order-n.order),a=t[0]?.order??99;n.push({id:`playoffs-fold`,name:`Playoffs`,type:`playoff`,order:a,childStageIds:[...t.map(e=>e.id),...i]})}let c=n.sort((e,t)=>e.order-t.order),l=/^(?:Group Stage:?\s+)?Week\s+(\d+)/i,u=[];if(c.forEach((e,t)=>{let n=l.exec(e.name);n&&u.push({idx:t,entry:e,week:parseInt(n[1],10)})}),u.length>1){let e=[...u].sort((e,t)=>e.week-t.week);u.forEach((t,n)=>{c[t.idx]=e[n].entry})}return c}function Pn(e,t){if(t&&t.length>0){let n=new Map(t.map(e=>[e.id,e])),r=new Map;for(let t of e){let e=t.stageId,i=e?n.get(e):null,a=i?.name??t.stage??`Other`;r.has(a)||r.set(a,{stage:a,stageId:e??``,order:i?.order??99,type:i?.type,format:i?.format,matches:[]}),r.get(a).matches.push(t)}return Array.from(r.values()).sort((e,t)=>e.order-t.order)}let n=new Map;for(let t of e){let e=t.stage??`Other`;n.has(e)||n.set(e,[]),n.get(e).push(t)}return Array.from(n.entries()).map(([e,t])=>({stage:e,order:0,matches:t}))}function Fn(){let{gameSlug:e,tournamentSlug:t}=v(),{data:n,isLoading:r,isError:i,error:a,refetch:o}=be(e,t),{isWatching:s,addToWatchlist:c,removeFromWatchlist:l}=te();re(n?.name);let u=(0,F.useMemo)(()=>Pn(n?.matches??[],n?.stages),[n?.matches,n?.stages]),{teamSlug:d,journey:f,teamMatchIds:p,selectTeam:m,clearTeam:h}=Ce(n?.matches??[],n?.status),{matchCount:g,completedCount:_,stripData:y}=(0,F.useMemo)(()=>{let e=(n?.matches??[]).filter(e=>e.status!==`cancelled`),t=e.filter(e=>e.playedAt).length,r=e=>{let t=e.filter(e=>e.status!==`cancelled`);return{completed:t.filter(e=>e.playedAt).length,total:t.length}},i=n?.stages??[],a=new Map;for(let e of i){if(e.type===`other`||Q(e))continue;let t=e.name.match(/^([^:]+):\s*(.+)$/);if(!t)continue;let n=t[1].trim(),r=a.get(n)??[];r.push(e),a.set(n,r)}let o=new Set;for(let[e,t]of a)t.length>=3&&o.add(e);let s=e=>{let t=e.name.match(/^([^:]+):/);return!!t&&o.has(t[1].trim())},c=new Set(i.map(e=>e.parentStageId).filter(e=>e!=null)),l=e=>e.parentStageId!=null,d=e=>c.has(e.id),f=i.filter(e=>e.type!==`other`&&!Q(e)&&!s(e)&&!l(e)&&!d(e)),p=i.filter(e=>l(e)&&/^playoffs/i.test(e.name)||Q(e)),m=i.filter(e=>e.type===`other`&&!l(e)),h=f.map(e=>{let t=r(u.find(t=>t.stageId===e.id||t.stage===e.name)?.matches??[]),n=t.total,i=t.completed,a=e.blocks??[];return a.length>0?{id:e.id,name:e.name,type:e.type,blocks:a.map(e=>({id:e.id,name:e.name,completed:e.matchesCompleted,total:e.matchesTotal,startDate:e.startDate,endDate:e.endDate}))}:{id:e.id,name:e.name,type:e.type,blocks:[{id:`${e.id}-all`,name:`All Matches`,completed:i,total:n}]}}).filter(e=>e.blocks.reduce((e,t)=>e+t.total,0)>0);if(p.length>0){let e=e=>{let t=(n?.matches??[]).filter(t=>t.stageId===e&&t.scheduledAt).map(e=>new Date(e.scheduledAt).getTime());return t.length>0?Math.min(...t):1/0},t=e=>{let t=e.toLowerCase();if(t.includes(`grand final`)||t.includes(`grand-final`))return 100;let n=t.includes(`upper`),r=t.includes(`lower`),i=n?0:r?20:40;return t.includes(`round 1`)||t.includes(`r1`)?i+1:t.includes(`round 2`)||t.includes(`r2`)?i+2:t.includes(`round 3`)||t.includes(`r3`)?i+3:t.includes(`round 4`)||t.includes(`r4`)?i+4:t.includes(`quarterfinal`)||t.includes(`quarter final`)||t.includes(`qf`)?i+5:t.includes(`semifinal`)||t.includes(`semi final`)||t.includes(`sf`)?i+6:t.includes(`final`)?i+7:i+10},a=[...p].sort((n,r)=>{let a=t(n.name),o=t(r.name);if(a!==o)return a-o;let s=e(n.id),c=e(r.id);return s===c?n.order===r.order?i.indexOf(n)-i.indexOf(r):n.order-r.order:s-c}).map(e=>{let{completed:t,total:n}=r(u.find(t=>t.stageId===e.id||t.stage===e.name)?.matches??[]),i=e.name.replace(/^Playoffs:\s*/,``).trim()||e.name;return{id:e.id,name:i,completed:t,total:n}}).filter(e=>e.total>0);if(a.length>0){let e=a.filter(e=>e.total>0&&e.completed===e.total).length;h.push({id:`synthetic-playoffs`,name:`Playoffs`,type:`playoff`,blocks:a,roundsTotal:a.length,roundsComplete:e})}}if(o.size>0){let e=e=>{let t=(n?.matches??[]).filter(t=>t.stageId===e&&(t.scheduledAt||t.playedAt)).map(e=>new Date(e.scheduledAt??e.playedAt).getTime());return t.length>0?Math.min(...t):1/0},t=e=>{let t=e.match(/round\s*(\d+)/i);return t?parseInt(t[1],10):1/0};for(let n of o){let o=(a.get(n)??[]).slice();o.sort((n,r)=>{let a=t(n.name),o=t(r.name);if(a!==o)return a-o;let s=e(n.id),c=e(r.id);return s===c?n.order===r.order?i.indexOf(n)-i.indexOf(r):n.order-r.order:s-c});let s=o.map(e=>{let{completed:t,total:i}=r(u.find(t=>t.stageId===e.id||t.stage===e.name)?.matches??[]),a=e.name.slice(n.length+1).trim()||e.name;return{id:e.id,name:a,completed:t,total:i}}).filter(e=>e.total>0);if(s.length===0)continue;let c=s.length,l=s.reduce((e,t)=>e+t.total,0),d=s.reduce((e,t)=>e+t.completed,0),f=s.length>6?[{id:`synthetic-${n.toLowerCase().replace(/\s+/g,`-`)}-aggregate`,name:`${c} rounds`,completed:d,total:l}]:s,p=s.filter(e=>e.total>0&&e.completed===e.total).length;h.push({id:`synthetic-${n.toLowerCase().replace(/\s+/g,`-`)}`,name:n,type:`group`,blocks:f,roundsTotal:c,roundsComplete:p})}}if(m.length>0){let e=e=>{let t=(n?.matches??[]).filter(t=>t.stageId===e&&(t.scheduledAt||t.playedAt)).map(e=>new Date(e.scheduledAt??e.playedAt).getTime());return t.length>0?Math.min(...t):1/0},t=e=>{let t=e.match(/week\s*(\d+)/i);return t?parseInt(t[1],10):1/0},i=[...m].sort((n,r)=>{let i=t(n.name),a=t(r.name);if(i!==a)return i-a;let o=e(n.id),s=e(r.id);return o===s?n.name.localeCompare(r.name):o-s}).map(e=>{let{completed:t,total:n}=r(u.find(t=>t.stageId===e.id||t.stage===e.name)?.matches??[]);return{id:e.id,name:e.name,completed:t,total:n}}).filter(e=>e.total>0);if(i.length>0){let e=h.findIndex(e=>e.id===`synthetic-playoffs`),t={id:`synthetic-regular-season`,name:`Regular Season`,type:`group`,blocks:i};e>=0?h.splice(e,0,t):h.push(t)}}return{matchCount:e.length,completedCount:t,stripData:h}},[n,u]),b=(0,F.useMemo)(()=>{let e={"synthetic-regular-season":1,"synthetic-playoffs":4,qualifier:0,group:2,round_robin:2,swiss:2,upper_bracket:3,lower_bracket:3,playoff:4,grand_final:5},t=t=>t.id in e?e[t.id]:t.type in e?e[t.type]:3,n=[...y].sort((e,n)=>t(e)-t(n)).map(e=>({id:e.id,name:e.name,type:e.type,completed:e.blocks.reduce((e,t)=>e+t.completed,0),total:e.blocks.reduce((e,t)=>e+t.total,0),roundsComplete:e.roundsComplete,roundsTotal:e.roundsTotal})).filter(e=>e.total>0),r=n.reduce((e,t)=>e+t.total,0);return n.filter(e=>{if(e.id!==`synthetic-regular-season`)return!0;let t=r>0?e.total/r:1;return e.total>=3&&t>=.05})},[y]),x=(0,F.useMemo)(()=>Nn(n?.stages??[],n?.matches??[]),[n?.stages,n?.matches]),[S,C]=(0,F.useState)(``),w=(0,F.useMemo)(()=>{if(!S)return null;let e=x.find(e=>e.id===S);return e?new Set(e.childStageIds):null},[S,x]);if((0,F.useEffect)(()=>{let e=n?.matches??[],t=new Set(e.map(e=>e.stageId).filter(Boolean)),r=x.find(e=>e.childStageIds.some(e=>t.has(e)));if(r){C(r.id);return}C(``)},[n?.id,x,n?.matches]),i&&a instanceof k)return(0,L.jsx)(xe,{entityType:`tournament`,gameSlug:e});if(r||n?.redirect||i||!n)return(0,L.jsx)(oe,{title:`Tournament`,breadcrumbs:[{label:`Tournaments`,href:`/${e}/tournaments`}],className:`flex h-full flex-col overflow-hidden`,loadingKind:`detail`,emptyMessage:`Tournament not found.`,status:{isLoading:r||!!n?.redirect,isError:i,error:i?Error(`Failed to load tournament`):null,isEmpty:!r&&!i&&!n,retry:()=>void o()},children:(0,L.jsx)(`div`,{})});let T=x,ee=T.length>1,E=ve(e),D=[`${n.name} — ${E} tournament${n.region?` in ${n.region}`:``}.`,n.prizePool?`Prize pool ${n.prizePool}.`:null,g>0?`${g} matches${_>0?`, ${_} completed`:``}.`:null,`Schedule, standings, brackets, and stats on Glicko.`].filter(Boolean).join(` `),O=ie({name:n.name,url:typeof window<`u`?window.location.href:`https://glicko.app/${e}/tournaments/${n.slug}`,startDate:n.startDate??new Date().toISOString(),endDate:n.endDate??void 0,location:n.region??void 0});return(0,L.jsxs)(oe,{title:n.name,breadcrumbs:[{label:`Tournaments`,href:`/${e}/tournaments`}],actions:(0,L.jsx)(ye,{entry:{type:`tournament`,slug:n.slug,name:n.name},isWatching:s(n.slug),onAdd:c,onRemove:l}),className:`flex h-full flex-col overflow-hidden`,seo:{title:`${n.name} — ${E}`,description:D,image:_e(e??`valorant`,`tournament`,n.slug),type:`article`},children:[(0,L.jsx)(se,{data:O}),(0,L.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,L.jsxs)(ue,{className:`mx-auto max-w-5xl`,children:[(0,L.jsx)(ke,{tournament:n,matchCount:g,completedCount:_,gameSlug:e}),b.length>0&&(0,L.jsx)(En,{phases:b}),ee&&(0,L.jsx)(`div`,{className:`mb-4`,children:(0,L.jsx)(On,{stages:T.map(e=>({id:e.id,name:e.name})),activeStageId:S,onChange:C})}),(0,L.jsx)(wn,{tournament:n,stages:u,gameSlug:e,journey:f,teamSlug:d,teamMatchIds:p,onSelectTeam:m,onClearTeam:h,activeStageId:S,activeChildStageIds:w})]})})]})}export{Fn as default};