import { isFunction, has } from "../../../min-dash/dist/index.esm.mjs";
function wrapForCompatibility(api) {
  return function() {
    if (!window.Promise) {
      throw new Error("Promises is not supported in this environment. Please polyfill Promise.");
    }
    var argLen = arguments.length;
    if (argLen >= 1 && isFunction(arguments[argLen - 1])) {
      var callback = arguments[argLen - 1];
      console.warn(new Error(
        "Passing callbacks to " + api.name + " is deprecated and will be removed in a future major release. Please switch to promises: https://bpmn.io/l/moving-to-promises.html"
      ));
      var argsWithoutCallback = Array.prototype.slice.call(arguments, 0, -1);
      api.apply(this, argsWithoutCallback).then(function(result) {
        var firstKey = Object.keys(result)[0];
        return callback(null, result[firstKey]);
      }, function(err) {
        return callback(err, err.warnings);
      });
    } else {
      return api.apply(this, arguments);
    }
  };
}
var DI_ERROR_MESSAGE = "Tried to access di from the businessObject. The di is available through the diagram element only. For more information, see https://github.com/bpmn-io/bpmn-js/issues/1472";
function ensureCompatDiRef(businessObject) {
  if (!has(businessObject, "di")) {
    Object.defineProperty(businessObject, "di", {
      enumerable: false,
      get: function() {
        throw new Error(DI_ERROR_MESSAGE);
      }
    });
  }
}
export {
  ensureCompatDiRef,
  wrapForCompatibility
};
