import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React, { Component } from 'react';
import Icon from '../../icon';
import Input from '../../input';
import Button from '../../button';
import { saveRef } from './util';

var FilterInput = /*#__PURE__*/function (_Component) {
  _inherits(FilterInput, _Component);

  var _super = _createSuper(FilterInput);

  function FilterInput(props) {
    var _this;

    _classCallCheck(this, FilterInput);

    _this = _super.call(this, props);

    _defineProperty(_assertThisInitialized(_this), "componentWillReceiveProps", function (nextProps) {
      if ('filterValue' in nextProps) {
        var value = nextProps.filterValue;

        _this.setState({
          value: value
        });
      }
    });

    _defineProperty(_assertThisInitialized(_this), "handleChange", function (event, input) {
      var onChange = _this.props.onChange;
      onChange(event.target.value);

      _this.setState({
        value: event.target.value
      });
    });

    _defineProperty(_assertThisInitialized(_this), "clearInputValue", function () {
      var onChange = _this.props.onChange;
      onChange('');
    });

    _defineProperty(_assertThisInitialized(_this), "focus", function () {
      _this.filterInputRef.focus();
    });

    _defineProperty(_assertThisInitialized(_this), "blur", function () {
      _this.filterInputRef.blur();
    });

    var _value = props.filterValue || '';

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

  _createClass(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.createElement(Button, {
        size: "small",
        onClick: this.clearInputValue,
        shape: "circle",
        icon: "close"
      });
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefixCls, "-filter")
      }, /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-filter-input")
      }, /*#__PURE__*/React.createElement(Input, {
        value: value,
        placeholder: placeholder,
        prefix: /*#__PURE__*/React.createElement(Icon, {
          type: "search"
        }),
        suffix: suffix,
        onChange: this.handleChange,
        onKeyDown: this.props.onKeyDown,
        ref: saveRef(this, 'filterInputRef')
      })));
    }
  }]);

  return FilterInput;
}(Component);

export default FilterInput;
//# sourceMappingURL=FilterInput.js.map
