import React from 'react'; import { Text, View, TouchableOpacity, StyleSheet } from 'react-native'; import type { ContentItem, FormProperty } from '../types'; import type { ContentViewItem } from '../store/contentModel'; import { getTextStyles } from '../utils/styleKeys'; interface FormRadioProps { element: ContentItem; contentItem: ContentViewItem; value: string; onChange: (value: string) => void; onBlur?: () => void; error?: string; touched?: boolean; disabled?: boolean; } export const FormRadio: React.FC = ({ element, value, onChange, onBlur, error, touched, disabled, }) => { const properties = element.data as FormProperty; const handleSelect = (optionValue: string) => { if (!disabled) { onChange(optionValue); if (onBlur) onBlur(); } }; return properties.label ? ( {properties.label && ( {properties.label} )} {(properties.options || [])?.map((option) => ( handleSelect(option.value)} disabled={disabled || option.disabled} style={[ properties.styles as any, properties.customStyles, (disabled || option.disabled) && formStyles.disabled, { flexDirection: 'row', alignItems: 'center', gap: 6 }, ]} > {value === option.value && ( )} {/* {option.label} */} {option.label} ))} {error && touched && {error}} ) : ( <> {(properties.options || [])?.map((option) => ( handleSelect(option.value)} disabled={disabled || option.disabled} style={[ properties.styles as any, properties.customStyles, (disabled || option.disabled) && formStyles.disabled, { flexDirection: 'row', alignItems: 'center', gap: 6 }, ]} > {value === option.value && ( )} {option.label} ))} {error && touched && {error}} ); }; const formStyles = StyleSheet.create({ container: { marginBottom: 16, }, groupLabel: { fontSize: 16, fontWeight: '500', marginBottom: 12, }, required: { color: '#ff0000', }, radioContainer: { flexDirection: 'row', alignItems: 'center', marginBottom: 8, }, radio: { borderWidth: 2, borderRadius: 10, justifyContent: 'center', alignItems: 'center', marginRight: 12, }, radioDot: { borderRadius: 5, }, optionLabel: { fontSize: 16, fontWeight: '400', flex: 1, }, disabled: { opacity: 0.5, }, disabledOption: { color: '#999', }, errorText: { color: '#ff0000', fontSize: 12, marginTop: 4, }, });