define(["cardBuilder","layoutManager","appFooter-shared","apphost","connectionManager","events","globalize","require","appRouter","emby-tabs"],function(cardBuilder,layoutManager,appFooter,appHost,connectionManager,events,globalize,require,appRouter){"use strict";var instance;require(["css!./dockedtabs"]);var headerHomeButton,headerSearchButton,headerMenuButton,currentServerId,hiddenMode=0,libraryMode=2,currentMode=hiddenMode,userSignedIn=!1;function onLocalUserSignedIn(e,serverId,userId){currentMode=hiddenMode,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){var tabs;mode!==currentMode&&(tabs=instance)&&((currentMode=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:"&#xf090;",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("Settings"),icon:"&#xE5D2;",href:appRouter.getRouteUrl("settings")}),function(tabs,parentElement){if(!tabs.length)return parentElement.innerHTML="";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+'" tabindex="-1" 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}(tabs,parentElement)})}(getElement(tabs)),mode===hiddenMode?(tabs.hide(),updateHomeButton(!1),updateSearchButton(!1),updateMenuButton(!1)):(tabs.show(),updateHomeButton(!0),updateSearchButton(!0),updateMenuButton(!0)))}function onViewShow(e){var detail=e.detail;layoutManager.tv||!1===detail.drawer&&!detail.dockedTabs||detail.startup&&!userSignedIn?setMode(hiddenMode):setMode(libraryMode)}function getElement(instance){var elem;return instance.element||(instance.element=((elem=document.createElement("div")).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"),element.innerHTML="")},new DockedTabs,DockedTabs});