import { useMemo } from "react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "~/components/ui/table"; import { Badge } from "~/components/ui/badge"; import { TrendingUp, TrendingDown, Minus, Trophy, Medal, Award } from "lucide-react"; import { buildTiedRankChecker } from "~/lib/standings-display"; export interface StandingsRow { teamId: string; teamName: string; totalPoints: number; currentRank: number; previousRank?: number | null; firstPlaceCount: number; secondPlaceCount: number; thirdPlaceCount: number; fourthPlaceCount: number; fifthPlaceCount: number; sixthPlaceCount: number; seventhPlaceCount: number; eighthPlaceCount: number; participantsRemaining: number; } interface StandingsTableProps { standings: StandingsRow[]; showMovement?: boolean; showPlacementBreakdown?: boolean; } function getRankBadge(rank: number, isTied?: boolean) { const t = isTied ? "T" : ""; if (rank === 1) { return (
{t}{rank}
); } else if (rank === 2) { return (
{t}{rank}
); } else if (rank === 3) { return (
{t}{rank}
); } else { return {t}{rank}; } } export function StandingsTable({ standings, showMovement = true, showPlacementBreakdown = false, }: StandingsTableProps) { const isTied = useMemo( () => buildTiedRankChecker(standings.map((s) => s.currentRank)), [standings] ); const getMovementIndicator = (current: number, previous?: number | null) => { if (!showMovement || !previous) return null; const change = previous - current; // Positive means moved up if (change > 0) { return (
); } else if (change < 0) { return (
); } else { return (
); } }; return ( Rank {showMovement && Change} Team Total Points {showPlacementBreakdown && ( <> 4th 5th 6th 7th 8th )} Remaining {standings.length === 0 ? ( No standings data available yet ) : ( standings.map((row) => ( {getRankBadge(row.currentRank, isTied(row.currentRank))} {showMovement && ( {getMovementIndicator(row.currentRank, row.previousRank)} )} {row.teamName} {row.totalPoints.toFixed(2)} {showPlacementBreakdown && ( <> {row.firstPlaceCount || "-"} {row.secondPlaceCount || "-"} {row.thirdPlaceCount || "-"} {row.fourthPlaceCount || "-"} {row.fifthPlaceCount || "-"} {row.sixthPlaceCount || "-"} {row.seventhPlaceCount || "-"} {row.eighthPlaceCount || "-"} )} {row.participantsRemaining > 0 ? ( {row.participantsRemaining} ) : ( - )} )) )}
); }