Liferay.Loader.define("data-engine-js-components-web@1.0.87/js/core/utils/columnResizedHandler",["module","exports","require","../../utils/FormSupport.es","../../utils/settingsContext"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.getColumn=getColumn,t.handleResizeRight=handleResizeRight,t.handleResizeLeft=handleResizeLeft,t.default=function columnResizedHandler({column:e,direction:t,loc:n,props:r,state:o}){const{pages:i}=o;let l=[...i];getColumn(i,n)&&(l="left"===t?handleResizeLeft(r,o,n,e):handleResizeRight(r,o,n,e+1));return{pages:l}};var r=function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var n={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var i=r?Object.getOwnPropertyDescriptor(e,o):null;i&&(i.get||i.set)?Object.defineProperty(n,o,i):n[o]=e[o]}n.default=e,t&&t.set(e,n);return n}(n("../../utils/FormSupport.es")),o=n("../../utils/settingsContext");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function ownKeys(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 _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function getColumn(e,t=[]){let n,o=e;return t.forEach((t=>{const{columnIndex:i,pageIndex:l,rowIndex:s}=t;let d=l;e.length-1<l&&(d=0),n=r.getColumn(o,n?0:d,s,i),o=n&&o[0].nestedFields?o[0].nestedFields.filter((e=>n.fields.includes(e.fieldName))):n&&n.fields})),n}const getContext=(e,t=[])=>(t.length&&t.forEach(((t,n)=>{const{columnIndex:r,pageIndex:o,rowIndex:i}=t;let l=e[n>0?0:o].rows[i].columns[r].fields;e[0].nestedFields&&(l=l.map((t=>e[0].nestedFields.find((e=>e.fieldName===t))))),e=l})),e),getColumnPosition=(e,t)=>{const{columnIndex:n,pageIndex:o,rowIndex:i}=t;return r.getColumnPosition(e,o,i,n)};function handleResizeRight(e,t,n,i){const{pages:l}=t,{columnIndex:s,pageIndex:d,rowIndex:a}=n[n.length-1],c=getContext(l,n.slice(0,-1)),u=getColumn(c,[n[n.length-1]]),p=getColumn(c,[{columnIndex:s+1,pageIndex:d,rowIndex:a}]),g=getColumnPosition(c,{columnIndex:s,pageIndex:n.length>1?0:d,rowIndex:a});let f,h,m=c;if(!p&&u.size>g-i&&i<g){const e=g-i;f=_objectSpread(_objectSpread({},u),{},{size:u.size-e}),m=r.addColumn(m,s+1,n.length>1?0:d,a,{fields:[],size:e})}else if(p){const e=Math.abs(g-i);i<g&&u.size>e?(f=_objectSpread(_objectSpread({},u),{},{size:Math.max(u.size-e,1)}),h=_objectSpread(_objectSpread({},p),{},{size:Math.min(p.size+e,12)})):i>g&&(1!==p.size||p.fields.length?p.size>e&&(f=_objectSpread(_objectSpread({},u),{},{size:u.size+e}),h=_objectSpread(_objectSpread({},p),{},{size:p.size-e})):(f=_objectSpread(_objectSpread({},u),{},{size:u.size+e}),m=r.removeColumn(m,n.length>1?0:d,a,s+1)))}return f&&(m=r.updateColumn(m,n.length>1?0:d,a,s,f)),h&&(m=r.updateColumn(m,n.length>1?0:d,a,s+1,h)),n.length>1&&(m=[(0,o.updateField)(e,m[0],"rows",m[0].rows)],c[0].settingsContext=m[0].settingsContext),c[n.length>1?0:d].rows=m[n.length>1?0:d].rows,l}function handleResizeLeft(e,t,n,i){const{pages:l}=t,{columnIndex:s,pageIndex:d,rowIndex:a}=n[n.length-1],c=getContext(l,n.slice(0,-1)),u=getColumn(c,[n[n.length-1]]),p=getColumn(c,[{columnIndex:s-1,pageIndex:d,rowIndex:a}]),g=getColumnPosition(c,{columnIndex:s-1,pageIndex:n.length>1?0:d,rowIndex:a});let f=c;if(0===s&&i>0)f=r.addColumn(f,s,n.length>1?0:d,a,{fields:[],size:i}),f=r.updateColumn(f,n.length>1?0:d,a,s+1,_objectSpread(_objectSpread({},u),{},{size:u.size-i}));else if(p&&1===p.size&&!p.fields.length&&i<=g)f=r.removeColumn(f,n.length>1?0:d,a,s-1),f=r.updateColumn(f,n.length>1?0:d,a,s-1,_objectSpread(_objectSpread({},u),{},{size:u.size+1}));else if(p){const e=Math.abs(g-i);g>=i&&p.size>e?(u.size+=e,p.size-=e):g<i&&u.size>e&&(u.size-=e,p.size+=e),f=r.updateColumn(f,n.length>1?0:d,a,s,u),f=r.updateColumn(f,n.length>1?0:d,a,s-1,p)}return n.length>1&&(f=[(0,o.updateField)(e,f[0],"rows",f[0].rows)],c[0].settingsContext=f[0].settingsContext),c[n.length>1?0:d].rows=f[n.length>1?0:d].rows,l}}}));
//# sourceMappingURL=columnResizedHandler.js.map