import{s as r,ad as m,ae as v,af as w,ag as T,U as b,ah as y,ai as x,x as h,aj as S,ak as L}from"./index-f325A3R6.js";const p=e=>({name:e.tag,type:e.type,now:"",history:e.urlTestDelay>0?[{time:new Date().toISOString(),delay:e.urlTestDelay}]:[],extra:{},udp:!0,icon:""});let a=new Map,c=new Map,l=[],g="",u=null;const f=()=>{const e={};for(const t of c.values())e[t.tag]=p(t);for(const t of a.values())for(const o of t.items)e[o.tag]||(e[o.tag]=p(o));for(const t of a.values())e[t.tag]={name:t.tag,type:t.type,now:t.selected,all:t.items.map(o=>o.tag),history:[],extra:{},udp:!0,icon:""};for(const t of a.values())for(const o of t.items){const s=e[o.tag];s&&!s.all?.length&&o.urlTestDelay>0&&(s.history=[{time:new Date().toISOString(),delay:o.urlTestDelay}])}for(const t of x.value){const o=e[t.name];o&&(o.icon=t.icon)}h.value=e,S.value=Array.from(a.values()).filter(t=>t.items.length).map(t=>t.tag),L.value=[]},P=()=>{l.forEach(e=>e.close()),l=[],g="",u=null},d=()=>{P(),a=new Map,c=new Map},D=()=>{const e=b.value,t=r()?.client;if(!e||e.type!=="singbox"||!t){d();return}if(g===e.uuid&&l.length)return;d(),g=e.uuid;let o,s=!1;u=new Promise(n=>o=n),l=[y("groups",n=>{a=new Map;for(const i of n.group)a.set(i.tag,i);f(),s||(s=!0,o())}),y("outbounds",n=>{c=new Map;for(const i of n.outbounds)c.set(i.tag,i);f()})]},R=()=>d(),k=async()=>{D(),u&&await u,f()},C=async(e,t)=>{const o=r()?.client;if(!o)return;await o.selectOutbound({groupTag:e,outboundTag:t});const s=a.get(e);s&&(s.selected=t,f()),m.value&&v.value.filter(n=>w(n).includes(e)).forEach(n=>T(n.id))},I=async(e,t,o,s)=>{const n=r()?.client;n&&await n.uRLTest({outboundTag:s||e})},A=async e=>{const t=r()?.client;t&&await t.uRLTest({outboundTag:e})},O=async()=>{const e=r()?.client;e&&await Promise.allSettled(Array.from(a.keys()).map(t=>e.uRLTest({outboundTag:t})))};export{O as allProxiesLatencyTest,k as fetchProxies,C as handlerProxySelect,A as proxyGroupLatencyTest,I as proxyLatencyTest,R as resetProxies};
