Liferay.Loader.define("data-engine-js-components-web@1.0.75/js/utils/FormSupport.es",["module","exports","require","./visitors.es"],(function(e,n,r){window;{Object.defineProperty(n,"__esModule",{value:!0}),n.implAddColumn=u,n.implAddRow=l,n.addRow=c,n.addColumn=function(e,n,r,o,s=u(11,[])){return new t.PagesVisitor(e).mapRows(((e,t,u)=>{let l=e;return t===o&&u===r&&(l=i(i({},e),{},{columns:[...e.columns.slice(0,n),s,...e.columns.slice(n)]})),l}))},n.isEmptyColumn=d,n.addFieldToColumn=m,n.getFieldIndexes=function(e,n){let r={};return new t.PagesVisitor(e).mapFields(((e,t,o,i,s)=>{("string"==typeof e&&e===n||"object"==typeof e&&e.fieldName===n)&&(r={columnIndex:o,fieldIndex:t,pageIndex:s,rowIndex:i})})),r},n.isEmptyRow=f,n.isEmptyPage=a,n.isEmpty=function(e){return e.every(((n,r)=>a(e,r)))},n.setColumnFields=function(e,n,r,t,o=[]){e[Number(n)].rows.length-1<r?e=m(e=c(e,r,n),n,r,t,o):e[Number(n)].rows[Number(r)].columns[Number(t)].fields=o;return e},n.removeColumn=function(e,n,r,o){return new t.PagesVisitor(e).mapRows(((e,t,s)=>{let u=e;return t===r&&s===n&&(u=i(i({},e),{},{columns:e.columns.filter(((e,n)=>n!==o))})),u}))},n.removeFields=function(e,n,r,o){return new t.PagesVisitor(e).mapColumns(((e,t,s,u)=>{const l=i({},e);return u===n&&s===r&&t===o&&(l.fields=[]),l}))},n.rowHasFields=w,n.removeEmptyRows=function(e,n){return e[n].rows.reduce(((r,t,o)=>(w(e,n,o)&&(r=[...r,t]),r)),[])},n.removeRow=function(e,n,r){return e[Number(n)].rows.splice(Number(r),1),e},n.visitNestedFields=function e({nestedFields:n},r){Array.isArray(n)&&n.forEach((n=>{r(n),e(n,r)}))},n.findField=p,n.findFieldByFieldName=function(e,n){return p(e,(e=>e.fieldName===n))},n.findFieldByName=function(e,n){return p(e,(e=>e.name===n))},n.getRow=b,n.getColumn=g,n.getColumnPosition=function(e,n,r,t){const o=e[n];let i=null;if(i=o.rows[r],!o)return void console.error("Row Index ".concat(r," cannot be retrieved from ").concat(o));return-1!==t&&i.columns?i.columns.reduce(((o,i,s)=>{if(s<=t){o+=g(e,n,r,s).size}return o}),0):0},n.getField=function(e,n,r,t){let o=g(e,n,r,t).fields[0];e[n].nestedFields&&(o=e[n].nestedFields.find((e=>e.fieldName===o)));return o},n.getIndexes=y,n.getNestedIndexes=function e(n){let r=[];n.dataset.ddmFieldRow&&(r=[y(n)]);n.parentElement.classList.contains("ddm-form-page")||(r=[...e(n.parentElement),...r]);return r},n.updateField=function(e,n,r){return new t.PagesVisitor(e).mapFields((e=>n===e.fieldName?i(i({},e),r):e),!0,!0)},n.updateColumn=function(e,n,r,o,s){return new t.PagesVisitor(e).mapColumns(((e,t,u,l)=>{let c=e;return t===o&&u===r&&l===n&&(c=i(i({},e),s)),c}))};var t=r("./visitors.es");function o(e,n){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);n&&(t=t.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),r.push.apply(r,t)}return r}function i(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?o(Object(r),!0).forEach((function(n){s(e,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))}))}return e}function s(e,n,r){return n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function u(e,n=[]){return{fields:n,size:e}}function l(e,n){return{columns:[u(e,n)]}}function c(e,n,r,o=l(12,[])){return new t.PagesVisitor(e).mapPages(((e,t)=>{let s=e;return r===t&&(s=i(i({},e),{},{rows:[...e.rows.slice(0,n),o,...e.rows.slice(n)]})),s}))}function d(e,n,r,t){return!e[n].rows[r].columns[t].fields.length}function m(e,n,r,o,s){const u=e[n].rows.length;if(r>=u){const r=l(12,[s]);return c(e,u,n,r)}d(e,n,r,o)||(e=c(e,r,n));return new t.PagesVisitor(e).mapColumns(((e,t,u,l)=>t===o&&u===r&&l===n?i(i({},e),{},{fields:[...e.fields,s]}):e))}function f(e,n,r){return e[n].rows[r].columns.every(((t,o)=>d(e,n,r,o)))}function a(e,n){return e[n].rows.every(((r,t)=>f(e,n,t)))}function w(e,n,r){let t=!1;const o=e[Number(n)];if(o){const e=o.rows[Number(r)];e&&e.columns&&(t=e.columns.some((e=>e.fields.length)))}return t}function p(e,n){return new t.PagesVisitor(e).findField(n)}function b(e,n,r){return e[Number(n)].rows[Number(r)]}function g(e,n,r,t){return b(e,n,r).columns[Number(t)]}function y(e){const{ddmFieldColumn:n,ddmFieldPage:r,ddmFieldRow:t}=e.dataset;return{columnIndex:Number(n)||0,pageIndex:Number(r)||0,rowIndex:Number(t)||0}}}}));
//# sourceMappingURL=FormSupport.es.js.map