'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { getDriverRepository } from '@/lib/di-container'; import { Driver } from '@gridpilot/racing/domain/entities/Driver'; import { EntityMappers, DriverDTO } from '@gridpilot/racing/application/mappers/EntityMappers'; import CreateDriverForm from '@/components/drivers/CreateDriverForm'; import Card from '@/components/ui/Card'; import Button from '@/components/ui/Button'; import ProfileHeader from '@/components/profile/ProfileHeader'; import ProfileStats from '@/components/drivers/ProfileStats'; import ProfileRaceHistory from '@/components/drivers/ProfileRaceHistory'; import ProfileSettings from '@/components/drivers/ProfileSettings'; import CareerHighlights from '@/components/drivers/CareerHighlights'; import RatingBreakdown from '@/components/drivers/RatingBreakdown'; import { getDriverTeam, getCurrentDriverId } from '@gridpilot/racing/application'; type Tab = 'overview' | 'statistics' | 'history' | 'settings'; export default function ProfilePage() { const router = useRouter(); const [driver, setDriver] = useState(null); const [activeTab, setActiveTab] = useState('overview'); const [loading, setLoading] = useState(true); useEffect(() => { const loadDriver = async () => { const driverRepo = getDriverRepository(); const drivers = await driverRepo.findAll(); const driverData = EntityMappers.toDriverDTO(drivers[0] || null); setDriver(driverData); setLoading(false); }; loadDriver(); }, []); const handleSaveSettings = async (updates: Partial) => { if (!driver) return; const driverRepo = getDriverRepository(); const drivers = await driverRepo.findAll(); const currentDriver = drivers[0]; if (currentDriver) { const updatedDriver: Driver = currentDriver.update({ bio: updates.bio ?? currentDriver.bio, country: updates.country ?? currentDriver.country, }); const persistedDriver = await driverRepo.update(updatedDriver); const updatedDto = EntityMappers.toDriverDTO(persistedDriver); setDriver(updatedDto); } }; if (loading) { return (
Loading profile...
); } if (!driver) { return (

Driver Profile

Create your GridPilot profile to get started

Create Your Profile

Create your driver profile. Alpha data resets on reload, so test freely.

); } const tabs: { id: Tab; label: string }[] = [ { id: 'overview', label: 'Overview' }, { id: 'statistics', label: 'Statistics' }, { id: 'history', label: 'Race History' }, { id: 'settings', label: 'Settings' } ]; return (
setActiveTab('settings')} />
{tabs.map((tab) => ( ))}
{activeTab === 'overview' && (

About

{driver.bio ? (

{driver.bio}

) : (

No bio yet. Add one in settings!

)}

Quick Stats

Preferences

Team

{(() => { const currentDriverId = getCurrentDriverId(); const teamData = getDriverTeam(currentDriverId); if (teamData) { const { team, membership } = teamData; return (
router.push(`/teams/${team.id}`)} >
{team.tag}
{team.name}
{membership.role.charAt(0).toUpperCase() + membership.role.slice(1)} • Joined {new Date(membership.joinedAt).toLocaleDateString('en-US', { month: 'short', year: 'numeric' })}
); } return (

You're not on a team yet

); })()}
)} {activeTab === 'statistics' && (
)} {activeTab === 'history' && ( )} {activeTab === 'settings' && ( )}
); } function StatItem({ label, value, color }: { label: string; value: string; color: string }) { return (
{label} {value}
); } function PreferenceItem({ icon, label, value }: { icon: string; label: string; value: string }) { return (
{icon}
{label}
{value}
); }