'use client';
import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import {
Trophy,
Medal,
Crown,
Star,
TrendingUp,
Shield,
Search,
Plus,
Sparkles,
Users,
Target,
Zap,
Award,
ChevronRight,
Flame,
Flag,
Activity,
BarChart3,
UserPlus,
} 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 { getDriverLeaderboard } from '@/lib/services/drivers/DriverService';
import type { DriverLeaderboardViewModel } from '@/lib/view-models';
import Image from 'next/image';
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' },
];
// ============================================================================
// 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 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
);
})}
);
}
// ============================================================================
// 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 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);
return (
);
})}
);
}
// ============================================================================
// MAIN PAGE COMPONENT
// ============================================================================
export default function DriversPage() {
const router = useRouter();
const [drivers, setDrivers] = useState([]);
const [viewModel, setViewModel] = useState(null);
const [loading, setLoading] = useState(true);
const [searchQuery, setSearchQuery] = useState('');
const [totalRaces, setTotalRaces] = useState(0);
const [totalWins, setTotalWins] = useState(0);
const [activeCount, setActiveCount] = useState(0);
useEffect(() => {
const load = async () => {
const vm = await getDriverLeaderboard();
setViewModel(vm);
setDrivers(vm.drivers);
setTotalRaces(vm.totalRaces);
setTotalWins(vm.totalWins);
setActiveCount(vm.activeCount);
setLoading(false);
};
void load();
}, []);
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 (
);
}
return (
{/* Hero Section */}
{/* Background decoration */}
Meet the racers who make every lap count. From rookies to champions, track their journey and see who's dominating the grid.
{/* Quick Stats */}
{totalWins.toLocaleString()} total wins
{totalRaces.toLocaleString()} races
{/* CTA */}
See full driver rankings
{/* Search */}
{/* Featured Drivers */}
{!searchQuery && (
Featured Drivers
Top performers on the grid
{featuredDrivers.map((driver, index) => (
handleDriverClick(driver.id)}
/>
))}
)}
{/* Active Drivers */}
{!searchQuery &&
}
{/* Skill Distribution */}
{!searchQuery &&
}
{/* Leaderboard Preview */}
{/* Empty State */}
{filteredDrivers.length === 0 && (
No drivers found matching "{searchQuery}"
)}
);
}