import { useEffect, useState } from 'react' import { View, Text, ScrollView, TouchableOpacity, ActivityIndicator, RefreshControl, } 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' 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) => { const d = new Date(iso) return d.toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' }) } return ( { setRefreshing(true); load() }} tintColor="#A47148" />} > {/* Header */} Bonjour{user?.name ? `, ${user.name.split(' ')[0]}` : ''} đŸ‘‹ {new Date().toLocaleDateString('fr-FR', { weekday: 'long', day: 'numeric', month: 'long' })} {/* Quick actions */} Note du jour router.push('/(tabs)/notebooks')} className="flex-1 bg-white border border-border rounded-2xl p-4 items-center gap-2" > Carnets router.push('/(tabs)/search')} className="flex-1 bg-white border border-border rounded-2xl p-4 items-center gap-2" > Recherche IA {/* Recent notes */} RĂ©centes {loading ? ( ) : recentNotes.length === 0 ? ( Aucune note pour l'instant. ) : ( recentNotes.map((note) => ( router.push(`/note/${note.id}`)} className="bg-white border border-border rounded-2xl p-4 mb-2.5 active:opacity-70" > {note.title || 'Sans titre'} {note.notebookName && ( {note.notebookName} )} {formatDate(note.updatedAt)} )) )} ) }