/*
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/Handles","../../../../core/reactiveUtils","../../../../core/scheduling","../../viewpointUtils","../../../input/InputHandler","../../../navigation/gamepadAndKeyboardUtils"],(function(t,e,a,i,n,s,r,o){"use strict";let l=function(t){function r(e){var i;return(i=t.call(this,!0)||this).view=e,i.frameTask=null,i.watchHandles=new a,i.currentDevice=null,i.transformation={translation:[0,0,0],heading:0,tilt:0,zoom:0},i.handle=i.registerIncoming("gamepad",(t=>i._handleGamePadEvent(t))),i.handle.pause(),i}e._inheritsLoose(r,t);var l=r.prototype;return l.onInstall=function(e){t.prototype.onInstall.call(this,e),this.watchHandles.add([i.watch((()=>{var t;return null==(t=this.view.navigation.gamepad)?void 0:t.enabled}),(t=>{t?(this.handle.resume(),this.frameTask||(this.frameTask=n.addFrameTask({update:t=>this._frameUpdate(t.deltaTime)}))):(this.handle.pause(),this.frameTask&&(this.frameTask.remove(),this.frameTask=null))}),i.initial)])},l.onUninstall=function(){this.watchHandles.removeAll(),this.frameTask&&(this.frameTask.remove(),this.frameTask=null),t.prototype.onUninstall.call(this)},l._handleGamePadEvent=function(t){const e=this.view.navigation.gamepad.device;e&&t.data.device!==e||this.currentDevice&&this.currentDevice!==t.data.device||("end"===t.data.action?(this.currentDevice=null,o.resetTransformation(this.transformation)):(this.currentDevice=t.data.device,o.extractTransformation(t.data,this.view.navigation.gamepad,this.transformation)))},l._frameUpdate=function(t){const e=this.transformation;if(o.isZeroTransformation(e))return;const a=this.view.viewpoint.clone(),i=this.view.navigation.gamepad.velocityFactor,n=d*i*t;s.translateBy(a,a,[e.translation[0]*n,-e.translation[1]*n]);const r=1+e.translation[2]*h*t,l=this.view.constraints.rotationEnabled?-e.heading*c*t:0,v=this.view.size,u=[v[0]/2,v[1]];s.scaleAndRotateBy(a,a,r,l,u,v);const m=this.view.constraints.constrain(a,this.view.viewpoint);this.view.viewpoint=m},r}(r.InputHandler);const c=.06,d=.7,h=6e-4;t.GamepadNavigation=l,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
