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'; /** Dimensions locales (multiples de l'échelle 4px du DSFR). */ const TILE_MIN_HEIGHT = 92; const TILE_EMOJI = 30; const BACK_ICON = 16; const CHEVRON_ICON = 12; const BORDER_DEFAULT = 1.5; const BORDER_SELECTED = 2.5; 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: TILE_MIN_HEIGHT, backgroundColor: Colors.white, borderRadius: Radius.sm, paddingVertical: Spacing.md, paddingHorizontal: Spacing.sm, alignItems: 'center', justifyContent: 'center', gap: Spacing.xs, borderWidth: BORDER_DEFAULT, borderColor: Colors.gray[200], }, tileEmoji: { fontSize: TILE_EMOJI }, tileName: { fontSize: FontSize.xs, fontWeight: FontWeight.semibold, color: Colors.black, textAlign: 'center' }, chevron: { marginTop: Spacing.xs / 2 }, });