'use client' import { useMemo } from 'react' import { cn } from '@/lib/utils' import { useLanguage } from '@/lib/i18n' interface HeatmapDay { date: string count: number } interface RevisionHeatmapProps { data: HeatmapDay[] className?: string } function intensityClass(count: number, max: number): string { if (count <= 0) return 'bg-black/[0.04] dark:bg-white/[0.06]' const ratio = count / Math.max(max, 1) if (ratio >= 0.75) return 'bg-brand-accent' if (ratio >= 0.5) return 'bg-brand-accent/70' if (ratio >= 0.25) return 'bg-brand-accent/40' return 'bg-brand-accent/20' } export function RevisionHeatmap({ data, className }: RevisionHeatmapProps) { const { t } = useLanguage() const { cells, maxCount } = useMemo(() => { const map = new Map(data.map((d) => [d.date, d.count])) const today = new Date() const cells: { date: string; count: number; label: string }[] = [] for (let i = 89; i >= 0; i--) { const d = new Date(today) d.setDate(d.getDate() - i) const key = d.toISOString().slice(0, 10) cells.push({ date: key, count: map.get(key) || 0, label: d.toLocaleDateString(undefined, { day: 'numeric', month: 'short' }), }) } const maxCount = Math.max(1, ...cells.map((c) => c.count)) return { cells, maxCount } }, [data]) return (
{t('flashcards.heatmapTitle')}
{t('flashcards.heatmapLast90')}