'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { Trophy, Crown, Star, TrendingUp, Shield, Search, Users, Award, ChevronRight, Flag, Activity, BarChart3, } from 'lucide-react'; import Button from '@/components/ui/Button'; import Input from '@/components/ui/Input'; import Card from '@/components/ui/Card'; import Heading from '@/components/ui/Heading'; import { useDriverLeaderboard } from '@/hooks/useDriverService'; import Image from 'next/image'; import { mediaConfig } from '@/lib/config/mediaConfig'; import type { DriverLeaderboardItemViewModel } from '@/lib/view-models/DriverLeaderboardItemViewModel'; // ============================================================================ // DEMO DATA // ============================================================================ // // In alpha, all driver listings come from the in-memory repositories wired // through the DI container. We intentionally avoid hardcoded fallback driver // lists here so that the demo data stays consistent across pages. // ============================================================================ // SKILL LEVEL CONFIG // ============================================================================ const SKILL_LEVELS: { id: string; label: string; icon: React.ElementType; color: string; bgColor: string; borderColor: string; description: string; }[] = [ { id: 'pro', label: 'Pro', icon: Crown, color: 'text-yellow-400', bgColor: 'bg-yellow-400/10', borderColor: 'border-yellow-400/30', description: 'Elite competition level' }, { id: 'advanced', label: 'Advanced', icon: Star, color: 'text-purple-400', bgColor: 'bg-purple-400/10', borderColor: 'border-purple-400/30', description: 'Highly competitive' }, { id: 'intermediate', label: 'Intermediate', icon: TrendingUp, color: 'text-primary-blue', bgColor: 'bg-primary-blue/10', borderColor: 'border-primary-blue/30', description: 'Developing skills' }, { id: 'beginner', label: 'Beginner', icon: Shield, color: 'text-green-400', bgColor: 'bg-green-400/10', borderColor: 'border-green-400/30', description: 'Learning the ropes' }, ]; // ============================================================================ // CATEGORY CONFIG // ============================================================================ const CATEGORIES: { id: string; label: string; color: string; bgColor: string; borderColor: string; }[] = [ { id: 'beginner', label: 'Beginner', color: 'text-green-400', bgColor: 'bg-green-400/10', borderColor: 'border-green-400/30' }, { id: 'intermediate', label: 'Intermediate', color: 'text-primary-blue', bgColor: 'bg-primary-blue/10', borderColor: 'border-primary-blue/30' }, { id: 'advanced', label: 'Advanced', color: 'text-purple-400', bgColor: 'bg-purple-400/10', borderColor: 'border-purple-400/30' }, { id: 'pro', label: 'Pro', color: 'text-yellow-400', bgColor: 'bg-yellow-400/10', borderColor: 'border-yellow-400/30' }, { id: 'endurance', label: 'Endurance', color: 'text-orange-400', bgColor: 'bg-orange-400/10', borderColor: 'border-orange-400/30' }, { id: 'sprint', label: 'Sprint', color: 'text-red-400', bgColor: 'bg-red-400/10', borderColor: 'border-red-400/30' }, ]; // ============================================================================ // FEATURED DRIVER CARD COMPONENT // ============================================================================ interface FeaturedDriverCardProps { driver: DriverLeaderboardItemViewModel; position: number; onClick: () => void; } function FeaturedDriverCard({ driver, position, onClick }: FeaturedDriverCardProps) { const levelConfig = SKILL_LEVELS.find((l) => l.id === driver.skillLevel); const categoryConfig = CATEGORIES.find((c) => c.id === driver.category); const getBorderColor = (pos: number) => { switch (pos) { case 1: return 'border-yellow-400/50 hover:border-yellow-400'; case 2: return 'border-gray-300/50 hover:border-gray-300'; case 3: return 'border-amber-600/50 hover:border-amber-600'; default: return 'border-charcoal-outline hover:border-primary-blue'; } }; const getMedalColor = (pos: number) => { switch (pos) { case 1: return 'text-yellow-400'; case 2: return 'text-gray-300'; case 3: return 'text-amber-600'; default: return 'text-gray-500'; } }; return ( ); } // ============================================================================ // SKILL DISTRIBUTION COMPONENT // ============================================================================ interface SkillDistributionProps { drivers: DriverLeaderboardItemViewModel[]; } function SkillDistribution({ drivers }: SkillDistributionProps) { const distribution = SKILL_LEVELS.map((level) => ({ ...level, count: drivers.filter((d) => d.skillLevel === level.id).length, percentage: drivers.length > 0 ? Math.round((drivers.filter((d) => d.skillLevel === level.id).length / drivers.length) * 100) : 0, })); return (

