/* Global search — App.search from js/app.js:171-191. Same sources and the same 4/4/3 caps. The inline onclick="App.searchGo(...)" strings become navigate() calls, and the setTimeout(cb, 120) hack that waited for the old router to swap innerHTML is gone: the target screen reads `state.open` instead. */ import { useMemo, useRef, useState } from 'react' import { useNavigate } from 'react-router-dom' import { useQuery } from '@tanstack/react-query' import { seedQuery } from '../data/seedQueries' import { Avatar, Icon } from '../ui/primitives' export default function GlobalSearch({ inputRef }) { const navigate = useNavigate() const [q, setQ] = useState('') const [open, setOpen] = useState(false) const boxRef = useRef(null) const { data: jobs = [] } = useQuery(seedQuery('jobs')) const { data: candidates = [] } = useQuery(seedQuery('candidates')) const { data: managers = [] } = useQuery(seedQuery('managers')) const results = useMemo(() => { const term = q.trim().toLowerCase() if (!term) return null return { jobs: jobs.filter((j) => (j.title + j.id + j.department).toLowerCase().includes(term)).slice(0, 4), candidates: candidates.filter((c) => (c.name + c.email + c.jobTitle).toLowerCase().includes(term)).slice(0, 4), managers: managers.filter((m) => m.name.toLowerCase().includes(term)).slice(0, 3), } }, [q, jobs, candidates, managers]) function go(path, state) { setQ('') setOpen(false) navigate(path, { state }) } const empty = results && !results.jobs.length && !results.candidates.length && !results.managers.length return (