// 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/copy-features.html":'\x3cdiv class\x3d"esriCTSelectFeaturesContainer"\x3e\r\n  \x3cdiv style\x3d"height: 100%; width: 100%;"\x3e\r\n    \x3cdiv class\x3d"esriCTCopyFeaturesListTitle"\x3e${nls.copyFeatures.title}\x3c/div\x3e\r\n    \x3cdiv class\x3d"esriCTCopyFeaturesListContent" data-dojo-attach-point\x3d"layerListTable"\x3e\x3c/div\x3e\r\n    \x3cdiv class\x3d"esriCTCopyFeaturesBtnContainer"\x3e\r\n      \x3cdiv class\x3d"esriCTCopyFeaturesBtn jimu-btn" data-dojo-attach-point\x3d"createMultipleFeaturesBtn" title\x3d"${nls.copyFeatures.createFeatures}" tabindex\x3d"0" aria-label\x3d"${nls.copyFeatures.createFeatures}" role\x3d"button"\x3e${nls.copyFeatures.createFeatures}\x3c/div\x3e\r\n      \x3cdiv class\x3d"esriCTCopyFeaturesBtn jimu-btn" data-dojo-attach-point\x3d"createSingleFeatureBtn" title\x3d"${nls.copyFeatures.createSingleFeature}" tabindex\x3d"0" aria-label\x3d"${nls.copyFeatures.createSingleFeature}" role\x3d"button"\x3e${nls.copyFeatures.createSingleFeature}\x3c/div\x3e\r\n      \x3cdiv class\x3d"esriCTCopyFeaturesBtn jimu-btn" data-dojo-attach-point\x3d"cancelBtn" title\x3d"${nls.common.cancel}" tabindex\x3d"0" aria-label\x3d"${nls.common.cancel}" role\x3d"button"\x3e${nls.common.cancel}\x3c/div\x3e\r\n    \x3c/div\x3e\r\n  \x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dijit/_WidgetBase dijit/_TemplatedMixin dojo/_base/declare dojo/Evented dojo/_base/lang dojo/_base/array dojo/dom-construct dojo/on jimu/dijit/CheckBox dojo/dom-class dojo/dom-attr ./highlightSymbolUtils esri/layers/GraphicsLayer dojo/text!./copy-features.html jimu/utils dijit/focus dojo/keys dojo/query dojo/_base/event esri/tasks/query esri/tasks/QueryTask dojo/Deferred dojo/promise/all".split(" "),function(u,v,w,x,e,h,p,k,y,n,m,z,A,B,r,C,l,t,q,D,E,F,G){return w([u,x,v],{templateString:B,
layerLabel:null,featuresList:null,checkBoxNodes:{},layerCheckBoxNodes:{},featuresByLayerId:{},featureTitlesByLayerId:{},_highlightGraphicsLayer:null,startup:function(){this.inherited(arguments);this._highlightGraphicsLayer=this._createNewGraphicsLayer("highlightGraphicsLayer");this.toggleWorkBenchDOMTabindexes("-1")},postCreate:function(){this.checkBoxNodes={};this.layerCheckBoxNodes={};this.featuresByLayerId={};this.featureTitlesByLayerId={};this._highlightGraphicsLayer=null;this.own(k(this.cancelBtn,
"click",e.hitch(this,function(){this.cancelBtnClicked();this.toggleWorkBenchDOMTabindexes("0");this.emit("cancelBtnClicked")})));this.own(k(this.cancelBtn,"keydown",e.hitch(this,function(a){if(a.keyCode===l.ENTER||a.keyCode===l.SPACE)q.stop(a),this.cancelBtnClicked(),this.toggleWorkBenchDOMTabindexes("0"),this.emit("cancelBtnClicked")})));this.own(k(this.createMultipleFeaturesBtn,"click",e.hitch(this,this._createMultipleFeaturesBtnClicked)));this.own(k(this.createMultipleFeaturesBtn,"keydown",e.hitch(this,
function(a){if(a.keyCode===l.ENTER||a.keyCode===l.SPACE)q.stop(a),this._createMultipleFeaturesBtnClicked()})));this.own(k(this.createSingleFeatureBtn,"click",e.hitch(this,this._createSingleFeatureBtnClicked)));this.own(k(this.createSingleFeatureBtn,"keydown",e.hitch(this,function(a){if(a.keyCode===l.ENTER||a.keyCode===l.SPACE)q.stop(a),this._createSingleFeatureBtnClicked()})))},toggleWorkBenchDOMTabindexes:function(a){t(".esriCTWorkBenchDOM",this.widgetDomNode).forEach(e.hitch(this,function(c){m.set(c,
"tabindex",a)}))},selectFeaturesToCopy:function(a){if(a&&0<a.length){this.checkBoxNodes={};this.layerCheckBoxNodes={};this.featuresByLayerId={};this.featureTitlesByLayerId={};this._showHideSingleFeatureButton(a[0]._layer.geometryType);n.remove(this.mainNode,"esriCTHidden");var c=new F;this._processSelectedFeatures(a,c).then(e.hitch(this,function(){p.empty(this.layerListTable);for(var b in this.featureTitlesByLayerId){var d=this.layerInfosObj.getLayerInfoById(b);d=d.title?d.title:d.name;var g=p.create("div",
{},this.layerListTable);this.layerCheckBoxNodes[b]=this._createListNode(d,g,!1,b);this.checkBoxNodes[b]||(this.checkBoxNodes[b]=[]);0<this.featureTitlesByLayerId[b].length&&this._createFeatureEntries(b,g)}this._highlightFeatures()}))}this._setFirstAndLastFocusNodes()},_processSelectedFeatures:function(a,c){var b={},d,g;this.featuresByLayerId={};this.featureTitlesByLayerId={};h.forEach(a,e.hitch(this,function(f){this.featuresByLayerId[f._layer.id]||(this.featuresByLayerId[f._layer.id]=[],this.featureTitlesByLayerId[f._layer.id]=
[]);this.featuresByLayerId[f._layer.id].push(f);this.featureTitlesByLayerId[f._layer.id].push(f.getTitle())}));for(g in this.featuresByLayerId)g&&(a=this._getObjectIdFieldOfLayer(g),a=this._getSelectedFeatureObjectIds(this.featuresByLayerId[g],a),b[g]=this._getSelectedFeatureGeometry(g,a));G(b).then(e.hitch(this,function(f){for(d in f)d&&this._updateGeometryForSelectedFeature(d,f)}),e.hitch(this,function(){this.appUtils.showMessage(this.nls.copyFeatures.copyFeatureUpdateGeometryError)}));return c.resolve(null)},
_getObjectIdFieldOfLayer:function(a){return this.layerInfosObj.getLayerInfoById(a).layerObject.objectIdField},_updateGeometryForSelectedFeature:function(a,c){var b=this._getObjectIdFieldOfLayer(a);h.forEach(this.featuresByLayerId[a],e.hitch(this,function(d){h.forEach(c[a].features,e.hitch(this,function(g){g.attributes[b]===d.attributes[b]&&(d.geometry=g.geometry)}))}))},_getSelectedFeatureObjectIds:function(a,c){var b=[];h.forEach(a,e.hitch(this,function(d){b.push(d.attributes[c])}));return b},_getSelectedFeatureGeometry:function(a,
c){var b=this.layerInfosObj.getLayerInfoById(a);a=new E(b.getUrl());var d=new D;d.outFields=[b.layerObject.objectIdField];d.objectIds=c;d.returnGeometry=!0;d.outSpatialReference=this.map.spatialReference;return a.execute(d).promise},_createFeatureEntries:function(a,c){h.forEach(this.featureTitlesByLayerId[a],e.hitch(this,function(b){b=this._createListNode(b,c,!0,a);this.checkBoxNodes[a].push(b)}))},_createListNode:function(a,c,b,d){c=p.create("div",{"class":"jimu-widget-row esriCTCopyFeaturesNode"},
c);var g=p.create("div",{"class":"jimu-float-leading checkBoxNode"},c);a=new y({label:a,checked:!0},g);b?(n.add(c,"esriCTCopyFeaturesChildNode"),m.set(a.domNode,"parentLayerId",d),k(a.domNode,"click",e.hitch(this,this._childNodeStateChanged)),k(a.domNode,"keydown",e.hitch(this,function(f){f.keyCode!==l.ENTER&&f.keyCode!==l.SPACE||this._childNodeStateChanged(f)}))):(m.set(a.domNode,"layerId",d),k(a.domNode,"click",e.hitch(this,this._parentNodeStateChanged)),k(a.domNode,"keydown",e.hitch(this,function(f){f.keyCode!==
l.ENTER&&f.keyCode!==l.SPACE||this._parentNodeStateChanged(f)})));return a},_parentNodeStateChanged:function(a){a=m.get(a.currentTarget,"layerId");var c=this.checkBoxNodes[a],b=this.layerCheckBoxNodes[a].getValue();h.forEach(c,e.hitch(this,function(d){b?d.setValue(!0):d.setValue(!1)}));this._highlightFeatures()},_childNodeStateChanged:function(a){var c=m.get(a.currentTarget,"parentLayerId");a=this.layerCheckBoxNodes[c];c=this.checkBoxNodes[c];var b=!0;this._highlightFeatures();h.some(c,e.hitch(this,
function(d){if(!d.getValue())return b=!1,!0}));a.setValue(b)},cancelBtnClicked:function(){n.add(this.mainNode,"esriCTHidden");this._highlightGraphicsLayer.clear()},_createMultipleFeaturesBtnClicked:function(){var a=[],c;(c=this._getSelectedFeaturesForCopy())&&0<c.length&&(h.forEach(c,e.hitch(this,function(b){b&&b.geometry&&a.push(b.geometry)})),this.emit("createMultipleFeatures",a))},_createSingleFeatureBtnClicked:function(){var a;(a=this._getSelectedFeaturesForCopy())&&0<a.length&&this.emit("createSingleFeature",
a)},_validateSelectedFeature:function(a){(!a||0>=a.length)&&this.appUtils.showMessage(this.nls.copyFeatures.selectFeatureToCopyMessage)},_getSelectedFeaturesForCopy:function(){var a,c=[];for(a in this.featuresByLayerId){var b=this._getSelectedFeaturesByLayerId(a);0<b.length&&(c=c.concat(b))}this._validateSelectedFeature(c);return c},_getSelectedFeaturesByLayerId:function(a){var c=[];h.forEach(this.checkBoxNodes[a],e.hitch(this,function(b,d){b.getValue()&&c.push(this.featuresByLayerId[a][d])}));return c},
_showHideSingleFeatureButton:function(a){"esriGeometryPoint"===a?(n.add(this.createSingleFeatureBtn,"esriCTHidden"),m.set(this.createSingleFeatureBtn,"tabindex","-1")):(n.remove(this.createSingleFeatureBtn,"esriCTHidden"),m.set(this.createSingleFeatureBtn,"tabindex","0"))},_createNewGraphicsLayer:function(a){var c={};if(a+=this.widgetId)this.map._layers[a]&&this.map.removeLayer(this.map._layers[a]),c={id:a};a=new A(c);this.map.addLayer(a);return a},_highlightFeatures:function(){this._highlightGraphicsLayer.clear();
for(var a in this.featureTitlesByLayerId)this._highlightSingleLayerFeatures(a)},_highlightSingleLayerFeatures:function(a){var c=this.map.getLayer(a);a=this._getSelectedFeaturesByLayerId(a);h.forEach(a,e.hitch(this,function(b){b=z.getHighLightSymbol(b,c);this._highlightGraphicsLayer.add(b)}))},_setFirstAndLastFocusNodes:function(){var a=t(".jimu-checkbox",this.domNode);a.length&&(C.focus(a[0]),r.initFirstFocusNode(this.widgetDomNode,a[0]));r.initLastFocusNode(this.widgetDomNode,this.cancelBtn)}})});