Liferay.Loader.define("data-engine-js-components-web@1.0.75/js/core/reducers/fieldReducer.es",["module","exports","require","../../utils/fieldSupport","../../utils/repeatable.es","../../utils/visitors.es","../actions/eventTypes.es"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.createRepeatedField=c,t.updateNestedFieldNames=u,t.default=function(e,t){switch(t.type){case i.EVENT_TYPES.FIELD.BLUR:{const{fieldInstance:n}=t.payload;return{pages:new a.PagesVisitor(e.pages).mapFields((e=>{const t=e.name===n.name&&e.required&&""===n.value;return l(l({},e),{},{displayErrors:!!e.displayErrors||t,focused:!t&&e.focused})}))}}case i.EVENT_TYPES.FIELD.FOCUS:{const{fieldInstance:n}=t.payload;return{pages:new a.PagesVisitor(e.pages).mapFields((e=>{const t=e.name===n.name;return l(l({},e),{},{focused:t})}))}}case i.EVENT_TYPES.FIELD.REMOVED:{const n=new a.PagesVisitor(e.pages),s=(e,t)=>t?(0,r.parseNestedFieldName)(e):(0,r.parseName)(e);return{pages:n.mapColumns((e=>{const n=(e,a)=>{const i=e.filter((({name:e})=>e!==t.payload)),d=s(t.payload,a),o=i.filter((({fieldName:e})=>e===d.fieldName)).map(((e,t)=>{const n=(0,r.generateName)(e.name,{repeatedIndex:t});return l(l({},e),{},{nestedFields:u(n,e.nestedFields),newName:n})}));return i.map((e=>{const t=o.find((({name:t})=>t===e.name));return t&&(e=l(l({},t),{},{name:t.newName})),l(l({},e),{},{nestedFields:e.nestedFields?n(e.nestedFields,e.name):[]})}))};return l(l({},e),{},{fields:n(e.fields)})}))}}case i.EVENT_TYPES.FIELD.REPEATED:return{pages:new a.PagesVisitor(e.pages).mapColumns((e=>{const n=e=>{const s=e.reduce(((e=-1,n,s)=>(n.name===t.payload&&(e=s),e)),-1);if(s>-1){const t=s+1,n=c(e[s],t);let a=0;return[...e.slice(0,t),n,...e.slice(t)].map((e=>{if(e.fieldName===n.fieldName){const t=(0,r.generateName)(e.name,{repeatedIndex:a++});return l(l({},e),{},{name:t,nestedFields:u(t,e.nestedFields)})}return e}))}return e.map((e=>l(l({},e),{},{nestedFields:e.nestedFields?n(e.nestedFields):[]})))};return l(l({},e),{},{fields:n(e.fields)})}))};default:return e}};var s=n("../../utils/fieldSupport"),r=n("../../utils/repeatable.es"),a=n("../../utils/visitors.es"),i=n("../actions/eventTypes.es");function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,s)}return n}function l(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){const n=(0,s.generateInstanceId)(),{locale:a,name:i,nestedFields:d,predefinedValue:o}=e;let u;return e.localizedValue&&(u=Object.keys(e.localizedValue).reduce(((e,t)=>(e[t]="",e)),{}),u[a]=null!=o?o:u[a]),l(l({},e),{},{confirmationValue:"",instanceId:n,localizedValue:u,name:(0,r.generateName)(i,{instanceId:n,repeatedIndex:t}),nestedFields:null==d?void 0:d.map((e=>c(e))),valid:!0,value:o})}function u(e,t){return(t||[]).map((t=>{const n=(0,r.generateNestedFieldName)(t.name,e);return l(l({},t),{},{name:n,nestedFields:u(n,t.nestedFields)},(0,r.parseNestedFieldName)(n))}))}}}));
//# sourceMappingURL=fieldReducer.es.js.map