/** * @file Rend le sélecteur de date mensuel du formulaire calendrier. */ import { Icon } from "../../../components/Icon.jsx"; import { addMonths, formatLocalDateKey, getLocalDayIndex, getMonthGridDays, getMonthStart, pad2, parseLocalDateKey } from "./calendarUtils.js"; import { WEEKDAY_LABELS } from "./calendarLayout.js"; function normalizeDraftDateKey(value) { const date = parseLocalDateKey(value); return date ? formatLocalDateKey(date) : ""; } function formatMonthDateLabel(dateKey, mode) { const date = parseLocalDateKey(dateKey); if (!date) return ""; const weekday = WEEKDAY_LABELS[getLocalDayIndex(date)]; const dayLabel = date.toLocaleDateString(undefined, { day: "2-digit", month: "short", year: "numeric" }); if (mode !== "weekday") return dayLabel; const ordinal = Math.floor((date.getDate() - 1) / 7) + 1; return `S${pad2(ordinal)} - ${weekday}`; } function formatMonthTitle(dateLike) { return new Date(dateLike).toLocaleDateString(undefined, { month: "long", year: "numeric" }); } function getWeekdayPickerRows(monthDate) { const monthGridDays = getMonthGridDays(monthDate).filter((day) => day.inMonth); return Array.from({ length: 5 }, (_, rowIndex) => { const ordinal = rowIndex + 1; return { ordinal, days: WEEKDAY_LABELS.map((_, dayIndex) => { const matches = monthGridDays.filter((day) => day.dayIndex === dayIndex); return matches[rowIndex] || null; }) }; }); } export function MonthDateDropdown({ value, displayedMonth, minDate = "", mode, textContent, label, align = "start", onChange, onMonthChange }) { const safeValue = normalizeDraftDateKey(value) || formatLocalDateKey(displayedMonth); return (
); } function MonthDatePicker({ value, displayedMonth, minDate, mode, textContent, onChange, onMonthChange }) { const days = getMonthGridDays(displayedMonth); const weekdayRows = getWeekdayPickerRows(displayedMonth); const minDateKey = normalizeDraftDateKey(minDate); return (
{mode === "weekday" ? ( <> {weekdayRows.flatMap((row) => [ {`S${pad2(row.ordinal)}`}, ...row.days.map((day, dayIndex) => { const dateKey = day ? formatLocalDateKey(day.date) : ""; const disabled = !day || (minDateKey && dateKey < minDateKey); return ( ); }) ])} ) : ( <>
{formatMonthTitle(displayedMonth)}
{WEEKDAY_LABELS.map((day) => {day.slice(0, 3)})} {days.map((day) => { const dateKey = formatLocalDateKey(day.date); const disabled = !day.inMonth || (minDateKey && dateKey < minDateKey); return ( ); })} )}
); }