"use client" import { useEffect, useState } from "react" import { addDays, addMonths, format, isSameDay, isSameMonth, startOfMonth, startOfWeek, } from "date-fns" import { fr } from "date-fns/locale" import { ChevronLeft, ChevronRight } from "lucide-react" import { WEEK_OPTS } from "@/lib/agenda/agenda-date" import { Button } from "@/components/ui/button" import { cn } from "@/lib/utils" const WEEKDAYS = ["L", "M", "M", "J", "V", "S", "D"] export function AgendaMiniMonth({ selected, onSelect, }: { selected: Date onSelect: (date: Date) => void }) { const [cursor, setCursor] = useState(() => startOfMonth(selected)) useEffect(() => { setCursor(startOfMonth(selected)) }, [selected]) const gridStart = startOfWeek(cursor, WEEK_OPTS) const today = new Date() const cells: Date[] = [] for (let i = 0; i < 42; i++) cells.push(addDays(gridStart, i)) return (
{format(cursor, "MMMM yyyy", { locale: fr }).replace(/^./, (c) => c.toUpperCase(), )}
{WEEKDAYS.map((d, i) => ( {d} ))} {cells.map((day) => { const isToday = isSameDay(day, today) const isSelected = isSameDay(day, selected) const inMonth = isSameMonth(day, cursor) return ( ) })}
) }