text: // COPYRIGHT © 2021 Esri
  //
  // All rights reserved under the copyright laws of the United States
  // and applicable international laws, treaties, and conventions.
  //
  // This material is licensed for use under the Esri Master License
  // Agreement (MLA), and is bound by the terms of that agreement.
  // You may redistribute and use this code without modification,
  // provided you adhere to the terms of the MLA and include this
  // copyright notice.
  //
  // See use restrictions at http://www.esri.com/legal/pdfs/mla_e204_e300/english
  //
  // For additional information, contact:
  // Environmental Systems Research Institute, Inc.
  // Attn: Contracts and Legal Services Department
  // 380 New York Street
  // Redlands, California, USA 92373
  // USA
  //
  // email: contracts@esri.com
  //
  // See http://js.arcgis.com/3.36/esri/copyright.txt for details.
  
  define(["dojo/_base/declare","dojo/_base/lang","esri/dijit/geoenrichment/Deferred","dojo/dom-class","dojo/dom-construct","dojox/uuid/generateRandomUuid","dijit/_WidgetBase","dijit/_TemplatedMixin","esri/dijit/geoenrichment/Pagination","esri/dijit/geoenrichment/utils/ColorUtil","esri/dijit/geoenrichment/utils/DeviceUtil","esri/dijit/geoenrichment/utils/DomUtil","esri/dijit/geoenrichment/utils/FitUtil","esri/dijit/geoenrichment/ReportPlayer/core/supportClasses/ElementUsageTypes","esri/dijit/geoenrichment/ReportPlayer/core/supportClasses/ViewModes","../themes/BackgroundThemeUtil","../supportClasses/templateJsonUtils/query/TemplateJsonQueryUtil","../sections/sectionUtils/SectionJsonUtil","dojo/text!../templates/InfographicsPage.html","dojo/i18n!esri/nls/jsapi"],(function(t,e,i,n,s,o,h,a,r,c,d,l,u,g,_,p,m,f,S,y){y=y.geoenrichment.dijit.ReportPlayer.Infographics;var P=d.isMobileDevice()?20:120,v=d.isMobileDevice()?10:60;function M(t){var e=m.getParentBox(t);return e&&e.w?e:f.calcSectionJsonBox(t)}return t([h,a],{templateString:S,nls:y,viewModel:null,theme:null,parentWidget:null,currentFeatureIndex:null,keepPagePosition:!0,renderBackgroundImage:!1,scaleSectionsToFit:!1,pagination:null,_sections:null,_currentMinWidth:0,_currentMinHeight:0,postCreate:function(){this.inherited(arguments),this._sections=[],this._createPagination(),n[this.scaleSectionsToFit?"add":"remove"](this.domNode,"scaleSectionsToFit")},_createPagination:function(){var t=this;this.pagination=new r({createItemContainer:e.hitch(this,this._createItemContainer),updateItemContainer:e.hitch(this,this._updateItemContainer),detachChildrenUponHiding:!0,onNodePlaced:e.hitch(this,this._onNodePlaced),scrollAnimation:"slide",cyclicPagination:!0,onPageChanged:function(){t.onPageIndexChanged(t.getCurrentPageIndex())}}).placeAt(this.paginationDiv),this.own(this.pagination),this.pagination.set("items",[]),this.pagination.startup()},_createItemContainer:function(){var t=s.create("div",{class:"infographicPage_infographicRoot"});return t.style.minWidth=this._currentMinWidth+"px",t.style.minHeight=this._currentMinHeight+"px",t},_sectionsHash:null,_getSectionByJson:function(t){return this._sectionsHash=this._sectionsHash||{},t._idInPagination||(t._idInPagination=o()),this._sectionsHash[t._idInPagination]},_putSectionToHash:function(t,e){this._sectionsHash&&(this._sectionsHash[e._idInPagination]=t)},_updateItemContainer:function(t,e){this._createSectionNode(t,e)},_createSectionNode:function(t,e){if(t&&t.parentNode){t.innerHTML="",t.style.minWidth="",t.style.minHeight="";var i=s.create("div",{class:"infographicPage_infographicRootSectionNode"},t),n=M(e);if(this.scaleSectionsToFit){t.style.width=this._currentMinWidth+2+"px",t.style.height=this._currentMinHeight+2+"px";var o=u.fitBox(n,{w:this._currentMinWidth,h:this._currentMinHeight});i.style.transform="scale("+o.ratio+")",i.style.webkitTransform="scale("+o.ratio+")",i.style.position="absolute",i.style.left=(this._currentMinWidth-n.w)/2+"px",i.style.top=(this._currentMinHeight-n.h)/2+"px"}else t.style.width=n.w+2+"px",t.style.height=n.h+2+"px";i.style.width=n.w+"px",i.style.height=n.h+"px";var h=this._getSectionByJson(e);if(h&&h.domNode)h.placeAt(i),l.isNodeInLayout(t)&&this._onNodePlaced(t,e);else{h&&h.destroy();var a={class:"adjustableGrid_inCellSection"};a.json=e,a.viewModel=this.viewModel,a.theme=this.theme,a.parentWidget=this,a.initialWidth=n.w,a.initialHeight=n.h,a.currentFeatureIndex=this.currentFeatureIndex,a.elementUsageType=g.PAGE_PANEL_SECTION,a.initialViewMode=_.PREVIEW_VALUES,h=this.viewModel.layoutBuilder.createElement("section",a,i),this._sections.push(h),h.__pageIndex=this._sectionJsons.indexOf(e);var r=this._getSectionVisualState(h.__pageIndex);r&&h.setVisualState(r),this._putSectionToHash(h,e)}return this._renderNodeBackground(i,e),h.domNode._panelScale=o?o.ratio:1,o&&h.notifyPanelScaleChanged(o.ratio),h}},_renderNodeBackground:function(t,e){var i=m.getParentStyle(e),n=this.viewModel.getDocumentDefaultStyles(this.theme),o=s.create("div",{class:"esriGEAbsoluteStretched"},t,"first");o.style.backgroundColor=i&&i.backgroundColor&&!c.isTransparent(i.backgroundColor)?i.backgroundColor:n.backgroundColor,this.renderBackgroundImage&&n&&p.renderThemeBackgroundImage(o,n.backgroundImage,{documentOptions:this.parentWidget.documentOptions,pos:M(e)})},_currentSection:null,_onNodePlaced:function(t,e){var i=this._getSectionByJson(e);i&&i.notifyShown(),this._currentSection=i,this._isAutoResizeMode&&this._resizePaginationToFitSelectedElement(t)},getCurrentSection:function(){return this._currentSection},getPanelScaleByNode:function(t){var e;return this._sections.some((function(i){if(l.isChildOf(t,i.domNode))return e=i.domNode._panelScale,!0})),e},getCurrentPageIndex:function(){return this.pagination.get("currentPage")},setCurrentPageIndex:function(t){this.pagination.set("currentPage",t)},showNextPage:function(){this.pagination.set("currentPage","next")},showPreviousPage:function(){this.pagination.set("currentPage","prev")},_prevPageState:null,_sectionJsons:null,getNumItems:function(){return this.pagination.items.length},setItems:function(t){return this._setItems(t)},_setItems:function(t,e){var n=this;this._sectionJsons=t;var s=new i,o=this._prevPageState===e&&this.keepPagePosition,h=this.pagination.get("currentPage");function a(){n._resizeContent(),s.resolve()}return this._calcMinWidthAndHeight(),this._destroySections(),this.pagination.set("items",t),this._prevPageState=e,l[t.length?"hide":"show"](this.emptyPlaceholderDiv),o?(this._resizeContent(),this.pagination.set("currentPage",Math.max(h,0)),setTimeout(a,100)):a(),s.promise},_calcMinWidthAndHeight:function(){this.scaleSectionsToFit?(this._currentMinWidth=this._width-P-2,this._currentMinHeight=this._height-v-2):(this._currentMinWidth=0,this._currentMinHeight=0,this._sectionJsons&&this._sectionJsons.forEach((function(t){var e=M(t);this._currentMinWidth=Math.max(this._currentMinWidth,e.w),this._currentMinHeight=Math.max(this._currentMinHeight,e.h)}),this))},setHeight:function(t){this.domNode.style.height=t+"px"},_width:0,_height:0,_isAutoResizeMode:!0,_isResizing:!1,_pendingResizeNode:null,resize:function(t,e){this._width=t,this._height=e,this._resizeContent()},_checkAutoResizeMode:function(){this._isAutoResizeMode=0===this._width&&0===this._height},_resizeContent:function(){this._checkAutoResizeMode(),this._isResizing=!0,this._pendingResizeNode=null,this._isAutoResizeMode?(this.domNode.style.width="auto",this.domNode.style.height="auto",this.paginationDiv.style.width=this._currentMinWidth+"px",this.paginationDiv.style.height=this._currentMinHeight+"px",this.pagination.resize(),this.paginationDiv.style.width="auto",this.paginationDiv.style.height="auto"):(this._calcMinWidthAndHeight(),this.domNode.style.width=this._width+"px",this.domNode.style.height=this._height+"px",this.paginationDiv.style.width=this._width+"px",this.paginationDiv.style.height=this._height+"px",this.pagination.resize()),this._isResizing=!1,this._pendingResizeNode&&this._isAutoResizeMode?this._resizePaginationToFitSelectedElement(this._pendingResizeNode):this.onResized()},_resizePaginationToFitSelectedElement:function(t){this._isAutoResizeMode&&(this._isResizing?this._pendingResizeNode=t:(this._pendingResizeNode=null,this.paginationDiv.style.width=t.clientWidth+P+"px",this.paginationDiv.style.height=t.clientHeight+v+"px",this.onResized(!0)))},notifyShown:function(){this._currentSection&&this._currentSection.notifyShown()},_visualState:null,getVisualState:function(){var t={type:"infographicsPage",sections:{}};return this._sections.forEach((function(e){t.sections[e.__pageIndex]=e.getVisualState()})),t},setVisualState:function(t){t&&t.sections&&(this._sections.forEach((function(e){var i=t.sections[e.__pageIndex];i&&(e.setVisualState(i),delete t.sections[e.__pageIndex])})),this._visualState=t)},_getSectionVisualState:function(t){var e=this._visualState&&this._visualState.sections[t];if(e)return delete this._visualState.sections[t],e},onPageIndexChanged:function(t){},onResized:function(t){},_destroySections:function(){this._sections.forEach((function(t){t.destroy()})),this._sections.length=0},destroy:function(){this._destroySections(),this.inherited(arguments)}})}));