"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = exports.Pagination = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _Focusable = require("../common/Focusable");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _PaginationCore = _interopRequireDefault(require("./PaginationCore"));
var _PaginationSt = require("./Pagination.st.css.js");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Pagination/Pagination.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var coreComponentDefaults = {
  showFirstPage: true,
  showLastPage: true,
  responsive: false,
  showFirstLastNavButtons: false,
  showInputModeTotalPages: false,
  paginationMode: 'pages',
  nextLabel: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.ChevronRight, {
    className: _PaginationSt.classes.arrow,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 16,
      columnNumber: 14
    }
  }),
  previousLabel: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.ChevronLeft, {
    className: _PaginationSt.classes.arrow,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 17,
      columnNumber: 18
    }
  })
};

/** Component for pagination */
class Pagination extends _react.PureComponent {
  constructor() {
    super(...arguments);
    this._getMaxPagesToShow = () => {
      var {
        currentPage,
        totalPages
      } = this.props;
      var defaultCount = 7;
      if (!currentPage || !totalPages) return defaultCount;
      var absoluteNumDistance = Math.min(Math.abs(1 - currentPage), Math.abs(currentPage - totalPages));
      if (absoluteNumDistance >= 4) {
        return 9;
      } else if (absoluteNumDistance === 3) {
        return 8;
      }
      return defaultCount;
    };
  }
  render() {
    var {
      dataHook,
      currentPage,
      totalPages,
      onChange,
      nextLabel,
      previousLabel,
      className,
      pageUrl
    } = this.props;
    return /*#__PURE__*/_react.default.createElement("div", {
      className: (0, _PaginationSt.st)(_PaginationSt.classes.root, className),
      "data-hook": dataHook,
      onFocus: this.props.focusableOnFocus,
      onBlur: this.props.focusableOnBlur,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 61,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react.default.createElement(_PaginationCore.default, (0, _extends2.default)({
      className: _PaginationSt.classes.pagination
    }, coreComponentDefaults, {
      previousLabel: previousLabel || coreComponentDefaults.previousLabel,
      nextLabel: nextLabel || coreComponentDefaults.nextLabel,
      onChange: onChange,
      totalPages: totalPages,
      currentPage: currentPage,
      maxPagesToShow: this._getMaxPagesToShow(),
      showNextLabel: currentPage !== totalPages,
      showPreviousLabel: currentPage !== 1,
      pageUrl: pageUrl,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 67,
        columnNumber: 9
      }
    })));
  }
}
exports.Pagination = Pagination;
Pagination.displayName = 'Pagination';
Pagination.defaultProps = {
  currentPage: 1
};
var _default = exports.default = (0, _Focusable.withFocusable)(Pagination);
//# sourceMappingURL=Pagination.js.map