{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-range-picker",
  "type": "registry:component",
  "title": "Date range picker",
  "description": "A dashboard date range control with presets, a two-month keyboard calendar, and an optional comparison period.",
  "categories": [
    "forms"
  ],
  "dependencies": [
    "@tabler/icons-react",
    "@radix-ui/react-popover"
  ],
  "registryDependencies": [
    "button",
    "switch"
  ],
  "files": [
    {
      "path": "src/registry/overtrue/date-range-picker.tsx",
      "type": "registry:component",
      "target": "components/overtrue/date-range-picker.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport {\n  IconCalendarEvent,\n  IconChevronDown,\n  IconChevronLeft,\n  IconChevronRight,\n} from \"@tabler/icons-react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Switch } from \"@/components/ui/switch\";\nimport { cn } from \"@/lib/utils\";\n\n/* ------------------------------------------------------------------------ */\n/* Types                                                                     */\n/* ------------------------------------------------------------------------ */\n\n/** An inclusive span of local calendar days. Times of day are ignored. */\nexport interface DateRange {\n  from: Date;\n  to: Date;\n}\n\nexport type DateRangeCompareMode = \"previous-period\" | \"previous-year\";\nexport type DateRangeApplyMode = \"confirm\" | \"auto\";\nexport type WeekdayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\nexport interface DateRangePreset {\n  /** Stable id, such as \"last-30-days\". */\n  id: string;\n  label: string;\n  from: Date;\n  to: Date;\n}\n\nexport interface DateRangeChangeDetails {\n  /** The preset whose dates match the new range, if any. */\n  preset: DateRangePreset | null;\n  /** The comparison range that goes with the new range, or null when comparison is off. */\n  compare: DateRange | null;\n}\n\n/** Interface copy. Dates and weekdays are localized through `locale`. */\nexport interface DateRangePickerLabels {\n  placeholder: string;\n  dialog: string;\n  presets: string;\n  previousMonth: string;\n  nextMonth: string;\n  compare: string;\n  compareMode: string;\n  previousPeriod: string;\n  previousYear: string;\n  cancel: string;\n  apply: string;\n  selectEnd: string;\n  rangeStart: string;\n  rangeEnd: string;\n  today: string;\n  days: (count: number) => string;\n}\n\nexport interface DateRangePickerProps extends Omit<\n  React.ComponentProps<\"div\">,\n  \"defaultValue\" | \"onChange\" | \"children\"\n> {\n  /** The committed range. Pass null for none; leave undefined to let the picker manage it. */\n  value?: DateRange | null;\n  defaultValue?: DateRange | null;\n  /** Called when a range is applied, or on the second click and preset clicks with `applyMode=\"auto\"`. */\n  onChange?: (range: DateRange, details: DateRangeChangeDetails) => void;\n  /** The comparison range. Null turns comparison off; leave undefined to let the picker manage it. */\n  compare?: DateRange | null;\n  defaultCompare?: DateRange | null;\n  onCompareChange?: (compare: DateRange | null) => void;\n  /** How the comparison range is derived. Defaults to \"previous-period\". */\n  compareMode?: DateRangeCompareMode;\n  defaultCompareMode?: DateRangeCompareMode;\n  onCompareModeChange?: (mode: DateRangeCompareMode) => void;\n  /** Show the comparison toggle. Defaults to true when any compare prop is passed. */\n  showCompare?: boolean;\n  /** Quick ranges in the side column. Defaults to `presetRanges(today)`; pass [] to hide the column. */\n  presets?: DateRangePreset[];\n  /** Anchors presets and the today marker. Defaults to the current date. */\n  today?: Date;\n  minDate?: Date;\n  maxDate?: Date;\n  isDateDisabled?: (date: Date) => boolean;\n  /** Longest selectable range in days, counted inclusively. */\n  maxDays?: number;\n  /** First column of the calendar. Defaults to the locale's first day of the week. */\n  weekStartsOn?: WeekdayIndex;\n  /** Months shown side by side. Two collapse to one when the panel is narrow. */\n  numberOfMonths?: 1 | 2;\n  /** BCP 47 locale for dates and weekday names. Defaults to the runtime locale. */\n  locale?: string;\n  /** \"confirm\" waits for Apply; \"auto\" commits on the second click and on presets. */\n  applyMode?: DateRangeApplyMode;\n  size?: \"sm\" | \"default\";\n  /** Panel alignment against the trigger. */\n  align?: \"start\" | \"center\" | \"end\";\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /**\n   * Render the panel in place under the trigger instead of a portalled popover.\n   * It is sized to the nearest CSS container, stays open on outside clicks, and\n   * never steals focus on mount. For sheets, documentation, and screenshots.\n   */\n  inline?: boolean;\n  disabled?: boolean;\n  /** Adds hidden inputs `name[from]` and `name[to]` with yyyy-mm-dd values for forms. */\n  name?: string;\n  /** Replaces the trigger label. */\n  formatLabel?: (\n    range: DateRange | null,\n    preset: DateRangePreset | null,\n  ) => React.ReactNode;\n  labels?: Partial<DateRangePickerLabels>;\n  triggerClassName?: string;\n  contentClassName?: string;\n}\n\n/* ------------------------------------------------------------------------ */\n/* Calendar days                                                             */\n/* ------------------------------------------------------------------------ */\n\nconst DAY_MS = 86_400_000;\n\nconst startOfDay = (date: Date) =>\n  new Date(date.getFullYear(), date.getMonth(), date.getDate());\nconst addDays = (date: Date, days: number) =>\n  new Date(date.getFullYear(), date.getMonth(), date.getDate() + days);\nconst daysInMonth = (year: number, month: number) =>\n  new Date(year, month + 1, 0).getDate();\nconst monthIndex = (date: Date) => date.getFullYear() * 12 + date.getMonth();\nconst fromMonthIndex = (index: number) =>\n  new Date(Math.floor(index / 12), ((index % 12) + 12) % 12, 1);\n/** Sortable key for a calendar day. */\nconst dayKey = (date: Date) =>\n  date.getFullYear() * 10_000 + date.getMonth() * 100 + date.getDate();\nconst sameDay = (a?: Date | null, b?: Date | null) =>\n  !!a && !!b && dayKey(a) === dayKey(b);\n/** Whole days since the epoch, immune to daylight-saving shifts. */\nconst epochDay = (date: Date) =>\n  Math.round(\n    Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) / DAY_MS,\n  );\n\nfunction addMonths(date: Date, months: number) {\n  const first = new Date(date.getFullYear(), date.getMonth() + months, 1);\n  const year = first.getFullYear();\n  const month = first.getMonth();\n  return new Date(\n    year,\n    month,\n    Math.min(date.getDate(), daysInMonth(year, month)),\n  );\n}\n\nfunction orderRange(a: Date, b: Date): DateRange {\n  return dayKey(a) <= dayKey(b) ? { from: a, to: b } : { from: b, to: a };\n}\n\nconst toISODate = (date: Date) =>\n  `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, \"0\")}-${String(date.getDate()).padStart(2, \"0\")}`;\n\n/** Number of days in a range, counting both ends. */\nexport function rangeDays(range: DateRange) {\n  return Math.abs(epochDay(range.to) - epochDay(range.from)) + 1;\n}\n\n/** True when both ranges cover the same calendar days, or both are empty. */\nexport function isSameRange(a?: DateRange | null, b?: DateRange | null) {\n  if (!a || !b) return !a && !b;\n  return sameDay(a.from, b.from) && sameDay(a.to, b.to);\n}\n\n/** The same number of days, ending the day before the range starts. */\nexport function previousPeriod(range: DateRange): DateRange {\n  const to = addDays(startOfDay(range.from), -1);\n  return { from: addDays(to, -(rangeDays(range) - 1)), to };\n}\n\n/** The same calendar days one year earlier. February 29 becomes February 28. */\nexport function previousYear(range: DateRange): DateRange {\n  return {\n    from: addMonths(startOfDay(range.from), -12),\n    to: addMonths(startOfDay(range.to), -12),\n  };\n}\n\n/** The comparison range for a mode. */\nexport function compareRange(range: DateRange, mode: DateRangeCompareMode) {\n  return mode === \"previous-year\" ? previousYear(range) : previousPeriod(range);\n}\n\n/** The ten standard dashboard ranges, each ending today unless named otherwise. */\nexport function presetRanges(today: Date = new Date()): DateRangePreset[] {\n  const t = startOfDay(today);\n  const year = t.getFullYear();\n  const month = t.getMonth();\n  const yesterday = addDays(t, -1);\n  return [\n    { id: \"today\", label: \"Today\", from: t, to: t },\n    { id: \"yesterday\", label: \"Yesterday\", from: yesterday, to: yesterday },\n    { id: \"last-7-days\", label: \"Last 7 days\", from: addDays(t, -6), to: t },\n    { id: \"last-30-days\", label: \"Last 30 days\", from: addDays(t, -29), to: t },\n    { id: \"last-90-days\", label: \"Last 90 days\", from: addDays(t, -89), to: t },\n    { id: \"this-month\", label: \"This month\", from: new Date(year, month, 1), to: t },\n    {\n      id: \"last-month\",\n      label: \"Last month\",\n      from: new Date(year, month - 1, 1),\n      to: new Date(year, month, 0),\n    },\n    {\n      id: \"quarter-to-date\",\n      label: \"Quarter to date\",\n      from: new Date(year, month - (month % 3), 1),\n      to: t,\n    },\n    { id: \"year-to-date\", label: \"Year to date\", from: new Date(year, 0, 1), to: t },\n    {\n      id: \"last-12-months\",\n      label: \"Last 12 months\",\n      from: addDays(addMonths(t, -12), 1),\n      to: t,\n    },\n  ];\n}\n\nconst formatters = new Map<string, Intl.DateTimeFormat>();\nfunction formatter(\n  locale: string | undefined,\n  options: Intl.DateTimeFormatOptions,\n) {\n  const key = `${locale ?? \"\"}|${JSON.stringify(options)}`;\n  let cached = formatters.get(key);\n  if (!cached) {\n    cached = new Intl.DateTimeFormat(locale, options);\n    formatters.set(key, cached);\n  }\n  return cached;\n}\n\nconst FULL: Intl.DateTimeFormatOptions = {\n  month: \"short\",\n  day: \"numeric\",\n  year: \"numeric\",\n};\n\n/** \"Sep 1 – Sep 30, 2026\". The start drops its year when both ends share one. */\nexport function formatDateRange(range: DateRange, locale?: string) {\n  const from = startOfDay(range.from);\n  const to = startOfDay(range.to);\n  const full = formatter(locale, FULL);\n  if (sameDay(from, to)) return full.format(to);\n  const start =\n    from.getFullYear() === to.getFullYear()\n      ? formatter(locale, { month: \"short\", day: \"numeric\" }).format(from)\n      : full.format(from);\n  return `${start} – ${full.format(to)}`;\n}\n\ntype IntlLocaleWithWeek = Intl.Locale & {\n  getWeekInfo?: () => { firstDay: number };\n  weekInfo?: { firstDay: number };\n};\n\nfunction localeWeekStart(locale?: string): WeekdayIndex {\n  try {\n    const resolved = new Intl.Locale(\n      locale ?? new Intl.DateTimeFormat().resolvedOptions().locale,\n    ) as IntlLocaleWithWeek;\n    const info = resolved.getWeekInfo?.() ?? resolved.weekInfo;\n    if (info?.firstDay) return (info.firstDay % 7) as WeekdayIndex;\n  } catch {\n    // Older engines: fall through to Sunday.\n  }\n  return 0;\n}\n\nfunction prefersReducedMotion() {\n  return (\n    typeof window !== \"undefined\" &&\n    window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches\n  );\n}\n\nconst defaultLabels: DateRangePickerLabels = {\n  placeholder: \"Select dates\",\n  dialog: \"Choose a date range\",\n  presets: \"Presets\",\n  previousMonth: \"Previous month\",\n  nextMonth: \"Next month\",\n  compare: \"Compare\",\n  compareMode: \"Comparison period\",\n  previousPeriod: \"Previous period\",\n  previousYear: \"Previous year\",\n  cancel: \"Cancel\",\n  apply: \"Apply\",\n  selectEnd: \"select an end date\",\n  rangeStart: \"range start\",\n  rangeEnd: \"range end\",\n  today: \"today\",\n  days: (count) => (count === 1 ? \"1 day\" : `${count} days`),\n};\n\n/* Panel geometry, in px. A month is seven 36px columns. */\nconst PRESET_COLUMN = 144;\nconst MONTH_BLOCK = 284; // 252px grid plus 16px padding each side\nconst MONTH_GAP = 0; // the second month adds its own padding\nconst ONE_MONTH_MIN = 420;\n\ninterface Draft {\n  from: Date | null;\n  to: Date | null;\n}\n\nconst toDraft = (range: DateRange | null | undefined): Draft =>\n  range\n    ? { from: startOfDay(range.from), to: startOfDay(range.to) }\n    : { from: null, to: null };\n\n/** First visible month index so `focus` shows and the range end or today sits on the right. */\nfunction viewFor(focus: Date, end: Date | null, today: Date, count: number) {\n  const focusMonth = monthIndex(focus);\n  const last = Math.max(monthIndex(end ?? focus), monthIndex(today));\n  return Math.max(focusMonth, Math.min(last, focusMonth + count - 1));\n}\n\nconst EASE = \"cubic-bezier(0.22, 1, 0.36, 1)\";\nconst keyframes = `@keyframes date-range-picker-in{from{opacity:0;transform:translateY(-6px) scale(.96)}to{opacity:1;transform:none}}`;\n\n/* ------------------------------------------------------------------------ */\n/* Component                                                                 */\n/* ------------------------------------------------------------------------ */\n\n/** A dashboard date range control with presets, a two-month calendar, and an optional comparison period. */\nexport function DateRangePicker({\n  value: valueProp,\n  defaultValue = null,\n  onChange,\n  compare: compareProp,\n  defaultCompare = null,\n  onCompareChange,\n  compareMode: compareModeProp,\n  defaultCompareMode = \"previous-period\",\n  onCompareModeChange,\n  showCompare: showCompareProp,\n  presets: presetsProp,\n  today: todayProp,\n  minDate,\n  maxDate,\n  isDateDisabled,\n  maxDays,\n  weekStartsOn: weekStartsOnProp,\n  numberOfMonths = 2,\n  locale,\n  applyMode = \"confirm\",\n  size = \"default\",\n  align = \"start\",\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  inline = false,\n  disabled = false,\n  name,\n  formatLabel,\n  labels: labelsProp,\n  id,\n  \"aria-label\": ariaLabel,\n  \"aria-labelledby\": ariaLabelledby,\n  className,\n  triggerClassName,\n  contentClassName,\n  ...props\n}: DateRangePickerProps) {\n  const labels = { ...defaultLabels, ...labelsProp };\n  const uid = React.useId();\n  const panelId = `${uid}-panel`;\n  const compareSwitchId = `${uid}-compare`;\n\n  const todayKey = todayProp ? dayKey(todayProp) : 0;\n  const today = React.useMemo(\n    () =>\n      todayKey\n        ? new Date(\n            Math.floor(todayKey / 10_000),\n            Math.floor(todayKey / 100) % 100,\n            todayKey % 100,\n          )\n        : startOfDay(new Date()),\n    [todayKey],\n  );\n  const presets = React.useMemo(\n    () => presetsProp ?? presetRanges(today),\n    [presetsProp, today],\n  );\n  const weekStartsOn = React.useMemo(\n    () => weekStartsOnProp ?? localeWeekStart(locale),\n    [weekStartsOnProp, locale],\n  );\n  const minKey = minDate ? dayKey(minDate) : -Infinity;\n  const maxKey = maxDate ? dayKey(maxDate) : Infinity;\n  const clampDay = (date: Date) =>\n    dayKey(date) < minKey && minDate\n      ? startOfDay(minDate)\n      : dayKey(date) > maxKey && maxDate\n        ? startOfDay(maxDate)\n        : startOfDay(date);\n\n  /* ---- Controlled and uncontrolled state ---- */\n  const [valueState, setValueState] = React.useState<DateRange | null>(\n    defaultValue,\n  );\n  const value = valueProp !== undefined ? valueProp : valueState;\n  const [compareState, setCompareState] = React.useState<DateRange | null>(\n    defaultCompare,\n  );\n  const compare = compareProp !== undefined ? compareProp : compareState;\n  const [modeState, setModeState] =\n    React.useState<DateRangeCompareMode>(defaultCompareMode);\n  const mode = compareModeProp ?? modeState;\n  const [openState, setOpenState] = React.useState(defaultOpen);\n  const open = openProp ?? openState;\n  const showCompare =\n    showCompareProp ??\n    (compareProp !== undefined ||\n      onCompareChange !== undefined ||\n      defaultCompare !== null);\n\n  /* ---- Draft state while the panel is open ---- */\n  const [panelNode, setPanelNode] = React.useState<HTMLDivElement | null>(\n    null,\n  );\n  const panelRef = React.useRef<HTMLDivElement | null>(null);\n  const attachPanel = React.useCallback((node: HTMLDivElement | null) => {\n    panelRef.current = node;\n    setPanelNode(node);\n  }, []);\n  const [panelWidth, setPanelWidth] = React.useState<number | null>(null);\n  const hasPresets = presets.length > 0;\n  const natural =\n    (hasPresets ? PRESET_COLUMN : 0) +\n    MONTH_BLOCK * numberOfMonths +\n    (numberOfMonths === 2 ? MONTH_GAP : 0);\n  const width = panelWidth ?? natural;\n  const twoMonthMin = (hasPresets ? PRESET_COLUMN : 0) + MONTH_BLOCK * 2 - 8;\n  const months: 1 | 2 = numberOfMonths === 2 && width >= twoMonthMin ? 2 : 1;\n  const presetLayout: \"column\" | \"row\" | \"none\" = !hasPresets\n    ? \"none\"\n    : width >= (months === 2 ? twoMonthMin : ONE_MONTH_MIN)\n      ? \"column\"\n      : \"row\";\n\n  const [draft, setDraft] = React.useState<Draft>(() => toDraft(value));\n  const [anchor, setAnchor] = React.useState<Date | null>(null);\n  const [hover, setHover] = React.useState<Date | null>(null);\n  const [draftCompare, setDraftCompare] = React.useState(compare != null);\n  const [draftMode, setDraftMode] = React.useState<DateRangeCompareMode>(mode);\n  const [focused, setFocused] = React.useState<Date>(() =>\n    clampDay(value?.from ?? today),\n  );\n  const [view, setView] = React.useState(() =>\n    viewFor(\n      clampDay(value?.from ?? today),\n      value ? startOfDay(value.to) : null,\n      today,\n      months,\n    ),\n  );\n\n  const resetDraft = () => {\n    const next = toDraft(value);\n    const focus = clampDay(next.from ?? today);\n    setDraft(next);\n    setAnchor(null);\n    setHover(null);\n    setDraftCompare(compare != null);\n    setDraftMode(mode);\n    setFocused(focus);\n    setView(viewFor(focus, next.to, today, months));\n  };\n\n  // Reset the draft whenever the panel opens, including controlled opens.\n  const [prevOpen, setPrevOpen] = React.useState(open);\n  if (prevOpen !== open) {\n    setPrevOpen(open);\n    if (open) resetDraft();\n  }\n  // Keep the focused day visible when the panel collapses to one month.\n  const [prevMonths, setPrevMonths] = React.useState(months);\n  if (prevMonths !== months) {\n    setPrevMonths(months);\n    setView(viewFor(focused, draft.to, today, months));\n  }\n\n  React.useLayoutEffect(() => {\n    if (!panelNode) return;\n    const measure = () => setPanelWidth(panelNode.offsetWidth);\n    measure();\n    const observer = new ResizeObserver(measure);\n    observer.observe(panelNode);\n    return () => observer.disconnect();\n  }, [panelNode]);\n\n  /* ---- Refs for focus and motion ---- */\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const monthsRef = React.useRef<HTMLDivElement>(null);\n  const presetListRef = React.useRef<HTMLDivElement>(null);\n  const focusRequest = React.useRef<number | null>(null);\n  const slide = React.useRef(0);\n  const userOpened = React.useRef(false);\n  const focusedRef = React.useRef(focused);\n  focusedRef.current = focused;\n\n  const focusDay = React.useCallback((date: Date) => {\n    panelRef.current\n      ?.querySelector<HTMLButtonElement>(\n        `[data-day=\"${dayKey(date)}\"]:not([data-outside])`,\n      )\n      ?.focus({ preventScroll: true });\n  }, []);\n\n  React.useEffect(() => {\n    if (focusRequest.current === null) return;\n    if (focusRequest.current !== dayKey(focused)) return;\n    focusRequest.current = null;\n    focusDay(focused);\n  }, [focused, view, focusDay]);\n\n  React.useLayoutEffect(() => {\n    const direction = slide.current;\n    slide.current = 0;\n    if (!direction || !monthsRef.current || prefersReducedMotion()) return;\n    monthsRef.current.animate?.(\n      [\n        { opacity: 0.3, transform: `translateX(${direction * 12}px)` },\n        { opacity: 1, transform: \"none\" },\n      ],\n      { duration: 320, easing: EASE },\n    );\n  }, [view]);\n\n  /* ---- Derived ranges ---- */\n  const matchPreset = (range: DateRange | null) =>\n    range ? (presets.find((preset) => isSameRange(preset, range)) ?? null) : null;\n  const draftRange: DateRange | null =\n    draft.from && draft.to ? { from: draft.from, to: draft.to } : null;\n  const previewing = !!anchor && !!hover && !sameDay(anchor, hover);\n  const shown: DateRange | null = anchor\n    ? orderRange(anchor, hover ?? anchor)\n    : draftRange;\n  const shownCompare =\n    draftCompare && shown ? compareRange(shown, draftMode) : null;\n  const activePreset = anchor ? null : matchPreset(draftRange);\n  const committedPreset = matchPreset(value ?? null);\n\n  const isUnavailable = (date: Date) => {\n    const key = dayKey(date);\n    if (key < minKey || key > maxKey) return true;\n    if (isDateDisabled?.(date)) return true;\n    if (anchor && maxDays && rangeDays({ from: anchor, to: date }) > maxDays)\n      return true;\n    return false;\n  };\n\n  /* ---- Actions ---- */\n  const setOpen = (next: boolean) => {\n    if (next === open) return;\n    if (next) userOpened.current = true;\n    if (openProp === undefined) setOpenState(next);\n    onOpenChange?.(next);\n    if (inline) {\n      if (next) {\n        requestAnimationFrame(() => focusDay(focusedRef.current));\n      } else if (panelRef.current?.contains(document.activeElement)) {\n        triggerRef.current?.focus();\n      }\n    }\n  };\n\n  const commit = (\n    range: DateRange,\n    compareOn: boolean,\n    nextMode: DateRangeCompareMode,\n  ) => {\n    const nextCompare = compareOn ? compareRange(range, nextMode) : null;\n    if (!isSameRange(range, value)) {\n      if (valueProp === undefined) setValueState(range);\n      onChange?.(range, { preset: matchPreset(range), compare: nextCompare });\n    }\n    if (nextMode !== mode) {\n      if (compareModeProp === undefined) setModeState(nextMode);\n      onCompareModeChange?.(nextMode);\n    }\n    if (!isSameRange(nextCompare, compare)) {\n      if (compareProp === undefined) setCompareState(nextCompare);\n      onCompareChange?.(nextCompare);\n    }\n  };\n\n  const showMonthOf = (date: Date, preferEnd?: Date | null) => {\n    const target = viewFor(date, preferEnd ?? null, today, months);\n    const first = view - months + 1;\n    const index = monthIndex(date);\n    if (index >= first && index <= view && !preferEnd) return;\n    if (target !== view) {\n      slide.current = target > view ? 1 : -1;\n      setView(target);\n    }\n  };\n\n  const moveFocus = (date: Date) => {\n    const next = clampDay(date);\n    const index = monthIndex(next);\n    const first = view - months + 1;\n    if (index > view) {\n      slide.current = 1;\n      setView(index);\n    } else if (index < first) {\n      slide.current = -1;\n      setView(index + months - 1);\n    }\n    if (anchor) setHover(next);\n    if (sameDay(next, focused) && index >= first && index <= view) {\n      focusDay(next);\n      return;\n    }\n    focusRequest.current = dayKey(next);\n    setFocused(next);\n  };\n\n  const selectDay = (date: Date) => {\n    if (isUnavailable(date)) return;\n    setFocused(date);\n    if (!anchor) {\n      setAnchor(date);\n      setHover(date);\n      setDraft({ from: date, to: null });\n      return;\n    }\n    const range = orderRange(anchor, date);\n    setAnchor(null);\n    setHover(null);\n    setDraft(range);\n    if (applyMode === \"auto\") {\n      commit(range, draftCompare, draftMode);\n      setOpen(false);\n    }\n  };\n\n  const selectPreset = (preset: DateRangePreset) => {\n    const range = { from: startOfDay(preset.from), to: startOfDay(preset.to) };\n    setDraft(range);\n    setAnchor(null);\n    setHover(null);\n    setFocused(clampDay(range.from));\n    showMonthOf(range.from, range.to);\n    if (applyMode === \"auto\") {\n      commit(range, draftCompare, draftMode);\n      setOpen(false);\n    }\n  };\n\n  const cancelPending = () => {\n    setAnchor(null);\n    setHover(null);\n    setDraft(toDraft(value));\n  };\n\n  const apply = () => {\n    const range =\n      draftRange ?? (anchor ? { from: anchor, to: anchor } : (value ?? null));\n    if (range) commit(range, draftCompare, draftMode);\n    setOpen(false);\n  };\n\n  const toggleCompare = (on: boolean) => {\n    setDraftCompare(on);\n    if (applyMode === \"auto\") {\n      const range = draftRange ?? value;\n      if (range) commit(range, on, draftMode);\n    }\n  };\n\n  const changeMode = (next: DateRangeCompareMode) => {\n    setDraftMode(next);\n    if (applyMode === \"auto\") {\n      const range = draftRange ?? value;\n      if (range) commit(range, draftCompare, next);\n    }\n  };\n\n  /* ---- Keyboard ---- */\n  const onGridKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n    const offset = (focused.getDay() - weekStartsOn + 7) % 7;\n    let next: Date | null = null;\n    switch (event.key) {\n      case \"ArrowLeft\":\n        next = addDays(focused, -1);\n        break;\n      case \"ArrowRight\":\n        next = addDays(focused, 1);\n        break;\n      case \"ArrowUp\":\n        next = addDays(focused, -7);\n        break;\n      case \"ArrowDown\":\n        next = addDays(focused, 7);\n        break;\n      case \"PageUp\":\n        next = addMonths(focused, event.shiftKey ? -12 : -1);\n        break;\n      case \"PageDown\":\n        next = addMonths(focused, event.shiftKey ? 12 : 1);\n        break;\n      case \"Home\":\n        next = addDays(focused, -offset);\n        break;\n      case \"End\":\n        next = addDays(focused, 6 - offset);\n        break;\n      default:\n        return;\n    }\n    event.preventDefault();\n    moveFocus(next);\n  };\n\n  const onPanelKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n    if (event.key !== \"Escape\" || !inline) return;\n    event.preventDefault();\n    if (anchor) cancelPending();\n    else setOpen(false);\n  };\n\n  const onPresetKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n    const keys =\n      presetLayout === \"row\"\n        ? { prev: \"ArrowLeft\", next: \"ArrowRight\" }\n        : { prev: \"ArrowUp\", next: \"ArrowDown\" };\n    if (![keys.prev, keys.next, \"Home\", \"End\"].includes(event.key)) return;\n    const items = Array.from(\n      presetListRef.current?.querySelectorAll<HTMLButtonElement>(\n        \"[data-preset]\",\n      ) ?? [],\n    );\n    const index = items.indexOf(document.activeElement as HTMLButtonElement);\n    const nextIndex =\n      event.key === \"Home\"\n        ? 0\n        : event.key === \"End\"\n          ? items.length - 1\n          : event.key === keys.prev\n            ? Math.max(0, index - 1)\n            : Math.min(items.length - 1, index + 1);\n    event.preventDefault();\n    items[nextIndex]?.focus();\n    items[nextIndex]?.scrollIntoView?.({ block: \"nearest\", inline: \"nearest\" });\n  };\n\n  // Keep the active preset chip in view in the compact row.\n  React.useEffect(() => {\n    if (!open || presetLayout !== \"row\") return;\n    const list = presetListRef.current;\n    const active = list?.querySelector<HTMLElement>(\"[data-active]\");\n    if (!list || !active) return;\n    list.scrollLeft =\n      active.offsetLeft - (list.clientWidth - active.offsetWidth) / 2;\n  }, [open, presetLayout, activePreset?.id]);\n\n  /* ---- Rendering ---- */\n  const weekdays = React.useMemo(() => {\n    const short = formatter(locale, { weekday: \"short\" });\n    const long = formatter(locale, { weekday: \"long\" });\n    // 1 January 2023 was a Sunday.\n    return Array.from({ length: 7 }, (_, i) => {\n      const date = new Date(2023, 0, 1 + ((weekStartsOn + i) % 7));\n      return { short: short.format(date), long: long.format(date) };\n    });\n  }, [locale, weekStartsOn]);\n\n  const visibleMonths = Array.from({ length: months }, (_, i) =>\n    fromMonthIndex(view - months + 1 + i),\n  );\n  const focusInView =\n    monthIndex(focused) >= view - months + 1 && monthIndex(focused) <= view;\n  const canGoBack = !minDate || view - months + 1 > monthIndex(minDate);\n  const canGoForward = !maxDate || view < monthIndex(maxDate);\n  const navigate = (direction: -1 | 1) => {\n    slide.current = direction;\n    setView((current) => current + direction);\n    const shifted = addMonths(focused, direction);\n    setFocused(clampDay(shifted));\n  };\n\n  const longDate = formatter(locale, {\n    weekday: \"long\",\n    month: \"long\",\n    day: \"numeric\",\n    year: \"numeric\",\n  });\n  const caption = formatter(locale, { month: \"long\", year: \"numeric\" });\n\n  const renderMonth = (month: Date) => {\n    const first = new Date(month.getFullYear(), month.getMonth(), 1);\n    const lead = (first.getDay() - weekStartsOn + 7) % 7;\n    const start = addDays(first, -lead);\n    const lastDate = daysInMonth(month.getFullYear(), month.getMonth());\n    const captionId = `${uid}-caption-${monthIndex(month)}`;\n    const shownFrom = shown ? dayKey(shown.from) : 0;\n    const shownTo = shown ? dayKey(shown.to) : 0;\n    const compareFrom = shownCompare ? dayKey(shownCompare.from) : 0;\n    const compareTo = shownCompare ? dayKey(shownCompare.to) : 0;\n\n    return (\n      <div\n        key={monthIndex(month)}\n        data-slot=\"date-range-picker-month\"\n        className=\"mx-auto w-full max-w-[19.25rem] min-w-0 px-3 sm:max-w-[17.75rem] sm:px-4\"\n      >\n        <div\n          id={captionId}\n          aria-live=\"polite\"\n          className=\"flex h-8 items-center justify-center text-sm font-semibold tracking-tight\"\n        >\n          {caption.format(month)}\n        </div>\n        <div\n          role=\"grid\"\n          aria-labelledby={captionId}\n          className=\"mt-2 flex flex-col gap-1\"\n          onMouseLeave={() => anchor && setHover(null)}\n        >\n          <div role=\"row\" className=\"grid grid-cols-7\">\n            {weekdays.map((weekday) => (\n              <div\n                key={weekday.long}\n                role=\"columnheader\"\n                aria-label={weekday.long}\n                className=\"flex h-7 items-center justify-center text-xs font-normal text-muted-foreground\"\n              >\n                <abbr title={weekday.long} className=\"no-underline\">\n                  {weekday.short}\n                </abbr>\n              </div>\n            ))}\n          </div>\n          {Array.from({ length: 6 }, (_, week) => (\n            <div key={week} role=\"row\" className=\"grid grid-cols-7\">\n              {Array.from({ length: 7 }, (_, column) => {\n                const date = addDays(start, week * 7 + column);\n                const key = dayKey(date);\n                const outside = date.getMonth() !== month.getMonth();\n                const unavailable = isUnavailable(date);\n                const isStart = !!shown && key === shownFrom;\n                const isEnd = !!shown && key === shownTo;\n                const inRange = !!shown && key >= shownFrom && key <= shownTo;\n                const single = isStart && isEnd;\n                const isToday = sameDay(date, today);\n                const isAnchor = sameDay(date, anchor);\n                const isPreviewEnd = previewing && sameDay(date, hover);\n                const solid = isAnchor || (!previewing && (isStart || isEnd));\n                const inCompare =\n                  !!shownCompare && key >= compareFrom && key <= compareTo;\n                const rowStart = column === 0 || date.getDate() === 1;\n                const rowEnd = column === 6 || date.getDate() === lastDate;\n                const label = [\n                  longDate.format(date),\n                  isStart && !single ? labels.rangeStart : null,\n                  isEnd && !single ? labels.rangeEnd : null,\n                  isToday ? labels.today : null,\n                ]\n                  .filter(Boolean)\n                  .join(\", \");\n                // Keep one day reachable with Tab even when the focused day scrolled out of view.\n                const tabbable =\n                  !outside &&\n                  (focusInView\n                    ? sameDay(date, focused)\n                    : monthIndex(month) === view - months + 1 && date.getDate() === 1);\n\n                return (\n                  <div\n                    key={key}\n                    role=\"gridcell\"\n                    aria-selected={!outside && inRange ? true : undefined}\n                    className=\"relative h-11 min-w-0 sm:h-9\"\n                  >\n                    {!outside && inRange && !single && (\n                      <span\n                        aria-hidden=\"true\"\n                        className={cn(\n                          \"pointer-events-none absolute inset-y-[3px] transition-colors duration-150 motion-reduce:transition-none\",\n                          previewing\n                            ? \"bg-primary/[0.07] dark:bg-primary/10\"\n                            : \"bg-primary/[0.11] dark:bg-primary/[0.16]\",\n                          isStart\n                            ? rowEnd\n                              ? \"hidden\"\n                              : \"start-1/2 end-0\"\n                            : isEnd\n                              ? rowStart\n                                ? \"hidden\"\n                                : \"start-0 end-1/2\"\n                              : \"inset-x-0\",\n                          rowStart && !isStart && \"rounded-s-full\",\n                          rowEnd && !isEnd && \"rounded-e-full\",\n                        )}\n                      />\n                    )}\n                    {!outside && inCompare && (\n                      <span\n                        aria-hidden=\"true\"\n                        className=\"pointer-events-none absolute inset-x-2 bottom-0 h-0.5 rounded-full bg-muted-foreground/45\"\n                      />\n                    )}\n                    <button\n                      type=\"button\"\n                      data-slot=\"date-range-picker-day\"\n                      data-day={key}\n                      data-selected={!outside && (isStart || isEnd) ? \"\" : undefined}\n                      data-range-start={!outside && isStart ? \"\" : undefined}\n                      data-range-end={!outside && isEnd ? \"\" : undefined}\n                      data-in-range={!outside && inRange ? \"\" : undefined}\n                      data-preview={!outside && previewing && inRange ? \"\" : undefined}\n                      data-compare={!outside && inCompare ? \"\" : undefined}\n                      data-today={isToday ? \"\" : undefined}\n                      data-outside={outside ? \"\" : undefined}\n                      data-disabled={unavailable ? \"\" : undefined}\n                      tabIndex={tabbable ? 0 : -1}\n                      aria-label={label}\n                      aria-current={isToday ? \"date\" : undefined}\n                      aria-disabled={unavailable || undefined}\n                      onClick={() => selectDay(date)}\n                      onFocus={() => {\n                        if (!outside && !sameDay(date, focused)) setFocused(date);\n                        if (anchor && !outside) setHover(date);\n                      }}\n                      onMouseEnter={() => {\n                        if (anchor && !unavailable) setHover(date);\n                      }}\n                      className={cn(\n                        \"relative z-10 flex size-full items-center justify-center rounded-lg text-sm tabular-nums transition-[color,background-color,box-shadow] duration-150 outline-none motion-reduce:transition-none\",\n                        \"focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:shadow-[0_0_0_5px_color-mix(in_oklab,var(--color-primary)_10%,transparent)]\",\n                        outside\n                          ? \"text-muted-foreground/35\"\n                          : unavailable\n                            ? \"cursor-not-allowed text-muted-foreground/40\"\n                            : \"text-foreground\",\n                        !outside &&\n                          !unavailable &&\n                          !solid &&\n                          (inRange ? \"hover:bg-primary/15\" : \"hover:bg-muted\"),\n                        outside && !unavailable && \"hover:bg-muted/60\",\n                        !outside &&\n                          solid &&\n                          \"bg-primary font-medium text-primary-foreground shadow-[inset_0_1px_0_rgb(255_255_255/0.18),0_1px_2px_rgb(0_0_0/0.12)] dark:shadow-[0_6px_16px_-6px_color-mix(in_oklab,var(--color-primary)_75%,transparent),inset_0_1px_0_rgb(255_255_255/0.18)] hover:bg-primary/90 focus-visible:ring-offset-1 focus-visible:ring-offset-popover\",\n                        !outside &&\n                          isPreviewEnd &&\n                          \"bg-popover font-medium ring-1 ring-primary/60 ring-inset\",\n                        isToday && !solid && \"font-semibold\",\n                      )}\n                    >\n                      {date.getDate()}\n                      {isToday && !outside && (\n                        <span\n                          aria-hidden=\"true\"\n                          className={cn(\n                            \"absolute bottom-1 left-1/2 size-1 -translate-x-1/2 rounded-full\",\n                            solid ? \"bg-primary-foreground\" : \"bg-primary\",\n                          )}\n                        />\n                      )}\n                    </button>\n                  </div>\n                );\n              })}\n            </div>\n          ))}\n        </div>\n      </div>\n    );\n  };\n\n  const summary = anchor && !previewing ? (\n    <>\n      <span className=\"font-medium text-foreground\">\n        {formatter(locale, FULL).format(anchor)}\n      </span>\n      <span className=\"text-muted-foreground\"> – {labels.selectEnd}</span>\n    </>\n  ) : shown ? (\n    <>\n      <span className=\"font-medium text-foreground\">\n        {formatDateRange(shown, locale)}\n      </span>\n      <span className=\"text-muted-foreground\">\n        {\" · \"}\n        {labels.days(rangeDays(shown))}\n      </span>\n    </>\n  ) : (\n    <span className=\"text-muted-foreground\">{labels.placeholder}</span>\n  );\n\n  const presetList = presetLayout !== \"none\" && (\n    <div\n      className={cn(\n        \"relative shrink-0\",\n        presetLayout === \"column\" ? \"w-36 border-e border-border/60\" : \"border-t border-border/60\",\n      )}\n    >\n      <div\n        ref={presetListRef}\n        role=\"listbox\"\n        aria-label={labels.presets}\n        aria-orientation={presetLayout === \"row\" ? \"horizontal\" : \"vertical\"}\n        data-slot=\"date-range-picker-presets\"\n        onKeyDown={onPresetKeyDown}\n        className={cn(\n          presetLayout === \"column\"\n            ? \"absolute inset-0 flex flex-col overflow-y-auto p-2\"\n            : \"flex gap-1.5 overflow-x-auto px-3 py-2.5 [mask-image:linear-gradient(to_right,transparent,#000_12px,#000_calc(100%-24px),transparent)] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\",\n        )}\n      >\n        {presets.map((preset, index) => {\n          const active = activePreset?.id === preset.id;\n          const tabbable = activePreset ? active : index === 0;\n          return (\n            <button\n              key={preset.id}\n              type=\"button\"\n              role=\"option\"\n              aria-selected={active}\n              data-preset={preset.id}\n              data-slot=\"date-range-picker-preset\"\n              data-active={active ? \"\" : undefined}\n              tabIndex={tabbable ? 0 : -1}\n              onClick={() => selectPreset(preset)}\n              className={cn(\n                \"shrink-0 text-[13px] whitespace-nowrap transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring/50 motion-reduce:transition-none\",\n                presetLayout === \"column\"\n                  ? \"flex h-9 w-full items-center rounded-md px-2.5 text-start sm:h-8\"\n                  : \"h-9 rounded-full border px-3 sm:h-8\",\n                active\n                  ? \"bg-primary/10 font-medium text-primary dark:bg-primary/15\"\n                  : \"text-muted-foreground hover:bg-muted hover:text-foreground\",\n                presetLayout === \"row\" &&\n                  (active ? \"border-primary/25\" : \"border-border/70\"),\n              )}\n            >\n              {preset.label}\n            </button>\n          );\n        })}\n      </div>\n    </div>\n  );\n\n  const calendar = (\n    <div className=\"relative min-w-0 flex-1 py-3 sm:py-4\">\n      <button\n        type=\"button\"\n        aria-label={labels.previousMonth}\n        disabled={!canGoBack}\n        onClick={() => navigate(-1)}\n        className=\"absolute start-2 top-3 z-20 flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-40 sm:top-4 sm:start-3\"\n      >\n        <IconChevronLeft aria-hidden=\"true\" className=\"size-4 rtl:rotate-180\" />\n      </button>\n      <button\n        type=\"button\"\n        aria-label={labels.nextMonth}\n        disabled={!canGoForward}\n        onClick={() => navigate(1)}\n        className=\"absolute end-2 top-3 z-20 flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-40 sm:top-4 sm:end-3\"\n      >\n        <IconChevronRight aria-hidden=\"true\" className=\"size-4 rtl:rotate-180\" />\n      </button>\n      <div\n        ref={monthsRef}\n        onKeyDown={onGridKeyDown}\n        className={cn(\"flex\", months === 2 && \"divide-x divide-border/70\")}\n      >\n        {visibleMonths.map(renderMonth)}\n      </div>\n    </div>\n  );\n\n  const compareRow = showCompare && (\n    <div\n      data-slot=\"date-range-picker-compare\"\n      data-state={draftCompare ? \"on\" : \"off\"}\n      className=\"flex shrink-0 flex-wrap items-center gap-x-3 gap-y-2 border-t border-border/60 px-4 py-2.5\"\n    >\n      <div className=\"flex items-center gap-2\">\n        <Switch\n          id={compareSwitchId}\n          checked={draftCompare}\n          onCheckedChange={toggleCompare}\n        />\n        <label\n          htmlFor={compareSwitchId}\n          className=\"cursor-pointer text-sm font-medium select-none\"\n        >\n          {labels.compare}\n        </label>\n      </div>\n      <div\n        role=\"radiogroup\"\n        aria-label={labels.compareMode}\n        aria-disabled={!draftCompare || undefined}\n        onKeyDown={(event) => {\n          if (![\"ArrowLeft\", \"ArrowRight\", \"ArrowUp\", \"ArrowDown\"].includes(event.key))\n            return;\n          event.preventDefault();\n          const next =\n            draftMode === \"previous-period\" ? \"previous-year\" : \"previous-period\";\n          changeMode(next);\n          (event.currentTarget.querySelector(\n            `[data-mode=\"${next}\"]`,\n          ) as HTMLButtonElement | null)?.focus();\n        }}\n        className={cn(\n          \"inline-flex h-7 items-center rounded-md bg-muted p-0.5 transition-opacity\",\n          !draftCompare && \"opacity-50\",\n        )}\n      >\n        {([\"previous-period\", \"previous-year\"] as const).map((option) => {\n          const checked = draftMode === option;\n          return (\n            <button\n              key={option}\n              type=\"button\"\n              role=\"radio\"\n              data-mode={option}\n              aria-checked={checked}\n              tabIndex={checked ? 0 : -1}\n              disabled={!draftCompare}\n              onClick={() => changeMode(option)}\n              className={cn(\n                \"h-6 rounded-[5px] px-2 text-xs whitespace-nowrap transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring/50 disabled:cursor-not-allowed motion-reduce:transition-none\",\n                checked\n                  ? \"bg-card font-medium text-foreground shadow-xs\"\n                  : \"text-muted-foreground hover:text-foreground\",\n              )}\n            >\n              {option === \"previous-period\"\n                ? labels.previousPeriod\n                : labels.previousYear}\n            </button>\n          );\n        })}\n      </div>\n      {shownCompare && (\n        <span className=\"ms-auto inline-flex items-center gap-2 text-xs text-muted-foreground tabular-nums\">\n          <span\n            aria-hidden=\"true\"\n            className=\"w-3.5 border-t-2 border-dashed border-muted-foreground/50\"\n          />\n          {formatDateRange(shownCompare, locale)}\n        </span>\n      )}\n    </div>\n  );\n\n  const footer = (\n    <div\n      data-slot=\"date-range-picker-footer\"\n      className=\"flex shrink-0 flex-wrap items-center gap-x-4 gap-y-2.5 border-t border-border/60 px-4 py-3\"\n    >\n      <p\n        aria-live=\"polite\"\n        className=\"min-w-0 flex-1 truncate text-sm tabular-nums\"\n      >\n        {summary}\n      </p>\n      {applyMode === \"confirm\" && (\n        <div className=\"flex shrink-0 gap-2 max-sm:w-full\">\n          <Button\n            type=\"button\"\n            variant=\"outline\"\n            size=\"sm\"\n            className=\"text-[13px] max-sm:h-10 max-sm:flex-1\"\n            onClick={() => {\n              cancelPending();\n              setOpen(false);\n            }}\n          >\n            {labels.cancel}\n          </Button>\n          <Button\n            type=\"button\"\n            size=\"sm\"\n            className=\"text-[13px] max-sm:h-10 max-sm:flex-1\"\n            disabled={!draftRange && !anchor && !value}\n            onClick={apply}\n          >\n            {labels.apply}\n          </Button>\n        </div>\n      )}\n    </div>\n  );\n\n  const panel = (\n    <div\n      ref={attachPanel}\n      id={inline ? panelId : undefined}\n      role={inline ? \"dialog\" : undefined}\n      aria-label={inline ? labels.dialog : undefined}\n      data-slot=\"date-range-picker-content\"\n      data-layout={months === 2 ? \"two-months\" : \"one-month\"}\n      onKeyDown={onPanelKeyDown}\n      style={{\n        width: inline\n          ? `min(${natural}px, 100cqw)`\n          : `min(${natural}px, var(--radix-popover-content-available-width, 100vw))`,\n      }}\n      className={cn(\n        \"flex flex-col overflow-hidden rounded-xl border border-border/70 bg-popover/90 text-popover-foreground shadow-xl backdrop-blur-md outline-none\",\n        \"motion-safe:animate-[date-range-picker-in_240ms_cubic-bezier(0.22,1,0.36,1)]\",\n        inline\n          ? cn(\n              \"absolute top-full z-30 mt-2\",\n              align === \"end\"\n                ? \"end-0 origin-top-right\"\n                : align === \"center\"\n                  ? \"left-1/2 -translate-x-1/2 origin-top\"\n                  : \"start-0 origin-top-left\",\n            )\n          : \"max-h-(--radix-popover-content-available-height) max-w-full origin-(--radix-popover-content-transform-origin) overflow-y-auto\",\n        contentClassName,\n      )}\n    >\n      <div\n        className={cn(\n          \"flex shrink-0\",\n          presetLayout === \"row\" ? \"flex-col-reverse\" : \"flex-row\",\n        )}\n      >\n        {presetList}\n        {calendar}\n      </div>\n      {compareRow}\n      {footer}\n    </div>\n  );\n\n  const dates = value ? formatDateRange(value, locale) : null;\n  const triggerLabel = formatLabel ? (\n    formatLabel(value ?? null, committedPreset)\n  ) : value ? (\n    committedPreset ? (\n      <>\n        <span className=\"shrink-0 font-medium\">{committedPreset.label}</span>\n        <span className=\"min-w-0 truncate text-muted-foreground tabular-nums @max-sm:hidden\">\n          {dates}\n        </span>\n      </>\n    ) : (\n      <span className=\"min-w-0 truncate font-medium tabular-nums\">{dates}</span>\n    )\n  ) : (\n    <span className=\"truncate text-muted-foreground\">{labels.placeholder}</span>\n  );\n\n  const triggerClasses = cn(\n    \"group/trigger inline-flex w-full min-w-0 items-center gap-2 rounded-md border border-input bg-card text-foreground shadow-xs transition-[color,background-color,border-color,box-shadow] outline-none hover:bg-muted focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 data-[state=open]:border-ring/60 data-[state=open]:ring-2 data-[state=open]:ring-ring/15 motion-reduce:transition-none\",\n    size === \"sm\"\n      ? \"h-10 px-2.5 text-[13px] sm:h-8\"\n      : \"h-11 px-3 text-base sm:h-9 sm:text-sm\",\n    triggerClassName,\n  );\n  const triggerContent = (\n    <>\n      <IconCalendarEvent\n        aria-hidden=\"true\"\n        className=\"size-4 shrink-0 text-muted-foreground\"\n      />\n      <span className=\"flex min-w-0 flex-1 items-baseline gap-2 text-start\">\n        {triggerLabel}\n      </span>\n      <IconChevronDown\n        aria-hidden=\"true\"\n        className=\"size-4 shrink-0 text-muted-foreground transition-transform duration-200 group-data-[state=open]/trigger:rotate-180 motion-reduce:transition-none\"\n      />\n    </>\n  );\n\n  return (\n    <div\n      data-slot=\"date-range-picker\"\n      data-state={open ? \"open\" : \"closed\"}\n      className={cn(\"relative inline-flex min-w-0 align-middle\", className)}\n      {...props}\n    >\n      <style>{keyframes}</style>\n      {name && value && (\n        <>\n          <input type=\"hidden\" name={`${name}[from]`} value={toISODate(value.from)} />\n          <input type=\"hidden\" name={`${name}[to]`} value={toISODate(value.to)} />\n        </>\n      )}\n      {inline ? (\n        <>\n          <button\n            ref={triggerRef}\n            type=\"button\"\n            id={id}\n            aria-label={ariaLabel}\n            aria-labelledby={ariaLabelledby}\n            aria-haspopup=\"dialog\"\n            aria-expanded={open}\n            aria-controls={open ? panelId : undefined}\n            data-slot=\"date-range-picker-trigger\"\n            data-state={open ? \"open\" : \"closed\"}\n            disabled={disabled}\n            onClick={() => setOpen(!open)}\n            className={triggerClasses}\n          >\n            {triggerContent}\n          </button>\n          {open && panel}\n        </>\n      ) : (\n        <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n          <PopoverPrimitive.Trigger asChild>\n            <button\n              ref={triggerRef}\n              type=\"button\"\n              id={id}\n              aria-label={ariaLabel}\n              aria-labelledby={ariaLabelledby}\n              data-slot=\"date-range-picker-trigger\"\n              disabled={disabled}\n              className={triggerClasses}\n            >\n              {triggerContent}\n            </button>\n          </PopoverPrimitive.Trigger>\n          <PopoverPrimitive.Portal>\n            <PopoverPrimitive.Content\n              align={align}\n              sideOffset={8}\n              collisionPadding={8}\n              aria-label={labels.dialog}\n              className=\"z-50 outline-none\"\n              onOpenAutoFocus={(event) => {\n                event.preventDefault();\n                if (!userOpened.current) return;\n                requestAnimationFrame(() => focusDay(focusedRef.current));\n              }}\n              onEscapeKeyDown={(event) => {\n                if (!anchor) return;\n                event.preventDefault();\n                cancelPending();\n              }}\n            >\n              {panel}\n            </PopoverPrimitive.Content>\n          </PopoverPrimitive.Portal>\n        </PopoverPrimitive.Root>\n      )}\n    </div>\n  );\n}\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/date-range-picker. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
