Liferay.Loader.define("dynamic-data-mapping-form-builder@3.0.51/js/components/LayoutProvider/handlers/fieldBlurredHandler.es", ['module', 'exports', 'require', '../util/settingsContext.es', './fieldEditedHandler.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports["default"] = exports.handleFieldBlurred = void 0;

    var _settingsContext = require("../util/settingsContext.es");

    var _fieldEditedHandler = require("./fieldEditedHandler.es");

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    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;
    }

    var handleFieldBlurred = function handleFieldBlurred(props, state, event) {
      var newState = {
        fieldHovered: {},
        pages: state.pages
      };

      if (event) {
        var propertyName = event.propertyName,
            propertyValue = event.propertyValue;

        if (propertyName === 'name' && propertyValue === '') {
          newState = (0, _settingsContext.updateField)(state, propertyName, propertyValue);
        }

        if (propertyName === 'fieldReference' && (propertyValue === '' || (0, _fieldEditedHandler.findInvalidFieldReference)(state.focusedField, state.pages, propertyValue))) {
          newState = (0, _fieldEditedHandler.updateState)(props, _objectSpread({}, state, {
            focusedField: (0, _settingsContext.updateFieldReference)(state.focusedField, false, true)
          }), propertyName, state.focusedField.fieldName);
        }
      }

      return newState;
    };

    exports.handleFieldBlurred = handleFieldBlurred;
    var _default = handleFieldBlurred;
    exports["default"] = _default;
    //# sourceMappingURL=fieldBlurredHandler.es.js.map
  }
});
//# sourceMappingURL=fieldBlurredHandler.es.js.map