import { ServiceFactory } from '@/lib/services/ServiceFactory';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
import DriverRankingsInteractive from './DriverRankingsInteractive';
import type { DriverLeaderboardItemViewModel } from '@/lib/view-models/DriverLeaderboardItemViewModel';

// ============================================================================
// SERVER COMPONENT - Fetches data and passes to Interactive wrapper
// ============================================================================

export default async function DriverRankingsStatic() {
  // Create services for server-side data fetching
  const serviceFactory = new ServiceFactory(getWebsiteApiBaseUrl());
  const driverService = serviceFactory.createDriverService();

  // Fetch data server-side
  let drivers: DriverLeaderboardItemViewModel[] = [];

  try {
    const driversViewModel = await driverService.getDriverLeaderboard();
    drivers = driversViewModel.drivers;
  } catch (error) {
    console.error('Failed to load driver rankings:', error);
    drivers = [];
  }

  // Pass data to Interactive wrapper which handles client-side interactions
  return <DriverRankingsInteractive drivers={drivers} />;
}