"use client";
import { useQuery } from "@tanstack/react-query";
import { fetchWithTeam } from "../lib/api/entities.js";
function useQuotaCheck(action, enabled = true) {
  const { data, isLoading } = useQuery({
    queryKey: ["quota-check", action],
    queryFn: async () => {
      const res = await fetchWithTeam("/api/v1/billing/check-action", {
        method: "POST",
        body: JSON.stringify({ action })
      });
      const json = await res.json();
      return json.data || { allowed: true };
    },
    enabled,
    staleTime: 3e4,
    // Cache for 30s
    retry: false
  });
  return {
    canCreate: (data == null ? void 0 : data.allowed) ?? true,
    // Default to true while loading
    isLoading,
    reason: data == null ? void 0 : data.reason,
    message: data == null ? void 0 : data.message,
    meta: data == null ? void 0 : data.meta,
    isQuotaExceeded: (data == null ? void 0 : data.reason) === "quota_exceeded",
    isFeatureBlocked: (data == null ? void 0 : data.reason) === "feature_not_in_plan"
  };
}
export {
  useQuotaCheck
};
