import{t as e}from"./dist-DPmmj29U.js";import{t}from"./useQuery-CQCUTxAw.js";import{t as n}from"./useCurrentUser-boOMG5Xx.js";import{t as r}from"./parseAddr-CsIsUI6W.js";function i(){let{nostr:i}=e(),{user:a}=n(),o=t({queryKey:[`custom-emojis`,a?.pubkey??``],queryFn:async({signal:e})=>{if(!a)return[];let t=await i.query([{kinds:[10030],authors:[a.pubkey],limit:1}],{signal:e});if(t.length===0)return[];let n=t[0],o=[];for(let e of n.tags)e[0]===`emoji`&&e[1]&&e[2]&&o.push({shortcode:e[1],url:e[2],packId:``});let s=[];for(let e of n.tags)if(e[0]===`a`&&e[1]){let t=r(e[1]);t&&t.kind===30030&&s.push(t)}if(s.length>0){let t=s.map(e=>({kinds:[30030],authors:[e.pubkey],"#d":[e.identifier],limit:1}));try{let n=await i.query(t,{signal:e});for(let e of n){let t=e.tags.find(([e])=>e===`d`)?.[1]??``;for(let n of e.tags)n[0]===`emoji`&&n[1]&&n[2]&&o.push({shortcode:n[1],url:n[2],packId:t})}}catch{}}let c=new Map;for(let e of o){let t=c.get(e.shortcode);t?t.push(e):c.set(e.shortcode,[e])}let l=new Set;for(let[e,t]of c)new Set(t.map(e=>e.url)).size>1&&l.add(e);let u=[],d=new Set;for(let e of o){let t=l.has(e.shortcode)&&e.packId?`${e.packId}-${e.shortcode}`:e.shortcode;d.has(t)||(d.add(t),u.push({shortcode:t,url:e.url}))}return u},enabled:!!a,staleTime:5*6e4,gcTime:10*6e4});return{emojis:o.data??[],isLoading:o.isLoading}}export{i as t};