define(["apphost","connectionManager","appHeader","loading","layoutManager","apphost","focusManager","dom","globalize","appRouter","emby-scroller","listViewStyle"],function(appHost,connectionManager,appHeader,loading,layoutManager,apphost,focusManager,dom,globalize,appRouter){"use strict";return function(view,params){function getRouteHtml(route,user){var html="",listItemClass="listItem listItem-button settingsListItem";layoutManager.tv&&(listItemClass+=" listItem-focusscale");var data="",path=route.path;return path&&"settings"===route.type&&(path+="?userId="+user.Id,path+="&serverId="+user.ServerId),path&&(data+=' data-path="'+path+'"'),route.command&&(data+=' data-command="'+route.command+'"'),html+='<button type="button" class="'+listItemClass+'"'+data+">",html+='<i class="md-icon settingsIcon listItemIcon listItemIcon-transparent">',html+=route.icon||"settings",html+="</i>",html+='<div class="listItemBody">',html+='<div class="listItemBodyText">',html+=globalize.translate(route.title),html+="</div>",html+="</div>",html+="</button>"}view.querySelector(".appInfo").innerHTML=apphost.appName()+" "+apphost.appVersion(),view.addEventListener("viewbeforeshow",function(e){var isRestored=e.detail.isRestored;loading.hide(),isRestored||function(){var apiClient=params.serverId?connectionManager.getApiClient(params.serverId):connectionManager.currentApiClient();apiClient.getUser(params.userId||apiClient.getCurrentUserId()).then(function(user){view.querySelector(".headerUser").innerHTML=user.Name,function(view,user,apiClient){var fldImage=view.querySelector(".userImage");if(user.PrimaryImageTag){var imageUrl=apiClient.getUserImageUrl(user.Id,{width:200,tag:user.PrimaryImageTag,type:"Primary"});fldImage.innerHTML="<img style='width:7em;border-radius:.2em;' src='"+imageUrl+"' />"}else fldImage.innerHTML='<i class="md-icon defaultCardBackground0" style="font-size:7em;">&#xe7fd;</i>';fldImage.classList.remove("hide")}(view,user,apiClient),function(user){var routes=appRouter.getRoutes().filter(function(r){return function(route,user){return"settings"===route.type&&appRouter.validateUserAccessToRoute(route,user)}(r,user)});routes=routes.sort(function(a,b){var aOrder=null==a.order?1e3:a.order,bOrder=null==b.order?1e3:b.order;if(bOrder<aOrder)return 1;if(aOrder<bOrder)return-1;var aName=a.title,bName=b.title;return bName<aName?1:aName<bName?-1:0}),user.Policy.IsAdministrator&&self.Dashboard&&routes.push({title:"ManageEmbyServer",path:appRouter.getRouteUrl("manageserver"),icon:"dashboard"});user.EnableAutoLogin&&!connectionManager.isLoggedIntoConnect()||routes.push({title:"HeaderSignOut",command:"signout",icon:"&#xE879;"});!function(routes,user){var html="";html+='<div class="verticalSection settingsVerticalSection">',html+="<div>";for(var i=0,length=routes.length;i<length;i++)html+=getRouteHtml(routes[i],user);html+="</div>",html+="</div>";var routesElem=view.querySelector(".dynamicRoutes");routesElem.innerHTML=html,focusManager.autoFocus(routesElem)}(routes,user)}(user)})}()}),function(view){var lnkSelectServer=view.querySelector(".selectServer");lnkSelectServer.href=appRouter.getRouteUrl("selectserver"),appHost.supports("multiserver")?lnkSelectServer.classList.remove("hide"):lnkSelectServer.classList.add("hide")}(view),view.addEventListener("click",function(e){var card=dom.parentWithClass(e.target,"settingsListItem");if(card){var path=card.getAttribute("data-path");path&&appRouter.show(path),"signout"===card.getAttribute("data-command")&&appRouter.logout()}},!0)}});