define(["exports","./../dom.js","./../emby-apiclient/connectionmanager.js","./../emby-apiclient/events.js","./../common/usersettings/usersettings.js","./../common/playback/playbackmanager.js","./../common/itemmanager/itemmanager.js","./../common/globalize.js","./../loading/loading.js","./../dialoghelper/dialoghelper.js"],function(_exports,_dom,_connectionmanager,_events,_usersettings,_playbackmanager,_itemmanager,_globalize,_loading,_dialoghelper){var currentChangeOptions,inputDisplayElement,alpanumericShortcutTimeout;function clearState(){clearAlphaNumericShortcutTimeout(),currentChangeOptions=null;var elem=inputDisplayElement;elem&&(elem.innerHTML="",elem.classList.add("hide"))}function onAlphanumericShortcutTimeout(){var options=currentChangeOptions,options=(clearState(),null==options?void 0:options.newItem);options&&(_loading.default.show(),_playbackmanager.default.play({items:[options]}))}function clearAlphaNumericShortcutTimeout(){alpanumericShortcutTimeout&&(clearTimeout(alpanumericShortcutTimeout),alpanumericShortcutTimeout=null)}function updateDisplayElement(options){var item=options.currentItem,offset=options.offset;!function(apiClient,options){var query;return options.channelsResult?Promise.resolve(options.channelsResult):(query={UserId:apiClient.getCurrentUserId(),IsAiring:!0,ImageTypeLimit:1,EnableImageTypes:"Primary,Thumb,Backdrop",Fields:"ProgramPrimaryImageAspectRatio",EnableUserData:!1,SortBy:"ChannelNumber,SortName",AddCurrentProgram:!1},_usersettings.default.addLiveTvChannelSortingToQuery(query,_globalize.default),apiClient.getLiveTvChannels(query).then(function(result){return options.channelsResult=result}))}(_connectionmanager.default.getApiClient(item),options).then(function(result){for(var index=-1,channels=result.Items,i=0,length=channels.length;i<length;i++)if(channels[i].Id===item.Id){index=i;break}-1===index&&(index=0),index+=offset,index=Math.min(channels.length-1,index),index=Math.max(index,0),(item=channels[index])&&(options.numChannels=channels.length,options.newItem=item,options.newItemIndex=index,function(item){var html,elem=inputDisplayElement;elem&&(html="",html+=_itemmanager.default.getDisplayName(item,{channelNumberFirst:!0}),elem.innerHTML=html,elem.classList.remove("hide"))}(item))})}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["css!modules/alphanumericshortcuts/alphanumericshortcuts.css"]),_events.default.on(_playbackmanager.default,"playbackstop",clearState);_exports.default={onChannelChangeRequest:function(options){inputDisplayElement||((inputDisplayElement=document.createElement("div")).classList.add("alphanumeric-shortcut","hide","dialog"),_dom.default.allowBackdropFilter()&&inputDisplayElement.classList.add("dialog-blur"),document.body.appendChild(inputDisplayElement));var maxIndex,index,currentOptions=currentChangeOptions;currentOptions?(null!=(index=currentOptions.newItemIndex)&&(maxIndex=currentOptions.numChannels-1,(index=index+options.offset)<0?options.offset+=0-index:maxIndex<index&&(options.offset-=index-maxIndex)),currentOptions.offset+=options.offset,options=currentOptions):currentChangeOptions=options,updateDisplayElement(options),clearAlphaNumericShortcutTimeout(),alpanumericShortcutTimeout=setTimeout(onAlphanumericShortcutTimeout,2e3)}}});