Liferay.Loader.define("data-engine-js-components-web@1.0.112/js/custom/form/reducers/repeatableDNDReducer.es",["module","exports","require","../../../utils/repeatable.es","../../../utils/visitors.es","../eventTypes"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.updateNestedFieldNames=updateNestedFieldNames,t.default=function repeatableDNDReducer(e,t){switch(t.type){case s.EVENT_TYPES.FORM_VIEW.REPEATABLE_FIELD.CHANGE_ORDER:{const{draggedIndex:r,sourceFieldName:s,sourceNestedFieldIndex:o,targetIndex:a,targetNestedFieldIndex:i}=t.payload,{pages:c}=e;return{pages:new d.PagesVisitor(c).mapColumns((e=>{const reorderRepeatedField=e=>{let t=[...e];if(!e.find((e=>e.fieldName===s)))return e.map((e=>e.nestedFields?_objectSpread(_objectSpread({},e),{},{nestedFields:reorderRepeatedField(e.nestedFields)}):e));const d=null!=o?o:r,c=null!=i?i:a,l=t[d];t=t.filter(((e,t)=>t!==d));const p=d<c?1:0;return t=[...t.slice(0,c-p),l,...t.slice(c-p)],t.map(((e,t)=>{const r=function updateFieldName(e,t){return(0,n.isNestedFieldName)(e)?(0,n.updateNestedFieldNameIndex)(e,t):(0,n.generateName)(e,{repeatedIndex:t})}(e.name,t);return _objectSpread(_objectSpread({},e),{},{name:r,nestedFields:e.nestedFields?updateNestedFieldNames(r,e.nestedFields):[]})}))};return _objectSpread(_objectSpread({},e),{},{fields:reorderRepeatedField(e.fields)})}))}}default:return e}};var n=r("../../../utils/repeatable.es"),d=r("../../../utils/visitors.es"),s=r("../eventTypes");function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function updateNestedFieldNames(e,t){return(t||[]).map((t=>{const r=(0,n.generateNestedFieldName)(t.name,e);return _objectSpread(_objectSpread(_objectSpread({},t),t.editorConfig&&{editorConfig:updateEditorConfigFieldName(t.editorConfig,r)}),{},{name:r,nestedFields:updateNestedFieldNames(r,t.nestedFields)},(0,n.parseNestedFieldName)(r))}))}function updateEditorConfigFieldName(e,t){const r=_objectSpread({},e);for(const[e,d]of Object.entries(r))if("string"==typeof d){const s=(0,n.parseName)(decodeURIComponent(d));if(Object.keys(s).length){const o=encodeURIComponent((0,n.generateName)(null,s));r[e]=d.replace(o,encodeURIComponent(t)+"selectItem")}}return r}}}));
//# sourceMappingURL=repeatableDNDReducer.es.js.map