// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/dijit/geoenrichment/ReportPlayer/core/grid/coreUtils/gridLayoutCalcUtils/rows/_RowModifierLoose","dojo/_base/lang dojox/uuid/generateRandomUuid ../GridLayoutCalculatorQueryUtil ../GridElementBoxCalculator ./RowDataUtil ../../GridQueryUtil".split(" "),function(m,n,p,q,k,r){var g={collectRowBoxes:function(a,b){for(var c=[],e=0;e<a.columns.length;){var f=a.columns[e],d=this._createEmptyBox(),f=p.getColumnSpannedFields(a,b,f.field)||[f.field];d.elements=this._getFieldsElements(a,b,f);this._measureBox(d);
var h=c[c.length-1];h&&(h.nextSibling=d,d.prevSibling=h);c.push(d);e+=f.length}return c},_createEmptyBox:function(){return{id:n(),box:null,elements:[],overlappingBoxes:[],overlappingBoxesCache:{},prevSibling:null,nextSibling:null}},_getFieldsElements:function(a,b,c){var e=[];c.forEach(function(c){c={data:b,dataIndex:b.index,field:c,box:q.calcDataBox(a,b,c,{places:2})};e.push(c)});return e},_measureBox:function(a){var b=0;a.elements.forEach(function(a){b+=a.box.w});a.box={x:a.elements[0].box.x,y:a.elements[0].box.y,
h:a.elements[0].box.h,w:b}},mergeBoxesForBottomRow:function(a){var b=this._createEmptyBox();a.forEach(function(a){a.elements.forEach(function(a){b.elements.push({data:null,field:a.field,box:m.clone(a.box)})})});this._measureBox(b);b.box.h=1E6;return[b]},getBoxAtField:function(a,b){return a.filter(function(a){return a.elements[0].field===b})[0]}},t={buildInfluenceTree:function(a,b,c){function e(c,d){(d?b:a).forEach(function(a){var b;if(b=!a.overlappingBoxesCache[c.id]){b=c.box;var d=a.box;b=!(b.x+
.5>=d.x+d.w||b.x+b.w<=d.x+.5)}b&&(c.overlappingBoxes.push(a),c.overlappingBoxesCache[a.id]=!0)});c.overlappingBoxes.forEach(function(a){e(a,!d)})}c=g.getBoxAtField(a,c);e(c,!0);return c}},u={applyForce:function(a,b,c){function e(b,c){var d=b.elements[0];d.data&&k.setDataHeight(a,d.data,d.field,k.getDataHeight(a,d.data,d.field)+(c?-1:1)*f,!0);b.overlappingBoxes.forEach(function(a){e(a,!c)})}var f=this._checkDelta(a,b,c);e(b,!1)},_checkDelta:function(a,b,c){function e(a,b){0!==d&&(b?0>d||(d=Math.min(d,
a.box.h-f),a.prevSibling&&(d=Math.min(d,a.prevSibling.box.y+a.prevSibling.box.h-f-a.box.y)),a.nextSibling&&(d=Math.min(d,a.nextSibling.box.y+a.nextSibling.box.h-f-a.box.y))):0<d||(d=Math.max(d,-(a.box.h-f)),a.prevSibling&&(d=Math.max(d,-(a.box.y+a.box.h-(a.prevSibling.box.y+f)))),a.nextSibling&&(d=Math.max(d,-(a.box.y+a.box.h-(a.nextSibling.box.y+f))))),a.overlappingBoxes.forEach(function(a){e(a,!b)}))}var f=a.layoutDefaults.rowMinHeight;c=Math.max(c,f);var d=c-b.box.h;e(b,!1);return d}},l={_getInluencedStartBox:function(a,
b,c){var e=a.store.data[b.index+1];b=g.collectRowBoxes(a,b);a=e?g.collectRowBoxes(a,e):g.mergeBoxesForBottomRow(b);return t.buildInfluenceTree(b,a,c)},getAffectedCells:function(a,b,c){function e(b){if(b.elements[0].data){var c=r.querySingleCell(a,{rowIndex:b.elements[0].data.index,columnField:b.elements[0].field,considerSpans:!0});c&&f.push(c)}b.overlappingBoxes.forEach(e)}var f=[];b=this._getInluencedStartBox(a,b,c);e(b);return f},adjustRowCell:function(a,b,c,e){b=this._getInluencedStartBox(a,b,
c);u.applyForce(a,b,e)}};return{adjustRowHeight:function(a,b,c,e){l.adjustRowCell(a,b,c,e)},getAffectedCells:function(a,b,c){return l.getAffectedCells(a,b,c)}}});