'use client'; import type { DriverViewModel } from '@/lib/view-models/DriverViewModel'; import { Card } from '@/ui/Card'; import { Box } from '@/ui/Box'; import { Text } from '@/ui/Text'; import { Heading } from '@/ui/Heading'; import { Stack } from '@/ui/Stack'; import { StatCard } from '@/ui/StatCard'; import { ProfileHeader } from '@/components/drivers/ProfileHeader'; import { ProfileStats } from './ProfileStats'; import { CareerHighlights } from '@/components/drivers/CareerHighlights'; import { DriverRankings } from '@/components/drivers/DriverRankings'; import { PerformanceMetrics } from '@/components/drivers/PerformanceMetrics'; import { useDriverProfile } from "@/hooks/driver/useDriverProfile"; interface DriverProfileProps { driver: DriverViewModel; isOwnProfile?: boolean; onEditClick?: () => void; } interface DriverTeamViewModel { team: { name: string; tag: string; }; } export function DriverProfile({ driver, isOwnProfile = false, onEditClick }: DriverProfileProps) { const { data: profileData } = useDriverProfile(driver.id); // Extract team data from profile const teamData: DriverTeamViewModel | null = (() => { if (!profileData?.teamMemberships || profileData.teamMemberships.length === 0) { return null; } const currentTeam = profileData.teamMemberships.find((m: { isCurrent: boolean }) => m.isCurrent) || profileData.teamMemberships[0]; if (!currentTeam) { return null; } return { team: { name: currentTeam.teamName, tag: currentTeam.teamTag ?? '' } }; })(); const driverStats = profileData?.stats ?? null; const globalRank = driverStats?.overallRank ?? null; const totalDrivers = 1000; // Placeholder const performanceStats = driverStats ? { winRate: driverStats.totalRaces > 0 ? (driverStats.wins / driverStats.totalRaces) * 100 : 0, podiumRate: driverStats.totalRaces > 0 ? (driverStats.podiums / driverStats.totalRaces) * 100 : 0, dnfRate: driverStats.totalRaces > 0 ? (driverStats.dnfs / driverStats.totalRaces) * 100 : 0, avgFinish: driverStats.avgFinish ?? 0, consistency: driverStats.consistency ?? 0, bestFinish: driverStats.bestFinish ?? 0, worstFinish: driverStats.worstFinish ?? 0, } : null; const rankings = driverStats ? [ { type: 'overall' as const, name: 'Overall Ranking', rank: globalRank ?? driverStats.overallRank ?? 0, totalDrivers, percentile: driverStats.percentile ?? 0, rating: driverStats.rating ?? 0, }, ] : []; return ( {})} teamName={teamData?.team.name ?? null} teamTag={teamData?.team.tag ?? null} /> {driver.bio && ( About {driver.bio} )} {driverStats && ( Career Statistics {performanceStats && } )} {!driverStats && ( Career Statistics No statistics available yet. Compete in races to start building your record. )} Performance by Class {driverStats && ( 0 ? ((driverStats.totalRaces - driverStats.dnfs) / driverStats.totalRaces) * 100 : 0, }} /> )} 🔒 Private Information Detailed race history, settings, and preferences are only visible to the driver. 📊 Coming Soon Per-car statistics, per-track performance, and head-to-head comparisons will be available in production. ); }