import { notFound } from 'next/navigation';
import { PageWrapper } from '@/components/shared/state/PageWrapper';
import { SponsorLeagueDetailTemplate } from '@/templates/SponsorLeagueDetailTemplate';
import { SponsorsApiClient } from '@/lib/api/sponsors/SponsorsApiClient';
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';

export default async function Page({ params }: { params: { id: string } }) {
  // Manual wiring: create dependencies
  const baseUrl = getWebsiteApiBaseUrl();
  const logger = new ConsoleLogger();
  const errorReporter = new EnhancedErrorReporter(logger, {
    showUserNotifications: true,
    logToConsole: true,
    reportToExternal: process.env.NODE_ENV === 'production',
  });

  // Create API client
  const apiClient = new SponsorsApiClient(baseUrl, errorReporter, logger);

  // Fetch data
  const data = await apiClient.getLeagueDetail(params.id);
  
  if (!data) notFound();
  
  // Data is already in the right format from API client
  return <PageWrapper data={data} Template={SponsorLeagueDetailTemplate} />;
}