'use client'; import { ResponsiveContainer, LineChart, Line, XAxis, YAxis, Tooltip, CartesianGrid } from 'recharts'; import type { Locale } from '@/lib/locale'; interface DailyData { date: string; amount: number; count: number; } interface DailyChartProps { data: DailyData[]; dark?: boolean; locale?: Locale; } function formatDate(dateStr: string) { const [, m, d] = dateStr.split('-'); return `${m}/${d}`; } function formatAmount(value: number) { if (value >= 10000) return `¥${(value / 10000).toFixed(1)}w`; if (value >= 1000) return `¥${(value / 1000).toFixed(1)}k`; return `¥${value}`; } interface TooltipPayload { value: number; dataKey: string; } function CustomTooltip({ active, payload, label, dark, currency, amountLabel, countLabel, }: { active?: boolean; payload?: TooltipPayload[]; label?: string; dark?: boolean; currency: string; amountLabel: string; countLabel: string; }) { if (!active || !payload?.length) return null; return (

{label}

{payload.map((p) => (

{p.dataKey === 'amount' ? amountLabel : countLabel}:{' '} {p.dataKey === 'amount' ? `${currency}${p.value.toLocaleString()}` : p.value}

))}
); } export default function DailyChart({ data, dark, locale = 'zh' }: DailyChartProps) { const currency = locale === 'en' ? '$' : '¥'; const chartTitle = locale === 'en' ? 'Daily Recharge Trend' : '每日充值趋势'; const emptyText = locale === 'en' ? 'No data' : '暂无数据'; const amountLabel = locale === 'en' ? 'Amount' : '金额'; const countLabel = locale === 'en' ? 'Orders' : '笔数'; const tickInterval = data.length > 30 ? Math.ceil(data.length / 12) - 1 : 0; if (data.length === 0) { return (

{chartTitle}

{emptyText}

); } const axisColor = dark ? '#64748b' : '#94a3b8'; const gridColor = dark ? '#334155' : '#e2e8f0'; return (

{chartTitle}

} />
); }