/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../geometry","../../core/maybe","../../core/Logger","../../core/accessorSupport/ensureType","../../core/arrayUtils","../../core/has","../../core/accessorSupport/set","../../core/accessorSupport/decorators/subclass","./DrawAction","./DrawTool","./input/DrawEvents","../input/InputManager","../interactive/keybindings","../support/screenUtils","../../geometry/Point"],(function(e,t,i,o,r,n,s,a,h,d,p,c,l,_,u,v,w,m){"use strict";e.PointDrawAction=function(e){function i(t){var i;return(i=e.call(this,t)||this)._addVertexOnPointerUp=!1,i}t._inheritsLoose(i,e);var o=i.prototype;return o.initialize=function(){"2d"===this.view.type?this._addViewHandles():this._addDrawTool()},o.destroy=function(){"2d"===this.view.type?this._removeViewHandles():this._removeDrawTool(),this.emit("destroy")},o.complete=function(){"2d"===this.view.type?this._cursorScreenPoint&&this._completeDrawing():this._drawTool.completeCreateOperation()},o._addViewHandles=function(){this._removeViewHandles(),this._handles.add([this.view.on("pointer-down",(e=>{this._shouldHandlePointerEvent(e)&&(this._abortSnapping(),this._activePointerId=e.pointerId,this._addVertexOnPointerUp=!0,this._cursorScreenPoint=w.createScreenPointFromEvent(e),"touch"===e.pointerType&&this._updateCursor(e.native))}),u.ViewEventPriorities.TOOL),this.view.on("pointer-move",(e=>{this._abortSnapping(),this._cursorScreenPoint=w.createScreenPointFromEvent(e),"touch"!==e.pointerType&&this._updateCursor(e.native)}),u.ViewEventPriorities.TOOL),this.view.on("pointer-drag",(e=>{this._shouldHandlePointerEvent(e)&&(this._abortSnapping(),this._addVertexOnPointerUp=!1)}),u.ViewEventPriorities.TOOL),this.view.on("pointer-up",(e=>{if(this._shouldHandlePointerEvent(e))if(this._abortSnapping(),this._activePointerId=null,this._addVertexOnPointerUp)e.stopPropagation(),this._vertexAddHandler(e);else{const t="touch"===e.pointerType;this._updateCursor(e.native,t)}}),u.ViewEventPriorities.TOOL),this.view.on("drag",["Shift"],(e=>{e.stopPropagation()}),u.ViewEventPriorities.TOOL),this.view.on("key-down",(e=>{e.key===v.SKETCH_KEYS.complete&&this._cursorScreenPoint&&(this._abortSnapping(),this._vertexAddHandler(e))}),u.ViewEventPriorities.TOOL)],this._viewHandlesKey)},o._removeViewHandles=function(){this._handles.remove(this._viewHandlesKey)},o._addDrawTool=function(){this._drawTool=new l.DrawTool({view:this.view,elevationInfo:this.elevationInfo,hasZ:this.hasZ,geometryType:"point",mode:"click"}),this.view.addAndActivateTool(this._drawTool),this._handles.add([this._drawTool.on("cursor-update",(e=>{1===e.vertices.length&&this.emit("cursor-update",new _.CursorUpdateEvent(this.view,null,e.vertices[0].vertexIndex,this._drawTool.getVertexCoords()))})),this._drawTool.on("complete",(e=>{this.emit("draw-complete",new _.DrawCompleteEvent(null,this._drawTool.getVertexCoords())),this._removeDrawTool()}))],this._drawToolHandlesKey)},o._removeDrawTool=function(){this._handles.remove(this._drawToolHandlesKey),this.view.tools.remove(this._drawTool),this._drawTool=r.destroyMaybe(this._drawTool)},o._addVertex=function(e){const t=this._coordinateHelper.arrayToVector(e);this._isDuplicateOfLastVertex(t)||(this._lastVertexUnsnapped=this._stagedVertexUnsnapped,this._popCursorVertex(),this._editGeometryOperations.appendVertex(t),this.notifyChange("vertices"),this._completeDrawing())},o._updateCursor=function(e,t=!1){if(this._popCursorVertex(),!this._cursorScreenPoint)return;const i=this.getCoordsAndPointFromScreenPoint(this._cursorScreenPoint);r.isSome(i)&&!t&&this._pushCursorVertex(i.vertex,(()=>this.emit("cursor-update",new _.CursorUpdateEvent(this.view,e,this._activeComponent.vertices.length,this.vertices,r.isSome(this._stagedVertex)?new m(this._stagedVertex):null))))},o._completeDrawing=function(e){this._activePointerId=null,this._popCursorVertex(),this._abortSnapping(),r.isSome(this._snappingManager)&&this._snappingManager.doneSnapping();const t=new _.DrawCompleteEvent(e,this.vertices);this.emit("draw-complete",t),t.defaultPrevented||this._removeViewHandles()},i}(c),e.PointDrawAction=i.__decorate([p.subclass("esri.views.draw.PointDrawAction")],e.PointDrawAction),Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
