import { notFound } from 'next/navigation';
import { PageWrapper } from '@/components/shared/state/PageWrapper';
import { SponsorLeagueDetailPageClient } from '@/client-wrapper/SponsorLeagueDetailPageClient';
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';
import { getWebsiteServerEnv } from '@/lib/config/env';

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

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

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