"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var FIRST_PAGE = 1;
var PageItems = function PageItems(_ref) {
  var currentPage = _ref.currentPage,
    numberOfPages = _ref.numberOfPages,
    onClickPageItem = _ref.onClickPageItem,
    PageItem = _ref.PageItem,
    TruncatedPageNumbers = _ref.TruncatedPageNumbers,
    currentPageLabel = _ref.currentPageLabel,
    pageItemLabel = _ref.pageItemLabel,
    _ref$getPageHref = _ref.getPageHref,
    getPageHref = _ref$getPageHref === void 0 ? function () {
      return undefined;
    } : _ref$getPageHref;
  var isFirstPage = currentPage === FIRST_PAGE;
  var isSecondPage = currentPage === FIRST_PAGE + 1;
  var isSecondLastPage = currentPage === numberOfPages - 1;
  var isLastPage = currentPage === numberOfPages;
  var isWithinFirstThree = currentPage <= 3;
  var isWithinLastThree = currentPage > numberOfPages - 3;
  var totalIsOnlyOnePage = numberOfPages === FIRST_PAGE;
  var totalLessThanFour = numberOfPages < 4;
  var totalLessThanFive = numberOfPages < 5;
  var handlePageItemClick = (0, _react.useCallback)(function (page) {
    return function () {
      return onClickPageItem(page);
    };
  }, [onClickPageItem]);
  return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(PageItem, {
    onClick: handlePageItemClick(FIRST_PAGE),
    isCurrentPage: isFirstPage,
    label: isFirstPage ? currentPageLabel : pageItemLabel,
    href: getPageHref(FIRST_PAGE)
  }, FIRST_PAGE), !isWithinFirstThree && !totalLessThanFive && _react.default.createElement(TruncatedPageNumbers, null), isLastPage && !isFirstPage && !isWithinFirstThree && _react.default.createElement(PageItem, {
    onClick: handlePageItemClick(currentPage - 2),
    label: pageItemLabel,
    href: getPageHref(currentPage - 2)
  }, currentPage - 2), !isFirstPage && !isSecondPage && _react.default.createElement(PageItem, {
    onClick: handlePageItemClick(currentPage - 1),
    label: pageItemLabel,
    href: getPageHref(currentPage - 1)
  }, currentPage - 1), !isFirstPage && !isLastPage && _react.default.createElement(PageItem, {
    isCurrentPage: true,
    label: currentPageLabel
  }, currentPage), !isLastPage && !isSecondLastPage && _react.default.createElement(PageItem, {
    onClick: handlePageItemClick(currentPage + 1),
    label: pageItemLabel,
    href: getPageHref(currentPage + 1)
  }, currentPage + 1), isFirstPage && !totalLessThanFour && _react.default.createElement(PageItem, {
    onClick: handlePageItemClick(FIRST_PAGE + 2),
    label: pageItemLabel,
    href: getPageHref(FIRST_PAGE + 2)
  }, FIRST_PAGE + 2), !isWithinLastThree && !totalLessThanFive && _react.default.createElement(TruncatedPageNumbers, null), !totalIsOnlyOnePage && _react.default.createElement(PageItem, {
    onClick: handlePageItemClick(numberOfPages),
    isCurrentPage: isLastPage,
    label: isLastPage ? currentPageLabel : pageItemLabel,
    href: getPageHref(numberOfPages)
  }, numberOfPages));
};
var _default = exports.default = PageItems;