import * as React from "react";
import { useGuardedMutation } from "@open-mercato/ui/backend/injection/useGuardedMutation";
import { useT } from "@open-mercato/shared/lib/i18n/context";
function useDealMutationContext({
  currentDealId,
  fallbackId,
  data
}) {
  const t = useT();
  const mutationContextId = React.useMemo(
    () => currentDealId ? `customer-deal:${currentDealId}` : `customer-deal:${fallbackId || "pending"}`,
    [currentDealId, fallbackId]
  );
  const { runMutation, retryLastMutation } = useGuardedMutation({
    contextId: mutationContextId,
    blockedMessage: t("ui.forms.flash.saveBlocked", "Save blocked by validation")
  });
  const injectionContext = React.useMemo(
    () => ({
      formId: mutationContextId,
      dealId: currentDealId,
      resourceKind: "customers.deal",
      resourceId: currentDealId ?? void 0,
      data,
      retryLastMutation
    }),
    [currentDealId, data, mutationContextId, retryLastMutation]
  );
  const runMutationWithContext = React.useCallback(
    async (operation, mutationPayload) => {
      return runMutation({
        operation,
        mutationPayload,
        context: injectionContext
      });
    },
    [injectionContext, runMutation]
  );
  return {
    mutationContextId,
    injectionContext,
    runMutationWithContext,
    retryLastMutation
  };
}
export {
  useDealMutationContext
};
//# sourceMappingURL=useDealMutationContext.js.map
