define(["libraryBrowser","listViewStyle"],function(libraryBrowser){"use strict";function notifications(){var self=this;self.getNotificationsSummaryPromise=null,self.total=0,self.getNotificationsSummary=function(){var apiClient=window.ApiClient;if(apiClient)return self.getNotificationsSummaryPromise=self.getNotificationsSummaryPromise||apiClient.getNotificationSummary(Dashboard.getCurrentUserId()),self.getNotificationsSummaryPromise},self.updateNotificationCount=function(){if(Dashboard.getCurrentUserId()&&window.ApiClient){var promise=self.getNotificationsSummary();promise&&promise.then(function(summary){var btnNotificationsInner=document.querySelector(".btnNotificationsInner");btnNotificationsInner&&(btnNotificationsInner.classList.remove("levelNormal"),btnNotificationsInner.classList.remove("levelWarning"),btnNotificationsInner.classList.remove("levelError"),btnNotificationsInner.innerHTML=summary.UnreadCount,summary.UnreadCount&&btnNotificationsInner.classList.add("level"+summary.MaxUnreadNotificationLevel))})}},self.markNotificationsRead=function(ids,callback){ApiClient.markNotificationsRead(Dashboard.getCurrentUserId(),ids,!0).then(function(){self.getNotificationsSummaryPromise=null,self.updateNotificationCount(),callback&&callback()})},self.showNotificationsList=function(startIndex,limit,elem){refreshNotifications(startIndex,limit,elem,!0)}}function refreshNotifications(startIndex,limit,elem,showPaging){var apiClient=window.ApiClient;if(apiClient)return apiClient.getNotifications(Dashboard.getCurrentUserId(),{StartIndex:startIndex,Limit:limit}).then(function(result){listUnreadNotifications(result.Notifications,result.TotalRecordCount,startIndex,limit,elem,showPaging)})}function listUnreadNotifications(list,totalRecordCount,startIndex,limit,elem,showPaging){if(!totalRecordCount)return void elem.html('

'+Globalize.translate("LabelNoUnreadNotifications")+"

");Notifications.total=totalRecordCount;var html="";if(totalRecordCount>limit&&showPaging===!0){var query={StartIndex:startIndex,Limit:limit};html+=libraryBrowser.getQueryPagingHtml({startIndex:query.StartIndex,limit:query.Limit,totalRecordCount:totalRecordCount,showLimit:!1,updatePageSizeSetting:!1})}require(["humanedate"],function(){for(var i=0,length=list.length;i'),itemHtml+='
',itemHtml+="Error"==notification.Level?'error':'dvr',itemHtml+='
',itemHtml+='

',itemHtml+=notification.Name,itemHtml+="

",itemHtml+='
',itemHtml+=humane_date(notification.Date),itemHtml+="
",notification.Description&&(itemHtml+='
',itemHtml+=notification.Description,itemHtml+="
"),itemHtml+="
",itemHtml+="
",notification.Url&&(itemHtml+=""),itemHtml}function onWebSocketMessage(e,msg){"NotificationUpdated"!==msg.MessageType&&"NotificationAdded"!==msg.MessageType&&"NotificationsMarkedRead"!==msg.MessageType||(Notifications.getNotificationsSummaryPromise=null,Notifications.updateNotificationCount())}function initializeApiClient(apiClient){Events.off(apiClient,"websocketmessage",onWebSocketMessage),Events.on(apiClient,"websocketmessage",onWebSocketMessage)}window.Notifications=new notifications;var needsRefresh=!0;window.ApiClient&&initializeApiClient(window.ApiClient),Events.on(ConnectionManager,"apiclientcreated",function(e,apiClient){initializeApiClient(apiClient)}),Events.on(ConnectionManager,"localusersignedin",function(){needsRefresh=!0}),Events.on(ConnectionManager,"localusersignedout",function(){needsRefresh=!0}),pageClassOn("pageshow","type-interior",function(){needsRefresh&&Notifications.updateNotificationCount()})});