"use client"; import { useTranslations } from "next-intl"; /** * TokenHealthBadge — Batch G * * Small badge in the Header showing token health status. * Polls /api/token-health every 60s. */ import { useState, useEffect } from "react"; const STATUS_MAP = { healthy: { icon: "check_circle", color: "#22c55e", tooltip: "All tokens healthy" }, warning: { icon: "warning", color: "#f59e0b", tooltip: "Some tokens need attention" }, error: { icon: "error", color: "#ef4444", tooltip: "Token refresh failures detected" }, unknown: { icon: "help", color: "#6b7280", tooltip: "Health status unknown" }, }; export default function TokenHealthBadge() { const t = useTranslations("stats"); const [health, setHealth] = useState(null); const [showTooltip, setShowTooltip] = useState(false); useEffect(() => { const fetchHealth = async () => { try { const res = await fetch("/api/token-health"); if (res.ok) { const data = await res.json(); setHealth(data); } } catch { // silent } }; fetchHealth(); const interval = setInterval(fetchHealth, 60000); return () => clearInterval(interval); }, []); if (!health || health.total === 0) return null; const status = STATUS_MAP[health.status] || STATUS_MAP.unknown; return (
setShowTooltip(true)} onMouseLeave={() => setShowTooltip(false)} > {showTooltip && (

{t("tokenHealth")}

{t("totalOAuth")} {health.total}
{t("healthy")} {health.healthy}
{health.errored > 0 && (
{t("errored")} {health.errored}
)} {health.warning > 0 && (
{t("warning")} {health.warning}
)} {health.lastCheckAt && (
{t("lastCheck")} {new Date(health.lastCheckAt).toLocaleTimeString()}
)}
)}
); }