import type { ConferenceGroup } from "~/lib/bracket-templates"; import { TreeColumns, BracketTreePaginated, type BracketMatch, type BracketOwnership, } from "./BracketTreeView"; interface NbaBracketLayoutProps { matches: Array<{ round: string; matchNumber: number }>; rounds: string[]; matchesByRound: Map; ownershipMap: Map; userParticipantIds: Set; conferenceGroups: ConferenceGroup[]; scoringRoundIdx: number; } const DESIRED_CARD_HEIGHT = 112; const CARD_GAP = 14; 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; } function bracketHeight(matchesByRound: Map, rounds: string[]): number { const max = Math.max(...rounds.map((r) => matchesByRound.get(r)?.length ?? 0), 1); return max * (DESIRED_CARD_HEIGHT + CARD_GAP); } export function NbaBracketLayout({ rounds, matchesByRound, ownershipMap, userParticipantIds, conferenceGroups, scoringRoundIdx, }: NbaBracketLayoutProps) { // 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 sharedHeight = bracketHeight(sharedMatches, sharedRounds); return ( <> {/* ── Desktop: two-conference stacked layout ── */}
{conferenceGroups.map((group, gi) => { const confRounds = conferenceRounds[gi]; const confMatches = splitMatchesByConference(matchesByRound, group); const height = bracketHeight(confMatches, confRounds); return (

{group.name}

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