'use client'; import { useCallback, useEffect, useRef, useState } from 'react'; import { ArrowRight, FileText, Search, X } from 'lucide-react'; import { cn } from '@/lib/utils'; const PAGES = [ { title: 'Faculty', href: '/people/faculty', section: 'People' }, { title: 'Staff', href: '/people/staff', section: 'People' }, { title: 'Research Scholars', href: '/people/students', section: 'People' }, { title: 'Postdoctoral Researchers', href: '/people/postdocs', section: 'People' }, { title: 'B.Tech Program', href: '/academics/btech', section: 'Academics' }, { title: 'M.Tech Program', href: '/academics/mtech', section: 'Academics' }, { title: 'PhD Program', href: '/academics/phd', section: 'Academics' }, { title: 'Courses', href: '/academics/courses', section: 'Academics' }, { title: 'Research Areas', href: '/research', section: 'Research' }, { title: 'Labs & Groups', href: '/research/labs', section: 'Research' }, { title: 'Publications', href: '/research/publications', section: 'Research' }, { title: 'News', href: '/news', section: 'Updates' }, { title: 'Events', href: '/events', section: 'Updates' }, { title: 'Blog', href: '/blog', section: 'Updates' }, { title: 'About', href: '/about', section: 'About' }, { title: 'Leadership', href: '/about/leadership', section: 'About' }, { title: 'Contact', href: '/about/contact', section: 'About' }, { title: 'Careers', href: '/about/careers', section: 'Careers' }, ]; interface SearchModalProps { open: boolean; onClose: () => void; } export function SearchModal({ open, onClose }: SearchModalProps) { const [query, setQuery] = useState(''); const inputRef = useRef(null); const filtered = query.trim() ? PAGES.filter( (p) => p.title.toLowerCase().includes(query.toLowerCase()) || p.section.toLowerCase().includes(query.toLowerCase()), ) : PAGES; const handleKeyDown = useCallback( (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }, [onClose], ); useEffect(() => { if (open) { document.addEventListener('keydown', handleKeyDown); document.body.style.overflow = 'hidden'; setTimeout(() => inputRef.current?.focus(), 50); } else { document.body.style.overflow = ''; } return () => { document.removeEventListener('keydown', handleKeyDown); document.body.style.overflow = ''; }; }, [open, handleKeyDown]); useEffect(() => { if (!open) setQuery(''); }, [open]); if (!open) return null; return (
{/* Search input */}
setQuery(e.target.value)} placeholder="Search pages, people, programs..." className="placeholder:text-muted-foreground flex-1 bg-transparent text-base outline-none" />
{/* Results */}
{filtered.length === 0 ? (
No results found for "{query}"
) : ( filtered.map((page) => (

{page.title}

{page.section}

)) )}
{/* Footer hint */}
Esc {' '} to close
); }