import React from 'react' import { Input, Textarea } from '@/components/ui' import { FieldType } from '@/types' export interface FormFieldDef { id: string label: string type: FieldType hint?: string | null options: string[] required: boolean } export function FieldRenderer({ field, value, onChange }: { field: FormFieldDef value: any onChange: (v: any) => void }) { switch (field.type) { case 'SHORT_TEXT': return onChange(e.target.value)} placeholder={field.hint || ''}/> case 'LONG_TEXT': return onChange(e.target.value)} placeholder={field.hint || ''}/> case 'NUMBER': return onChange(e.target.value)} style={{ maxWidth: '160px' }}/> case 'DATE': return onChange(e.target.value)} style={{ maxWidth: '180px' }}/> case 'SINGLE_CHOICE': return ( {field.options.map(opt => ( onChange(opt)} style={{ accentColor: '#534AB7' }}/> {opt} ))} ) case 'MULTI_CHOICE': return ( {field.options.map(opt => ( { const cur = value || [] onChange(e.target.checked ? [...cur, opt] : cur.filter((x: string) => x !== opt)) }} style={{ accentColor: '#534AB7' }}/> {opt} ))} ) case 'RATING': return ( {[1, 2, 3, 4, 5].map(n => ( onChange(n)} style={{ fontSize: '24px', cursor: 'pointer', color: (value || 0) >= n ? '#EF9F27' : '#ddd' }}>★ ))} ) case 'PHOTO': return onChange(e.target.files?.[0]?.name || '')}/> default: return null } } export function FormFieldList({ fields, values, onChange }: { fields: FormFieldDef[] values: Record onChange: (fieldId: string, value: any) => void }) { return ( <> {fields.map(field => ( {field.label} {field.required && *} {field.hint && {field.hint}} onChange(field.id, v)}/> ))} > ) }