'use client';
import { useState } from 'react';
import { AnimatedNumber } from '@/components/ui/AnimatedNumber';
import { Sparkline } from '@/components/ui/primitives';
import { fmt, fmtDelta, fmtInt } from '@/lib/format';
import { useDegraded, useLive } from '@/lib/live';
import { levelById, pressureColor, trendArrow } from '@/lib/pressure';
import { Time } from '@/lib/time';
import type { GlobalPressure } from '@/lib/types';
import { ExplainPanel } from './ExplainPanel';
/** The instrument. SSR renders `initial`; afterwards the live slice drives it. Click → Explain (spec §44). */
export function Gauge({ initial }: { initial: GlobalPressure | null }) {
const live = useLive((s) => s.global);
const updates = useLive((s) => s.updates);
const { degraded, frozenSince } = useDegraded();
const [open, setOpen] = useState(false);
const g = live ?? initial;
if (!g) {
return (
Global Internet Pressure
—
The pressure API is unreachable. This is our failure, not an Internet event.
);
}
const color = pressureColor(g.level);
const level = levelById(g.level);
const dim = degraded ? 'opacity-50 saturate-50' : '';
return (
{/* faint radial glow tinted by the current level — the only gradient on the site */}
Global Internet Pressure
velocity
{fmtDelta(g.velocity_per_h)}/h
· {fmtDelta(g.acceleration_per_h2)}/h²
Δ24h
{fmtDelta(g.delta_24h)}
volatility
{fmt(g.volatility_1h)}
{fmtInt(g.coverage.probes_active)}
/{fmtInt(g.coverage.probes_total)} probes · {fmtInt(g.coverage.probe_regions)} regions · {fmtInt(g.coverage.targets)} targets · {fmtInt(g.coverage.bgp_collectors)} collectors · confidence{' '}
{Math.round(g.confidence * 100)} %
1 h
{degraded && (
Frozen since — instrument degraded, not an Internet event.
)}
Engine · baseline {fmt(g.coverage.baseline_days)} d · {fmtInt(g.coverage.measurements_5m)} measurements / 5 min
{open &&
setOpen(false)} />}
);
}