Liferay.Loader.define("portal-search-ranking-web@2.0.50/js/utils/util.es", ['module', 'exports', 'require'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.buildUrl = buildUrl;
    exports.insertAtIndex = insertAtIndex;
    exports.isArray = isArray;
    exports.isNil = isNil;
    exports.isNull = isNull;
    exports.removeAtIndex = removeAtIndex;
    exports.move = move;
    exports.removeIdFromList = removeIdFromList;
    exports.resultsDataToMap = resultsDataToMap;
    exports.toggleListItem = toggleListItem;
    exports.updateDataMap = updateDataMap;

    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;
    }

    function _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

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

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * The contents of this file are subject to the terms of the Liferay Enterprise
     * Subscription License ("License"). You may not use this file except in
     * compliance with the License. You can obtain a copy of the License by
     * contacting Liferay, Inc. See the License for the specific language governing
     * permissions and limitations under the License, including but not limited to
     * distribution rights of the Software.
     */

    /**
     * Sets parameters on a url.
     * @param {String} baseUrl The base url to modify
     * @param {Object} params Key-value pairs for parameters to set.
     * @return {String} The complete url string.
     */
    function buildUrl(baseUrl, params) {
      var url = new URL(baseUrl);
      var searchParams = url.searchParams;

      if (params) {
        Object.keys(params).forEach(function (key) {
          return searchParams.set(key, params[key]);
        });
      }

      return url.href;
    }
    /**
     * Inserts an item into a list at the specified index.
     * @param {Array} list The list where the item will be inserted into.
     * @param {number} index The position where the item will be inserted.
     * @param {*} item The item that will be inserted.
     * @return {Array}
     */

    function insertAtIndex(list, index, item) {
      return [].concat(_toConsumableArray(list.slice(0, index)), [item], _toConsumableArray(list.slice(index, list.length)));
    }
    /**
     * Checks if a value is an array.
     * @param {*} val The value to test.
     */

    function isArray(val) {
      return Object.prototype.toString.call(val) === '[object Array]';
    }
    /**
     * Checks if a value is null or undefined.
     * @param {*} val The variable to check.
     */

    function isNil(val) {
      return val == null;
    }
    /**
     * Checks if a value is null.
     * @param {*} val The value to check.
     */

    function isNull(val) {
      return val === null;
    }
    /**
     * Removes an item at the specified index.
     * @param {Array} list The list the where an item will be removed.
     * @param {number} index The position where the item will be removed.
     * @return {Array}
     */

    function removeAtIndex(list, index) {
      return list.filter(function (fItem, fIndex) {
        return fIndex !== index;
      });
    }
    /**
     * Moves an item in an array. Does not mutate the original array.
     * @param {Array} list The list to move an item.
     * @param {number} from The index of the item being moved.
     * @param {number} to The new index that the item will be moved to.
     */

    function move(list, from, to) {
      var listWithInserted = insertAtIndex(list, to, list[from]);
      return removeAtIndex(listWithInserted, from > to ? from + 1 : from);
    }
    /**
     * Removes an item from a list. If an array is given to the param 'toRemove',
     * each item in the array will be removed.
     * @param {Array} list The list of IDs to remove an item
     * @param {Array|number|string} toRemove The id or ids to remove.
     */

    function removeIdFromList() {
      var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      var toRemove = arguments.length > 1 ? arguments[1] : undefined;
      return list.filter(function (curId) {
        return isArray(toRemove) ? !toRemove.includes(curId) : curId !== toRemove;
      });
    }
    /**
     * Converts an array of search result objects to a map of id to result object.
     * If an id already exists in the dataMap it will be ignored.
     * Use `updateDataMap` to update specific properties from ids.
     * @param {Array} resultsData The items in search results.
     * @param {Object} initialMap The initial map data to prevent overwrites.
     * @return {Object} The new object that uses id as the key.
     */

    function resultsDataToMap(resultsData) {
      var initialMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      return resultsData.reduce(function (acc, cur) {
        return acc[cur.id] ? acc : _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, cur.id, cur));
      }, initialMap);
    }
    /**
     * Toggles an item to be added or removed from a list. Used for maintaining
     * selected ids in a list.
     * @param {Array} list The list to toggle an item.
     * @param {number|string} id The value of the item to add or remove.
     */

    function toggleListItem(list, id) {
      return list.includes(id) ? list.filter(function (value) {
        return value !== id;
      }) : [].concat(_toConsumableArray(list), [id]);
    }
    /**
     * Updates the specified ids in the dataMap with new properties. Ignores
     * performing updates on ids that don't exist in the dataMap.
     *
     * Do NOT use this method for adding new items to the data map since new ids
     * will be ignored. They are ignored to prevent creating new items with
     * incomplete properties.
     * @param {Object} dataMap The data map that will be updated.
     * @param {Array} ids The list of ids to update.
     * @param {Object} properties The item's new properties.
     * @returns {Object} The updated dataMap.
     */

    function updateDataMap(dataMap, ids, properties) {
      return ids.reduce(function (updatedDataMap, id) {
        if (!dataMap[id]) {
          return updatedDataMap;
        }

        return _objectSpread(_objectSpread({}, updatedDataMap), {}, _defineProperty({}, id, _objectSpread(_objectSpread({}, dataMap[id]), properties)));
      }, dataMap);
    }
    //# sourceMappingURL=util.es.js.map
  }
});
//# sourceMappingURL=util.es.js.map