import { useState } from 'react' import { View, Text, TextInput, FlatList, TouchableOpacity, ActivityIndicator, StyleSheet, } 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' import { C } from '../_layout' 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} contentContainerStyle={s.list} renderItem={({ item }) => ( router.push(`/note/${item.id}`)} style={s.card}> {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'} } />} ) } const s = StyleSheet.create({ safe: { flex: 1, backgroundColor: C.paper }, top: { paddingHorizontal: 20, paddingTop: 16, paddingBottom: 8 }, title: { fontSize: 22, fontStyle: 'italic', fontWeight: '700', color: C.ink, marginBottom: 16 }, inputRow: { flexDirection: 'row', alignItems: 'center', backgroundColor: C.white, borderWidth: 1, borderColor: C.border, borderRadius: 12, paddingHorizontal: 12, paddingVertical: 10, gap: 8 }, input: { flex: 1, fontSize: 15, color: C.ink }, center: { flex: 1, alignItems: 'center', justifyContent: 'center' }, list: { paddingHorizontal: 20, paddingTop: 12, paddingBottom: 32 }, card: { backgroundColor: C.white, borderWidth: 1, borderColor: C.border, borderRadius: 16, padding: 16, marginBottom: 10 }, cardTitle: { fontSize: 15, fontWeight: '600', color: C.ink }, snippet: { fontSize: 12, color: C.concrete, marginTop: 4 }, nb: { fontSize: 11, color: C.concrete, marginTop: 4, opacity: 0.7 }, empty: { textAlign: 'center', color: C.concrete, marginTop: 48, fontSize: 13 }, })