import type { PowerOverview } from "@dci/core"; import { HonestEmpty } from "@/components/intelligence/shared"; import { CountryFlag } from "@/components/ui/country-flag"; import { RowLink, TBody, THead, Table, Td, Th, Tr } from "@/components/ui/table"; import { fmtInt, fmtMw, fmtPct } from "@/lib/format"; import { routes } from "@/lib/routes"; import { compareBy, parseSort, sortTh, type SearchParams } from "@/lib/sort"; export const ENERGY_SORTS = ["name", "renewable", "twh", "year", "carbon", "mw", "facilities"] as const; export type EnergySort = (typeof ENERGY_SORTS)[number]; type Row = PowerOverview["countryEnergy"][number]; function getter(k: EnergySort): (r: Row) => number | string | null { switch (k) { case "name": return (r) => r.name; case "renewable": return (r) => r.energy.renewableShare; case "twh": return (r) => r.energy.electricityTwh; case "year": return (r) => r.energy.statsYear; case "carbon": return (r) => r.energy.gridCarbonIntensity; case "mw": return (r) => r.knownMw; case "facilities": return (r) => r.facilities; } } /** National electricity context per country (World Bank vintage) next to the known DC load — sortable via ?sort=&order=. */ export function CountryEnergyTable({ rows, sp }: { rows: Row[]; sp: SearchParams }) { if (!rows.length) return ; const sort = parseSort(sp, ENERGY_SORTS, { key: "facilities", order: "desc" }); const sorted = [...rows].sort(compareBy(getter(sort.key), sort.order)); const th = (k: EnergySort) => sortTh(routes.power(), sp, sort, k); const source = rows.find((r) => r.energy.sourceName)?.energy.sourceName ?? null; return (
{sorted.map((r) => ( ))}
Country Renewable share Electricity Year Grid carbon Known DC MW Facilities
{r.name} {r.energy.renewableShare === null ? — : fmtPct(r.energy.renewableShare / 100, 1)} {r.energy.electricityTwh === null ? — : `${fmtInt(r.energy.electricityTwh)} TWh`} {r.energy.statsYear ?? —} {r.energy.gridCarbonIntensity === null ? not available : `${fmtInt(r.energy.gridCarbonIntensity)} gCO₂/kWh`} {r.knownMw === null ? — : fmtMw(r.knownMw)} {fmtInt(r.facilities)}

{source ? `Source: ${source} (latest available vintage per country). ` : ""}Grid carbon intensity reads “not available” until a reliable public source is connected — it is never estimated.

); }