import { useState } from 'react'; import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts'; import { epochDayToDate } from '../../lib/formatters'; import { CHART_THEME } from '../../lib/chart-theme'; import type { DailyRollup } from '../../types/stats'; interface WatchTimeChartProps { rollups: DailyRollup[]; } type Range = 14 | 30 | 90; function formatActiveMinutes(value: number | string, _name?: string, _payload?: unknown) { const minutes = Number(value); return [`${Number.isFinite(minutes) ? minutes : 0} min`, 'Active Time']; } export function WatchTimeChart({ rollups }: WatchTimeChartProps) { const [range, setRange] = useState(14); const byDay = new Map(); for (const r of rollups) { byDay.set(r.rollupDayOrMonth, (byDay.get(r.rollupDayOrMonth) ?? 0) + r.totalActiveMin); } const chartData = Array.from(byDay.entries()) .sort(([dayA], [dayB]) => dayA - dayB) .map(([day, mins]) => ({ date: epochDayToDate(day).toLocaleDateString(undefined, { month: 'short', day: 'numeric' }), minutes: Math.round(mins), })) .slice(-range); const ranges: Range[] = [14, 30, 90]; return (

Watch Time

{ranges.map((r) => ( ))}
); }