import { memo, useMemo } from "react"; import { type DraftPick, groupPicksByTeamAndSport } from "./picks-utils"; interface DraftSummaryViewProps { draftSlots: Array<{ id: string; team: { id: string; name: string } }>; ownerMap?: Record; picks: DraftPick[]; sports: Array<{ id: string; name: string }>; } export const DraftSummaryView = memo(function DraftSummaryView({ draftSlots, ownerMap = {}, picks, sports, }: DraftSummaryViewProps) { const picksByTeamAndSport = useMemo( () => groupPicksByTeamAndSport(picks), [picks] ); const totalPicksBySport = useMemo(() => { const map = new Map(); sports.forEach((sport) => { let count = 0; picksByTeamAndSport.forEach((teamMap) => { count += teamMap.get(sport.id)?.length ?? 0; }); map.set(sport.id, count); }); return map; }, [picksByTeamAndSport, sports]); if (sports.length === 0) { return (

No sports have been configured for this season.

); } return (
{draftSlots.map((slot, index) => { const displayName = ownerMap[slot.team.id] || slot.team.name; const isLast = index === draftSlots.length - 1; return ( ); })} {sports.map((sport, sportIndex) => { const isLastRow = sportIndex === sports.length - 1; const sportTotal = totalPicksBySport.get(sport.id) ?? 0; return ( {draftSlots.map((slot, slotIndex) => { const count = picksByTeamAndSport.get(slot.team.id)?.get(sport.id) ?.length ?? 0; const isLast = slotIndex === draftSlots.length - 1; return ( ); })} ); })}
Sport Total {displayName}
{sport.name} {sportTotal > 0 ? sportTotal : null} = 2 ? "bg-accent/30 font-semibold" : "bg-background" } ${!isLastRow ? "border-b" : ""} ${!isLast ? "border-r" : ""}`} > {count > 0 ? count : null}
); });