/*
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","../../../core/screenUtils","../../../core/time","../InputHandler","./support"],(function(t,e,i,n,r,s){"use strict";let a=function(t){function i(i){var n;return(n=t.call(this,!1)||this).navigationTouch=i,n.startStateModifiers=new Set,n.activePointerMap=new Map,n.isDragging=!1,n.isCurrentDragSuppressed=!1,n.drag=n.registerOutgoing("drag"),n.registerIncoming("pointer-drag",n._handlePointerDrag.bind(e._assertThisInitialized(n))),n.registerIncoming("pointer-up",n._handlePointerUpAndPointerLost.bind(e._assertThisInitialized(n))),n.registerIncoming("pointer-capture-lost",n._handlePointerUpAndPointerLost.bind(e._assertThisInitialized(n))),n.registerIncoming("pointer-cancel",n._handlePointerUpAndPointerLost.bind(e._assertThisInitialized(n))),n}e._inheritsLoose(i,t);var r=i.prototype;return r._createPayload=function(t,e,i,n){return{action:t,pointerType:this.pointerType,button:this.mouseButton,buttons:e.buttons,timestamp:n,pointers:c(this.activePointerMap),pointer:e,angle:i.angle,radius:i.radius,center:i.center}},r._addPointer=function(t){const e=t.native.pointerId,i=d(this.activePointerMap).angle,n={event:t,initialAngle:0,lastAngle:0};this.activePointerMap.set(e,n);const r=u(n,o(this.activePointerMap));n.initialAngle=r,n.lastAngle=r,this._updatePointerAngles(i)},r._updatePointer=function(t){if(t&&null==t.x&&null==t.y)return;const e=t.native.pointerId,i=this.activePointerMap.get(e);i?i.event=t:this._addPointer(t)},r._removePointer=function(t){const e=d(this.activePointerMap).angle;this.activePointerMap.delete(t),this._updatePointerAngles(e)},r._updatePointerAngles=function(t){const e=d(this.activePointerMap);this.activePointerMap.forEach((i=>{i.initialAngle=u(i,e)-t,i.lastAngle=u(i,e)-t}))},r._emitEvent=function(t,e,i){const n=d(this.activePointerMap);this.drag.emit(this._createPayload(t,e,n,i),void 0,this.startStateModifiers)},r._handlePointerUpAndPointerLost=function(t){const e=t.data.native.pointerId,i=n.Milliseconds(t.timestamp);this.activePointerMap.get(e)&&(1===this.activePointerMap.size?(this._updatePointer(t.data),!this.isCurrentDragSuppressed&&this._emitEvent("end",t.data,i),this.isDragging=!1,this.isCurrentDragSuppressed=!1,this._removePointer(e)):(this._removePointer(e),this._emitEvent("removed",t.data,n.Milliseconds(t.timestamp))))},r._handlePointerDrag=function(t){const e=t.data,i=e.currentEvent,r=n.Milliseconds(t.timestamp);switch(e.action){case"start":case"update":this.isDragging?this.activePointerMap.has(i.native.pointerId)?(this._updatePointer(i),!this.isCurrentDragSuppressed&&this._emitEvent("update",i,r)):(this._addPointer(i),this._emitEvent("added",i,r),this.isCurrentDragSuppressed=this.isSuppressed):(this._updatePointer(i),this.pointerType=t.data.startEvent.pointerType,this.mouseButton=t.data.startEvent.button,this.startStateModifiers=t.modifiers,this.isDragging=!0,this.isCurrentDragSuppressed=this.isSuppressed,!this.isCurrentDragSuppressed&&this._emitEvent("start",i,r))}},e._createClass(i,[{key:"isSuppressed",get:function(){return this.navigationTouch&&!this.navigationTouch.browserTouchPanEnabled&&"touch"===this.pointerType&&1===this.activePointerMap.size}}]),i}(r.InputHandler);function o(t){const e=[];return t.forEach((t=>{e.push(i.createScreenPoint(t.event.x,t.event.y))})),s.fitCircleLSQ(e)}function d(t){const e=o(t);let i=0;return t.forEach((t=>{let n=u(t,e),r=n-t.lastAngle;for(;r>Math.PI;)r-=2*Math.PI;for(;r<-Math.PI;)r+=2*Math.PI;n=t.lastAngle+r,t.lastAngle=n;const s=n-t.initialAngle;i+=s})),i/=t.size||1,{angle:i,radius:e.radius,center:e.center}}function c(t){const e=new Map;return t.forEach(((t,i)=>e.set(i,t.event))),e}function u(t,e){const i=t.event,n=i.x-e.center.x,r=i.y-e.center.y;return Math.atan2(r,n)}var p;t.Button=void 0,(p=t.Button||(t.Button={}))[p.Left=0]="Left",p[p.Middle=1]="Middle",p[p.Right=2]="Right",p[p.Back=3]="Back",p[p.Forward=4]="Forward",p[p.Undefined=-1]="Undefined",t.Drag=a,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
