import { useState } from 'react' import { format, startOfMonth, endOfMonth, eachDayOfInterval, isSameMonth, isSameDay, isToday, addMonths, subMonths } from 'date-fns' import { es } from 'date-fns/locale' import { ChevronLeft, ChevronRight } from 'lucide-react' interface DatePickerProps { selectedDate: Date | null onDateSelect: (date: Date) => void minDate?: Date disabled?: boolean } export default function DatePicker({ selectedDate, onDateSelect, minDate, disabled }: DatePickerProps) { const [currentMonth, setCurrentMonth] = useState(selectedDate ? new Date(selectedDate) : new Date()) const days = eachDayOfInterval({ start: startOfMonth(currentMonth), end: endOfMonth(currentMonth) }) const previousMonth = () => setCurrentMonth(subMonths(currentMonth, 1)) const nextMonth = () => setCurrentMonth(addMonths(currentMonth, 1)) const isDateDisabled = (date: Date) => { if (minDate) { return date < minDate } return false } const isDateSelected = (date: Date) => { return selectedDate && isSameDay(date, selectedDate) } return (

{format(currentMonth, 'MMMM yyyy', { locale: es })}

{['L', 'M', 'X', 'J', 'V', 'S', 'D'].map((day, index) => (
{day}
))}
{days.map((date, index) => { const disabled = isDateDisabled(date) const selected = isDateSelected(date) const today = isToday(date) const notCurrentMonth = !isSameMonth(date, currentMonth) return ( ) })}
) }