'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = undefined;

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _dec, _class, _class2, _temp;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Pagination = require('@instructure/ui-pagination/lib/components/Pagination');

var _Pagination2 = _interopRequireDefault(_Pagination);

var _lib = require('@instructure/ui-themeable/lib');

var _lib2 = _interopRequireDefault(_lib);

var _formatMessage = require('../../../format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

var _theme = require('./theme');

var _theme2 = _interopRequireDefault(_theme);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.Paginator__styles__pagination {\n  padding-top: ' + theme.paginationPadding + ';\n}\n';
  },
  'pagination': 'Paginator__styles__pagination'
};
var Paginator = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp = _class2 = function (_Component) {
  (0, _inherits3.default)(Paginator, _Component);

  function Paginator() {
    (0, _classCallCheck3.default)(this, Paginator);
    return (0, _possibleConstructorReturn3.default)(this, (Paginator.__proto__ || Object.getPrototypeOf(Paginator)).apply(this, arguments));
  }

  (0, _createClass3.default)(Paginator, [{
    key: 'renderPagination',
    value: function renderPagination() {
      var _this2 = this;

      var paginationButtons = Array.from(Array(this.props.totalPages)).map(function (v, i) {
        var page = i + 1;
        return _react2.default.createElement(
          _Pagination.PaginationButton,
          {
            key: i,
            current: page === _this2.props.currentPage,
            onClick: _this2.props.onPageChange.bind(null, page)
          },
          page
        );
      });
      return _react2.default.createElement(
        'div',
        { className: styles.pagination },
        _react2.default.createElement(
          _Pagination2.default,
          {
            labelNext: 'N\xE6ste side',
            labelPrev: 'Forrige side',
            variant: 'compact'
          },
          paginationButtons
        )
      );
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        null,
        this.props.children,
        this.renderPagination()
      );
    }
  }]);
  Paginator.displayName = 'Paginator'
  ;
  return Paginator;
}(_react.Component), _class2.propTypes = {
  children: _propTypes2.default.node.isRequired,
  currentPage: _propTypes2.default.number.isRequired,
  onPageChange: _propTypes2.default.func.isRequired,
  totalPages: _propTypes2.default.number.isRequired
}, _temp)) || _class);
exports.default = Paginator;