import{c as I,as as d,C as _,bX as w,bC as R,bY as M,bZ as W,b_ as N,r as y,m as A,az as P,N as h,b$ as F,a_ as C}from"./vendor-BmRNukEL.js";import{l as D,ac as G,ad as L,ae as f,q as O,af as z,aa as B,L as g,ag as H,ah as K,ai as v,aj as U,ab as V}from"./index-PU-0vjEQ.js";import{A as q,D as j}from"./types-zo7pMMkl.js";C(V);const{getModuleSettings:x}=D(B);function X(){let r=!1,o,e;const p=O(),{mutate:E}=d(q),{mutate:T}=d(j),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 N(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 F(o),e&&await T({command:{token:e}})}catch(a){g.error(m.name,a)}}function k(a){const{favIcons:i}=H(),t=y(i.value??[]),s=A(()=>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??[]}),h(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--EhzWV24.js.map
