define(["./common/globalize.js","./emby-apiclient/events.js","./common/input/api.js"],function(_globalize,_events,_api){function showToastFromNotification(notification){return options=notification.title,Emby.importModule("./modules/toast/toast.js").then(function(toast){return toast(options)});var options}function showNotification(notification,apiClient){if("undefined"==typeof Notification||!navigator.serviceWorker||!Emby.serviceWorkerEnabled)return showToastFromNotification(notification);notification.timestamp=Date.now(),notification.renotify=!0,notification.tag+=apiClient.serverId(),!notification.data&&notification.actions&&(notification.data=apiClient.serverId());function onFailure(){return showToastFromNotification(notification)}navigator.serviceWorker.getRegistration().then(function(reg){return Notification.requestPermission().then(function(permission){return"granted"!==permission?showToastFromNotification(notification):reg.showNotification(notification.title,notification).catch(onFailure)})},onFailure)}function showPackageInstallNotification(apiClient,installation,status){apiClient.getCurrentUser().then(function(user){user.Policy.IsAdministrator&&(user={tag:status},"PackageInstallationCompleted"===status?(user.title=_globalize.default.translate("PackageInstallCompleted").replace("{0}",installation.Name+" "+installation.Version),user.actions=[{action:"restartserver",title:_globalize.default.translate("RestartServer")}]):"PackageInstallationCancelled"===status?user.title=_globalize.default.translate("PackageInstallCancelled").replace("{0}",installation.Name+" "+installation.Version):"PackageInstallationFailed"===status?user.title=_globalize.default.translate("PackageInstallFailed").replace("{0}",installation.Name+" "+installation.Version):"PackageInstalling"===status&&(user.title=_globalize.default.translate("InstallingPackage").replace("{0}",installation.Name+" "+installation.Version),installation.PercentComplete)&&(user.body=installation.PercentComplete+"%"),user.title)&&showNotification(user,apiClient)})}_events.default.on(_api.default,"PackageInstallationCompleted",function(e,apiClient,data){showPackageInstallNotification(apiClient,data,"PackageInstallationCompleted")}),_events.default.on(_api.default,"PackageInstallationFailed",function(e,apiClient,data){showPackageInstallNotification(apiClient,data,"PackageInstallationFailed")}),_events.default.on(_api.default,"PackageInstallationCancelled",function(e,apiClient,data){showPackageInstallNotification(apiClient,data,"PackageInstallationCancelled")}),_events.default.on(_api.default,"PackageInstalling",function(e,apiClient,data){showPackageInstallNotification(apiClient,data,"PackageInstalling")}),_events.default.on(_api.default,"ServerShuttingDown",function(e,apiClient,data){showNotification({title:_globalize.default.translate("ServerNameIsShuttingDown",apiClient.serverName()),tag:"ServerShuttingDown"},apiClient)}),_events.default.on(_api.default,"ServerRestarting",function(e,apiClient,data){showNotification({title:_globalize.default.translate("ServerNameIsRestarting",apiClient.serverName()),tag:"ServerRestarting"},apiClient)}),_events.default.on(_api.default,"RestartRequired",function(e,apiClient){showNotification({title:_globalize.default.translate("PleaseRestartServerName",apiClient.serverName()),tag:"RestartRequired",actions:[{action:"restartserver",title:_globalize.default.translate("RestartServer")}]},apiClient)})});