Liferay.Loader.define("dynamic-data-mapping-form-report-web@1.0.20/js/utils/client.es", ['module', 'exports', 'require', 'frontend-js-web'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.request = exports.getURL = void 0;

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

    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 HEADERS = {
      Accept: 'application/json',
      'Accept-Language': Liferay.ThemeDisplay.getBCP47LanguageId(),
      'Content-Type': 'application/json'
    };

    var parseJSON = function parseJSON(response, resolve, reject) {
      return response.text().then(function (text) {
        return resolve(text ? JSON.parse(text) : {});
      })["catch"](function (error) {
        return reject(error);
      });
    };

    var parseResponse = function parseResponse(response) {
      return new Promise(function (resolve, reject) {
        if (response.ok) {
          parseJSON(response, resolve, reject);
        } else {
          parseJSON(response, reject, reject);
        }
      });
    };

    var getURL = function getURL(path, params) {
      var _objectSpread2;

      params = _objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, 'p_auth', Liferay.authToken), _defineProperty(_objectSpread2, "t", Date.now()), _objectSpread2), params);
      var uri = new URL("".concat(window.location.origin).concat(path));
      var keys = Object.keys(params);
      keys.forEach(function (key) {
        if (Array.isArray(params[key])) {
          params[key].forEach(function (value) {
            return uri.searchParams.append(key, value);
          });
        } else {
          uri.searchParams.set(key, params[key]);
        }
      });
      return uri.toString();
    };

    exports.getURL = getURL;

    var request = function request(_ref) {
      var endpoint = _ref.endpoint,
          _ref$method = _ref.method,
          method = _ref$method === void 0 ? 'GET' : _ref$method,
          _ref$params = _ref.params,
          params = _ref$params === void 0 ? {} : _ref$params;
      return (0, _frontendJsWeb.fetch)(getURL(endpoint, params), {
        headers: HEADERS,
        method: method
      }).then(function (response) {
        return parseResponse(response);
      });
    };

    exports.request = request;
    //# sourceMappingURL=client.es.js.map
  }
});
//# sourceMappingURL=client.es.js.map