diff --git a/app/Jobs/OrderHandleJob.php b/app/Jobs/OrderHandleJob.php index 11f7b79..960f659 100644 --- a/app/Jobs/OrderHandleJob.php +++ b/app/Jobs/OrderHandleJob.php @@ -43,12 +43,12 @@ class OrderHandleJob implements ShouldQueue $orderService = new OrderService($order); switch ($order->status) { // cancel - case 0: + case Order::STATUS_PENDING: if ($order->created_at <= (time() - 3600 * 2)) { $orderService->cancel(); } break; - case 1: + case Order::STATUS_PROCESSING: $orderService->open(); break; } diff --git a/public/assets/admin/assets/index.js b/public/assets/admin/assets/index.js index 7e6130c..fc23123 100644 --- a/public/assets/admin/assets/index.js +++ b/public/assets/admin/assets/index.js @@ -1,8 +1,8 @@ import{r as u,j as e,t as Sl,c as kl,I as Ka,a as As,S as Na,u as Ts,b as Tl,d as _a,R as fn,e as gn,f as Dl,F as Pl,C as El,L as jn,T as vn,g as bn,h as Rl,i as Il,k as Vl,l as A,z as x,m as V,n as ge,o as Ne,p as re,q as es,s as Se,v as it,w as Ml,O as wa,x as Fl,y as Ol,A as Ll,B as zl,D as Al,E as $l,Q as Ul,G as Hl,H as ql,J as Kl,P as Bl,K as Gl,M as Wl,N as Yl,U as Ql,V as yn,W as Nn,X as zt,Y as At,Z as Ca,_ as ss,$ as $t,a0 as Ut,a1 as _n,a2 as wn,a3 as Cn,a4 as Sa,a5 as Sn,a6 as Jl,a7 as kn,a8 as Tn,a9 as Dn,aa as Pn,ab as $s,ac as En,ad as Xl,ae as Rn,af as In,ag as Zl,ah as ei,ai as si,aj as ti,ak as ai,al as ni,am as ri,an as li,ao as ii,ap as oi,aq as ci,ar as Vn,as as di,at as ui,au as Us,av as Mn,aw as mi,ax as xi,ay as Fn,az as ka,aA as hi,aB as pi,aC as Ba,aD as fi,aE as On,aF as gi,aG as Ln,aH as ji,aI as vi,aJ as bi,aK as yi,aL as Ni,aM as _i,aN as zn,aO as wi,aP as Ci,aQ as Si,aR as Le,aS as ki,aT as An,aU as $n,aV as Ti,aW as Di,aX as Un,aY as Pi,aZ as Ei,a_ as Ze,a$ as Ri,b0 as Ii,b1 as Hn,b2 as qn,b3 as Kn,b4 as Vi,b5 as Mi,b6 as Fi,b7 as Bn,b8 as Oi,b9 as Ta,ba as Gn,bb as Li,bc as Wn,bd as zi,be as Yn,bf as Ai,bg as Qn,bh as Jn,bi as $i,bj as Ui,bk as Xn,bl as Hi,bm as qi,bn as Zn,bo as Ki,bp as er,bq as Bi,br as Gi,bs as is,bt as jt,bu as Wi,bv as Yi,bw as Qi,bx as Ji,by as Xi,bz as Zi,bA as Ga,bB as Wa,bC as eo,bD as so,bE as to,bF as ao,bG as no,bH as ha,bI as pt,bJ as ro,bK as lo,bL as io,bM as Ya,bN as pa,bO as fa,bP as oo,bQ as co,bR as sr,bS as uo,bT as Da,bU as mo,bV as xo,bW as ho,bX as tr,bY as ar,bZ as po,b_ as fo,b$ as go,c0 as jo,c1 as vo,c2 as nr,c3 as bo,c4 as yo,c5 as No,c6 as _o,c7 as Rt,c8 as Ve,c9 as Qa,ca as wo,cb as rr,cc as lr,cd as ir,ce as or,cf as cr,cg as dr,ch as Co,ci as So,cj as ko,ck as Ht,cl as Hs,cm as cs,cn as ns,co as rs,cp as ds,cq as us,cr as ms,cs as To,ct as Do,cu as Po,cv as Eo,cw as Ro,cx as Io,cy as Vo,cz as Mo,cA as Fo,cB as ga,cC as Pa,cD as Ea,cE as Oo,cF as Ds,cG as Ps,cH as qt,cI as Lo,cJ as It,cK as zo,cL as Ja,cM as ur,cN as Xa,cO as Vt,cP as Ao,cQ as $o,cR as Uo,cS as Ho,cT as mr,cU as qo,cV as Ko,cW as xr,cX as ja,cY as hr,cZ as Bo,c_ as pr,c$ as fr,d0 as Go,d1 as Wo,d2 as Yo,d3 as Qo,d4 as Jo}from"./vendor.js";import"./index.js";var xp=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function hp(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function Xo(s){if(s.__esModule)return s;var n=s.default;if(typeof n=="function"){var t=function r(){return this instanceof r?Reflect.construct(n,arguments,this.constructor):n.apply(this,arguments)};t.prototype=n.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(s).forEach(function(r){var a=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:function(){return s[r]}})}),t}const Zo={theme:"system",setTheme:()=>null},gr=u.createContext(Zo);function ec({children:s,defaultTheme:n="system",storageKey:t="vite-ui-theme",...r}){const[a,i]=u.useState(()=>localStorage.getItem(t)||n);u.useEffect(()=>{const d=window.document.documentElement;if(d.classList.remove("light","dark"),a==="system"){const m=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";d.classList.add(m);return}d.classList.add(a)},[a]);const l={theme:a,setTheme:d=>{localStorage.setItem(t,d),i(d)}};return e.jsx(gr.Provider,{...r,value:l,children:s})}const sc=()=>{const s=u.useContext(gr);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},tc=function(){const n=typeof document<"u"&&document.createElement("link").relList;return n&&n.supports&&n.supports("modulepreload")?"modulepreload":"preload"}(),ac=function(s,n){return new URL(s,n).href},Za={},me=function(n,t,r){let a=Promise.resolve();if(t&&t.length>0){const l=document.getElementsByTagName("link"),d=document.querySelector("meta[property=csp-nonce]"),m=d?.nonce||d?.getAttribute("nonce");a=Promise.allSettled(t.map(o=>{if(o=ac(o,r),o in Za)return;Za[o]=!0;const c=o.endsWith(".css"),h=c?'[rel="stylesheet"]':"";if(!!r)for(let C=l.length-1;C>=0;C--){const S=l[C];if(S.href===o&&(!c||S.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${o}"]${h}`))return;const E=document.createElement("link");if(E.rel=c?"stylesheet":tc,c||(E.as="script"),E.crossOrigin="",E.href=o,m&&E.setAttribute("nonce",m),document.head.appendChild(E),c)return new Promise((C,S)=>{E.addEventListener("load",C),E.addEventListener("error",()=>S(new Error(`Unable to preload CSS for ${o}`)))})}))}function i(l){const d=new Event("vite:preloadError",{cancelable:!0});if(d.payload=l,window.dispatchEvent(d),!d.defaultPrevented)throw l}return a.then(l=>{for(const d of l||[])d.status==="rejected"&&i(d.reason);return n().catch(i)})};function N(...s){return Sl(kl(s))}const nt=As("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),P=u.forwardRef(({className:s,variant:n,size:t,asChild:r=!1,children:a,disabled:i,loading:l=!1,leftSection:d,rightSection:m,...o},c)=>{const h=r?Na:"button";return e.jsxs(h,{className:N(nt({variant:n,size:t,className:s})),disabled:l||i,ref:c,...o,children:[(d&&l||!d&&!m&&l)&&e.jsx(Ka,{className:"mr-2 h-4 w-4 animate-spin"}),!l&&d&&e.jsx("div",{className:"mr-2",children:d}),a,!l&&m&&e.jsx("div",{className:"ml-2",children:m}),m&&l&&e.jsx(Ka,{className:"ml-2 h-4 w-4 animate-spin"})]})});P.displayName="Button";function Ys({className:s,minimal:n=!1}){const t=Ts(),r=Tl(),a=r?.message||r?.statusText||"Unknown error occurred";return e.jsx("div",{className:N("h-svh w-full",s),children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[!n&&e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"500"}),e.jsxs("span",{className:"font-medium",children:["Oops! Something went wrong ",":')"]}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["We apologize for the inconvenience. ",e.jsx("br",{}),a]}),!n&&e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(P,{variant:"outline",onClick:()=>t(-1),children:"Go Back"}),e.jsx(P,{onClick:()=>t("/"),children:"Back to Home"})]})]})})}function en(){const s=Ts();return e.jsx("div",{className:"h-svh",children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"404"}),e.jsx("span",{className:"font-medium",children:"Oops! Page Not Found!"}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["It seems like the page you're looking for ",e.jsx("br",{}),"does not exist or might have been removed."]}),e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(P,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(P,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function nc(){return e.jsx("div",{className:"h-svh",children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"503"}),e.jsx("span",{className:"font-medium",children:"Website is under maintenance!"}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["The site is not available at the moment. ",e.jsx("br",{}),"We'll be back online shortly."]}),e.jsx("div",{className:"mt-6 flex gap-4",children:e.jsx(P,{variant:"outline",children:"Learn more"})})]})})}function rc(s){return typeof s>"u"}function lc(s){return s===null}function ic(s){return lc(s)||rc(s)}class oc{storage;prefixKey;constructor(n){this.storage=n.storage,this.prefixKey=n.prefixKey}getKey(n){return`${this.prefixKey}${n}`.toUpperCase()}set(n,t,r=null){const a=JSON.stringify({value:t,time:Date.now(),expire:r!==null?new Date().getTime()+r*1e3:null});this.storage.setItem(this.getKey(n),a)}get(n,t=null){const r=this.storage.getItem(this.getKey(n));if(!r)return{value:t,time:0};try{const a=JSON.parse(r),{value:i,time:l,expire:d}=a;return ic(d)||d>new Date().getTime()?{value:i,time:l}:(this.remove(n),{value:t,time:0})}catch{return this.remove(n),{value:t,time:0}}}remove(n){this.storage.removeItem(this.getKey(n))}clear(){this.storage.clear()}}function jr({prefixKey:s="",storage:n=sessionStorage}){return new oc({prefixKey:s,storage:n})}const vr="Xboard_",cc=function(s={}){return jr({prefixKey:s.prefixKey||"",storage:localStorage})},dc=function(s={}){return jr({prefixKey:s.prefixKey||"",storage:sessionStorage})},Kt=cc({prefixKey:vr});dc({prefixKey:vr});const br="access_token";function ft(){return Kt.get(br)}function yr(){Kt.remove(br)}const sn=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function uc({children:s}){const n=Ts(),t=_a(),r=ft();return u.useEffect(()=>{if(!r.value&&!sn.includes(t.pathname)){const a=encodeURIComponent(t.pathname+t.search);n(`/sign-in?redirect=${a}`)}},[r.value,t.pathname,t.search,n]),sn.includes(t.pathname)||r.value?e.jsx(e.Fragment,{children:s}):null}const ke=u.forwardRef(({className:s,orientation:n="horizontal",decorative:t=!0,...r},a)=>e.jsx(fn,{ref:a,decorative:t,orientation:n,className:N("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...r}));ke.displayName=fn.displayName;const mc=As("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Mt=u.forwardRef(({className:s,...n},t)=>e.jsx(gn,{ref:t,className:N(mc(),s),...n}));Mt.displayName=gn.displayName;const _e=Pl,Nr=u.createContext({}),g=({...s})=>e.jsx(Nr.Provider,{value:{name:s.name},children:e.jsx(El,{...s})}),Bt=()=>{const s=u.useContext(Nr),n=u.useContext(_r),{getFieldState:t,formState:r}=Dl(),a=t(s.name,r);if(!s)throw new Error("useFormField should be used within ");const{id:i}=n;return{id:i,name:s.name,formItemId:`${i}-form-item`,formDescriptionId:`${i}-form-item-description`,formMessageId:`${i}-form-item-message`,...a}},_r=u.createContext({}),f=u.forwardRef(({className:s,...n},t)=>{const r=u.useId();return e.jsx(_r.Provider,{value:{id:r},children:e.jsx("div",{ref:t,className:N("space-y-2",s),...n})})});f.displayName="FormItem";const j=u.forwardRef(({className:s,...n},t)=>{const{error:r,formItemId:a}=Bt();return e.jsx(Mt,{ref:t,className:N(r&&"text-destructive",s),htmlFor:a,...n})});j.displayName="FormLabel";const y=u.forwardRef(({...s},n)=>{const{error:t,formItemId:r,formDescriptionId:a,formMessageId:i}=Bt();return e.jsx(Na,{ref:n,id:r,"aria-describedby":t?`${a} ${i}`:`${a}`,"aria-invalid":!!t,...s})});y.displayName="FormControl";const F=u.forwardRef(({className:s,...n},t)=>{const{formDescriptionId:r}=Bt();return e.jsx("p",{ref:t,id:r,className:N("text-[0.8rem] text-muted-foreground",s),...n})});F.displayName="FormDescription";const D=u.forwardRef(({className:s,children:n,...t},r)=>{const{error:a,formMessageId:i}=Bt(),l=a?String(a?.message):n;return l?e.jsx("p",{ref:r,id:i,className:N("text-[0.8rem] font-medium text-destructive",s),...t,children:l}):null});D.displayName="FormMessage";const Gt=Rl,vt=u.forwardRef(({className:s,...n},t)=>e.jsx(jn,{ref:t,className:N("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...n}));vt.displayName=jn.displayName;const Ge=u.forwardRef(({className:s,...n},t)=>e.jsx(vn,{ref:t,className:N("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",s),...n}));Ge.displayName=vn.displayName;const ws=u.forwardRef(({className:s,...n},t)=>e.jsx(bn,{ref:t,className:N("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...n}));ws.displayName=bn.displayName;function we(s=void 0,n="YYYY-MM-DD HH:mm:ss"){return s==null?"":(Math.floor(s).toString().length===10&&(s=s*1e3),Il(s).format(n))}function xc(s=void 0,n="YYYY-MM-DD"){return we(s,n)}function Xs(s){const n=typeof s=="string"?parseFloat(s):s;return isNaN(n)?"0.00":n.toFixed(2)}function Ls(s,n=!0){if(s==null)return n?"¥0.00":"0.00";const t=typeof s=="string"?parseFloat(s):s;if(isNaN(t))return n?"¥0.00":"0.00";const a=(t/100).toFixed(2).replace(/\.?0+$/,i=>i.includes(".")?".00":i);return n?`¥${a}`:a}function Ft(s){return new Promise(n=>{(async()=>{try{if(navigator.clipboard)await navigator.clipboard.writeText(s);else{const r=document.createElement("textarea");r.value=s,r.style.position="fixed",r.style.opacity="0",document.body.appendChild(r),r.select();const a=document.execCommand("copy");if(document.body.removeChild(r),!a)throw new Error("execCommand failed")}n(!0)}catch(r){console.error(r),n(!1)}})()})}function ps(s){const n=s/1024,t=n/1024,r=t/1024,a=r/1024;return a>=1?Xs(a)+" TB":r>=1?Xs(r)+" GB":t>=1?Xs(t)+" MB":Xs(n)+" KB"}const hc="locale";function pc(){return Kt.get(hc)}function wr(){yr();const s=window.location.pathname,n=s&&!["/404","/sign-in"].includes(s),t=new URL(window.location.href),a=`${t.pathname.split("/")[1]?`/${t.pathname.split("/")[1]}`:""}#/sign-in`;window.location.href=a+(n?`?redirect=${s}`:"")}const fc=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function gc(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const I=Vl.create({baseURL:gc(),timeout:12e3,headers:{"Content-Type":"application/json"}});I.interceptors.request.use(s=>{s.method?.toLowerCase()==="get"&&(s.params={...s.params,t:Date.now()});const n=ft();if(!fc.includes(s.url?.split("?")[0]||"")){if(!n.value)return wr(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=n.value}return s.headers["Content-Language"]=pc().value||"zh-CN",s},s=>Promise.reject(s));I.interceptors.response.use(s=>s?.data||{code:-1,message:"未知错误"},s=>{const n=s.response?.status,t=s.response?.data?.message;return(n===401||n===403)&&wr(),A.error(t||{401:"登录已过期",403:"没有权限",404:"资源或接口不存在"}[n]||"未知异常"),Promise.reject(s.response?.data||{data:null,code:-1,message:"未知错误"})});const jc="access_token";function vc(s){Kt.set(jc,s)}const U=window?.settings?.secure_path,bc=s=>I.get(U+"/stat/getOrder",{params:s}),yc=()=>I.get(U+"/stat/getStats"),tn=s=>I.get(U+"/stat/getTrafficRank",{params:s}),Nc=()=>I.get(U+"/theme/getThemes"),_c=s=>I.post(U+"/theme/getThemeConfig",{name:s}),wc=(s,n)=>I.post(U+"/theme/saveThemeConfig",{name:s,config:n}),Cc=s=>{const n=new FormData;return n.append("file",s),I.post(U+"/theme/upload",n,{headers:{"Content-Type":"multipart/form-data"}})},Sc=s=>I.post(U+"/theme/delete",{name:s}),kc=s=>I.post(U+"/config/save",s),Cr=()=>I.get(U+"/server/manage/getNodes"),Tc=s=>I.post(U+"/server/manage/save",s),Dc=s=>I.post(U+"/server/manage/drop",s),Pc=s=>I.post(U+"/server/manage/copy",s),Ec=s=>I.post(U+"/server/manage/update",s),Rc=s=>I.post(U+"/server/manage/sort",s),bt=()=>I.get(U+"/server/group/fetch"),Ic=s=>I.post(U+"/server/group/save",s),Vc=s=>I.post(U+"/server/group/drop",s),Sr=()=>I.get(U+"/server/route/fetch"),Mc=s=>I.post(U+"/server/route/save",s),Fc=s=>I.post(U+"/server/route/drop",s),Oc=()=>I.get(U+"/payment/fetch"),Lc=()=>I.get(U+"/payment/getPaymentMethods"),zc=s=>I.post(U+"/payment/getPaymentForm",s),Ac=s=>I.post(U+"/payment/save",s),$c=s=>I.post(U+"/payment/drop",s),Uc=s=>I.post(U+"/payment/show",s),Hc=s=>I.post(U+"/payment/sort",s),qc=s=>I.post(U+"/notice/save",s),Kc=s=>I.post(U+"/notice/drop",s),Bc=s=>I.post(U+"/notice/show",s),Gc=()=>I.get(U+"/knowledge/fetch"),Wc=s=>I.get(U+"/knowledge/fetch?id="+s),Yc=s=>I.post(U+"/knowledge/save",s),Qc=s=>I.post(U+"/knowledge/drop",s),Jc=s=>I.post(U+"/knowledge/show",s),Xc=s=>I.post(U+"/knowledge/sort",s),qs=()=>I.get(U+"/plan/fetch"),Zc=s=>I.post(U+"/plan/save",s),aa=s=>I.post(U+"/plan/update",s),ed=s=>I.post(U+"/plan/drop",s),sd=s=>I.post(U+"/plan/sort",{ids:s}),td=async s=>I.post(U+"/order/fetch",s),ad=s=>I.post(U+"/order/detail",s),nd=s=>I.post(U+"/order/paid",s),rd=s=>I.post(U+"/order/cancel",s),an=s=>I.post(U+"/order/update",s),ld=s=>I.post(U+"/order/assign",s),id=s=>I.post(U+"/coupon/fetch",s),od=s=>I.post(U+"/coupon/generate",s),cd=s=>I.post(U+"/coupon/drop",s),dd=s=>I.post(U+"/coupon/update",s),ud=s=>I.post(U+"/user/fetch",s),md=s=>I.post(U+"/user/update",s),xd=s=>I.post(U+"/user/resetSecret",s),hd=s=>I.post(U+"/user/generate",s),pd=s=>I.post(U+"/stat/getStatUser",s),fd=s=>I.post(U+"/ticket/fetch",s),gd=s=>I.get(U+"/ticket/fetch?id= "+s),jd=s=>I.post(U+"/ticket/close",{id:s}),gs=(s="")=>I.get(U+"/config/fetch?key="+s),js=s=>I.post(U+"/config/save",s),vd=()=>I.get(U+"/config/getEmailTemplate"),bd=()=>I.post(U+"/config/testSendMail"),yd=()=>I.post(U+"/config/setTelegramWebhook"),Nd=x.object({subscribe_template_singbox:x.string().nullable(),subscribe_template_clash:x.string().nullable(),subscribe_template_clashmeta:x.string().nullable(),subscribe_template_stash:x.string().nullable(),subscribe_template_surge:x.string().nullable()}),_d={subscribe_template_singbox:"",subscribe_template_clash:"",subscribe_template_clashmeta:"",subscribe_template_stash:"",subscribe_template_surge:""};function wd(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),[a,i]=u.useState("singbox"),l=ge({resolver:Ne(Nd),defaultValues:_d,mode:"onBlur"}),{data:d}=re({queryKey:["settings","client"],queryFn:()=>gs("subscribe_template")}),{mutateAsync:m}=es({mutationFn:js,onSuccess:h=>{h.data&&A.success(s("common.autoSaved"))}});u.useEffect(()=>{if(d?.data.subscribe_template){const h=d.data.subscribe_template;Object.entries(h).forEach(([_,E])=>{l.setValue(_,E)}),r.current=h}},[d]),console.log(l.getValues());const o=u.useCallback(Se.debounce(async h=>{if(!Se.isEqual(h,r.current)){t(!0);try{await m(h),r.current=h}finally{t(!1)}}},1e3),[m]),c=u.useCallback(h=>{o(h)},[o]);return e.jsx(_e,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Gt,{value:a,onValueChange:i,children:[e.jsxs(vt,{children:[e.jsx(Ge,{value:"singbox",children:"Sing-box"}),e.jsx(Ge,{value:"clash",children:"Clash"}),e.jsx(Ge,{value:"clashmeta",children:"Clash Meta"}),e.jsx(Ge,{value:"stash",children:"Stash"}),e.jsx(Ge,{value:"surge",children:"Surge"})]}),e.jsx(ws,{value:"singbox",children:e.jsx(g,{control:l.control,name:"subscribe_template_singbox",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe_template.singbox.title")}),e.jsx(y,{children:e.jsx(it,{height:"500px",defaultLanguage:"json",value:h.value||"",onChange:_=>{typeof _=="string"&&(h.onChange(_),c(l.getValues()))},options:{minimap:{enabled:!1},fontSize:14}})}),e.jsx(F,{children:s("subscribe_template.singbox.description")}),e.jsx(D,{})]})})}),e.jsx(ws,{value:"clash",children:e.jsx(g,{control:l.control,name:"subscribe_template_clash",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe_template.clash.title")}),e.jsx(y,{children:e.jsx(it,{height:"500px",defaultLanguage:"yaml",value:h.value||"",onChange:_=>{typeof _=="string"&&(h.onChange(_),c(l.getValues()))},options:{minimap:{enabled:!1},fontSize:14}})}),e.jsx(F,{children:s("subscribe_template.clash.description")}),e.jsx(D,{})]})})}),e.jsx(ws,{value:"clashmeta",children:e.jsx(g,{control:l.control,name:"subscribe_template_clashmeta",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe_template.clashmeta.title")}),e.jsx(y,{children:e.jsx(it,{height:"500px",defaultLanguage:"yaml",value:h.value||"",onChange:_=>{typeof _=="string"&&(h.onChange(_),c(l.getValues()))},options:{minimap:{enabled:!1},fontSize:14}})}),e.jsx(F,{children:s("subscribe_template.clashmeta.description")}),e.jsx(D,{})]})})}),e.jsx(ws,{value:"stash",children:e.jsx(g,{control:l.control,name:"subscribe_template_stash",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe_template.stash.title")}),e.jsx(y,{children:e.jsx(it,{height:"500px",defaultLanguage:"yaml",value:h.value||"",onChange:_=>{typeof _=="string"&&(h.onChange(_),c(l.getValues()))},options:{minimap:{enabled:!1},fontSize:14}})}),e.jsx(F,{children:s("subscribe_template.stash.description")}),e.jsx(D,{})]})})}),e.jsx(ws,{value:"surge",children:e.jsx(g,{control:l.control,name:"subscribe_template_surge",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe_template.surge.title")}),e.jsx(y,{children:e.jsx(it,{height:"500px",defaultLanguage:"ini",value:h.value||"",onChange:_=>{typeof _=="string"&&(h.onChange(_),c(l.getValues()))},options:{minimap:{enabled:!1},fontSize:14}})}),e.jsx(F,{children:s("subscribe_template.surge.description")}),e.jsx(D,{})]})})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Cd(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("subscribe_template.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe_template.description")})]}),e.jsx(ke,{}),e.jsx(wd,{})]})}const Sd=()=>e.jsx(uc,{children:e.jsx(wa,{})}),kd=Ml([{path:"/sign-in",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>qd);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(Sd,{}),children:[{path:"/",lazy:async()=>({Component:(await me(()=>Promise.resolve().then(()=>Zd),void 0,import.meta.url)).default}),errorElement:e.jsx(Ys,{}),children:[{index:!0,lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>_u);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(Ys,{}),children:[{path:"system",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>ku);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Eu);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Fu);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>$u);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Bu);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Ju);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>tm);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>im);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>mm);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>gm);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe-template",element:e.jsx(Cd,{})}]},{path:"payment",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>km);return{default:s}},void 0,import.meta.url)).default})},{path:"plugin",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Pm);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Vm);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>$m);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Ym);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(Ys,{}),children:[{path:"manage",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Cx);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Px);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Fx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(Ys,{}),children:[{path:"plan",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Kx);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>rh);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>hh);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(Ys,{}),children:[{path:"manage",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>qh);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>dp);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:Ys},{path:"/404",Component:en},{path:"/503",Component:nc},{path:"*",Component:en}]);function Td(){return I.get("/user/info")}const na={token:ft()?.value||"",userInfo:null,isLoggedIn:!!ft()?.value,loading:!1,error:null},mt=Fl("user/fetchUserInfo",async()=>(await Td()).data,{condition:(s,{getState:n})=>{const{user:t}=n();return!!t.token&&!t.loading}}),kr=Ol({name:"user",initialState:na,reducers:{setToken(s,n){s.token=n.payload,s.isLoggedIn=!!n.payload},resetUserState:()=>na},extraReducers:s=>{s.addCase(mt.pending,n=>{n.loading=!0,n.error=null}).addCase(mt.fulfilled,(n,t)=>{n.loading=!1,n.userInfo=t.payload,n.error=null}).addCase(mt.rejected,(n,t)=>{if(n.loading=!1,n.error=t.error.message||"Failed to fetch user info",!n.token)return na})}}),{setToken:Dd,resetUserState:Pd}=kr.actions,Ed=s=>s.user.userInfo,Rd=kr.reducer,Tr=Ll({reducer:{user:Rd}});ft()?.value&&Tr.dispatch(mt());zl.use(Al).use($l).init({resources:{"en-US":window.XBOARD_TRANSLATIONS?.["en-US"]||{},"zh-CN":window.XBOARD_TRANSLATIONS?.["zh-CN"]||{},"ko-KR":window.XBOARD_TRANSLATIONS?.["ko-KR"]||{}},fallbackLng:"zh-CN",supportedLngs:["en-US","zh-CN","ko-KR"],detection:{order:["querystring","localStorage","navigator"],lookupQuerystring:"lang",lookupLocalStorage:"i18nextLng",caches:["localStorage"]},interpolation:{escapeValue:!1}});const Id=new Ul;Hl.createRoot(document.getElementById("root")).render(e.jsx(ql.StrictMode,{children:e.jsx(Kl,{client:Id,children:e.jsx(Bl,{store:Tr,children:e.jsxs(ec,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(Gl,{router:kd}),e.jsx(Wl,{richColors:!0,position:"top-right"})]})})})}));const We=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:N("rounded-xl border bg-card text-card-foreground shadow",s),...n}));We.displayName="Card";const ts=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:N("flex flex-col space-y-1.5 p-6",s),...n}));ts.displayName="CardHeader";const Cs=u.forwardRef(({className:s,...n},t)=>e.jsx("h3",{ref:t,className:N("font-semibold leading-none tracking-tight",s),...n}));Cs.displayName="CardTitle";const et=u.forwardRef(({className:s,...n},t)=>e.jsx("p",{ref:t,className:N("text-sm text-muted-foreground",s),...n}));et.displayName="CardDescription";const as=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:N("p-6 pt-0",s),...n}));as.displayName="CardContent";const Vd=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:N("flex items-center p-6 pt-0",s),...n}));Vd.displayName="CardFooter";const T=u.forwardRef(({className:s,type:n,...t},r)=>e.jsx("input",{type:n,className:N("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:r,...t}));T.displayName="Input";const Dr=u.forwardRef(({className:s,...n},t)=>{const[r,a]=u.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:r?"text":"password",className:N("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...n}),e.jsx(P,{type:"button",size:"icon",variant:"ghost",className:"absolute right-1 top-1/2 h-6 w-6 -translate-y-1/2 rounded-md text-muted-foreground",onClick:()=>a(i=>!i),children:r?e.jsx(Yl,{size:18}):e.jsx(Ql,{size:18})})]})});Dr.displayName="PasswordInput";const Md=s=>I({url:"/passport/auth/login",method:"post",data:s});function Fd({className:s,onForgotPassword:n,...t}){const r=Ts(),a=yn(),{t:i}=V("auth"),l=x.object({email:x.string().min(1,{message:i("signIn.validation.emailRequired")}),password:x.string().min(1,{message:i("signIn.validation.passwordRequired")}).min(7,{message:i("signIn.validation.passwordLength")})}),d=ge({resolver:Ne(l),defaultValues:{email:"",password:""}});async function m(o){try{const{data:c}=await Md(o);vc(c.auth_data),a(Dd(c.auth_data)),await a(mt()).unwrap(),r("/")}catch(c){console.error("Login failed:",c),c.response?.data?.message&&d.setError("root",{message:c.response.data.message})}}return e.jsx("div",{className:N("grid gap-6",s),...t,children:e.jsx(_e,{...d,children:e.jsx("form",{onSubmit:d.handleSubmit(m),className:"space-y-4",children:e.jsxs("div",{className:"space-y-4",children:[d.formState.errors.root&&e.jsx("div",{className:"text-sm text-destructive",children:d.formState.errors.root.message}),e.jsx(g,{control:d.control,name:"email",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:i("signIn.email")}),e.jsx(y,{children:e.jsx(T,{placeholder:i("signIn.emailPlaceholder"),autoComplete:"email",...o})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"password",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:i("signIn.password")}),e.jsx(y,{children:e.jsx(Dr,{placeholder:i("signIn.passwordPlaceholder"),autoComplete:"current-password",...o})}),e.jsx(D,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(P,{variant:"link",type:"button",className:"px-0 text-sm font-normal text-muted-foreground hover:text-primary",onClick:n,children:i("signIn.forgotPassword")})}),e.jsx(P,{className:"w-full",size:"lg",loading:d.formState.isSubmitting,children:i("signIn.submit")})]})})})})}const be=Nn,Je=_n,Od=wn,yt=Ca,Pr=u.forwardRef(({className:s,...n},t)=>e.jsx(zt,{ref:t,className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n}));Pr.displayName=zt.displayName;const fe=u.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(Od,{children:[e.jsx(Pr,{}),e.jsxs(At,{ref:r,className:N("max-h-[95%] overflow-auto fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...t,children:[n,e.jsxs(Ca,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(ss,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));fe.displayName=At.displayName;const Ce=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-1.5 text-center sm:text-left",s),...n});Ce.displayName="DialogHeader";const ze=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});ze.displayName="DialogFooter";const ye=u.forwardRef(({className:s,...n},t)=>e.jsx($t,{ref:t,className:N("text-lg font-semibold leading-none tracking-tight",s),...n}));ye.displayName=$t.displayName;const Te=u.forwardRef(({className:s,...n},t)=>e.jsx(Ut,{ref:t,className:N("text-sm text-muted-foreground",s),...n}));Te.displayName=Ut.displayName;const st=As("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),J=u.forwardRef(({className:s,variant:n,size:t,asChild:r=!1,...a},i)=>{const l=r?Na:"button";return e.jsx(l,{className:N(st({variant:n,size:t,className:s})),ref:i,...a})});J.displayName="Button";const Ss=Zl,ks=ei,Ld=si,zd=u.forwardRef(({className:s,inset:n,children:t,...r},a)=>e.jsxs(Cn,{ref:a,className:N("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",n&&"pl-8",s),...r,children:[t,e.jsx(Sa,{className:"ml-auto h-4 w-4"})]}));zd.displayName=Cn.displayName;const Ad=u.forwardRef(({className:s,...n},t)=>e.jsx(Sn,{ref:t,className:N("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...n}));Ad.displayName=Sn.displayName;const fs=u.forwardRef(({className:s,sideOffset:n=4,...t},r)=>e.jsx(Jl,{children:e.jsx(kn,{ref:r,sideOffset:n,className:N("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...t})}));fs.displayName=kn.displayName;const je=u.forwardRef(({className:s,inset:n,...t},r)=>e.jsx(Tn,{ref:r,className:N("relative flex cursor-default cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n&&"pl-8",s),...t}));je.displayName=Tn.displayName;const $d=u.forwardRef(({className:s,children:n,checked:t,...r},a)=>e.jsxs(Dn,{ref:a,className:N("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:t,...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Pn,{children:e.jsx($s,{className:"h-4 w-4"})})}),n]}));$d.displayName=Dn.displayName;const Ud=u.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(En,{ref:r,className:N("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...t,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Pn,{children:e.jsx(Xl,{className:"h-4 w-4 fill-current"})})}),n]}));Ud.displayName=En.displayName;const Ra=u.forwardRef(({className:s,inset:n,...t},r)=>e.jsx(Rn,{ref:r,className:N("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",s),...t}));Ra.displayName=Rn.displayName;const tt=u.forwardRef(({className:s,...n},t)=>e.jsx(In,{ref:t,className:N("-mx-1 my-1 h-px bg-muted",s),...n}));tt.displayName=In.displayName;const va=({className:s,...n})=>e.jsx("span",{className:N("ml-auto text-xs tracking-widest opacity-60",s),...n});va.displayName="DropdownMenuShortcut";const ra=[{code:"en-US",name:"English",flag:ti,shortName:"EN"},{code:"zh-CN",name:"中文",flag:ai,shortName:"CN"},{code:"ko-KR",name:"한국어",flag:ni,shortName:"KR"}];function Er(){const{i18n:s}=V(),n=a=>{s.changeLanguage(a)},t=ra.find(a=>a.code===s.language)||ra[1],r=t.flag;return e.jsxs(Ss,{children:[e.jsx(ks,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 px-2 gap-1",children:[e.jsx(r,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:"text-sm font-medium",children:t.shortName})]})}),e.jsx(fs,{align:"end",className:"w-[120px]",children:ra.map(a=>{const i=a.flag,l=a.code===s.language;return e.jsxs(je,{onClick:()=>n(a.code),className:N("flex items-center gap-2 px-2 py-1.5 cursor-pointer",l&&"bg-accent"),children:[e.jsx(i,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:N("text-sm",l&&"font-medium"),children:a.name})]},a.code)})})]})}function Hd(){const[s,n]=u.useState(!1),{t}=V("auth"),r=t("signIn.resetPassword.command");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"container relative grid h-svh flex-col items-center justify-center bg-primary-foreground lg:max-w-none lg:px-0",children:[e.jsx("div",{className:"absolute right-4 top-4 md:right-8 md:top-8",children:e.jsx(Er,{})}),e.jsxs("div",{className:"mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[480px] lg:p-8",children:[e.jsxs("div",{className:"flex flex-col space-y-2 text-center",children:[e.jsx("h1",{className:"text-3xl font-bold",children:window?.settings?.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:window?.settings?.description})]}),e.jsxs(We,{className:"p-6",children:[e.jsxs("div",{className:"flex flex-col space-y-2 text-left",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:t("signIn.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("signIn.description")})]}),e.jsx(Fd,{onForgotPassword:()=>n(!0)})]})]})]}),e.jsx(be,{open:s,onOpenChange:n,children:e.jsx(fe,{children:e.jsxs(Ce,{children:[e.jsx(ye,{children:t("signIn.resetPassword.title")}),e.jsx(Te,{children:t("signIn.resetPassword.description")}),e.jsx("div",{className:"mt-4",children:e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"rounded-md bg-secondary p-4 pr-12 text-sm",children:r}),e.jsx(J,{variant:"ghost",size:"icon",className:"absolute right-2 top-2 h-8 w-8 hover:bg-secondary-foreground/10",onClick:()=>Ft(r).then(()=>{A.success(t("common:copy.success"))}),children:e.jsx(ri,{className:"h-4 w-4"})})]})})]})})})]})}const qd=Object.freeze(Object.defineProperty({__proto__:null,default:Hd},Symbol.toStringTag,{value:"Module"})),Ee=u.forwardRef(({className:s,fadedBelow:n=!1,fixedHeight:t=!1,...r},a)=>e.jsx("div",{ref:a,className:N("relative flex h-full w-full flex-col",n&&"after:pointer-events-none after:absolute after:bottom-0 after:left-0 after:hidden after:h-32 after:w-full after:bg-[linear-gradient(180deg,_transparent_10%,_hsl(var(--background))_70%)] after:md:block",t&&"md:h-svh",s),...r}));Ee.displayName="Layout";const Re=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:N("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...n}));Re.displayName="LayoutHeader";const Fe=u.forwardRef(({className:s,fixedHeight:n,...t},r)=>e.jsx("div",{ref:r,className:N("flex-1 overflow-hidden px-4 py-6 md:px-8",n&&"h-[calc(100%-var(--header-height))]",s),...t}));Fe.displayName="LayoutBody";const Rr=li,Ir=ii,Vr=oi,ve=ci,he=di,pe=ui,ce=u.forwardRef(({className:s,sideOffset:n=4,...t},r)=>e.jsx(Vn,{ref:r,sideOffset:n,className:N("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...t}));ce.displayName=Vn.displayName;function Wt(){const{pathname:s}=_a();return{checkActiveNav:t=>{if(t==="/"&&s==="/")return!0;const r=t.replace(/^\//,""),a=s.replace(/^\//,"");return r?a.startsWith(r):!1}}}function Mr({key:s,defaultValue:n}){const[t,r]=u.useState(()=>{const a=localStorage.getItem(s);return a!==null?JSON.parse(a):n});return u.useEffect(()=>{localStorage.setItem(s,JSON.stringify(t))},[t,s]),[t,r]}function Kd(){const[s,n]=Mr({key:"collapsed-sidebar-items",defaultValue:[]}),t=a=>!s.includes(a);return{isExpanded:t,toggleItem:a=>{t(a)?n([...s,a]):n(s.filter(i=>i!==a))}}}function Bd({links:s,isCollapsed:n,className:t,closeNav:r}){const{t:a}=V(),i=({sub:l,...d})=>{const m=`${a(d.title)}-${d.href}`;return n&&l?u.createElement(Yd,{...d,sub:l,key:m,closeNav:r}):n?u.createElement(Wd,{...d,key:m,closeNav:r}):l?u.createElement(Gd,{...d,sub:l,key:m,closeNav:r}):u.createElement(Fr,{...d,key:m,closeNav:r})};return e.jsx("div",{"data-collapsed":n,className:N("group border-b bg-background py-2 transition-[max-height,padding] duration-500 data-[collapsed=true]:py-2 md:border-none",t),children:e.jsx(ve,{delayDuration:0,children:e.jsx("nav",{className:"grid gap-1 group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2",children:s.map(i)})})})}function Fr({title:s,icon:n,label:t,href:r,closeNav:a,subLink:i=!1}){const{checkActiveNav:l}=Wt(),{t:d}=V();return e.jsxs(Us,{to:r,onClick:a,className:N(nt({variant:l(r)?"secondary":"ghost",size:"sm"}),"h-12 justify-start text-wrap rounded-none px-6",i&&"h-10 w-full border-l border-l-slate-500 px-2"),"aria-current":l(r)?"page":void 0,children:[e.jsx("div",{className:"mr-2",children:n}),d(s),t&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:d(t)})]})}function Gd({title:s,icon:n,label:t,sub:r,closeNav:a}){const{checkActiveNav:i}=Wt(),{isExpanded:l,toggleItem:d}=Kd(),{t:m}=V(),o=!!r?.find(_=>i(_.href)),c=m(s),h=l(c)||o;return e.jsxs(Rr,{open:h,onOpenChange:()=>d(c),children:[e.jsxs(Ir,{className:N(nt({variant:o?"secondary":"ghost",size:"sm"}),"group h-12 w-full justify-start rounded-none px-6"),children:[e.jsx("div",{className:"mr-2",children:n}),m(s),t&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:m(t)}),e.jsx("span",{className:N('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(Mn,{stroke:1})})]}),e.jsx(Vr,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:r.map(_=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(Fr,{..._,subLink:!0,closeNav:a})},m(_.title)))})})]})}function Wd({title:s,icon:n,label:t,href:r,closeNav:a}){const{checkActiveNav:i}=Wt(),{t:l}=V();return e.jsxs(he,{delayDuration:0,children:[e.jsx(pe,{asChild:!0,children:e.jsxs(Us,{to:r,onClick:a,className:N(nt({variant:i(r)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[n,e.jsx("span",{className:"sr-only",children:l(s)})]})}),e.jsxs(ce,{side:"right",className:"flex items-center gap-4",children:[l(s),t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:l(t)})]})]})}function Yd({title:s,icon:n,label:t,sub:r,closeNav:a}){const{checkActiveNav:i}=Wt(),{t:l}=V(),d=!!r?.find(m=>i(m.href));return e.jsxs(Ss,{children:[e.jsxs(he,{delayDuration:0,children:[e.jsx(pe,{asChild:!0,children:e.jsx(ks,{asChild:!0,children:e.jsx(P,{variant:d?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:n})})}),e.jsxs(ce,{side:"right",className:"flex items-center gap-4",children:[l(s)," ",t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:l(t)}),e.jsx(Mn,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(fs,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(Ra,{children:[l(s)," ",t?`(${l(t)})`:""]}),e.jsx(tt,{}),r.map(({title:m,icon:o,label:c,href:h})=>e.jsx(je,{asChild:!0,children:e.jsxs(Us,{to:h,onClick:a,className:`${i(h)?"bg-secondary":""}`,children:[o," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:l(m)}),c&&e.jsx("span",{className:"ml-auto text-xs",children:l(c)})]})},`${l(m)}-${h}`))]})]})}const Or=[{title:"nav:dashboard",label:"",href:"/",icon:e.jsx(mi,{size:18})},{title:"nav:systemManagement",label:"",href:"",icon:e.jsx(xi,{size:18}),sub:[{title:"nav:systemConfig",label:"",href:"/config/system",icon:e.jsx(Fn,{size:18})},{title:"nav:pluginManagement",label:"",href:"/config/plugin",icon:e.jsx(ka,{size:18})},{title:"nav:themeConfig",label:"",href:"/config/theme",icon:e.jsx(hi,{size:18})},{title:"nav:noticeManagement",label:"",href:"/config/notice",icon:e.jsx(pi,{size:18})},{title:"nav:paymentConfig",label:"",href:"/config/payment",icon:e.jsx(Ba,{size:18})},{title:"nav:knowledgeManagement",label:"",href:"/config/knowledge",icon:e.jsx(fi,{size:18})}]},{title:"nav:nodeManagement",label:"",href:"",icon:e.jsx(On,{size:18}),sub:[{title:"nav:nodeManagement",label:"",href:"/server/manage",icon:e.jsx(gi,{size:18})},{title:"nav:permissionGroupManagement",label:"",href:"/server/group",icon:e.jsx(Ln,{size:18})},{title:"nav:routeManagement",label:"",href:"/server/route",icon:e.jsx(ji,{size:18})}]},{title:"nav:subscriptionManagement",label:"",href:"",icon:e.jsx(vi,{size:18}),sub:[{title:"nav:planManagement",label:"",href:"/finance/plan",icon:e.jsx(bi,{size:18})},{title:"nav:orderManagement",label:"",href:"/finance/order",icon:e.jsx(Ba,{size:18})},{title:"nav:couponManagement",label:"",href:"/finance/coupon",icon:e.jsx(yi,{size:18})}]},{title:"nav:userManagement",label:"",href:"",icon:e.jsx(Ni,{size:18}),sub:[{title:"nav:userManagement",label:"",href:"/user/manage",icon:e.jsx(_i,{size:18})},{title:"nav:ticketManagement",label:"",href:"/user/ticket",icon:e.jsx(zn,{size:18})}]}];function Qd({className:s,isCollapsed:n,setIsCollapsed:t}){const[r,a]=u.useState(!1),{t:i}=V();return u.useEffect(()=>{r?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[r]),e.jsxs("aside",{className:N(`fixed left-0 right-0 top-0 z-50 flex h-auto flex-col border-r-2 border-r-muted transition-[width] md:bottom-0 md:right-auto md:h-svh ${n?"md:w-14":"md:w-64"}`,s),children:[e.jsx("div",{onClick:()=>a(!1),className:`absolute inset-0 transition-[opacity] delay-100 duration-700 ${r?"h-svh opacity-50":"h-0 opacity-0"} w-full bg-black md:hidden`}),e.jsxs(Ee,{className:"flex h-full flex-col",children:[e.jsxs(Re,{className:"sticky top-0 justify-between px-4 py-3 shadow md:px-4",children:[e.jsxs("div",{className:`flex items-center ${n?"":"gap-2"}`,children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",className:`transition-all ${n?"h-6 w-6":"h-8 w-8"}`,children:[e.jsx("rect",{width:"256",height:"256",fill:"none"}),e.jsx("line",{x1:"208",y1:"128",x2:"128",y2:"208",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"16"}),e.jsx("line",{x1:"192",y1:"40",x2:"40",y2:"192",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"16"}),e.jsx("span",{className:"sr-only",children:"Website Name"})]}),e.jsx("div",{className:`flex flex-col justify-end truncate ${n?"invisible w-0":"visible w-auto"}`,children:e.jsx("span",{className:"font-medium",children:window?.settings?.title})})]}),e.jsx(P,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":i("common:toggleNavigation"),"aria-controls":"sidebar-menu","aria-expanded":r,onClick:()=>a(l=>!l),children:r?e.jsx(wi,{}):e.jsx(Ci,{})})]}),e.jsx(Bd,{id:"sidebar-menu",className:N("flex-1 overflow-auto",r?"block":"hidden md:block","md:py-2"),closeNav:()=>a(!1),isCollapsed:n,links:Or}),e.jsx("div",{className:N("border-t border-border/50 bg-background","px-4 py-2.5 text-xs text-muted-foreground",r?"block":"hidden md:block",n?"text-center":"text-left"),children:e.jsxs("div",{className:N("flex items-center gap-1.5",n?"justify-center":"justify-start"),children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-green-500"}),e.jsxs("span",{className:N("tracking-wide whitespace-nowrap","transition-opacity duration-200",n&&"md:opacity-0"),children:["v",window?.settings?.version]})]})}),e.jsx(P,{onClick:()=>t(l=>!l),size:"icon",variant:"outline",className:"absolute -right-5 top-1/2 hidden rounded-full md:inline-flex","aria-label":i("common:toggleSidebar"),children:e.jsx(Si,{stroke:1.5,className:`h-5 w-5 ${n?"rotate-180":""}`})})]})]})}function Jd(){const[s,n]=Mr({key:"collapsed-sidebar",defaultValue:!1});return u.useEffect(()=>{const t=()=>{n(window.innerWidth<768?!1:s)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[s,n]),[s,n]}function Xd(){const[s,n]=Jd();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(Qd,{isCollapsed:s,setIsCollapsed:n}),e.jsx("main",{id:"content",className:`overflow-x-hidden pt-16 transition-[margin] md:overflow-y-hidden md:pt-0 ${s?"md:ml-14":"md:ml-64"} h-full`,children:e.jsx(wa,{})})]})}const Zd=Object.freeze(Object.defineProperty({__proto__:null,default:Xd},Symbol.toStringTag,{value:"Module"})),Ms=u.forwardRef(({className:s,...n},t)=>e.jsx(Le,{ref:t,className:N("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...n}));Ms.displayName=Le.displayName;const eu=({children:s,...n})=>e.jsx(be,{...n,children:e.jsx(fe,{className:"overflow-hidden p-0",children:e.jsx(Ms,{className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:s})})}),Ks=u.forwardRef(({className:s,...n},t)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(ki,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(Le.Input,{ref:t,className:N("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",s),...n})]}));Ks.displayName=Le.Input.displayName;const Fs=u.forwardRef(({className:s,...n},t)=>e.jsx(Le.List,{ref:t,className:N("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...n}));Fs.displayName=Le.List.displayName;const Bs=u.forwardRef((s,n)=>e.jsx(Le.Empty,{ref:n,className:"py-6 text-center text-sm",...s}));Bs.displayName=Le.Empty.displayName;const Ye=u.forwardRef(({className:s,...n},t)=>e.jsx(Le.Group,{ref:t,className:N("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",s),...n}));Ye.displayName=Le.Group.displayName;const rt=u.forwardRef(({className:s,...n},t)=>e.jsx(Le.Separator,{ref:t,className:N("-mx-1 h-px bg-border",s),...n}));rt.displayName=Le.Separator.displayName;const Me=u.forwardRef(({className:s,...n},t)=>e.jsx(Le.Item,{ref:t,className:N("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...n}));Me.displayName=Le.Item.displayName;function su(){const s=[];for(const n of Or)if(n.href&&s.push(n),n.sub)for(const t of n.sub)s.push({...t,parent:n.title});return s}function Ke(){const[s,n]=u.useState(!1),t=Ts(),r=su(),{t:a}=V("search"),{t:i}=V("nav");u.useEffect(()=>{const d=m=>{m.key==="k"&&(m.metaKey||m.ctrlKey)&&(m.preventDefault(),n(o=>!o))};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[]);const l=u.useCallback(d=>{n(!1),t(d)},[t]);return e.jsxs(e.Fragment,{children:[e.jsxs(J,{variant:"outline",className:"relative h-9 w-9 p-0 xl:h-10 xl:w-60 xl:justify-start xl:px-3 xl:py-2",onClick:()=>n(!0),children:[e.jsx(An,{className:"h-4 w-4 xl:mr-2"}),e.jsx("span",{className:"hidden xl:inline-flex",children:a("placeholder")}),e.jsx("span",{className:"sr-only",children:a("shortcut.label")}),e.jsx("kbd",{className:"pointer-events-none absolute right-1.5 top-2 hidden h-6 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium opacity-100 xl:flex",children:a("shortcut.key")})]}),e.jsxs(eu,{open:s,onOpenChange:n,children:[e.jsx(Ks,{placeholder:a("placeholder")}),e.jsxs(Fs,{children:[e.jsx(Bs,{children:a("noResults")}),e.jsx(Ye,{heading:a("title"),children:r.map(d=>e.jsxs(Me,{value:`${d.parent?d.parent+" ":""}${d.title}`,onSelect:()=>l(d.href),children:[e.jsx("div",{className:"mr-2",children:d.icon}),e.jsx("span",{children:i(d.title)}),d.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:i(d.parent)})]},d.href))})]})]})]})}const ne=window?.settings?.secure_path,Lr=5*60*1e3,ba=new Map,tu=s=>{const n=ba.get(s);return n?Date.now()-n.timestamp>Lr?(ba.delete(s),null):n.data:null},au=(s,n)=>{ba.set(s,{data:n,timestamp:Date.now()})},nu=async(s,n=Lr)=>{const t=tu(s);if(t)return t;const r=await I.get(s);return au(s,r),r},Ot={getList:s=>I.post(`${ne}/user/fetch`,s),update:s=>I.post(`${ne}/user/update`,s),resetSecret:s=>I.post(`${ne}/user/resetSecret`,{id:s}),generate:s=>I.post(`${ne}/user/generate`,s),getStats:s=>I.post(`${ne}/stat/getStatUser`,s),destroy:s=>I.post(`${ne}/user/destroy`,{id:s}),sendMail:s=>I.post(`${ne}/user/sendMail`,s),dumpCSV:s=>I.post(`${ne}/user/dumpCSV`,s,{responseType:"blob"}),batchBan:s=>I.post(`${ne}/user/ban`,s)},nn={getList:()=>nu(`${ne}/notice/fetch`),save:s=>I.post(`${ne}/notice/save`,s),drop:s=>I.post(`${ne}/notice/drop`,{id:s}),updateStatus:s=>I.post(`${ne}/notice/show`,{id:s}),sort:s=>I.post(`${ne}/notice/sort`,{ids:s})},la={getList:s=>I.post(`${ne}/ticket/fetch`,s),getInfo:s=>I.get(`${ne}/ticket/fetch?id=${s}`),reply:s=>I.post(`${ne}/ticket/reply`,s),close:s=>I.post(`${ne}/ticket/close`,{id:s})},rn={getSystemStatus:()=>I.get(`${ne}/system/getSystemStatus`),getQueueStats:()=>I.get(`${ne}/system/getQueueStats`),getQueueWorkload:()=>I.get(`${ne}/system/getQueueWorkload`),getQueueMasters:()=>I.get(`${ne}/system/getQueueMasters`),getSystemLog:s=>I.get(`${ne}/system/getSystemLog`,{params:s})},_s={getPluginList:()=>I.get(`${ne}/plugin/getPlugins`),uploadPlugin:s=>{const n=new FormData;return n.append("file",s),I.post(`${ne}/plugin/upload`,n,{headers:{"Content-Type":"multipart/form-data"}})},deletePlugin:s=>I.post(`${ne}/plugin/delete`,{code:s}),installPlugin:s=>I.post(`${ne}/plugin/install`,{code:s}),uninstallPlugin:s=>I.post(`${ne}/plugin/uninstall`,{code:s}),enablePlugin:s=>I.post(`${ne}/plugin/enable`,{code:s}),disablePlugin:s=>I.post(`${ne}/plugin/disable`,{code:s}),getPluginConfig:s=>I.get(`${ne}/plugin/config`,{params:{code:s}}),updatePluginConfig:(s,n)=>I.post(`${ne}/plugin/config`,{code:s,config:n})},ru=()=>I.get(`${ne}/update/check`),lu=()=>I.post(`${ne}/update/execute`),iu=As("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/10",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function q({className:s,variant:n,...t}){return e.jsx("div",{className:N(iu({variant:n}),s),...t})}const zs=u.forwardRef(({className:s,children:n,...t},r)=>e.jsxs($n,{ref:r,className:N("relative overflow-hidden",s),...t,children:[e.jsx(Ti,{className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(Lt,{}),e.jsx(Di,{})]}));zs.displayName=$n.displayName;const Lt=u.forwardRef(({className:s,orientation:n="vertical",...t},r)=>e.jsx(Un,{ref:r,orientation:n,className:N("flex touch-none select-none transition-colors",n==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",n==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",s),...t,children:e.jsx(Pi,{className:"relative flex-1 rounded-full bg-border"})}));Lt.displayName=Un.displayName;function ou(){const{t:s}=V("common"),[n,t]=u.useState(!1),{data:r}=re({queryKey:["checkUpdate"],queryFn:async()=>await ru(),refetchInterval:1e3*60*60}),a=r?.data,i=es({mutationFn:lu,onSuccess:l=>{const d=l.data;d.success?(A.success(s("update.updateSuccess")),t(!1)):A.error(d.message)},onError:()=>{A.error(s("update.updateFailed"))}});return a?.has_update?e.jsxs(e.Fragment,{children:[e.jsxs(P,{size:"icon",variant:"ghost",className:"rounded-full relative",onClick:()=>t(!0),children:[e.jsx(Ei,{size:20,className:"text-red-500"}),e.jsx("span",{className:"absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full"})]}),e.jsx(be,{open:n,onOpenChange:t,children:e.jsxs(fe,{className:"sm:max-w-[500px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:s("update.title")}),e.jsxs(Te,{children:[s("update.newVersion")," ",a?.latest_version]})]}),e.jsxs("div",{className:"py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[s("update.currentVersion"),":",a?.current_version]}),e.jsxs(q,{variant:"outline",children:[s("update.latestVersion"),":",a?.latest_version]})]}),e.jsx(zs,{className:"h-[200px] rounded-md border p-4",children:e.jsx("div",{className:"space-y-4",children:a?.update_logs.map(l=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(q,{variant:"secondary",children:l.version}),e.jsx("span",{className:"text-sm text-muted-foreground",children:Ze(new Date(l.date),"yyyy-MM-dd HH:mm")})]}),e.jsx("p",{className:"text-sm",children:l.message})]},l.version))})})]}),e.jsxs(ze,{children:[e.jsx(P,{variant:"outline",onClick:()=>t(!1),children:s("update.updateLater")}),e.jsx(P,{onClick:()=>i.mutate(),disabled:i.isPending,children:i.isPending?s("update.updating"):s("update.updateNow")})]})]})})]}):null}function Ae(){const{theme:s,setTheme:n}=sc();return u.useEffect(()=>{const t=s==="dark"?"#020817":"#fff",r=document.querySelector("meta[name='theme-color']");r&&r.setAttribute("content",t)},[s]),e.jsxs(e.Fragment,{children:[e.jsx(P,{size:"icon",variant:"ghost",className:"rounded-full",onClick:()=>n(s==="light"?"dark":"light"),children:s==="light"?e.jsx(Ri,{size:20}):e.jsx(Ii,{size:20})}),e.jsx(Er,{}),e.jsx(ou,{})]})}const zr=u.forwardRef(({className:s,...n},t)=>e.jsx(Hn,{ref:t,className:N("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...n}));zr.displayName=Hn.displayName;const Ar=u.forwardRef(({className:s,...n},t)=>e.jsx(qn,{ref:t,className:N("aspect-square h-full w-full",s),...n}));Ar.displayName=qn.displayName;const $r=u.forwardRef(({className:s,...n},t)=>e.jsx(Kn,{ref:t,className:N("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...n}));$r.displayName=Kn.displayName;function $e(){const s=Ts(),n=yn(),t=Vi(Ed),{t:r}=V(["common"]),a=()=>{yr(),n(Pd()),s("/sign-in")},i=t?.email?.split("@")[0]||r("common:user"),l=i.substring(0,2).toUpperCase();return e.jsxs(Ss,{children:[e.jsx(ks,{asChild:!0,children:e.jsx(P,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(zr,{className:"h-8 w-8",children:[e.jsx(Ar,{src:t?.avatar_url,alt:i}),e.jsx($r,{children:l})]})})}),e.jsxs(fs,{className:"w-56",align:"end",forceMount:!0,children:[e.jsx(Ra,{className:"font-normal",children:e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("p",{className:"text-sm font-medium leading-none",children:i}),e.jsx("p",{className:"text-xs leading-none text-muted-foreground",children:t?.email||r("common:defaultEmail")})]})}),e.jsx(tt,{}),e.jsx(je,{asChild:!0,children:e.jsxs(Us,{to:"/config/system",children:[r("common:settings"),e.jsx(va,{children:"⌘S"})]})}),e.jsx(tt,{}),e.jsxs(je,{onClick:a,children:[r("common:logout"),e.jsx(va,{children:"⇧⌘Q"})]})]})]})}const G=Mi,He=Hi,W=Fi,K=u.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(Bn,{ref:r,className:N("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",s),...t,children:[n,e.jsx(Oi,{asChild:!0,children:e.jsx(Ta,{className:"h-4 w-4 opacity-50"})})]}));K.displayName=Bn.displayName;const Ur=u.forwardRef(({className:s,...n},t)=>e.jsx(Gn,{ref:t,className:N("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(Li,{className:"h-4 w-4"})}));Ur.displayName=Gn.displayName;const Hr=u.forwardRef(({className:s,...n},t)=>e.jsx(Wn,{ref:t,className:N("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(Ta,{className:"h-4 w-4"})}));Hr.displayName=Wn.displayName;const B=u.forwardRef(({className:s,children:n,position:t="popper",...r},a)=>e.jsx(zi,{children:e.jsxs(Yn,{ref:a,className:N("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",s),position:t,...r,children:[e.jsx(Ur,{}),e.jsx(Ai,{className:N("p-1",t==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx(Hr,{})]})}));B.displayName=Yn.displayName;const cu=u.forwardRef(({className:s,...n},t)=>e.jsx(Qn,{ref:t,className:N("px-2 py-1.5 text-sm font-semibold",s),...n}));cu.displayName=Qn.displayName;const z=u.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(Jn,{ref:r,className:N("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...t,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx($i,{children:e.jsx($s,{className:"h-4 w-4"})})}),e.jsx(Ui,{children:n})]}));z.displayName=Jn.displayName;const du=u.forwardRef(({className:s,...n},t)=>e.jsx(Xn,{ref:t,className:N("-mx-1 my-1 h-px bg-muted",s),...n}));du.displayName=Xn.displayName;function Gs({className:s,classNames:n,showOutsideDays:t=!0,...r}){return e.jsx(qi,{showOutsideDays:t,className:N("p-3",s),classNames:{months:"flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",month:"space-y-4",caption:"flex justify-center pt-1 relative items-center",caption_label:"text-sm font-medium",nav:"space-x-1 flex items-center",nav_button:N(st({variant:"outline"}),"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"),nav_button_previous:"absolute left-1",nav_button_next:"absolute right-1",table:"w-full border-collapse space-y-1",head_row:"flex",head_cell:"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",row:"flex w-full mt-2",cell:N("relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md",r.mode==="range"?"[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md":"[&:has([aria-selected])]:rounded-md"),day:N(st({variant:"ghost"}),"h-8 w-8 p-0 font-normal aria-selected:opacity-100"),day_range_start:"day-range-start",day_range_end:"day-range-end",day_selected:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",day_today:"bg-accent text-accent-foreground",day_outside:"day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground",day_disabled:"text-muted-foreground opacity-50",day_range_middle:"aria-selected:bg-accent aria-selected:text-accent-foreground",day_hidden:"invisible",...n},components:{IconLeft:({className:a,...i})=>e.jsx(Zn,{className:N("h-4 w-4",a),...i}),IconRight:({className:a,...i})=>e.jsx(Sa,{className:N("h-4 w-4",a),...i})},...r})}Gs.displayName="Calendar";const vs=Bi,bs=Gi,xs=u.forwardRef(({className:s,align:n="center",sideOffset:t=4,...r},a)=>e.jsx(Ki,{children:e.jsx(er,{ref:a,align:n,sideOffset:t,className:N("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...r})}));xs.displayName=er.displayName;const Es={income:{main:"hsl(var(--primary))",gradient:{start:"hsl(var(--primary))",end:"transparent"}},commission:{main:"hsl(var(--secondary))",gradient:{start:"hsl(var(--secondary))",end:"transparent"}}},dt=s=>(s/100).toFixed(2),uu=({active:s,payload:n,label:t})=>{const{t:r}=V();return s&&n&&n.length?e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-sm",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:t}),n.map((a,i)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"h-2 w-2 rounded-full",style:{backgroundColor:a.color}}),e.jsxs("span",{className:"text-muted-foreground",children:[r(a.name),":"]}),e.jsx("span",{className:"font-medium",children:a.name.includes(r("dashboard:overview.amount"))?`¥${dt(a.value)}`:r("dashboard:overview.transactions",{count:a.value})})]},i))]}):null},mu=[{value:"7d",label:"dashboard:overview.last7Days"},{value:"30d",label:"dashboard:overview.last30Days"},{value:"90d",label:"dashboard:overview.last90Days"},{value:"180d",label:"dashboard:overview.last180Days"},{value:"365d",label:"dashboard:overview.lastYear"},{value:"custom",label:"dashboard:overview.customRange"}],xu=(s,n)=>{const t=new Date;if(s==="custom"&&n)return{startDate:n.from,endDate:n.to};let r;switch(s){case"7d":r=is(t,7);break;case"30d":r=is(t,30);break;case"90d":r=is(t,90);break;case"180d":r=is(t,180);break;case"365d":r=is(t,365);break;default:r=is(t,30)}return{startDate:r,endDate:t}};function hu(){const[s,n]=u.useState("amount"),[t,r]=u.useState("30d"),[a,i]=u.useState({from:is(new Date,7),to:new Date}),{t:l}=V(),{startDate:d,endDate:m}=xu(t,a),{data:o}=re({queryKey:["orderStat",{start_date:Ze(d,"yyyy-MM-dd"),end_date:Ze(m,"yyyy-MM-dd")}],queryFn:async()=>{const{data:c}=await bc({start_date:Ze(d,"yyyy-MM-dd"),end_date:Ze(m,"yyyy-MM-dd")});return c},refetchInterval:3e4});return e.jsxs(We,{children:[e.jsx(ts,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Cs,{children:l("dashboard:overview.title")}),e.jsxs(et,{children:[o?.summary.start_date," ",l("dashboard:overview.to")," ",o?.summary.end_date]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsxs(G,{value:t,onValueChange:c=>r(c),children:[e.jsx(K,{className:"w-[120px]",children:e.jsx(W,{placeholder:l("dashboard:overview.selectTimeRange")})}),e.jsx(B,{children:mu.map(c=>e.jsx(z,{value:c.value,children:l(c.label)},c.value))})]}),t==="custom"&&e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(J,{variant:"outline",className:N("min-w-0 justify-start text-left font-normal",!a&&"text-muted-foreground"),children:[e.jsx(jt,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:a?.from?a.to?e.jsxs(e.Fragment,{children:[Ze(a.from,"yyyy-MM-dd")," -"," ",Ze(a.to,"yyyy-MM-dd")]}):Ze(a.from,"yyyy-MM-dd"):l("dashboard:overview.selectDate")})]})}),e.jsx(xs,{className:"w-auto p-0",align:"end",children:e.jsx(Gs,{mode:"range",defaultMonth:a?.from,selected:{from:a?.from,to:a?.to},onSelect:c=>{c?.from&&c?.to&&i({from:c.from,to:c.to})},numberOfMonths:2})})]})]}),e.jsx(Gt,{value:s,onValueChange:c=>n(c),children:e.jsxs(vt,{children:[e.jsx(Ge,{value:"amount",children:l("dashboard:overview.amount")}),e.jsx(Ge,{value:"count",children:l("dashboard:overview.count")})]})})]})]})}),e.jsxs(as,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:l("dashboard:overview.totalIncome")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",dt(o?.summary?.paid_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l("dashboard:overview.totalTransactions",{count:o?.summary?.paid_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l("dashboard:overview.avgOrderAmount")," ¥",dt(o?.summary?.avg_paid_amount||0)]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:l("dashboard:overview.totalCommission")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",dt(o?.summary?.commission_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l("dashboard:overview.totalTransactions",{count:o?.summary?.commission_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l("dashboard:overview.commissionRate")," ",o?.summary?.commission_rate.toFixed(2)||0,"%"]})]})]}),e.jsx("div",{className:"h-[400px] w-full",children:e.jsx(Wi,{width:"100%",height:"100%",children:e.jsxs(Yi,{data:o?.list||[],margin:{top:20,right:20,left:0,bottom:0},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"incomeGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:Es.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Es.income.gradient.end,stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"commissionGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:Es.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Es.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(Qi,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:c=>Ze(new Date(c),"MM-dd",{locale:eo})}),e.jsx(Ji,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:c=>s==="amount"?`¥${dt(c)}`:l("dashboard:overview.transactions",{count:c})}),e.jsx(Xi,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(Zi,{content:e.jsx(uu,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(Ga,{type:"monotone",dataKey:"paid_total",name:l("dashboard:overview.orderAmount"),stroke:Es.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(Ga,{type:"monotone",dataKey:"commission_total",name:l("dashboard:overview.commissionAmount"),stroke:Es.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(Wa,{dataKey:"paid_count",name:l("dashboard:overview.orderCount"),fill:Es.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(Wa,{dataKey:"commission_count",name:l("dashboard:overview.commissionCount"),fill:Es.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})]})]})}function oe({className:s,...n}){return e.jsx("div",{className:N("animate-pulse rounded-md bg-primary/10",s),...n})}function pu(){return e.jsxs(We,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(oe,{className:"h-4 w-[120px]"}),e.jsx(oe,{className:"h-4 w-4"})]}),e.jsxs(as,{children:[e.jsx(oe,{className:"h-8 w-[140px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx(oe,{className:"h-4 w-[100px]"})]})]})]})}function fu(){return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:Array.from({length:8}).map((s,n)=>e.jsx(pu,{},n))})}var ae=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.CANCELLED=2]="CANCELLED",s[s.COMPLETED=3]="COMPLETED",s[s.DISCOUNTED=4]="DISCOUNTED",s))(ae||{});const ot={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},ct={0:"yellow-500",1:"blue-500",2:"red-500",3:"green-500",4:"green-500"};var os=(s=>(s[s.NEW=1]="NEW",s[s.RENEWAL=2]="RENEWAL",s[s.UPGRADE=3]="UPGRADE",s[s.RESET_FLOW=4]="RESET_FLOW",s))(os||{}),xe=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(xe||{});const Nt={0:"待确认",1:"发放中",2:"有效",3:"无效"},_t={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var Pe=(s=>(s.MONTH_PRICE="month_price",s.QUARTER_PRICE="quarter_price",s.HALF_YEAR_PRICE="half_year_price",s.YEAR_PRICE="year_price",s.TWO_YEAR_PRICE="two_year_price",s.THREE_YEAR_PRICE="three_year_price",s.ONETIME_PRICE="onetime_price",s.RESET_PRICE="reset_price",s))(Pe||{});const gu={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var ie=(s=>(s.Shadowsocks="shadowsocks",s.Vmess="vmess",s.Trojan="trojan",s.Hysteria="hysteria",s.Vless="vless",s.Tuic="tuic",s.Socks="socks",s.Naive="naive",s.Http="http",s.Mieru="mieru",s))(ie||{});const Xe=[{type:"shadowsocks",label:"Shadowsocks"},{type:"vmess",label:"VMess"},{type:"trojan",label:"Trojan"},{type:"hysteria",label:"Hysteria"},{type:"vless",label:"VLess"},{type:"tuic",label:"TUIC"},{type:"socks",label:"SOCKS"},{type:"naive",label:"Naive"},{type:"http",label:"HTTP"},{type:"mieru",label:"Mieru"}],qe={shadowsocks:"#489851",vmess:"#CB3180",trojan:"#EBB749",hysteria:"#5684e6",vless:"#1a1a1a",tuic:"#00C853",socks:"#2196F3",naive:"#9C27B0",http:"#FF5722",mieru:"#4CAF50"};var Be=(s=>(s[s.AMOUNT=1]="AMOUNT",s[s.PERCENTAGE=2]="PERCENTAGE",s))(Be||{});const ju={1:"按金额优惠",2:"按比例优惠"};var Vs=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(Vs||{}),Oe=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(Oe||{}),xt=(s=>(s.MONTH="monthly",s.QUARTER="quarterly",s.HALF_YEAR="half_yearly",s.YEAR="yearly",s.TWO_YEAR="two_yearly",s.THREE_YEAR="three_yearly",s.ONETIME="onetime",s.RESET="reset_traffic",s))(xt||{});function Rs({title:s,value:n,icon:t,trend:r,description:a,onClick:i,highlight:l,className:d}){return e.jsxs(We,{className:N("transition-colors",i&&"cursor-pointer hover:bg-muted/50",l&&"border-primary/50",d),onClick:i,children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Cs,{className:"text-sm font-medium",children:s}),t]}),e.jsxs(as,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n}),r?e.jsxs("div",{className:"flex items-center pt-1",children:[e.jsx(lo,{className:N("h-4 w-4",r.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:N("ml-1 text-xs",r.isPositive?"text-emerald-500":"text-red-500"),children:[r.isPositive?"+":"-",Math.abs(r.value),"%"]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:r.label})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:a})]})]})}function vu({className:s}){const n=Ts(),{t}=V(),{data:r,isLoading:a}=re({queryKey:["dashboardStats"],queryFn:async()=>(await yc()).data,refetchInterval:1e3*60*5});if(a||!r)return e.jsx(fu,{});const i=()=>{const l=new URLSearchParams;l.set("commission_status",xe.PENDING.toString()),l.set("status",ae.COMPLETED.toString()),l.set("commission_balance","gt:0"),n(`/finance/order?${l.toString()}`)};return e.jsxs("div",{className:N("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(Rs,{title:t("dashboard:stats.todayIncome"),value:Ls(r.todayIncome),icon:e.jsx(so,{className:"h-4 w-4 text-emerald-500"}),trend:{value:r.dayIncomeGrowth,label:t("dashboard:stats.vsYesterday"),isPositive:r.dayIncomeGrowth>0}}),e.jsx(Rs,{title:t("dashboard:stats.monthlyIncome"),value:Ls(r.currentMonthIncome),icon:e.jsx(to,{className:"h-4 w-4 text-blue-500"}),trend:{value:r.monthIncomeGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:r.monthIncomeGrowth>0}}),e.jsx(Rs,{title:t("dashboard:stats.pendingTickets"),value:r.ticketPendingTotal,icon:e.jsx(ao,{className:N("h-4 w-4",r.ticketPendingTotal>0?"text-orange-500":"text-muted-foreground")}),description:r.ticketPendingTotal>0?t("dashboard:stats.hasPendingTickets"):t("dashboard:stats.noPendingTickets"),onClick:()=>n("/user/ticket"),highlight:r.ticketPendingTotal>0}),e.jsx(Rs,{title:t("dashboard:stats.pendingCommission"),value:r.commissionPendingTotal,icon:e.jsx(no,{className:N("h-4 w-4",r.commissionPendingTotal>0?"text-blue-500":"text-muted-foreground")}),description:r.commissionPendingTotal>0?t("dashboard:stats.hasPendingCommission"):t("dashboard:stats.noPendingCommission"),onClick:i,highlight:r.commissionPendingTotal>0}),e.jsx(Rs,{title:t("dashboard:stats.monthlyNewUsers"),value:r.currentMonthNewUsers,icon:e.jsx(ha,{className:"h-4 w-4 text-blue-500"}),trend:{value:r.userGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:r.userGrowth>0}}),e.jsx(Rs,{title:t("dashboard:stats.totalUsers"),value:r.totalUsers,icon:e.jsx(ha,{className:"h-4 w-4 text-muted-foreground"}),description:t("dashboard:stats.activeUsers",{count:r.activeUsers})}),e.jsx(Rs,{title:t("dashboard:stats.monthlyUpload"),value:ps(r.monthTraffic.upload),icon:e.jsx(pt,{className:"h-4 w-4 text-emerald-500"}),description:t("dashboard:stats.todayTraffic",{value:ps(r.todayTraffic.upload)})}),e.jsx(Rs,{title:t("dashboard:stats.monthlyDownload"),value:ps(r.monthTraffic.download),icon:e.jsx(ro,{className:"h-4 w-4 text-blue-500"}),description:t("dashboard:stats.todayTraffic",{value:ps(r.todayTraffic.download)})})]})}const ya={today:{getValue:()=>{const s=oo();return{start:s,end:co(s,1)}}},last7days:{getValue:()=>{const s=new Date;return{start:is(s,7),end:s}}},last30days:{getValue:()=>{const s=new Date;return{start:is(s,30),end:s}}},custom:{getValue:()=>null}};function ln({selectedRange:s,customDateRange:n,onRangeChange:t,onCustomRangeChange:r}){const{t:a}=V(),i={today:a("dashboard:trafficRank.today"),last7days:a("dashboard:trafficRank.last7days"),last30days:a("dashboard:trafficRank.last30days"),custom:a("dashboard:trafficRank.customRange")};return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsxs(G,{value:s,onValueChange:t,children:[e.jsx(K,{className:"w-[120px]",children:e.jsx(W,{placeholder:a("dashboard:trafficRank.selectTimeRange")})}),e.jsx(B,{position:"popper",className:"z-50",children:Object.entries(ya).map(([l])=>e.jsx(z,{value:l,children:i[l]},l))})]}),s==="custom"&&e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(J,{variant:"outline",className:N("min-w-0 justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(jt,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:n?.from?n.to?e.jsxs(e.Fragment,{children:[Ze(n.from,"yyyy-MM-dd")," -"," ",Ze(n.to,"yyyy-MM-dd")]}):Ze(n.from,"yyyy-MM-dd"):e.jsx("span",{children:a("dashboard:trafficRank.selectDateRange")})})]})}),e.jsx(xs,{className:"w-auto p-0",align:"end",children:e.jsx(Gs,{mode:"range",defaultMonth:n?.from,selected:{from:n?.from,to:n?.to},onSelect:l=>{l?.from&&l?.to&&r({from:l.from,to:l.to})},numberOfMonths:2})})]})]})}const Qs=s=>`${(s/1024/1024/1024).toFixed(2)} GB`;function bu({className:s}){const{t:n}=V(),[t,r]=u.useState("today"),[a,i]=u.useState({from:is(new Date,7),to:new Date}),[l,d]=u.useState("today"),[m,o]=u.useState({from:is(new Date,7),to:new Date}),c=u.useMemo(()=>t==="custom"?{start:a.from,end:a.to}:ya[t].getValue(),[t,a]),h=u.useMemo(()=>l==="custom"?{start:m.from,end:m.to}:ya[l].getValue(),[l,m]),{data:_}=re({queryKey:["nodeTrafficRank",c.start,c.end],queryFn:()=>tn({type:"node",start_time:Se.round(c.start.getTime()/1e3),end_time:Se.round(c.end.getTime()/1e3)}),refetchInterval:3e4}),{data:E}=re({queryKey:["userTrafficRank",h.start,h.end],queryFn:()=>tn({type:"user",start_time:Se.round(h.start.getTime()/1e3),end_time:Se.round(h.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:N("grid gap-4 md:grid-cols-2",s),children:[e.jsxs(We,{children:[e.jsx(ts,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Cs,{className:"flex items-center text-base font-medium",children:[e.jsx(io,{className:"mr-2 h-4 w-4"}),n("dashboard:trafficRank.nodeTrafficRank")]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx(ln,{selectedRange:t,customDateRange:a,onRangeChange:r,onCustomRangeChange:i}),e.jsx(Ya,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(as,{className:"flex-1",children:_?.data?e.jsxs(zs,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:_.data.map(C=>e.jsx(ve,{delayDuration:200,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:C.name}),e.jsxs("span",{className:N("ml-2 flex items-center text-xs font-medium",C.change>=0?"text-green-600":"text-red-600"),children:[C.change>=0?e.jsx(pa,{className:"mr-1 h-3 w-3"}):e.jsx(fa,{className:"mr-1 h-3 w-3"}),Math.abs(C.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${C.value/_.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Qs(C.value)})]})]})})}),e.jsx(ce,{side:"right",className:"space-y-2 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.currentTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:Qs(C.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:Qs(C.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:N("font-medium",C.change>=0?"text-green-600":"text-red-600"),children:[C.change>=0?"+":"",C.change,"%"]})]})})]})},C.id))}),e.jsx(Lt,{orientation:"vertical"})]}):e.jsx("div",{className:"flex h-[400px] items-center justify-center",children:e.jsx("div",{className:"animate-pulse",children:n("common:loading")})})})]}),e.jsxs(We,{children:[e.jsx(ts,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Cs,{className:"flex items-center text-base font-medium",children:[e.jsx(ha,{className:"mr-2 h-4 w-4"}),n("dashboard:trafficRank.userTrafficRank")]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx(ln,{selectedRange:l,customDateRange:m,onRangeChange:d,onCustomRangeChange:o}),e.jsx(Ya,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(as,{className:"flex-1",children:E?.data?e.jsxs(zs,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:E.data.map(C=>e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:C.name}),e.jsxs("span",{className:N("ml-2 flex items-center text-xs font-medium",C.change>=0?"text-green-600":"text-red-600"),children:[C.change>=0?e.jsx(pa,{className:"mr-1 h-3 w-3"}):e.jsx(fa,{className:"mr-1 h-3 w-3"}),Math.abs(C.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${C.value/E.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Qs(C.value)})]})]})})}),e.jsx(ce,{side:"right",className:"space-y-2 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.currentTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:Qs(C.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:Qs(C.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:N("font-medium",C.change>=0?"text-green-600":"text-red-600"),children:[C.change>=0?"+":"",C.change,"%"]})]})})]})},C.id))}),e.jsx(Lt,{orientation:"vertical"})]}):e.jsx("div",{className:"flex h-[400px] items-center justify-center",children:e.jsx("div",{className:"animate-pulse",children:n("common:loading")})})})]})]})}const Dt=u.forwardRef(({className:s,value:n,...t},r)=>e.jsx(sr,{ref:r,className:N("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...t,children:e.jsx(uo,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(n||0)}%)`}})}));Dt.displayName=sr.displayName;function yu(){const{t:s}=V(),[n,t]=u.useState(null),[r,a]=u.useState(null),[i,l]=u.useState(!0),[d,m]=u.useState(!1),o=async()=>{try{m(!0);const[_,E]=await Promise.all([rn.getSystemStatus(),rn.getQueueStats()]);t(_.data),a(E.data)}catch(_){console.error("Error fetching system data:",_)}finally{l(!1),m(!1)}};u.useEffect(()=>{o();const _=setInterval(o,3e4);return()=>clearInterval(_)},[]);const c=()=>{o()};if(i)return e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx(Da,{className:"h-6 w-6 animate-spin"})});const h=_=>_?e.jsx(tr,{className:"h-5 w-5 text-green-500"}):e.jsx(ar,{className:"h-5 w-5 text-red-500"});return e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(We,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Cs,{className:"flex items-center gap-2",children:[e.jsx(mo,{className:"h-5 w-5"}),s("dashboard:queue.title")]}),e.jsx(et,{children:s("dashboard:queue.status.description")})]}),e.jsx(J,{variant:"outline",size:"icon",onClick:c,disabled:d,children:e.jsx(xo,{className:N("h-4 w-4",d&&"animate-spin")})})]}),e.jsx(as,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[h(r?.status||!1),e.jsx("span",{className:"font-medium",children:s("dashboard:queue.status.running")})]}),e.jsx(q,{variant:r?.status?"secondary":"destructive",children:r?.status?s("dashboard:queue.status.normal"):s("dashboard:queue.status.abnormal")})]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.status.waitTime",{seconds:r?.wait?.default||0})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.recentJobs")}),e.jsx("p",{className:"text-2xl font-bold",children:r?.recentJobs||0}),e.jsx(Dt,{value:(r?.recentJobs||0)/(r?.periods?.recentJobs||1)*100,className:"h-1"})]})}),e.jsx(ce,{children:e.jsx("p",{children:s("dashboard:queue.details.statisticsPeriod",{hours:r?.periods?.recentJobs||0})})})]})}),e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.jobsPerMinute")}),e.jsx("p",{className:"text-2xl font-bold",children:r?.jobsPerMinute||0}),e.jsx(Dt,{value:(r?.jobsPerMinute||0)/(r?.queueWithMaxThroughput?.throughput||1)*100,className:"h-1"})]})}),e.jsx(ce,{children:e.jsx("p",{children:s("dashboard:queue.details.maxThroughput",{value:r?.queueWithMaxThroughput?.throughput||0})})})]})})]})]})})]}),e.jsxs(We,{children:[e.jsxs(ts,{children:[e.jsxs(Cs,{className:"flex items-center gap-2",children:[e.jsx(ho,{className:"h-5 w-5"}),s("dashboard:queue.jobDetails")]}),e.jsx(et,{children:s("dashboard:queue.details.description")})]}),e.jsx(as,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.failedJobs7Days")}),e.jsx("p",{className:"text-2xl font-bold text-destructive",children:r?.failedJobs||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("dashboard:queue.details.retentionPeriod",{hours:r?.periods?.failedJobs||0})})]}),e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.longestRunningQueue")}),e.jsxs("p",{className:"text-2xl font-bold",children:[r?.queueWithMaxRuntime?.runtime||0,"s"]}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:r?.queueWithMaxRuntime?.name||"N/A"})]})]}),e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.activeProcesses")}),e.jsxs("span",{className:"font-medium",children:[r?.processes||0," /"," ",(r?.processes||0)+(r?.pausedMasters||0)]})]}),e.jsx(Dt,{value:(r?.processes||0)/((r?.processes||0)+(r?.pausedMasters||0))*100,className:"mt-2 h-1"})]})]})})]})]})}function Nu(){const{t:s}=V();return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx("div",{className:"flex items-center",children:e.jsx("h1",{className:"text-2xl font-bold tracking-tight md:text-3xl",children:s("dashboard:title")})}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ke,{}),e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsx(Fe,{children:e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsx(vu,{}),e.jsx(hu,{}),e.jsx(bu,{}),e.jsx(yu,{})]})})})]})}const _u=Object.freeze(Object.defineProperty({__proto__:null,default:Nu},Symbol.toStringTag,{value:"Module"}));function wu({className:s,items:n,...t}){const{pathname:r}=_a(),a=Ts(),[i,l]=u.useState(r??"/settings"),d=o=>{l(o),a(o)},{t:m}=V("settings");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-1 md:hidden",children:e.jsxs(G,{value:i,onValueChange:d,children:[e.jsx(K,{className:"h-12 sm:w-48",children:e.jsx(W,{placeholder:"Theme"})}),e.jsx(B,{children:n.map(o=>e.jsx(z,{value:o.href,children:e.jsxs("div",{className:"flex gap-x-4 px-2 py-1",children:[e.jsx("span",{className:"scale-125",children:o.icon}),e.jsx("span",{className:"text-md",children:m(o.title)})]})},o.href))})]})}),e.jsx("div",{className:"hidden w-full overflow-x-auto bg-background px-1 py-2 md:block",children:e.jsx("nav",{className:N("flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",s),...t,children:n.map(o=>e.jsxs(Us,{to:o.href,className:N(nt({variant:"ghost"}),r===o.href?"bg-muted hover:bg-muted":"hover:bg-transparent hover:underline","justify-start"),children:[e.jsx("span",{className:"mr-2",children:o.icon}),m(o.title)]},o.href))})})]})}const Cu=[{title:"site.title",key:"site",icon:e.jsx(po,{size:18}),href:"/config/system",description:"site.description"},{title:"safe.title",key:"safe",icon:e.jsx(Ln,{size:18}),href:"/config/system/safe",description:"safe.description"},{title:"subscribe.title",key:"subscribe",icon:e.jsx(zn,{size:18}),href:"/config/system/subscribe",description:"subscribe.description"},{title:"invite.title",key:"invite",icon:e.jsx(fo,{size:18}),href:"/config/system/invite",description:"invite.description"},{title:"server.title",key:"server",icon:e.jsx(On,{size:18}),href:"/config/system/server",description:"server.description"},{title:"email.title",key:"email",icon:e.jsx(go,{size:18}),href:"/config/system/email",description:"email.description"},{title:"telegram.title",key:"telegram",icon:e.jsx(jo,{size:18}),href:"/config/system/telegram",description:"telegram.description"},{title:"app.title",key:"app",icon:e.jsx(Fn,{size:18}),href:"/config/system/app",description:"app.description"},{title:"subscribe_template.title",key:"subscribe_template",icon:e.jsx(vo,{size:18}),href:"/config/system/subscribe-template",description:"subscribe_template.description"}];function Su(){const{t:s}=V("settings");return e.jsxs(Ee,{fadedBelow:!0,fixedHeight:!0,children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight md:text-3xl",children:s("title")}),e.jsx("div",{className:"text-muted-foreground",children:s("description")})]}),e.jsx(ke,{className:"my-6"}),e.jsxs("div",{className:"flex flex-1 flex-col space-y-8 overflow-auto lg:flex-row lg:space-x-12 lg:space-y-0",children:[e.jsx("aside",{className:"sticky top-0 lg:w-1/5",children:e.jsx(wu,{items:Cu})}),e.jsx("div",{className:"flex-1 w-full p-1 pr-4",children:e.jsx("div",{className:"pb-16",children:e.jsx(wa,{})})})]})]})]})}const ku=Object.freeze(Object.defineProperty({__proto__:null,default:Su},Symbol.toStringTag,{value:"Module"})),Y=u.forwardRef(({className:s,...n},t)=>e.jsx(nr,{className:N("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s),...n,ref:t,children:e.jsx(bo,{className:N("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));Y.displayName=nr.displayName;const ys=u.forwardRef(({className:s,...n},t)=>e.jsx("textarea",{className:N("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...n}));ys.displayName="Textarea";const Tu=x.object({logo:x.string().nullable().default(""),force_https:x.number().nullable().default(0),stop_register:x.number().nullable().default(0),app_name:x.string().nullable().default(""),app_description:x.string().nullable().default(""),app_url:x.string().nullable().default(""),subscribe_url:x.string().nullable().default(""),try_out_plan_id:x.number().nullable().default(0),try_out_hour:x.coerce.number().nullable().default(0),tos_url:x.string().nullable().default(""),currency:x.string().nullable().default(""),currency_symbol:x.string().nullable().default("")});function Du(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),{data:a}=re({queryKey:["settings","site"],queryFn:()=>gs("site")}),{data:i}=re({queryKey:["plans"],queryFn:()=>qs()}),l=ge({resolver:Ne(Tu),defaultValues:{},mode:"onBlur"}),{mutateAsync:d}=es({mutationFn:js,onSuccess:c=>{c.data&&A.success(s("common.autoSaved"))}});u.useEffect(()=>{if(a?.data?.site){const c=a?.data?.site;Object.entries(c).forEach(([h,_])=>{l.setValue(h,_)}),r.current=c}},[a]);const m=u.useCallback(Se.debounce(async c=>{if(!Se.isEqual(c,r.current)){t(!0);try{const h=Object.entries(c).reduce((_,[E,C])=>(_[E]=C===null?"":C,_),{});await d(h),r.current=c}finally{t(!1)}}},1e3),[d]),o=u.useCallback(c=>{m(c)},[m]);return u.useEffect(()=>{const c=l.watch(h=>{o(h)});return()=>c.unsubscribe()},[l.watch,o]),e.jsx(_e,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:l.control,name:"app_name",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("site.form.siteName.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("site.form.siteName.placeholder"),...c,value:c.value||"",onChange:h=>{c.onChange(h),o(l.getValues())}})}),e.jsx(F,{children:s("site.form.siteName.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:l.control,name:"app_description",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("site.form.siteDescription.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("site.form.siteDescription.placeholder"),...c,value:c.value||"",onChange:h=>{c.onChange(h),o(l.getValues())}})}),e.jsx(F,{children:s("site.form.siteDescription.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:l.control,name:"app_url",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("site.form.siteUrl.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("site.form.siteUrl.placeholder"),...c,value:c.value||"",onChange:h=>{c.onChange(h),o(l.getValues())}})}),e.jsx(F,{children:s("site.form.siteUrl.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:l.control,name:"force_https",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("site.form.forceHttps.label")}),e.jsx(F,{children:s("site.form.forceHttps.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:!!c.value,onCheckedChange:h=>{c.onChange(Number(h)),o(l.getValues())}})})]})}),e.jsx(g,{control:l.control,name:"logo",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("site.form.logo.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("site.form.logo.placeholder"),...c,value:c.value||"",onChange:h=>{c.onChange(h),o(l.getValues())}})}),e.jsx(F,{children:s("site.form.logo.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:l.control,name:"subscribe_url",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("site.form.subscribeUrl.label")}),e.jsx(y,{children:e.jsx(ys,{placeholder:s("site.form.subscribeUrl.placeholder"),...c,value:c.value||"",onChange:h=>{c.onChange(h),o(l.getValues())}})}),e.jsx(F,{children:s("site.form.subscribeUrl.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:l.control,name:"tos_url",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("site.form.tosUrl.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("site.form.tosUrl.placeholder"),...c,value:c.value||"",onChange:h=>{c.onChange(h),o(l.getValues())}})}),e.jsx(F,{children:s("site.form.tosUrl.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:l.control,name:"stop_register",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("site.form.stopRegister.label")}),e.jsx(F,{children:s("site.form.stopRegister.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:!!c.value,onCheckedChange:h=>{c.onChange(Number(h)),o(l.getValues())}})})]})}),e.jsx(g,{control:l.control,name:"try_out_plan_id",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("site.form.tryOut.label")}),e.jsx(y,{children:e.jsxs(G,{value:c.value?.toString(),onValueChange:h=>{c.onChange(Number(h)),o(l.getValues())},children:[e.jsx(K,{children:e.jsx(W,{placeholder:s("site.form.tryOut.placeholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("site.form.tryOut.placeholder")}),i?.data?.map(h=>e.jsx(z,{value:h.id.toString(),children:h.name},h.id.toString()))]})]})}),e.jsx(F,{children:s("site.form.tryOut.description")}),e.jsx(D,{})]})}),!!l.watch("try_out_plan_id")&&e.jsx(g,{control:l.control,name:"try_out_hour",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"",children:s("site.form.tryOut.duration.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("site.form.tryOut.duration.placeholder"),...c,value:c.value||"",onChange:h=>{c.onChange(h),o(l.getValues())}})}),e.jsx(F,{children:s("site.form.tryOut.duration.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:l.control,name:"currency",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("site.form.currency.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("site.form.currency.placeholder"),...c,value:c.value||"",onChange:h=>{c.onChange(h),o(l.getValues())}})}),e.jsx(F,{children:s("site.form.currency.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:l.control,name:"currency_symbol",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("site.form.currencySymbol.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("site.form.currencySymbol.placeholder"),...c,value:c.value||"",onChange:h=>{c.onChange(h),o(l.getValues())}})}),e.jsx(F,{children:s("site.form.currencySymbol.description")}),e.jsx(D,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("site.form.saving")})]})})}function Pu(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("site.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("site.description")})]}),e.jsx(ke,{}),e.jsx(Du,{})]})}const Eu=Object.freeze(Object.defineProperty({__proto__:null,default:Pu},Symbol.toStringTag,{value:"Module"})),Ru=x.object({email_verify:x.boolean().nullable(),safe_mode_enable:x.boolean().nullable(),secure_path:x.string().nullable(),email_whitelist_enable:x.boolean().nullable(),email_whitelist_suffix:x.array(x.string().nullable()).nullable(),email_gmail_limit_enable:x.boolean().nullable(),recaptcha_enable:x.boolean().nullable(),recaptcha_key:x.string().nullable(),recaptcha_site_key:x.string().nullable(),register_limit_by_ip_enable:x.boolean().nullable(),register_limit_count:x.coerce.string().transform(s=>s===""?null:s).nullable(),register_limit_expire:x.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_enable:x.boolean().nullable(),password_limit_count:x.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_expire:x.coerce.string().transform(s=>s===""?null:s).nullable()}),Iu={email_verify:!1,safe_mode_enable:!1,secure_path:"",email_whitelist_enable:!1,email_whitelist_suffix:[],email_gmail_limit_enable:!1,recaptcha_enable:!1,recaptcha_key:"",recaptcha_site_key:"",register_limit_by_ip_enable:!1,register_limit_count:"",register_limit_expire:"",password_limit_enable:!1,password_limit_count:"",password_limit_expire:""};function Vu(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(Ru),defaultValues:Iu,mode:"onBlur"}),{data:i}=re({queryKey:["settings","safe"],queryFn:()=>gs("safe")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:o=>{o.data&&A.success(s("common.autoSaved"))}});u.useEffect(()=>{if(i?.data.safe){const o=i.data.safe;Object.entries(o).forEach(([c,h])=>{typeof h=="number"?a.setValue(c,String(h)):a.setValue(c,h)}),r.current=o}},[i]);const d=u.useCallback(Se.debounce(async o=>{if(!Se.isEqual(o,r.current)){t(!0);try{await l(o),r.current=o}finally{t(!1)}}},1e3),[l]),m=u.useCallback(o=>{d(o)},[d]);return u.useEffect(()=>{const o=a.watch(c=>{m(c)});return()=>o.unsubscribe()},[a.watch,m]),e.jsx(_e,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:a.control,name:"email_verify",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.emailVerify.label")}),e.jsx(F,{children:s("safe.form.emailVerify.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"email_gmail_limit_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.gmailLimit.label")}),e.jsx(F,{children:s("safe.form.gmailLimit.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"safe_mode_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.safeMode.label")}),e.jsx(F,{children:s("safe.form.safeMode.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"secure_path",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.securePath.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.securePath.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.securePath.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"email_whitelist_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.emailWhitelist.label")}),e.jsx(F,{children:s("safe.form.emailWhitelist.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),a.watch("email_whitelist_enable")&&e.jsx(g,{control:a.control,name:"email_whitelist_suffix",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.emailWhitelist.suffixes.label")}),e.jsx(y,{children:e.jsx(ys,{placeholder:s("safe.form.emailWhitelist.suffixes.placeholder"),...o,value:(o.value||[]).join(` `),onChange:c=>{const h=c.target.value.split(` -`).filter(Boolean);o.onChange(h),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.emailWhitelist.suffixes.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"recaptcha_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.recaptcha.enable.label")}),e.jsx(F,{children:s("safe.form.recaptcha.enable.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),a.watch("recaptcha_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:a.control,name:"recaptcha_site_key",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.recaptcha.siteKey.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.recaptcha.siteKey.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.recaptcha.siteKey.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"recaptcha_key",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.recaptcha.key.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.recaptcha.key.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.recaptcha.key.description")}),e.jsx(D,{})]})})]}),e.jsx(g,{control:a.control,name:"register_limit_by_ip_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.registerLimit.enable.label")}),e.jsx(F,{children:s("safe.form.registerLimit.enable.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),a.watch("register_limit_by_ip_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:a.control,name:"register_limit_count",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.registerLimit.count.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.registerLimit.count.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.registerLimit.count.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"register_limit_expire",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.registerLimit.expire.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.registerLimit.expire.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.registerLimit.expire.description")}),e.jsx(D,{})]})})]}),e.jsx(g,{control:a.control,name:"password_limit_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.passwordLimit.enable.label")}),e.jsx(F,{children:s("safe.form.passwordLimit.enable.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),a.watch("password_limit_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:a.control,name:"password_limit_count",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.passwordLimit.count.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.passwordLimit.count.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.passwordLimit.count.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"password_limit_expire",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.passwordLimit.expire.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.passwordLimit.expire.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.passwordLimit.expire.description")}),e.jsx(D,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("safe.form.saving")})]})})}function Mu(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("safe.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("safe.description")})]}),e.jsx(ke,{}),e.jsx(Vu,{})]})}const Fu=Object.freeze(Object.defineProperty({__proto__:null,default:Mu},Symbol.toStringTag,{value:"Module"})),Ou=x.object({plan_change_enable:x.boolean().nullable().default(!1),reset_traffic_method:x.coerce.number().nullable().default(0),surplus_enable:x.boolean().nullable().default(!1),new_order_event_id:x.coerce.number().nullable().default(0),renew_order_event_id:x.coerce.number().nullable().default(0),change_order_event_id:x.coerce.number().nullable().default(0),show_info_to_server_enable:x.boolean().nullable().default(!1),show_protocol_to_server_enable:x.boolean().nullable().default(!1),default_remind_expire:x.boolean().nullable().default(!1),default_remind_traffic:x.boolean().nullable().default(!1),subscribe_path:x.string().nullable().default("s")}),Lu={plan_change_enable:!1,reset_traffic_method:0,surplus_enable:!1,new_order_event_id:0,renew_order_event_id:0,change_order_event_id:0,show_info_to_server_enable:!1,show_protocol_to_server_enable:!1,default_remind_expire:!1,default_remind_traffic:!1,subscribe_path:"s"};function zu(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(Ou),defaultValues:Lu,mode:"onBlur"}),{data:i}=re({queryKey:["settings","subscribe"],queryFn:()=>gs("subscribe")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:o=>{o.data&&A.success(s("common.autoSaved"))}});u.useEffect(()=>{if(i?.data?.subscribe){const o=i?.data?.subscribe;Object.entries(o).forEach(([c,h])=>{a.setValue(c,h)}),r.current=o}},[i]);const d=u.useCallback(Se.debounce(async o=>{if(!Se.isEqual(o,r.current)){t(!0);try{await l(o),r.current=o}finally{t(!1)}}},1e3),[l]),m=u.useCallback(o=>{d(o)},[d]);return u.useEffect(()=>{const o=a.watch(c=>{m(c)});return()=>o.unsubscribe()},[a.watch,m]),e.jsx(_e,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:a.control,name:"plan_change_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.plan_change_enable.title")}),e.jsx(F,{children:s("subscribe.plan_change_enable.description")}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"reset_traffic_method",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.reset_traffic_method.title")}),e.jsxs(G,{onValueChange:o.onChange,value:o.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:"请选择重置方式"})})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("subscribe.reset_traffic_method.options.monthly_first")}),e.jsx(z,{value:"1",children:s("subscribe.reset_traffic_method.options.monthly_reset")}),e.jsx(z,{value:"2",children:s("subscribe.reset_traffic_method.options.no_reset")}),e.jsx(z,{value:"3",children:s("subscribe.reset_traffic_method.options.yearly_first")}),e.jsx(z,{value:"4",children:s("subscribe.reset_traffic_method.options.yearly_reset")})]})]}),e.jsx(F,{children:s("subscribe.reset_traffic_method.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"surplus_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.surplus_enable.title")}),e.jsx(F,{children:s("subscribe.surplus_enable.description")}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"new_order_event_id",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.new_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(K,{children:e.jsx(W,{placeholder:"请选择"})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("subscribe.new_order_event.options.no_action")}),e.jsx(z,{value:"1",children:s("subscribe.new_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("subscribe.new_order_event.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"renew_order_event_id",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.renew_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(K,{children:e.jsx(W,{placeholder:"请选择"})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("subscribe.renew_order_event.options.no_action")}),e.jsx(z,{value:"1",children:s("subscribe.renew_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("renew_order_event.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"change_order_event_id",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.change_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(K,{children:e.jsx(W,{placeholder:"请选择"})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("subscribe.change_order_event.options.no_action")}),e.jsx(z,{value:"1",children:s("subscribe.change_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("subscribe.change_order_event.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"subscribe_path",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.subscribe_path.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:"subscribe",...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s("subscribe.subscribe_path.description"),e.jsx("br",{}),s("subscribe.subscribe_path.current_format",{path:o.value||"s"})]}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"show_info_to_server_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("subscribe.show_info_to_server.title")}),e.jsx(F,{children:s("subscribe.show_info_to_server.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"show_protocol_to_server_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("subscribe.show_protocol_to_server.title")}),e.jsx(F,{children:s("subscribe.show_protocol_to_server.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Au(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("subscribe.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe.description")})]}),e.jsx(ke,{}),e.jsx(zu,{})]})}const $u=Object.freeze(Object.defineProperty({__proto__:null,default:Au},Symbol.toStringTag,{value:"Module"})),Uu=x.object({invite_force:x.boolean().default(!1),invite_commission:x.coerce.string().default("0"),invite_gen_limit:x.coerce.string().default("0"),invite_never_expire:x.boolean().default(!1),commission_first_time_enable:x.boolean().default(!1),commission_auto_check_enable:x.boolean().default(!1),commission_withdraw_limit:x.coerce.string().default("0"),commission_withdraw_method:x.array(x.string()).default(["支付宝","USDT","Paypal"]),withdraw_close_enable:x.boolean().default(!1),commission_distribution_enable:x.boolean().default(!1),commission_distribution_l1:x.coerce.number().default(0),commission_distribution_l2:x.coerce.number().default(0),commission_distribution_l3:x.coerce.number().default(0)}),Hu={invite_force:!1,invite_commission:"0",invite_gen_limit:"0",invite_never_expire:!1,commission_first_time_enable:!1,commission_auto_check_enable:!1,commission_withdraw_limit:"0",commission_withdraw_method:["支付宝","USDT","Paypal"],withdraw_close_enable:!1,commission_distribution_enable:!1,commission_distribution_l1:0,commission_distribution_l2:0,commission_distribution_l3:0};function qu(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(Uu),defaultValues:Hu,mode:"onBlur"}),{data:i}=re({queryKey:["settings","invite"],queryFn:()=>gs("invite")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:o=>{o.data&&A.success(s("common.autoSaved"))}});u.useEffect(()=>{if(i?.data?.invite){const o=i?.data?.invite;Object.entries(o).forEach(([c,h])=>{typeof h=="number"?a.setValue(c,String(h)):a.setValue(c,h)}),r.current=o}},[i]);const d=u.useCallback(Se.debounce(async o=>{if(!Se.isEqual(o,r.current)){t(!0);try{await l(o),r.current=o}finally{t(!1)}}},1e3),[l]),m=u.useCallback(o=>{d(o)},[d]);return u.useEffect(()=>{const o=a.watch(c=>{m(c)});return()=>o.unsubscribe()},[a.watch,m]),e.jsx(_e,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:a.control,name:"invite_force",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.invite_force.title")}),e.jsx(F,{children:s("invite.invite_force.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"invite_commission",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("invite.invite_commission.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("invite.invite_commission.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("invite.invite_commission.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"invite_gen_limit",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("invite.invite_gen_limit.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("invite.invite_gen_limit.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("invite.invite_gen_limit.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"invite_never_expire",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.invite_never_expire.title")}),e.jsx(F,{children:s("invite.invite_never_expire.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"commission_first_time_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.commission_first_time.title")}),e.jsx(F,{children:s("invite.commission_first_time.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"commission_auto_check_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.commission_auto_check.title")}),e.jsx(F,{children:s("invite.commission_auto_check.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"commission_withdraw_limit",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("invite.commission_withdraw_limit.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("invite.commission_withdraw_limit.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("invite.commission_withdraw_limit.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"commission_withdraw_method",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("invite.commission_withdraw_method.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("invite.commission_withdraw_method.placeholder"),...o,value:Array.isArray(o.value)?o.value.join(","):"",onChange:c=>{const h=c.target.value.split(",").filter(Boolean);o.onChange(h),m(a.getValues())}})}),e.jsx(F,{children:s("invite.commission_withdraw_method.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"withdraw_close_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.withdraw_close.title")}),e.jsx(F,{children:s("invite.withdraw_close.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"commission_distribution_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.commission_distribution.title")}),e.jsx(F,{children:s("invite.commission_distribution.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),a.watch("commission_distribution_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:a.control,name:"commission_distribution_l1",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:s("invite.commission_distribution.l1")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:c=>{const h=c.target.value?Number(c.target.value):0;o.onChange(h),m(a.getValues())}})}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"commission_distribution_l2",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:s("invite.commission_distribution.l2")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:c=>{const h=c.target.value?Number(c.target.value):0;o.onChange(h),m(a.getValues())}})}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"commission_distribution_l3",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:s("invite.commission_distribution.l3")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:c=>{const h=c.target.value?Number(c.target.value):0;o.onChange(h),m(a.getValues())}})}),e.jsx(D,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("invite.saving")})]})})}function Ku(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("invite.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("invite.description")})]}),e.jsx(ke,{}),e.jsx(qu,{})]})}const Bu=Object.freeze(Object.defineProperty({__proto__:null,default:Ku},Symbol.toStringTag,{value:"Module"})),Gu=x.object({frontend_theme:x.string().nullable(),frontend_theme_sidebar:x.string().nullable(),frontend_theme_header:x.string().nullable(),frontend_theme_color:x.string().nullable(),frontend_background_url:x.string().url().nullable()}),Wu={frontend_theme:"",frontend_theme_sidebar:"",frontend_theme_header:"",frontend_theme_color:"",frontend_background_url:""};function Yu(){const{data:s}=re({queryKey:["settings","frontend"],queryFn:()=>gs("frontend")}),n=ge({resolver:Ne(Gu),defaultValues:Wu,mode:"onChange"});u.useEffect(()=>{if(s?.data?.frontend){const r=s?.data?.frontend;Object.entries(r).forEach(([a,i])=>{n.setValue(a,i)})}},[s]);function t(r){js(r).then(({data:a})=>{a&&A.success("更新成功")})}return e.jsx(_e,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(t),className:"space-y-8",children:[e.jsx(g,{control:n.control,name:"frontend_theme_sidebar",render:({field:r})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:"边栏风格"}),e.jsx(F,{children:"边栏风格"})]}),e.jsx(y,{children:e.jsx(Y,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(g,{control:n.control,name:"frontend_theme_header",render:({field:r})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:"头部风格"}),e.jsx(F,{children:"边栏风格"})]}),e.jsx(y,{children:e.jsx(Y,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(g,{control:n.control,name:"frontend_theme_color",render:({field:r})=>e.jsxs(f,{children:[e.jsx(j,{children:"主题色"}),e.jsxs("div",{className:"relative w-max",children:[e.jsx(y,{children:e.jsxs("select",{className:N(nt({variant:"outline"}),"w-[200px] appearance-none font-normal"),...r,children:[e.jsx("option",{value:"default",children:"默认"}),e.jsx("option",{value:"black",children:"黑色"}),e.jsx("option",{value:"blackblue",children:"暗蓝色"}),e.jsx("option",{value:"green",children:"奶绿色"})]})}),e.jsx(Ta,{className:"absolute right-3 top-2.5 h-4 w-4 opacity-50"})]}),e.jsx(F,{children:"主题色"}),e.jsx(D,{})]})}),e.jsx(g,{control:n.control,name:"frontend_background_url",render:({field:r})=>e.jsxs(f,{children:[e.jsx(j,{children:"背景"}),e.jsx(y,{children:e.jsx(T,{placeholder:"请输入图片地址",...r})}),e.jsx(F,{children:"将会在后台登录页面进行展示。"}),e.jsx(D,{})]})}),e.jsx(P,{type:"submit",children:"保存设置"})]})})}function Qu(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"个性化设置"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自定义系统界面外观,包括主题风格、布局、颜色方案、背景图等个性化选项。"})]}),e.jsx(ke,{}),e.jsx(Yu,{})]})}const Ju=Object.freeze(Object.defineProperty({__proto__:null,default:Qu},Symbol.toStringTag,{value:"Module"})),Xu=x.object({server_pull_interval:x.coerce.number().nullable(),server_push_interval:x.coerce.number().nullable(),server_token:x.string().nullable(),device_limit_mode:x.coerce.number().nullable()}),Zu={server_pull_interval:0,server_push_interval:0,server_token:"",device_limit_mode:0};function em(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(Xu),defaultValues:Zu,mode:"onBlur"}),{data:i}=re({queryKey:["settings","server"],queryFn:()=>gs("server")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:c=>{c.data&&A.success(s("common.AutoSaved"))}});u.useEffect(()=>{if(i?.data.server){const c=i.data.server;Object.entries(c).forEach(([h,_])=>{a.setValue(h,_)}),r.current=c}},[i]);const d=u.useCallback(Se.debounce(async c=>{if(!Se.isEqual(c,r.current)){t(!0);try{await l(c),r.current=c}finally{t(!1)}}},1e3),[l]),m=u.useCallback(c=>{d(c)},[d]);u.useEffect(()=>{const c=a.watch(h=>{m(h)});return()=>c.unsubscribe()},[a.watch,m]);const o=()=>{const c=Math.floor(Math.random()*17)+16,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let _="";for(let E=0;Ee.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("server.server_token.title")}),e.jsx(y,{children:e.jsxs("div",{className:"relative",children:[e.jsx(T,{placeholder:s("server.server_token.placeholder"),...c,value:c.value||"",className:"pr-10"}),e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3 py-2",onClick:h=>{h.preventDefault(),o()},children:e.jsx(yo,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(ce,{children:e.jsx("p",{children:s("server.server_token.generate_tooltip")})})]})})]})}),e.jsx(F,{children:s("server.server_token.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"server_pull_interval",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("server.server_pull_interval.title")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("server.server_pull_interval.placeholder"),...c,value:c.value||"",onChange:h=>{const _=h.target.value?Number(h.target.value):null;c.onChange(_)}})}),e.jsx(F,{children:s("server.server_pull_interval.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"server_push_interval",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("server.server_push_interval.title")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("server.server_push_interval.placeholder"),...c,value:c.value||"",onChange:h=>{const _=h.target.value?Number(h.target.value):null;c.onChange(_)}})}),e.jsx(F,{children:s("server.server_push_interval.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"device_limit_mode",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("server.device_limit_mode.title")}),e.jsxs(G,{onValueChange:c.onChange,value:c.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:s("server.device_limit_mode.placeholder")})})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("server.device_limit_mode.strict")}),e.jsx(z,{value:"1",children:s("server.device_limit_mode.relaxed")})]})]}),e.jsx(F,{children:s("server.device_limit_mode.description")}),e.jsx(D,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("server.saving")})]})})}function sm(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("server.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("server.description")})]}),e.jsx(ke,{}),e.jsx(em,{})]})}const tm=Object.freeze(Object.defineProperty({__proto__:null,default:sm},Symbol.toStringTag,{value:"Module"}));function am({open:s,onOpenChange:n,result:t}){const r=!t.error;return e.jsx(be,{open:s,onOpenChange:n,children:e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(tr,{className:"h-5 w-5 text-green-500"}):e.jsx(ar,{className:"h-5 w-5 text-destructive"}),e.jsx(ye,{children:r?"邮件发送成功":"邮件发送失败"})]}),e.jsx(Te,{children:r?"测试邮件已成功发送,请检查收件箱":"发送测试邮件时遇到错误"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"发送详情"}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2 text-sm",children:[e.jsx("div",{className:"text-muted-foreground",children:"收件地址"}),e.jsx("div",{children:t.email}),e.jsx("div",{className:"text-muted-foreground",children:"邮件主题"}),e.jsx("div",{children:t.subject}),e.jsx("div",{className:"text-muted-foreground",children:"模板名称"}),e.jsx("div",{children:t.template_name})]})]}),t.error&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium text-destructive",children:"错误信息"}),e.jsx("div",{className:"rounded-md bg-destructive/10 p-3 text-sm text-destructive break-all",children:t.error})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"配置信息"}),e.jsx(zs,{className:"h-[200px] rounded-md border p-4",children:e.jsx("div",{className:"grid gap-2 text-sm",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2",children:[e.jsx("div",{className:"text-muted-foreground",children:"驱动"}),e.jsx("div",{children:t.config.driver}),e.jsx("div",{className:"text-muted-foreground",children:"服务器"}),e.jsx("div",{children:t.config.host}),e.jsx("div",{className:"text-muted-foreground",children:"端口"}),e.jsx("div",{children:t.config.port}),e.jsx("div",{className:"text-muted-foreground",children:"加密方式"}),e.jsx("div",{children:t.config.encryption||"无"}),e.jsx("div",{className:"text-muted-foreground",children:"发件人"}),e.jsx("div",{children:t.config.from.address?`${t.config.from.address}${t.config.from.name?` (${t.config.from.name})`:""}`:"未设置"}),e.jsx("div",{className:"text-muted-foreground",children:"用户名"}),e.jsx("div",{children:t.config.username||"未设置"})]})})})]})]})]})})}const nm=x.object({email_template:x.string().nullable().default("classic"),email_host:x.string().nullable().default(""),email_port:x.coerce.number().nullable().default(465),email_username:x.string().nullable().default(""),email_password:x.string().nullable().default(""),email_encryption:x.string().nullable().default(""),email_from_address:x.string().email().nullable().default(""),remind_mail_enable:x.boolean().nullable().default(!1)});function rm(){const{t:s}=V("settings"),[n,t]=u.useState(null),[r,a]=u.useState(!1),i=u.useRef(null),[l,d]=u.useState(!1),m=ge({resolver:Ne(nm),defaultValues:{},mode:"onBlur"}),{data:o}=re({queryKey:["settings","email"],queryFn:()=>gs("email")}),{data:c}=re({queryKey:["emailTemplate"],queryFn:()=>vd()}),{mutateAsync:h}=es({mutationFn:js,onSuccess:w=>{w.data&&A.success(s("common.autoSaved"))}}),{mutate:_,isPending:E}=es({mutationFn:bd,onMutate:()=>{t(null),a(!1)},onSuccess:w=>{t(w.data),a(!0),w.data.error?A.error(s("email.test.error")):A.success(s("email.test.success"))}});u.useEffect(()=>{if(o?.data.email){const w=o.data.email;Object.entries(w).forEach(([b,k])=>{m.setValue(b,k)}),i.current=w}},[o]);const C=u.useCallback(Se.debounce(async w=>{if(!Se.isEqual(w,i.current)){d(!0);try{await h(w),i.current=w}finally{d(!1)}}},1e3),[h]),S=u.useCallback(w=>{C(w)},[C]);return u.useEffect(()=>{const w=m.watch(b=>{S(b)});return()=>w.unsubscribe()},[m.watch,S]),e.jsxs(e.Fragment,{children:[e.jsx(_e,{...m,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:m.control,name:"email_host",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_host.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(F,{children:s("email.email_host.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_port",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_port.title")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("common.placeholder"),...w,value:w.value||"",onChange:b=>{const k=b.target.value?Number(b.target.value):null;w.onChange(k)}})}),e.jsx(F,{children:s("email.email_port.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_encryption",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_encryption.title")}),e.jsxs(G,{onValueChange:w.onChange,value:w.value||"none",children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:"请选择加密方式"})})}),e.jsxs(B,{children:[e.jsx(z,{value:"none",children:s("email.email_encryption.none")}),e.jsx(z,{value:"ssl",children:s("email.email_encryption.ssl")}),e.jsx(z,{value:"tls",children:s("email.email_encryption.tls")})]})]}),e.jsx(F,{children:s("email.email_encryption.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_username",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_username.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(F,{children:s("email.email_username.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_password",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_password.title")}),e.jsx(y,{children:e.jsx(T,{type:"password",placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(F,{children:s("email.email_password.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_from_address",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_from.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(F,{children:s("email.email_from.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_template",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_template.title")}),e.jsxs(G,{onValueChange:b=>{w.onChange(b),S(m.getValues())},value:w.value||void 0,children:[e.jsx(y,{children:e.jsx(K,{className:"w-[200px]",children:e.jsx(W,{placeholder:s("email.email_template.placeholder")})})}),e.jsx(B,{children:c?.data?.map(b=>e.jsx(z,{value:b,children:b},b))})]}),e.jsx(F,{children:s("email.email_template.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"remind_mail_enable",render:({field:w})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("email.remind_mail.title")}),e.jsx(F,{children:s("email.remind_mail.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:w.value||!1,onCheckedChange:b=>{w.onChange(b),S(m.getValues())}})})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(P,{onClick:()=>_(),loading:E,disabled:E,children:s(E?"test.sending":"test.title")})})]})}),l&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("saving")}),n&&e.jsx(am,{open:r,onOpenChange:a,result:n})]})}function lm(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("email.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("email.description")})]}),e.jsx(ke,{}),e.jsx(rm,{})]})}const im=Object.freeze(Object.defineProperty({__proto__:null,default:lm},Symbol.toStringTag,{value:"Module"})),om=x.object({telegram_bot_enable:x.boolean().nullable(),telegram_bot_token:x.string().nullable(),telegram_discuss_link:x.string().nullable()}),cm={telegram_bot_enable:!1,telegram_bot_token:"",telegram_discuss_link:""};function dm(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(om),defaultValues:cm,mode:"onBlur"}),{data:i}=re({queryKey:["settings","telegram"],queryFn:()=>gs("telegram")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:h=>{h.data&&A.success(s("common.autoSaved"))}}),{mutate:d,isPending:m}=es({mutationFn:yd,onSuccess:h=>{h.data&&A.success(s("telegram.webhook.success"))}});u.useEffect(()=>{if(i?.data.telegram){const h=i.data.telegram;Object.entries(h).forEach(([_,E])=>{a.setValue(_,E)}),r.current=h}},[i]);const o=u.useCallback(Se.debounce(async h=>{if(!Se.isEqual(h,r.current)){t(!0);try{await l(h),r.current=h}finally{t(!1)}}},1e3),[l]),c=u.useCallback(h=>{o(h)},[o]);return u.useEffect(()=>{const h=a.watch(_=>{c(_)});return()=>h.unsubscribe()},[a.watch,c]),e.jsx(_e,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:a.control,name:"telegram_bot_token",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("telegram.bot_token.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("telegram.bot_token.placeholder"),...h,value:h.value||""})}),e.jsx(F,{children:s("telegram.bot_token.description")}),e.jsx(D,{})]})}),a.watch("telegram_bot_token")&&e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("telegram.webhook.title")}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(P,{loading:m,disabled:m,onClick:()=>d(),children:s(m?"telegram.webhook.setting":"telegram.webhook.button")}),n&&e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.saving")})]}),e.jsx(F,{children:s("telegram.webhook.description")}),e.jsx(D,{})]}),e.jsx(g,{control:a.control,name:"telegram_bot_enable",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("telegram.bot_enable.title")}),e.jsx(F,{children:s("telegram.bot_enable.description")}),e.jsx(y,{children:e.jsx(Y,{checked:h.value||!1,onCheckedChange:_=>{h.onChange(_),c(a.getValues())}})}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"telegram_discuss_link",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("telegram.discuss_link.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("telegram.discuss_link.placeholder"),...h,value:h.value||""})}),e.jsx(F,{children:s("telegram.discuss_link.description")}),e.jsx(D,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function um(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("telegram.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("telegram.description")})]}),e.jsx(ke,{}),e.jsx(dm,{})]})}const mm=Object.freeze(Object.defineProperty({__proto__:null,default:um},Symbol.toStringTag,{value:"Module"})),xm=x.object({windows_version:x.string().nullable(),windows_download_url:x.string().nullable(),macos_version:x.string().nullable(),macos_download_url:x.string().nullable(),android_version:x.string().nullable(),android_download_url:x.string().nullable()}),hm={windows_version:"",windows_download_url:"",macos_version:"",macos_download_url:"",android_version:"",android_download_url:""};function pm(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(xm),defaultValues:hm,mode:"onBlur"}),{data:i}=re({queryKey:["settings","app"],queryFn:()=>gs("app")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:o=>{o.data&&A.success(s("app.save_success"))}});u.useEffect(()=>{if(i?.data.app){const o=i.data.app;Object.entries(o).forEach(([c,h])=>{a.setValue(c,h)}),r.current=o}},[i]);const d=u.useCallback(Se.debounce(async o=>{if(!Se.isEqual(o,r.current)){t(!0);try{await l(o),r.current=o}finally{t(!1)}}},1e3),[l]),m=u.useCallback(o=>{d(o)},[d]);return u.useEffect(()=>{const o=a.watch(c=>{m(c)});return()=>o.unsubscribe()},[a.watch,m]),e.jsx(_e,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:a.control,name:"windows_version",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.windows.version.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.windows.version.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"windows_download_url",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.windows.download.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.windows.download.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"macos_version",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.macos.version.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.macos.version.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"macos_download_url",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.macos.download.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.macos.download.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"android_version",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.android.version.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.android.version.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"android_download_url",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.android.download.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.android.download.description")}),e.jsx(D,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function fm(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("app.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("app.description")})]}),e.jsx(ke,{}),e.jsx(pm,{})]})}const gm=Object.freeze(Object.defineProperty({__proto__:null,default:fm},Symbol.toStringTag,{value:"Module"})),Ia=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:N("w-full caption-bottom text-sm",s),...n})}));Ia.displayName="Table";const Va=u.forwardRef(({className:s,...n},t)=>e.jsx("thead",{ref:t,className:N("[&_tr]:border-b",s),...n}));Va.displayName="TableHeader";const Ma=u.forwardRef(({className:s,...n},t)=>e.jsx("tbody",{ref:t,className:N("[&_tr:last-child]:border-0",s),...n}));Ma.displayName="TableBody";const jm=u.forwardRef(({className:s,...n},t)=>e.jsx("tfoot",{ref:t,className:N("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...n}));jm.displayName="TableFooter";const Is=u.forwardRef(({className:s,...n},t)=>e.jsx("tr",{ref:t,className:N("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...n}));Is.displayName="TableRow";const Fa=u.forwardRef(({className:s,...n},t)=>e.jsx("th",{ref:t,className:N("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));Fa.displayName="TableHead";const Zs=u.forwardRef(({className:s,...n},t)=>e.jsx("td",{ref:t,className:N("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));Zs.displayName="TableCell";const vm=u.forwardRef(({className:s,...n},t)=>e.jsx("caption",{ref:t,className:N("mt-4 text-sm text-muted-foreground",s),...n}));vm.displayName="TableCaption";function bm({table:s}){const[n,t]=u.useState(""),{t:r}=V("common");u.useEffect(()=>{t((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const a=i=>{const l=parseInt(i);!isNaN(l)&&l>=1&&l<=s.getPageCount()?s.setPageIndex(l-1):t((s.getState().pagination.pageIndex+1).toString())};return e.jsxs("div",{className:"flex flex-col-reverse gap-4 px-2 py-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"flex-1 text-sm text-muted-foreground",children:r("table.pagination.selected",{selected:s.getFilteredSelectedRowModel().rows.length,total:s.getFilteredRowModel().rows.length})}),e.jsxs("div",{className:"flex flex-col-reverse items-center gap-4 sm:flex-row sm:gap-6 lg:gap-8",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:r("table.pagination.itemsPerPage")}),e.jsxs(G,{value:`${s.getState().pagination.pageSize}`,onValueChange:i=>{s.setPageSize(Number(i))},children:[e.jsx(K,{className:"h-8 w-[70px]",children:e.jsx(W,{placeholder:s.getState().pagination.pageSize})}),e.jsx(B,{side:"top",children:[10,20,30,40,50,100,500].map(i=>e.jsx(z,{value:`${i}`,children:i},i))})]})]}),e.jsxs("div",{className:"flex items-center justify-center space-x-2 text-sm font-medium",children:[e.jsx("span",{children:r("table.pagination.page")}),e.jsx(T,{type:"text",value:n,onChange:i=>t(i.target.value),onBlur:i=>a(i.target.value),onKeyDown:i=>{i.key==="Enter"&&a(i.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsx("span",{children:r("table.pagination.pageOf",{total:s.getPageCount()})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(P,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(0),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.firstPage")}),e.jsx(No,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.previousPage")}),e.jsx(Zn,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.nextPage")}),e.jsx(Sa,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(s.getPageCount()-1),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.lastPage")}),e.jsx(_o,{className:"h-4 w-4"})]})]})]})]})}function hs({table:s,toolbar:n,draggable:t=!1,onDragStart:r,onDragEnd:a,onDragOver:i,onDragLeave:l,onDrop:d,showPagination:m=!0,isLoading:o=!1}){const{t:c}=V("common"),h=u.useRef(null),_=s.getAllColumns().filter(w=>w.getIsPinned()==="left"),E=s.getAllColumns().filter(w=>w.getIsPinned()==="right"),C=w=>_.slice(0,w).reduce((b,k)=>b+(k.getSize()??0),0),S=w=>E.slice(w+1).reduce((b,k)=>b+(k.getSize()??0),0);return e.jsxs("div",{className:"space-y-4",children:[typeof n=="function"?n(s):n,e.jsx("div",{ref:h,className:"relative overflow-auto rounded-md border bg-card",children:e.jsx("div",{className:"overflow-auto",children:e.jsxs(Ia,{children:[e.jsx(Va,{children:s.getHeaderGroups().map(w=>e.jsx(Is,{className:"hover:bg-transparent",children:w.headers.map((b,k)=>{const p=b.column.getIsPinned()==="left",v=b.column.getIsPinned()==="right",M=p?C(_.indexOf(b.column)):void 0,H=v?S(E.indexOf(b.column)):void 0;return e.jsx(Fa,{colSpan:b.colSpan,style:{width:b.getSize(),...p&&{left:M},...v&&{right:H}},className:N("h-11 bg-card px-4 text-muted-foreground",(p||v)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",p&&"before:right-0",v&&"before:left-0"]),children:b.isPlaceholder?null:Rt(b.column.columnDef.header,b.getContext())},b.id)})},w.id))}),e.jsx(Ma,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((w,b)=>e.jsx(Is,{"data-state":w.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:t,onDragStart:k=>r?.(k,b),onDragEnd:a,onDragOver:i,onDragLeave:l,onDrop:k=>d?.(k,b),children:w.getVisibleCells().map((k,p)=>{const v=k.column.getIsPinned()==="left",M=k.column.getIsPinned()==="right",H=v?C(_.indexOf(k.column)):void 0,se=M?S(E.indexOf(k.column)):void 0;return e.jsx(Zs,{style:{width:k.column.getSize(),...v&&{left:H},...M&&{right:se}},className:N("bg-card",(v||M)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",v&&"before:right-0",M&&"before:left-0"]),children:Rt(k.column.columnDef.cell,k.getContext())},k.id)})},w.id)):e.jsx(Is,{children:e.jsx(Zs,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:c("table.noData")})})})]})})}),m&&e.jsx(bm,{table:s})]})}const ym=s=>x.object({id:x.number().nullable(),name:x.string().min(2,s("form.validation.name.min")).max(30,s("form.validation.name.max")),icon:x.string().optional().nullable(),notify_domain:x.string().refine(t=>!t||/^https?:\/\/\S+/.test(t),s("form.validation.notify_domain.url")).optional().nullable(),handling_fee_fixed:x.coerce.number().min(0).optional().nullable(),handling_fee_percent:x.coerce.number().min(0).max(100).optional().nullable(),payment:x.string().min(1,s("form.validation.payment.required")),config:x.record(x.string(),x.string())}),on={id:null,name:"",icon:"",notify_domain:"",handling_fee_fixed:0,handling_fee_percent:0,payment:"",config:{}};function qr({refetch:s,dialogTrigger:n,type:t="add",defaultFormValues:r=on}){const{t:a}=V("payment"),[i,l]=u.useState(!1),[d,m]=u.useState(!1),[o,c]=u.useState([]),[h,_]=u.useState([]),E=ym(a),C=ge({resolver:Ne(E),defaultValues:r,mode:"onChange"}),S=C.watch("payment");u.useEffect(()=>{i&&(async()=>{const{data:k}=await Lc();c(k)})()},[i]),u.useEffect(()=>{if(!S||!i)return;(async()=>{const k={payment:S,...t==="edit"&&{id:Number(C.getValues("id"))}};zc(k).then(({data:p})=>{_(p);const v=p.reduce((M,H)=>(H.field_name&&(M[H.field_name]=H.value??""),M),{});C.setValue("config",v)})})()},[S,i,C,t]);const w=async b=>{m(!0);try{(await Ac(b)).data&&(A.success(a("form.messages.success")),C.reset(on),s(),l(!1))}finally{m(!1)}};return e.jsxs(be,{open:i,onOpenChange:l,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add.button")})]})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsx(Ce,{children:e.jsx(ye,{children:a(t==="add"?"form.add.title":"form.edit.title")})}),e.jsx(_e,{...C,children:e.jsxs("form",{onSubmit:C.handleSubmit(w),className:"space-y-4",children:[e.jsx(g,{control:C.control,name:"name",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:a("form.fields.name.placeholder"),...b})}),e.jsx(F,{children:a("form.fields.name.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"icon",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.icon.label")}),e.jsx(y,{children:e.jsx(T,{...b,value:b.value||"",placeholder:a("form.fields.icon.placeholder")})}),e.jsx(F,{children:a("form.fields.icon.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"notify_domain",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.notify_domain.label")}),e.jsx(y,{children:e.jsx(T,{...b,value:b.value||"",placeholder:a("form.fields.notify_domain.placeholder")})}),e.jsx(F,{children:a("form.fields.notify_domain.description")}),e.jsx(D,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:C.control,name:"handling_fee_percent",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.handling_fee_percent.label")}),e.jsx(y,{children:e.jsx(T,{type:"number",...b,value:b.value||"",placeholder:a("form.fields.handling_fee_percent.placeholder")})}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"handling_fee_fixed",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.handling_fee_fixed.label")}),e.jsx(y,{children:e.jsx(T,{type:"number",...b,value:b.value||"",placeholder:a("form.fields.handling_fee_fixed.placeholder")})}),e.jsx(D,{})]})})]}),e.jsx(g,{control:C.control,name:"payment",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.payment.label")}),e.jsxs(G,{onValueChange:b.onChange,defaultValue:b.value,children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:a("form.fields.payment.placeholder")})})}),e.jsx(B,{children:o.map(k=>e.jsx(z,{value:k,children:k},k))})]}),e.jsx(F,{children:a("form.fields.payment.description")}),e.jsx(D,{})]})}),h.length>0&&e.jsx("div",{className:"space-y-4",children:h.map(b=>e.jsx(g,{control:C.control,name:`config.${b.field_name}`,render:({field:k})=>e.jsxs(f,{children:[e.jsx(j,{children:b.label}),e.jsx(y,{children:e.jsx(T,{...k,value:k.value||""})}),e.jsx(D,{})]})},b.field_name))}),e.jsxs(ze,{children:[e.jsx(yt,{asChild:!0,children:e.jsx(P,{type:"button",variant:"outline",children:a("form.buttons.cancel")})}),e.jsx(P,{type:"submit",disabled:d,children:a("form.buttons.submit")})]})]})})]})]})}function O({column:s,title:n,tooltip:t,className:r}){return s.getCanSort()?e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(P,{variant:"ghost",size:"default",className:N("-ml-3 flex h-8 items-center gap-2 text-nowrap font-medium hover:bg-muted/60",r),onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[e.jsx("span",{children:n}),t&&e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(Qa,{className:"h-4 w-4 cursor-pointer text-muted-foreground"})}),e.jsx(ce,{children:t})]})}),s.getIsSorted()==="asc"?e.jsx(pa,{className:"h-4 w-4 text-foreground/70"}):s.getIsSorted()==="desc"?e.jsx(fa,{className:"h-4 w-4 text-foreground/70"}):e.jsx(wo,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-foreground/70"})]})})}):e.jsxs("div",{className:N("flex items-center space-x-1 text-nowrap py-2 font-medium text-muted-foreground",r),children:[e.jsx("span",{children:n}),t&&e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{children:e.jsx(Qa,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(ce,{children:t})]})})]})}const Oa=Co,Kr=So,Nm=ko,Br=u.forwardRef(({className:s,...n},t)=>e.jsx(rr,{className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:t}));Br.displayName=rr.displayName;const Yt=u.forwardRef(({className:s,...n},t)=>e.jsxs(Nm,{children:[e.jsx(Br,{}),e.jsx(lr,{ref:t,className:N("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...n})]}));Yt.displayName=lr.displayName;const Qt=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-2 text-center sm:text-left",s),...n});Qt.displayName="AlertDialogHeader";const Jt=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Jt.displayName="AlertDialogFooter";const Xt=u.forwardRef(({className:s,...n},t)=>e.jsx(ir,{ref:t,className:N("text-lg font-semibold",s),...n}));Xt.displayName=ir.displayName;const Zt=u.forwardRef(({className:s,...n},t)=>e.jsx(or,{ref:t,className:N("text-sm text-muted-foreground",s),...n}));Zt.displayName=or.displayName;const ea=u.forwardRef(({className:s,...n},t)=>e.jsx(cr,{ref:t,className:N(st(),s),...n}));ea.displayName=cr.displayName;const sa=u.forwardRef(({className:s,...n},t)=>e.jsx(dr,{ref:t,className:N(st({variant:"outline"}),"mt-2 sm:mt-0",s),...n}));sa.displayName=dr.displayName;function Qe({onConfirm:s,children:n,title:t="确认操作",description:r="确定要执行此操作吗?",cancelText:a="取消",confirmText:i="确认",variant:l="default",className:d}){return e.jsxs(Oa,{children:[e.jsx(Kr,{asChild:!0,children:n}),e.jsxs(Yt,{className:N("sm:max-w-[425px]",d),children:[e.jsxs(Qt,{children:[e.jsx(Xt,{children:t}),e.jsx(Zt,{children:r})]}),e.jsxs(Jt,{children:[e.jsx(sa,{asChild:!0,children:e.jsx(P,{variant:"outline",children:a})}),e.jsx(ea,{asChild:!0,children:e.jsx(P,{variant:l,onClick:s,children:i})})]})]})]})}const Gr=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M11.29 15.29a2 2 0 0 0-.12.15a.8.8 0 0 0-.09.18a.6.6 0 0 0-.06.18a1.4 1.4 0 0 0 0 .2a.84.84 0 0 0 .08.38a.9.9 0 0 0 .54.54a.94.94 0 0 0 .76 0a.9.9 0 0 0 .54-.54A1 1 0 0 0 13 16a1 1 0 0 0-.29-.71a1 1 0 0 0-1.42 0M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2m0 18a8 8 0 1 1 8-8a8 8 0 0 1-8 8m0-13a3 3 0 0 0-2.6 1.5a1 1 0 1 0 1.73 1A1 1 0 0 1 12 9a1 1 0 0 1 0 2a1 1 0 0 0-1 1v1a1 1 0 0 0 2 0v-.18A3 3 0 0 0 12 7"})}),_m=({refetch:s,isSortMode:n=!1})=>{const{t}=V("payment");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(Ht,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.id")}),cell:({row:r})=>e.jsx(q,{variant:"outline",children:r.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"enable",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.enable")}),cell:({row:r})=>e.jsx(Y,{defaultChecked:r.getValue("enable"),onCheckedChange:async()=>{const{data:a}=await Uc({id:r.original.id});a||s()}}),enableSorting:!1,size:100},{accessorKey:"name",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.name")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r.getValue("name")})}),enableSorting:!1,size:200},{accessorKey:"payment",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.payment")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r.getValue("payment")})}),enableSorting:!1,size:200},{accessorKey:"notify_url",header:({column:r})=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(O,{column:r,title:t("table.columns.notify_url")}),e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{className:"ml-1",children:e.jsx(Gr,{className:"h-4 w-4"})}),e.jsx(ce,{children:t("table.columns.notify_url_tooltip")})]})})]}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[300px] truncate font-medium",children:r.getValue("notify_url")})}),enableSorting:!1,size:3e3},{id:"actions",header:({column:r})=>e.jsx(O,{className:"justify-end",column:r,title:t("table.columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(qr,{refetch:s,dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:t("table.actions.edit")})]}),type:"edit",defaultFormValues:r.original}),e.jsx(Qe,{title:t("table.actions.delete.title"),description:t("table.actions.delete.description"),onConfirm:async()=>{const{data:a}=await $c({id:r.original.id});a&&s()},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-destructive"}),e.jsx("span",{className:"sr-only",children:t("table.actions.delete.title")})]})})]}),size:100}]};function wm({table:s,refetch:n,saveOrder:t,isSortMode:r}){const{t:a}=V("payment"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:a("table.toolbar.sort.hint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qr,{refetch:n}),e.jsx(T,{placeholder:a("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),i&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[a("table.toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{variant:r?"default":"outline",onClick:t,size:"sm",children:a(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}function Cm(){const[s,n]=u.useState([]),[t,r]=u.useState([]),[a,i]=u.useState(!1),[l,d]=u.useState([]),[m,o]=u.useState({"drag-handle":!1}),[c,h]=u.useState({pageSize:20,pageIndex:0}),{refetch:_}=re({queryKey:["paymentList"],queryFn:async()=>{const{data:b}=await Oc();return d(b?.map(k=>({...k,enable:!!k.enable}))||[]),b}});u.useEffect(()=>{o({"drag-handle":a,actions:!a}),h({pageSize:a?99999:10,pageIndex:0})},[a]);const E=(b,k)=>{a&&(b.dataTransfer.setData("text/plain",k.toString()),b.currentTarget.classList.add("opacity-50"))},C=(b,k)=>{if(!a)return;b.preventDefault(),b.currentTarget.classList.remove("bg-muted");const p=parseInt(b.dataTransfer.getData("text/plain"));if(p===k)return;const v=[...l],[M]=v.splice(p,1);v.splice(k,0,M),d(v)},S=async()=>{a?Hc({ids:l.map(b=>b.id)}).then(()=>{_(),i(!1),A.success("排序保存成功")}):i(!0)},w=ns({data:l,columns:_m({refetch:_,isSortMode:a}),state:{sorting:t,columnFilters:s,columnVisibility:m,pagination:c},onSortingChange:r,onColumnFiltersChange:n,onColumnVisibilityChange:o,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),initialState:{columnPinning:{right:["actions"]}},pageCount:a?1:void 0});return e.jsx(hs,{table:w,toolbar:b=>e.jsx(wm,{table:b,refetch:_,saveOrder:S,isSortMode:a}),draggable:a,onDragStart:E,onDragEnd:b=>b.currentTarget.classList.remove("opacity-50"),onDragOver:b=>{b.preventDefault(),b.currentTarget.classList.add("bg-muted")},onDragLeave:b=>b.currentTarget.classList.remove("bg-muted"),onDrop:C,showPagination:!a})}function Sm(){const{t:s}=V("payment");return e.jsxs(Ee,{children:[e.jsxs(Re,{className:"flex items-center justify-between",children:[e.jsx(Ke,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{children:[e.jsx("header",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("section",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Cm,{})})]})]})}const km=Object.freeze(Object.defineProperty({__proto__:null,default:Sm},Symbol.toStringTag,{value:"Module"}));function Tm({pluginName:s,onClose:n,onSuccess:t}){const{t:r}=V("plugin"),[a,i]=u.useState(!0),[l,d]=u.useState(!1),[m,o]=u.useState(null),c=To({config:Do(Po())}),h=ge({resolver:Ne(c),defaultValues:{config:{}}});u.useEffect(()=>{(async()=>{try{const{data:S}=await _s.getPluginConfig(s);o(S),h.reset({config:Object.fromEntries(Object.entries(S).map(([w,b])=>[w,b.value]))})}catch{A.error(r("messages.configLoadError"))}finally{i(!1)}})()},[s]);const _=async C=>{d(!0);try{await _s.updatePluginConfig(s,C.config),A.success(r("messages.configSaveSuccess")),t()}catch{A.error(r("messages.configSaveError"))}finally{d(!1)}},E=(C,S)=>{switch(S.type){case"string":return e.jsx(g,{control:h.control,name:`config.${C}`,render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{children:S.label||S.description}),e.jsx(y,{children:e.jsx(T,{placeholder:S.placeholder,...w})}),S.description&&S.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.description}),e.jsx(D,{})]})},C);case"number":case"percentage":return e.jsx(g,{control:h.control,name:`config.${C}`,render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{children:S.label||S.description}),e.jsx(y,{children:e.jsxs("div",{className:"relative",children:[e.jsx(T,{type:"number",placeholder:S.placeholder,...w,onChange:b=>{const k=Number(b.target.value);S.type==="percentage"?w.onChange(Math.min(100,Math.max(0,k))):w.onChange(k)},className:S.type==="percentage"?"pr-8":"",min:S.type==="percentage"?0:void 0,max:S.type==="percentage"?100:void 0,step:S.type==="percentage"?1:void 0}),S.type==="percentage"&&e.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3",children:e.jsx(Eo,{className:"h-4 w-4 text-muted-foreground"})})]})}),S.description&&S.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.description}),e.jsx(D,{})]})},C);case"select":return e.jsx(g,{control:h.control,name:`config.${C}`,render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{children:S.label||S.description}),e.jsxs(G,{onValueChange:w.onChange,defaultValue:w.value,children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:S.placeholder})})}),e.jsx(B,{children:S.options?.map(b=>e.jsx(z,{value:b.value,children:b.label},b.value))})]}),S.description&&S.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.description}),e.jsx(D,{})]})},C);case"boolean":return e.jsx(g,{control:h.control,name:`config.${C}`,render:({field:w})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:S.label||S.description}),S.description&&S.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.description})]}),e.jsx(y,{children:e.jsx(Y,{checked:w.value,onCheckedChange:w.onChange})})]})},C);case"text":return e.jsx(g,{control:h.control,name:`config.${C}`,render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{children:S.label||S.description}),e.jsx(y,{children:e.jsx(ys,{placeholder:S.placeholder,...w})}),S.description&&S.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.description}),e.jsx(D,{})]})},C);default:return null}};return a?e.jsxs("div",{className:"space-y-4",children:[e.jsx(oe,{className:"h-4 w-[200px]"}),e.jsx(oe,{className:"h-10 w-full"}),e.jsx(oe,{className:"h-4 w-[200px]"}),e.jsx(oe,{className:"h-10 w-full"})]}):e.jsx(_e,{...h,children:e.jsxs("form",{onSubmit:h.handleSubmit(_),className:"space-y-4",children:[m&&Object.entries(m).map(([C,S])=>E(C,S)),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(P,{type:"button",variant:"outline",onClick:n,disabled:l,children:r("config.cancel")}),e.jsx(P,{type:"submit",loading:l,disabled:l,children:r("config.save")})]})]})})}function Dm(){const{t:s}=V("plugin"),[n,t]=u.useState(null),[r,a]=u.useState(!1),[i,l]=u.useState(null),[d,m]=u.useState(""),[o,c]=u.useState("all"),[h,_]=u.useState(!1),[E,C]=u.useState(!1),[S,w]=u.useState(!1),b=u.useRef(null),{data:k,isLoading:p,refetch:v}=re({queryKey:["pluginList"],queryFn:async()=>{const{data:R}=await _s.getPluginList();return R}});k&&[...new Set(k.map(R=>R.category||"other"))];const M=k?.filter(R=>{const X=R.name.toLowerCase().includes(d.toLowerCase())||R.description.toLowerCase().includes(d.toLowerCase())||R.code.toLowerCase().includes(d.toLowerCase()),Ns=o==="all"||R.category===o;return X&&Ns}),H=async R=>{t(R),_s.installPlugin(R).then(()=>{A.success(s("messages.installSuccess")),v()}).catch(X=>{A.error(X.message||s("messages.installError"))}).finally(()=>{t(null)})},se=async R=>{t(R),_s.uninstallPlugin(R).then(()=>{A.success(s("messages.uninstallSuccess")),v()}).catch(X=>{A.error(X.message||s("messages.uninstallError"))}).finally(()=>{t(null)})},L=async(R,X)=>{t(R),(X?_s.disablePlugin:_s.enablePlugin)(R).then(()=>{A.success(s(X?"messages.disableSuccess":"messages.enableSuccess")),v()}).catch(De=>{A.error(De.message||s(X?"messages.disableError":"messages.enableError"))}).finally(()=>{t(null)})},Z=R=>{k?.find(X=>X.code===R),l(R),a(!0)},de=async R=>{if(!R.name.endsWith(".zip")){A.error(s("upload.error.format"));return}_(!0),_s.uploadPlugin(R).then(()=>{A.success(s("messages.uploadSuccess")),C(!1),v()}).catch(X=>{A.error(X.message||s("messages.uploadError"))}).finally(()=>{_(!1),b.current&&(b.current.value="")})},Q=R=>{R.preventDefault(),R.stopPropagation(),R.type==="dragenter"||R.type==="dragover"?w(!0):R.type==="dragleave"&&w(!1)},te=R=>{R.preventDefault(),R.stopPropagation(),w(!1),R.dataTransfer.files&&R.dataTransfer.files[0]&&de(R.dataTransfer.files[0])},$=async R=>{t(R),_s.deletePlugin(R).then(()=>{A.success(s("messages.deleteSuccess")),v()}).catch(X=>{A.error(X.message||s("messages.deleteError"))}).finally(()=>{t(null)})};return e.jsxs(Ee,{children:[e.jsxs(Re,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(ka,{className:"h-6 w-6"}),e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("title")})]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{children:[e.jsxs("div",{className:"mb-8 space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"relative max-w-sm flex-1",children:[e.jsx(An,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(T,{placeholder:s("search.placeholder"),value:d,onChange:R=>m(R.target.value),className:"pl-9"})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs(P,{onClick:()=>C(!0),variant:"outline",className:"shrink-0",size:"sm",children:[e.jsx(pt,{className:"mr-2 h-4 w-4"}),s("upload.button")]})})]}),e.jsxs(Gt,{defaultValue:"all",className:"w-full",children:[e.jsxs(vt,{children:[e.jsx(Ge,{value:"all",children:s("tabs.all")}),e.jsx(Ge,{value:"installed",children:s("tabs.installed")}),e.jsx(Ge,{value:"available",children:s("tabs.available")})]}),e.jsx(ws,{value:"all",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:p?e.jsxs(e.Fragment,{children:[e.jsx(oa,{}),e.jsx(oa,{}),e.jsx(oa,{})]}):M?.map(R=>e.jsx(ia,{plugin:R,onInstall:H,onUninstall:se,onToggleEnable:L,onOpenConfig:Z,onDelete:$,isLoading:n===R.name},R.name))})}),e.jsx(ws,{value:"installed",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:M?.filter(R=>R.is_installed).map(R=>e.jsx(ia,{plugin:R,onInstall:H,onUninstall:se,onToggleEnable:L,onOpenConfig:Z,onDelete:$,isLoading:n===R.name},R.name))})}),e.jsx(ws,{value:"available",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:M?.filter(R=>!R.is_installed).map(R=>e.jsx(ia,{plugin:R,onInstall:H,onUninstall:se,onToggleEnable:L,onOpenConfig:Z,onDelete:$,isLoading:n===R.name},R.code))})})]})]}),e.jsx(be,{open:r,onOpenChange:a,children:e.jsxs(fe,{className:"sm:max-w-lg",children:[e.jsxs(Ce,{children:[e.jsxs(ye,{children:[k?.find(R=>R.code===i)?.name," ",s("config.title")]}),e.jsx(Te,{children:s("config.description")})]}),i&&e.jsx(Tm,{pluginName:i,onClose:()=>a(!1),onSuccess:()=>{a(!1),v()}})]})}),e.jsx(be,{open:E,onOpenChange:C,children:e.jsxs(fe,{className:"sm:max-w-md",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:s("upload.title")}),e.jsx(Te,{children:s("upload.description")})]}),e.jsxs("div",{className:N("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",S&&"border-primary/50 bg-muted/50"),onDragEnter:Q,onDragLeave:Q,onDragOver:Q,onDrop:te,children:[e.jsx("input",{type:"file",ref:b,className:"hidden",accept:".zip",onChange:R=>{const X=R.target.files?.[0];X&&de(X)}}),h?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(pt,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[s("upload.dragText")," ",e.jsx("button",{type:"button",onClick:()=>b.current?.click(),className:"mx-1 text-primary hover:underline",children:s("upload.clickText")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("upload.supportText")})]})]})})]})]})})]})]})}function ia({plugin:s,onInstall:n,onUninstall:t,onToggleEnable:r,onOpenConfig:a,onDelete:i,isLoading:l}){const{t:d}=V("plugin");return e.jsxs(We,{className:"group relative overflow-hidden transition-all hover:shadow-md",children:[e.jsxs(ts,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Cs,{children:s.name}),s.is_installed&&e.jsx(q,{variant:s.is_enabled?"success":"secondary",children:s.is_enabled?d("status.enabled"):d("status.disabled")})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ka,{className:"h-4 w-4"}),e.jsx("code",{className:"rounded bg-muted px-1 py-0.5",children:s.code})]}),e.jsxs("div",{children:["v",s.version]})]})]})}),e.jsx(et,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"mt-2",children:s.description}),e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1",children:[d("author"),": ",s.author]})})]})})]}),e.jsx(as,{children:e.jsx("div",{className:"flex items-center justify-end space-x-2",children:s.is_installed?e.jsxs(e.Fragment,{children:[e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>a(s.code),disabled:!s.is_enabled||l,children:[e.jsx(Ro,{className:"mr-2 h-4 w-4"}),d("button.config")]}),e.jsxs(P,{variant:s.is_enabled?"destructive":"default",size:"sm",onClick:()=>r(s.code,s.is_enabled),disabled:l,children:[e.jsx(Io,{className:"mr-2 h-4 w-4"}),s.is_enabled?d("button.disable"):d("button.enable")]}),e.jsx(Qe,{title:d("uninstall.title"),description:d("uninstall.description"),cancelText:d("common:cancel"),confirmText:d("uninstall.button"),variant:"destructive",onConfirm:()=>t(s.code),children:e.jsxs(P,{variant:"outline",size:"sm",className:"text-muted-foreground hover:text-destructive",disabled:l,children:[e.jsx(cs,{className:"mr-2 h-4 w-4"}),d("button.uninstall")]})})]}):e.jsxs(e.Fragment,{children:[e.jsx(P,{onClick:()=>n(s.code),disabled:l,loading:l,children:d("button.install")}),e.jsx(Qe,{title:d("delete.title"),description:d("delete.description"),cancelText:d("common:cancel"),confirmText:d("delete.button"),variant:"destructive",onConfirm:()=>i(s.code),children:e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",disabled:l,children:e.jsx(cs,{className:"h-4 w-4"})})})]})})})]})}function oa(){return e.jsxs(We,{children:[e.jsxs(ts,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"h-6 w-[200px]"}),e.jsx(oe,{className:"h-6 w-[80px]"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(oe,{className:"h-5 w-[120px]"}),e.jsx(oe,{className:"h-5 w-[60px]"})]})]})}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx(oe,{className:"h-4 w-[300px]"}),e.jsx(oe,{className:"h-4 w-[150px]"})]})]}),e.jsx(as,{children:e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(oe,{className:"h-9 w-[100px]"}),e.jsx(oe,{className:"h-9 w-[100px]"}),e.jsx(oe,{className:"h-8 w-8"})]})})]})}const Pm=Object.freeze(Object.defineProperty({__proto__:null,default:Dm},Symbol.toStringTag,{value:"Module"})),Em=(s,n)=>{let t=null;switch(s.field_type){case"input":t=e.jsx(T,{placeholder:s.placeholder,...n});break;case"textarea":t=e.jsx(ys,{placeholder:s.placeholder,...n});break;case"select":t=e.jsx("select",{className:N(st({variant:"outline"}),"w-full appearance-none font-normal"),...n,children:s.select_options&&Object.keys(s.select_options).map(r=>e.jsx("option",{value:r,children:s.select_options?.[r]},r))});break;default:t=null;break}return t};function Rm({themeKey:s,themeInfo:n}){const{t}=V("theme"),[r,a]=u.useState(!1),[i,l]=u.useState(!1),[d,m]=u.useState(!1),o=ge({defaultValues:n.configs.reduce((_,E)=>(_[E.field_name]="",_),{})}),c=async()=>{l(!0),_c(s).then(({data:_})=>{Object.entries(_).forEach(([E,C])=>{o.setValue(E,C)})}).finally(()=>{l(!1)})},h=async _=>{m(!0),wc(s,_).then(()=>{A.success(t("config.success")),a(!1)}).finally(()=>{m(!1)})};return e.jsxs(be,{open:r,onOpenChange:_=>{a(_),_?c():o.reset()},children:[e.jsx(Je,{asChild:!0,children:e.jsx(P,{variant:"outline",children:t("card.configureTheme")})}),e.jsxs(fe,{className:"max-h-[90vh] overflow-auto sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:t("config.title",{name:n.name})}),e.jsx(Te,{children:t("config.description")})]}),i?e.jsx("div",{className:"flex h-40 items-center justify-center",children:e.jsx(Da,{className:"h-6 w-6 animate-spin"})}):e.jsx(_e,{...o,children:e.jsxs("form",{onSubmit:o.handleSubmit(h),className:"space-y-4",children:[n.configs.map(_=>e.jsx(g,{control:o.control,name:_.field_name,render:({field:E})=>e.jsxs(f,{children:[e.jsx(j,{children:_.label}),e.jsx(y,{children:Em(_,E)}),e.jsx(D,{})]})},_.field_name)),e.jsxs(ze,{className:"mt-6 gap-2",children:[e.jsx(P,{type:"button",variant:"secondary",onClick:()=>a(!1),children:t("config.cancel")}),e.jsx(P,{type:"submit",loading:d,children:t("config.save")})]})]})})]})]})}function Im(){const{t:s}=V("theme"),[n,t]=u.useState(null),[r,a]=u.useState(!1),[i,l]=u.useState(!1),[d,m]=u.useState(!1),[o,c]=u.useState(null),h=u.useRef(null),[_,E]=u.useState(0),{data:C,isLoading:S,refetch:w}=re({queryKey:["themeList"],queryFn:async()=>{const{data:L}=await Nc();return L}}),b=async L=>{t(L),kc({frontend_theme:L}).then(()=>{A.success("主题切换成功"),w()}).finally(()=>{t(null)})},k=async L=>{if(!L.name.endsWith(".zip")){A.error(s("upload.error.format"));return}a(!0),Cc(L).then(()=>{A.success("主题上传成功"),l(!1),w()}).finally(()=>{a(!1),h.current&&(h.current.value="")})},p=L=>{L.preventDefault(),L.stopPropagation(),L.type==="dragenter"||L.type==="dragover"?m(!0):L.type==="dragleave"&&m(!1)},v=L=>{L.preventDefault(),L.stopPropagation(),m(!1),L.dataTransfer.files&&L.dataTransfer.files[0]&&k(L.dataTransfer.files[0])},M=()=>{o&&E(L=>L===0?o.images.length-1:L-1)},H=()=>{o&&E(L=>L===o.images.length-1?0:L+1)},se=(L,Z)=>{E(0),c({name:L,images:Z})};return e.jsxs(Ee,{children:[e.jsxs(Re,{className:"flex items-center justify-between",children:[e.jsx(Ke,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"",children:[e.jsxs("header",{className:"mb-8",children:[e.jsx("div",{className:"mb-2",children:e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-muted-foreground",children:s("description")}),e.jsxs(P,{onClick:()=>l(!0),variant:"outline",className:"ml-4 shrink-0",size:"sm",children:[e.jsx(pt,{className:"mr-2 h-4 w-4"}),s("upload.button")]})]})]}),e.jsx("section",{className:"grid gap-6 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3",children:S?e.jsxs(e.Fragment,{children:[e.jsx(cn,{}),e.jsx(cn,{})]}):C?.themes&&Object.entries(C.themes).map(([L,Z])=>e.jsx(We,{className:"group relative overflow-hidden transition-all hover:shadow-md",style:{backgroundImage:Z.background_url?`url(${Z.background_url})`:"none",backgroundSize:"cover",backgroundPosition:"center"},children:e.jsxs("div",{className:N("relative z-10 h-full transition-colors",Z.background_url?"group-hover:from-background/98 bg-gradient-to-t from-background/95 via-background/80 to-background/60 backdrop-blur-[1px] group-hover:via-background/90 group-hover:to-background/70":"bg-background"),children:[!!Z.can_delete&&e.jsx("div",{className:"absolute right-2 top-2",children:e.jsx(Qe,{title:s("card.delete.title"),description:s("card.delete.description"),confirmText:s("card.delete.button"),variant:"destructive",onConfirm:async()=>{if(L===C?.active){A.error(s("card.delete.error.active"));return}t(L),Sc(L).then(()=>{A.success("主题删除成功"),w()}).finally(()=>{t(null)})},children:e.jsx(P,{disabled:n===L,loading:n===L,variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",children:e.jsx(cs,{className:"h-4 w-4"})})})}),e.jsxs(ts,{children:[e.jsx(Cs,{children:Z.name}),e.jsx(et,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{children:Z.description}),Z.version&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("card.version",{version:Z.version})})]})})]}),e.jsxs(as,{className:"flex items-center justify-end space-x-3",children:[Z.images&&Array.isArray(Z.images)&&Z.images.length>0&&e.jsx(P,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>se(Z.name,Z.images),children:e.jsx(Vo,{className:"h-4 w-4"})}),e.jsx(Rm,{themeKey:L,themeInfo:Z}),e.jsx(P,{onClick:()=>b(L),disabled:n===L||L===C.active,loading:n===L,variant:L===C.active?"secondary":"default",children:L===C.active?s("card.currentTheme"):s("card.activateTheme")})]})]})},L))}),e.jsx(be,{open:i,onOpenChange:l,children:e.jsxs(fe,{className:"sm:max-w-md",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:s("upload.title")}),e.jsx(Te,{children:s("upload.description")})]}),e.jsxs("div",{className:N("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",d&&"border-primary/50 bg-muted/50"),onDragEnter:p,onDragLeave:p,onDragOver:p,onDrop:v,children:[e.jsx("input",{type:"file",ref:h,className:"hidden",accept:".zip",onChange:L=>{const Z=L.target.files?.[0];Z&&k(Z)}}),r?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(pt,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[s("upload.dragText")," ",e.jsx("button",{type:"button",onClick:()=>h.current?.click(),className:"mx-1 text-primary hover:underline",children:s("upload.clickText")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("upload.supportText")})]})]})})]})]})}),e.jsx(be,{open:!!o,onOpenChange:L=>{L||(c(null),E(0))},children:e.jsxs(fe,{className:"max-w-4xl",children:[e.jsxs(Ce,{children:[e.jsxs(ye,{children:[o?.name," ",s("preview.title")]}),e.jsx(Te,{className:"text-center",children:o&&s("preview.imageCount",{current:_+1,total:o.images.length})})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"aspect-[16/9] overflow-hidden rounded-lg border bg-muted",children:o?.images[_]&&e.jsx("img",{src:o.images[_],alt:`${o.name} 预览图 ${_+1}`,className:"h-full w-full object-contain"})}),o&&o.images.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"outline",size:"icon",className:"absolute left-4 top-1/2 h-8 w-8 -translate-y-1/2 rounded-full bg-background/80 hover:bg-background",onClick:M,children:e.jsx(Mo,{className:"h-4 w-4"})}),e.jsx(P,{variant:"outline",size:"icon",className:"absolute right-4 top-1/2 h-8 w-8 -translate-y-1/2 rounded-full bg-background/80 hover:bg-background",onClick:H,children:e.jsx(Fo,{className:"h-4 w-4"})})]})]}),o&&o.images.length>1&&e.jsx("div",{className:"mt-4 flex gap-2 overflow-x-auto pb-2",children:o.images.map((L,Z)=>e.jsx("button",{onClick:()=>E(Z),className:N("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2",_===Z?"border-primary":"border-transparent"),children:e.jsx("img",{src:L,alt:`缩略图 ${Z+1}`,className:"h-full w-full object-cover"})},Z))})]})})]})]})}function cn(){return e.jsxs(We,{children:[e.jsxs(ts,{children:[e.jsx(oe,{className:"h-6 w-[200px]"}),e.jsx(oe,{className:"h-4 w-[300px]"})]}),e.jsxs(as,{className:"flex items-center justify-end space-x-3",children:[e.jsx(oe,{className:"h-10 w-[100px]"}),e.jsx(oe,{className:"h-10 w-[100px]"})]})]})}const Vm=Object.freeze(Object.defineProperty({__proto__:null,default:Im},Symbol.toStringTag,{value:"Module"})),La=u.forwardRef(({className:s,value:n,onChange:t,...r},a)=>{const[i,l]=u.useState("");u.useEffect(()=>{if(i.includes(",")){const m=new Set([...n,...i.split(",").map(o=>o.trim())]);t(Array.from(m)),l("")}},[i,t,n]);const d=()=>{if(i){const m=new Set([...n,i]);t(Array.from(m)),l("")}};return e.jsxs("div",{className:N(" has-[:focus-visible]:outline-none has-[:focus-visible]:ring-1 has-[:focus-visible]:ring-neutral-950 dark:has-[:focus-visible]:ring-neutral-300 flex w-full flex-wrap gap-2 rounded-md border border-input shadow-sm px-3 py-2 text-sm ring-offset-white disabled:cursor-not-allowed disabled:opacity-50",s),children:[n.map(m=>e.jsxs(q,{variant:"secondary",children:[m,e.jsx(J,{variant:"ghost",size:"icon",className:"ml-2 h-3 w-3",onClick:()=>{t(n.filter(o=>o!==m))},children:e.jsx(ga,{className:"w-3"})})]},m)),e.jsx("input",{className:"flex-1 outline-none placeholder:text-muted-foreground bg-transparent",value:i,onChange:m=>l(m.target.value),onKeyDown:m=>{m.key==="Enter"||m.key===","?(m.preventDefault(),d()):m.key==="Backspace"&&i.length===0&&n.length>0&&(m.preventDefault(),t(n.slice(0,-1)))},...r,ref:a})]})});La.displayName="InputTags";const Mm=x.object({id:x.number().nullable(),title:x.string().min(1).max(250),content:x.string().min(1),show:x.boolean(),tags:x.array(x.string()),img_url:x.string().nullable()}),Fm={id:null,show:!1,tags:[],img_url:"",title:"",content:""};function Wr({refetch:s,dialogTrigger:n,type:t="add",defaultFormValues:r=Fm}){const{t:a}=V("notice"),[i,l]=u.useState(!1),d=ge({resolver:Ne(Mm),defaultValues:r,mode:"onChange",shouldFocusError:!0}),m=new Pa({html:!0});return e.jsx(_e,{...d,children:e.jsxs(be,{onOpenChange:l,open:i,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add.button")})]})}),e.jsxs(fe,{className:"sm:max-w-[1025px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:a(t==="add"?"form.add.title":"form.edit.title")}),e.jsx(Te,{})]}),e.jsx(g,{control:d.control,name:"title",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.title.label")}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(T,{placeholder:a("form.fields.title.placeholder"),...o})})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"content",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.content.label")}),e.jsx(y,{children:e.jsx(Ea,{style:{height:"500px"},value:o.value,renderHTML:c=>m.render(c),onChange:({text:c})=>{o.onChange(c)}})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"img_url",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.img_url.label")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:a("form.fields.img_url.placeholder"),...o,value:o.value||""})})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"show",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.show.label")}),e.jsx("div",{className:"relative py-2",children:e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:o.onChange})})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"tags",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.tags.label")}),e.jsx(y,{children:e.jsx(La,{value:o.value,onChange:o.onChange,placeholder:a("form.fields.tags.placeholder"),className:"w-full"})}),e.jsx(D,{})]})}),e.jsxs(ze,{children:[e.jsx(yt,{asChild:!0,children:e.jsx(P,{type:"button",variant:"outline",children:a("form.buttons.cancel")})}),e.jsx(P,{type:"submit",onClick:o=>{o.preventDefault(),d.handleSubmit(async c=>{qc(c).then(({data:h})=>{h&&(A.success(a("form.buttons.success")),s(),l(!1))})})()},children:a("form.buttons.submit")})]})]})]})})}function Om({table:s,refetch:n,saveOrder:t,isSortMode:r}){const{t:a}=V("notice"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between space-x-2 ",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[!r&&e.jsx(Wr,{refetch:n}),!r&&e.jsx(T,{placeholder:a("table.toolbar.search"),value:s.getColumn("title")?.getFilterValue()??"",onChange:l=>s.getColumn("title")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),i&&!r&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-9 px-2 lg:px-3",children:[a("table.toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(P,{variant:r?"default":"outline",onClick:t,className:"h-8",size:"sm",children:a(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}const Lm=s=>{const{t:n}=V("notice");return[{id:"drag-handle",header:"",cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Oo,{className:"h-4 w-4 text-muted-foreground cursor-move"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(q,{variant:"outline",className:"font-mono",children:t.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(Y,{defaultChecked:t.getValue("show"),onCheckedChange:async()=>{const{data:r}=await Bc({id:t.original.id});r||s()}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.title")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[500px] items-center",children:e.jsx("span",{className:"truncate font-medium",children:t.getValue("title")})}),enableSorting:!1,size:6e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Wr,{refetch:s,dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),type:"edit",defaultFormValues:t.original}),e.jsx(Qe,{title:n("table.actions.delete.title"),description:n("table.actions.delete.description"),onConfirm:async()=>{Kc({id:t.original.id}).then(()=>{A.success(n("table.actions.delete.success")),s()})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("table.actions.delete.title")})]})})]}),size:100}]};function zm(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),[m,o]=u.useState(!1),[c,h]=u.useState({}),[_,E]=u.useState({pageSize:50,pageIndex:0}),[C,S]=u.useState([]),{refetch:w}=re({queryKey:["notices"],queryFn:async()=>{const{data:M}=await nn.getList();return S(M),M}});u.useEffect(()=>{r({"drag-handle":m,content:!m,created_at:!m,actions:!m}),E({pageSize:m?99999:50,pageIndex:0})},[m]);const b=(M,H)=>{m&&(M.dataTransfer.setData("text/plain",H.toString()),M.currentTarget.classList.add("opacity-50"))},k=(M,H)=>{if(!m)return;M.preventDefault(),M.currentTarget.classList.remove("bg-muted");const se=parseInt(M.dataTransfer.getData("text/plain"));if(se===H)return;const L=[...C],[Z]=L.splice(se,1);L.splice(H,0,Z),S(L)},p=async()=>{if(!m){o(!0);return}nn.sort(C.map(M=>M.id)).then(()=>{A.success("排序保存成功"),o(!1),w()}).finally(()=>{o(!1)})},v=ns({data:C??[],columns:Lm(w),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,columnSizing:c,pagination:_},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:h,onPaginationChange:E,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(hs,{table:v,toolbar:M=>e.jsx(Om,{table:M,refetch:w,saveOrder:p,isSortMode:m}),draggable:m,onDragStart:b,onDragEnd:M=>M.currentTarget.classList.remove("opacity-50"),onDragOver:M=>{M.preventDefault(),M.currentTarget.classList.add("bg-muted")},onDragLeave:M=>M.currentTarget.classList.remove("bg-muted"),onDrop:k,showPagination:!m})})}function Am(){const{t:s}=V("notice");return e.jsxs(Ee,{children:[e.jsxs(Re,{className:"flex items-center justify-between",children:[e.jsx(Ke,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(zm,{})})]})]})}const $m=Object.freeze(Object.defineProperty({__proto__:null,default:Am},Symbol.toStringTag,{value:"Module"})),Um=x.object({id:x.number().nullable(),language:x.string().max(250),category:x.string().max(250),title:x.string().min(1).max(250),body:x.string().min(1),show:x.boolean()}),Hm={id:null,language:"zh-CN",category:"",title:"",body:"",show:!1};function Yr({refreshData:s,dialogTrigger:n,type:t="add",defaultFormValues:r=Hm}){const{t:a}=V("knowledge"),[i,l]=u.useState(!1),d=ge({resolver:Ne(Um),defaultValues:r,mode:"onChange",shouldFocusError:!0}),m=new Pa({html:!0});return u.useEffect(()=>{i&&r.id&&Wc(r.id).then(({data:o})=>{d.reset(o)})},[r.id,d,i]),e.jsxs(be,{onOpenChange:l,open:i,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add")})]})}),e.jsxs(fe,{className:"sm:max-w-[1025px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:a(t==="add"?"form.add":"form.edit")}),e.jsx(Te,{})]}),e.jsxs(_e,{...d,children:[e.jsx(g,{control:d.control,name:"title",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.title")}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(T,{placeholder:a("form.titlePlaceholder"),...o})})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"category",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.category")}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(T,{placeholder:a("form.categoryPlaceholder"),...o})})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"language",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.language")}),e.jsx(y,{children:e.jsxs(G,{value:o.value,onValueChange:o.onChange,children:[e.jsx(K,{children:e.jsx(W,{placeholder:a("form.languagePlaceholder")})}),e.jsx(B,{children:[{value:"en-US"},{value:"ja-JP"},{value:"ko-KR"},{value:"vi-VN"},{value:"zh-CN"},{value:"zh-TW"}].map(c=>e.jsx(z,{value:c.value,className:"cursor-pointer",children:a(`languages.${c.value}`)},c.value))})]})})]})}),e.jsx(g,{control:d.control,name:"body",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.content")}),e.jsx(y,{children:e.jsx(Ea,{style:{height:"500px"},value:o.value,renderHTML:c=>m.render(c),onChange:({text:c})=>{o.onChange(c)}})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"show",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.show")}),e.jsx("div",{className:"relative py-2",children:e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:o.onChange})})}),e.jsx(D,{})]})}),e.jsxs(ze,{children:[e.jsx(yt,{asChild:!0,children:e.jsx(P,{type:"button",variant:"outline",children:a("form.cancel")})}),e.jsx(P,{type:"submit",onClick:()=>{d.handleSubmit(o=>{Yc(o).then(({data:c})=>{c&&(d.reset(),A.success(a("messages.operationSuccess")),l(!1),s())})})()},children:a("form.submit")})]})]})]})]})}function qm({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(qt,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:a.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:a.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(xs,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Ms,{children:[e.jsx(Ks,{placeholder:n}),e.jsxs(Fs,{children:[e.jsx(Bs,{children:"No results found."}),e.jsx(Ye,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(Me,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx($s,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{}),e.jsx(Ye,{children:e.jsx(Me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function Km({table:s,refetch:n,saveOrder:t,isSortMode:r}){const a=s.getState().columnFilters.length>0,{t:i}=V("knowledge");return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sortModeHint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Yr,{refreshData:n}),e.jsx(T,{placeholder:i("toolbar.searchPlaceholder"),value:s.getColumn("title")?.getFilterValue()??"",onChange:l=>s.getColumn("title")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),s.getColumn("category")&&e.jsx(qm,{column:s.getColumn("category"),title:i("columns.category"),options:Array.from(new Set(s.getCoreRowModel().rows.map(l=>l.getValue("category")))).map(l=>({label:l,value:l}))}),a&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[i("toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{variant:r?"default":"outline",onClick:t,size:"sm",children:i(r?"toolbar.saveSort":"toolbar.editSort")})})]})}const Bm=({refetch:s,isSortMode:n=!1})=>{const{t}=V("knowledge");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(Ht,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.id")}),cell:({row:r})=>e.jsx(q,{variant:"outline",className:"justify-center",children:r.getValue("id")}),enableSorting:!0,size:70},{accessorKey:"show",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.status")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx(Y,{defaultChecked:r.getValue("show"),onCheckedChange:async()=>{Jc({id:r.original.id}).then(({data:a})=>{a||s()})}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.title")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"line-clamp-2 font-medium",children:r.getValue("title")})}),enableSorting:!0,size:600},{accessorKey:"category",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.category")}),cell:({row:r})=>e.jsx(q,{variant:"secondary",className:"max-w-[180px] truncate",children:r.getValue("category")}),enableSorting:!0,size:1800},{id:"actions",header:({column:r})=>e.jsx(O,{className:"justify-end",column:r,title:t("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx(Yr,{refreshData:s,dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:t("form.edit")})]}),type:"edit",defaultFormValues:r.original}),e.jsx(Qe,{title:t("messages.deleteConfirm"),description:t("messages.deleteDescription"),confirmText:t("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Qc({id:r.original.id}).then(({data:a})=>{a&&(A.success(t("messages.operationSuccess")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:t("messages.deleteButton")})]})})]}),size:100}]};function Gm(){const[s,n]=u.useState([]),[t,r]=u.useState([]),[a,i]=u.useState(!1),[l,d]=u.useState([]),[m,o]=u.useState({"drag-handle":!1}),[c,h]=u.useState({pageSize:20,pageIndex:0}),{refetch:_,isLoading:E,data:C}=re({queryKey:["knowledge"],queryFn:async()=>{const{data:p}=await Gc();return d(p||[]),p}});u.useEffect(()=>{o({"drag-handle":a,actions:!a}),h({pageSize:a?99999:10,pageIndex:0})},[a]);const S=(p,v)=>{a&&(p.dataTransfer.setData("text/plain",v.toString()),p.currentTarget.classList.add("opacity-50"))},w=(p,v)=>{if(!a)return;p.preventDefault(),p.currentTarget.classList.remove("bg-muted");const M=parseInt(p.dataTransfer.getData("text/plain"));if(M===v)return;const H=[...l],[se]=H.splice(M,1);H.splice(v,0,se),d(H)},b=async()=>{a?Xc({ids:l.map(p=>p.id)}).then(()=>{_(),i(!1),A.success("排序保存成功")}):i(!0)},k=ns({data:l,columns:Bm({refetch:_,isSortMode:a}),state:{sorting:t,columnFilters:s,columnVisibility:m,pagination:c},onSortingChange:r,onColumnFiltersChange:n,onColumnVisibilityChange:o,onPaginationChange:h,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(hs,{table:k,toolbar:p=>e.jsx(Km,{table:p,refetch:_,saveOrder:b,isSortMode:a}),draggable:a,onDragStart:S,onDragEnd:p=>p.currentTarget.classList.remove("opacity-50"),onDragOver:p=>{p.preventDefault(),p.currentTarget.classList.add("bg-muted")},onDragLeave:p=>p.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!a})}function Wm(){const{t:s}=V("knowledge");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight mb-2",children:s("title")}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Gm,{})})]})]})}const Ym=Object.freeze(Object.defineProperty({__proto__:null,default:Wm},Symbol.toStringTag,{value:"Module"}));function Qm(s,n){const[t,r]=u.useState(s);return u.useEffect(()=>{const a=setTimeout(()=>r(s),n);return()=>{clearTimeout(a)}},[s,n]),t}function ca(s,n){if(s.length===0)return{};if(!n)return{"":s};const t={};return s.forEach(r=>{const a=r[n]||"";t[a]||(t[a]=[]),t[a].push(r)}),t}function Jm(s,n){const t=JSON.parse(JSON.stringify(s));for(const[r,a]of Object.entries(t))t[r]=a.filter(i=>!n.find(l=>l.value===i.value));return t}function Xm(s,n){for(const[,t]of Object.entries(s))if(t.some(r=>n.find(a=>a.value===r.value)))return!0;return!1}const Qr=u.forwardRef(({className:s,...n},t)=>Lo(a=>a.filtered.count===0)?e.jsx("div",{ref:t,className:N("py-6 text-center text-sm",s),"cmdk-empty":"",role:"presentation",...n}):null);Qr.displayName="CommandEmpty";const at=u.forwardRef(({value:s,onChange:n,placeholder:t,defaultOptions:r=[],options:a,delay:i,onSearch:l,loadingIndicator:d,emptyIndicator:m,maxSelected:o=Number.MAX_SAFE_INTEGER,onMaxSelected:c,hidePlaceholderWhenSelected:h,disabled:_,groupBy:E,className:C,badgeClassName:S,selectFirstItem:w=!0,creatable:b=!1,triggerSearchOnFocus:k=!1,commandProps:p,inputProps:v,hideClearAllButton:M=!1},H)=>{const se=u.useRef(null),[L,Z]=u.useState(!1),de=u.useRef(!1),[Q,te]=u.useState(!1),[$,R]=u.useState(s||[]),[X,Ns]=u.useState(ca(r,E)),[De,le]=u.useState(""),Os=Qm(De,i||500);u.useImperativeHandle(H,()=>({selectedValue:[...$],input:se.current,focus:()=>se.current?.focus()}),[$]);const Ws=u.useCallback(ee=>{const ue=$.filter(Ue=>Ue.value!==ee.value);R(ue),n?.(ue)},[n,$]),bl=u.useCallback(ee=>{const ue=se.current;ue&&((ee.key==="Delete"||ee.key==="Backspace")&&ue.value===""&&$.length>0&&($[$.length-1].fixed||Ws($[$.length-1])),ee.key==="Escape"&&ue.blur())},[Ws,$]);u.useEffect(()=>{s&&R(s)},[s]),u.useEffect(()=>{if(!a||l)return;const ee=ca(a||[],E);JSON.stringify(ee)!==JSON.stringify(X)&&Ns(ee)},[r,a,E,l,X]),u.useEffect(()=>{const ee=async()=>{te(!0);const Ue=await l?.(Os);Ns(ca(Ue||[],E)),te(!1)};(async()=>{!l||!L||(k&&await ee(),Os&&await ee())})()},[Os,E,L,k]);const yl=()=>{if(!b||Xm(X,[{value:De,label:De}])||$.find(ue=>ue.value===De))return;const ee=e.jsx(Me,{value:De,className:"cursor-pointer",onMouseDown:ue=>{ue.preventDefault(),ue.stopPropagation()},onSelect:ue=>{if($.length>=o){c?.($.length);return}le("");const Ue=[...$,{value:ue,label:ue}];R(Ue),n?.(Ue)},children:`Create "${De}"`});if(!l&&De.length>0||l&&Os.length>0&&!Q)return ee},Nl=u.useCallback(()=>{if(m)return l&&!b&&Object.keys(X).length===0?e.jsx(Me,{value:"-",disabled:!0,children:m}):e.jsx(Qr,{children:m})},[b,m,l,X]),_l=u.useMemo(()=>Jm(X,$),[X,$]),wl=u.useCallback(()=>{if(p?.filter)return p.filter;if(b)return(ee,ue)=>ee.toLowerCase().includes(ue.toLowerCase())?1:-1},[b,p?.filter]),Cl=u.useCallback(()=>{const ee=$.filter(ue=>ue.fixed);R(ee),n?.(ee)},[n,$]);return e.jsxs(Ms,{...p,onKeyDown:ee=>{bl(ee),p?.onKeyDown?.(ee)},className:N("h-auto overflow-visible bg-transparent",p?.className),shouldFilter:p?.shouldFilter!==void 0?p.shouldFilter:!l,filter:wl(),children:[e.jsx("div",{className:N("rounded-md border border-input text-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring ",{"px-3 py-2":$.length!==0,"cursor-text":!_&&$.length!==0},C),onClick:()=>{_||se.current?.focus()},children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[$.map(ee=>e.jsxs(q,{className:N("data-[disabled]:bg-muted-foreground data-[disabled]:text-muted data-[disabled]:hover:bg-muted-foreground","data-[fixed]:bg-muted-foreground data-[fixed]:text-muted data-[fixed]:hover:bg-muted-foreground",S),"data-fixed":ee.fixed,"data-disabled":_||void 0,children:[ee.label,e.jsx("button",{className:N("ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",(_||ee.fixed)&&"hidden"),onKeyDown:ue=>{ue.key==="Enter"&&Ws(ee)},onMouseDown:ue=>{ue.preventDefault(),ue.stopPropagation()},onClick:()=>Ws(ee),children:e.jsx(ga,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},ee.value)),e.jsx(Le.Input,{...v,ref:se,value:De,disabled:_,onValueChange:ee=>{le(ee),v?.onValueChange?.(ee)},onBlur:ee=>{de.current===!1&&Z(!1),v?.onBlur?.(ee)},onFocus:ee=>{Z(!0),k&&l?.(Os),v?.onFocus?.(ee)},placeholder:h&&$.length!==0?"":t,className:N("flex-1 bg-transparent outline-none placeholder:text-muted-foreground",{"w-full":h,"px-3 py-2":$.length===0,"ml-1":$.length!==0},v?.className)}),e.jsx("button",{type:"button",onClick:Cl,className:N((M||_||$.length<1||$.filter(ee=>ee.fixed).length===$.length)&&"hidden"),children:e.jsx(ga,{})})]})}),e.jsx("div",{className:"relative",children:L&&e.jsx(Fs,{className:"absolute top-1 z-10 w-full rounded-md border bg-popover text-popover-foreground shadow-md outline-none animate-in",onMouseLeave:()=>{de.current=!1},onMouseEnter:()=>{de.current=!0},onMouseUp:()=>{se.current?.focus()},children:Q?e.jsx(e.Fragment,{children:d}):e.jsxs(e.Fragment,{children:[Nl(),yl(),!w&&e.jsx(Me,{value:"-",className:"hidden"}),Object.entries(_l).map(([ee,ue])=>e.jsx(Ye,{heading:ee,className:"h-full overflow-auto",children:e.jsx(e.Fragment,{children:ue.map(Ue=>e.jsx(Me,{value:Ue.value,disabled:Ue.disable,onMouseDown:lt=>{lt.preventDefault(),lt.stopPropagation()},onSelect:()=>{if($.length>=o){c?.($.length);return}le("");const lt=[...$,Ue];R(lt),n?.(lt)},className:N("cursor-pointer",Ue.disable&&"cursor-default text-muted-foreground"),children:Ue.label},Ue.value))})},ee))]})})})]})});at.displayName="MultipleSelector";const Zm=s=>x.object({id:x.number().optional(),name:x.string().min(2,s("messages.nameValidation.min")).max(50,s("messages.nameValidation.max")).regex(/^[a-zA-Z0-9\u4e00-\u9fa5_-]+$/,s("messages.nameValidation.pattern"))});function ta({refetch:s,dialogTrigger:n,defaultValues:t={name:""},type:r="add"}){const{t:a}=V("group"),i=ge({resolver:Ne(Zm(a)),defaultValues:t,mode:"onChange"}),[l,d]=u.useState(!1),[m,o]=u.useState(!1),c=async h=>{o(!0),Ic(h).then(()=>{A.success(a(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),s&&s(),i.reset(),d(!1)}).finally(()=>{o(!1)})};return e.jsxs(be,{open:l,onOpenChange:d,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("span",{children:a("form.add")})]})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:a(r==="edit"?"form.edit":"form.create")}),e.jsx(Te,{children:a(r==="edit"?"form.editDescription":"form.createDescription")})]}),e.jsx(_e,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(c),className:"space-y-4",children:[e.jsx(g,{control:i.control,name:"name",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.name")}),e.jsx(y,{children:e.jsx(T,{placeholder:a("form.namePlaceholder"),...h,className:"w-full"})}),e.jsx(F,{children:a("form.nameDescription")}),e.jsx(D,{})]})}),e.jsxs(ze,{className:"gap-2",children:[e.jsx(yt,{asChild:!0,children:e.jsx(P,{type:"button",variant:"outline",children:a("form.cancel")})}),e.jsxs(P,{type:"submit",disabled:m||!i.formState.isValid,children:[m&&e.jsx(Da,{className:"mr-2 h-4 w-4 animate-spin"}),a(r==="edit"?"form.update":"form.create")]})]})]})})]})]})}const Jr=u.createContext(void 0);function ex({children:s,refetch:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(null),[l,d]=u.useState(ie.Shadowsocks);return e.jsx(Jr.Provider,{value:{isOpen:t,setIsOpen:r,editingServer:a,setEditingServer:i,serverType:l,setServerType:d,refetch:n},children:s})}function Xr(){const s=u.useContext(Jr);if(s===void 0)throw new Error("useServerEdit must be used within a ServerEditProvider");return s}function da({dialogTrigger:s,value:n,setValue:t,templateType:r}){const{t:a}=V("server");u.useEffect(()=>{console.log(n)},[n]);const[i,l]=u.useState(!1),[d,m]=u.useState(()=>{if(!n||Object.keys(n).length===0)return"";try{return JSON.stringify(n,null,2)}catch{return""}}),[o,c]=u.useState(null),h=b=>{if(!b)return null;try{const k=JSON.parse(b);return typeof k!="object"||k===null?a("network_settings.validation.must_be_object"):null}catch{return a("network_settings.validation.invalid_json")}},_={tcp:{label:"TCP",content:{acceptProxyProtocol:!1,header:{type:"none"}}},"tcp-http":{label:"TCP + HTTP",content:{acceptProxyProtocol:!1,header:{type:"http",request:{version:"1.1",method:"GET",path:["/"],headers:{Host:["www.example.com"]}},response:{version:"1.1",status:"200",reason:"OK"}}}},grpc:{label:"gRPC",content:{serviceName:"GunService"}},ws:{label:"WebSocket",content:{path:"/",headers:{Host:"v2ray.com"}}},httpupgrade:{label:"HttpUpgrade",content:{acceptProxyProtocol:!1,path:"/",host:"xray.com",headers:{key:"value"}}},xhttp:{label:"XHTTP",content:{host:"example.com",path:"/yourpath",mode:"auto",extra:{headers:{},xPaddingBytes:"100-1000",noGRPCHeader:!1,noSSEHeader:!1,scMaxEachPostBytes:1e6,scMinPostsIntervalMs:30,scMaxBufferedPosts:30,xmux:{maxConcurrency:"16-32",maxConnections:0,cMaxReuseTimes:"64-128",cMaxLifetimeMs:0,hMaxRequestTimes:"800-900",hKeepAlivePeriod:0},downloadSettings:{address:"",port:443,network:"xhttp",security:"tls",tlsSettings:{},xhttpSettings:{path:"/yourpath"},sockopt:{}}}}}},E=()=>{switch(r){case"tcp":return["tcp","tcp-http"];case"grpc":return["grpc"];case"ws":return["ws"];case"httpupgrade":return["httpupgrade"];case"xhttp":return["xhttp"];default:return[]}},C=()=>{const b=h(d||"");if(b){A.error(b);return}try{if(!d){t(null),l(!1);return}t(JSON.parse(d)),l(!1)}catch{A.error(a("network_settings.errors.save_failed"))}},S=b=>{m(b),c(h(b))},w=b=>{const k=_[b];if(k){const p=JSON.stringify(k.content,null,2);m(p),c(null)}};return u.useEffect(()=>{i&&console.log(n)},[i,n]),u.useEffect(()=>{i&&n&&Object.keys(n).length>0&&m(JSON.stringify(n,null,2))},[i,n]),e.jsxs(be,{open:i,onOpenChange:b=>{!b&&i&&C(),l(b)},children:[e.jsx(Je,{asChild:!0,children:s??e.jsx(J,{variant:"link",children:a("network_settings.edit_protocol")})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsx(Ce,{children:e.jsx(ye,{children:a("network_settings.edit_protocol_config")})}),e.jsxs("div",{className:"space-y-4",children:[E().length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:E().map(b=>e.jsx(J,{variant:"outline",size:"sm",onClick:()=>w(b),children:a("network_settings.use_template",{template:_[b].label})},b))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ys,{className:`min-h-[200px] font-mono text-sm ${o?"border-red-500 focus-visible:ring-red-500":""}`,value:d,placeholder:E().length>0?a("network_settings.json_config_placeholder_with_template"):a("network_settings.json_config_placeholder"),onChange:b=>S(b.target.value)}),o&&e.jsx("p",{className:"text-sm text-red-500",children:o})]})]}),e.jsxs(ze,{className:"gap-2",children:[e.jsx(J,{variant:"outline",onClick:()=>l(!1),children:a("common.cancel")}),e.jsx(J,{onClick:C,disabled:!!o,children:a("common.confirm")})]})]})]})}function pp(s){throw new Error('Could not dynamically require "'+s+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}const sx={},tx=Object.freeze(Object.defineProperty({__proto__:null,default:sx},Symbol.toStringTag,{value:"Module"})),fp=Xo(tx),dn=s=>s.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),ax=()=>{try{const s=zo.box.keyPair(),n=dn(Ja.encodeBase64(s.secretKey)),t=dn(Ja.encodeBase64(s.publicKey));return{privateKey:n,publicKey:t}}catch(s){throw console.error("Error generating x25519 key pair:",s),s}},nx=()=>{try{return ax()}catch(s){throw console.error("Error generating key pair:",s),s}},rx=s=>{const n=new Uint8Array(Math.ceil(s/2));return window.crypto.getRandomValues(n),Array.from(n).map(t=>t.toString(16).padStart(2,"0")).join("").substring(0,s)},lx=()=>{const s=Math.floor(Math.random()*8)*2+2;return rx(s)},ix=x.object({cipher:x.string().default("aes-128-gcm"),obfs:x.string().default("0"),obfs_settings:x.object({path:x.string().default(""),host:x.string().default("")}).default({})}),ox=x.object({tls:x.coerce.number().default(0),tls_settings:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({}),network:x.string().default("tcp"),network_settings:x.record(x.any()).default({})}),cx=x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1),network:x.string().default("tcp"),network_settings:x.record(x.any()).default({})}),dx=x.object({version:x.coerce.number().default(2),alpn:x.string().default("h2"),obfs:x.object({open:x.coerce.boolean().default(!1),type:x.string().default("salamander"),password:x.string().default("")}).default({}),tls:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({}),bandwidth:x.object({up:x.string().default(""),down:x.string().default("")}).default({})}),ux=x.object({tls:x.coerce.number().default(0),tls_settings:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({}),reality_settings:x.object({server_port:x.coerce.number().default(443),server_name:x.string().default(""),allow_insecure:x.boolean().default(!1),public_key:x.string().default(""),private_key:x.string().default(""),short_id:x.string().default("")}).default({}),network:x.string().default("tcp"),network_settings:x.record(x.any()).default({}),flow:x.string().default("")}),mx=x.object({version:x.coerce.number().default(5),congestion_control:x.string().default("bbr"),alpn:x.array(x.string()).default(["h3"]),udp_relay_mode:x.string().default("native"),tls:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({})}),xx=x.object({}),hx=x.object({tls:x.coerce.number().default(0),tls_settings:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({})}),px=x.object({tls:x.coerce.number().default(0),tls_settings:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({})}),fx=x.object({transport:x.string().default("tcp"),multiplexing:x.string().default("MULTIPLEXING_LOW")}),Ie={shadowsocks:{schema:ix,ciphers:["aes-128-gcm","aes-192-gcm","aes-256-gcm","chacha20-ietf-poly1305","2022-blake3-aes-128-gcm","2022-blake3-aes-256-gcm"]},vmess:{schema:ox,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},trojan:{schema:cx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},hysteria:{schema:dx,versions:["1","2"],alpnOptions:["hysteria","http/1.1","h2","h3"]},vless:{schema:ux,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"},{value:"kcp",label:"mKCP"},{value:"httpupgrade",label:"HttpUpgrade"},{value:"xhttp",label:"XHTTP"}],flowOptions:["none","xtls-rprx-direct","xtls-rprx-splice","xtls-rprx-vision"]},tuic:{schema:mx,versions:["5","4"],congestionControls:["bbr","cubic","new_reno"],alpnOptions:[{value:"h3",label:"HTTP/3"},{value:"h2",label:"HTTP/2"},{value:"http/1.1",label:"HTTP/1.1"}],udpRelayModes:[{value:"native",label:"Native"},{value:"quic",label:"QUIC"}]},socks:{schema:xx},naive:{schema:px},http:{schema:hx},mieru:{schema:fx,transportOptions:[{value:"tcp",label:"TCP"},{value:"udp",label:"UDP"}],multiplexingOptions:[{value:"MULTIPLEXING_OFF",label:"Off"},{value:"MULTIPLEXING_LOW",label:"Low"},{value:"MULTIPLEXING_MIDDLE",label:"Middle"},{value:"MULTIPLEXING_HIGH",label:"High"}]}},gx=({serverType:s,value:n,onChange:t})=>{const{t:r}=V("server"),a=s?Ie[s]:null,i=a?.schema||x.record(x.any()),l=s?i.parse({}):{},d=ge({resolver:Ne(i),defaultValues:l,mode:"onChange"});if(u.useEffect(()=>{if(!n||Object.keys(n).length===0){if(s){const p=i.parse({});d.reset(p)}}else d.reset(n)},[s,n,t,d,i]),u.useEffect(()=>{const p=d.watch(v=>{t(v)});return()=>p.unsubscribe()},[d,t]),!s||!a)return null;const k={shadowsocks:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"cipher",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.shadowsocks.cipher.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.shadowsocks.cipher.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.shadowsocks.ciphers.map(v=>e.jsx(z,{value:v,children:v},v))})})]})})]})}),e.jsx(g,{control:d.control,name:"obfs",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.shadowsocks.obfs.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.shadowsocks.obfs.placeholder")})}),e.jsx(B,{children:e.jsxs(He,{children:[e.jsx(z,{value:"0",children:r("dynamic_form.shadowsocks.obfs.none")}),e.jsx(z,{value:"http",children:r("dynamic_form.shadowsocks.obfs.http")})]})})]})})]})}),d.watch("obfs")==="http"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"obfs_settings.path",render:({field:p})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:r("dynamic_form.shadowsocks.obfs_settings.path"),...p})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"obfs_settings.host",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:r("dynamic_form.shadowsocks.obfs_settings.host"),...p})}),e.jsx(D,{})]})})]})]}),vmess:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"tls",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vmess.tls.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value?.toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.vmess.tls.placeholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:r("dynamic_form.vmess.tls.disabled")}),e.jsx(z,{value:"1",children:r("dynamic_form.vmess.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls_settings.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.vmess.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.vmess.tls_settings.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"tls_settings.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vmess.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"network",render:({field:p})=>e.jsxs(f,{children:[e.jsxs(j,{children:[r("dynamic_form.vmess.network.label"),e.jsx(da,{value:d.watch("network_settings"),setValue:v=>d.setValue("network_settings",v),templateType:d.watch("network")})]}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.vmess.network.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.vmess.networkOptions.map(v=>e.jsx(z,{value:v.value,className:"cursor-pointer",children:v.label},v.value))})})]})})]})})]}),trojan:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.trojan.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.trojan.server_name.placeholder"),...p,value:p.value||""})})]})}),e.jsx(g,{control:d.control,name:"allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.trojan.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value||!1,onCheckedChange:p.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"network",render:({field:p})=>e.jsxs(f,{children:[e.jsxs(j,{children:[r("dynamic_form.trojan.network.label"),e.jsx(da,{value:d.watch("network_settings")||{},setValue:v=>d.setValue("network_settings",v),templateType:d.watch("network")||"tcp"})]}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value||"tcp",children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.trojan.network.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.trojan.networkOptions.map(v=>e.jsx(z,{value:v.value,className:"cursor-pointer",children:v.label},v.value))})})]})})]})})]}),hysteria:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"version",render:({field:p})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.hysteria.version.label")}),e.jsx(y,{children:e.jsxs(G,{value:(p.value||2).toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.hysteria.version.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.hysteria.versions.map(v=>e.jsxs(z,{value:v,className:"cursor-pointer",children:["V",v]},v))})})]})})]})}),d.watch("version")==1&&e.jsx(g,{control:d.control,name:"alpn",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.hysteria.alpn.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value||"h2",onValueChange:p.onChange,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.hysteria.alpn.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.hysteria.alpnOptions.map(v=>e.jsx(z,{value:v,children:v},v))})})]})})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"obfs.open",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.obfs.label")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value||!1,onCheckedChange:p.onChange})})})]})}),!!d.watch("obfs.open")&&e.jsxs(e.Fragment,{children:[d.watch("version")=="2"&&e.jsx(g,{control:d.control,name:"obfs.type",render:({field:p})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.hysteria.obfs.type.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value||"salamander",onValueChange:p.onChange,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.hysteria.obfs.type.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:e.jsx(z,{value:"salamander",children:r("dynamic_form.hysteria.obfs.type.salamander")})})})]})})]})}),e.jsx(g,{control:d.control,name:"obfs.password",render:({field:p})=>e.jsxs(f,{className:d.watch("version")==2?"w-full":"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.hysteria.obfs.password.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.hysteria.obfs.password.placeholder"),...p,value:p.value||"",className:"pr-9"})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",M=Array.from(crypto.getRandomValues(new Uint8Array(16))).map(H=>v[H%v.length]).join("");d.setValue("obfs.password",M),A.success(r("dynamic_form.hysteria.obfs.password.generate_success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Ve,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})]})]})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.hysteria.tls.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.hysteria.tls.server_name.placeholder"),...p,value:p.value||""})})]})}),e.jsx(g,{control:d.control,name:"tls.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value||!1,onCheckedChange:p.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"bandwidth.up",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.bandwidth.up.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:r("dynamic_form.hysteria.bandwidth.up.placeholder")+(d.watch("version")==2?r("dynamic_form.hysteria.bandwidth.up.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...p,value:p.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:r("dynamic_form.hysteria.bandwidth.up.suffix")})})]})]})}),e.jsx(g,{control:d.control,name:"bandwidth.down",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.bandwidth.down.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:r("dynamic_form.hysteria.bandwidth.down.placeholder")+(d.watch("version")==2?r("dynamic_form.hysteria.bandwidth.down.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...p,value:p.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:r("dynamic_form.hysteria.bandwidth.down.suffix")})})]})]})})]}),vless:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"tls",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.tls.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value?.toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.vless.tls.placeholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:r("dynamic_form.vless.tls.none")}),e.jsx(z,{value:"1",children:r("dynamic_form.vless.tls.tls")}),e.jsx(z,{value:"2",children:r("dynamic_form.vless.tls.reality")})]})]})})]})}),d.watch("tls")=="1"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls_settings.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.vless.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.tls_settings.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"tls_settings.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]}),d.watch("tls")==2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"reality_settings.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.reality_settings.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"reality_settings.server_port",render:({field:p})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.server_port.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.reality_settings.server_port.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"reality_settings.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]}),e.jsx("div",{className:"flex items-end gap-2",children:e.jsx(g,{control:d.control,name:"reality_settings.private_key",render:({field:p})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.private_key.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{children:e.jsx(T,{...p,className:"pr-9"})}),e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{try{const v=nx();d.setValue("reality_settings.private_key",v.privateKey),d.setValue("reality_settings.public_key",v.publicKey),A.success(r("dynamic_form.vless.reality_settings.key_pair.success"))}catch{A.error(r("dynamic_form.vless.reality_settings.key_pair.error"))}},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Ve,{icon:"ion:key-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(It,{children:e.jsx(ce,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.key_pair.generate")})})})]})]})]})})}),e.jsx(g,{control:d.control,name:"reality_settings.public_key",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.public_key.label")}),e.jsx(y,{children:e.jsx(T,{...p})})]})}),e.jsx(g,{control:d.control,name:"reality_settings.short_id",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.short_id.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{children:e.jsx(T,{...p,className:"pr-9",placeholder:r("dynamic_form.vless.reality_settings.short_id.placeholder")})}),e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const v=lx();d.setValue("reality_settings.short_id",v),A.success(r("dynamic_form.vless.reality_settings.short_id.success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Ve,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(It,{children:e.jsx(ce,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.short_id.generate")})})})]})]}),e.jsx(F,{className:"text-xs text-muted-foreground",children:r("dynamic_form.vless.reality_settings.short_id.description")})]})})]}),e.jsx(g,{control:d.control,name:"network",render:({field:p})=>e.jsxs(f,{children:[e.jsxs(j,{children:[r("dynamic_form.vless.network.label"),e.jsx(da,{value:d.watch("network_settings"),setValue:v=>d.setValue("network_settings",v),templateType:d.watch("network")})]}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.vless.network.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.vless.networkOptions.map(v=>e.jsx(z,{value:v.value,className:"cursor-pointer",children:v.label},v.value))})})]})})]})}),e.jsx(g,{control:d.control,name:"flow",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.flow.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:v=>p.onChange(v==="none"?null:v),value:p.value||"none",children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.vless.flow.placeholder")})}),e.jsx(B,{children:Ie.vless.flowOptions.map(v=>e.jsx(z,{value:v,children:v},v))})]})})]})})]}),tuic:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"version",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.tuic.version.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value?.toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.tuic.version.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.tuic.versions.map(v=>e.jsxs(z,{value:v,children:["V",v]},v))})})]})})]})}),e.jsx(g,{control:d.control,name:"congestion_control",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.tuic.congestion_control.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.tuic.congestion_control.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.tuic.congestionControls.map(v=>e.jsx(z,{value:v,children:v.toUpperCase()},v))})})]})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.tuic.tls.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.tuic.tls.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"tls.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.tuic.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"alpn",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.tuic.tls.alpn.label")}),e.jsx(y,{children:e.jsx(at,{options:Ie.tuic.alpnOptions,onChange:v=>p.onChange(v.map(M=>M.value)),value:Ie.tuic.alpnOptions.filter(v=>p.value?.includes(v.value)),placeholder:r("dynamic_form.tuic.tls.alpn.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:r("dynamic_form.tuic.tls.alpn.empty")})})})]})}),e.jsx(g,{control:d.control,name:"udp_relay_mode",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.tuic.udp_relay_mode.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.tuic.udp_relay_mode.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.tuic.udpRelayModes.map(v=>e.jsx(z,{value:v.value,children:v.label},v.value))})})]})})]})})]}),socks:()=>e.jsx(e.Fragment,{}),naive:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"tls",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.naive.tls.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value?.toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.naive.tls.placeholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:r("dynamic_form.naive.tls.disabled")}),e.jsx(z,{value:"1",children:r("dynamic_form.naive.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls_settings.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.naive.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.naive.tls_settings.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"tls_settings.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.naive.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]})]}),http:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"tls",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.http.tls.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value?.toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.http.tls.placeholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:r("dynamic_form.http.tls.disabled")}),e.jsx(z,{value:"1",children:r("dynamic_form.http.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls_settings.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.http.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.http.tls_settings.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"tls_settings.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.http.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]})]}),mieru:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"transport",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.mieru.transport.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.mieru.transport.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.mieru.transportOptions.map(v=>e.jsx(z,{value:v.value,children:v.label},v.value))})})]})})]})}),e.jsx(g,{control:d.control,name:"multiplexing",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.mieru.multiplexing.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.mieru.multiplexing.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.mieru.multiplexingOptions.map(v=>e.jsx(z,{value:v.value,children:v.label},v.value))})})]})})]})})]})};return e.jsx(ve,{children:k[s]?.()})},jx=x.object({id:x.number().optional().nullable(),code:x.string().optional(),name:x.string().min(1,"form.name.error"),rate:x.string().min(1,"form.rate.error"),tags:x.array(x.string()).default([]),excludes:x.array(x.string()).default([]),ips:x.array(x.string()).default([]),group_ids:x.array(x.string()).default([]),host:x.string().min(1,"form.host.error"),port:x.string().min(1,"form.port.error"),server_port:x.string().min(1,"form.server_port.error"),parent_id:x.string().default("0").nullable(),route_ids:x.array(x.string()).default([]),protocol_settings:x.record(x.any()).default({}).nullable()}),wt={id:null,code:"",name:"",rate:"1",tags:[],excludes:[],ips:[],group_ids:[],host:"",port:"",server_port:"",parent_id:"0",route_ids:[],protocol_settings:null};function vx(){const{t:s}=V("server"),{isOpen:n,setIsOpen:t,editingServer:r,setEditingServer:a,serverType:i,setServerType:l,refetch:d}=Xr(),[m,o]=u.useState([]),[c,h]=u.useState([]),[_,E]=u.useState([]),C=ge({resolver:Ne(jx),defaultValues:wt,mode:"onChange"});u.useEffect(()=>{S()},[n]),u.useEffect(()=>{r?.type&&r.type!==i&&l(r.type)},[r,i,l]),u.useEffect(()=>{r?r.type===i&&C.reset({...wt,...r}):C.reset({...wt,protocol_settings:Ie[i].schema.parse({})})},[r,C,i]);const S=async()=>{if(!n)return;const[v,M,H]=await Promise.all([bt(),Sr(),Cr()]);o(v.data?.map(se=>({label:se.name,value:se.id.toString()}))||[]),h(M.data?.map(se=>({label:se.remarks,value:se.id.toString()}))||[]),E(H.data||[])},w=u.useMemo(()=>_?.filter(v=>(v.parent_id===0||v.parent_id===null)&&v.type===i&&v.id!==C.watch("id")),[i,_,C]),b=()=>e.jsxs(Ss,{children:[e.jsx(ks,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(fs,{align:"start",children:e.jsx(Ld,{children:Xe.map(({type:v,label:M})=>e.jsx(je,{onClick:()=>{l(v),t(!0)},className:"cursor-pointer",children:e.jsx(q,{variant:"outline",className:"text-white",style:{background:qe[v]},children:M})},v))})})]}),k=()=>{t(!1),a(null),C.reset(wt)},p=async()=>{const v=C.getValues();(await Tc({...v,type:i})).data&&(k(),A.success(s("form.success")),d())};return e.jsxs(be,{open:n,onOpenChange:k,children:[b(),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:s(r?"form.edit_node":"form.new_node")}),e.jsx(Te,{})]}),e.jsxs(_e,{...C,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:C.control,name:"name",render:({field:v})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:s("form.name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("form.name.placeholder"),...v})}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"rate",render:({field:v})=>e.jsxs(f,{className:"flex-[1]",children:[e.jsx(j,{children:s("form.rate.label")}),e.jsx("div",{className:"relative flex",children:e.jsx(y,{children:e.jsx(T,{type:"number",min:"0",step:"0.1",...v})})}),e.jsx(D,{})]})})]}),e.jsx(g,{control:C.control,name:"code",render:({field:v})=>e.jsxs(f,{children:[e.jsxs(j,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(y,{children:e.jsx(T,{placeholder:s("form.code.placeholder"),...v,value:v.value||""})}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"tags",render:({field:v})=>e.jsxs(f,{children:[e.jsx(j,{children:s("form.tags.label")}),e.jsx(y,{children:e.jsx(La,{value:v.value,onChange:v.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"group_ids",render:({field:v})=>e.jsxs(f,{children:[e.jsxs(j,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(ta,{dialogTrigger:e.jsx(P,{variant:"link",children:s("form.groups.add")}),refetch:S})]}),e.jsx(y,{children:e.jsx(at,{options:m,onChange:M=>v.onChange(M.map(H=>H.value)),value:m?.filter(M=>v.value.includes(M.value)),placeholder:s("form.groups.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.groups.empty")})})}),e.jsx(D,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:C.control,name:"host",render:({field:v})=>e.jsxs(f,{children:[e.jsx(j,{children:s("form.host.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("form.host.placeholder"),...v})}),e.jsx(D,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(g,{control:C.control,name:"port",render:({field:v})=>e.jsxs(f,{className:"flex-1",children:[e.jsxs(j,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(Ve,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(It,{children:e.jsx(ce,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.port.tooltip")})})})]})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(y,{children:e.jsx(T,{placeholder:s("form.port.placeholder"),...v})}),e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(P,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const M=v.value;M&&C.setValue("server_port",M)},children:e.jsx(Ve,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(ce,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"server_port",render:({field:v})=>e.jsxs(f,{className:"flex-1",children:[e.jsxs(j,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(Ve,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(It,{children:e.jsx(ce,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(y,{children:e.jsx(T,{placeholder:s("form.server_port.placeholder"),...v})}),e.jsx(D,{})]})})]})]}),n&&e.jsx(gx,{serverType:i,value:C.watch("protocol_settings"),onChange:v=>C.setValue("protocol_settings",v,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(g,{control:C.control,name:"parent_id",render:({field:v})=>e.jsxs(f,{children:[e.jsx(j,{children:s("form.parent.label")}),e.jsxs(G,{onValueChange:v.onChange,value:v.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("form.parent.none")}),w?.map(M=>e.jsx(z,{value:M.id.toString(),className:"cursor-pointer",children:M.name},M.id))]})]}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"route_ids",render:({field:v})=>e.jsxs(f,{children:[e.jsx(j,{children:s("form.route.label")}),e.jsx(y,{children:e.jsx(at,{options:c,onChange:M=>v.onChange(M.map(H=>H.value)),value:c?.filter(M=>v.value.includes(M.value)),placeholder:s("form.route.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.route.empty")})})}),e.jsx(D,{})]})})]}),e.jsxs(ze,{className:"mt-6",children:[e.jsx(P,{type:"button",variant:"outline",onClick:k,children:s("form.cancel")}),e.jsx(P,{type:"submit",onClick:p,children:s("form.submit")})]})]})]})]})}function un({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(qt,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:a.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:a.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(xs,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Ms,{children:[e.jsx(Ks,{placeholder:n}),e.jsxs(Fs,{children:[e.jsx(Bs,{children:"No results found."}),e.jsx(Ye,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(Me,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx($s,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{}),e.jsx(Ye,{children:e.jsx(Me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const bx=[{value:ie.Shadowsocks,label:Xe.find(s=>s.type===ie.Shadowsocks)?.label,color:qe[ie.Shadowsocks]},{value:ie.Vmess,label:Xe.find(s=>s.type===ie.Vmess)?.label,color:qe[ie.Vmess]},{value:ie.Trojan,label:Xe.find(s=>s.type===ie.Trojan)?.label,color:qe[ie.Trojan]},{value:ie.Hysteria,label:Xe.find(s=>s.type===ie.Hysteria)?.label,color:qe[ie.Hysteria]},{value:ie.Vless,label:Xe.find(s=>s.type===ie.Vless)?.label,color:qe[ie.Vless]},{value:ie.Tuic,label:Xe.find(s=>s.type===ie.Tuic)?.label,color:qe[ie.Tuic]},{value:ie.Socks,label:Xe.find(s=>s.type===ie.Socks)?.label,color:qe[ie.Socks]},{value:ie.Naive,label:Xe.find(s=>s.type===ie.Naive)?.label,color:qe[ie.Naive]},{value:ie.Http,label:Xe.find(s=>s.type===ie.Http)?.label,color:qe[ie.Http]},{value:ie.Mieru,label:Xe.find(s=>s.type===ie.Mieru)?.label,color:qe[ie.Mieru]}];function yx({table:s,saveOrder:n,isSortMode:t,groups:r}){const a=s.getState().columnFilters.length>0,{t:i}=V("server");return e.jsxs("div",{className:"flex items-center justify-between ",children:[e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[!t&&e.jsxs(e.Fragment,{children:[e.jsx(vx,{}),e.jsx(T,{placeholder:i("toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(un,{column:s.getColumn("type"),title:i("toolbar.type"),options:bx}),s.getColumn("group_ids")&&e.jsx(un,{column:s.getColumn("group_ids"),title:i("columns.groups.title"),options:r.map(l=>({label:l.name,value:l.id.toString()}))})]}),a&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[i("toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]}),t&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sort.tip")})})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{variant:t?"default":"outline",onClick:n,size:"sm",children:i(t?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const gt=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M15.71 12.71a6 6 0 1 0-7.42 0a10 10 0 0 0-6.22 8.18a1 1 0 0 0 2 .22a8 8 0 0 1 15.9 0a1 1 0 0 0 1 .89h.11a1 1 0 0 0 .88-1.1a10 10 0 0 0-6.25-8.19M12 12a4 4 0 1 1 4-4a4 4 0 0 1-4 4"})}),Ct={0:"bg-destructive/80 shadow-sm shadow-destructive/50",1:"bg-yellow-500/80 shadow-sm shadow-yellow-500/50",2:"bg-emerald-500/80 shadow-sm shadow-emerald-500/50"},Nx=s=>{const{t:n}=V("server");return[{id:"drag-handle",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Ht,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.nodeId")}),cell:({row:t})=>{const r=t.getValue("id"),a=t.original.code;return e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(q,{variant:"outline",className:N("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:qe[t.original.type]},children:[e.jsx(ur,{className:"size-3"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:a??r}),t.original.parent?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-muted-foreground/30",children:"→"}),e.jsx("span",{children:t.original.parent?.code||t.original.parent?.id})]}):""]})]}),e.jsx(P,{variant:"ghost",size:"icon",className:"size-5 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:text-muted-foreground group-hover/id:opacity-100",onClick:i=>{i.stopPropagation(),Ft(a||r.toString()).then(()=>{A.success(n("common:copy.success"))})},children:e.jsx(Xa,{className:"size-3"})})]})}),e.jsxs(ce,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[Xe.find(i=>i.type===t.original.type)?.label,t.original.parent_id?" (子节点)":""]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a?"点击括号内容或复制按钮可复制节点代码":"点击复制按钮可复制节点ID"})]})]})})},size:50,enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.show")}),cell:({row:t})=>{const[r,a]=u.useState(!!t.getValue("show"));return e.jsx(Y,{checked:r,onCheckedChange:async i=>{a(i),Ec({id:t.original.id,type:t.original.type,show:i?1:0}).catch(()=>{a(!i),s()})},style:{backgroundColor:r?qe[t.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(O,{column:t,title:n("columns.node"),tooltip:e.jsxs("div",{className:"grid grid-cols-1 gap-3 p-2",children:[e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",Ct[0])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.0")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",Ct[1])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.1")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",Ct[2])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.2")})]})]})})}),cell:({row:t})=>e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("size-2.5 flex-shrink-0 rounded-full transition-all duration-200",Ct[t.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:t.getValue("name")})]})}),e.jsx(ce,{children:e.jsx("p",{className:"font-medium",children:n(`columns.status.${t.original.available_status}`)})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.address")}),cell:({row:t})=>{const r=`${t.original.host}:${t.original.port}`,a=t.original.port!==t.original.server_port;return e.jsxs("div",{className:"group relative flex min-w-0 items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-1 gap-y-0.5 pr-7",children:[e.jsx("div",{className:"flex items-center ",children:e.jsxs("span",{className:"font-mono text-sm font-medium text-foreground/90",children:[t.original.host,":",t.original.port]})}),a&&e.jsxs("span",{className:"whitespace-nowrap text-[0.7rem] tracking-tight text-muted-foreground/40",children:["(",n("columns.internalPort")," ",t.original.server_port,")"]})]}),e.jsx("div",{className:"absolute right-0 top-0",children:e.jsx(ve,{delayDuration:0,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"icon",className:"size-6 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:bg-muted/50 hover:text-muted-foreground group-hover:opacity-100",onClick:i=>{i.stopPropagation(),Ft(r).then(()=>{A.success(n("common:copy.success"))})},children:e.jsx(Xa,{className:"size-3"})})}),e.jsx(ce,{side:"top",sideOffset:10,children:n("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.onlineUsers.title"),tooltip:n("columns.onlineUsers.tooltip")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(gt,{className:"size-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("online")})]}),size:80,enableSorting:!0,enableHiding:!0},{accessorKey:"rate",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.rate.title"),tooltip:n("columns.rate.tooltip")}),cell:({row:t})=>e.jsxs(q,{variant:"secondary",className:"font-medium",children:[t.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"group_ids",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.groups.title"),tooltip:n("columns.groups.tooltip")}),cell:({row:t})=>{const r=t.original.groups||[];return e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.map((a,i)=>e.jsx(q,{variant:"secondary",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:a.name},i)),r.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:n("columns.groups.empty")})]})},enableSorting:!1,filterFn:(t,r,a)=>{const i=t.getValue(r);return i?a.some(l=>i.includes(l)):!1}},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.type")}),cell:({row:t})=>{const r=t.getValue("type");return e.jsx(q,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:qe[r]},children:r})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingServer:a,setServerType:i}=Xr();return e.jsx("div",{className:"flex justify-center",children:e.jsxs(Ss,{modal:!1,children:[e.jsx(ks,{asChild:!0,children:e.jsx(P,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Vt,{className:"size-4"})})}),e.jsxs(fs,{align:"end",className:"w-40",children:[e.jsx(je,{className:"cursor-pointer",onClick:()=>{i(t.original.type),a(t.original),r(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(Ao,{className:"mr-2 size-4"}),n("columns.actions_dropdown.edit")]})}),e.jsxs(je,{className:"cursor-pointer",onClick:async()=>{Pc({id:t.original.id}).then(({data:l})=>{l&&(A.success(n("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx($o,{className:"mr-2 size-4"}),n("columns.actions_dropdown.copy")]}),e.jsx(tt,{}),e.jsx(je,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:l=>l.preventDefault(),children:e.jsx(Qe,{title:n("columns.actions_dropdown.delete.title"),description:n("columns.actions_dropdown.delete.description"),confirmText:n("columns.actions_dropdown.delete.confirm"),variant:"destructive",onConfirm:async()=>{Dc({id:t.original.id}).then(({data:l})=>{l&&(A.success(n("columns.actions_dropdown.delete_success")),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(cs,{className:"mr-2 size-4"}),n("columns.actions_dropdown.delete.confirm")]})})})]})]})})},size:50}]};function _x(){const[s,n]=u.useState({}),[t,r]=u.useState({"drag-handle":!1}),[a,i]=u.useState([]),[l,d]=u.useState({pageSize:500,pageIndex:0}),[m,o]=u.useState([]),[c,h]=u.useState(!1),[_,E]=u.useState({}),[C,S]=u.useState([]),{refetch:w}=re({queryKey:["nodeList"],queryFn:async()=>{const{data:H}=await Cr();return S(H),H}}),{data:b}=re({queryKey:["groups"],queryFn:async()=>{const{data:H}=await bt();return H}});u.useEffect(()=>{r({"drag-handle":c,show:!c,host:!c,online:!c,rate:!c,groups:!c,type:!1,actions:!c}),E({name:c?2e3:200}),d({pageSize:c?99999:500,pageIndex:0})},[c]);const k=(H,se)=>{c&&(H.dataTransfer.setData("text/plain",se.toString()),H.currentTarget.classList.add("opacity-50"))},p=(H,se)=>{if(!c)return;H.preventDefault(),H.currentTarget.classList.remove("bg-muted");const L=parseInt(H.dataTransfer.getData("text/plain"));if(L===se)return;const Z=[...C],[de]=Z.splice(L,1);Z.splice(se,0,de),S(Z)},v=async()=>{if(!c){h(!0);return}const H=C?.map((se,L)=>({id:se.id,order:L+1}));Rc(H).then(()=>{A.success("排序保存成功"),h(!1),w()}).finally(()=>{h(!1)})},M=ns({data:C||[],columns:Nx(w),state:{sorting:m,columnVisibility:t,rowSelection:s,columnFilters:a,columnSizing:_,pagination:l},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:E,onPaginationChange:d,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ex,{refetch:w,children:e.jsx("div",{className:"space-y-4",children:e.jsx(hs,{table:M,toolbar:H=>e.jsx(yx,{table:H,refetch:w,saveOrder:v,isSortMode:c,groups:b||[]}),draggable:c,onDragStart:k,onDragEnd:H=>H.currentTarget.classList.remove("opacity-50"),onDragOver:H=>{H.preventDefault(),H.currentTarget.classList.add("bg-muted")},onDragLeave:H=>H.currentTarget.classList.remove("bg-muted"),onDrop:p,showPagination:!c})})})}function wx(){const{t:s}=V("server");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("manage.title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("manage.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(_x,{})})]})]})}const Cx=Object.freeze(Object.defineProperty({__proto__:null,default:wx},Symbol.toStringTag,{value:"Module"}));function Sx({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=V("group");return e.jsx("div",{className:"flex items-center justify-between space-x-4",children:e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(ta,{refetch:n}),e.jsx(T,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:N("h-8 w-[150px] lg:w-[250px]",t&&"border-primary/50 ring-primary/20")}),t&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]})})}const kx=s=>{const{t:n}=V("group");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(q,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium",children:t.getValue("name")})})},{accessorKey:"users_count",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.usersCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(gt,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"server_count",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.serverCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(ur,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("server_count")})]}),enableSorting:!0,size:8e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(ta,{defaultValues:t.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(Qe,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Vc({id:t.original.id}).then(({data:r})=>{r&&(A.success(n("messages.updateSuccess")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("messages.deleteButton")})]})})]})}]};function Tx(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),{data:m,refetch:o,isLoading:c}=re({queryKey:["serverGroupList"],queryFn:async()=>{const{data:_}=await bt();return _}}),h=ns({data:m||[],columns:kx(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(hs,{table:h,toolbar:_=>e.jsx(Sx,{table:_,refetch:o}),isLoading:c})}function Dx(){const{t:s}=V("group");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Tx,{})})]})]})}const Px=Object.freeze(Object.defineProperty({__proto__:null,default:Dx},Symbol.toStringTag,{value:"Module"})),Ex=s=>x.object({remarks:x.string().min(1,s("form.validation.remarks")),match:x.array(x.string()),action:x.enum(["block","dns"]),action_value:x.string().optional()});function Zr({refetch:s,dialogTrigger:n,defaultValues:t={remarks:"",match:[],action:"block",action_value:""},type:r="add"}){const{t:a}=V("route"),i=ge({resolver:Ne(Ex(a)),defaultValues:t,mode:"onChange"}),[l,d]=u.useState(!1);return e.jsxs(be,{open:l,onOpenChange:d,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add")})]})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:a(r==="edit"?"form.edit":"form.create")}),e.jsx(Te,{})]}),e.jsxs(_e,{...i,children:[e.jsx(g,{control:i.control,name:"remarks",render:({field:m})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:a("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:a("form.remarksPlaceholder"),...m})})}),e.jsx(D,{})]})}),e.jsx(g,{control:i.control,name:"match",render:({field:m})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:a("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(ys,{className:"min-h-[120px]",placeholder:a("form.matchPlaceholder"),value:m.value.join(` +`).filter(Boolean);o.onChange(h),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.emailWhitelist.suffixes.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"recaptcha_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.recaptcha.enable.label")}),e.jsx(F,{children:s("safe.form.recaptcha.enable.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),a.watch("recaptcha_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:a.control,name:"recaptcha_site_key",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.recaptcha.siteKey.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.recaptcha.siteKey.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.recaptcha.siteKey.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"recaptcha_key",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.recaptcha.key.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.recaptcha.key.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.recaptcha.key.description")}),e.jsx(D,{})]})})]}),e.jsx(g,{control:a.control,name:"register_limit_by_ip_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.registerLimit.enable.label")}),e.jsx(F,{children:s("safe.form.registerLimit.enable.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),a.watch("register_limit_by_ip_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:a.control,name:"register_limit_count",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.registerLimit.count.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.registerLimit.count.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.registerLimit.count.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"register_limit_expire",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.registerLimit.expire.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.registerLimit.expire.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.registerLimit.expire.description")}),e.jsx(D,{})]})})]}),e.jsx(g,{control:a.control,name:"password_limit_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.passwordLimit.enable.label")}),e.jsx(F,{children:s("safe.form.passwordLimit.enable.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),a.watch("password_limit_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:a.control,name:"password_limit_count",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.passwordLimit.count.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.passwordLimit.count.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.passwordLimit.count.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"password_limit_expire",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.passwordLimit.expire.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("safe.form.passwordLimit.expire.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(F,{children:s("safe.form.passwordLimit.expire.description")}),e.jsx(D,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("safe.form.saving")})]})})}function Mu(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("safe.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("safe.description")})]}),e.jsx(ke,{}),e.jsx(Vu,{})]})}const Fu=Object.freeze(Object.defineProperty({__proto__:null,default:Mu},Symbol.toStringTag,{value:"Module"})),Ou=x.object({plan_change_enable:x.boolean().nullable().default(!1),reset_traffic_method:x.coerce.number().nullable().default(0),surplus_enable:x.boolean().nullable().default(!1),new_order_event_id:x.coerce.number().nullable().default(0),renew_order_event_id:x.coerce.number().nullable().default(0),change_order_event_id:x.coerce.number().nullable().default(0),show_info_to_server_enable:x.boolean().nullable().default(!1),show_protocol_to_server_enable:x.boolean().nullable().default(!1),default_remind_expire:x.boolean().nullable().default(!1),default_remind_traffic:x.boolean().nullable().default(!1),subscribe_path:x.string().nullable().default("s")}),Lu={plan_change_enable:!1,reset_traffic_method:0,surplus_enable:!1,new_order_event_id:0,renew_order_event_id:0,change_order_event_id:0,show_info_to_server_enable:!1,show_protocol_to_server_enable:!1,default_remind_expire:!1,default_remind_traffic:!1,subscribe_path:"s"};function zu(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(Ou),defaultValues:Lu,mode:"onBlur"}),{data:i}=re({queryKey:["settings","subscribe"],queryFn:()=>gs("subscribe")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:o=>{o.data&&A.success(s("common.autoSaved"))}});u.useEffect(()=>{if(i?.data?.subscribe){const o=i?.data?.subscribe;Object.entries(o).forEach(([c,h])=>{a.setValue(c,h)}),r.current=o}},[i]);const d=u.useCallback(Se.debounce(async o=>{if(!Se.isEqual(o,r.current)){t(!0);try{await l(o),r.current=o}finally{t(!1)}}},1e3),[l]),m=u.useCallback(o=>{d(o)},[d]);return u.useEffect(()=>{const o=a.watch(c=>{m(c)});return()=>o.unsubscribe()},[a.watch,m]),e.jsx(_e,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:a.control,name:"plan_change_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.plan_change_enable.title")}),e.jsx(F,{children:s("subscribe.plan_change_enable.description")}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"reset_traffic_method",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.reset_traffic_method.title")}),e.jsxs(G,{onValueChange:o.onChange,value:o.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:"请选择重置方式"})})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("subscribe.reset_traffic_method.options.monthly_first")}),e.jsx(z,{value:"1",children:s("subscribe.reset_traffic_method.options.monthly_reset")}),e.jsx(z,{value:"2",children:s("subscribe.reset_traffic_method.options.no_reset")}),e.jsx(z,{value:"3",children:s("subscribe.reset_traffic_method.options.yearly_first")}),e.jsx(z,{value:"4",children:s("subscribe.reset_traffic_method.options.yearly_reset")})]})]}),e.jsx(F,{children:s("subscribe.reset_traffic_method.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"surplus_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.surplus_enable.title")}),e.jsx(F,{children:s("subscribe.surplus_enable.description")}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"new_order_event_id",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.new_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(K,{children:e.jsx(W,{placeholder:"请选择"})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("subscribe.new_order_event.options.no_action")}),e.jsx(z,{value:"1",children:s("subscribe.new_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("subscribe.new_order_event.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"renew_order_event_id",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.renew_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(K,{children:e.jsx(W,{placeholder:"请选择"})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("subscribe.renew_order_event.options.no_action")}),e.jsx(z,{value:"1",children:s("subscribe.renew_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("subscribe.renew_order_event.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"change_order_event_id",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.change_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(K,{children:e.jsx(W,{placeholder:"请选择"})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("subscribe.change_order_event.options.no_action")}),e.jsx(z,{value:"1",children:s("subscribe.change_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("subscribe.change_order_event.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"subscribe_path",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.subscribe_path.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:"subscribe",...o,value:o.value||"",onChange:c=>{o.onChange(c),m(a.getValues())}})}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s("subscribe.subscribe_path.description"),e.jsx("br",{}),s("subscribe.subscribe_path.current_format",{path:o.value||"s"})]}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"show_info_to_server_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("subscribe.show_info_to_server.title")}),e.jsx(F,{children:s("subscribe.show_info_to_server.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"show_protocol_to_server_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("subscribe.show_protocol_to_server.title")}),e.jsx(F,{children:s("subscribe.show_protocol_to_server.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value||!1,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Au(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("subscribe.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe.description")})]}),e.jsx(ke,{}),e.jsx(zu,{})]})}const $u=Object.freeze(Object.defineProperty({__proto__:null,default:Au},Symbol.toStringTag,{value:"Module"})),Uu=x.object({invite_force:x.boolean().default(!1),invite_commission:x.coerce.string().default("0"),invite_gen_limit:x.coerce.string().default("0"),invite_never_expire:x.boolean().default(!1),commission_first_time_enable:x.boolean().default(!1),commission_auto_check_enable:x.boolean().default(!1),commission_withdraw_limit:x.coerce.string().default("0"),commission_withdraw_method:x.array(x.string()).default(["支付宝","USDT","Paypal"]),withdraw_close_enable:x.boolean().default(!1),commission_distribution_enable:x.boolean().default(!1),commission_distribution_l1:x.coerce.number().default(0),commission_distribution_l2:x.coerce.number().default(0),commission_distribution_l3:x.coerce.number().default(0)}),Hu={invite_force:!1,invite_commission:"0",invite_gen_limit:"0",invite_never_expire:!1,commission_first_time_enable:!1,commission_auto_check_enable:!1,commission_withdraw_limit:"0",commission_withdraw_method:["支付宝","USDT","Paypal"],withdraw_close_enable:!1,commission_distribution_enable:!1,commission_distribution_l1:0,commission_distribution_l2:0,commission_distribution_l3:0};function qu(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(Uu),defaultValues:Hu,mode:"onBlur"}),{data:i}=re({queryKey:["settings","invite"],queryFn:()=>gs("invite")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:o=>{o.data&&A.success(s("common.autoSaved"))}});u.useEffect(()=>{if(i?.data?.invite){const o=i?.data?.invite;Object.entries(o).forEach(([c,h])=>{typeof h=="number"?a.setValue(c,String(h)):a.setValue(c,h)}),r.current=o}},[i]);const d=u.useCallback(Se.debounce(async o=>{if(!Se.isEqual(o,r.current)){t(!0);try{await l(o),r.current=o}finally{t(!1)}}},1e3),[l]),m=u.useCallback(o=>{d(o)},[d]);return u.useEffect(()=>{const o=a.watch(c=>{m(c)});return()=>o.unsubscribe()},[a.watch,m]),e.jsx(_e,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:a.control,name:"invite_force",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.invite_force.title")}),e.jsx(F,{children:s("invite.invite_force.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"invite_commission",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("invite.invite_commission.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("invite.invite_commission.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("invite.invite_commission.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"invite_gen_limit",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("invite.invite_gen_limit.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("invite.invite_gen_limit.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("invite.invite_gen_limit.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"invite_never_expire",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.invite_never_expire.title")}),e.jsx(F,{children:s("invite.invite_never_expire.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"commission_first_time_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.commission_first_time.title")}),e.jsx(F,{children:s("invite.commission_first_time.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"commission_auto_check_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.commission_auto_check.title")}),e.jsx(F,{children:s("invite.commission_auto_check.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"commission_withdraw_limit",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("invite.commission_withdraw_limit.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("invite.commission_withdraw_limit.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("invite.commission_withdraw_limit.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"commission_withdraw_method",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("invite.commission_withdraw_method.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("invite.commission_withdraw_method.placeholder"),...o,value:Array.isArray(o.value)?o.value.join(","):"",onChange:c=>{const h=c.target.value.split(",").filter(Boolean);o.onChange(h),m(a.getValues())}})}),e.jsx(F,{children:s("invite.commission_withdraw_method.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"withdraw_close_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.withdraw_close.title")}),e.jsx(F,{children:s("invite.withdraw_close.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),e.jsx(g,{control:a.control,name:"commission_distribution_enable",render:({field:o})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.commission_distribution.title")}),e.jsx(F,{children:s("invite.commission_distribution.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:c=>{o.onChange(c),m(a.getValues())}})})]})}),a.watch("commission_distribution_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:a.control,name:"commission_distribution_l1",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:s("invite.commission_distribution.l1")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:c=>{const h=c.target.value?Number(c.target.value):0;o.onChange(h),m(a.getValues())}})}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"commission_distribution_l2",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:s("invite.commission_distribution.l2")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:c=>{const h=c.target.value?Number(c.target.value):0;o.onChange(h),m(a.getValues())}})}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"commission_distribution_l3",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:s("invite.commission_distribution.l3")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:c=>{const h=c.target.value?Number(c.target.value):0;o.onChange(h),m(a.getValues())}})}),e.jsx(D,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("invite.saving")})]})})}function Ku(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("invite.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("invite.description")})]}),e.jsx(ke,{}),e.jsx(qu,{})]})}const Bu=Object.freeze(Object.defineProperty({__proto__:null,default:Ku},Symbol.toStringTag,{value:"Module"})),Gu=x.object({frontend_theme:x.string().nullable(),frontend_theme_sidebar:x.string().nullable(),frontend_theme_header:x.string().nullable(),frontend_theme_color:x.string().nullable(),frontend_background_url:x.string().url().nullable()}),Wu={frontend_theme:"",frontend_theme_sidebar:"",frontend_theme_header:"",frontend_theme_color:"",frontend_background_url:""};function Yu(){const{data:s}=re({queryKey:["settings","frontend"],queryFn:()=>gs("frontend")}),n=ge({resolver:Ne(Gu),defaultValues:Wu,mode:"onChange"});u.useEffect(()=>{if(s?.data?.frontend){const r=s?.data?.frontend;Object.entries(r).forEach(([a,i])=>{n.setValue(a,i)})}},[s]);function t(r){js(r).then(({data:a})=>{a&&A.success("更新成功")})}return e.jsx(_e,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(t),className:"space-y-8",children:[e.jsx(g,{control:n.control,name:"frontend_theme_sidebar",render:({field:r})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:"边栏风格"}),e.jsx(F,{children:"边栏风格"})]}),e.jsx(y,{children:e.jsx(Y,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(g,{control:n.control,name:"frontend_theme_header",render:({field:r})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:"头部风格"}),e.jsx(F,{children:"边栏风格"})]}),e.jsx(y,{children:e.jsx(Y,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(g,{control:n.control,name:"frontend_theme_color",render:({field:r})=>e.jsxs(f,{children:[e.jsx(j,{children:"主题色"}),e.jsxs("div",{className:"relative w-max",children:[e.jsx(y,{children:e.jsxs("select",{className:N(nt({variant:"outline"}),"w-[200px] appearance-none font-normal"),...r,children:[e.jsx("option",{value:"default",children:"默认"}),e.jsx("option",{value:"black",children:"黑色"}),e.jsx("option",{value:"blackblue",children:"暗蓝色"}),e.jsx("option",{value:"green",children:"奶绿色"})]})}),e.jsx(Ta,{className:"absolute right-3 top-2.5 h-4 w-4 opacity-50"})]}),e.jsx(F,{children:"主题色"}),e.jsx(D,{})]})}),e.jsx(g,{control:n.control,name:"frontend_background_url",render:({field:r})=>e.jsxs(f,{children:[e.jsx(j,{children:"背景"}),e.jsx(y,{children:e.jsx(T,{placeholder:"请输入图片地址",...r})}),e.jsx(F,{children:"将会在后台登录页面进行展示。"}),e.jsx(D,{})]})}),e.jsx(P,{type:"submit",children:"保存设置"})]})})}function Qu(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"个性化设置"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自定义系统界面外观,包括主题风格、布局、颜色方案、背景图等个性化选项。"})]}),e.jsx(ke,{}),e.jsx(Yu,{})]})}const Ju=Object.freeze(Object.defineProperty({__proto__:null,default:Qu},Symbol.toStringTag,{value:"Module"})),Xu=x.object({server_pull_interval:x.coerce.number().nullable(),server_push_interval:x.coerce.number().nullable(),server_token:x.string().nullable(),device_limit_mode:x.coerce.number().nullable()}),Zu={server_pull_interval:0,server_push_interval:0,server_token:"",device_limit_mode:0};function em(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(Xu),defaultValues:Zu,mode:"onBlur"}),{data:i}=re({queryKey:["settings","server"],queryFn:()=>gs("server")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:c=>{c.data&&A.success(s("common.AutoSaved"))}});u.useEffect(()=>{if(i?.data.server){const c=i.data.server;Object.entries(c).forEach(([h,_])=>{a.setValue(h,_)}),r.current=c}},[i]);const d=u.useCallback(Se.debounce(async c=>{if(!Se.isEqual(c,r.current)){t(!0);try{await l(c),r.current=c}finally{t(!1)}}},1e3),[l]),m=u.useCallback(c=>{d(c)},[d]);u.useEffect(()=>{const c=a.watch(h=>{m(h)});return()=>c.unsubscribe()},[a.watch,m]);const o=()=>{const c=Math.floor(Math.random()*17)+16,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let _="";for(let E=0;Ee.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("server.server_token.title")}),e.jsx(y,{children:e.jsxs("div",{className:"relative",children:[e.jsx(T,{placeholder:s("server.server_token.placeholder"),...c,value:c.value||"",className:"pr-10"}),e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3 py-2",onClick:h=>{h.preventDefault(),o()},children:e.jsx(yo,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(ce,{children:e.jsx("p",{children:s("server.server_token.generate_tooltip")})})]})})]})}),e.jsx(F,{children:s("server.server_token.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"server_pull_interval",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("server.server_pull_interval.title")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("server.server_pull_interval.placeholder"),...c,value:c.value||"",onChange:h=>{const _=h.target.value?Number(h.target.value):null;c.onChange(_)}})}),e.jsx(F,{children:s("server.server_pull_interval.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"server_push_interval",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("server.server_push_interval.title")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("server.server_push_interval.placeholder"),...c,value:c.value||"",onChange:h=>{const _=h.target.value?Number(h.target.value):null;c.onChange(_)}})}),e.jsx(F,{children:s("server.server_push_interval.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"device_limit_mode",render:({field:c})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("server.device_limit_mode.title")}),e.jsxs(G,{onValueChange:c.onChange,value:c.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:s("server.device_limit_mode.placeholder")})})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("server.device_limit_mode.strict")}),e.jsx(z,{value:"1",children:s("server.device_limit_mode.relaxed")})]})]}),e.jsx(F,{children:s("server.device_limit_mode.description")}),e.jsx(D,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("server.saving")})]})})}function sm(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("server.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("server.description")})]}),e.jsx(ke,{}),e.jsx(em,{})]})}const tm=Object.freeze(Object.defineProperty({__proto__:null,default:sm},Symbol.toStringTag,{value:"Module"}));function am({open:s,onOpenChange:n,result:t}){const r=!t.error;return e.jsx(be,{open:s,onOpenChange:n,children:e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(tr,{className:"h-5 w-5 text-green-500"}):e.jsx(ar,{className:"h-5 w-5 text-destructive"}),e.jsx(ye,{children:r?"邮件发送成功":"邮件发送失败"})]}),e.jsx(Te,{children:r?"测试邮件已成功发送,请检查收件箱":"发送测试邮件时遇到错误"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"发送详情"}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2 text-sm",children:[e.jsx("div",{className:"text-muted-foreground",children:"收件地址"}),e.jsx("div",{children:t.email}),e.jsx("div",{className:"text-muted-foreground",children:"邮件主题"}),e.jsx("div",{children:t.subject}),e.jsx("div",{className:"text-muted-foreground",children:"模板名称"}),e.jsx("div",{children:t.template_name})]})]}),t.error&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium text-destructive",children:"错误信息"}),e.jsx("div",{className:"rounded-md bg-destructive/10 p-3 text-sm text-destructive break-all",children:t.error})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"配置信息"}),e.jsx(zs,{className:"h-[200px] rounded-md border p-4",children:e.jsx("div",{className:"grid gap-2 text-sm",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2",children:[e.jsx("div",{className:"text-muted-foreground",children:"驱动"}),e.jsx("div",{children:t.config.driver}),e.jsx("div",{className:"text-muted-foreground",children:"服务器"}),e.jsx("div",{children:t.config.host}),e.jsx("div",{className:"text-muted-foreground",children:"端口"}),e.jsx("div",{children:t.config.port}),e.jsx("div",{className:"text-muted-foreground",children:"加密方式"}),e.jsx("div",{children:t.config.encryption||"无"}),e.jsx("div",{className:"text-muted-foreground",children:"发件人"}),e.jsx("div",{children:t.config.from.address?`${t.config.from.address}${t.config.from.name?` (${t.config.from.name})`:""}`:"未设置"}),e.jsx("div",{className:"text-muted-foreground",children:"用户名"}),e.jsx("div",{children:t.config.username||"未设置"})]})})})]})]})]})})}const nm=x.object({email_template:x.string().nullable().default("classic"),email_host:x.string().nullable().default(""),email_port:x.coerce.number().nullable().default(465),email_username:x.string().nullable().default(""),email_password:x.string().nullable().default(""),email_encryption:x.string().nullable().default(""),email_from_address:x.string().email().nullable().default(""),remind_mail_enable:x.boolean().nullable().default(!1)});function rm(){const{t:s}=V("settings"),[n,t]=u.useState(null),[r,a]=u.useState(!1),i=u.useRef(null),[l,d]=u.useState(!1),m=ge({resolver:Ne(nm),defaultValues:{},mode:"onBlur"}),{data:o}=re({queryKey:["settings","email"],queryFn:()=>gs("email")}),{data:c}=re({queryKey:["emailTemplate"],queryFn:()=>vd()}),{mutateAsync:h}=es({mutationFn:js,onSuccess:w=>{w.data&&A.success(s("common.autoSaved"))}}),{mutate:_,isPending:E}=es({mutationFn:bd,onMutate:()=>{t(null),a(!1)},onSuccess:w=>{t(w.data),a(!0),w.data.error?A.error(s("email.test.error")):A.success(s("email.test.success"))}});u.useEffect(()=>{if(o?.data.email){const w=o.data.email;Object.entries(w).forEach(([b,k])=>{m.setValue(b,k)}),i.current=w}},[o]);const C=u.useCallback(Se.debounce(async w=>{if(!Se.isEqual(w,i.current)){d(!0);try{await h(w),i.current=w}finally{d(!1)}}},1e3),[h]),S=u.useCallback(w=>{C(w)},[C]);return u.useEffect(()=>{const w=m.watch(b=>{S(b)});return()=>w.unsubscribe()},[m.watch,S]),e.jsxs(e.Fragment,{children:[e.jsx(_e,{...m,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:m.control,name:"email_host",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_host.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(F,{children:s("email.email_host.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_port",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_port.title")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:s("common.placeholder"),...w,value:w.value||"",onChange:b=>{const k=b.target.value?Number(b.target.value):null;w.onChange(k)}})}),e.jsx(F,{children:s("email.email_port.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_encryption",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_encryption.title")}),e.jsxs(G,{onValueChange:w.onChange,value:w.value||"none",children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:"请选择加密方式"})})}),e.jsxs(B,{children:[e.jsx(z,{value:"none",children:s("email.email_encryption.none")}),e.jsx(z,{value:"ssl",children:s("email.email_encryption.ssl")}),e.jsx(z,{value:"tls",children:s("email.email_encryption.tls")})]})]}),e.jsx(F,{children:s("email.email_encryption.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_username",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_username.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(F,{children:s("email.email_username.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_password",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_password.title")}),e.jsx(y,{children:e.jsx(T,{type:"password",placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(F,{children:s("email.email_password.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_from_address",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_from.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(F,{children:s("email.email_from.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"email_template",render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("email.email_template.title")}),e.jsxs(G,{onValueChange:b=>{w.onChange(b),S(m.getValues())},value:w.value||void 0,children:[e.jsx(y,{children:e.jsx(K,{className:"w-[200px]",children:e.jsx(W,{placeholder:s("email.email_template.placeholder")})})}),e.jsx(B,{children:c?.data?.map(b=>e.jsx(z,{value:b,children:b},b))})]}),e.jsx(F,{children:s("email.email_template.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"remind_mail_enable",render:({field:w})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("email.remind_mail.title")}),e.jsx(F,{children:s("email.remind_mail.description")})]}),e.jsx(y,{children:e.jsx(Y,{checked:w.value||!1,onCheckedChange:b=>{w.onChange(b),S(m.getValues())}})})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(P,{onClick:()=>_(),loading:E,disabled:E,children:s(E?"email.test.sending":"email.test.title")})})]})}),l&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("saving")}),n&&e.jsx(am,{open:r,onOpenChange:a,result:n})]})}function lm(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("email.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("email.description")})]}),e.jsx(ke,{}),e.jsx(rm,{})]})}const im=Object.freeze(Object.defineProperty({__proto__:null,default:lm},Symbol.toStringTag,{value:"Module"})),om=x.object({telegram_bot_enable:x.boolean().nullable(),telegram_bot_token:x.string().nullable(),telegram_discuss_link:x.string().nullable()}),cm={telegram_bot_enable:!1,telegram_bot_token:"",telegram_discuss_link:""};function dm(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(om),defaultValues:cm,mode:"onBlur"}),{data:i}=re({queryKey:["settings","telegram"],queryFn:()=>gs("telegram")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:h=>{h.data&&A.success(s("common.autoSaved"))}}),{mutate:d,isPending:m}=es({mutationFn:yd,onSuccess:h=>{h.data&&A.success(s("telegram.webhook.success"))}});u.useEffect(()=>{if(i?.data.telegram){const h=i.data.telegram;Object.entries(h).forEach(([_,E])=>{a.setValue(_,E)}),r.current=h}},[i]);const o=u.useCallback(Se.debounce(async h=>{if(!Se.isEqual(h,r.current)){t(!0);try{await l(h),r.current=h}finally{t(!1)}}},1e3),[l]),c=u.useCallback(h=>{o(h)},[o]);return u.useEffect(()=>{const h=a.watch(_=>{c(_)});return()=>h.unsubscribe()},[a.watch,c]),e.jsx(_e,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:a.control,name:"telegram_bot_token",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("telegram.bot_token.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("telegram.bot_token.placeholder"),...h,value:h.value||""})}),e.jsx(F,{children:s("telegram.bot_token.description")}),e.jsx(D,{})]})}),a.watch("telegram_bot_token")&&e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("telegram.webhook.title")}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(P,{loading:m,disabled:m,onClick:()=>d(),children:s(m?"telegram.webhook.setting":"telegram.webhook.button")}),n&&e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.saving")})]}),e.jsx(F,{children:s("telegram.webhook.description")}),e.jsx(D,{})]}),e.jsx(g,{control:a.control,name:"telegram_bot_enable",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("telegram.bot_enable.title")}),e.jsx(F,{children:s("telegram.bot_enable.description")}),e.jsx(y,{children:e.jsx(Y,{checked:h.value||!1,onCheckedChange:_=>{h.onChange(_),c(a.getValues())}})}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"telegram_discuss_link",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("telegram.discuss_link.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("telegram.discuss_link.placeholder"),...h,value:h.value||""})}),e.jsx(F,{children:s("telegram.discuss_link.description")}),e.jsx(D,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function um(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("telegram.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("telegram.description")})]}),e.jsx(ke,{}),e.jsx(dm,{})]})}const mm=Object.freeze(Object.defineProperty({__proto__:null,default:um},Symbol.toStringTag,{value:"Module"})),xm=x.object({windows_version:x.string().nullable(),windows_download_url:x.string().nullable(),macos_version:x.string().nullable(),macos_download_url:x.string().nullable(),android_version:x.string().nullable(),android_download_url:x.string().nullable()}),hm={windows_version:"",windows_download_url:"",macos_version:"",macos_download_url:"",android_version:"",android_download_url:""};function pm(){const{t:s}=V("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=ge({resolver:Ne(xm),defaultValues:hm,mode:"onBlur"}),{data:i}=re({queryKey:["settings","app"],queryFn:()=>gs("app")}),{mutateAsync:l}=es({mutationFn:js,onSuccess:o=>{o.data&&A.success(s("app.save_success"))}});u.useEffect(()=>{if(i?.data.app){const o=i.data.app;Object.entries(o).forEach(([c,h])=>{a.setValue(c,h)}),r.current=o}},[i]);const d=u.useCallback(Se.debounce(async o=>{if(!Se.isEqual(o,r.current)){t(!0);try{await l(o),r.current=o}finally{t(!1)}}},1e3),[l]),m=u.useCallback(o=>{d(o)},[d]);return u.useEffect(()=>{const o=a.watch(c=>{m(c)});return()=>o.unsubscribe()},[a.watch,m]),e.jsx(_e,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:a.control,name:"windows_version",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.windows.version.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.windows.version.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"windows_download_url",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.windows.download.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.windows.download.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"macos_version",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.macos.version.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.macos.version.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"macos_download_url",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.macos.download.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.macos.download.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"android_version",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.android.version.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.android.version.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"android_download_url",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("app.android.download.title")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.android.download.description")}),e.jsx(D,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function fm(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("app.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("app.description")})]}),e.jsx(ke,{}),e.jsx(pm,{})]})}const gm=Object.freeze(Object.defineProperty({__proto__:null,default:fm},Symbol.toStringTag,{value:"Module"})),Ia=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:N("w-full caption-bottom text-sm",s),...n})}));Ia.displayName="Table";const Va=u.forwardRef(({className:s,...n},t)=>e.jsx("thead",{ref:t,className:N("[&_tr]:border-b",s),...n}));Va.displayName="TableHeader";const Ma=u.forwardRef(({className:s,...n},t)=>e.jsx("tbody",{ref:t,className:N("[&_tr:last-child]:border-0",s),...n}));Ma.displayName="TableBody";const jm=u.forwardRef(({className:s,...n},t)=>e.jsx("tfoot",{ref:t,className:N("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...n}));jm.displayName="TableFooter";const Is=u.forwardRef(({className:s,...n},t)=>e.jsx("tr",{ref:t,className:N("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...n}));Is.displayName="TableRow";const Fa=u.forwardRef(({className:s,...n},t)=>e.jsx("th",{ref:t,className:N("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));Fa.displayName="TableHead";const Zs=u.forwardRef(({className:s,...n},t)=>e.jsx("td",{ref:t,className:N("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));Zs.displayName="TableCell";const vm=u.forwardRef(({className:s,...n},t)=>e.jsx("caption",{ref:t,className:N("mt-4 text-sm text-muted-foreground",s),...n}));vm.displayName="TableCaption";function bm({table:s}){const[n,t]=u.useState(""),{t:r}=V("common");u.useEffect(()=>{t((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const a=i=>{const l=parseInt(i);!isNaN(l)&&l>=1&&l<=s.getPageCount()?s.setPageIndex(l-1):t((s.getState().pagination.pageIndex+1).toString())};return e.jsxs("div",{className:"flex flex-col-reverse gap-4 px-2 py-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"flex-1 text-sm text-muted-foreground",children:r("table.pagination.selected",{selected:s.getFilteredSelectedRowModel().rows.length,total:s.getFilteredRowModel().rows.length})}),e.jsxs("div",{className:"flex flex-col-reverse items-center gap-4 sm:flex-row sm:gap-6 lg:gap-8",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:r("table.pagination.itemsPerPage")}),e.jsxs(G,{value:`${s.getState().pagination.pageSize}`,onValueChange:i=>{s.setPageSize(Number(i))},children:[e.jsx(K,{className:"h-8 w-[70px]",children:e.jsx(W,{placeholder:s.getState().pagination.pageSize})}),e.jsx(B,{side:"top",children:[10,20,30,40,50,100,500].map(i=>e.jsx(z,{value:`${i}`,children:i},i))})]})]}),e.jsxs("div",{className:"flex items-center justify-center space-x-2 text-sm font-medium",children:[e.jsx("span",{children:r("table.pagination.page")}),e.jsx(T,{type:"text",value:n,onChange:i=>t(i.target.value),onBlur:i=>a(i.target.value),onKeyDown:i=>{i.key==="Enter"&&a(i.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsx("span",{children:r("table.pagination.pageOf",{total:s.getPageCount()})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(P,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(0),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.firstPage")}),e.jsx(No,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.previousPage")}),e.jsx(Zn,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.nextPage")}),e.jsx(Sa,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(s.getPageCount()-1),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.lastPage")}),e.jsx(_o,{className:"h-4 w-4"})]})]})]})]})}function hs({table:s,toolbar:n,draggable:t=!1,onDragStart:r,onDragEnd:a,onDragOver:i,onDragLeave:l,onDrop:d,showPagination:m=!0,isLoading:o=!1}){const{t:c}=V("common"),h=u.useRef(null),_=s.getAllColumns().filter(w=>w.getIsPinned()==="left"),E=s.getAllColumns().filter(w=>w.getIsPinned()==="right"),C=w=>_.slice(0,w).reduce((b,k)=>b+(k.getSize()??0),0),S=w=>E.slice(w+1).reduce((b,k)=>b+(k.getSize()??0),0);return e.jsxs("div",{className:"space-y-4",children:[typeof n=="function"?n(s):n,e.jsx("div",{ref:h,className:"relative overflow-auto rounded-md border bg-card",children:e.jsx("div",{className:"overflow-auto",children:e.jsxs(Ia,{children:[e.jsx(Va,{children:s.getHeaderGroups().map(w=>e.jsx(Is,{className:"hover:bg-transparent",children:w.headers.map((b,k)=>{const p=b.column.getIsPinned()==="left",v=b.column.getIsPinned()==="right",M=p?C(_.indexOf(b.column)):void 0,H=v?S(E.indexOf(b.column)):void 0;return e.jsx(Fa,{colSpan:b.colSpan,style:{width:b.getSize(),...p&&{left:M},...v&&{right:H}},className:N("h-11 bg-card px-4 text-muted-foreground",(p||v)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",p&&"before:right-0",v&&"before:left-0"]),children:b.isPlaceholder?null:Rt(b.column.columnDef.header,b.getContext())},b.id)})},w.id))}),e.jsx(Ma,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((w,b)=>e.jsx(Is,{"data-state":w.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:t,onDragStart:k=>r?.(k,b),onDragEnd:a,onDragOver:i,onDragLeave:l,onDrop:k=>d?.(k,b),children:w.getVisibleCells().map((k,p)=>{const v=k.column.getIsPinned()==="left",M=k.column.getIsPinned()==="right",H=v?C(_.indexOf(k.column)):void 0,se=M?S(E.indexOf(k.column)):void 0;return e.jsx(Zs,{style:{width:k.column.getSize(),...v&&{left:H},...M&&{right:se}},className:N("bg-card",(v||M)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",v&&"before:right-0",M&&"before:left-0"]),children:Rt(k.column.columnDef.cell,k.getContext())},k.id)})},w.id)):e.jsx(Is,{children:e.jsx(Zs,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:c("table.noData")})})})]})})}),m&&e.jsx(bm,{table:s})]})}const ym=s=>x.object({id:x.number().nullable(),name:x.string().min(2,s("form.validation.name.min")).max(30,s("form.validation.name.max")),icon:x.string().optional().nullable(),notify_domain:x.string().refine(t=>!t||/^https?:\/\/\S+/.test(t),s("form.validation.notify_domain.url")).optional().nullable(),handling_fee_fixed:x.coerce.number().min(0).optional().nullable(),handling_fee_percent:x.coerce.number().min(0).max(100).optional().nullable(),payment:x.string().min(1,s("form.validation.payment.required")),config:x.record(x.string(),x.string())}),on={id:null,name:"",icon:"",notify_domain:"",handling_fee_fixed:0,handling_fee_percent:0,payment:"",config:{}};function qr({refetch:s,dialogTrigger:n,type:t="add",defaultFormValues:r=on}){const{t:a}=V("payment"),[i,l]=u.useState(!1),[d,m]=u.useState(!1),[o,c]=u.useState([]),[h,_]=u.useState([]),E=ym(a),C=ge({resolver:Ne(E),defaultValues:r,mode:"onChange"}),S=C.watch("payment");u.useEffect(()=>{i&&(async()=>{const{data:k}=await Lc();c(k)})()},[i]),u.useEffect(()=>{if(!S||!i)return;(async()=>{const k={payment:S,...t==="edit"&&{id:Number(C.getValues("id"))}};zc(k).then(({data:p})=>{_(p);const v=p.reduce((M,H)=>(H.field_name&&(M[H.field_name]=H.value??""),M),{});C.setValue("config",v)})})()},[S,i,C,t]);const w=async b=>{m(!0);try{(await Ac(b)).data&&(A.success(a("form.messages.success")),C.reset(on),s(),l(!1))}finally{m(!1)}};return e.jsxs(be,{open:i,onOpenChange:l,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add.button")})]})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsx(Ce,{children:e.jsx(ye,{children:a(t==="add"?"form.add.title":"form.edit.title")})}),e.jsx(_e,{...C,children:e.jsxs("form",{onSubmit:C.handleSubmit(w),className:"space-y-4",children:[e.jsx(g,{control:C.control,name:"name",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:a("form.fields.name.placeholder"),...b})}),e.jsx(F,{children:a("form.fields.name.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"icon",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.icon.label")}),e.jsx(y,{children:e.jsx(T,{...b,value:b.value||"",placeholder:a("form.fields.icon.placeholder")})}),e.jsx(F,{children:a("form.fields.icon.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"notify_domain",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.notify_domain.label")}),e.jsx(y,{children:e.jsx(T,{...b,value:b.value||"",placeholder:a("form.fields.notify_domain.placeholder")})}),e.jsx(F,{children:a("form.fields.notify_domain.description")}),e.jsx(D,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:C.control,name:"handling_fee_percent",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.handling_fee_percent.label")}),e.jsx(y,{children:e.jsx(T,{type:"number",...b,value:b.value||"",placeholder:a("form.fields.handling_fee_percent.placeholder")})}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"handling_fee_fixed",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.handling_fee_fixed.label")}),e.jsx(y,{children:e.jsx(T,{type:"number",...b,value:b.value||"",placeholder:a("form.fields.handling_fee_fixed.placeholder")})}),e.jsx(D,{})]})})]}),e.jsx(g,{control:C.control,name:"payment",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.payment.label")}),e.jsxs(G,{onValueChange:b.onChange,defaultValue:b.value,children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:a("form.fields.payment.placeholder")})})}),e.jsx(B,{children:o.map(k=>e.jsx(z,{value:k,children:k},k))})]}),e.jsx(F,{children:a("form.fields.payment.description")}),e.jsx(D,{})]})}),h.length>0&&e.jsx("div",{className:"space-y-4",children:h.map(b=>e.jsx(g,{control:C.control,name:`config.${b.field_name}`,render:({field:k})=>e.jsxs(f,{children:[e.jsx(j,{children:b.label}),e.jsx(y,{children:e.jsx(T,{...k,value:k.value||""})}),e.jsx(D,{})]})},b.field_name))}),e.jsxs(ze,{children:[e.jsx(yt,{asChild:!0,children:e.jsx(P,{type:"button",variant:"outline",children:a("form.buttons.cancel")})}),e.jsx(P,{type:"submit",disabled:d,children:a("form.buttons.submit")})]})]})})]})]})}function O({column:s,title:n,tooltip:t,className:r}){return s.getCanSort()?e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(P,{variant:"ghost",size:"default",className:N("-ml-3 flex h-8 items-center gap-2 text-nowrap font-medium hover:bg-muted/60",r),onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[e.jsx("span",{children:n}),t&&e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(Qa,{className:"h-4 w-4 cursor-pointer text-muted-foreground"})}),e.jsx(ce,{children:t})]})}),s.getIsSorted()==="asc"?e.jsx(pa,{className:"h-4 w-4 text-foreground/70"}):s.getIsSorted()==="desc"?e.jsx(fa,{className:"h-4 w-4 text-foreground/70"}):e.jsx(wo,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-foreground/70"})]})})}):e.jsxs("div",{className:N("flex items-center space-x-1 text-nowrap py-2 font-medium text-muted-foreground",r),children:[e.jsx("span",{children:n}),t&&e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{children:e.jsx(Qa,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(ce,{children:t})]})})]})}const Oa=Co,Kr=So,Nm=ko,Br=u.forwardRef(({className:s,...n},t)=>e.jsx(rr,{className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:t}));Br.displayName=rr.displayName;const Yt=u.forwardRef(({className:s,...n},t)=>e.jsxs(Nm,{children:[e.jsx(Br,{}),e.jsx(lr,{ref:t,className:N("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...n})]}));Yt.displayName=lr.displayName;const Qt=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-2 text-center sm:text-left",s),...n});Qt.displayName="AlertDialogHeader";const Jt=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Jt.displayName="AlertDialogFooter";const Xt=u.forwardRef(({className:s,...n},t)=>e.jsx(ir,{ref:t,className:N("text-lg font-semibold",s),...n}));Xt.displayName=ir.displayName;const Zt=u.forwardRef(({className:s,...n},t)=>e.jsx(or,{ref:t,className:N("text-sm text-muted-foreground",s),...n}));Zt.displayName=or.displayName;const ea=u.forwardRef(({className:s,...n},t)=>e.jsx(cr,{ref:t,className:N(st(),s),...n}));ea.displayName=cr.displayName;const sa=u.forwardRef(({className:s,...n},t)=>e.jsx(dr,{ref:t,className:N(st({variant:"outline"}),"mt-2 sm:mt-0",s),...n}));sa.displayName=dr.displayName;function Qe({onConfirm:s,children:n,title:t="确认操作",description:r="确定要执行此操作吗?",cancelText:a="取消",confirmText:i="确认",variant:l="default",className:d}){return e.jsxs(Oa,{children:[e.jsx(Kr,{asChild:!0,children:n}),e.jsxs(Yt,{className:N("sm:max-w-[425px]",d),children:[e.jsxs(Qt,{children:[e.jsx(Xt,{children:t}),e.jsx(Zt,{children:r})]}),e.jsxs(Jt,{children:[e.jsx(sa,{asChild:!0,children:e.jsx(P,{variant:"outline",children:a})}),e.jsx(ea,{asChild:!0,children:e.jsx(P,{variant:l,onClick:s,children:i})})]})]})]})}const Gr=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M11.29 15.29a2 2 0 0 0-.12.15a.8.8 0 0 0-.09.18a.6.6 0 0 0-.06.18a1.4 1.4 0 0 0 0 .2a.84.84 0 0 0 .08.38a.9.9 0 0 0 .54.54a.94.94 0 0 0 .76 0a.9.9 0 0 0 .54-.54A1 1 0 0 0 13 16a1 1 0 0 0-.29-.71a1 1 0 0 0-1.42 0M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2m0 18a8 8 0 1 1 8-8a8 8 0 0 1-8 8m0-13a3 3 0 0 0-2.6 1.5a1 1 0 1 0 1.73 1A1 1 0 0 1 12 9a1 1 0 0 1 0 2a1 1 0 0 0-1 1v1a1 1 0 0 0 2 0v-.18A3 3 0 0 0 12 7"})}),_m=({refetch:s,isSortMode:n=!1})=>{const{t}=V("payment");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(Ht,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.id")}),cell:({row:r})=>e.jsx(q,{variant:"outline",children:r.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"enable",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.enable")}),cell:({row:r})=>e.jsx(Y,{defaultChecked:r.getValue("enable"),onCheckedChange:async()=>{const{data:a}=await Uc({id:r.original.id});a||s()}}),enableSorting:!1,size:100},{accessorKey:"name",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.name")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r.getValue("name")})}),enableSorting:!1,size:200},{accessorKey:"payment",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.payment")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r.getValue("payment")})}),enableSorting:!1,size:200},{accessorKey:"notify_url",header:({column:r})=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(O,{column:r,title:t("table.columns.notify_url")}),e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{className:"ml-1",children:e.jsx(Gr,{className:"h-4 w-4"})}),e.jsx(ce,{children:t("table.columns.notify_url_tooltip")})]})})]}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[300px] truncate font-medium",children:r.getValue("notify_url")})}),enableSorting:!1,size:3e3},{id:"actions",header:({column:r})=>e.jsx(O,{className:"justify-end",column:r,title:t("table.columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(qr,{refetch:s,dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:t("table.actions.edit")})]}),type:"edit",defaultFormValues:r.original}),e.jsx(Qe,{title:t("table.actions.delete.title"),description:t("table.actions.delete.description"),onConfirm:async()=>{const{data:a}=await $c({id:r.original.id});a&&s()},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-destructive"}),e.jsx("span",{className:"sr-only",children:t("table.actions.delete.title")})]})})]}),size:100}]};function wm({table:s,refetch:n,saveOrder:t,isSortMode:r}){const{t:a}=V("payment"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:a("table.toolbar.sort.hint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qr,{refetch:n}),e.jsx(T,{placeholder:a("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),i&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[a("table.toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{variant:r?"default":"outline",onClick:t,size:"sm",children:a(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}function Cm(){const[s,n]=u.useState([]),[t,r]=u.useState([]),[a,i]=u.useState(!1),[l,d]=u.useState([]),[m,o]=u.useState({"drag-handle":!1}),[c,h]=u.useState({pageSize:20,pageIndex:0}),{refetch:_}=re({queryKey:["paymentList"],queryFn:async()=>{const{data:b}=await Oc();return d(b?.map(k=>({...k,enable:!!k.enable}))||[]),b}});u.useEffect(()=>{o({"drag-handle":a,actions:!a}),h({pageSize:a?99999:10,pageIndex:0})},[a]);const E=(b,k)=>{a&&(b.dataTransfer.setData("text/plain",k.toString()),b.currentTarget.classList.add("opacity-50"))},C=(b,k)=>{if(!a)return;b.preventDefault(),b.currentTarget.classList.remove("bg-muted");const p=parseInt(b.dataTransfer.getData("text/plain"));if(p===k)return;const v=[...l],[M]=v.splice(p,1);v.splice(k,0,M),d(v)},S=async()=>{a?Hc({ids:l.map(b=>b.id)}).then(()=>{_(),i(!1),A.success("排序保存成功")}):i(!0)},w=ns({data:l,columns:_m({refetch:_,isSortMode:a}),state:{sorting:t,columnFilters:s,columnVisibility:m,pagination:c},onSortingChange:r,onColumnFiltersChange:n,onColumnVisibilityChange:o,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),initialState:{columnPinning:{right:["actions"]}},pageCount:a?1:void 0});return e.jsx(hs,{table:w,toolbar:b=>e.jsx(wm,{table:b,refetch:_,saveOrder:S,isSortMode:a}),draggable:a,onDragStart:E,onDragEnd:b=>b.currentTarget.classList.remove("opacity-50"),onDragOver:b=>{b.preventDefault(),b.currentTarget.classList.add("bg-muted")},onDragLeave:b=>b.currentTarget.classList.remove("bg-muted"),onDrop:C,showPagination:!a})}function Sm(){const{t:s}=V("payment");return e.jsxs(Ee,{children:[e.jsxs(Re,{className:"flex items-center justify-between",children:[e.jsx(Ke,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{children:[e.jsx("header",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("section",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Cm,{})})]})]})}const km=Object.freeze(Object.defineProperty({__proto__:null,default:Sm},Symbol.toStringTag,{value:"Module"}));function Tm({pluginName:s,onClose:n,onSuccess:t}){const{t:r}=V("plugin"),[a,i]=u.useState(!0),[l,d]=u.useState(!1),[m,o]=u.useState(null),c=To({config:Do(Po())}),h=ge({resolver:Ne(c),defaultValues:{config:{}}});u.useEffect(()=>{(async()=>{try{const{data:S}=await _s.getPluginConfig(s);o(S),h.reset({config:Object.fromEntries(Object.entries(S).map(([w,b])=>[w,b.value]))})}catch{A.error(r("messages.configLoadError"))}finally{i(!1)}})()},[s]);const _=async C=>{d(!0);try{await _s.updatePluginConfig(s,C.config),A.success(r("messages.configSaveSuccess")),t()}catch{A.error(r("messages.configSaveError"))}finally{d(!1)}},E=(C,S)=>{switch(S.type){case"string":return e.jsx(g,{control:h.control,name:`config.${C}`,render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{children:S.label||S.description}),e.jsx(y,{children:e.jsx(T,{placeholder:S.placeholder,...w})}),S.description&&S.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.description}),e.jsx(D,{})]})},C);case"number":case"percentage":return e.jsx(g,{control:h.control,name:`config.${C}`,render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{children:S.label||S.description}),e.jsx(y,{children:e.jsxs("div",{className:"relative",children:[e.jsx(T,{type:"number",placeholder:S.placeholder,...w,onChange:b=>{const k=Number(b.target.value);S.type==="percentage"?w.onChange(Math.min(100,Math.max(0,k))):w.onChange(k)},className:S.type==="percentage"?"pr-8":"",min:S.type==="percentage"?0:void 0,max:S.type==="percentage"?100:void 0,step:S.type==="percentage"?1:void 0}),S.type==="percentage"&&e.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3",children:e.jsx(Eo,{className:"h-4 w-4 text-muted-foreground"})})]})}),S.description&&S.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.description}),e.jsx(D,{})]})},C);case"select":return e.jsx(g,{control:h.control,name:`config.${C}`,render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{children:S.label||S.description}),e.jsxs(G,{onValueChange:w.onChange,defaultValue:w.value,children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:S.placeholder})})}),e.jsx(B,{children:S.options?.map(b=>e.jsx(z,{value:b.value,children:b.label},b.value))})]}),S.description&&S.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.description}),e.jsx(D,{})]})},C);case"boolean":return e.jsx(g,{control:h.control,name:`config.${C}`,render:({field:w})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:S.label||S.description}),S.description&&S.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.description})]}),e.jsx(y,{children:e.jsx(Y,{checked:w.value,onCheckedChange:w.onChange})})]})},C);case"text":return e.jsx(g,{control:h.control,name:`config.${C}`,render:({field:w})=>e.jsxs(f,{children:[e.jsx(j,{children:S.label||S.description}),e.jsx(y,{children:e.jsx(ys,{placeholder:S.placeholder,...w})}),S.description&&S.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.description}),e.jsx(D,{})]})},C);default:return null}};return a?e.jsxs("div",{className:"space-y-4",children:[e.jsx(oe,{className:"h-4 w-[200px]"}),e.jsx(oe,{className:"h-10 w-full"}),e.jsx(oe,{className:"h-4 w-[200px]"}),e.jsx(oe,{className:"h-10 w-full"})]}):e.jsx(_e,{...h,children:e.jsxs("form",{onSubmit:h.handleSubmit(_),className:"space-y-4",children:[m&&Object.entries(m).map(([C,S])=>E(C,S)),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(P,{type:"button",variant:"outline",onClick:n,disabled:l,children:r("config.cancel")}),e.jsx(P,{type:"submit",loading:l,disabled:l,children:r("config.save")})]})]})})}function Dm(){const{t:s}=V("plugin"),[n,t]=u.useState(null),[r,a]=u.useState(!1),[i,l]=u.useState(null),[d,m]=u.useState(""),[o,c]=u.useState("all"),[h,_]=u.useState(!1),[E,C]=u.useState(!1),[S,w]=u.useState(!1),b=u.useRef(null),{data:k,isLoading:p,refetch:v}=re({queryKey:["pluginList"],queryFn:async()=>{const{data:R}=await _s.getPluginList();return R}});k&&[...new Set(k.map(R=>R.category||"other"))];const M=k?.filter(R=>{const X=R.name.toLowerCase().includes(d.toLowerCase())||R.description.toLowerCase().includes(d.toLowerCase())||R.code.toLowerCase().includes(d.toLowerCase()),Ns=o==="all"||R.category===o;return X&&Ns}),H=async R=>{t(R),_s.installPlugin(R).then(()=>{A.success(s("messages.installSuccess")),v()}).catch(X=>{A.error(X.message||s("messages.installError"))}).finally(()=>{t(null)})},se=async R=>{t(R),_s.uninstallPlugin(R).then(()=>{A.success(s("messages.uninstallSuccess")),v()}).catch(X=>{A.error(X.message||s("messages.uninstallError"))}).finally(()=>{t(null)})},L=async(R,X)=>{t(R),(X?_s.disablePlugin:_s.enablePlugin)(R).then(()=>{A.success(s(X?"messages.disableSuccess":"messages.enableSuccess")),v()}).catch(De=>{A.error(De.message||s(X?"messages.disableError":"messages.enableError"))}).finally(()=>{t(null)})},Z=R=>{k?.find(X=>X.code===R),l(R),a(!0)},de=async R=>{if(!R.name.endsWith(".zip")){A.error(s("upload.error.format"));return}_(!0),_s.uploadPlugin(R).then(()=>{A.success(s("messages.uploadSuccess")),C(!1),v()}).catch(X=>{A.error(X.message||s("messages.uploadError"))}).finally(()=>{_(!1),b.current&&(b.current.value="")})},Q=R=>{R.preventDefault(),R.stopPropagation(),R.type==="dragenter"||R.type==="dragover"?w(!0):R.type==="dragleave"&&w(!1)},te=R=>{R.preventDefault(),R.stopPropagation(),w(!1),R.dataTransfer.files&&R.dataTransfer.files[0]&&de(R.dataTransfer.files[0])},$=async R=>{t(R),_s.deletePlugin(R).then(()=>{A.success(s("messages.deleteSuccess")),v()}).catch(X=>{A.error(X.message||s("messages.deleteError"))}).finally(()=>{t(null)})};return e.jsxs(Ee,{children:[e.jsxs(Re,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(ka,{className:"h-6 w-6"}),e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("title")})]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{children:[e.jsxs("div",{className:"mb-8 space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"relative max-w-sm flex-1",children:[e.jsx(An,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(T,{placeholder:s("search.placeholder"),value:d,onChange:R=>m(R.target.value),className:"pl-9"})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs(P,{onClick:()=>C(!0),variant:"outline",className:"shrink-0",size:"sm",children:[e.jsx(pt,{className:"mr-2 h-4 w-4"}),s("upload.button")]})})]}),e.jsxs(Gt,{defaultValue:"all",className:"w-full",children:[e.jsxs(vt,{children:[e.jsx(Ge,{value:"all",children:s("tabs.all")}),e.jsx(Ge,{value:"installed",children:s("tabs.installed")}),e.jsx(Ge,{value:"available",children:s("tabs.available")})]}),e.jsx(ws,{value:"all",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:p?e.jsxs(e.Fragment,{children:[e.jsx(oa,{}),e.jsx(oa,{}),e.jsx(oa,{})]}):M?.map(R=>e.jsx(ia,{plugin:R,onInstall:H,onUninstall:se,onToggleEnable:L,onOpenConfig:Z,onDelete:$,isLoading:n===R.name},R.name))})}),e.jsx(ws,{value:"installed",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:M?.filter(R=>R.is_installed).map(R=>e.jsx(ia,{plugin:R,onInstall:H,onUninstall:se,onToggleEnable:L,onOpenConfig:Z,onDelete:$,isLoading:n===R.name},R.name))})}),e.jsx(ws,{value:"available",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:M?.filter(R=>!R.is_installed).map(R=>e.jsx(ia,{plugin:R,onInstall:H,onUninstall:se,onToggleEnable:L,onOpenConfig:Z,onDelete:$,isLoading:n===R.name},R.code))})})]})]}),e.jsx(be,{open:r,onOpenChange:a,children:e.jsxs(fe,{className:"sm:max-w-lg",children:[e.jsxs(Ce,{children:[e.jsxs(ye,{children:[k?.find(R=>R.code===i)?.name," ",s("config.title")]}),e.jsx(Te,{children:s("config.description")})]}),i&&e.jsx(Tm,{pluginName:i,onClose:()=>a(!1),onSuccess:()=>{a(!1),v()}})]})}),e.jsx(be,{open:E,onOpenChange:C,children:e.jsxs(fe,{className:"sm:max-w-md",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:s("upload.title")}),e.jsx(Te,{children:s("upload.description")})]}),e.jsxs("div",{className:N("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",S&&"border-primary/50 bg-muted/50"),onDragEnter:Q,onDragLeave:Q,onDragOver:Q,onDrop:te,children:[e.jsx("input",{type:"file",ref:b,className:"hidden",accept:".zip",onChange:R=>{const X=R.target.files?.[0];X&&de(X)}}),h?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(pt,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[s("upload.dragText")," ",e.jsx("button",{type:"button",onClick:()=>b.current?.click(),className:"mx-1 text-primary hover:underline",children:s("upload.clickText")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("upload.supportText")})]})]})})]})]})})]})]})}function ia({plugin:s,onInstall:n,onUninstall:t,onToggleEnable:r,onOpenConfig:a,onDelete:i,isLoading:l}){const{t:d}=V("plugin");return e.jsxs(We,{className:"group relative overflow-hidden transition-all hover:shadow-md",children:[e.jsxs(ts,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Cs,{children:s.name}),s.is_installed&&e.jsx(q,{variant:s.is_enabled?"success":"secondary",children:s.is_enabled?d("status.enabled"):d("status.disabled")})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ka,{className:"h-4 w-4"}),e.jsx("code",{className:"rounded bg-muted px-1 py-0.5",children:s.code})]}),e.jsxs("div",{children:["v",s.version]})]})]})}),e.jsx(et,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"mt-2",children:s.description}),e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1",children:[d("author"),": ",s.author]})})]})})]}),e.jsx(as,{children:e.jsx("div",{className:"flex items-center justify-end space-x-2",children:s.is_installed?e.jsxs(e.Fragment,{children:[e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>a(s.code),disabled:!s.is_enabled||l,children:[e.jsx(Ro,{className:"mr-2 h-4 w-4"}),d("button.config")]}),e.jsxs(P,{variant:s.is_enabled?"destructive":"default",size:"sm",onClick:()=>r(s.code,s.is_enabled),disabled:l,children:[e.jsx(Io,{className:"mr-2 h-4 w-4"}),s.is_enabled?d("button.disable"):d("button.enable")]}),e.jsx(Qe,{title:d("uninstall.title"),description:d("uninstall.description"),cancelText:d("common:cancel"),confirmText:d("uninstall.button"),variant:"destructive",onConfirm:()=>t(s.code),children:e.jsxs(P,{variant:"outline",size:"sm",className:"text-muted-foreground hover:text-destructive",disabled:l,children:[e.jsx(cs,{className:"mr-2 h-4 w-4"}),d("button.uninstall")]})})]}):e.jsxs(e.Fragment,{children:[e.jsx(P,{onClick:()=>n(s.code),disabled:l,loading:l,children:d("button.install")}),e.jsx(Qe,{title:d("delete.title"),description:d("delete.description"),cancelText:d("common:cancel"),confirmText:d("delete.button"),variant:"destructive",onConfirm:()=>i(s.code),children:e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",disabled:l,children:e.jsx(cs,{className:"h-4 w-4"})})})]})})})]})}function oa(){return e.jsxs(We,{children:[e.jsxs(ts,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"h-6 w-[200px]"}),e.jsx(oe,{className:"h-6 w-[80px]"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(oe,{className:"h-5 w-[120px]"}),e.jsx(oe,{className:"h-5 w-[60px]"})]})]})}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx(oe,{className:"h-4 w-[300px]"}),e.jsx(oe,{className:"h-4 w-[150px]"})]})]}),e.jsx(as,{children:e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(oe,{className:"h-9 w-[100px]"}),e.jsx(oe,{className:"h-9 w-[100px]"}),e.jsx(oe,{className:"h-8 w-8"})]})})]})}const Pm=Object.freeze(Object.defineProperty({__proto__:null,default:Dm},Symbol.toStringTag,{value:"Module"})),Em=(s,n)=>{let t=null;switch(s.field_type){case"input":t=e.jsx(T,{placeholder:s.placeholder,...n});break;case"textarea":t=e.jsx(ys,{placeholder:s.placeholder,...n});break;case"select":t=e.jsx("select",{className:N(st({variant:"outline"}),"w-full appearance-none font-normal"),...n,children:s.select_options&&Object.keys(s.select_options).map(r=>e.jsx("option",{value:r,children:s.select_options?.[r]},r))});break;default:t=null;break}return t};function Rm({themeKey:s,themeInfo:n}){const{t}=V("theme"),[r,a]=u.useState(!1),[i,l]=u.useState(!1),[d,m]=u.useState(!1),o=ge({defaultValues:n.configs.reduce((_,E)=>(_[E.field_name]="",_),{})}),c=async()=>{l(!0),_c(s).then(({data:_})=>{Object.entries(_).forEach(([E,C])=>{o.setValue(E,C)})}).finally(()=>{l(!1)})},h=async _=>{m(!0),wc(s,_).then(()=>{A.success(t("config.success")),a(!1)}).finally(()=>{m(!1)})};return e.jsxs(be,{open:r,onOpenChange:_=>{a(_),_?c():o.reset()},children:[e.jsx(Je,{asChild:!0,children:e.jsx(P,{variant:"outline",children:t("card.configureTheme")})}),e.jsxs(fe,{className:"max-h-[90vh] overflow-auto sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:t("config.title",{name:n.name})}),e.jsx(Te,{children:t("config.description")})]}),i?e.jsx("div",{className:"flex h-40 items-center justify-center",children:e.jsx(Da,{className:"h-6 w-6 animate-spin"})}):e.jsx(_e,{...o,children:e.jsxs("form",{onSubmit:o.handleSubmit(h),className:"space-y-4",children:[n.configs.map(_=>e.jsx(g,{control:o.control,name:_.field_name,render:({field:E})=>e.jsxs(f,{children:[e.jsx(j,{children:_.label}),e.jsx(y,{children:Em(_,E)}),e.jsx(D,{})]})},_.field_name)),e.jsxs(ze,{className:"mt-6 gap-2",children:[e.jsx(P,{type:"button",variant:"secondary",onClick:()=>a(!1),children:t("config.cancel")}),e.jsx(P,{type:"submit",loading:d,children:t("config.save")})]})]})})]})]})}function Im(){const{t:s}=V("theme"),[n,t]=u.useState(null),[r,a]=u.useState(!1),[i,l]=u.useState(!1),[d,m]=u.useState(!1),[o,c]=u.useState(null),h=u.useRef(null),[_,E]=u.useState(0),{data:C,isLoading:S,refetch:w}=re({queryKey:["themeList"],queryFn:async()=>{const{data:L}=await Nc();return L}}),b=async L=>{t(L),kc({frontend_theme:L}).then(()=>{A.success("主题切换成功"),w()}).finally(()=>{t(null)})},k=async L=>{if(!L.name.endsWith(".zip")){A.error(s("upload.error.format"));return}a(!0),Cc(L).then(()=>{A.success("主题上传成功"),l(!1),w()}).finally(()=>{a(!1),h.current&&(h.current.value="")})},p=L=>{L.preventDefault(),L.stopPropagation(),L.type==="dragenter"||L.type==="dragover"?m(!0):L.type==="dragleave"&&m(!1)},v=L=>{L.preventDefault(),L.stopPropagation(),m(!1),L.dataTransfer.files&&L.dataTransfer.files[0]&&k(L.dataTransfer.files[0])},M=()=>{o&&E(L=>L===0?o.images.length-1:L-1)},H=()=>{o&&E(L=>L===o.images.length-1?0:L+1)},se=(L,Z)=>{E(0),c({name:L,images:Z})};return e.jsxs(Ee,{children:[e.jsxs(Re,{className:"flex items-center justify-between",children:[e.jsx(Ke,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"",children:[e.jsxs("header",{className:"mb-8",children:[e.jsx("div",{className:"mb-2",children:e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-muted-foreground",children:s("description")}),e.jsxs(P,{onClick:()=>l(!0),variant:"outline",className:"ml-4 shrink-0",size:"sm",children:[e.jsx(pt,{className:"mr-2 h-4 w-4"}),s("upload.button")]})]})]}),e.jsx("section",{className:"grid gap-6 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3",children:S?e.jsxs(e.Fragment,{children:[e.jsx(cn,{}),e.jsx(cn,{})]}):C?.themes&&Object.entries(C.themes).map(([L,Z])=>e.jsx(We,{className:"group relative overflow-hidden transition-all hover:shadow-md",style:{backgroundImage:Z.background_url?`url(${Z.background_url})`:"none",backgroundSize:"cover",backgroundPosition:"center"},children:e.jsxs("div",{className:N("relative z-10 h-full transition-colors",Z.background_url?"group-hover:from-background/98 bg-gradient-to-t from-background/95 via-background/80 to-background/60 backdrop-blur-[1px] group-hover:via-background/90 group-hover:to-background/70":"bg-background"),children:[!!Z.can_delete&&e.jsx("div",{className:"absolute right-2 top-2",children:e.jsx(Qe,{title:s("card.delete.title"),description:s("card.delete.description"),confirmText:s("card.delete.button"),variant:"destructive",onConfirm:async()=>{if(L===C?.active){A.error(s("card.delete.error.active"));return}t(L),Sc(L).then(()=>{A.success("主题删除成功"),w()}).finally(()=>{t(null)})},children:e.jsx(P,{disabled:n===L,loading:n===L,variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",children:e.jsx(cs,{className:"h-4 w-4"})})})}),e.jsxs(ts,{children:[e.jsx(Cs,{children:Z.name}),e.jsx(et,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{children:Z.description}),Z.version&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("card.version",{version:Z.version})})]})})]}),e.jsxs(as,{className:"flex items-center justify-end space-x-3",children:[Z.images&&Array.isArray(Z.images)&&Z.images.length>0&&e.jsx(P,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>se(Z.name,Z.images),children:e.jsx(Vo,{className:"h-4 w-4"})}),e.jsx(Rm,{themeKey:L,themeInfo:Z}),e.jsx(P,{onClick:()=>b(L),disabled:n===L||L===C.active,loading:n===L,variant:L===C.active?"secondary":"default",children:L===C.active?s("card.currentTheme"):s("card.activateTheme")})]})]})},L))}),e.jsx(be,{open:i,onOpenChange:l,children:e.jsxs(fe,{className:"sm:max-w-md",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:s("upload.title")}),e.jsx(Te,{children:s("upload.description")})]}),e.jsxs("div",{className:N("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",d&&"border-primary/50 bg-muted/50"),onDragEnter:p,onDragLeave:p,onDragOver:p,onDrop:v,children:[e.jsx("input",{type:"file",ref:h,className:"hidden",accept:".zip",onChange:L=>{const Z=L.target.files?.[0];Z&&k(Z)}}),r?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(pt,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[s("upload.dragText")," ",e.jsx("button",{type:"button",onClick:()=>h.current?.click(),className:"mx-1 text-primary hover:underline",children:s("upload.clickText")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("upload.supportText")})]})]})})]})]})}),e.jsx(be,{open:!!o,onOpenChange:L=>{L||(c(null),E(0))},children:e.jsxs(fe,{className:"max-w-4xl",children:[e.jsxs(Ce,{children:[e.jsxs(ye,{children:[o?.name," ",s("preview.title")]}),e.jsx(Te,{className:"text-center",children:o&&s("preview.imageCount",{current:_+1,total:o.images.length})})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"aspect-[16/9] overflow-hidden rounded-lg border bg-muted",children:o?.images[_]&&e.jsx("img",{src:o.images[_],alt:`${o.name} 预览图 ${_+1}`,className:"h-full w-full object-contain"})}),o&&o.images.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"outline",size:"icon",className:"absolute left-4 top-1/2 h-8 w-8 -translate-y-1/2 rounded-full bg-background/80 hover:bg-background",onClick:M,children:e.jsx(Mo,{className:"h-4 w-4"})}),e.jsx(P,{variant:"outline",size:"icon",className:"absolute right-4 top-1/2 h-8 w-8 -translate-y-1/2 rounded-full bg-background/80 hover:bg-background",onClick:H,children:e.jsx(Fo,{className:"h-4 w-4"})})]})]}),o&&o.images.length>1&&e.jsx("div",{className:"mt-4 flex gap-2 overflow-x-auto pb-2",children:o.images.map((L,Z)=>e.jsx("button",{onClick:()=>E(Z),className:N("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2",_===Z?"border-primary":"border-transparent"),children:e.jsx("img",{src:L,alt:`缩略图 ${Z+1}`,className:"h-full w-full object-cover"})},Z))})]})})]})]})}function cn(){return e.jsxs(We,{children:[e.jsxs(ts,{children:[e.jsx(oe,{className:"h-6 w-[200px]"}),e.jsx(oe,{className:"h-4 w-[300px]"})]}),e.jsxs(as,{className:"flex items-center justify-end space-x-3",children:[e.jsx(oe,{className:"h-10 w-[100px]"}),e.jsx(oe,{className:"h-10 w-[100px]"})]})]})}const Vm=Object.freeze(Object.defineProperty({__proto__:null,default:Im},Symbol.toStringTag,{value:"Module"})),La=u.forwardRef(({className:s,value:n,onChange:t,...r},a)=>{const[i,l]=u.useState("");u.useEffect(()=>{if(i.includes(",")){const m=new Set([...n,...i.split(",").map(o=>o.trim())]);t(Array.from(m)),l("")}},[i,t,n]);const d=()=>{if(i){const m=new Set([...n,i]);t(Array.from(m)),l("")}};return e.jsxs("div",{className:N(" has-[:focus-visible]:outline-none has-[:focus-visible]:ring-1 has-[:focus-visible]:ring-neutral-950 dark:has-[:focus-visible]:ring-neutral-300 flex w-full flex-wrap gap-2 rounded-md border border-input shadow-sm px-3 py-2 text-sm ring-offset-white disabled:cursor-not-allowed disabled:opacity-50",s),children:[n.map(m=>e.jsxs(q,{variant:"secondary",children:[m,e.jsx(J,{variant:"ghost",size:"icon",className:"ml-2 h-3 w-3",onClick:()=>{t(n.filter(o=>o!==m))},children:e.jsx(ga,{className:"w-3"})})]},m)),e.jsx("input",{className:"flex-1 outline-none placeholder:text-muted-foreground bg-transparent",value:i,onChange:m=>l(m.target.value),onKeyDown:m=>{m.key==="Enter"||m.key===","?(m.preventDefault(),d()):m.key==="Backspace"&&i.length===0&&n.length>0&&(m.preventDefault(),t(n.slice(0,-1)))},...r,ref:a})]})});La.displayName="InputTags";const Mm=x.object({id:x.number().nullable(),title:x.string().min(1).max(250),content:x.string().min(1),show:x.boolean(),tags:x.array(x.string()),img_url:x.string().nullable()}),Fm={id:null,show:!1,tags:[],img_url:"",title:"",content:""};function Wr({refetch:s,dialogTrigger:n,type:t="add",defaultFormValues:r=Fm}){const{t:a}=V("notice"),[i,l]=u.useState(!1),d=ge({resolver:Ne(Mm),defaultValues:r,mode:"onChange",shouldFocusError:!0}),m=new Pa({html:!0});return e.jsx(_e,{...d,children:e.jsxs(be,{onOpenChange:l,open:i,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add.button")})]})}),e.jsxs(fe,{className:"sm:max-w-[1025px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:a(t==="add"?"form.add.title":"form.edit.title")}),e.jsx(Te,{})]}),e.jsx(g,{control:d.control,name:"title",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.title.label")}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(T,{placeholder:a("form.fields.title.placeholder"),...o})})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"content",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.content.label")}),e.jsx(y,{children:e.jsx(Ea,{style:{height:"500px"},value:o.value,renderHTML:c=>m.render(c),onChange:({text:c})=>{o.onChange(c)}})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"img_url",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.img_url.label")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:a("form.fields.img_url.placeholder"),...o,value:o.value||""})})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"show",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.show.label")}),e.jsx("div",{className:"relative py-2",children:e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:o.onChange})})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"tags",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.fields.tags.label")}),e.jsx(y,{children:e.jsx(La,{value:o.value,onChange:o.onChange,placeholder:a("form.fields.tags.placeholder"),className:"w-full"})}),e.jsx(D,{})]})}),e.jsxs(ze,{children:[e.jsx(yt,{asChild:!0,children:e.jsx(P,{type:"button",variant:"outline",children:a("form.buttons.cancel")})}),e.jsx(P,{type:"submit",onClick:o=>{o.preventDefault(),d.handleSubmit(async c=>{qc(c).then(({data:h})=>{h&&(A.success(a("form.buttons.success")),s(),l(!1))})})()},children:a("form.buttons.submit")})]})]})]})})}function Om({table:s,refetch:n,saveOrder:t,isSortMode:r}){const{t:a}=V("notice"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between space-x-2 ",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[!r&&e.jsx(Wr,{refetch:n}),!r&&e.jsx(T,{placeholder:a("table.toolbar.search"),value:s.getColumn("title")?.getFilterValue()??"",onChange:l=>s.getColumn("title")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),i&&!r&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-9 px-2 lg:px-3",children:[a("table.toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(P,{variant:r?"default":"outline",onClick:t,className:"h-8",size:"sm",children:a(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}const Lm=s=>{const{t:n}=V("notice");return[{id:"drag-handle",header:"",cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Oo,{className:"h-4 w-4 text-muted-foreground cursor-move"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(q,{variant:"outline",className:"font-mono",children:t.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(Y,{defaultChecked:t.getValue("show"),onCheckedChange:async()=>{const{data:r}=await Bc({id:t.original.id});r||s()}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.title")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[500px] items-center",children:e.jsx("span",{className:"truncate font-medium",children:t.getValue("title")})}),enableSorting:!1,size:6e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Wr,{refetch:s,dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),type:"edit",defaultFormValues:t.original}),e.jsx(Qe,{title:n("table.actions.delete.title"),description:n("table.actions.delete.description"),onConfirm:async()=>{Kc({id:t.original.id}).then(()=>{A.success(n("table.actions.delete.success")),s()})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("table.actions.delete.title")})]})})]}),size:100}]};function zm(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),[m,o]=u.useState(!1),[c,h]=u.useState({}),[_,E]=u.useState({pageSize:50,pageIndex:0}),[C,S]=u.useState([]),{refetch:w}=re({queryKey:["notices"],queryFn:async()=>{const{data:M}=await nn.getList();return S(M),M}});u.useEffect(()=>{r({"drag-handle":m,content:!m,created_at:!m,actions:!m}),E({pageSize:m?99999:50,pageIndex:0})},[m]);const b=(M,H)=>{m&&(M.dataTransfer.setData("text/plain",H.toString()),M.currentTarget.classList.add("opacity-50"))},k=(M,H)=>{if(!m)return;M.preventDefault(),M.currentTarget.classList.remove("bg-muted");const se=parseInt(M.dataTransfer.getData("text/plain"));if(se===H)return;const L=[...C],[Z]=L.splice(se,1);L.splice(H,0,Z),S(L)},p=async()=>{if(!m){o(!0);return}nn.sort(C.map(M=>M.id)).then(()=>{A.success("排序保存成功"),o(!1),w()}).finally(()=>{o(!1)})},v=ns({data:C??[],columns:Lm(w),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,columnSizing:c,pagination:_},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:h,onPaginationChange:E,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(hs,{table:v,toolbar:M=>e.jsx(Om,{table:M,refetch:w,saveOrder:p,isSortMode:m}),draggable:m,onDragStart:b,onDragEnd:M=>M.currentTarget.classList.remove("opacity-50"),onDragOver:M=>{M.preventDefault(),M.currentTarget.classList.add("bg-muted")},onDragLeave:M=>M.currentTarget.classList.remove("bg-muted"),onDrop:k,showPagination:!m})})}function Am(){const{t:s}=V("notice");return e.jsxs(Ee,{children:[e.jsxs(Re,{className:"flex items-center justify-between",children:[e.jsx(Ke,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(zm,{})})]})]})}const $m=Object.freeze(Object.defineProperty({__proto__:null,default:Am},Symbol.toStringTag,{value:"Module"})),Um=x.object({id:x.number().nullable(),language:x.string().max(250),category:x.string().max(250),title:x.string().min(1).max(250),body:x.string().min(1),show:x.boolean()}),Hm={id:null,language:"zh-CN",category:"",title:"",body:"",show:!1};function Yr({refreshData:s,dialogTrigger:n,type:t="add",defaultFormValues:r=Hm}){const{t:a}=V("knowledge"),[i,l]=u.useState(!1),d=ge({resolver:Ne(Um),defaultValues:r,mode:"onChange",shouldFocusError:!0}),m=new Pa({html:!0});return u.useEffect(()=>{i&&r.id&&Wc(r.id).then(({data:o})=>{d.reset(o)})},[r.id,d,i]),e.jsxs(be,{onOpenChange:l,open:i,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add")})]})}),e.jsxs(fe,{className:"sm:max-w-[1025px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:a(t==="add"?"form.add":"form.edit")}),e.jsx(Te,{})]}),e.jsxs(_e,{...d,children:[e.jsx(g,{control:d.control,name:"title",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.title")}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(T,{placeholder:a("form.titlePlaceholder"),...o})})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"category",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.category")}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(T,{placeholder:a("form.categoryPlaceholder"),...o})})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"language",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.language")}),e.jsx(y,{children:e.jsxs(G,{value:o.value,onValueChange:o.onChange,children:[e.jsx(K,{children:e.jsx(W,{placeholder:a("form.languagePlaceholder")})}),e.jsx(B,{children:[{value:"en-US"},{value:"ja-JP"},{value:"ko-KR"},{value:"vi-VN"},{value:"zh-CN"},{value:"zh-TW"}].map(c=>e.jsx(z,{value:c.value,className:"cursor-pointer",children:a(`languages.${c.value}`)},c.value))})]})})]})}),e.jsx(g,{control:d.control,name:"body",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.content")}),e.jsx(y,{children:e.jsx(Ea,{style:{height:"500px"},value:o.value,renderHTML:c=>m.render(c),onChange:({text:c})=>{o.onChange(c)}})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"show",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.show")}),e.jsx("div",{className:"relative py-2",children:e.jsx(y,{children:e.jsx(Y,{checked:o.value,onCheckedChange:o.onChange})})}),e.jsx(D,{})]})}),e.jsxs(ze,{children:[e.jsx(yt,{asChild:!0,children:e.jsx(P,{type:"button",variant:"outline",children:a("form.cancel")})}),e.jsx(P,{type:"submit",onClick:()=>{d.handleSubmit(o=>{Yc(o).then(({data:c})=>{c&&(d.reset(),A.success(a("messages.operationSuccess")),l(!1),s())})})()},children:a("form.submit")})]})]})]})]})}function qm({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(qt,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:a.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:a.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(xs,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Ms,{children:[e.jsx(Ks,{placeholder:n}),e.jsxs(Fs,{children:[e.jsx(Bs,{children:"No results found."}),e.jsx(Ye,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(Me,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx($s,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{}),e.jsx(Ye,{children:e.jsx(Me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function Km({table:s,refetch:n,saveOrder:t,isSortMode:r}){const a=s.getState().columnFilters.length>0,{t:i}=V("knowledge");return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sortModeHint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Yr,{refreshData:n}),e.jsx(T,{placeholder:i("toolbar.searchPlaceholder"),value:s.getColumn("title")?.getFilterValue()??"",onChange:l=>s.getColumn("title")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),s.getColumn("category")&&e.jsx(qm,{column:s.getColumn("category"),title:i("columns.category"),options:Array.from(new Set(s.getCoreRowModel().rows.map(l=>l.getValue("category")))).map(l=>({label:l,value:l}))}),a&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[i("toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{variant:r?"default":"outline",onClick:t,size:"sm",children:i(r?"toolbar.saveSort":"toolbar.editSort")})})]})}const Bm=({refetch:s,isSortMode:n=!1})=>{const{t}=V("knowledge");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(Ht,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.id")}),cell:({row:r})=>e.jsx(q,{variant:"outline",className:"justify-center",children:r.getValue("id")}),enableSorting:!0,size:70},{accessorKey:"show",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.status")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx(Y,{defaultChecked:r.getValue("show"),onCheckedChange:async()=>{Jc({id:r.original.id}).then(({data:a})=>{a||s()})}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.title")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"line-clamp-2 font-medium",children:r.getValue("title")})}),enableSorting:!0,size:600},{accessorKey:"category",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.category")}),cell:({row:r})=>e.jsx(q,{variant:"secondary",className:"max-w-[180px] truncate",children:r.getValue("category")}),enableSorting:!0,size:1800},{id:"actions",header:({column:r})=>e.jsx(O,{className:"justify-end",column:r,title:t("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx(Yr,{refreshData:s,dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:t("form.edit")})]}),type:"edit",defaultFormValues:r.original}),e.jsx(Qe,{title:t("messages.deleteConfirm"),description:t("messages.deleteDescription"),confirmText:t("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Qc({id:r.original.id}).then(({data:a})=>{a&&(A.success(t("messages.operationSuccess")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:t("messages.deleteButton")})]})})]}),size:100}]};function Gm(){const[s,n]=u.useState([]),[t,r]=u.useState([]),[a,i]=u.useState(!1),[l,d]=u.useState([]),[m,o]=u.useState({"drag-handle":!1}),[c,h]=u.useState({pageSize:20,pageIndex:0}),{refetch:_,isLoading:E,data:C}=re({queryKey:["knowledge"],queryFn:async()=>{const{data:p}=await Gc();return d(p||[]),p}});u.useEffect(()=>{o({"drag-handle":a,actions:!a}),h({pageSize:a?99999:10,pageIndex:0})},[a]);const S=(p,v)=>{a&&(p.dataTransfer.setData("text/plain",v.toString()),p.currentTarget.classList.add("opacity-50"))},w=(p,v)=>{if(!a)return;p.preventDefault(),p.currentTarget.classList.remove("bg-muted");const M=parseInt(p.dataTransfer.getData("text/plain"));if(M===v)return;const H=[...l],[se]=H.splice(M,1);H.splice(v,0,se),d(H)},b=async()=>{a?Xc({ids:l.map(p=>p.id)}).then(()=>{_(),i(!1),A.success("排序保存成功")}):i(!0)},k=ns({data:l,columns:Bm({refetch:_,isSortMode:a}),state:{sorting:t,columnFilters:s,columnVisibility:m,pagination:c},onSortingChange:r,onColumnFiltersChange:n,onColumnVisibilityChange:o,onPaginationChange:h,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(hs,{table:k,toolbar:p=>e.jsx(Km,{table:p,refetch:_,saveOrder:b,isSortMode:a}),draggable:a,onDragStart:S,onDragEnd:p=>p.currentTarget.classList.remove("opacity-50"),onDragOver:p=>{p.preventDefault(),p.currentTarget.classList.add("bg-muted")},onDragLeave:p=>p.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!a})}function Wm(){const{t:s}=V("knowledge");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight mb-2",children:s("title")}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Gm,{})})]})]})}const Ym=Object.freeze(Object.defineProperty({__proto__:null,default:Wm},Symbol.toStringTag,{value:"Module"}));function Qm(s,n){const[t,r]=u.useState(s);return u.useEffect(()=>{const a=setTimeout(()=>r(s),n);return()=>{clearTimeout(a)}},[s,n]),t}function ca(s,n){if(s.length===0)return{};if(!n)return{"":s};const t={};return s.forEach(r=>{const a=r[n]||"";t[a]||(t[a]=[]),t[a].push(r)}),t}function Jm(s,n){const t=JSON.parse(JSON.stringify(s));for(const[r,a]of Object.entries(t))t[r]=a.filter(i=>!n.find(l=>l.value===i.value));return t}function Xm(s,n){for(const[,t]of Object.entries(s))if(t.some(r=>n.find(a=>a.value===r.value)))return!0;return!1}const Qr=u.forwardRef(({className:s,...n},t)=>Lo(a=>a.filtered.count===0)?e.jsx("div",{ref:t,className:N("py-6 text-center text-sm",s),"cmdk-empty":"",role:"presentation",...n}):null);Qr.displayName="CommandEmpty";const at=u.forwardRef(({value:s,onChange:n,placeholder:t,defaultOptions:r=[],options:a,delay:i,onSearch:l,loadingIndicator:d,emptyIndicator:m,maxSelected:o=Number.MAX_SAFE_INTEGER,onMaxSelected:c,hidePlaceholderWhenSelected:h,disabled:_,groupBy:E,className:C,badgeClassName:S,selectFirstItem:w=!0,creatable:b=!1,triggerSearchOnFocus:k=!1,commandProps:p,inputProps:v,hideClearAllButton:M=!1},H)=>{const se=u.useRef(null),[L,Z]=u.useState(!1),de=u.useRef(!1),[Q,te]=u.useState(!1),[$,R]=u.useState(s||[]),[X,Ns]=u.useState(ca(r,E)),[De,le]=u.useState(""),Os=Qm(De,i||500);u.useImperativeHandle(H,()=>({selectedValue:[...$],input:se.current,focus:()=>se.current?.focus()}),[$]);const Ws=u.useCallback(ee=>{const ue=$.filter(Ue=>Ue.value!==ee.value);R(ue),n?.(ue)},[n,$]),bl=u.useCallback(ee=>{const ue=se.current;ue&&((ee.key==="Delete"||ee.key==="Backspace")&&ue.value===""&&$.length>0&&($[$.length-1].fixed||Ws($[$.length-1])),ee.key==="Escape"&&ue.blur())},[Ws,$]);u.useEffect(()=>{s&&R(s)},[s]),u.useEffect(()=>{if(!a||l)return;const ee=ca(a||[],E);JSON.stringify(ee)!==JSON.stringify(X)&&Ns(ee)},[r,a,E,l,X]),u.useEffect(()=>{const ee=async()=>{te(!0);const Ue=await l?.(Os);Ns(ca(Ue||[],E)),te(!1)};(async()=>{!l||!L||(k&&await ee(),Os&&await ee())})()},[Os,E,L,k]);const yl=()=>{if(!b||Xm(X,[{value:De,label:De}])||$.find(ue=>ue.value===De))return;const ee=e.jsx(Me,{value:De,className:"cursor-pointer",onMouseDown:ue=>{ue.preventDefault(),ue.stopPropagation()},onSelect:ue=>{if($.length>=o){c?.($.length);return}le("");const Ue=[...$,{value:ue,label:ue}];R(Ue),n?.(Ue)},children:`Create "${De}"`});if(!l&&De.length>0||l&&Os.length>0&&!Q)return ee},Nl=u.useCallback(()=>{if(m)return l&&!b&&Object.keys(X).length===0?e.jsx(Me,{value:"-",disabled:!0,children:m}):e.jsx(Qr,{children:m})},[b,m,l,X]),_l=u.useMemo(()=>Jm(X,$),[X,$]),wl=u.useCallback(()=>{if(p?.filter)return p.filter;if(b)return(ee,ue)=>ee.toLowerCase().includes(ue.toLowerCase())?1:-1},[b,p?.filter]),Cl=u.useCallback(()=>{const ee=$.filter(ue=>ue.fixed);R(ee),n?.(ee)},[n,$]);return e.jsxs(Ms,{...p,onKeyDown:ee=>{bl(ee),p?.onKeyDown?.(ee)},className:N("h-auto overflow-visible bg-transparent",p?.className),shouldFilter:p?.shouldFilter!==void 0?p.shouldFilter:!l,filter:wl(),children:[e.jsx("div",{className:N("rounded-md border border-input text-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring ",{"px-3 py-2":$.length!==0,"cursor-text":!_&&$.length!==0},C),onClick:()=>{_||se.current?.focus()},children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[$.map(ee=>e.jsxs(q,{className:N("data-[disabled]:bg-muted-foreground data-[disabled]:text-muted data-[disabled]:hover:bg-muted-foreground","data-[fixed]:bg-muted-foreground data-[fixed]:text-muted data-[fixed]:hover:bg-muted-foreground",S),"data-fixed":ee.fixed,"data-disabled":_||void 0,children:[ee.label,e.jsx("button",{className:N("ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",(_||ee.fixed)&&"hidden"),onKeyDown:ue=>{ue.key==="Enter"&&Ws(ee)},onMouseDown:ue=>{ue.preventDefault(),ue.stopPropagation()},onClick:()=>Ws(ee),children:e.jsx(ga,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},ee.value)),e.jsx(Le.Input,{...v,ref:se,value:De,disabled:_,onValueChange:ee=>{le(ee),v?.onValueChange?.(ee)},onBlur:ee=>{de.current===!1&&Z(!1),v?.onBlur?.(ee)},onFocus:ee=>{Z(!0),k&&l?.(Os),v?.onFocus?.(ee)},placeholder:h&&$.length!==0?"":t,className:N("flex-1 bg-transparent outline-none placeholder:text-muted-foreground",{"w-full":h,"px-3 py-2":$.length===0,"ml-1":$.length!==0},v?.className)}),e.jsx("button",{type:"button",onClick:Cl,className:N((M||_||$.length<1||$.filter(ee=>ee.fixed).length===$.length)&&"hidden"),children:e.jsx(ga,{})})]})}),e.jsx("div",{className:"relative",children:L&&e.jsx(Fs,{className:"absolute top-1 z-10 w-full rounded-md border bg-popover text-popover-foreground shadow-md outline-none animate-in",onMouseLeave:()=>{de.current=!1},onMouseEnter:()=>{de.current=!0},onMouseUp:()=>{se.current?.focus()},children:Q?e.jsx(e.Fragment,{children:d}):e.jsxs(e.Fragment,{children:[Nl(),yl(),!w&&e.jsx(Me,{value:"-",className:"hidden"}),Object.entries(_l).map(([ee,ue])=>e.jsx(Ye,{heading:ee,className:"h-full overflow-auto",children:e.jsx(e.Fragment,{children:ue.map(Ue=>e.jsx(Me,{value:Ue.value,disabled:Ue.disable,onMouseDown:lt=>{lt.preventDefault(),lt.stopPropagation()},onSelect:()=>{if($.length>=o){c?.($.length);return}le("");const lt=[...$,Ue];R(lt),n?.(lt)},className:N("cursor-pointer",Ue.disable&&"cursor-default text-muted-foreground"),children:Ue.label},Ue.value))})},ee))]})})})]})});at.displayName="MultipleSelector";const Zm=s=>x.object({id:x.number().optional(),name:x.string().min(2,s("messages.nameValidation.min")).max(50,s("messages.nameValidation.max")).regex(/^[a-zA-Z0-9\u4e00-\u9fa5_-]+$/,s("messages.nameValidation.pattern"))});function ta({refetch:s,dialogTrigger:n,defaultValues:t={name:""},type:r="add"}){const{t:a}=V("group"),i=ge({resolver:Ne(Zm(a)),defaultValues:t,mode:"onChange"}),[l,d]=u.useState(!1),[m,o]=u.useState(!1),c=async h=>{o(!0),Ic(h).then(()=>{A.success(a(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),s&&s(),i.reset(),d(!1)}).finally(()=>{o(!1)})};return e.jsxs(be,{open:l,onOpenChange:d,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("span",{children:a("form.add")})]})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:a(r==="edit"?"form.edit":"form.create")}),e.jsx(Te,{children:a(r==="edit"?"form.editDescription":"form.createDescription")})]}),e.jsx(_e,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(c),className:"space-y-4",children:[e.jsx(g,{control:i.control,name:"name",render:({field:h})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.name")}),e.jsx(y,{children:e.jsx(T,{placeholder:a("form.namePlaceholder"),...h,className:"w-full"})}),e.jsx(F,{children:a("form.nameDescription")}),e.jsx(D,{})]})}),e.jsxs(ze,{className:"gap-2",children:[e.jsx(yt,{asChild:!0,children:e.jsx(P,{type:"button",variant:"outline",children:a("form.cancel")})}),e.jsxs(P,{type:"submit",disabled:m||!i.formState.isValid,children:[m&&e.jsx(Da,{className:"mr-2 h-4 w-4 animate-spin"}),a(r==="edit"?"form.update":"form.create")]})]})]})})]})]})}const Jr=u.createContext(void 0);function ex({children:s,refetch:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(null),[l,d]=u.useState(ie.Shadowsocks);return e.jsx(Jr.Provider,{value:{isOpen:t,setIsOpen:r,editingServer:a,setEditingServer:i,serverType:l,setServerType:d,refetch:n},children:s})}function Xr(){const s=u.useContext(Jr);if(s===void 0)throw new Error("useServerEdit must be used within a ServerEditProvider");return s}function da({dialogTrigger:s,value:n,setValue:t,templateType:r}){const{t:a}=V("server");u.useEffect(()=>{console.log(n)},[n]);const[i,l]=u.useState(!1),[d,m]=u.useState(()=>{if(!n||Object.keys(n).length===0)return"";try{return JSON.stringify(n,null,2)}catch{return""}}),[o,c]=u.useState(null),h=b=>{if(!b)return null;try{const k=JSON.parse(b);return typeof k!="object"||k===null?a("network_settings.validation.must_be_object"):null}catch{return a("network_settings.validation.invalid_json")}},_={tcp:{label:"TCP",content:{acceptProxyProtocol:!1,header:{type:"none"}}},"tcp-http":{label:"TCP + HTTP",content:{acceptProxyProtocol:!1,header:{type:"http",request:{version:"1.1",method:"GET",path:["/"],headers:{Host:["www.example.com"]}},response:{version:"1.1",status:"200",reason:"OK"}}}},grpc:{label:"gRPC",content:{serviceName:"GunService"}},ws:{label:"WebSocket",content:{path:"/",headers:{Host:"v2ray.com"}}},httpupgrade:{label:"HttpUpgrade",content:{acceptProxyProtocol:!1,path:"/",host:"xray.com",headers:{key:"value"}}},xhttp:{label:"XHTTP",content:{host:"example.com",path:"/yourpath",mode:"auto",extra:{headers:{},xPaddingBytes:"100-1000",noGRPCHeader:!1,noSSEHeader:!1,scMaxEachPostBytes:1e6,scMinPostsIntervalMs:30,scMaxBufferedPosts:30,xmux:{maxConcurrency:"16-32",maxConnections:0,cMaxReuseTimes:"64-128",cMaxLifetimeMs:0,hMaxRequestTimes:"800-900",hKeepAlivePeriod:0},downloadSettings:{address:"",port:443,network:"xhttp",security:"tls",tlsSettings:{},xhttpSettings:{path:"/yourpath"},sockopt:{}}}}}},E=()=>{switch(r){case"tcp":return["tcp","tcp-http"];case"grpc":return["grpc"];case"ws":return["ws"];case"httpupgrade":return["httpupgrade"];case"xhttp":return["xhttp"];default:return[]}},C=()=>{const b=h(d||"");if(b){A.error(b);return}try{if(!d){t(null),l(!1);return}t(JSON.parse(d)),l(!1)}catch{A.error(a("network_settings.errors.save_failed"))}},S=b=>{m(b),c(h(b))},w=b=>{const k=_[b];if(k){const p=JSON.stringify(k.content,null,2);m(p),c(null)}};return u.useEffect(()=>{i&&console.log(n)},[i,n]),u.useEffect(()=>{i&&n&&Object.keys(n).length>0&&m(JSON.stringify(n,null,2))},[i,n]),e.jsxs(be,{open:i,onOpenChange:b=>{!b&&i&&C(),l(b)},children:[e.jsx(Je,{asChild:!0,children:s??e.jsx(J,{variant:"link",children:a("network_settings.edit_protocol")})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsx(Ce,{children:e.jsx(ye,{children:a("network_settings.edit_protocol_config")})}),e.jsxs("div",{className:"space-y-4",children:[E().length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:E().map(b=>e.jsx(J,{variant:"outline",size:"sm",onClick:()=>w(b),children:a("network_settings.use_template",{template:_[b].label})},b))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ys,{className:`min-h-[200px] font-mono text-sm ${o?"border-red-500 focus-visible:ring-red-500":""}`,value:d,placeholder:E().length>0?a("network_settings.json_config_placeholder_with_template"):a("network_settings.json_config_placeholder"),onChange:b=>S(b.target.value)}),o&&e.jsx("p",{className:"text-sm text-red-500",children:o})]})]}),e.jsxs(ze,{className:"gap-2",children:[e.jsx(J,{variant:"outline",onClick:()=>l(!1),children:a("common.cancel")}),e.jsx(J,{onClick:C,disabled:!!o,children:a("common.confirm")})]})]})]})}function pp(s){throw new Error('Could not dynamically require "'+s+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}const sx={},tx=Object.freeze(Object.defineProperty({__proto__:null,default:sx},Symbol.toStringTag,{value:"Module"})),fp=Xo(tx),dn=s=>s.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),ax=()=>{try{const s=zo.box.keyPair(),n=dn(Ja.encodeBase64(s.secretKey)),t=dn(Ja.encodeBase64(s.publicKey));return{privateKey:n,publicKey:t}}catch(s){throw console.error("Error generating x25519 key pair:",s),s}},nx=()=>{try{return ax()}catch(s){throw console.error("Error generating key pair:",s),s}},rx=s=>{const n=new Uint8Array(Math.ceil(s/2));return window.crypto.getRandomValues(n),Array.from(n).map(t=>t.toString(16).padStart(2,"0")).join("").substring(0,s)},lx=()=>{const s=Math.floor(Math.random()*8)*2+2;return rx(s)},ix=x.object({cipher:x.string().default("aes-128-gcm"),obfs:x.string().default("0"),obfs_settings:x.object({path:x.string().default(""),host:x.string().default("")}).default({})}),ox=x.object({tls:x.coerce.number().default(0),tls_settings:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({}),network:x.string().default("tcp"),network_settings:x.record(x.any()).default({})}),cx=x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1),network:x.string().default("tcp"),network_settings:x.record(x.any()).default({})}),dx=x.object({version:x.coerce.number().default(2),alpn:x.string().default("h2"),obfs:x.object({open:x.coerce.boolean().default(!1),type:x.string().default("salamander"),password:x.string().default("")}).default({}),tls:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({}),bandwidth:x.object({up:x.string().default(""),down:x.string().default("")}).default({})}),ux=x.object({tls:x.coerce.number().default(0),tls_settings:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({}),reality_settings:x.object({server_port:x.coerce.number().default(443),server_name:x.string().default(""),allow_insecure:x.boolean().default(!1),public_key:x.string().default(""),private_key:x.string().default(""),short_id:x.string().default("")}).default({}),network:x.string().default("tcp"),network_settings:x.record(x.any()).default({}),flow:x.string().default("")}),mx=x.object({version:x.coerce.number().default(5),congestion_control:x.string().default("bbr"),alpn:x.array(x.string()).default(["h3"]),udp_relay_mode:x.string().default("native"),tls:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({})}),xx=x.object({}),hx=x.object({tls:x.coerce.number().default(0),tls_settings:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({})}),px=x.object({tls:x.coerce.number().default(0),tls_settings:x.object({server_name:x.string().default(""),allow_insecure:x.boolean().default(!1)}).default({})}),fx=x.object({transport:x.string().default("tcp"),multiplexing:x.string().default("MULTIPLEXING_LOW")}),Ie={shadowsocks:{schema:ix,ciphers:["aes-128-gcm","aes-192-gcm","aes-256-gcm","chacha20-ietf-poly1305","2022-blake3-aes-128-gcm","2022-blake3-aes-256-gcm"]},vmess:{schema:ox,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},trojan:{schema:cx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},hysteria:{schema:dx,versions:["1","2"],alpnOptions:["hysteria","http/1.1","h2","h3"]},vless:{schema:ux,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"},{value:"kcp",label:"mKCP"},{value:"httpupgrade",label:"HttpUpgrade"},{value:"xhttp",label:"XHTTP"}],flowOptions:["none","xtls-rprx-direct","xtls-rprx-splice","xtls-rprx-vision"]},tuic:{schema:mx,versions:["5","4"],congestionControls:["bbr","cubic","new_reno"],alpnOptions:[{value:"h3",label:"HTTP/3"},{value:"h2",label:"HTTP/2"},{value:"http/1.1",label:"HTTP/1.1"}],udpRelayModes:[{value:"native",label:"Native"},{value:"quic",label:"QUIC"}]},socks:{schema:xx},naive:{schema:px},http:{schema:hx},mieru:{schema:fx,transportOptions:[{value:"tcp",label:"TCP"},{value:"udp",label:"UDP"}],multiplexingOptions:[{value:"MULTIPLEXING_OFF",label:"Off"},{value:"MULTIPLEXING_LOW",label:"Low"},{value:"MULTIPLEXING_MIDDLE",label:"Middle"},{value:"MULTIPLEXING_HIGH",label:"High"}]}},gx=({serverType:s,value:n,onChange:t})=>{const{t:r}=V("server"),a=s?Ie[s]:null,i=a?.schema||x.record(x.any()),l=s?i.parse({}):{},d=ge({resolver:Ne(i),defaultValues:l,mode:"onChange"});if(u.useEffect(()=>{if(!n||Object.keys(n).length===0){if(s){const p=i.parse({});d.reset(p)}}else d.reset(n)},[s,n,t,d,i]),u.useEffect(()=>{const p=d.watch(v=>{t(v)});return()=>p.unsubscribe()},[d,t]),!s||!a)return null;const k={shadowsocks:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"cipher",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.shadowsocks.cipher.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.shadowsocks.cipher.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.shadowsocks.ciphers.map(v=>e.jsx(z,{value:v,children:v},v))})})]})})]})}),e.jsx(g,{control:d.control,name:"obfs",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.shadowsocks.obfs.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.shadowsocks.obfs.placeholder")})}),e.jsx(B,{children:e.jsxs(He,{children:[e.jsx(z,{value:"0",children:r("dynamic_form.shadowsocks.obfs.none")}),e.jsx(z,{value:"http",children:r("dynamic_form.shadowsocks.obfs.http")})]})})]})})]})}),d.watch("obfs")==="http"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"obfs_settings.path",render:({field:p})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:r("dynamic_form.shadowsocks.obfs_settings.path"),...p})}),e.jsx(D,{})]})}),e.jsx(g,{control:d.control,name:"obfs_settings.host",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:r("dynamic_form.shadowsocks.obfs_settings.host"),...p})}),e.jsx(D,{})]})})]})]}),vmess:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"tls",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vmess.tls.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value?.toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.vmess.tls.placeholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:r("dynamic_form.vmess.tls.disabled")}),e.jsx(z,{value:"1",children:r("dynamic_form.vmess.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls_settings.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.vmess.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.vmess.tls_settings.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"tls_settings.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vmess.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"network",render:({field:p})=>e.jsxs(f,{children:[e.jsxs(j,{children:[r("dynamic_form.vmess.network.label"),e.jsx(da,{value:d.watch("network_settings"),setValue:v=>d.setValue("network_settings",v),templateType:d.watch("network")})]}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.vmess.network.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.vmess.networkOptions.map(v=>e.jsx(z,{value:v.value,className:"cursor-pointer",children:v.label},v.value))})})]})})]})})]}),trojan:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.trojan.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.trojan.server_name.placeholder"),...p,value:p.value||""})})]})}),e.jsx(g,{control:d.control,name:"allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.trojan.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value||!1,onCheckedChange:p.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"network",render:({field:p})=>e.jsxs(f,{children:[e.jsxs(j,{children:[r("dynamic_form.trojan.network.label"),e.jsx(da,{value:d.watch("network_settings")||{},setValue:v=>d.setValue("network_settings",v),templateType:d.watch("network")||"tcp"})]}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value||"tcp",children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.trojan.network.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.trojan.networkOptions.map(v=>e.jsx(z,{value:v.value,className:"cursor-pointer",children:v.label},v.value))})})]})})]})})]}),hysteria:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"version",render:({field:p})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.hysteria.version.label")}),e.jsx(y,{children:e.jsxs(G,{value:(p.value||2).toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.hysteria.version.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.hysteria.versions.map(v=>e.jsxs(z,{value:v,className:"cursor-pointer",children:["V",v]},v))})})]})})]})}),d.watch("version")==1&&e.jsx(g,{control:d.control,name:"alpn",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.hysteria.alpn.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value||"h2",onValueChange:p.onChange,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.hysteria.alpn.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.hysteria.alpnOptions.map(v=>e.jsx(z,{value:v,children:v},v))})})]})})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"obfs.open",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.obfs.label")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value||!1,onCheckedChange:p.onChange})})})]})}),!!d.watch("obfs.open")&&e.jsxs(e.Fragment,{children:[d.watch("version")=="2"&&e.jsx(g,{control:d.control,name:"obfs.type",render:({field:p})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.hysteria.obfs.type.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value||"salamander",onValueChange:p.onChange,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.hysteria.obfs.type.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:e.jsx(z,{value:"salamander",children:r("dynamic_form.hysteria.obfs.type.salamander")})})})]})})]})}),e.jsx(g,{control:d.control,name:"obfs.password",render:({field:p})=>e.jsxs(f,{className:d.watch("version")==2?"w-full":"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.hysteria.obfs.password.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.hysteria.obfs.password.placeholder"),...p,value:p.value||"",className:"pr-9"})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",M=Array.from(crypto.getRandomValues(new Uint8Array(16))).map(H=>v[H%v.length]).join("");d.setValue("obfs.password",M),A.success(r("dynamic_form.hysteria.obfs.password.generate_success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Ve,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})]})]})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.hysteria.tls.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.hysteria.tls.server_name.placeholder"),...p,value:p.value||""})})]})}),e.jsx(g,{control:d.control,name:"tls.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value||!1,onCheckedChange:p.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"bandwidth.up",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.bandwidth.up.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:r("dynamic_form.hysteria.bandwidth.up.placeholder")+(d.watch("version")==2?r("dynamic_form.hysteria.bandwidth.up.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...p,value:p.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:r("dynamic_form.hysteria.bandwidth.up.suffix")})})]})]})}),e.jsx(g,{control:d.control,name:"bandwidth.down",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.bandwidth.down.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:r("dynamic_form.hysteria.bandwidth.down.placeholder")+(d.watch("version")==2?r("dynamic_form.hysteria.bandwidth.down.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...p,value:p.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:r("dynamic_form.hysteria.bandwidth.down.suffix")})})]})]})})]}),vless:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"tls",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.tls.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value?.toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.vless.tls.placeholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:r("dynamic_form.vless.tls.none")}),e.jsx(z,{value:"1",children:r("dynamic_form.vless.tls.tls")}),e.jsx(z,{value:"2",children:r("dynamic_form.vless.tls.reality")})]})]})})]})}),d.watch("tls")=="1"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls_settings.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.vless.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.tls_settings.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"tls_settings.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]}),d.watch("tls")==2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"reality_settings.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.reality_settings.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"reality_settings.server_port",render:({field:p})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.server_port.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.reality_settings.server_port.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"reality_settings.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]}),e.jsx("div",{className:"flex items-end gap-2",children:e.jsx(g,{control:d.control,name:"reality_settings.private_key",render:({field:p})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.private_key.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{children:e.jsx(T,{...p,className:"pr-9"})}),e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{try{const v=nx();d.setValue("reality_settings.private_key",v.privateKey),d.setValue("reality_settings.public_key",v.publicKey),A.success(r("dynamic_form.vless.reality_settings.key_pair.success"))}catch{A.error(r("dynamic_form.vless.reality_settings.key_pair.error"))}},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Ve,{icon:"ion:key-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(It,{children:e.jsx(ce,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.key_pair.generate")})})})]})]})]})})}),e.jsx(g,{control:d.control,name:"reality_settings.public_key",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.public_key.label")}),e.jsx(y,{children:e.jsx(T,{...p})})]})}),e.jsx(g,{control:d.control,name:"reality_settings.short_id",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.short_id.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{children:e.jsx(T,{...p,className:"pr-9",placeholder:r("dynamic_form.vless.reality_settings.short_id.placeholder")})}),e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const v=lx();d.setValue("reality_settings.short_id",v),A.success(r("dynamic_form.vless.reality_settings.short_id.success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Ve,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(It,{children:e.jsx(ce,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.short_id.generate")})})})]})]}),e.jsx(F,{className:"text-xs text-muted-foreground",children:r("dynamic_form.vless.reality_settings.short_id.description")})]})})]}),e.jsx(g,{control:d.control,name:"network",render:({field:p})=>e.jsxs(f,{children:[e.jsxs(j,{children:[r("dynamic_form.vless.network.label"),e.jsx(da,{value:d.watch("network_settings"),setValue:v=>d.setValue("network_settings",v),templateType:d.watch("network")})]}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.vless.network.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.vless.networkOptions.map(v=>e.jsx(z,{value:v.value,className:"cursor-pointer",children:v.label},v.value))})})]})})]})}),e.jsx(g,{control:d.control,name:"flow",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.vless.flow.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:v=>p.onChange(v==="none"?null:v),value:p.value||"none",children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.vless.flow.placeholder")})}),e.jsx(B,{children:Ie.vless.flowOptions.map(v=>e.jsx(z,{value:v,children:v},v))})]})})]})})]}),tuic:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"version",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.tuic.version.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value?.toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.tuic.version.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.tuic.versions.map(v=>e.jsxs(z,{value:v,children:["V",v]},v))})})]})})]})}),e.jsx(g,{control:d.control,name:"congestion_control",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.tuic.congestion_control.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.tuic.congestion_control.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.tuic.congestionControls.map(v=>e.jsx(z,{value:v,children:v.toUpperCase()},v))})})]})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.tuic.tls.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.tuic.tls.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"tls.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.tuic.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"alpn",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.tuic.tls.alpn.label")}),e.jsx(y,{children:e.jsx(at,{options:Ie.tuic.alpnOptions,onChange:v=>p.onChange(v.map(M=>M.value)),value:Ie.tuic.alpnOptions.filter(v=>p.value?.includes(v.value)),placeholder:r("dynamic_form.tuic.tls.alpn.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:r("dynamic_form.tuic.tls.alpn.empty")})})})]})}),e.jsx(g,{control:d.control,name:"udp_relay_mode",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.tuic.udp_relay_mode.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.tuic.udp_relay_mode.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.tuic.udpRelayModes.map(v=>e.jsx(z,{value:v.value,children:v.label},v.value))})})]})})]})})]}),socks:()=>e.jsx(e.Fragment,{}),naive:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"tls",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.naive.tls.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value?.toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.naive.tls.placeholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:r("dynamic_form.naive.tls.disabled")}),e.jsx(z,{value:"1",children:r("dynamic_form.naive.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls_settings.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.naive.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.naive.tls_settings.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"tls_settings.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.naive.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]})]}),http:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"tls",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.http.tls.label")}),e.jsx(y,{children:e.jsxs(G,{value:p.value?.toString(),onValueChange:v=>p.onChange(Number(v)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.http.tls.placeholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:r("dynamic_form.http.tls.disabled")}),e.jsx(z,{value:"1",children:r("dynamic_form.http.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls_settings.server_name",render:({field:p})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.http.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dynamic_form.http.tls_settings.server_name.placeholder"),...p})})]})}),e.jsx(g,{control:d.control,name:"tls_settings.allow_insecure",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.http.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(Y,{checked:p.value,onCheckedChange:p.onChange})})})]})})]})]}),mieru:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"transport",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.mieru.transport.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.mieru.transport.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.mieru.transportOptions.map(v=>e.jsx(z,{value:v.value,children:v.label},v.value))})})]})})]})}),e.jsx(g,{control:d.control,name:"multiplexing",render:({field:p})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dynamic_form.mieru.multiplexing.label")}),e.jsx(y,{children:e.jsxs(G,{onValueChange:p.onChange,value:p.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dynamic_form.mieru.multiplexing.placeholder")})}),e.jsx(B,{children:e.jsx(He,{children:Ie.mieru.multiplexingOptions.map(v=>e.jsx(z,{value:v.value,children:v.label},v.value))})})]})})]})})]})};return e.jsx(ve,{children:k[s]?.()})},jx=x.object({id:x.number().optional().nullable(),code:x.string().optional(),name:x.string().min(1,"form.name.error"),rate:x.string().min(1,"form.rate.error"),tags:x.array(x.string()).default([]),excludes:x.array(x.string()).default([]),ips:x.array(x.string()).default([]),group_ids:x.array(x.string()).default([]),host:x.string().min(1,"form.host.error"),port:x.string().min(1,"form.port.error"),server_port:x.string().min(1,"form.server_port.error"),parent_id:x.string().default("0").nullable(),route_ids:x.array(x.string()).default([]),protocol_settings:x.record(x.any()).default({}).nullable()}),wt={id:null,code:"",name:"",rate:"1",tags:[],excludes:[],ips:[],group_ids:[],host:"",port:"",server_port:"",parent_id:"0",route_ids:[],protocol_settings:null};function vx(){const{t:s}=V("server"),{isOpen:n,setIsOpen:t,editingServer:r,setEditingServer:a,serverType:i,setServerType:l,refetch:d}=Xr(),[m,o]=u.useState([]),[c,h]=u.useState([]),[_,E]=u.useState([]),C=ge({resolver:Ne(jx),defaultValues:wt,mode:"onChange"});u.useEffect(()=>{S()},[n]),u.useEffect(()=>{r?.type&&r.type!==i&&l(r.type)},[r,i,l]),u.useEffect(()=>{r?r.type===i&&C.reset({...wt,...r}):C.reset({...wt,protocol_settings:Ie[i].schema.parse({})})},[r,C,i]);const S=async()=>{if(!n)return;const[v,M,H]=await Promise.all([bt(),Sr(),Cr()]);o(v.data?.map(se=>({label:se.name,value:se.id.toString()}))||[]),h(M.data?.map(se=>({label:se.remarks,value:se.id.toString()}))||[]),E(H.data||[])},w=u.useMemo(()=>_?.filter(v=>(v.parent_id===0||v.parent_id===null)&&v.type===i&&v.id!==C.watch("id")),[i,_,C]),b=()=>e.jsxs(Ss,{children:[e.jsx(ks,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(fs,{align:"start",children:e.jsx(Ld,{children:Xe.map(({type:v,label:M})=>e.jsx(je,{onClick:()=>{l(v),t(!0)},className:"cursor-pointer",children:e.jsx(q,{variant:"outline",className:"text-white",style:{background:qe[v]},children:M})},v))})})]}),k=()=>{t(!1),a(null),C.reset(wt)},p=async()=>{const v=C.getValues();(await Tc({...v,type:i})).data&&(k(),A.success(s("form.success")),d())};return e.jsxs(be,{open:n,onOpenChange:k,children:[b(),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:s(r?"form.edit_node":"form.new_node")}),e.jsx(Te,{})]}),e.jsxs(_e,{...C,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:C.control,name:"name",render:({field:v})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:s("form.name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("form.name.placeholder"),...v})}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"rate",render:({field:v})=>e.jsxs(f,{className:"flex-[1]",children:[e.jsx(j,{children:s("form.rate.label")}),e.jsx("div",{className:"relative flex",children:e.jsx(y,{children:e.jsx(T,{type:"number",min:"0",step:"0.1",...v})})}),e.jsx(D,{})]})})]}),e.jsx(g,{control:C.control,name:"code",render:({field:v})=>e.jsxs(f,{children:[e.jsxs(j,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(y,{children:e.jsx(T,{placeholder:s("form.code.placeholder"),...v,value:v.value||""})}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"tags",render:({field:v})=>e.jsxs(f,{children:[e.jsx(j,{children:s("form.tags.label")}),e.jsx(y,{children:e.jsx(La,{value:v.value,onChange:v.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"group_ids",render:({field:v})=>e.jsxs(f,{children:[e.jsxs(j,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(ta,{dialogTrigger:e.jsx(P,{variant:"link",children:s("form.groups.add")}),refetch:S})]}),e.jsx(y,{children:e.jsx(at,{options:m,onChange:M=>v.onChange(M.map(H=>H.value)),value:m?.filter(M=>v.value.includes(M.value)),placeholder:s("form.groups.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.groups.empty")})})}),e.jsx(D,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:C.control,name:"host",render:({field:v})=>e.jsxs(f,{children:[e.jsx(j,{children:s("form.host.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:s("form.host.placeholder"),...v})}),e.jsx(D,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(g,{control:C.control,name:"port",render:({field:v})=>e.jsxs(f,{className:"flex-1",children:[e.jsxs(j,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(Ve,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(It,{children:e.jsx(ce,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.port.tooltip")})})})]})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(y,{children:e.jsx(T,{placeholder:s("form.port.placeholder"),...v})}),e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(P,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const M=v.value;M&&C.setValue("server_port",M)},children:e.jsx(Ve,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(ce,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"server_port",render:({field:v})=>e.jsxs(f,{className:"flex-1",children:[e.jsxs(j,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(Ve,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(It,{children:e.jsx(ce,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(y,{children:e.jsx(T,{placeholder:s("form.server_port.placeholder"),...v})}),e.jsx(D,{})]})})]})]}),n&&e.jsx(gx,{serverType:i,value:C.watch("protocol_settings"),onChange:v=>C.setValue("protocol_settings",v,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(g,{control:C.control,name:"parent_id",render:({field:v})=>e.jsxs(f,{children:[e.jsx(j,{children:s("form.parent.label")}),e.jsxs(G,{onValueChange:v.onChange,value:v.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(B,{children:[e.jsx(z,{value:"0",children:s("form.parent.none")}),w?.map(M=>e.jsx(z,{value:M.id.toString(),className:"cursor-pointer",children:M.name},M.id))]})]}),e.jsx(D,{})]})}),e.jsx(g,{control:C.control,name:"route_ids",render:({field:v})=>e.jsxs(f,{children:[e.jsx(j,{children:s("form.route.label")}),e.jsx(y,{children:e.jsx(at,{options:c,onChange:M=>v.onChange(M.map(H=>H.value)),value:c?.filter(M=>v.value.includes(M.value)),placeholder:s("form.route.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.route.empty")})})}),e.jsx(D,{})]})})]}),e.jsxs(ze,{className:"mt-6",children:[e.jsx(P,{type:"button",variant:"outline",onClick:k,children:s("form.cancel")}),e.jsx(P,{type:"submit",onClick:p,children:s("form.submit")})]})]})]})]})}function un({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(qt,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:a.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:a.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(xs,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Ms,{children:[e.jsx(Ks,{placeholder:n}),e.jsxs(Fs,{children:[e.jsx(Bs,{children:"No results found."}),e.jsx(Ye,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(Me,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx($s,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{}),e.jsx(Ye,{children:e.jsx(Me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const bx=[{value:ie.Shadowsocks,label:Xe.find(s=>s.type===ie.Shadowsocks)?.label,color:qe[ie.Shadowsocks]},{value:ie.Vmess,label:Xe.find(s=>s.type===ie.Vmess)?.label,color:qe[ie.Vmess]},{value:ie.Trojan,label:Xe.find(s=>s.type===ie.Trojan)?.label,color:qe[ie.Trojan]},{value:ie.Hysteria,label:Xe.find(s=>s.type===ie.Hysteria)?.label,color:qe[ie.Hysteria]},{value:ie.Vless,label:Xe.find(s=>s.type===ie.Vless)?.label,color:qe[ie.Vless]},{value:ie.Tuic,label:Xe.find(s=>s.type===ie.Tuic)?.label,color:qe[ie.Tuic]},{value:ie.Socks,label:Xe.find(s=>s.type===ie.Socks)?.label,color:qe[ie.Socks]},{value:ie.Naive,label:Xe.find(s=>s.type===ie.Naive)?.label,color:qe[ie.Naive]},{value:ie.Http,label:Xe.find(s=>s.type===ie.Http)?.label,color:qe[ie.Http]},{value:ie.Mieru,label:Xe.find(s=>s.type===ie.Mieru)?.label,color:qe[ie.Mieru]}];function yx({table:s,saveOrder:n,isSortMode:t,groups:r}){const a=s.getState().columnFilters.length>0,{t:i}=V("server");return e.jsxs("div",{className:"flex items-center justify-between ",children:[e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[!t&&e.jsxs(e.Fragment,{children:[e.jsx(vx,{}),e.jsx(T,{placeholder:i("toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(un,{column:s.getColumn("type"),title:i("toolbar.type"),options:bx}),s.getColumn("group_ids")&&e.jsx(un,{column:s.getColumn("group_ids"),title:i("columns.groups.title"),options:r.map(l=>({label:l.name,value:l.id.toString()}))})]}),a&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[i("toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]}),t&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sort.tip")})})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{variant:t?"default":"outline",onClick:n,size:"sm",children:i(t?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const gt=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M15.71 12.71a6 6 0 1 0-7.42 0a10 10 0 0 0-6.22 8.18a1 1 0 0 0 2 .22a8 8 0 0 1 15.9 0a1 1 0 0 0 1 .89h.11a1 1 0 0 0 .88-1.1a10 10 0 0 0-6.25-8.19M12 12a4 4 0 1 1 4-4a4 4 0 0 1-4 4"})}),Ct={0:"bg-destructive/80 shadow-sm shadow-destructive/50",1:"bg-yellow-500/80 shadow-sm shadow-yellow-500/50",2:"bg-emerald-500/80 shadow-sm shadow-emerald-500/50"},Nx=s=>{const{t:n}=V("server");return[{id:"drag-handle",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Ht,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.nodeId")}),cell:({row:t})=>{const r=t.getValue("id"),a=t.original.code;return e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(q,{variant:"outline",className:N("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:qe[t.original.type]},children:[e.jsx(ur,{className:"size-3"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:a??r}),t.original.parent?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-muted-foreground/30",children:"→"}),e.jsx("span",{children:t.original.parent?.code||t.original.parent?.id})]}):""]})]}),e.jsx(P,{variant:"ghost",size:"icon",className:"size-5 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:text-muted-foreground group-hover/id:opacity-100",onClick:i=>{i.stopPropagation(),Ft(a||r.toString()).then(()=>{A.success(n("common:copy.success"))})},children:e.jsx(Xa,{className:"size-3"})})]})}),e.jsxs(ce,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[Xe.find(i=>i.type===t.original.type)?.label,t.original.parent_id?" (子节点)":""]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a?"点击括号内容或复制按钮可复制节点代码":"点击复制按钮可复制节点ID"})]})]})})},size:50,enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.show")}),cell:({row:t})=>{const[r,a]=u.useState(!!t.getValue("show"));return e.jsx(Y,{checked:r,onCheckedChange:async i=>{a(i),Ec({id:t.original.id,type:t.original.type,show:i?1:0}).catch(()=>{a(!i),s()})},style:{backgroundColor:r?qe[t.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(O,{column:t,title:n("columns.node"),tooltip:e.jsxs("div",{className:"grid grid-cols-1 gap-3 p-2",children:[e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",Ct[0])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.0")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",Ct[1])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.1")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",Ct[2])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.2")})]})]})})}),cell:({row:t})=>e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("size-2.5 flex-shrink-0 rounded-full transition-all duration-200",Ct[t.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:t.getValue("name")})]})}),e.jsx(ce,{children:e.jsx("p",{className:"font-medium",children:n(`columns.status.${t.original.available_status}`)})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.address")}),cell:({row:t})=>{const r=`${t.original.host}:${t.original.port}`,a=t.original.port!==t.original.server_port;return e.jsxs("div",{className:"group relative flex min-w-0 items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-1 gap-y-0.5 pr-7",children:[e.jsx("div",{className:"flex items-center ",children:e.jsxs("span",{className:"font-mono text-sm font-medium text-foreground/90",children:[t.original.host,":",t.original.port]})}),a&&e.jsxs("span",{className:"whitespace-nowrap text-[0.7rem] tracking-tight text-muted-foreground/40",children:["(",n("columns.internalPort")," ",t.original.server_port,")"]})]}),e.jsx("div",{className:"absolute right-0 top-0",children:e.jsx(ve,{delayDuration:0,children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"icon",className:"size-6 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:bg-muted/50 hover:text-muted-foreground group-hover:opacity-100",onClick:i=>{i.stopPropagation(),Ft(r).then(()=>{A.success(n("common:copy.success"))})},children:e.jsx(Xa,{className:"size-3"})})}),e.jsx(ce,{side:"top",sideOffset:10,children:n("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.onlineUsers.title"),tooltip:n("columns.onlineUsers.tooltip")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(gt,{className:"size-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("online")})]}),size:80,enableSorting:!0,enableHiding:!0},{accessorKey:"rate",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.rate.title"),tooltip:n("columns.rate.tooltip")}),cell:({row:t})=>e.jsxs(q,{variant:"secondary",className:"font-medium",children:[t.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"group_ids",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.groups.title"),tooltip:n("columns.groups.tooltip")}),cell:({row:t})=>{const r=t.original.groups||[];return e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.map((a,i)=>e.jsx(q,{variant:"secondary",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:a.name},i)),r.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:n("columns.groups.empty")})]})},enableSorting:!1,filterFn:(t,r,a)=>{const i=t.getValue(r);return i?a.some(l=>i.includes(l)):!1}},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.type")}),cell:({row:t})=>{const r=t.getValue("type");return e.jsx(q,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:qe[r]},children:r})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingServer:a,setServerType:i}=Xr();return e.jsx("div",{className:"flex justify-center",children:e.jsxs(Ss,{modal:!1,children:[e.jsx(ks,{asChild:!0,children:e.jsx(P,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Vt,{className:"size-4"})})}),e.jsxs(fs,{align:"end",className:"w-40",children:[e.jsx(je,{className:"cursor-pointer",onClick:()=>{i(t.original.type),a(t.original),r(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(Ao,{className:"mr-2 size-4"}),n("columns.actions_dropdown.edit")]})}),e.jsxs(je,{className:"cursor-pointer",onClick:async()=>{Pc({id:t.original.id}).then(({data:l})=>{l&&(A.success(n("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx($o,{className:"mr-2 size-4"}),n("columns.actions_dropdown.copy")]}),e.jsx(tt,{}),e.jsx(je,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:l=>l.preventDefault(),children:e.jsx(Qe,{title:n("columns.actions_dropdown.delete.title"),description:n("columns.actions_dropdown.delete.description"),confirmText:n("columns.actions_dropdown.delete.confirm"),variant:"destructive",onConfirm:async()=>{Dc({id:t.original.id}).then(({data:l})=>{l&&(A.success(n("columns.actions_dropdown.delete_success")),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(cs,{className:"mr-2 size-4"}),n("columns.actions_dropdown.delete.confirm")]})})})]})]})})},size:50}]};function _x(){const[s,n]=u.useState({}),[t,r]=u.useState({"drag-handle":!1}),[a,i]=u.useState([]),[l,d]=u.useState({pageSize:500,pageIndex:0}),[m,o]=u.useState([]),[c,h]=u.useState(!1),[_,E]=u.useState({}),[C,S]=u.useState([]),{refetch:w}=re({queryKey:["nodeList"],queryFn:async()=>{const{data:H}=await Cr();return S(H),H}}),{data:b}=re({queryKey:["groups"],queryFn:async()=>{const{data:H}=await bt();return H}});u.useEffect(()=>{r({"drag-handle":c,show:!c,host:!c,online:!c,rate:!c,groups:!c,type:!1,actions:!c}),E({name:c?2e3:200}),d({pageSize:c?99999:500,pageIndex:0})},[c]);const k=(H,se)=>{c&&(H.dataTransfer.setData("text/plain",se.toString()),H.currentTarget.classList.add("opacity-50"))},p=(H,se)=>{if(!c)return;H.preventDefault(),H.currentTarget.classList.remove("bg-muted");const L=parseInt(H.dataTransfer.getData("text/plain"));if(L===se)return;const Z=[...C],[de]=Z.splice(L,1);Z.splice(se,0,de),S(Z)},v=async()=>{if(!c){h(!0);return}const H=C?.map((se,L)=>({id:se.id,order:L+1}));Rc(H).then(()=>{A.success("排序保存成功"),h(!1),w()}).finally(()=>{h(!1)})},M=ns({data:C||[],columns:Nx(w),state:{sorting:m,columnVisibility:t,rowSelection:s,columnFilters:a,columnSizing:_,pagination:l},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:E,onPaginationChange:d,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ex,{refetch:w,children:e.jsx("div",{className:"space-y-4",children:e.jsx(hs,{table:M,toolbar:H=>e.jsx(yx,{table:H,refetch:w,saveOrder:v,isSortMode:c,groups:b||[]}),draggable:c,onDragStart:k,onDragEnd:H=>H.currentTarget.classList.remove("opacity-50"),onDragOver:H=>{H.preventDefault(),H.currentTarget.classList.add("bg-muted")},onDragLeave:H=>H.currentTarget.classList.remove("bg-muted"),onDrop:p,showPagination:!c})})})}function wx(){const{t:s}=V("server");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("manage.title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("manage.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(_x,{})})]})]})}const Cx=Object.freeze(Object.defineProperty({__proto__:null,default:wx},Symbol.toStringTag,{value:"Module"}));function Sx({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=V("group");return e.jsx("div",{className:"flex items-center justify-between space-x-4",children:e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(ta,{refetch:n}),e.jsx(T,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:N("h-8 w-[150px] lg:w-[250px]",t&&"border-primary/50 ring-primary/20")}),t&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]})})}const kx=s=>{const{t:n}=V("group");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(q,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium",children:t.getValue("name")})})},{accessorKey:"users_count",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.usersCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(gt,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"server_count",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.serverCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(ur,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("server_count")})]}),enableSorting:!0,size:8e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(ta,{defaultValues:t.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(Qe,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Vc({id:t.original.id}).then(({data:r})=>{r&&(A.success(n("messages.updateSuccess")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("messages.deleteButton")})]})})]})}]};function Tx(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),{data:m,refetch:o,isLoading:c}=re({queryKey:["serverGroupList"],queryFn:async()=>{const{data:_}=await bt();return _}}),h=ns({data:m||[],columns:kx(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(hs,{table:h,toolbar:_=>e.jsx(Sx,{table:_,refetch:o}),isLoading:c})}function Dx(){const{t:s}=V("group");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Tx,{})})]})]})}const Px=Object.freeze(Object.defineProperty({__proto__:null,default:Dx},Symbol.toStringTag,{value:"Module"})),Ex=s=>x.object({remarks:x.string().min(1,s("form.validation.remarks")),match:x.array(x.string()),action:x.enum(["block","dns"]),action_value:x.string().optional()});function Zr({refetch:s,dialogTrigger:n,defaultValues:t={remarks:"",match:[],action:"block",action_value:""},type:r="add"}){const{t:a}=V("route"),i=ge({resolver:Ne(Ex(a)),defaultValues:t,mode:"onChange"}),[l,d]=u.useState(!1);return e.jsxs(be,{open:l,onOpenChange:d,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ve,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add")})]})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:a(r==="edit"?"form.edit":"form.create")}),e.jsx(Te,{})]}),e.jsxs(_e,{...i,children:[e.jsx(g,{control:i.control,name:"remarks",render:({field:m})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:a("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:a("form.remarksPlaceholder"),...m})})}),e.jsx(D,{})]})}),e.jsx(g,{control:i.control,name:"match",render:({field:m})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(j,{children:a("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(ys,{className:"min-h-[120px]",placeholder:a("form.matchPlaceholder"),value:m.value.join(` `),onChange:o=>{m.onChange(o.target.value.split(` -`))}})})}),e.jsx(D,{})]})}),e.jsx(g,{control:i.control,name:"action",render:({field:m})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:a("form.actionPlaceholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"block",children:a("actions.block")}),e.jsx(z,{value:"dns",children:a("actions.dns")})]})]})})}),e.jsx(D,{})]})}),i.watch("action")==="dns"&&e.jsx(g,{control:i.control,name:"action_value",render:({field:m})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:a("form.dnsPlaceholder"),...m})})})]})}),e.jsxs(ze,{children:[e.jsx(yt,{asChild:!0,children:e.jsx(P,{variant:"outline",children:a("form.cancel")})}),e.jsx(P,{type:"submit",onClick:()=>{Mc(i.getValues()).then(({data:m})=>{m&&(d(!1),s&&s(),toast.success(a(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),i.reset())})},children:a("form.submit")})]})]})]})]})}function Rx({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=V("route");return e.jsx("div",{className:"flex items-center justify-between ",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[e.jsx(Zr,{refetch:n}),e.jsx(T,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("remarks")?.getFilterValue()??"",onChange:a=>s.getColumn("remarks")?.setFilterValue(a.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),t&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]})})}function Ix({columns:s,data:n,refetch:t}){const[r,a]=u.useState({}),[i,l]=u.useState({}),[d,m]=u.useState([]),[o,c]=u.useState([]),h=ns({data:n,columns:s,state:{sorting:o,columnVisibility:i,rowSelection:r,columnFilters:d},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:c,onColumnFiltersChange:m,onColumnVisibilityChange:l,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(hs,{table:h,toolbar:_=>e.jsx(Rx,{table:_,refetch:t})})}const Vx=s=>{const{t:n}=V("route"),t={block:{icon:Uo,variant:"destructive",className:"bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-800"},dns:{icon:Ho,variant:"secondary",className:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-800"}};return[{accessorKey:"id",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.id")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(q,{variant:"outline",children:r.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.remarks")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:r.original.remarks})}),enableHiding:!1,enableSorting:!1},{accessorKey:"action_value",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.action_value.title")}),cell:({row:r})=>{const a=r.original.action,i=r.original.action_value,l=r.original.match?.length||0;return e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("span",{className:"text-sm font-medium",children:a==="dns"&&i?n("columns.action_value.dns",{value:i}):a==="block"?e.jsx("span",{className:"text-destructive",children:n("columns.action_value.block")}):n("columns.action_value.direct")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("columns.matchRules",{count:l})})]})},enableHiding:!1,enableSorting:!1,size:300},{accessorKey:"action",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.action")}),cell:({row:r})=>{const a=r.getValue("action"),i=t[a]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(q,{variant:t[a]?.variant||"default",className:N("flex items-center gap-1.5 px-3 py-1 capitalize",t[a]?.className),children:[i&&e.jsx(i,{className:"h-3.5 w-3.5"}),n(`actions.${a}`)]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:n("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Zr,{defaultValues:r.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(Qe,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Fc({id:r.original.id}).then(({data:a})=>{a&&(A.success(n("messages.deleteSuccess")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("messages.deleteButton")})]})})]})}]};function Mx(){const{t:s}=V("route"),[n,t]=u.useState([]);function r(){Sr().then(({data:a})=>{t(a)})}return u.useEffect(()=>{r()},[]),e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Ix,{data:n,columns:Vx(r),refetch:r})})]})]})}const Fx=Object.freeze(Object.defineProperty({__proto__:null,default:Mx},Symbol.toStringTag,{value:"Module"})),el=u.createContext(void 0);function Ox({children:s,refreshData:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(null);return e.jsx(el.Provider,{value:{isOpen:t,setIsOpen:r,editingPlan:a,setEditingPlan:i,refreshData:n},children:s})}function za(){const s=u.useContext(el);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function Lx({table:s,saveOrder:n,isSortMode:t}){const{setIsOpen:r}=za(),{t:a}=V("subscribe");return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsxs(P,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>r(!0),children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("div",{children:a("plan.add")})]}),e.jsx(T,{placeholder:a("plan.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:i=>s.getColumn("name")?.setFilterValue(i.target.value),className:"h-8 w-[150px] lg:w-[250px]"})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{variant:t?"default":"outline",onClick:n,size:"sm",children:a(t?"plan.sort.save":"plan.sort.edit")})})]})}const mn={monthly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},quarterly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},half_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},two_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},three_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},onetime:{color:"text-slate-700",bgColor:"bg-slate-100/80"},reset_traffic:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},zx=s=>{const{t:n}=V("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(Ht,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(q,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.show")}),cell:({row:t})=>e.jsx(Y,{defaultChecked:t.getValue("show"),onCheckedChange:r=>{aa({id:t.original.id,show:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.sell")}),cell:({row:t})=>e.jsx(Y,{defaultChecked:t.getValue("sell"),onCheckedChange:r=>{aa({id:t.original.id,sell:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.renew"),tooltip:n("plan.columns.renew_tooltip")}),cell:({row:t})=>e.jsx(Y,{defaultChecked:t.getValue("renew"),onCheckedChange:r=>{aa({id:t.original.id,renew:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:t.getValue("name")})}),enableSorting:!1,enableHiding:!1,size:900},{accessorKey:"users_count",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.stats")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-2",children:[e.jsx(gt,{}),e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:t.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"group",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.group")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[600px] flex-wrap items-center gap-1.5 text-nowrap",children:e.jsx(q,{variant:"secondary",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:t.getValue("group")?.name})}),enableSorting:!1,enableHiding:!1},{accessorKey:"prices",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.price")}),cell:({row:t})=>{const r=t.getValue("prices"),a=[{period:n("plan.columns.price_period.monthly"),key:"monthly",unit:n("plan.columns.price_period.unit.month")},{period:n("plan.columns.price_period.quarterly"),key:"quarterly",unit:n("plan.columns.price_period.unit.quarter")},{period:n("plan.columns.price_period.half_yearly"),key:"half_yearly",unit:n("plan.columns.price_period.unit.half_year")},{period:n("plan.columns.price_period.yearly"),key:"yearly",unit:n("plan.columns.price_period.unit.year")},{period:n("plan.columns.price_period.two_yearly"),key:"two_yearly",unit:n("plan.columns.price_period.unit.two_year")},{period:n("plan.columns.price_period.three_yearly"),key:"three_yearly",unit:n("plan.columns.price_period.unit.three_year")},{period:n("plan.columns.price_period.onetime"),key:"onetime",unit:""},{period:n("plan.columns.price_period.reset_traffic"),key:"reset_traffic",unit:n("plan.columns.price_period.unit.times")}];return e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:a.map(({period:i,key:l,unit:d})=>r[l]!=null&&e.jsxs(q,{variant:"secondary",className:N("px-2 py-0.5 font-medium transition-colors text-nowrap",mn[l].color,mn[l].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[i," ¥",r[l],d]},l))})},enableSorting:!1,size:9e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("plan.columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingPlan:a}=za();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{a(t.original),r(!0)},children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.edit")})]}),e.jsx(Qe,{title:n("plan.columns.delete_confirm.title"),description:n("plan.columns.delete_confirm.description"),confirmText:n("plan.columns.delete"),variant:"destructive",onConfirm:async()=>{ed({id:t.original.id}).then(({data:i})=>{i&&(A.success(n("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.delete")})]})})]})}}]},Ax=x.object({id:x.number().nullable(),group_id:x.union([x.number(),x.string()]).nullable().optional(),name:x.string().min(1).max(250),content:x.string().nullable().optional(),transfer_enable:x.union([x.number().min(0),x.string().min(1)]),prices:x.object({monthly:x.union([x.number(),x.string()]).nullable().optional(),quarterly:x.union([x.number(),x.string()]).nullable().optional(),half_yearly:x.union([x.number(),x.string()]).nullable().optional(),yearly:x.union([x.number(),x.string()]).nullable().optional(),two_yearly:x.union([x.number(),x.string()]).nullable().optional(),three_yearly:x.union([x.number(),x.string()]).nullable().optional(),onetime:x.union([x.number(),x.string()]).nullable().optional(),reset_traffic:x.union([x.number(),x.string()]).nullable().optional()}).default({}),speed_limit:x.union([x.number(),x.string()]).nullable().optional(),capacity_limit:x.union([x.number(),x.string()]).nullable().optional(),device_limit:x.union([x.number(),x.string()]).nullable().optional(),force_update:x.boolean().optional(),reset_traffic_method:x.number().nullable(),users_count:x.number().optional()}),sl=u.forwardRef(({className:s,...n},t)=>e.jsx(mr,{ref:t,className:N("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...n,children:e.jsx(qo,{className:N("flex items-center justify-center text-current"),children:e.jsx($s,{className:"h-4 w-4"})})}));sl.displayName=mr.displayName;const St={id:null,group_id:null,name:"",content:"",transfer_enable:"",prices:{monthly:"",quarterly:"",half_yearly:"",yearly:"",two_yearly:"",three_yearly:"",onetime:"",reset_traffic:""},speed_limit:"",capacity_limit:"",device_limit:"",force_update:!1,reset_traffic_method:null},kt={monthly:{label:"月付",months:1,discount:1},quarterly:{label:"季付",months:3,discount:.95},half_yearly:{label:"半年付",months:6,discount:.9},yearly:{label:"年付",months:12,discount:.85},two_yearly:{label:"两年付",months:24,discount:.8},three_yearly:{label:"三年付",months:36,discount:.75},onetime:{label:"流量包",months:1,discount:1},reset_traffic:{label:"重置包",months:1,discount:1}},$x=[{value:null,label:"follow_system"},{value:0,label:"monthly_first"},{value:1,label:"monthly_reset"},{value:2,label:"no_reset"},{value:3,label:"yearly_first"},{value:4,label:"yearly_reset"}];function Ux(){const{isOpen:s,setIsOpen:n,editingPlan:t,setEditingPlan:r,refreshData:a}=za(),[i,l]=u.useState(!1),{t:d}=V("subscribe"),m=ge({resolver:Ne(Ax),defaultValues:{...St,...t||{}},mode:"onChange"});u.useEffect(()=>{t?m.reset({...St,...t}):m.reset(St)},[t,m]);const o=new Pa({html:!0}),[c,h]=u.useState();async function _(){bt().then(({data:S})=>{h(S)})}u.useEffect(()=>{s&&_()},[s]);const E=S=>{if(isNaN(S))return;const w=Object.entries(kt).reduce((b,[k,p])=>{const v=S*p.months*p.discount;return{...b,[k]:v.toFixed(2)}},{});m.setValue("prices",w,{shouldDirty:!0})},C=()=>{n(!1),r(null),m.reset(St)};return e.jsx(be,{open:s,onOpenChange:C,children:e.jsxs(fe,{children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:d(t?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(Te,{})]}),e.jsxs(_e,{...m,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:m.control,name:"name",render:({field:S})=>e.jsxs(f,{children:[e.jsx(j,{children:d("plan.form.name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:d("plan.form.name.placeholder"),...S})}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"group_id",render:({field:S})=>e.jsxs(f,{children:[e.jsxs(j,{className:"flex items-center justify-between",children:[d("plan.form.group.label"),e.jsx(ta,{dialogTrigger:e.jsx(P,{variant:"link",children:d("plan.form.group.add")}),refetch:_})]}),e.jsxs(G,{value:S.value?.toString()??"",onValueChange:w=>S.onChange(w?Number(w):null),children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:d("plan.form.group.placeholder")})})}),e.jsx(B,{children:c?.map(w=>e.jsx(z,{value:w.id.toString(),children:w.name},w.id))})]}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"transfer_enable",render:({field:S})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:d("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",min:0,placeholder:d("plan.form.transfer.placeholder"),className:"rounded-r-none",...S})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.transfer.unit")})]}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"speed_limit",render:({field:S})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:d("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",min:0,placeholder:d("plan.form.speed.placeholder"),className:"rounded-r-none",...S,value:S.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.speed.unit")})]}),e.jsx(D,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:d("plan.form.price.title")}),e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(T,{type:"number",placeholder:d("plan.form.price.base_price"),className:"h-7 w-32 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500",onChange:S=>{const w=parseFloat(S.target.value);E(w)}})]}),e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const S=Object.keys(kt).reduce((w,b)=>({...w,[b]:""}),{});m.setValue("prices",S,{shouldDirty:!0})},children:d("plan.form.price.clear.button")})}),e.jsx(ce,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:d("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(kt).filter(([S])=>!["onetime","reset_traffic"].includes(S)).map(([S,w])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(g,{control:m.control,name:`prices.${S}`,render:({field:b})=>e.jsxs(f,{children:[e.jsxs(j,{className:"text-xs font-medium text-muted-foreground",children:[d(`plan.columns.price_period.${S}`),e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",w.months===1?d("plan.form.price.period.monthly"):d("plan.form.price.period.months",{count:w.months}),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:"0.00",min:0,...b,value:b.value??"",onChange:k=>b.onChange(k.target.value),className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})},S))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(kt).filter(([S])=>["onetime","reset_traffic"].includes(S)).map(([S,w])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(g,{control:m.control,name:`prices.${S}`,render:({field:b})=>e.jsx(f,{children:e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-0",children:[e.jsx(j,{className:"text-xs font-medium",children:d(`plan.columns.price_period.${S}`)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:d(S==="onetime"?"plan.form.price.onetime_desc":"plan.form.price.reset_desc")})]}),e.jsxs("div",{className:"relative w-full md:w-32",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:"0.00",min:0,...b,className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})})},S))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(g,{control:m.control,name:"device_limit",render:({field:S})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:d("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",min:0,placeholder:d("plan.form.device.placeholder"),className:"rounded-r-none",...S,value:S.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.device.unit")})]}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"capacity_limit",render:({field:S})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:d("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",min:0,placeholder:d("plan.form.capacity.placeholder"),className:"rounded-r-none",...S,value:S.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.capacity.unit")})]}),e.jsx(D,{})]})})]}),e.jsx(g,{control:m.control,name:"reset_traffic_method",render:({field:S})=>e.jsxs(f,{children:[e.jsx(j,{children:d("plan.form.reset_method.label")}),e.jsxs(G,{value:S.value?.toString()??"null",onValueChange:w=>S.onChange(w=="null"?null:Number(w)),children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:d("plan.form.reset_method.placeholder")})})}),e.jsx(B,{children:$x.map(w=>e.jsx(z,{value:w.value?.toString()??"null",children:d(`plan.form.reset_method.options.${w.label}`)},w.value))})]}),e.jsx(F,{className:"text-xs",children:d("plan.form.reset_method.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"content",render:({field:S})=>{const[w,b]=u.useState(!1);return e.jsxs(f,{className:"space-y-2",children:[e.jsxs(j,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d("plan.form.content.label"),e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>b(!w),children:w?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{d:"M10 12.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5z"}),e.jsx("path",{fillRule:"evenodd",d:"M.664 10.59a1.651 1.651 0 010-1.186A10.004 10.004 0 0110 3c4.257 0 7.893 2.66 9.336 6.41.147.381.146.804 0 1.186A10.004 10.004 0 0110 17c-4.257 0-7.893-2.66-9.336-6.41zM14 10a4 4 0 11-8 0 4 4 0 018 0z",clipRule:"evenodd"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{fillRule:"evenodd",d:"M3.28 2.22a.75.75 0 00-1.06 1.06l14.5 14.5a.75.75 0 101.06-1.06l-1.745-1.745a10.029 10.029 0 003.3-4.38 1.651 1.651 0 000-1.185A10.004 10.004 0 009.999 3a9.956 9.956 0 00-4.744 1.194L3.28 2.22zM7.752 6.69l1.092 1.092a2.5 2.5 0 013.374 3.373l1.091 1.092a4 4 0 00-5.557-5.557z",clipRule:"evenodd"}),e.jsx("path",{d:"M10.748 13.93l2.523 2.523a9.987 9.987 0 01-3.27.547c-4.258 0-7.894-2.66-9.337-6.41a1.651 1.651 0 010-1.186A10.007 10.007 0 012.839 6.02L6.07 9.252a4 4 0 004.678 4.678z"})]})})}),e.jsx(ce,{side:"top",children:e.jsx("p",{className:"text-xs",children:d(w?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",onClick:()=>{S.onChange(d("plan.form.content.template.content"))},children:d("plan.form.content.template.button")})}),e.jsx(ce,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:d("plan.form.content.template.tooltip")})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${w?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(y,{children:e.jsx(Ea,{style:{height:"400px"},value:S.value||"",renderHTML:k=>o.render(k),onChange:({text:k})=>S.onChange(k),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:d("plan.form.content.placeholder"),className:"rounded-md border"})})}),w&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:d("plan.form.content.preview")}),e.jsx("div",{className:"prose prose-sm dark:prose-invert h-[400px] max-w-none overflow-y-auto rounded-md border p-4",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:o.render(S.value||"")}})})]})]}),e.jsx(F,{className:"text-xs",children:d("plan.form.content.description")}),e.jsx(D,{})]})}})]}),e.jsx(ze,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:t&&e.jsx(g,{control:m.control,name:"force_update",render:({field:S})=>e.jsxs(f,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(y,{children:e.jsx(sl,{checked:S.value,onCheckedChange:S.onChange})}),e.jsx("div",{className:"",children:e.jsx(j,{className:"text-sm",children:d("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(P,{type:"button",variant:"outline",onClick:C,children:d("plan.form.submit.cancel")}),e.jsx(P,{type:"submit",disabled:i,onClick:()=>{m.handleSubmit(async S=>{l(!0),(await Zc(S)).data&&(A.success(d(t?"plan.form.submit.success.update":"plan.form.submit.success.add")),C(),a()),l(!1)})()},children:d(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})]})})}function Hx(){const[s,n]=u.useState({}),[t,r]=u.useState({"drag-handle":!1}),[a,i]=u.useState([]),[l,d]=u.useState([]),[m,o]=u.useState(!1),[c,h]=u.useState({pageSize:20,pageIndex:0}),[_,E]=u.useState([]),{refetch:C}=re({queryKey:["planList"],queryFn:async()=>{const{data:p}=await qs();return E(p),p}});u.useEffect(()=>{r({"drag-handle":m}),h({pageSize:m?99999:10,pageIndex:0})},[m]);const S=(p,v)=>{m&&(p.dataTransfer.setData("text/plain",v.toString()),p.currentTarget.classList.add("opacity-50"))},w=(p,v)=>{if(!m)return;p.preventDefault(),p.currentTarget.classList.remove("bg-muted");const M=parseInt(p.dataTransfer.getData("text/plain"));if(M===v)return;const H=[..._],[se]=H.splice(M,1);H.splice(v,0,se),E(H)},b=async()=>{if(!m){o(!0);return}const p=_?.map(v=>v.id);sd(p).then(()=>{A.success("排序保存成功"),o(!1),C()}).finally(()=>{o(!1)})},k=ns({data:_||[],columns:zx(C),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:c},enableRowSelection:!0,onPaginationChange:h,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}},pageCount:m?1:void 0});return e.jsx(Ox,{refreshData:C,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(hs,{table:k,toolbar:p=>e.jsx(Lx,{table:p,refetch:C,saveOrder:b,isSortMode:m}),draggable:m,onDragStart:S,onDragEnd:p=>p.currentTarget.classList.remove("opacity-50"),onDragOver:p=>{p.preventDefault(),p.currentTarget.classList.add("bg-muted")},onDragLeave:p=>p.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!m}),e.jsx(Ux,{})]})})}function qx(){const{t:s}=V("subscribe");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("plan.title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("plan.page.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Hx,{})})]})]})}const Kx=Object.freeze(Object.defineProperty({__proto__:null,default:qx},Symbol.toStringTag,{value:"Module"})),Js=[{value:ae.PENDING,label:ot[ae.PENDING],icon:Ko,color:ct[ae.PENDING]},{value:ae.PROCESSING,label:ot[ae.PROCESSING],icon:xr,color:ct[ae.PROCESSING]},{value:ae.COMPLETED,label:ot[ae.COMPLETED],icon:ja,color:ct[ae.COMPLETED]},{value:ae.CANCELLED,label:ot[ae.CANCELLED],icon:hr,color:ct[ae.CANCELLED]},{value:ae.DISCOUNTED,label:ot[ae.DISCOUNTED],icon:ja,color:ct[ae.DISCOUNTED]}],ut=[{value:xe.PENDING,label:Nt[xe.PENDING],icon:Bo,color:_t[xe.PENDING]},{value:xe.PROCESSING,label:Nt[xe.PROCESSING],icon:xr,color:_t[xe.PROCESSING]},{value:xe.VALID,label:Nt[xe.VALID],icon:ja,color:_t[xe.VALID]},{value:xe.INVALID,label:Nt[xe.INVALID],icon:hr,color:_t[xe.INVALID]}];function Tt({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=s?.getFilterValue(),i=Array.isArray(a)?new Set(a):a!==void 0?new Set([a]):new Set;return e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(qt,{className:"mr-2 h-4 w-4"}),n,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:i.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:i.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):t.filter(l=>i.has(l.value)).map(l=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(xs,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Ms,{children:[e.jsx(Ks,{placeholder:n}),e.jsxs(Fs,{children:[e.jsx(Bs,{children:"No results found."}),e.jsx(Ye,{children:t.map(l=>{const d=i.has(l.value);return e.jsxs(Me,{onSelect:()=>{const m=new Set(i);d?m.delete(l.value):m.add(l.value);const o=Array.from(m);s?.setFilterValue(o.length?o:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",d?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx($s,{className:N("h-4 w-4")})}),l.icon&&e.jsx(l.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${l.color}`}),e.jsx("span",{children:l.label}),r?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(l.value)})]},l.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{}),e.jsx(Ye,{children:e.jsx(Me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Bx=x.object({email:x.string().min(1),plan_id:x.number(),period:x.string(),total_amount:x.number()}),Gx={email:"",plan_id:0,total_amount:0,period:""};function tl({refetch:s,trigger:n,defaultValues:t}){const{t:r}=V("order"),[a,i]=u.useState(!1),l=ge({resolver:Ne(Bx),defaultValues:{...Gx,...t},mode:"onChange"}),[d,m]=u.useState([]);return u.useEffect(()=>{a&&qs().then(({data:o})=>{m(o)})},[a]),e.jsxs(be,{open:a,onOpenChange:i,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("div",{children:r("dialog.addOrder")})]})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:r("dialog.assignOrder")}),e.jsx(Te,{})]}),e.jsxs(_e,{...l,children:[e.jsx(g,{control:l.control,name:"email",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dialog.fields.userEmail")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dialog.placeholders.email"),...o})})]})}),e.jsx(g,{control:l.control,name:"plan_id",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dialog.fields.subscriptionPlan")}),e.jsx(y,{children:e.jsxs(G,{value:o.value?o.value?.toString():void 0,onValueChange:c=>o.onChange(parseInt(c)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dialog.placeholders.plan")})}),e.jsx(B,{children:d.map(c=>e.jsx(z,{value:c.id.toString(),children:c.name},c.id))})]})})]})}),e.jsx(g,{control:l.control,name:"period",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dialog.fields.orderPeriod")}),e.jsx(y,{children:e.jsxs(G,{value:o.value,onValueChange:o.onChange,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dialog.placeholders.period")})}),e.jsx(B,{children:Object.keys(gu).map(c=>e.jsx(z,{value:c,children:r(`period.${c}`)},c))})]})})]})}),e.jsx(g,{control:l.control,name:"total_amount",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dialog.fields.paymentAmount")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:r("dialog.placeholders.amount"),value:o.value/100,onChange:c=>o.onChange(parseFloat(c.currentTarget.value)*100)})}),e.jsx(D,{})]})}),e.jsxs(ze,{children:[e.jsx(P,{variant:"outline",onClick:()=>i(!1),children:r("dialog.actions.cancel")}),e.jsx(P,{type:"submit",onClick:()=>{l.handleSubmit(o=>{ld(o).then(({data:c})=>{c&&(s&&s(),l.reset(),i(!1),A.success(r("dialog.messages.addSuccess")))})})()},children:r("dialog.actions.confirm")})]})]})]})]})}function Wx({table:s,refetch:n}){const{t}=V("order"),r=s.getState().columnFilters.length>0,a=Object.values(os).filter(m=>typeof m=="number").map(m=>({label:t(`type.${os[m]}`),value:m,color:m===os.NEW?"green-500":m===os.RENEWAL?"blue-500":m===os.UPGRADE?"purple-500":"orange-500"})),i=Object.values(Pe).map(m=>({label:t(`period.${m}`),value:m,color:m===Pe.MONTH_PRICE?"slate-500":m===Pe.QUARTER_PRICE?"cyan-500":m===Pe.HALF_YEAR_PRICE?"indigo-500":m===Pe.YEAR_PRICE?"violet-500":m===Pe.TWO_YEAR_PRICE?"fuchsia-500":m===Pe.THREE_YEAR_PRICE?"pink-500":m===Pe.ONETIME_PRICE?"rose-500":"orange-500"})),l=Object.values(ae).filter(m=>typeof m=="number").map(m=>({label:t(`status.${ae[m]}`),value:m,icon:m===ae.PENDING?Js[0].icon:m===ae.PROCESSING?Js[1].icon:m===ae.COMPLETED?Js[2].icon:m===ae.CANCELLED?Js[3].icon:Js[4].icon,color:m===ae.PENDING?"yellow-500":m===ae.PROCESSING?"blue-500":m===ae.COMPLETED?"green-500":m===ae.CANCELLED?"red-500":"green-500"})),d=Object.values(xe).filter(m=>typeof m=="number").map(m=>({label:t(`commission.${xe[m]}`),value:m,icon:m===xe.PENDING?ut[0].icon:m===xe.PROCESSING?ut[1].icon:m===xe.VALID?ut[2].icon:ut[3].icon,color:m===xe.PENDING?"yellow-500":m===xe.PROCESSING?"blue-500":m===xe.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tl,{refetch:n}),e.jsx(T,{placeholder:t("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:m=>s.getColumn("trade_no")?.setFilterValue(m.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2",children:[s.getColumn("type")&&e.jsx(Tt,{column:s.getColumn("type"),title:t("table.columns.type"),options:a}),s.getColumn("period")&&e.jsx(Tt,{column:s.getColumn("period"),title:t("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(Tt,{column:s.getColumn("status"),title:t("table.columns.status"),options:l}),s.getColumn("commission_status")&&e.jsx(Tt,{column:s.getColumn("commission_status"),title:t("table.columns.commissionStatus"),options:d})]}),r&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("actions.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]})}function ls({label:s,value:n,className:t,valueClassName:r}){return e.jsxs("div",{className:N("flex items-center py-1.5",t),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:N("text-sm",r),children:n||"-"})]})}function Yx({status:s}){const{t:n}=V("order"),t={[ae.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[ae.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[ae.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[ae.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[ae.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(q,{variant:"secondary",className:N("font-medium",t[s]),children:n(`status.${ae[s]}`)})}function Qx({id:s,trigger:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(),{t:l}=V("order");return u.useEffect(()=>{(async()=>{if(t){const{data:m}=await ad({id:s});i(m)}})()},[t,s]),e.jsxs(be,{onOpenChange:r,open:t,children:[e.jsx(Je,{asChild:!0,children:n}),e.jsxs(fe,{className:"max-w-xl",children:[e.jsxs(Ce,{className:"space-y-2",children:[e.jsx(ye,{className:"text-lg font-medium",children:l("dialog.title")}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:[l("table.columns.tradeNo"),":",a?.trade_no]}),a?.status&&e.jsx(Yx,{status:a.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ls,{label:l("dialog.fields.userEmail"),value:a?.user?.email?e.jsxs(Us,{to:`/user/manage?email=${a.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[a.user.email,e.jsx(pr,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(ls,{label:l("dialog.fields.orderPeriod"),value:a&&l(`period.${a.period}`)}),e.jsx(ls,{label:l("dialog.fields.subscriptionPlan"),value:a?.plan?.name,valueClassName:"font-medium"}),e.jsx(ls,{label:l("dialog.fields.callbackNo"),value:a?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ls,{label:l("dialog.fields.paymentAmount"),value:Ls(a?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(ke,{className:"my-2"}),e.jsx(ls,{label:l("dialog.fields.balancePayment"),value:Ls(a?.balance_amount||0)}),e.jsx(ls,{label:l("dialog.fields.discountAmount"),value:Ls(a?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(ls,{label:l("dialog.fields.refundAmount"),value:Ls(a?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(ls,{label:l("dialog.fields.deductionAmount"),value:Ls(a?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ls,{label:l("dialog.fields.createdAt"),value:we(a?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(ls,{label:l("dialog.fields.updatedAt"),value:we(a?.updated_at),valueClassName:"font-mono text-xs"})]})]})]})]})]})}const Jx={[os.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[os.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[os.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[os.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Xx={[Pe.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Zx=s=>ae[s],eh=s=>xe[s],sh=s=>os[s],th=s=>{const{t:n}=V("order");return[{accessorKey:"trade_no",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.tradeNo")}),cell:({row:t})=>{const r=t.original.trade_no,a=r.length>6?`${r.slice(0,3)}...${r.slice(-3)}`:r;return e.jsx("div",{className:"flex items-center",children:e.jsx(Qx,{trigger:e.jsxs(J,{variant:"ghost",size:"sm",className:"flex h-8 items-center gap-1.5 px-2 font-medium text-primary transition-colors hover:bg-primary/10 hover:text-primary/80",children:[e.jsx("span",{className:"font-mono",children:a}),e.jsx(pr,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.type")}),cell:({row:t})=>{const r=t.getValue("type"),a=Jx[r];return e.jsx(q,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",a.color,a.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:n(`type.${sh(r)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.plan")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium text-foreground/90 sm:max-w-72 md:max-w-[31rem]",children:t.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.period")}),cell:({row:t})=>{const r=t.getValue("period"),a=Xx[r];return e.jsx(q,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",a?.color,a?.bgColor,"hover:bg-opacity-80"),children:n(`period.${r}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.amount")}),cell:({row:t})=>{const r=t.getValue("total_amount"),a=typeof r=="number"?(r/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",a]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:t})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(O,{column:t,title:n("table.columns.status")}),e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{children:e.jsx(Gr,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(ce,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:t})=>{const r=Js.find(a=>a.value===t.getValue("status"));return r?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r.icon&&e.jsx(r.icon,{className:`h-4 w-4 text-${r.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`status.${Zx(r.value)}`)})]}),r.value===ae.PENDING&&e.jsxs(Ss,{modal:!0,children:[e.jsx(ks,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Vt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(fs,{align:"end",className:"w-[140px]",children:[e.jsx(je,{className:"cursor-pointer",onClick:async()=>{await nd({trade_no:t.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(je,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await rd({trade_no:t.original.trade_no}),s()},children:n("actions.cancel")})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.commission")}),cell:({row:t})=>{const r=t.getValue("commission_balance"),a=r?(r/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:r?`¥${a}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.commissionStatus")}),cell:({row:t})=>{const r=t.original.status,a=t.original.commission_balance,i=ut.find(l=>l.value===t.getValue("commission_status"));return a==0||!i?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i.icon&&e.jsx(i.icon,{className:`h-4 w-4 text-${i.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`commission.${eh(i.value)}`)})]}),i.value===xe.PENDING&&r===ae.COMPLETED&&e.jsxs(Ss,{modal:!0,children:[e.jsx(ks,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Vt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(fs,{align:"end",className:"w-[120px]",children:[e.jsx(je,{className:"cursor-pointer",onClick:async()=>{await an({trade_no:t.original.trade_no,commission_status:xe.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(je,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await an({trade_no:t.original.trade_no,commission_status:xe.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.createdAt")}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:we(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function ah(){const[s]=fr(),[n,t]=u.useState({}),[r,a]=u.useState({}),[i,l]=u.useState([]),[d,m]=u.useState([]),[o,c]=u.useState({pageIndex:0,pageSize:20});u.useEffect(()=>{const w=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([b,k])=>{const p=s.get(b);return p?{id:b,value:k==="number"?parseInt(p):p}:null}).filter(Boolean);w.length>0&&l(w)},[s]);const{refetch:h,data:_,isLoading:E}=re({queryKey:["orderList",o,i,d],queryFn:()=>td({pageSize:o.pageSize,current:o.pageIndex+1,filter:i,sort:d})}),C=ns({data:_?.data??[],columns:th(h),state:{sorting:d,columnVisibility:r,rowSelection:n,columnFilters:i,pagination:o},rowCount:_?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:m,onColumnFiltersChange:l,onColumnVisibilityChange:a,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),onPaginationChange:c,getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(hs,{table:C,toolbar:e.jsx(Wx,{table:C,refetch:h}),showPagination:!0})}function nh(){const{t:s}=V("order");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(ah,{})})]})]})}const rh=Object.freeze(Object.defineProperty({__proto__:null,default:nh},Symbol.toStringTag,{value:"Module"}));function lh({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(qt,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:a.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:a.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(xs,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Ms,{children:[e.jsx(Ks,{placeholder:n}),e.jsxs(Fs,{children:[e.jsx(Bs,{children:"No results found."}),e.jsx(Ye,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(Me,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx($s,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{}),e.jsx(Ye,{children:e.jsx(Me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const ih=x.object({id:x.coerce.number().nullable().optional(),name:x.string().min(1,"请输入优惠券名称"),code:x.string().nullable(),type:x.coerce.number(),value:x.coerce.number(),started_at:x.coerce.number(),ended_at:x.coerce.number(),limit_use:x.union([x.string(),x.number()]).nullable(),limit_use_with_user:x.union([x.string(),x.number()]).nullable(),generate_count:x.coerce.number().nullable().optional(),limit_plan_ids:x.array(x.coerce.number()).default([]).nullable(),limit_period:x.array(x.nativeEnum(xt)).default([]).nullable()}).refine(s=>s.ended_at>s.started_at,{message:"结束时间必须晚于开始时间",path:["ended_at"]}),xn={name:"",code:null,type:Be.AMOUNT,value:0,started_at:Math.floor(Date.now()/1e3),ended_at:Math.floor(Date.now()/1e3)+7*24*60*60,limit_use:null,limit_use_with_user:null,limit_plan_ids:[],limit_period:[],generate_count:null};function al({defaultValues:s,refetch:n,type:t="create",dialogTrigger:r=null,open:a,onOpenChange:i}){const{t:l}=V("coupon"),[d,m]=u.useState(!1),o=a??d,c=i??m,[h,_]=u.useState([]),E=ge({resolver:Ne(ih),defaultValues:s||xn});u.useEffect(()=>{s&&E.reset(s)},[s,E]),u.useEffect(()=>{qs().then(({data:b})=>_(b))},[]);const C=b=>{if(!b)return;const k=(p,v)=>{const M=new Date(v*1e3);return p.setHours(M.getHours(),M.getMinutes(),M.getSeconds()),Math.floor(p.getTime()/1e3)};b.from&&E.setValue("started_at",k(b.from,E.watch("started_at"))),b.to&&E.setValue("ended_at",k(b.to,E.watch("ended_at")))},S=async b=>{const k=await od(b);if(b.generate_count&&k){const p=new Blob([k],{type:"text/csv;charset=utf-8;"}),v=document.createElement("a");v.href=window.URL.createObjectURL(p),v.download=`coupons_${new Date().getTime()}.csv`,v.click(),window.URL.revokeObjectURL(v.href)}c(!1),t==="create"&&E.reset(xn),n()},w=(b,k)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:k}),e.jsx(T,{type:"datetime-local",step:"1",value:we(E.watch(b),"YYYY-MM-DDTHH:mm:ss"),onChange:p=>{const v=new Date(p.target.value);E.setValue(b,Math.floor(v.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(be,{open:o,onOpenChange:c,children:[r&&e.jsx(Je,{asChild:!0,children:r}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsx(Ce,{children:e.jsx(ye,{children:l(t==="create"?"form.add":"form.edit")})}),e.jsx(_e,{...E,children:e.jsxs("form",{onSubmit:E.handleSubmit(S),className:"space-y-4",children:[e.jsx(g,{control:E.control,name:"name",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.name.label")}),e.jsx(T,{placeholder:l("form.name.placeholder"),...b}),e.jsx(D,{})]})}),t==="create"&&e.jsx(g,{control:E.control,name:"generate_count",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.generateCount.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.generateCount.placeholder"),...b,value:b.value===void 0?"":b.value,onChange:k=>b.onChange(k.target.value===""?"":parseInt(k.target.value)),className:"h-9"}),e.jsx(F,{className:"text-xs",children:l("form.generateCount.description")}),e.jsx(D,{})]})}),(!E.watch("generate_count")||E.watch("generate_count")==null)&&e.jsx(g,{control:E.control,name:"code",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.code.label")}),e.jsx(T,{placeholder:l("form.code.placeholder"),...b,className:"h-9"}),e.jsx(F,{className:"text-xs",children:l("form.code.description")}),e.jsx(D,{})]})}),e.jsxs(f,{children:[e.jsx(j,{children:l("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(g,{control:E.control,name:"type",render:({field:b})=>e.jsxs(G,{value:b.value.toString(),onValueChange:k=>{const p=b.value,v=parseInt(k);b.onChange(v);const M=E.getValues("value");M&&(p===Be.AMOUNT&&v===Be.PERCENTAGE?E.setValue("value",M/100):p===Be.PERCENTAGE&&v===Be.AMOUNT&&E.setValue("value",M*100))},children:[e.jsx(K,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(W,{placeholder:l("form.type.placeholder")})}),e.jsx(B,{children:Object.entries(ju).map(([k,p])=>e.jsx(z,{value:k,children:l(`table.toolbar.types.${k}`)},k))})]})}),e.jsx(g,{control:E.control,name:"value",render:({field:b})=>{const k=b.value==null?"":E.watch("type")===Be.AMOUNT&&typeof b.value=="number"?(b.value/100).toString():b.value.toString();return e.jsx(T,{type:"number",placeholder:l("form.value.placeholder"),...b,value:k,onChange:p=>{const v=p.target.value;if(v===""){b.onChange("");return}const M=parseFloat(v);isNaN(M)||b.onChange(E.watch("type")===Be.AMOUNT?Math.round(M*100):M)},step:"any",min:0,className:"flex-[2] rounded-none border-x-0 text-left"})}}),e.jsx("div",{className:"flex min-w-[40px] items-center justify-center rounded-md rounded-l-none border border-l-0 border-input bg-muted/50 px-3 font-medium text-muted-foreground",children:e.jsx("span",{children:E.watch("type")==Be.AMOUNT?"¥":"%"})})]})]}),e.jsxs(f,{children:[e.jsx(j,{children:l("form.validity.label")}),e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(P,{variant:"outline",className:N("w-full justify-start text-left font-normal",!E.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(jt,{className:"mr-2 h-4 w-4"}),we(E.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",l("form.validity.to")," ",we(E.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})}),e.jsxs(xs,{className:"w-auto p-0",align:"start",children:[e.jsx("div",{className:"border-b border-border",children:e.jsx(Gs,{mode:"range",selected:{from:new Date(E.watch("started_at")*1e3),to:new Date(E.watch("ended_at")*1e3)},onSelect:C,numberOfMonths:2})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-4",children:[w("started_at",l("table.validity.startTime")),e.jsx("div",{className:"mt-6 text-sm text-muted-foreground",children:l("form.validity.to")}),w("ended_at",l("table.validity.endTime"))]})})]})]}),e.jsx(D,{})]}),e.jsx(g,{control:E.control,name:"limit_use",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.limitUse.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.limitUse.placeholder"),...b,value:b.value===null?"":b.value,onChange:k=>b.onChange(k.target.value===""?null:parseInt(k.target.value)),className:"h-9"}),e.jsx(F,{className:"text-xs",children:l("form.limitUse.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:E.control,name:"limit_use_with_user",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.limitUseWithUser.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.limitUseWithUser.placeholder"),...b,value:b.value===null?"":b.value,onChange:k=>b.onChange(k.target.value===""?null:parseInt(k.target.value)),className:"h-9"}),e.jsx(F,{className:"text-xs",children:l("form.limitUseWithUser.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:E.control,name:"limit_period",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.limitPeriod.label")}),e.jsx(at,{options:Object.entries(xt).filter(([k])=>isNaN(Number(k))).map(([k,p])=>({label:l(`coupon:period.${p}`),value:k})),onChange:k=>{if(k.length===0){b.onChange([]);return}const p=k.map(v=>xt[v.value]);b.onChange(p)},value:(b.value||[]).map(k=>({label:l(`coupon:period.${k}`),value:Object.entries(xt).find(([p,v])=>v===k)?.[0]||""})),placeholder:l("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPeriod.empty")})}),e.jsx(F,{className:"text-xs",children:l("form.limitPeriod.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:E.control,name:"limit_plan_ids",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.limitPlan.label")}),e.jsx(at,{options:h?.map(k=>({label:k.name,value:k.id.toString()}))||[],onChange:k=>b.onChange(k.map(p=>Number(p.value))),value:(h||[]).filter(k=>(b.value||[]).includes(k.id)).map(k=>({label:k.name,value:k.id.toString()})),placeholder:l("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPlan.empty")})}),e.jsx(D,{})]})}),e.jsx(ze,{children:e.jsx(P,{type:"submit",disabled:E.formState.isSubmitting,children:E.formState.isSubmitting?l("form.submit.saving"):l("form.submit.save")})})]})})]})]})}function oh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=V("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(al,{refetch:n,dialogTrigger:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("div",{children:r("form.add")})]})}),e.jsx(T,{placeholder:r("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(lh,{column:s.getColumn("type"),title:r("table.toolbar.type"),options:[{value:Be.AMOUNT,label:r(`table.toolbar.types.${Be.AMOUNT}`)},{value:Be.PERCENTAGE,label:r(`table.toolbar.types.${Be.PERCENTAGE}`)}]}),t&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]})}const nl=u.createContext(void 0);function ch({children:s,refetch:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(null),l=m=>{i(m),r(!0)},d=()=>{r(!1),i(null)};return e.jsxs(nl.Provider,{value:{isOpen:t,currentCoupon:a,openEdit:l,closeEdit:d},children:[s,a&&e.jsx(al,{defaultValues:a,refetch:n,type:"edit",open:t,onOpenChange:r})]})}function dh(){const s=u.useContext(nl);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const uh=s=>{const{t:n}=V("coupon");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(q,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx(Y,{defaultChecked:t.original.show,onCheckedChange:r=>{dd({id:t.original.id,show:r}).then(({data:a})=>!a&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.type")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:n(`table.toolbar.types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.code")}),cell:({row:t})=>e.jsx(q,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.limitUse")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:t.original.limit_use===null?n("table.validity.unlimited"):t.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.limitUseWithUser")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:t.original.limit_use_with_user===null?n("table.validity.noLimit"):t.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.validity")}),cell:({row:t})=>{const[r,a]=u.useState(!1),i=Date.now(),l=t.original.started_at*1e3,d=t.original.ended_at*1e3,m=i>d,o=ie.jsx(O,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>{const{openEdit:r}=dh();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>r(t.original),children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),e.jsx(Qe,{title:n("table.actions.deleteConfirm.title"),description:n("table.actions.deleteConfirm.description"),confirmText:n("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{cd({id:t.original.id}).then(({data:a})=>{a&&(A.success("删除成功"),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("table.actions.delete")})]})})]})}}]};function mh(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),[m,o]=u.useState({pageIndex:0,pageSize:20}),{refetch:c,data:h}=re({queryKey:["couponList",m,a,l],queryFn:()=>id({pageSize:m.pageSize,current:m.pageIndex+1,filter:a,sort:l})}),_=ns({data:h?.data??[],columns:uh(c),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:m},pageCount:Math.ceil((h?.total??0)/m.pageSize),rowCount:h?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:o,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ch,{refetch:c,children:e.jsx("div",{className:"space-y-4",children:e.jsx(hs,{table:_,toolbar:e.jsx(oh,{table:_,refetch:c})})})})}function xh(){const{t:s}=V("coupon");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(mh,{})})]})]})}const hh=Object.freeze(Object.defineProperty({__proto__:null,default:xh},Symbol.toStringTag,{value:"Module"})),ph=1,fh=1e6;let ua=0;function gh(){return ua=(ua+1)%Number.MAX_SAFE_INTEGER,ua.toString()}const ma=new Map,hn=s=>{if(ma.has(s))return;const n=setTimeout(()=>{ma.delete(s),ht({type:"REMOVE_TOAST",toastId:s})},fh);ma.set(s,n)},jh=(s,n)=>{switch(n.type){case"ADD_TOAST":return{...s,toasts:[n.toast,...s.toasts].slice(0,ph)};case"UPDATE_TOAST":return{...s,toasts:s.toasts.map(t=>t.id===n.toast.id?{...t,...n.toast}:t)};case"DISMISS_TOAST":{const{toastId:t}=n;return t?hn(t):s.toasts.forEach(r=>{hn(r.id)}),{...s,toasts:s.toasts.map(r=>r.id===t||t===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return n.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==n.toastId)}}},Pt=[];let Et={toasts:[]};function ht(s){Et=jh(Et,s),Pt.forEach(n=>{n(Et)})}function vh({...s}){const n=gh(),t=a=>ht({type:"UPDATE_TOAST",toast:{...a,id:n}}),r=()=>ht({type:"DISMISS_TOAST",toastId:n});return ht({type:"ADD_TOAST",toast:{...s,id:n,open:!0,onOpenChange:a=>{a||r()}}}),{id:n,dismiss:r,update:t}}function rl(){const[s,n]=u.useState(Et);return u.useEffect(()=>(Pt.push(n),()=>{const t=Pt.indexOf(n);t>-1&&Pt.splice(t,1)}),[s]),{...s,toast:vh,dismiss:t=>ht({type:"DISMISS_TOAST",toastId:t})}}function bh({open:s,onOpenChange:n,table:t}){const{t:r}=V("user"),{toast:a}=rl(),[i,l]=u.useState(!1),[d,m]=u.useState(""),[o,c]=u.useState(""),h=async()=>{if(!d||!o){a({title:r("messages.error"),description:r("messages.send_mail.required_fields"),variant:"destructive"});return}try{l(!0),await Ot.sendMail({subject:d,content:o,filter:t.getState().columnFilters,sort:t.getState().sorting[0]?.id,sort_type:t.getState().sorting[0]?.desc?"DESC":"ASC"}),a({title:r("messages.success"),description:r("messages.send_mail.success")}),n(!1),m(""),c("")}catch{a({title:r("messages.error"),description:r("messages.send_mail.failed"),variant:"destructive"})}finally{l(!1)}};return e.jsx(be,{open:s,onOpenChange:n,children:e.jsxs(fe,{className:"sm:max-w-[500px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:r("send_mail.title")}),e.jsx(Te,{children:r("send_mail.description")})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"subject",className:"text-right",children:r("send_mail.subject")}),e.jsx(T,{id:"subject",value:d,onChange:_=>m(_.target.value),className:"col-span-3"})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"content",className:"text-right",children:r("send_mail.content")}),e.jsx(ys,{id:"content",value:o,onChange:_=>c(_.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(ze,{children:e.jsx(J,{type:"submit",onClick:h,disabled:i,children:r(i?"send_mail.sending":"send_mail.send")})})]})})}const yh=x.object({email_prefix:x.string().optional(),email_suffix:x.string().min(1),password:x.string().optional(),expired_at:x.number().optional().nullable(),plan_id:x.number().nullable(),generate_count:x.number().optional().nullable()}).refine(s=>s.generate_count===null?s.email_prefix!==void 0&&s.email_prefix!=="":!0,{message:"Email prefix is required when generate_count is null",path:["email_prefix"]}),Nh={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0};function _h({refetch:s}){const{t:n}=V("user"),[t,r]=u.useState(!1),a=ge({resolver:Ne(yh),defaultValues:Nh,mode:"onChange"}),[i,l]=u.useState([]);return u.useEffect(()=>{t&&qs().then(({data:d})=>{d&&l(d)})},[t]),e.jsxs(be,{open:t,onOpenChange:r,children:[e.jsx(Je,{asChild:!0,children:e.jsxs(J,{size:"sm",variant:"outline",className:"space-x-2 gap-0",children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:n("generate.title")}),e.jsx(Te,{})]}),e.jsxs(_e,{...a,children:[e.jsxs(f,{children:[e.jsx(j,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!a.watch("generate_count")&&e.jsx(g,{control:a.control,name:"email_prefix",render:({field:d})=>e.jsx(T,{className:"flex-[5] rounded-r-none",placeholder:n("generate.form.email_prefix"),...d})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${a.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(g,{control:a.control,name:"email_suffix",render:({field:d})=>e.jsx(T,{className:"flex-[4] rounded-l-none",placeholder:n("generate.form.email_domain"),...d})})]})]}),e.jsx(g,{control:a.control,name:"password",render:({field:d})=>e.jsxs(f,{children:[e.jsx(j,{children:n("generate.form.password")}),e.jsx(T,{placeholder:n("generate.form.password_placeholder"),...d}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"expired_at",render:({field:d})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(j,{children:n("generate.form.expire_time")}),e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsx(y,{children:e.jsxs(J,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!d.value&&"text-muted-foreground"),children:[d.value?we(d.value):e.jsx("span",{children:n("generate.form.expire_time_placeholder")}),e.jsx(jt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(xs,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(Wo,{asChild:!0,children:e.jsx(J,{variant:"outline",className:"w-full",onClick:()=>{d.onChange(null)},children:n("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Gs,{mode:"single",selected:d.value?new Date(d.value*1e3):void 0,onSelect:m=>{m&&d.onChange(m?.getTime()/1e3)}})})]})]})]})}),e.jsx(g,{control:a.control,name:"plan_id",render:({field:d})=>e.jsxs(f,{children:[e.jsx(j,{children:n("generate.form.subscription")}),e.jsx(y,{children:e.jsxs(G,{value:d.value?d.value.toString():"null",onValueChange:m=>d.onChange(m==="null"?null:parseInt(m)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(B,{children:[e.jsx(z,{value:"null",children:n("generate.form.subscription_none")}),i.map(m=>e.jsx(z,{value:m.id.toString(),children:m.name},m.id))]})]})})]})}),!a.watch("email_prefix")&&e.jsx(g,{control:a.control,name:"generate_count",render:({field:d})=>e.jsxs(f,{children:[e.jsx(j,{children:n("generate.form.generate_count")}),e.jsx(T,{type:"number",placeholder:n("generate.form.generate_count_placeholder"),value:d.value||"",onChange:m=>d.onChange(m.target.value?parseInt(m.target.value):null)})]})})]}),e.jsxs(ze,{children:[e.jsx(J,{variant:"outline",onClick:()=>r(!1),children:n("generate.form.cancel")}),e.jsx(J,{onClick:()=>a.handleSubmit(d=>{hd(d).then(({data:m})=>{m&&(A.success(n("generate.form.success")),a.reset(),s(),r(!1))})})(),children:n("generate.form.submit")})]})]})]})}const ll=Nn,wh=_n,Ch=wn,il=u.forwardRef(({className:s,...n},t)=>e.jsx(zt,{className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:t}));il.displayName=zt.displayName;const Sh=As("fixed overflow-y-scroll z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-md",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-md"}},defaultVariants:{side:"right"}}),Aa=u.forwardRef(({side:s="right",className:n,children:t,...r},a)=>e.jsxs(Ch,{children:[e.jsx(il,{}),e.jsxs(At,{ref:a,className:N(Sh({side:s}),n),...r,children:[e.jsxs(Ca,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[e.jsx(ss,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),t]})]}));Aa.displayName=At.displayName;const $a=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-2 text-center sm:text-left",s),...n});$a.displayName="SheetHeader";const ol=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});ol.displayName="SheetFooter";const Ua=u.forwardRef(({className:s,...n},t)=>e.jsx($t,{ref:t,className:N("text-lg font-semibold text-foreground",s),...n}));Ua.displayName=$t.displayName;const Ha=u.forwardRef(({className:s,...n},t)=>e.jsx(Ut,{ref:t,className:N("text-sm text-muted-foreground",s),...n}));Ha.displayName=Ut.displayName;function kh({table:s,refetch:n,permissionGroups:t=[],subscriptionPlans:r=[]}){const{t:a}=V("user"),{toast:i}=rl(),l=s.getState().columnFilters.length>0,[d,m]=u.useState([]),[o,c]=u.useState(!1),[h,_]=u.useState(!1),[E,C]=u.useState(!1),[S,w]=u.useState(!1),b=async()=>{try{const Q=await Ot.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),te=Q;console.log(Q);const $=new Blob([te],{type:"text/csv;charset=utf-8;"}),R=window.URL.createObjectURL($),X=document.createElement("a");X.href=R,X.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(X),X.click(),X.remove(),window.URL.revokeObjectURL(R),i({title:a("messages.success"),description:a("messages.export.success")})}catch{i({title:a("messages.error"),description:a("messages.export.failed"),variant:"destructive"})}},k=async()=>{try{w(!0),await Ot.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),i({title:a("messages.success"),description:a("messages.batch_ban.success")}),n()}catch{i({title:a("messages.error"),description:a("messages.batch_ban.failed"),variant:"destructive"})}finally{w(!1),C(!1)}},p=[{label:a("filter.fields.email"),value:"email",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.id"),value:"id",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.plan_id"),value:"plan_id",type:"select",operators:[{label:a("filter.operators.eq"),value:"eq"}],useOptions:!0},{label:a("filter.fields.transfer_enable"),value:"transfer_enable",type:"number",unit:"GB",operators:[{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.total_used"),value:"total_used",type:"number",unit:"GB",operators:[{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.online_count"),value:"online_count",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"},{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"}]},{label:a("filter.fields.expired_at"),value:"expired_at",type:"date",operators:[{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.uuid"),value:"uuid",type:"text",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.token"),value:"token",type:"text",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.banned"),value:"banned",type:"select",operators:[{label:a("filter.operators.eq"),value:"eq"}],options:[{label:a("filter.status.normal"),value:"0"},{label:a("filter.status.banned"),value:"1"}]},{label:a("filter.fields.remark"),value:"remarks",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.inviter_email"),value:"invite_user.email",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.invite_user_id"),value:"invite_user_id",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.is_admin"),value:"is_admin",type:"boolean",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.is_staff"),value:"is_staff",type:"boolean",operators:[{label:a("filter.operators.eq"),value:"eq"}]}],v=Q=>Q*1024*1024*1024,M=Q=>Q/(1024*1024*1024),H=()=>{m([...d,{field:"",operator:"",value:""}])},se=Q=>{m(d.filter((te,$)=>$!==Q))},L=(Q,te,$)=>{const R=[...d];if(R[Q]={...R[Q],[te]:$},te==="field"){const X=p.find(Ns=>Ns.value===$);X&&(R[Q].operator=X.operators[0].value,R[Q].value=X.type==="boolean"?!1:"")}m(R)},Z=(Q,te)=>{const $=p.find(R=>R.value===Q.field);if(!$)return null;switch($.type){case"text":return e.jsx(T,{placeholder:a("filter.sheet.value"),value:Q.value,onChange:R=>L(te,"value",R.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(T,{type:"number",placeholder:a("filter.sheet.value_number",{unit:$.unit}),value:$.unit==="GB"?M(Q.value||0):Q.value,onChange:R=>{const X=Number(R.target.value);L(te,"value",$.unit==="GB"?v(X):X)}}),$.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:$.unit})]});case"date":return e.jsx(Gs,{mode:"single",selected:Q.value,onSelect:R=>L(te,"value",R),className:"flex flex-1 justify-center rounded-md border"});case"select":return e.jsxs(G,{value:Q.value,onValueChange:R=>L(te,"value",R),children:[e.jsx(K,{children:e.jsx(W,{placeholder:a("filter.sheet.value")})}),e.jsx(B,{children:$.useOptions?r.map(R=>e.jsx(z,{value:R.value.toString(),children:R.label},R.value)):$.options?.map(R=>e.jsx(z,{value:R.value.toString(),children:R.label},R.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Y,{checked:Q.value,onCheckedChange:R=>L(te,"value",R)}),e.jsx(Mt,{children:Q.value?a("filter.boolean.true"):a("filter.boolean.false")})]});default:return null}},de=()=>{const Q=d.filter(te=>te.field&&te.operator&&te.value!=="").map(te=>{const $=p.find(X=>X.value===te.field);let R=te.value;return te.operator==="contains"?{id:te.field,value:R}:($?.type==="date"&&R instanceof Date&&(R=Math.floor(R.getTime()/1e3)),$?.type==="boolean"&&(R=R?1:0),{id:te.field,value:`${te.operator}:${R}`})});s.setColumnFilters(Q),c(!1)};return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-2",children:[e.jsx(_h,{refetch:n}),e.jsx(T,{placeholder:a("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:Q=>s.getColumn("email")?.setFilterValue(Q.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(ll,{open:o,onOpenChange:c,children:[e.jsx(wh,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Yo,{className:"mr-2 h-4 w-4"}),a("filter.advanced"),d.length>0&&e.jsx(q,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:d.length})]})}),e.jsxs(Aa,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs($a,{children:[e.jsx(Ua,{children:a("filter.sheet.title")}),e.jsx(Ha,{children:a("filter.sheet.description")})]}),e.jsxs("div",{className:"mt-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:a("filter.sheet.conditions")}),e.jsx(P,{variant:"outline",size:"sm",onClick:H,children:a("filter.sheet.add")})]}),e.jsx(zs,{className:"h-[calc(100vh-280px)] ",children:e.jsx("div",{className:"space-y-4",children:d.map((Q,te)=>e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Mt,{children:a("filter.sheet.condition",{number:te+1})}),e.jsx(P,{variant:"ghost",size:"sm",onClick:()=>se(te),children:e.jsx(ss,{className:"h-4 w-4"})})]}),e.jsxs(G,{value:Q.field,onValueChange:$=>L(te,"field",$),children:[e.jsx(K,{children:e.jsx(W,{placeholder:a("filter.sheet.field")})}),e.jsx(B,{children:e.jsx(He,{children:p.map($=>e.jsx(z,{value:$.value,className:"cursor-pointer",children:$.label},$.value))})})]}),Q.field&&e.jsxs(G,{value:Q.operator,onValueChange:$=>L(te,"operator",$),children:[e.jsx(K,{children:e.jsx(W,{placeholder:a("filter.sheet.operator")})}),e.jsx(B,{children:p.find($=>$.value===Q.field)?.operators.map($=>e.jsx(z,{value:$.value,children:$.label},$.value))})]}),Q.field&&Q.operator&&Z(Q,te)]},te))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(P,{variant:"outline",onClick:()=>{m([]),c(!1)},children:a("filter.sheet.reset")}),e.jsx(P,{onClick:de,children:a("filter.sheet.apply")})]})]})]})]}),l&&e.jsxs(P,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),m([])},className:"h-8 px-2 lg:px-3",children:[a("reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]}),e.jsxs(Ss,{modal:!1,children:[e.jsx(ks,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:a("actions.title")})}),e.jsxs(fs,{children:[e.jsx(je,{onClick:()=>_(!0),children:a("actions.send_email")}),e.jsx(je,{onClick:b,children:a("actions.export_csv")}),e.jsx(tt,{}),e.jsx(je,{onClick:()=>C(!0),className:"text-red-600 focus:text-red-600",children:a("actions.batch_ban")})]})]})]}),e.jsx(bh,{open:h,onOpenChange:_,table:s}),e.jsx(Oa,{open:E,onOpenChange:C,children:e.jsxs(Yt,{children:[e.jsxs(Qt,{children:[e.jsx(Xt,{children:a("actions.confirm_ban.title")}),e.jsx(Zt,{children:a(l?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(Jt,{children:[e.jsx(sa,{disabled:S,children:a("actions.confirm_ban.cancel")}),e.jsx(ea,{onClick:k,disabled:S,className:"bg-red-600 hover:bg-red-700 focus:ring-red-600",children:a(S?"actions.confirm_ban.banning":"actions.confirm_ban.confirm")})]})]})})]})}const cl=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"m17.71 11.29l-5-5a1 1 0 0 0-.33-.21a1 1 0 0 0-.76 0a1 1 0 0 0-.33.21l-5 5a1 1 0 0 0 1.42 1.42L11 9.41V17a1 1 0 0 0 2 0V9.41l3.29 3.3a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42"})}),dl=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17.71 11.29a1 1 0 0 0-1.42 0L13 14.59V7a1 1 0 0 0-2 0v7.59l-3.29-3.3a1 1 0 0 0-1.42 1.42l5 5a1 1 0 0 0 .33.21a.94.94 0 0 0 .76 0a1 1 0 0 0 .33-.21l5-5a1 1 0 0 0 0-1.42"})}),Th=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17 11H9.41l3.3-3.29a1 1 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33a1 1 0 0 0 0 .76a1 1 0 0 0 .21.33l5 5a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42L9.41 13H17a1 1 0 0 0 0-2"})}),Dh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17.92 11.62a1 1 0 0 0-.21-.33l-5-5a1 1 0 0 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0l5-5a1 1 0 0 0 .21-.33a1 1 0 0 0 0-.76"})}),xa=[{accessorKey:"record_at",header:"时间",cell:({row:s})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("time",{className:"text-sm text-muted-foreground",children:xc(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(cl,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:ps(s.original.u)})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(dl,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:ps(s.original.d)})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const n=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(q,{variant:"outline",className:"font-mono",children:[n,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const n=s.original.u+s.original.d;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:ps(n)})}}];function ul({user_id:s,dialogTrigger:n}){const{t}=V(["traffic"]),[r,a]=u.useState(!1),[i,l]=u.useState({pageIndex:0,pageSize:20}),{data:d,isLoading:m}=re({queryKey:["userStats",s,i,r],queryFn:()=>r?pd({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),o=ns({data:d?.data??[],columns:xa,pageCount:Math.ceil((d?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:rs(),onPaginationChange:l});return e.jsxs(be,{open:r,onOpenChange:a,children:[e.jsx(Je,{asChild:!0,children:n}),e.jsxs(fe,{className:"sm:max-w-[700px]",children:[e.jsx(Ce,{children:e.jsx(ye,{children:t("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Ia,{children:[e.jsx(Va,{children:o.getHeaderGroups().map(c=>e.jsx(Is,{children:c.headers.map(h=>e.jsx(Fa,{className:N("h-10 px-2 text-xs",h.id==="total"&&"text-right"),children:h.isPlaceholder?null:Rt(h.column.columnDef.header,h.getContext())},h.id))},c.id))}),e.jsx(Ma,{children:m?Array.from({length:i.pageSize}).map((c,h)=>e.jsx(Is,{children:Array.from({length:xa.length}).map((_,E)=>e.jsx(Zs,{className:"p-2",children:e.jsx(oe,{className:"h-6 w-full"})},E))},h)):o.getRowModel().rows?.length?o.getRowModel().rows.map(c=>e.jsx(Is,{"data-state":c.getIsSelected()&&"selected",className:"h-10",children:c.getVisibleCells().map(h=>e.jsx(Zs,{className:"px-2",children:Rt(h.column.columnDef.cell,h.getContext())},h.id))},c.id)):e.jsx(Is,{children:e.jsx(Zs,{colSpan:xa.length,className:"h-24 text-center",children:t("trafficRecord.noRecords")})})})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.perPage")}),e.jsxs(G,{value:`${o.getState().pagination.pageSize}`,onValueChange:c=>{o.setPageSize(Number(c))},children:[e.jsx(K,{className:"h-8 w-[70px]",children:e.jsx(W,{placeholder:o.getState().pagination.pageSize})}),e.jsx(B,{side:"top",children:[10,20,30,40,50].map(c=>e.jsx(z,{value:`${c}`,children:c},c))})]}),e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.records")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"flex w-[100px] items-center justify-center text-sm",children:t("trafficRecord.page",{current:o.getState().pagination.pageIndex+1,total:o.getPageCount()})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>o.previousPage(),disabled:!o.getCanPreviousPage()||m,children:e.jsx(Th,{className:"h-4 w-4"})}),e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>o.nextPage(),disabled:!o.getCanNextPage()||m,children:e.jsx(Dh,{className:"h-4 w-4"})})]})]})]})]})]})]})}function Ph({onConfirm:s,children:n,title:t="确认操作",description:r="确定要执行此操作吗?",cancelText:a="取消",confirmText:i="确认",variant:l="default",className:d}){return e.jsxs(Oa,{children:[e.jsx(Kr,{asChild:!0,children:n}),e.jsxs(Yt,{className:N("sm:max-w-[425px]",d),children:[e.jsxs(Qt,{children:[e.jsx(Xt,{children:t}),e.jsx(Zt,{children:r})]}),e.jsxs(Jt,{children:[e.jsx(sa,{asChild:!0,children:e.jsx(P,{variant:"outline",children:a})}),e.jsx(ea,{asChild:!0,children:e.jsx(P,{variant:l,onClick:s,children:i})})]})]})]})}const Eh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M5 18h4.24a1 1 0 0 0 .71-.29l6.92-6.93L19.71 8a1 1 0 0 0 0-1.42l-4.24-4.29a1 1 0 0 0-1.42 0l-2.82 2.83l-6.94 6.93a1 1 0 0 0-.29.71V17a1 1 0 0 0 1 1m9.76-13.59l2.83 2.83l-1.42 1.42l-2.83-2.83ZM6 13.17l5.93-5.93l2.83 2.83L8.83 16H6ZM21 20H3a1 1 0 0 0 0 2h18a1 1 0 0 0 0-2"})}),Rh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 11h-6V5a1 1 0 0 0-2 0v6H5a1 1 0 0 0 0 2h6v6a1 1 0 0 0 2 0v-6h6a1 1 0 0 0 0-2"})}),Ih=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21 8.94a1.3 1.3 0 0 0-.06-.27v-.09a1 1 0 0 0-.19-.28l-6-6a1 1 0 0 0-.28-.19a.3.3 0 0 0-.09 0a.9.9 0 0 0-.33-.11H10a3 3 0 0 0-3 3v1H6a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3v-1h1a3 3 0 0 0 3-3zm-6-3.53L17.59 8H16a1 1 0 0 1-1-1ZM15 19a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1h1v7a3 3 0 0 0 3 3h5Zm4-4a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h3v3a3 3 0 0 0 3 3h3Z"})}),Vh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21 11a1 1 0 0 0-1 1a8.05 8.05 0 1 1-2.22-5.5h-2.4a1 1 0 0 0 0 2h4.53a1 1 0 0 0 1-1V3a1 1 0 0 0-2 0v1.77A10 10 0 1 0 22 12a1 1 0 0 0-1-1"})}),Mh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M9.5 10.5H12a1 1 0 0 0 0-2h-1V8a1 1 0 0 0-2 0v.55a2.5 2.5 0 0 0 .5 4.95h1a.5.5 0 0 1 0 1H8a1 1 0 0 0 0 2h1v.5a1 1 0 0 0 2 0v-.55a2.5 2.5 0 0 0-.5-4.95h-1a.5.5 0 0 1 0-1M21 12h-3V3a1 1 0 0 0-.5-.87a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0A1 1 0 0 0 2 3v16a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3v-6a1 1 0 0 0-1-1M5 20a1 1 0 0 1-1-1V4.73l2 1.14a1.08 1.08 0 0 0 1 0l3-1.72l3 1.72a1.08 1.08 0 0 0 1 0l2-1.14V19a3 3 0 0 0 .18 1Zm15-1a1 1 0 0 1-2 0v-5h2Z"})}),Fh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M12.3 12.22A4.92 4.92 0 0 0 14 8.5a5 5 0 0 0-10 0a4.92 4.92 0 0 0 1.7 3.72A8 8 0 0 0 1 19.5a1 1 0 0 0 2 0a6 6 0 0 1 12 0a1 1 0 0 0 2 0a8 8 0 0 0-4.7-7.28M9 11.5a3 3 0 1 1 3-3a3 3 0 0 1-3 3m9.74.32A5 5 0 0 0 15 3.5a1 1 0 0 0 0 2a3 3 0 0 1 3 3a3 3 0 0 1-1.5 2.59a1 1 0 0 0-.5.84a1 1 0 0 0 .45.86l.39.26l.13.07a7 7 0 0 1 4 6.38a1 1 0 0 0 2 0a9 9 0 0 0-4.23-7.68"})}),Oh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M12 2a10 10 0 0 0-6.88 2.77V3a1 1 0 0 0-2 0v4.5a1 1 0 0 0 1 1h4.5a1 1 0 0 0 0-2h-2.4A8 8 0 1 1 4 12a1 1 0 0 0-2 0A10 10 0 1 0 12 2m0 6a1 1 0 0 0-1 1v3a1 1 0 0 0 1 1h2a1 1 0 0 0 0-2h-1V9a1 1 0 0 0-1-1"})}),Lh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M20 6h-4V5a3 3 0 0 0-3-3h-2a3 3 0 0 0-3 3v1H4a1 1 0 0 0 0 2h1v11a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3V8h1a1 1 0 0 0 0-2M10 5a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v1h-4Zm7 14a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V8h10Z"})}),zh=(s,n,t,r)=>{const{t:a}=V("user");return[{accessorKey:"is_admin",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l)),size:0},{accessorKey:"is_staff",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l)),size:0},{accessorKey:"id",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.id")}),cell:({row:i})=>e.jsx(q,{variant:"outline",children:i.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.email")}),cell:({row:i})=>{const l=i.original.t||0,d=Date.now()/1e3-l<120,m=Math.floor(Date.now()/1e3-l);let o=d?a("columns.online_status.online"):l===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:we(l)});if(!d&&l!==0){const c=Math.floor(m/60),h=Math.floor(c/60),_=Math.floor(h/24);_>0?o+=` +`))}})})}),e.jsx(D,{})]})}),e.jsx(g,{control:i.control,name:"action",render:({field:m})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:m.onChange,defaultValue:m.value,children:[e.jsx(K,{children:e.jsx(W,{placeholder:a("form.actionPlaceholder")})}),e.jsxs(B,{children:[e.jsx(z,{value:"block",children:a("actions.block")}),e.jsx(z,{value:"dns",children:a("actions.dns")})]})]})})}),e.jsx(D,{})]})}),i.watch("action")==="dns"&&e.jsx(g,{control:i.control,name:"action_value",render:({field:m})=>e.jsxs(f,{children:[e.jsx(j,{children:a("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(T,{type:"text",placeholder:a("form.dnsPlaceholder"),...m})})})]})}),e.jsxs(ze,{children:[e.jsx(yt,{asChild:!0,children:e.jsx(P,{variant:"outline",children:a("form.cancel")})}),e.jsx(P,{type:"submit",onClick:()=>{Mc(i.getValues()).then(({data:m})=>{m&&(d(!1),s&&s(),toast.success(a(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),i.reset())})},children:a("form.submit")})]})]})]})]})}function Rx({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=V("route");return e.jsx("div",{className:"flex items-center justify-between ",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[e.jsx(Zr,{refetch:n}),e.jsx(T,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("remarks")?.getFilterValue()??"",onChange:a=>s.getColumn("remarks")?.setFilterValue(a.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),t&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]})})}function Ix({columns:s,data:n,refetch:t}){const[r,a]=u.useState({}),[i,l]=u.useState({}),[d,m]=u.useState([]),[o,c]=u.useState([]),h=ns({data:n,columns:s,state:{sorting:o,columnVisibility:i,rowSelection:r,columnFilters:d},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:c,onColumnFiltersChange:m,onColumnVisibilityChange:l,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(hs,{table:h,toolbar:_=>e.jsx(Rx,{table:_,refetch:t})})}const Vx=s=>{const{t:n}=V("route"),t={block:{icon:Uo,variant:"destructive",className:"bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-800"},dns:{icon:Ho,variant:"secondary",className:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-800"}};return[{accessorKey:"id",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.id")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(q,{variant:"outline",children:r.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.remarks")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:r.original.remarks})}),enableHiding:!1,enableSorting:!1},{accessorKey:"action_value",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.action_value.title")}),cell:({row:r})=>{const a=r.original.action,i=r.original.action_value,l=r.original.match?.length||0;return e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("span",{className:"text-sm font-medium",children:a==="dns"&&i?n("columns.action_value.dns",{value:i}):a==="block"?e.jsx("span",{className:"text-destructive",children:n("columns.action_value.block")}):n("columns.action_value.direct")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("columns.matchRules",{count:l})})]})},enableHiding:!1,enableSorting:!1,size:300},{accessorKey:"action",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.action")}),cell:({row:r})=>{const a=r.getValue("action"),i=t[a]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(q,{variant:t[a]?.variant||"default",className:N("flex items-center gap-1.5 px-3 py-1 capitalize",t[a]?.className),children:[i&&e.jsx(i,{className:"h-3.5 w-3.5"}),n(`actions.${a}`)]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:n("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Zr,{defaultValues:r.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(Qe,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Fc({id:r.original.id}).then(({data:a})=>{a&&(A.success(n("messages.deleteSuccess")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("messages.deleteButton")})]})})]})}]};function Mx(){const{t:s}=V("route"),[n,t]=u.useState([]);function r(){Sr().then(({data:a})=>{t(a)})}return u.useEffect(()=>{r()},[]),e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Ix,{data:n,columns:Vx(r),refetch:r})})]})]})}const Fx=Object.freeze(Object.defineProperty({__proto__:null,default:Mx},Symbol.toStringTag,{value:"Module"})),el=u.createContext(void 0);function Ox({children:s,refreshData:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(null);return e.jsx(el.Provider,{value:{isOpen:t,setIsOpen:r,editingPlan:a,setEditingPlan:i,refreshData:n},children:s})}function za(){const s=u.useContext(el);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function Lx({table:s,saveOrder:n,isSortMode:t}){const{setIsOpen:r}=za(),{t:a}=V("subscribe");return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsxs(P,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>r(!0),children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("div",{children:a("plan.add")})]}),e.jsx(T,{placeholder:a("plan.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:i=>s.getColumn("name")?.setFilterValue(i.target.value),className:"h-8 w-[150px] lg:w-[250px]"})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{variant:t?"default":"outline",onClick:n,size:"sm",children:a(t?"plan.sort.save":"plan.sort.edit")})})]})}const mn={monthly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},quarterly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},half_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},two_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},three_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},onetime:{color:"text-slate-700",bgColor:"bg-slate-100/80"},reset_traffic:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},zx=s=>{const{t:n}=V("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(Ht,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(q,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.show")}),cell:({row:t})=>e.jsx(Y,{defaultChecked:t.getValue("show"),onCheckedChange:r=>{aa({id:t.original.id,show:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.sell")}),cell:({row:t})=>e.jsx(Y,{defaultChecked:t.getValue("sell"),onCheckedChange:r=>{aa({id:t.original.id,sell:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.renew"),tooltip:n("plan.columns.renew_tooltip")}),cell:({row:t})=>e.jsx(Y,{defaultChecked:t.getValue("renew"),onCheckedChange:r=>{aa({id:t.original.id,renew:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:t.getValue("name")})}),enableSorting:!1,enableHiding:!1,size:900},{accessorKey:"users_count",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.stats")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-2",children:[e.jsx(gt,{}),e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:t.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"group",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.group")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[600px] flex-wrap items-center gap-1.5 text-nowrap",children:e.jsx(q,{variant:"secondary",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:t.getValue("group")?.name})}),enableSorting:!1,enableHiding:!1},{accessorKey:"prices",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.price")}),cell:({row:t})=>{const r=t.getValue("prices"),a=[{period:n("plan.columns.price_period.monthly"),key:"monthly",unit:n("plan.columns.price_period.unit.month")},{period:n("plan.columns.price_period.quarterly"),key:"quarterly",unit:n("plan.columns.price_period.unit.quarter")},{period:n("plan.columns.price_period.half_yearly"),key:"half_yearly",unit:n("plan.columns.price_period.unit.half_year")},{period:n("plan.columns.price_period.yearly"),key:"yearly",unit:n("plan.columns.price_period.unit.year")},{period:n("plan.columns.price_period.two_yearly"),key:"two_yearly",unit:n("plan.columns.price_period.unit.two_year")},{period:n("plan.columns.price_period.three_yearly"),key:"three_yearly",unit:n("plan.columns.price_period.unit.three_year")},{period:n("plan.columns.price_period.onetime"),key:"onetime",unit:""},{period:n("plan.columns.price_period.reset_traffic"),key:"reset_traffic",unit:n("plan.columns.price_period.unit.times")}];return e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:a.map(({period:i,key:l,unit:d})=>r[l]!=null&&e.jsxs(q,{variant:"secondary",className:N("px-2 py-0.5 font-medium transition-colors text-nowrap",mn[l].color,mn[l].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[i," ¥",r[l],d]},l))})},enableSorting:!1,size:9e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("plan.columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingPlan:a}=za();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{a(t.original),r(!0)},children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.edit")})]}),e.jsx(Qe,{title:n("plan.columns.delete_confirm.title"),description:n("plan.columns.delete_confirm.description"),confirmText:n("plan.columns.delete"),variant:"destructive",onConfirm:async()=>{ed({id:t.original.id}).then(({data:i})=>{i&&(A.success(n("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.delete")})]})})]})}}]},Ax=x.object({id:x.number().nullable(),group_id:x.union([x.number(),x.string()]).nullable().optional(),name:x.string().min(1).max(250),content:x.string().nullable().optional(),transfer_enable:x.union([x.number().min(0),x.string().min(1)]),prices:x.object({monthly:x.union([x.number(),x.string()]).nullable().optional(),quarterly:x.union([x.number(),x.string()]).nullable().optional(),half_yearly:x.union([x.number(),x.string()]).nullable().optional(),yearly:x.union([x.number(),x.string()]).nullable().optional(),two_yearly:x.union([x.number(),x.string()]).nullable().optional(),three_yearly:x.union([x.number(),x.string()]).nullable().optional(),onetime:x.union([x.number(),x.string()]).nullable().optional(),reset_traffic:x.union([x.number(),x.string()]).nullable().optional()}).default({}),speed_limit:x.union([x.number(),x.string()]).nullable().optional(),capacity_limit:x.union([x.number(),x.string()]).nullable().optional(),device_limit:x.union([x.number(),x.string()]).nullable().optional(),force_update:x.boolean().optional(),reset_traffic_method:x.number().nullable(),users_count:x.number().optional()}),sl=u.forwardRef(({className:s,...n},t)=>e.jsx(mr,{ref:t,className:N("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...n,children:e.jsx(qo,{className:N("flex items-center justify-center text-current"),children:e.jsx($s,{className:"h-4 w-4"})})}));sl.displayName=mr.displayName;const St={id:null,group_id:null,name:"",content:"",transfer_enable:"",prices:{monthly:"",quarterly:"",half_yearly:"",yearly:"",two_yearly:"",three_yearly:"",onetime:"",reset_traffic:""},speed_limit:"",capacity_limit:"",device_limit:"",force_update:!1,reset_traffic_method:null},kt={monthly:{label:"月付",months:1,discount:1},quarterly:{label:"季付",months:3,discount:.95},half_yearly:{label:"半年付",months:6,discount:.9},yearly:{label:"年付",months:12,discount:.85},two_yearly:{label:"两年付",months:24,discount:.8},three_yearly:{label:"三年付",months:36,discount:.75},onetime:{label:"流量包",months:1,discount:1},reset_traffic:{label:"重置包",months:1,discount:1}},$x=[{value:null,label:"follow_system"},{value:0,label:"monthly_first"},{value:1,label:"monthly_reset"},{value:2,label:"no_reset"},{value:3,label:"yearly_first"},{value:4,label:"yearly_reset"}];function Ux(){const{isOpen:s,setIsOpen:n,editingPlan:t,setEditingPlan:r,refreshData:a}=za(),[i,l]=u.useState(!1),{t:d}=V("subscribe"),m=ge({resolver:Ne(Ax),defaultValues:{...St,...t||{}},mode:"onChange"});u.useEffect(()=>{t?m.reset({...St,...t}):m.reset(St)},[t,m]);const o=new Pa({html:!0}),[c,h]=u.useState();async function _(){bt().then(({data:S})=>{h(S)})}u.useEffect(()=>{s&&_()},[s]);const E=S=>{if(isNaN(S))return;const w=Object.entries(kt).reduce((b,[k,p])=>{const v=S*p.months*p.discount;return{...b,[k]:v.toFixed(2)}},{});m.setValue("prices",w,{shouldDirty:!0})},C=()=>{n(!1),r(null),m.reset(St)};return e.jsx(be,{open:s,onOpenChange:C,children:e.jsxs(fe,{children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:d(t?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(Te,{})]}),e.jsxs(_e,{...m,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:m.control,name:"name",render:({field:S})=>e.jsxs(f,{children:[e.jsx(j,{children:d("plan.form.name.label")}),e.jsx(y,{children:e.jsx(T,{placeholder:d("plan.form.name.placeholder"),...S})}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"group_id",render:({field:S})=>e.jsxs(f,{children:[e.jsxs(j,{className:"flex items-center justify-between",children:[d("plan.form.group.label"),e.jsx(ta,{dialogTrigger:e.jsx(P,{variant:"link",children:d("plan.form.group.add")}),refetch:_})]}),e.jsxs(G,{value:S.value?.toString()??"",onValueChange:w=>S.onChange(w?Number(w):null),children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:d("plan.form.group.placeholder")})})}),e.jsx(B,{children:c?.map(w=>e.jsx(z,{value:w.id.toString(),children:w.name},w.id))})]}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"transfer_enable",render:({field:S})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:d("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",min:0,placeholder:d("plan.form.transfer.placeholder"),className:"rounded-r-none",...S})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.transfer.unit")})]}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"speed_limit",render:({field:S})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:d("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",min:0,placeholder:d("plan.form.speed.placeholder"),className:"rounded-r-none",...S,value:S.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.speed.unit")})]}),e.jsx(D,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:d("plan.form.price.title")}),e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(T,{type:"number",placeholder:d("plan.form.price.base_price"),className:"h-7 w-32 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500",onChange:S=>{const w=parseFloat(S.target.value);E(w)}})]}),e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const S=Object.keys(kt).reduce((w,b)=>({...w,[b]:""}),{});m.setValue("prices",S,{shouldDirty:!0})},children:d("plan.form.price.clear.button")})}),e.jsx(ce,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:d("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(kt).filter(([S])=>!["onetime","reset_traffic"].includes(S)).map(([S,w])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(g,{control:m.control,name:`prices.${S}`,render:({field:b})=>e.jsxs(f,{children:[e.jsxs(j,{className:"text-xs font-medium text-muted-foreground",children:[d(`plan.columns.price_period.${S}`),e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",w.months===1?d("plan.form.price.period.monthly"):d("plan.form.price.period.months",{count:w.months}),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:"0.00",min:0,...b,value:b.value??"",onChange:k=>b.onChange(k.target.value),className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})},S))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(kt).filter(([S])=>["onetime","reset_traffic"].includes(S)).map(([S,w])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(g,{control:m.control,name:`prices.${S}`,render:({field:b})=>e.jsx(f,{children:e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-0",children:[e.jsx(j,{className:"text-xs font-medium",children:d(`plan.columns.price_period.${S}`)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:d(S==="onetime"?"plan.form.price.onetime_desc":"plan.form.price.reset_desc")})]}),e.jsxs("div",{className:"relative w-full md:w-32",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:"0.00",min:0,...b,className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})})},S))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(g,{control:m.control,name:"device_limit",render:({field:S})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:d("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",min:0,placeholder:d("plan.form.device.placeholder"),className:"rounded-r-none",...S,value:S.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.device.unit")})]}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"capacity_limit",render:({field:S})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(j,{children:d("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(T,{type:"number",min:0,placeholder:d("plan.form.capacity.placeholder"),className:"rounded-r-none",...S,value:S.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.capacity.unit")})]}),e.jsx(D,{})]})})]}),e.jsx(g,{control:m.control,name:"reset_traffic_method",render:({field:S})=>e.jsxs(f,{children:[e.jsx(j,{children:d("plan.form.reset_method.label")}),e.jsxs(G,{value:S.value?.toString()??"null",onValueChange:w=>S.onChange(w=="null"?null:Number(w)),children:[e.jsx(y,{children:e.jsx(K,{children:e.jsx(W,{placeholder:d("plan.form.reset_method.placeholder")})})}),e.jsx(B,{children:$x.map(w=>e.jsx(z,{value:w.value?.toString()??"null",children:d(`plan.form.reset_method.options.${w.label}`)},w.value))})]}),e.jsx(F,{className:"text-xs",children:d("plan.form.reset_method.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:m.control,name:"content",render:({field:S})=>{const[w,b]=u.useState(!1);return e.jsxs(f,{className:"space-y-2",children:[e.jsxs(j,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d("plan.form.content.label"),e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>b(!w),children:w?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{d:"M10 12.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5z"}),e.jsx("path",{fillRule:"evenodd",d:"M.664 10.59a1.651 1.651 0 010-1.186A10.004 10.004 0 0110 3c4.257 0 7.893 2.66 9.336 6.41.147.381.146.804 0 1.186A10.004 10.004 0 0110 17c-4.257 0-7.893-2.66-9.336-6.41zM14 10a4 4 0 11-8 0 4 4 0 018 0z",clipRule:"evenodd"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{fillRule:"evenodd",d:"M3.28 2.22a.75.75 0 00-1.06 1.06l14.5 14.5a.75.75 0 101.06-1.06l-1.745-1.745a10.029 10.029 0 003.3-4.38 1.651 1.651 0 000-1.185A10.004 10.004 0 009.999 3a9.956 9.956 0 00-4.744 1.194L3.28 2.22zM7.752 6.69l1.092 1.092a2.5 2.5 0 013.374 3.373l1.091 1.092a4 4 0 00-5.557-5.557z",clipRule:"evenodd"}),e.jsx("path",{d:"M10.748 13.93l2.523 2.523a9.987 9.987 0 01-3.27.547c-4.258 0-7.894-2.66-9.337-6.41a1.651 1.651 0 010-1.186A10.007 10.007 0 012.839 6.02L6.07 9.252a4 4 0 004.678 4.678z"})]})})}),e.jsx(ce,{side:"top",children:e.jsx("p",{className:"text-xs",children:d(w?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(ve,{children:e.jsxs(he,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",onClick:()=>{S.onChange(d("plan.form.content.template.content"))},children:d("plan.form.content.template.button")})}),e.jsx(ce,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:d("plan.form.content.template.tooltip")})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${w?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(y,{children:e.jsx(Ea,{style:{height:"400px"},value:S.value||"",renderHTML:k=>o.render(k),onChange:({text:k})=>S.onChange(k),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:d("plan.form.content.placeholder"),className:"rounded-md border"})})}),w&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:d("plan.form.content.preview")}),e.jsx("div",{className:"prose prose-sm dark:prose-invert h-[400px] max-w-none overflow-y-auto rounded-md border p-4",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:o.render(S.value||"")}})})]})]}),e.jsx(F,{className:"text-xs",children:d("plan.form.content.description")}),e.jsx(D,{})]})}})]}),e.jsx(ze,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:t&&e.jsx(g,{control:m.control,name:"force_update",render:({field:S})=>e.jsxs(f,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(y,{children:e.jsx(sl,{checked:S.value,onCheckedChange:S.onChange})}),e.jsx("div",{className:"",children:e.jsx(j,{className:"text-sm",children:d("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(P,{type:"button",variant:"outline",onClick:C,children:d("plan.form.submit.cancel")}),e.jsx(P,{type:"submit",disabled:i,onClick:()=>{m.handleSubmit(async S=>{l(!0),(await Zc(S)).data&&(A.success(d(t?"plan.form.submit.success.update":"plan.form.submit.success.add")),C(),a()),l(!1)})()},children:d(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})]})})}function Hx(){const[s,n]=u.useState({}),[t,r]=u.useState({"drag-handle":!1}),[a,i]=u.useState([]),[l,d]=u.useState([]),[m,o]=u.useState(!1),[c,h]=u.useState({pageSize:20,pageIndex:0}),[_,E]=u.useState([]),{refetch:C}=re({queryKey:["planList"],queryFn:async()=>{const{data:p}=await qs();return E(p),p}});u.useEffect(()=>{r({"drag-handle":m}),h({pageSize:m?99999:10,pageIndex:0})},[m]);const S=(p,v)=>{m&&(p.dataTransfer.setData("text/plain",v.toString()),p.currentTarget.classList.add("opacity-50"))},w=(p,v)=>{if(!m)return;p.preventDefault(),p.currentTarget.classList.remove("bg-muted");const M=parseInt(p.dataTransfer.getData("text/plain"));if(M===v)return;const H=[..._],[se]=H.splice(M,1);H.splice(v,0,se),E(H)},b=async()=>{if(!m){o(!0);return}const p=_?.map(v=>v.id);sd(p).then(()=>{A.success("排序保存成功"),o(!1),C()}).finally(()=>{o(!1)})},k=ns({data:_||[],columns:zx(C),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:c},enableRowSelection:!0,onPaginationChange:h,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}},pageCount:m?1:void 0});return e.jsx(Ox,{refreshData:C,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(hs,{table:k,toolbar:p=>e.jsx(Lx,{table:p,refetch:C,saveOrder:b,isSortMode:m}),draggable:m,onDragStart:S,onDragEnd:p=>p.currentTarget.classList.remove("opacity-50"),onDragOver:p=>{p.preventDefault(),p.currentTarget.classList.add("bg-muted")},onDragLeave:p=>p.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!m}),e.jsx(Ux,{})]})})}function qx(){const{t:s}=V("subscribe");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("plan.title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("plan.page.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Hx,{})})]})]})}const Kx=Object.freeze(Object.defineProperty({__proto__:null,default:qx},Symbol.toStringTag,{value:"Module"})),Js=[{value:ae.PENDING,label:ot[ae.PENDING],icon:Ko,color:ct[ae.PENDING]},{value:ae.PROCESSING,label:ot[ae.PROCESSING],icon:xr,color:ct[ae.PROCESSING]},{value:ae.COMPLETED,label:ot[ae.COMPLETED],icon:ja,color:ct[ae.COMPLETED]},{value:ae.CANCELLED,label:ot[ae.CANCELLED],icon:hr,color:ct[ae.CANCELLED]},{value:ae.DISCOUNTED,label:ot[ae.DISCOUNTED],icon:ja,color:ct[ae.DISCOUNTED]}],ut=[{value:xe.PENDING,label:Nt[xe.PENDING],icon:Bo,color:_t[xe.PENDING]},{value:xe.PROCESSING,label:Nt[xe.PROCESSING],icon:xr,color:_t[xe.PROCESSING]},{value:xe.VALID,label:Nt[xe.VALID],icon:ja,color:_t[xe.VALID]},{value:xe.INVALID,label:Nt[xe.INVALID],icon:hr,color:_t[xe.INVALID]}];function Tt({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=s?.getFilterValue(),i=Array.isArray(a)?new Set(a):a!==void 0?new Set([a]):new Set;return e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(qt,{className:"mr-2 h-4 w-4"}),n,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:i.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:i.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):t.filter(l=>i.has(l.value)).map(l=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(xs,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Ms,{children:[e.jsx(Ks,{placeholder:n}),e.jsxs(Fs,{children:[e.jsx(Bs,{children:"No results found."}),e.jsx(Ye,{children:t.map(l=>{const d=i.has(l.value);return e.jsxs(Me,{onSelect:()=>{const m=new Set(i);d?m.delete(l.value):m.add(l.value);const o=Array.from(m);s?.setFilterValue(o.length?o:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",d?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx($s,{className:N("h-4 w-4")})}),l.icon&&e.jsx(l.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${l.color}`}),e.jsx("span",{children:l.label}),r?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(l.value)})]},l.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{}),e.jsx(Ye,{children:e.jsx(Me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Bx=x.object({email:x.string().min(1),plan_id:x.number(),period:x.string(),total_amount:x.number()}),Gx={email:"",plan_id:0,total_amount:0,period:""};function tl({refetch:s,trigger:n,defaultValues:t}){const{t:r}=V("order"),[a,i]=u.useState(!1),l=ge({resolver:Ne(Bx),defaultValues:{...Gx,...t},mode:"onChange"}),[d,m]=u.useState([]);return u.useEffect(()=>{a&&qs().then(({data:o})=>{m(o)})},[a]),e.jsxs(be,{open:a,onOpenChange:i,children:[e.jsx(Je,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("div",{children:r("dialog.addOrder")})]})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:r("dialog.assignOrder")}),e.jsx(Te,{})]}),e.jsxs(_e,{...l,children:[e.jsx(g,{control:l.control,name:"email",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dialog.fields.userEmail")}),e.jsx(y,{children:e.jsx(T,{placeholder:r("dialog.placeholders.email"),...o})})]})}),e.jsx(g,{control:l.control,name:"plan_id",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dialog.fields.subscriptionPlan")}),e.jsx(y,{children:e.jsxs(G,{value:o.value?o.value?.toString():void 0,onValueChange:c=>o.onChange(parseInt(c)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dialog.placeholders.plan")})}),e.jsx(B,{children:d.map(c=>e.jsx(z,{value:c.id.toString(),children:c.name},c.id))})]})})]})}),e.jsx(g,{control:l.control,name:"period",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dialog.fields.orderPeriod")}),e.jsx(y,{children:e.jsxs(G,{value:o.value,onValueChange:o.onChange,children:[e.jsx(K,{children:e.jsx(W,{placeholder:r("dialog.placeholders.period")})}),e.jsx(B,{children:Object.keys(gu).map(c=>e.jsx(z,{value:c,children:r(`period.${c}`)},c))})]})})]})}),e.jsx(g,{control:l.control,name:"total_amount",render:({field:o})=>e.jsxs(f,{children:[e.jsx(j,{children:r("dialog.fields.paymentAmount")}),e.jsx(y,{children:e.jsx(T,{type:"number",placeholder:r("dialog.placeholders.amount"),value:o.value/100,onChange:c=>o.onChange(parseFloat(c.currentTarget.value)*100)})}),e.jsx(D,{})]})}),e.jsxs(ze,{children:[e.jsx(P,{variant:"outline",onClick:()=>i(!1),children:r("dialog.actions.cancel")}),e.jsx(P,{type:"submit",onClick:()=>{l.handleSubmit(o=>{ld(o).then(({data:c})=>{c&&(s&&s(),l.reset(),i(!1),A.success(r("dialog.messages.addSuccess")))})})()},children:r("dialog.actions.confirm")})]})]})]})]})}function Wx({table:s,refetch:n}){const{t}=V("order"),r=s.getState().columnFilters.length>0,a=Object.values(os).filter(m=>typeof m=="number").map(m=>({label:t(`type.${os[m]}`),value:m,color:m===os.NEW?"green-500":m===os.RENEWAL?"blue-500":m===os.UPGRADE?"purple-500":"orange-500"})),i=Object.values(Pe).map(m=>({label:t(`period.${m}`),value:m,color:m===Pe.MONTH_PRICE?"slate-500":m===Pe.QUARTER_PRICE?"cyan-500":m===Pe.HALF_YEAR_PRICE?"indigo-500":m===Pe.YEAR_PRICE?"violet-500":m===Pe.TWO_YEAR_PRICE?"fuchsia-500":m===Pe.THREE_YEAR_PRICE?"pink-500":m===Pe.ONETIME_PRICE?"rose-500":"orange-500"})),l=Object.values(ae).filter(m=>typeof m=="number").map(m=>({label:t(`status.${ae[m]}`),value:m,icon:m===ae.PENDING?Js[0].icon:m===ae.PROCESSING?Js[1].icon:m===ae.COMPLETED?Js[2].icon:m===ae.CANCELLED?Js[3].icon:Js[4].icon,color:m===ae.PENDING?"yellow-500":m===ae.PROCESSING?"blue-500":m===ae.COMPLETED?"green-500":m===ae.CANCELLED?"red-500":"green-500"})),d=Object.values(xe).filter(m=>typeof m=="number").map(m=>({label:t(`commission.${xe[m]}`),value:m,icon:m===xe.PENDING?ut[0].icon:m===xe.PROCESSING?ut[1].icon:m===xe.VALID?ut[2].icon:ut[3].icon,color:m===xe.PENDING?"yellow-500":m===xe.PROCESSING?"blue-500":m===xe.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tl,{refetch:n}),e.jsx(T,{placeholder:t("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:m=>s.getColumn("trade_no")?.setFilterValue(m.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2",children:[s.getColumn("type")&&e.jsx(Tt,{column:s.getColumn("type"),title:t("table.columns.type"),options:a}),s.getColumn("period")&&e.jsx(Tt,{column:s.getColumn("period"),title:t("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(Tt,{column:s.getColumn("status"),title:t("table.columns.status"),options:l}),s.getColumn("commission_status")&&e.jsx(Tt,{column:s.getColumn("commission_status"),title:t("table.columns.commissionStatus"),options:d})]}),r&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("actions.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]})}function ls({label:s,value:n,className:t,valueClassName:r}){return e.jsxs("div",{className:N("flex items-center py-1.5",t),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:N("text-sm",r),children:n||"-"})]})}function Yx({status:s}){const{t:n}=V("order"),t={[ae.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[ae.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[ae.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[ae.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[ae.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(q,{variant:"secondary",className:N("font-medium",t[s]),children:n(`status.${ae[s]}`)})}function Qx({id:s,trigger:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(),{t:l}=V("order");return u.useEffect(()=>{(async()=>{if(t){const{data:m}=await ad({id:s});i(m)}})()},[t,s]),e.jsxs(be,{onOpenChange:r,open:t,children:[e.jsx(Je,{asChild:!0,children:n}),e.jsxs(fe,{className:"max-w-xl",children:[e.jsxs(Ce,{className:"space-y-2",children:[e.jsx(ye,{className:"text-lg font-medium",children:l("dialog.title")}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:[l("table.columns.tradeNo"),":",a?.trade_no]}),a?.status&&e.jsx(Yx,{status:a.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ls,{label:l("dialog.fields.userEmail"),value:a?.user?.email?e.jsxs(Us,{to:`/user/manage?email=${a.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[a.user.email,e.jsx(pr,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(ls,{label:l("dialog.fields.orderPeriod"),value:a&&l(`period.${a.period}`)}),e.jsx(ls,{label:l("dialog.fields.subscriptionPlan"),value:a?.plan?.name,valueClassName:"font-medium"}),e.jsx(ls,{label:l("dialog.fields.callbackNo"),value:a?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ls,{label:l("dialog.fields.paymentAmount"),value:Ls(a?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(ke,{className:"my-2"}),e.jsx(ls,{label:l("dialog.fields.balancePayment"),value:Ls(a?.balance_amount||0)}),e.jsx(ls,{label:l("dialog.fields.discountAmount"),value:Ls(a?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(ls,{label:l("dialog.fields.refundAmount"),value:Ls(a?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(ls,{label:l("dialog.fields.deductionAmount"),value:Ls(a?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ls,{label:l("dialog.fields.createdAt"),value:we(a?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(ls,{label:l("dialog.fields.updatedAt"),value:we(a?.updated_at),valueClassName:"font-mono text-xs"})]})]})]})]})]})}const Jx={[os.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[os.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[os.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[os.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Xx={[Pe.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Pe.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Zx=s=>ae[s],eh=s=>xe[s],sh=s=>os[s],th=s=>{const{t:n}=V("order");return[{accessorKey:"trade_no",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.tradeNo")}),cell:({row:t})=>{const r=t.original.trade_no,a=r.length>6?`${r.slice(0,3)}...${r.slice(-3)}`:r;return e.jsx("div",{className:"flex items-center",children:e.jsx(Qx,{trigger:e.jsxs(J,{variant:"ghost",size:"sm",className:"flex h-8 items-center gap-1.5 px-2 font-medium text-primary transition-colors hover:bg-primary/10 hover:text-primary/80",children:[e.jsx("span",{className:"font-mono",children:a}),e.jsx(pr,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.type")}),cell:({row:t})=>{const r=t.getValue("type"),a=Jx[r];return e.jsx(q,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",a.color,a.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:n(`type.${sh(r)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.plan")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium text-foreground/90 sm:max-w-72 md:max-w-[31rem]",children:t.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.period")}),cell:({row:t})=>{const r=t.getValue("period"),a=Xx[r];return e.jsx(q,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",a?.color,a?.bgColor,"hover:bg-opacity-80"),children:n(`period.${r}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.amount")}),cell:({row:t})=>{const r=t.getValue("total_amount"),a=typeof r=="number"?(r/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",a]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:t})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(O,{column:t,title:n("table.columns.status")}),e.jsx(ve,{delayDuration:100,children:e.jsxs(he,{children:[e.jsx(pe,{children:e.jsx(Gr,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(ce,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:t})=>{const r=Js.find(a=>a.value===t.getValue("status"));return r?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r.icon&&e.jsx(r.icon,{className:`h-4 w-4 text-${r.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`status.${Zx(r.value)}`)})]}),r.value===ae.PENDING&&e.jsxs(Ss,{modal:!0,children:[e.jsx(ks,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Vt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(fs,{align:"end",className:"w-[140px]",children:[e.jsx(je,{className:"cursor-pointer",onClick:async()=>{await nd({trade_no:t.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(je,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await rd({trade_no:t.original.trade_no}),s()},children:n("actions.cancel")})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.commission")}),cell:({row:t})=>{const r=t.getValue("commission_balance"),a=r?(r/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:r?`¥${a}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.commissionStatus")}),cell:({row:t})=>{const r=t.original.status,a=t.original.commission_balance,i=ut.find(l=>l.value===t.getValue("commission_status"));return a==0||!i?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i.icon&&e.jsx(i.icon,{className:`h-4 w-4 text-${i.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`commission.${eh(i.value)}`)})]}),i.value===xe.PENDING&&r===ae.COMPLETED&&e.jsxs(Ss,{modal:!0,children:[e.jsx(ks,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Vt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(fs,{align:"end",className:"w-[120px]",children:[e.jsx(je,{className:"cursor-pointer",onClick:async()=>{await an({trade_no:t.original.trade_no,commission_status:xe.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(je,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await an({trade_no:t.original.trade_no,commission_status:xe.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.createdAt")}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:we(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function ah(){const[s]=fr(),[n,t]=u.useState({}),[r,a]=u.useState({}),[i,l]=u.useState([]),[d,m]=u.useState([]),[o,c]=u.useState({pageIndex:0,pageSize:20});u.useEffect(()=>{const w=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([b,k])=>{const p=s.get(b);return p?{id:b,value:k==="number"?parseInt(p):p}:null}).filter(Boolean);w.length>0&&l(w)},[s]);const{refetch:h,data:_,isLoading:E}=re({queryKey:["orderList",o,i,d],queryFn:()=>td({pageSize:o.pageSize,current:o.pageIndex+1,filter:i,sort:d})}),C=ns({data:_?.data??[],columns:th(h),state:{sorting:d,columnVisibility:r,rowSelection:n,columnFilters:i,pagination:o},rowCount:_?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:m,onColumnFiltersChange:l,onColumnVisibilityChange:a,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),onPaginationChange:c,getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(hs,{table:C,toolbar:e.jsx(Wx,{table:C,refetch:h}),showPagination:!0})}function nh(){const{t:s}=V("order");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(ah,{})})]})]})}const rh=Object.freeze(Object.defineProperty({__proto__:null,default:nh},Symbol.toStringTag,{value:"Module"}));function lh({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(qt,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:a.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:a.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(xs,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Ms,{children:[e.jsx(Ks,{placeholder:n}),e.jsxs(Fs,{children:[e.jsx(Bs,{children:"No results found."}),e.jsx(Ye,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(Me,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx($s,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{}),e.jsx(Ye,{children:e.jsx(Me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const ih=x.object({id:x.coerce.number().nullable().optional(),name:x.string().min(1,"请输入优惠券名称"),code:x.string().nullable(),type:x.coerce.number(),value:x.coerce.number(),started_at:x.coerce.number(),ended_at:x.coerce.number(),limit_use:x.union([x.string(),x.number()]).nullable(),limit_use_with_user:x.union([x.string(),x.number()]).nullable(),generate_count:x.coerce.number().nullable().optional(),limit_plan_ids:x.array(x.coerce.number()).default([]).nullable(),limit_period:x.array(x.nativeEnum(xt)).default([]).nullable()}).refine(s=>s.ended_at>s.started_at,{message:"结束时间必须晚于开始时间",path:["ended_at"]}),xn={name:"",code:null,type:Be.AMOUNT,value:0,started_at:Math.floor(Date.now()/1e3),ended_at:Math.floor(Date.now()/1e3)+7*24*60*60,limit_use:null,limit_use_with_user:null,limit_plan_ids:[],limit_period:[],generate_count:null};function al({defaultValues:s,refetch:n,type:t="create",dialogTrigger:r=null,open:a,onOpenChange:i}){const{t:l}=V("coupon"),[d,m]=u.useState(!1),o=a??d,c=i??m,[h,_]=u.useState([]),E=ge({resolver:Ne(ih),defaultValues:s||xn});u.useEffect(()=>{s&&E.reset(s)},[s,E]),u.useEffect(()=>{qs().then(({data:b})=>_(b))},[]);const C=b=>{if(!b)return;const k=(p,v)=>{const M=new Date(v*1e3);return p.setHours(M.getHours(),M.getMinutes(),M.getSeconds()),Math.floor(p.getTime()/1e3)};b.from&&E.setValue("started_at",k(b.from,E.watch("started_at"))),b.to&&E.setValue("ended_at",k(b.to,E.watch("ended_at")))},S=async b=>{const k=await od(b);if(b.generate_count&&k){const p=new Blob([k],{type:"text/csv;charset=utf-8;"}),v=document.createElement("a");v.href=window.URL.createObjectURL(p),v.download=`coupons_${new Date().getTime()}.csv`,v.click(),window.URL.revokeObjectURL(v.href)}c(!1),t==="create"&&E.reset(xn),n()},w=(b,k)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:k}),e.jsx(T,{type:"datetime-local",step:"1",value:we(E.watch(b),"YYYY-MM-DDTHH:mm:ss"),onChange:p=>{const v=new Date(p.target.value);E.setValue(b,Math.floor(v.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(be,{open:o,onOpenChange:c,children:[r&&e.jsx(Je,{asChild:!0,children:r}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsx(Ce,{children:e.jsx(ye,{children:l(t==="create"?"form.add":"form.edit")})}),e.jsx(_e,{...E,children:e.jsxs("form",{onSubmit:E.handleSubmit(S),className:"space-y-4",children:[e.jsx(g,{control:E.control,name:"name",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.name.label")}),e.jsx(T,{placeholder:l("form.name.placeholder"),...b}),e.jsx(D,{})]})}),t==="create"&&e.jsx(g,{control:E.control,name:"generate_count",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.generateCount.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.generateCount.placeholder"),...b,value:b.value===void 0?"":b.value,onChange:k=>b.onChange(k.target.value===""?"":parseInt(k.target.value)),className:"h-9"}),e.jsx(F,{className:"text-xs",children:l("form.generateCount.description")}),e.jsx(D,{})]})}),(!E.watch("generate_count")||E.watch("generate_count")==null)&&e.jsx(g,{control:E.control,name:"code",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.code.label")}),e.jsx(T,{placeholder:l("form.code.placeholder"),...b,className:"h-9"}),e.jsx(F,{className:"text-xs",children:l("form.code.description")}),e.jsx(D,{})]})}),e.jsxs(f,{children:[e.jsx(j,{children:l("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(g,{control:E.control,name:"type",render:({field:b})=>e.jsxs(G,{value:b.value.toString(),onValueChange:k=>{const p=b.value,v=parseInt(k);b.onChange(v);const M=E.getValues("value");M&&(p===Be.AMOUNT&&v===Be.PERCENTAGE?E.setValue("value",M/100):p===Be.PERCENTAGE&&v===Be.AMOUNT&&E.setValue("value",M*100))},children:[e.jsx(K,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(W,{placeholder:l("form.type.placeholder")})}),e.jsx(B,{children:Object.entries(ju).map(([k,p])=>e.jsx(z,{value:k,children:l(`table.toolbar.types.${k}`)},k))})]})}),e.jsx(g,{control:E.control,name:"value",render:({field:b})=>{const k=b.value==null?"":E.watch("type")===Be.AMOUNT&&typeof b.value=="number"?(b.value/100).toString():b.value.toString();return e.jsx(T,{type:"number",placeholder:l("form.value.placeholder"),...b,value:k,onChange:p=>{const v=p.target.value;if(v===""){b.onChange("");return}const M=parseFloat(v);isNaN(M)||b.onChange(E.watch("type")===Be.AMOUNT?Math.round(M*100):M)},step:"any",min:0,className:"flex-[2] rounded-none border-x-0 text-left"})}}),e.jsx("div",{className:"flex min-w-[40px] items-center justify-center rounded-md rounded-l-none border border-l-0 border-input bg-muted/50 px-3 font-medium text-muted-foreground",children:e.jsx("span",{children:E.watch("type")==Be.AMOUNT?"¥":"%"})})]})]}),e.jsxs(f,{children:[e.jsx(j,{children:l("form.validity.label")}),e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(P,{variant:"outline",className:N("w-full justify-start text-left font-normal",!E.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(jt,{className:"mr-2 h-4 w-4"}),we(E.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",l("form.validity.to")," ",we(E.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})}),e.jsxs(xs,{className:"w-auto p-0",align:"start",children:[e.jsx("div",{className:"border-b border-border",children:e.jsx(Gs,{mode:"range",selected:{from:new Date(E.watch("started_at")*1e3),to:new Date(E.watch("ended_at")*1e3)},onSelect:C,numberOfMonths:2})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-4",children:[w("started_at",l("table.validity.startTime")),e.jsx("div",{className:"mt-6 text-sm text-muted-foreground",children:l("form.validity.to")}),w("ended_at",l("table.validity.endTime"))]})})]})]}),e.jsx(D,{})]}),e.jsx(g,{control:E.control,name:"limit_use",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.limitUse.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.limitUse.placeholder"),...b,value:b.value===null?"":b.value,onChange:k=>b.onChange(k.target.value===""?null:parseInt(k.target.value)),className:"h-9"}),e.jsx(F,{className:"text-xs",children:l("form.limitUse.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:E.control,name:"limit_use_with_user",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.limitUseWithUser.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.limitUseWithUser.placeholder"),...b,value:b.value===null?"":b.value,onChange:k=>b.onChange(k.target.value===""?null:parseInt(k.target.value)),className:"h-9"}),e.jsx(F,{className:"text-xs",children:l("form.limitUseWithUser.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:E.control,name:"limit_period",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.limitPeriod.label")}),e.jsx(at,{options:Object.entries(xt).filter(([k])=>isNaN(Number(k))).map(([k,p])=>({label:l(`coupon:period.${p}`),value:k})),onChange:k=>{if(k.length===0){b.onChange([]);return}const p=k.map(v=>xt[v.value]);b.onChange(p)},value:(b.value||[]).map(k=>({label:l(`coupon:period.${k}`),value:Object.entries(xt).find(([p,v])=>v===k)?.[0]||""})),placeholder:l("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPeriod.empty")})}),e.jsx(F,{className:"text-xs",children:l("form.limitPeriod.description")}),e.jsx(D,{})]})}),e.jsx(g,{control:E.control,name:"limit_plan_ids",render:({field:b})=>e.jsxs(f,{children:[e.jsx(j,{children:l("form.limitPlan.label")}),e.jsx(at,{options:h?.map(k=>({label:k.name,value:k.id.toString()}))||[],onChange:k=>b.onChange(k.map(p=>Number(p.value))),value:(h||[]).filter(k=>(b.value||[]).includes(k.id)).map(k=>({label:k.name,value:k.id.toString()})),placeholder:l("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPlan.empty")})}),e.jsx(D,{})]})}),e.jsx(ze,{children:e.jsx(P,{type:"submit",disabled:E.formState.isSubmitting,children:E.formState.isSubmitting?l("form.submit.saving"):l("form.submit.save")})})]})})]})]})}function oh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=V("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(al,{refetch:n,dialogTrigger:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("div",{children:r("form.add")})]})}),e.jsx(T,{placeholder:r("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(lh,{column:s.getColumn("type"),title:r("table.toolbar.type"),options:[{value:Be.AMOUNT,label:r(`table.toolbar.types.${Be.AMOUNT}`)},{value:Be.PERCENTAGE,label:r(`table.toolbar.types.${Be.PERCENTAGE}`)}]}),t&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]})]})}const nl=u.createContext(void 0);function ch({children:s,refetch:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(null),l=m=>{i(m),r(!0)},d=()=>{r(!1),i(null)};return e.jsxs(nl.Provider,{value:{isOpen:t,currentCoupon:a,openEdit:l,closeEdit:d},children:[s,a&&e.jsx(al,{defaultValues:a,refetch:n,type:"edit",open:t,onOpenChange:r})]})}function dh(){const s=u.useContext(nl);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const uh=s=>{const{t:n}=V("coupon");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(q,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx(Y,{defaultChecked:t.original.show,onCheckedChange:r=>{dd({id:t.original.id,show:r}).then(({data:a})=>!a&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.type")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:n(`table.toolbar.types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.code")}),cell:({row:t})=>e.jsx(q,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.limitUse")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:t.original.limit_use===null?n("table.validity.unlimited"):t.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.limitUseWithUser")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:t.original.limit_use_with_user===null?n("table.validity.noLimit"):t.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.validity")}),cell:({row:t})=>{const[r,a]=u.useState(!1),i=Date.now(),l=t.original.started_at*1e3,d=t.original.ended_at*1e3,m=i>d,o=ie.jsx(O,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>{const{openEdit:r}=dh();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>r(t.original),children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),e.jsx(Qe,{title:n("table.actions.deleteConfirm.title"),description:n("table.actions.deleteConfirm.description"),confirmText:n("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{cd({id:t.original.id}).then(({data:a})=>{a&&(A.success("删除成功"),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("table.actions.delete")})]})})]})}}]};function mh(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),[m,o]=u.useState({pageIndex:0,pageSize:20}),{refetch:c,data:h}=re({queryKey:["couponList",m,a,l],queryFn:()=>id({pageSize:m.pageSize,current:m.pageIndex+1,filter:a,sort:l})}),_=ns({data:h?.data??[],columns:uh(c),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:m},pageCount:Math.ceil((h?.total??0)/m.pageSize),rowCount:h?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:o,getCoreRowModel:rs(),getFilteredRowModel:ds(),getPaginationRowModel:us(),getSortedRowModel:ms(),getFacetedRowModel:Ds(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ch,{refetch:c,children:e.jsx("div",{className:"space-y-4",children:e.jsx(hs,{table:_,toolbar:e.jsx(oh,{table:_,refetch:c})})})})}function xh(){const{t:s}=V("coupon");return e.jsxs(Ee,{children:[e.jsxs(Re,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ae,{}),e.jsx($e,{})]})]}),e.jsxs(Fe,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(mh,{})})]})]})}const hh=Object.freeze(Object.defineProperty({__proto__:null,default:xh},Symbol.toStringTag,{value:"Module"})),ph=1,fh=1e6;let ua=0;function gh(){return ua=(ua+1)%Number.MAX_SAFE_INTEGER,ua.toString()}const ma=new Map,hn=s=>{if(ma.has(s))return;const n=setTimeout(()=>{ma.delete(s),ht({type:"REMOVE_TOAST",toastId:s})},fh);ma.set(s,n)},jh=(s,n)=>{switch(n.type){case"ADD_TOAST":return{...s,toasts:[n.toast,...s.toasts].slice(0,ph)};case"UPDATE_TOAST":return{...s,toasts:s.toasts.map(t=>t.id===n.toast.id?{...t,...n.toast}:t)};case"DISMISS_TOAST":{const{toastId:t}=n;return t?hn(t):s.toasts.forEach(r=>{hn(r.id)}),{...s,toasts:s.toasts.map(r=>r.id===t||t===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return n.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==n.toastId)}}},Pt=[];let Et={toasts:[]};function ht(s){Et=jh(Et,s),Pt.forEach(n=>{n(Et)})}function vh({...s}){const n=gh(),t=a=>ht({type:"UPDATE_TOAST",toast:{...a,id:n}}),r=()=>ht({type:"DISMISS_TOAST",toastId:n});return ht({type:"ADD_TOAST",toast:{...s,id:n,open:!0,onOpenChange:a=>{a||r()}}}),{id:n,dismiss:r,update:t}}function rl(){const[s,n]=u.useState(Et);return u.useEffect(()=>(Pt.push(n),()=>{const t=Pt.indexOf(n);t>-1&&Pt.splice(t,1)}),[s]),{...s,toast:vh,dismiss:t=>ht({type:"DISMISS_TOAST",toastId:t})}}function bh({open:s,onOpenChange:n,table:t}){const{t:r}=V("user"),{toast:a}=rl(),[i,l]=u.useState(!1),[d,m]=u.useState(""),[o,c]=u.useState(""),h=async()=>{if(!d||!o){a({title:r("messages.error"),description:r("messages.send_mail.required_fields"),variant:"destructive"});return}try{l(!0),await Ot.sendMail({subject:d,content:o,filter:t.getState().columnFilters,sort:t.getState().sorting[0]?.id,sort_type:t.getState().sorting[0]?.desc?"DESC":"ASC"}),a({title:r("messages.success"),description:r("messages.send_mail.success")}),n(!1),m(""),c("")}catch{a({title:r("messages.error"),description:r("messages.send_mail.failed"),variant:"destructive"})}finally{l(!1)}};return e.jsx(be,{open:s,onOpenChange:n,children:e.jsxs(fe,{className:"sm:max-w-[500px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:r("send_mail.title")}),e.jsx(Te,{children:r("send_mail.description")})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"subject",className:"text-right",children:r("send_mail.subject")}),e.jsx(T,{id:"subject",value:d,onChange:_=>m(_.target.value),className:"col-span-3"})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"content",className:"text-right",children:r("send_mail.content")}),e.jsx(ys,{id:"content",value:o,onChange:_=>c(_.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(ze,{children:e.jsx(J,{type:"submit",onClick:h,disabled:i,children:r(i?"send_mail.sending":"send_mail.send")})})]})})}const yh=x.object({email_prefix:x.string().optional(),email_suffix:x.string().min(1),password:x.string().optional(),expired_at:x.number().optional().nullable(),plan_id:x.number().nullable(),generate_count:x.number().optional().nullable()}).refine(s=>s.generate_count===null?s.email_prefix!==void 0&&s.email_prefix!=="":!0,{message:"Email prefix is required when generate_count is null",path:["email_prefix"]}),Nh={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0};function _h({refetch:s}){const{t:n}=V("user"),[t,r]=u.useState(!1),a=ge({resolver:Ne(yh),defaultValues:Nh,mode:"onChange"}),[i,l]=u.useState([]);return u.useEffect(()=>{t&&qs().then(({data:d})=>{d&&l(d)})},[t]),e.jsxs(be,{open:t,onOpenChange:r,children:[e.jsx(Je,{asChild:!0,children:e.jsxs(J,{size:"sm",variant:"outline",className:"space-x-2 gap-0",children:[e.jsx(Ve,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(fe,{className:"sm:max-w-[425px]",children:[e.jsxs(Ce,{children:[e.jsx(ye,{children:n("generate.title")}),e.jsx(Te,{})]}),e.jsxs(_e,{...a,children:[e.jsxs(f,{children:[e.jsx(j,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!a.watch("generate_count")&&e.jsx(g,{control:a.control,name:"email_prefix",render:({field:d})=>e.jsx(T,{className:"flex-[5] rounded-r-none",placeholder:n("generate.form.email_prefix"),...d})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${a.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(g,{control:a.control,name:"email_suffix",render:({field:d})=>e.jsx(T,{className:"flex-[4] rounded-l-none",placeholder:n("generate.form.email_domain"),...d})})]})]}),e.jsx(g,{control:a.control,name:"password",render:({field:d})=>e.jsxs(f,{children:[e.jsx(j,{children:n("generate.form.password")}),e.jsx(T,{placeholder:n("generate.form.password_placeholder"),...d}),e.jsx(D,{})]})}),e.jsx(g,{control:a.control,name:"expired_at",render:({field:d})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(j,{children:n("generate.form.expire_time")}),e.jsxs(vs,{children:[e.jsx(bs,{asChild:!0,children:e.jsx(y,{children:e.jsxs(J,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!d.value&&"text-muted-foreground"),children:[d.value?we(d.value):e.jsx("span",{children:n("generate.form.expire_time_placeholder")}),e.jsx(jt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(xs,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(Wo,{asChild:!0,children:e.jsx(J,{variant:"outline",className:"w-full",onClick:()=>{d.onChange(null)},children:n("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Gs,{mode:"single",selected:d.value?new Date(d.value*1e3):void 0,onSelect:m=>{m&&d.onChange(m?.getTime()/1e3)}})})]})]})]})}),e.jsx(g,{control:a.control,name:"plan_id",render:({field:d})=>e.jsxs(f,{children:[e.jsx(j,{children:n("generate.form.subscription")}),e.jsx(y,{children:e.jsxs(G,{value:d.value?d.value.toString():"null",onValueChange:m=>d.onChange(m==="null"?null:parseInt(m)),children:[e.jsx(K,{children:e.jsx(W,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(B,{children:[e.jsx(z,{value:"null",children:n("generate.form.subscription_none")}),i.map(m=>e.jsx(z,{value:m.id.toString(),children:m.name},m.id))]})]})})]})}),!a.watch("email_prefix")&&e.jsx(g,{control:a.control,name:"generate_count",render:({field:d})=>e.jsxs(f,{children:[e.jsx(j,{children:n("generate.form.generate_count")}),e.jsx(T,{type:"number",placeholder:n("generate.form.generate_count_placeholder"),value:d.value||"",onChange:m=>d.onChange(m.target.value?parseInt(m.target.value):null)})]})})]}),e.jsxs(ze,{children:[e.jsx(J,{variant:"outline",onClick:()=>r(!1),children:n("generate.form.cancel")}),e.jsx(J,{onClick:()=>a.handleSubmit(d=>{hd(d).then(({data:m})=>{m&&(A.success(n("generate.form.success")),a.reset(),s(),r(!1))})})(),children:n("generate.form.submit")})]})]})]})}const ll=Nn,wh=_n,Ch=wn,il=u.forwardRef(({className:s,...n},t)=>e.jsx(zt,{className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:t}));il.displayName=zt.displayName;const Sh=As("fixed overflow-y-scroll z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-md",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-md"}},defaultVariants:{side:"right"}}),Aa=u.forwardRef(({side:s="right",className:n,children:t,...r},a)=>e.jsxs(Ch,{children:[e.jsx(il,{}),e.jsxs(At,{ref:a,className:N(Sh({side:s}),n),...r,children:[e.jsxs(Ca,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[e.jsx(ss,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),t]})]}));Aa.displayName=At.displayName;const $a=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-2 text-center sm:text-left",s),...n});$a.displayName="SheetHeader";const ol=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});ol.displayName="SheetFooter";const Ua=u.forwardRef(({className:s,...n},t)=>e.jsx($t,{ref:t,className:N("text-lg font-semibold text-foreground",s),...n}));Ua.displayName=$t.displayName;const Ha=u.forwardRef(({className:s,...n},t)=>e.jsx(Ut,{ref:t,className:N("text-sm text-muted-foreground",s),...n}));Ha.displayName=Ut.displayName;function kh({table:s,refetch:n,permissionGroups:t=[],subscriptionPlans:r=[]}){const{t:a}=V("user"),{toast:i}=rl(),l=s.getState().columnFilters.length>0,[d,m]=u.useState([]),[o,c]=u.useState(!1),[h,_]=u.useState(!1),[E,C]=u.useState(!1),[S,w]=u.useState(!1),b=async()=>{try{const Q=await Ot.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),te=Q;console.log(Q);const $=new Blob([te],{type:"text/csv;charset=utf-8;"}),R=window.URL.createObjectURL($),X=document.createElement("a");X.href=R,X.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(X),X.click(),X.remove(),window.URL.revokeObjectURL(R),i({title:a("messages.success"),description:a("messages.export.success")})}catch{i({title:a("messages.error"),description:a("messages.export.failed"),variant:"destructive"})}},k=async()=>{try{w(!0),await Ot.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),i({title:a("messages.success"),description:a("messages.batch_ban.success")}),n()}catch{i({title:a("messages.error"),description:a("messages.batch_ban.failed"),variant:"destructive"})}finally{w(!1),C(!1)}},p=[{label:a("filter.fields.email"),value:"email",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.id"),value:"id",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.plan_id"),value:"plan_id",type:"select",operators:[{label:a("filter.operators.eq"),value:"eq"}],useOptions:!0},{label:a("filter.fields.transfer_enable"),value:"transfer_enable",type:"number",unit:"GB",operators:[{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.total_used"),value:"total_used",type:"number",unit:"GB",operators:[{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.online_count"),value:"online_count",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"},{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"}]},{label:a("filter.fields.expired_at"),value:"expired_at",type:"date",operators:[{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.uuid"),value:"uuid",type:"text",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.token"),value:"token",type:"text",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.banned"),value:"banned",type:"select",operators:[{label:a("filter.operators.eq"),value:"eq"}],options:[{label:a("filter.status.normal"),value:"0"},{label:a("filter.status.banned"),value:"1"}]},{label:a("filter.fields.remark"),value:"remarks",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.inviter_email"),value:"invite_user.email",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.invite_user_id"),value:"invite_user_id",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.is_admin"),value:"is_admin",type:"boolean",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.is_staff"),value:"is_staff",type:"boolean",operators:[{label:a("filter.operators.eq"),value:"eq"}]}],v=Q=>Q*1024*1024*1024,M=Q=>Q/(1024*1024*1024),H=()=>{m([...d,{field:"",operator:"",value:""}])},se=Q=>{m(d.filter((te,$)=>$!==Q))},L=(Q,te,$)=>{const R=[...d];if(R[Q]={...R[Q],[te]:$},te==="field"){const X=p.find(Ns=>Ns.value===$);X&&(R[Q].operator=X.operators[0].value,R[Q].value=X.type==="boolean"?!1:"")}m(R)},Z=(Q,te)=>{const $=p.find(R=>R.value===Q.field);if(!$)return null;switch($.type){case"text":return e.jsx(T,{placeholder:a("filter.sheet.value"),value:Q.value,onChange:R=>L(te,"value",R.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(T,{type:"number",placeholder:a("filter.sheet.value_number",{unit:$.unit}),value:$.unit==="GB"?M(Q.value||0):Q.value,onChange:R=>{const X=Number(R.target.value);L(te,"value",$.unit==="GB"?v(X):X)}}),$.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:$.unit})]});case"date":return e.jsx(Gs,{mode:"single",selected:Q.value,onSelect:R=>L(te,"value",R),className:"flex flex-1 justify-center rounded-md border"});case"select":return e.jsxs(G,{value:Q.value,onValueChange:R=>L(te,"value",R),children:[e.jsx(K,{children:e.jsx(W,{placeholder:a("filter.sheet.value")})}),e.jsx(B,{children:$.useOptions?r.map(R=>e.jsx(z,{value:R.value.toString(),children:R.label},R.value)):$.options?.map(R=>e.jsx(z,{value:R.value.toString(),children:R.label},R.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Y,{checked:Q.value,onCheckedChange:R=>L(te,"value",R)}),e.jsx(Mt,{children:Q.value?a("filter.boolean.true"):a("filter.boolean.false")})]});default:return null}},de=()=>{const Q=d.filter(te=>te.field&&te.operator&&te.value!=="").map(te=>{const $=p.find(X=>X.value===te.field);let R=te.value;return te.operator==="contains"?{id:te.field,value:R}:($?.type==="date"&&R instanceof Date&&(R=Math.floor(R.getTime()/1e3)),$?.type==="boolean"&&(R=R?1:0),{id:te.field,value:`${te.operator}:${R}`})});s.setColumnFilters(Q),c(!1)};return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-2",children:[e.jsx(_h,{refetch:n}),e.jsx(T,{placeholder:a("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:Q=>s.getColumn("email")?.setFilterValue(Q.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(ll,{open:o,onOpenChange:c,children:[e.jsx(wh,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Yo,{className:"mr-2 h-4 w-4"}),a("filter.advanced"),d.length>0&&e.jsx(q,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:d.length})]})}),e.jsxs(Aa,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs($a,{children:[e.jsx(Ua,{children:a("filter.sheet.title")}),e.jsx(Ha,{children:a("filter.sheet.description")})]}),e.jsxs("div",{className:"mt-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:a("filter.sheet.conditions")}),e.jsx(P,{variant:"outline",size:"sm",onClick:H,children:a("filter.sheet.add")})]}),e.jsx(zs,{className:"h-[calc(100vh-280px)] ",children:e.jsx("div",{className:"space-y-4",children:d.map((Q,te)=>e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Mt,{children:a("filter.sheet.condition",{number:te+1})}),e.jsx(P,{variant:"ghost",size:"sm",onClick:()=>se(te),children:e.jsx(ss,{className:"h-4 w-4"})})]}),e.jsxs(G,{value:Q.field,onValueChange:$=>L(te,"field",$),children:[e.jsx(K,{children:e.jsx(W,{placeholder:a("filter.sheet.field")})}),e.jsx(B,{children:e.jsx(He,{children:p.map($=>e.jsx(z,{value:$.value,className:"cursor-pointer",children:$.label},$.value))})})]}),Q.field&&e.jsxs(G,{value:Q.operator,onValueChange:$=>L(te,"operator",$),children:[e.jsx(K,{children:e.jsx(W,{placeholder:a("filter.sheet.operator")})}),e.jsx(B,{children:p.find($=>$.value===Q.field)?.operators.map($=>e.jsx(z,{value:$.value,children:$.label},$.value))})]}),Q.field&&Q.operator&&Z(Q,te)]},te))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(P,{variant:"outline",onClick:()=>{m([]),c(!1)},children:a("filter.sheet.reset")}),e.jsx(P,{onClick:de,children:a("filter.sheet.apply")})]})]})]})]}),l&&e.jsxs(P,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),m([])},className:"h-8 px-2 lg:px-3",children:[a("filter.sheet.reset"),e.jsx(ss,{className:"ml-2 h-4 w-4"})]}),e.jsxs(Ss,{modal:!1,children:[e.jsx(ks,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:a("actions.title")})}),e.jsxs(fs,{children:[e.jsx(je,{onClick:()=>_(!0),children:a("actions.send_email")}),e.jsx(je,{onClick:b,children:a("actions.export_csv")}),e.jsx(tt,{}),e.jsx(je,{onClick:()=>C(!0),className:"text-red-600 focus:text-red-600",children:a("actions.batch_ban")})]})]})]}),e.jsx(bh,{open:h,onOpenChange:_,table:s}),e.jsx(Oa,{open:E,onOpenChange:C,children:e.jsxs(Yt,{children:[e.jsxs(Qt,{children:[e.jsx(Xt,{children:a("actions.confirm_ban.title")}),e.jsx(Zt,{children:a(l?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(Jt,{children:[e.jsx(sa,{disabled:S,children:a("actions.confirm_ban.cancel")}),e.jsx(ea,{onClick:k,disabled:S,className:"bg-red-600 hover:bg-red-700 focus:ring-red-600",children:a(S?"actions.confirm_ban.banning":"actions.confirm_ban.confirm")})]})]})})]})}const cl=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"m17.71 11.29l-5-5a1 1 0 0 0-.33-.21a1 1 0 0 0-.76 0a1 1 0 0 0-.33.21l-5 5a1 1 0 0 0 1.42 1.42L11 9.41V17a1 1 0 0 0 2 0V9.41l3.29 3.3a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42"})}),dl=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17.71 11.29a1 1 0 0 0-1.42 0L13 14.59V7a1 1 0 0 0-2 0v7.59l-3.29-3.3a1 1 0 0 0-1.42 1.42l5 5a1 1 0 0 0 .33.21a.94.94 0 0 0 .76 0a1 1 0 0 0 .33-.21l5-5a1 1 0 0 0 0-1.42"})}),Th=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17 11H9.41l3.3-3.29a1 1 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33a1 1 0 0 0 0 .76a1 1 0 0 0 .21.33l5 5a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42L9.41 13H17a1 1 0 0 0 0-2"})}),Dh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17.92 11.62a1 1 0 0 0-.21-.33l-5-5a1 1 0 0 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0l5-5a1 1 0 0 0 .21-.33a1 1 0 0 0 0-.76"})}),xa=[{accessorKey:"record_at",header:"时间",cell:({row:s})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("time",{className:"text-sm text-muted-foreground",children:xc(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(cl,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:ps(s.original.u)})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(dl,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:ps(s.original.d)})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const n=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(q,{variant:"outline",className:"font-mono",children:[n,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const n=s.original.u+s.original.d;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:ps(n)})}}];function ul({user_id:s,dialogTrigger:n}){const{t}=V(["traffic"]),[r,a]=u.useState(!1),[i,l]=u.useState({pageIndex:0,pageSize:20}),{data:d,isLoading:m}=re({queryKey:["userStats",s,i,r],queryFn:()=>r?pd({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),o=ns({data:d?.data??[],columns:xa,pageCount:Math.ceil((d?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:rs(),onPaginationChange:l});return e.jsxs(be,{open:r,onOpenChange:a,children:[e.jsx(Je,{asChild:!0,children:n}),e.jsxs(fe,{className:"sm:max-w-[700px]",children:[e.jsx(Ce,{children:e.jsx(ye,{children:t("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Ia,{children:[e.jsx(Va,{children:o.getHeaderGroups().map(c=>e.jsx(Is,{children:c.headers.map(h=>e.jsx(Fa,{className:N("h-10 px-2 text-xs",h.id==="total"&&"text-right"),children:h.isPlaceholder?null:Rt(h.column.columnDef.header,h.getContext())},h.id))},c.id))}),e.jsx(Ma,{children:m?Array.from({length:i.pageSize}).map((c,h)=>e.jsx(Is,{children:Array.from({length:xa.length}).map((_,E)=>e.jsx(Zs,{className:"p-2",children:e.jsx(oe,{className:"h-6 w-full"})},E))},h)):o.getRowModel().rows?.length?o.getRowModel().rows.map(c=>e.jsx(Is,{"data-state":c.getIsSelected()&&"selected",className:"h-10",children:c.getVisibleCells().map(h=>e.jsx(Zs,{className:"px-2",children:Rt(h.column.columnDef.cell,h.getContext())},h.id))},c.id)):e.jsx(Is,{children:e.jsx(Zs,{colSpan:xa.length,className:"h-24 text-center",children:t("trafficRecord.noRecords")})})})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.perPage")}),e.jsxs(G,{value:`${o.getState().pagination.pageSize}`,onValueChange:c=>{o.setPageSize(Number(c))},children:[e.jsx(K,{className:"h-8 w-[70px]",children:e.jsx(W,{placeholder:o.getState().pagination.pageSize})}),e.jsx(B,{side:"top",children:[10,20,30,40,50].map(c=>e.jsx(z,{value:`${c}`,children:c},c))})]}),e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.records")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"flex w-[100px] items-center justify-center text-sm",children:t("trafficRecord.page",{current:o.getState().pagination.pageIndex+1,total:o.getPageCount()})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>o.previousPage(),disabled:!o.getCanPreviousPage()||m,children:e.jsx(Th,{className:"h-4 w-4"})}),e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>o.nextPage(),disabled:!o.getCanNextPage()||m,children:e.jsx(Dh,{className:"h-4 w-4"})})]})]})]})]})]})]})}function Ph({onConfirm:s,children:n,title:t="确认操作",description:r="确定要执行此操作吗?",cancelText:a="取消",confirmText:i="确认",variant:l="default",className:d}){return e.jsxs(Oa,{children:[e.jsx(Kr,{asChild:!0,children:n}),e.jsxs(Yt,{className:N("sm:max-w-[425px]",d),children:[e.jsxs(Qt,{children:[e.jsx(Xt,{children:t}),e.jsx(Zt,{children:r})]}),e.jsxs(Jt,{children:[e.jsx(sa,{asChild:!0,children:e.jsx(P,{variant:"outline",children:a})}),e.jsx(ea,{asChild:!0,children:e.jsx(P,{variant:l,onClick:s,children:i})})]})]})]})}const Eh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M5 18h4.24a1 1 0 0 0 .71-.29l6.92-6.93L19.71 8a1 1 0 0 0 0-1.42l-4.24-4.29a1 1 0 0 0-1.42 0l-2.82 2.83l-6.94 6.93a1 1 0 0 0-.29.71V17a1 1 0 0 0 1 1m9.76-13.59l2.83 2.83l-1.42 1.42l-2.83-2.83ZM6 13.17l5.93-5.93l2.83 2.83L8.83 16H6ZM21 20H3a1 1 0 0 0 0 2h18a1 1 0 0 0 0-2"})}),Rh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 11h-6V5a1 1 0 0 0-2 0v6H5a1 1 0 0 0 0 2h6v6a1 1 0 0 0 2 0v-6h6a1 1 0 0 0 0-2"})}),Ih=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21 8.94a1.3 1.3 0 0 0-.06-.27v-.09a1 1 0 0 0-.19-.28l-6-6a1 1 0 0 0-.28-.19a.3.3 0 0 0-.09 0a.9.9 0 0 0-.33-.11H10a3 3 0 0 0-3 3v1H6a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3v-1h1a3 3 0 0 0 3-3zm-6-3.53L17.59 8H16a1 1 0 0 1-1-1ZM15 19a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1h1v7a3 3 0 0 0 3 3h5Zm4-4a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h3v3a3 3 0 0 0 3 3h3Z"})}),Vh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21 11a1 1 0 0 0-1 1a8.05 8.05 0 1 1-2.22-5.5h-2.4a1 1 0 0 0 0 2h4.53a1 1 0 0 0 1-1V3a1 1 0 0 0-2 0v1.77A10 10 0 1 0 22 12a1 1 0 0 0-1-1"})}),Mh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M9.5 10.5H12a1 1 0 0 0 0-2h-1V8a1 1 0 0 0-2 0v.55a2.5 2.5 0 0 0 .5 4.95h1a.5.5 0 0 1 0 1H8a1 1 0 0 0 0 2h1v.5a1 1 0 0 0 2 0v-.55a2.5 2.5 0 0 0-.5-4.95h-1a.5.5 0 0 1 0-1M21 12h-3V3a1 1 0 0 0-.5-.87a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0A1 1 0 0 0 2 3v16a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3v-6a1 1 0 0 0-1-1M5 20a1 1 0 0 1-1-1V4.73l2 1.14a1.08 1.08 0 0 0 1 0l3-1.72l3 1.72a1.08 1.08 0 0 0 1 0l2-1.14V19a3 3 0 0 0 .18 1Zm15-1a1 1 0 0 1-2 0v-5h2Z"})}),Fh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M12.3 12.22A4.92 4.92 0 0 0 14 8.5a5 5 0 0 0-10 0a4.92 4.92 0 0 0 1.7 3.72A8 8 0 0 0 1 19.5a1 1 0 0 0 2 0a6 6 0 0 1 12 0a1 1 0 0 0 2 0a8 8 0 0 0-4.7-7.28M9 11.5a3 3 0 1 1 3-3a3 3 0 0 1-3 3m9.74.32A5 5 0 0 0 15 3.5a1 1 0 0 0 0 2a3 3 0 0 1 3 3a3 3 0 0 1-1.5 2.59a1 1 0 0 0-.5.84a1 1 0 0 0 .45.86l.39.26l.13.07a7 7 0 0 1 4 6.38a1 1 0 0 0 2 0a9 9 0 0 0-4.23-7.68"})}),Oh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M12 2a10 10 0 0 0-6.88 2.77V3a1 1 0 0 0-2 0v4.5a1 1 0 0 0 1 1h4.5a1 1 0 0 0 0-2h-2.4A8 8 0 1 1 4 12a1 1 0 0 0-2 0A10 10 0 1 0 12 2m0 6a1 1 0 0 0-1 1v3a1 1 0 0 0 1 1h2a1 1 0 0 0 0-2h-1V9a1 1 0 0 0-1-1"})}),Lh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M20 6h-4V5a3 3 0 0 0-3-3h-2a3 3 0 0 0-3 3v1H4a1 1 0 0 0 0 2h1v11a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3V8h1a1 1 0 0 0 0-2M10 5a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v1h-4Zm7 14a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V8h10Z"})}),zh=(s,n,t,r)=>{const{t:a}=V("user");return[{accessorKey:"is_admin",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l)),size:0},{accessorKey:"is_staff",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l)),size:0},{accessorKey:"id",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.id")}),cell:({row:i})=>e.jsx(q,{variant:"outline",children:i.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.email")}),cell:({row:i})=>{const l=i.original.t||0,d=Date.now()/1e3-l<120,m=Math.floor(Date.now()/1e3-l);let o=d?a("columns.online_status.online"):l===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:we(l)});if(!d&&l!==0){const c=Math.floor(m/60),h=Math.floor(c/60),_=Math.floor(h/24);_>0?o+=` `+a("columns.online_status.offline_duration.days",{count:_}):h>0?o+=` `+a("columns.online_status.offline_duration.hours",{count:h}):c>0?o+=` `+a("columns.online_status.offline_duration.minutes",{count:c}):o+=` diff --git a/public/assets/admin/locales/en-US.js b/public/assets/admin/locales/en-US.js index 7a2fd91..06f1dcf 100644 --- a/public/assets/admin/locales/en-US.js +++ b/public/assets/admin/locales/en-US.js @@ -443,8 +443,8 @@ window.XBOARD_TRANSLATIONS['en-US'] = { }, "expire": { "label": "Limit Duration", - "placeholder": "Enter limit duration in hours", - "description": "Duration of the registration limit in hours" + "placeholder": "Enter limit duration in minutes", + "description": "Duration of the registration limit in minutes" } }, "passwordLimit": { @@ -459,8 +459,8 @@ window.XBOARD_TRANSLATIONS['en-US'] = { }, "expire": { "label": "Lock Duration", - "placeholder": "Enter lock duration in hours", - "description": "Duration of the account lock in hours" + "placeholder": "Enter lock duration in minutes", + "description": "Duration of the account lock in minutes" } } } diff --git a/public/assets/admin/locales/ko-KR.js b/public/assets/admin/locales/ko-KR.js index d9bb23a..c33eeb6 100644 --- a/public/assets/admin/locales/ko-KR.js +++ b/public/assets/admin/locales/ko-KR.js @@ -441,8 +441,8 @@ window.XBOARD_TRANSLATIONS['ko-KR'] = { }, "expire": { "label": "제한 기간", - "placeholder": "제한 기간을 시간 단위로 입력", - "description": "등록 제한 기간(시간)" + "placeholder": "제한 기간을 분 단위로 입력", + "description": "등록 제한 기간(분)" } }, "passwordLimit": { @@ -457,8 +457,8 @@ window.XBOARD_TRANSLATIONS['ko-KR'] = { }, "expire": { "label": "잠금 기간", - "placeholder": "잠금 기간을 시간 단위로 입력", - "description": "계정 잠금 기간(시간)" + "placeholder": "잠금 기간을 분 단위로 입력", + "description": "계정 잠금 기간(분)" } } } diff --git a/public/assets/admin/locales/zh-CN.js b/public/assets/admin/locales/zh-CN.js index 2213081..7311746 100644 --- a/public/assets/admin/locales/zh-CN.js +++ b/public/assets/admin/locales/zh-CN.js @@ -363,8 +363,8 @@ window.XBOARD_TRANSLATIONS['zh-CN'] = { }, "expire": { "label": "限制时长", - "placeholder": "输入限制时长(小时)", - "description": "注册限制的持续时间(小时)" + "placeholder": "输入限制时长(分钟)", + "description": "注册限制的持续时间(分钟)" } }, "passwordLimit": { @@ -379,8 +379,8 @@ window.XBOARD_TRANSLATIONS['zh-CN'] = { }, "expire": { "label": "锁定时长", - "placeholder": "输入锁定时长(小时)", - "description": "账户锁定的持续时间(小时)" + "placeholder": "输入锁定时长(分钟)", + "description": "账户锁定的持续时间(分钟)" } } }