// Global search overlay — searches tenants (rentals) + equipment const { useState: useStateS, useMemo: useMemoS, useEffect: useEffectS, useRef: useRefS } = React; function SearchOverlay({ open, onClose, equipment = [], rentals = [], go }) { const t = useTheme(); const [q, setQ] = useStateS(''); const [visible, setVisible] = useStateS(open); const inputRef = useRefS(null); useEffectS(() => { if (open) { setVisible(true); return; } const id = setTimeout(() => setVisible(false), 340); return () => clearTimeout(id); }, [open]); useEffectS(() => { if (open) { setQ(''); setTimeout(() => inputRef.current && inputRef.current.focus(), 250); } }, [open]); const query = q.trim().toLowerCase(); // Unique tenants from rentals (Stammkunden) const tenants = useMemoS(() => { const map = {}; rentals.forEach(r => { const key = r.tenantName.toLowerCase(); if (!map[key]) map[key] = { name: r.tenantName, count: 0, last: '', phone: r.phone, email: r.email }; map[key].count += 1; if (r.start > map[key].last) map[key].last = r.start; }); return Object.values(map); }, [rentals]); const tenantHits = query ? tenants.filter(x => x.name.toLowerCase().includes(query) || (x.phone || '').toLowerCase().includes(query) || (x.email || '').toLowerCase().includes(query)) : []; const eqHits = query ? equipment.filter(e => e.name.toLowerCase().includes(query) || (e.cat || '').toLowerCase().includes(query) || (e.kind || '').toLowerCase().includes(query)) : []; const rentalHits = query ? rentals.filter(r => (r.purpose || '').toLowerCase().includes(query) || (r.equipmentName || '').toLowerCase().includes(query)) : []; const empty = query && tenantHits.length === 0 && eqHits.length === 0 && rentalHits.length === 0; const Section = ({ title, count }) => (