{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-wheel-picker",
  "title": "Date Wheel Picker",
  "description": "An iOS-style year/month/day wheel-based date picker, switchable between the Shamsi and Gregorian calendars, with a responsive Popover-on-desktop, Drawer-on-mobile composition.",
  "dependencies": [
    "@ncdai/react-wheel-picker",
    "@base-ui/react"
  ],
  "registryDependencies": [
    "utils",
    "@persianlabsui/wheel-picker",
    "@persianlabsui/popover",
    "@persianlabsui/drawer",
    "@persianlabsui/persian-date"
  ],
  "files": [
    {
      "path": "registry/base/ui/date-wheel-picker.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport {\n  Drawer,\n  DrawerPanel,\n  DrawerPopup,\n  DrawerTrigger,\n} from \"@/components/ui/drawer\"\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from \"@/components/ui/popover\"\nimport type { WheelPickerOption } from \"@/components/ui/wheel-picker\"\nimport { WheelPicker, WheelPickerWrapper } from \"@/components/ui/wheel-picker\"\nimport { useIsMobile } from \"@/hooks/use-media-query\"\nimport {\n  daysInMonth,\n  formatDate,\n  fromParts,\n  toParts,\n  toPersianDigits,\n  type CalendarType,\n  type DigitStyle,\n} from \"@/lib/persian-date\"\nimport { cn } from \"@/lib/utils\"\n\n/** Mirrors persian-date's `DigitStyle`, kept local so this file has no digit-only dependency on it. */\nexport type DateWheelPickerDigits = DigitStyle\n\nconst DEFAULT_MIN_YEAR: Record<CalendarType, number> = {\n  shamsi: 1300,\n  miladi: 1921,\n}\n\nconst DEFAULT_MAX_YEAR: Record<CalendarType, number> = {\n  shamsi: 1450,\n  miladi: 2071,\n}\n\n// A fixed, non-\"today\" default -- reading the current date at module load or\n// in a bare useState initializer would embed whatever date the server\n// happened to build/start at, which can differ from whatever date the client\n// happens to hydrate at and trigger a hydration mismatch. Nowruz 1403 is an\n// arbitrary, static stand-in; consumers that actually want \"today\" as the\n// initial value should compute it themselves, deferred via useEffect (see\n// the Demo example on the doc page), not rely on this component to do it.\nconst DEFAULT_VALUE = fromParts({ year: 1403, month: 1, day: 1 }, \"shamsi\")\n\nfunction label(value: number, digits: DateWheelPickerDigits): string {\n  const text = String(value)\n  return digits === \"fa\" ? toPersianDigits(text) : text\n}\n\nexport interface DateWheelPickerProps {\n  /** Current value in controlled mode. */\n  value?: Date\n  /** Initial value in uncontrolled mode. @default 1403/01/01 (Nowruz) */\n  defaultValue?: Date\n  onValueChange?: (date: Date) => void\n  /** @default \"shamsi\" */\n  calendarType?: CalendarType\n  /** Wheel label digit style. @default \"fa\" */\n  digits?: DateWheelPickerDigits\n  /** Lower bound of the year wheel, in `calendarType`'s years. @default 1300 (shamsi) / 1921 (miladi) */\n  minYear?: number\n  /** Upper bound of the year wheel, in `calendarType`'s years. @default 1450 (shamsi) / 2071 (miladi) */\n  maxYear?: number\n  /**\n   * Interval between year wheel options, e.g. 5 for a decade-jump picker.\n   * When greater than 1, `value`/`defaultValue`'s year must land on the\n   * stepped sequence (`minYear + n * yearStep`) to be selectable.\n   * @default 1\n   */\n  yearStep?: number\n  /**\n   * Whether the wheels loop past their ends (December back to January, the\n   * last day of the month back to the 1st, the last year back to the\n   * first). @default false\n   */\n  loop?: boolean\n  className?: string\n}\n\nfunction DateWheelPicker({\n  value: valueProp,\n  defaultValue = DEFAULT_VALUE,\n  onValueChange,\n  calendarType = \"shamsi\",\n  digits = \"fa\",\n  minYear,\n  maxYear,\n  yearStep = 1,\n  loop = false,\n  className,\n}: DateWheelPickerProps) {\n  const [uncontrolledValue, setUncontrolledValue] =\n    React.useState<Date>(defaultValue)\n  const isControlled = valueProp !== undefined\n  const value = isControlled ? valueProp : uncontrolledValue\n\n  const setValue = React.useCallback(\n    (next: Date) => {\n      if (!isControlled) setUncontrolledValue(next)\n      onValueChange?.(next)\n    },\n    [isControlled, onValueChange]\n  )\n\n  const resolvedMinYear = minYear ?? DEFAULT_MIN_YEAR[calendarType]\n  const resolvedMaxYear = maxYear ?? DEFAULT_MAX_YEAR[calendarType]\n\n  const parts = toParts(value, calendarType)\n\n  const yearOptions = React.useMemo<WheelPickerOption<number>[]>(() => {\n    const years: WheelPickerOption<number>[] = []\n    for (\n      let year = resolvedMinYear;\n      year <= resolvedMaxYear;\n      year += yearStep\n    ) {\n      years.push({ label: label(year, digits), value: year })\n    }\n    return years\n  }, [resolvedMinYear, resolvedMaxYear, yearStep, digits])\n\n  const monthOptions = React.useMemo<WheelPickerOption<number>[]>(() => {\n    return Array.from({ length: 12 }, (_, index) => {\n      const month = index + 1\n      const sample = fromParts(\n        { year: parts.year, month, day: 1 },\n        calendarType\n      )\n      return {\n        label: formatDate(sample, \"MMMM\", { calendarType, digits }),\n        value: month,\n      }\n    })\n  }, [parts.year, calendarType, digits])\n\n  const dayCount = daysInMonth(\n    fromParts({ year: parts.year, month: parts.month, day: 1 }, calendarType),\n    calendarType\n  )\n\n  const dayOptions = React.useMemo<WheelPickerOption<number>[]>(\n    () =>\n      Array.from({ length: dayCount }, (_, index) => {\n        const day = index + 1\n        return { label: label(day, digits), value: day }\n      }),\n    [dayCount, digits]\n  )\n\n  const day = Math.min(parts.day, dayCount)\n\n  function handleYearChange(nextYear: number) {\n    const nextDayCount = daysInMonth(\n      fromParts({ year: nextYear, month: parts.month, day: 1 }, calendarType),\n      calendarType\n    )\n    setValue(\n      fromParts(\n        {\n          year: nextYear,\n          month: parts.month,\n          day: Math.min(day, nextDayCount),\n        },\n        calendarType\n      )\n    )\n  }\n\n  function handleMonthChange(nextMonth: number) {\n    const nextDayCount = daysInMonth(\n      fromParts({ year: parts.year, month: nextMonth, day: 1 }, calendarType),\n      calendarType\n    )\n    setValue(\n      fromParts(\n        {\n          year: parts.year,\n          month: nextMonth,\n          day: Math.min(day, nextDayCount),\n        },\n        calendarType\n      )\n    )\n  }\n\n  function handleDayChange(nextDay: number) {\n    setValue(\n      fromParts(\n        { year: parts.year, month: parts.month, day: nextDay },\n        calendarType\n      )\n    )\n  }\n\n  return (\n    <WheelPickerWrapper className={cn(\"min-w-72\", className)}>\n      <WheelPicker\n        options={yearOptions}\n        value={parts.year}\n        onValueChange={handleYearChange}\n        infinite={loop}\n        classNames={{ optionItem: \"tabular-nums\" }}\n      />\n      <WheelPicker\n        options={monthOptions}\n        value={parts.month}\n        onValueChange={handleMonthChange}\n        infinite={loop}\n        classNames={{ optionItem: \"truncate px-1\" }}\n      />\n      <WheelPicker\n        options={dayOptions}\n        value={day}\n        onValueChange={handleDayChange}\n        infinite={loop}\n        classNames={{ optionItem: \"tabular-nums\" }}\n      />\n    </WheelPickerWrapper>\n  )\n}\n\n/**\n * A responsive wrapper around DateWheelPicker: a Popover trigger + content on\n * desktop, a Drawer trigger + panel on mobile. Follows the same\n * root/trigger/content composition as ResponsiveTimePicker, ResponsiveDialog,\n * and ResponsiveMenu.\n *\n * Note: Base UI's `render` prop only picks up children placed *inside* the\n * render target, not children passed to the wrapping trigger --\n * `<ResponsiveDateWheelPickerTrigger render={<Button/>}>{icon}</ResponsiveDateWheelPickerTrigger>`\n * silently renders an empty button. Put trigger content on the target\n * element itself instead: `<ResponsiveDateWheelPickerTrigger render={<Button>{icon}</Button>} />`.\n */\ntype ResponsiveDateWheelPickerContextValue = { isDesktop: boolean }\n\nconst ResponsiveDateWheelPickerContext =\n  React.createContext<ResponsiveDateWheelPickerContextValue | null>(null)\n\nfunction useResponsiveDateWheelPickerContext() {\n  const context = React.useContext(ResponsiveDateWheelPickerContext)\n  if (!context) {\n    throw new Error(\n      \"ResponsiveDateWheelPicker components must be used within <ResponsiveDateWheelPicker>\"\n    )\n  }\n  return context\n}\n\ntype ResponsiveDateWheelPickerProps = {\n  children: React.ReactNode\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n}\n\nfunction ResponsiveDateWheelPicker({\n  children,\n  open,\n  defaultOpen,\n  onOpenChange,\n}: ResponsiveDateWheelPickerProps) {\n  const isDesktop = !useIsMobile()\n  const contextValue = React.useMemo(() => ({ isDesktop }), [isDesktop])\n\n  return (\n    <ResponsiveDateWheelPickerContext.Provider value={contextValue}>\n      {isDesktop ? (\n        <Popover\n          open={open}\n          defaultOpen={defaultOpen}\n          onOpenChange={onOpenChange}\n        >\n          {children}\n        </Popover>\n      ) : (\n        <Drawer\n          open={open}\n          defaultOpen={defaultOpen}\n          onOpenChange={onOpenChange}\n        >\n          {children}\n        </Drawer>\n      )}\n    </ResponsiveDateWheelPickerContext.Provider>\n  )\n}\n\nfunction ResponsiveDateWheelPickerTrigger(\n  props: React.ComponentProps<typeof PopoverTrigger>\n) {\n  const { isDesktop } = useResponsiveDateWheelPickerContext()\n  return isDesktop ? (\n    <PopoverTrigger {...props} />\n  ) : (\n    <DrawerTrigger {...(props as React.ComponentProps<typeof DrawerTrigger>)} />\n  )\n}\n\ntype ResponsiveDateWheelPickerContentProps = DateWheelPickerProps & {\n  align?: React.ComponentProps<typeof PopoverContent>[\"align\"]\n  side?: React.ComponentProps<typeof PopoverContent>[\"side\"]\n  sideOffset?: number\n}\n\nfunction ResponsiveDateWheelPickerContent({\n  align = \"center\",\n  side = \"bottom\",\n  sideOffset = 6,\n  className,\n  ...dateWheelPickerProps\n}: ResponsiveDateWheelPickerContentProps) {\n  const { isDesktop } = useResponsiveDateWheelPickerContext()\n\n  if (isDesktop) {\n    return (\n      <PopoverContent\n        align={align}\n        side={side}\n        sideOffset={sideOffset}\n        className=\"w-auto p-3\"\n      >\n        <DateWheelPicker className={className} {...dateWheelPickerProps} />\n      </PopoverContent>\n    )\n  }\n\n  return (\n    <DrawerPopup showBar>\n      <DrawerPanel\n        scrollable={false}\n        className={cn(\"flex items-center justify-center pb-8\")}\n      >\n        <DateWheelPicker className={className} {...dateWheelPickerProps} />\n      </DrawerPanel>\n    </DrawerPopup>\n  )\n}\n\nexport {\n  DateWheelPicker,\n  ResponsiveDateWheelPicker,\n  ResponsiveDateWheelPickerContent,\n  ResponsiveDateWheelPickerTrigger,\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/base/hooks/use-media-query.ts",
      "content": "\"use client\"\n\nimport { useCallback, useSyncExternalStore } from \"react\"\n\nconst BREAKPOINTS = {\n  \"2xl\": 1536,\n  \"3xl\": 1600,\n  \"4xl\": 2000,\n  lg: 1024,\n  md: 800,\n  sm: 640,\n  xl: 1280,\n} as const\n\ntype Breakpoint = keyof typeof BREAKPOINTS\ntype BreakpointQuery =\n  Breakpoint | `max-${Breakpoint}` | `${Breakpoint}:max-${Breakpoint}`\n\nfunction resolveMin(value: Breakpoint | number): string {\n  const px = typeof value === \"number\" ? value : BREAKPOINTS[value]\n  return `(min-width: ${px}px)`\n}\n\nfunction resolveMax(value: Breakpoint | number): string {\n  const px = typeof value === \"number\" ? value : BREAKPOINTS[value]\n  return `(max-width: ${px - 1}px)`\n}\n\n/**\n * @internal exported for unit tests; not part of the public API.\n */\nexport function parseQuery(\n  query: BreakpointQuery | MediaQueryInput | (string & {})\n): string {\n  if (typeof query !== \"string\") {\n    const parts: string[] = []\n    if (query.min != null) parts.push(resolveMin(query.min))\n    if (query.max != null) parts.push(resolveMax(query.max))\n    if (query.pointer === \"coarse\") parts.push(\"(pointer: coarse)\")\n    if (query.pointer === \"fine\") parts.push(\"(pointer: fine)\")\n    if (parts.length === 0) return \"(min-width: 0px)\"\n    return parts.join(\" and \")\n  }\n\n  if (query.startsWith(\"(\")) return query\n\n  const parts: string[] = []\n  for (const segment of query.split(\":\")) {\n    if (segment.startsWith(\"max-\")) {\n      const bp = segment.slice(4)\n      if (bp in BREAKPOINTS) parts.push(resolveMax(bp as Breakpoint))\n    } else if (segment in BREAKPOINTS) {\n      parts.push(resolveMin(segment as Breakpoint))\n    }\n  }\n\n  return parts.length > 0 ? parts.join(\" and \") : query\n}\n\nfunction getServerSnapshot(): boolean {\n  return false\n}\n\nexport type MediaQueryInput = {\n  min?: Breakpoint | number\n  max?: Breakpoint | number\n  /** Touch-like input (finger). Use \"fine\" for mouse/trackpad. */\n  pointer?: \"coarse\" | \"fine\"\n}\n\n/** Tracks a CSS media query with Tailwind-like breakpoint syntax. Returns `false` during SSR. */\nexport function useMediaQuery(\n  query: BreakpointQuery | MediaQueryInput | (string & {})\n): boolean {\n  const mediaQuery = parseQuery(query)\n\n  const subscribe = useCallback(\n    (callback: () => void) => {\n      if (typeof window === \"undefined\") return () => {}\n      const mql = window.matchMedia(mediaQuery)\n      mql.addEventListener(\"change\", callback)\n      return () => mql.removeEventListener(\"change\", callback)\n    },\n    [mediaQuery]\n  )\n\n  const getSnapshot = useCallback(() => {\n    if (typeof window === \"undefined\") return false\n    return window.matchMedia(mediaQuery).matches\n  }, [mediaQuery])\n\n  return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)\n}\n\nexport function useIsMobile(): boolean {\n  return useMediaQuery(\"max-md\")\n}\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:ui"
}