import{c as I,at as d,C as _,bX as w,bC as R,bY as M,bZ as W,b_ as A,r as N,m as y,aA as P,N as F,b$ as h,a_ as C}from"./vendor-sJIIH5Cr.js";import{j as D,a8 as G,a9 as L,aa as f,n as O,ab as z,a6 as B,L as g,ac as H,ad as K,ae as v,af as U,a7 as V}from"./index-BGo1APpE.js";import{A as j,D as q}from"./types-zo7pMMkl.js";C(V);const{getModuleSettings:x}=D(B);function X(){let r=!1,o,e;const p=O(),{mutate:E}=d(j),{mutate:T}=d(q),l=_("saved-fcm-token",null);async function S(){if(!await w())return;const a=x(G),i=a?.vapidKey,t=R(a,"vapidKey");if(r&&o){const c=await navigator.serviceWorker.getRegistration(f);await u(o,i,c);return}const n=M(t);o=W(n),await navigator.serviceWorker.register(L,{scope:f});const s=await navigator.serviceWorker.getRegistration(f);await u(o,i,s),s?.active?.postMessage({type:"initialize",config:t}),r=!0,k(s),p.on(z,m)}async function u(a,i,t){try{if(e=await A(a,{vapidKey:i,serviceWorkerRegistration:t}),e&&e!==l.value&&(await E({command:{token:e}}),l.value=e),e)return;await Notification.requestPermission()}catch(n){g.error(u.name,n)}}async function m(){try{r&&o&&await h(o),e&&await T({command:{token:e}})}catch(a){g.error(m.name,a)}}function k(a){const{favIcons:i}=H(),t=N(i.value??[]),n=y(()=>t.value?.find(({type:c,sizes:b})=>c===v.type&&b===v.sizes)?.href??K),{on:s}=P(U);s(c=>{t.value=c?.favicons??[]}),F(n,()=>{a?.active?.postMessage({type:"update-icon",icon:n.value})},{immediate:!0})}return{initModule:S}}const J=I(X);export{J as useWebPushNotificationsModule};
//# sourceMappingURL=useWebPushNotificationsModule-CW-KpA2z.js.map
