import axiosInstance from "@/lib/axios";
import { useQuery } from "@tanstack/react-query";

// Fetcher that accepts `input` as a parameter
const fetchUserProfile = async () => {
  const userId = localStorage.getItem("userId");

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

  const { data } = await axiosInstance.get(
    `/users/${userId}/dashboard/profile/${userId}`
  );

  return data;
};

export const useGetUserProfile = () => {
  return useQuery({
    queryKey: ["UserProfile"],
    queryFn: fetchUserProfile,
    staleTime: 1000 * 60 * 10,
    refetchOnWindowFocus: false,
    refetchOnMount: "always",
  });
};
