import { useState } from 'react' import { ArrowLeft, ChevronRight, Calendar } from 'lucide-react' import { useTranslation } from '../../i18n' export function DatePicker({ value, onChange, tripDates }: { value: string onChange: (date: string) => void tripDates?: Set }) { const { t } = useTranslation() const [open, setOpen] = useState(false) const [viewMonth, setViewMonth] = useState(() => { const d = value ? new Date(value + 'T00:00:00') : new Date() return { year: d.getFullYear(), month: d.getMonth() } }) const daysInMonth = new Date(viewMonth.year, viewMonth.month + 1, 0).getDate() // Monday-first, matching CustomDateTimePicker / VacayCalendar (getDay() is Sunday=0). const firstDow = (new Date(viewMonth.year, viewMonth.month, 1).getDay() + 6) % 7 const monthName = new Date(viewMonth.year, viewMonth.month).toLocaleDateString(undefined, { month: 'long', year: 'numeric' }) const prevMonth = () => { setViewMonth(p => p.month === 0 ? { year: p.year - 1, month: 11 } : { ...p, month: p.month - 1 }) } const nextMonth = () => { setViewMonth(p => p.month === 11 ? { year: p.year + 1, month: 0 } : { ...p, month: p.month + 1 }) } const pad = (n: number) => String(n).padStart(2, '0') const cells: (number | null)[] = [] for (let i = 0; i < firstDow; i++) cells.push(null) for (let d = 1; d <= daysInMonth; d++) cells.push(d) const formatted = value ? new Date(value + 'T00:00:00').toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' }) : null return (
{open && ( <>
setOpen(false)} />
{/* Month nav */}
{monthName}
{/* Weekday headers */}
{['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'].map((d, i) => (
{d}
))}
{/* Day grid */}
{cells.map((day, i) => { if (day === null) return
const dateStr = `${viewMonth.year}-${pad(viewMonth.month + 1)}-${pad(day)}` const isSelected = dateStr === value const isTrip = tripDates?.has(dateStr) const isToday = dateStr === new Date().toISOString().split('T')[0] return ( ) })}
)}
) }