{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-autocomplete",
  "title": "Autocomplete",
  "description": "Busca autocomplete async — ReUI Autocomplete.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@lema-ds/popover",
    "@lema-ds/input",
    "@lema-ds/skeleton"
  ],
  "files": [
    {
      "path": "components/ds/ds-autocomplete.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Popover, PopoverAnchor, PopoverContent } from \"@/components/ui/popover\"\nimport { Input } from \"@/components/ui/input\"\nimport { CheckIcon, SearchIcon } from \"lucide-react\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\n\n// ── Types ──────────────────────────────────────────────────────────────────\n\nexport interface AutocompleteOption {\n  label: string\n  value: string\n}\n\nexport interface AutocompleteProps extends React.HTMLAttributes<HTMLDivElement> {\n  options: AutocompleteOption[]\n  value?: string\n  onValueChange?: (value: string) => void\n  placeholder?: string\n  loading?: boolean\n}\n\n// ── Component ──────────────────────────────────────────────────────────────\n\nexport function Autocomplete({\n  className,\n  options,\n  value,\n  onValueChange,\n  placeholder = \"Search...\",\n  loading = false,\n  ...props\n}: AutocompleteProps) {\n  const [open, setOpen] = React.useState(false)\n  const [query, setQuery] = React.useState(\"\")\n  const listboxId = React.useId()\n  const [activeIndex, setActiveIndex] = React.useState(-1)\n\n  const filtered = options.filter((o) =>\n    o.label.toLowerCase().includes(query.toLowerCase())\n  )\n  const displayValue = value\n    ? (options.find((o) => o.value === value)?.label ?? query)\n    : query\n\n  return (\n    <div\n      data-slot=\"autocomplete\"\n      className={cn(\"w-full\", className)}\n      {...props}\n    >\n      <Popover open={open} onOpenChange={setOpen}>\n        <PopoverAnchor asChild>\n          <div className=\"relative\">\n            <SearchIcon\n              className=\"pointer-events-none absolute top-1/2 left-3 z-10 size-4 -translate-y-1/2 text-muted-foreground\"\n              aria-hidden=\"true\"\n            />\n            <Input\n              role=\"combobox\"\n              aria-expanded={open}\n              aria-controls={listboxId}\n              aria-activedescendant={\n                activeIndex >= 0\n                  ? `${listboxId}-${filtered[activeIndex]?.value}`\n                  : undefined\n              }\n              aria-autocomplete=\"list\"\n              aria-label={placeholder}\n              placeholder={placeholder}\n              value={displayValue}\n              onChange={(e) => {\n                setQuery(e.target.value)\n                setActiveIndex(-1)\n                setOpen(true)\n              }}\n              onFocus={() => setOpen(true)}\n              onKeyDown={(e) => {\n                if (e.key === \"ArrowDown\") {\n                  e.preventDefault()\n                  setActiveIndex((i) => Math.min(i + 1, filtered.length - 1))\n                }\n                if (e.key === \"ArrowUp\") {\n                  e.preventDefault()\n                  setActiveIndex((i) => Math.max(i - 1, 0))\n                }\n                if (e.key === \"Enter\" && activeIndex >= 0) {\n                  const opt = filtered[activeIndex]\n                  if (opt) {\n                    onValueChange?.(opt.value)\n                    setQuery(opt.label)\n                    setOpen(false)\n                  }\n                }\n                if (e.key === \"Escape\") setOpen(false)\n              }}\n              className=\"pl-9\"\n            />\n          </div>\n        </PopoverAnchor>\n        <PopoverContent\n          className=\"w-[var(--radix-popover-anchor-width)] p-1\"\n          align=\"start\"\n          onOpenAutoFocus={(e) => e.preventDefault()}\n        >\n          {loading ? (\n            <div className=\"flex flex-col gap-1 p-1\">\n              <Skeleton className=\"h-7 w-full\" />\n              <Skeleton className=\"h-7 w-full\" />\n            </div>\n          ) : filtered.length === 0 ? (\n            <span className=\"p-2 text-xs text-muted-foreground\">\n              No results\n            </span>\n          ) : (\n            <div id={listboxId} role=\"listbox\" className=\"flex flex-col gap-1\">\n              {filtered.map((opt, idx) => (\n                <button\n                  key={opt.value}\n                  id={`${listboxId}-${opt.value}`}\n                  type=\"button\"\n                  role=\"option\"\n                  aria-selected={value === opt.value}\n                  data-active={idx === activeIndex ? \"true\" : undefined}\n                  onClick={() => {\n                    onValueChange?.(opt.value)\n                    setQuery(opt.label)\n                    setOpen(false)\n                  }}\n                  className={cn(\n                    \"flex items-center justify-between 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                    value === opt.value && \"bg-muted\",\n                    idx === activeIndex && \"bg-muted\"\n                  )}\n                >\n                  <span className=\"truncate\">{opt.label}</span>\n                  {value === opt.value && (\n                    <CheckIcon className=\"size-3.5\" aria-hidden=\"true\" />\n                  )}\n                </button>\n              ))}\n            </div>\n          )}\n        </PopoverContent>\n      </Popover>\n    </div>\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
