// utils/hooks/useGetMatches.ts
import axiosInstance from "@/lib/axios";
import { useQuery } from "@tanstack/react-query";

// useGetMatches.ts
const fetchIntrested = async (
  filters: Record<string, string>,
  page: number
) => {
  const userId = localStorage.getItem("userId");

  if (!userId) throw new Error("UserID not provided");

  const params = new URLSearchParams({
    page: page.toString(),
    per_page: "15",
  });

  // Append each filter only if it has a value
  Object.entries(filters).forEach(([key, value]) => {
    if (value && value.trim() !== "") {
      params.append(key, value);
    }
  });

  const { data } = await axiosInstance.get(
    `/users/${userId}/dashboard/intrested?${params.toString()}`
  );

  return data;
};

export const useGetIntrested = (
  filters: Record<string, string>,
  page: number
) => {
  return useQuery({
    queryKey: ["intrested", filters, page],
    queryFn: () => fetchIntrested(filters, page),
    staleTime: 1000 * 60 * 10,
    refetchOnWindowFocus: false,
    refetchOnMount: "always",
  });
};
