import { ActionIcon, Card, Flex, Text } from "@mantine/core"; import { PlayIcon } from "@phosphor-icons/react"; import React from "react"; import { BracketMaps } from "../utils/bracket-maps"; interface Match { lid: number; round: number; order: number | null; type: string; home: any; away?: any; reset?: boolean; } interface BracketViewProps { bracket: Match[][]; bracketMaps: BracketMaps; onAnnounce?: (teamOne: any, teamTwo: any) => void; } const BracketView: React.FC = ({ bracket, bracketMaps, onAnnounce, }) => { const isMatchType = (type: string, expected: string) => { return type?.toLowerCase() === expected.toLowerCase(); }; const getParentMatchOrder = (parentLid: number): number | string => { const parentMatch = bracketMaps.matchByLid.get(parentLid); if ( parentMatch && parentMatch.order !== null && parentMatch.order !== undefined ) { return parentMatch.order; } return `Match ${parentLid}`; }; return ( {bracket.map((round, roundIndex) => ( {round.map((match, matchIndex) => { if (!match) return null; if ( isMatchType(match.type, "bye") || isMatchType(match.type, "tbye") ) { return ; } return ( {match.order} {match.home?.seed && ( {match.home.seed} )}
{match.home?.seed ? ( match.home.team ? ( {match.home.team.name} ) : ( Team {match.home.seed} ) ) : match.home?.parent_lid !== null && match.home?.parent_lid !== undefined ? ( {match.home.loser ? "Loser" : "Winner"} of Match{" "} {getParentMatchOrder(match.home.parent_lid)} ) : ( TBD )}
{match.away?.seed && ( {match.away.seed} )}
{match.away?.seed ? ( match.away.team ? ( {match.away.team.name} ) : ( Team {match.away.seed} ) ) : match.away?.parent_lid !== null && match.away?.parent_lid !== undefined ? ( {match.away.loser ? "Loser" : "Winner"} of Match{" "} {getParentMatchOrder(match.away.parent_lid)} ) : match.away ? ( TBD ) : null}
{match.reset && ( IF NECESSARY )} {onAnnounce && match.home?.team && match.away?.team && ( { onAnnounce(match.home.team, match.away.team); }} bd="none" style={{ boxShadow: "none" }} size="xs" > )}
); })}
))}
); }; export default BracketView;