"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

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

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

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

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

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

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

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

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

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

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

var _KeyCode = _interopRequireDefault(require("./KeyCode"));

var Options = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(Options, _Component);

  var _super = (0, _createSuper2["default"])(Options);

  function Options(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, Options);
    _this = _super.call(this, props);
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "buildOptionText", function (value) {
      return "".concat(value, " ").concat(_this.props.locale.items_per_page);
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeSize", function (value) {
      _this.props.changeSize(Number(value));
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleChange", function (e) {
      _this.setState({
        goInputText: e.target.value
      });
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "go", function (e) {
      var val = _this.state.goInputText;

      if (val === '') {
        return;
      }

      val = Number(val);

      if (isNaN(val)) {
        val = _this.state.current;
      }

      if (e.keyCode === _KeyCode["default"].ENTER || e.type === 'click') {
        _this.setState({
          goInputText: '',
          current: _this.props.quickGo(val)
        });
      }
    });
    _this.state = {
      current: props.current,
      goInputText: ''
    };
    return _this;
  }

  (0, _createClass2["default"])(Options, [{
    key: "render",
    value: function render() {
      var props = this.props;
      var state = this.state;
      var locale = props.locale;
      var prefixCls = "".concat(props.rootPrefixCls, "-options");
      var changeSize = props.changeSize;
      var quickGo = props.quickGo;
      var goButton = props.goButton;
      var buildOptionText = props.buildOptionText || this.buildOptionText;
      var Select = props.selectComponentClass;
      var changeSelect = null;
      var goInput = null;
      var gotoButton = null;
      var label = null;

      if (!(changeSize || quickGo)) {
        return null;
      }

      if (changeSize && Select) {
        var Option = Select.Option;
        var pageSize = props.pageSize || props.pageSizeOptions[0];
        var options = props.pageSizeOptions.map(function (opt, i) {
          return /*#__PURE__*/_react["default"].createElement(Option, {
            key: i,
            value: opt
          }, buildOptionText(opt));
        });
        changeSelect = /*#__PURE__*/_react["default"].createElement(Select, (0, _extends2["default"])({}, props.selectProps, {
          showSearch: false,
          className: "".concat(prefixCls, "-size-changer"),
          optionLabelProp: "children",
          dropdownMatchSelectWidth: false,
          value: pageSize.toString(),
          onChange: this.changeSize,
          getPopupContainer: function getPopupContainer(triggerNode) {
            return triggerNode.parentNode;
          },
          border: false
        }), options);
      }

      if (quickGo) {
        if (goButton) {
          if (typeof goButton === 'boolean') {
            gotoButton = /*#__PURE__*/_react["default"].createElement("button", {
              type: "button",
              onClick: this.go,
              onKeyUp: this.go
            }, locale.jump_to_confirm);
          } else {
            gotoButton = /*#__PURE__*/_react["default"].createElement("span", {
              onClick: this.go,
              onKeyUp: this.go
            }, goButton);
          }
        }

        goInput = /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(prefixCls, "-quick-jumper")
        }, locale.jump_to, /*#__PURE__*/_react["default"].createElement("input", {
          type: "text",
          value: state.goInputText,
          onChange: this.handleChange,
          onKeyUp: this.go
        }), locale.page, gotoButton);
      }

      if (props.changeSizeLabel) {
        label = /*#__PURE__*/_react["default"].createElement("span", {
          className: "".concat(prefixCls, "-label")
        }, locale.label_items_per_page);
      }

      return /*#__PURE__*/_react["default"].createElement("li", {
        className: "".concat(prefixCls)
      }, label, changeSelect, goInput);
    }
  }]);
  return Options;
}(_react.Component);

exports["default"] = Options;
(0, _defineProperty2["default"])(Options, "defaultProps", {
  pageSizeOptions: ['10', '20', '30', '40']
});
//# sourceMappingURL=Options.js.map
