{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-select-list",
  "title": "Select List",
  "description": "A searchable list of items with selection state, support for groups, icons and virtual scrolling behavior.",
  "dependencies": [
    "lucide-react",
    "@tanstack/react-virtual",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@lema-ds/button",
    "@lema-ds/input",
    "@lema-ds/badge",
    "@lema-ds/skeleton",
    "@lema-ds/ds-empty",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-select-list.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Search, X, Check } from \"lucide-react\"\nimport { useVirtualizer } from \"@tanstack/react-virtual\"\nimport { cva } from \"class-variance-authority\"\nimport type { VariantProps } from \"class-variance-authority\"\nimport type { HTMLAttributes, ReactNode } from \"react\"\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\nimport { Input } from \"@/components/ui/input\"\nimport { Button } from \"@/components/ui/button\"\nimport { Badge } from \"@/components/ui/badge\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport { Empty } from \"@/components/ui/ds-empty\"\n\n// ── Types ──────────────────────────────────────────────────────────────────\n\nexport interface SelectListItem {\n  id: string | number\n  name: string\n  icon?: ReactNode\n  iconColor?: string\n  group?: string\n  value?: string | number\n  slug?: string\n}\n\nexport interface SelectListProps\n  extends\n    VariantProps<typeof selectListContainerVariants>,\n    Omit<HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n  data: SelectListItem[]\n  selectedId?: string | number\n  height?: number\n  size?: \"sm\" | \"md\" | \"lg\"\n  debounce?: number\n  placeholder?: string\n  intent?: \"default\" | \"primary\" | \"secondary\" | \"destructive\"\n  disabled?: boolean\n  loading?: boolean\n  onSelect: (item: SelectListItem) => void\n  onSearch?: (value: string) => void\n  search?: string\n  emptyMessage?: string\n  locale?: UILocale\n}\n\n// ── Variants ───────────────────────────────────────────────────────────────\n\nexport const selectListContainerVariants = cva(\n  \"relative flex w-full flex-col gap-4 font-sans transition-all duration-300 outline-none\",\n  {\n    variants: {\n      disabled: { true: \"pointer-events-none cursor-not-allowed opacity-50\" },\n      loading: { true: \"pointer-events-none\" },\n    },\n    defaultVariants: { disabled: false },\n  }\n)\n\nexport const selectListItemVariants = cva(\n  \"group flex cursor-default items-center justify-between border-b border-border transition-colors duration-150 last:border-b-0\",\n  {\n    variants: {\n      isSelected: {\n        true: \"bg-muted/50\",\n        false: \"bg-background hover:bg-muted/30\",\n      },\n      size: {\n        sm: \"gap-2 px-3 py-3\",\n        md: \"gap-2 px-4 py-4\",\n        lg: \"gap-3 px-5 py-5\",\n      },\n      intent: {\n        default: \"\",\n        primary: \"\",\n        secondary: \"\",\n        destructive: \"\",\n      },\n    },\n    compoundVariants: [\n      { isSelected: true, intent: \"primary\", className: \"bg-primary/10\" },\n      { isSelected: false, intent: \"primary\", className: \"hover:bg-primary/5\" },\n      { isSelected: true, intent: \"secondary\", className: \"bg-secondary/10\" },\n      {\n        isSelected: false,\n        intent: \"secondary\",\n        className: \"hover:bg-secondary/5\",\n      },\n    ],\n    defaultVariants: { isSelected: false, size: \"md\", intent: \"default\" },\n  }\n)\n\n// ── SelectList ─────────────────────────────────────────────────────────────\n\nconst ITEM_ESTIMATE_SIZE: Record<\"sm\" | \"md\" | \"lg\", number> = {\n  sm: 60,\n  md: 72,\n  lg: 84,\n}\n\nexport function SelectList({\n  data,\n  selectedId,\n  height = 300,\n  debounce = 300,\n  placeholder = \"Search...\",\n  intent = \"primary\",\n  size = \"md\",\n  onSelect,\n  onSearch,\n  search: searchProp,\n  disabled = false,\n  loading = false,\n  locale: localeProp,\n  emptyMessage = \"No results found\",\n  className,\n  ...props\n}: SelectListProps) {\n  const locale = useUILocale(localeProp)\n  const [inputValue, setInputValue] = React.useState(searchProp || \"\")\n  const debounceRef = React.useRef<NodeJS.Timeout>(null)\n  const inputRef = React.useRef<HTMLInputElement>(null)\n  const scrollRef = React.useRef<HTMLDivElement>(null)\n\n  React.useEffect(() => {\n    if (searchProp !== undefined) setInputValue(searchProp)\n  }, [searchProp])\n\n  const handleChange = (value: string) => {\n    setInputValue(value)\n    if (onSearch) {\n      if (debounceRef.current) clearTimeout(debounceRef.current)\n      debounceRef.current = setTimeout(() => onSearch(value), debounce)\n    }\n  }\n\n  const handleClear = () => {\n    setInputValue(\"\")\n    if (debounceRef.current) clearTimeout(debounceRef.current)\n    if (onSearch) onSearch(\"\")\n    inputRef.current?.focus()\n  }\n\n  const filteredData = React.useMemo(() => {\n    if (onSearch) return data\n    if (!inputValue) return data\n    return data.filter((item) =>\n      item.name.toLowerCase().includes(inputValue.toLowerCase())\n    )\n  }, [data, inputValue, onSearch])\n\n  // eslint-disable-next-line react-hooks/incompatible-library\n  const virtualizer = useVirtualizer({\n    count: filteredData.length,\n    getScrollElement: () => scrollRef.current,\n    estimateSize: () => ITEM_ESTIMATE_SIZE[size ?? \"md\"],\n    overscan: 5,\n  })\n\n  const renderItem = (\n    item: SelectListItem,\n    isSelected: boolean,\n    isLast = false\n  ) => (\n    <div\n      className={cn(\n        selectListItemVariants({\n          isSelected,\n          size,\n          intent: isSelected ? intent : undefined,\n        }),\n        isLast && \"border-b-0\"\n      )}\n      data-slot=\"select-list-item\"\n    >\n      <div className=\"flex min-w-0 flex-1 items-center gap-3 pr-4\">\n        {item.icon && (\n          <div\n            className=\"flex shrink-0 items-center justify-center text-muted-foreground\"\n            style={{ color: item.iconColor }}\n            data-slot=\"select-list-item-icon\"\n          >\n            {item.icon}\n          </div>\n        )}\n        <div className=\"flex min-w-0 flex-col\">\n          <span\n            className=\"truncate font-semibold text-foreground\"\n            title={item.name}\n            data-slot=\"select-list-item-name\"\n          >\n            {item.name}\n          </span>\n          {(item.group || item.value) && (\n            <div className=\"flex items-center gap-2 text-xs text-muted-foreground\">\n              {item.group && <span>{item.group}</span>}\n              {item.group && item.value && <span>•</span>}\n              {item.value && <span>{item.value}</span>}\n            </div>\n          )}\n        </div>\n      </div>\n\n      <div className=\"shrink-0\">\n        {isSelected ? (\n          <Badge\n            variant={\n              intent === \"primary\"\n                ? \"default\"\n                : intent === \"default\"\n                  ? \"secondary\"\n                  : intent\n            }\n            data-slot=\"select-list-selected-badge\"\n            className=\"pointer-events-none flex h-8 items-center gap-1.5 rounded-full px-4 py-1 text-sm\"\n          >\n            <Check className=\"size-3\" />\n            <span>{UI_I18N[locale].selectList.selected}</span>\n          </Badge>\n        ) : (\n          <Button\n            size=\"sm\"\n            variant={\n              intent === \"primary\"\n                ? \"default\"\n                : intent === \"default\"\n                  ? \"outline\"\n                  : intent\n            }\n            data-slot=\"select-list-select-button\"\n            className=\"rounded-full\"\n            onClick={() => !disabled && onSelect(item)}\n            disabled={disabled || loading}\n            aria-label={`${UI_I18N[locale].selectList.select} ${item.name}`}\n          >\n            {UI_I18N[locale].selectList.select}\n          </Button>\n        )}\n      </div>\n    </div>\n  )\n\n  return (\n    <div\n      className={cn(\n        selectListContainerVariants({ disabled, loading }),\n        className\n      )}\n      aria-busy={loading}\n      data-slot=\"select-list\"\n      {...props}\n    >\n      <div className=\"relative flex w-full items-center\">\n        <Search className=\"absolute left-3 size-4 text-muted-foreground\" />\n        <Input\n          ref={inputRef}\n          value={inputValue}\n          onChange={(e) => handleChange(e.target.value)}\n          placeholder={placeholder}\n          disabled={disabled || loading}\n          data-slot=\"select-list-search\"\n          className=\"pr-9 pl-9\"\n        />\n        {inputValue && !disabled && !loading && (\n          <button\n            onClick={handleClear}\n            className=\"absolute right-3 flex size-4 items-center justify-center rounded-full text-muted-foreground hover:text-foreground focus:ring-2 focus:ring-ring focus:outline-none\"\n            aria-label={UI_I18N[locale].selectList.clearSearch}\n          >\n            <X className=\"size-3\" />\n          </button>\n        )}\n      </div>\n\n      <div className=\"overflow-hidden rounded-md border shadow-sm\">\n        {loading && filteredData.length === 0 ? (\n          <div className=\"flex flex-col p-2\">\n            {Array.from({ length: 4 }).map((_, i) => (\n              <div\n                key={`skeleton-${i}`}\n                className=\"flex items-center justify-between border-b p-4 last:border-0\"\n                data-slot=\"select-list-skeleton\"\n              >\n                <div className=\"flex flex-1 items-center gap-3\">\n                  <Skeleton className=\"size-8 rounded-full\" />\n                  <div className=\"flex flex-col gap-2\">\n                    <Skeleton className=\"h-4 w-30\" />\n                    <Skeleton className=\"h-3 w-20\" />\n                  </div>\n                </div>\n                <Skeleton className=\"h-8 w-20 rounded-full\" />\n              </div>\n            ))}\n          </div>\n        ) : filteredData.length === 0 ? (\n          <div\n            style={{ minHeight: height }}\n            className=\"flex items-center justify-center\"\n            data-slot=\"select-list-empty\"\n          >\n            <Empty\n              variant=\"no-results\"\n              title={emptyMessage}\n              compact\n              locale={locale}\n            />\n          </div>\n        ) : (\n          <div\n            ref={scrollRef}\n            style={{ height, overflowY: \"auto\" }}\n            className=\"w-full\"\n            data-slot=\"select-list-list\"\n          >\n            <div\n              style={{\n                height: `${virtualizer.getTotalSize()}px`,\n                position: \"relative\",\n              }}\n            >\n              {virtualizer.getVirtualItems().map((virtualItem) => {\n                const item = filteredData[virtualItem.index]\n                const isLast = virtualItem.index === filteredData.length - 1\n                return (\n                  <div\n                    key={virtualItem.key}\n                    style={{\n                      position: \"absolute\",\n                      top: 0,\n                      left: 0,\n                      width: \"100%\",\n                      height: `${virtualItem.size}px`,\n                      transform: `translateY(${virtualItem.start}px)`,\n                    }}\n                  >\n                    {renderItem(item, selectedId === item.id, isLast)}\n                  </div>\n                )\n              })}\n            </div>\n          </div>\n        )}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
