'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { Users, Trophy, Search, Crown, Star, TrendingUp, Shield, Target, Award, ArrowLeft, Medal, Percent, Hash, Globe, Languages, } from 'lucide-react'; import Button from '@/components/ui/Button'; import Input from '@/components/ui/Input'; import Heading from '@/components/ui/Heading'; import { getGetAllTeamsQuery, getGetTeamMembersQuery, getDriverStats } from '@/lib/di-container'; import type { Team } from '@gridpilot/racing'; // ============================================================================ // TYPES // ============================================================================ type SkillLevel = 'beginner' | 'intermediate' | 'advanced' | 'pro'; type SortBy = 'rating' | 'wins' | 'winRate' | 'races'; interface TeamDisplayData { id: string; name: string; memberCount: number; rating: number | null; totalWins: number; totalRaces: number; performanceLevel: SkillLevel; isRecruiting: boolean; createdAt: Date; description?: string; specialization?: 'endurance' | 'sprint' | 'mixed'; region?: string; languages?: string[]; } // ============================================================================ // DEMO TEAMS DATA // ============================================================================ const DEMO_TEAMS: TeamDisplayData[] = [ { id: 'demo-team-1', name: 'Apex Predators Racing', description: 'Elite GT3 team competing at the highest level.', memberCount: 8, rating: 4850, totalWins: 47, totalRaces: 156, performanceLevel: 'pro', isRecruiting: true, createdAt: new Date(Date.now() - 180 * 24 * 60 * 60 * 1000), specialization: 'mixed', region: '🇺🇸 North America', languages: ['English'], }, { id: 'demo-team-2', name: 'Velocity Esports', description: 'Professional sim racing team with sponsors.', memberCount: 12, rating: 5200, totalWins: 63, totalRaces: 198, performanceLevel: 'pro', isRecruiting: false, createdAt: new Date(Date.now() - 365 * 24 * 60 * 60 * 1000), specialization: 'endurance', region: '🇬🇧 Europe', languages: ['English', 'German'], }, { id: 'demo-team-3', name: 'Nitro Motorsport', description: 'Championship-winning sprint specialists.', memberCount: 6, rating: 4720, totalWins: 38, totalRaces: 112, performanceLevel: 'pro', isRecruiting: true, createdAt: new Date(Date.now() - 90 * 24 * 60 * 60 * 1000), specialization: 'sprint', region: '🇩🇪 Germany', languages: ['German', 'English'], }, { id: 'demo-team-4', name: 'Horizon Racing Collective', description: 'Ambitious team on the rise.', memberCount: 10, rating: 3800, totalWins: 24, totalRaces: 89, performanceLevel: 'advanced', isRecruiting: true, createdAt: new Date(Date.now() - 60 * 24 * 60 * 60 * 1000), specialization: 'mixed', region: '🇳🇱 Netherlands', languages: ['Dutch', 'English'], }, { id: 'demo-team-5', name: 'Phoenix Rising eSports', description: 'From the ashes to the podium.', memberCount: 7, rating: 3650, totalWins: 19, totalRaces: 76, performanceLevel: 'advanced', isRecruiting: true, createdAt: new Date(Date.now() - 45 * 24 * 60 * 60 * 1000), specialization: 'endurance', region: '🇫🇷 France', languages: ['French', 'English'], }, { id: 'demo-team-6', name: 'Thunderbolt Racing', description: 'Fast and furious sprint racing.', memberCount: 5, rating: 3420, totalWins: 15, totalRaces: 54, performanceLevel: 'advanced', isRecruiting: false, createdAt: new Date(Date.now() - 120 * 24 * 60 * 60 * 1000), specialization: 'sprint', region: '🇮🇹 Italy', languages: ['Italian', 'English'], }, { id: 'demo-team-7', name: 'Grid Starters', description: 'Growing together as racers.', memberCount: 9, rating: 2800, totalWins: 11, totalRaces: 67, performanceLevel: 'intermediate', isRecruiting: true, createdAt: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000), specialization: 'mixed', region: '🇪🇸 Spain', languages: ['Spanish', 'English'], }, { id: 'demo-team-8', name: 'Midnight Racers', description: 'Night owls who love endurance racing.', memberCount: 6, rating: 2650, totalWins: 8, totalRaces: 42, performanceLevel: 'intermediate', isRecruiting: true, createdAt: new Date(Date.now() - 15 * 24 * 60 * 60 * 1000), specialization: 'endurance', region: '🌍 International', languages: ['English'], }, { id: 'demo-team-9', name: 'Casual Speedsters', description: 'Racing for fun, improving together.', memberCount: 4, rating: 2400, totalWins: 5, totalRaces: 31, performanceLevel: 'intermediate', isRecruiting: true, createdAt: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), specialization: 'sprint', region: '🇵🇱 Poland', languages: ['Polish', 'English'], }, { id: 'demo-team-10', name: 'Fresh Rubber Racing', description: 'New team for new racers!', memberCount: 3, rating: 1800, totalWins: 2, totalRaces: 18, performanceLevel: 'beginner', isRecruiting: true, createdAt: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000), specialization: 'mixed', region: '🇧🇷 Brazil', languages: ['Portuguese', 'English'], }, { id: 'demo-team-11', name: 'Rookie Revolution', description: 'First time racers welcome!', memberCount: 5, rating: 1650, totalWins: 1, totalRaces: 12, performanceLevel: 'beginner', isRecruiting: true, createdAt: new Date(Date.now() - 5 * 24 * 60 * 60 * 1000), specialization: 'sprint', region: '🇦🇺 Australia', languages: ['English'], }, { id: 'demo-team-12', name: 'Pit Lane Pioneers', description: 'Learning endurance racing from scratch.', memberCount: 4, rating: 1500, totalWins: 0, totalRaces: 8, performanceLevel: 'beginner', isRecruiting: true, createdAt: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000), specialization: 'endurance', region: '🇯🇵 Japan', languages: ['Japanese', 'English'], }, { id: 'demo-team-13', name: 'Shadow Squadron', description: 'Elite drivers emerging from the shadows.', memberCount: 6, rating: 4100, totalWins: 12, totalRaces: 34, performanceLevel: 'advanced', isRecruiting: true, createdAt: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), specialization: 'mixed', region: '🇸🇪 Scandinavia', languages: ['Swedish', 'Norwegian', 'English'], }, { id: 'demo-team-14', name: 'Turbo Collective', description: 'Fast, furious, and friendly.', memberCount: 4, rating: 3200, totalWins: 7, totalRaces: 28, performanceLevel: 'intermediate', isRecruiting: true, createdAt: new Date(Date.now() - 12 * 60 * 60 * 1000), specialization: 'sprint', region: '🇨🇦 Canada', languages: ['English', 'French'], }, ]; // ============================================================================ // SKILL LEVEL CONFIG // ============================================================================ const SKILL_LEVELS: { id: SkillLevel; label: string; icon: React.ElementType; color: string; bgColor: string; borderColor: string; }[] = [ { id: 'pro', label: 'Pro', icon: Crown, color: 'text-yellow-400', bgColor: 'bg-yellow-400/10', borderColor: 'border-yellow-400/30', }, { id: 'advanced', label: 'Advanced', icon: Star, color: 'text-purple-400', bgColor: 'bg-purple-400/10', borderColor: 'border-purple-400/30', }, { id: 'intermediate', label: 'Intermediate', icon: TrendingUp, color: 'text-primary-blue', bgColor: 'bg-primary-blue/10', borderColor: 'border-primary-blue/30', }, { id: 'beginner', label: 'Beginner', icon: Shield, color: 'text-green-400', bgColor: 'bg-green-400/10', borderColor: 'border-green-400/30', }, ]; // ============================================================================ // SORT OPTIONS // ============================================================================ const SORT_OPTIONS: { id: SortBy; label: string; icon: React.ElementType }[] = [ { id: 'rating', label: 'Rating', icon: Star }, { id: 'wins', label: 'Total Wins', icon: Trophy }, { id: 'winRate', label: 'Win Rate', icon: Percent }, { id: 'races', label: 'Races', icon: Hash }, ]; // ============================================================================ // TOP THREE PODIUM COMPONENT // ============================================================================ interface TopThreePodiumProps { teams: TeamDisplayData[]; onTeamClick: (teamId: string) => void; } function TopThreePodium({ teams, onTeamClick }: TopThreePodiumProps) { const top3 = teams.slice(0, 3); if (top3.length < 3) return null; // Display order: 2nd, 1st, 3rd const podiumOrder = [top3[1], top3[0], top3[2]]; const podiumHeights = ['h-28', 'h-36', 'h-20']; const podiumPositions = [2, 1, 3]; const getPositionColor = (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 getGradient = (position: number) => { switch (position) { case 1: return 'from-yellow-400/30 via-yellow-500/20 to-yellow-600/10'; case 2: return 'from-gray-300/30 via-gray-400/20 to-gray-500/10'; case 3: return 'from-amber-500/30 via-amber-600/20 to-amber-700/10'; default: return 'from-gray-600/30 to-gray-700/10'; } }; const getBorderColor = (position: number) => { switch (position) { case 1: return 'border-yellow-400/50'; case 2: return 'border-gray-300/50'; case 3: return 'border-amber-600/50'; default: return 'border-charcoal-outline'; } }; return (
Loading leaderboard...
Rankings of all teams by performance metrics
{filteredAndSortedTeams.length}
{filteredAndSortedTeams.filter((t) => t.performanceLevel === 'pro').length}
{filteredAndSortedTeams.reduce((sum, t) => sum + t.totalWins, 0)}
{filteredAndSortedTeams.reduce((sum, t) => sum + t.totalRaces, 0)}
No teams found
Try adjusting your filters or search query