define(["exports","./../dom.js","./../layoutmanager.js","./../common/inputmanager.js","./../emby-apiclient/events.js","./../common/methodtimer.js","./../focusmanager.js"],function(_exports,_dom,_layoutmanager,_inputmanager,_events,_methodtimer,_focusmanager){var _styleElement;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var isMouseIdle,lastPointerMoveData,mouseInterval,mouseManager={},lastMouseInputTime=0;function removeIdleClasses(){isMouseIdle=!1,document.body.classList.remove("mouseIdle","mouseIdle-tv")}function addIdleClasses(){isMouseIdle=!0;var classList=document.body.classList;_layoutmanager.default.tv?classList.add("mouseIdle","mouseIdle-tv"):classList.add("mouseIdle")}function onPointerMove(e){var obj,eventX=e.screenX,e=e.screenY;void 0===eventX&&void 0===e||((obj=lastPointerMoveData)?Math.abs(eventX-obj.x)<10&&Math.abs(e-obj.y)<10||(obj.x=eventX,obj.y=e,lastMouseInputTime=Date.now(),isMouseIdle&&removeIdleClasses()):lastPointerMoveData={x:eventX,y:e})}function onPointerEnter(e){var pointerType=e.pointerType;pointerType&&"mouse"!==pointerType||isMouseIdle||(pointerType=e.target).closest&&!pointerType.closest(".nohoverfocus")&&(e=_focusmanager.default.focusableParent(pointerType,!1))&&_focusmanager.default.focus(e)}function onMouseInterval(){!isMouseIdle&&5e3<=Date.now()-lastMouseInputTime&&addIdleClasses()}function stopMouseListening(){_styleElement.remove(),mouseInterval&&(mouseInterval.destroy(),mouseInterval=null),removeIdleClasses(),_dom.default.removeEventListener(document,"pointermove",onPointerMove,{passive:!0}),_dom.default.removeEventListener(document,"mousemove",onPointerMove,{passive:!0})}function startMouseListening(){document.head.appendChild(_styleElement),(_layoutmanager.default.tv?addIdleClasses:removeIdleClasses)(),mouseInterval=mouseInterval||new _methodtimer.default({onInterval:onMouseInterval,timeoutMs:5e3,type:"interval"}),window.PointerEvent?_dom.default.addEventListener(document,"pointermove",onPointerMove,{passive:!0}):_dom.default.addEventListener(document,"mousemove",onPointerMove,{passive:!0})}var listeners=[];function requestMouseListening(listener){listeners.includes(listener)||(0===listeners.length&&startMouseListening(),listeners.push(listener))}function releaseMouseListening(listener){listener=listeners.indexOf(listener);-1!==listener&&listeners.splice(listener,1),listeners.length||stopMouseListening()}function initMouse(){var linkUrl,link;linkUrl=Emby.Page.baseUrl()+"/modules/input/mouse.css",globalThis.urlCacheParam&&(linkUrl+="?"+globalThis.urlCacheParam),(link=document.createElement("link")).setAttribute("rel","stylesheet"),link.setAttribute("type","text/css"),link.setAttribute("href",linkUrl),_styleElement=link,document.head.appendChild(link),(_layoutmanager.default.tv?requestMouseListening:releaseMouseListening)("tv"),_dom.default.removeEventListener(document,window.PointerEvent?"pointerenter":"mouseenter",onPointerEnter,{capture:!0,passive:!0}),_layoutmanager.default.tv}function sendCommandFromEvent(name,e){_inputmanager.default.trigger(name,{sourceElement:e.target,originalEvent:e})}window.addEventListener("mouseup",function(e){switch(e.button){case 3:e.stopPropagation(),e.preventDefault(),sendCommandFromEvent("back",e);break;case 4:e.stopPropagation(),e.preventDefault(),sendCommandFromEvent("forward",e)}}),initMouse(),mouseManager.requestMouseListening=requestMouseListening,mouseManager.releaseMouseListening=releaseMouseListening,mouseManager.lastMouseInputTime=function(){return lastMouseInputTime},_events.default.on(_layoutmanager.default,"modechange",initMouse);_exports.default=mouseManager});