import { useEffect, useState } from 'react' import { View, Text, FlatList, TouchableOpacity, ActivityIndicator, RefreshControl, } from 'react-native' import { SafeAreaView } from 'react-native-safe-area-context' import { useRouter } from 'expo-router' import { ChevronRight } from 'lucide-react-native' import { apiFetch } from '@/lib/api' import { ENDPOINTS } from '@/lib/config' interface Notebook { id: string name: string icon: string | null _count: { notes: number } } export default function NotebooksScreen() { const [notebooks, setNotebooks] = useState([]) const [loading, setLoading] = useState(true) const [refreshing, setRefreshing] = useState(false) const router = useRouter() const load = async () => { try { const res = await apiFetch(ENDPOINTS.notebooks) if (res.ok) { const data = await res.json() setNotebooks(data.notebooks ?? []) } } finally { setLoading(false) setRefreshing(false) } } useEffect(() => { load() }, []) if (loading) { return ( ) } return ( Carnets item.id} contentContainerClassName="px-5 pb-8" refreshControl={ { setRefreshing(true); load() }} tintColor="#A47148" />} renderItem={({ item }) => ( router.push(`/notebook/${item.id}`)} className="flex-row items-center bg-white border border-border rounded-2xl p-4 mb-2.5 active:opacity-70" > {item.icon ?? '📓'} {item.name} {item._count?.notes ?? 0} notes )} ListEmptyComponent={ Aucun carnet. } /> ) }