"use client"
interface Player {
id: number
name: string
}
interface BracketMatchup {
id: number
roundId: number
player1P1: Player | null
player1P2: Player | null
player2P1: Player | null
player2P2: Player | null
match: { id: number; team1Score: number; team2Score: number } | null
bracketPosition: number | null
status: string
}
interface TournamentRound {
id: number
roundNumber: number
status: string
bracketMatchups: BracketMatchup[]
}
interface BracketVisualizationProps {
rounds: TournamentRound[]
}
export function BracketVisualization({ rounds }: BracketVisualizationProps) {
if (rounds.length === 0) {
return (
No schedule generated yet. Generate a schedule to see the bracket.
)
}
const currentRoundIdx = rounds.findIndex(r => r.status === "in_progress")
const completedRounds = rounds.filter(r => r.status === "completed").length
return (
Tournament Bracket
{rounds.length} rounds
{completedRounds} completed
{rounds.map((round, roundIdx) => {
const isCurrent = roundIdx === currentRoundIdx
const isCompleted = round.status === "completed"
return (
{/* Round Header */}
Round {round.roundNumber}
{isCurrent && (
(current)
)}
{/* Matchups */}
{round.bracketMatchups
.sort((a, b) => (a.bracketPosition || 0) - (b.bracketPosition || 0))
.map((matchup) => (
))}
)
})}
)
}
function MatchupCard({ matchup, isCurrentRound }: { matchup: BracketMatchup; isCurrentRound: boolean }) {
const team1Name = matchup.player1P1 && matchup.player1P2
? `${matchup.player1P1.name.split(" ").pop()} & ${matchup.player1P2.name.split(" ").pop()}`
: "TBD"
const team2Name = matchup.player2P1 && matchup.player2P2
? `${matchup.player2P1.name.split(" ").pop()} & ${matchup.player2P2.name.split(" ").pop()}`
: "TBD"
const hasResult = matchup.match !== null
const team1Won = hasResult && matchup.match!.team1Score > matchup.match!.team2Score
const team2Won = hasResult && matchup.match!.team2Score > matchup.match!.team1Score
const borderColor = isCurrentRound
? "border-green-400"
: hasResult
? "border-gray-300"
: "border-gray-200"
return (
{/* Team 1 */}
{team1Name}
{hasResult && (
{matchup.match!.team1Score}
)}
{/* Divider */}
{/* Team 2 */}
{team2Name}
{hasResult && (
{matchup.match!.team2Score}
)}
{/* Status indicator */}
{!hasResult && matchup.status === "pending" && (
pending
)}
)
}