"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 _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 _icon = _interopRequireDefault(require("../../icon"));

var _input = _interopRequireDefault(require("../../input"));

var _button = _interopRequireDefault(require("../../button"));

var _util = require("./util");

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

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

  function FilterInput(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, FilterInput);
    _this = _super.call(this, props);
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "componentWillReceiveProps", function (nextProps) {
      if ('filterValue' in nextProps) {
        var value = nextProps.filterValue;

        _this.setState({
          value: value
        });
      }
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleChange", function (event, input) {
      var onChange = _this.props.onChange;
      onChange(event.target.value);

      _this.setState({
        value: event.target.value
      });
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "clearInputValue", function () {
      var onChange = _this.props.onChange;
      onChange('');
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "focus", function () {
      _this.filterInputRef.focus();
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "blur", function () {
      _this.filterInputRef.blur();
    });

    var _value = props.filterValue || '';

    _this.state = {
      value: _value
    };
    return _this;
  }

  (0, _createClass2["default"])(FilterInput, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          prefixCls = _this$props.prefixCls,
          placeholder = _this$props.placeholder;
      var value = this.state.value;

      var suffix = value && /*#__PURE__*/_react["default"].createElement(_button["default"], {
        size: "small",
        onClick: this.clearInputValue,
        shape: "circle",
        icon: "close"
      });

      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-filter")
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(prefixCls, "-filter-input")
      }, /*#__PURE__*/_react["default"].createElement(_input["default"], {
        value: value,
        placeholder: placeholder,
        prefix: /*#__PURE__*/_react["default"].createElement(_icon["default"], {
          type: "search"
        }),
        suffix: suffix,
        onChange: this.handleChange,
        onKeyDown: this.props.onKeyDown,
        ref: (0, _util.saveRef)(this, 'filterInputRef')
      })));
    }
  }]);
  return FilterInput;
}(_react.Component);

var _default = FilterInput;
exports["default"] = _default;
//# sourceMappingURL=FilterInput.js.map
