Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/shared/hooks/usePaginationState.es", ['module', 'exports', 'require', 'frontend-js-react-web$react', '../../components/AppContext.es', '../util/array.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.usePaginationState = void 0;

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

    var _AppContext = require("../../components/AppContext.es");

    var _array = require("../util/array.es");

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

    var usePaginationState = function usePaginationState(props) {
      var _useContext = (0, _react.useContext)(_AppContext.AppContext),
          defaultDelta = _useContext.defaultDelta;

      var _props$initialPage = props.initialPage,
          initialPage = _props$initialPage === void 0 ? 1 : _props$initialPage,
          _props$initialPageSiz = props.initialPageSize,
          initialPageSize = _props$initialPageSiz === void 0 ? defaultDelta : _props$initialPageSiz,
          _props$items = props.items,
          items = _props$items === void 0 ? false : _props$items;
      var defaultPageSize = initialPageSize <= defaultDelta ? initialPageSize : defaultDelta;

      var _useState = (0, _react.useState)(initialPage),
          _useState2 = _slicedToArray(_useState, 2),
          page = _useState2[0],
          setPage = _useState2[1];

      var _useState3 = (0, _react.useState)(defaultPageSize),
          _useState4 = _slicedToArray(_useState3, 2),
          pageSize = _useState4[0],
          setPageSize = _useState4[1];

      var pagination = (0, _react.useMemo)(function () {
        return {
          page: page,
          pageSize: pageSize,
          setPage: setPage,
          setPageSize: setPageSize
        };
      }, [page, pageSize]);
      var paginatedItems = (0, _react.useMemo)(function () {
        return items ? (0, _array.paginateArray)(items, page, pageSize) : [];
      }, [page, pageSize, items]);
      return {
        page: page,
        pageSize: pageSize,
        paginatedItems: paginatedItems,
        pagination: pagination
      };
    };

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