'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactIntl = require('react-intl');

var _cspaceInput = require('cspace-input');

var _AdminSearchBar = require('../../../styles/cspace-ui/AdminSearchBar.css');

var _AdminSearchBar2 = _interopRequireDefault(_AdminSearchBar);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const LineInput = _cspaceInput.components.LineInput,
      MiniButton = _cspaceInput.components.MiniButton;


const messages = (0, _reactIntl.defineMessages)({
  filter: {
    'id': 'vocabularySearchBarSearchBar.filter',
    'defaultMessage': 'Filter by name'
  },
  clear: {
    'id': 'vocabularySearchBar.clear',
    'defaultMessage': 'Clear'
  }
});

const propTypes = {
  value: _propTypes2.default.string,
  onChange: _propTypes2.default.func
};

const contextTypes = {
  intl: _reactIntl.intlShape
};

class VocabularySearchBar extends _react.Component {
  constructor() {
    super();

    this.handleClearButtonClick = this.handleClearButtonClick.bind(this);
    this.handleInputChange = this.handleInputChange.bind(this);
  }

  handleClearButtonClick() {
    const onChange = this.props.onChange;


    if (onChange) {
      onChange('');
    }
  }

  handleInputChange(value) {
    const onChange = this.props.onChange;


    if (onChange) {
      onChange(value);
    }
  }

  render() {
    const value = this.props.value;
    const intl = this.context.intl;


    return _react2.default.createElement(
      'div',
      { className: _AdminSearchBar2.default.common },
      _react2.default.createElement(LineInput, {
        label: intl.formatMessage(messages.filter),
        onChange: this.handleInputChange,
        value: value
      }),
      _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          MiniButton,
          {
            autoWidth: true,
            onClick: this.handleClearButtonClick
          },
          intl.formatMessage(messages.clear)
        )
      )
    );
  }
}

exports.default = VocabularySearchBar;
VocabularySearchBar.propTypes = propTypes;
VocabularySearchBar.contextTypes = contextTypes;