define(["cardBuilder","layoutManager","appFooter-shared","viewManager","apphost","connectionManager","events","globalize","browser","require","dom","appRouter","emby-tabs"],function(cardBuilder,layoutManager,appFooter,viewManager,appHost,connectionManager,events,globalize,browser,require,dom,appRouter){"use strict";var instance;require(["css!./dockedtabs"]);var headerHomeButton,headerSearchButton,headerMenuButton,currentServerId,hiddenMode=0,serverMode=1,libraryMode=2,currentMode=hiddenMode,userSignedIn=!1;function onLocalUserSignedIn(e,serverId,userId){currentServerId=serverId,userSignedIn=!0}function onLocalUserSignedOut(e){userSignedIn=!1}function updateHomeButton(tabsEnabled){(tabsEnabled||headerHomeButton)&&(headerHomeButton=headerHomeButton||document.querySelector(".headerHomeButton"),tabsEnabled?headerHomeButton.classList.add("hiddenWhenBottomNavVisible"):headerHomeButton.classList.remove("hiddenWhenBottomNavVisible"))}function updateSearchButton(tabsEnabled){(tabsEnabled||headerSearchButton)&&(headerSearchButton=headerSearchButton||document.querySelector(".headerSearchButton"),tabsEnabled?headerSearchButton.classList.add("hiddenWhenBottomNavVisible"):headerSearchButton.classList.remove("hiddenWhenBottomNavVisible"))}function updateMenuButton(tabsEnabled){(tabsEnabled||headerMenuButton)&&(headerMenuButton=headerMenuButton||document.querySelector(".headerMenuButton"),tabsEnabled?headerMenuButton.classList.add("hiddenWhenBottomNavVisible"):headerMenuButton.classList.remove("hiddenWhenBottomNavVisible"))}function setMode(mode){if(mode!==currentMode){var tabs=instance;tabs&&((currentMode=mode)===serverMode?function(parentElement){setTabs([{name:globalize.translate("Home"),icon:"&#xE88A;",href:appRouter.getRouteUrl("home")},{name:globalize.translate("Dashboard"),active:!0,icon:"&#xE871;",href:"/dashboard.html"},{name:globalize.translate("Users"),icon:"&#xE7FB;",href:"/users/users.html"},{name:globalize.translate("Library"),icon:"&#xE2C7;",href:"/librarysetup/library.html"},{name:globalize.translate("More"),icon:"&#xE5D2;",href:"/servermenu/servermenu.html"}],parentElement)}(getElement(tabs)):mode===libraryMode&&function(parentElement){var tabs=[];connectionManager.getApiClient(currentServerId).getUserViews().then(function(result){tabs.push({name:globalize.translate("Home"),icon:"&#xE88A;",active:!0,href:appRouter.getRouteUrl("home")}),appHost.supports("sync")&&tabs.push({name:globalize.translate("Downloads"),icon:"&#xe2c0;",href:appRouter.getRouteUrl("downloads")});for(var i=0,length=result.Items.length;i<length&&!(3<=tabs.length);i++)tabs.push({name:result.Items[i].Name,icon:cardBuilder.getDefaultIcon(result.Items[i]),href:appRouter.getRouteUrl(result.Items[i])});tabs.push({name:globalize.translate("Search"),icon:"&#xE8B6;",href:appRouter.getRouteUrl("search")}),tabs.push({name:globalize.translate("More"),icon:"&#xE5D2;",href:appRouter.getRouteUrl("settings")}),setTabs(tabs,parentElement)})}(getElement(tabs)),mode===hiddenMode?(tabs.hide(),updateHomeButton(!1),updateSearchButton(!1),updateMenuButton(!1)):(tabs.show(),updateHomeButton(!0),updateSearchButton(!0),updateMenuButton(!0)))}}function setTabs(tabs,parentElement){var html='<div is="emby-tabs" class="dockedtabs-tabs" data-selectionbar="false">';html+=tabs.map(function(tab,index){var active=tab.active?" emby-tab-button-active":"";return'<a is="emby-linkbutton" href="'+tab.href+'" class="dockedtabs-tab-button emby-tab-button'+active+'" data-index="'+index+'">                <i class="dockedtabs-tab-button-icon md-icon">'+tab.icon+"</i><div>"+tab.name+"</div></a>"}).join(""),html+="</div>",parentElement.innerHTML=html}function onViewShow(e){var detail=e.detail;layoutManager.tv?setMode(hiddenMode):!1===detail.drawer?setMode(hiddenMode):detail.startup&&!userSignedIn?setMode(hiddenMode):detail.dashboardTheme?setMode(serverMode):setMode(libraryMode)}function getElement(instance){var element=instance.element;return element=element||(instance.element=function(){var elem=document.createElement("div");return elem.classList.add("hide"),elem.classList.add("dockedtabs"),appFooter.add(elem),elem}())}function DockedTabs(){instance=this,events.on(connectionManager,"localusersignedin",onLocalUserSignedIn),events.on(connectionManager,"localusersignedout",onLocalUserSignedOut),document.addEventListener("viewshow",onViewShow)}return DockedTabs.prototype.destroy=function(){document.removeEventListener("viewshow",onViewShow);this.element;this.element=null},DockedTabs.prototype.show=function(){getElement(this).classList.remove("hide")},DockedTabs.prototype.hide=function(){var element=this.element;element&&element.classList.add("hide")},new DockedTabs,DockedTabs});