{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-table-server-faceted-filter",
  "type": "registry:component",
  "title": "Data Table Server Faceted Filter",
  "description": "Single or multi-select faceted filter used by the canonical M8 data table.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "badge",
    "button",
    "command",
    "popover",
    "separator"
  ],
  "files": [
    {
      "path": "registry/blocks/data-table/data-table-server-faceted-filter.tsx",
      "content": "\"use client\";\n// astro-ui-m8-skin-version: 1.5.3 (A-C6 — run `npx astro-ui-m8-skin-lock` to compare against your installed @mano8/astro-ui-m8)\n\nimport * as React from \"react\";\nimport { Check, PlusCircle } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n  Command,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandList,\n  CommandSeparator,\n} from \"@/components/ui/command\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"@/components/ui/popover\";\nimport { Separator } from \"@/components/ui/separator\";\n\nexport interface FacetedFilterOption {\n  label: string;\n  value: string;\n  icon?: React.ComponentType<{ className?: string }>;\n}\n\nexport interface DataTableServerFacetedFilterLabels {\n  clear: string;\n  empty: string;\n  selected: (count: number) => string;\n}\n\nconst DEFAULT_LABELS: DataTableServerFacetedFilterLabels = {\n  clear: \"Clear\",\n  empty: \"No results found.\",\n  selected: (count) => `${count} selected`,\n};\n\ninterface DataTableServerFacetedFilterProps<TFilter extends string> {\n  title: string;\n  options: FacetedFilterOption[];\n  value: TFilter | \"\";\n  onFilterChange: (value: TFilter | \"\") => void;\n  labels?: Partial<DataTableServerFacetedFilterLabels>;\n  multi?: boolean;\n}\n\nexport function DataTableServerFacetedFilter<TFilter extends string>({\n  title,\n  options,\n  value,\n  onFilterChange,\n  labels,\n  multi = true,\n}: DataTableServerFacetedFilterProps<TFilter>) {\n  const t = { ...DEFAULT_LABELS, ...labels };\n  const selected = React.useMemo<Set<string>>(() => {\n    if (!value) return new Set<string>();\n    return multi ? new Set(String(value).split(\",\").filter(Boolean)) : new Set([String(value)]);\n  }, [multi, value]);\n\n  const selectedCount = selected.size;\n\n  const toggleMulti = (nextValue: string) => {\n    const next = new Set(selected);\n    if (next.has(nextValue)) {\n      next.delete(nextValue);\n    } else {\n      next.add(nextValue);\n    }\n    onFilterChange((Array.from(next).join(\",\") as TFilter) || \"\");\n  };\n\n  const chooseSingle = (nextValue: string) => {\n    const current = selected.values().next().value as string | undefined;\n    onFilterChange(current === nextValue ? \"\" : (nextValue as TFilter));\n  };\n\n  return (\n    <Popover>\n      <PopoverTrigger asChild>\n        <Button variant=\"outline\" size=\"sm\" className=\"h-8 border-dashed\">\n          <PlusCircle className=\"mr-2 size-4\" />\n          {title}\n          {selectedCount > 0 ? (\n            <>\n              <Separator orientation=\"vertical\" className=\"mx-2 h-4\" />\n              <Badge variant=\"secondary\" className=\"rounded-sm px-1 font-normal lg:hidden\">\n                {selectedCount}\n              </Badge>\n              <div className=\"hidden space-x-1 lg:flex\">\n                {selectedCount > 2 ? (\n                  <Badge variant=\"secondary\" className=\"rounded-sm px-1 font-normal\">\n                    {t.selected(selectedCount)}\n                  </Badge>\n                ) : (\n                  options\n                    .filter((option) => selected.has(option.value))\n                    .map((option) => (\n                      <Badge\n                        key={option.value}\n                        variant=\"secondary\"\n                        className=\"rounded-sm px-1 font-normal\"\n                      >\n                        {option.label}\n                      </Badge>\n                    ))\n                )}\n              </div>\n            </>\n          ) : null}\n        </Button>\n      </PopoverTrigger>\n      <PopoverContent className=\"w-[220px] p-0\" align=\"start\">\n        <Command>\n          <CommandInput placeholder={title} />\n          <CommandList>\n            <CommandEmpty>{t.empty}</CommandEmpty>\n            <CommandGroup>\n              {options.map((option) => {\n                const isSelected = selected.has(option.value);\n                return (\n                  <CommandItem\n                    key={option.value}\n                    onSelect={() => {\n                      if (multi) {\n                        toggleMulti(option.value);\n                      } else {\n                        chooseSingle(option.value);\n                      }\n                    }}\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                      <Check className=\"size-4\" />\n                    </div>\n                    {option.icon ? (\n                      <option.icon className=\"mr-2 size-4 text-muted-foreground\" />\n                    ) : null}\n                    <span>{option.label}</span>\n                  </CommandItem>\n                );\n              })}\n            </CommandGroup>\n            {selectedCount > 0 ? (\n              <>\n                <CommandSeparator />\n                <CommandGroup>\n                  <CommandItem onSelect={() => onFilterChange(\"\")} className=\"justify-center\">\n                    {t.clear}\n                  </CommandItem>\n                </CommandGroup>\n              </>\n            ) : null}\n          </CommandList>\n        </Command>\n      </PopoverContent>\n    </Popover>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/m8-ui/data-table-server-faceted-filter.tsx"
    }
  ]
}
