import { useState } from 'react'; import { View, Text, StyleSheet, TouchableOpacity, ActivityIndicator } from 'react-native'; import { useEmotions } from '@/hooks/useEmotions'; import { Colors } from '@/lib/colors'; import type { Emotion } from '@/types'; interface EmotionPickerProps { value?: number; onChange: (emotionId: number) => void; } export default function EmotionPicker({ value, onChange }: EmotionPickerProps) { const { data: emotions, isLoading } = useEmotions(); const [selectedParent, setSelectedParent] = useState(null); if (isLoading) { return ( ); } if (selectedParent?.enfants && selectedParent.enfants.length > 0) { return ( setSelectedParent(null)}> ← Retour aux emotions Precisez votre emotion de{' '} {selectedParent.nom} : {selectedParent.enfants.map((child) => { const isSelected = value === child.id; return ( onChange(child.id)} > {child.icone || '🔵'} {child.nom} ); })} ); } return ( {emotions?.map((emotion) => { const hasChildren = emotion.enfants && emotion.enfants.length > 0; const isSelected = value === emotion.id || emotion.enfants?.some((e) => e.id === value); return ( { if (hasChildren) { setSelectedParent(emotion); } else { onChange(emotion.id); } }} > {emotion.icone || '🔵'} {emotion.nom} {hasChildren && ▼} ); })} ); } const styles = StyleSheet.create({ loading: { padding: 40, alignItems: 'center' }, backBtn: { marginBottom: 12 }, backText: { fontSize: 14, color: Colors.primary, textDecorationLine: 'underline' }, subTitle: { fontSize: 14, color: Colors.gray[600], marginBottom: 12 }, grid: { flexDirection: 'row', flexWrap: 'wrap', gap: 10 }, emotionCard: { width: '30%', backgroundColor: Colors.white, borderRadius: 4, padding: 14, alignItems: 'center', gap: 6, borderWidth: 1.5, borderColor: Colors.gray[200], }, emotionEmoji: { fontSize: 30 }, emotionName: { fontSize: 12, fontWeight: '600', color: Colors.black, textAlign: 'center' }, arrow: { fontSize: 10, color: Colors.gray[400] }, });