/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{clock as t}from"../../../core/clock.js";import{InputHandler as e}from"../InputHandler.js";import{getDoubleClickParameters as i,getPointerId as a,manhattanDistance as o}from"./support.js";class s extends e{constructor(e={},a=t){super(!1),this._clock=a,this._pointerState=new Map,this._parameters=i(e),this._immediateDoubleClick=this.registerOutgoing("immediate-double-click"),this.registerIncoming("pointer-down",this._handlePointerDown.bind(this)),this.registerIncoming("pointer-up",this._handlePointerUp.bind(this))}onUninstall(){this._pointerState.forEach(t=>{t.immediateDoubleClick&&t.immediateDoubleClick.timeoutHandle.remove()}),super.onUninstall()}_handlePointerDown(t){const e=t.data,i=a(e);if(!this._pointerState.has(i)){const t={downButton:e.native.button,x:e.x,y:e.y,immediateDoubleClick:null};this._pointerState.set(i,t),this.startCapturingPointer(e.native)}}_handlePointerUp(t){const e=t.data,i=a(e),s=this._pointerState.get(i);if(s&&s.downButton===e.native.button){const i=s.immediateDoubleClick,a="touch"===t.data.native.pointerType?this._parameters.maximumDoubleTouchDistance:this._parameters.maximumDoubleClickDistance;i?(i.timeoutHandle.remove(),o(i,t.data)>a?this._startImmediateDoubleClick(t,s):(this._immediateDoubleClick.emit(t.data,void 0,i.modifiers),this._removeState(e))):o(s,t.data)>a?this._removeState(e):this._startImmediateDoubleClick(t,s)}}_startImmediateDoubleClick(t,e){const i="touch"===t.data.native.pointerType?this._parameters.maximumDoubleTouchDelay:this._parameters.maximumDoubleClickDelay;e.immediateDoubleClick={x:t.data.x,y:t.data.y,modifiers:t.modifiers,timeoutHandle:this._clock.setTimeout(()=>this._removeState(t.data),i)}}_removeState(t){const e=a(t);this._pointerState.delete(e),this.stopCapturingPointer(t.native),this.refreshHasPendingInputs()}}export{s as ImmediateDoubleClick};
