"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.Pagination = void 0;

var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _react = _interopRequireDefault(require("react"));

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _lib = require("@sentecacommerce-theme/lib");

var _router = require("next/router");

var _Common = require("../../../../../Common");

var _templateObject, _templateObject2, _templateObject3, _templateObject4;

var Pagination = function Pagination(_ref) {
  var lastPage = _ref.lastPage,
      currentPage = _ref.currentPage,
      canGoToNextPage = _ref.canGoToNextPage,
      canGoToPrevPage = _ref.canGoToPrevPage;
  var router = (0, _router.useRouter)();
  var pagesArray = lastPage && new Array(lastPage).fill(1).map(function (_, i) {
    return i + 1;
  });
  var arePrevDotsRendered = false;
  var areNextDotsRendered = false;
  var query = {};
  if (router.query.slug) query.slug = router.query.slug;
  return /*#__PURE__*/_react["default"].createElement(Container, null, pagesArray ? pagesArray.map(function (el, index) {
    if (el !== 1 && el < currentPage - 2) {
      if (arePrevDotsRendered) return null;
      arePrevDotsRendered = true;
      return /*#__PURE__*/_react["default"].createElement(Dots, {
        key: "Dots__" + el
      }, "...");
    }

    if (el !== lastPage && el > currentPage + 2) {
      if (areNextDotsRendered) return null;
      areNextDotsRendered = true;
      return /*#__PURE__*/_react["default"].createElement(Dots, {
        key: "Dots__" + el + "--" + index
      }, "...");
    }

    return /*#__PURE__*/_react["default"].createElement(_lib.Link, {
      key: "Link__" + index + "--" + el,
      href: {
        pathname: router.pathname || '',
        query: (0, _extends2["default"])({}, router.query || {}, {
          page: el
        })
      },
      passHref: true
    }, /*#__PURE__*/_react["default"].createElement(PageNumber, {
      current: el === currentPage
    }, /*#__PURE__*/_react["default"].createElement(NumberContainer, null, el)));
  }) : null);
};

exports.Pagination = Pagination;

var Container = _styledComponents["default"].div.attrs({
  className: 'd-flex mt-3 mb-5 align-items-center align-self-end'
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var PageNumber = (0, _styledComponents["default"])(_Common.Typography).attrs({
  color: 'primary',
  variant: 7,
  as: 'span'
})(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  position: relative;\n  min-width: 3rem;\n  min-height: 3rem;\n  border-radius: 0.3rem;\n  cursor: pointer;\n  margin: 0 0.25rem;\n  font-weight: bold;\n\n  &:after {\n    content: '';\n    position: absolute;\n    bottom: -0.66rem;\n    left: 25%;\n    width: 50%;\n    height: 0.4rem;\n    background-color: ", ";\n  }\n\n  @media (min-width: ", ") {\n    margin: 0 0.5rem;\n  }\n"])), function (_ref2) {
  var theme = _ref2.theme,
      current = _ref2.current;
  return current ? theme.palette.primary : 'initial';
}, function (_ref3) {
  var theme = _ref3.theme;
  return theme.breakpoints.lg.min;
});

var Dots = _styledComponents["default"].div.attrs({
  className: 'd-md-block'
})(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  min-width: 3rem;\n  min-height: 3rem;\n  margin: 0 0.25rem;\n  pointer-events: none;\n  font-weight: bold;\n  text-align: center;\n"])));

var NumberContainer = _styledComponents["default"].div.attrs({
  className: ''
})(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  position: absolute;\n  top: 50%;\n  left: 50%;\n  transform: translate(-50%, -50%);\n  line-height: 1;\n\n  ", ":hover & {\n    text-decoration: underline !important;\n  }\n"])), PageNumber);
//# sourceMappingURL=index.js.map