define(["userSettings","loading","connectionManager","apphost","layoutManager","focusManager","homeSections","emby-itemscontainer"],function(userSettings,loading,connectionManager,appHost,layoutManager,focusManager,homeSections){"use strict";function HomeTab(view,params){this.view=view,this.params=params,this.apiClient=connectionManager.currentApiClient(),this.sectionsContainer=view.querySelector(".sections"),view.querySelector(".sections").addEventListener("settingschange",onHomeScreenSettingsChanged.bind(this))}function onHomeScreenSettingsChanged(){this.sectionsRendered=!1,this.paused||this.onResume({refresh:!0})}function autoFocus(){var state=this;!focusManager.autoFocus(state.view)&&state.retries<20?(state.retries++,setTimeout(autoFocus.bind(state),100)):(state.view=null,state.retries=null)}return HomeTab.prototype.onResume=function(options){if(this.sectionsRendered){var sectionsContainer=this.sectionsContainer;return sectionsContainer?homeSections.resume(sectionsContainer,options):Promise.resolve()}this.refresh(options)},HomeTab.prototype.refresh=function(options){loading.show();var view=this.view,apiClient=this.apiClient;return this.destroyHomeSections(),this.sectionsRendered=!0,apiClient.getCurrentUser().then(function(user){return homeSections.loadSections(view.querySelector(".sections"),apiClient,user,userSettings).then(function(){if(options.autoFocus){if(!focusManager.autoFocus(view)){var state={retries:0,view:view};setTimeout(autoFocus.bind(state),100)}}loading.hide()})})},HomeTab.prototype.onPause=function(){var sectionsContainer=this.sectionsContainer;sectionsContainer&&homeSections.pause(sectionsContainer)},HomeTab.prototype.destroy=function(){this.view=null,this.params=null,this.apiClient=null,this.destroyHomeSections(),this.sectionsContainer=null},HomeTab.prototype.destroyHomeSections=function(){var sectionsContainer=this.sectionsContainer;sectionsContainer&&homeSections.destroySections(sectionsContainer)},HomeTab});