Liferay.Loader.define("data-engine-taglib@3.3.53/data_layout_builder/js/reducers/fieldSetReducer",["module","exports","require","data-engine-js-components-web","../eventTypes","../utils/dataConverter.es","../utils/normalizers.es"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function fieldSetReducer(e,t,a){switch(t.type){case d.EVENT_TYPES.FIELD_SET.UPDATE_LIST:return{fieldSets:t.payload.fieldSets};case d.EVENT_TYPES.FIELD_SET.ADD:{const{allowInvalidAvailableLocalesForProperty:d,fieldTypes:r,generateFieldNameUsingFieldLabel:o,getFieldNameGenerator:s}=a,{activePage:g,editingLanguageId:u,pages:p}=e,{fieldSet:c,fieldName:f,indexes:b={columnIndex:0,pageIndex:g,rowIndex:p[g].rows.length},parentFieldName:y,properties:F,useFieldName:m}=t.payload,S=(0,n.getFieldSetDDMForm)({allowInvalidAvailableLocalesForProperty:d,editingLanguageId:u,fieldSet:c,fieldTypes:r}),{dataLayoutPages:L}=c.defaultDataLayout||(0,n.getDefaultDataLayout)(c),I=c.id&&(0,l.normalizeDataLayoutRows)(L),w=s(p,o),P=new i.PagesVisitor(S.pages),j=[],{availableLanguageIds:D,defaultLanguageId:T}=c,v={availableLanguageIds:D,defaultLanguageId:T,editingLanguageId:u,fieldNameGenerator:w,fieldTypes:r,generateFieldNameUsingFieldLabel:o};P.mapFields((e=>{j.push(i.SettingsContext.updateField(v,e,"label",e.label))}));let E=i.FieldSetUtil.createFieldSet(_objectSpread({editingLanguageId:u,fieldTypes:r},v),{skipFieldNameGeneration:!1,useFieldName:m},j);if(F&&Object.keys(F).forEach((e=>{E=i.SettingsContext.updateField(v,E,e,F[e])})),S.id&&(E=i.SettingsContext.updateField(v,E,"ddmStructureId",S.id)),I&&I.length&&(E=i.SettingsContext.updateField(v,E,"rows",I)),f)return(0,i.sectionAdded)(v,_objectSpread(_objectSpread({},e),{},{pages:p}),{data:{fieldName:f,parentFieldName:y},indexes:b,newField:i.SettingsContext.updateField(v,E,"label",c.name)});const O=i.SettingsContext.updateField(v,E,"label",S.localizedTitle),_=i.FieldSupport.addFieldToPage({defaultLanguageId:T,editingLanguageId:u,fieldNameGenerator:w,generateFieldNameUsingFieldLabel:o,indexes:b,newField:O,pages:p,parentFieldName:y});return{activePage:b.pageIndex,focusedField:O,pages:_}}case d.EVENT_TYPES.FIELD_SET.UPDATE:{const{fieldTypes:d}=a,{editingLanguageId:r,pages:o}=e,{fieldSet:s}=t.payload,{availableLanguageIds:g,dataDefinitionFields:u,defaultDataLayout:p,defaultLanguageId:c,id:f}=s,b="".concat(f),y=new i.PagesVisitor(o);return{pages:y.mapFields((e=>{if(String(e.ddmStructureId)!==b)return e;const t=u.map((({name:e})=>(0,n.getDDMFormField)({dataDefinition:s,editingLanguageId:r,fieldName:e,fieldTypes:d}))),a=(0,l.normalizeDataLayoutRows)(p.dataLayoutPages),o={availableLanguageIds:g,defaultLanguageId:c,editingLanguageId:r};let f=i.SettingsContext.updateField(o,e,"label",s.name);return a&&a.length&&(f=i.SettingsContext.updateField(o,f,"rows",a)),_objectSpread(_objectSpread({},f),{},{nestedFields:t,rows:a})}))}}default:return{}}};var i=a("data-engine-js-components-web"),d=a("../eventTypes"),n=a("../utils/dataConverter.es"),l=a("../utils/normalizers.es");function ownKeys(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,i)}return a}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(a),!0).forEach((function(t){_defineProperty(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):ownKeys(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function _defineProperty(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}}}));
//# sourceMappingURL=fieldSetReducer.js.map