'use client'; import type { DriverViewModel } from '@/lib/view-models/DriverViewModel'; import type { DriverProfileStatsViewModel } from '@/lib/view-models/DriverProfileViewModel'; import Card from '../ui/Card'; import ProfileHeader from '../profile/ProfileHeader'; import ProfileStats from './ProfileStats'; import CareerHighlights from './CareerHighlights'; import DriverRankings from './DriverRankings'; import PerformanceMetrics from './PerformanceMetrics'; import { useEffect, useState } from 'react'; import { useServices } from '@/lib/services/ServiceProvider'; interface DriverProfileProps { driver: DriverViewModel; isOwnProfile?: boolean; onEditClick?: () => void; } interface DriverTeamViewModel { team: { name: string; tag: string; }; } export default function DriverProfile({ driver, isOwnProfile = false, onEditClick }: DriverProfileProps) { const { driverService } = useServices(); const [profileData, setProfileData] = useState(null); const [teamData, setTeamData] = useState(null); useEffect(() => { const load = async () => { try { // Load driver profile const profile = await driverService.getDriverProfile(driver.id); // Extract stats from profile if (profile.stats) { setProfileData(profile.stats); } // Load team data if available if (profile.teamMemberships && profile.teamMemberships.length > 0) { const currentTeam = profile.teamMemberships.find(m => m.isCurrent) || profile.teamMemberships[0]; if (currentTeam) { setTeamData({ team: { name: currentTeam.teamName, tag: currentTeam.teamTag ?? '' } }); } } } catch (error) { console.error('Failed to load driver profile data:', error); } }; void load(); }, [driver.id, driverService]); const driverStats = profileData; const globalRank = profileData?.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.

); } function StatCard({ label, value, color }: { label: string; value: string; color: string }) { return (
{label}
{value}
); }