define(["serverNotifications","playbackManager","events","globalize","require"],function(serverNotifications,playbackManager,events,globalize,require){"use strict";function onOneDocumentClick(){document.removeEventListener("click",onOneDocumentClick),document.removeEventListener("keydown",onOneDocumentClick),window.Notification&&Notification.requestPermission()}function closeAfter(notification,timeoutMs){setTimeout(function(){notification.close?notification.close():notification.cancel&¬ification.cancel()},timeoutMs)}function resetRegistration(){var serviceWorker=navigator.serviceWorker;serviceWorker&&serviceWorker.ready.then(function(registration){serviceWorkerRegistration=registration})}function showPersistentNotification(title,options,timeoutMs){serviceWorkerRegistration.showNotification(title,options)}function showNonPersistentNotification(title,options,timeoutMs){try{var notif=new Notification(title,options);notif.show&¬if.show(),timeoutMs&&closeAfter(notif,timeoutMs)}catch(err){if(!options.actions)throw err;options.actions=[],showNonPersistentNotification(title,options,timeoutMs)}}function showNotification(options,timeoutMs,apiClient){var title=options.title;return options.data=options.data||{},options.data.serverId=apiClient.serverInfo().Id,options.icon=options.icon||getIconUrl(),options.badge=options.badge||getIconUrl("badge.png"),resetRegistration(),serviceWorkerRegistration?void showPersistentNotification(title,options,timeoutMs):void showNonPersistentNotification(title,options,timeoutMs)}function showNewItemNotification(item,apiClient){if(!playbackManager.isPlayingLocally(["Video"])){var body=item.Name;item.SeriesName&&(body=item.SeriesName+" - "+body);var notification={title:"New "+item.Type,body:body,vibrate:!0,tag:"newItem"+item.Id,data:{}},imageTags=item.ImageTags||{};imageTags.Primary&&(notification.icon=apiClient.getScaledImageUrl(item.Id,{width:80,tag:imageTags.Primary,type:"Primary"})),showNotification(notification,15e3,apiClient)}}function onLibraryChanged(data,apiClient){var newItems=data.ItemsAdded;newItems.length&&apiClient.getItems(apiClient.getCurrentUserId(),{Recursive:!0,Limit:3,Filters:"IsNotFolder",SortBy:"DateCreated",SortOrder:"Descending",Ids:newItems.join(","),MediaTypes:"Audio,Video"}).then(function(result){for(var items=result.Items,i=0,length=items.length;i