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

// Fetcher that accepts `input` as a parameter
const fetchInputData = async (input: string) => {
  const { data } = await axiosInstance.get(`/settings/${input}`);

  return data;
};

// Hook that takes `input` and uses it in the query key and fetcher
export const useGetInputData = (input: string) => {
  return useQuery({
    queryKey: ["InputData", input], // differentiate cache per input
    queryFn: () => fetchInputData(input),
    enabled: !!input, // only run if input is not empty/null
    staleTime: 1000 * 60 * 10,
    refetchOnWindowFocus: false,
  });
};
