'use strict';

var react = require('@carbon/react');
var React = require('react');
var PropTypes = require('prop-types');
var RuleBuilderPropTypes = require('./RuleBuilderPropTypes.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespace(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);

var propTypes = {
  rule: RuleBuilderPropTypes.RulesPropType.isRequired,
  onChange: PropTypes__default.default.func.isRequired,
  renderColumnField: PropTypes__default.default.func,
  renderOperandField: PropTypes__default.default.func,
  i18n: PropTypes__default.default.shape({
    valuePlaceholder: PropTypes__default.default.string
  })
};
var defaultProps = {
  renderColumnField: undefined,
  renderOperandField: undefined,
  i18n: {
    valuePlaceholder: 'Enter a value'
  }
};
var RuleValueField = function RuleValueField(_ref) {
  var rule = _ref.rule,
    _onChange = _ref.onChange,
    renderColumnField = _ref.renderColumnField,
    renderOperandField = _ref.renderOperandField,
    i18n = _ref.i18n;
  if (renderOperandField) {
    return renderOperandField({
      value: rule.value,
      onChange: _onChange
    });
  }
  if (renderColumnField) {
    return renderColumnField({
      value: rule.value,
      onChange: _onChange
    });
  }
  return /*#__PURE__*/React__namespace.createElement(react.TextInput, {
    id: "".concat(rule.id, "-value"),
    placeholder: i18n.valuePlaceholder,
    light: true,
    labelText: "",
    defaultValue: rule.value,
    onChange: function onChange(e) {
      return _onChange(e.target.value);
    },
    "data-testid": "".concat(rule.id, "-value")
  });
};
RuleValueField.propTypes = propTypes;
RuleValueField.defaultProps = defaultProps;
RuleValueField.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "RuleValueField",
  "props": {
    "renderColumnField": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "renderOperandField": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  valuePlaceholder: 'Enter a value',\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "valuePlaceholder": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "rule": {
      "description": "",
      "type": {
        "name": "custom",
        "raw": "RulesPropType.isRequired"
      },
      "required": false
    },
    "onChange": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    }
  }
};
var RuleValueField$1 = RuleValueField;

module.exports = RuleValueField$1;
