define(["exports","./basetab.js","./../modules/cardbuilder/cardbuilder.js","./../modules/common/usersettings/usersettings.js","./../modules/common/globalize.js","./../modules/layoutmanager.js","./../modules/focusmanager.js","./../modules/common/inputmanager.js"],function(_exports,_basetab,_cardbuilder,_usersettings,_globalize,_layoutmanager,_focusmanager,_inputmanager){function fetchItems(query){var apiClient=this.apiClient;return query=Object.assign({UserId:apiClient.getCurrentUserId(),IsAiring:!0,ImageTypeLimit:1,EnableImageTypes:"Primary,Thumb,Backdrop",Fields:"ProgramPrimaryImageAspectRatio,PrimaryImageAspectRatio",EnableUserData:!1,SortBy:"ChannelNumber,SortName"},query),_usersettings.default.addLiveTvChannelSortingToQuery(query,_globalize.default),apiClient.getLiveTvChannels(query)}function OnNowTab(view){_basetab.default.apply(this,arguments)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Object.assign(OnNowTab.prototype,_basetab.default.prototype);var FocusScrollOffset="-padding-inline-start";function scrollToIndex(instance,index,focus,scrollBehavior){instance.itemsContainer.scrollToIndex(index,{offsetLeft:FocusScrollOffset,behavior:scrollBehavior},focus)}function triggerCommand(name,e){e={sourceElement:e.target,repeat:e.repeat,originalEvent:e};_inputmanager.default.trigger(name,e)}function onInputCommand(e){var detail=e.detail;switch(detail.command){case"channelup":triggerCommand("rtl"===document.dir?"left":"right",detail.originalEvent||e),e.preventDefault();break;case"channeldown":triggerCommand("rtl"===document.dir?"right":"left",detail.originalEvent||e),e.preventDefault()}}OnNowTab.prototype.loadTemplate=function(){var view=this.view;return view.innerHTML='\n                    <div is="emby-scroller" data-mousewheel="false" data-focusscroll="start" data-focusscrolloffset="'+FocusScrollOffset+'" class="padded-top-focusscale padded-bottom-focusscale">\n                        <div is="emby-itemscontainer" data-focusabletype="nearest" class="focusable focuscontainer-x scrollSlider itemsContainer videoosd-padded-left videoosd-padded-right" data-refreshinterval="300000" data-virtualscrolllayout="horizontal-grid"></div>\n                    </div>\n',this.itemsContainer=view.querySelector(".itemsContainer"),this.itemsContainer.fetchData=fetchItems.bind(this),this.itemsContainer.getListOptions=function(items){var forceBackdrop=!!_layoutmanager.default.tv;return{renderer:_cardbuilder.default,options:{preferThumb:forceBackdrop?null:"auto",inheritThumb:!1,shape:forceBackdrop?"backdrop":"auto",overlayPlayButton:!0,contextMenu:!1,multiSelect:!1,programsAsSeries:!1,showCurrentProgramImage:!0,defaultShape:"portrait",action:"play",cardClass:"videoOsd-itemstab-card videoOsd-itemstab-card-threeline",fields:["CurrentProgramName","CurrentProgramParentNameOrName","CurrentProgramTime"],allowBottomPadding:!1,defaultBackground:!0,textLinks:!1,enableFocusScaling:!1},virtualScrollLayout:"horizontal-grid"}}.bind(this),_inputmanager.default.on(this.itemsContainer,onInputCommand),Promise.resolve()},OnNowTab.prototype.scrollToCurrentItem=function(focus,scrollBehavior){this.paused||this.itemsContainer.contains(document.activeElement)||(focus?_focusmanager.default.focus(this.itemsContainer):function(instance,focus,scrollBehavior){var itemId,item=instance.item;item&&"TvChannel"===item.Type?(itemId=item.Id,-1!==(item=instance.itemsContainer.indexOfItemId(itemId))?scrollToIndex(instance,item,focus,scrollBehavior):fetchItems.call(instance,{Limit:0}).then(function(totalResult){totalResult.TotalRecordCount<=1?scrollToIndex(instance,0,focus,scrollBehavior):fetchItems.call(instance,{StartItemId:itemId,Limit:0}).then(function(result){result=result.TotalRecordCount?Math.max(totalResult.TotalRecordCount-result.TotalRecordCount,0):0;scrollToIndex(instance,result,focus,scrollBehavior)})})):scrollToIndex(instance,0,focus,scrollBehavior)}(this,focus,scrollBehavior))},OnNowTab.prototype.onResume=function(options){var instance=this;return _basetab.default.prototype.onResume.apply(this,arguments).then(function(){var optionsWithoutRefresh=Object.assign(Object.assign({},options),{refresh:!1}),hasFocus=instance.itemsContainer.contains(document.activeElement);return instance.itemsContainer.resume(optionsWithoutRefresh).then(function(){options.refresh?instance.refreshItem():instance.scrollToCurrentItem(hasFocus,"instant")})})},OnNowTab.prototype.refreshItem=function(){_basetab.default.prototype.refreshItem.apply(this,arguments);var instance=this,hasFocus=instance.itemsContainer.contains(document.activeElement);return instance.itemsContainer.refreshItems().then(function(){instance.scrollToCurrentItem(hasFocus)})},OnNowTab.prototype.onPause=function(){_basetab.default.prototype.onPause.apply(this,arguments),this.itemsContainer.pause()},OnNowTab.prototype.destroy=function(){_basetab.default.prototype.destroy.apply(this,arguments),this.itemsContainer=null,this.item=null};_exports.default=OnNowTab});