import { useTranslation } from "../../i18n"; import { useCurrency } from "../../hooks/useCurrency"; import { fmtInt, fmtPct, fmtTokens } from "../../lib/dashboard-format"; import { modelColor } from "./DailyBars"; import type { ModelRow } from "../../types/dashboard"; interface ModelTotalsChartProps { /** Provider-agnostic model totals, pre-sorted by totalTokens desc. */ rows: ModelRow[]; } /** Horizontal ranked bars: one row per bare model name, providers merged. */ export function ModelTotalsChart({ rows }: ModelTotalsChartProps) { const { t } = useTranslation(); const { money } = useCurrency(); if (!rows.length) { return (
{t("noData")}
); } const max = Math.max(...rows.map((m) => m.totalTokens || 0), 1); return (
{rows.map((m, i) => { const color = i < 10 ? modelColor(i) : "#6b7280"; const name = m.isSecondary ? t("subagentModel") : m.modelDisplay || m.model; const tooltip = [ name, `${t("kpiRequests")}: ${fmtInt(m.requests)}`, `${t("totalTokens")}: ${fmtInt(m.totalTokens)}`, `${t("colCacheHit")}: ${fmtPct(m.cacheHitRate)}`, `${t("cost")}: ${money(m.costUsd)}`, ].join("\n"); return (
{name} {m.costEstimated && ( ({t("estimate")}) )}
{fmtTokens(m.totalTokens)}
); })}
); }