import type { CostTimeSeriesPoint } from "../types"; interface CostSummaryProps { costSeries: CostTimeSeriesPoint[]; } function formatCost(value: number): string { return `$${Math.round(value)}`; } export function CostSummary({ costSeries }: CostSummaryProps) { const totalCost = costSeries.reduce((sum, p) => sum + p.cost, 0); const dayBuckets = new Set(costSeries.map(p => p.timestamp)).size; const avgDaily = dayBuckets > 0 ? totalCost / dayBuckets : 0; // Most expensive model over the visible window const modelTotals = new Map(); for (const point of costSeries) { modelTotals.set(point.model, (modelTotals.get(point.model) ?? 0) + point.cost); } let topModel = ""; let topModelCost = 0; for (const [model, cost] of modelTotals) { if (cost > topModelCost) { topModel = model; topModelCost = cost; } } const cards = [ { label: "Total", value: formatCost(totalCost) }, { label: "Avg / day", value: formatCost(avgDaily) }, { label: "Top model", value: topModel || "—", sub: topModel ? formatCost(topModelCost) : undefined, }, ]; return (
{cards.map(card => (

{card.label}

{card.value}

{card.sub &&

{card.sub}

}
))}
); }