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