/* Voyage Assistant — SearchBar éditable avec autocomplete lieux. Chaque champ est cliquable individuellement et ouvre son éditeur inline. Le bouton Rechercher déclenche onSearch(values). */ const Autocomplete = ({ value, onChange, onPick, placeholder, type }) => { const [items, setItems] = React.useState([]); const [open, setOpen] = React.useState(false); const [loading, setLoading] = React.useState(false); const inputRef = React.useRef(null); const timerRef = React.useRef(null); React.useEffect(() => { if (timerRef.current) clearTimeout(timerRef.current); timerRef.current = setTimeout(async () => { setLoading(true); try { const qs = new URLSearchParams({ q: value || '', limit: 8 }); if (type) qs.set('type', type); const res = await fetch(`${window.VA_CONFIG.API_BASE}/lieux?${qs.toString()}`); const data = await res.json(); setItems(Array.isArray(data) ? data : []); } catch { setItems([]); } finally { setLoading(false); } }, 150); return () => clearTimeout(timerRef.current); }, [value, type]); React.useEffect(() => { if (inputRef.current) inputRef.current.focus(); }, []); return (