// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
require({cache:{"url:widgets/CostAnalysis/asset-statistics.html":'\x3cdiv style\x3d"height: 100%; width: 100%"\x3e\r\n  \x3cdiv class\x3d"esriCTContentSection" data-dojo-attach-point\x3d"assetStatisticsNode"\x3e\r\n    \x3cdiv class\x3d"esriCTFloatLeft esriCTFullwidth"\x3e\r\n      \x3cdiv class\x3d"esriCTDetailStatisticsTitle"\x3e\r\n        ${nls.detailStatistics.detailStatisticsLabel}\r\n      \x3c/div\x3e\r\n      \x3c!--Add New Statistics button--\x3e\r\n      \x3cdiv class\x3d"esriCTStatisticsButtonContainer"\x3e\r\n        \x3cdiv data-dojo-attach-point\x3d"addNewStatisticsIcon" class\x3d"esriCTBtnStatisticsAddSection" tabindex\x3d"0"\r\n          role\x3d"button" aria-label\x3d"${nls.statisticsSettings.addNewStatisticsText}"\r\n          title\x3d"${nls.statisticsSettings.addNewStatisticsText}"\x3e\r\n          \x3cspan class\x3d"esriCTBtnAddStatisticsIcon"\x3e\x3c/span\x3e\r\n          \x3cspan class\x3d"esriCTBtnStatisticsAddLabel"\x3e${nls.detailStatistics.addStatisticsButtonLabel}\x3c/span\x3e\r\n        \x3c/div\x3e\r\n      \x3c/div\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv class\x3d"esriCTDetailStatisticsContent esriCTFloatLeft esriCTFullwidth" data-dojo-attach-point\x3d"assetsListNode"\x3e\r\n    \x3c/div\x3e\r\n  \x3c/div\x3e\r\n  \x3cdiv class\x3d"esriCTPageFooter"\x3e\r\n    \x3cdiv class\x3d"jimu-btn esriCTEllipsis" data-dojo-attach-point\x3d"okButton" tabindex\x3d"0" role\x3d"button"\r\n      aria-label\x3d"${nls.common.back}"\x3e${nls.common.back}\x3c/div\x3e\r\n  \x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/declare jimu/BaseWidget dojo/Evented dijit/_WidgetsInTemplateMixin dojo/text!./asset-statistics.html dojo/_base/lang dojo/on dojo/_base/array dojo/dom-construct dijit/form/TextBox dojo/keys jimu/utils dijit/focus".split(" "),function(q,r,t,u,e,k,l,g,h,v,m,n,p){return q([r,t,u],{templateString:e,baseClass:"jimu-widget-cost-analysis-asset-statistics",_layerNamesObj:{},_statTypeNames:{},postCreate:function(){this.inherited(arguments);this._layerNamesObj={};this._statTypeNames={count:this.nls.statisticsType.countLabel,
area:this.nls.statisticsType.areaLabel,length:this.nls.statisticsType.lengthLabel,avg:this.nls.statisticsType.averageLabel,sum:this.nls.statisticsType.summationLabel,max:this.nls.statisticsType.maxLabel,min:this.nls.statisticsType.minLabel}},startup:function(){this.inherited(arguments);this._getLayerNames();this._initAssetStatistics();this.own(l(this.okButton,"click",k.hitch(this,function(){this.emit("onOkButtonClicked")})));this.own(l(this.okButton,"keydown",k.hitch(this,function(a){a.keyCode!==
m.ENTER&&a.keyCode!==m.SPACE||this.emit("onOkButtonClicked")})))},_initAssetStatistics:function(){this.displayStatisticsDetail(this.config.statisticsSettings)},displayStatisticsDetail:function(a){h.empty(this.assetsListNode);0===a.length?(a=h.create("div",{innerHTML:this.nls.detailStatistics.noDetailStatisticAvailable,"class":"esriCTNoDetailStatisticMessage",tabindex:"0",role:"presentation","aria-label":this.nls.detailStatistics.noDetailStatisticAvailable},this.assetsListNode),p.focus(a)):g.forEach(a,
k.hitch(this,function(b){this._addStatisticEntry(b)}))},_addStatisticEntry:function(a){var b="";var c="";(c=this.layerInfosObj.getLayerInfoById(a.id))&&c.layerObject&&(b=this.appUtils.getUnitsAbbreviation(c.layerObject.geometryType,this.config.generalSettings.measurementUnit));var d=this._getFeatureValue(a);"count"!==a.type&&(d=this.appUtils.applyRounding(d));if("length"===a.type||"area"===a.type)d+=" "+b;c=a.label?a.label:this._layerNamesObj[a.id]+" ("+this._statTypeNames[a.type]+")";"NaN"===d&&
(d=0);this._createStatisticsDetailUI(c,d)},_createStatisticsDetailUI:function(a,b){var c=h.create("div",{"class":"esriCTStatisticWrapper"},this.assetsListNode);h.create("div",{"class":"esriCTStatisticLabel esriCTEllipsis",title:a,innerHTML:a},c);c=h.create("div",{},c);new v({value:b,"aria-label":a,"class":"esriCTFullwidth esriCTEllipsis esriCTAssetDetailTextBox",tabindex:"0",readonly:!0,role:"presentation"},c)},_getLayerNames:function(){g.forEach(this.map.itemInfo.itemData.operationalLayers,k.hitch(this,
function(a){this._layerNamesObj[a.id]=a.title}))},_getFeatureValue:function(a){if(0<Object.keys(this.assetItemSummary).length&&this.assetItemSummary[a.id]){var b=this.assetItemSummary[a.id].templates;var c=a.field;a=a.type;return this._calculateFeatureValue(b,c,a)}return"0"},_calculateFeatureValue:function(a,b,c){switch(c){case "count":return this._calculateCountOfFeatures(a);case "area":return this._calculateAreaLengthOfFeatures(a);case "length":return this._calculateAreaLengthOfFeatures(a);case "avg":return this._calculateAvgSumOfFeatures(a,
b,c);case "sum":return this._calculateAvgSumOfFeatures(a,b,c);case "max":return this._calculateMinMaxOfFeatures(a,b,c);case "min":return this._calculateMinMaxOfFeatures(a,b,c);case "default":return""}},_calculateCountOfFeatures:function(a){var b=0;for(e in a)b+=a[e].features.length;return b},_calculateAreaLengthOfFeatures:function(a){var b=0;for(e in a)b+=this._getFeatureDimension(a[e]);return b},_getFeatureDimension:function(a){var b=0;g.forEach(a.features,function(c){b+=c.featureDimension});return b},
_calculateAvgSumOfFeatures:function(a,b,c){var d=0,f=0;if(""===b)return"";for(e in a)f+=this._getSumAndCountOfFields(a[e].features,b).count,d+=this._getSumAndCountOfFields(a[e].features,b).total;return"avg"===c?d/f:d},_getSumAndCountOfFields:function(a,b){var c=0,d=0;g.forEach(a,function(f){f.attributes[b]&&(c+=f.attributes[b],d++)});return{total:c,count:d}},_calculateMinMaxOfFeatures:function(a,b,c){if(""===b)return"";var d=[];var f=[];for(e in a)d=this._getFeatureAttributesArray(a[e].features,b,
f);return"max"===c?Math.max.apply(null,d):Math.min.apply(null,d)},_getFeatureAttributesArray:function(a,b,c){g.forEach(a,function(d){d.attributes[b]?c.push(d.attributes[b]):c.push("")});return c},setFirstAndLastNode:function(){n.initFirstFocusNode(this.widgetDomNode,this.addNewStatisticsIcon);p.focus(this.addNewStatisticsIcon);n.initLastFocusNode(this.widgetDomNode,this.okButton)}})});