import type { Ref } from "react"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "../ui/command"; import { cn } from "@app/lib/cn"; import { CheckIcon } from "lucide-react"; import { useTranslations } from "next-intl"; export type TagValue = { text: string; id: string }; export type MultiSelectTagsProps = { emptyPlaceholder?: string; searchPlaceholder?: string; searchQuery?: string; options: Array; value: Array; onChange: (newValue: Array) => void; onSearch: (query: string) => void; ref?: Ref; disabled?: boolean; lockedIds?: Set; }; export function MultiSelectContent({ emptyPlaceholder, searchPlaceholder, searchQuery, value, options, onSearch, onChange, lockedIds }: MultiSelectTagsProps) { const t = useTranslations(); const selectedValues = new Set(value.map((v) => v.id)); return ( {emptyPlaceholder ?? t("noResults")} {options.map((option) => { const isLocked = lockedIds?.has(option.id); return ( { if (isLocked) return; let newValues = []; if (selectedValues.has(option.id)) { newValues = value.filter( (v) => v.id !== option.id ); } else { newValues = [...value, option]; } onChange(newValues); }} > {`${option.text}`} ); })} ); }