text: 'use strict';
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  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 _react = require('react');
  
  var _react2 = _interopRequireDefault(_react);
  
  var _propTypes = require('prop-types');
  
  var _propTypes2 = _interopRequireDefault(_propTypes);
  
  var _Pager = require('./Pager');
  
  var _Pager2 = _interopRequireDefault(_Pager);
  
  var _Options = require('./Options');
  
  var _Options2 = _interopRequireDefault(_Options);
  
  var _KeyCode = require('./KeyCode');
  
  var _KeyCode2 = _interopRequireDefault(_KeyCode);
  
  var _zh_CN = require('./locale/zh_CN');
  
  var _zh_CN2 = _interopRequireDefault(_zh_CN);
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  
  function noop() {}
  
  function isInteger(value) {
    return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  }
  
  var Pagination = function (_React$Component) {
    (0, _inherits3['default'])(Pagination, _React$Component);
  
    function Pagination(props) {
      (0, _classCallCheck3['default'])(this, Pagination);
  
      var _this = (0, _possibleConstructorReturn3['default'])(this, (Pagination.__proto__ || Object.getPrototypeOf(Pagination)).call(this, props));
  
      _initialiseProps.call(_this);
  
      var hasOnChange = props.onChange !== noop;
      var hasCurrent = 'current' in props;
      if (hasCurrent && !hasOnChange) {
        console.warn('Warning: You provided a `current` prop to a Pagination component without an `onChange` handler. This will render a read-only component.'); // eslint-disable-line
      }
  
      var current = props.defaultCurrent;
      if ('current' in props) {
        current = props.current;
      }
  
      var pageSize = props.defaultPageSize;
      if ('pageSize' in props) {
        pageSize = props.pageSize;
      }
  
      _this.state = {
        current: current,
        _current: current,
        pageSize: pageSize
      };
      return _this;
    }
  
    (0, _createClass3['default'])(Pagination, [{
      key: 'componentWillReceiveProps',
      value: function componentWillReceiveProps(nextProps) {
        if ('current' in nextProps) {
          this.setState({
            current: nextProps.current,
            _current: nextProps.current
          });
        }
  
        if ('pageSize' in nextProps) {
          var newState = {};
          var current = this.state.current;
          var newCurrent = this._calcPage(nextProps.pageSize);
          current = current > newCurrent ? newCurrent : current;
          if (!('current' in nextProps)) {
            newState.current = current;
            newState._current = current;
          }
          newState.pageSize = nextProps.pageSize;
          this.setState(newState);
        }
      }
  
      // private methods
  
    }, {
      key: 'render',
      value: function render() {
        var _this2 = this;
  
        var props = this.props;
        var locale = props.locale;
  
        var prefixCls = props.prefixCls;
        var allPages = this._calcPage();
        var pagerList = [];
        var jumpPrev = null;
        var jumpNext = null;
        var firstPager = null;
        var lastPager = null;
  
        var pageBufferSize = props.showLessItems ? 1 : 2;
        var _state = this.state,
            current = _state.current,
            pageSize = _state.pageSize;
  
  
        if (props.simple) {
          return _react2['default'].createElement(
            'ul',
            { className: prefixCls + ' ' + prefixCls + '-simple ' + props.className },
            _react2['default'].createElement(
              'li',
              {
                title: props.showTitle ? locale.prev_page : null,
                onClick: this._prev,
                tabIndex: '0',
                onKeyPress: function onKeyPress(evt) {
                  return _this2._runIfEnter(evt, _this2._prev);
                },
                className: (this._hasPrev() ? '' : prefixCls + '-disabled') + ' ' + prefixCls + '-prev',
                'aria-disabled': !this._hasPrev()
              },
              _react2['default'].createElement('a', null)
            ),
            _react2['default'].createElement(
              'li',
              {
                title: props.showTitle ? this.state.current + '/' + allPages : null,
                className: prefixCls + '-simple-pager'
              },
              _react2['default'].createElement('input', {
                type: 'text',
                value: this.state._current,
                onKeyDown: this._handleKeyDown,
                onKeyUp: this._handleKeyUp,
                onChange: this._handleKeyUp,
                size: '3'
              }),
              _react2['default'].createElement(
                'span',
                { className: prefixCls + '-slash' },
                '\uFF0F'
              ),
              allPages
            ),
            _react2['default'].createElement(
              'li',
              {
                title: props.showTitle ? locale.next_page : null,
                onClick: this._next,
                tabIndex: '0',
                onKeyPress: function onKeyPress(evt) {
                  return _this2._runIfEnter(evt, _this2._next);
                },
                className: (this._hasNext() ? '' : prefixCls + '-disabled') + ' ' + prefixCls + '-next',
                'aria-disabled': !this._hasNext()
              },
              _react2['default'].createElement('a', null)
            )
          );
        }
  
        if (allPages <= 5 + pageBufferSize * 2) {
          var _loop = function _loop(i) {
            var active = _this2.state.current === i;
            pagerList.push(_react2['default'].createElement(_Pager2['default'], {
              locale: locale,
              rootPrefixCls: prefixCls,
              onClick: function onClick() {
                _this2._handleChange(i);
              },
              onKeyPress: function onKeyPress(evt) {
                _this2._runIfEnter(evt, _this2._handleChange, i);
              },
              key: i,
              page: i,
              active: active,
              showTitle: props.showTitle
            }));
          };
  
          for (var i = 1; i <= allPages; i++) {
            _loop(i);
          }
        } else {
          var prevItemTitle = props.showLessItems ? locale.prev_3 : locale.prev_5;
          var nextItemTitle = props.showLessItems ? locale.next_3 : locale.next_5;
          jumpPrev = _react2['default'].createElement(
            'li',
            {
              title: props.showTitle ? prevItemTitle : null,
              key: 'prev',
              onClick: this._jumpPrev,
              tabIndex: '0',
              onKeyPress: function onKeyPress(evt) {
                return _this2._runIfEnter(evt, _this2._jumpPrev);
              },
              className: prefixCls + '-jump-prev'
            },
            _react2['default'].createElement('a', null)
          );
          jumpNext = _react2['default'].createElement(
            'li',
            {
              title: props.showTitle ? nextItemTitle : null,
              key: 'next',
              tabIndex: '0',
              onClick: this._jumpNext,
              onKeyPress: function onKeyPress(evt) {
                return _this2._runIfEnter(evt, _this2._jumpNext);
              },
              className: prefixCls + '-jump-next'
            },
            _react2['default'].createElement('a', null)
          );
          lastPager = _react2['default'].createElement(_Pager2['default'], {
            locale: props.locale,
            last: true,
            rootPrefixCls: prefixCls,
            onClick: function onClick() {
              return _this2._handleChange(allPages);
            },
            onKeyPress: function onKeyPress(evt) {
              _this2._runIfEnter(evt, _this2._handleChange, allPages);
            },
            key: allPages,
            page: allPages,
            active: false,
            showTitle: props.showTitle
          });
          firstPager = _react2['default'].createElement(_Pager2['default'], {
            locale: props.locale,
            rootPrefixCls: prefixCls,
            onClick: function onClick() {
              return _this2._handleChange(1);
            },
            onKeyPress: function onKeyPress(evt) {
              _this2._runIfEnter(evt, _this2._handleChange, 1);
            },
            key: 1,
            page: 1,
            active: false,
            showTitle: props.showTitle
          });
  
          var left = Math.max(1, current - pageBufferSize);
          var right = Math.min(current + pageBufferSize, allPages);
  
          if (current - 1 <= pageBufferSize) {
            right = 1 + pageBufferSize * 2;
          }
  
          if (allPages - current <= pageBufferSize) {
            left = allPages - pageBufferSize * 2;
          }
  
          var _loop2 = function _loop2(i) {
            var active = current === i;
            pagerList.push(_react2['default'].createElement(_Pager2['default'], {
              locale: props.locale,
              rootPrefixCls: prefixCls,
              onClick: function onClick() {
                return _this2._handleChange(i);
              },
              onKeyPress: function onKeyPress(evt) {
                _this2._runIfEnter(evt, _this2._handleChange, i);
              },
              key: i,
              page: i,
              active: active,
              showTitle: props.showTitle
            }));
          };
  
          for (var i = left; i <= right; i++) {
            _loop2(i);
          }
  
          if (current - 1 >= pageBufferSize * 2 && current !== 1 + 2) {
            pagerList[0] = _react2['default'].cloneElement(pagerList[0], {
              className: prefixCls + '-item-after-jump-prev'
            });
            pagerList.unshift(jumpPrev);
          }
          if (allPages - current >= pageBufferSize * 2 && current !== allPages - 2) {
            pagerList[pagerList.length - 1] = _react2['default'].cloneElement(pagerList[pagerList.length - 1], {
              className: prefixCls + '-item-before-jump-next'
            });
            pagerList.push(jumpNext);
          }
  
          if (left !== 1) {
            pagerList.unshift(firstPager);
          }
          if (right !== allPages) {
            pagerList.push(lastPager);
          }
        }
  
        var totalText = null;
  
        if (props.showTotal) {
          totalText = _react2['default'].createElement(
            'li',
            { className: prefixCls + '-total-text' },
            props.showTotal(props.total, [(current - 1) * pageSize + 1, current * pageSize > props.total ? props.total : current * pageSize])
          );
        }
        var prevDisabled = !this._hasPrev();
        var nextDisabled = !this._hasNext();
        return _react2['default'].createElement(
          'ul',
          {
            className: prefixCls + ' ' + props.className,
            style: props.style,
            unselectable: 'unselectable'
          },
          totalText,
          _react2['default'].createElement(
            'li',
            {
              title: props.showTitle ? locale.prev_page : null,
              onClick: this._prev,
              tabIndex: '0',
              onKeyPress: function onKeyPress(evt) {
                return _this2._runIfEnter(evt, _this2._prev);
              },
              className: (!prevDisabled ? '' : prefixCls + '-disabled') + ' ' + prefixCls + '-prev',
              'aria-disabled': prevDisabled
            },
            _react2['default'].createElement('a', null)
          ),
          pagerList,
          _react2['default'].createElement(
            'li',
            {
              title: props.showTitle ? locale.next_page : null,
              onClick: this._next,
              tabIndex: '0',
              onKeyPress: function onKeyPress(evt) {
                return _this2._runIfEnter(evt, _this2._next);
              },
              className: (!nextDisabled ? '' : prefixCls + '-disabled') + ' ' + prefixCls + '-next',
              'aria-disabled': nextDisabled
            },
            _react2['default'].createElement('a', null)
          ),
          _react2['default'].createElement(_Options2['default'], {
            locale: props.locale,
            rootPrefixCls: prefixCls,
            selectComponentClass: props.selectComponentClass,
            selectPrefixCls: props.selectPrefixCls,
            changeSize: this.props.showSizeChanger ? this._changePageSize : null,
            current: this.state.current,
            pageSize: this.state.pageSize,
            pageSizeOptions: this.props.pageSizeOptions,
            quickGo: this.props.showQuickJumper ? this._handleChange : null
          })
        );
      }
    }]);
    return Pagination;
  }(_react2['default'].Component);
  
  Pagination.propTypes = {
    current: _propTypes2['default'].number,
    defaultCurrent: _propTypes2['default'].number,
    total: _propTypes2['default'].number,
    pageSize: _propTypes2['default'].number,
    defaultPageSize: _propTypes2['default'].number,
    onChange: _propTypes2['default'].func,
    showSizeChanger: _propTypes2['default'].bool,
    showLessItems: _propTypes2['default'].bool,
    onShowSizeChange: _propTypes2['default'].func,
    selectComponentClass: _propTypes2['default'].func,
    showQuickJumper: _propTypes2['default'].bool,
    showTitle: _propTypes2['default'].bool,
    pageSizeOptions: _propTypes2['default'].arrayOf(_propTypes2['default'].string),
    showTotal: _propTypes2['default'].func,
    locale: _propTypes2['default'].object,
    style: _propTypes2['default'].object
  };
  Pagination.defaultProps = {
    defaultCurrent: 1,
    total: 0,
    defaultPageSize: 10,
    onChange: noop,
    className: '',
    selectPrefixCls: 'rc-select',
    prefixCls: 'rc-pagination',
    selectComponentClass: null,
    showQuickJumper: false,
    showSizeChanger: false,
    showLessItems: false,
    showTitle: true,
    onShowSizeChange: noop,
    locale: _zh_CN2['default'],
    style: {}
  };
  
  var _initialiseProps = function _initialiseProps() {
    var _this3 = this;
  
    this._calcPage = function (p) {
      var pageSize = p;
      if (typeof pageSize === 'undefined') {
        pageSize = _this3.state.pageSize;
      }
      return Math.floor((_this3.props.total - 1) / pageSize) + 1;
    };
  
    this._isValid = function (page) {
      return isInteger(page) && page >= 1 && page !== _this3.state.current;
    };
  
    this._handleKeyDown = function (evt) {
      if (evt.keyCode === _KeyCode2['default'].ARROW_UP || evt.keyCode === _KeyCode2['default'].ARROW_DOWN) {
        evt.preventDefault();
      }
    };
  
    this._handleKeyUp = function (evt) {
      var _val = evt.target.value;
      var val = void 0;
  
      if (_val === '') {
        val = _val;
      } else if (isNaN(Number(_val))) {
        val = _this3.state._current;
      } else {
        val = Number(_val);
      }
  
      _this3.setState({
        _current: val
      });
  
      if (evt.keyCode === _KeyCode2['default'].ENTER) {
        _this3._handleChange(val);
      } else if (evt.keyCode === _KeyCode2['default'].ARROW_UP) {
        _this3._handleChange(val - 1);
      } else if (evt.keyCode === _KeyCode2['default'].ARROW_DOWN) {
        _this3._handleChange(val + 1);
      }
    };
  
    this._changePageSize = function (size) {
      var current = _this3.state.current;
      var newCurrent = _this3._calcPage(size);
      current = current > newCurrent ? newCurrent : current;
      if (typeof size === 'number') {
        if (!('pageSize' in _this3.props)) {
          _this3.setState({
            pageSize: size
          });
        }
        if (!('current' in _this3.props)) {
          _this3.setState({
            current: current,
            _current: current
          });
        }
      }
      _this3.props.onShowSizeChange(current, size);
    };
  
    this._handleChange = function (p) {
      var page = p;
      if (_this3._isValid(page)) {
        if (page > _this3._calcPage()) {
          page = _this3._calcPage();
        }
  
        if (!('current' in _this3.props)) {
          _this3.setState({
            current: page,
            _current: page
          });
        }
  
        var pageSize = _this3.state.pageSize;
        _this3.props.onChange(page, pageSize);
  
        return page;
      }
  
      return _this3.state.current;
    };
  
    this._prev = function () {
      if (_this3._hasPrev()) {
        _this3._handleChange(_this3.state.current - 1);
      }
    };
  
    this._next = function () {
      if (_this3._hasNext()) {
        _this3._handleChange(_this3.state.current + 1);
      }
    };
  
    this._jumpPrev = function () {
      _this3._handleChange(Math.max(1, _this3.state.current - (_this3.props.showLessItems ? 3 : 5)));
    };
  
    this._jumpNext = function () {
      _this3._handleChange(Math.min(_this3._calcPage(), _this3.state.current + (_this3.props.showLessItems ? 3 : 5)));
    };
  
    this._hasPrev = function () {
      return _this3.state.current > 1;
    };
  
    this._hasNext = function () {
      return _this3.state.current < _this3._calcPage();
    };
  
    this._runIfEnter = function (event, callback) {
      for (var _len = arguments.length, restParams = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
        restParams[_key - 2] = arguments[_key];
      }
  
      if (event.key === 'Enter' || event.charCode === 13) {
        callback.apply(undefined, restParams);
      }
    };
  };
  
  exports['default'] = Pagination;
  module.exports = exports['default'];