import React from 'react';
import { Flexbox, Typography } from '../../../index';
import PageItems from '../PageItems';
import ChevronIcon from './components/ChevronIcon';
import { StyledCurrentPageBox, StyledList, TruncatedPageNumbers, StyledLink } from './components/LargeComponents';
var PageItem = function PageItem(_ref) {
  var _ref$isCurrentPage = _ref.isCurrentPage,
    isCurrentPage = _ref$isCurrentPage === void 0 ? false : _ref$isCurrentPage,
    onClick = _ref.onClick,
    children = _ref.children,
    label = _ref.label,
    href = _ref.href;
  return React.createElement(Flexbox, {
    item: true,
    as: "li"
  }, isCurrentPage ? React.createElement(StyledCurrentPageBox, {
    container: true
  }, React.createElement(Typography, {
    type: "primary",
    color: function color(t) {
      return t.color.buttonText;
    },
    weight: "bold"
  }, children)) : React.createElement(StyledLink, {
    $type: "page-item",
    onClick: onClick,
    "aria-label": "".concat(label, " ").concat(children),
    to: href
  }, React.createElement(Typography, {
    type: "primary",
    color: function color(t) {
      return t.color.text;
    },
    weight: "bold"
  }, children)));
};
var ChevronLink = function ChevronLink(_ref2) {
  var direction = _ref2.direction,
    onClick = _ref2.onClick,
    label = _ref2.label,
    href = _ref2.href;
  return React.createElement(Flexbox, {
    item: true,
    container: true,
    alignItems: "center"
  }, React.createElement(StyledLink, {
    $type: "chevron",
    onClick: onClick,
    "aria-label": label,
    to: href
  }, React.createElement(ChevronIcon, {
    direction: direction,
    size: 16,
    inline: true
  })));
};
var LargeLinks = function LargeLinks(_ref3) {
  var currentPage = _ref3.currentPage,
    numberOfPages = _ref3.numberOfPages,
    _ref3$onClickPageItem = _ref3.onClickPageItem,
    onClickPageItem = _ref3$onClickPageItem === void 0 ? function () {} : _ref3$onClickPageItem,
    onClickPrevious = _ref3.onClickPrevious,
    onClickNext = _ref3.onClickNext,
    previousPageLabel = _ref3.previousPageLabel,
    nextPageLabel = _ref3.nextPageLabel,
    currentPageLabel = _ref3.currentPageLabel,
    pageItemLabel = _ref3.pageItemLabel,
    getPageHref = _ref3.getPageHref;
  if (numberOfPages <= 1) {
    return null;
  }
  return React.createElement(Flexbox, {
    container: true
  }, currentPage !== 1 && React.createElement(ChevronLink, {
    direction: "left",
    onClick: onClickPrevious,
    label: previousPageLabel,
    href: getPageHref(currentPage - 1)
  }), React.createElement(StyledList, {
    $numberOfPages: numberOfPages
  }, React.createElement(PageItems, {
    currentPage: currentPage,
    numberOfPages: numberOfPages,
    onClickPageItem: onClickPageItem,
    PageItem: PageItem,
    TruncatedPageNumbers: TruncatedPageNumbers,
    currentPageLabel: currentPageLabel,
    pageItemLabel: pageItemLabel,
    getPageHref: getPageHref
  })), currentPage !== numberOfPages && React.createElement(ChevronLink, {
    direction: "right",
    onClick: onClickNext,
    label: nextPageLabel,
    href: getPageHref(currentPage + 1)
  }));
};
export default React.memo(LargeLinks);