const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./C1H_OB9n.js","./BQCsJfSh.js","./DURqPrI0.js","./5z6Kzs-b.js","./yjcpNk9y.js","./B3GRdcTn.js","./DM3z28FY.js","./DzOcMAzI.js","../assets/settings.BkyZlcdC.css"])))=>i.map(i=>d[i]);
import{ag as m,bO as j,as as R}from"./DURqPrI0.js";import{_ as L}from"./DM3z28FY.js";import{l5 as D,ny as G,mA as U,kM as y,la as W,eQ as F,bo as H,mM as I,lo as K,hp as w,dW as z,k9 as k,k8 as V,fo as C,ku as x,he as J,mx as Y,l$ as Q,j1 as X,a0 as q,j2 as Z,kK as $,b$ as _,mc as tt,hd as et,h1 as at,fN as st}from"./BQCsJfSh.js";import{a as rt}from"./Mf9ziyUv.js";import{h as ot,C as P,ad as nt,ab as it,al as ct,W as ut,aj as ft,ak as ht}from"./RrweKcqb.js";import{a4 as dt,C as lt}from"./CSZ2C-U5.js";import{k as pt}from"./BtHNt0Dj.js";import{p as E}from"./BSpZGo8_.js";const S=D("Badge",{web:()=>L(()=>import("./C1H_OB9n.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8]),import.meta.url).then(t=>new t.BadgeWeb)}),i=G(rt({key:"checked",defaultValue:{},storage:pt})),mt=t=>i.get()[t],gt=t=>m(i,$(t)),kt=t=>i.update(z(t,k())),b=j(void 0),yt=()=>{let t="";const s=a=>a.split("/").map((e,r,c)=>c.slice(0,r+1).join("/")).slice(1);return E.subscribe(a=>{i.update(e=>{for(const r of s(t))e[r]=k();return e}),setTimeout(()=>{const e=R(b);i.update(r=>{for(const c of s(a.url.pathname))e&&c===e||(r[c]=k());return r})},300),t=a.url.pathname})},B="checked",bt=1380*60;let p;const A=async()=>{const t=Q.get();if(t)return(!p||k()-p.created_at>bt)&&(p=await t.sign(await X(q,"GET"))),Z(p)},_t=async()=>{const t=await A();if(!t)return;const s=await fetch(C(`kv/${B}`),{headers:{authorization:t}});if(!s.ok)return;const a=x(await s.text());a&&i.update(e=>{for(const[r,c]of Object.entries(a))J(c,e[r])&&(e[r]=c);return e})},v=Y(3e3,async()=>{const t=await A();if(t)try{await fetch(C(`kv/${B}`),{method:"POST",headers:{authorization:t},body:JSON.stringify(i.get())})}catch{}}),Pt=()=>{let t=!1;const s=y.subscribe(e=>{t=!1,p=void 0,e&&_t().then(()=>{t=!0,v()})}),a=i.subscribe(()=>{t&&y.get()&&v()});return()=>{s(),a()}},O=m(U(1e3,m([y,i,ot,W,dt,F({tracker:I,repository:K,filters:[{kinds:[H,...P]},nt(P)]})],w)),([t,s,a,e,r,c])=>{const l=(o,n)=>{if(!n||n.pubkey===t)return!1;for(const[u,h]of Object.entries(s))if((u==="*"||u.startsWith(o)||u==="/chat/*"&&o.startsWith("/chat/"))&&h>n.created_at)return!1;return!0},f=new Set;for(const{pubkeys:o,messages:n}of a.values()){const u=it(o);l(u,n[0])&&(f.add("/chat"),f.add(u))}const T=_.length>0?_:lt(r);for(const o of T){const n=ct(o),u=tt((c.get(o)||new Map).values());if(ut(e.get(o))){for(const[h,[d]]of et(g=>at("h",g.tags),u))if(h){const g=ft(o,h);l(g,d)&&(f.add(g),l(n,d)&&f.add(n))}}else{const h=ht(o),d=st(u);l(h,d)&&(f.add(h),l(n,d)&&f.add(n))}}return f}),M=m([E,O,b],([t,s,a])=>new Set([...s].filter(e=>!!(!t.url.pathname.startsWith(e)||a&&e===a)))),vt=()=>m([M,V],w).subscribe(async([t,s])=>{if(s.badge)try{await S.set({count:t.size})}catch{}else await N()}),N=async()=>{try{await S.clear()}catch{}},Nt=Object.freeze(Object.defineProperty({__proto__:null,allNotifications:O,checked:i,clearBadges:N,deferredRoomPath:b,deriveChecked:gt,getChecked:mt,notifications:M,setChecked:kt,syncBadges:vt,syncChecked:yt,syncCheckedRemote:Pt},Symbol.toStringTag,{value:"Module"}));export{S as B,N as a,gt as b,i as c,b as d,Nt as e,vt as f,yt as g,Pt as h,M as n,kt as s};
//# sourceMappingURL=7wtNjeph.js.map
