// 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/sections/supportClasses/SectionLayoutManager",["dojo/_base/declare","dojo/dom-style","esri/dijit/geoenrichment/utils/FitUtil"],function(f,d,l){f=f(null,{section:null,constructor:function(a){this.section=a},getWidth:function(){return d.get(this.section.domNode,"width")},_widthInitializedFlag:!1,setWidth:function(a,b){b=b||{};var c=this._widthInitializedFlag?d.get(this.section.domNode,"width"):0;b&&b.previousDim&&(c=b.previousDim.w,this._widthInitializedFlag=
!0);d.set(this.section.domNode,"width",a+"px");this._widthInitializedFlag=this._widthInitializedFlag||1<a;this.section.hasFixedLayout?this.section.getTables().forEach(function(c){(c.getMaxWidth()!==a||b.forceResize)&&c.setMaxWidth(a,{resizeToFitAllowedWidth:b.resizeContentToFit,preserveRightOffset:b.preserveRightOffset})}):this._widthInitializedFlag&&b&&b.resizeContentProportionally&&c&&a&&c!==a&&this.scaleFloatingContentProportionally({xScale:a/c,yScale:1})},getHeight:function(a){if(!this.section.hasFixedLayout)return 0;
var b=0;this.section._stackElements.forEach(function(c){switch(c.stackId){case "table":b+=c.getHeight(a);break;case "hr":b+=d.get(c,"height");break;case "pageBreak":b+=d.get(c,"height")}});return b},getResizedHeight:function(){return this.section.hasFixedLayout?this.getHeight(!0):d.get(this.section.domNode,"height")},_resizedHeightInitializedFlag:!1,_setResizedHeight:function(a,b){if(this.section.hasFixedLayout){var c=this.section.getLastTable();c&&c.setSpaceAfter(a-this.getHeight())}c=this._resizedHeightInitializedFlag?
d.get(this.section.domNode,"height"):0;b&&b.previousDim&&(c=b.previousDim.h,this._resizedHeightInitializedFlag=!0);d.set(this.section.domNode,"height",a+"px");this._resizedHeightInitializedFlag=this._resizedHeightInitializedFlag||1<a;!this.section.hasFixedLayout&&b&&b.resizeContentProportionally&&c&&a&&c!==a&&this.scaleFloatingContentProportionally({xScale:1,yScale:a/c})},setResizedHeight:function(a,b){this._setResizedHeight(a,b);if(this.section.hasFixedLayout){var c=this;this.section.getTables().forEach(function(a){a.needScaleToFitHeight()&&
c._scaleFixedTableToFitHeight(a)})}},updateHeightAfterContentChange:function(){this.section.hasFixedLayout&&this._setResizedHeight(this.getResizedHeight())},scaleFloatingContentProportionally:function(a){this.section.hasFixedLayout||1===a.xScale&&1===a.yScale||this.section._stackElements.forEach(function(b){switch(b.stackId){case "table":b.scaleProportionallyWithinParent(a);break;case "img":b.scaleProportionallyWithinParent(a)}})},getFloatingContentBox:function(){var a,b,c,d;function g(e){a=Math.min(a,
e.l);b=Math.min(b,e.t);c=Math.max(c,e.l+e.w);d=Math.max(d,e.t+e.h)}b=a=Infinity;d=c=0;this.section._stackElements.forEach(function(a){switch(a.stackId){case "table":g(a.getTableBox());break;case "img":g(a.getImageBox(!1))}});return{l:a,t:b,w:c-a,h:d-b}},fitContentNicely:function(a,b){a=a||{};this.section.hasFixedLayout?this._fitFixedTablesNicely(a,b):this._fitFloatingContentNicely(a,b)},_fitFixedTablesNicely:function(a,b){if("none"!==a.fitMode){"all"===a.fitMode&&delete a.fitMode;var c=this;(b||this.section.getTables()).forEach(function(b){"table"===
b.stackId&&("width"!==a.fitMode&&a.fitMode||b.resizeToFitAllowedWidth(),"height"!==a.fitMode&&a.fitMode||c._scaleFixedTableToFitHeight(b))});this.section._notifyContentChanged()}},_scaleFixedTableToFitHeight:function(a){a.resizeToFitHeight(this.section.getResizedHeight());a.setSpaceAfter(0)},_fitFloatingContentNicely:function(a,b){if("none"!==a.fitMode){var c=this.getFloatingContentBox();b=b||this.section._stackElements;if(b.length){var f,g;if(1!==b.length||"img"!==b[0].stackId||b[0].isMapImage()){var e=
a.noOffset||this.section.noInfographicTableOffset&&this.section.hasInfographic()||this.section.noChartTableOffset&&this.section.hasChart()?0:5,h={xScale:"height"===a.fitMode?1:(this.section.getWidth()-2*e)/c.w,yScale:"width"===a.fitMode?1:(d.get(this.section.domNode,"height")-2*e)/c.h};f=e-c.l*h.xScale;g=e-c.t*h.yScale}else{var e=a.noOffset?0:10,k=l.fitBox(c,{w:this.section.getWidth()-2*e,h:d.get(this.section.domNode,"height")-2*e},{hAlign:"center",vAlign:"middle"}),h={xScale:k.ratio,yScale:k.ratio};
f=e+k.x-c.l*h.xScale;g=e+k.y-c.t*h.yScale}b.forEach(function(a){switch(a.stackId){case "table":a.scaleProportionallyWithinParent(h);a.setGridPosition(f+a.getLeft(),g+a.getTop());break;case "img":a.scaleProportionallyWithinParent(h),d.set(a.domNode,{left:f+d.get(a.domNode,"left")+"px",top:g+d.get(a.domNode,"top")+"px"})}})}}},getPreferredHeight:function(){var a=this.section.getInfographicWithTable();if(!a||!a.infographic.getPreferredHeight)return 0;var b=a.table.getTableBox(),c=b.t,b=this.getResizedHeight()-
b.t-b.h,a=a.infographic.getPreferredHeight()||0;return c+b+a}});f.TABLE_FIT_PRETTY_OFFSET=5;f.IMAGE_FIT_PRETTY_OFFSET=10;return f});