"use strict";

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

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _immutable = _interopRequireDefault(require("immutable"));

var _BooleanConditionInput = _interopRequireDefault(require("./BooleanConditionInput"));

var _FieldConditionInput = _interopRequireDefault(require("./FieldConditionInput"));

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

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

const conditionInputComponentForOperator = operator => operator === _searchOperators.OP_AND || operator === _searchOperators.OP_OR ? _BooleanConditionInput.default : _FieldConditionInput.default;

const propTypes = {
  condition: _propTypes.default.instanceOf(_immutable.default.Map),
  fields: _propTypes.default.object,
  inline: _propTypes.default.bool,
  readOnly: _propTypes.default.bool,
  onCommit: _propTypes.default.func
};

function SearchConditionInput(props) {
  const {
    condition,
    fields,
    inline,
    readOnly,
    onCommit
  } = props;
  const operator = condition.get('op');
  const ConditionInput = conditionInputComponentForOperator(operator);
  return _react.default.createElement(ConditionInput, {
    condition: condition,
    fields: fields,
    inline: inline,
    readOnly: readOnly,
    onCommit: onCommit
  });
}

SearchConditionInput.propTypes = propTypes;