import type { SeasonMatch, MatchSubGame } from "~/models/season-match"; type MatchWithRelations = SeasonMatch & { participant1: { name: string } | null; participant2: { name: string } | null; winner: { name: string } | null; subGames: MatchSubGame[]; }; interface MatchScheduleProps { matches: MatchWithRelations[]; title?: string; } const STATUS_BADGE: Record = { scheduled: "bg-muted text-muted-foreground", in_progress: "bg-amber-500/15 text-amber-400 border border-amber-500/30", complete: "bg-emerald-500/15 text-emerald-400 border border-emerald-500/30", canceled: "bg-destructive/15 text-destructive border border-destructive/30", postponed: "bg-muted text-muted-foreground", }; const STATUS_LABEL: Record = { scheduled: "Scheduled", in_progress: "Live", complete: "Final", canceled: "Canceled", postponed: "Postponed", }; function formatDate(d: Date | null) { if (!d) return "TBD"; return new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", hour: "numeric", minute: "2-digit", timeZoneName: "short", }).format(new Date(d)); } function MatchRow({ match }: { match: MatchWithRelations }) { const p1 = match.participant1?.name ?? "TBD"; const p2 = match.participant2?.name ?? "TBD"; const isComplete = match.status === "complete"; const winnerId = match.winnerId; return (
{p1}
{p2}
{isComplete && (
{match.participant1Score ?? "-"}
{match.participant2Score ?? "-"}
)} {match.status === "in_progress" && (
{match.participant1Score ?? "-"}
{match.participant2Score ?? "-"}
)}
{match.matchday != null && (
Matchday {match.matchday}
)}
{match.status === "in_progress" && } {STATUS_LABEL[match.status] ?? match.status} {formatDate(match.scheduledAt)}
); } // Groups by matchday number when available, or by UTC calendar date (YYYY-MM-DD) for date-based sports. // UTC date keys ensure consistent grouping regardless of the viewer's timezone. function groupByMatchday(matches: MatchWithRelations[]) { const groups = new Map(); for (const m of matches) { const key = m.matchday != null ? `Matchday ${m.matchday}` : m.scheduledAt?.toISOString().slice(0, 10) ?? "TBD"; if (!groups.has(key)) groups.set(key, []); groups.get(key)!.push(m); } return groups; } export function MatchSchedule({ matches, title = "Schedule" }: MatchScheduleProps) { if (matches.length === 0) { return (
No matches scheduled yet.
); } const grouped = groupByMatchday(matches); return (
{title &&

{title}

} {[...grouped.entries()].map(([label, group]) => (
{label}
{group.map((m) => ( ))}
))}
); }