import { useTranslation } from "react-i18next"; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend, } from "recharts"; import { useUsageTrends } from "@/lib/query/usage"; interface UsageTrendChartProps { days: number; } export function UsageTrendChart({ days }: UsageTrendChartProps) { const { t } = useTranslation(); const { data: trends, isLoading } = useUsageTrends(days); if (isLoading) { return
; } const isToday = days === 1; const chartData = trends?.map((stat) => { const pointDate = new Date(stat.date); return { rawDate: stat.date, label: isToday ? pointDate.toLocaleTimeString("zh-CN", { hour: "2-digit" }) : pointDate.toLocaleDateString("zh-CN", { month: "2-digit", day: "2-digit", }), hour: pointDate.getHours(), inputTokens: stat.totalInputTokens, outputTokens: stat.totalOutputTokens, cacheCreationTokens: stat.totalCacheCreationTokens, cacheReadTokens: stat.totalCacheReadTokens, cost: parseFloat(stat.totalCost), }; }) || []; const hourlyData = (() => { if (!isToday) return chartData; const map = new Map{rangeLabel}