'use client'; import React, { useState, useEffect } from 'react'; import { Button } from '@/components/ui/Button'; import { Card } from '@/components/ui/Card'; interface DailyCalendarProps { currentDate: Date; onDateSelect: (date: Date) => void; dailyDates: string[]; // Liste des dates qui ont des dailies (format YYYY-MM-DD) } export function DailyCalendar({ currentDate, onDateSelect, dailyDates }: DailyCalendarProps) { const [viewDate, setViewDate] = useState(new Date(currentDate)); // Formatage des dates pour comparaison (éviter le décalage timezone) const formatDateKey = (date: Date) => { const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); return `${year}-${month}-${day}`; }; const currentDateKey = formatDateKey(currentDate); // Navigation mois const goToPreviousMonth = () => { const newDate = new Date(viewDate); newDate.setMonth(newDate.getMonth() - 1); setViewDate(newDate); }; const goToNextMonth = () => { const newDate = new Date(viewDate); newDate.setMonth(newDate.getMonth() + 1); setViewDate(newDate); }; const goToToday = () => { const today = new Date(); setViewDate(today); onDateSelect(today); }; // Obtenir les jours du mois const getDaysInMonth = () => { const year = viewDate.getFullYear(); const month = viewDate.getMonth(); // Premier jour du mois const firstDay = new Date(year, month, 1); // Dernier jour du mois const lastDay = new Date(year, month + 1, 0); // Premier lundi de la semaine contenant le premier jour const startDate = new Date(firstDay); const dayOfWeek = firstDay.getDay(); const daysToSubtract = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // Lundi = 0 startDate.setDate(firstDay.getDate() - daysToSubtract); // Générer toutes les dates du calendrier (6 semaines) const days = []; const currentDay = new Date(startDate); for (let i = 0; i < 42; i++) { // 6 semaines × 7 jours days.push(new Date(currentDay)); currentDay.setDate(currentDay.getDate() + 1); } return { days, firstDay, lastDay }; }; const { days, firstDay, lastDay } = getDaysInMonth(); const handleDateClick = (date: Date) => { onDateSelect(date); }; const isToday = (date: Date) => { const today = new Date(); return formatDateKey(date) === formatDateKey(today); }; const isCurrentMonth = (date: Date) => { return date.getMonth() === viewDate.getMonth(); }; const hasDaily = (date: Date) => { return dailyDates.includes(formatDateKey(date)); }; const isSelected = (date: Date) => { return formatDateKey(date) === currentDateKey; }; const formatMonthYear = () => { return viewDate.toLocaleDateString('fr-FR', { month: 'long', year: 'numeric' }); }; const weekDays = ['Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam', 'Dim']; return ( {/* Header avec navigation */}

{formatMonthYear()}

{/* Bouton Aujourd'hui */}
{/* Jours de la semaine */}
{weekDays.map((day) => (
{day}
))}
{/* Grille du calendrier */}
{days.map((date, index) => { const dateKey = formatDateKey(date); const isCurrentMonthDay = isCurrentMonth(date); const isTodayDay = isToday(date); const hasCheckboxes = hasDaily(date); const isSelectedDay = isSelected(date); return ( ); })}
{/* Légende */}
Jour avec des tâches
Aujourd'hui
); }