import React, { useState } from 'react' import { ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native' import { Checkbox } from '../../../components' import { logger } from '../../../utils/Logger' export interface Condition { id: string name: string content: string is_required: boolean } interface ConditionsProps { conditions: Condition[] acceptedConditions: Record onAcceptCondition: (conditionId: string, isAccepted: boolean) => void styles?: { container?: object title?: object conditionButton?: object conditionButtonText?: object checkbox?: object conditionContent?: object expandedContent?: object } texts?: { title?: string viewButton?: string hideButton?: string acceptCheckbox?: string } } const Conditions: React.FC = ({ conditions, acceptedConditions, onAcceptCondition, styles: customStyles, texts, }) => { // Track which conditions are expanded const [expandedConditions, setExpandedConditions] = useState>( {} ) if (!conditions || conditions.length === 0) { return null } const toggleCondition = (conditionId: string) => { setExpandedConditions((prev) => ({ ...prev, [conditionId]: !prev[conditionId], })) logger.debug('[Conditions] Condition toggled', { conditionId, expanded: !expandedConditions[conditionId], }) } return ( {texts?.title || 'Event Conditions'} {conditions.map((condition) => ( toggleCondition(condition.id)} > {condition.name} {condition.is_required ? '*' : ''} ( {expandedConditions[condition.id] ? texts?.hideButton || 'Hide' : texts?.viewButton || 'View'} ) {expandedConditions[condition.id] && ( {condition.content} )} {condition.is_required && ( onAcceptCondition(condition.id, !acceptedConditions[condition.id]) } styles={customStyles?.checkbox} text={texts?.acceptCheckbox || 'I have read and accept these conditions'} /> )} ))} ) } const styles = StyleSheet.create({ container: { marginBottom: 20, }, title: { fontSize: 18, fontWeight: 'bold', marginBottom: 10, }, conditionRow: { marginBottom: 15, }, conditionButton: { padding: 8, backgroundColor: '#f5f5f5', borderRadius: 4, marginBottom: 5, }, conditionButtonText: { color: '#007bff', }, expandedContent: { backgroundColor: '#f9f9f9', padding: 15, borderRadius: 4, marginBottom: 10, maxHeight: 150, }, conditionContent: { fontSize: 14, lineHeight: 20, }, }) export default Conditions