var ot=Object.defineProperty,at=Object.defineProperties;var lt=Object.getOwnPropertyDescriptors;var Le=Object.getOwnPropertySymbols;var rt=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable;var Ie=(n,t,s)=>t in n?ot(n,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[t]=s,b=(n,t)=>{for(var s in t||(t={}))rt.call(t,s)&&Ie(n,s,t[s]);if(Le)for(var s of Le(t))ct.call(t,s)&&Ie(n,s,t[s]);return n},M=(n,t)=>at(n,lt(t));import{R as e,c as v,f as it,r as m,a as ae,E as ze,b as ut,d as Z,e as we,u as Ee,g as Ce,h as U,i as He,j as be,k as ee,l as Oe,m as mt,n as he,o as dt,p as Ne,q as pt,s as Pe,t as ft,v as Et,w as ht,x as yt,y as xt,z as gt,A as vt,B as wt,C as Ct,D as bt,F as Nt,G as Pt,H as St,N as kt,O as Dt,I as Ft,J as pe,K as At,L as $t,M as Lt}from"./vendor.4a7a512f.js";const It=function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))o(a);new MutationObserver(a=>{for(const l of a)if(l.type==="childList")for(const r of l.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&o(r)}).observe(document,{childList:!0,subtree:!0});function s(a){const l={};return a.integrity&&(l.integrity=a.integrity),a.referrerpolicy&&(l.referrerPolicy=a.referrerpolicy),a.crossorigin==="use-credentials"?l.credentials="include":a.crossorigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function o(a){if(a.ep)return;a.ep=!0;const l=s(a);fetch(a.href,l)}};It();function ne(){return navigator.userAgent==="ClashX Runtime"}let P=null;class Rt{constructor(t){this.instance=null,window.WebViewJavascriptBridge!=null&&(this.instance=window.WebViewJavascriptBridge),this.initBridge(s=>{this.instance=s,t()})}initBridge(t){if(!ne())return t==null?void 0:t(null);if(window.WebViewJavascriptBridge!=null)return t(window.WebViewJavascriptBridge);if(window.WVJBCallbacks!=null)return window.WVJBCallbacks.push(t);window.WVJBCallbacks=[t];const s=document.createElement("iframe");s.style.display="none",s.src="https://__bridge_loaded__",document.documentElement.appendChild(s),setTimeout(()=>document.documentElement.removeChild(s),0)}async callHandler(t,s){return await new Promise(o=>{var a;(a=this.instance)==null||a.callHandler(t,s,o)})}async ping(){return await this.callHandler("ping")}async readConfigString(){return await this.callHandler("readConfigString")}async getPasteboard(){return await this.callHandler("getPasteboard")}async getAPIInfo(){return await this.callHandler("apiInfo")}async setPasteboard(t){return await this.callHandler("setPasteboard",t)}async writeConfigWithString(t){return await this.callHandler("writeConfigWithString",t)}async setSystemProxy(t){return await this.callHandler("setSystemProxy",t)}async getStartAtLogin(){return await this.callHandler("getStartAtLogin")}async getProxyDelay(t){return await this.callHandler("speedTest",t)}async setStartAtLogin(t){return await this.callHandler("setStartAtLogin",t)}async isSystemProxySet(){return await this.callHandler("isSystemProxySet")}}function Tt(n){if(P!=null){n();return}P=new Rt(n)}function q(n){const{title:t,children:s,className:o,style:a}=n;return e.createElement("header",{className:v("header",o),style:a},e.createElement("h1",{className:"md:text-xl"},t),e.createElement("div",{className:"flex flex-auto items-center justify-end"},s))}function O(n){const{type:t,size:s=14,className:o,style:a}=n,l=v("clash-iconfont",`icon-${t}`,o),r=b({fontSize:s},a),i=M(b({},n),{className:l,style:r});return e.createElement("i",b({},i))}function G(){}function Bt(n,t){const s=[],o=[];for(const a of n)t(a)?s.push(a):o.push(a);return[s,o]}function _(n){var o;const t=["B","KB","MB","GB","TB"],s=Math.floor(Math.log(n||1)/Math.log(1024));return`${it(n/Math.pow(1024,s),2).toFixed(2)} ${(o=t==null?void 0:t[s])!=null?o:""}`}function Ue(n){return n.replace(/.*[/\\]/,"")}function fe(n){const{className:t,checked:s=!1,disabled:o=!1,onChange:a=G}=n,l=v("switch",{checked:s,disabled:o},t);function r(){o||a(!s)}return e.createElement("div",{className:l,onClick:r},e.createElement(O,{className:"switch-icon font-bold",type:"check",size:20}))}const H=m.exports.forwardRef((n,t)=>{const{className:s,style:o,children:a}=n;return e.createElement("div",{className:v("card",s),style:o,ref:t},a)});function Re(n){const{options:t,value:s,onSelect:o}=n;return e.createElement("div",{className:"button-select"},t.map(a=>e.createElement("button",{value:a.value,key:a.value,className:v("button-select-options",{actived:s===a.value}),onClick:()=>o==null?void 0:o(a.value)},a.label)))}const Mt={SideBar:{Proxies:"Proxies",Overview:"Overview",Logs:"Logs",Rules:"Rules",Settings:"Setting",Connections:"Connections",Version:"Version"},Settings:{title:"Settings",labels:{startAtLogin:"Start at login",language:"language",setAsSystemProxy:"Set as system proxy",allowConnectFromLan:"Allow Lan",proxyMode:"Mode",logLevel:"Log Level",redirProxyPort:"Redir proxy port",socks5ProxyPort:"Socks5 proxy port",httpProxyPort:"HTTP proxy port",mixedProxyPort:"Mixed proxy port",externalController:"External controller"},values:{cn:"\u4E2D\u6587",en:"English",global:"Global",rules:"Rules",direct:"Direct",script:"Script"},versionString:"Current ClashX is the latest version\uFF1A{{version}}",checkUpdate:"Check Update",externalControllerSetting:{title:"External Controller",note:"Please note that modifying this configuration will only configure Dashboard. Will not modify your Clash configuration file. Please make sure that the external controller address matches the address in the Clash configuration file, otherwise, Dashboard will not be able to connect to Clash.",host:"Host",port:"Port",secret:"Secret"}},Logs:{title:"Logs",levelLabel:"Log level"},Rules:{title:"Rules",providerTitle:"Providers",providerUpdateTime:"Last updated at",ruleCount:"Rule count"},Connections:{title:"Connections",keepClosed:"Keep closed connections",total:{text:"total",upload:"upload",download:"download"},closeAll:{title:"Warning",content:"This would close all connections"},filter:{all:"All"},columns:{host:"Host",network:"Network",type:"Type",chains:"Chains",process:"Process",rule:"Rule",time:"Time",speed:"Speed",upload:"Upload",download:"Download",sourceIP:"Source IP",destinationIP:"Destination IP"},info:{title:"Connection",id:"ID",host:"Host",hostEmpty:"Empty",dstIP:"Target",dstIPEmpty:"Empty",srcIP:"Source",upload:"Upload",download:"Download",network:"Network",process:"Process",processPath:"Path",inbound:"Inbound",rule:"Rule",chains:"Chains",status:"Status",opening:"Open",closed:"Closed",closeConnection:"Close"}},Proxies:{title:"Proxies",editDialog:{title:"Edit Proxy",color:"Color",name:"Name",type:"Type",server:"Server",port:"Port",password:"Password",cipher:"Cipher",obfs:"Obfs","obfs-host":"Obfs-host",uuid:"UUID",alterId:"AlterId",tls:"TLS"},groupTitle:"Policy Group",providerTitle:"Providers",providerUpdateTime:"Last updated at",expandText:"Expand",collapseText:"Collapse",speedTestText:"Speed Test",breakConnectionsText:"Close connections which include the group"},Modal:{ok:"Ok",cancel:"Cancel"}},zt={SideBar:{Proxies:"\u4EE3\u7406",Overview:"\u603B\u89C8",Logs:"\u65E5\u5FD7",Rules:"\u89C4\u5219",Settings:"\u8BBE\u7F6E",Connections:"\u8FDE\u63A5",Version:"\u7248\u672C"},Settings:{title:"\u8BBE\u7F6E",labels:{startAtLogin:"\u5F00\u673A\u65F6\u542F\u52A8",language:"\u8BED\u8A00",setAsSystemProxy:"\u8BBE\u7F6E\u4E3A\u7CFB\u7EDF\u4EE3\u7406",allowConnectFromLan:"\u5141\u8BB8\u6765\u81EA\u5C40\u57DF\u7F51\u7684\u8FDE\u63A5",proxyMode:"\u4EE3\u7406\u6A21\u5F0F",logLevel:"\u65E5\u5FD7\u7B49\u7EA7",redirProxyPort:"Redir \u4EE3\u7406\u7AEF\u53E3",socks5ProxyPort:"Socks5 \u4EE3\u7406\u7AEF\u53E3",httpProxyPort:"HTTP \u4EE3\u7406\u7AEF\u53E3",mixedProxyPort:"\u6DF7\u5408\u4EE3\u7406\u7AEF\u53E3",externalController:"\u5916\u90E8\u63A7\u5236\u8BBE\u7F6E"},values:{cn:"\u4E2D\u6587",en:"English",global:"\u5168\u5C40",rules:"\u89C4\u5219",direct:"\u76F4\u8FDE",script:"\u811A\u672C"},versionString:"\u5F53\u524D ClashX \u5DF2\u662F\u6700\u65B0\u7248\u672C\uFF1A{{version}}",checkUpdate:"\u68C0\u67E5\u66F4\u65B0",externalControllerSetting:{title:"\u7F16\u8F91\u5916\u90E8\u63A7\u5236\u8BBE\u7F6E",note:"\u8BF7\u6CE8\u610F\uFF0C\u4FEE\u6539\u8BE5\u914D\u7F6E\u9879\u5E76\u4E0D\u4F1A\u4FEE\u6539\u4F60\u7684 Clash \u914D\u7F6E\u6587\u4EF6\uFF0C\u8BF7\u786E\u8BA4\u4FEE\u6539\u540E\u7684\u5916\u90E8\u63A7\u5236\u5730\u5740\u548C Clash \u914D\u7F6E\u6587\u4EF6\u5185\u7684\u5730\u5740\u4E00\u81F4\uFF0C\u5426\u5219\u4F1A\u5BFC\u81F4 Dashboard \u65E0\u6CD5\u8FDE\u63A5\u3002",host:"Host",port:"\u7AEF\u53E3",secret:"\u5BC6\u94A5"}},Logs:{title:"\u65E5\u5FD7",levelLabel:"\u65E5\u5FD7\u7B49\u7EA7"},Rules:{title:"\u89C4\u5219",providerTitle:"\u89C4\u5219\u96C6",providerUpdateTime:"\u6700\u540E\u66F4\u65B0\u4E8E",ruleCount:"\u89C4\u5219\u6761\u6570"},Connections:{title:"\u8FDE\u63A5",keepClosed:"\u4FDD\u7559\u5173\u95ED\u8FDE\u63A5",total:{text:"\u603B\u91CF",upload:"\u4E0A\u4F20",download:"\u4E0B\u8F7D"},closeAll:{title:"\u8B66\u544A",content:"\u5C06\u4F1A\u5173\u95ED\u6240\u6709\u8FDE\u63A5"},filter:{all:"\u5168\u90E8"},columns:{host:"\u57DF\u540D",network:"\u7F51\u7EDC",process:"\u8FDB\u7A0B",type:"\u7C7B\u578B",chains:"\u8282\u70B9\u94FE",rule:"\u89C4\u5219",time:"\u8FDE\u63A5\u65F6\u95F4",speed:"\u901F\u7387",upload:"\u4E0A\u4F20",download:"\u4E0B\u8F7D",sourceIP:"\u6765\u6E90 IP",destinationIP:"\u76EE\u6807 IP"},info:{title:"\u8FDE\u63A5\u4FE1\u606F",id:"ID",host:"\u57DF\u540D",hostEmpty:"\u7A7A",dstIP:"\u76EE\u6807 IP",dstIPEmpty:"\u7A7A",srcIP:"\u6765\u6E90",upload:"\u4E0A\u4F20",download:"\u4E0B\u8F7D",network:"\u7F51\u7EDC",process:"\u8FDB\u7A0B",processPath:"\u8DEF\u5F84",inbound:"\u5165\u53E3",rule:"\u89C4\u5219",chains:"\u4EE3\u7406",status:"\u72B6\u6001",opening:"\u8FDE\u63A5\u4E2D",closed:"\u5DF2\u5173\u95ED",closeConnection:"\u5173\u95ED\u8FDE\u63A5"}},Proxies:{title:"\u4EE3\u7406",editDialog:{title:"\u7F16\u8F91\u4EE3\u7406",color:"\u989C\u8272",name:"\u540D\u5B57",type:"\u7C7B\u578B",server:"\u670D\u52A1\u5668",port:"\u7AEF\u53E3",password:"\u5BC6\u7801",cipher:"\u52A0\u5BC6\u65B9\u5F0F",obfs:"Obfs","obfs-host":"Obfs-host",uuid:"UUID",alterId:"AlterId",tls:"TLS"},groupTitle:"\u7B56\u7565\u7EC4",providerTitle:"\u4EE3\u7406\u96C6",providerUpdateTime:"\u6700\u540E\u66F4\u65B0\u4E8E",expandText:"\u5C55\u5F00",collapseText:"\u6536\u8D77",speedTestText:"\u6D4B\u901F",breakConnectionsText:"\u5207\u6362\u65F6\u6253\u65AD\u5305\u542B\u7B56\u7565\u7EC4\u7684\u8FDE\u63A5"},Modal:{ok:"\u786E \u5B9A",cancel:"\u53D6 \u6D88"}},je={en_US:Mt,zh_CN:zt},Ht=Object.keys(je);function Ot(){for(const n of window.navigator.languages){if(n.includes("zh"))return"zh_CN";if(n.includes("us"))return"en_US"}return"en_US"}function Se(n){return m.exports.useMemo(()=>{function s(o,a){if(typeof o=="string")n(l=>{const r=o,i=a;l[r]=i});else if(typeof o=="function"){const l=o;n(r=>l(r))}else typeof o=="object"&&n(l=>ae(l,r=>{const i=o;for(const u of Object.keys(i)){const h=u;r[h]=i[h]}}))}return s},[n])}class We{constructor(t){this.EE=new ze,this.innerBuffer=[],this.url="",this.connection=null,this.config=Object.assign({bufferLength:0,retryInterval:5e3},t)}connectWebsocket(){const t=new URL(this.url);this.connection=new WebSocket(t.toString()),this.connection.addEventListener("message",s=>{const o=JSON.parse(s.data);this.EE.emit("data",[o]),this.config.bufferLength>0&&(this.innerBuffer.push(o),this.innerBuffer.length>this.config.bufferLength&&this.innerBuffer.splice(0,this.innerBuffer.length-this.config.bufferLength))}),this.connection.addEventListener("error",s=>{var o;this.EE.emit("error",s),(o=this.connection)==null||o.close(),setTimeout(this.connectWebsocket,this.config.retryInterval)})}connect(t){var s;this.url===t&&this.connection||(this.url=t,(s=this.connection)==null||s.close(),this.connectWebsocket())}subscribe(t,s){this.EE.addListener(t,s)}unsubscribe(t,s){this.EE.removeListener(t,s)}buffer(){return this.innerBuffer.slice()}destory(){var t;this.EE.removeAllListeners(),(t=this.connection)==null||t.close(),this.connection=null}}class Ut{constructor(t,s){this.axiosClient=ut.create({baseURL:t,headers:s?{Authorization:`Bearer ${s}`}:{}})}async getConfig(){return await this.axiosClient.get("configs")}async updateConfig(t){return await this.axiosClient.patch("configs",t)}async getRules(){return await this.axiosClient.get("rules")}async getProxyProviders(){const t=await this.axiosClient.get("providers/proxies",{validateStatus(s){return s>=200&&s<300||s===404}});return t.status===404&&(t.data={providers:{}}),t}async getRuleProviders(){return await this.axiosClient.get("providers/rules")}async updateProvider(t){return await this.axiosClient.put(`providers/proxies/${encodeURIComponent(t)}`)}async updateRuleProvider(t){return await this.axiosClient.put(`providers/rules/${encodeURIComponent(t)}`)}async healthCheckProvider(t){return await this.axiosClient.get(`providers/proxies/${encodeURIComponent(t)}/healthcheck`)}async getProxies(){return await this.axiosClient.get("proxies")}async getProxy(t){return await this.axiosClient.get(`proxies/${encodeURIComponent(t)}`)}async getVersion(){return await this.axiosClient.get("version")}async getProxyDelay(t){return await this.axiosClient.get(`proxies/${encodeURIComponent(t)}/delay`,{params:{timeout:5e3,url:"http://www.gstatic.com/generate_204"}})}async closeAllConnections(){return await this.axiosClient.delete("connections")}async closeConnection(t){return await this.axiosClient.delete(`connections/${t}`)}async getConnections(){return await this.axiosClient.get("connections")}async changeProxySelected(t,s){return await this.axiosClient.put(`proxies/${encodeURIComponent(t)}`,{name:s})}}const jt=Z(async()=>{if(!ne())return null;const n=await P.getAPIInfo();return{hostname:n.host,port:n.port,secret:n.secret,protocol:"http:"}}),_e=we("externalControllers",[]);function re(){var h,f,E,d,p,w,g,A,k,D,V,N,j,I,$;const n=Ee(jt),t=Ce(),s=Ee(_e);if(n!=null)return n;let o;{const R=document.querySelector('meta[name="external-controller"]');((h=R==null?void 0:R.content)==null?void 0:h.match(/^https?:/))!=null&&(o=new URL(R.content))}const a=new URLSearchParams(t.search),l=(p=(d=(E=a.get("host"))!=null?E:(f=s==null?void 0:s[0])==null?void 0:f.hostname)!=null?d:o==null?void 0:o.hostname)!=null?p:"127.0.0.1",r=(k=(A=(g=a.get("port"))!=null?g:(w=s==null?void 0:s[0])==null?void 0:w.port)!=null?A:o==null?void 0:o.port)!=null?k:"9090",i=(j=(N=(V=a.get("secret"))!=null?V:(D=s==null?void 0:s[0])==null?void 0:D.secret)!=null?N:o==null?void 0:o.username)!=null?j:"",u=((I=a.get("protocol"))!=null?I:l==="127.0.0.1")?"http:":($=o==null?void 0:o.protocol)!=null?$:window.location.protocol;return{hostname:l,port:r,secret:i,protocol:u}}const Wt=Z({key:"",instance:null});function z(){const{hostname:n,port:t,secret:s,protocol:o}=re(),[a,l]=U(Wt),r=`${o}//${n}:${t}?secret=${s}`;if(a.key===r)return a.instance;const i=new Ut(`${o}//${n}:${t}`,s);return l({key:r,instance:i}),i}const ke=Z(!0),_t=we("language",void 0);function S(){const[n,t]=U(_t),s=m.exports.useMemo(()=>n!=null?n:Ot(),[n]),o=m.exports.useCallback(function(a){function l(r){return dt(je[s][a],r)}return{t:l}},[s]);return{lang:s,locales:Ht,setLang:t,translation:o}}const Ge=Z({version:"",premium:!1,meta:!1});function Ve(){const[n,t]=U(Ge),s=z(),o=be(ke);return ee([s],async function(){const a=await Oe.fromPromise(s.getVersion(),l=>l);o(a.isOk()),t(a.isErr()?{version:"",premium:!1,meta:!1}:{version:a.value.data.version,premium:!!a.value.data.premium,meta:!!a.value.data.meta})}),n}function Je(){const[{premium:n,meta:t}]=U(Ge),s=z(),{data:o,mutate:a}=ee(["/providers/rule",s,n,t],async()=>{if(!n&&!t)return[];const l=await s.getRuleProviders();return Object.keys(l.data.providers).map(r=>l.data.providers[r])});return{providers:o!=null?o:[],update:a}}const Gt=we("profile",{breakConnections:!1,logLevel:""});function me(){const[n,t]=U(Gt),s=m.exports.useCallback(o=>{t(ae(n,o))},[n,t]);return{data:n,set:Se(s)}}const Xe=Z([]);function qe(){const[n,t]=U(Xe),s=z(),{data:o,mutate:a}=ee(["/providers/proxy",s],async()=>{const l=await s.getProxyProviders();return Object.keys(l.data.providers).map(r=>l.data.providers[r]).filter(r=>r.name!=="default").filter(r=>r.vehicleType!=="Compatible")});return m.exports.useEffect(()=>{t(o!=null?o:[])},[o,t]),{providers:n,update:a}}function De(){const n=z(),{data:t,mutate:s}=ee(["/config",n],async()=>{var l;const a=(await n.getConfig()).data;return{port:a.port,socksPort:a["socks-port"],mixedPort:(l=a["mixed-port"])!=null?l:0,redirPort:a["redir-port"],mode:a.mode.toLowerCase(),logLevel:a["log-level"],allowLan:a["allow-lan"]}});return{general:t!=null?t:{},update:s}}const Ke=He({proxies:[],groups:[],global:{name:"GLOBAL",type:"Selector",now:"",history:[],all:[]}});function de(){const[n,t]=U(Ke),s=Se(t),o=z(),{mutate:a}=ee(["/proxies",o],async()=>{const r=await o.getProxies(),i=r.data.proxies.GLOBAL;i.name="GLOBAL";const u=new Set(["Selector","URLTest","Fallback","LoadBalance"]),h=new Set(["DIRECT","REJECT","GLOBAL"]),f=i.all.filter(p=>!h.has(p)).map(p=>M(b({},r.data.proxies[p]),{name:p})),[E,d]=Bt(f,p=>!u.has(p.type));s({proxies:E,groups:d,global:i})}),l=m.exports.useCallback((r,i)=>{s(u=>{r==="GLOBAL"&&(u.global.now=i);for(const h of u.groups)h.name===r&&(h.now=i)})},[s]);return{proxies:n.proxies,groups:n.groups,global:n.global,update:a,markProxySelected:l,set:s}}const Ye=Z(n=>{const t=n(Ke),s=n(Xe),o=new Map;for(const a of t.proxies)o.set(a.name,a);for(const a of s)for(const l of a.proxies)o.set(l.name,l);return o});function Qe(){const{data:n,mutate:t}=ee("/clashx",async()=>{var a,l;if(!ne())return{isClashX:!1,startAtLogin:!1,systemProxy:!1};const s=(a=await(P==null?void 0:P.getStartAtLogin()))!=null?a:!1,o=(l=await(P==null?void 0:P.isSystemProxySet()))!=null?l:!1;return{startAtLogin:s,systemProxy:o,isClashX:!0}});return{data:n,update:t}}const Vt=He([]);function Jt(){const[n,t]=U(Vt),s=Se(t),o=z();async function a(){const l=await o.getRules();s(l.data.rules)}return{rules:n,update:a}}const Xt=Z(new We({bufferLength:200}));function Ze(){const n=re(),{general:t}=De(),{data:{logLevel:s}}=me(),o=Ee(Xt),a=s||t.logLevel,l=mt(`${n.protocol}//${n.hostname}:${n.port}/logs?level=${a}&secret=${n.secret}`),r=he(n);return m.exports.useEffect(()=>{if(a){const i=r.current,h=`${i.protocol==="http:"?"ws:":"wss:"}//${i.hostname}:${i.port}/logs?level=${a}&token=${i.secret}`;o.connect(h)}},[r,o,a,l]),o}function qt(){const n=re(),t=m.exports.useRef(new We({bufferLength:200})),o=`${n.protocol==="http:"?"ws:":"wss:"}//${n.hostname}:${n.port}/connections?token=${n.secret}`;return m.exports.useEffect(()=>{t.current.connect(o)},[o]),t.current}const Te={"#909399":0,"#57b366":260,"#ff9a28":600,"#ff3e5e":1/0};function Kt(n){const{className:t,data:s,onClick:o,select:a,canClick:l,errSet:r,rowHeight:i}=n,{translation:u}=S(),{t:h}=u("Proxies"),[f,E]=m.exports.useState(!1),[d,p]=m.exports.useState(!1),[w]=U(Ye),g=m.exports.useRef(null);m.exports.useLayoutEffect(()=>{var N,j;p(((j=(N=g==null?void 0:g.current)==null?void 0:N.offsetHeight)!=null?j:0)>30)},[]);const A=f?"auto":i,k=l?o:G;function D(){E(!f)}const V=s.map(N=>{var te;const I=v(l?"cursor-pointer":"cursor-default",{"tags-selected":a===N,error:r==null?void 0:r.has(N)}),$=(te=w.get(N))==null?void 0:te.history,R=$!=null&&$.length?$.slice(-1)[0].delay:0,se=Object.keys(Te).find(T=>R<=Te[T]);return e.createElement("li",{className:I,key:N,onClick:()=>k(N)},N," ",e.createElement("span",{className:"proxy-delay",style:{color:se}},"\u2003",R===0?"":`${R}ms`," "))});return e.createElement("div",{className:v("flex items-start overflow-y-hidden",t),style:{height:A}},e.createElement("ul",{ref:g,className:v("tags",{expand:f})},V),d&&e.createElement("span",{className:"h-7 px-5 select-none cursor-pointer leading-7",onClick:D},h(f?"collapseText":"expandText")))}function Q(n){const{className:t,style:s,value:o="",align:a="center",inside:l=!1,autoFocus:r=!1,type:i="text",disabled:u=!1,onChange:h=G,onBlur:f=G,onEnter:E=G}=n,d=v("input",`text-${a}`,{"focus:shadow-none":l},t);function p(w){w.code==="Enter"&&E(w)}return e.createElement("input",{disabled:u,className:d,style:s,value:o,autoFocus:r,type:i,onChange:w=>h(w.target.value,w),onBlur:f,onKeyDown:p})}function Yt(n){const{value:t,options:s,onSelect:o,className:a,style:l}=n,r=m.exports.useRef(document.createElement("div")),i=m.exports.useRef(null),[u,h]=m.exports.useState(!1),[f,E]=m.exports.useState({});m.exports.useLayoutEffect(()=>{const g=i.current.getBoundingClientRect();E({top:Math.floor(g.top+g.height)+6,left:Math.floor(g.left)-10})},[]),m.exports.useLayoutEffect(()=>{const g=r.current;return document.body.appendChild(g),()=>{document.body.removeChild(g)}},[]);function d(){h(!u)}const p=m.exports.useMemo(()=>s.find(g=>g.value===t),[t,s]),w=e.createElement("div",{className:v("select-list",{"select-list-show":u}),style:f},e.createElement("ul",{className:"list"},s.map(g=>{var A;return e.createElement(Qt,{className:v({selected:g.value===t}),onClick:k=>{o==null||o(g.value,k),h(!1)},disabled:g.disabled,key:(A=g.key)!=null?A:g.value,value:g.value},g.label)})));return e.createElement(e.Fragment,null,e.createElement("div",{className:v("select",a),style:l,ref:i,onClick:d},p==null?void 0:p.label,e.createElement(O,{type:"triangle-down"})),Ne.exports.createPortal(w,r.current))}function Qt(n){const{className:t,style:s,disabled:o=!1,children:a,onClick:l=G}=n,r=v("option",{disabled:o},t);return e.createElement("li",{className:r,style:s,onClick:l},a)}function et(n){const{show:t=!0,title:s="Modal",size:o="small",footer:a=!0,onOk:l=G,onClose:r=G,bodyClassName:i,bodyStyle:u,className:h,style:f,children:E}=n,{translation:d}=S(),{t:p}=d("Modal"),w=m.exports.useRef(document.createElement("div")),g=m.exports.useRef(null);m.exports.useLayoutEffect(()=>{const D=w.current;return document.body.appendChild(D),()=>{document.body.removeChild(D)}},[]);function A(D){D.target===g.current&&r()}const k=e.createElement("div",{className:v("modal-mask",{"modal-show":t}),ref:g,onMouseDown:A},e.createElement("div",{className:v("modal",`modal-${o}`,h),style:f},e.createElement("div",{className:"modal-title"},s),e.createElement("div",{className:v("modal-body",i),style:u},E),a&&e.createElement("div",{className:"footer"},e.createElement(ye,{onClick:()=>r()},p("cancel")),e.createElement(ye,{type:"primary",onClick:()=>l()},p("ok")))));return Ne.exports.createPortal(k,w.current)}const Zt={success:"check",info:"info",warning:"info",error:"close"};function en(n){const{message:t="",type:s="info",inside:o=!1,children:a,className:l,style:r}=n,i=v("alert",`alert-${o?"note":"box"}-${s}`,l);return e.createElement("div",{className:i,style:r},e.createElement("span",{className:"alert-icon"},e.createElement(O,{type:Zt[s],size:26})),t?e.createElement("p",{className:"alert-message"},t):e.createElement("div",{className:"alert-message"},a))}function ye(n){const{type:t="normal",onClick:s=G,children:o,className:a,style:l,disiabled:r}=n,i=v("button",`button-${t}`,a,{"button-disabled":r});return e.createElement("button",{className:i,style:l,onClick:s,disabled:r},o)}function ue(n){const[t,s]=pt(n),o=m.exports.useMemo(()=>{function a(l,r){typeof l=="string"?s(i=>{const u=l,h=r;i[u]=h}):typeof l=="function"?s(l):typeof l=="object"&&s(i=>{const u=l;for(const h of Object.keys(u)){const f=h;i[f]=u[f]}})}return a},[s]);return[t,o]}function tn(n,t=0){if(n.length<2)throw new Error("List requires at least two elements");const[s,o]=m.exports.useState(t);function a(){o((s+1)%n.length)}return{current:m.exports.useMemo(()=>n[s],[n,s]),next:a}}function Fe(n=!1){const[t,s]=m.exports.useState(n);function o(){s(!1)}function a(){s(!0)}return{visible:t,hide:o,show:a}}function tt(n){const{className:t,checked:s=!1,onChange:o=G}=n,a=v("checkbox",{checked:s},t);function l(){o(!s)}return e.createElement("div",{className:a,onClick:l},e.createElement(O,{className:"checkbox-icon",type:"check",size:18}),e.createElement("div",null,n.children))}function le(n){const{color:t,className:s,style:o}=n,a=v("tag",s),l=b({color:t},o),r=M(b({},n),{className:a,style:l});return e.createElement("span",b({},r),n.children)}function nn(n){const t=v("spinner",n.className);return e.createElement("div",{className:t},e.createElement("div",{className:"spinner-circle"},e.createElement("div",{className:"spinner-inner"})),e.createElement("div",{className:"spinner-circle"},e.createElement("div",{className:"spinner-inner"})),e.createElement("div",{className:"spinner-circle"},e.createElement("div",{className:"spinner-inner"})),e.createElement("div",{className:"spinner-circle"},e.createElement("div",{className:"spinner-inner"})),e.createElement("div",{className:"spinner-circle"},e.createElement("div",{className:"spinner-inner"})))}function nt(n){const t=v("loading","visible",n.className);return n.visible?e.createElement("div",{className:t},e.createElement(nn,{className:n.spinnerClassName})):null}function sn(n){var a,l,r;const t=m.exports.useRef(document.createElement("div"));m.exports.useLayoutEffect(()=>{const i=t.current;return document.body.appendChild(i),()=>{document.body.removeChild(i)}},[]);const s="absolute h-full right-0 transition-transform transform translate-x-full duration-100 pointer-events-auto",o=e.createElement("div",{className:v(n.className,"absolute inset-0 pointer-events-none z-9999")},e.createElement(H,{className:v(s,n.bodyClassName,{"translate-x-0":n.visible}),style:{width:(a=n.width)!=null?a:400}},n.children));return Ne.exports.createPortal(o,(r=(l=n.containerRef)==null?void 0:l.current)!=null?r:t.current)}Pe.extend(ft);function Ae(n,t){const s=t==="en_US"?"en":"zh-cn";return Pe().locale(s).from(n)}function on(n){const{translation:t}=S(),s=m.exports.useMemo(()=>t("Connections").t,[t]),{className:o,style:a}=n,l=v("flex flex-wrap px-1",o);function r(i){var u;(u=n.onChange)==null||u.call(n,i)}return e.createElement("div",{className:l,style:a},e.createElement("div",{className:v("connections-devices-item pt-2 mb-2",{selected:n.selected===""}),onClick:()=>r("")},s("filter.all")),n.devices.map(i=>e.createElement("div",{key:i.label,className:v("connections-devices-item pt-2 mb-2",{selected:n.selected===i.label}),onClick:()=>r(i.label)},i.label," (",i.number,")")))}function an(n){var o,a,l,r,i,u,h,f,E,d,p,w,g;const{translation:t}=S(),s=m.exports.useMemo(()=>t("Connections").t,[t]);return e.createElement("div",{className:v(n.className,"text-xs flex flex-col overflow-y-auto")},e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.id")),e.createElement("span",{className:"font-mono"},n.connection.id)),e.createElement("div",{className:"flex my-3 justify-between"},e.createElement("div",{className:"flex flex-1"},e.createElement("span",{className:"font-bold w-20"},s("info.network")),e.createElement("span",{className:"font-mono"},(o=n.connection.metadata)==null?void 0:o.network)),e.createElement("div",{className:"flex flex-1"},e.createElement("span",{className:"font-bold w-20"},s("info.inbound")),e.createElement("span",{className:"font-mono"},(a=n.connection.metadata)==null?void 0:a.type))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.host")),e.createElement("span",{className:"font-mono flex-1 break-all"},n.connection.metadata?`${n.connection.metadata.host||n.connection.metadata.destinationIP}:${(l=n.connection.metadata)==null?void 0:l.destinationPort}`:s("info.hostEmpty"))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.dstIP")),e.createElement("span",{className:"font-mono"},n.connection.metadata?`${((r=n.connection.metadata)==null?void 0:r.remoteDestination)||((i=n.connection.metadata)==null?void 0:i.destinationIP)||((u=n.connection.metadata)==null?void 0:u.host)}`:s("info.hostEmpty"))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.srcIP")),e.createElement("span",{className:"font-mono"},`${(h=n.connection.metadata)==null?void 0:h.sourceIP}:${(f=n.connection.metadata)==null?void 0:f.sourcePort}`)),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.process")),e.createElement("span",{className:"font-mono"},(E=n.connection.metadata)!=null&&E.processPath?`${Ue(n.connection.metadata.processPath)}`:s("info.hostEmpty"))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.processPath")),e.createElement("span",{className:"font-mono flex-1 break-all"},(d=n.connection.metadata)!=null&&d.processPath?`${n.connection.metadata.processPath}`:s("info.hostEmpty"))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.rule")),e.createElement("span",{className:"font-mono"},n.connection.rule&&`${n.connection.rule}${n.connection.rulePayload&&` :: ${n.connection.rulePayload}`}`)),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.chains")),e.createElement("span",{className:"font-mono flex-1 break-all"},(p=n.connection.chains)==null?void 0:p.slice().reverse().join(" / "))),e.createElement("div",{className:"flex my-3 justify-between"},e.createElement("div",{className:"flex flex-1"},e.createElement("span",{className:"font-bold w-20"},s("info.upload")),e.createElement("span",{className:"font-mono"},_((w=n.connection.upload)!=null?w:0))),e.createElement("div",{className:"flex flex-1"},e.createElement("span",{className:"font-bold w-20"},s("info.download")),e.createElement("span",{className:"font-mono"},_((g=n.connection.download)!=null?g:0)))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.status")),e.createElement("span",{className:"font-mono"},n.connection.completed?e.createElement("span",{className:"text-red"},s("info.closed")):e.createElement("span",{className:"text-green"},s("info.opening")))))}class ln{constructor(){this.connections=new Map,this.saveDisconnection=!1}appendToSet(t){var o;const s=t.reduce((a,l)=>a.set(l.id,l),new Map);for(const a of this.connections.keys())if(!s.has(a))if(!this.saveDisconnection)this.connections.delete(a);else{const l=this.connections.get(a);l!=null&&this.connections.set(a,ae(l,r=>{r.completed=!0,r.uploadSpeed=0,r.downloadSpeed=0}))}for(const a of s.keys()){if(!this.connections.has(a)){this.connections.set(a,M(b({},s.get(a)),{uploadSpeed:0,downloadSpeed:0}));continue}const l=this.connections.get(a),r=s.get(a);(o=this.connections)==null||o.set(a,M(b({},r),{uploadSpeed:r.upload-l.upload,downloadSpeed:r.download-l.download}))}}toggleSave(){var t,s;if(this.saveDisconnection){this.saveDisconnection=!1;for(const o of this.connections.keys())(s=(t=this.connections)==null?void 0:t.get(o))!=null&&s.completed&&this.connections.delete(o)}else this.saveDisconnection=!0;return this.saveDisconnection}getConnections(){return[...this.connections.values()]}}function rn(){const n=m.exports.useMemo(()=>new ln,[]),t=m.exports.useRef(!0),[s,o]=m.exports.useState([]),[a,l]=m.exports.useState(!1),r=m.exports.useCallback(function(u){n.appendToSet(u),t.current&&o(n.getConnections()),t.current=!t.current},[n]),i=m.exports.useCallback(function(){const u=n.toggleSave();l(u),u||o(n.getConnections()),t.current=!0},[n]);return{connections:s,feed:r,toggleSave:i,save:a}}const x={Host:"host",Network:"network",Process:"process",Type:"type",Chains:"chains",Rule:"rule",Speed:"speed",Upload:"upload",Download:"download",SourceIP:"sourceIP",DestinationIP:"destinationIP",Time:"time"},cn=new Set([x.Network,x.Type,x.Speed,x.Upload,x.Download,x.SourceIP,x.Time,x.Process]);function un(n,t){switch(!0){case(n===0&&t===0):return"-";case(n!==0&&t!==0):return`\u2191 ${_(n)}/s \u2193 ${_(t)}/s`;case n!==0:return`\u2191 ${_(n)}/s`;default:return`\u2193 ${_(t)}/s`}}const F=Et().setRowType();function mn(){const{translation:n,lang:t}=S(),s=m.exports.useMemo(()=>n("Connections").t,[n]),o=qt(),a=he(o),l=z(),r=m.exports.useRef(null),[i,u]=ue({uploadTotal:0,downloadTotal:0}),{visible:h,show:f,hide:E}=Fe();function d(){l.closeAllConnections().finally(()=>E())}const{connections:p,feed:w,save:g,toggleSave:A}=rn(),k=m.exports.useMemo(()=>p.map(c=>({id:c.id,host:`${c.metadata.host||c.metadata.destinationIP}:${c.metadata.destinationPort}`,chains:c.chains.slice().reverse().join(" / "),rule:c.rulePayload?`${c.rule} :: ${c.rulePayload}`:c.rule,time:new Date(c.start).getTime(),upload:c.upload,download:c.download,sourceIP:c.metadata.sourceIP,destinationIP:`${c.metadata.remoteDestination||c.metadata.destinationIP||c.metadata.host}`,type:c.metadata.type,network:c.metadata.network.toUpperCase(),process:c.metadata.processPath,speed:{upload:c.uploadSpeed,download:c.downloadSpeed},completed:!!c.completed,original:c})),[p]),D=m.exports.useMemo(()=>{const c=ht(p,"metadata.sourceIP");return Object.keys(c).map(C=>({label:C,number:c[C].length})).sort((C,y)=>C.label.localeCompare(y.label))},[p]),V=m.exports.useRef(null),N=yt(V,{threshold:[1]}),j=m.exports.useMemo(()=>F.createColumns([F.createDataColumn(x.Host,{minSize:260,size:260,header:s(`columns.${x.Host}`)}),F.createDataColumn(x.Network,{minSize:80,size:80,header:s(`columns.${x.Network}`)}),F.createDataColumn(x.Type,{minSize:100,size:100,header:s(`columns.${x.Type}`)}),F.createDataColumn(x.Chains,{minSize:200,size:200,header:s(`columns.${x.Chains}`)}),F.createDataColumn(x.Rule,{minSize:140,size:140,header:s(`columns.${x.Rule}`)}),F.createDataColumn(x.Process,{minSize:100,size:100,header:s(`columns.${x.Process}`),cell:c=>c.value?Ue(c.value):"-"}),F.createDataColumn(c=>[c.speed.upload,c.speed.download],{id:x.Speed,header:s(`columns.${x.Speed}`),minSize:200,size:200,sortDescFirst:!0,sortingFn(c,C){var W,B,Y,$e;const y=(B=(W=c.original)==null?void 0:W.speed)!=null?B:{upload:0,download:0},L=($e=(Y=C.original)==null?void 0:Y.speed)!=null?$e:{upload:0,download:0};return y.download===L.download?y.upload-L.upload:y.download-L.download},cell:c=>un(c.value[0],c.value[1])}),F.createDataColumn(x.Upload,{minSize:100,size:100,header:s(`columns.${x.Upload}`),cell:c=>_(c.value)}),F.createDataColumn(x.Download,{minSize:100,size:100,header:s(`columns.${x.Download}`),cell:c=>_(c.value)}),F.createDataColumn(x.SourceIP,{minSize:140,size:140,header:s(`columns.${x.SourceIP}`),filterFn:"equals"}),F.createDataColumn(x.DestinationIP,{minSize:140,size:140,header:s(`columns.${x.DestinationIP}`)}),F.createDataColumn(x.Time,{minSize:120,size:120,header:s(`columns.${x.Time}`),cell:c=>Ae(new Date(c.value),t),sortingFn:(c,C)=>{var y,L,W,B;return((L=(y=C.original)==null?void 0:y.time)!=null?L:0)-((B=(W=c.original)==null?void 0:W.time)!=null?B:0)}})]),[t,s]);m.exports.useLayoutEffect(()=>{function c(C){for(const y of C)u({uploadTotal:y.uploadTotal,downloadTotal:y.downloadTotal}),w(y.connections)}return o==null||o.subscribe("data",c),()=>{o==null||o.unsubscribe("data",c)}},[o,w,u]),xt(()=>{var c;(c=a.current)==null||c.destory()});const I=gt(F,{data:k,columns:j,getCoreRowModel:vt(),getSortedRowModel:wt(),getColumnFilteredRowModel:Ct(),initialState:{sorting:[{id:x.Time,desc:!1}]},columnResizeMode:"onChange",enableColumnResizing:!0,autoResetSorting:!1,autoResetColumnFilters:!1}),$=I.getHeaderGroups()[0],[R,se]=m.exports.useState("");function te(c){se(c),I.setColumnFilterValue(x.SourceIP,c||void 0)}const[T,X]=ue({visible:!1,selectedID:"",connection:{}});function J(){X(c=>{c.connection.completed=!0}),l.closeConnection(T.selectedID)}const K=he(T.connection);m.exports.useEffect(()=>{var C;const c=(C=k.find(y=>y.id===T.selectedID))==null?void 0:C.original;c?X(y=>{y.connection=b({},c),T.selectedID===K.current.id&&(y.connection.completed=K.current.completed)}):Object.keys(K.current).length!==0&&!K.current.completed&&X(y=>{y.connection.completed=!0})},[k,T.selectedID,K,X]);const oe=m.exports.useMemo(()=>{var c;return((c=N==null?void 0:N.intersectionRatio)!=null?c:0)<1},[N]),ce=$.headers.map((c,C)=>{const y=c.column,L=y.id;return e.createElement("th",M(b({},c.getHeaderProps(W=>ae(W,B=>{B.className=v("connections-th",{resizing:y.getIsResizing(),fixed:y.id===x.Host,shadow:oe&&y.id===x.Host}),!B.style&&(B.style={}),B.style.width=c.getSize()}))),{ref:y.id===x.Host?V:void 0,key:L}),e.createElement("div",b({},y.getToggleSortingProps()),c.renderHeader(),y.getIsSorted()!==!1?y.getIsSorted()==="desc"?" \u2193":" \u2191":null),C!==$.headers.length-1&&e.createElement("div",M(b({},c.getResizerProps()),{className:"connections-resizer"})))}),ie=I.getRowModel().rows.map(c=>{var C;return e.createElement("tr",M(b({},c.getRowProps()),{className:"cursor-default select-none",key:(C=c.original)==null?void 0:C.id,onClick:()=>{var y;return X({visible:!0,selectedID:(y=c.original)==null?void 0:y.id})}}),c.getAllCells().map(y=>{var W;const L=v("connections-block",{"text-center":cn.has(y.column.id),completed:(W=c.original)==null?void 0:W.completed},{fixed:y.column.id===x.Host,shadow:oe&&y.column.id===x.Host});return e.createElement("td",M(b({},y.getCellProps(B=>ae(B,Y=>{!Y.style&&(Y.style={}),Y.className=L,Y.style.width=y.column.getSize()}))),{key:y.column.id}),y.renderCell())}))});return e.createElement("div",{className:"page !h-100vh"},e.createElement(q,{title:s("title")},e.createElement("span",{className:"cursor-default flex-1 connections-filter"},`(${s("total.text")}: ${s("total.upload")} ${_(i.uploadTotal)} ${s("total.download")} ${_(i.downloadTotal)})`),e.createElement(tt,{className:"connections-filter",checked:g,onChange:A},s("keepClosed")),e.createElement(O,{className:"connections-filter dangerous",onClick:f,type:"close-all",size:20})),D.length>1&&e.createElement(on,{devices:D,selected:R,onChange:te}),e.createElement(H,{ref:r,className:"connections-card relative"},e.createElement("div",{className:"overflow-auto min-h-full min-w-full"},e.createElement("table",b({},I.getTableProps()),e.createElement("thead",null,e.createElement("tr",M(b({},$.getHeaderGroupProps()),{className:"connections-header"}),ce)),e.createElement("tbody",b({},I.getTableBodyProps()),ie)))),e.createElement(et,{title:s("closeAll.title"),show:h,onClose:E,onOk:d},s("closeAll.content")),e.createElement(sn,{containerRef:r,bodyClassName:"flex flex-col bg-[#15222a] text-[#b7c5d6]",visible:T.visible,width:450},e.createElement("div",{className:"flex h-8 justify-between items-center"},e.createElement("span",{className:"font-bold pl-3"},s("info.title")),e.createElement(O,{type:"close",size:16,className:"cursor-pointer",onClick:()=>X("visible",!1)})),e.createElement(an,{className:"mt-3 px-5",connection:T.connection}),e.createElement("div",{className:"flex mt-3 pr-3 justify-end"},e.createElement(ye,{type:"danger",disiabled:T.connection.completed,onClick:()=>J()},s("info.closeConnection")))))}function dn(){const{translation:n}=S(),{t}=n("Settings"),{hostname:s,port:o,secret:a}=re(),[l,r]=U(ke),[i,u]=ue({hostname:"",port:"",secret:""});m.exports.useEffect(()=>{u({hostname:s,port:o,secret:a})},[s,o,a,u]);const h=be(_e);function f(){const{hostname:E,port:d,secret:p}=i;h([{hostname:E,port:d,secret:p}])}return e.createElement(et,{show:!l,title:t("externalControllerSetting.title"),bodyClassName:"external-controller",onClose:()=>r(!0),onOk:f},e.createElement(en,{type:"info",inside:!0},e.createElement("p",null,t("externalControllerSetting.note"))),e.createElement("div",{className:"flex items-center"},e.createElement("span",{className:"font-bold my-1 w-14 md:my-3"},t("externalControllerSetting.host")),e.createElement(Q,{className:"flex-1 my-1 md:my-3",align:"left",inside:!0,value:i.hostname,onChange:E=>u("hostname",E),onEnter:f})),e.createElement("div",{className:"flex items-center"},e.createElement("div",{className:"font-bold my-1 w-14 md:my-3"},t("externalControllerSetting.port")),e.createElement(Q,{className:"flex-1 my-1 w-14 md:my-3",align:"left",inside:!0,value:i.port,onChange:E=>u("port",E),onEnter:f})),e.createElement("div",{className:"flex items-center"},e.createElement("div",{className:"font-bold my-1 w-14 md:my-3"},t("externalControllerSetting.secret")),e.createElement(Q,{className:"flex-1 my-1 w-14 md:my-3",align:"left",inside:!0,value:i.secret,onChange:E=>u("secret",E),onEnter:f})))}const pn=[{label:"Default",value:""},{label:"Debug",value:"debug"},{label:"Info",value:"info"},{label:"Warn",value:"warning"},{label:"Error",value:"error"},{label:"Silent",value:"silent"}],fn=new Map([["debug","text-teal-500"],["info","text-sky-500"],["warning","text-pink-500"],["error","text-rose-500"]]);function En(){var f,E;const n=m.exports.useRef(null),t=m.exports.useRef([]),[s,o]=m.exports.useState([]),{translation:a}=S(),{data:{logLevel:l},set:r}=me(),{t:i}=a("Logs"),u=Ze(),h=m.exports.useRef((E=(f=n.current)==null?void 0:f.scrollHeight)!=null?E:0);return m.exports.useLayoutEffect(()=>{var p;const d=n.current;d!=null&&h.current===d.scrollTop+d.clientHeight&&(d.scrollTop=d.scrollHeight-d.clientHeight),h.current=(p=d==null?void 0:d.scrollHeight)!=null?p:0}),m.exports.useEffect(()=>{function d(p){t.current=t.current.slice().concat(p.map(w=>M(b({},w),{time:new Date}))),o(t.current)}return u!=null&&(u.subscribe("data",d),t.current=u.buffer(),o(t.current)),()=>u==null?void 0:u.unsubscribe("data",d)},[u]),e.createElement("div",{className:"page"},e.createElement(q,{title:i("title")},e.createElement("span",{className:"text-sm text-primary-darken mr-2"},i("levelLabel"),":"),e.createElement(Yt,{options:pn,value:bt(l),onSelect:d=>r(p=>{p.logLevel=d})})),e.createElement(H,{className:"flex flex-col flex-1 mt-2.5 md:mt-4"},e.createElement("ul",{className:"logs-panel",ref:n},s.map((d,p)=>e.createElement("li",{className:"leading-5 inline-block",key:p},e.createElement("span",{className:"mr-2 text-orange-400"},"[",Pe(d.time).format("YYYY-MM-DD HH:mm:ss"),"]"),e.createElement("span",{className:fn.get(d.type)},"[",d.type.toUpperCase(),"]"),e.createElement("span",null," ",d.payload))))))}var xe=(n=>(n.SPEED_NOTIFY="speed-notify",n))(xe||{});class hn{constructor(){this.EE=new ze}notifySpeedTest(){this.EE.emit("speed-notify")}subscribe(t,s){this.EE.addListener(t,s)}unsubscribe(t,s){this.EE.removeListener(t,s)}}var ge=new hn;const Be={"#909399":0,"#57b366":260,"#ff9a28":600,"#ff3e5e":1/0};function st(n){const{config:t,className:s}=n,{set:o}=de(),a=z(),l=m.exports.useCallback(async E=>{var p;if(ne())return(p=await(P==null?void 0:P.getProxyDelay(E)))!=null?p:0;const{data:{delay:d}}=await a.getProxyDelay(E);return d},[a]),r=m.exports.useCallback(async function(){const E=await Oe.fromPromise(l(t.name),p=>p),d=E.isErr()?0:E.value;o(p=>{const w=p.proxies.find(g=>g.name===t.name);w!=null&&w.history.push({time:Date.now().toString(),delay:d})})},[t.name,l,o]),i=m.exports.useMemo(()=>{var E;return(E=t.history)!=null&&E.length?t.history.slice(-1)[0].delay:0},[t]);m.exports.useLayoutEffect(()=>{const E=()=>{r()};return ge.subscribe(xe.SPEED_NOTIFY,E),()=>ge.unsubscribe(xe.SPEED_NOTIFY,E)},[r]);const u=m.exports.useMemo(()=>i===0,[i]),h=m.exports.useMemo(()=>Object.keys(Be).find(E=>i<=Be[E]),[i]),f=u?void 0:h;return e.createElement("div",{className:v("proxy-item",{"proxy-error":u},s)},e.createElement("span",{className:"proxy-type",style:{backgroundColor:f}},t.type),e.createElement("p",{className:"proxy-name"},t.name),e.createElement("p",{className:"proxy-delay",style:{color:h}},i===0?"-":`${i}ms`))}function yn(n){const{markProxySelected:t}=de(),[s]=U(Ye),{data:o}=me(),a=z(),{config:l}=n;async function r(h){if(await a.changeProxySelected(n.config.name,h),t(n.config.name,h),o.breakConnections){const f=[],E=await a.getConnections();for(const d of E.data.connections)d.chains.includes(n.config.name)&&f.push(d.id);await Promise.all(f.map(d=>a.closeConnection(d)))}}const i=m.exports.useMemo(()=>{var f;const h=new Set;for(const E of l.all){const d=(f=s.get(E))==null?void 0:f.history;(d==null?void 0:d.length)&&d.slice(-1)[0].delay===0&&h.add(E)}return h},[l.all,s]),u=l.type==="Selector";return e.createElement("div",{className:"proxy-group"},e.createElement("div",{className:"flex h-10 mt-4 w-full items-center justify-between md:h-15 md:mt-0 md:w-auto "},e.createElement("span",{className:"h-6 px-5 w-35 overflow-hidden overflow-ellipsis whitespace-nowrap md:w-30"},l.name),e.createElement(le,{className:"mr-5 md:mr-0"},l.type)),e.createElement("div",{className:"flex-1 py-2 md:py-4"},e.createElement(Kt,{className:"ml-5 md:ml-8",data:l.all,onClick:r,errSet:i,select:l.now,canClick:u,rowHeight:30})))}function xn(n){const{update:t}=qe(),{translation:s,lang:o}=S(),a=z(),{provider:l}=n,{t:r}=s("Proxies"),{visible:i,hide:u,show:h}=Fe();function f(){h(),a.healthCheckProvider(l.name).then(async()=>await t()).finally(()=>u())}function E(){h(),a.updateProvider(l.name).then(async()=>await t()).finally(()=>u())}const d=m.exports.useMemo(()=>l.proxies.slice().sort((p,w)=>-1*ve(p,w)),[l.proxies]);return e.createElement(H,{className:"proxy-provider"},e.createElement(nt,{visible:i}),e.createElement("div",{className:"flex flex-col justify-between md:flex-row md:items-center "},e.createElement("div",{className:"flex items-center"},e.createElement("span",{className:"mr-6"},l.name),e.createElement(le,null,l.vehicleType),e.createElement(le,{className:"rule-provider-behavior"},l.proxies.length)),e.createElement("div",{className:"flex pt-3 items-center md:pt-0"},l.updatedAt&&e.createElement("span",{className:"text-sm"},`${r("providerUpdateTime")}: ${Ae(new Date(l.updatedAt),o)}`),e.createElement(O,{className:"cursor-pointer text-red pl-5",type:"healthcheck",size:18,onClick:f}),e.createElement(O,{className:"cursor-pointer pl-5",type:"update",size:18,onClick:E}))),e.createElement("ul",{className:"proxies-list"},d.map(p=>e.createElement("li",{key:p.name},e.createElement(st,{className:"proxy-provider-item",config:p})))))}const gn={[0]:"sort",[1]:"sort-ascending",[2]:"sort-descending"};function ve(n,t){const s=n.history.length>0?n.history.slice(-1)[0].delay:0;return((t.history.length>0?t.history.slice(-1)[0].delay:0)||Number.MAX_SAFE_INTEGER)-(s||Number.MAX_SAFE_INTEGER)}function vn(){const{groups:n,global:t}=de(),{data:s,set:o}=me(),{general:a}=De(),{translation:l}=S(),{t:r}=l("Proxies"),i=m.exports.useMemo(()=>a.mode==="global"?[t,...n]:n,[a,n,t]);return e.createElement(e.Fragment,null,i.length!==0&&e.createElement("div",{className:"flex flex-col"},e.createElement(q,{title:r("groupTitle")},e.createElement(tt,{className:"cursor-pointer text-sm text-shadow-primary text-[#619cc2]",checked:s.breakConnections,onChange:u=>o("breakConnections",u)},r("breakConnectionsText"))),e.createElement(H,{className:"my-2.5 p-0 md:my-4"},e.createElement("ul",{className:"list-none divide-y divide-gray-300"},i.map(u=>e.createElement("li",{key:u.name},e.createElement(yn,{config:u})))))))}function wn(){const{providers:n}=qe(),{translation:t}=S(),{t:s}=t("Proxies");return e.createElement(e.Fragment,null,n.length!==0&&e.createElement("div",{className:"flex flex-col"},e.createElement(q,{title:s("providerTitle")}),e.createElement("ul",{className:"list-none"},n.map(o=>e.createElement("li",{className:"my-2.5 md:my-4",key:o.name},e.createElement(xn,{provider:o}))))))}function Cn(){const{proxies:n}=de(),{translation:t}=S(),{t:s}=t("Proxies");function o(){ge.notifySpeedTest()}const{current:a,next:l}=tn([1,2,0]),r=m.exports.useMemo(()=>{switch(a){case 2:return n.slice().sort((u,h)=>ve(u,h));case 1:return n.slice().sort((u,h)=>-1*ve(u,h));default:return n.slice()}},[a,n]),i=l;return e.createElement(e.Fragment,null,r.length!==0&&e.createElement("div",{className:"flex flex-col"},e.createElement(q,{title:s("title")},e.createElement(O,{className:"ml-3",type:gn[a],onClick:i,size:20}),e.createElement(O,{className:"ml-3",type:"speed",size:20}),e.createElement("span",{className:"proxies-speed-test text-[#619cc2]",onClick:o},s("speedTestText"))),e.createElement(H,{className:"proxy-provider"},e.createElement("ul",{className:"proxies-list"},r.map(u=>e.createElement("li",{key:u.name},e.createElement(st,{config:u})))))))}function bn(){return e.createElement("div",{className:"page"},e.createElement(vn,null),e.createElement(wn,null),e.createElement(Cn,null))}function Nn(n){const{update:t}=Je(),{translation:s,lang:o}=S(),a=z(),{provider:l}=n,{t:r}=s("Rules"),{visible:i,hide:u,show:h}=Fe();function f(){h(),a.updateRuleProvider(l.name).then(async()=>await t()).finally(()=>u())}const E=v("rule-provider-icon",{"rule-provider-loading":i});return e.createElement("div",{className:"rule-provider"},e.createElement("div",{className:"rule-provider-header"},e.createElement("div",{className:"rule-provider-header-part"},e.createElement("span",{className:"rule-provider-name"},l.name),e.createElement(le,null,l.vehicleType),e.createElement(le,{className:"rule-provider-behavior"},l.behavior),e.createElement("span",{className:"rule-provider-update"},`${r("ruleCount")}: ${l.ruleCount}`)),e.createElement("div",{className:"rule-provider-header-part"},l.updatedAt&&e.createElement("span",{className:"rule-provider-update"},`${r("providerUpdateTime")}: ${Ae(new Date(l.updatedAt),o)}`),e.createElement(O,{className:E,type:"update",size:18,onClick:f}))))}function Pn(){const{providers:n}=Je(),{translation:t}=S(),{t:s}=t("Rules");return e.createElement(e.Fragment,null,n.length!==0&&e.createElement("div",{className:"flex flex-col"},e.createElement(q,{title:s("providerTitle")}),e.createElement(H,{className:"divide-y rounded shadow-primary mt-4 p-0"},n.map(o=>e.createElement(Nn,{key:o.name,provider:o})))))}function Sn(){const{rules:n,update:t}=Jt(),{translation:s}=S(),{t:o}=s("Rules");ee("rules",t);function a({index:l,style:r}){const i=n[l],u=i.size||-1;return e.createElement("li",{className:"rule-item",style:r},e.createElement("div",{className:"flex py-1"},e.createElement("div",{className:"text-center w-40 rule-type"},i.type),e.createElement("div",{className:"flex-1 text-center payload"}," ",u!==-1?`${i.payload} :: ${u}`:i.payload),e.createElement("div",{className:"text-center w-40 rule-proxy"},i.proxy)))}return e.createElement("div",{className:"page"},e.createElement(Pn,null),e.createElement(q,{className:"not-first:mt-7.5",title:o("title")}),e.createElement(H,{className:"flex flex-col flex-1 mt-2.5 p-0 md:mt-4 focus:outline-none text-sm"},e.createElement(Nt,{className:"min-h-120"},({height:l,width:r})=>e.createElement(Pt,{height:l,width:r,itemCount:n.length,itemSize:40},a))))}const kn=[{label:"\u4E2D\u6587",value:"zh_CN"},{label:"English",value:"en_US"}];function Dn(){var oe,ce,ie;const{premium:n}=Ve(),{data:t,update:s}=Qe(),{general:o,update:a}=De(),l=be(ke),r=re(),{translation:i,setLang:u,lang:h}=S(),{t:f}=i("Settings"),E=z(),[d,p]=ue({mixedProxyPort:0,socks5ProxyPort:7891,httpProxyPort:7890,redirProxyPort:7892});m.exports.useEffect(()=>{var c,C,y,L;p("socks5ProxyPort",(c=o==null?void 0:o.socksPort)!=null?c:0),p("httpProxyPort",(C=o==null?void 0:o.port)!=null?C:0),p("mixedProxyPort",(y=o==null?void 0:o.mixedPort)!=null?y:0),p("redirProxyPort",(L=o==null?void 0:o.redirPort)!=null?L:0)},[o,p]);async function w(c){await E.updateConfig({mode:c}),await a()}async function g(c){await(P==null?void 0:P.setStartAtLogin(c)),await s()}async function A(c){await(P==null?void 0:P.setSystemProxy(c)),await s()}function k(c){u(c)}async function D(){await E.updateConfig({port:d.httpProxyPort}),await a()}async function V(){await E.updateConfig({"socks-port":d.socks5ProxyPort}),await a()}async function N(){await E.updateConfig({"mixed-port":d.mixedProxyPort}),await a()}async function j(){await E.updateConfig({"redir-port":d.redirProxyPort}),await a()}async function I(c){await E.updateConfig({"allow-lan":c}),await a()}const{hostname:$,port:R}=r,{allowLan:se,mode:te}=o,T=(oe=t==null?void 0:t.startAtLogin)!=null?oe:!1,X=(ce=t==null?void 0:t.systemProxy)!=null?ce:!1,J=(ie=t==null?void 0:t.isClashX)!=null?ie:!1,K=m.exports.useMemo(()=>{const c=[{label:f("values.global"),value:"Global"},{label:f("values.rules"),value:"Rule"},{label:f("values.direct"),value:"Direct"}];return n&&c.push({label:f("values.script"),value:"Script"}),c},[f,n]);return e.createElement("div",{className:"page"},e.createElement(q,{title:f("title")}),e.createElement(H,{className:"settings-card"},e.createElement("div",{className:"flex flex-wrap"},e.createElement("div",{className:"flex flex-wrap w-full py-3 px-8 items-center justify-between "},e.createElement("span",{className:"font-bold label"},f("labels.language")),e.createElement(Re,{options:kn,value:h,onSelect:c=>k(c)})),e.createElement("div",{className:"flex flex-wrap w-full py-3 px-8 items-center justify-between "},e.createElement("span",{className:"font-bold label"},f("labels.allowConnectFromLan")),e.createElement(fe,{checked:se,onChange:I}))),e.createElement("div",{className:"flex flex-wrap"},e.createElement("div",{className:"flex flex-wrap w-full py-3 px-8 items-center justify-between "},e.createElement("span",{className:"font-bold label"},f("labels.proxyMode")),e.createElement(Re,{options:K,value:St(te),onSelect:w})))),J&&e.createElement(H,{className:"settings-card"},e.createElement("div",{className:"flex flex-wrap"},e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},f("labels.startAtLogin")),e.createElement(fe,{checked:T,onChange:g})),e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},f("labels.setAsSystemProxy")),e.createElement(fe,{checked:X,onChange:A})))),e.createElement(H,{className:"settings-card"},e.createElement("div",{className:"flex flex-wrap"},e.createElement("div",{className:"flex flex-wrap w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},f("labels.mixedProxyPort")),e.createElement(Q,{className:"w-28",disabled:J,value:d.mixedProxyPort,onChange:c=>p("mixedProxyPort",+c),onBlur:N})),e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},f("labels.redirProxyPort")),e.createElement(Q,{className:"w-28",disabled:J,value:d.redirProxyPort,onChange:c=>p("redirProxyPort",+c),onBlur:j}))),e.createElement("div",{className:"flex flex-wrap"},e.createElement("div",{className:"flex flex-wrap w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},f("labels.socks5ProxyPort")),e.createElement(Q,{className:"w-28",disabled:J,value:d.socks5ProxyPort,onChange:c=>p("socks5ProxyPort",+c),onBlur:V})),e.createElement("div",{className:"flex flex-wrap w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},f("labels.httpProxyPort")),e.createElement(Q,{className:"w-28",disabled:J,value:d.httpProxyPort,onChange:c=>p("httpProxyPort",+c),onBlur:D})),e.createElement("div",{className:"flex flex-wrap w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},f("labels.externalController")),e.createElement("span",{className:v({"modify-btn":!J},"external-controller"),onClick:()=>!J&&l(!1)},`${$}:${R}`)))))}var Fn="./assets/logo.0dc1c7df.png";function An(n){const{routes:t}=n,{translation:s}=S(),{version:o,premium:a,meta:l}=Ve(),{data:r}=Qe(),{t:i}=s("SideBar"),u=Ce(),h=t.map(({path:f,name:E,noMobile:d})=>e.createElement("li",{className:v("item",{"no-mobile":d}),key:E},e.createElement(kt,{to:{pathname:f,search:u.search},className:({isActive:p})=>v({active:p})},i(E))));return e.createElement("div",{className:"sidebar"},e.createElement("img",{src:Fn,alt:"logo",className:"sidebar-logo"}),e.createElement("ul",{className:"sidebar-menu"},h),e.createElement("div",{className:"sidebar-version"},e.createElement("span",{className:"sidebar-version-label"},"Clash",(r==null?void 0:r.isClashX)&&"X"," ",i("Version")),e.createElement("span",{className:"sidebar-version-text"},o),a&&e.createElement("span",{className:"sidebar-version-label"},"Premium"),l&&e.createElement("span",{className:"sidebar-version-label"},"Meta")))}function $n(){Ze();const n=Ce(),t=[{path:"/proxies",name:"Proxies",element:e.createElement(bn,null)},{path:"/logs",name:"Logs",element:e.createElement(En,null)},{path:"/rules",name:"Rules",element:e.createElement(Sn,null),noMobile:!0},{path:"/connections",name:"Connections",element:e.createElement(mn,null),noMobile:!1},{path:"/settings",name:"Settings",element:e.createElement(Dn,null)}],s=e.createElement("div",{className:v("app",{"not-clashx":!ne()})},e.createElement(An,{routes:t}),e.createElement("div",{className:"page-container"},e.createElement(Dt,null)),e.createElement(dn,null));return e.createElement(Ft,null,e.createElement(pe,{path:"/",element:s},e.createElement(pe,{path:"/",element:e.createElement(At,{to:{pathname:"/proxies",search:n.search},replace:!0})}),t.map(o=>e.createElement(pe,{path:o.path,key:o.path,element:o.element}))))}function Me(){const n=document.getElementById("root"),t=e.createElement(m.exports.StrictMode,null,e.createElement(Lt,null,e.createElement(m.exports.Suspense,{fallback:e.createElement(nt,{visible:!0})},e.createElement($n,null))));$t(n).render(t)}ne()?Tt(()=>Me()):Me();