import React, { useState, useEffect, useRef } from 'react'; import { Link } from 'react-router-dom'; import { MagnifyingGlassIcon, XCircleIcon, HashIcon, } from '@phosphor-icons/react'; import useSearchableData from '../hooks/useSearchableData'; import { filterItems } from '../utils/search'; const categoryColorMap = { page: 'text-red-400 border-red-400/20 bg-red-400/5', command: 'text-amber-400 border-amber-400/20 bg-amber-400/5', post: 'text-blue-400 border-blue-400/20 bg-blue-400/5', project: 'text-orange-400 border-orange-400/20 bg-orange-400/5', log: 'text-rose-400 border-rose-400/20 bg-rose-400/5', app: 'text-teal-400 border-teal-400/20 bg-teal-400/5', story: 'text-violet-400 border-violet-400/20 bg-violet-400/5', notebook: 'text-lime-400 border-lime-400/20 bg-lime-400/5', }; const getCategoryStyle = (type) => { return categoryColorMap[type] || 'text-gray-400 border-white/10 bg-white/5'; }; const BrutalistSearch = ({ isVisible, toggleSearch }) => { const [searchTerm, setSearchTerm] = useState(''); const [searchResults, setSearchResults] = useState([]); const [isDropdownOpen, setIsDropdownOpen] = useState(false); const { items, isLoading } = useSearchableData(); const searchRef = useRef(null); const inputRef = useRef(null); useEffect(() => { if (isVisible && inputRef.current) { inputRef.current.focus(); } }, [isVisible]); useEffect(() => { if (searchTerm) { const results = filterItems(items, searchTerm).slice(0, 8); // Limit results for clean look setSearchResults(results); setIsDropdownOpen(true); } else { setSearchResults([]); setIsDropdownOpen(false); } }, [searchTerm, items]); useEffect(() => { const handleClickOutside = (event) => { if (searchRef.current && !searchRef.current.contains(event.target)) { setIsDropdownOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, []); const getResultLink = (result) => { return result.path || '/'; }; if (!isVisible) { return null; } return (