import { useQuery } from "@tanstack/react-query";
import { useTeam } from "./useTeam.js";
function useQuota(limitSlug) {
  const { team } = useTeam();
  const {
    data: quotaInfo,
    isLoading,
    error,
    refetch
  } = useQuery({
    queryKey: ["quota", team == null ? void 0 : team.id, limitSlug],
    queryFn: async () => {
      if (!team) {
        throw new Error("No team selected");
      }
      const response = await fetch(`/api/v1/teams/${team.id}/usage/${limitSlug}`);
      if (!response.ok) {
        throw new Error("Failed to fetch quota info");
      }
      const data = await response.json();
      return data.data;
    },
    enabled: !!team && !!limitSlug,
    staleTime: 1 * 60 * 1e3,
    // 1 minute (quota checks should be relatively fresh)
    refetchOnWindowFocus: false
  });
  return {
    ...quotaInfo,
    isLoading,
    error,
    refetch
  };
}
export {
  useQuota
};
