import 'server-only'; import { request } from './api'; import type { MapResponse, RankingResponse } from './types'; import type { CompareMode, CompareResponse, CompareSnapshotResponse, IndicatorsResponse, RankHistoryResponse, RankingsListResponse, RegionsResponse } from './types-compare'; /** * Server-side endpoints for the compare / rankings pages (same `request()` wrapper as `lib/api.ts`, * kept in a separate module so the two page groups can be developed concurrently). * The API caps `/compare` at 8 countries × 8 indicators per call; `/compare/snapshot` at 8 × 40. */ export const apiCompare = { compare: (countries: string[], indicators: string[], q: { from?: number | null; to?: number | null; mode?: CompareMode; include_forecast?: boolean } = {}) => request('/compare', { countries: countries.join(','), indicators: indicators.slice(0, 8).join(','), from: q.from ?? undefined, to: q.to ?? undefined, mode: q.mode ?? 'absolute', include_forecast: q.include_forecast }), snapshot: (countries: string[], q: { topic?: string | null; indicators?: string[] | null } = {}) => request('/compare/snapshot', { countries: countries.join(','), topic: q.indicators?.length ? undefined : q.topic ?? undefined, indicators: q.indicators?.length ? q.indicators.join(',') : undefined }), rankings: (topic?: string) => request('/rankings', { topic }), ranking: (slug: string, q: { year?: number | null; group?: string | null; sort?: 'asc' | 'desc' | null; limit?: number; offset?: number; sparkline?: boolean } = {}) => request(`/rankings/${encodeURIComponent(slug)}`, { year: q.year ?? undefined, group: q.group ?? undefined, sort: q.sort ?? undefined, limit: q.limit ?? 300, offset: q.offset, sparkline: q.sparkline ?? true }), rankHistory: (slug: string, countries: string[], q: { from?: number; to?: number } = {}) => request(`/rankings/${encodeURIComponent(slug)}/history`, { countries: countries.join(','), ...q }), indicatorMap: (slug: string, q: { year?: number | null; nearest?: boolean } = {}) => request(`/indicators/${encodeURIComponent(slug)}/map`, { year: q.year ?? undefined, nearest: q.nearest }), indicators: (q: { topic?: string; q?: string; featured?: boolean } = {}) => request('/indicators', q), regions: (kind?: string) => request('/regions', { kind }), };