import { PageWrapper } from '@/components/shared/state/PageWrapper';
import { DriversTemplate } from '@/templates/DriversTemplate';
import { DriverService } from '@/lib/services/drivers/DriverService';
import { DriversApiClient } from '@/lib/api/drivers/DriversApiClient';
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';

export default async function Page() {
  // Manual dependency creation (consistent with /races and /teams)
  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 driversApiClient = new DriversApiClient(baseUrl, errorReporter, logger);

  // Create service
  const service = new DriverService(driversApiClient);
  
  const data = await service.getDriverLeaderboard();
  
  return <PageWrapper data={data} Template={DriversTemplate} />;
}