"use client"; import { GROUP_IDS, GroupId, Match, Team } from "@/lib/types"; import Flag from "./Flag"; function teamById(teams: Team[], id: string | null) { return id ? teams.find((t) => t.id === id) : undefined; } function fmtDate(iso: string): string { const d = new Date(iso); return d.toLocaleString("de-DE", { weekday: "short", day: "2-digit", month: "2-digit", hour: "2-digit", minute: "2-digit", }); } function statusText(m: Match): { text: string; live: boolean } { switch (m.status) { case "LIVE": case "IN_PLAY": return { text: m.minute != null ? `${m.minute}'` : "läuft", live: true }; case "PAUSED": return { text: "Halbzeit", live: true }; case "FINISHED": return { text: "Beendet", live: false }; default: return { text: fmtDate(m.utcDate), live: false }; } } function ScoreOrTime({ m }: { m: Match }) { const hasScore = m.homeScore != null && m.awayScore != null; const st = statusText(m); if (hasScore) { return ( {m.homeScore} : {m.awayScore} ); } return {fmtDate(m.utcDate)}; } export default function Fixtures({ group, teams, matches, onSelectGroup, }: { group: GroupId; teams: Team[]; matches: Match[]; onSelectGroup: (g: GroupId) => void; }) { const list = matches .filter((m) => m.group === group) .sort((a, b) => +new Date(a.utcDate) - +new Date(b.utcDate)); return (
{GROUP_IDS.map((g) => ( ))}
{list.length === 0 ? (
Für Gruppe {group} liegen noch keine Spiele im Feed vor.
) : (
{list.map((m) => { const home = teamById(teams, m.homeTeamId); const away = teamById(teams, m.awayTeamId); const st = statusText(m); const homeWin = m.homeScore != null && m.awayScore != null && m.homeScore > m.awayScore; const awayWin = m.homeScore != null && m.awayScore != null && m.awayScore > m.homeScore; return (
{st.live && } {st.text}
{home?.name ?? "—"}
{away?.name ?? "—"}
{m.venue && 📍 {m.venue}} {m.attendance != null && ( 👥 {m.attendance.toLocaleString("de-DE")} )}
); })}
)}
); }