Skill Distribution

Driver population by skill level

{distribution.map((level) => { const Icon = level.icon; return (
{level.count}

{level.label}

{level.percentage}% of drivers

); })}
); } // ============================================================================ // CATEGORY DISTRIBUTION COMPONENT // ============================================================================ interface CategoryDistributionProps { drivers: DriverLeaderboardItemViewModel[]; } function CategoryDistribution({ drivers }: CategoryDistributionProps) { const distribution = CATEGORIES.map((category) => ({ ...category, count: drivers.filter((d) => d.category === category.id).length, percentage: drivers.length > 0 ? Math.round((drivers.filter((d) => d.category === category.id).length / drivers.length) * 100) : 0, })); return (

Category Distribution

Driver population by category

{distribution.map((category) => (
{category.count}

{category.label}

{category.percentage}% of drivers

))}
); } // ============================================================================ // LEADERBOARD PREVIEW COMPONENT // ============================================================================ interface LeaderboardPreviewProps { drivers: DriverLeaderboardItemViewModel[]; onDriverClick: (id: string) => void; } function LeaderboardPreview({ drivers, onDriverClick }: LeaderboardPreviewProps) { const router = useRouter(); const top5 = drivers.slice(0, 5); const getMedalColor = (position: number) => { switch (position) { case 1: return 'text-yellow-400'; case 2: return 'text-gray-300'; case 3: return 'text-amber-600'; default: return 'text-gray-500'; } }; const getMedalBg = (position: number) => { switch (position) { case 1: return 'bg-yellow-400/10 border-yellow-400/30'; case 2: return 'bg-gray-300/10 border-gray-300/30'; case 3: return 'bg-amber-600/10 border-amber-600/30'; default: return 'bg-iron-gray/50 border-charcoal-outline'; } }; return (

Top Drivers

Highest rated competitors

{top5.map((driver, index) => { const levelConfig = SKILL_LEVELS.find((l) => l.id === driver.skillLevel); const categoryConfig = CATEGORIES.find((c) => c.id === driver.category); const position = index + 1; return ( ); })}
); } // ============================================================================ // RECENT ACTIVITY COMPONENT // ============================================================================ interface RecentActivityProps { drivers: DriverLeaderboardItemViewModel[]; onDriverClick: (id: string) => void; } function RecentActivity({ drivers, onDriverClick }: RecentActivityProps) { const activeDrivers = drivers.filter((d) => d.isActive).slice(0, 6); return (

Active Drivers

Currently competing in leagues

{activeDrivers.map((driver) => { const levelConfig = SKILL_LEVELS.find((l) => l.id === driver.skillLevel); const categoryConfig = CATEGORIES.find((c) => c.id === driver.category); return ( ); })}
); } // ============================================================================ // MAIN PAGE COMPONENT // ============================================================================ export default function DriversPage() { const router = useRouter(); const { data: viewModel, isLoading: loading } = useDriverLeaderboard(); const [searchQuery, setSearchQuery] = useState(''); const drivers = viewModel?.drivers || []; const totalRaces = viewModel?.totalRaces || 0; const totalWins = viewModel?.totalWins || 0; const activeCount = viewModel?.activeCount || 0; const handleDriverClick = (driverId: string) => { router.push(`/drivers/${driverId}`); }; // Filter by search const filteredDrivers = drivers.filter((driver) => { if (!searchQuery) return true; return ( driver.name.toLowerCase().includes(searchQuery.toLowerCase()) || driver.nationality.toLowerCase().includes(searchQuery.toLowerCase()) ); }); // Featured drivers (top 4) const featuredDrivers = filteredDrivers.slice(0, 4); if (loading) { return (

Loading drivers...

); } return (
{/* Hero Section */}
{/* Background decoration */}
Drivers

Meet the racers who make every lap count. From rookies to champions, track their journey and see who's dominating the grid.

{/* Quick Stats */}
{drivers.length} drivers
{activeCount} active
{totalWins.toLocaleString()} total wins
{totalRaces.toLocaleString()} races
{/* CTA */}

See full driver rankings

{/* Search */}
setSearchQuery(e.target.value)} className="pl-11" />
{/* Featured Drivers */} {!searchQuery && (

Featured Drivers

Top performers on the grid

{featuredDrivers.map((driver, index) => ( handleDriverClick(driver.id)} /> ))}
)} {/* Active Drivers */} {!searchQuery && } {/* Skill Distribution */} {!searchQuery && } {/* Category Distribution */} {!searchQuery && } {/* Leaderboard Preview */} {/* Empty State */} {filteredDrivers.length === 0 && (

No drivers found matching "{searchQuery}"

)}
); }