import type { BaseFormBuilderProps, GenericFormElementProps, } from "@components/Form/DynamicForm.tsx"; import type { FieldValues } from "react-hook-form"; import { MultiSelect, MultiSelectItem } from "../UI/MultiSelect.tsx"; export interface MultiSelectFieldProps extends BaseFormBuilderProps { type: "multiSelect"; placeholder?: string; onValueChange: (name: string) => void; isChecked: (name: string) => boolean; value: string[]; properties: BaseFormBuilderProps["properties"] & { enumValue: { [s: string]: string | number; }; formatEnumName?: boolean; }; } const formatEnumDisplay = (name: string): string => { return name .replace(/_/g, " ") .toLowerCase() .split(" ") .map((s) => s.charAt(0).toUpperCase() + s.substring(1)) .join(" "); }; export function MultiSelectInput({ field, }: GenericFormElementProps>) { const { enumValue, formatEnumName, ...remainingProperties } = field.properties; const valueToKeyMap: Record = {}; const optionsEnumValues: [string, number][] = []; if (enumValue) { Object.entries(enumValue).forEach(([key, val]) => { if (typeof val === "number" && key !== "UNSET") { valueToKeyMap[val.toString()] = key; optionsEnumValues.push([key, val as number]); } }); } return ( {optionsEnumValues.map(([name, value]) => ( field.onValueChange(name)} > {formatEnumName ? formatEnumDisplay(name) : name} ))} ); }