import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { TextInput } from './form/TextInput';
import { Block } from './Block';
import { Icon } from './Icon';
export var Filter =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(Filter, _React$Component);

  function Filter(props, context) {
    var _this;

    _this = _React$Component.call(this, props, context) || this;
    _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this));
    _this.handleFocusField = _this.handleFocusField.bind(_assertThisInitialized(_this));
    return _this;
  }

  var _proto = Filter.prototype;

  _proto.handleChange = function handleChange(event) {
    this.props.onChange(this.refs.searchField.getValue());
  };

  _proto.focus = function focus() {
    this.refs.searchField.focus();
  };

  _proto.handleFocusField = function handleFocusField(event) {
    if (this.props.selectOnFocus) {
      event.target.select();
    }

    if (this.props.onFocus) {
      this.props.onFocus(event);
    }
  };

  _proto.render = function render() {
    var _this$props = this.props,
        wrapperClassName = _this$props.wrapperClassName,
        ariaLabel = _this$props.ariaLabel,
        id = _this$props.id,
        props = _objectWithoutPropertiesLoose(_this$props, ["wrapperClassName", "ariaLabel", "id"]);

    Object.assign(props, {
      'aria-label': props['aria-label'] || ariaLabel,
      id: props['controlId'] || id
    });
    return React.createElement(Block, {
      className: "rc-filter",
      noOffset: true
    }, React.createElement(TextInput, _extends({}, props, {
      wrapperClassName: classnames('form-group', wrapperClassName),
      ref: "searchField",
      onChange: this.handleChange,
      onFocus: this.handleFocusField
    })), React.createElement(Icon, {
      name: "search"
    }));
  };

  return Filter;
}(React.Component);

_defineProperty(Filter, "propTypes", {
  onChange: PropTypes.func.isRequired,
  id: PropTypes.string,
  testAutomationId: PropTypes.string,
  wrapperClassName: PropTypes.string,
  selectOnFocus: PropTypes.bool,
  onFocus: PropTypes.func,
  ariaLabel: PropTypes.string
});

_defineProperty(Filter, "defaultProps", {
  id: null,
  testAutomationId: 'fieldFilter',
  wrapperClassName: '',
  selectOnFocus: false,
  onFocus: function onFocus() {},
  ariaLabel: 'TRANSLATE:SEARCH'
});