Liferay.Loader.define("segments-web@2.0.29/js/components/inputs/CollectionInput.es", ['module', 'exports', 'require', 'frontend-js-react-web$prop-types', 'frontend-js-react-web$react'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _propTypes = _interopRequireDefault(require("frontend-js-react-web$prop-types"));

    var _react = _interopRequireDefault(require("frontend-js-react-web$react"));

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

    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    function _classCallCheck(instance, Constructor) {
      if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
      }
    }

    function _defineProperties(target, props) {
      for (var i = 0; i < props.length; i++) {
        var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
      }
    }

    function _createClass(Constructor, protoProps, staticProps) {
      if (protoProps) _defineProperties(Constructor.prototype, protoProps);if (staticProps) _defineProperties(Constructor, staticProps);return Constructor;
    }

    function _possibleConstructorReturn(self, call) {
      if (call && (_typeof(call) === "object" || typeof call === "function")) {
        return call;
      }return _assertThisInitialized(self);
    }

    function _getPrototypeOf(o) {
      _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
        return o.__proto__ || Object.getPrototypeOf(o);
      };return _getPrototypeOf(o);
    }

    function _assertThisInitialized(self) {
      if (self === void 0) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
      }return self;
    }

    function _inherits(subClass, superClass) {
      if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function");
      }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });if (superClass) _setPrototypeOf(subClass, superClass);
    }

    function _setPrototypeOf(o, p) {
      _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
        o.__proto__ = p;return o;
      };return _setPrototypeOf(o, p);
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    /**
     * Input displayed for collection type properties. 2 inputs will be displayed
     * side by side. The resulting value will be a single string with an '='
     * character separating the key and value.
     * @class CollectionInput
     * @extends {React.Component}
     */
    var CollectionInput = /*#__PURE__*/function (_React$Component) {
      _inherits(CollectionInput, _React$Component);

      function CollectionInput() {
        var _getPrototypeOf2;

        var _this;

        _classCallCheck(this, CollectionInput);

        for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
          args[_key] = arguments[_key];
        }

        _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(CollectionInput)).call.apply(_getPrototypeOf2, [this].concat(args)));

        _defineProperty(_assertThisInitialized(_this), "_handleKeyChange", function (event) {
          var _this$_stringToKeyVal = _this._stringToKeyValueObject(_this.props.value),
              value = _this$_stringToKeyVal.value;

          _this.props.onChange({
            value: "".concat(event.target.value, "=").concat(value)
          });
        });

        _defineProperty(_assertThisInitialized(_this), "_handleValueChange", function (event) {
          var _this$_stringToKeyVal2 = _this._stringToKeyValueObject(_this.props.value),
              key = _this$_stringToKeyVal2.key;

          _this.props.onChange({
            value: "".concat(key, "=").concat(event.target.value)
          });
        });

        _defineProperty(_assertThisInitialized(_this), "_handleKeyDown", function (event) {
          if (event.key === '=') {
            event.preventDefault();
          }
        });

        _defineProperty(_assertThisInitialized(_this), "_stringToKeyValueObject", function (stringValue) {
          var _ref = typeof stringValue == 'string' ? stringValue.split('=') : [],
              _ref2 = _slicedToArray(_ref, 2),
              _ref2$ = _ref2[0],
              key = _ref2$ === void 0 ? '' : _ref2$,
              _ref2$2 = _ref2[1],
              value = _ref2$2 === void 0 ? '' : _ref2$2;

          return {
            key: key,
            value: value
          };
        });

        return _this;
      }

      _createClass(CollectionInput, [{
        key: "render",
        value: function render() {
          var disabled = this.props.disabled;

          var _this$_stringToKeyVal3 = this._stringToKeyValueObject(this.props.value),
              key = _this$_stringToKeyVal3.key,
              value = _this$_stringToKeyVal3.value;

          return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("input", {
              className: "criterion-input form-control",
              "data-testid": "collection-key-input",
              disabled: disabled,
              onChange: this._handleKeyChange,
              onKeyDown: this._handleKeyDown,
              placeholder: Liferay.Language.get('key'),
              type: "text",
              value: key
            }), /*#__PURE__*/_react.default.createElement("input", {
              className: "criterion-input form-control",
              "data-testid": "collection-value-input",
              disabled: disabled,
              onChange: this._handleValueChange,
              onKeyDown: this._handleKeyDown,
              placeholder: Liferay.Language.get('value'),
              type: "text",
              value: value
            }))
          );
        }
      }]);

      return CollectionInput;
    }(_react.default.Component);

    var _default = CollectionInput;
    exports.default = _default;
    //# sourceMappingURL=CollectionInput.es.js.map
  }
});
//# sourceMappingURL=CollectionInput.es.js.map