"use client"; import { useEffect, useState } from "react"; import { fetchGroups, fetchAllSignals, Group, Signal } from "../lib/api"; export default function AgentStats() { const [groups, setGroups] = useState([]); const [signals, setSignals] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { async function load() { try { const [grps, all] = await Promise.all([fetchGroups(), fetchAllSignals()]); setGroups(grps); setSignals(all.flatMap((g) => g.signals)); } catch { // ignore } finally { setLoading(false); } } load(); }, []); const totalSignals = groups.reduce((acc, g) => acc + g.signal_count, 0); const activeGroups = groups.filter((g) => g.signal_count > 0).length; const criticalSignals = signals.filter( (s) => s.metadata.severity === "critical" || s.metadata.severity === "high" ).length; const errorRate = totalSignals > 0 ? `${((criticalSignals / totalSignals) * 100).toFixed(2)}%` : "0.00%"; const stats = [ { title: "Active Groups", value: loading ? "—" : `${activeGroups} / ${groups.length}`, icon: "memory", iconColor: "#a88cfb", }, { title: "Total Signals", value: loading ? "—" : totalSignals >= 1000 ? `${(totalSignals / 1000).toFixed(1)}k` : String(totalSignals), icon: "speed", iconColor: "#00daf3", }, { title: "High Priority", value: loading ? "—" : `${criticalSignals}`, icon: "warning", iconColor: criticalSignals > 0 ? "#ff6f78" : "#10b981", }, { title: "Lens Coverage", value: loading ? "—" : `${[...new Set(groups.map((g) => g.lens).filter(Boolean))].length} types`, icon: "verified", iconColor: "#10b981", }, ]; return (
{stats.map((stat, idx) => (

{stat.title}

{stat.value.split(" ").map((part, i) => ( {part}{" "} ))}

{stat.icon}
))}
); }