import{c as _,aq as d,D as b,bY as w,bQ as R,bZ as M,b_ as W,b$ as y,r as N,m as A,ay as P,N as F,c0 as h,a_ as D}from"./vendor-BeMjADS_.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-hIFmQ6q1.js";import{A as q,D as j}from"./types-zo7pMMkl.js";D(V);const{getModuleSettings:x}=G(B);function Q(){let r=!1,o,e;const p=O(),{mutate:E}=d(q),{mutate:T}=d(j),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 n=M(t);o=W(n),await navigator.serviceWorker.register(C,{scope:f});const s=await navigator.serviceWorker.getRegistration(f);await u(o,i,s),s?.active?.postMessage({type:"initialize",config:t}),r=!0,k(s),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(n){g.error(u.name,n)}}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??[]),n=A(()=>t.value?.find(({type:c,sizes:I})=>c===v.type&&I===v.sizes)?.href??K),{on:s}=P(U);s(c=>{t.value=c?.favicons??[]}),F(n,()=>{a?.active?.postMessage({type:"update-icon",icon:n.value})},{immediate:!0})}return{initModule:S}}const J=_(Q);export{J as useWebPushNotificationsModule};
//# sourceMappingURL=useWebPushNotificationsModule-CAa-siDT.js.map
