// 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/template-picker.html":'\x3cdiv\x3e\r\n  \x3cdiv class\x3d"esriCTAssetTemplatePicker" data-dojo-attach-point\x3d"templatePickerNode"\x3e\r\n  \x3c/div\x3e\r\n  \x3cdiv class\x3d"esriCTEditorToolBar" data-dojo-attach-point\x3d"editorToolbarNode"\x3e\r\n  \x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/declare jimu/BaseWidget dojo/Evented dijit/_WidgetsInTemplateMixin dojo/text!./template-picker.html dojo/_base/array dojo/_base/lang dojo/on dojo/Deferred dojo/dom-class dojo/dom-construct esri/dijit/editing/Editor esri/tasks/GeometryService dojo/_base/html jimu/dijit/Popup jimu/dijit/Message dojo/keys esri/geometry/geometryEngine ./scenario-selection esri/SpatialReference esri/geometry/Polyline esri/geometry/Polygon esri/tasks/query esri/tasks/QueryTask esri/graphic esri/layers/FeatureLayer esri/toolbars/draw ./copy-features dojo/dom-attr dijit/focus dojo/_base/event jimu/utils".split(" "),function(I,
J,K,L,M,k,e,m,z,p,A,u,N,O,P,Q,q,t,B,v,y,C,D,R,E,S,F,T,G,w,x,H){return I([J,K,L],{templateString:M,baseClass:"jimu-widget-cost-template-picker",_projectOverview:null,_templatePicker:null,_editor:null,_scenarioSelectionObj:null,_selectScenarioPopup:null,_isFeatureIntersected:null,_configuredTemplateObj:[],_configuredGeographyCostEquation:{},_onBeforeEditCompleteResult:{},_templateInfoCalculated:!1,_addFeaturesEventInfo:[],_windowResizeTimer:null,selectedTemplateInfo:{},_splitAssetsArr:[],_currentAssetSplitGeometry:null,
_nonEditableLayers:[],_splitAssetInfo:[],_allIntersectedRegions:[],_selectedTemplate:null,_featuresToBeCopied:[],_layerEvents:[],_copyFeaturesObj:null,_layersForEditor:[],postCreate:function(){this.inherited(arguments);this._isFeatureIntersected=this._selectScenarioPopup=this._scenarioSelectionObj=this._editor=this._templatePicker=this._projectOverview=null;this._configuredTemplateObj=[];this._configuredGeographyCostEquation={};this.selectedTemplateInfo={};this._onBeforeEditCompleteResult={};this._addFeaturesEventInfo=
[];this._splitAssetsArr=[];this._currentAssetSplitGeometry=null;this._nonEditableLayers=[];this._splitAssetInfo=[];this._windowResizeTimer=null;this._allIntersectedRegions=[];this._selectedTemplate=null;this._featuresToBeCopied=[];this._layerEvents=[];this._copyFeaturesObj=null;this._layersForEditor=[]},startup:function(){this.inherited(arguments);this._getLayersForSelection();m(window,"resize",e.hitch(this,this.onWindowResize));this.own(m(this.sketchButton,"click",e.hitch(this,function(){p.contains(this.sketchButton,
"esriCTSketchEnable")||(this._toolBarActive=!0,this._activateSketchButton(),this._deActivateSelectButton());this._toggleToolState()})));this.own(m(this.sketchButton,"keydown",e.hitch(this,function(a){if(a.keyCode===q.ENTER||a.keyCode===q.SPACE)p.contains(this.sketchButton,"esriCTSketchEnable")||(this._toolBarActive=!0,this._activateSketchButton(),this._deActivateSelectButton()),this._toggleToolState()})));this.own(m(this.selectButton,"click",e.hitch(this,function(){p.contains(this.selectButton,"esriCTSelectEnable")||
(this._toolBarActive=!1,this._activateSelectButton(),this._deActivateSketchButton());this._toggleToolState()})));this.own(m(this.selectButton,"keydown",e.hitch(this,function(a){if(a.keyCode===q.ENTER||a.keyCode===q.SPACE)p.contains(this.selectButton,"esriCTSelectEnable")||(this._toolBarActive=!1,this._activateSelectButton(),this._deActivateSketchButton()),this._toggleToolState()})))},destroy:function(){this._deactivateAllTools();this.removeLayerEvents();this._configuredGeographyCostEquation={};this._editor&&
(this._editor.destroy(),this._editor=null);this._copyFeaturesObj&&(this._copyFeaturesObj.destroy(),this._copyFeaturesObj=null);this.inherited(arguments)},loadCostingInfo:function(a,c){var b=c.GEOGRAPHYGUID;var d=c.TEMPLATENAME;this._configuredGeographyCostEquation.hasOwnProperty(b)?this._configuredGeographyCostEquation[b].hasOwnProperty(a)?this._configuredGeographyCostEquation[b][a].hasOwnProperty(d)?this._configuredGeographyCostEquation[b]&&this._configuredGeographyCostEquation[b][a]&&this._configuredGeographyCostEquation[b][a][d]&&
(this._configuredGeographyCostEquation[b][a][d].COSTEQUATION=c.COSTEQUATION):this._configuredGeographyCostEquation[b][a][d]=c:(this._configuredGeographyCostEquation[b][a]={},this._configuredGeographyCostEquation[b][a][d]=c):(this._configuredGeographyCostEquation[b]={},this._configuredGeographyCostEquation[b][a]={},this._configuredGeographyCostEquation[b][a][d]=c)},onWindowResize:function(){this._windowResizeTimer&&clearTimeout(this._windowResizeTimer);this._windowResizeTimer=setTimeout(e.hitch(this,
this.resize),500)},_getLayersForSelection:function(){var a,c,b=[];this._layersForEditor=null;this._getConfiguredTemplates();k.forEach(this.config.layerSettings,e.hitch(this,function(d){if(d.editable||d.selectable)if(a=this.map.getLayer(d.id)){c=this._getLayerSettingsById(d.id);if(c.selectedField)var f=c.selectedField;(a=this._filterLayerTemplates(a,f))&&b.push({featureLayer:a,disableAttributeUpdate:!d.editable,disableGeometryUpdate:!d.editable,editable:d.editable});d.editable||this._nonEditableLayers.push(d.id)}}));
setTimeout(e.hitch(this,function(){this._layersForEditor=b;this._editor||this.initEditingToolbar()}),500)},_getLayerSettingsById:function(a){var c={};k.some(this.config.layerSettings,e.hitch(this,function(b){if(b.id===a)return c=b,!0}));return c},_filterLayerTemplates:function(a,c){var b,d;for(d in this.config.costingInfoSettings)0<this.config.costingInfoSettings[d].length&&(b=this.layerInfosObj.getLayerInfoById(d))&&b.layerObject&&b.layerObject.url===a.url&&(0<a.templates.length?a.templates=this._setConfiguredTemplates(a.templates,
d,c):a.types=this._setConfiguredTemplates(a.types,d,c));return a},_setConfiguredTemplates:function(a,c,b){var d=[];for(var f=a.length-1;0<=f;f--){var h=a[f].templates?a[f].templates[0].name:a[f].name;h=this._configuredTemplateObj[c].indexOf(h);-1!==h&&(b&&("templates"in a[f]?a[f].templates[0].prototype.attributes[b]=this.projectInfo.projectId:a[f].prototype.attributes[b]=this.projectInfo.projectId),d.push(a[f]))}return d},_getConfiguredTemplates:function(){for(var a in this.config.costingInfoSettings)this._getConfiguredTemplateNameArray(a)},
_getConfiguredTemplateNameArray:function(a){k.forEach(this.config.costingInfoSettings[a],e.hitch(this,function(c){this._configuredTemplateObj[a]||(this._configuredTemplateObj[a]=[]);this._configuredTemplateObj[a].push(c.featureTemplate)}))},initEditingToolbar:function(){if(null!==this._layersForEditor){var a=this._layersForEditor?this._layersForEditor:[];a={settings:{map:this.map,geometryService:new N(this.config.helperServices.geometry.url),layerInfos:a,toolbarVisible:!1,showAttributesOnClick:!0,
toolbarOptions:{reshapeVisible:!1,cutVisible:!1,mergeVisible:!1},createOptions:{polylineDrawTools:[u.CREATE_TOOL_POLYLINE,u.CREATE_TOOL_FREEHAND_POLYLINE],polygonDrawTools:[u.CREATE_TOOL_POLYGON,u.CREATE_TOOL_RECTANGLE,u.CREATE_TOOL_CIRCLE,u.CREATE_TOOL_FREEHAND_POLYGON]},showTooltip:!1}};this._editor=new u(a,A.create("div",{},this.editorToolbarNode));this.own(m(this._editor,"load",e.hitch(this,function(){this.emit("editorLoaded")})));this._editor.startup();this.bindLayerEvents();this._editor.templatePicker.showTooltip=
!0;a=k.filter(this._editor.templatePicker.featureLayers,e.hitch(this,function(c){return-1===this._nonEditableLayers.indexOf(c.id)}));this._editor.templatePicker.featureLayers=a;this.templatePickerNode&&this._editor.templatePicker.placeAt(this.templatePickerNode);this.own(m(this._editor.templatePicker,"selection-change",e.hitch(this,function(){var c;if(c=this._editor.templatePicker.getSelected())this._selectedTemplate=c;p.contains(this.selectButton,"esriCTSelectDisable")||this._activateCustomSelectTool()})));
this.own(m(this._editor.editToolbar,"deactivate",e.hitch(this,function(){this.emit("editEnd")})));this.own(m(this._editor.editToolbar,"activate",e.hitch(this,function(){this.emit("editStart")})));this.customToolbar||this._createCustomSelectTool();setTimeout(e.hitch(this,this.resize,100))}},_displayCopyAssetsPopup:function(){this._copyFeaturesDialog=new Q({message:this.nls.scenarioSelection.copyFeatureMsg,type:"question",maxWidth:375,buttons:[{label:this.nls.common.yes,onClick:e.hitch(this,function(){this._copyFeaturesDialog.close();
this._copyFeaturesObj.cancelBtnClicked();this._selectedTemplate&&this._copyFeature()})},{label:this.nls.common.no,onClick:e.hitch(this,function(){this._copyFeaturesDialog.close()})}]});var a=this._copyFeaturesDialog.enabledButtons;this.own(m(a[0],"keydown",e.hitch(this,function(c){if(c.keyCode===q.ENTER||c.keyCode===q.SPACE)x.stop(c),this._copyFeaturesObj.toggleWorkBenchDOMTabindexes("0"),H.initFirstFocusNode(this.widgetDomNode,this.featureModeTextNode),H.initLastFocusNode(this.widgetDomNode,this.refreshButton),
w.focus(this.featureModeTextNode)})));this.own(m(a[1],"keydown",e.hitch(this,function(c){if(c.keyCode===q.ENTER||c.keyCode===q.SPACE)x.stop(c),this._copyFeaturesObj.toggleWorkBenchDOMTabindexes("-1"),this._copyFeaturesObj._setFirstAndLastFocusNodes()})))},_copyFeature:function(){if(this._selectedTemplate){var a=new E(this._featuresToBeCopied.shift());this._selectedTemplate.featureLayer.applyEdits([a])}},_onCancelBtnClicked:function(){},_addCustomApplyEdits:function(){this._editor&&this._editor.settings&&
this._editor.settings.layers&&k.forEach(this._editor.settings.layers,e.hitch(this,function(a){a.myApplyEdits=a.applyEdits;var c=this;a.applyEdits=function(b,d,f){b&&0!==b.length?c._selectedTemplate&&(c._orgFeature=b[0],c._checkAssetIntersection()):a.myApplyEdits(b,d,f);var h=new z;setTimeout(function(){h.resolve(!0)},100);return h}}))},removeLayerEvents:function(){this._editor&&this._editor.settings&&this._editor.settings.layers&&k.forEach(this._editor.settings.layers,e.hitch(this,function(a){a.myApplyEdits&&
(a.applyEdits=a.myApplyEdits,delete a.myApplyEdits)}));this._layerEvents&&0<this._layerEvents.length&&(k.forEach(this._layerEvents,e.hitch(this,function(a){a[0].remove()})),this._layerEvents=[]);this._copyFeaturesObj&&this._copyFeaturesObj.cancelBtnClicked()},bindLayerEvents:function(){this.removeLayerEvents();this._addCustomApplyEdits();this._editor&&this._editor.settings&&this._editor.settings.layers&&0<this._editor.settings.layers.length&&k.forEach(this._editor.settings.layers,e.hitch(this,function(a){var c=
this.own(m(a,"before-apply-edits",e.hitch(this,this.onBeforeEditComplete)));var b=this.own(m(a,"edits-complete",e.hitch(this,this.onEditCompletes)));this._layerEvents.push(c);this._layerEvents.push(b);-1<this._nonEditableLayers.indexOf(a.id)&&(c=this.own(m(a,"selection-complete",e.hitch(this,function(d){d.features.length&&this._editor&&this._editor.drawingToolbar&&this._editor.drawingToolbar._tools&&p.add(this._editor.drawingToolbar._tools.DELETE.domNode,"esriCTHidden")}))),a=this.own(m(a,"selection-clear",
e.hitch(this,function(){this._editor&&this._editor.drawingToolbar&&this._editor.drawingToolbar._tools&&p.remove(this._editor.drawingToolbar._tools.DELETE.domNode,"esriCTHidden")}))),this._layerEvents.push(c),this._layerEvents.push(a))}))},onBeforeEditComplete:function(a){this._editor.attributeInspector.focused&&(a.deletes&&0===a.deletes.length||a.updates&&0<a.updates.length)||(this.loadingIndicator.show(),this._onBeforeEditCompleteResult[a.target.id]||(this._onBeforeEditCompleteResult[a.target.id]=
[]),this._onBeforeEditCompleteResult[a.target.id].push(a))},onEditCompletes:function(a){this._editor.attributeInspector.focused&&(a.deletes&&0===a.deletes.length||a.updates&&0<a.updates.length)||(a=this._getSucceededFeatures(a,a.target.id),this.loadingIndicator.hide(),a.deletes&&0<a.deletes.length&&this.deleteFeatures(a.deletes,a.target),a.adds&&0<a.adds.length&&this.addFeatures(a.adds,a.target),a.updates&&0<a.updates.length&&this.editFeatures(a.updates))},_getSucceededFeatures:function(a,c){k.forEach(a.adds,
e.hitch(this,function(b,d){b.success||(this._onBeforeEditCompleteResult[c][0].adds.splice(d,1),this._splitAssetInfo.splice(d,1))}));k.forEach(a.updates,e.hitch(this,function(b,d){b.success||(this._onBeforeEditCompleteResult[c][0].updates.splice(d,1),this._splitAssetInfo.splice(d,1))}));k.forEach(a.deletes,e.hitch(this,function(b,d){b.success||(this._onBeforeEditCompleteResult[c][0].deletes.splice(d,1),this._splitAssetInfo.splice(d,1))}));return this._onBeforeEditCompleteResult[c].shift()},addFeatures:function(a,
c){k.forEach(this._splitAssetInfo,e.hitch(this,function(b,d){delete b.ASSETGEOMETRY;a[d].templateInfo=b;a[d].templateName=b.TEMPLATENAME}));this.emit("assetAdded",a,c,this._splitAssetInfo);this._orgFeature=null;0<this._featuresToBeCopied.length&&this._copyFeature()},editFeatures:function(a){this.emit("assetUpdated",a)},deleteFeatures:function(a,c){this.emit("assetDeleted",a,c)},_polygonToPolyline:function(a){var c,b;var d=[];var f=new y(new v(a.spatialReference));for(b=0;b<a.rings.length;b++){var h=
[];for(c=0;c<a.rings[b].length;c++)h.push(a.rings[b][c]);f.addPath(h)}d.push(f);return d},_getSplitFeatureGeometries:function(a,c){var b;var d=[];var f=[];if(0<c.length){"polyline"===a.geometry.type?b=!0:"polygon"===a.geometry.type&&(b=!1);k.forEach(c,e.hitch(this,function(l){d.push(l.geometry)}));c=t.union(d);c=this._polygonToPolyline(c)[0];var h=a.geometry;c=t.cut(h,c);1<c.length?(f.push({geometry:c[0],isIntersectedGeometry:!1}),b?k.forEach(c,e.hitch(this,function(l,n){0<n&&k.forEach(l.paths,e.hitch(this,
function(g){var r=new y(new v(a.geometry.spatialReference));r.addPath(g);f.push({geometry:r,isIntersectedGeometry:!0})}))})):k.forEach(c,e.hitch(this,function(l,n){0<n&&k.forEach(l.rings,e.hitch(this,function(g){var r=new C(new v(a.geometry.spatialReference));r.addRing(g);f.push({geometry:r,isIntersectedGeometry:!0})}))}))):f.push({geometry:a.geometry,isIntersectedGeometry:!0})}else f.push({geometry:a.geometry,isIntersectedGeometry:!1});return f},_checkAssetIntersection:function(){this._intersectedCostingGraphicArr=
[];this._allIntersectedRegions=[];this._splitAssetInfo=[];this.selectedTemplateInfo={};this._getIntersectedCostingGraphicArr(this._orgFeature).then(e.hitch(this,function(a){var c;if(c=t.simplify(this._orgFeature.geometry))this._orgFeature.geometry=c,this._allIntersectedRegions=e.clone(a),this._intersectedCostingGraphicArr=a,this.config.projectSettings.costingGeometryLayer?"point"===this._orgFeature.geometry.type?this._splitAssetsArr.push({geometry:this._orgFeature.geometry,isIntersectedGeometry:0<
a.length}):this._splitAssetsArr=this._getSplitFeatureGeometries(this._orgFeature,this._intersectedCostingGraphicArr):this._splitAssetsArr.push({geometry:this._orgFeature.geometry,isIntersectedGeometry:0<a.length}),this._processOverlappingGeometries()}))},_getIntersectedCostingGraphicArr:function(a){var c=new z;if(this.config.projectSettings.costingGeometryLayer){var b=new D;var d=this.map.getLayer(this.config.projectSettings.costingGeometryLayer);var f=new R(d.url);d.getDefinitionExpression()&&(b.where=
d.getDefinitionExpression());a.geometry?(b.outSpatialReference=a.geometry.spatialReference,b.returnGeometry=!0,b.outFields=["*"],b.geometry=a.geometry,f.execute(b,e.hitch(this,function(h){var l=[];h&&0<h.features.length&&(l=h.features);c.resolve(l)}),e.hitch(this,function(){c.resolve([])}))):setTimeout(e.hitch(this,function(){c.resolve([])}),0)}else c.resolve([]);return c.promise},_processOverlappingGeometries:function(){var a=[],c=[],b=[],d=[];0<this._splitAssetsArr.length&&(k.forEach(this._splitAssetsArr,
e.hitch(this,function(f){f.isIntersectedGeometry?(f=this._splitForOverlappingGeometries(f),0<f.processed.length&&(a=a.concat(f.processed)),0<f.unProcessed.length&&(c=c.concat(f.unProcessed))):a.push(f)})),this._splitAssetsArr=[],this._splitAssetsArr=a);k.forEach(c,e.hitch(this,function(f){f=this._splitForOverlappingGeometries(f,!0);0<f.processed.length&&(b=b.concat(f.processed));0<f.unProcessed.length&&(d=d.concat(f.unProcessed))}));this._splitAssetsArr=this._splitAssetsArr.concat(b);this._deleteDuplicateSplits();
this._displayPopupForAssets()},_deleteDuplicateSplits:function(){var a=[];k.forEach(this._splitAssetsArr,e.hitch(this,function(c,b){if(0>a.indexOf(b))for(b+=1;b<this._splitAssetsArr.length;b++)t.equals(c.geometry,this._splitAssetsArr[b].geometry)&&a.push(b)}));0<a.length&&(a.sort(function(c,b){return c-b}),k.forEach(a,e.hitch(this,function(c,b){this._splitAssetsArr.splice(c-b,1)})))},isLineValid:function(a){return a.paths&&1===a.paths.length&&2===a.paths[0].length&&a.paths[0][0][0]===a.paths[0][1][0]&&
a.paths[0][0][1]===a.paths[0][1][1]?!1:!0},_splitForOverlappingGeometries:function(a,c){var b=[],d=[],f=[],h=!1;k.forEach(this._allIntersectedRegions,e.hitch(this,function(g){t.intersects(a.geometry,g.geometry)&&f.push(g)}));k.forEach(f,e.hitch(this,function(g){t.contains(g.geometry,a.geometry)&&(h=!0)}));if(h)b.push(a);else{var l=a.geometry,n=f.length;k.forEach(f,e.hitch(this,function(g,r){g=this._polygonToPolyline(g.geometry)[0];g=t.cut(l,g);if(1<g.length)for(l=g[0],r=1;r<g.length;r++)1===r&&this.isLineValid(g[r])?
b.push({geometry:g[r],isIntersectedGeometry:!0}):d.push({geometry:g[r],isIntersectedGeometry:!0});else 0<g.length?this.isLineValid(g[0])&&b.push({geometry:g[0],isIntersectedGeometry:!0}):c?this.isLineValid(l)&&b.push({geometry:l,isIntersectedGeometry:!0}):r===n-1&&d.push({geometry:l,isIntersectedGeometry:!0})}))}return{processed:b,unProcessed:d}},_displayPopupForAssets:function(){this.map.getLayer(this.config.projectSettings.costingGeometryLayer);if(0<this._splitAssetsArr.length){var a=this._splitAssetsArr.pop(0);
this._currentAssetSplitGeometry=a.geometry;this._intersectedCostingGraphicArr=[];var c=!1;a.isIntersectedGeometry&&k.forEach(this._allIntersectedRegions,e.hitch(this,function(d){t.contains(d.geometry,a.geometry)&&(this._intersectedCostingGraphicArr.push(d),c=!0)}));if(1<this._intersectedCostingGraphicArr.length){var b=this._intersectedCostingGraphicArr[0];this._intersectedCostingGraphicArr=[];this._intersectedCostingGraphicArr.push(b)}c?(this._isFeatureIntersected=c,this._displayPopupForRegion()):
this._initializeScenarioSelection(this.nls.scenarioSelection.noneText,c,null)}else 0<this._splitAssetInfo.length&&this._createAndAddFeatures(this._splitAssetInfo)},_createAndAddFeatures:function(a){var c=[],b;if(this._selectedTemplate){var d=e.clone(this._selectedTemplate.template.prototype.attributes);if(this._editor.attributeInspector&&this._editor.attributeInspector._currentFeature)for(b in d)k.forEach(this._selectedTemplate.featureLayer.fields,e.hitch(this,function(f){if(f.name===b&&!f.nullable&&
(null===d[b]||void 0===d[b]||""===d[b]))return d[b]=this._editor.attributeInspector._currentFeature.attributes[b],!0}));k.forEach(a,e.hitch(this,function(f,h){c.push(new E(f.ASSETGEOMETRY,null,e.clone(d)));this.selectedProjectFeatureAttr&&this._updateFeatureAttributes(c[h])}));this._selectedTemplate.featureLayer.myApplyEdits(c,null,null)}},_updateFeatureAttributes:function(a){var c,b,d,f;k.some(this.config.layerSettings,e.hitch(this,function(n){n.attributeSetting&&n.id===this._selectedTemplate.featureLayer.id&&
(c=n.attributeSetting)}));if(c){var h=this.map.getLayer(this._selectedTemplate.featureLayer.id);var l=this.map.getLayer(this.config.projectSettings.projectLayer);k.forEach(c,e.hitch(this,function(n){b=h.getField(n.layerField).length;d=l.getField(n.projectField).length;f=this.selectedProjectFeatureAttr[n.projectField];b<d&&f&&0<f.length&&(f=f.slice(0,b));a.attributes[n.layerField]=f}))}},_displayPopupForRegion:function(){var a=this.map.getLayer(this.config.projectSettings.costingGeometryLayer);if(0<
this._intersectedCostingGraphicArr.length){var c=this._intersectedCostingGraphicArr.pop(0);var b=c.attributes[this.config.projectSettings.geographyField];c=c.attributes[a.globalIdField];this._initializeScenarioSelection(b,this._isFeatureIntersected,c)}else this._displayPopupForAssets()},_destroyScenarioSelection:function(){this._scenarioSelectionObj&&this._scenarioSelectionObj.destroy();this._selectScenarioPopup&&this._selectScenarioPopup.destroy()},_initializeScenarioSelection:function(a,c,b){var d;
var f=this._selectedTemplate.featureLayer.id;var h=this._selectedTemplate.template.name;this._destroyScenarioSelection();var l=[];var n=[];k.forEach(this.config.costingInfoSettings[f],e.hitch(this,function(g){if(g.geography===a&&g.featureTemplate===h){if(""===g.scenario||null===g.scenario||void 0===g.scenario)g=e.clone(g),g.scenario=this.nls.scenarioSelection.noneText;l.push(g)}else if(g.featureTemplate===h&&(""===g.geography||null===g.geography||void 0===g.geography)){if(""===g.scenario||null===
g.scenario||void 0===g.scenario)d=g.costEquation,g=e.clone(g),g.scenario=this.nls.scenarioSelection.noneText,g.geography=this.nls.scenarioSelection.noneText;n.push(g)}}));1===l.length?(this._configuredGeographyCostEquation[b]&&this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id]&&this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id][h]?(this.selectedTemplateInfo=this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id][h],
this.selectedTemplateInfo.ASSETGEOMETRY=this._currentAssetSplitGeometry):(this.selectedTemplateInfo={},this.selectedTemplateInfo.TEMPLATENAME=h,this.selectedTemplateInfo.COSTEQUATION=l[0].costEquation,this.selectedTemplateInfo.GEOGRAPHY=a,this.selectedTemplateInfo.SCENARIO=l[0].scenario,this.selectedTemplateInfo.GEOGRAPHYGUID=b,this.selectedTemplateInfo.ASSETGEOMETRY=this._currentAssetSplitGeometry,this._configuredGeographyCostEquation.hasOwnProperty(this.selectedTemplateInfo.GEOGRAPHYGUID)||(this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID]=
{}),this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID].hasOwnProperty(this._selectedTemplate.featureLayer.id)||(this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID][this._selectedTemplate.featureLayer.id]={}),this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID][this._selectedTemplate.featureLayer.id][this.selectedTemplateInfo.TEMPLATENAME]=this.selectedTemplateInfo),this._splitAssetInfo.push(e.clone(this.selectedTemplateInfo)),
this._displayPopupForRegion()):1!==n.length||0!==l.length||c?1<n.length&&0===l.length&&!c?this._configuredGeographyCostEquation[b]&&this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id]&&this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id][h]?(this.selectedTemplateInfo=this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id][h],this.selectedTemplateInfo.ASSETGEOMETRY=this._currentAssetSplitGeometry,this._splitAssetInfo.push(e.clone(this.selectedTemplateInfo)),
this._displayPopupForRegion()):(this._scenarioSelectionObj=new B({regionName:a,scenarioOptions:n,nls:this.nls,templateName:h,geographyGlobalID:b,costingGeometryLayer:this.config.projectSettings.costingGeometryLayer}),this._displaySelectScenarioPopup(a)):0===l.length?(this._configuredGeographyCostEquation[b]&&this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id]&&this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id][h]?(this.selectedTemplateInfo=
this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id][h],this.selectedTemplateInfo.ASSETGEOMETRY=this._currentAssetSplitGeometry):(this.selectedTemplateInfo={},this.selectedTemplateInfo.TEMPLATENAME=h,this.selectedTemplateInfo.COSTEQUATION=d,this.selectedTemplateInfo.GEOGRAPHY=a,this.selectedTemplateInfo.SCENARIO=this.nls.scenarioSelection.noneText,this.selectedTemplateInfo.GEOGRAPHYGUID=b,this.selectedTemplateInfo.ASSETGEOMETRY=this._currentAssetSplitGeometry,this._configuredGeographyCostEquation.hasOwnProperty(this.selectedTemplateInfo.GEOGRAPHYGUID)||
(this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID]={}),this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID].hasOwnProperty(this._selectedTemplate.featureLayer.id)||(this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID][this._selectedTemplate.featureLayer.id]={}),this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID][this._selectedTemplate.featureLayer.id][this.selectedTemplateInfo.TEMPLATENAME]=
this.selectedTemplateInfo),this._splitAssetInfo.push(e.clone(this.selectedTemplateInfo)),this._displayPopupForRegion()):1<l.length&&(this._configuredGeographyCostEquation[b]&&this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id]&&this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id][h]?(this.selectedTemplateInfo=this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id][h],this.selectedTemplateInfo.ASSETGEOMETRY=this._currentAssetSplitGeometry,
this._splitAssetInfo.push(e.clone(this.selectedTemplateInfo)),this._displayPopupForRegion()):(this._scenarioSelectionObj=new B({regionName:a,scenarioOptions:l,nls:this.nls,templateName:h,geographyGlobalID:b,costingGeometryLayer:this.config.projectSettings.costingGeometryLayer}),this._displaySelectScenarioPopup(a))):(this._configuredGeographyCostEquation[b]&&this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id]&&this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id][h]?
(this.selectedTemplateInfo=this._configuredGeographyCostEquation[b][this._selectedTemplate.featureLayer.id][h],this.selectedTemplateInfo.ASSETGEOMETRY=this._currentAssetSplitGeometry):(this.selectedTemplateInfo={},this.selectedTemplateInfo.TEMPLATENAME=h,this.selectedTemplateInfo.COSTEQUATION=n[0].costEquation,this.selectedTemplateInfo.GEOGRAPHY=a,this.selectedTemplateInfo.SCENARIO=this.nls.scenarioSelection.noneText,this.selectedTemplateInfo.GEOGRAPHYGUID=b,this.selectedTemplateInfo.ASSETGEOMETRY=
this._currentAssetSplitGeometry,this._configuredGeographyCostEquation.hasOwnProperty(this.selectedTemplateInfo.GEOGRAPHYGUID)||(this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID]={}),this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID].hasOwnProperty(this._selectedTemplate.featureLayer.id)||(this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID][this._selectedTemplate.featureLayer.id]={}),this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID][this._selectedTemplate.featureLayer.id][this.selectedTemplateInfo.TEMPLATENAME]=
this.selectedTemplateInfo),this._splitAssetInfo.push(e.clone(this.selectedTemplateInfo)),this._displayPopupForRegion())},_displaySelectScenarioPopup:function(){this._selectScenarioPopup=new P({titleLabel:this.nls.scenarioSelection.popupTitle,autoHeight:!0,content:this._scenarioSelectionObj,width:400,buttons:[{label:this.nls.common.ok,key:q.ENTER,onClick:e.hitch(this,"_onScenarioSelectionOk")},{label:this.nls.common.cancel,key:q.ESCAPE,onClick:e.hitch(this,"_onScenarioSelectionCancel")}]});G.set(this._scenarioSelectionObj.scenarioDropDown,
"aria-label",this.nls.scenarioSelection.scenarioLabel);G.set(this._scenarioSelectionObj.regionNameTextBox,"aria-label",this.nls.scenarioSelection.regionLabel);this._scenarioSelectionObj.startup();var a=this._selectScenarioPopup.enabledButtons;this.own(m(a[0],"keydown",e.hitch(this,function(c){if(c.keyCode===q.ENTER||c.keyCode===q.SPACE)x.stop(c),w.focus(this.selectButton)})));this.own(m(a[1],"keydown",e.hitch(this,function(c){if(c.keyCode===q.ENTER||c.keyCode===q.SPACE)x.stop(c),w.focus(this.selectButton)})))},
_onScenarioSelectionOk:function(){this.selectedTemplateInfo={};var a=this._scenarioSelectionObj.scenarioDropDown._getSelectedOptionsAttr();this.selectedTemplateInfo.TEMPLATENAME=a.item.featureTemplate;this.selectedTemplateInfo.COSTEQUATION=a.item.costEquation;this.selectedTemplateInfo.GEOGRAPHY=this._scenarioSelectionObj.regionNameTextBox.getValue();this.selectedTemplateInfo.SCENARIO=a.label;this.selectedTemplateInfo.GEOGRAPHYGUID=a.item.geographyGlobalID;this.selectedTemplateInfo.ASSETGEOMETRY=this._currentAssetSplitGeometry;
this._configuredGeographyCostEquation.hasOwnProperty(this.selectedTemplateInfo.GEOGRAPHYGUID)||(this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID]={});this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID].hasOwnProperty(this._selectedTemplate.featureLayer.id)||(this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID][this._selectedTemplate.featureLayer.id]={});this._configuredGeographyCostEquation[this.selectedTemplateInfo.GEOGRAPHYGUID][this._selectedTemplate.featureLayer.id][this.selectedTemplateInfo.TEMPLATENAME]=
this.selectedTemplateInfo;this._selectScenarioPopup.close();this._splitAssetInfo.push(e.clone(this.selectedTemplateInfo));this._displayPopupForRegion()},_onScenarioSelectionCancel:function(){this._selectScenarioPopup.close()},resize:function(){if(this.domNode){var a=O.getMarginBox(this.domNode);a=a.w;0<a&&this._editor&&this._editor.templatePicker&&this._editor.templatePicker.update(!0)}},_getSelectedFeatures:function(a){var c=[];k.forEach(a,e.hitch(this,function(b){(b=b.getSelectedFeatures())&&0<
b.length&&k.forEach(b,e.hitch(this,function(d){c.push(d)}))}));return c},_createCustomSelectTool:function(){var a;this.customToolbar=new F(this.map,{tooltipOffset:10,drawTime:90});this._toolBarActive=!1;this.own(m(this.customToolbar,"draw-complete",e.hitch(this,function(c){var b=new D;b.geometry=c.geometry;var d=this._getOtherLayersFromMap();this._editor._selectionHelper.selectFeatures(d,b,S.SELECTION_NEW,e.hitch(this,function(){var f=this._getSelectedFeatures(d);0<f.length?(this.customToolbar.deactivate(),
this._toolBarActive=!1,this._copyFeaturesObj||this._createCopyFeaturesInstance(),this._copyFeaturesObj.selectFeaturesToCopy(f)):a=this.appUtils.showMessage(this.nls.copyFeatures.noFeaturesSelectedMessage)}));a&&a.enabledButtons&&this.own(m(a.enabledButtons[0],"keydown",e.hitch(this,function(f){if(f.keyCode===q.ENTER||f.keyCode===q.SPACE)x.stop(f),w.focus(this.selectButton)})))})))},_createCopyFeaturesInstance:function(){this._copyFeaturesObj=new T({nls:this.nls,layerInfosObj:this.layerInfosObj,mainNode:this.selectFeaturesNode,
appUtils:this.appUtils,map:this.map,widgetId:this.widgetId,widgetDomNode:this.widgetDomNode},A.create("div",{},this.selectFeaturesNode));this.own(m(this._copyFeaturesObj,"createSingleFeature",e.hitch(this,function(a){if(a=this._createSingleGeometry(a))this._featuresToBeCopied=[a],this._displayCopyAssetsPopup()})));this.own(m(this._copyFeaturesObj,"createMultipleFeatures",e.hitch(this,function(a){a&&0<a.length&&(this._featuresToBeCopied=a,this._displayCopyAssetsPopup())})));this.own(m(this._copyFeaturesObj,
"cancelBtnClicked",e.hitch(this,function(){var a=this.refreshButton,c=this.featureModeTextNode;this._activateCustomSelectTool();"none"===this.downloadCSVBtn.style.display||p.contains(this.downloadCSVBtn,"esriCTHidden")||(a=this.downloadCSVBtn);p.contains(this.projectNameDiv,"esriCTHidden")||(c=this.projectNameDiv);this.appUtils.setFirstAndLastWBFocusNode(this.widgetDomNode,c,a);w.focus(this.projectNameDiv)})));this._copyFeaturesObj.startup()},_createSingleGeometry:function(a){var c;var b=a[0]._layer.geometryType;
"esriGeometryPolyline"===b?c=this._createSinglePolyline(a):"esriGeometryPolygon"===b&&(c=this._createSinglePolygon(a));return c},_createSinglePolyline:function(a){var c=new y(new v(a[0].geometry.spatialReference));k.forEach(a,e.hitch(this,function(b){b.geometry&&b.geometry.paths&&k.forEach(b.geometry.paths,function(d){c.addPath(d)})}));return c},_createSinglePolygon:function(a){var c=new C(new v(a[0].geometry.spatialReference));k.forEach(a,e.hitch(this,function(b){b.geometry&&b.geometry.rings&&k.forEach(b.geometry.rings,
function(d){c.addRing(d)})}));return c},_toggleToolState:function(){p.contains(this.selectButton,"esriCTSelectDisable")?this._activateTemplatePickerTool():this._toolBarActive?this._activateTemplatePickerTool():this._activateCustomSelectTool()},_activateCustomSelectTool:function(){var a=this._editor.templatePicker.getSelected();this._editor._drawToolbar.deactivate();a?this.customToolbar.activate(F.EXTENT):this.customToolbar.deactivate()},_activateTemplatePickerTool:function(){var a=this._editor.templatePicker.getSelected();
this.customToolbar.deactivate();a&&this._editor._activateDrawToolbar(this._selectedTemplate)},_activateSketchButton:function(){p.add(this.sketchButton,"esriCTSketchEnable");p.remove(this.sketchButton,"esriCTSketchDisable")},_deActivateSketchButton:function(){p.add(this.sketchButton,"esriCTSketchDisable");p.remove(this.sketchButton,"esriCTSketchEnable")},_activateSelectButton:function(){p.add(this.selectButton,"esriCTSelectEnable");p.remove(this.selectButton,"esriCTSelectDisable")},_deActivateSelectButton:function(){p.add(this.selectButton,
"esriCTSelectDisable");p.remove(this.selectButton,"esriCTSelectEnable")},_deactivateAllTools:function(){this.customToolbar.deactivate();this._editor&&this._editor._drawToolbar&&this._editor._drawToolbar.deactivate()},_getOtherLayersFromMap:function(){var a=[];var c=this.layerInfosObj.getLayerInfoArray();k.forEach(c,e.hitch(this,function(b){var d=this.map.getLayer(b.id);if("Feature Layer"===d.type){var f=!1;k.forEach(this._editor._settings.layers,e.hitch(this,function(h){h.id===d.id&&(f=!0)}));f&&
-1<this._nonEditableLayers.indexOf(d.id)&&(f=!1);f||this._selectedTemplate.featureLayer.geometryType===d.geometryType&&d.id!==this.config.projectSettings.costingGeometryLayer&&d.id!==this.config.projectSettings.projectLayer&&a.push(d)}}));return a}})});