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

export default async function Page() {
  // Execute the PageQuery
  const result = await LeaguesPageQuery.execute();
  
  // Handle different result types
  if (result.isErr()) {
    const error = result.getError();
    
    switch (error) {
      case 'notFound':
        notFound();
      case 'redirect':
        // In a real app, this would redirect to login
        notFound();
      case 'LEAGUES_FETCH_FAILED':
      case 'UNKNOWN_ERROR':
      default:
        // Return error state - use LeaguesTemplate with empty data
        return <LeaguesTemplate data={{ leagues: [] }} />;
    }
  }
  
  const viewData = result.unwrap();
  
  return <LeaguesTemplate data={viewData} />;
}