Liferay.Loader.define("dynamic-data-mapping-form-field-type@5.0.95/KeyValue/KeyValue.es", ['module', 'exports', 'require', 'dynamic-data-mapping-form-renderer', 'frontend-js-react-web$react', '../FieldBase/ReactFieldBase.es', '../Text/Text.es', '../hooks/useSyncValue.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    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);
    }

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

    var _dynamicDataMappingFormRenderer = require("dynamic-data-mapping-form-renderer");

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

    var _ReactFieldBase = require("../FieldBase/ReactFieldBase.es");

    var _Text = _interopRequireDefault(require("../Text/Text.es"));

    var _useSyncValue3 = require("../hooks/useSyncValue.es");

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

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    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 _extends() {
      _extends = Object.assign || function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }return target;
      };return _extends.apply(this, arguments);
    }

    function _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    var KeyValue = function KeyValue(_ref) {
      var className = _ref.className,
          disabled = _ref.disabled,
          _onChange = _ref.onChange,
          value = _ref.value,
          otherProps = _objectWithoutProperties(_ref, ["className", "disabled", "onChange", "value"]);

      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "active form-text key-value-editor"
        }, /*#__PURE__*/_react.default.createElement("label", {
          className: "control-label key-value-label"
        }, className === 'key-value-reference-input' ? Liferay.Language.get('field-reference') : Liferay.Language.get('field-name'), ":"), /*#__PURE__*/_react.default.createElement("input", _extends({}, otherProps, {
          className: "".concat(disabled ? 'disabled ' : '').concat(className),
          onChange: function onChange(event) {
            var value = (0, _dynamicDataMappingFormRenderer.normalizeFieldName)(event.target.value);

            _onChange({
              target: {
                value: value
              }
            });
          },
          readOnly: disabled,
          tabIndex: disabled ? '-1' : '0',
          type: "text",
          value: value
        })))
      );
    };

    var Main = function Main(_ref2) {
      var generateKeyword = _ref2.generateKeyword,
          initialKeyword = _ref2.keyword,
          keywordReadOnly = _ref2.keywordReadOnly,
          name = _ref2.name,
          onBlur = _ref2.onBlur,
          _onChange2 = _ref2.onChange,
          onFocus = _ref2.onFocus,
          onKeywordBlur = _ref2.onKeywordBlur,
          onKeywordChange = _ref2.onKeywordChange,
          onReferenceBlur = _ref2.onReferenceBlur,
          onReferenceChange = _ref2.onReferenceChange,
          placeholder = _ref2.placeholder,
          readOnly = _ref2.readOnly,
          reference = _ref2.reference,
          required = _ref2.required,
          _ref2$showKeyword = _ref2.showKeyword,
          showKeyword = _ref2$showKeyword === void 0 ? false : _ref2$showKeyword,
          showLabel = _ref2.showLabel,
          spritemap = _ref2.spritemap,
          value = _ref2.value,
          visible = _ref2.visible,
          otherProps = _objectWithoutProperties(_ref2, ["generateKeyword", "keyword", "keywordReadOnly", "name", "onBlur", "onChange", "onFocus", "onKeywordBlur", "onKeywordChange", "onReferenceBlur", "onReferenceChange", "placeholder", "readOnly", "reference", "required", "showKeyword", "showLabel", "spritemap", "value", "visible"]);

      var _useSyncValue = (0, _useSyncValue3.useSyncValue)(initialKeyword),
          _useSyncValue2 = _slicedToArray(_useSyncValue, 2),
          keyword = _useSyncValue2[0],
          setKeyword = _useSyncValue2[1];

      var generateKeywordRef = (0, _react.useRef)(generateKeyword);
      return (/*#__PURE__*/_react.default.createElement(_ReactFieldBase.FieldBase, _extends({}, otherProps, {
          name: name,
          readOnly: readOnly,
          required: required,
          showLabel: showLabel,
          spritemap: spritemap,
          visible: visible
        }), /*#__PURE__*/_react.default.createElement(_Text.default, {
          name: "keyValueLabel".concat(name),
          onBlur: onBlur,
          onChange: function onChange(event) {
            var value = event.target.value;

            _onChange2(event);

            if (generateKeywordRef.current) {
              var newKeyword = (0, _dynamicDataMappingFormRenderer.normalizeFieldName)(value);
              onKeywordChange(event, newKeyword, true);
            }
          },
          onFocus: onFocus,
          placeholder: placeholder,
          readOnly: readOnly,
          required: required,
          showLabel: showLabel,
          spritemap: spritemap,
          syncDelay: false,
          value: value,
          visible: visible
        }), showKeyword && /*#__PURE__*/_react.default.createElement(KeyValue, {
          className: "key-value-input",
          disabled: keywordReadOnly,
          onBlur: onKeywordBlur,
          onChange: function onChange(event) {
            var value = event.target.value;
            generateKeywordRef.current = false;
            onKeywordChange(event, value, false);
            setKeyword(value);
          },
          value: keyword
        }), /*#__PURE__*/_react.default.createElement(KeyValue, {
          className: "key-value-reference-input",
          onBlur: onReferenceBlur,
          onChange: function onChange(event) {
            onReferenceChange(event);
          },
          value: reference
        }))
      );
    };

    Main.displayName = 'KeyValue';
    var _default = Main;
    exports.default = _default;
    //# sourceMappingURL=KeyValue.es.js.map
  }
});
//# sourceMappingURL=KeyValue.es.js.map