import{_ as S,o as n,c as d,a as y,t as c,b as a,w as i,a8 as x,j as h,V,d as m,x as g,a7 as b,F as p,J as C,a2 as P,aw as k,Q as v,N as _,Y as R,u as G}from"./index-WOIPm_2l.js";const w={setup(){const{tm:t}=G("features/settings");return{tm:t}},data(){return{githubProxies:["https://edgeone.gh-proxy.com","https://hk.gh-proxy.com/","https://gh-proxy.com/","https://gh.llkk.cc"],githubProxyRadioControl:"0",selectedGitHubProxy:"",radioValue:"0",loadingTestingConnection:!1,testingProxies:{},proxyStatus:{},initializing:!0}},methods:{getProxyByControl(t){const e=String(t);if(e==="-1")return"";const l=Number.parseInt(e,10);return Number.isNaN(l)?"":this.githubProxies[l]||""},async testSingleProxy(t){this.testingProxies[t]=!0;const e=this.githubProxies[t];try{const l=await R.post("/api/stat/test-ghproxy-connection",{proxy_url:e});console.log(l.data),l.status===200?this.proxyStatus[t]={available:!0,latency:Math.round(l.data.data.latency)}:this.proxyStatus[t]={available:!1,latency:0}}catch{this.proxyStatus[t]={available:!1,latency:0}}finally{this.testingProxies[t]=!1}},async testAllProxies(){this.loadingTestingConnection=!0;const t=this.githubProxies.map((e,l)=>this.testSingleProxy(l));await Promise.all(t),this.loadingTestingConnection=!1}},mounted(){this.initializing=!0;const t=localStorage.getItem("selectedGitHubProxy")||"",e=localStorage.getItem("githubProxyRadioValue")||"0",l=String(localStorage.getItem("githubProxyRadioControl")||"0");this.radioValue=e,this.githubProxyRadioControl=l,e==="1"?l!=="-1"?this.selectedGitHubProxy=this.getProxyByControl(l):this.selectedGitHubProxy=t:this.selectedGitHubProxy="",this.initializing=!1},watch:{selectedGitHubProxy:function(t,e){this.initializing||(t||(t=""),localStorage.setItem("selectedGitHubProxy",t))},radioValue:function(t){this.initializing||(localStorage.setItem("githubProxyRadioValue",t),String(t)==="0"?this.selectedGitHubProxy="":String(this.githubProxyRadioControl)!=="-1"&&(this.selectedGitHubProxy=this.getProxyByControl(this.githubProxyRadioControl)))},githubProxyRadioControl:function(t){if(this.initializing)return;const e=String(t);if(localStorage.setItem("githubProxyRadioControl",e),String(this.radioValue)!=="1"){this.selectedGitHubProxy="";return}e!=="-1"&&(this.selectedGitHubProxy=this.getProxyByControl(e))}}},H={key:0,style:{"margin-left":"16px"}},z={class:"d-flex align-center"},B={class:"mr-2"},N={key:0};function I(t,e,l,r,o,f){return n(),d(p,null,[y("h5",null,c(r.tm("network.proxySelector.title")),1),a(b,{class:"mt-2",modelValue:o.radioValue,"onUpdate:modelValue":e[0]||(e[0]=s=>o.radioValue=s),"hide-details":"true"},{default:i(()=>[a(x,{label:r.tm("network.proxySelector.noProxy"),value:"0"},null,8,["label"]),a(x,{value:"1"},{label:i(()=>[y("span",null,c(r.tm("network.proxySelector.useProxy")),1),o.radioValue==="1"?(n(),h(V,{key:0,class:"ml-2",onClick:f.testAllProxies,size:"x-small",variant:"tonal",loading:o.loadingTestingConnection},{default:i(()=>[m(c(r.tm("network.proxySelector.testConnection")),1)]),_:1},8,["onClick","loading"])):g("",!0)]),_:1})]),_:1},8,["modelValue"]),a(_,null,{default:i(()=>[o.radioValue==="1"?(n(),d("div",H,[a(b,{modelValue:o.githubProxyRadioControl,"onUpdate:modelValue":e[2]||(e[2]=s=>o.githubProxyRadioControl=s),class:"mt-2","hide-details":"true"},{default:i(()=>[(n(!0),d(p,null,C(o.githubProxies,(s,u)=>(n(),h(x,{color:"success",key:s,value:String(u)},{label:i(()=>[y("div",z,[y("span",B,c(s),1),o.proxyStatus[u]?(n(),d("div",N,[a(P,{color:o.proxyStatus[u].available?"success":"error",size:"x-small",class:"mr-1"},{default:i(()=>[m(c(o.proxyStatus[u].available?r.tm("network.proxySelector.available"):r.tm("network.proxySelector.unavailable")),1)]),_:2},1032,["color"]),o.proxyStatus[u].available?(n(),h(P,{key:0,color:"info",size:"x-small"},{default:i(()=>[m(c(o.proxyStatus[u].latency)+"ms ",1)]),_:2},1024)):g("",!0)])):g("",!0)])]),_:2},1032,["value"]))),128)),a(x,{color:"primary",value:"-1",label:r.tm("network.proxySelector.custom")},k({_:2},[String(o.githubProxyRadioControl)==="-1"?{name:"label",fn:i(()=>[a(v,{density:"compact",modelValue:o.selectedGitHubProxy,"onUpdate:modelValue":e[1]||(e[1]=s=>o.selectedGitHubProxy=s),variant:"outlined",style:{width:"100vw"},placeholder:r.tm("network.proxySelector.custom"),"hide-details":"true"},null,8,["modelValue","placeholder"])]),key:"0"}:void 0]),1032,["label"])]),_:1},8,["modelValue"])])):g("",!0)]),_:1})],64)}const F=S(w,[["render",I]]);export{F as P};
