'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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

var _styleModule = require('./style.module.scss');

var _styleModule2 = _interopRequireDefault(_styleModule);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/* istanbul ignore file */

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 _react2.default.createElement(
    'footer',
    { className: _styleModule2.default.SearchPagination },
    currentRefinement !== nbPages && _react2.default.createElement(
      'button',
      {
        className: _styleModule2.default['SearchPagination-Button'],
        'focus-hit': 'firstElementChild',
        onClick: function onClick(e) {
          return handlePageChange(e, 1);
        },
        type: 'button'
      },
      'Next'
    ),
    _react2.default.createElement(
      'span',
      { className: _styleModule2.default['SearchPagination-State'] },
      currentRefinement,
      ' of ',
      nbPages
    ),
    currentRefinement !== 1 && _react2.default.createElement(
      'button',
      {
        className: _styleModule2.default['SearchPagination-Button'],
        'focus-hit': 'lastElementChild',
        onClick: function onClick(e) {
          return handlePageChange(e, -1);
        },
        type: 'button'
      },
      'Back'
    )
  );
};

var Pagination = (0, _reactInstantsearchDom.connectPagination)(CustomPagination);

CustomPagination.propTypes = process.env.NODE_ENV !== "production" ? {
  currentRefinement: _propTypes2.default.number,
  nbPages: _propTypes2.default.number,
  refine: _propTypes2.default.func
} : {};

exports.default = Pagination;
module.exports = exports['default'];