import { useEffect, useState } from 'react'; import { Link, useParams } from '@tanstack/react-router'; import { ArrowLeft, Shield, Star } from 'lucide-react'; import { useFavoriteStore } from '@/stores/favoriteStore'; import { Card, CardBody, CardHeader } from '@/components/ui/Card'; import { Badge } from '@/components/ui/Badge'; import { teamFlag } from '@/lib/teams'; import { fmt, useFormat, useT } from '@/lib/i18n'; 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 { t, kickoffDay, kickoffTime } = useFormat(); 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 ? 'win' : us < them ? 'loss' : 'draw') : null; return ( {f.group ? fmt(t.team.groupShort, { group: f.group }) : f.stage !== 'group' ? t.team.stageShort[f.stage] : f.round} {isHome ? t.common.vs : t.team.awayIndicator} {opp.team ? teamFlag(opp.team) : } {opp.label} {done && us != null ? {us}–{them} : `${kickoffDay(f.kickoff)} ${kickoffTime(f.kickoff)}`} {res && {t.team.resultShort[res]}} ); } function FavoriteStar({ team }: { team: string }) { const t = useT(); const favorite = useFavoriteStore((s) => s.favorite); const toggle = useFavoriteStore((s) => s.toggleFavorite); const active = favorite === team; return ( ); } export function TeamProfilePage() { const { name } = useParams({ strict: false }) as { name: string }; const t = useT(); 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
{t.team.unknown} {t.team.allTeams}
; if (!profile) return
; const s = profile.standing; return (
{t.team.allTeams} {teamFlag(profile.team)}

{profile.team}

{profile.group && {fmt(t.common.group, { group: profile.group })}} {fmt(t.team.eloBadge, { rating: profile.elo })} {fmt(t.team.titleOddsBadge, { pct: pct(profile.championOdds) })} {fmt(t.team.advanceOddsBadge, { pct: pct(profile.qualifyOdds) })}
{s && (
{t.team.groupStanding}
{fmt(t.team.standingLine, { rank: s.rank, points: s.points, won: s.won, drawn: s.drawn, lost: s.lost, gd: s.gd > 0 ? `+${s.gd}` : s.gd })}
)}
{t.team.fixtures} {profile.fixtures.map((f) => )} {t.team.allTimeTopScorers} {profile.keyPlayers.length ? (
    {profile.keyPlayers.map((p, i) => (
  1. {i + 1} {p.name} {p.goals} {p.pens ? {fmt(t.common.pensShort, { n: p.pens })} : null}
  2. ))}
) :

{t.common.noData}

}
); }