import type { CountrySummary } from "@dci/core"; import { api } from "@/lib/api"; import { routes } from "@/lib/routes"; /** iso2 → canonical country slug (falls back to the iso2, which the API also accepts). */ export async function countrySlugMap(): Promise<{ map: Map; countries: CountrySummary[] }> { const r = await api.countries(); const map = new Map(); for (const c of r.items) map.set(c.iso2.toUpperCase(), c.slug); return { map, countries: r.items }; } export function countryHref(map: Map, iso2: string | null | undefined): string | null { if (!iso2) return null; return routes.country(map.get(iso2.toUpperCase()) ?? iso2.toLowerCase()); } /** construction + planned MW when at least one is published; null otherwise (never 0 for unknown). */ export function pipelineMw(m: { constructionMw: number | null; plannedMw: number | null }): number | null { if (m.constructionMw === null && m.plannedMw === null) return null; return (m.constructionMw ?? 0) + (m.plannedMw ?? 0); }