import React, { useCallback } from 'react';
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 = useCallback(function (page) {
    return function () {
      return onClickPageItem(page);
    };
  }, [onClickPageItem]);
  return React.createElement(React.Fragment, null, React.createElement(PageItem, {
    onClick: handlePageItemClick(FIRST_PAGE),
    isCurrentPage: isFirstPage,
    label: isFirstPage ? currentPageLabel : pageItemLabel,
    href: getPageHref(FIRST_PAGE)
  }, FIRST_PAGE), !isWithinFirstThree && !totalLessThanFive && React.createElement(TruncatedPageNumbers, null), isLastPage && !isFirstPage && !isWithinFirstThree && React.createElement(PageItem, {
    onClick: handlePageItemClick(currentPage - 2),
    label: pageItemLabel,
    href: getPageHref(currentPage - 2)
  }, currentPage - 2), !isFirstPage && !isSecondPage && React.createElement(PageItem, {
    onClick: handlePageItemClick(currentPage - 1),
    label: pageItemLabel,
    href: getPageHref(currentPage - 1)
  }, currentPage - 1), !isFirstPage && !isLastPage && React.createElement(PageItem, {
    isCurrentPage: true,
    label: currentPageLabel
  }, currentPage), !isLastPage && !isSecondLastPage && React.createElement(PageItem, {
    onClick: handlePageItemClick(currentPage + 1),
    label: pageItemLabel,
    href: getPageHref(currentPage + 1)
  }, currentPage + 1), isFirstPage && !totalLessThanFour && React.createElement(PageItem, {
    onClick: handlePageItemClick(FIRST_PAGE + 2),
    label: pageItemLabel,
    href: getPageHref(FIRST_PAGE + 2)
  }, FIRST_PAGE + 2), !isWithinLastThree && !totalLessThanFive && React.createElement(TruncatedPageNumbers, null), !totalIsOnlyOnePage && React.createElement(PageItem, {
    onClick: handlePageItemClick(numberOfPages),
    isCurrentPage: isLastPage,
    label: isLastPage ? currentPageLabel : pageItemLabel,
    href: getPageHref(numberOfPages)
  }, numberOfPages));
};
export default PageItems;