define(["exports","./../modules/emby-apiclient/connectionmanager.js","./../modules/cardbuilder/cardbuilder.js","./../modules/tabbedview/basetab.js","./../modules/emby-elements/emby-itemscontainer/emby-itemscontainer.js","./../modules/emby-elements/emby-scroller/emby-scroller.js","./../modules/common/globalize.js","./../modules/common/datetime.js","./../modules/loading/loading.js"],function(_exports,_connectionmanager,_cardbuilder,_basetab,_embyItemscontainer,_embyScroller,_globalize,_datetime,_loading){function UpcomingTab(view,params){_basetab.default.apply(this,arguments),this.view=view,this.params=params,this.apiClient=_connectionmanager.default.getApiClient(params.serverId)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Object.assign(UpcomingTab.prototype,_basetab.default.prototype),UpcomingTab.prototype.onResume=function(options){_basetab.default.prototype.onResume.apply(this,arguments);var promises,parentId,view,instance,apiClient=this.apiClient;options.refresh&&(promises=[],parentId=this.params.parentId,_loading.default.show(),promises.push(apiClient.getUpcomingEpisodes({Limit:100,UserId:apiClient.getCurrentUserId(),ImageTypeLimit:1,EnableImageTypes:"Primary,Backdrop,Thumb",EnableTotalRecordCount:!1,parentId:parentId,Fields:"Overview"})),view=this.view,instance=this,Promise.all(promises).then(function(responses){return _loading.default.hide(),function(view,items){for(var groups=[],currentGroupName="",currentGroup=[],i=0,length=items.length;i<length;i++){var item=items[i],dateText="";if(item.PremiereDate)try{var premiereDate=new Date(Date.parse(item.PremiereDate)),dateText=_datetime.default.isRelativeDay(premiereDate,-1)?_globalize.default.translate("Yesterday"):_datetime.default.toLocaleDateString(premiereDate,{weekday:"long",month:"short",day:"numeric"})}catch(err){dateText=item.PremiereDate}dateText!==currentGroupName?(currentGroup.length&&groups.push({name:currentGroupName,items:currentGroup}),currentGroupName=dateText,currentGroup=[item]):currentGroup.push(item)}var html="";for(i=0,length=groups.length;i<length;i++)html=(html+='<div class="verticalSection verticalSection-cards">')+'<h2 class="sectionTitle sectionTitle-cards padded-left padded-left-page">'+groups[i].name+'</h2><div is="emby-scroller" class="padded-top-focusscale padded-bottom-focusscale" data-framesize="matchgrandparent" data-focusscroll="true" data-mousewheel="false"><div is="emby-itemscontainer" data-focusabletype="nearest" class="itemsContainer scrollSlider focuscontainer-x focusable padded-left padded-left-page padded-right"></div></div></div>';(view=view.classList.contains("upcomingContainer")?view:view.querySelector(".upcomingContainer")).innerHTML=html;var itemContainers=view.querySelectorAll(".itemsContainer");for(i=0,length=groups.length;i<length;i++)_cardbuilder.default.buildCards(groups[i].items,{shape:"backdrop",preferThumb:!0,fields:["ParentName","Name"],multiSelect:!1,itemsContainer:itemContainers[i],contextMenu:!1,draggable:!1,action:"overview"})}(view,responses[0].Items),options.autoFocus&&instance.autoFocus(),Promise.resolve()}))},UpcomingTab.prototype.onPause=function(){_basetab.default.prototype.onPause.apply(this,arguments)},UpcomingTab.prototype.destroy=function(){_basetab.default.prototype.destroy.apply(this,arguments),this.view=null,this.params=null,this.apiClient=null};_exports.default=UpcomingTab});