'use client'; import Link from 'next/link'; import Image from 'next/image'; import { Trophy, Users, Flag, Award, Gamepad2, Calendar, ChevronRight, Sparkles, } from 'lucide-react'; import type { LeagueSummaryViewModel } from '@core/racing/application/presenters/IAllLeaguesWithCapacityAndScoringPresenter'; import { getLeagueCoverClasses } from '@/lib/leagueCovers'; interface LeagueCardProps { league: LeagueSummaryViewModel; onClick?: () => void; } function getChampionshipIcon(type?: string) { switch (type) { case 'driver': return Trophy; case 'team': return Users; case 'nations': return Flag; case 'trophy': return Award; default: return Trophy; } } function getChampionshipLabel(type?: string) { switch (type) { case 'driver': return 'Driver'; case 'team': return 'Team'; case 'nations': return 'Nations'; case 'trophy': return 'Trophy'; default: return 'Championship'; } } function getGameColor(gameId?: string): string { switch (gameId) { case 'iracing': return 'bg-orange-500/20 text-orange-400 border-orange-500/30'; case 'acc': return 'bg-green-500/20 text-green-400 border-green-500/30'; case 'f1-23': case 'f1-24': return 'bg-red-500/20 text-red-400 border-red-500/30'; default: return 'bg-primary-blue/20 text-primary-blue border-primary-blue/30'; } } function isNewLeague(createdAt: string | Date): boolean { const oneWeekAgo = new Date(); oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); return new Date(createdAt) > oneWeekAgo; } export default function LeagueCard({ league, onClick }: LeagueCardProps) { const imageService = getImageService(); const coverUrl = imageService.getLeagueCover(league.id); const logoUrl = imageService.getLeagueLogo(league.id); const ChampionshipIcon = getChampionshipIcon(league.scoring?.primaryChampionshipType); const championshipLabel = getChampionshipLabel(league.scoring?.primaryChampionshipType); const gameColorClass = getGameColor(league.scoring?.gameId); const isNew = isNewLeague(league.createdAt); const isTeamLeague = league.maxTeams && league.maxTeams > 0; // Calculate fill percentage - use teams for team leagues, drivers otherwise const usedSlots = isTeamLeague ? (league.usedTeamSlots ?? 0) : (league.usedDriverSlots ?? 0); const maxSlots = isTeamLeague ? (league.maxTeams ?? 0) : (league.maxDrivers ?? 0); const fillPercentage = maxSlots > 0 ? (usedSlots / maxSlots) * 100 : 0; const hasOpenSlots = maxSlots > 0 && usedSlots < maxSlots; // Determine slot label based on championship type const getSlotLabel = () => { if (isTeamLeague) return 'Teams'; if (league.scoring?.primaryChampionshipType === 'nations') return 'Nations'; return 'Drivers'; }; const slotLabel = getSlotLabel(); return (
{league.description || 'No description available'}
{/* Stats Row */}