'use client'; import React from 'react'; import { Users, Trophy, Crown, Award, ArrowLeft, Medal, Percent, Hash, Globe, Languages, Target } from 'lucide-react'; import Button from '@/components/ui/Button'; import Input from '@/components/ui/Input'; import Heading from '@/components/ui/Heading'; import TopThreePodium from '@/components/teams/TopThreePodium'; import type { TeamSummaryViewModel } from '@/lib/view-models/TeamSummaryViewModel'; import TeamRankingsFilter from '@/components/TeamRankingsFilter'; import Image from 'next/image'; import { getMediaUrl } from '@/lib/utilities/media'; // ============================================================================ // TYPES // ============================================================================ type SkillLevel = 'pro' | 'advanced' | 'intermediate' | 'beginner'; type SortBy = 'rating' | 'wins' | 'winRate' | 'races'; interface TeamLeaderboardTemplateProps { teams: TeamSummaryViewModel[]; searchQuery: string; filterLevel: SkillLevel | 'all'; sortBy: SortBy; onSearchChange: (query: string) => void; onFilterLevelChange: (level: SkillLevel | 'all') => void; onSortChange: (sort: SortBy) => void; onTeamClick: (id: string) => void; onBackToTeams: () => void; } // ============================================================================ // HELPER FUNCTIONS // ============================================================================ const getSafeRating = (team: TeamSummaryViewModel): number => { return 0; }; const getSafeTotalWins = (team: TeamSummaryViewModel): number => { const raw = team.totalWins; const value = typeof raw === 'number' ? raw : 0; return Number.isFinite(value) ? value : 0; }; const getSafeTotalRaces = (team: TeamSummaryViewModel): number => { const raw = team.totalRaces; const value = typeof raw === 'number' ? raw : 0; return Number.isFinite(value) ? value : 0; }; const getMedalColor = (position: number) => { switch (position) { case 0: return 'text-yellow-400'; case 1: return 'text-gray-300'; case 2: return 'text-amber-600'; default: return 'text-gray-500'; } }; const getMedalBg = (position: number) => { switch (position) { case 0: return 'bg-gradient-to-br from-yellow-400/20 to-yellow-600/10 border-yellow-400/40'; case 1: return 'bg-gradient-to-br from-gray-300/20 to-gray-400/10 border-gray-300/40'; case 2: return 'bg-gradient-to-br from-amber-600/20 to-amber-700/10 border-amber-600/40'; default: return 'bg-iron-gray/50 border-charcoal-outline'; } }; // ============================================================================ // MAIN TEMPLATE COMPONENT // ============================================================================ export default function TeamLeaderboardTemplate({ teams, searchQuery, filterLevel, sortBy, onSearchChange, onFilterLevelChange, onSortChange, onTeamClick, onBackToTeams, }: TeamLeaderboardTemplateProps) { // Filter and sort teams const filteredAndSortedTeams = teams .filter((team) => { // Search filter if (searchQuery) { const query = searchQuery.toLowerCase(); if (!team.name.toLowerCase().includes(query) && !(team.description ?? '').toLowerCase().includes(query)) { return false; } } // Level filter if (filterLevel !== 'all' && team.performanceLevel !== filterLevel) { return false; } return true; }) .sort((a, b) => { switch (sortBy) { case 'rating': { const aRating = getSafeRating(a); const bRating = getSafeRating(b); return bRating - aRating; } case 'wins': { const aWinsSort = getSafeTotalWins(a); const bWinsSort = getSafeTotalWins(b); return bWinsSort - aWinsSort; } case 'winRate': { const aRaces = getSafeTotalRaces(a); const bRaces = getSafeTotalRaces(b); const aWins = getSafeTotalWins(a); const bWins = getSafeTotalWins(b); const aRate = aRaces > 0 ? aWins / aRaces : 0; const bRate = bRaces > 0 ? bWins / bRaces : 0; return bRate - aRate; } case 'races': { const aRacesSort = getSafeTotalRaces(a); const bRacesSort = getSafeTotalRaces(b); return bRacesSort - aRacesSort; } default: return 0; } }); return (
Rankings of all teams by performance metrics
{filteredAndSortedTeams.length}
{filteredAndSortedTeams.filter((t) => t.performanceLevel === 'pro').length}
{filteredAndSortedTeams.reduce
{filteredAndSortedTeams.reduce
No teams found
Try adjusting your filters or search query