import type { BracketTemplate, ConferenceGroup } from "~/lib/bracket-templates"; import type { FeederMap } from "~/lib/bracket-layout"; import { TreeColumns, bracketGeometry, type BracketMatch, type BracketOwnership, } from "./BracketTreeView"; import { BracketTreePaginated } from "./BracketTreePaginated"; interface NbaBracketLayoutProps { matches: Array<{ round: string; matchNumber: number }>; rounds: string[]; matchesByRound: Map; ownershipMap: Map; userParticipantIds: Set; conferenceGroups: ConferenceGroup[]; scoringRoundIdx: number; feeders?: FeederMap; template?: BracketTemplate; } function splitMatchesByConference( matchesByRound: Map, group: ConferenceGroup ): Map { const result = new Map(); for (const [round, allowed] of Object.entries(group.roundMatchNumbers)) { const roundMatches = matchesByRound.get(round) ?? []; const filtered = roundMatches.filter((m) => allowed.includes(m.matchNumber)); if (filtered.length > 0) result.set(round, filtered); } return result; } export function NbaBracketLayout({ rounds, matchesByRound, ownershipMap, userParticipantIds, conferenceGroups, scoringRoundIdx, feeders, template, }: NbaBracketLayoutProps) { const roundOrder = template?.rounds.map((r) => r.name) ?? rounds; // Rounds that belong to any conference group const conferenceRoundSet = new Set( conferenceGroups.flatMap((g) => Object.keys(g.roundMatchNumbers)) ); // Rounds not in any group are shared (e.g. NBA Finals) const sharedRounds = rounds.filter((r) => !conferenceRoundSet.has(r)); // Per-conference round lists (preserving template order) const conferenceRounds = conferenceGroups.map((g) => rounds.filter((r) => g.roundMatchNumbers[r] !== undefined) ); // Shared rounds bracket height const sharedMatches = new Map( sharedRounds.map((r) => [r, matchesByRound.get(r) ?? []]) ); const sharedGeometry = bracketGeometry(sharedRounds, sharedMatches, feeders, roundOrder); return ( <> {/* ── Desktop: two-conference stacked layout ── */}
{conferenceGroups.map((group, gi) => { const confRounds = conferenceRounds[gi]; const confMatches = splitMatchesByConference(matchesByRound, group); const geometry = bracketGeometry(confRounds, confMatches, feeders, roundOrder); return (

{group.name}

); })} {sharedRounds.length > 0 && (
)}
{/* ── Mobile: paginated across all rounds ── */}
); }