'use client'; import { useDriverProfile } from "@/lib/hooks/driver"; import { useMemo } from 'react'; import Card from '../ui/Card'; import RankBadge from './RankBadge'; interface ProfileStatsProps { driverId?: string; stats?: { totalRaces: number; wins: number; podiums: number; dnfs: number; avgFinish: number; completionRate: number; }; } export default function ProfileStats({ driverId, stats }: ProfileStatsProps) { const { data: profileData } = useDriverProfile(driverId ?? ''); const driverStats = profileData?.stats ?? null; const totalDrivers = profileData?.currentDriver?.totalDrivers ?? 0; // League rank widget needs a dedicated API contract; keep it disabled until provided. // (Leaving UI block out avoids `never` typing issues.) const defaultStats = useMemo(() => { if (stats) { return stats; } if (!driverStats) { return null; } return { totalRaces: driverStats.totalRaces, wins: driverStats.wins, podiums: driverStats.podiums, dnfs: driverStats.dnfs, avgFinish: driverStats.avgFinish ?? 0, completionRate: driverStats.totalRaces > 0 ? ((driverStats.totalRaces - driverStats.dnfs) / driverStats.totalRaces) * 100 : 0, }; }, [stats, driverStats]); const winRate = defaultStats && defaultStats.totalRaces > 0 ? ((defaultStats.wins / defaultStats.totalRaces) * 100).toFixed(1) : '0.0'; const podiumRate = defaultStats && defaultStats.totalRaces > 0 ? ((defaultStats.podiums / defaultStats.totalRaces) * 100).toFixed(1) : '0.0'; const getTrendIndicator = (value: number) => { if (value > 0) return '↑'; if (value < 0) return '↓'; return '→'; }; const getPercentileLabel = (percentile: number) => { if (percentile >= 90) return 'Top 10%'; if (percentile >= 75) return 'Top 25%'; if (percentile >= 50) return 'Top 50%'; return `${(100 - percentile).toFixed(0)}th percentile`; }; const getPercentileColor = (percentile: number) => { if (percentile >= 90) return 'text-green-400'; if (percentile >= 75) return 'text-primary-blue'; if (percentile >= 50) return 'text-warning-amber'; return 'text-gray-400'; }; return (
No statistics available yet. Compete in races to start building your record.
Detailed per-car and per-class performance breakdowns will be available in a future version once more race history data is tracked.
Performance trends, track-specific stats, head-to-head comparisons vs friends, and league member comparisons will be available in production.