{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-picker",
  "type": "registry:ui",
  "title": "DatePicker",
  "description": "A compact calendar with independent month controls, single/range/multiple selection, date/count limits and optional footer content.",
  "dependencies": [
    "@base-ui/react@1.8.0",
    "lucide-react@0.561.0"
  ],
  "registryDependencies": [
    "https://ghost-ui.com/r/ghost-tokens.json",
    "https://ghost-ui.com/r/button.json",
    "https://ghost-ui.com/r/combobox.json",
    "https://ghost-ui.com/r/select.json",
    "https://ghost-ui.com/r/separator.json"
  ],
  "files": [
    {
      "path": "src/components/ui/date-picker.tsx",
      "type": "registry:component",
      "target": "@ui/date-picker.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Check } from \"lucide-react\";\nimport { Button, IconButton } from \"./button\";\nimport { Combobox } from \"./combobox\";\nimport { Select } from \"./select\";\nimport { Separator } from \"./separator\";\nimport \"./date-picker.css\";\n\nexport type DatePickerMode = \"single\" | \"range\" | \"multiple\";\nexport type DatePickerRange = { start: string; end: string | null };\nexport type DatePickerValue = string | DatePickerRange | string[] | null;\nexport type DatePickerDisabledDate = (date: string) => boolean;\nexport type DatePickerPreset = { id: string; label: string; value: { start: string; end: string } };\n\nconst DATE_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nexport type DatePickerFormat = \"locale\" | \"DD/MM/YYYY\" | \"MM/DD/YYYY\" | \"YYYY-MM-DD\" | \"DD/MM/YY\" | \"MM/DD/YY\" | \"YY-MM-DD\";\nexport interface DatePickerFormatOptions { locale?: string; dateFormat?: DatePickerFormat }\nconst MIN_DATE = \"0001-01-01\";\nconst MAX_DATE = \"9999-12-31\";\nconst pad = (value: number) => String(value).padStart(2, \"0\");\n\nfunction makeUtcDate(year: number, month: number, day: number) {\n  const date = new Date(0);\n  date.setUTCHours(0, 0, 0, 0);\n  date.setUTCFullYear(year, month, day);\n  return date;\n}\nfunction dateFromParts(year: number, month: number, day: number) { return `${String(year).padStart(4, \"0\")}-${pad(month)}-${pad(day)}`; }\nfunction daysInMonth(year: number, month: number) { return makeUtcDate(year, month, 0).getUTCDate(); }\n\n/** Date-only helpers use UTC only as a neutral arithmetic calendar. */\nexport function isValidDateOnly(value: string): boolean {\n  const match = DATE_PATTERN.exec(value);\n  if (!match) return false;\n  const [, yearText, monthText, dayText] = match;\n  const year = Number(yearText), month = Number(monthText), day = Number(dayText);\n  if (year < 1 || year > 9999 || month < 1 || month > 12 || day < 1) return false;\n  const date = makeUtcDate(year, month - 1, day);\n  return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;\n}\nexport function resolveDateFormat(options: DatePickerFormatOptions = {}): string {\n  if (options.dateFormat && options.dateFormat !== \"locale\") return options.dateFormat;\n  return new Intl.DateTimeFormat(options.locale ?? \"en-GB\", { year: \"numeric\", month: \"2-digit\", day: \"2-digit\", calendar: \"gregory\", numberingSystem: \"latn\", timeZone: \"UTC\" })\n    .formatToParts(makeUtcDate(2006, 10, 22)).map(part => part.type === \"year\" ? \"YYYY\" : part.type === \"month\" ? \"MM\" : part.type === \"day\" ? \"DD\" : part.value.replace(/[\\u061c\\u200e\\u200f\\u202a-\\u202e\\u2066-\\u2069]/g, \"\")).join(\"\");\n}\nfunction withDateSeparators(value: string, format: string): string {\n  const width=(format.match(/YYYY|YY|MM|DD/g)??[]).reduce((n,token)=>n+token.length,0);\n  if (!new RegExp(`^\\\\d{${width}}$`).test(value)) return value;\n  let offset = 0;\n  return format.replace(/YYYY|YY|MM|DD/g, token => { const part = value.slice(offset, offset + token.length); offset += token.length; return part; });\n}\nexport function parseDisplayDate(value: string, options: DatePickerFormatOptions = {}): string | null {\n  const format = resolveDateFormat(options);\n  const order = format.match(/YYYY|YY|MM|DD/g) ?? [];\n  const escaped = format.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n  const pattern = new RegExp(\"^\" + escaped.replace(/YYYY|YY|MM|DD/g, token => `(\\\\d{${token.length}})`) + \"$\");\n  const match = pattern.exec(withDateSeparators(value.trim().replace(/[\\u061c\\u200e\\u200f]/g, \"\"), format));\n  if (!match) return null;\n  const parts = Object.fromEntries(order.map((token, index) => [token, match[index + 1]]));\n  const iso = `${parts.YYYY ?? `20${parts.YY}`}-${parts.MM}-${parts.DD}`;\n  return isValidDateOnly(iso) ? iso : null;\n}\nexport function formatDisplayDate(value: string | null | undefined, options: DatePickerFormatOptions = {}): string {\n  if (!value || !isValidDateOnly(value)) return \"\";\n  const [year, month, day] = value.split(\"-\");\n  const format = resolveDateFormat(options);\n  if (/(^|[^Y])YY([^Y]|$)/.test(format) && !year.startsWith(\"20\")) return value;\n  return format.replace(/YYYY|YY|MM|DD/g, token => token === \"YYYY\" ? year : token === \"YY\" ? year.slice(2) : token === \"MM\" ? month : day);\n}\nexport function compareDateOnly(a: string, b: string) { return a < b ? -1 : a > b ? 1 : 0; }\nexport function addDateDays(value: string, amount: number): string {\n  if (!isValidDateOnly(value) || !Number.isSafeInteger(amount)) return value;\n  const [year, month, day] = value.split(\"-\").map(Number);\n  const date = makeUtcDate(year, month - 1, day);\n  const minTime = makeUtcDate(1, 0, 1).getTime(), maxTime = makeUtcDate(9999, 11, 31).getTime();\n  const target = date.getTime() + amount * 86400000;\n  if (target <= minTime) return MIN_DATE;\n  if (target >= maxTime) return MAX_DATE;\n  date.setTime(target);\n  const nextYear = date.getUTCFullYear();\n  if (nextYear < 1) return MIN_DATE;\n  if (nextYear > 9999) return MAX_DATE;\n  return dateFromParts(nextYear, date.getUTCMonth() + 1, date.getUTCDate());\n}\nexport function addDateMonths(value: string, amount: number): string {\n  if (!isValidDateOnly(value) || !Number.isSafeInteger(amount)) return value;\n  const [year, month, day] = value.split(\"-\").map(Number);\n  const absoluteMonth = year * 12 + month - 1 + Math.trunc(amount);\n  const nextYear = Math.floor(absoluteMonth / 12);\n  const nextMonth = absoluteMonth - nextYear * 12 + 1;\n  if (nextYear < 1) return dateFromParts(1, 1, 1);\n  if (nextYear > 9999) return dateFromParts(9999, 12, Math.min(day, 31));\n  return dateFromParts(nextYear, nextMonth, Math.min(day, daysInMonth(nextYear, nextMonth)));\n}\nexport function getCalendarDates(month: string): string[] {\n  const first = isValidDateOnly(`${month.slice(0, 7)}-01`) ? `${month.slice(0, 7)}-01` : `${todayDate().slice(0, 7)}-01`;\n  const [year, monthNumber] = first.split(\"-\").map(Number);\n  const mondayOffset = (makeUtcDate(year, monthNumber - 1, 1).getUTCDay() + 6) % 7;\n  return Array.from({ length: 42 }, (_, index) => { const date=makeUtcDate(year,monthNumber-1,1+index-mondayOffset);return dateFromParts(date.getUTCFullYear(),date.getUTCMonth()+1,date.getUTCDate()); });\n}\n\nfunction isRangeValue(value: DatePickerValue): value is DatePickerRange { return typeof value === \"object\" && value !== null && !Array.isArray(value) && \"start\" in value; }\nfunction todayDate(utc = false) { const date = new Date(); return dateFromParts(Math.min(9999, Math.max(1, utc ? date.getUTCFullYear() : date.getFullYear())), (utc ? date.getUTCMonth() : date.getMonth()) + 1, utc ? date.getUTCDate() : date.getDate()); }\nfunction validBound(value: string | undefined) { return value === undefined || isValidDateOnly(value); }\nfunction boundsAreValid(min?: string, max?: string) { return validBound(min) && validBound(max) && (!min || !max || compareDateOnly(min, max) <= 0); }\nfunction inBounds(date: string, min?: string, max?: string, isDateDisabled?: DatePickerDisabledDate) {\n  if (!isValidDateOnly(date) || !boundsAreValid(min, max)) return false;\n  if (min && compareDateOnly(date, min) < 0) return false;\n  if (max && compareDateOnly(date, max) > 0) return false;\n  try { return !isDateDisabled?.(date); } catch { return false; }\n}\nfunction normalizeMonth(value: string | null | undefined) { return value && isValidDateOnly(value) ? `${value.slice(0, 7)}-01` : `${todayDate().slice(0, 7)}-01`; }\nfunction boundedMonth(value: string, min?: string, max?: string) {\n  const month = normalizeMonth(value);\n  if (min && month < normalizeMonth(min)) return normalizeMonth(min);\n  if (max && month > normalizeMonth(max)) return normalizeMonth(max);\n  return month;\n}\nfunction rangeDateCount(start: string, end: string) {\n  const time = (date: string) => makeUtcDate(Number(date.slice(0, 4)), Number(date.slice(5, 7)) - 1, Number(date.slice(8, 10))).getTime();\n  return Math.round((time(end) - time(start)) / 86400000) + 1;\n}\nfunction rangeLabel(start: string, end: string, locale: string, style: \"default\" | \"short\" | \"full\" = \"default\") {\n  const sameMonth = start.slice(0, 7) === end.slice(0, 7);\n  const full = style === \"full\", short = style === \"short\" || (!full && !sameMonth);\n  const formatter = new Intl.DateTimeFormat(locale, { day: \"numeric\", month: full ? \"long\" : \"short\", year: short ? \"2-digit\" : \"numeric\", timeZone: \"UTC\", calendar: \"gregory\", numberingSystem: \"latn\" });\n  const date = (value: string) => makeUtcDate(Number(value.slice(0, 4)), Number(value.slice(5, 7)) - 1, Number(value.slice(8, 10)));\n  const count = rangeDateCount(start, end);\n  return `${formatter.formatRange(date(start), date(end)).replace(/\\s*[–—]\\s*/g, \"–\")} · ${short ? `${count}d` : `${count} ${count === 1 ? \"day\" : \"days\"}`}`;\n}\n/** The preview and every activation share the same inclusive minimum span. */\nfunction rangeCandidate(anchor: string, target: string, minimum: number | undefined, maximum: number | undefined, min?: string, max?: string, unavailable?: DatePickerDisabledDate): { start: string; end: string } | null {\n  if (!inBounds(anchor, min, max, unavailable) || !inBounds(target, min, max, unavailable)) return null;\n  const direction = target < anchor ? -1 : 1;\n  const length = rangeDateCount(target < anchor ? target : anchor, target < anchor ? anchor : target);\n  const endpoint = length < (minimum ?? 1) ? addDateDays(anchor, direction * (Math.max(1, minimum ?? 1) - 1)) : target;\n  const result = endpoint < anchor ? { start: endpoint, end: anchor } : { start: anchor, end: endpoint };\n  const count = rangeDateCount(result.start, result.end);\n  return inBounds(endpoint, min, max, unavailable) && count >= (minimum ?? 0) && (maximum === undefined || count <= maximum) ? result : null;\n}\nfunction validValue(value: DatePickerValue, mode: DatePickerMode) {\n  if (value === null) return true;\n  if (mode === \"single\") return typeof value === \"string\" && isValidDateOnly(value);\n  if (mode === \"multiple\") return Array.isArray(value) && value.every(isValidDateOnly) && new Set(value).size === value.length;\n  if (!isRangeValue(value) || !isValidDateOnly(value.start)) return false;\n  return value.end === null || (isValidDateOnly(value.end) && compareDateOnly(value.start, value.end) <= 0);\n}\n// Search at most one year around the bounded candidate; month navigation exposes later availability.\nfunction findInitialDate(value: DatePickerValue, min?: string, max?: string, isDateDisabled?: DatePickerDisabledDate, referenceDate = todayDate()) {\n  const selected = typeof value === \"string\" ? value : isRangeValue(value) ? value.start : null;\n  let candidate = selected && isValidDateOnly(selected) ? selected : referenceDate;\n  if (min && compareDateOnly(candidate, min) < 0) candidate = min;\n  if (max && compareDateOnly(candidate, max) > 0) candidate = max;\n  if (inBounds(candidate, min, max, isDateDisabled)) return candidate;\n  const lower = min ?? MIN_DATE, upper = max ?? MAX_DATE;\n  const span = Math.max(0, Math.round((makeUtcDate(Number(upper.slice(0, 4)), Number(upper.slice(5, 7)) - 1, Number(upper.slice(8, 10))).getTime() - makeUtcDate(Number(lower.slice(0, 4)), Number(lower.slice(5, 7)) - 1, Number(lower.slice(8, 10))).getTime()) / 86400000));\n  for (let offset = 1; offset <= Math.min(span, 366); offset += 1) {\n    const forward = addDateDays(candidate, offset);\n    if (compareDateOnly(forward, upper) <= 0 && inBounds(forward, min, max, isDateDisabled)) return forward;\n    const backward = addDateDays(candidate, -offset);\n    if (compareDateOnly(backward, lower) >= 0 && inBounds(backward, min, max, isDateDisabled)) return backward;\n  }\n  return candidate;\n}\nfunction findNearestAvailable(date: string, min?: string, max?: string, isDateDisabled?: DatePickerDisabledDate) {\n  if (inBounds(date, min, max, isDateDisabled)) return date;\n  const lower = min ?? MIN_DATE, upper = max ?? MAX_DATE;\n  const span = Math.max(0, Math.round((makeUtcDate(Number(upper.slice(0, 4)), Number(upper.slice(5, 7)) - 1, Number(upper.slice(8, 10))).getTime() - makeUtcDate(Number(lower.slice(0, 4)), Number(lower.slice(5, 7)) - 1, Number(lower.slice(8, 10))).getTime()) / 86400000));\n  for (let offset = 1; offset <= Math.min(span, 366); offset += 1) {\n    const forward = addDateDays(date, offset);\n    if (compareDateOnly(forward, upper) <= 0 && inBounds(forward, min, max, isDateDisabled)) return forward;\n    const backward = addDateDays(date, -offset);\n    if (compareDateOnly(backward, lower) >= 0 && inBounds(backward, min, max, isDateDisabled)) return backward;\n  }\n  return date;\n}\nfunction monthValue(year: number, month: number) { return dateFromParts(Math.min(9999, Math.max(1, year)), Math.min(12, Math.max(1, month)), 1); }\nfunction setMonthPreservingDay(month: string, activeDate: string) { const year = Number(month.slice(0, 4)), monthNumber = Number(month.slice(5, 7)); return dateFromParts(year, monthNumber, Math.min(Number(activeDate.slice(8, 10)), daysInMonth(year, monthNumber))); }\nfunction availableDateInMonth(month: string, preferred: string, min?: string, max?: string, isDateDisabled?: DatePickerDisabledDate) {\n  const first = normalizeMonth(month), year = Number(first.slice(0, 4)), monthNumber = Number(first.slice(5, 7));\n  const last = dateFromParts(year, monthNumber, daysInMonth(year, monthNumber));\n  const lower = min && min > first ? min : first, upper = max && max < last ? max : last;\n  const candidate = setMonthPreservingDay(first, preferred);\n  if (!boundsAreValid(lower, upper)) return candidate;\n  return findNearestAvailable(candidate < lower ? lower : candidate > upper ? upper : candidate, lower, upper, isDateDisabled);\n}\n\nfunction ChevronLeft() { return <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" stroke=\"currentColor\" strokeWidth=\"2\"><path d=\"m14 6-6 6 6 6\" fill=\"none\" /></svg>; }\nfunction ChevronRight() { return <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" stroke=\"currentColor\" strokeWidth=\"2\"><path d=\"m10 6 6 6-6 6\" fill=\"none\" /></svg>; }\nfunction ChevronDown() { return <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" stroke=\"currentColor\" strokeWidth=\"2\"><path d=\"m6 9 6 6 6-6\" fill=\"none\" /></svg>; }\n\nexport interface DatePickerProps {\n  mode?: DatePickerMode; value?: DatePickerValue; defaultValue?: DatePickerValue;\n  onValueChange?: (value: DatePickerValue) => void; onValidityChange?: (valid: boolean) => void;\n  min?: string; max?: string; minSelectedDates?: number; maxSelectedDates?: number; isDateDisabled?: DatePickerDisabledDate;\n  disabled?: boolean; invalid?: boolean; locale?: string; commitMode?: \"immediate\" | \"explicit\";\n  numberOfMonths?: 1 | 2; name?: string; className?: string; label?: React.ReactNode; footer?: React.ReactNode;\n  /** Let the enclosing overlay/card own border and padding. */\n  embedded?: boolean;\n  /** Caller-resolved ISO ranges. Uses the same review and validation as calendar selection. */\n  presets?: readonly DatePickerPreset[];\n  /** Footer selector by default. A two-calendar sidebar falls back to the footer in compact layouts. */\n  presetPlacement?: \"footer\" | \"sidebar\";\n}\n\nexport interface DayOfMonthPickerProps {\n  /** Bare date grid, optionally placed on one subtle surface. */\n  variant?: \"bare\" | \"subtle\";\n  value?: readonly number[];\n  defaultValue?: readonly number[];\n  onValueChange?: (value: number[]) => void;\n  disabled?: boolean;\n  label?: string;\n  className?: string;\n}\n\n/** Selects recurring month-day integers; these are not civil dates. */\nexport function DayOfMonthPicker({ variant = \"bare\", value, defaultValue = [], onValueChange, disabled = false, label = \"Days of the month\", className }: DayOfMonthPickerProps) {\n  const [internal, setInternal] = React.useState<number[]>([...defaultValue]);\n  const selected = [...new Set((value ?? internal).filter(day => Number.isInteger(day) && day >= 1 && day <= 31))].sort((a, b) => a - b);\n  const [active, setActive] = React.useState(1);\n  const refs = React.useRef<Array<HTMLButtonElement | null>>([]);\n  const choose = (day: number) => {\n    const next = [...selected.filter(item => item !== day), ...(selected.includes(day) ? [] : [day])].sort((a, b) => a - b);\n    if (value === undefined) setInternal(next);\n    onValueChange?.(next);\n  };\n  return <div role=\"group\" aria-label={label} data-variant={variant} className={[\"ui-day-of-month-picker\", className].filter(Boolean).join(\" \")} onKeyDown={event => {\n    const offset = event.key === \"ArrowRight\" ? 1 : event.key === \"ArrowLeft\" ? -1 : event.key === \"ArrowDown\" ? 7 : event.key === \"ArrowUp\" ? -7 : 0;\n    if (!offset && event.key !== \"Home\" && event.key !== \"End\") return;\n    event.preventDefault();\n    const next = event.key === \"Home\" ? 1 : event.key === \"End\" ? 31 : Math.max(1, Math.min(31, active + offset));\n    setActive(next);\n    refs.current[next - 1]?.focus();\n  }}>\n    {Array.from({ length: 31 }, (_, index) => index + 1).map(day => <Button key={day} ref={node => { refs.current[day - 1] = node; }} type=\"button\" size=\"sm\" variant={selected.includes(day) ? \"solid\" : \"ghost\"} aria-pressed={selected.includes(day)} aria-label={`Day ${day}`} disabled={disabled} tabIndex={active === day ? 0 : -1} onFocus={() => setActive(day)} onClick={() => choose(day)}>{day}</Button>)}\n  </div>;\n}\n\ntype CalendarProps = {\n  disabled?: boolean; today?: string; id: string; month: string; locale: string; selected: DatePickerValue; mode: DatePickerMode; min?: string; max?: string;\n  isDateDisabled?: DatePickerDisabledDate; activeDate: string; hoverDate: string | null; panelIndex: number; minSelectedDates?: number; maxSelectedDates?: number;\n  dayRefs: React.MutableRefObject<Map<string, HTMLButtonElement>>; onActiveDateChange: (date: string) => void;\n  onHoverDateChange: (date: string | null) => void; onSelect: (date: string) => void; onMonthChange: (month: string) => void;\n  descriptionId?: string;\n}\n\nconst monthItems = (locale: string) => Array.from({ length: 12 }, (_, i) => ({ value: String(i + 1), label: new Intl.DateTimeFormat(locale, { month: \"long\", timeZone: \"UTC\", calendar: \"gregory\", numberingSystem: \"latn\" }).format(makeUtcDate(2024, i, 1)) }));\nfunction MonthYearCombobox({ id, month, locale, disabled, min, max, onMonthChange }: { id: string; month: string; locale: string; disabled: boolean; min?: string; max?: string; onMonthChange: (month: string) => void }) {\n  const [yearQuery, setYearQuery] = React.useState(\"\");\n  const [yearOpen, setYearOpen] = React.useState(false);\n  const yearList = React.useRef<HTMLDivElement>(null);\n  const year = Number(month.slice(0, 4)), monthNumber = Number(month.slice(5, 7));\n  const names = monthItems(locale);\n  const lower = min ? Number(min.slice(0, 4)) : 1, upper = max ? Number(max.slice(0, 4)) : 9999;\n  const first = Math.max(lower, Math.min(year - 30, upper - 60));\n  const yearValues = new Set(Array.from({ length: Math.max(0, Math.min(61, upper - first + 1)) }, (_, i) => first + i));\n  if (/^\\d{1,4}$/.test(yearQuery)) { const candidate = Number(yearQuery); if (candidate >= lower && candidate <= upper) yearValues.add(candidate); }\n  const years = [...yearValues].sort((a, b) => a - b).map(value => ({ value: String(value), label: yearQuery && Number(yearQuery) === value ? yearQuery : String(value) }));\n  const availableMonths = names.filter(item => { const next = monthValue(year, Number(item.value)); return next === boundedMonth(next, min, max); });\n  React.useEffect(() => {\n    if (!yearOpen || yearQuery) return;\n    const frame = requestAnimationFrame(() => {\n      const list = yearList.current, selected = list?.querySelector<HTMLElement>(`[data-year=\"${year}\"]`);\n      if (list && selected) list.scrollTop += selected.getBoundingClientRect().top - list.getBoundingClientRect().top;\n    });\n    return () => cancelAnimationFrame(frame);\n  }, [yearOpen, yearQuery, year]);\n  const labelMonth = names[monthNumber - 1].label;\n  const changeMonth = (next: number) => onMonthChange(monthValue(year, next));\n  const changeYear = (next: number) => onMonthChange(monthValue(next, monthNumber));\n  return <div className=\"ui-date-picker-month-year\" aria-label={`Calendar ${id}`}>\n    <Combobox.Root items={availableMonths} value={String(monthNumber)} onValueChange={value => { if (value) changeMonth(Number(value)); }}>\n      <Combobox.Trigger render={<Button type=\"button\" variant=\"ghost\" size=\"sm\" className=\"ui-date-picker-month-trigger\" disabled={disabled} aria-label={`Choose month, ${labelMonth}`} />}>{labelMonth}<ChevronDown /></Combobox.Trigger>\n      <Combobox.Portal><Combobox.Positioner><Combobox.Popup className=\"ui-date-picker-search-popup ui-date-picker-month-popup\" aria-label=\"Choose month\"><Combobox.InputGroup><Combobox.Input aria-label=\"Search months\" placeholder=\"Search months\" /></Combobox.InputGroup><Combobox.List>{(item: { value: string; label: string }) => <Combobox.Item key={item.value} value={item.value}>{item.label}<Combobox.ItemIndicator><Check aria-hidden=\"true\" /></Combobox.ItemIndicator></Combobox.Item>}</Combobox.List><Combobox.Empty>No months found.</Combobox.Empty></Combobox.Popup></Combobox.Positioner></Combobox.Portal>\n    </Combobox.Root>\n    <Combobox.Root items={years} value={String(year)} open={yearOpen} onOpenChange={open => { setYearOpen(open); setYearQuery(\"\"); }} inputValue={yearQuery} onInputValueChange={setYearQuery} onValueChange={value => { if (value) changeYear(Number(value)); }}>\n      <Combobox.Trigger render={<Button type=\"button\" variant=\"ghost\" size=\"sm\" className=\"ui-date-picker-year-trigger\" disabled={disabled} aria-label={`Choose year, ${year}`} />}>{year}<ChevronDown /></Combobox.Trigger>\n      <Combobox.Portal><Combobox.Positioner><Combobox.Popup className=\"ui-date-picker-search-popup ui-date-picker-year-popup\" aria-label=\"Choose year\"><Combobox.InputGroup><Combobox.Input aria-label=\"Search years\" placeholder=\"Year\" inputMode=\"numeric\" /></Combobox.InputGroup><Combobox.List ref={yearList} className=\"ui-date-picker-year-list\">{(item: { value: string; label: string }) => <Combobox.Item key={item.value} value={item.value} data-year={item.value}>{item.label}<Combobox.ItemIndicator><Check aria-hidden=\"true\" /></Combobox.ItemIndicator></Combobox.Item>}</Combobox.List><Combobox.Empty>No years found.</Combobox.Empty></Combobox.Popup></Combobox.Positioner></Combobox.Portal>\n    </Combobox.Root>\n  </div>;\n}\n\nfunction Calendar({ disabled = false, today, id, month, locale, selected, mode, min, max, minSelectedDates, maxSelectedDates, isDateDisabled, activeDate, hoverDate, panelIndex, dayRefs, onActiveDateChange, onHoverDateChange, onSelect, onMonthChange, descriptionId }: CalendarProps) {\n  const monthNumber = Number(month.slice(5, 7)), year = Number(month.slice(0, 4));\n  const monthLabel = new Intl.DateTimeFormat(locale, { month: \"long\", year: \"numeric\", timeZone: \"UTC\", calendar: \"gregory\", numberingSystem: \"latn\" }).format(makeUtcDate(year, monthNumber - 1, 1));\n  const dates = getCalendarDates(month), selectedStart = typeof selected === \"string\" ? selected : isRangeValue(selected) ? selected.start : null, selectedEnd = isRangeValue(selected) ? selected.end : null;\n  const anchor = isRangeValue(selected) && selected.end === null ? selected.start : null;\n  const previewTarget = hoverDate ?? ((minSelectedDates ?? 0) > 1 ? anchor : null);\n  const preview = mode === \"range\" && anchor && previewTarget ? rangeCandidate(anchor, previewTarget, minSelectedDates, maxSelectedDates, min, max, isDateDisabled) : null;\n  const previewStart = preview?.start ?? null, previewFinish = preview?.end ?? null;\n  const committedStart = isRangeValue(selected) && selected.end ? (compareDateOnly(selected.start, selected.end) <= 0 ? selected.start : selected.end) : null;\n  const committedEnd = isRangeValue(selected) && selected.end ? (compareDateOnly(selected.start, selected.end) <= 0 ? selected.end : selected.start) : null;\n  const headingId = `${id}-month-${panelIndex}-${month.slice(0, 7).replace(\"-\", \"\")}`;\n  const mondayIndex = (date: string) => (makeUtcDate(Number(date.slice(0, 4)), Number(date.slice(5, 7)) - 1, Number(date.slice(8, 10))).getUTCDay() + 6) % 7;\n  function keyDown(event: React.KeyboardEvent<HTMLButtonElement>, date: string) {\n    let next: string | null = null;\n    if (event.key === \"ArrowLeft\") next = addDateDays(date, -1); if (event.key === \"ArrowRight\") next = addDateDays(date, 1);\n    if (event.key === \"ArrowUp\") next = addDateDays(date, -7); if (event.key === \"ArrowDown\") next = addDateDays(date, 7);\n    if (event.key === \"Home\") next = addDateDays(date, -mondayIndex(date)); if (event.key === \"End\") next = addDateDays(date, 6 - mondayIndex(date));\n    if (event.key === \"PageUp\") next = addDateMonths(date, event.shiftKey ? -12 : -1); if (event.key === \"PageDown\") next = addDateMonths(date, event.shiftKey ? 12 : 1);\n    if (next && next !== date) { event.preventDefault(); onActiveDateChange(next); return; }\n    if (event.key === \"Enter\" || event.key === \" \") { event.preventDefault(); if (inBounds(date, min, max, isDateDisabled)) onSelect(date); }\n  }\n  const changeMonth = (delta: number) => onMonthChange(addDateMonths(month, delta));\n  return <section className=\"ui-date-picker-calendar\" aria-labelledby={headingId} data-panel={panelIndex}>\n    <div className=\"ui-date-picker-calendar-header\"><div className=\"ui-date-picker-panel-toolbar\"><MonthYearCombobox id={headingId} month={month} locale={locale} disabled={disabled} min={min} max={max} onMonthChange={onMonthChange} /><h3 id={headingId} className=\"ui-date-picker-calendar-title\">{monthLabel}</h3></div><div className=\"ui-date-picker-nav\"><IconButton type=\"button\" variant=\"ghost\" size=\"icon-sm\" icon={<ChevronLeft />} disabled={disabled || month === \"0001-01-01\" || boundedMonth(addDateMonths(month, -1), min, max) === month} aria-label={`Previous month (${monthLabel})`} onClick={() => changeMonth(-1)} /><IconButton type=\"button\" variant=\"ghost\" size=\"icon-sm\" icon={<ChevronRight />} disabled={disabled || month === \"9999-12-01\" || boundedMonth(addDateMonths(month, 1), min, max) === month} aria-label={`Next month (${monthLabel})`} onClick={() => changeMonth(1)} /></div></div>\n    <div className=\"ui-date-picker-weekdays\" role=\"row\" aria-hidden=\"true\">{[\"M\", \"T\", \"W\", \"T\", \"F\", \"S\", \"S\"].map((day, index) => <span key={`${day}-${index}`}>{day}</span>)}</div>\n    <div className=\"ui-date-picker-grid\" role=\"grid\" aria-labelledby={headingId}>{Array.from({ length: 6 }, (_, week) => <div role=\"row\" className=\"ui-date-picker-week\" key={week}>{dates.slice(week * 7, week * 7 + 7).map((date, columnIndex) => {\n      const index = week * 7 + columnIndex, inMonth = date.slice(0, 7) === month.slice(0, 7), selectable = inBounds(date, min, max, isDateDisabled), dateDisabled = disabled || !selectable || (!inMonth && !isValidDateOnly(date));\n      const selectedDates = Array.isArray(selected) ? selected : [];\n      const isStart = inMonth && date === committedStart, isEnd = inMonth && date === committedEnd;\n      const isSelected = inMonth && (mode === \"multiple\" ? selectedDates.includes(date) : mode === \"range\" ? (date === (isRangeValue(selected) ? selected.start : null) || date === selectedEnd) : date === selectedStart);\n      const isPreview = inMonth && Boolean(previewStart && previewFinish && compareDateOnly(date, previewStart) >= 0 && compareDateOnly(date, previewFinish) <= 0);\n      const isCommittedRange = inMonth && Boolean(committedStart && committedEnd && compareDateOnly(date, committedStart) >= 0 && compareDateOnly(date, committedEnd) <= 0);\n      const isActive = inMonth && date === activeDate;\n      const dayLabel = isValidDateOnly(date) ? new Intl.DateTimeFormat(locale, { dateStyle: \"full\", timeZone: \"UTC\", calendar: \"gregory\", numberingSystem: \"latn\" }).format(makeUtcDate(Number(date.slice(0, 4)), Number(date.slice(5, 7)) - 1, Number(date.slice(8, 10)))) : date;\n      const atLimit = mode === \"multiple\" && maxSelectedDates !== undefined && selectedDates.length >= maxSelectedDates && !selectedDates.includes(date);\n      const unavailableEnd = mode === \"range\" && anchor !== null && rangeCandidate(anchor, date, minSelectedDates, maxSelectedDates, min, max, isDateDisabled) === null;\n      const cellClasses = [\"ui-date-picker-cell\", !inMonth ? \"is-outside\" : \"\", isCommittedRange ? \"is-in-range\" : \"\", isPreview ? \"is-hover-range\" : \"\", date === previewStart ? \"is-hover-start\" : \"\", date === previewFinish ? \"is-hover-end\" : \"\", isPreview && columnIndex === 0 && date !== previewStart ? \"is-hover-row-start\" : \"\", isPreview && columnIndex === 6 && date !== previewFinish ? \"is-hover-row-end\" : \"\", isCommittedRange && columnIndex === 0 && date !== committedStart ? \"is-range-row-start\" : \"\", isCommittedRange && columnIndex === 6 && date !== committedEnd ? \"is-range-row-end\" : \"\", isStart ? \"is-range-start\" : \"\", isEnd ? \"is-range-end\" : \"\"].filter(Boolean).join(\" \");\n      return <div className={cellClasses} data-preview-start={date === previewStart ? \"true\" : undefined} data-preview-end={date === previewFinish ? \"true\" : undefined} role=\"gridcell\" aria-selected={isSelected} key={`${panelIndex}-${date}-${index}`}>\n        <button type=\"button\" className=\"ui-date-picker-day\" data-date={date} data-active={isActive ? \"true\" : undefined} data-selected={isSelected ? \"true\" : undefined} data-today={date === today ? \"true\" : undefined} aria-label={dayLabel} aria-describedby={anchor && (minSelectedDates ?? 0) > 1 ? descriptionId : undefined} aria-pressed={isSelected} aria-disabled={dateDisabled || atLimit || unavailableEnd} disabled={dateDisabled} tabIndex={isActive && !dateDisabled ? 0 : -1} ref={element => { const key = `${panelIndex}:${date}`; if (element && isActive) dayRefs.current.set(key, element); else if (!element) dayRefs.current.delete(key); }} onClick={() => { onActiveDateChange(date); if (!dateDisabled) onSelect(date); }} onFocus={() => { if (selectable) onHoverDateChange(date); }} onPointerEnter={event => { if (event.pointerType === \"mouse\" && selectable) onHoverDateChange(date); }} onPointerLeave={event => { if (event.pointerType === \"mouse\") onHoverDateChange(null); }} onKeyDown={event => keyDown(event, date)}>{isValidDateOnly(date) ? Number(date.slice(8, 10)) : \"\"}</button>\n      </div>;\n    })}</div>)}</div>\n    {!dates.some(date => date.slice(0, 7) === month.slice(0, 7) && inBounds(date, min, max, isDateDisabled)) && <p className=\"ui-date-picker-availability\" role=\"status\">No available dates this month.</p>}\n  </section>;\n}\n\nexport const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(function DatePicker({ mode = \"single\", value, defaultValue = mode === \"multiple\" ? [] : null, onValueChange, onValidityChange, min, max, minSelectedDates, maxSelectedDates, isDateDisabled, disabled = false, invalid = false, locale = \"en-GB\", commitMode, numberOfMonths, name, className, label, footer, embedded = false, presets, presetPlacement = \"footer\" }, ref) {\n  const id = React.useId(), isControlled = value !== undefined;\n  const [internalValue, setInternalValue] = React.useState<DatePickerValue>(defaultValue);\n  const selected = isControlled ? value ?? null : internalValue;\n  const selectedValid = validValue(selected, mode);\n  const effectiveCommitMode = commitMode ?? (mode === \"range\" || mode === \"multiple\" ? \"explicit\" : \"immediate\");\n  const monthCount = numberOfMonths ?? (mode === \"range\" ? 2 : 1);\n  const [clockReady, setClockReady] = React.useState(false);\n  // Hydration starts from one UTC seed, then resolves the browser-local date.\n  const initial = findInitialDate(selectedValid ? selected : null, min, max, isDateDisabled, todayDate(true));\n  const [activeDates, setActiveDates] = React.useState(() => [initial, availableDateInMonth(addDateMonths(normalizeMonth(initial), 1), initial, min, max, isDateDisabled)]);\n  const [months, setMonths] = React.useState(() => [normalizeMonth(initial), boundedMonth(addDateMonths(normalizeMonth(initial), 1), min, max)]);\n  const monthsRef = React.useRef(months);\n  monthsRef.current = months;\n  const [hoverDate, setHoverDate] = React.useState<string | null>(null);\n  const [presetChoice, setPresetChoice] = React.useState<string | null>(null);\n  const [presetOpen, setPresetOpen] = React.useState(false);\n  const customFocus = React.useRef(false);\n  const [draft, setDraft] = React.useState<DatePickerValue>(selected);\n  const dayRefs = React.useRef<Map<string, HTMLButtonElement>>(new Map());\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  React.useImperativeHandle(ref, () => rootRef.current as HTMLDivElement);\n  const boundsInvalid = !boundsAreValid(min, max);\n  const countConfigInvalid = (minSelectedDates !== undefined && (!Number.isSafeInteger(minSelectedDates) || minSelectedDates < 0)) || (maxSelectedDates !== undefined && (!Number.isSafeInteger(maxSelectedDates) || maxSelectedDates < 0)) || (minSelectedDates !== undefined && maxSelectedDates !== undefined && minSelectedDates > maxSelectedDates) || (mode === \"single\" && (minSelectedDates !== undefined || maxSelectedDates !== undefined));\n  const countOf = (v: DatePickerValue) => typeof v === \"string\" ? 1 : isRangeValue(v) ? (v.end ? rangeDateCount(v.start, v.end) : 0) : Array.isArray(v) ? v.length : 0;\n  const datesAreAvailable = (v: DatePickerValue) => {\n    if (!validValue(v, mode)) return false;\n    const dates = typeof v === \"string\" ? [v] : isRangeValue(v) ? [v.start, ...(v.end ? [v.end] : [])] : Array.isArray(v) ? v : [];\n    return dates.every(date => inBounds(date, min, max, isDateDisabled));\n  };\n  const privateMinimum = mode !== \"single\" && (minSelectedDates ?? 0) > 0;\n  const current = effectiveCommitMode === \"explicit\" || privateMinimum ? draft : selected;\n  const currentCount = countOf(current), selectedCount = countOf(selected);\n  const countValid = countConfigInvalid ? false : (minSelectedDates === undefined || currentCount >= minSelectedDates) && (maxSelectedDates === undefined || currentCount <= maxSelectedDates);\n  const selectedCountValid = countConfigInvalid ? false : (minSelectedDates === undefined || selectedCount >= minSelectedDates) && (maxSelectedDates === undefined || selectedCount <= maxSelectedDates);\n  const valueValid = datesAreAvailable(current);\n  const validity = !invalid && !boundsInvalid && !countConfigInvalid && selectedValid && valueValid && countValid;\n  const hasError = invalid || boundsInvalid || countConfigInvalid || !selectedValid || !datesAreAvailable(selected);\n  React.useEffect(() => {\n    setClockReady(true);\n    setDraft(selected);\n    const next = findInitialDate(selectedValid ? selected : null, min, max, isDateDisabled);\n    const month = normalizeMonth(next);\n    const existingPanel = monthsRef.current.slice(0, monthCount === 2 ? 2 : 1).findIndex(item => item === month);\n    const panel = existingPanel < 0 ? 0 : existingPanel;\n    setActiveDates(dates => dates.map((date, index) => index === panel ? next : availableDateInMonth(monthsRef.current[index], date, min, max, isDateDisabled)));\n    setMonths(items => items.map((item, index) => boundedMonth(existingPanel < 0 && index === 0 ? month : item, min, max)));\n  }, [selected, selectedValid, mode, min, max, isDateDisabled, locale, monthCount]);\n  React.useEffect(() => { onValidityChange?.(validity); }, [validity, onValidityChange]);\n\n  const emit = (next: DatePickerValue, allowUnderMinimum = false) => {\n    if (disabled || !validValue(next, mode) || !datesAreAvailable(next) || boundsInvalid || countConfigInvalid) return;\n    const count = countOf(next);\n    if (maxSelectedDates !== undefined && count > maxSelectedDates) return;\n    if (!allowUnderMinimum && minSelectedDates !== undefined && count < minSelectedDates) return;\n    if (!isControlled) setInternalValue(next);\n    onValueChange?.(next);\n  };\n  const focusDate = (date: string, panel: number) => {\n    if (disabled) return;\n    const next = isValidDateOnly(date) ? findNearestAvailable(date, min, max, isDateDisabled) : activeDates[panel];\n    setActiveDates(dates => dates.map((date, index) => index === panel ? next : date));\n    setMonths(currentMonths => currentMonths.map((month, index) => index === panel ? normalizeMonth(next) : month));\n    requestAnimationFrame(() => dayRefs.current.get(`${panel}:${next}`)?.focus());\n  };\n  const selectDate = (date: string) => {\n    if (disabled || invalid || boundsInvalid || countConfigInvalid || !inBounds(date, min, max, isDateDisabled)) return;\n    if (mode === \"single\") { if (effectiveCommitMode === \"explicit\") setDraft(date); else emit(date); return; }\n    if (mode === \"multiple\") {\n      const dates = Array.isArray(current) ? current : [];\n      const next = dates.includes(date) ? dates.filter(item => item !== date).sort() : [...dates, date].sort();\n      if (maxSelectedDates !== undefined && next.length > maxSelectedDates) return;\n      setDraft(next);\n      if (effectiveCommitMode === \"immediate\") emit(next);\n      return;\n    }\n    const range = isRangeValue(current) ? current : null;\n    const next = range && !range.end ? rangeCandidate(range.start, date, minSelectedDates, maxSelectedDates, min, max, isDateDisabled) : { start: date, end: null };\n    if (!next) return;\n    setDraft(next);\n    if (effectiveCommitMode === \"immediate\") emit(next, !next.end && !privateMinimum);\n  };\n  const changePanelMonth = (index: number, next: string) => {\n    if (disabled) return;\n    const month = boundedMonth(next, min, max);\n    setMonths(items => items.map((item, panel) => panel === index ? month : item));\n    setActiveDates(dates => dates.map((date, panel) => panel === index ? availableDateInMonth(month, date, min, max, isDateDisabled) : date));\n  };\n  const draftComplete = mode === \"single\" ? typeof draft === \"string\" : mode === \"range\" ? isRangeValue(draft) && draft.end !== null : Array.isArray(draft);\n  const canApply = !disabled && !invalid && !boundsInvalid && !countConfigInvalid && selectedValid && draftComplete && validValue(draft, mode) && datesAreAvailable(draft) && (minSelectedDates === undefined || countOf(draft) >= minSelectedDates) && (maxSelectedDates === undefined || countOf(draft) <= maxSelectedDates);\n  const cancel = () => setDraft(selected);\n  const apply = () => { if (canApply) emit(draft); };\n  const currentStart = typeof current === \"string\" ? current : isRangeValue(current) ? current.start : null;\n  const currentEnd = isRangeValue(current) ? current.end : null;\n  const rangeDays = currentStart && currentEnd ? countOf(current) : null;\n  const formValid = selectedValid && datesAreAvailable(selected) && !boundsInvalid && !countConfigInvalid && selectedCountValid && (!isRangeValue(selected) || selected.end !== null);\n  const visibleCount = mode === \"range\" && numberOfMonths === undefined ? 2 : monthCount;\n  const panelMonths = visibleCount === 2 ? [months[0], months[1] || addDateMonths(months[0], 1)] : [months[0]];\n  const hasPresets = mode === \"range\" && Boolean(presets?.length);\n  const presetItems = (presets ?? []).map(item => {\n    const range = item.value, count = range && isValidDateOnly(range.start) && isValidDateOnly(range.end) ? rangeDateCount(range.start, range.end) : 0;\n    const reason = !range || !validValue(range, \"range\") || !range.end || !item.id || !item.label || presets!.filter(other => other.id === item.id).length !== 1 ? \"Invalid preset\" : !datesAreAvailable(range) ? \"Outside allowed dates\" : (minSelectedDates !== undefined && count < minSelectedDates) || (maxSelectedDates !== undefined && count > maxSelectedDates) ? \"Outside the selected-day limits\" : \"\";\n    return { ...item, range, value: item.id, reason };\n  });\n  const matchingPresets = presetItems.filter(item => !item.reason && isRangeValue(current) && current.start === item.range.start && current.end === item.range.end);\n  const matchingPreset = matchingPresets.find(item => item.id === presetChoice) ?? matchingPresets[0];\n  let customRangeId = `${id}-custom-range`;\n  while (presetItems.some(item => item.id === customRangeId)) customRangeId += \"-\";\n  const customRangeItem = { id: customRangeId, value: customRangeId, label: \"Custom range\", reason: \"\" };\n  const presetGroups = [{ value: \"presets\", items: presetItems }, { value: \"custom\", items: [customRangeItem] }];\n  const choosePreset = (presetId: string | null) => {\n    if (presetId === customRangeId) { customFocus.current = true; setPresetOpen(false); return; }\n    const item = presetItems.find(item => item.id === presetId);\n    if (!item || item.reason || disabled || invalid || boundsInvalid || countConfigInvalid) return;\n    setDraft(item.range);\n    setPresetChoice(item.id);\n    setHoverDate(null);\n    const startMonth = normalizeMonth(item.range.start), endMonth = normalizeMonth(item.range.end);\n    const second = endMonth === startMonth ? boundedMonth(addDateMonths(startMonth, 1), min, max) : endMonth;\n    setMonths([startMonth, second]);\n    setActiveDates([item.range.start, availableDateInMonth(second, item.range.end, min, max, isDateDisabled)]);\n    if (effectiveCommitMode === \"immediate\") emit(item.range);\n  };\n  const pendingRange = mode === \"range\" && isRangeValue(current) && !current.end;\n  const candidate = pendingRange ? rangeCandidate(current.start, hoverDate ?? current.start, minSelectedDates, maxSelectedDates, min, max, isDateDisabled) : null;\n  const rangeSummary = rangeDays ? `${formatDisplayDate(currentStart, { locale })} – ${formatDisplayDate(currentEnd, { locale })} · ${rangeDays} days` : pendingRange && (minSelectedDates ?? 0) > 1 ? candidate ? `${formatDisplayDate(candidate.start, { locale })} – ${formatDisplayDate(candidate.end, { locale })} · ${minSelectedDates}-day minimum` : `A ${minSelectedDates}-day minimum is unavailable in this direction.` : \"Select an end date\";\n  const selectionUnavailable = disabled || invalid || boundsInvalid || countConfigInvalid;\n  const sidebar = hasPresets && presetPlacement === \"sidebar\" && visibleCount === 2;\n  const completeRange = isRangeValue(current) && current.end && validValue(current, \"range\") ? current : null;\n  const presetLabel = completeRange ? rangeLabel(completeRange.start, completeRange.end!, locale) : pendingRange ? \"Select an end date\" : \"Select range\";\n  const shortPresetLabel = completeRange ? rangeLabel(completeRange.start, completeRange.end!, locale, \"short\") : presetLabel;\n  const accessibleRange = completeRange ? rangeLabel(completeRange.start, completeRange.end!, locale, \"full\") : pendingRange ? rangeSummary : \"Select range\";\n  const rangeFeedback = pendingRange && (minSelectedDates ?? 0) > 1 ? rangeSummary : rangeDays && !countValid ? currentCount < (minSelectedDates ?? 0) ? `Select at least ${minSelectedDates} days.` : `Select no more than ${maxSelectedDates} days.` : null;\n  const hasCountLimits = minSelectedDates !== undefined || maxSelectedDates !== undefined;\n  const countGuidance = [minSelectedDates !== undefined ? `Minimum ${minSelectedDates} ${mode === \"range\" ? \"days\" : \"dates\"}` : null, maxSelectedDates !== undefined ? `Maximum ${maxSelectedDates} ${mode === \"range\" ? \"days\" : \"dates\"}` : null, mode === \"multiple\" && currentCount < (minSelectedDates ?? 0) ? `Select ${(minSelectedDates ?? 0) - currentCount} more ${(minSelectedDates ?? 0) - currentCount === 1 ? \"date\" : \"dates\"}` : null].filter(Boolean).join(\" · \");\n  const presetTrigger = <Button type=\"button\" variant=\"ghost\" size=\"sm\" className=\"ui-date-picker-preset-trigger\" disabled={selectionUnavailable} aria-label={`Preset range, ${accessibleRange}`} />;\n  const presetTriggerContent = <><span className=\"ui-date-picker-preset-label\">{presetLabel}</span><span className=\"ui-date-picker-preset-label-short\" aria-hidden=\"true\">{shortPresetLabel}</span><ChevronDown /></>;\n  const presetPopupProps = { className: \"ui-date-picker-preset-popup\", \"aria-label\": \"Preset ranges\", onKeyDown: (event: React.KeyboardEvent) => { if (event.key === \"Escape\") event.stopPropagation(); }, finalFocus: () => { if (!customFocus.current) return true; customFocus.current = false; return dayRefs.current.get(`0:${activeDates[0]}`) ?? true; } };\n  return <div ref={rootRef} className={[\"ui-date-picker\", className].filter(Boolean).join(\" \")} data-embedded={embedded?\"true\":undefined} data-mode={mode} data-display=\"inline\" data-month-count={visibleCount} data-presets={hasPresets ? \"true\" : undefined} data-preset-placement={hasPresets ? sidebar ? \"sidebar\" : \"footer\" : undefined} data-invalid={validity ? undefined : \"true\"} onKeyDown={event => { if (event.key === \"Escape\" && (effectiveCommitMode === \"explicit\" || privateMinimum) && !event.defaultPrevented) { event.preventDefault(); event.stopPropagation(); cancel(); } }}>\n    <div className=\"ui-date-picker-inline\" role=\"region\" aria-label={typeof label === \"string\" ? label : mode === \"range\" ? \"Choose date range\" : mode === \"multiple\" ? \"Choose dates\" : \"Choose date\"}>\n      {sidebar && <div className=\"ui-date-picker-presets\" role=\"group\" aria-label=\"Preset ranges\">{presetItems.map((item, index) => <Button key={`${item.id}-${index}`} type=\"button\" variant=\"ghost\" size=\"sm\" className=\"ui-date-picker-preset\" disabled={selectionUnavailable || Boolean(item.reason)} aria-pressed={matchingPreset?.id === item.id} aria-label={item.reason ? `${item.label}: ${item.reason}` : item.label} onClick={() => choosePreset(item.id)}>{item.label}<span className=\"ui-date-picker-preset-indicator\">{matchingPreset?.id === item.id && <Check aria-hidden=\"true\" />}</span></Button>)}</div>}\n      <div className=\"ui-date-picker-content\" data-mode={mode}>\n        <div className=\"ui-date-picker-panels\" data-base-ui-swipe-ignore=\"\" data-month-count={visibleCount}>{panelMonths.map((month, index) => <Calendar key={index} today={clockReady ? todayDate() : undefined} disabled={selectionUnavailable} id={id} month={month} locale={locale} selected={current} mode={mode} min={min} max={max} minSelectedDates={minSelectedDates} maxSelectedDates={maxSelectedDates} isDateDisabled={isDateDisabled} activeDate={activeDates[index]} hoverDate={hoverDate} panelIndex={index} dayRefs={dayRefs} onActiveDateChange={date => focusDate(date, index)} onHoverDateChange={setHoverDate} onSelect={selectDate} onMonthChange={next => changePanelMonth(index, next)} descriptionId={`${id}-summary`} />)}</div>\n        {footer != null && <div className=\"ui-date-picker-custom-footer\">{footer}</div>}\n        {hasCountLimits && !countConfigInvalid && !hasPresets && <p className=\"ui-date-picker-availability ui-date-picker-count-guidance\">{countGuidance}</p>}\n        {(effectiveCommitMode === \"explicit\" || hasPresets) && <div className=\"ui-date-picker-footer\">\n          {hasPresets && <>\n            <div className=\"ui-date-picker-preset-selector\">{presetItems.length > 8 ? <Combobox.Root items={presetGroups} value={matchingPreset?.id ?? null} onValueChange={choosePreset} open={presetOpen} onOpenChange={setPresetOpen}>\n              <Combobox.Trigger render={presetTrigger}>{presetTriggerContent}</Combobox.Trigger>\n              <Combobox.Portal><Combobox.Positioner side=\"bottom\" align=\"start\"><Combobox.Popup {...presetPopupProps}>\n                <Combobox.InputGroup><Combobox.Input aria-label=\"Search ranges\" placeholder=\"Search ranges\" /></Combobox.InputGroup>\n                <Combobox.List>{(group: typeof presetGroups[number], index: number) => <Combobox.Group key={group.value} items={group.items}>\n                  {index > 0 && <Combobox.Separator render={<Separator />} />}\n                  <Combobox.Collection>{(item: typeof customRangeItem) => <Combobox.Item key={item.id} value={item.id} disabled={Boolean(item.reason)} aria-label={item.reason ? `${item.label}: ${item.reason}` : item.label}>{item.label}<Combobox.ItemIndicator><Check aria-hidden=\"true\" /></Combobox.ItemIndicator></Combobox.Item>}</Combobox.Collection>\n                </Combobox.Group>}</Combobox.List>\n                <Combobox.Empty>No ranges found.</Combobox.Empty>\n              </Combobox.Popup></Combobox.Positioner></Combobox.Portal>\n            </Combobox.Root> : <Select.Root items={[...presetItems, customRangeItem]} value={matchingPreset?.id ?? null} onValueChange={choosePreset} open={presetOpen} onOpenChange={setPresetOpen} disabled={selectionUnavailable}>\n              <Select.Trigger variant=\"ghost\" compact render={presetTrigger}>{presetTriggerContent}</Select.Trigger>\n              <Select.Portal><Select.Positioner side=\"bottom\" align=\"start\"><Select.Popup {...presetPopupProps}>\n                <Select.List>{presetItems.map(item => <Select.Item key={item.id} value={item.id} disabled={Boolean(item.reason)} aria-label={item.reason ? `${item.label}: ${item.reason}` : item.label}><Select.ItemText>{item.label}</Select.ItemText><Select.ItemIndicator><Check aria-hidden=\"true\" /></Select.ItemIndicator></Select.Item>)}\n                  <Select.Separator render={<Separator />} />\n                  <Select.Item value={customRangeId}><Select.ItemText>Custom range</Select.ItemText></Select.Item>\n                </Select.List>\n              </Select.Popup></Select.Positioner></Select.Portal>\n            </Select.Root>}</div>\n            {sidebar && <span className=\"ui-date-picker-range-summary ui-date-picker-preset-summary\" aria-hidden=\"true\">{presetLabel}</span>}\n          </>}\n          {mode === \"range\" && !hasPresets && <span className=\"ui-date-picker-range-summary\" aria-hidden=\"true\"><span className=\"ui-date-picker-preset-label\">{presetLabel}</span><span className=\"ui-date-picker-preset-label-short\">{shortPresetLabel}</span></span>}\n          {mode === \"multiple\" && hasCountLimits && <span className=\"ui-date-picker-range-summary\" aria-hidden=\"true\">{currentCount} selected</span>}\n          {effectiveCommitMode === \"explicit\" && <div className=\"ui-date-picker-commit-actions\"><Button type=\"button\" variant=\"ghost\" size=\"sm\" disabled={disabled} onClick={cancel}>Cancel</Button><Button type=\"button\" variant=\"solid\" size=\"sm\" disabled={!canApply} onClick={apply}>Apply</Button></div>}\n        </div>}\n        {!hasPresets && effectiveCommitMode === \"explicit\" && (mode === \"range\" || (mode === \"multiple\" && hasCountLimits)) && <span className=\"ui-date-picker-selection-status\" role=\"status\" id={`${id}-summary`}>{mode === \"range\" ? accessibleRange : `${currentCount} selected. ${countGuidance}`}</span>}\n        {hasPresets && <><span className=\"ui-date-picker-selection-status\" role=\"status\" id={`${id}-summary`}>{accessibleRange}</span>{rangeFeedback && <p className=\"ui-date-picker-availability\">{rangeFeedback}</p>}</>}\n        {effectiveCommitMode === \"immediate\" && privateMinimum && !countValid && (!hasPresets || draft !== selected) && <div className=\"ui-date-picker-private-review\">{!hasPresets && <p className=\"ui-date-picker-availability\" role=\"status\" id={`${id}-summary`}>{mode === \"multiple\" ? `Select ${Math.max(0, (minSelectedDates ?? 0) - currentCount)} more dates.` : rangeSummary}</p>}{draft !== selected && <Button type=\"button\" variant=\"ghost\" size=\"sm\" onClick={cancel}>Cancel</Button>}</div>}\n      </div>\n    </div>\n    {hasError && <p className=\"ui-error ui-error--caption\" role=\"alert\">{boundsInvalid ? \"The date range is not available.\" : countConfigInvalid ? \"The date selection requirements are not available.\" : \"Choose a valid date within the available range.\"}</p>}\n    {name && (mode === \"range\" ? <><input type=\"hidden\" name={`${name}-start`} value={formValid && isRangeValue(selected) ? selected.start : \"\"} disabled={disabled || !formValid || !isRangeValue(selected)} /><input type=\"hidden\" name={`${name}-end`} value={formValid && isRangeValue(selected) ? selected.end ?? \"\" : \"\"} disabled={disabled || !formValid || !isRangeValue(selected) || !selected.end} /></> : mode === \"multiple\" ? (formValid && Array.isArray(selected) ? selected : []).map(date => <input key={date} type=\"hidden\" name={name} value={date} disabled={disabled} />) : <input type=\"hidden\" name={name} value={formValid && typeof selected === \"string\" ? selected : \"\"} disabled={disabled || !formValid || typeof selected !== \"string\"} />)}\n  </div>;\n});\n\nDatePicker.displayName = \"DatePicker\";\n"
    },
    {
      "path": "src/components/ui/date-picker.css",
      "type": "registry:file",
      "target": "@ui/date-picker.css",
      "content": ".ui-date-picker { display:flex; width:286px; max-width:100%; min-width:0; flex-direction:column; gap:var(--space-2); color:var(--foreground); font-family:var(--font-sans); container:date-picker / inline-size; }\n.ui-date-picker[data-month-count=\"2\"] { width:554px; }\n.ui-date-picker-content { box-sizing:border-box; min-width:0; container:date-content / inline-size; }\n.ui-date-picker-inline { box-sizing:border-box; width:100%; min-width:0; padding:var(--space-4); border:1px solid var(--border); border-radius:var(--radius); }\n.ui-date-picker-panels { display:grid; min-width:0; grid-template-columns:minmax(0,1fr); gap:var(--space-4); }\n.ui-date-picker-panels[data-month-count=\"2\"] { grid-template-columns:repeat(2,minmax(0,1fr)); }\n.ui-date-picker-calendar { width:100%; min-width:0; }\n.ui-date-picker-calendar-header { display:flex; min-height:var(--space-8); align-items:center; justify-content:space-between; gap:var(--space-1); }\n.ui-date-picker-panel-toolbar,.ui-date-picker-month-year { display:flex; min-width:0; align-items:center; gap:0; }\n.ui-date-picker-month-trigger,.ui-date-picker-year-trigger { min-width:0; padding-inline:var(--space-1); }\n.ui-date-picker-month-trigger svg,.ui-date-picker-year-trigger svg,.ui-date-picker-nav svg { width:var(--icon-size); height:var(--icon-size); stroke:currentColor; stroke-width:var(--icon-stroke); }\n.ui-date-picker-calendar-title { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; }\n.ui-date-picker-nav { display:inline-flex; flex:none; gap:var(--space-1); }\n.ui-date-picker-weekdays,.ui-date-picker-grid { display:grid; width:100%; grid-template-columns:repeat(7,minmax(0,1fr)); text-align:center; }\n.ui-date-picker-weekdays { margin-block:var(--space-2) var(--space-1); color:var(--muted-foreground); font-size:var(--font-size-caption); }\n.ui-date-picker-week { display:contents; }\n.ui-date-picker-cell { position:relative; display:grid; min-width:0; height:var(--space-8); place-items:center; }\n.ui-date-picker-cell.is-in-range::before,.ui-date-picker-cell.is-hover-range::before { position:absolute; z-index:0; inset:0; background:var(--secondary); content:\"\"; }\n.ui-date-picker-cell.is-range-start::before { left:50%; }\n.ui-date-picker-cell.is-range-end::before { right:50%; }\n.ui-date-picker-cell.is-hover-start::before { left:0; border-start-start-radius:var(--radius-lg); border-end-start-radius:var(--radius-lg); }\n.ui-date-picker-cell.is-hover-end::before { right:0; border-start-end-radius:var(--radius-lg); border-end-end-radius:var(--radius-lg); }\n.ui-date-picker-cell.is-hover-row-start::before,.ui-date-picker-cell.is-range-row-start::before { border-start-start-radius:var(--radius-lg); border-end-start-radius:var(--radius-lg); }\n.ui-date-picker-cell.is-hover-row-end::before,.ui-date-picker-cell.is-range-row-end::before { border-start-end-radius:var(--radius-lg); border-end-end-radius:var(--radius-lg); }\n.ui-date-picker-day { position:relative; z-index:1; display:grid; width:100%; height:var(--space-8); padding:0; place-items:center; border:0; border-radius:var(--radius-lg); background:transparent; color:var(--foreground); font:inherit; font-size:var(--font-size-base); cursor:pointer; touch-action:manipulation; user-select:none; -webkit-user-select:none; -webkit-tap-highlight-color:transparent; }\n@media (hover:hover) and (pointer:fine) { .ui-date-picker-day:hover:not(:disabled):not([data-selected=\"true\"]) { background:var(--secondary-hover); } }\n.ui-date-picker-day:active:not(:disabled):not([data-selected=\"true\"]) { background:var(--secondary-active,var(--secondary-hover)); }\n.ui-date-picker-day[data-selected=\"true\"] { background:var(--primary); color:var(--primary-foreground); }\n.ui-date-picker-day[data-today=\"true\"]:not([data-selected=\"true\"]) { box-shadow:inset 0 0 0 1px var(--primary); }\n.ui-date-picker-day:focus-visible { outline:var(--focus-border-width) solid var(--ring); outline-offset:var(--focus-outline-offset); }\n.ui-date-picker-day[aria-disabled=\"true\"],.ui-date-picker-cell.is-outside .ui-date-picker-day { color:var(--muted-foreground); opacity:.4; }\n.ui-date-picker-footer { display:flex; flex-wrap:wrap; min-width:0; align-items:center; justify-content:space-between; gap:var(--space-2); padding-top:var(--space-2); background:var(--background); font-size:var(--font-size-caption); }\n.ui-date-picker-custom-footer { min-width:0; padding-top:var(--space-3); }\n.ui-date-picker-commit-actions { display:flex; flex:none; min-height:32px; align-items:center; justify-content:flex-end; gap:var(--space-2); margin-inline-start:auto; }\n.ui-date-picker-range-summary { min-width:0; color:var(--muted-foreground); font-size:var(--font-size-caption); overflow-wrap:anywhere; }\n.ui-date-picker-count-guidance { padding-top:var(--space-2); }\n.ui-date-picker-commit-actions > .ui-button { align-self:center; }\n.ui-date-picker-availability { margin:0; color:var(--muted-foreground); font-size:var(--font-size-caption); line-height:var(--leading-copy); }\n.ui-date-picker-search-popup { max-height:min(20rem, var(--available-height)); overflow:auto; }\n.ui-date-picker-search-popup [role=\"listbox\"] { max-height:15rem; overflow:auto; }\n.ui-date-picker-search-popup [data-slot=\"input\"] { min-width:0; }\n.ui-popup.ui-date-picker-month-popup { width:calc(5 * var(--space-8)); min-width:0; }\n.ui-popup.ui-date-picker-year-popup { width:calc(4 * var(--space-8)); min-width:0; }\n.ui-date-picker-search-popup .ui-date-picker-year-list { max-height:192px; overflow-y:auto; overscroll-behavior:contain; }\n.ui-date-picker-cell.is-hover-end .ui-date-picker-day:not([data-selected=\"true\"]) { box-shadow:inset 0 0 0 1px var(--primary); }\n.ui-date-picker-day[data-selected=\"true\"][aria-disabled=\"true\"]:not(:disabled) { color:var(--primary-foreground); opacity:1; }\n.ui-date-picker[data-presets=\"true\"] { width:342px; }\n.ui-date-picker[data-presets=\"true\"][data-month-count=\"1\"] { width:286px; }\n.ui-date-picker[data-presets=\"true\"][data-month-count=\"2\"] { width:554px; }\n.ui-date-picker[data-preset-placement=\"sidebar\"][data-month-count=\"2\"] { width:704px; }\n.ui-date-picker[data-presets=\"true\"] > .ui-date-picker-inline { display:flex; padding:0; overflow:hidden; }\n.ui-date-picker[data-presets=\"true\"] .ui-date-picker-content { flex:1; padding:var(--space-4); }\n.ui-date-picker[data-presets=\"true\"] .ui-date-picker-footer { gap:var(--space-1); }\n.ui-date-picker[data-presets=\"true\"] .ui-date-picker-commit-actions > .ui-button { align-self:center; }\n.ui-date-picker-presets { box-sizing:border-box; display:flex; width:150px; flex:none; flex-direction:column; gap:var(--space-1); padding:var(--space-2); border-inline-end:1px solid var(--border); background:color-mix(in srgb,var(--background) 60%,var(--secondary)); }\n.ui-date-picker-preset { justify-content:space-between; gap:var(--space-2); width:100%; padding-inline:var(--space-2); white-space:nowrap; }\n.ui-date-picker-preset-indicator { display:inline-flex; width:var(--icon-size); flex:none; align-items:center; }\n.ui-date-picker-preset-indicator svg,.ui-date-picker-preset-trigger svg { width:var(--icon-size); height:var(--icon-size); stroke-width:var(--icon-stroke); }\n.ui-date-picker-preset-selector { display:flex; min-width:0; align-items:center; }\n.ui-date-picker-preset-trigger { --quiet-hover:transparent; --quiet-active:transparent; --control-selected-background:transparent; max-width:100%; gap:var(--space-1); padding-inline:0; font-size:var(--font-size-caption); white-space:nowrap; }\n.ui-date-picker .ui-select-trigger.ui-date-picker-preset-trigger[data-variant=\"ghost\"] { height:calc(var(--space-6) + var(--space-1)); min-height:calc(var(--space-6) + var(--space-1)); padding:0; border:0; color:var(--muted-foreground); font-size:var(--font-size-caption); }\n.ui-date-picker .ui-date-picker-preset-trigger { color:var(--muted-foreground); }\n.ui-date-picker .ui-button.ui-date-picker-preset-trigger:is(:hover,:active,:focus-visible,[data-popup-open]) { background:transparent; color:var(--foreground); transform:none; }\n.ui-date-picker-preset-trigger > span { min-width:0; overflow:hidden; text-overflow:ellipsis; }\n.ui-date-picker-preset-label-short { display:none; }\n.ui-date-picker-preset-trigger > svg { flex:none; }\n.ui-date-picker-preset-summary { display:none; white-space:nowrap; }\n.ui-date-picker[data-preset-placement=\"sidebar\"] .ui-date-picker-preset-selector { display:none; }\n.ui-date-picker[data-preset-placement=\"sidebar\"] .ui-date-picker-preset-summary { display:block; }\n.ui-date-picker-selection-status { position:absolute; width:1px; height:1px; padding:0; overflow:hidden; clip-path:inset(50%); white-space:nowrap; }\n.ui-date-picker-preset-popup { min-width:220px; max-width:calc(100vw - 32px); }\n.ui-popup.ui-select-popup.ui-date-picker-preset-popup { min-width:220px; }\n.ui-date-picker-preset-popup [role=\"listbox\"] { max-height:220px; overflow-y:auto; overscroll-behavior:contain; }\n@container date-picker (max-width:703px) { .ui-date-picker-presets { display:none; } .ui-date-picker[data-preset-placement=\"sidebar\"] .ui-date-picker-preset-selector { display:flex; } .ui-date-picker[data-preset-placement=\"sidebar\"] .ui-date-picker-preset-summary { display:none; } }\n@container date-picker (max-width:319px) { .ui-date-picker-preset-label { display:none; } .ui-date-picker-preset-label-short { display:block; } }\n@media (max-width:600px), (pointer:coarse) {\n  .ui-date-picker,.ui-date-picker[data-month-count=\"2\"],.ui-date-picker[data-presets=\"true\"],.ui-date-picker[data-presets=\"true\"][data-month-count=\"1\"],.ui-date-picker[data-presets=\"true\"][data-month-count=\"2\"] { width:326px; }\n  .ui-date-picker-inline { padding:var(--space-2); }\n  .ui-date-picker-panels[data-month-count=\"2\"] { grid-template-columns:minmax(0,1fr); }\n  .ui-date-picker-panels[data-month-count=\"2\"] > .ui-date-picker-calendar + .ui-date-picker-calendar { display:none; }\n  .ui-date-picker[data-presets=\"true\"] .ui-date-picker-content { padding:var(--space-2); }\n  .ui-date-picker-presets { display:none; }\n  .ui-date-picker[data-preset-placement=\"sidebar\"] .ui-date-picker-preset-selector { display:flex; }\n  .ui-date-picker[data-preset-placement=\"sidebar\"] .ui-date-picker-preset-summary { display:none; }\n}\n@container date-content (max-width:519px) { .ui-date-picker-panels[data-month-count=\"2\"] { grid-template-columns:minmax(0,1fr); } .ui-date-picker-panels[data-month-count=\"2\"] > .ui-date-picker-calendar + .ui-date-picker-calendar { display:none; } }\n@media (pointer:coarse) {\n  .ui-date-picker-cell,.ui-date-picker-day { height:44px; }\n  .ui-date-picker-calendar-header .ui-button { min-height:44px; }\n  .ui-date-picker-nav .ui-button { width:44px; min-width:44px; }\n}\n\n.ui-date-picker-private-review { display:flex; align-items:center; justify-content:space-between; gap:var(--space-2); padding-top:var(--space-2); }\n\n/* Embedding is owned here; consumers do not reset private panel styles. */\n.ui-date-picker[data-embedded=\"true\"] > .ui-date-picker-inline { border:0;padding:0; }\n.ui-date-picker[data-embedded=\"true\"] { width:100%; }\n.ui-day-of-month-picker { box-sizing:border-box;display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:var(--space-1);width:100%;min-width:0; }\n.ui-day-of-month-picker[data-variant=\"subtle\"] { padding:var(--space-2);border-radius:var(--radius-control-base);background:var(--secondary);--quiet-hover:var(--secondary-hover);--quiet-active:var(--secondary-active,var(--secondary-hover)); }\n.ui-day-of-month-picker>.ui-button { justify-self:center;width:100%;max-width:var(--space-8);height:var(--space-8);min-height:0;min-width:0;padding:0;border-radius:var(--radius-lg);font-size:var(--font-size-base);font-variant-numeric:tabular-nums; }\n"
    }
  ]
}
