"use strict";

Liferay.Loader.define("@frontend-taglib-clay$clayui/shared@3.58.0/lib/getEllipsisItems", ['module', 'exports', 'require', 'frontend-js-react-web$react'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.getEllipsisItems = void 0;

    var _react = _interopRequireDefault(require("frontend-js-react-web$react"));

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

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

    function _nonIterableSpread() {
      throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
    }

    function _unsupportedIterableToArray(o, minLen) {
      if (!o) return;if (typeof o === "string") return _arrayLikeToArray(o, minLen);var n = Object.prototype.toString.call(o).slice(8, -1);if (n === "Object" && o.constructor) n = o.constructor.name;if (n === "Map" || n === "Set") return Array.from(o);if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
    }

    function _iterableToArray(iter) {
      if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
    }

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

    function _arrayLikeToArray(arr, len) {
      if (len == null || len > arr.length) len = arr.length;for (var i = 0, arr2 = new Array(len); i < len; i++) {
        arr2[i] = arr[i];
      }return arr2;
    }

    function _extends() {
      _extends = Object.assign || function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }return target;
      };return _extends.apply(this, arguments);
    }

    var getBufferList = function getBufferList(start, end, config) {
      var EllipsisComponent = config.EllipsisComponent,
          ellipsisProps = config.ellipsisProps,
          items = config.items,
          spritemap = config.spritemap;
      var removedItems = items.slice(start, Math.max(end, start));

      if (removedItems.length > 1) {
        return [/*#__PURE__*/_react.default.createElement(EllipsisComponent, _extends({
          items: removedItems,
          key: "ellipsisComponent",
          spritemap: spritemap
        }, ellipsisProps))];
      }

      return removedItems;
    };

    var getEllipsisItems = function getEllipsisItems(config, ellipsisBuffer) {
      var activeIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
      var items = config.items;
      var lastIndex = items.length - 1;

      var leftBuffer = getBufferList(1, activeIndex - ellipsisBuffer, config);
      var rightBuffer = getBufferList(activeIndex + ellipsisBuffer + 1, lastIndex, config);
      var newArray = [items[0]].concat(_toConsumableArray(leftBuffer), _toConsumableArray(items.slice(Math.max(activeIndex - ellipsisBuffer, 1), // Add 1 to account for active index
      Math.min(activeIndex + ellipsisBuffer + 1, lastIndex))), _toConsumableArray(rightBuffer));

      if (items.length > 1) {
        newArray.push(items[lastIndex]);
      }

      return newArray;
    };

    exports.getEllipsisItems = getEllipsisItems;
  }
});
//# sourceMappingURL=getEllipsisItems.js.map