Liferay.Loader.define("dynamic-data-mapping-form-renderer@5.0.53/js/reducers/defaultReducer.es", ['module', 'exports', 'require', '../actions/eventTypes.es', '../util/visitors.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _eventTypes = require("../actions/eventTypes.es");

    var _visitors = require("../util/visitors.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 _default = function _default(state, action) {
      switch (action.type) {
        case _eventTypes.EVENT_TYPES.ALL:
          {
            var defaultLanguageId = state.defaultLanguageId;
            var _action$payload = action.payload,
                editingLanguageId = _action$payload.editingLanguageId,
                pages = _action$payload.pages;

            if (editingLanguageId && state.editingLanguageId !== editingLanguageId) {
              var visitor = new _visitors.PagesVisitor(pages !== null && pages !== void 0 ? pages : state.pages);
              return _objectSpread(_objectSpread({}, action.payload), {}, {
                pages: visitor.mapFields(function (_ref) {
                  var localizedValue = _ref.localizedValue;
                  var value;

                  if (localizedValue) {
                    if (localizedValue[editingLanguageId] !== undefined) {
                      value = localizedValue[editingLanguageId];
                    } else if (localizedValue[defaultLanguageId]) {
                      value = localizedValue[defaultLanguageId];
                    }
                  }

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

            return action.payload;
          }

        case _eventTypes.EVENT_TYPES.UPDATE_DATA_RECORD_VALUES:
          return {
            dataRecordValues: action.payload
          };

        default:
          return state;
      }
    };

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