{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-multi-select",
  "title": "MultiSelect",
  "description": "Combobox que permite selecionar múltiplos itens de uma lista.",
  "dependencies": [
    "lucide-react",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@lema-ds/popover",
    "@lema-ds/command",
    "@lema-ds/badge",
    "@lema-ds/button",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-multi-select.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { CheckIcon, ChevronDownIcon, XIcon } from \"lucide-react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"@/components/ui/button\"\nimport { Badge } from \"@/components/ui/badge\"\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from \"@/components/ui/popover\"\nimport {\n  Command,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandList,\n  CommandSeparator,\n} from \"@/components/ui/command\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\n\n// ── Types ──\n\nexport interface Option {\n  label: string\n  value: string\n  icon?: React.ElementType\n}\n\nexport const multiSelectVariants = cva(\n  \"m-1 transition-colors hover:bg-muted focus:bg-muted\",\n  {\n    variants: {\n      size: {\n        sm: \"h-5 px-1 text-xs\",\n        md: \"h-6 px-2 text-xs\",\n        lg: \"h-8 px-3 text-sm\",\n      },\n    },\n    defaultVariants: {\n      size: \"md\",\n    },\n  }\n)\n\nexport interface MultiSelectProps\n  extends\n    Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"onChange\" | \"value\">,\n    VariantProps<typeof multiSelectVariants> {\n  options: Option[]\n  value: string[]\n  onChange: (value: string[]) => void\n  placeholder?: string\n  maxCount?: number\n  locale?: UILocale\n}\n\n// ── Component ──\n\nexport const MultiSelect = React.forwardRef<\n  HTMLButtonElement,\n  MultiSelectProps\n>(\n  (\n    {\n      options,\n      value,\n      onChange,\n      placeholder,\n      maxCount = 3,\n      locale: localeProp,\n      size = \"md\",\n      className,\n      disabled,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const [open, setOpen] = React.useState(false)\n\n    const t = UI_I18N[locale]\n    const currentPlaceholder = placeholder ?? t.select.placeholder\n    const searchPlaceholder = t.select.search\n    const noResults = t.select.noResults\n\n    const selectedValues = new Set(value)\n\n    const handleSelect = (currentValue: string) => {\n      const newSelected = new Set(selectedValues)\n      if (newSelected.has(currentValue)) {\n        newSelected.delete(currentValue)\n      } else {\n        newSelected.add(currentValue)\n      }\n      onChange(Array.from(newSelected))\n    }\n\n    const handleClear = (e: React.MouseEvent) => {\n      e.stopPropagation()\n      onChange([])\n    }\n\n    const handleRemoveOption = (e: React.MouseEvent, optionValue: string) => {\n      e.stopPropagation()\n      const newSelected = new Set(selectedValues)\n      newSelected.delete(optionValue)\n      onChange(Array.from(newSelected))\n    }\n\n    const selectedOptions = options.filter((opt) =>\n      selectedValues.has(opt.value)\n    )\n\n    return (\n      <Popover open={open} onOpenChange={setOpen}>\n        <PopoverTrigger asChild>\n          <Button\n            ref={ref}\n            variant=\"outline\"\n            role=\"combobox\"\n            aria-expanded={open}\n            aria-haspopup=\"listbox\"\n            aria-label={currentPlaceholder}\n            className={cn(\n              \"h-auto min-h-10 w-full justify-between p-1\",\n              disabled && \"pointer-events-none opacity-50\",\n              className\n            )}\n            disabled={disabled}\n            {...props}\n          >\n            <div className=\"flex flex-wrap items-center gap-1 overflow-hidden pl-2\">\n              {selectedOptions.length > 0 ? (\n                <>\n                  {selectedOptions.slice(0, maxCount).map((option) => (\n                    <Badge\n                      key={option.value}\n                      variant=\"secondary\"\n                      className={cn(multiSelectVariants({ size }))}\n                    >\n                      {option.icon && (\n                        <option.icon className=\"mr-1 size-3 text-muted-foreground\" />\n                      )}\n                      {option.label}\n                      <div\n                        role=\"button\"\n                        tabIndex={0}\n                        className=\"ml-1 rounded-full ring-offset-background outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2\"\n                        onKeyDown={(e) => {\n                          if (e.key === \"Enter\") {\n                            handleRemoveOption(\n                              e as unknown as React.MouseEvent,\n                              option.value\n                            )\n                          }\n                        }}\n                        onMouseDown={(e) => e.preventDefault()}\n                        onClick={(e) => handleRemoveOption(e, option.value)}\n                      >\n                        <XIcon className=\"size-3 text-muted-foreground hover:text-foreground\" />\n                        <span className=\"sr-only\">{t.badge.remove}</span>\n                      </div>\n                    </Badge>\n                  ))}\n                  {selectedOptions.length > maxCount && (\n                    <Badge\n                      variant=\"secondary\"\n                      className={cn(multiSelectVariants({ size }))}\n                    >\n                      +{selectedOptions.length - maxCount} {t.select.selected}\n                    </Badge>\n                  )}\n                </>\n              ) : (\n                <span className=\"px-2 font-normal text-muted-foreground\">\n                  {currentPlaceholder}\n                </span>\n              )}\n            </div>\n            <div className=\"flex items-center gap-1 pr-2\">\n              {selectedValues.size > 0 && !disabled && (\n                <div\n                  role=\"button\"\n                  tabIndex={0}\n                  className=\"rounded-full p-1 text-muted-foreground hover:text-foreground focus:ring-2 focus:ring-ring focus:outline-none\"\n                  onClick={handleClear}\n                  onKeyDown={(e) => {\n                    if (e.key === \"Enter\")\n                      handleClear(e as unknown as React.MouseEvent)\n                  }}\n                >\n                  <XIcon className=\"size-4\" />\n                  <span className=\"sr-only\">{t.combobox.clearSelection}</span>\n                </div>\n              )}\n              <ChevronDownIcon className=\"size-4 text-muted-foreground opacity-50\" />\n            </div>\n          </Button>\n        </PopoverTrigger>\n        <PopoverContent\n          className=\"w-(--radix-popover-trigger-width) p-0\"\n          align=\"start\"\n        >\n          <Command>\n            <CommandInput placeholder={searchPlaceholder} />\n            <CommandList>\n              <CommandEmpty>{noResults}</CommandEmpty>\n              <CommandGroup>\n                {options.map((option) => {\n                  const isSelected = selectedValues.has(option.value)\n                  return (\n                    <CommandItem\n                      key={option.value}\n                      value={option.label}\n                      onSelect={() => handleSelect(option.value)}\n                    >\n                      <div\n                        className={cn(\n                          \"mr-2 flex size-4 items-center justify-center rounded-sm border border-primary\",\n                          isSelected\n                            ? \"bg-primary text-primary-foreground\"\n                            : \"opacity-50 [&_svg]:invisible\"\n                        )}\n                      >\n                        <CheckIcon className={cn(\"size-3\")} />\n                      </div>\n                      {option.icon && (\n                        <option.icon className=\"mr-2 size-4 text-muted-foreground\" />\n                      )}\n                      <span>{option.label}</span>\n                    </CommandItem>\n                  )\n                })}\n              </CommandGroup>\n              {selectedValues.size > 0 && (\n                <>\n                  <CommandSeparator />\n                  <CommandGroup>\n                    <CommandItem\n                      onSelect={() => onChange([])}\n                      className=\"justify-center text-center text-sm font-medium\"\n                    >\n                      {t.combobox.clearAll}\n                    </CommandItem>\n                  </CommandGroup>\n                </>\n              )}\n            </CommandList>\n          </Command>\n        </PopoverContent>\n      </Popover>\n    )\n  }\n)\nMultiSelect.displayName = \"MultiSelect\"\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
