import{t as e}from"./axios-CYLKoSFs.js";import{t}from"./tiktokGifts-DfCadSx2.js";var n=`overinteractive_gifts_v3`;function r(){try{let e=localStorage.getItem(n);if(e){let t=JSON.parse(e),n=t?.gifts??t;if(Array.isArray(n)&&n.length>0){let e=n.filter(e=>e.scope===`general`||e.source===1||e.source===2);if(e.length>0)return[...e].sort((e,t)=>e.coins-t.coins)}}}catch(e){console.log(e)}return c(t)}var i=`overinteractive:gifts-cache-updated`;async function a(){try{let t=await e.get(`/api/gifts`),r=Array.isArray(t.data)?t.data:[];r.length>0&&(localStorage.setItem(n,JSON.stringify({gifts:r,ts:Date.now()})),window.dispatchEvent(new Event(i)))}catch(e){console.warn(`[OverInteractive] Gift cache refresh failed:`,e)}}function o(e,n){let r=e.gifts??[],i=e.giftNames??[],a=e.giftImages??[];if(r.length===0&&i.length===0)return[];let o=e=>n.find(t=>t.id===e||t.idAliases?.includes(e))??t.find(t=>t.id===e),s=e=>{let r=e.trim().toLowerCase();return n.find(e=>e.name.trim().toLowerCase()===r)??t.find(e=>e.name.trim().toLowerCase()===r)};if(i.length>0){let e=new Set,t=[];for(let n=0;n<i.length;n++){let r=i[n],o=r.trim().toLowerCase();if(e.has(o))continue;e.add(o);let c=a[n],l=c?void 0:s(r);t.push({imgUrl:c??l?.imgUrl,emoji:l?.emoji,name:r})}return t}let c=new Set,l=[];for(let e of r){let t=o(e),n=t?.id??e;c.has(n)||(c.add(n),l.push(t?{imgUrl:t.imgUrl,emoji:t.emoji,name:t.name}:{name:e}))}return l}function s(e,t){for(let n of o(e,t))if(n.imgUrl)return n.imgUrl;return null}function c(e){let t=new Map;for(let n of e){let e=n.name.toLowerCase(),r=t.get(e);(!r||l(n.id,r.id)>0)&&t.set(e,n)}return[...t.values()].sort((e,t)=>e.coins-t.coins)}function l(e,t){let n=parseInt(e,10),r=parseInt(t,10);return!isNaN(n)&&!isNaN(r)?n-r:e.localeCompare(t)}export{s as a,o as i,r as n,a as r,i as t};