import { GET_SIDEBAR_BADGE_ROUTE } from "@/core/utils/routes";
import axios from "axios";
import useSWR from "swr";

export const useSidebarBadge = ({ enable = true }) => {
  const fetcher = async (url) => {
    try {
      const response = await axios({
        url,
        method: "get",
        withCredentials: true,
      });
      return response.data.data;
    } catch (error) {
      throw new Error();
    }
  };

  return useSWR(enable ? GET_SIDEBAR_BADGE_ROUTE : "", fetcher, {
    keepPreviousData: true,
    dedupingInterval: 30000,
  });
};
