Files
gridpilot.gg/apps/website/components/leagues/LeagueCard.tsx
2025-12-05 12:24:38 +01:00

144 lines
5.3 KiB
TypeScript

'use client';
import Link from 'next/link';
import Image from 'next/image';
import type { LeagueSummaryDTO } from '@gridpilot/racing/application/dto/LeagueSummaryDTO';
import Card from '../ui/Card';
import { getLeagueCoverClasses } from '@/lib/leagueCovers';
import { getImageService } from '@/lib/di-container';
interface LeagueCardProps {
league: LeagueSummaryDTO;
onClick?: () => void;
}
export default function LeagueCard({ league, onClick }: LeagueCardProps) {
const imageService = getImageService();
const coverUrl = imageService.getLeagueCover(league.id);
const logoUrl = imageService.getLeagueLogo(league.id);
return (
<div
className="cursor-pointer hover:scale-[1.03] transition-transform duration-150"
onClick={onClick}
>
<Card>
<div className="space-y-3">
<div className={getLeagueCoverClasses(league.id)} aria-hidden="true">
<div className="relative w-full h-full">
<Image
src={coverUrl}
alt={`${league.name} cover`}
fill
className="object-cover opacity-80"
sizes="(min-width: 1024px) 33vw, (min-width: 768px) 50vw, 100vw"
/>
<div className="absolute left-4 bottom-4 flex items-center">
<div className="w-10 h-10 rounded-full overflow-hidden border border-charcoal-outline/80 bg-deep-graphite/80 shadow-[0_0_10px_rgba(0,0,0,0.6)]">
<Image
src={logoUrl}
alt={`${league.name} logo`}
width={40}
height={40}
className="w-full h-full object-cover"
/>
</div>
</div>
</div>
</div>
<div className="flex items-start justify-between">
<h3 className="text-xl font-semibold text-white">{league.name}</h3>
<span className="text-xs text-gray-500">
{new Date(league.createdAt).toLocaleDateString()}
</span>
</div>
<p className="text-gray-400 text-sm line-clamp-2">
{league.description}
</p>
{league.structureSummary && (
<p className="text-xs text-gray-400">
{league.structureSummary}
</p>
)}
{league.scoringPatternSummary && (
<p className="text-xs text-gray-400">
{league.scoringPatternSummary}
</p>
)}
{league.timingSummary && (
<p className="text-xs text-gray-400">
{league.timingSummary}
</p>
)}
<div className="flex items-center justify-between pt-2 border-t border-charcoal-outline">
<div className="flex flex-col text-xs text-gray-500">
<span>
Owner:{' '}
<Link
href={`/drivers/${league.ownerId}?from=league&leagueId=${league.id}`}
className="text-primary-blue hover:underline"
>
{league.ownerId.slice(0, 8)}...
</Link>
</span>
<span className="mt-1 text-gray-400">
Drivers:{' '}
<span className="text-white font-medium">
{typeof league.usedDriverSlots === 'number'
? league.usedDriverSlots
: '—'}
</span>
{' / '}
<span className="text-gray-300">
{league.maxDrivers ?? '—'}
</span>
</span>
{typeof league.usedTeamSlots === 'number' ||
typeof league.maxTeams === 'number' ? (
<span className="mt-0.5 text-gray-400">
Teams:{' '}
<span className="text-white font-medium">
{typeof league.usedTeamSlots === 'number'
? league.usedTeamSlots
: '—'}
</span>
{' / '}
<span className="text-gray-300">
{league.maxTeams ?? '—'}
</span>
</span>
) : null}
</div>
<div className="flex flex-col items-end text-xs text-gray-400">
{league.scoring ? (
<>
<span className="text-primary-blue font-semibold">
{league.scoring.gameName}
</span>
<span className="mt-0.5">
{league.scoring.primaryChampionshipType === 'driver'
? 'Driver championship'
: league.scoring.primaryChampionshipType === 'team'
? 'Team championship'
: league.scoring.primaryChampionshipType === 'nations'
? 'Nations championship'
: 'Trophy championship'}
</span>
<span className="mt-0.5">
{league.scoring.scoringPatternSummary}
</span>
</>
) : (
<span className="text-gray-500">Scoring: Not configured</span>
)}
</div>
</div>
</div>
</Card>
</div>
);
}