import { useEffect, useState } from 'react'; import { Link, useParams } from '@tanstack/react-router'; import { ArrowLeft } from 'lucide-react'; import { Card, CardBody, CardHeader } from '@/components/ui/Card'; import { Badge } from '@/components/ui/Badge'; import { teamFlag } from '@/lib/teams'; import { kickoffDay, kickoffTime } from '@/lib/format'; import type { Fixture, TeamProfile } from '@/lib/types'; const pct = (x: number | null) => (x == null ? '—' : `${(x * 100).toFixed(1)}%`); function FixtureRow({ f, team }: { f: Fixture; team: string }) { const isHome = f.home.team === team; const opp = isHome ? f.away : f.home; const done = f.status === 'finished' || f.status === 'live'; const us = isHome ? f.homeScore : f.awayScore; const them = isHome ? f.awayScore : f.homeScore; const res = done && us != null && them != null ? (us > them ? 'W' : us < them ? 'L' : 'D') : null; return ( {f.group ? `Grp ${f.group}` : f.round.replace('Round of', 'R')} {isHome ? 'vs' : '@'} {opp.team ? teamFlag(opp.team) : '⚽'} {opp.label} {done && us != null ? {us}–{them} : `${kickoffDay(f.kickoff)} ${kickoffTime(f.kickoff)}`} {res && {res}} ); } export function TeamProfilePage() { const { name } = useParams({ strict: false }) as { name: string }; const [profile, setProfile] = useState(null); const [failed, setFailed] = useState(false); useEffect(() => { let alive = true; setProfile(null); setFailed(false); fetch(`/api/team/${encodeURIComponent(name)}`) .then((r) => (r.ok ? r.json() : Promise.reject())) .then((d: TeamProfile) => alive && setProfile(d)) .catch(() => alive && setFailed(true)); return () => { alive = false; }; }, [name]); if (failed) return
Unknown team. All teams
; if (!profile) return
; const s = profile.standing; return (
All teams {teamFlag(profile.team)}

{profile.team}

{profile.group && Group {profile.group}} Elo {profile.elo} Title {pct(profile.championOdds)} Advance {pct(profile.qualifyOdds)}
{s && (
Group standing
#{s.rank} · {s.points} pts · {s.won}-{s.drawn}-{s.lost} · GD {s.gd > 0 ? `+${s.gd}` : s.gd}
)}
Fixtures {profile.fixtures.map((f) => )} All-time top scorers {profile.keyPlayers.length ? (
    {profile.keyPlayers.map((p, i) => (
  1. {i + 1} {p.name} {p.goals} {p.pens ? {p.pens}p : null}
  2. ))}
) :

No data.

}
); }