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 h,b$ as F,aV as D}from"./vendor-d3O24IFR.js";import{j as G,aa as L,ab as C,ac as f,o as O,ad as z,a8 as B,L as g,ae as H,af as K,ag as v,ah as V,a9 as U}from"./index-DtNTt4xe.js";import{A as q,D as x}from"./types-zo7pMMkl.js";D(U);const{getModuleSettings:j}=G(B);function X(){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=j(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 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=P(i.value??[]),s=y(()=>t.value?.find(({type:c,sizes:b})=>c===v.type&&b===v.sizes)?.href??K),{on:n}=A(V);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-COv7ym0W.js.map
