import { LeagueSponsorshipsPageQuery } from '@/lib/page-queries/LeagueSponsorshipsPageQuery';
import { LeagueSponsorshipsTemplate } from '@/templates/LeagueSponsorshipsTemplate';
import { notFound } from 'next/navigation';

interface Props {
  params: Promise<{ id: string }>;
}

export default async function LeagueSponsorshipsPage({ params }: Props) {
  const { id: leagueId } = await params;

  if (!leagueId) {
    notFound();
  }

  const result = await LeagueSponsorshipsPageQuery.execute(leagueId);

  if (result.isErr()) {
    const error = result.getError();
    if (error === 'notFound') {
      notFound();
    }
    // For serverError, show the template with empty data
    return <LeagueSponsorshipsTemplate viewData={{
      leagueId,
      activeTab: 'overview',
      onTabChange: () => {},
      league: {
        id: leagueId,
        name: 'Unknown League',
        description: 'League information unavailable',
      },
      sponsorshipSlots: [],
      sponsorshipRequests: [],
    }} />;
  }

  return <LeagueSponsorshipsTemplate viewData={result.unwrap()} />;
}