import { SelectControl, TextControl, TextareaControl, CheckboxControl, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import PTRichText from '@admin/components/PTRichText'; import { normalizeDefaultValues } from '@admin/sections/EditFields/AdvancedSettings'; import type { EditFieldProps } from './consts'; export default function EditField({ type, value, onChange, options: providedOptions, placeholder, id, fieldKey, }: EditFieldProps) { let finalType = type; let finalOptions = providedOptions; if (fieldKey === 'country') { const defaultValues = normalizeDefaultValues( window.petitionerData.default_values ); const countries = defaultValues.country_list || []; finalType = 'select'; finalOptions = countries.map((country) => ({ label: country, value: country, })); } if (fieldKey === 'approval_status') { finalType = 'select'; finalOptions = [ { label: __('Confirmed', 'petitioner'), value: 'Confirmed' }, { label: __('Declined', 'petitioner'), value: 'Declined' }, ]; } if (finalType === 'select' && finalOptions) { return ( ); } if (finalType === 'checkbox') { return ( onChange(checked ? '1' : '0')} /> ); } if (finalType === 'textarea') { return ( ); } if (finalType === 'wysiwyg' && id) { return ( ); } // Default: TextControl handles text, email, tel, number, date, etc. return ( ); }