import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Area, AreaChart, CartesianGrid, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts'; import { SALES_STATS } from '../../constants/salesStats'; import { useChartColors } from '../../hooks/useChartColors'; interface DualAreaChartProps { data: { date: string; series1: number; series2: number }[]; title: string; chartId: string; series1Label: string; series2Label: string; series1Color?: string; series2Color?: string; height?: number; } export function DualAreaChart({ data, title, chartId, series1Label, series2Label, series1Color, series2Color, height = SALES_STATS.CHART.HEIGHT, }: DualAreaChartProps) { const { t, i18n } = useTranslation(); const colors = useChartColors(); const color1 = series1Color || colors.referrals; const color2 = series2Color || colors.earnings; const chartData = useMemo( () => data.map((item) => ({ ...item, label: new Date(item.date + 'T00:00:00').toLocaleDateString(i18n.language, { month: 'short', day: 'numeric', }), })), [data, i18n.language], ); if (data.length === 0) { return (

{title}

{t('common.noData')}
); } return (

{title}

{ const displayValue = value ?? 0; if (name === 'series1') return [displayValue, series1Label]; return [displayValue, series2Label]; }} /> { if (value === 'series1') return series1Label; return series2Label; }} />
); }