import { useEffect, useState } from 'react' import { View, Text, ScrollView, TouchableOpacity, ActivityIndicator, RefreshControl, StyleSheet, } from 'react-native' import { SafeAreaView } from 'react-native-safe-area-context' import { useRouter } from 'expo-router' import { CalendarDays, Sparkles, BookOpen } from 'lucide-react-native' import { apiFetch } from '@/lib/api' import { ENDPOINTS } from '@/lib/config' import { useAuthStore } from '@/lib/store' import { C } from '../_layout' interface Note { id: string title: string updatedAt: string notebookName?: string color?: string } export default function HomeScreen() { const user = useAuthStore((s) => s.user) const [recentNotes, setRecentNotes] = useState([]) const [loading, setLoading] = useState(true) const [refreshing, setRefreshing] = useState(false) const router = useRouter() const load = async () => { try { const res = await apiFetch(ENDPOINTS.notes()) if (res.ok) { const data = await res.json() setRecentNotes((data.notes ?? []).slice(0, 10)) } } finally { setLoading(false) setRefreshing(false) } } useEffect(() => { load() }, []) const handleDailyNote = async () => { const res = await apiFetch(ENDPOINTS.dailyNote) if (res.ok) { const data = await res.json() router.push(`/note/${data.id}`) } } const formatDate = (iso: string) => new Date(iso).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' }) return ( { setRefreshing(true); load() }} tintColor={C.brand} />} > Bonjour{user?.name ? `, ${user.name.split(' ')[0]}` : ''} đŸ‘‹ {new Date().toLocaleDateString('fr-FR', { weekday: 'long', day: 'numeric', month: 'long' })} Note du jour router.push('/(tabs)/notebooks')} style={s.quickBtn}> Carnets router.push('/(tabs)/search')} style={s.quickBtn}> Recherche IA RĂ©centes {loading ? : recentNotes.length === 0 ? Aucune note pour l'instant. : recentNotes.map((note) => ( router.push(`/note/${note.id}`)} style={s.noteCard}> {note.title || 'Sans titre'} {note.notebookName && {note.notebookName}} {formatDate(note.updatedAt)} ))} ) } const s = StyleSheet.create({ safe: { flex: 1, backgroundColor: C.paper }, headerBlock: { paddingHorizontal: 20, paddingTop: 16, paddingBottom: 8 }, greeting: { fontSize: 22, fontWeight: '700', fontStyle: 'italic', color: C.ink }, date: { fontSize: 13, color: C.concrete, marginTop: 2 }, quickRow: { flexDirection: 'row', gap: 10, paddingHorizontal: 20, marginTop: 16 }, quickBtn: { flex: 1, backgroundColor: C.white, borderWidth: 1, borderColor: C.border, borderRadius: 16, padding: 14, alignItems: 'center', gap: 8 }, quickLabel: { fontSize: 11, fontWeight: '600', color: C.ink, textAlign: 'center' }, recentBlock: { paddingHorizontal: 20, marginTop: 24 }, sectionLabel: { fontSize: 10, fontWeight: '800', letterSpacing: 2, textTransform: 'uppercase', color: C.concrete, marginBottom: 12 }, empty: { color: C.concrete, fontSize: 14 }, noteCard: { backgroundColor: C.white, borderWidth: 1, borderColor: C.border, borderRadius: 16, padding: 16, marginBottom: 10 }, noteTitle: { fontSize: 15, fontWeight: '600', color: C.ink }, noteMeta: { fontSize: 11, color: C.concrete }, })