"use client"; import { useMemo, useState } from "react"; import { useTranslations } from "next-intl"; import { Button } from "@app/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger } from "@app/components/ui/popover"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@app/components/ui/command"; import { CheckIcon, Funnel } from "lucide-react"; import { cn } from "@app/lib/cn"; import { dataTableFilterPopoverContentClassName } from "@app/lib/dataTableFilterPopover"; import { Badge } from "./ui/badge"; type FilterOption = { value: string; label: string; }; type ColumnMultiFilterButtonProps = { options: FilterOption[]; selectedValues: string[]; onSelectedValuesChange: (values: string[]) => void; searchPlaceholder?: string; emptyMessage?: string; className?: string; label: string; }; export function ColumnMultiFilterButton({ options, selectedValues, onSelectedValuesChange, searchPlaceholder = "Search...", emptyMessage = "No options found", className, label }: ColumnMultiFilterButtonProps) { const [open, setOpen] = useState(false); const t = useTranslations(); const selectedSet = useMemo( () => new Set(selectedValues), [selectedValues] ); const summary = useMemo(() => { if (selectedValues.length === 0) { return null; } if (selectedValues.length === 1) { return ( options.find((o) => o.value === selectedValues[0])?.label ?? selectedValues[0] ); } return t("accessUsersRoleFilterCount", { count: selectedValues.length }); }, [selectedValues, options, t]); function toggle(value: string) { const next = selectedSet.has(value) ? selectedValues.filter((v) => v !== value) : [...selectedValues, value]; onSelectedValuesChange(next); } return ( {emptyMessage} {selectedValues.length > 0 && ( { onSelectedValuesChange([]); setOpen(false); }} className="text-muted-foreground" > {t("accessUsersRoleFilterClear")} )} {options.map((option) => ( { toggle(option.value); }} > {option.label} ))} ); }