// 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/editing/tools/Cut","dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/_base/connect dojo/has dojo/DeferredList ../../../graphicsUtils ../../../graphic ../../../tasks/query ../../../layers/FeatureLayer ../../../toolbars/draw ../Cut ./ToggleToolBase ../../../kernel".split(" "),function(g,e,b,f,n,p,q,l,r,t,u,v,w,x){g=g([w],{declaredClass:"esri.dijit.editing.tools.Cut",id:"btnFeatureCut",_enabledIcon:"toolbarIcon cutIcon",_disabledIcon:"toolbarIcon cutIcon",_drawType:u.POLYLINE,
_enabled:!0,_label:"NLS_cutLbl",_cutConnects:[],activate:function(){this._cutConnects.push(f.connect(this._toolbar,"onDrawEnd",this,"_onDrawEnd"));this.inherited(arguments)},deactivate:function(){this.inherited(arguments);b.forEach(this._cutConnects,f.disconnect);this._cutConnects=[];this._edits=[]},_onDrawEnd:function(h){var d=this._cutLayers=b.filter(this._settings.layers,function(a){return"esriGeometryPolygon"===a.geometryType||"esriGeometryPolyline"===a.geometryType&&a.visible&&a._isMapAtVisibleScale()});
this._cutConnects=this._cutConnects.concat(b.map(d,e.hitch(this,function(a){return f.connect(a,"onEditsComplete",e.hitch(this,function(a,c,d){if(this._settings.undoRedoManager){var h=this._settings.undoRedoManager;b.forEach(this._edits,e.hitch(this,function(a){h.add(new v({featureLayer:a.layer,addedGraphics:a.adds,preUpdatedGraphics:a.preUpdates,postUpdatedGraphics:a.updates}))}),this)}this.onFinished()}))})));var c=new r;c.geometry=h;b.forEach(d,function(a,d){this._settings.editor._selectionHelper.selectFeatures([a],
c,t.SELECTION_NEW,e.hitch(this,"_cutFeatures",a,c))},this)},_cutFeatures:function(b,d,c){if(c&&c.length){this._edits=[];var a=[];a.push(this._settings.geometryService.cut(q.getGeometries(c),d.geometry,e.hitch(this,"_cutHandler",b,c)));(new p(a)).addCallback(e.hitch(this,function(){this.onApplyEdits(this._edits)}))}},_cutHandler:function(h,d,c){var a=[],g=[],f=b.map(d,function(a){return new l(e.clone(a.toJson()))}),m,k;b.forEach(c.cutIndexes,function(b,f){m!=b?(m=b,g.push(d[b].setGeometry(c.geometries[f]))):
(k=new l(c.geometries[f],null,e.mixin({},d[b].attributes),null),k.attributes[d[0].getLayer().objectIdField]=null,a.push(k))},this);this._edits.push({layer:h,adds:a,updates:g,preUpdates:f})}});n("extend-esri")&&e.setObject("dijit.editing.tools.Cut",g,x);return g});