'use client' import { useQuery, gql } from '@/lib/graphql/hooks' import { use } from 'react' import Link from 'next/link' import { TeamFlag } from '@/components/team-flag' import { MatchCard } from '@/components/match-card' const TEAM_QUERY = gql` query Team($slug: String!) { team(slug: $slug) { id name iso2 slug fifaCode continent confederation stats { appearances wins draws losses goalsFor goalsAgainst goalDiff titles winPct } } } ` const TEAM_MATCHES_QUERY = gql` query TeamMatches($teamName: String!) { topScorers(limit: 100) { playerName goals penalties ownGoals tournaments team { name iso2 } } } ` interface TeamData { id: number; name: string; iso2?: string | null; slug: string fifaCode?: string | null; continent?: string | null; confederation?: string | null stats?: { appearances: number; wins: number; draws: number; losses: number goalsFor: number; goalsAgainst: number; goalDiff: number; titles: number; winPct: number } | null } export default function TeamPage({ params }: { params: Promise<{ slug: string }> }) { const { slug } = use(params) const { data: teamData, loading } = useQuery(TEAM_QUERY, { variables: { slug } }) const team: TeamData | null = teamData?.team ?? null // Load all scorers to filter by team const { data: scorerData } = useQuery(gql` query TeamScorers { topScorers(limit: 200) { playerName goals penalties ownGoals tournaments team { id name iso2 } } } `) const allScorers = scorerData?.topScorers ?? [] const teamScorers = team ? allScorers.filter((s: { team?: { id: number } | null }) => s.team?.id === team.id).slice(0, 15) : [] if (loading && !teamData) { return