{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "month-picker",
  "title": "Month Picker",
  "description": "A year-at-a-glance grid of twelve months with year paging and min, max and unavailable months, giving a YYYY-MM value.",
  "registryDependencies": [
    "@tealmac/period-grid",
    "@tealmac/date-time-core",
    "@tealmac/date-time-segments"
  ],
  "files": [
    {
      "path": "registry/tealmac/month-picker.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronLeft, ChevronRight } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport {\n  monthNames,\n  parseMonth,\n  resolveLocale,\n  today as todayISO,\n  toMonth,\n} from \"@/registry/tealmac/date-time-core\"\nimport { useControllableValue } from \"@/registry/tealmac/date-time-segments\"\nimport { PeriodGrid, StepButton } from \"@/registry/tealmac/period-grid\"\n\nexport interface MonthPickerProps extends Omit<\n  React.ComponentProps<\"div\">,\n  \"defaultValue\" | \"onChange\" | \"role\"\n> {\n  /** Controlled month, \"2026-10\", or null. */\n  value?: string | null\n  defaultValue?: string | null\n  onValueChange?: (value: string | null) => void\n  /** Year shown first. Defaults to the year of the value or today. */\n  defaultYear?: number\n  /** Earliest and latest selectable month, \"YYYY-MM\". */\n  min?: string\n  max?: string\n  isMonthUnavailable?: (month: string) => boolean\n  locale?: string\n  /** \"short\" (Oct) or \"long\" (October) labels. */\n  labelWidth?: \"short\" | \"long\"\n  today?: string\n  label?: string\n}\n\nfunction MonthPicker({\n  value,\n  defaultValue = null,\n  onValueChange,\n  defaultYear,\n  min,\n  max,\n  isMonthUnavailable,\n  locale,\n  labelWidth = \"short\",\n  today,\n  label = \"Month\",\n  className,\n  ...props\n}: MonthPickerProps) {\n  const loc = resolveLocale(locale)\n  const [selected, setSelected] = useControllableValue<string | null>(\n    value,\n    defaultValue,\n    onValueChange\n  )\n  const now = (today ?? todayISO()).slice(0, 7)\n  const sel = parseMonth(selected)\n  const [year, setYear] = React.useState(\n    defaultYear ?? sel?.y ?? Number(now.slice(0, 4))\n  )\n  const [focus, setFocus] = React.useState(\n    selected ?? toMonth(year, parseMonth(now)?.m ?? 1)\n  )\n  const short = React.useMemo(\n    () => monthNames(loc, labelWidth),\n    [loc, labelWidth]\n  )\n  const long = React.useMemo(() => monthNames(loc, \"long\"), [loc])\n  const yearLabel = new Intl.NumberFormat(loc, { useGrouping: false }).format(\n    year\n  )\n\n  const cells = Array.from({ length: 12 }, (_, i) => {\n    const id = toMonth(year, i + 1)\n    return {\n      id,\n      label: short[i],\n      ariaLabel: `${long[i]} ${yearLabel}`,\n      selected: id === selected,\n      current: id === now,\n      disabled:\n        (min !== undefined && id < min) ||\n        (max !== undefined && id > max) ||\n        !!isMonthUnavailable?.(id),\n    }\n  })\n  const focusId = focus.startsWith(`${String(year).padStart(4, \"0\")}-`)\n    ? focus\n    : toMonth(year, 1)\n\n  function shiftMonths(id: string, delta: number) {\n    const p = parseMonth(id)!\n    const idx = p.y * 12 + (p.m - 1) + delta\n    return toMonth(Math.floor(idx / 12), (idx % 12) + 1)\n  }\n\n  const prevDisabled = min !== undefined && toMonth(year - 1, 12) < min\n  const nextDisabled = max !== undefined && toMonth(year + 1, 1) > max\n  const headingId = React.useId()\n\n  return (\n    <div\n      role=\"group\"\n      aria-label={label}\n      data-slot=\"month-picker\"\n      className={cn(\n        \"bg-background inline-flex w-72 max-w-full flex-col gap-2 rounded-lg p-3\",\n        className\n      )}\n      {...props}\n    >\n      <div className=\"flex h-8 items-center justify-between\">\n        <StepButton\n          label=\"Previous year\"\n          disabled={prevDisabled}\n          onClick={() => setYear(year - 1)}\n        >\n          <ChevronLeft className=\"size-4 rtl:rotate-180\" aria-hidden=\"true\" />\n        </StepButton>\n        <h2\n          id={headingId}\n          aria-live=\"polite\"\n          className=\"text-sm font-medium tabular-nums\"\n        >\n          {yearLabel}\n        </h2>\n        <StepButton\n          label=\"Next year\"\n          disabled={nextDisabled}\n          onClick={() => setYear(year + 1)}\n        >\n          <ChevronRight className=\"size-4 rtl:rotate-180\" aria-hidden=\"true\" />\n        </StepButton>\n      </div>\n      <PeriodGrid\n        label={`${label}, ${yearLabel}`}\n        cells={cells}\n        columns={3}\n        focusId={focusId}\n        onFocusChange={setFocus}\n        onNavigate={(delta, id) => {\n          const next = shiftMonths(id, delta)\n          setFocus(next)\n          setYear(parseMonth(next)!.y)\n        }}\n        onPage={(dir) => {\n          setYear(year + dir)\n          setFocus(toMonth(year + dir, parseMonth(focusId)!.m))\n        }}\n        onSelect={(id) => setSelected(id)}\n      />\n    </div>\n  )\n}\n\nexport { MonthPicker }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}