/*
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/Logger","./EventMatch"],(function(n,e,t,i){"use strict";const s=t.getLogger("esri.views.input.InputHandler");let o=function(){function n(n){this._manager=null,this._incoming={},this._outgoing={},this._incomingEventMatches=null,this._incomingEventTypes=null,this._outgoingEventTypes=null,this._hasSideEffects=n}var t=n.prototype;return t.onInstall=function(n){this._manager?s.error("This InputHandler has already been registered with an InputManager"):(n.setEventCallback((n=>this._handleEvent(n))),n.setUninstallCallback((()=>this._onUninstall())),this._manager=n)},t.onUninstall=function(){},t.registerIncoming=function(n,e,t){let s;"function"==typeof e?(t=e,s=[]):s=e||[];const o="string"==typeof n?new i.EventMatch(n,s):n,r=()=>{this._incomingEventTypes=null,this._incomingEventMatches=null},h=n=>{const e=this._incoming[n.match.eventType];if(e){const t=e.indexOf(n);e.splice(t,1),r(),this._manager&&this._manager.updateDependencies()}},c=new a(o,t,{onPause:h,onRemove:h,onResume:n=>{const e=this._incoming[n.match.eventType];e&&!e.includes(n)&&(e.push(n),r(),this._manager&&this._manager.updateDependencies())}});let u=this._incoming[o.eventType];return u||(u=[],this._incoming[o.eventType]=u),u.push(c),r(),this._manager&&this._manager.updateDependencies(),c},t.registerOutgoing=function(n){if(this._outgoing[n])throw Error("There is already a callback registered for this outgoing InputEvent: "+n);const e=new r(n,{onEmit:(n,e,t,i)=>{this._manager.emit(n.eventType,e,t,i)},onRemove:n=>{delete this._outgoing[n.eventType],this._manager.updateDependencies()}});return this._outgoing[n]=e,this._outgoingEventTypes=null,this._manager&&this._manager.updateDependencies(),e},t.startCapturingPointer=function(n){this._manager.setPointerCapture(n,!0)},t.stopCapturingPointer=function(n){this._manager.setPointerCapture(n,!1)},t.refreshHasPendingInputs=function(){this._manager.refreshHasPendingInputs()},t._onUninstall=function(){this._manager?(this.onUninstall(),this._manager=null):s.error("This InputHandler is not registered with an InputManager")},t._handleEvent=function(n){const e=this._incoming[n.type];if(e)for(const t of e)if(t.match.matches(n)&&(t.callback(n),n.shouldStopPropagation()))break},e._createClass(n,[{key:"incomingEventMatches",get:function(){if(!this._incomingEventMatches){this._incomingEventMatches=[];for(const n in this._incoming){const e=this._incoming[n];for(const n of e)this._incomingEventMatches.push(n.match)}}return this._incomingEventMatches}},{key:"incomingEventTypes",get:function(){return this._incomingEventTypes||(this._incomingEventTypes=this.incomingEventMatches.map((n=>n.eventType))),this._incomingEventTypes}},{key:"outgoingEventTypes",get:function(){return this._outgoingEventTypes||(this._outgoingEventTypes=Object.keys(this._outgoing)),this._outgoingEventTypes}},{key:"hasSideEffects",get:function(){return this._hasSideEffects}},{key:"hasPendingInputs",get:function(){return!1}}]),n}(),a=function(){function n(n,e,t){this.match=n,this._callback=e,this._handler=t}var t=n.prototype;return t.pause=function(){this._handler.onPause(this)},t.resume=function(){this._handler.onResume(this)},t.remove=function(){this._handler.onRemove(this)},e._createClass(n,[{key:"callback",get:function(){return this._callback}}]),n}(),r=function(){function n(n,e){this.eventType=n,this._removed=!1,this._handler=e}var e=n.prototype;return e.emit=function(n,e,t){this._removed||this._handler.onEmit(this,n,e,t)},e.remove=function(){this._removed=!0,this._handler.onRemove(this)},n}();n.InputHandler=o,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
