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

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

    var _fields = require("../util/fields.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 handleElementSetAdded = function handleElementSetAdded(props, state, event) {
      var fieldSetPages = event.fieldSetPages,
          indexes = event.indexes;
      var pages = state.pages;
      var pageIndex = indexes.pageIndex,
          rowIndex = indexes.rowIndex;
      var visitor = new _dynamicDataMappingFormRenderer.PagesVisitor(fieldSetPages);
      var newFieldsetPages = visitor.mapFields(function (field) {
        var name = (0, _fields.generateFieldName)(pages, field.fieldName);
        var settingsContextVisitor = new _dynamicDataMappingFormRenderer.PagesVisitor(field.settingsContext.pages);
        return _objectSpread(_objectSpread({}, field), {}, {
          fieldName: name,
          fieldReference: name,
          settingsContext: _objectSpread(_objectSpread({}, field.settingsContext), {}, {
            pages: settingsContextVisitor.mapFields(function (settingsContextField) {
              if (settingsContextField.fieldName === 'fieldReference' || settingsContextField.fieldName === 'name') {
                settingsContextField = _objectSpread(_objectSpread({}, settingsContextField), {}, {
                  value: name
                });
              }

              return settingsContextField;
            })
          })
        });
      });
      var rows = newFieldsetPages[0].rows;

      for (var i = rows.length - 1; i >= 0; i--) {
        pages[pageIndex].rows.splice(rowIndex, 0, rows[i]);
      }

      return {
        pages: pages.map(function (page, index) {
          if (index === pageIndex) {
            return _objectSpread(_objectSpread({}, page), {}, {
              rows: _dynamicDataMappingFormRenderer.FormSupport.removeEmptyRows(pages, index)
            });
          }

          return page;
        })
      };
    };

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