"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var useRelayMutationWithApolloAPI_exports = {};
__export(useRelayMutationWithApolloAPI_exports, {
  useRelayMutationWithApolloAPI: () => useRelayMutationWithApolloAPI
});
module.exports = __toCommonJS(useRelayMutationWithApolloAPI_exports);
var import_hooks = require("react-relay/hooks");
function useRelayMutationWithApolloAPI(mutation) {
  const [commitMutation, isMutationInFlight] = (0, import_hooks.useMutation)(mutation);
  return [
    (options) => {
      return new Promise((resolve, reject) => {
        commitMutation({
          variables: options.variables,
          onCompleted: (response, errors) => {
            resolve(
              errors ? {
                data: response,
                errors: errors.map((e) => new Error(e.message))
              } : { data: response }
            );
          },
          onError: (error) => {
            reject(error);
          }
        });
      });
    },
    isMutationInFlight
  ];
}
