"use client"; import { Search, X } from "lucide-react"; import { useEffect, useRef, useState } from "react"; import { useMessageSearch } from "@/hooks"; import { getMessageChannelLabel, renderMessageContent } from "@/lib/format"; import type { MessageRecord } from "@/lib/types"; interface SearchOverlayProps { open: boolean; onClose: () => void; onSelect: (id: string) => void; } export function SearchOverlay({ open, onClose, onSelect }: SearchOverlayProps) { const [query, setQuery] = useState(""); const inputRef = useRef(null); const { data: results } = useMessageSearch(query, true); useEffect(() => { if (open) { setTimeout(() => inputRef.current?.focus(), 100); } else { setQuery(""); } }, [open]); useEffect(() => { const handleKey = (e: KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === "k") { e.preventDefault(); onClose(); // this is called when Cmd+K is pressed globally — toggle } if (e.key === "Escape") onClose(); }; document.addEventListener("keydown", handleKey); return () => document.removeEventListener("keydown", handleKey); }, [onClose]); if (!open) return null; return (
{/* Results */}
{!results || results.length === 0 ? (
{query.length < 2 ? "Type at least 2 characters" : "No results found"}
) : ( results.map((msg) => ( )) )}
); }