Liferay.Loader.define("data-engine-js-components-web@1.0.79/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 d(d({},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 d(d({},e),{},{focused:t})}))}}case i.EVENT_TYPES.FIELD.REMOVED:{const n=new a.PagesVisitor(e.pages),r=(e,t)=>t?(0,s.parseNestedFieldName)(e):(0,s.parseName)(e);return{pages:n.mapColumns((e=>{const n=(e,a)=>{const i=e.filter((({name:e})=>e!==t.payload)),o=r(t.payload,a),l=i.filter((({fieldName:e})=>e===o.fieldName)).map(((e,t)=>{const n=(0,s.generateName)(e.name,{repeatedIndex:t});return d(d({},e),{},{nestedFields:u(n,e.nestedFields),newName:n})}));return i.map((e=>{const t=l.find((({name:t})=>t===e.name));return t&&(e=d(d({},t),{},{name:t.newName})),d(d({},e),{},{nestedFields:e.nestedFields?n(e.nestedFields,e.name):[]})}))};return d(d({},e),{},{fields:n(e.fields)})}))}}case i.EVENT_TYPES.FIELD.REPEATED:return{pages:new a.PagesVisitor(e.pages).mapColumns((e=>{const n=e=>{const r=e.reduce(((e=-1,n,r)=>(n.name===t.payload&&(e=r),e)),-1);if(r>-1){const t=r+1,n=c(e[r],t);let a=0;return[...e.slice(0,t),n,...e.slice(t)].map((e=>{if(e.fieldName===n.fieldName){const t=(0,s.generateName)(e.name,{repeatedIndex:a++});return d(d(d({},e),e.editorConfig&&{editorConfig:p(e.editorConfig,t)}),{},{name:t,nestedFields:u(t,e.nestedFields)})}return e}))}return e.map((e=>d(d({},e),{},{nestedFields:e.nestedFields?n(e.nestedFields):[]})))};return d(d({},e),{},{fields:n(e.fields)})}))};default:return e}};var r=n("../../utils/fieldSupport"),s=n("../../utils/repeatable.es"),a=n("../../utils/visitors.es"),i=n("../actions/eventTypes.es");function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){l(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function l(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,r.generateInstanceId)(),{locale:a,name:i,nestedFields:o,predefinedValue:l}=e;let u;return e.localizedValue&&(u=Object.keys(e.localizedValue).reduce(((e,t)=>(e[t]="",e)),{}),u[a]=null!=l?l:u[a]),d(d({},e),{},{confirmationValue:"",instanceId:n,localizedValue:u,name:(0,s.generateName)(i,{instanceId:n,repeatedIndex:t}),nestedFields:null==o?void 0:o.map((e=>c(e))),valid:!0,value:l})}function u(e,t){return(t||[]).map((t=>{const n=(0,s.generateNestedFieldName)(t.name,e);return d(d(d({},t),t.editorConfig&&{editorConfig:p(t.editorConfig,n)}),{},{name:n,nestedFields:u(n,t.nestedFields)},(0,s.parseNestedFieldName)(n))}))}function p(e,t){const n=d({},e);for(const[e,r]of Object.entries(n))if("string"==typeof r){const a=(0,s.parseName)(decodeURIComponent(r));if(Object.keys(a).length){const i=encodeURIComponent((0,s.generateName)(null,a));n[e]=r.replace(i,encodeURIComponent(t)+"selectItem")}}return n}}}));
//# sourceMappingURL=fieldReducer.es.js.map