import{c as I,aq as d,D as _,bX as w,bP as R,bY as M,bZ as W,b_ as N,r as P,m as y,ax as A,N as F,b$ as h,aZ as D}from"./vendor-CB-jpi5M.js";import{j as G,a9 as L,aa as C,ab as f,n as O,ac as z,a7 as B,L as g,ad as H,ae as K,af as v,ag as U,a8 as V}from"./index-B-IqqSSt.js";import{A as q,D as x}from"./types-zo7pMMkl.js";D(V);const{getModuleSettings:Z}=G(B);function j(){let r=!1,o,e;const p=O(),{mutate:E}=d(q),{mutate:T}=d(x),l=_("saved-fcm-token",null);async function S(){if(!await w())return;const a=Z(L),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(C,{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 N(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=P(i.value??[]),n=y(()=>t.value?.find(({type:c,sizes:b})=>c===v.type&&b===v.sizes)?.href??K),{on:s}=A(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(j);export{J as useWebPushNotificationsModule};
//# sourceMappingURL=useWebPushNotificationsModule-DQIYIkfG.js.map
