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

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

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

  // Fetch data server-side
  let teams: TeamSummaryViewModel[] = [];

  try {
    teams = await teamService.getAllTeams();
  } catch (error) {
    console.error('Failed to load team leaderboard:', error);
    teams = [];
  }

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