// frontend/src/components/Tournament/Podium.jsx import { Trophy } from 'lucide-react'; import { printName } from '../../utils/helpers'; export default function Podium({ matches }) { const isDoubleElim = matches.some(m => m.bracket === 'Loser'); const wb = matches.filter(m => m.bracket === 'Winner').sort((a, b) => a.round - b.round); const lb = matches.filter(m => m.bracket === 'Loser').sort((a, b) => a.round - b.round); const finals = matches.filter(m => m.bracket === 'Finals').sort((a, b) => a.round - b.round); let gfMatch = null; let resetMatch = null; let tpMatch = null; if (isDoubleElim) { tpMatch = lb[lb.length - 1]; gfMatch = finals[0]; resetMatch = finals[1]; } else { gfMatch = wb[wb.length - 1]; tpMatch = finals[0]; } const podium = [ { rank: 1, label: "1st", team: "TBD", isReal: false, color: "bg-yellow-400 text-yellow-900 dark:text-yellow-950 shadow-yellow-400/50" }, { rank: 2, label: "2nd", team: "TBD", isReal: false, color: "bg-zinc-300 dark:bg-zinc-400 text-zinc-800 dark:text-zinc-900 shadow-zinc-400/50" }, { rank: 3, label: "3rd", team: "TBD", isReal: false, color: "bg-amber-600 text-amber-50 dark:text-amber-50 shadow-amber-600/50", hidden: false } ]; // --- CALCULATE 3RD PLACE --- if (tpMatch) { if (tpMatch.isFinished && tpMatch.winnerName) { // If match is done, grab the actual team name podium[2].team = isDoubleElim ? (tpMatch.winnerName === tpMatch.p1 ? tpMatch.p2 : tpMatch.p1) // DE: Loser of LB Final : tpMatch.winnerName; // SE: Winner of 3rd Place Match podium[2].isReal = true; } else { // Set the exact string expected by the print formatter podium[2].team = isDoubleElim ? `Loser of #${tpMatch.number}` : `Winner of #${tpMatch.number}`; } } else { podium[2].hidden = true; } // --- CALCULATE 1ST & 2ND PLACE --- if (resetMatch && resetMatch.isFinished && resetMatch.winnerName) { podium[0].team = resetMatch.winnerName; podium[0].isReal = true; podium[1].team = resetMatch.winnerName === resetMatch.p1 ? resetMatch.p2 : resetMatch.p1; podium[1].isReal = true; } else if (gfMatch) { if (gfMatch.isFinished && gfMatch.winnerName) { // Has the loser bracket champ won, forcing a reset? const isResetForced = resetMatch && resetMatch.hasTeams; if (!isResetForced) { // GF Winner is 1st, GF Loser is 2nd podium[0].team = gfMatch.winnerName; podium[0].isReal = true; podium[1].team = gfMatch.winnerName === gfMatch.p1 ? gfMatch.p2 : gfMatch.p1; podium[1].isReal = true; } else { // Reset forced, wait for the final match podium[0].team = `Winner of #${resetMatch.number}`; podium[1].team = `Loser of #${resetMatch.number}`; } } else { // GF not finished yet podium[0].team = `Winner of #${gfMatch.number}`; podium[1].team = `Loser of #${gfMatch.number}`; } } return (