import { useMemo } from 'react';
import { Radio } from 'lucide-react';
import { PageHeader } from '@/components/ui/PageHeader';
import { MatchCard } from '@/components/MatchCard';
import { useTournamentStore } from '@/stores/tournamentStore';
import { dayKeyOf, isToday, kickoffDay } from '@/lib/format';
import type { Fixture } from '@/lib/types';
function Section({ title, fixtures }: { title: string; fixtures: Fixture[] }) {
if (!fixtures.length) return null;
return (
{title}
{fixtures.map((f) => )}
);
}
export function LivePage() {
const snapshot = useTournamentStore((s) => s.snapshot);
const groups = useMemo(() => {
const fixtures = snapshot?.fixtures ?? [];
const live = fixtures.filter((f) => f.status === 'live').sort((a, b) => a.kickoff.localeCompare(b.kickoff));
const today = fixtures
.filter((f) => f.status !== 'live' && isToday(f.kickoff))
.sort((a, b) => a.kickoff.localeCompare(b.kickoff));
// If nothing is on today, surface the next match day in full.
const upcoming = fixtures
.filter((f) => f.status === 'scheduled' && !isToday(f.kickoff) && new Date(f.kickoff).getTime() > Date.now())
.sort((a, b) => a.kickoff.localeCompare(b.kickoff));
const nextDayKey = upcoming[0] ? dayKeyOf(upcoming[0].kickoff) : null;
const nextDay = nextDayKey ? upcoming.filter((f) => dayKeyOf(f.kickoff) === nextDayKey) : [];
const recent = fixtures
.filter((f) => f.status === 'finished')
.sort((a, b) => b.kickoff.localeCompare(a.kickoff))
.slice(0, 6);
return { live, today, nextDay, nextDayLabel: upcoming[0] ? kickoffDay(upcoming[0].kickoff) : '', recent };
}, [snapshot]);
if (!snapshot) {
return (
{Array.from({ length: 4 }).map((_, i) => (
))}
);
}
const nothingToday = !groups.live.length && !groups.today.length;
return (
{nothingToday && (
)}
{nothingToday && !groups.nextDay.length && !groups.recent.length && (
The schedule is loaded — matches will appear here as the tournament unfolds.
)}
);
}