define(["layoutManager","events","viewManager","libraryBrowser","embyRouter","apphost","playbackManager","browser","appfooter-shared","dockedtabs","paper-icon-button-light","material-icons","scrollStyles","flexStyles"],function(layoutManager,events,viewManager,libraryBrowser,embyRouter,appHost,playbackManager,browser,appFooter,DockedTabs){"use strict";function renderHeader(){var html="";html+='
',html+='
';var backIcon=browser.safari?"chevron_left":"";html+='",html+='',html+='',html+='

',html+="
",html+='
',html+='',html+='',html+='',html+='',html+='',layoutManager.mobile||(html+=''),html+="
",html+="
",html+='
',html+="
",skinHeader.innerHTML=html,browser.chrome||skinHeader.classList.add("skinHeader-blurred"),lazyLoadViewMenuBarImages(),bindMenuEvents()}function lazyLoadViewMenuBarImages(){require(["imageLoader"],function(imageLoader){imageLoader.lazyChildren(skinHeader)})}function onBackClick(){embyRouter.back()}function updateUserInHeader(user){var hasImage,headerUserButton=skinHeader.querySelector(".headerUserButton");if(user&&user.name&&user.imageUrl){var userButtonHeight=26,url=user.imageUrl;user.supportsImageParams&&(url+="&height="+Math.round(userButtonHeight*Math.max(window.devicePixelRatio||1,2))),headerUserButton&&(updateHeaderUserButton(headerUserButton,url),hasImage=!0)}headerUserButton&&!hasImage&&updateHeaderUserButton(headerUserButton,null),user&&updateLocalUser(user.localUser),requiresUserRefresh=!1}function updateHeaderUserButton(headerUserButton,src){src?(headerUserButton.classList.add("headerUserButtonRound"),headerUserButton.classList.remove("autoSize"),headerUserButton.innerHTML=''):(headerUserButton.classList.remove("headerUserButtonRound"),headerUserButton.classList.add("autoSize"),headerUserButton.innerHTML='person')}function updateLocalUser(user){var headerSearchButton=skinHeader.querySelector(".headerSearchButton"),btnCast=skinHeader.querySelector(".btnCast"),dashboardEntryHeaderButton=skinHeader.querySelector(".dashboardEntryHeaderButton");user?(btnCast.classList.remove("hide"),headerSearchButton&&headerSearchButton.classList.remove("hide"),dashboardEntryHeaderButton&&(user.Policy.IsAdministrator?dashboardEntryHeaderButton.classList.remove("hide"):dashboardEntryHeaderButton.classList.add("hide"))):(btnCast.classList.add("hide"),headerSearchButton&&headerSearchButton.classList.add("hide"),dashboardEntryHeaderButton&&dashboardEntryHeaderButton.classList.add("hide"))}function showSearch(){Dashboard.navigate("search.html")}function onHeaderUserButtonClick(e){Dashboard.showUserFlyout(e.target)}function onHeaderAppsButtonClick(){Dashboard.navigate("home.html")}function bindMenuEvents(){mainDrawerButton=document.querySelector(".mainDrawerButton"),mainDrawerButton&&mainDrawerButton.addEventListener("click",toggleMainDrawer);var headerBackButton=document.querySelector(".headerBackButton");headerBackButton&&headerBackButton.addEventListener("click",onBackClick);var headerSearchButton=document.querySelector(".headerSearchButton");headerSearchButton&&headerSearchButton.addEventListener("click",showSearch);var headerUserButton=document.querySelector(".headerUserButton");headerUserButton&&headerUserButton.addEventListener("click",onHeaderUserButtonClick);var headerAppsButton=document.querySelector(".headerAppsButton");headerAppsButton&&headerAppsButton.addEventListener("click",onHeaderAppsButtonClick),initHeadRoom(skinHeader),skinHeader.querySelector(".btnNotifications").addEventListener("click",function(){Dashboard.navigate("notificationlist.html")});var btnCast=document.querySelector(".headerButton-btnCast");btnCast&&btnCast.addEventListener("click",onCastButtonClicked)}function onCastButtonClicked(){var btn=this;require(["playerSelectionMenu"],function(playerSelectionMenu){playerSelectionMenu.show(btn)})}function getItemHref(item,context){return embyRouter.getRouteUrl(item,{context:context})}function toggleMainDrawer(){navDrawerInstance.isVisible?closeMainDrawer():openMainDrawer()}function openMainDrawer(){navDrawerInstance.open(),lastOpenTime=(new Date).getTime()}function onMainDrawerOpened(){layoutManager.mobile&&document.body.classList.add("bodyWithPopupOpen")}function closeMainDrawer(){navDrawerInstance.close()}function onMainDrawerSelect(e){navDrawerInstance.isVisible?onMainDrawerOpened():document.body.classList.remove("bodyWithPopupOpen")}function refreshLibraryInfoInDrawer(user,drawer){var html="";html+='
';var homeHref=window.ApiClient?"home.html":"selectserver.html?showuser=1";html+=''+Globalize.translate("ButtonHome")+"",html+=''+Globalize.translate("ButtonRemote")+"",html+='
',html+='
',html+="
";var localUser=user.localUser;localUser&&localUser.Policy.IsAdministrator&&(html+='
',html+='
',html+='
',html+=Globalize.translate("HeaderAdmin"),html+="
",html+=''+Globalize.translate("ButtonManageServer")+"",html+=''+Globalize.translate("MetadataManager")+"",layoutManager.mobile||(html+=''+Globalize.translate("ButtonReports")+""),html+="
"),html+='
',html+='
',user.localUser&&(html+=''+Globalize.translate("ButtonSettings")+""),html+=''+Globalize.translate("ManageOfflineDownloads")+"",html+=''+Globalize.translate("SyncToOtherDevices")+"",Dashboard.isConnectMode()&&(html+=''+Globalize.translate("ButtonSelectServer")+""),user.localUser&&(html+=''+Globalize.translate("ButtonSignOut")+""),html+="
",navDrawerScrollContainer.innerHTML=html;var lnkManageServer=navDrawerScrollContainer.querySelector(".lnkManageServer");lnkManageServer&&lnkManageServer.addEventListener("click",onManageServerClicked)}function refreshDashboardInfoInDrawer(page,user){loadNavDrawer(),navDrawerScrollContainer.querySelector(".adminDrawerLogo")?updateDashboardMenuSelectedItem():createDashboardMenu(page)}function updateDashboardMenuSelectedItem(){for(var links=navDrawerScrollContainer.querySelectorAll(".sidebarLink"),i=0,length=links.length;i',html+=Globalize.translate("HeaderMedia"),html+="",html+=items.map(function(i){var icon="folder",color="inherit",itemId=i.Id;"channels"==i.CollectionType?itemId="channels":"livetv"==i.CollectionType&&(itemId="livetv"),"photos"==i.CollectionType?(icon="photo_library",color="#009688"):"music"==i.CollectionType||"musicvideos"==i.CollectionType?(icon="library_music",color="#FB8521"):"books"==i.CollectionType?(icon="library_books",color="#1AA1E1"):"playlists"==i.CollectionType?(icon="view_list",color="#795548"):"games"==i.CollectionType?(icon="games",color="#F44336"):"movies"==i.CollectionType?(icon="video_library",color="#CE5043"):"channels"==i.CollectionType||"Channel"==i.Type?(icon="videocam",color="#E91E63"):"tvshows"==i.CollectionType?(icon="tv",color="#4CAF50"):"livetv"==i.CollectionType&&(icon="live_tv",color="#293AAE"),icon=i.icon||icon;var onclick=i.onclick?" function(){"+i.onclick+"}":"null";return''+icon+''+i.Name+""}).join(""),libraryMenuOptions.innerHTML=html;for(var elem=libraryMenuOptions,sidebarLinks=elem.querySelectorAll(".sidebarLink"),i=0,length=sidebarLinks.length;i200&&setTimeout(function(){closeMainDrawer(),setTimeout(function(){action?action():Dashboard.navigate(link.href)},getNavigateDelay())},50),event.stopPropagation(),event.preventDefault(),!1)},onLogoutClicked:function(){return(new Date).getTime()-lastOpenTime>200&&(closeMainDrawer(),setTimeout(function(){Dashboard.logout()},getNavigateDelay())),!1},onHardwareMenuButtonClick:function(){toggleMainDrawer()},onSettingsClicked:function(event){return 1!=event.which||(Dashboard.navigate("dashboard.html"),!1)},setTabs:function(type,selectedIndex,builder){require(["mainTabsManager"],function(mainTabsManager){type?mainTabsManager.setTabs(viewManager.currentView(),selectedIndex,builder):mainTabsManager.setTabs(null)})},setDefaultTitle:function(){var libraryMenuButtonText=document.querySelector(".libraryMenuButtonText");libraryMenuButtonText&&(libraryMenuButtonText.innerHTML=''),document.title="Emby"},setTitle:function(title){var html=title,page=viewManager.currentView();if(page){var helpUrl=page.getAttribute("data-helpurl");helpUrl&&(html+='info'+Globalize.translate("ButtonHelp")+"")}var libraryMenuButtonText=document.querySelector(".libraryMenuButtonText");libraryMenuButtonText&&(libraryMenuButtonText.innerHTML=html),document.title=title||"Emby"},setTransparentMenu:function(transparent){transparent?skinHeader.classList.add("semiTransparent"):skinHeader.classList.remove("semiTransparent")}},pageClassOn("pagebeforeshow","page",function(e){var page=this;page.classList.contains("withTabs")||(LibraryMenu.setTabs(null),page.classList.contains("pageWithAbsoluteTabs")?document.body.classList.add("withTallToolbar"):document.body.classList.remove("withTallToolbar"))}),pageClassOn("pageshow","page",function(e){var page=this,isDashboardPage=page.classList.contains("type-interior");isDashboardPage?(mainDrawerButton&&mainDrawerButton.classList.remove("hide"),refreshDashboardInfoInDrawer(page)):(mainDrawerButton&&(enableLibraryNavDrawer?mainDrawerButton.classList.remove("hide"):mainDrawerButton.classList.add("hide")),(navDrawerElement&&navDrawerElement.classList.contains("adminDrawer")||!navDrawerElement)&&refreshLibraryDrawer()),setDrawerClass(page),updateViewMenuBar(page),e.detail.isRestored||window.scrollTo(0,0),updateTitle(page),updateBackButton(page),page.classList.contains("libraryPage")?(document.body.classList.add("libraryDocument"),document.body.classList.remove("dashboardDocument"),document.body.classList.remove("hideMainDrawer"),navDrawerInstance&&navDrawerInstance.setEdgeSwipeEnabled(!1)):isDashboardPage?(document.body.classList.remove("libraryDocument"),document.body.classList.add("dashboardDocument"),document.body.classList.remove("hideMainDrawer"),navDrawerInstance&&navDrawerInstance.setEdgeSwipeEnabled(!0)):(document.body.classList.remove("libraryDocument"),document.body.classList.remove("dashboardDocument"),document.body.classList.add("hideMainDrawer"),navDrawerInstance&&navDrawerInstance.setEdgeSwipeEnabled(!1)),updateLibraryNavLinks(page)}),window.ApiClient&&initializeApiClient(window.ApiClient),renderHeader(),events.on(ConnectionManager,"apiclientcreated",function(e,apiClient){initializeApiClient(apiClient)}),events.on(ConnectionManager,"localusersignedin",function(e,user){setDrawerClass(),ConnectionManager.user(ConnectionManager.getApiClient(user.ServerId)).then(function(user){refreshLibraryDrawer(user),updateUserInHeader(user)})}),events.on(ConnectionManager,"localusersignedout",updateUserInHeader),events.on(playbackManager,"playerchange",updateCastIcon),setDrawerClass(),enableBottomTabs&&new DockedTabs({appFooter:appFooter}),LibraryMenu});