import React, { useCallback } from 'react'; import { View, Text, StyleSheet, SafeAreaView, ScrollView } from 'react-native'; import { useFocusEffect } from 'expo-router'; import { Header } from '@/components/Header'; import { useStats } from '@/hooks/useStats'; import { useSettings, type ThemeColors } from '@/theme'; export default function StatsScreen() { const { theme } = useSettings(); const stats = useStats(); useFocusEffect( useCallback(() => { return () => {}; }, []) ); const maxDaily = Math.max(1, ...stats.daily.map((d) => d.count)); return (
Overview {stats.totalCompleted} Completed {stats.completedLast7} Last 7 days {stats.completedLast30} Last 30 days {stats.completionRate}% Success rate {stats.currentStreak} Day streak 0 ? theme.accent : theme.text }]}> {stats.overdueCount} Overdue Last 7 days {stats.daily.map((d, i) => { const height = (d.count / maxDaily) * BASE_HEIGHT; return ( 0 ? theme.accent : theme.cardAlt }, ]} /> {d.label} ); })} By tags {stats.byCategory.length === 0 ? ( No completed tasks yet ) : ( stats.byCategory.map((c) => ( {c.name} {c.count} )) )} By priority {stats.byPriority.length === 0 ? ( No completed tasks yet ) : ( stats.byPriority.map((p) => ( {p.label} {p.count} )) )} ); } const BASE_HEIGHT = 90; function priorityColor(theme: ThemeColors, priority: string): string { switch (priority) { case 'critical': return theme.dangerStrong; case 'high': return theme.warning; case 'low': case 'medium': return theme.success; default: return theme.textMuted; } } const styles = StyleSheet.create({ container: { flex: 1, }, content: { padding: 16, paddingBottom: 32, gap: 12, }, card: { borderRadius: 16, padding: 16, }, cardTitle: { fontSize: 13, fontWeight: '600', textTransform: 'uppercase', letterSpacing: 0.5, marginBottom: 14, }, summaryGrid: { flexDirection: 'row', flexWrap: 'wrap', }, summaryItem: { width: '33.33%', marginBottom: 16, }, summaryValue: { fontSize: 26, fontWeight: '700', }, summaryLabel: { fontSize: 12, marginTop: 2, }, chartRow: { flexDirection: 'row', alignItems: 'flex-end', gap: 8, }, chartCol: { flex: 1, alignItems: 'center', }, chartBarTrack: { height: BASE_HEIGHT, justifyContent: 'flex-end', width: '100%', }, chartBar: { width: '100%', borderRadius: 6, minHeight: 4, }, chartLabel: { fontSize: 11, marginTop: 6, }, row: { flexDirection: 'row', alignItems: 'center', paddingVertical: 8, }, dot: { width: 10, height: 10, borderRadius: 5, marginRight: 10, }, rowLabel: { flex: 1, fontSize: 15, }, rowValue: { fontSize: 15, fontWeight: '600', }, emptyText: { fontSize: 14, }, });