import { Button } from '@/component/ui/button' import { Input } from '@/component/ui/input' import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, } from '@/component/ui/select' import { ElementDefinition } from '@/entitiy/element/model/interface' import { ElementOption } from '@/type/template' import { ChevronDown, Plus, Trash2 } from 'lucide-react' interface SelectConfig { placeholder?: string required?: boolean options: ElementOption[] targetCells: any[] } export const selectDefinition: ElementDefinition = { type: 'select', label: 'Выпадающий список', icon: , version: 1, defaultConfig: { placeholder: '', required: false, options: [], targetCells: [], }, mapToCells: config => config.targetCells || [], mapToCellValues: (config, value) => { const cells = config.targetCells || [] return cells.map(target => ({ target, value: value || '' })) }, Editor: ({ config, onChange }) => { const handleAddOption = () => { onChange({ ...config, options: [...config.options, { value: '', label: '' }], }) } const handleUpdateOption = ( index: number, field: 'value' | 'label', value: string ) => { onChange({ ...config, options: config.options.map((option, i) => i === index ? { ...option, [field]: value } : option ), }) } const handleRemoveOption = (index: number) => { onChange({ ...config, options: config.options.filter((_, i) => i !== index), }) } return (
{config.options.map((option, index) => (
handleUpdateOption(index, 'value', e.target.value) } /> handleUpdateOption(index, 'label', e.target.value) } />
))}
) }, Preview: ({ config }) => ( ), Render: ({ config, value, onChange }) => ( ), }