import{c as _,as as d,D as b,bY as w,bQ as R,bZ as M,b_ as W,b$ as A,r as N,m as y,aA as P,N as F,c0 as h,a_ as D}from"./vendor-DtjVbdLs.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-D5bkQlXq.js";import{A as j,D as q}from"./types-zo7pMMkl.js";D(V);const{getModuleSettings:x}=G(B);function Q(){let r=!1,o,e;const p=O(),{mutate:E}=d(j),{mutate:T}=d(q),l=b("saved-fcm-token",null);async function S(){if(!await w())return;const a=x(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 s=M(t);o=W(s),await navigator.serviceWorker.register(C,{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:I})=>c===v.type&&I===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=_(Q);export{J as useWebPushNotificationsModule};
//# sourceMappingURL=useWebPushNotificationsModule-Df-RrRij.js.map
