define(["exports","./../emby-apiclient/connectionmanager.js","./../common/servicelocator.js","./../layoutmanager.js","./../common/globalize.js","./../approuter.js","./../actionsheet/actionsheet.js","./../common/itemmanager/itemmanager.js"],function(_exports,_connectionmanager,_servicelocator,_layoutmanager,_globalize,_approuter,_actionsheet,_itemmanager){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;_exports.default=function(options){var apiClient=_connectionmanager.default.currentApiClient();return function(apiClient){return apiClient?_connectionmanager.default.getSignedInUsers(apiClient):Promise.resolve([])}(apiClient).then(function(signedInUsers){return function(apiClient){return apiClient?apiClient.getCurrentUser():Promise.resolve(null)}(apiClient).then(function(user){return _actionsheet.default.show({items:function(apiClient,user,signedInUsers){var items=[],userIcon=(items.push({name:_globalize.default.translate("HeaderAppSettings"),id:"settings",icon:"&#xe8B8;",secondaryText:_servicelocator.appHost.appName()+" "+_servicelocator.appHost.appVersion()}),user&&user.Policy.IsAdministrator&&_approuter.default.getRouteInfo(_approuter.default.getRouteUrl("manageserver"))&&items.push({name:_globalize.default.translate("ManageEmbyServer"),id:"manageserver",icon:"dashboard"}),_servicelocator.appHost.supports("multiserver")&&items.push({name:_globalize.default.translate("HeaderChangeServer"),id:"selectserver",icon:_itemmanager.default.getDefaultIcon({Type:"Server"})}),_itemmanager.default.getDefaultIcon(user));if(apiClient&&!_connectionmanager.default.isLoggedIntoConnect()){for(var i=0,length=signedInUsers.length;i<length;i++){var signedInUser=signedInUsers[i];signedInUser.Id!==user.Id&&items.push({name:signedInUser.Name,id:"user-"+signedInUser.Id,ImageUrl:signedInUser.PrimaryImageTag?apiClient.getUserImageUrl(signedInUser.Id,{maxWidth:80,type:"Primary",tag:signedInUser.PrimaryImageTag}):null,icon:userIcon})}items.push({name:_globalize.default.translate("HeaderChangeUser"),id:"changeuser",icon:_itemmanager.default.getDefaultIcon({Type:"User"})})}return items.push({name:_globalize.default.translate("HeaderSignOut"),id:"logout",icon:"&#xe879;"}),_layoutmanager.default.tv&&_servicelocator.appHost.supports("exit")&&items.push({name:_globalize.default.translate("Exit"),id:"exit",icon:"&#xe879;"}),_servicelocator.appHost.supports("sleep")&&items.push({name:_globalize.default.translate("Sleep"),id:"sleep",icon:"&#xe426;"}),_servicelocator.appHost.supports("shutdown")&&items.push({name:_globalize.default.translate("Shutdown"),id:"shutdown",icon:"&#xe8AC;"}),_servicelocator.appHost.supports("restart")&&items.push({name:_globalize.default.translate("Restart"),id:"restart",icon:"&#xe5D5;"}),items}(apiClient,user,signedInUsers),positionTo:options.positionTo,positionY:options.positionY,positionX:options.positionX,transformOrigin:options.transformOrigin,item:user,showServerName:!0,hasItemIcon:!0,hasItemImage:!0,roundImage:!0,fields:["Name","ShortOverview"]}).then(function(id){switch(id){case"logout":_approuter.default.logout(apiClient);break;case"changeuser":_approuter.default.showServerLogin({apiClient:apiClient});break;case"home":_approuter.default.goHome();break;case"exit":_servicelocator.appHost.exit();break;case"sleep":_servicelocator.appHost.sleep();break;case"shutdown":_servicelocator.appHost.shutdown();break;case"restart":_servicelocator.appHost.restart();break;case"settings":_approuter.default.showSettings();break;case"manageserver":_layoutmanager.default.tv?_approuter.default.showSettings({start:"server"}):_approuter.default.show(_approuter.default.getRouteUrl("manageserver"));break;case"selectserver":_approuter.default.showSelectServer();break;default:if(!(id||"").startsWith("user-"))return Promise.reject();var userId=id.substring(5);!function(apiClient,userId){_approuter.default.changeToUser({apiClient:apiClient,userId:userId}).catch(function(err){"aborterror"!==((null==err?void 0:err.name)||"").toLowerCase()&&console.log("error changing to user: "+err)})}(apiClient,userId)}return Promise.resolve()})})})}});