import{c as I,as as d,C as _,bX as w,bC as R,bY as M,bZ as W,b_ as y,r as N,ay as A,N as P,b$ as h,aZ as F,m as C}from"./vendor-Di1tOLi3.js";import{k as D,ab as G,ac as L,ad as f,q as O,ae as z,a7 as B,L as g,af as H,ag as K,a9 as U,ah as V,ai as v}from"./index-BrdDZgk2.js";import{A as q,D as Z}from"./types-zo7pMMkl.js";F(U);const{getModuleSettings:x}=D(B);function X(){let r=!1,o,e;const p=O(),{mutate:E}=d(q),{mutate:T}=d(Z),l=_("saved-fcm-token",null);async function k(){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,S(n),p.on(z,m)}async function u(a,i,t){try{if(e=await y(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 S(a){const{favIcons:i}=H(),t=N(i.value??[]),s=C(()=>t.value?.find(({type:c,sizes:b})=>c===v.type&&b===v.sizes)?.href??V),{on:n}=A(K);n(c=>{t.value=c?.favicons??[]}),P(s,()=>{a?.active?.postMessage({type:"update-icon",icon:s.value})},{immediate:!0})}return{initModule:k}}const J=I(X);export{J as useWebPushNotificationsModule};
//# sourceMappingURL=useWebPushNotificationsModule-CBlR-BlX.js.map
