'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import LeagueCard from '@/components/alpha/LeagueCard'; import CreateLeagueForm from '@/components/alpha/CreateLeagueForm'; import Button from '@/components/ui/Button'; import Card from '@/components/ui/Card'; import { League } from '@/domain/entities/League'; import { getLeagueRepository } from '@/lib/di-container'; export default function LeaguesPage() { const router = useRouter(); const [leagues, setLeagues] = useState([]); const [loading, setLoading] = useState(true); const [showCreateForm, setShowCreateForm] = useState(false); useEffect(() => { loadLeagues(); }, []); const loadLeagues = async () => { try { const leagueRepo = getLeagueRepository(); const allLeagues = await leagueRepo.findAll(); setLeagues(allLeagues); } catch (error) { console.error('Failed to load leagues:', error); } finally { setLoading(false); } }; const handleLeagueClick = (leagueId: string) => { router.push(`/leagues/${leagueId}`); }; if (loading) { return (
Loading leagues...
); } return (

Leagues

{leagues.length === 0 ? 'Create your first league to get started' : `${leagues.length} ${leagues.length === 1 ? 'league' : 'leagues'} available`}

{showCreateForm && (

Create New League

Experiment with different point systems

)} {leagues.length === 0 ? (

No leagues yet

Create one to get started. Alpha data resets on page reload.

) : (
{leagues.map((league) => ( handleLeagueClick(league.id)} /> ))}
)}
); }