import { useState } from 'react'; import { View, Text, StyleSheet, ScrollView, TouchableOpacity } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { useRapport } from '@/hooks/useRapport'; import { Colors } from '@/lib/colors'; import { Spacing, Radius, FontSize, FontWeight } from '@/lib/theme'; import { AppBar, Card, Badge, SectionTitle, EmptyState, Loader } from '@/components/ui'; import EmotionPieChart from '@/components/EmotionPieChart'; type Period = 'week' | 'month' | 'quarter' | 'year'; const PERIODS: { value: Period; label: string }[] = [ { value: 'week', label: 'Semaine' }, { value: 'month', label: 'Mois' }, { value: 'quarter', label: 'Trimestre' }, { value: 'year', label: 'Année' }, ]; export default function ReportsScreen() { const [period, setPeriod] = useState('month'); const { data: rapport, isLoading } = useRapport(period); return ( {/* Sélecteur de période — boutons segmentés */} {PERIODS.map((p) => { const active = period === p.value; return ( setPeriod(p.value)} accessibilityLabel={p.label} > {p.label} ); })} {isLoading ? ( ) : rapport && rapport.stats.total_saisies > 0 ? ( <> {/* Stats */} {rapport.stats.total_saisies} Saisies {rapport.stats.intensite_moyenne?.toFixed(1) || '—'} Intensité moy. {rapport.stats.emotion_dominante?.icone || '—'} {rapport.stats.emotion_dominante?.nom || 'Aucune'} Du {new Date(rapport.date_debut).toLocaleDateString('fr-FR')} au{' '} {new Date(rapport.date_fin).toLocaleDateString('fr-FR')} {/* Répartition */} {rapport.repartition.length > 0 && ( Répartition des émotions ({ nom: item.nom, couleur: item.couleur, count: item.count, pourcentage: item.pourcentage, }))} /> Détail par émotion {rapport.repartition.map((item, idx) => ( 0 && styles.repItemBorder]} > {item.pourcentage}% {item.count} saisies Moy. {item.intensite_moyenne.toFixed(1)}/10 ))} )} ) : ( )} ); } const styles = StyleSheet.create({ screen: { flex: 1, backgroundColor: Colors.gray[50] }, container: { flex: 1 }, content: { padding: Spacing.lg, paddingBottom: Spacing.xxxl }, segment: { flexDirection: 'row', backgroundColor: Colors.gray[100], borderRadius: Radius.sm, padding: Spacing.xs, marginBottom: Spacing.lg }, segmentBtn: { flex: 1, paddingVertical: Spacing.sm, alignItems: 'center', borderRadius: Radius.sm, minHeight: 40, justifyContent: 'center' }, segmentBtnActive: { backgroundColor: Colors.primary }, segmentText: { fontSize: FontSize.xs, fontWeight: FontWeight.semibold, color: Colors.gray[500] }, segmentTextActive: { color: Colors.white }, statsCard: { marginBottom: Spacing.xl }, statsRow: { flexDirection: 'row', alignItems: 'center' }, statCell: { flex: 1, alignItems: 'center', gap: Spacing.xs }, statDivider: { width: 1, alignSelf: 'stretch', backgroundColor: Colors.gray[200], marginVertical: Spacing.xs }, statValue: { fontSize: FontSize.xxl, fontWeight: FontWeight.heavy, color: Colors.black }, statEmoji: { fontSize: FontSize.xxl }, statLabel: { fontSize: FontSize.tiny, color: Colors.gray[500], textAlign: 'center' }, periodInfo: { fontSize: FontSize.xs, color: Colors.gray[400], textAlign: 'center', marginTop: Spacing.md }, block: { marginBottom: Spacing.xl }, detailHeader: { marginTop: Spacing.lg }, repItem: { paddingVertical: Spacing.md }, repItemBorder: { borderTopWidth: 1, borderTopColor: Colors.gray[200] }, repHeader: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginBottom: Spacing.sm }, repPct: { fontSize: FontSize.sm, fontWeight: FontWeight.bold, color: Colors.black }, progressBar: { height: 6, backgroundColor: Colors.gray[200], borderRadius: Radius.sm, marginBottom: Spacing.xs }, progressFill: { height: 6, borderRadius: Radius.sm }, repFooter: { flexDirection: 'row', justifyContent: 'space-between' }, repDetail: { fontSize: FontSize.xs, color: Colors.gray[500] }, });