import { Group, MultiSelect, Select, Text } from "@mantine/core"; import { IconCheck } from "@tabler/icons-react"; import { Choice } from "@/ee/base/types/base.types"; import { choiceColor } from "@/ee/base/components/cells/choice-color"; import { useTranslation } from "react-i18next"; import type { ComboboxItem } from "@mantine/core"; type DefaultValuePickerProps = { choices: Choice[]; value: string | string[] | null; multiple?: boolean; onChange: (value: string | string[] | null) => void; dropdownPortalTarget?: HTMLElement | null; }; export function DefaultValuePicker({ choices, value, multiple, onChange, dropdownPortalTarget, }: DefaultValuePickerProps) { const { t } = useTranslation(); const data = choices.map((c) => ({ value: c.id, label: c.name })); const comboboxProps = { portalProps: { target: dropdownPortalTarget ?? undefined }, }; const renderOption = ({ option, checked, }: { option: ComboboxItem; checked?: boolean; }) => { const choice = choices.find((c) => c.id === option.value); const colors = choice ? choiceColor(choice.color) : undefined; return ( {colors && ( )} {option.label} {checked && ( )} ); }; if (multiple) { const selected = ( Array.isArray(value) ? value : value ? [value] : [] ).filter((id) => choices.some((c) => c.id === id)); return ( onChange(vals.length ? vals : null)} clearable comboboxProps={comboboxProps} renderOption={renderOption} /> ); } const single = typeof value === "string" && choices.some((c) => c.id === value) ? value : null; return (