'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 PLAYER_QUERY = gql` query Player($name: String!) { player(name: $name) { playerName goals penalties ownGoals tournaments team { id name iso2 slug } } } ` const PLAYER_MATCHES_QUERY = gql` query PlayerMatches($name: String!) { tournaments { year } } ` interface PlayerData { playerName: string; goals: number; penalties: number; ownGoals: number; tournaments: number team?: { id: number; name: string; iso2?: string | null; slug: string } | null } export default function PlayerPage({ params }: { params: Promise<{ name: string }> }) { const { name: encodedName } = use(params) const name = decodeURIComponent(encodedName) const { data, loading } = useQuery(PLAYER_QUERY, { variables: { name } }) const player: PlayerData | null = data?.player ?? null // Fetch all goals for this player broken down by year const { data: goalsData } = useQuery(gql` query PlayerGoalsByYear($name: String!) { tournaments { year } topScorers(limit: 1000) { playerName goals team { id } } } `, { variables: { name } }) if (loading && !data) { return
Loading player…
} if (!player) { return (

{name}

No goal data found for this player in World Cup history.

← All-time scorers
) } const normalGoals = player.goals - player.penalties - player.ownGoals return (
{/* Hero */}
{player.team && }

{player.playerName}

{player.team && ( {player.team.name} → )}
{player.goals}
World Cup Goals
{/* Stats breakdown */}
{[ { label: 'Total Goals', value: player.goals }, { label: 'Open Play', value: normalGoals }, { label: 'Penalties', value: player.penalties }, { label: 'Tournaments', value: player.tournaments }, ].map(item => (
{item.label}
{item.value}
))}
{player.ownGoals > 0 && (
Includes {player.ownGoals} own goal{player.ownGoals !== 1 ? 's' : ''}
)} {/* Back links */}
← All-time scorers {player.team && ( → {player.team.name} team page )}
) }