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/common/globalize.js","./../modules/emby-apiclient/connectionmanager.js","./../modules/emby-apiclient/events.js","./../modules/common/imagehelper.js","./../modules/common/input/api.js","./../modules/tabbedview/sectionscontroller.js"],function(_exports,_basetab,_embyItemscontainer,_embyButton,_embyScroller,_datetime,_globalize,_connectionmanager,_events,_imagehelper,_api,_sectionscontroller){function LiveTvScheduleTab(view,params){_basetab.default.apply(this,arguments),_sectionscontroller.default.apply(this,arguments),this.view=view,this.params=params,this.apiClient=_connectionmanager.default.getApiClient(params.serverId)}function pushSection(sections,name,enableFocusPreview,items){var cardLayout=1.5<=(_imagehelper.default.getPrimaryImageAspectRatio(items)||1);sections.push({Name:name,CollectionType:"livetv",Monitor:[],ListOptions:{shape:"autooverflow",fields:enableFocusPreview?[]:["ParentNameOrName","ChannelName","AirTime"],showAirEndTime:!0,cardLayout:cardLayout,centerText:!cardLayout,action:"edit",cardFooterAside:!1,showChannelLogo:cardLayout,preferThumb:cardLayout||null,multiSelect:!1},QueryOptions:{},Items:items})}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Object.assign(LiveTvScheduleTab.prototype,_basetab.default.prototype),Object.assign(LiveTvScheduleTab.prototype,_sectionscontroller.default.prototype),LiveTvScheduleTab.prototype.fetchSections=function(){var enableFocusPreview=this.enableFocusPreview(),apiClient=this.getApiClient();return apiClient.getLiveTvTimers({IsActive:!1,IsScheduled:!0}).then(function(result){for(var sections=[],items=(sections.push({Name:_globalize.default.translate("HeaderActiveRecordings"),CollectionType:"livetv",SectionType:"recordings",Monitor:["RecordingStarted","RecordingEnded"],RefreshInterval:3e5,ListOptions:{shape:"autooverflow",cardLayout:!1,fields:["ParentNameOrName","ChannelName","AirTime"],showAirEndTime:!0,preferThumb:"auto",centerText:!0,multiSelect:!1},QueryOptions:{UserId:apiClient.getCurrentUserId(),IsInProgress:!0,Recursive:!0}}),result.Items),currentGroupName="",currentGroup=[],i=0,length=items.length;i<length;i++){var item=items[i],dateText="";if(item.StartDate)try{var premiereDate=_datetime.default.parseISO8601Date(item.StartDate),dateText=_datetime.default.toLocaleDateString(premiereDate,{weekday:"long",month:"short",day:"numeric"})}catch(err){}dateText!==currentGroupName?(currentGroup.length&&pushSection(sections,currentGroupName,enableFocusPreview,currentGroup),currentGroupName=dateText,currentGroup=[item]):currentGroup.push(item)}return currentGroup.length&&pushSection(sections,currentGroupName,enableFocusPreview,currentGroup),sections})},LiveTvScheduleTab.prototype.onResume=function(options){var serverNotificationHandler;return _basetab.default.prototype.onResume.apply(this,arguments),this.serverNotificationHandler||(serverNotificationHandler=function(){this.paused?this.needsSectionsRefresh=!0:this.onResume({refresh:!0,refreshSections:!0})}.bind(this),_events.default.on(_api.default,"TimerCreated",serverNotificationHandler),_events.default.on(_api.default,"TimerCancelled",serverNotificationHandler),_events.default.on(_api.default,"RecordingStarted",serverNotificationHandler),_events.default.on(_api.default,"RecordingEnded",serverNotificationHandler),this.serverNotificationHandler=serverNotificationHandler),_sectionscontroller.default.prototype.onResume.apply(this,arguments)},LiveTvScheduleTab.prototype.onPause=function(){_basetab.default.prototype.onPause.apply(this,arguments),_sectionscontroller.default.prototype.onPause.apply(this,arguments)},LiveTvScheduleTab.prototype.destroy=function(){_basetab.default.prototype.destroy.apply(this,arguments);var serverNotificationHandler=this.serverNotificationHandler;serverNotificationHandler&&(_events.default.off(_api.default,"TimerCreated",serverNotificationHandler),_events.default.off(_api.default,"TimerCancelled",serverNotificationHandler),_events.default.off(_api.default,"RecordingStarted",serverNotificationHandler),_events.default.off(_api.default,"RecordingEnded",serverNotificationHandler),this.serverNotificationHandler=null),_sectionscontroller.default.prototype.destroy.apply(this,arguments)};_exports.default=LiveTvScheduleTab});