'use client'; import Breadcrumbs from '@/components/layout/Breadcrumbs'; import LeagueHeader from '@/components/leagues/LeagueHeader'; import { useEffectiveDriverId } from '@/hooks/useEffectiveDriverId'; import { useServices } from '@/lib/services/ServiceProvider'; import { LeaguePageDetailViewModel } from '@/lib/view-models/LeaguePageDetailViewModel'; import { useParams, usePathname, useRouter } from 'next/navigation'; import React, { useEffect, useState } from 'react'; export default function LeagueLayout({ children, }: { children: React.ReactNode; }) { const params = useParams(); const pathname = usePathname(); const router = useRouter(); const leagueId = params.id as string; const currentDriverId = useEffectiveDriverId(); const { leagueService } = useServices(); const [leagueDetail, setLeagueDetail] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { async function loadLeague() { try { const leagueDetailData = await leagueService.getLeagueDetail(leagueId, currentDriverId); setLeagueDetail(leagueDetailData); } catch (error) { console.error('Failed to load league:', error); } finally { setLoading(false); } } loadLeague(); }, [leagueId, currentDriverId, leagueService]); if (loading) { return (
Loading league...
); } if (!leagueDetail) { return (
League not found
); } // Define tab configuration const baseTabs = [ { label: 'Overview', href: `/leagues/${leagueId}`, exact: true }, { label: 'Schedule', href: `/leagues/${leagueId}/schedule`, exact: false }, { label: 'Standings', href: `/leagues/${leagueId}/standings`, exact: false }, { label: 'Rulebook', href: `/leagues/${leagueId}/rulebook`, exact: false }, ]; const adminTabs = [ { label: 'Schedule Admin', href: `/leagues/${leagueId}/schedule/admin`, exact: false }, { label: 'Sponsorships', href: `/leagues/${leagueId}/sponsorships`, exact: false }, { label: 'Stewarding', href: `/leagues/${leagueId}/stewarding`, exact: false }, { label: 'Wallet', href: `/leagues/${leagueId}/wallet`, exact: false }, { label: 'Settings', href: `/leagues/${leagueId}/settings`, exact: false }, ]; const tabs = leagueDetail.isAdmin ? [...baseTabs, ...adminTabs] : baseTabs; return (
{/* Tab Navigation */}
{tabs.map((tab) => ( ))}
{children}
); }