Liferay.Loader.define("commerce-frontend-js@3.0.43/utilities/AJAX/index", ['module', 'exports', 'require', 'frontend-js-web', '../index'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _frontendJsWeb = require("frontend-js-web");

    var _index = require("../index");

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    var BASE_OPTIONS = _objectSpread({}, _index.fetchParams);

    function _fetch(url) {
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
      var formattedURL = new URL(url, Liferay.ThemeDisplay.getPortalURL());
      Object.entries(params).map(function (_ref) {
        var _ref2 = _slicedToArray(_ref, 2),
            key = _ref2[0],
            value = _ref2[1];

        formattedURL.searchParams.append(key, value);
      });
      return (0, _frontendJsWeb.fetch)(formattedURL.pathname + formattedURL.search, _objectSpread(_objectSpread({}, BASE_OPTIONS), options)).then(function (response) {
        if (!response.ok) {
          return response.json().catch(function (parseError) {
            return Promise.reject(new Error(parseError));
          }).then(function (reason) {
            return Promise.reject(reason);
          });
        }

        if (response.status === 204) {
          return Promise.resolve();
        }

        return response.json();
      }).catch(function (error) {
        return Promise.reject(error);
      });
    }

    var AJAX = {
      DELETE: function DELETE(apiUrl) {
        var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

        var options = _objectSpread({
          method: 'DELETE'
        }, customOptions);

        return _fetch(apiUrl, options);
      },
      GET: function GET(apiUrl) {
        var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
        return _fetch(apiUrl, customOptions);
      },
      PATCH: function PATCH(apiUrl) {
        var jsonProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
        var customOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

        var options = _objectSpread({
          body: JSON.stringify(jsonProps),
          method: 'PATCH'
        }, customOptions);

        return _fetch(apiUrl, options);
      },
      POST: function POST(apiUrl) {
        var json = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
        var customOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

        var options = _objectSpread({
          body: JSON.stringify(json),
          method: 'POST'
        }, customOptions);

        return _fetch(apiUrl, options);
      },
      PUT: function PUT(apiUrl) {
        var json = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
        var customOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

        var options = _objectSpread({
          body: JSON.stringify(json),
          method: 'PUT'
        }, customOptions);

        return _fetch(apiUrl, options);
      }
    };
    var _default = AJAX;
    exports.default = _default;
    //# sourceMappingURL=index.js.map
  }
});
//# sourceMappingURL=index.js.map