define(["exports","./../modules/tabbedview/basetab.js","./../modules/emby-elements/emby-itemscontainer/emby-itemscontainer.js","./../modules/emby-elements/emby-button/emby-button.js","./../modules/emby-elements/emby-scroller/emby-scroller.js","./../modules/emby-apiclient/connectionmanager.js","./../modules/emby-apiclient/events.js","./../modules/appheader/appheader.js","./../modules/layoutmanager.js","./../modules/backdrop/backdrop.js","./../modules/emby-elements/guide/guide.js"],function(_exports,_basetab,_embyItemscontainer,_embyButton,_embyScroller,_connectionmanager,_events,_appheader,_layoutmanager,_backdrop,_guide){function GuideTab(view,params){_basetab.default.apply(this,arguments),this.apiClient=_connectionmanager.default.getApiClient(params.serverId),this.view=view,this.params=params,_layoutmanager.default.tv&&view.classList.add("guideContainer-tv"),this.boundonGuideFocus=function(e,detail){this._lastFocusInfo=detail,this.onFocusIn(detail.element)}.bind(this),this.boundonGuideFocusOut=function(e,detail){this._lastFocusInfo=null,this.onFocusOut()}.bind(this)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["css!livetv/guide.css"]),Object.assign(GuideTab.prototype,_basetab.default.prototype),GuideTab.prototype.getFocusPreviewItem=function(element){var focusInfo=this._lastFocusInfo;return(null==focusInfo?void 0:focusInfo.element)===element?focusInfo.item:null},GuideTab.prototype.refetchItemForFocusPreview=function(){return!0},GuideTab.prototype.enableFocusPreview=function(){return!!_layoutmanager.default.tv},GuideTab.prototype.createFocusPreviewElement=function(){var elem=this.view.querySelector(".guideSelectedInfo");return this.fillFocusPreviewContainer(elem),elem.querySelector(".focusPreviewOverview").classList.add("guide-focusPreviewOverview"),elem},GuideTab.prototype.onResume=function(options){_basetab.default.prototype.onResume.apply(this,arguments),options=options||{},_appheader.default.ensureVisible(),_backdrop.default.clear();var isNew,promise,guideInstance=this.guideInstance,guideContainer=this.view,focusGuideOnLoad=options.autoFocus||guideContainer.contains(document.activeElement),guideContainer=(guideInstance||(isNew=!0,guideInstance=this.guideInstance=new _guide.default({element:guideContainer,serverId:this.params.serverId,condensed:_layoutmanager.default.tv}),_layoutmanager.default.tv&&(_events.default.on(this.guideInstance,"focus",this.boundonGuideFocus),guideContainer.addEventListener("focusout",this.boundonGuideFocusOut),this.view.querySelector(".guideSelectedInfo").classList.remove("hide")),options.refresh=!0),_layoutmanager.default.tv?this.view.classList.add("liveGuideTab-tv"):this.view.classList.remove("liveGuideTab-tv"),this.getApiClient());return(promise=(promise=isNew&&_layoutmanager.default.tv?guideContainer.getItems(guideContainer.getCurrentUserId(),{IncludeItemTypes:"TvChannel",EnableTotalRecordCount:!1,Limit:1,SortBy:"DatePlayed",SortOrder:"Descending",Fields:"UserDataPlayCount",Recursive:!0,EnableImages:!1,AddCurrentProgram:!1}):promise)||Promise.resolve({Items:[]})).then(function(result){var _lastPlayedChannel$Us,result=result.Items[0];return null!=result&&null!=(_lastPlayedChannel$Us=result.UserData)&&_lastPlayedChannel$Us.PlayCount&&(options.scrollToChannelId=result.Id,options.focusOnScroll=focusGuideOnLoad,options.scrollBehavior="instant"),options.resetScroll="true"!==(null==(_lastPlayedChannel$Us=options.previousViewInfo)||null==(_lastPlayedChannel$Us=_lastPlayedChannel$Us.params)?void 0:_lastPlayedChannel$Us.asDialog),guideInstance.resume(options)})},GuideTab.prototype.enableFocusPreviewImage=function(){return!0},GuideTab.prototype.hideFocusPreviewElementUsingDisplay=function(){return!1},GuideTab.prototype.onPause=function(){_basetab.default.prototype.onPause.apply(this,arguments);var guideInstance=this.guideInstance;guideInstance&&guideInstance.pause()},GuideTab.prototype.destroy=function(){var view=this.view,guideInstance=(_basetab.default.prototype.destroy.apply(this,arguments),this.guideInstance);guideInstance&&(this.boundonGuideFocus&&(_events.default.off(guideInstance,"focus",this.boundonGuideFocus),this.boundonGuideFocus=null),this.boundonGuideFocusOut&&(null!=view&&view.removeEventListener("focusout",this.boundonGuideFocusOut),this.boundonGuideFocusOut=null),guideInstance.destroy()),this._lastFocusInfo=null,this.guideInstance=null};_exports.default=GuideTab});