import { useQuery } from "@tanstack/react-query";
import { chatApi } from "../api/chat";

export function useChatSearch(companyId: string | null, query: string) {
  return useQuery({
    queryKey: ["chat", "search", companyId, query],
    queryFn: () => chatApi.searchMessages(companyId!, query),
    enabled: !!companyId && query.trim().length >= 2,
    placeholderData: (prev) => prev,
    staleTime: 30_000,
  });
}
