import { useState } from 'react' import { View, Text, TextInput, FlatList, TouchableOpacity, ActivityIndicator, } from 'react-native' import { SafeAreaView } from 'react-native-safe-area-context' import { Search as SearchIcon, X } from 'lucide-react-native' import { useRouter } from 'expo-router' import { apiFetch } from '@/lib/api' import { ENDPOINTS } from '@/lib/config' interface SearchResult { id: string title: string snippet: string notebookName?: string score?: number } export default function SearchScreen() { const [query, setQuery] = useState('') const [results, setResults] = useState([]) const [loading, setLoading] = useState(false) const [searched, setSearched] = useState(false) const router = useRouter() const handleSearch = async () => { if (!query.trim()) return setLoading(true) setSearched(true) try { const res = await apiFetch(`${ENDPOINTS.search}?q=${encodeURIComponent(query)}`) if (res.ok) { const data = await res.json() setResults(data.results ?? []) } } finally { setLoading(false) } } return ( Recherche {query.length > 0 && ( { setQuery(''); setResults([]); setSearched(false) }}> )} {loading ? ( ) : ( item.id} contentContainerClassName="px-5 pt-3 pb-8" renderItem={({ item }) => ( router.push(`/note/${item.id}`)} className="bg-white border border-border rounded-2xl p-4 mb-2.5 active:opacity-70" > {item.title || 'Sans titre'} {item.snippet && ( {item.snippet} )} {item.notebookName && ( {item.notebookName} )} )} ListEmptyComponent={ searched ? ( Aucun résultat pour "{query}" ) : ( Tapez votre recherche puis appuyez sur Entrée ) } /> )} ) }