import { useQuery } from "@tanstack/react-query";
import { apiFetch } from "@/lib/api-client";
import { TypeCartillaResults } from "@/components/cartilla/types";

const useCartillaResults = (filtros: Record<string, string>, rubroValue: string) => {
  return useQuery({
    queryKey: ["cartilla-results", filtros],
    queryFn: () => {
      const params = new URLSearchParams(filtros).toString();
      return apiFetch<TypeCartillaResults>(`prestadores?${params}&rubro=${rubroValue.split("=")[1]}`);
    },
    enabled: Boolean(filtros.plan && filtros.especialidad && filtros.localidad),
    retry: false,
  });
};

export default useCartillaResults;
