"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _reactInstantsearchDom = require("react-instantsearch-dom");

/* istanbul ignore file */
// Style
var classes = {};
/* istanbul ignore next */

if (typeof window !== 'undefined') classes = require("./style.module.scss");

var CustomPagination = function CustomPagination(_ref) {
  var currentRefinement = _ref.currentRefinement,
      nbPages = _ref.nbPages,
      refine = _ref.refine;
  if (nbPages <= 1) return null;

  var handlePageChange = function handlePageChange(e, i) {
    refine(currentRefinement + i);
    e.stopPropagation();
  };

  return /*#__PURE__*/_react["default"].createElement("footer", {
    className: classes.SearchPagination
  }, currentRefinement !== nbPages && /*#__PURE__*/_react["default"].createElement("button", {
    className: classes['SearchPagination-Button'],
    "focus-hit": "firstElementChild",
    onClick: function onClick(e) {
      return handlePageChange(e, 1);
    },
    type: "button"
  }, "Next"), /*#__PURE__*/_react["default"].createElement("span", {
    className: classes['SearchPagination-State']
  }, currentRefinement, " of ", nbPages), currentRefinement !== 1 && /*#__PURE__*/_react["default"].createElement("button", {
    className: classes['SearchPagination-Button'],
    "focus-hit": "lastElementChild",
    onClick: function onClick(e) {
      return handlePageChange(e, -1);
    },
    type: "button"
  }, "Back"));
};

var Pagination = (0, _reactInstantsearchDom.connectPagination)(CustomPagination);
CustomPagination.propTypes = {
  currentRefinement: _propTypes["default"].number,
  nbPages: _propTypes["default"].number,
  refine: _propTypes["default"].func
};
var _default = Pagination;
exports["default"] = _default;