'use client' import HeatMap from '@uiw/react-heat-map' import { Habit } from '@/lib/types' interface HabitHeatmapProps { habits: Habit[] } export default function HabitHeatmap({ habits }: HabitHeatmapProps) { // Aggregate all habit completions into a count per day const completionCounts = habits.reduce((acc: { [key: string]: number }, habit) => { habit.completions.forEach(date => { // Convert date format from ISO (YYYY-MM-DD) to YYYY/MM/DD for the heatmap const formattedDate = date.replace(/-/g, '/') acc[formattedDate] = (acc[formattedDate] || 0) + 1 }) return acc }, {}) // Convert to the format expected by the heatmap const value = Object.entries(completionCounts).map(([date, count]) => ({ date, count })) // Get start date (30 days ago) const startDate = new Date() startDate.setDate(startDate.getDate() - 30) return (