// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.24/esri/copyright.txt for details.
//>>built
define("esri/dijit/geoenrichment/ReportPlayer/core/grid/coreUtils/gridLayoutCalcUtils/rows/RowsProcessor",["dojox/uuid/generateRandomUuid","./RowDataUtil","../GridLayoutCalculatorQueryUtil"],function(n,g,m){function p(b,f){var c=[],h,e=0;f&&Object.keys(f).forEach(function(a){m.fieldToColumn(b,a)?e++:delete f});e&&b.columns.some(function(a){if(h||f[a.field])c.push(a),h=!0;f[a.field]&&e--;if(!e)return!0});return c}function q(b,f){var c=[],h,e=0;f&&Object.keys(f).forEach(function(a){m.dataIdToData(b,
a)?e++:delete f});e&&b.store.data.some(function(a){if(h||f[a.id])c.push(a),h=!0;f[a.id]&&e--;if(!e)return!0});return c}return{recalcRows:function(b){var f={};b.columns.forEach(function(a,b){f[a.field]=b});var c;b.store.data.forEach(function(a,l){a.index=l;a.style=a.style||{};a.style.fields=a.style.fields||{};void 0===a.id&&(a.id=n());void 0===a.style.height&&(a.style.height=b.layoutDefaults.defaultRowHeight);delete a.excludedIndexHorizontal;delete a.movableFieldsHashHorizontal;if(a.columnSpans){a.excludedIndexHorizontal=
{};a.movableFieldsHashHorizontal={};a._columnSpans=a._columnSpans||{};for(c in a.columnSpans){var d=a._columnSpans[c],k={},d=d?p(b,d):m.getSpannedColumns(b,c,a.columnSpans[c]);1<d.length&&(d.forEach(function(b){k[b.field]=!0;b.field!==c&&(a.excludedIndexHorizontal[f[b.field]]=!0)}),a.movableFieldsHashHorizontal[c]=d[d.length-1].field);a.columnSpans[c]=d.length;a._columnSpans[c]=k}var e=0;Object.keys(a.columnSpans).forEach(function(b){2>a.columnSpans[b]?(delete a.columnSpans[b],delete a._columnSpans[b]):
e++});e||(delete a.columnSpans,delete a._columnSpans)}delete a.excludedIndexVertical;delete a.movableIndexHashVertical;a.fieldInfos=a.fieldInfos||{}});b.store.data.forEach(function(a,e){if(a.rowSpans)for(c in a._rowSpans=a._rowSpans||{},a.rowSpans){var d=a._rowSpans[c],k={};k[a.id]=!0;var l=f[c],h=a.rowSpans[c];if(d)d=q(b,d);else for(var d=[],g=e;g<e+h;g++)d.push(b.store.data[g]);1<d.length&&(d.forEach(function(b){if(b.id!==a.id){b.excludedIndexVertical=b.excludedIndexVertical||{};b.excludedIndexVertical[l]=
!0;var d=a.columnSpans&&a.columnSpans[c];if(d)for(var e=1;e<d;e++)b.excludedIndexVertical[l+e]=!0}k[b.id]=!0}),a.movableIndexHashVertical=a.movableIndexHashVertical||{},a.movableIndexHashVertical[c]=e+d.length-1);a.rowSpans[c]=d.length;a._rowSpans[c]=k}});b.store.data.forEach(function(a,e){if(a.rowSpans){for(c in a.rowSpans)a.rowSpans[c]=Math.min(a.rowSpans[c],b.store.data.length-e);var d=0;Object.keys(a.rowSpans).forEach(function(b){2>a.rowSpans[b]?(delete a.rowSpans[b],a._rowSpans&&delete a._rowSpans[b]):
d++});d||(delete a.rowSpans,delete a._rowSpans)}});b.store.data.forEach(function(a,b){a.fieldInfos&&Object.keys(a.fieldInfos).forEach(function(b){void 0===f[b]&&delete a.fieldInfos[b]});a.style&&a.style.fields&&Object.keys(a.style.fields).forEach(function(b){void 0===f[b]&&delete a.style.fields[b]})});if(b.looseResize){b.store.data.forEach(function(a){b.columns.some(function(c){g.getDataHeightOwn(b,a,c.field)||g.setDataHeight(b,a,c.field,a.style.height)})});var h=b.store.data[b.store.data.length-
1],e=g.recalcGridHeight(b);b.columns.some(function(a){var c=0;b.store.data.forEach(function(d){c+=g.getDataHeightOwn(b,d,a.field)});var d=e-c;0!==d&&g.setDataHeight(b,h,a.field,g.getDataHeightOwn(b,h,a.field)+d)})}g.recalcGridHeight(b)}}});