// 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/infographics/simpleInfographic/_DataDrillingSupport","dojo/_base/declare dojo/on dojo/when dojo/dom-class dojo/dom-construct dojo/dom-geometry dojo/dom-style dojo/query esri/dijit/geoenrichment/FlowList ./SimpleInfographicViewModes ../../grid/coreUtils/GridDataUtil ../dataDrilling/DataDrillingLibrary ../dataDrilling/DataDrillingAnimationTypes esri/dijit/geoenrichment/utils/DelayUtil esri/dijit/geoenrichment/utils/DomUtil esri/dijit/geoenrichment/utils/MouseUtil esri/dijit/geoenrichment/utils/PopupUtil esri/dijit/geoenrichment/utils/TooltipUtil esri/dijit/geoenrichment/utils/WaitingUtil ../../sections/SectionTypes ../../supportClasses/ViewModes ./DataDrillingBackgroundUtil ./DataDrillingExportUtil dojo/i18n!../../../../../../nls/jsapi".split(" "),
function(x,l,m,q,n,L,y,D,z,w,E,r,t,u,A,M,B,C,F,G,H,I,v,p){p=p.geoenrichment.dijit.ReportPlayer.ReportPlayer;var J={w:700,h:600},K=x(z.itemRenderers.DefaultItemRenderer,{createLabelNode:!0,labelClass:"TrimWithEllipses esriGEReportPlayerTabs_label"});return x(null,{drillingOptionsList:null,_drillingSections:null,_drillingSectionsButtons:null,postCreate:function(){var a=this;this.inherited(arguments);l(this.backToMainViewButton,"click",function(){a._setViewMode(w.VIEW_MAIN,!0)});this.viewModel.dynamicReportInfo&&
(v.canPrintDataDrilling(this)&&(C.setTooltipToNode(this.printButton,p.printInfographic),q.add(this.dataDrillingViewDiv,"canPrintDataDrilling"),l(this.printButton,"click",function(){v.printDataDrilling(a)})),v.canExportDataDrilling(this)&&(C.setTooltipToNode(this.exportButton,p.exportInfographic),q.add(this.dataDrillingViewDiv,"canExportDataDrilling"),l(this.exportButton,"click",function(){v.exportDataDrilling(a)})))},_getCountryID:function(){return this.viewModel.dynamicReportInfo.infographicOptions.countryID},
_addDataDrillingHandlers:function(a,c){var d=this,e=E.getFieldInfo(c.getFieldCells()[0]),g=this._getDDValue(e),f=g&&"object"===typeof g?g:null,g="standard"===g&&r.hasDrillingOptions(this._getCountryID(),e);(f||g)&&a.own(l.once(this.domNode,"mouseover",function(){var b=n.create("div",{"class":"simpleInfographic_drillDataButton"},a.domNode);n.create("div",{"class":"dijitInline simpleInfographic_drillDataButtonIcon esriGESpaceAfterBig"},b);n.create("div",{"class":"dijitInline simpleInfographic_drillDataButtonLabel",
innerHTML:p.drillForMoreData},b);l(b,"click",function(){d._selectedOptionsCache=d._selectedOptionsCache||{};var a=d._selectedOptionsCache[e.variableID]||0,c=d._setViewMode(w.VIEW_DATA_DRILLING,!0,b);f?d._renderCustomSectionJson(f,e,c):(d._loadDataDrillingOptionsList(e),d.drillingOptionsList.setSelectedIndex(a),d._loadDataDrillingView(e,d.drillingOptionsList.selectedItem.label,null,null,c))});d._drillingSectionsButtons.push({destroy:function(){n.destroy(b)}});var c=[];a.getTables().forEach(function(a){c.push(a.domNode)});
var h=A.intersectNodeBoxes(c,a.domNode);y.set(b,{left:h.x+"px",top:h.y+"px",width:h.w+"px",height:h.h+"px",lineHeight:h.h+"px"});var g=A.position(b);g.w>h.w&&y.set(b,"left",h.x-(g.w-h.w)/2+"px")}))},_getDDValue:function(a){return a&&this._currentInfographicJson.dataDrilling&&this._currentInfographicJson.dataDrilling[a.templateName]},_selectedOptionsCache:null,_createDrillingOptionsList:function(a){this._selectedOptionsCache=this._selectedOptionsCache||{};var c=new z({"class":"simpleInfographic_drillingOptionsList",
itemRenderer:new K});this.own(c);B.makePopup(c,this,a,{orient:["before","below"]});return c},_updateDrillingOptionsListWithFieldInfo:function(a,c){var d=this;a.onChange=function(){B.close(a);d._selectedOptionsCache[c.variableID]=a.selectedIndex;d._setViewMode(w.VIEW_DATA_DRILLING,!0);d._loadDataDrillingView(c,a.selectedItem.label)};var e=(r.getDrillingOptions(this._getCountryID(),c)||[]).map(function(a,c){return{label:a.name,value:c}});a.setItems(e)},_loadDataDrillingOptionsList:function(a){this.drillingOptionsList||
(this.drillingOptionsList=this._createDrillingOptionsList(this.drillingOptionsButton));this._updateDrillingOptionsListWithFieldInfo(this.drillingOptionsList,a);q[1<this.drillingOptionsList.items.length?"add":"remove"](this.dataDrillingViewDiv,"hasMultipleDrillingOptions")},_dataDrillingState:null,_loadDataDrillingView:function(a,c,d,e,g){var f=this;this._dataDrillingState={fieldInfo:a,optionName:c,calcState:d,sectionVisualState:e};this._destroyDrillingSections();this._showDDProgress(!0);return m(function(){var b=
f._getDataDrillingPanelDimensions(),e=r.getDrillingOptionInfo(f._getCountryID(),a,c,b.w,b.h,d),b=e.enrichInfos;return m(b&&b.length&&f.viewModel.enrichFieldData(b),function(){return e})}(),function(b){return m(f._renderStandardOptionInfo(b,a,g,c,d,e),function(){f._showDDProgress(!1)})})},_renderStandardOptionInfo:function(a,c,d,e,g,f){var b=this,k;this._destroyDrillingSections();var h=this._getDataDrillingPanelSectionParams();h.json={type:G.DETAILS,stack:[a.tableJson]};h.calculationStatesGroup=a.calculationStatesGroup;
h.onCalculationStateChanged=function(a){b._loadDataDrillingView(c,e,a,k.getVisualState())};return m(d,function(){return u.delay(function(){k=b._createDataDrillingSection(h);k.fitContentNicely();k.domNode.style.opacity="0.01";return u.delay(function(){k.setVisualState(f);k.domNode.style.opacity=""},100)})})},_renderCustomSectionJson:function(a,c,d,e,g){var f=this;this._destroyDrillingSections();this._loadDataDrillingOptionsList(null);this._dataDrillingState=null;var b,k=this._getDataDrillingPanelSectionParams();
k.json=a.sectionJson;a.states&&(k.calculationStatesGroup=r.createCalculationStatesGroup(a.states),k.onCalculationStateChanged=function(d){f._renderCustomSectionJson(a,c,null,d,b.getVisualState())});this._showDDProgress(!0);return m(d,function(){return u.delay(function(){b=f._createDataDrillingSection(k);b.fitContentNicely();b.domNode.style.opacity="0.01";return u.delay(function(){b.setVisualState(g);b.domNode.style.opacity="";f._showDDProgress(!1)})})})},_getDataDrillingPanelSectionParams:function(){var a=
{"class":"infographicContainer_Section infographicContainer_dataDrillingSection"};a.initialWidth=this._getDataDrillingPanelDimensions().w;a.viewModel=this.viewModel;a.themeContext=this.themeContext;a.theme=this.theme;a.parentWidget=this;a.tableClass="infographicContainerTable";a.hasFixedLayout=!1;a.noChartTableOffset=a.noInfographicTableOffset=this.dataDrillingAnimationType===t.SLIDE;return a},_createDataDrillingSection:function(a){a=this.viewModel.layoutBuilder.createElement("section",a,this.drilledDataViewDiv);
this._drillingSections.push(a);a.setViewMode(H.PREVIEW_VALUES);a.setResizedHeight(this._getDataDrillingPanelDimensions().h);q[D(".sectionDynamicSettings_settingsButton",this.dataDrillingViewDiv)[0]?"add":"remove"](this.dataDrillingViewDiv,"hasChartSettingsButton");this.dataDrillingAnimationType===t.ZOOM&&this._setUpDDPanelBackgroundColor();return a},_setUpDDPanelBackgroundColor:function(){I.setUpDDPanelBackgroundColor({viewModel:this.viewModel,theme:this.theme,themeContext:this.themeContext,infographicJson:this._currentInfographicJson,
node:this.dataDrillingViewDiv})},_getDataDrillingPanelDimensions:function(){switch(this.dataDrillingAnimationType){case t.ZOOM:return J;default:return{w:this.width,h:this.height}}},_showDDProgress:function(a){F[a?"showProgress":"removeProgress"](this.dataDrillingAnimationType===t.SLIDE?this.domNode:this.dataDrillingViewDiv)},_getDataDrillingState:function(){return this._dataDrillingState},_setDataDrillingState:function(a){a&&this._loadDataDrillingView(a.fieldInfo,a.optionName,a.calcState,a.sectionVisualState)},
_destroyDrillingSections:function(){this._drillingSections=this._drillingSections||[];this._drillingSections.forEach(function(a){a.destroy()});this._drillingSections.length=0;this.domNode&&n.empty(this.drilledDataViewDiv)},_destroyDrillingSectionsButtons:function(){this._drillingSectionsButtons=this._drillingSectionsButtons||[];this._drillingSectionsButtons.forEach(function(a){a.destroy()});this._drillingSectionsButtons.length=0}})});