import { useState } from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Svg, { Rect, Text as SvgText } from 'react-native-svg'; import { useTranslation } from 'react-i18next'; import { useColors } from '../../lib/theme'; import type { DailyStat } from '../../hooks/useMailStatus'; type Props = { dailyStats: DailyStat[]; totalBlocked: number; }; const CHART_HEIGHT = 72; const BAR_RADIUS = 4; const LABEL_HEIGHT = 16; const SVG_HEIGHT = CHART_HEIGHT + LABEL_HEIGHT; export function MailWeeklyChart({ dailyStats, totalBlocked }: Props) { const { t } = useTranslation(); const colors = useColors(); const [activeIdx, setActiveIdx] = useState(null); const chartMax = Math.max(...dailyStats.map((d) => d.count), 1); const weekTotal = dailyStats.reduce((s, d) => s + d.count, 0); return ( {/* Header */} {t('mail.chart_title')} {t('mail.chart_week_total', { count: weekTotal })} {/* Tooltip */} {activeIdx !== null && dailyStats[activeIdx] !== undefined && ( {dailyStats[activeIdx].label}: {dailyStats[activeIdx].count} )} {/* SVG Bar Chart */} {dailyStats.map((day, i) => { const barH = day.count > 0 ? Math.max(6, Math.round((day.count / chartMax) * CHART_HEIGHT)) : 4; const x = i * 40 + 4; const barW = 32; const y = CHART_HEIGHT - barH; const isActive = activeIdx === i; const fill = day.count > 0 ? isActive ? '#b91c1c' : '#ef4444' : colors.border; return ( ); })} {dailyStats.map((day, i) => ( {day.label} ))} {/* Invisible tap targets per bar */} {dailyStats.map((day, i) => ( setActiveIdx((prev) => (prev === i ? null : i))} activeOpacity={0.7} accessibilityLabel={`${day.label}: ${day.count}`} /> ))} ); }