'use client'; import type { DriverDTO } from '@core/racing/application/dto/DriverDTO'; 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 { DriverTeamPresenter } from '@/lib/presenters/DriverTeamPresenter'; import { getPrimaryLeagueIdForDriver } from '@/lib/leagueMembership'; import type { ProfileOverviewOutputPort } from '@core/racing/application/ports/output/ProfileOverviewOutputPort'; import type { DriverTeamViewModel } from '@core/racing/application/presenters/IDriverTeamPresenter'; interface DriverProfileProps { driver: DriverDTO; isOwnProfile?: boolean; onEditClick?: () => void; } interface DriverProfileStatsViewModel { rating: number; wins: number; podiums: number; dnfs: number; totalRaces: number; avgFinish: number; bestFinish: number; worstFinish: number; consistency: number; percentile: number; overallRank?: number; } type DriverProfileOverviewViewModel = ProfileOverviewOutputPort | null; export default function DriverProfile({ driver, isOwnProfile = false, onEditClick }: DriverProfileProps) { const [profileData, setProfileData] = useState(null); const [teamData, setTeamData] = useState(null); useEffect(() => { const load = async () => { // Load profile data using GetProfileOverviewUseCase const profileUseCase = getGetProfileOverviewUseCase(); const profileViewModel = await profileUseCase.execute({ driverId: driver.id }); setProfileData(profileViewModel); // Load team data using caller-owned presenter const teamUseCase = getGetDriverTeamUseCase(); const driverTeamPresenter = new DriverTeamPresenter(); await teamUseCase.execute({ driverId: driver.id }, driverTeamPresenter); const teamResult = driverTeamPresenter.getViewModel(); setTeamData(teamResult ?? null); }; void load(); }, [driver.id]); const driverStats = profileData?.stats || null; const primaryLeagueId = getPrimaryLeagueIdForDriver(driver.id); const leagueRank = primaryLeagueId ? getLeagueRankings(driver.id, primaryLeagueId) : { rank: 0, totalDrivers: 0, percentile: 0 }; const globalRank = profileData?.driver?.globalRank ?? null; const totalDrivers = profileData?.driver?.totalDrivers ?? 0; 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, }, { type: 'league' as const, name: 'Primary League', rank: leagueRank.rank, totalDrivers: leagueRank.totalDrivers, percentile: leagueRank.percentile, 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}
); }