import type { Pulse } from "@dci/core";
import Link from "next/link";
import { EventList } from "@/components/event-list";
import { cn } from "@/components/ui/cn";
import { CountryFlag } from "@/components/ui/country-flag";
import { fmtInt, fmtMw } from "@/lib/format";
import { routes } from "@/lib/routes";
function Stat({ label, value, href, muted }: { label: string; value: string; href?: string; muted?: boolean }) {
const inner = (
<>
{value}
{label}
>
);
return href ? (
{inner}
) : (
{inner}
);
}
/** WHAT CHANGED TODAY (§16): deterministic pulse counts + the major events of the window; nothing scored, everything countable. */
export function PulseBlock({ pulse, compact }: { pulse: Pulse; compact?: boolean }) {
const win = pulse.window === "24h" ? "24 h" : pulse.window;
const live = (type: string) => routes.live(`type=${type}&since=${encodeURIComponent(pulse.since)}`);
const stats: Array<{ label: string; value: number | null; href?: string; mw?: boolean }> = [
{ label: "new projects", value: pulse.newProjects, href: live("project_announced") },
{ label: "entered construction", value: pulse.projectsEnteredConstruction, href: live("construction_started") },
{ label: "facilities opened", value: pulse.facilitiesOpened, href: live("facility_opened") },
{ label: "newly announced (published MW)", value: pulse.newlyAnnouncedMw, mw: true },
{ label: "construction started (published MW)", value: pulse.constructionStartedMw, mw: true },
{ label: "cloud regions announced", value: pulse.cloudRegionsAnnounced, href: live("cloud_region_announced") },
{ label: "power agreements", value: pulse.powerAgreements, href: live("power_agreement") },
{ label: "grid constraint events", value: pulse.gridConstraintEvents, href: live("grid_constraint") },
{ label: "acquisitions", value: pulse.acquisitions, href: live("acquisition") },
{ label: "financing events", value: pulse.financingEvents, href: live("investment_announced") },
{ label: "facilities newly indexed", value: pulse.newFacilitiesIndexed, href: live("facility_discovered") },
{ label: "capacity changes", value: pulse.capacityChanges, href: live("capacity_changed") },
];
return (
{stats.map((s) => (
))}
{pulse.operatorsNewMarkets.length > 0 && (
Operators entering new markets · {win}
{pulse.operatorsNewMarkets.slice(0, 8).map((o, i) => (
-
{o.operator.name}
→
{o.market?.name ?? ""}
))}
{pulse.operatorsNewMarkets.length > 8 && - +{fmtInt(pulse.operatorsNewMarkets.length - 8)} more
}
)}
{(pulse.byCountry.length > 0 || pulse.byOperator.length > 0) && (
{pulse.byCountry.length > 0 && (
Most active countries
{pulse.byCountry.slice(0, 5).map((c) => (
-
{c.name}
{fmtInt(c.events)} ev · {fmtInt(c.newProjects)} prj
))}
)}
{pulse.byOperator.length > 0 && (
Most active operators
{pulse.byOperator.slice(0, 5).map((o) => (
-
{o.name}
{fmtInt(o.events)} ev · {fmtInt(o.newProjects)} prj
))}
)}
)}
Major events · {win}
All major →
);
}