Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/shared/components/pagination-bar/PaginationBar.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/pagination-bar', 'portal-workflow-metrics-web$path-to-regexp', 'frontend-js-react-web$react', '../../../components/AppContext.es', '../../hooks/useRouter.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports["default"] = void 0;

    var _paginationBar = require("@frontend-taglib-clay$clayui/pagination-bar");

    var _pathToRegexp = _interopRequireDefault(require("portal-workflow-metrics-web$path-to-regexp"));

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

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

    var _useRouter2 = require("../../hooks/useRouter.es");

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { "default": obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj["default"] = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

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

    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 PaginationBar = function PaginationBar(_ref) {
      var page = _ref.page,
          pageBuffer = _ref.pageBuffer,
          pageSize = _ref.pageSize,
          totalCount = _ref.totalCount,
          _ref$setPage = _ref.setPage,
          setPage = _ref$setPage === void 0 ? function () {} : _ref$setPage,
          _ref$setPageSize = _ref.setPageSize,
          setPageSize = _ref$setPageSize === void 0 ? function () {} : _ref$setPageSize,
          withoutRouting = _ref.withoutRouting;

      var _useContext = (0, _react.useContext)(_AppContext.AppContext),
          deltaValues = _useContext.deltaValues;

      var _useRouter = (0, _useRouter2.useRouter)(),
          history = _useRouter.history,
          search = _useRouter.location.search,
          _useRouter$match = _useRouter.match,
          params = _useRouter$match.params,
          path = _useRouter$match.path;

      var deltas = (0, _react.useMemo)(function () {
        return deltaValues.map(function (label) {
          return {
            label: label
          };
        });
      }, [deltaValues]);
      var labels = (0, _react.useMemo)(function () {
        return {
          paginationResults: Liferay.Language.get('showing-x-to-x-of-x-entries'),
          perPageItems: Liferay.Language.get('x-entries'),
          selectPerPageItems: Liferay.Language.get('x-entries')
        };
      }, []);
      var handleChangePageSize = (0, _react.useCallback)(function (newPageSize) {
        if (!withoutRouting) {
          var pathname = _pathToRegexp["default"].compile(path)(_objectSpread({}, params, {
            page: 1,
            pageSize: newPageSize
          }));

          history.push({
            pathname: pathname,
            search: search
          });
        } else {
          setPage(1);
          setPageSize(newPageSize);
        }
      }, // eslint-disable-next-line react-hooks/exhaustive-deps
      [params, path, search]);
      var handleChangePage = (0, _react.useCallback)(function (newPage) {
        if (!withoutRouting) {
          var pathname = _pathToRegexp["default"].compile(path)(_objectSpread({}, params, {
            page: newPage
          }));

          history.push({
            pathname: pathname,
            search: search
          });
        } else {
          setPage(newPage);
        }
      }, // eslint-disable-next-line react-hooks/exhaustive-deps
      [params, path, search]);

      if (totalCount <= deltaValues[0]) {
        return _react["default"].createElement(_react["default"].Fragment, null);
      }

      return _react["default"].createElement(_paginationBar.ClayPaginationBarWithBasicItems, {
        activeDelta: Number(pageSize),
        activePage: Number(page),
        className: "mt-2",
        deltas: deltas,
        ellipsisBuffer: pageBuffer,
        labels: labels,
        onDeltaChange: handleChangePageSize,
        onPageChange: handleChangePage,
        totalItems: Number(totalCount)
      });
    };

    var _default = PaginationBar;
    exports["default"] = _default;
    //# sourceMappingURL=PaginationBar.es.js.map
  }
});
//# sourceMappingURL=PaginationBar.es.js.map