/*
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","../../state/controllers/GamepadKeyboardController","../../../input/InputHandler"],(function(e,a,t,n,l,r){"use strict";let i=function(e){function r(a){var n;return(n=e.call(this,!0)||this).view=a,n.watchHandles=new t,n.handle=n.registerIncoming("gamepad",(e=>n._handleEventGamepad(e))),n.handle.pause(),n}a._inheritsLoose(r,e);var i=r.prototype;return i.onInstall=function(a){e.prototype.onInstall.call(this,a),this.watchHandles.add([n.watch((()=>this.view.navigation.gamepad.enabled),(e=>{e?this.handle.resume():(this.handle.pause(),this.cameraControllerGamepad&&(this.cameraControllerGamepad.finishController(),this.cameraControllerGamepad=null))}),n.initial),n.watch((()=>this.view.navigation.gamepad.device),(e=>{this.cameraControllerGamepad&&e&&this.cameraControllerGamepad.gamepadDevice!==e&&(this.cameraControllerGamepad.finishController(),this.cameraControllerGamepad=null)}))])},i.onUninstall=function(){this.watchHandles.removeAll(),e.prototype.onUninstall.call(this)},i._handleEventGamepad=function(e){const a=this.view.navigation.gamepad.device;if(a&&e.data.device!==a)return;const t=this.cameraControllerGamepad&&this.cameraControllerGamepad.active;if(t||l.GamepadKeyboardController.activatesFor(this.view,e.data)){if(!t){const a=new l.GamepadKeyboardController({view:this.view,gamepadDevice:e.data.device});this.view.state.switchCameraController(a)&&(this.cameraControllerGamepad=a)}this.cameraControllerGamepad&&this.cameraControllerGamepad.active&&this.cameraControllerGamepad.gamepadDevice===e.data.device&&this.cameraControllerGamepad.handleEventGamepad(e.data)}},r}(r.InputHandler);e.GamepadNavigation=i,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
