'use client'; import Link from 'next/link'; import { useEffect, useState } from 'react'; import { Bar } from '@/components/ui/primitives'; import { fmt, fmtDelta, fmtInt } from '@/lib/format'; import { COMPONENT_LABEL, pressureColor } from '@/lib/pressure'; import { Time } from '@/lib/time'; import type { Explain, GlobalPressure } from '@/lib/types'; function scopeHref(scopeType: string, scopeId: string | null): string | null { if (!scopeId) return null; if (scopeType === 'region') return `/internet/${scopeId}`; if (scopeType === 'country') return `/country/${scopeId.toLowerCase()}`; if (scopeType === 'asn') return `/asn/${scopeId}`; if (scopeType === 'service') return `/service/${scopeId}`; if (scopeType === 'bgp') return '/bgp'; return null; } /** "Why is Global Pressure 42.7?" — explain rows, then components → signals from /api/v1/explain. */ export function ExplainPanel({ global, onClose }: { global: GlobalPressure; onClose: () => void }) { const [deep, setDeep] = useState(null); const [err, setErr] = useState(null); const [openComp, setOpenComp] = useState(null); useEffect(() => { const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose(); window.addEventListener('keydown', onKey); document.body.style.overflow = 'hidden'; fetch('/api/v1/explain') .then((r) => (r.ok ? r.json() : Promise.reject(new Error(String(r.status))))) .then((d: Explain) => setDeep(d)) .catch(() => setErr('Deep explanation unavailable')); return () => { window.removeEventListener('keydown', onKey); document.body.style.overflow = ''; }; }, [onClose]); return (
); }