// 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/work-bench.html":'\x3cdiv style\x3d"height: 100%; width: 100%"\x3e\r\n  \x3cdiv class\x3d"esriCTContentSection"\x3e\r\n    \x3cdiv class\x3d"esriCTBoldFont esriCTProjectName" data-dojo-attach-point\x3d"projectNameDiv" tabindex\x3d"0"\x3e\x3c/div\x3e\r\n    \x3cdiv class\x3d"esriCTSelectFeatureToCopyParentContainer"\x3e\r\n      \x3cdiv class\x3d"esriCTSelectFeatureLabel" data-dojo-attach-point\x3d"featureModeTextNode" tabindex\x3d"0" role\x3d"region" aria-label\x3d"${nls.workBench.featureModeText}"\x3e${nls.workBench.featureModeText}:\x3c/div\x3e\r\n      \x3cdiv class\x3d"esriCTSelectFeatureToCopyContainer"\x3e\r\n        \x3cdiv class\x3d"esriCTSelectDisable esriCTFeatureModeIcons esriCTWorkBenchDOM" data-dojo-attach-point\x3d"selectButton" tabindex\x3d"0" role\x3d"button" aria-label\x3d"${nls.workBench.selectToolTitle}" title\x3d"${nls.workBench.selectToolTitle}"\x3e\x3c/div\x3e\r\n        \x3cdiv class\x3d"esriCTSketchEnable esriCTFeatureModeIcons esriCTWorkBenchDOM" data-dojo-attach-point\x3d"sketchButton" tabindex\x3d"0" role\x3d"button" aria-label\x3d"${nls.workBench.sketchToolTitle}" title\x3d"${nls.workBench.sketchToolTitle}"\x3e\x3c/div\x3e\r\n      \x3c/div\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv class\x3d"esriCTTemplatePickerLabel "tabindex\x3d"0" role\x3d"region" aria-label\x3d"${nls.workBench.templatePickerTitle}"\x3e${nls.workBench.templatePickerTitle}\x3c/div\x3e\r\n    \x3cdiv class\x3d"esriCTAddEditFeatureContainer" data-dojo-attach-point\x3d"templatePickerContainer"\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv data-dojo-attach-point\x3d"projectOverview"\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 esriCTWorkBenchDOM" data-dojo-attach-point\x3d"backButton" tabindex\x3d"0" role\x3d"button" aria-label\x3d"${nls.common.back}"\x3e${nls.common.back}\x3c/div\x3e\r\n    \x3cdiv class\x3d"jimu-btn esriCTEllipsis esriCTWorkBenchDOM" data-dojo-attach-point\x3d"refreshButton" tabindex\x3d"0" role\x3d"button" aria-label\x3d"${nls.workBench.refresh}"\x3e${nls.workBench.refresh}\x3c/div\x3e\r\n    \x3cdiv class\x3d"jimu-btn esriCTEllipsis esriCTWorkBenchDOM" data-dojo-attach-point\x3d"downloadCSVBtn" tabindex\x3d"0" role\x3d"button"\r\n        aria-label\x3d"${nls.workBench.downloadCSVBtnTitle}"\x3e${nls.workBench.downloadCSVBtnTitle}\x3c/div\x3e\r\n  \x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/declare jimu/BaseWidget jimu/FilterManager dojo/Evented dijit/_WidgetsInTemplateMixin dojo/text!./work-bench.html dojo/_base/lang dojo/dom-style dojo/dom-attr dojo/_base/array dojo/dom-class dojo/on dojo/query esri/graphic dojo/dom-construct dojo/Deferred dojo/promise/all esri/layers/FeatureLayer esri/tasks/GeometryService esri/graphicsUtils ./template-picker ./project-overview ./project-summary ./asset-details jimu/CSVUtils esri/tasks/query esri/tasks/QueryTask esri/geometry/geometryEngine esri/SpatialReference esri/geometry/Point dojo/keys dojo/_base/event dijit/focus".split(" "),
function(F,G,H,I,J,K,f,L,r,k,n,m,w,t,v,x,y,u,B,M,N,O,P,Q,R,S,T,U,C,D,q,z,E){return F([G,I,J],{templateString:K,baseClass:"jimu-widget-cost-analysis-work-bench",_projectOverview:null,_projectSummary:null,_assetItemSummary:{},_assetGroupSummary:{},_assetTableIds:{},_recentlyOperatedLayerIds:[],_projectAssetTable:null,_additionalCostTable:null,_assetInfoForReset:{},_reportColumns:[],filterManager:null,_pointLayer:null,_originalTemplateAttributes:null,_isLoadingProject:null,_exsitingLabelPointDefExpression:null,
_canExportProject:!0,postCreate:function(){this.inherited(arguments);this._assetItemSummary={};this._assetGroupSummary={};this._assetTableIds={};this._recentlyOperatedLayerIds=[];this._assetInfoForReset={};this.filterManager=H.getInstance();this._exsitingLabelPointDefExpression=this._isLoadingProject=this._originalTemplateAttributes=this._pointLayer=null;this._reportColumns=[];if(!this.config.generalSettings.hasOwnProperty("canExportProject")||this.config.generalSettings.hasOwnProperty("canExportProject")&&
!this.config.generalSettings.canExportProject)L.set(this.downloadCSVBtn,"display","none"),r.set(this.downloadCSVBtn,"tabindex","-1"),this._canExportProject=!1},onWidgetActive:function(){this._templatePicker&&this._templatePicker.bindLayerEvents()},onWidgetDeActive:function(){this._templatePicker&&this._templatePicker._editor&&this._templatePicker._editor.editToolbar&&(this._templatePicker._editor.templatePicker.clearSelection(),this._templatePicker._editor.editToolbar.deactivate(),this._templatePicker.removeLayerEvents())},
onShow:function(a){this.refreshTemplatePicker(a)},onWidgetOpen:function(){this.refreshTemplatePicker();this.config.projectSettings.projectLayer||(this._recentlyOperatedLayerIds=[],this._filterAssets());this._templatePicker&&!this._templatePicker._editor&&(this._disableWebMapPopup(),this._templatePicker.initEditingToolbar())},onWidgetClose:function(){this.config.projectSettings.projectLayer||this._clearAppliedFilters();this._templatePicker&&this._templatePicker._editor&&(this._templatePicker._editor.destroy(),
this._templatePicker._editor=null,this._enableWebMapPopup())},refreshTemplatePicker:function(a){if(this._templatePicker){this._templatePicker.onWindowResize();if(!a){a=this.refreshButton;var b=this.featureModeTextNode;"none"===this.downloadCSVBtn.style.display||n.contains(this.downloadCSVBtn,"esriCTHidden")||(a=this.downloadCSVBtn);n.contains(this.projectNameDiv,"esriCTHidden")||(b=this.projectNameDiv);this.appUtils.setFirstAndLastWBFocusNode(this.widgetDomNode,b,a)}this._handle508AccessibilityForTemplatePicker()}},
startup:function(){this.inherited(arguments);this._storeExistingLabelPointLayerDefExpression();this.config.generalSettings.hasOwnProperty("canExportProject")&&this.config.generalSettings.canExportProject&&this._getReportColumns();this.config.projectSettings.projectLayer?(this.own(m(this.backButton,"click",f.hitch(this,function(){this._backButtonClicked()}))),this.own(m(this.backButton,"keydown",f.hitch(this,function(c){if(c.keyCode===q.ENTER||c.keyCode===q.SPACE)z.stop(c),this._backButtonClicked()})))):
(r.set(this.refreshButton,"innerHTML",this.nls.common.reset),r.set(this.refreshButton,"aria-label",this.nls.common.reset),n.add(this.backButton,"esriCTHidden"));this.own(m(this.refreshButton,"click",f.hitch(this,function(){this._refreshButtonClicked()})));this.own(m(this.refreshButton,"keydown",f.hitch(this,function(c){if(c.keyCode===q.ENTER||c.keyCode===q.SPACE)z.stop(c),this._refreshButtonClicked()})));this.own(m(this.downloadCSVBtn,"click",f.hitch(this,function(){var c=this._createDownLoadData();
this._downLoadCSV(c)})));this.own(m(this.downloadCSVBtn,"keydown",f.hitch(this,function(c){if(c.keyCode===q.ENTER||c.keyCode===q.SPACE)c=this._createDownLoadData(),this._downLoadCSV(c)})));this.onProjectCreateOrLoad(this.projectInfo,this.assetInfo);var a=this.refreshButton,b=this.featureModeTextNode;"none"===this.downloadCSVBtn.style.display||n.contains(this.downloadCSVBtn,"esriCTHidden")||(a=this.downloadCSVBtn);n.contains(this.projectNameDiv,"esriCTHidden")||(b=this.projectNameDiv);this.appUtils.setFirstAndLastWBFocusNode(this.widgetDomNode,
b,a);this._handle508AccessibilityForTemplatePicker()},_backButtonClicked:function(){n.contains(this.backButton,"jimu-state-disabled")||(this._clearAppliedFilters(),this._templatePicker.destroy(),this._templatePicker=null,this._enableWebMapPopup(),this.emit("showProjectPanel"))},_refreshButtonClicked:function(){this._clearAppliedFilters();this._templatePicker&&(this._templatePicker.destroy(),this._templatePicker=null);this.projectInfo.projectId&&this.config.projectSettings.projectLayer?this.emit("reloadProject",
this.projectInfo.projectId):this._resetProject()},_resetProject:function(){var a=[],b;this.loadingIndicator.show();if(this._assetInfoForReset&&0<Object.keys(this._assetInfoForReset).length)for(b in this._assetInfoForReset){var c=this.layerInfosObj.getLayerInfoById(b).layerObject;var d=c.globalIdField+" in ('"+this._assetInfoForReset[b].join("','")+"')";a.push(this.appUtils.deleteFeatures(c.url,d))}y(a).then(f.hitch(this,function(){this.loadingIndicator.hide();this._assetInfoForReset={};this.onProjectCreateOrLoad(this.projectInfo,
this.assetInfo);this.emit("resetProject")}),f.hitch(this,function(){this.loadingIndicator.hide()}))},_clearAppliedFilters:function(){this.config.projectSettings.projectLayer&&this.filterManager.applyWidgetFilter(this.config.projectSettings.projectLayer,this.widgetId,"",!0,!0);this._recentlyOperatedLayerIds=[];k.forEach(this.config.layerSettings,f.hitch(this,function(b){var c=this.layerInfosObj.getLayerInfoById(b.id);b.editable&&c&&c.layerObject&&c.layerObject.clearSelection()}));var a=this.map.getLayer(this.config.projectSettings.pointLayerCentroid);
a&&(a.setDefinitionExpression(this._exsitingLabelPointDefExpression),a.refresh());this._filterAssets(!0)},_loadProjectAssetTable:function(){var a=new x;if(this.config.projectSettings.assetTable&&!this._projectAssetTable){var b=this.layerInfosObj.getTableInfoById(this.config.projectSettings.assetTable).layerObject;this._projectAssetTable=new u(b.url);this.own(m(this._projectAssetTable,"load",function(){a.resolve()}))}else a.resolve();return a.promise},_loadAdditionalCostTable:function(){var a;var b=
new x;(a=this.config.projectSettings.multiplierAdditionalCostTable)&&!this._additionalCostTable?(a=this.layerInfosObj.getTableInfoById(a).layerObject.url,this._additionalCostTable=new u(a),this.own(m(this._additionalCostTable,"load",function(){b.resolve()}))):b.resolve();return b.promise},onProjectCreateOrLoad:function(a,b){var c=[];this.projectInfo=a;this._displayLabelRelatedToSelectProject();c.push(this._loadProjectAssetTable());c.push(this._loadAdditionalCostTable());y(c).then(f.hitch(this,function(){var d,
e,g;this.projectInfo=a;this._recentlyOperatedLayerIds=[];this._assetTableIds={};this._assetItemSummary={};this._assetGroupSummary={};this._disableWebMapPopup();this.initWorkBenchComponents().then(f.hitch(this,function(){g=this.config.projectSettings.projectLayer;this.projectInfo.projectId&&g&&(e=this.layerInfosObj.getLayerInfoById(g).layerObject,d=e.globalIdField+"\x3d '"+this.projectInfo.projectId+"'",this.filterManager.applyWidgetFilter(g,this.widgetId,d,!0,!0));this._projectOverview&&this._projectOverview.showAssetItemSummary(this._assetItemSummary,
!1);this._assetDetails&&this._assetDetails.reset();b?this.loadProject(b):(this._filterAssets(),this._projectSummary.addConfiguredAdditionalCostArray());0===Object.keys(this._assetItemSummary).length?n.add(this.downloadCSVBtn,"esriCTHidden"):n.remove(this.downloadCSVBtn,"esriCTHidden");var h=this.refreshButton,l=this.featureModeTextNode;"none"===this.downloadCSVBtn.style.display||n.contains(this.downloadCSVBtn,"esriCTHidden")||(h=this.downloadCSVBtn);n.contains(this.projectNameDiv,"esriCTHidden")||
(l=this.projectNameDiv);this.appUtils.setFirstAndLastWBFocusNode(this.widgetDomNode,l,h);this._handle508AccessibilityForTemplatePicker()}))}))},loadProject:function(a){var b=[];this._isLoadingProject=!0;this._projectSummary.loadingProject=!0;this._projectSummary.loadAdditionalCost(a.additionalCostInfo);for(var c in a.assetInfo){var d=a.assetInfo[c],e=this.layerInfosObj.getLayerInfoById(c).layerObject;b=b.concat(d);this._loadAsset(e,d,a,c)}this._setExtentToProjectAssets(b);this._recentlyOperatedLayerIds=
[];this._onAssetInfoUpdate();this._projectSummary.loadingProject=!1;this._projectSummary.calculateGrossCost(this._projectSummary.totalCost,!1)},_loadAsset:function(a,b,c,d){k.forEach(b,f.hitch(this,function(e){var g=e.attributes[a.globalIdField],h=c.assetTemplateInfo[g];e.templateInfo=h;e.templateName=h.TEMPLATENAME;this._templatePicker.loadCostingInfo(d,h);this._assetTableIds[g]=h.OBJECTID;this._onFeaturesAdded([e],a,[h],!1)}))},_setExtentToProjectAssets:function(a){0<a.length&&this.map.setExtent(M.graphicsExtent(a).expand(1.5))},
initWorkBenchComponents:function(){var a=new x;this._initTemplatePicker();this._initProjectSummary();this._initProjectOverview();this._initAssetDetails(a);return a.promise},_initTemplatePicker:function(){var a=v.create("div",{},this.templatePickerContainer);this._templatePicker=new N({config:this.config,nls:this.nls,layerInfosObj:this.layerInfosObj,loadingIndicator:this.loadingIndicator,projectInfo:this.projectInfo,selectedProjectFeatureAttr:this.selectedProjectFeatureAttr?this.selectedProjectFeatureAttr:
null,map:this.map,selectFeaturesNode:this.copyFeaturesNode,selectButton:this.selectButton,sketchButton:this.sketchButton,appUtils:this.appUtils,widgetId:this.widgetId,widgetDomNode:this.widgetDomNode,refreshButton:this.refreshButton,downloadCSVBtn:this.downloadCSVBtn,projectNameDiv:this.projectNameDiv,featureModeTextNode:this.featureModeTextNode},a);m(this._templatePicker,"assetAdded",f.hitch(this,function(b,c,d){0<b.length&&0<d.length&&(this._onFeaturesAdded(b,c,d,!0),this.emit("onAssetAdded",b,
c.id,this._projectA),n.contains(this.downloadCSVBtn,"esriCTHidden")&&n.remove(this.downloadCSVBtn,"esriCTHidden"),this._onAssetInfoUpdate())}));m(this._templatePicker,"assetDeleted",f.hitch(this,function(b,c){var d=this._getGlobalIds(c.globalIdField,b);this._onFeaturesUpdated(b);0===Object.keys(this._assetItemSummary).length&&n.add(this.downloadCSVBtn,"esriCTHidden");this._onAssetInfoUpdate(!0);k.forEach(d,f.hitch(this,function(e){this._assetTableIds.hasOwnProperty(e)&&delete this._assetTableIds[e];
this._assetInfoForReset&&this._assetInfoForReset[c.id]&&(e=this._assetInfoForReset[c.id].indexOf(e),-1<e&&this._assetInfoForReset[c.id].splice(e,1))}));this._projectAssetTable&&(b=this.config.assetTableFields.ASSETGUID+" in ('"+d.join("','")+"')",this.appUtils.deleteFeatures(this._projectAssetTable.url,b))}));m(this._templatePicker,"assetUpdated",f.hitch(this,function(b){this._onFeaturesUpdated(b,!0);this._onAssetInfoUpdate()}));m(this._templatePicker,"editorLoaded",f.hitch(this,function(){this._handle508AccessibilityForTemplatePicker()}));
this._templatePicker.startup()},_handle508AccessibilityForTemplatePicker:function(){setTimeout(f.hitch(this,function(){var a=w("div[role\x3d'grid']",this.templatePickerContainer);var b=w("[type\x3d'checkbox']",this.templatePickerContainer);var c=w("[dojoattachpoint\x3d'lastFocusNode']",this.templatePickerContainer);a&&a[0]&&r.set(a[0],"tabindex","-1");k.forEach(b,f.hitch(this,function(d){r.set(d,"tabindex","-1")}));c&&c[0]&&r.set(c[0],"tabindex","-1")}),500)},_initProjectSummary:function(){this._projectSummary?
this._projectSummary.reset(this.projectInfo):(this._projectSummary=new P({nls:this.nls,map:this.map,config:this.config,appUtils:this.appUtils,layerInfosObj:this.layerInfosObj,projectInfo:this.projectInfo,additionalCostTable:this._additionalCostTable,widgetDomNode:this.widgetDomNode},v.create("div",{},this.projectSummaryDiv)),this.own(m(this._projectSummary,"grossCostUpdated",f.hitch(this,function(a,b,c){this._projectOverview.grossCostUpdated(b);this._assetDetails.grossCostUpdated(a,b,c);this.emit("onGrossCostUpdated",
a,b,c)}))),this.own(m(this._projectSummary,"onOkButtonClicked",f.hitch(this,function(){this.emit("showAssetDetails")}))),this.own(m(this._projectSummary,"onCancelButtonClicked",f.hitch(this,function(){this.emit("showAssetDetails")}))),this._projectSummary.startup())},_initProjectOverview:function(){this._projectOverview?this._projectOverview.updateProjectInfo(this.projectInfo):(this._projectOverview=new O({config:this.config,appUtils:this.appUtils,nls:this.nls,map:this.map,layerInfosObj:this.layerInfosObj,
geometryService:new B(this.config.helperServices.geometry.url),projectInfo:this.projectInfo,widgetDomNode:this.widgetDomNode,projectNameDiv:this.projectNameDiv,selectButton:this.selectButton,featureModeTextNode:this.featureModeTextNode},v.create("div",{},this.projectOverview)),this.own(m(this._projectOverview,"actionClicked",f.hitch(this,function(a){this.emit("actionClicked",a)}))),this.own(m(this._projectOverview,"titleClicked",f.hitch(this,function(a){this.emit("titleClicked",a)}))),this.own(m(this._projectOverview,
"totalCostCalculated",f.hitch(this,function(a){this._assetDetails.totalCostUpdated(a);this._projectSummary.calculateGrossCost(a,!0)}))),this.own(m(this._projectOverview,"addOrModifyLabelPoint",f.hitch(this,function(a){this._addOrModifyLabelPoint(a.projectGeometry)}))),this._projectOverview.startup())},_initAssetDetails:function(a){this._assetDetails?(this._assetDetails.showAssetDetails({}),a.resolve()):(this._assetDetails=new Q({nls:this.nls,map:this.map,config:this.config,appUtils:this.appUtils,
layerInfosObj:this.layerInfosObj,projectInfo:this.projectInfo,widgetDomNode:this.widgetDomNode},v.create("div",{},this.assetDetailsDiv)),this.own(m(this._assetDetails,"showAdditionalCost",f.hitch(this,function(){this._projectSummary&&this._projectSummary.cloneTableData();this.emit("showAdditionalCost")}))),this.own(m(this._assetDetails,"onOkButtonClicked",f.hitch(this,function(){this.emit("showWorkBenchPanel")}))),this.own(m(this._assetDetails,"onCancelButtonClicked",f.hitch(this,function(){this.emit("showWorkBenchPanel")}))),
this.own(m(this._assetDetails,"onLoad",f.hitch(this,function(){a.resolve()}))),this.own(m(this._assetDetails,"groupCostEquationUpdated",f.hitch(this,this._updateGroupCostEquation))),this._assetDetails.startup())},_createDownLoadData:function(){var a=[],b,c,d,e;for(b in this._assetGroupSummary)for(c in this._assetGroupSummary[b])for(d in this._assetGroupSummary[b][c])for(e in this._assetGroupSummary[b][c][d])this._assetGroupSummary[b][c][d][e]&&0<this._assetGroupSummary[b][c][d][e].length&&a.push(this._getReportAttributes(b,
this._assetGroupSummary[b][c][d][e]));return{features:a,cols:this._reportColumns}},_getReportColumns:function(){k.forEach(this.config.generalSettings.CSVReportSettings.reportSettings,f.hitch(this,function(a){a.isVisible&&this._reportColumns.push(a.columnLabel||a.columnTitle)}))},_getReportAttributes:function(a,b){var c={};k.forEach(this.config.generalSettings.CSVReportSettings.reportSettings,f.hitch(this,function(d){d.isVisible&&(c[d.columnLabel||d.columnTitle]=this._fetchReportFieldTitleAndData(d,
a,b))}));return c},_getFeatureColumns:function(a){var b=[],c;for(c in a)b.push(c);return b},_fetchReportFieldTitleAndData:function(a,b,c){b=this.layerInfosObj.getLayerOrTableInfoById(b).layerObject;switch(a.fieldToMap){case "layerName":var d=b.name;break;case "TEMPLATENAME":case "GEOGRAPHY":case "SCENARIO":case "COSTEQUATION":d=c[0].templateInfo[a.fieldToMap]||"None";break;case "count":d=c.length;break;case "Length":d=this._getTotalAreaOrLength(b.geometryType,c,"length");break;case "Area":d=this._getTotalAreaOrLength(b.geometryType,
c,"area");break;case "cost":d=this._getTotalCostForRegion(c)}return d},_getTotalAreaOrLength:function(a,b,c){var d=0;"esriGeometryPolyline"===a?"length"===c&&k.forEach(b,f.hitch(this,function(e){d+=e.featureDimension})):"esriGeometryPolygon"===a&&"area"===c&&k.forEach(b,f.hitch(this,function(e){d+=e.featureDimension}));return 0===d?"NA":this.appUtils.applyRounding(d)},_getTotalCostForRegion:function(a){var b=0;k.forEach(a,f.hitch(this,function(c){b+=c.individualCost}));return this.appUtils.applyRounding(b)},
_onAssetInfoUpdate:function(a){this._projectOverview.showAssetItemSummary(this._assetItemSummary,!0);this._assetDetails.showAssetDetails(this._assetGroupSummary,a);this._filterAssets();this.emit("assetInfoUpdated",this._assetItemSummary)},_addAssetGroupSummary:function(a,b,c){var d=c[0].TEMPLATENAME;this._assetGroupSummary.hasOwnProperty(b.id)?this._assetGroupSummary[b.id].hasOwnProperty(d)||(this._assetGroupSummary[b.id][d]={}):(this._assetGroupSummary[b.id]={},this._assetGroupSummary[b.id][d]={});
k.forEach(a,f.hitch(this,function(e,g){g=c[g];g.SCENARIO===this.nls.scenarioSelection.noneText&&(g.SCENARIO="null");g.GEOGRAPHY===this.nls.scenarioSelection.noneText&&(g.GEOGRAPHY="null");this._assetGroupSummary[b.id][d].hasOwnProperty(g.GEOGRAPHY)?this._assetGroupSummary[b.id][d][g.GEOGRAPHY].hasOwnProperty(g.SCENARIO)||(this._assetGroupSummary[b.id][d][g.GEOGRAPHY][g.SCENARIO]=[]):(this._assetGroupSummary[b.id][d][g.GEOGRAPHY]={},this._assetGroupSummary[b.id][d][g.GEOGRAPHY][g.SCENARIO]=[]);this._assetGroupSummary[b.id][d][g.GEOGRAPHY][g.SCENARIO].push(e)}))},
_updateAssetGroupSummary:function(a,b,c){var d=b.templateInfo.TEMPLATENAME;var e=b.templateInfo.GEOGRAPHY;var g=b.templateInfo.SCENARIO;var h=b.attributes[a.objectIdField];e===this.nls.scenarioSelection.noneText&&(e="null");g===this.nls.scenarioSelection.noneText&&(g="null");k.some(this._assetGroupSummary[a.id][d][e][g],f.hitch(this,function(l,p){if(l.attributes[a.objectIdField]===h)return c?this._assetGroupSummary[a.id][d][e][g][p].featureDimension=b.featureDimension:this._assetGroupSummary[a.id][d][e][g].splice(p,
1),!0}))},_onFeaturesAdded:function(a,b,c,d){var e=[];var g=c[0].TEMPLATENAME;e=this._getGlobalIds(b.globalIdField,a);this._addAssetGroupSummary(a,b,c);this._assetItemSummary.hasOwnProperty(b.id)?this._assetItemSummary[b.id].templates.hasOwnProperty(g)?(a=this._assetItemSummary[b.id].templates[g].features.concat(a),this._assetItemSummary[b.id].templates[g].units=a.length):this._assetItemSummary[b.id].templates[g]={units:a.length,features:a,cost:null}:(this._assetItemSummary[b.id]={layerName:b.name,
templates:{},geometryType:b.geometryType},this._assetItemSummary[b.id].templates[g]={units:a.length,features:a,cost:null});this._recentlyOperatedLayerIds=[b.id];this._setFeaturesAndUnits(a,b,g);this._assetItemSummary[b.id].templates[g].cost=this._getTotalCost(b,g);d&&this._projectAssetTable?this._addAssetsToProjectAssetTable(c,e):(this._assetInfoForReset||(this._assetInfoForReset={}),this._assetInfoForReset[b.id]=this._assetInfoForReset[b.id]?this._assetInfoForReset[b.id].concat(e):f.clone(e))},_updateFeaturesInfo:function(a){var b;
k.forEach(a,f.hitch(this,function(c){var d=c._layer;for(b in this._assetItemSummary[d.id].templates)this._setUpdatedTemplateFeatures(c,d,b)}));return a},_setUpdatedTemplateFeatures:function(a,b,c){k.some(this._assetItemSummary[b.id].templates[c].features,f.hitch(this,function(d){if(d.attributes[b.objectIdField]===a.attributes[b.objectIdField])return a.featureDimension=d.featureDimension,a.templateName=c,a.templateInfo=d.templateInfo,!0}))},_onFeaturesUpdated:function(a,b){a=this._updateFeaturesInfo(a);
this._recentlyOperatedLayerIds=[];k.forEach(a,f.hitch(this,function(c){var d=c.templateName;var e=c._layer;this._recentlyOperatedLayerIds.push(e.id);k.some(this._assetItemSummary[e.id].templates[d].features,f.hitch(this,function(g,h){if(g.attributes[e.objectIdField]===c.attributes[e.objectIdField])return this._assetItemSummary.hasOwnProperty(e.id)&&this._assetItemSummary[e.id].templates[d]&&(b?(this._assetItemSummary[e.id].templates[d].features[h]=c,this._setFeaturesAndUnits(this._assetItemSummary[e.id].templates[d].features,
e,d,b)):(g=this._assetItemSummary[e.id].templates[d].units,g-=c.featureDimension,this._assetItemSummary[e.id].templates[d].units=this.appUtils.removeNegativeExponents(g)),this._updateAssetGroupSummary(e,c,b)),b||this._assetItemSummary[e.id].templates[d].features.splice(h,1),!0}));0===this._assetItemSummary[e.id].templates[d].features.length?delete this._assetItemSummary[e.id].templates[d]:this._assetItemSummary[e.id].templates[d].cost=this._getTotalCost(e,d);0===Object.keys(this._assetItemSummary[e.id].templates).length&&
delete this._assetItemSummary[e.id]}))},_setFeaturesAndUnits:function(a,b,c,d){var e=0;var g=this.config.generalSettings.measurementUnit;k.forEach(a,f.hitch(this,function(h){if(!h.hasOwnProperty("featureDimension")||d)h.featureDimension="esriGeometryPolygon"===b.geometryType?this.appUtils.getAreaOfGeometry(h.geometry,this.appUtils.units[g].areaUnit):"esriGeometryPolyline"===b.geometryType?this.appUtils.getLengthOfGeometry(h.geometry,this.appUtils.units[g].lengthUnit):1,d||(h.templateName=c);e+=h.featureDimension}));
this._assetItemSummary[b.id].templates[c].features=a;return this._assetItemSummary[b.id].templates[c].units=e},_getGroupTotalMeasure:function(a,b){var c=0;var d=b.TEMPLATENAME;var e=b.GEOGRAPHY;b=b.SCENARIO;try{var g=this._assetGroupSummary[a][d][e][b];k.forEach(g,f.hitch(this,function(h){c+=h.featureDimension}))}catch(h){c=0}return c},_getGroupTotalCount:function(a,b){var c;var d=0;var e=b.TEMPLATENAME;var g=b.GEOGRAPHY;b=b.SCENARIO;try{(c=this._assetGroupSummary[a][e][g][b])&&0<c.length&&(d=c.length)}catch(h){d=
0}return d},_getTotalCost:function(a,b){var c=0;k.forEach(this._assetItemSummary[a.id].templates[b].features,f.hitch(this,function(d){var e=this._getGroupTotalMeasure(a.id,d.templateInfo);var g=this._getGroupTotalCount(a.id,d.templateInfo);try{var h=d.templateInfo.COSTEQUATION;h=h.replace(/{MEASURE}/ig,d.featureDimension);h=h.replace(/{TOTALMEASURE}/ig,e);h=h.replace(/{TOTALCOUNT}/ig,g);var l=this.appUtils.evaluate(h)}catch(p){l=0}k.some(this._assetGroupSummary[a.id][b][d.templateInfo.GEOGRAPHY][d.templateInfo.SCENARIO],
f.hitch(this,function(p){if(p.attributes[a.objectIdField]===d.attributes[a.objectIdField])return p.individualCost=l,!0}));d.individualCost=l;c+=l}));return Number(c)},_getGlobalIds:function(a,b){var c=[];k.forEach(b,f.hitch(this,function(d){c.push(d.attributes[a])}));return c},_getExpressionToFilterAssets:function(a){var b,c=[],d;if((d=this.layerInfosObj.getLayerInfoById(a))&&d.layerObject&&this._assetItemSummary[a]){var e=d.layerObject;for(b in this._assetItemSummary[a].templates)c=c.concat(this._getGlobalIds(e.globalIdField,
this._assetItemSummary[a].templates[b].features))}return 0<c.length?e.globalIdField+" in ('"+c.join("','")+"')":"1\x3d2"},_filterAssets:function(a){this._recentlyOperatedLayerIds&&0!==this._recentlyOperatedLayerIds.length||(this._recentlyOperatedLayerIds=[],k.forEach(this.config.layerSettings,f.hitch(this,function(b){b.editable&&this._recentlyOperatedLayerIds.push(b.id)})));k.forEach(this._recentlyOperatedLayerIds,f.hitch(this,function(b){var c="";a||(c=this._getExpressionToFilterAssets(b));this.filterManager.applyWidgetFilter(b,
this.widgetId,c,!0,!0)}))},_addAssetsToProjectAssetTable:function(a,b){var c=[],d=["COSTEQUATION","SCENARIO","TEMPLATENAME","GEOGRAPHYGUID"];this.loadingIndicator.show();k.forEach(b,f.hitch(this,function(e,g){var h={};k.forEach(this._projectAssetTable.fields,f.hitch(this,function(l){var p="";-1<d.indexOf(l.name.toUpperCase())?(p=a[g][l.name.toUpperCase()],"SCENARIO"!==l.name.toUpperCase()&&"GEOGRAPHYGUID"!==l.name.toUpperCase()||"null"!==p||(p=null),h[l.name]=p):"ASSETGUID"===l.name.toUpperCase()?
h[l.name]=e:"PROJECTGUID"===l.name.toUpperCase()&&this.projectInfo.projectId&&(h[l.name]=this.projectInfo.projectId)}));c.push(new t(null,null,h))}));this._projectAssetTable.applyEdits(c,null,null,f.hitch(this,function(e){var g=!1;k.forEach(e,f.hitch(this,function(h,l){h.success?this._assetTableIds[b[l]]=h.objectId:g=!0}));g&&this.appUtils.showMessage(this.nls.workBench.errorInSavingAssetDetails);this.loadingIndicator.hide()}),f.hitch(this,function(){this.loadingIndicator.hide();this.appUtils.showMessage(this.nls.workBench.errorInSavingAssetDetails)}))},
_updateGroupCostEquation:function(a){var b=[];var c=a.groupInfo;var d=this._assetGroupSummary[c.layerId][c.templateName][c.region][c.scenario];var e=this.layerInfosObj.getLayerInfoById(c.layerId).layerObject;k.forEach(d,f.hitch(this,function(g){var h={};var l=g.attributes[e.globalIdField];var p=g.attributes[e.objectIdField];k.some(this._assetItemSummary[c.layerId].templates[c.templateName].features,f.hitch(this,function(A){if(A.attributes[e.objectIdField]===p)return A.templateInfo.COSTEQUATION=a.templateInfo.COSTEQUATION,
A.templateInfo.SCENARIO=a.templateInfo.SCENARIO,!0}));g.templateInfo.COSTEQUATION=a.templateInfo.COSTEQUATION;g.templateInfo.SCENARIO=a.templateInfo.SCENARIO;this._projectAssetTable&&this._assetTableIds[l]&&(h[this.config.assetTableFields.COSTEQUATION]=a.templateInfo.COSTEQUATION,h[this.config.assetTableFields.SCENARIO]="null"===a.templateInfo.SCENARIO?null:a.templateInfo.SCENARIO,h[this.config.assetTableFields.OBJECTID]=this._assetTableIds[l],b.push(new t(null,null,h)))}));delete this._assetGroupSummary[c.layerId][c.templateName][c.region][c.scenario];
this._assetGroupSummary[c.layerId][c.templateName][c.region][a.templateInfo.SCENARIO]=d;this._templatePicker.loadCostingInfo(e.id,d[0].templateInfo);this._assetItemSummary[e.id].templates[c.templateName].cost=this._getTotalCost(e,c.templateName);this._projectOverview.showAssetItemSummary(this._assetItemSummary,!1);this._assetDetails.showAssetDetails(this._assetGroupSummary);this._projectAssetTable&&(this.loadingIndicator.show(),this._projectAssetTable.applyEdits(null,b,null,f.hitch(this,function(){this.loadingIndicator.hide()}),
f.hitch(this,function(){this.loadingIndicator.hide()})))},_enableWebMapPopup:function(){this.map&&this.map.setInfoWindowOnClick(!0)},_disableWebMapPopup:function(){this.map&&this.map.setInfoWindowOnClick(!1);this._hideWebMapPopup()},_hideWebMapPopup:function(){this.map.infoWindow.isShowing&&this.map.infoWindow.hide();this.map.infoWindow.clearFeatures()},_addOrModifyLabelPoint:function(a){this.loadingIndicator.show();""!==this.config.projectSettings.pointLayerCentroid&&null!==this.config.projectSettings.pointLayerCentroid&&
void 0!==this.config.projectSettings.pointLayerCentroid?this._isLoadingProject?this._displayLabelRelatedToSelectProject():this._checkExistingLabelPoint(a):this.loadingIndicator.hide()},_displayLabelRelatedToSelectProject:function(){if(this._pointLayer=this.map.getLayer(this.config.projectSettings.pointLayerCentroid)){var a=this._pointLayer.getDefinitionExpression(),b=this._getFieldName(this._pointLayer,"projectid")+" \x3d '"+this.projectInfo.projectId+"'";""!==a&&null!==a&&void 0!==a?-1===a.indexOf(b)&&
(a=a+" AND "+b):a=b;this._pointLayer.setDefinitionExpression(a);this._pointLayer.refresh()}this._isLoadingProject=!1;this.loadingIndicator.hide()},_checkExistingLabelPoint:function(a){var b={},c;b.existingLabelPoint=this._getExistingLabelPointDeferred();y(b).then(f.hitch(this,function(d){0<d.existingLabelPoint.features.length?this._createLabelPoint(!1,a,d.existingLabelPoint.features[0]):this._createLabelPoint(!0,a)}),f.hitch(this,function(){this.loadingIndicator.hide();c=this.appUtils.showMessage(this.nls.createLoadProject.errorAddingPointLabel);
this._handleShowDialogClosed(c)}))},_createLabelPoint:function(a,b,c){var d;if(0<b.rings.length){var e=new B(this.config.helperServices.geometry.url);b=U.simplify(b);e.labelPoints([b],f.hitch(this,function(g){this.config.projectSettings.pointLayerCentroid&&(g=g[0],a?this._addLabelPoint(g):this._updateExistingLabelPoint(c,g))}),f.hitch(this,function(){this.loadingIndicator.hide();d=this.appUtils.showMessage(this.nls.createLoadProject.errorFetchingPointLabel);this._handleShowDialogClosed(d)}))}else this._deleteExistingLabelPoint(c)},
_deleteExistingLabelPoint:function(a){var b;if(a){var c={};c[this._pointLayer.objectIdField]=a.attributes[this._pointLayer.objectIdField];var d=new t(null,null,c,null),e=new u(this._pointLayer.url,{outFields:["*"]});e.onLoad=f.hitch(this,function(){e.applyEdits(null,null,[d],f.hitch(this,function(g,h,l){l[0].success||(b=this.appUtils.showMessage(this.nls.createLoadProject.errorAddingPointLabel),this._handleShowDialogClosed(b));this.map.getLayer(this.config.projectSettings.pointLayerCentroid).refresh();
this.loadingIndicator.hide()}),f.hitch(this,function(){this.loadingIndicator.hide();b=this.appUtils.showMessage(this.nls.createLoadProject.errorAddingPointLabel);this._handleShowDialogClosed(b)}))})}else this.loadingIndicator.hide()},_getExistingLabelPointDeferred:function(){var a=this._getFieldName(this._pointLayer,"projectid")+" \x3d '"+this.projectInfo.projectId+"'";var b=new T(this._pointLayer.url),c=new S;c.outFields=["*"];c.where=a;c.returnGeometry=!0;c.outSpatialReference=this.map.spatialReference;
return b.execute(c).promise},_getFieldName:function(a,b){var c;k.forEach(a.fields,f.hitch(this,function(d){d.name.toLowerCase()===b.toLowerCase()&&(c=d.name)}));return c},_addLabelPoint:function(a){var b=new D(a.x,a.y,new C({wkid:this.map.spatialReference.wkid}));a=this._pointLayer.hasOwnProperty("templates")&&0<this._pointLayer.templates.length&&this._pointLayer.templates[0].hasOwnProperty("prototype")&&this._pointLayer.templates[0].prototype.hasOwnProperty("attributes")?this._pointLayer.templates[0].prototype.attributes:
this._pointLayer.hasOwnProperty("types")&&0<this._pointLayer.types.length&&this._pointLayer.types[0].hasOwnProperty("templates")&&0<this._pointLayer.types[0].templates.length&&this._pointLayer.types[0].templates[0].hasOwnProperty("prototype")&&this._pointLayer.types[0].templates[0].prototype.hasOwnProperty("attributes")?this._pointLayer.types[0].templates[0].prototype.attributes:null;null===this._originalTemplateAttributes||""===this._originalTemplateAttributes||void 0===this._originalTemplateAttributes?
this._originalTemplateAttributes=f.clone(a):a=f.clone(this._originalTemplateAttributes);var c=this._getFieldName(this._pointLayer,"projectid");a[c]=this.projectInfo.projectId;a=new t(b,null,a,null);(new u(this._pointLayer.url)).applyEdits([a],null,null,f.hitch(this,function(d,e,g){d[0].success||(d=this.appUtils.showMessage(this.nls.createLoadProject.errorAddingPointLabel),this._handleShowDialogClosed(d));this.map.getLayer(this.config.projectSettings.pointLayerCentroid).refresh();this.loadingIndicator.hide()}),
f.hitch(this,function(){this.loadingIndicator.hide();var d=this.appUtils.showMessage(this.nls.createLoadProject.errorAddingPointLabel);this._handleShowDialogClosed(d)}))},_updateExistingLabelPoint:function(a,b){var c={};c[this._pointLayer.objectIdField]=a.attributes[this._pointLayer.objectIdField];a=new D(b.x,b.y,new C({wkid:this.map.spatialReference.wkid}));var d=new t(a,null,c,null),e=new u(this._pointLayer.url,{outFields:["*"]});e.onLoad=f.hitch(this,function(){e.applyEdits(null,[d],null,f.hitch(this,
function(g,h,l){h[0].success||(g=this.appUtils.showMessage(this.nls.createLoadProject.errorAddingPointLabel),this._handleShowDialogClosed(g));this.map.getLayer(this.config.projectSettings.pointLayerCentroid).refresh();this.loadingIndicator.hide()}),f.hitch(this,function(){this.loadingIndicator.hide();var g=this.appUtils.showMessage(this.nls.createLoadProject.errorAddingPointLabel);this._handleShowDialogClosed(g)}))})},updateProjectFeatureAttributes:function(a){this._templatePicker.selectedProjectFeatureAttr=
a},_storeExistingLabelPointLayerDefExpression:function(){var a=this.map.getLayer(this.config.projectSettings.pointLayerCentroid);a&&(a=a.getDefinitionExpression(),this._exsitingLabelPointDefExpression=f.clone(a))},_handleShowDialogClosed:function(a){(a=a.enabledButtons[0])&&this.own(m(a,"keydown",f.hitch(this,function(b){if(b.keyCode===q.ENTER||b.keyCode===q.SPACE)z.stop(b),n.contains(this.sketchButton,"esriCTSketchDisable")?E.focus(this.selectButton):E.focus(this.sketchButton)})))},_downLoadCSV:function(a){var b=
this._getCSVFileName();R.exportCSV(b,a.features,a.cols)},_getCSVFileName:function(){var a="AssetItemDetails";this.config.generalSettings.CSVReportSettings.reportName?a=this.config.generalSettings.CSVReportSettings.reportName:this.projectInfo&&this.projectInfo.name&&(a="Export-"+this.projectInfo.name);return a}})});