import{Y as I,Q as i,r as f}from"./DgRzpAjP.js";const v=20,m="nodePerformanceHistory",N=I("nodeRecommendation",()=>{const s=f(new Map),u=i("scoringWeights",{latency:50,stability:30,successRate:20}),a=i("excludedNodes",[]),T=i("autoSwitchToRecommended",!1),h=i("minTestInterval",1),y=f({total:0,completed:0,current:null,isRunning:!1}),g=()=>{try{const e=localStorage.getItem(m);if(e){const t=JSON.parse(e);s.value=new Map(Object.entries(t))}}catch(e){console.warn("Failed to load node performance data:",e)}},d=()=>{try{const e=Object.fromEntries(s.value);localStorage.setItem(m,JSON.stringify(e))}catch(e){console.warn("Failed to save node performance data:",e)}},p=(e,t,c)=>{const n=Date.now(),o=s.value.get(e),l={timestamp:n,latency:t,success:c};o?(o.history=[l,...o.history].slice(0,v),o.lastTestTime=n,o.score=null):s.value.set(e,{nodeName:e,history:[l],lastTestTime:n,score:null}),d()},S=e=>{const t=Date.now();for(const[c,n]of Object.entries(e)){const o=n>0,l={timestamp:t,latency:o?n:null,success:o},r=s.value.get(c);r?(r.history=[l,...r.history].slice(0,v),r.lastTestTime=t,r.score=null):s.value.set(c,{nodeName:c,history:[l],lastTestTime:t,score:null})}d()},w=e=>s.value.get(e),R=e=>a.value.includes(e),x=e=>{const t=a.value.indexOf(e);t>=0?a.value.splice(t,1):a.value.push(e)},E=()=>{s.value.clear(),localStorage.removeItem(m)},O=e=>{u.value={...u.value,...e}};return g(),{performanceData:s,scoringWeights:u,excludedNodes:a,autoSwitchEnabled:T,minTestInterval:h,batchTestProgress:y,recordTestResult:p,recordBatchResults:S,getNodePerformance:w,isExcluded:R,toggleExclusion:x,clearAllData:E,updateWeights:O,loadFromStorage:g,saveToStorage:d}});export{N as u};
