'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _BooleanConditionInput = require('./BooleanConditionInput');

var _BooleanConditionInput2 = _interopRequireDefault(_BooleanConditionInput);

var _FieldConditionInput = require('./FieldConditionInput');

var _FieldConditionInput2 = _interopRequireDefault(_FieldConditionInput);

var _searchOperators = require('../../../constants/searchOperators');

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

var conditionInputComponentForOperator = function conditionInputComponentForOperator(operator) {
  return operator === _searchOperators.OP_AND || operator === _searchOperators.OP_OR ? _BooleanConditionInput2.default : _FieldConditionInput2.default;
};

var propTypes = {
  condition: _propTypes2.default.instanceOf(_immutable2.default.Map),
  fields: _propTypes2.default.object,
  inline: _propTypes2.default.bool,
  readOnly: _propTypes2.default.bool,
  onCommit: _propTypes2.default.func
};

function SearchConditionInput(props) {
  var condition = props.condition,
      fields = props.fields,
      inline = props.inline,
      readOnly = props.readOnly,
      onCommit = props.onCommit;


  var operator = condition.get('op');
  var ConditionInput = conditionInputComponentForOperator(operator);

  return _react2.default.createElement(ConditionInput, {
    condition: condition,
    fields: fields,
    inline: inline,
    readOnly: readOnly,
    onCommit: onCommit
  });
}

SearchConditionInput.propTypes = propTypes;