import { useState } from 'react'; import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { useEmotions } from '@/hooks/useEmotions'; import { Colors } from '@/lib/colors'; import { Spacing, Radius, FontSize, FontWeight, MIN_TOUCH, HIT_SLOP } from '@/lib/theme'; import { Loader } from '@/components/ui'; 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 émotions Précisez votre émotion de{' '} {selectedParent.nom} : {selectedParent.enfants.map((child) => ( onChange(child.id)} /> ))} ); } 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); } }} /> ); })} ); } function EmotionTile({ emotion, selected, hasChildren, onPress, }: { emotion: Emotion; selected: boolean; hasChildren?: boolean; onPress: () => void; }) { return ( {emotion.icone || '🔵'} {emotion.nom} {hasChildren && } ); } const styles = StyleSheet.create({ backBtn: { flexDirection: 'row', alignItems: 'center', gap: Spacing.xs, marginBottom: Spacing.md, minHeight: MIN_TOUCH }, backText: { fontSize: FontSize.sm, fontWeight: FontWeight.semibold, color: Colors.primary }, subTitle: { fontSize: FontSize.sm, color: Colors.gray[600], marginBottom: Spacing.md }, subTitleAccent: { fontWeight: FontWeight.bold }, grid: { flexDirection: 'row', flexWrap: 'wrap', gap: Spacing.md, justifyContent: 'space-between' }, tile: { width: '30%', minHeight: 92, backgroundColor: Colors.white, borderRadius: Radius.sm, paddingVertical: Spacing.md, paddingHorizontal: Spacing.sm, alignItems: 'center', justifyContent: 'center', gap: Spacing.xs, borderWidth: 1.5, borderColor: Colors.gray[200], }, tileEmoji: { fontSize: 30 }, tileName: { fontSize: FontSize.xs, fontWeight: FontWeight.semibold, color: Colors.black, textAlign: 'center' }, chevron: { marginTop: 2 }, });