"use strict";var push=function(){function i(){return new Promise(function(n){navigator.serviceWorker.getRegistration().then(function(t){return t&&navigator.serviceWorker.controller||navigator.serviceWorker.register("/sw.js").then(function(){n(t)}).catch(function(n){if(n.name=="SecurityError"||n.name=="NotSupportedError"){show_err("Could not start.<br>This page requires a secure server. (e.g. one that can serve https:// pages). <br>The page can also be served from `localhost'.");return}}),t})})}function r(){return new Promise(function(t){navigator.serviceWorker.getRegistration().then(function(i){i&&i.pushManager?i.pushManager.getSubscription().then(function(r){if(r&&r.endpoint&&r.getKey&&r.getKey("p256dh")){var u={endpoint:r.endpoint,token:n.encode(r.getKey("p256dh"))};r.getKey("auth")&&(u.authToken=n.encode(r.getKey("auth")));t(u)}else r||i.pushManager.subscribe({userVisibleOnly:!0}).then(function(i){if(i&&i.endpoint&&i.getKey&&i.getKey("p256dh")){var r={endpoint:i.endpoint,token:n.encode(i.getKey("p256dh"))};i.getKey("auth")&&(r.authToken=n.encode(i.getKey("auth")));t(r)}})}).catch(function(){t(null)}):t(null)}).catch(function(){t(null)})})}function u(t){var i=new Promise(function(i){navigator.serviceWorker.getRegistration().then(function(r){r.pushManager.subscribe({userVisibleOnly:!0}).then(function(r){if(!r.endpoint){let n=new Error;n.name="NoEndpoint";n.message="Subscription does not have an endpoint";throw n;}if(!r.getKey){let n=new Error;n.name="NoData";n.message="Subscription does not allow data";throw n;}var u={token:n.encode(r.getKey("p256dh")),endpoint:r.endpoint};r.getKey("auth")&&(u.authToken=n.encode(r.getKey("auth")));t||WebApiHandler.post("/api/PushNotifications/registerBrowser",JSON.stringify(u),function(){},function(){alert("There was an error subscribing to push notifications. If the problem persists please contact support.")});try{let n=r.getKey("auth");n}catch(f){}return i(u),r.endpoint}).catch(function(){})}).catch(function(){})})}function t(n,i,r){"Notification"in window&&Notification.permission==="granted"&&push.getSubscriptionInfo().then(function(u){u?($("#"+n).val(u.endpoint),$("#"+r).val(u.token),u.authToken&&$("#"+i).val(u.authToken)):push.register().then(function(){push.subscribe(!0).then(function(u){u&&t(n,i,r)})})})}var n={_strmap:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",encode:function(n){for(var i="",r=new Uint8Array(n),f=r.byteLength,u,t=0;t<f;t++)i+=String.fromCharCode(r[t]);return u=window.btoa(i),u.replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")},_lookup:function(t,i){return n._strmap.indexOf(t.charAt(i))},decode:function(t){for(var r=new Uint8Array(Math.floor(t.length*3/4)),u=0,i=0;i<t.length;){var o=n._lookup(t,i++),f=n._lookup(t,i++),e=n._lookup(t,i++),s=n._lookup(t,i++);r[u++]=o<<2|f>>>4;r[u++]=f<<4|e>>>2;r[u++]=e<<6|s}return r}};return"ServiceWorker"in navigator&&navigator.serviceWorker.addEventListener("message",function(n){n.data.type=="postActivate"&&push.subscribe();n.data.type=="content"&&notify("Got message",n.data.content)}),{subscribe:u,register:i,getSubscriptionInfo:r,handleNotificationReauth:t}}()