import{c as I,as as d,D 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 D}from"./vendor-D0AQuxPe.js";import{j as C,a9 as G,aa as L,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-BZGh_npj.js";import{A as j,D as q}from"./types-zo7pMMkl.js";D(V);const{getModuleSettings:x}=C(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 s=M(t);o=W(s),await navigator.serviceWorker.register(L,{scope:f});const n=await navigator.serviceWorker.getRegistration(f);await u(o,i,n),n?.active?.postMessage({type:"initialize",config:t}),r=!0,k(n),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(s){g.error(u.name,s)}}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??[]),s=y(()=>t.value?.find(({type:c,sizes:b})=>c===v.type&&b===v.sizes)?.href??K),{on:n}=P(U);n(c=>{t.value=c?.favicons??[]}),F(s,()=>{a?.active?.postMessage({type:"update-icon",icon:s.value})},{immediate:!0})}return{initModule:S}}const J=I(X);export{J as useWebPushNotificationsModule};
//# sourceMappingURL=useWebPushNotificationsModule-U-tJ0YO7.js.map
