"use client"; import { Plus, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Separator } from "@/components/ui/separator"; import { FormMappingPicker } from "./form-mapping-picker"; type FormField = { id: string; label: string; type: string; required: boolean; placeholder?: string; helpText?: string; options?: { label: string; value: string }[]; defaultValue?: unknown; mappedProperty: string | null; validation?: { min?: number; max?: number; pattern?: string; maxLength?: number; }; conditionals?: { fieldId: string; operator: string; value: unknown; action: string; }[]; }; const OPERATORS = ["eq", "neq", "contains", "isEmpty"] as const; const ACTIONS = ["show", "hide"] as const; const CHOICE_TYPES = new Set([ "select", "multi_select", "radio", ]); export function FormFieldConfig({ field, allFields, workspaceId, onChange, }: { field: FormField; allFields: FormField[]; workspaceId: string; onChange: (patch: Partial) => void; }) { const otherFields = allFields.filter((f) => f.id !== field.id); const v = field.validation ?? {}; const conditionals = field.conditionals ?? []; const updateOption = ( index: number, patch: Partial<{ label: string; value: string }>, ) => { const options = [...(field.options ?? [])]; const current = options[index] ?? { label: "", value: "" }; options[index] = { ...current, ...patch }; onChange({ options }); }; const addOption = () => { const n = (field.options?.length ?? 0) + 1; onChange({ options: [ ...(field.options ?? []), { label: `Option ${n}`, value: `option_${n}` }, ], }); }; const removeOption = (index: number) => { const options = [...(field.options ?? [])]; options.splice(index, 1); onChange({ options: options.length ? options : undefined }); }; return (

Field settings

{field.label} ยท {field.type.replaceAll("_", " ")}

onChange({ label: e.target.value })} />
onChange({ placeholder: e.target.value || undefined, }) } />