import{c as k,$ as l,d as A,M as d,b as c,au as x,aF as D,P as N}from"./app-QjDgb7aF.js";import{b as T,u as a,j as f,g as y,i as w,J as g,D as h,H as U,a as b}from"./vue-Cm77DuTi.js";const R=T({__name:"MkPushNotificationAllowButton",props:{primary:{type:Boolean},gradate:{type:Boolean},rounded:{type:Boolean},inline:{type:Boolean},link:{type:Boolean},to:{},autofocus:{type:Boolean},wait:{type:Boolean},danger:{type:Boolean},full:{type:Boolean},showOnlyToRegister:{type:Boolean}},setup(e,{expose:C}){let o=b(),r=b(!1),n=b(null),i=b();function P(){if(!(!o.value||!r.value||!k.swPublickey))return x(o.value.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:S(k.swPublickey)}).then(async t=>{n.value=t,i.value=await A("sw/register",{endpoint:t.endpoint,auth:p(t.getKey("auth")),publickey:p(t.getKey("p256dh"))})},async t=>{if(t?.name==="NotAllowedError"){console.info("User denied the notification permission request.");return}await m()}),null,null)}async function m(){if(!n.value)return;const t=n.value.endpoint,u=await D();i.value=void 0,l&&u.length>=2?N("sw/unregister",{i:l.token,endpoint:t}):(n.value.unsubscribe(),N("sw/unregister",{endpoint:t}),n.value=null)}function p(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t)))}function S(t){const u="=".repeat((4-t.length%4)%4),M=(t+u).replace(/-/g,"+").replace(/_/g,"/"),v=window.atob(M),B=new Uint8Array(v.length);for(let s=0;s<v.length;++s)B[s]=v.charCodeAt(s);return B}return navigator.serviceWorker==null||navigator.serviceWorker.ready.then(async t=>{if(o.value=t,n.value=await o.value.pushManager.getSubscription(),k.swPublickey&&"PushManager"in window&&l&&l.token&&(r.value=!0,n.value)){const u=await A("sw/show-registration",{endpoint:n.value.endpoint});u&&(i.value=u)}}),C({pushRegistrationInServer:i}),(t,u)=>a(r)&&!a(i)?(f(),y(d,{key:0,type:"button",primary:"",gradate:e.gradate,rounded:e.rounded,inline:e.inline,autofocus:e.autofocus,wait:e.wait,full:e.full,onClick:P},{default:w(()=>[g(h(a(c).ts.subscribePushNotification),1)]),_:1},8,["gradate","rounded","inline","autofocus","wait","full"])):!e.showOnlyToRegister&&(a(l)?a(i):a(n))?(f(),y(d,{key:1,type:"button",primary:!1,gradate:e.gradate,rounded:e.rounded,inline:e.inline,autofocus:e.autofocus,wait:e.wait,full:e.full,onClick:m},{default:w(()=>[g(h(a(c).ts.unsubscribePushNotification),1)]),_:1},8,["gradate","rounded","inline","autofocus","wait","full"])):a(l)&&a(i)?(f(),y(d,{key:2,disabled:"",rounded:e.rounded,inline:e.inline,wait:e.wait,full:e.full},{default:w(()=>[g(h(a(c).ts.pushNotificationAlreadySubscribed),1)]),_:1},8,["rounded","inline","wait","full"])):a(r)?U("",!0):(f(),y(d,{key:3,disabled:"",rounded:e.rounded,inline:e.inline,wait:e.wait,full:e.full},{default:w(()=>[g(h(a(c).ts.pushNotificationNotSupported),1)]),_:1},8,["rounded","inline","wait","full"]))}});export{R as _};
//# sourceMappingURL=MkPushNotificationAllowButton.vue_vue_type_script_setup_true_lang-DvaRqget.js.map
