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/common/datetime.js","./../modules/emby-apiclient/connectionmanager.js","./../modules/emby-apiclient/events.js","./../modules/indicators/indicators.js","./../modules/mediainfo/mediainfo.js","./../modules/appheader/appheader.js","./../modules/layoutmanager.js","./../modules/backdrop/backdrop.js","./../modules/emby-elements/guide/guide.js"],function(_exports,_basetab,_embyItemscontainer,_embyButton,_embyScroller,_datetime,_connectionmanager,_events,_indicators,_mediainfo,_appheader,_layoutmanager,_backdrop,_guide){var focusTimeout,currentItemId,serverId,guideItemDetailsElement,guideImageElement;function getTime(date){return _datetime.default.getDisplayTime(date).toLowerCase()}function setSelectedInfo(item){var html="",secondaryMediaInfoHtml=(html=(html=html+'<div class="guideSelectedItemPrimaryInfo">'+("<h2>"+item.Name+"</h2>"))+_indicators.default.getTimerIndicator(item)+"</div>",_mediainfo.default.getPrimaryMediaInfoHtml(item)),secondaryMediaInfoHtml=(secondaryMediaInfoHtml&&(html=(html+='<div class="guideSelectedItemMediaInfo mediaInfoItems">')+secondaryMediaInfoHtml+"</div>"),item.ShortOverview||item.Overview),secondaryMediaInfoHtml=(secondaryMediaInfoHtml&&(html=(html+='<div class="guideOverview" style="margin-top:.15em;">')+secondaryMediaInfoHtml+"</div>"),"");if(item.StartDate)try{secondaryMediaInfoHtml+=getTime(new Date(Date.parse(item.StartDate)))}catch(e){console.log("Error parsing date: "+item.PremiereDate)}if(item.EndDate)try{secondaryMediaInfoHtml+=" - "+getTime(new Date(Date.parse(item.EndDate)))}catch(e){console.log("Error parsing date: "+item.EndDate)}secondaryMediaInfoHtml&&(html=(html+='<div style="margin-top:.15em;">')+secondaryMediaInfoHtml+"</div>"),guideItemDetailsElement.innerHTML=html;secondaryMediaInfoHtml=function(item,options){return(options=options||{}).type=options.type||"Primary","string"==typeof item?_connectionmanager.default.getApiClient(item.ServerId).getImageUrl(item,options):item.ImageTags&&item.ImageTags[options.type]?(options.tag=item.ImageTags[options.type],_connectionmanager.default.getApiClient(item.ServerId).getImageUrl(item.Id,options)):"Primary"===options.type&&item.AlbumId&&item.AlbumPrimaryImageTag?(options.tag=item.AlbumPrimaryImageTag,_connectionmanager.default.getApiClient(item.ServerId).getImageUrl(item.AlbumId,options)):null}(item);guideImageElement.style.backgroundImage=secondaryMediaInfoHtml?"url('"+secondaryMediaInfoHtml+"')":""}function onFocusTimeout(){var apiClient;serverId&&(apiClient=_connectionmanager.default.getApiClient(serverId)).getItem(apiClient.getCurrentUserId(),currentItemId).then(function(item){setSelectedInfo(item)})}function onGuideFocus(e,detail){focusTimeout&&clearTimeout(focusTimeout),currentItemId=detail.item.Id,focusTimeout=setTimeout(onFocusTimeout,500)}function GuideTab(view,params){_basetab.default.apply(this,arguments),this.apiClient=_connectionmanager.default.getApiClient(params.serverId),this.view=view,this.params=params,serverId=params.serverId,guideItemDetailsElement=view.querySelector(".guideItemDetails"),guideImageElement=view.querySelector(".guideImage"),_layoutmanager.default.tv&&view.querySelector(".guideContainer").classList.add("guideContainer-tv")}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["css!livetv/guide.css"]),Object.assign(GuideTab.prototype,_basetab.default.prototype),GuideTab.prototype.onResume=function(options){_basetab.default.prototype.onResume.apply(this,arguments),_appheader.default.ensureVisible(),_backdrop.default.clear();var guideInstance=this.guideInstance;return guideInstance||(guideInstance=this.guideInstance=new _guide.default({element:this.view.querySelector(".guideContainer"),serverId:this.params.serverId,condensed:_layoutmanager.default.tv}),_layoutmanager.default.tv&&(_events.default.on(this.guideInstance,"focus",onGuideFocus),this.view.querySelector(".guideSelectedInfo").classList.remove("hide")),(options=options||{}).refresh=!0),_layoutmanager.default.tv?this.view.classList.add("liveGuideTab-tv"):this.view.classList.remove("liveGuideTab-tv"),guideInstance.resume(options)},GuideTab.prototype.onPause=function(){_basetab.default.prototype.onPause.apply(this,arguments);var guideInstance=this.guideInstance;guideInstance&&guideInstance.pause()},GuideTab.prototype.destroy=function(){_basetab.default.prototype.destroy.apply(this,arguments);var guideInstance=this.guideInstance;guideInstance&&(_events.default.off(guideInstance,"focus",onGuideFocus),guideInstance.destroy()),guideImageElement=guideItemDetailsElement=serverId=null,this.view=null,this.params=null,this.guideInstance=null,this.apiClient=null},_exports.default=GuideTab});