import { useEffect, useRef, useState } from "react"; import { forgesight } from "@/lib/api"; import { Activity, Cpu, Zap, Thermometer, BarChart3, Database } from "lucide-react"; /* ── helpers ─────────────────────────────────────────────────────────────── */ function arc(pct, r = 38) { const clamp = Math.min(100, Math.max(0, pct)); const angle = (clamp / 100) * 270 - 135; // 270° sweep, start -135° const rad = (a) => (a * Math.PI) / 180; const x = 50 + r * Math.cos(rad(angle)); const y = 50 + r * Math.sin(rad(angle)); const large = clamp > 50 ? 1 : 0; const sx = 50 + r * Math.cos(rad(-135)); const sy = 50 + r * Math.sin(rad(-135)); return `M ${sx} ${sy} A ${r} ${r} 0 ${large} 1 ${x} ${y}`; } function ArcGauge({ pct = 0, label, value, icon: Icon, color = "#ED1C24" }) { const prev = useRef(pct); const [displayed, setDisplayed] = useState(pct); useEffect(() => { // smooth interpolation const start = prev.current; const end = pct; const dur = 600; const t0 = performance.now(); let raf; const step = (now) => { const progress = Math.min((now - t0) / dur, 1); const eased = 1 - Math.pow(1 - progress, 3); setDisplayed(start + (end - start) * eased); if (progress < 1) raf = requestAnimationFrame(step); else prev.current = end; }; raf = requestAnimationFrame(step); return () => cancelAnimationFrame(raf); }, [pct]); const bgPath = arc(100); const fgPath = arc(displayed); return (