"use client"; import { Fragment } from "react"; import { cn } from "@/lib/utils"; import type { ProviderUsage, UtilizationWindow } from "@/lib/types/agent-profile"; import { getBarColor, getTextColor } from "./utilization-bars"; /** "5-hour" → "5h", "7-day (Opus)" → "7d (Opus)". */ export function shortWindowLabel(label: string): string { return label.replace(/(\d+)-hour/i, "$1h").replace(/(\d+)-day/i, "$1d"); } /** Compact time-until-reset: "3h 3m", "5d 12h", "42m", "soon". */ export function formatResetShort(resetAt: string, now = Date.now()): string { const diffMs = new Date(resetAt).getTime() - now; if (!Number.isFinite(diffMs) || diffMs <= 0) return "soon"; const totalHours = Math.floor(diffMs / 3_600_000); const minutes = Math.floor((diffMs % 3_600_000) / 60_000); if (totalHours >= 24) return `${Math.floor(totalHours / 24)}d ${totalHours % 24}h`; if (totalHours > 0) return `${totalHours}h ${minutes}m`; return `${minutes}m`; } export type UsageStatus = { label: "Good" | "High" | "Critical"; className: string; }; /** Worst-window health for a provider, rendered like "Good" / "Critical". */ export function usageStatus(usage: ProviderUsage): UsageStatus { const worst = Math.max(0, ...usage.windows.map((w) => w.utilization_pct)); if (worst >= 90) return { label: "Critical", className: "text-red-600 dark:text-red-400" }; if (worst >= 80) return { label: "High", className: "text-amber-600 dark:text-amber-400" }; return { label: "Good", className: "text-emerald-600 dark:text-emerald-400" }; } function UsageWindowCells({ window: w }: { window: UtilizationWindow }) { const pct = Math.min(100, Math.max(0, w.utilization_pct)); return ( <> {shortWindowLabel(w.label)}