define(["apphost","connectionManager","events","globalize","browser","require","dom","embyRouter","emby-tabs"],function(appHost,connectionManager,events,globalize,browser,require,dom,embyRouter){"use strict";function showUserView(id){var view=currentUserViews.filter(function(current){return current.Id==id})[0];view&&embyRouter.showItem(view)}function executeCommand(id){switch(id){case"settings":embyRouter.showSettings();break;case"signout":Dashboard.logout();break;case"selectserver":embyRouter.showSelectServer();break;case"reports":Dashboard.navigate("reports.html");break;case"metadatamanager":Dashboard.navigate("edititemmetadata.html");break;case"manageserver":Dashboard.navigate("dashboard.html");break;case"remotecontrol":Dashboard.navigate("nowplaying.html");break;case"sync":Dashboard.navigate("mysync.html");break;case"nowplaying":Dashboard.navigate("nowplaying.html");break;default:showUserView(id)}}function showMenu(menuItems,button,tabIndex){var actionSheetType=browser.safari?"actionsheet":"webActionSheet";require([actionSheetType],function(actionSheet){actionSheet.show({items:menuItems,positionTo:button,entryAnimation:"slideup",exitAnimation:"fadeout",entryAnimationDuration:160,exitAnimationDuration:100,offsetTop:-35,positionY:"top",dialogClass:"dockedtabs-dlg",menuItemClass:"dockedtabs-dlg-menuitem"}).then(function(id){if(executeCommand(id),id){var tabs=dom.parentWithClass(button,"dockedtabs-tabs");tabs.selectedIndex(tabIndex,!1)}})})}function showLibrariesMenu(button){var commands=currentUserViews.map(function(view){return{name:view.Name,id:view.Id}});showMenu(commands,button,1)}function showMoreMenu(button){var commands=[];currentUser.Policy.IsAdministrator&&(commands.push({name:globalize.translate("ButtonManageServer"),id:"manageserver"}),dom.getWindowSize().innerWidth>=1e3&&commands.push({name:globalize.translate("MetadataManager"),id:"metadatamanager"}),commands.push({name:globalize.translate("ButtonReports"),id:"reports"})),appHost.supports("multiserver")&&commands.push({name:globalize.translate("HeaderSelectServer"),id:"selectserver"}),commands.push({name:globalize.translate("TabSettings"),id:"settings"}),currentUser.Policy.EnableSync&&commands.push({name:globalize.translate("SyncToOtherDevices"),id:"sync"}),commands.push({name:globalize.translate("ButtonSignOut"),id:"signout"}),showMenu(commands,button,5)}function onTabClick(e){var index=parseInt(this.getAttribute("data-index"));switch(index){case 0:embyRouter.goHome();break;case 1:showLibrariesMenu(this),e.preventDefault(),e.stopPropagation();break;case 2:embyRouter.showLiveTV();break;case 3:Dashboard.navigate("mysync.html?mode=offline");break;case 4:Dashboard.navigate("nowplaying.html");break;case 5:showMoreMenu(this),e.preventDefault(),e.stopPropagation()}}function addNoFlexClass(buttons){setTimeout(function(){for(var i=0,length=buttons.length;i ",appHost.supports("sync")&&(html+=' "),html+=' ",html+=' ",elem.innerHTML=html;for(var buttons=elem.querySelectorAll(".emby-tab-button"),i=0,length=buttons.length;i0;hasLiveTv?element.querySelector(".docked-tab-livetv").classList.remove("hide"):element.querySelector(".docked-tab-livetv").classList.add("hide");var downloadsTab=element.querySelector(".docked-tab-syncdownloads");downloadsTab&&(user.Policy.EnableSync?downloadsTab.classList.remove("hide"):downloadsTab.classList.add("hide"))}function showUserTabs(user,element){currentUser=user;var apiClient=ConnectionManager.getApiClient(user.ServerId);apiClient.getUserViews({},user.Id).then(function(result){currentUserViews=result.Items,onUserViewResponse(user,result.Items,element)},function(){currentUserViews=[],onUserViewResponse(user,[],element)})}function showCurrentUserTabs(element){Dashboard.getCurrentUserId()&&Dashboard.getCurrentUser().then(function(user){showUserTabs(user,element)})}function onViewShow(e){e.detail.properties.indexOf("fullscreen")===-1&&Dashboard.getCurrentUserId()?instance.show():instance.hide()}function dockedTabs(options){var self=this;instance=self,self.element=render(options),events.on(connectionManager,"localusersignedin",function(e,user){self.show(),showUserTabs(user,self.element)}),events.on(connectionManager,"localusersignedout",function(){self.hide()}),showCurrentUserTabs(self.element),document.addEventListener("viewshow",onViewShow)}require(["css!./dockedtabs"]);var instance,currentUser={},currentUserViews=[];return dockedTabs.prototype.destroy=function(){document.removeEventListener("viewshow",onViewShow),instance=null;var self=this;self.element;self.element=null},dockedTabs.prototype.show=function(){this.element.classList.remove("hide")},dockedTabs.prototype.hide=function(){this.element.classList.add("hide")},dockedTabs});