import{c as I,aa as m,C as _,bW as w,bO as R,bX as W,bY as M,bZ as y,r as A,E as N,aj as P,ax as h,b_ as F,aT as C}from"./vendor-CsGITfgk.js";import{j as D,aa as G,ab as L,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 U,a9 as V}from"./index-CsCqMgta.js";import{A as j,D as x}from"./types-zo7pMMkl.js";C(V);const{getModuleSettings:q}=D(B);function X(){let r=!1,o,e;const p=O(),{mutate:E}=m(j),{mutate:T}=m(x),l=_("saved-fcm-token",null);async function S(){if(!await w())return;const a=q(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=W(t);o=M(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,d)}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 d(){try{r&&o&&await F(o),e&&await T({command:{token:e}})}catch(a){g.error(d.name,a)}}function k(a){const{favIcons:i}=H(),t=A(i.value??[]),s=N(()=>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 Q=I(X);export{Q as useWebPushNotificationsModule};
//# sourceMappingURL=useWebPushNotificationsModule-O3euf59z.js.map
