{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-cascader",
  "title": "Cascader",
  "description": "Seleção em cascata níveis — ReUI Cascader.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "@lema-ds/popover",
    "@lema-ds/button",
    "@lema-ds/skeleton",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-cascader.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from \"@/components/ui/popover\"\nimport { Button } from \"@/components/ui/button\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport { ChevronRightIcon, CheckIcon } from \"lucide-react\"\n\n// ── Types ──────────────────────────────────────────────────────────────────\n\nexport interface CascaderOption {\n  label: string\n  value: string\n  children?: CascaderOption[]\n}\n\nexport interface CascaderProps\n  extends\n    React.HTMLAttributes<HTMLDivElement>,\n    VariantProps<typeof cascaderVariants> {\n  options: CascaderOption[]\n  value?: string[]\n  onValueChange?: (value: string[]) => void\n  placeholder?: string\n  locale?: UILocale\n  loading?: boolean\n}\n\n// ── Variants ───────────────────────────────────────────────────────────────\n\nexport const cascaderVariants = cva(\"w-fit\", {\n  variants: {\n    size: {\n      sm: \"text-xs\",\n      md: \"text-sm\",\n      lg: \"text-sm\",\n    },\n  },\n  defaultVariants: { size: \"md\" },\n})\n\n// ── Helpers ────────────────────────────────────────────────────────────────\n\nfunction getSkeletonDims() {\n  return { trigger: \"h-9 w-48\", panel: \"h-40 w-64\" }\n}\n\n// ── Component ──────────────────────────────────────────────────────────────\n\nexport function Cascader({\n  className,\n  options,\n  value = [],\n  onValueChange,\n  placeholder,\n  locale: localeProp,\n  loading = false,\n  size = \"md\",\n  ...props\n}: CascaderProps) {\n  const locale = useUILocale(localeProp)\n  const t = UI_I18N[locale].select\n  const resolvedPlaceholder = placeholder ?? t.placeholder\n  const triggerId = React.useId()\n  const [open, setOpen] = React.useState(false)\n  const [path, setPath] = React.useState<string[]>(value)\n\n  // eslint-disable-next-line react-hooks/set-state-in-effect\n  React.useEffect(() => setPath(value), [value])\n\n  if (loading) {\n    const dims = getSkeletonDims()\n    return <Skeleton className={cn(dims.trigger, \"rounded-xl\", className)} />\n  }\n\n  const findPath = (\n    opts: CascaderOption[],\n    target: string[]\n  ): CascaderOption[] => {\n    const res: CascaderOption[] = []\n    let cur = opts\n    for (const v of target) {\n      const f = cur.find((o) => o.value === v)\n      if (!f) break\n      res.push(f)\n      cur = f.children ?? []\n    }\n    return res\n  }\n\n  const handleSelect = (level: number, opt: CascaderOption) => {\n    const next = [...path.slice(0, level), opt.value]\n    if (opt.children && opt.children.length > 0) {\n      setPath(next)\n    } else {\n      setPath(next)\n      onValueChange?.(next)\n      setOpen(false)\n    }\n  }\n\n  const display =\n    findPath(options, path)\n      .map((o) => o.label)\n      .join(\" / \") || placeholder\n\n  const renderLevel = (opts: CascaderOption[], level: number) => (\n    <div\n      key={level}\n      role=\"group\"\n      aria-label={`Level ${level + 1}`}\n      className=\"min-w-32 border-r p-1 last:border-0 sm:min-w-40\"\n    >\n      <div\n        role=\"listbox\"\n        aria-orientation=\"vertical\"\n        className=\"flex flex-col gap-0.5\"\n      >\n        {opts.map((opt) => {\n          const active = path[level] === opt.value\n          const hasChildren = !!opt.children?.length\n          return (\n            <button\n              key={opt.value}\n              type=\"button\"\n              role=\"option\"\n              aria-selected={active}\n              onClick={() => handleSelect(level, opt)}\n              onKeyDown={(e) => {\n                if (e.key === \"Enter\" || e.key === \" \") {\n                  e.preventDefault()\n                  handleSelect(level, opt)\n                }\n                if (e.key === \"Escape\") setOpen(false)\n                if (e.key === \"ArrowRight\" && hasChildren)\n                  handleSelect(level, opt)\n              }}\n              className={cn(\n                \"flex h-8 w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none\",\n                active && \"bg-muted\"\n              )}\n            >\n              <span className=\"truncate\">{opt.label}</span>\n              <span className=\"flex items-center gap-1\">\n                {active && !opt.children && (\n                  <CheckIcon className=\"size-3.5\" aria-hidden=\"true\" />\n                )}\n                {opt.children && (\n                  <ChevronRightIcon\n                    className=\"size-3.5 text-muted-foreground\"\n                    aria-hidden=\"true\"\n                  />\n                )}\n              </span>\n            </button>\n          )\n        })}\n      </div>\n    </div>\n  )\n\n  const levels: CascaderOption[][] = []\n  let cur = options\n  for (let i = 0; i <= path.length; i++) {\n    levels.push(cur)\n    const next = cur.find((o) => o.value === path[i])\n    if (next?.children) cur = next.children\n    else break\n  }\n\n  return (\n    <div\n      data-slot=\"cascader\"\n      className={cn(cascaderVariants({ size }), className)}\n      {...props}\n    >\n      <Popover open={open} onOpenChange={setOpen}>\n        <PopoverTrigger asChild>\n          <Button\n            id={triggerId}\n            variant=\"outline\"\n            aria-haspopup=\"listbox\"\n            aria-expanded={open}\n            aria-label={resolvedPlaceholder}\n            className=\"min-w-48 justify-between rounded-xl\"\n          >\n            <span className=\"truncate\">{display}</span>\n            <ChevronRightIcon\n              className=\"size-4 rotate-90 text-muted-foreground\"\n              aria-hidden=\"true\"\n            />\n          </Button>\n        </PopoverTrigger>\n        <PopoverContent\n          className=\"flex max-w-[calc(100vw-2rem)] gap-0 overflow-x-auto p-0\"\n          align=\"start\"\n          aria-labelledby={triggerId}\n        >\n          {levels.map((lvl, idx) => renderLevel(lvl, idx))}\n        </PopoverContent>\n      </Popover>\n    </div>\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
