import { useQuery } from "@tanstack/react-query";
import * as api from "../service/MenuService";
import { useParams } from "next/navigation";
import { hasAuthToken } from "@/lib/api/func";

export const useGetFoods = () => {
  const { name } = useParams<{ name: string }>();
  return useQuery({
    queryKey: ["menu", name],
    queryFn: () => api.getFoods(name),
    enabled: !!name,
    staleTime: 5 * 60_000,
    refetchOnMount: false,
  });
};

export const useGetCategories = () => {
  const { name } = useParams<{ name: string }>();
  return useQuery({
    queryKey: ["categories", name],
    queryFn: () => api.getCategories(name),
    enabled: !!name,
    staleTime: 5 * 60_000,
    refetchOnMount: false,
  });
};

export const useGetNotificationsCount = () => {
  return useQuery({
    queryKey: ["notifications-count"],
    queryFn: api.getNotificationsCount,
    enabled: hasAuthToken(),
  });
};
