define(["layoutManager","inputManager","connectionManager","events","viewManager","libraryBrowser","appRouter","apphost","playbackManager","browser","globalize","paper-icon-button-light","material-icons","scrollStyles","flexStyles"],function(layoutManager,inputManager,connectionManager,events,viewManager,libraryBrowser,appRouter,appHost,playbackManager,browser,globalize){"use strict";function getCurrentApiClient(){return currentUser&¤tUser.localUser?connectionManager.getApiClient(currentUser.localUser.ServerId):connectionManager.currentApiClient()}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.classList.add("skinHeader-withBackground"),skinHeader.innerHTML=html,headerHomeButton=skinHeader.querySelector(".headerHomeButton"),headerUserButton=skinHeader.querySelector(".headerUserButton"),headerSettingsButton=skinHeader.querySelector(".headerSettingsButton"),headerCastButton=skinHeader.querySelector(".headerCastButton"),headerSearchButton=skinHeader.querySelector(".headerSearchButton"),browser.chrome||skinHeader.classList.add("skinHeader-blurred"),lazyLoadViewMenuBarImages(),bindMenuEvents()}function lazyLoadViewMenuBarImages(){require(["imageLoader"],function(imageLoader){imageLoader.lazyChildren(skinHeader)})}function onBackClick(){appRouter.back()}function updateUserInHeader(user){var hasImage;if(user&&user.name){if(user.imageUrl){var userButtonHeight=26,url=user.imageUrl;user.supportsImageParams&&(url+="&height="+Math.round(userButtonHeight*Math.max(window.devicePixelRatio||1,2))),updateHeaderUserButton(url),hasImage=!0}headerUserButton.classList.remove("hide")}else headerUserButton.classList.add("hide");hasImage||updateHeaderUserButton(null),user&&user.localUser?(headerHomeButton&&headerHomeButton.classList.remove("hide"),headerSearchButton&&headerSearchButton.classList.remove("hide"),headerSettingsButton&&(user.localUser.Policy.IsAdministrator?headerSettingsButton.classList.remove("hide"):headerSettingsButton.classList.add("hide")),headerCastButton.classList.remove("hide")):(headerHomeButton.classList.add("hide"),headerCastButton.classList.add("hide"),headerSearchButton&&headerSearchButton.classList.add("hide"),headerSettingsButton&&headerSettingsButton.classList.add("hide")),requiresUserRefresh=!1}function updateHeaderUserButton(src){src?(headerUserButton.classList.add("headerUserButtonRound"),headerUserButton.innerHTML=''):(headerUserButton.classList.remove("headerUserButtonRound"),headerUserButton.innerHTML='')}function showSearch(){inputManager.trigger("search")}function onHeaderUserButtonClick(e){Dashboard.showUserFlyout(e.target)}function onHeaderHomeButtonClick(){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),headerSearchButton&&headerSearchButton.addEventListener("click",showSearch),headerUserButton.addEventListener("click",onHeaderUserButtonClick),headerHomeButton.addEventListener("click",onHeaderHomeButtonClick),initHeadRoom(skinHeader),skinHeader.querySelector(".btnNotifications").addEventListener("click",function(){Dashboard.navigate("notificationlist.html")}),headerCastButton.addEventListener("click",onCastButtonClicked)}function onCastButtonClicked(){var btn=this;require(["playerSelectionMenu"],function(playerSelectionMenu){playerSelectionMenu.show(btn)})}function getItemHref(item,context){return appRouter.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+='
',html+=''+globalize.translate("ButtonHome")+"",html+='
',html+='',html+='
',html+=globalize.translate("sharedcomponents#HeaderMyDownloads"),html+="
",html+=''+globalize.translate("sharedcomponents#Browse")+"",html+=''+globalize.translate("sharedcomponents#Manage")+"",html+="
",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")+"",html+="
"),html+='
',html+='',user.localUser&&(html+=''+globalize.translate("ButtonSettings")+""),html+=''+globalize.translate("sharedcomponents#Sync")+"",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(apiClient){currentDrawerType="admin",loadNavDrawer(),navDrawerScrollContainer.querySelector(".adminDrawerLogo")?updateDashboardMenuSelectedItem():createDashboardMenu(apiClient)}function isUrlInCurrentView(url){return window.location.href.toString().toLowerCase().indexOf(url.toLowerCase())!==-1}function updateDashboardMenuSelectedItem(){for(var links=navDrawerScrollContainer.querySelectorAll(".navMenuOption"),currentViewId=viewManager.currentView().id,i=0,length=links.length;i0),selected){link.classList.add("navMenuOption-selected");var title="";link=link.querySelector("span")||link;var secondaryTitle=(link.innerText||link.textContent).trim();title+=secondaryTitle,LibraryMenu.setTitle(title)}else link.classList.remove("navMenuOption-selected")}}function createToolsMenuList(pluginItems){for(var links=[{name:globalize.translate("TabServer")},{name:globalize.translate("TabDashboard"),href:"dashboard.html",pageIds:["dashboardPage"],icon:"dashboard"},{name:globalize.translate("TabSettings"),href:"dashboardgeneral.html",pageIds:["dashboardGeneralPage"],icon:"settings"},{name:globalize.translate("TabUsers"),href:"userprofiles.html",pageIds:["userProfilesPage","newUserPage","editUserPage","userLibraryAccessPage","userParentalControlPage","userPasswordPage"],icon:"people"},{name:"Emby Premiere",href:"supporterkey.html",pageIds:["supporterKeyPage"],icon:"star"},{name:globalize.translate("TabLibrary"),href:"library.html",pageIds:["mediaLibraryPage","librarySettingsPage","libraryDisplayPage","metadataImagesConfigurationPage","metadataNfoPage"],icon:"folder",color:"#38c"},{name:globalize.translate("TabSubtitles"),href:"metadatasubtitles.html",pageIds:["metadataSubtitlesPage"],icon:"closed_caption"},{name:globalize.translate("TabPlayback"),icon:"play_circle_filled",color:"#E5342E",href:"cinemamodeconfiguration.html",pageIds:["cinemaModeConfigurationPage","playbackConfigurationPage","streamingSettingsPage"]},{name:globalize.translate("TabTranscoding"),icon:"transform",href:"encodingsettings.html",pageIds:["encodingSettingsPage"]},{divider:!0,name:globalize.translate("TabDevices")},{name:globalize.translate("TabDevices"),href:"devices.html",pageIds:["devicesPage","devicePage"],icon:"tablet"},{name:globalize.translate("HeaderDownloadSync"),icon:"file_download",href:"syncactivity.html",pageIds:["syncActivityPage","syncJobPage","syncSettingsPage"],color:"#009688"},{name:globalize.translate("TabCameraUpload"),href:"devicesupload.html",pageIds:["devicesUploadPage"],icon:"photo_camera"},{divider:!0,name:globalize.translate("TabExtras")},{name:globalize.translate("DLNA"),href:"dlnasettings.html",pageIds:["dlnaSettingsPage","dlnaProfilesPage","dlnaProfilePage"],icon:"settings"},{name:globalize.translate("TabLiveTV"),href:"livetvstatus.html",pageIds:["liveTvStatusPage","liveTvSettingsPage","liveTvTunerPage"],icon:"dvr"},{name:globalize.translate("TabNotifications"),icon:"notifications",color:"brown",href:"notificationsettings.html",pageIds:["notificationSettingsPage","notificationSettingPage"]},{name:globalize.translate("TabPlugins"),icon:"add_shopping_cart",color:"#9D22B1",href:"plugins.html",pageIds:["pluginsPage","pluginCatalogPage"]}],i=0,length=pluginItems.length;i",item.icon&&(menuHtml+=''+item.icon+""),menuHtml+="",menuHtml+=item.name,menuHtml+="",menuHtml+=""}function getToolsMenuHtml(apiClient){return getToolsMenuLinks(apiClient).then(function(items){var i,length,item,menuHtml="";for(menuHtml+='
',i=0,length=items.length;i
"),item.href?menuHtml+=getToolsLinkHtml(item):item.name&&(menuHtml+='
',menuHtml+=item.name,menuHtml+="
");return menuHtml+=""})}function createDashboardMenu(apiClient){return getToolsMenuHtml(apiClient).then(function(toolsMenuHtml){var html="";html+='",html+=toolsMenuHtml,html=html.split("href=").join('onclick="return LibraryMenu.onLinkClicked(event, this);" href='),navDrawerScrollContainer.innerHTML=html,updateDashboardMenuSelectedItem()})}function onSidebarLinkClick(){var section=this.getElementsByClassName("sectionName")[0],text=section?section.innerHTML:this.innerHTML;LibraryMenu.setTitle(text)}function getUserViews(apiClient,userId){return apiClient.getUserViews({},userId).then(function(result){for(var items=result.Items,list=[],i=0,length=items.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(".navMenuOption"),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,function(){return[]}):mainTabsManager.setTabs(null)})},setDefaultTitle:function(){pageTitleElement||(pageTitleElement=document.querySelector(".pageTitle")),pageTitleElement&&(pageTitleElement.classList.add("pageTitleWithLogo"),pageTitleElement.classList.add("pageTitleWithDefaultLogo"),pageTitleElement.style.backgroundImage=null,pageTitleElement.innerHTML=""),document.title="Emby"},setTitle:function(title){var html=title,page=viewManager.currentView();if(page){var helpUrl=page.getAttribute("data-helpurl");helpUrl&&(html+=''+globalize.translate("ButtonHelp")+"")}pageTitleElement||(pageTitleElement=document.querySelector(".pageTitle")),pageTitleElement&&(pageTitleElement.classList.remove("pageTitleWithLogo"),pageTitleElement.classList.remove("pageTitleWithDefaultLogo"),pageTitleElement.style.backgroundImage=null,pageTitleElement.innerHTML=html),document.title=title||"Emby"},setTransparentMenu:function(transparent){transparent?skinHeader.classList.add("semiTransparent"):skinHeader.classList.remove("semiTransparent")}};var currentPageType;return pageClassOn("pagebeforeshow","page",function(e){var page=this;page.classList.contains("withTabs")||LibraryMenu.setTabs(null)}),pageClassOn("pageshow","page",function(e){var page=this,isDashboardPage=page.classList.contains("type-interior"),isLibraryPage=!isDashboardPage&&page.classList.contains("libraryPage"),apiClient=getCurrentApiClient();isDashboardPage?(mainDrawerButton&&mainDrawerButton.classList.remove("hide"),refreshDashboardInfoInDrawer(apiClient)):(mainDrawerButton&&(enableLibraryNavDrawer?mainDrawerButton.classList.remove("hide"):mainDrawerButton.classList.add("hide")),"library"!==currentDrawerType&&refreshLibraryDrawer()),updateMenuForPageType(isDashboardPage,isLibraryPage),e.detail.isRestored||window.scrollTo(0,0),updateTitle(page),updateBackButton(page),updateLibraryNavLinks(page)}),renderHeader(),events.on(connectionManager,"localusersignedin",function(e,user){currentDrawerType=null,currentUser={localUser:user},loadNavDrawer(),connectionManager.user(connectionManager.getApiClient(user.ServerId)).then(function(user){currentUser=user,updateUserInHeader(user)})}),events.on(connectionManager,"localusersignedout",function(){currentUser={},updateUserInHeader()}),events.on(playbackManager,"playerchange",updateCastIcon),loadNavDrawer(),LibraryMenu});