From ef8cc8b9a05c6e42a8612448495d1c1afbbd5d60 Mon Sep 17 00:00:00 2001 From: xboard Date: Fri, 17 Jan 2025 10:07:27 +0800 Subject: [PATCH] fix: correct know issues --- app/Http/Requests/Admin/UserUpdate.php | 4 ++-- public/assets/admin/assets/index.js | 14 +++++++------- public/assets/admin/locales/zh-CN.js | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/Http/Requests/Admin/UserUpdate.php b/app/Http/Requests/Admin/UserUpdate.php index 5717680..793606d 100644 --- a/app/Http/Requests/Admin/UserUpdate.php +++ b/app/Http/Requests/Admin/UserUpdate.php @@ -26,9 +26,9 @@ class UserUpdate extends FormRequest 'is_staff' => 'required|in:0,1', 'u' => 'integer', 'd' => 'integer', - 'balance' => 'integer', + 'balance' => 'numeric', 'commission_type' => 'integer', - 'commission_balance' => 'integer', + 'commission_balance' => 'numeric', 'remarks' => 'nullable', 'speed_limit' => 'nullable|integer', 'device_limit' => 'nullable|integer' diff --git a/public/assets/admin/assets/index.js b/public/assets/admin/assets/index.js index bd88977..8f1ea12 100644 --- a/public/assets/admin/assets/index.js +++ b/public/assets/admin/assets/index.js @@ -1,9 +1,9 @@ -import{r as m,j as e,t as ll,c as ol,I as Na,a as Ts,S as Zt,u as is,b as Xt,d as il,O as ea,e as cl,f as q,g as dl,h as ml,i as ul,k as xl,B as hl,l as fl,Q as pl,m as gl,R as jl,n as vl,P as bl,o as yl,p as Nl,q as Ka,F as _l,C as wl,s as Cl,v as Sl,w as kl,x as Dl,y as Ha,z as I,A as h,D as ce,E as ue,G as Ua,H as St,J as kt,K as sa,L as Oe,T as Dt,M as Tt,N as Ba,U as Ga,V as Wa,W as ta,X as Ya,Y as Tl,Z as Ja,_ as Qa,$ as Za,a0 as Xa,a1 as Ps,a2 as en,a3 as Pl,a4 as sn,a5 as tn,a6 as Rl,a7 as El,a8 as Vl,a9 as Il,aa as Fl,ab as Ml,ac as Ol,ad as zl,ae as Ll,af as Al,ag as $l,ah as an,ai as ql,aj as Kl,ak as Rs,al as nn,am as Hl,an as Ul,ao as rn,ap as Bl,aq as Gl,ar as _a,as as Wl,at as ln,au as Yl,av as on,aw as Jl,ax as Ql,ay as Zl,az as Xl,aA as eo,aB as so,aC as cn,aD as to,aE as ao,aF as no,aG as Se,aH as ro,aI as lo,aJ as oo,aK as io,aL as dn,aM as mn,aN as un,aO as co,aP as xn,aQ as hn,aR as fn,aS as mo,aT as uo,aU as xo,aV as pn,aW as ho,aX as aa,aY as gn,aZ as fo,a_ as jn,a$ as po,b0 as vn,b1 as go,b2 as bn,b3 as yn,b4 as jo,b5 as vo,b6 as Nn,b7 as bo,b8 as yo,b9 as _n,ba as No,bb as wn,bc as _o,bd as wo,be as qe,bf as se,bg as $e,bh as it,bi as Co,bj as So,bk as ko,bl as Do,bm as To,bn as Po,bo as wa,bp as Ca,bq as Ro,br as Eo,bs as Vo,bt as Io,bu as Fo,bv as Kt,bw as Ht,bx as Mo,by as Oo,bz as Cn,bA as zo,bB as Lo,bC as Sn,bD as Ao,bE as pe,bF as $o,bG as Sa,bH as Ut,bI as Bt,bJ as qo,bK as Ko,bL as kn,bM as Ho,bN as na,bO as Uo,bP as Bo,bQ as Go,bR as Dn,bS as Tn,bT as Pn,bU as Wo,bV as Yo,bW as Jo,bX as Qo,bY as Rn,bZ as Zo,b_ as es,b$ as Xo,c0 as ei,c1 as si,c2 as bt,c3 as Ne,c4 as ka,c5 as ti,c6 as En,c7 as Vn,c8 as In,c9 as Fn,ca as Mn,cb as On,cc as ai,cd as ni,ce as ri,cf as Pt,cg as Es,ch as cs,ci as ze,cj as Le,ck as Ue,cl as Be,cm as Ge,cn as li,co as oi,cp as ii,cq as Gt,cr as ra,cs as la,ct as ci,cu as ds,cv as ms,cw as ct,cx as di,cy as yt,cz as mi,cA as Da,cB as zn,cC as Ta,cD as Nt,cE as ui,cF as xi,cG as hi,cH as fi,cI as Ln,cJ as pi,cK as gi,cL as An,cM as Wt,cN as $n,cO as ji,cP as qn,cQ as Kn,cR as vi,cS as bi,cT as yi,cU as Ni,cV as _i}from"./vendor.js";import"./index.js";var bh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function yh(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function wi(s){if(s.__esModule)return s;var n=s.default;if(typeof n=="function"){var a=function l(){return this instanceof l?Reflect.construct(n,arguments,this.constructor):n.apply(this,arguments)};a.prototype=n.prototype}else a={};return Object.defineProperty(a,"__esModule",{value:!0}),Object.keys(s).forEach(function(l){var r=Object.getOwnPropertyDescriptor(s,l);Object.defineProperty(a,l,r.get?r:{enumerable:!0,get:function(){return s[l]}})}),a}const Ci={theme:"system",setTheme:()=>null},Hn=m.createContext(Ci);function Si({children:s,defaultTheme:n="system",storageKey:a="vite-ui-theme",...l}){const[r,i]=m.useState(()=>localStorage.getItem(a)||n);m.useEffect(()=>{const u=window.document.documentElement;if(u.classList.remove("light","dark"),r==="system"){const x=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";u.classList.add(x);return}u.classList.add(r)},[r]);const c={theme:r,setTheme:u=>{localStorage.setItem(a,u),i(u)}};return e.jsx(Hn.Provider,{...l,value:c,children:s})}const ki=()=>{const s=m.useContext(Hn);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},Di=function(){const n=typeof document<"u"&&document.createElement("link").relList;return n&&n.supports&&n.supports("modulepreload")?"modulepreload":"preload"}(),Ti=function(s,n){return new URL(s,n).href},Pa={},oe=function(n,a,l){let r=Promise.resolve();if(a&&a.length>0){const c=document.getElementsByTagName("link"),u=document.querySelector("meta[property=csp-nonce]"),x=u?.nonce||u?.getAttribute("nonce");r=Promise.allSettled(a.map(o=>{if(o=Ti(o,l),o in Pa)return;Pa[o]=!0;const d=o.endsWith(".css"),p=d?'[rel="stylesheet"]':"";if(!!l)for(let f=c.length-1;f>=0;f--){const _=c[f];if(_.href===o&&(!d||_.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${o}"]${p}`))return;const V=document.createElement("link");if(V.rel=d?"stylesheet":Di,d||(V.as="script"),V.crossOrigin="",V.href=o,x&&V.setAttribute("nonce",x),document.head.appendChild(V),d)return new Promise((f,_)=>{V.addEventListener("load",f),V.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${o}`)))})}))}function i(c){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=c,window.dispatchEvent(u),!u.defaultPrevented)throw c}return r.then(c=>{for(const u of c||[])u.status==="rejected"&&i(u.reason);return n().catch(i)})};function y(...s){return ll(ol(s))}const Ks=Ts("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"}}),E=m.forwardRef(({className:s,variant:n,size:a,asChild:l=!1,children:r,disabled:i,loading:c=!1,leftSection:u,rightSection:x,...o},d)=>{const p=l?Zt:"button";return e.jsxs(p,{className:y(Ks({variant:n,size:a,className:s})),disabled:c||i,ref:d,...o,children:[(u&&c||!u&&!x&&c)&&e.jsx(Na,{className:"mr-2 h-4 w-4 animate-spin"}),!c&&u&&e.jsx("div",{className:"mr-2",children:u}),r,!c&&x&&e.jsx("div",{className:"ml-2",children:x}),x&&c&&e.jsx(Na,{className:"ml-2 h-4 w-4 animate-spin"})]})});E.displayName="Button";function Os({className:s,minimal:n=!1}){const a=is();return e.jsx("div",{className:y("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",{})," Please try again later."]}),!n&&e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(E,{variant:"outline",onClick:()=>a(-1),children:"Go Back"}),e.jsx(E,{onClick:()=>a("/"),children:"Back to Home"})]})]})})}function Ra(){const s=is();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(E,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(E,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function Pi(){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(E,{variant:"outline",children:"Learn more"})})]})})}function Ri(s){return typeof s>"u"}function Ei(s){return s===null}function Vi(s){return Ei(s)||Ri(s)}class Ii{storage;prefixKey;constructor(n){this.storage=n.storage,this.prefixKey=n.prefixKey}getKey(n){return`${this.prefixKey}${n}`.toUpperCase()}set(n,a,l=null){const r=JSON.stringify({value:a,time:Date.now(),expire:l!==null?new Date().getTime()+l*1e3:null});this.storage.setItem(this.getKey(n),r)}get(n,a=null){const l=this.storage.getItem(this.getKey(n));if(!l)return{value:a,time:0};try{const r=JSON.parse(l),{value:i,time:c,expire:u}=r;return Vi(u)||u>new Date().getTime()?{value:i,time:c}:(this.remove(n),{value:a,time:0})}catch{return this.remove(n),{value:a,time:0}}}remove(n){this.storage.removeItem(this.getKey(n))}clear(){this.storage.clear()}}function Un({prefixKey:s="",storage:n=sessionStorage}){return new Ii({prefixKey:s,storage:n})}const Bn="Xboard_",Fi=function(s={}){return Un({prefixKey:s.prefixKey||"",storage:localStorage})},Mi=function(s={}){return Un({prefixKey:s.prefixKey||"",storage:sessionStorage})},Rt=Fi({prefixKey:Bn});Mi({prefixKey:Bn});const Gn="access_token";function st(){return Rt.get(Gn)}function Wn(){Rt.remove(Gn)}const Ea=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function Oi({children:s}){const n=is(),a=Xt(),l=st();return m.useEffect(()=>{if(!l.value&&!Ea.includes(a.pathname)){const r=encodeURIComponent(a.pathname+a.search);n(`/sign-in?redirect=${r}`)}},[l.value,a.pathname,a.search,n]),Ea.includes(a.pathname)||l.value?e.jsx(e.Fragment,{children:s}):null}const zi=()=>e.jsx(Oi,{children:e.jsx(ea,{})}),Li=il([{path:"/sign-in",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>dc);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(zi,{}),children:[{path:"/",lazy:async()=>({Component:(await oe(()=>Promise.resolve().then(()=>vc),void 0,import.meta.url)).default}),errorElement:e.jsx(Os,{}),children:[{index:!0,lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Bd);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(Os,{}),children:[{path:"system",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Jd);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>em);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>rm);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>dm);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>fm);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>bm);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Cm);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Pm);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Fm);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Am);return{default:s}},void 0,import.meta.url)).default})}]},{path:"payment",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Zm);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>tu);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>cu);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>gu);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(Os,{}),children:[{path:"manage",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>qu);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Gu);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Xu);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(Os,{}),children:[{path:"plan",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>ix);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Nx);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Rx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(Os,{}),children:[{path:"manage",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>eh);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>gh);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:Os},{path:"/404",Component:Ra},{path:"/503",Component:Pi},{path:"*",Component:Ra}]),Ai="locale";function $i(){return Rt.get(Ai)}function Yn(){Wn();const s=window.location.pathname,n=s&&!["/404","/sign-in"].includes(s),a=new URL(window.location.href),r=`${a.pathname.split("/")[1]?`/${a.pathname.split("/")[1]}`:""}#/sign-in`;window.location.href=r+(n?`?redirect=${s}`:"")}const qi=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function Ki(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const O=cl.create({baseURL:Ki(),timeout:12e3,headers:{"Content-Type":"application/json"}});O.interceptors.request.use(s=>{s.method?.toLowerCase()==="get"&&(s.params={...s.params,t:Date.now()});const n=st();if(!qi.includes(s.url?.split("?")[0]||"")){if(!n.value)return Yn(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=n.value}return s.headers["Content-Language"]=$i().value||"zh-CN",s},s=>Promise.reject(s));O.interceptors.response.use(s=>s?.data||{code:-1,message:"未知错误"},s=>{const n=s.response?.status,a=s.response?.data?.message;return(n===401||n===403)&&Yn(),q.error(a||{401:"登录已过期",403:"没有权限",404:"资源或接口不存在"}[n]||"未知异常"),Promise.reject(s.response?.data||{data:null,code:-1,message:"未知错误"})});function Hi(){return O.get("/user/info")}const Ot={token:st()?.value||"",userInfo:null,isLoggedIn:!!st()?.value,loading:!1,error:null},Xs=dl("user/fetchUserInfo",async()=>(await Hi()).data,{condition:(s,{getState:n})=>{const{user:a}=n();return!!a.token&&!a.loading}}),Jn=ml({name:"user",initialState:Ot,reducers:{setToken(s,n){s.token=n.payload,s.isLoggedIn=!!n.payload},resetUserState:()=>Ot},extraReducers:s=>{s.addCase(Xs.pending,n=>{n.loading=!0,n.error=null}).addCase(Xs.fulfilled,(n,a)=>{n.loading=!1,n.userInfo=a.payload,n.error=null}).addCase(Xs.rejected,(n,a)=>{if(n.loading=!1,n.error=a.error.message||"Failed to fetch user info",!n.token)return Ot})}}),{setToken:Ui,resetUserState:Bi}=Jn.actions,Gi=s=>s.user.userInfo,Wi=Jn.reducer,Qn=ul({reducer:{user:Wi}});st()?.value&&Qn.dispatch(Xs());xl.use(hl).use(fl).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 Yi=new pl;gl.createRoot(document.getElementById("root")).render(e.jsx(jl.StrictMode,{children:e.jsx(vl,{client:Yi,children:e.jsx(bl,{store:Qn,children:e.jsxs(Si,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(yl,{router:Li}),e.jsx(Nl,{richColors:!0,position:"top-right"})]})})})}));const He=m.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:y("rounded-xl border bg-card text-card-foreground shadow",s),...n}));He.displayName="Card";const ss=m.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:y("flex flex-col space-y-1.5 p-6",s),...n}));ss.displayName="CardHeader";const bs=m.forwardRef(({className:s,...n},a)=>e.jsx("h3",{ref:a,className:y("font-semibold leading-none tracking-tight",s),...n}));bs.displayName="CardTitle";const tt=m.forwardRef(({className:s,...n},a)=>e.jsx("p",{ref:a,className:y("text-sm text-muted-foreground",s),...n}));tt.displayName="CardDescription";const ts=m.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:y("p-6 pt-0",s),...n}));ts.displayName="CardContent";const Ji=m.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:y("flex items-center p-6 pt-0",s),...n}));Ji.displayName="CardFooter";const Qi=Ts("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),_t=m.forwardRef(({className:s,...n},a)=>e.jsx(Ka,{ref:a,className:y(Qi(),s),...n}));_t.displayName=Ka.displayName;const xe=_l,Zn=m.createContext({}),j=({...s})=>e.jsx(Zn.Provider,{value:{name:s.name},children:e.jsx(wl,{...s})}),Et=()=>{const s=m.useContext(Zn),n=m.useContext(Xn),{getFieldState:a,formState:l}=Cl(),r=a(s.name,l);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`,...r}},Xn=m.createContext({}),g=m.forwardRef(({className:s,...n},a)=>{const l=m.useId();return e.jsx(Xn.Provider,{value:{id:l},children:e.jsx("div",{ref:a,className:y("space-y-2",s),...n})})});g.displayName="FormItem";const v=m.forwardRef(({className:s,...n},a)=>{const{error:l,formItemId:r}=Et();return e.jsx(_t,{ref:a,className:y(l&&"text-destructive",s),htmlFor:r,...n})});v.displayName="FormLabel";const N=m.forwardRef(({...s},n)=>{const{error:a,formItemId:l,formDescriptionId:r,formMessageId:i}=Et();return e.jsx(Zt,{ref:n,id:l,"aria-describedby":a?`${r} ${i}`:`${r}`,"aria-invalid":!!a,...s})});N.displayName="FormControl";const F=m.forwardRef(({className:s,...n},a)=>{const{formDescriptionId:l}=Et();return e.jsx("p",{ref:a,id:l,className:y("text-[0.8rem] text-muted-foreground",s),...n})});F.displayName="FormDescription";const P=m.forwardRef(({className:s,children:n,...a},l)=>{const{error:r,formMessageId:i}=Et(),c=r?String(r?.message):n;return c?e.jsx("p",{ref:l,id:i,className:y("text-[0.8rem] font-medium text-destructive",s),...a,children:c}):null});P.displayName="FormMessage";const T=m.forwardRef(({className:s,type:n,...a},l)=>e.jsx("input",{type:n,className:y("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:l,...a}));T.displayName="Input";const er=m.forwardRef(({className:s,...n},a)=>{const[l,r]=m.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:l?"text":"password",className:y("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:a,...n}),e.jsx(E,{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:()=>r(i=>!i),children:l?e.jsx(Sl,{size:18}):e.jsx(kl,{size:18})})]})});er.displayName="PasswordInput";const Zi=s=>O({url:"/passport/auth/login",method:"post",data:s});function me(s=void 0,n="YYYY-MM-DD HH:mm:ss"){return s==null?"":(Math.floor(s).toString().length===10&&(s=s*1e3),Dl(s).format(n))}function Xi(s=void 0,n="YYYY-MM-DD"){return me(s,n)}function As(s){const n=typeof s=="string"?parseFloat(s):s;return isNaN(n)?"0.00":n.toFixed(2)}function ks(s,n=!0){if(s==null)return n?"¥0.00":"0.00";const a=typeof s=="string"?parseFloat(s):s;if(isNaN(a))return n?"¥0.00":"0.00";const r=(a/100).toFixed(2).replace(/\.?0+$/,i=>i.includes(".")?".00":i);return n?`¥${r}`:r}function wt(s){return new Promise(n=>{(async()=>{try{if(navigator.clipboard)await navigator.clipboard.writeText(s);else{const l=document.createElement("textarea");l.value=s,l.style.position="fixed",l.style.opacity="0",document.body.appendChild(l),l.select();const r=document.execCommand("copy");if(document.body.removeChild(l),!r)throw new Error("execCommand failed")}n(!0)}catch(l){console.error(l),n(!1)}})()})}function Ze(s){const n=s/1024,a=n/1024,l=a/1024,r=l/1024;return r>=1?As(r)+" TB":l>=1?As(l)+" GB":a>=1?As(a)+" MB":As(n)+" KB"}const ec="access_token";function sc(s){Rt.set(ec,s)}function tc({className:s,onForgotPassword:n,...a}){const l=is(),r=Ha(),{t:i}=I("auth"),c=h.object({email:h.string().min(1,{message:i("signIn.validation.emailRequired")}),password:h.string().min(1,{message:i("signIn.validation.passwordRequired")}).min(7,{message:i("signIn.validation.passwordLength")})}),u=ce({resolver:ue(c),defaultValues:{email:"",password:""}});async function x(o){Zi(o).then(({data:d})=>{sc(d.auth_data),r(Ui(d.auth_data)),r(Xs()).unwrap(),l("/")})}return e.jsx("div",{className:y("grid gap-6",s),...a,children:e.jsx(xe,{...u,children:e.jsx("form",{onSubmit:u.handleSubmit(x),className:"space-y-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:u.control,name:"email",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:i("signIn.email")}),e.jsx(N,{children:e.jsx(T,{placeholder:i("signIn.emailPlaceholder"),autoComplete:"email",...o})}),e.jsx(P,{})]})}),e.jsx(j,{control:u.control,name:"password",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:i("signIn.password")}),e.jsx(N,{children:e.jsx(er,{placeholder:i("signIn.passwordPlaceholder"),autoComplete:"current-password",...o})}),e.jsx(P,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(E,{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(E,{className:"w-full",size:"lg",loading:u.formState.isSubmitting,children:i("signIn.submit")})]})})})})}const ge=Ua,Fe=Ba,ac=Ga,dt=sa,sr=m.forwardRef(({className:s,...n},a)=>e.jsx(St,{ref:a,className:y("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}));sr.displayName=St.displayName;const he=m.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(ac,{children:[e.jsx(sr,{}),e.jsxs(kt,{ref:l,className:y("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),...a,children:[n,e.jsxs(sa,{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(Oe,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));he.displayName=kt.displayName;const ve=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col space-y-1.5 text-center sm:text-left",s),...n});ve.displayName="DialogHeader";const Me=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Me.displayName="DialogFooter";const je=m.forwardRef(({className:s,...n},a)=>e.jsx(Dt,{ref:a,className:y("text-lg font-semibold leading-none tracking-tight",s),...n}));je.displayName=Dt.displayName;const Te=m.forwardRef(({className:s,...n},a)=>e.jsx(Tt,{ref:a,className:y("text-sm text-muted-foreground",s),...n}));Te.displayName=Tt.displayName;const qs=Ts("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=m.forwardRef(({className:s,variant:n,size:a,asChild:l=!1,...r},i)=>{const c=l?Zt:"button";return e.jsx(c,{className:y(qs({variant:n,size:a,className:s})),ref:i,...r})});J.displayName="Button";const ys=Rl,Ns=El,nc=Vl,rc=m.forwardRef(({className:s,inset:n,children:a,...l},r)=>e.jsxs(Wa,{ref:r,className:y("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),...l,children:[a,e.jsx(ta,{className:"ml-auto h-4 w-4"})]}));rc.displayName=Wa.displayName;const lc=m.forwardRef(({className:s,...n},a)=>e.jsx(Ya,{ref:a,className:y("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}));lc.displayName=Ya.displayName;const os=m.forwardRef(({className:s,sideOffset:n=4,...a},l)=>e.jsx(Tl,{children:e.jsx(Ja,{ref:l,sideOffset:n,className:y("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),...a})}));os.displayName=Ja.displayName;const fe=m.forwardRef(({className:s,inset:n,...a},l)=>e.jsx(Qa,{ref:l,className:y("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),...a}));fe.displayName=Qa.displayName;const oc=m.forwardRef(({className:s,children:n,checked:a,...l},r)=>e.jsxs(Za,{ref:r,className:y("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:a,...l,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Xa,{children:e.jsx(Ps,{className:"h-4 w-4"})})}),n]}));oc.displayName=Za.displayName;const ic=m.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(en,{ref:l,className:y("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),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Xa,{children:e.jsx(Pl,{className:"h-4 w-4 fill-current"})})}),n]}));ic.displayName=en.displayName;const oa=m.forwardRef(({className:s,inset:n,...a},l)=>e.jsx(sn,{ref:l,className:y("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",s),...a}));oa.displayName=sn.displayName;const at=m.forwardRef(({className:s,...n},a)=>e.jsx(tn,{ref:a,className:y("-mx-1 my-1 h-px bg-muted",s),...n}));at.displayName=tn.displayName;const Yt=({className:s,...n})=>e.jsx("span",{className:y("ml-auto text-xs tracking-widest opacity-60",s),...n});Yt.displayName="DropdownMenuShortcut";const zt=[{code:"en-US",name:"English",flag:Il,shortName:"EN"},{code:"zh-CN",name:"中文",flag:Fl,shortName:"CN"},{code:"ko-KR",name:"한국어",flag:Ml,shortName:"KR"}];function tr(){const{i18n:s}=I(),n=r=>{s.changeLanguage(r)},a=zt.find(r=>r.code===s.language)||zt[1],l=a.flag;return e.jsxs(ys,{children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 px-2 gap-1",children:[e.jsx(l,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:"text-sm font-medium",children:a.shortName})]})}),e.jsx(os,{align:"end",className:"w-[120px]",children:zt.map(r=>{const i=r.flag,c=r.code===s.language;return e.jsxs(fe,{onClick:()=>n(r.code),className:y("flex items-center gap-2 px-2 py-1.5 cursor-pointer",c&&"bg-accent"),children:[e.jsx(i,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:y("text-sm",c&&"font-medium"),children:r.name})]},r.code)})})]})}function cc(){const[s,n]=m.useState(!1),{t:a}=I("auth"),l=a("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(tr,{})}),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(He,{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:a("signIn.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("signIn.description")})]}),e.jsx(tc,{onForgotPassword:()=>n(!0)})]})]})]}),e.jsx(ge,{open:s,onOpenChange:n,children:e.jsx(he,{children:e.jsxs(ve,{children:[e.jsx(je,{children:a("signIn.resetPassword.title")}),e.jsx(Te,{children:a("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:l}),e.jsx(J,{variant:"ghost",size:"icon",className:"absolute right-2 top-2 h-8 w-8 hover:bg-secondary-foreground/10",onClick:()=>wt(l).then(()=>{q.success(a("common:copy.success"))}),children:e.jsx(Ol,{className:"h-4 w-4"})})]})})]})})})]})}const dc=Object.freeze(Object.defineProperty({__proto__:null,default:cc},Symbol.toStringTag,{value:"Module"})),we=m.forwardRef(({className:s,fadedBelow:n=!1,fixedHeight:a=!1,...l},r)=>e.jsx("div",{ref:r,className:y("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",a&&"md:h-svh",s),...l}));we.displayName="Layout";const Ce=m.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:y("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...n}));Ce.displayName="LayoutHeader";const ke=m.forwardRef(({className:s,fixedHeight:n,...a},l)=>e.jsx("div",{ref:l,className:y("flex-1 overflow-hidden px-4 py-6 md:px-8",n&&"h-[calc(100%-var(--header-height))]",s),...a}));ke.displayName="LayoutBody";const ar=zl,nr=Ll,rr=Al,ie=$l,re=ql,le=Kl,te=m.forwardRef(({className:s,sideOffset:n=4,...a},l)=>e.jsx(an,{ref:l,sideOffset:n,className:y("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),...a}));te.displayName=an.displayName;function Vt(){const{pathname:s}=Xt();return{checkActiveNav:a=>{if(a==="/"&&s==="/")return!0;const l=a.replace(/^\//,""),r=s.replace(/^\//,"");return l?r.startsWith(l):!1}}}function lr({key:s,defaultValue:n}){const[a,l]=m.useState(()=>{const r=localStorage.getItem(s);return r!==null?JSON.parse(r):n});return m.useEffect(()=>{localStorage.setItem(s,JSON.stringify(a))},[a,s]),[a,l]}function mc(){const[s,n]=lr({key:"collapsed-sidebar-items",defaultValue:[]}),a=r=>!s.includes(r);return{isExpanded:a,toggleItem:r=>{a(r)?n([...s,r]):n(s.filter(i=>i!==r))}}}function uc({links:s,isCollapsed:n,className:a,closeNav:l}){const{t:r}=I(),i=({sub:c,...u})=>{const x=`${r(u.title)}-${u.href}`;return n&&c?m.createElement(fc,{...u,sub:c,key:x,closeNav:l}):n?m.createElement(hc,{...u,key:x,closeNav:l}):c?m.createElement(xc,{...u,sub:c,key:x,closeNav:l}):m.createElement(or,{...u,key:x,closeNav:l})};return e.jsx("div",{"data-collapsed":n,className:y("group border-b bg-background py-2 transition-[max-height,padding] duration-500 data-[collapsed=true]:py-2 md:border-none",a),children:e.jsx(ie,{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 or({title:s,icon:n,label:a,href:l,closeNav:r,subLink:i=!1}){const{checkActiveNav:c}=Vt(),{t:u}=I();return e.jsxs(Rs,{to:l,onClick:r,className:y(Ks({variant:c(l)?"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":c(l)?"page":void 0,children:[e.jsx("div",{className:"mr-2",children:n}),u(s),a&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:u(a)})]})}function xc({title:s,icon:n,label:a,sub:l,closeNav:r}){const{checkActiveNav:i}=Vt(),{isExpanded:c,toggleItem:u}=mc(),{t:x}=I(),o=!!l?.find(k=>i(k.href)),d=x(s),p=c(d)||o;return e.jsxs(ar,{open:p,onOpenChange:()=>u(d),children:[e.jsxs(nr,{className:y(Ks({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}),x(s),a&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:x(a)}),e.jsx("span",{className:y('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(nn,{stroke:1})})]}),e.jsx(rr,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:l.map(k=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(or,{...k,subLink:!0,closeNav:r})},x(k.title)))})})]})}function hc({title:s,icon:n,label:a,href:l,closeNav:r}){const{checkActiveNav:i}=Vt(),{t:c}=I();return e.jsxs(re,{delayDuration:0,children:[e.jsx(le,{asChild:!0,children:e.jsxs(Rs,{to:l,onClick:r,className:y(Ks({variant:i(l)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[n,e.jsx("span",{className:"sr-only",children:c(s)})]})}),e.jsxs(te,{side:"right",className:"flex items-center gap-4",children:[c(s),a&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:c(a)})]})]})}function fc({title:s,icon:n,label:a,sub:l,closeNav:r}){const{checkActiveNav:i}=Vt(),{t:c}=I(),u=!!l?.find(x=>i(x.href));return e.jsxs(ys,{children:[e.jsxs(re,{delayDuration:0,children:[e.jsx(le,{asChild:!0,children:e.jsx(Ns,{asChild:!0,children:e.jsx(E,{variant:u?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:n})})}),e.jsxs(te,{side:"right",className:"flex items-center gap-4",children:[c(s)," ",a&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:c(a)}),e.jsx(nn,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(os,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(oa,{children:[c(s)," ",a?`(${c(a)})`:""]}),e.jsx(at,{}),l.map(({title:x,icon:o,label:d,href:p})=>e.jsx(fe,{asChild:!0,children:e.jsxs(Rs,{to:p,onClick:r,className:`${i(p)?"bg-secondary":""}`,children:[o," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:c(x)}),d&&e.jsx("span",{className:"ml-auto text-xs",children:c(d)})]})},`${c(x)}-${p}`))]})]})}const ir=[{title:"nav:dashboard",label:"",href:"/",icon:e.jsx(Hl,{size:18})},{title:"nav:systemManagement",label:"",href:"",icon:e.jsx(Ul,{size:18}),sub:[{title:"nav:systemConfig",label:"",href:"/config/system",icon:e.jsx(rn,{size:18})},{title:"nav:themeConfig",label:"",href:"/config/theme",icon:e.jsx(Bl,{size:18})},{title:"nav:noticeManagement",label:"",href:"/config/notice",icon:e.jsx(Gl,{size:18})},{title:"nav:paymentConfig",label:"",href:"/config/payment",icon:e.jsx(_a,{size:18})},{title:"nav:knowledgeManagement",label:"",href:"/config/knowledge",icon:e.jsx(Wl,{size:18})}]},{title:"nav:nodeManagement",label:"",href:"",icon:e.jsx(ln,{size:18}),sub:[{title:"nav:nodeManagement",label:"",href:"/server/manage",icon:e.jsx(Yl,{size:18})},{title:"nav:permissionGroupManagement",label:"",href:"/server/group",icon:e.jsx(on,{size:18})},{title:"nav:routeManagement",label:"",href:"/server/route",icon:e.jsx(Jl,{size:18})}]},{title:"nav:subscriptionManagement",label:"",href:"",icon:e.jsx(Ql,{size:18}),sub:[{title:"nav:planManagement",label:"",href:"/finance/plan",icon:e.jsx(Zl,{size:18})},{title:"nav:orderManagement",label:"",href:"/finance/order",icon:e.jsx(_a,{size:18})},{title:"nav:couponManagement",label:"",href:"/finance/coupon",icon:e.jsx(Xl,{size:18})}]},{title:"nav:userManagement",label:"",href:"",icon:e.jsx(eo,{size:18}),sub:[{title:"nav:userManagement",label:"",href:"/user/manage",icon:e.jsx(so,{size:18})},{title:"nav:ticketManagement",label:"",href:"/user/ticket",icon:e.jsx(cn,{size:18})}]}];function pc({className:s,isCollapsed:n,setIsCollapsed:a}){const[l,r]=m.useState(!1),{t:i}=I();return m.useEffect(()=>{l?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[l]),e.jsxs("aside",{className:y(`fixed left-0 right-0 top-0 z-50 w-full 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:()=>r(!1),className:`absolute inset-0 transition-[opacity] delay-100 duration-700 ${l?"h-svh opacity-50":"h-0 opacity-0"} w-full bg-black md:hidden`}),e.jsxs(we,{children:[e.jsxs(Ce,{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(E,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":i("common:toggleNavigation"),"aria-controls":"sidebar-menu","aria-expanded":l,onClick:()=>r(c=>!c),children:l?e.jsx(to,{}):e.jsx(ao,{})})]}),e.jsx(uc,{id:"sidebar-menu",className:`h-full flex-1 overflow-auto ${l?"max-h-screen":"max-h-0 py-0 md:max-h-screen md:py-2"}`,closeNav:()=>r(!1),isCollapsed:n,links:ir}),e.jsx("div",{className:y("px-4 py-3 text-xs text-muted-foreground/70 border-t border-border/50 bg-muted/20","transition-all duration-200 ease-in-out",n?"text-center":"text-left"),children:e.jsxs("div",{className:y("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/70"}),e.jsxs("span",{className:"tracking-wide",children:["v",window?.settings?.version]})]})}),e.jsx(E,{onClick:()=>a(c=>!c),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(no,{stroke:1.5,className:`h-5 w-5 ${n?"rotate-180":""}`})})]})]})}function gc(){const[s,n]=lr({key:"collapsed-sidebar",defaultValue:!1});return m.useEffect(()=>{const a=()=>{n(window.innerWidth<768?!1:s)};return a(),window.addEventListener("resize",a),()=>{window.removeEventListener("resize",a)}},[s,n]),[s,n]}function jc(){const[s,n]=gc();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(pc,{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(ea,{})})]})}const vc=Object.freeze(Object.defineProperty({__proto__:null,default:jc},Symbol.toStringTag,{value:"Module"})),_s=m.forwardRef(({className:s,...n},a)=>e.jsx(Se,{ref:a,className:y("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...n}));_s.displayName=Se.displayName;const bc=({children:s,...n})=>e.jsx(ge,{...n,children:e.jsx(he,{className:"overflow-hidden p-0",children:e.jsx(_s,{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})})}),Vs=m.forwardRef(({className:s,...n},a)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(ro,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(Se.Input,{ref:a,className:y("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})]}));Vs.displayName=Se.Input.displayName;const ws=m.forwardRef(({className:s,...n},a)=>e.jsx(Se.List,{ref:a,className:y("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...n}));ws.displayName=Se.List.displayName;const Is=m.forwardRef((s,n)=>e.jsx(Se.Empty,{ref:n,className:"py-6 text-center text-sm",...s}));Is.displayName=Se.Empty.displayName;const Ie=m.forwardRef(({className:s,...n},a)=>e.jsx(Se.Group,{ref:a,className:y("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}));Ie.displayName=Se.Group.displayName;const Hs=m.forwardRef(({className:s,...n},a)=>e.jsx(Se.Separator,{ref:a,className:y("-mx-1 h-px bg-border",s),...n}));Hs.displayName=Se.Separator.displayName;const _e=m.forwardRef(({className:s,...n},a)=>e.jsx(Se.Item,{ref:a,className:y("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}));_e.displayName=Se.Item.displayName;function yc(){const s=[];for(const n of ir)if(n.href&&s.push(n),n.sub)for(const a of n.sub)s.push({...a,parent:n.title});return s}function Pe(){const[s,n]=m.useState(!1),a=is(),l=yc(),{t:r}=I("search"),{t:i}=I("nav");m.useEffect(()=>{const u=x=>{x.key==="k"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),n(o=>!o))};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[]);const c=m.useCallback(u=>{n(!1),a(u)},[a]);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(lo,{className:"h-4 w-4 xl:mr-2"}),e.jsx("span",{className:"hidden xl:inline-flex",children:r("placeholder")}),e.jsx("span",{className:"sr-only",children:r("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:r("shortcut.key")})]}),e.jsxs(bc,{open:s,onOpenChange:n,children:[e.jsx(Vs,{placeholder:r("placeholder")}),e.jsxs(ws,{children:[e.jsx(Is,{children:r("noResults")}),e.jsx(Ie,{heading:r("title"),children:l.map(u=>e.jsxs(_e,{value:`${u.parent?u.parent+" ":""}${u.title}`,onSelect:()=>c(u.href),children:[e.jsx("div",{className:"mr-2",children:u.icon}),e.jsx("span",{children:i(u.title)}),u.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:i(u.parent)})]},u.href))})]})]})]})}function Re(){const{theme:s,setTheme:n}=ki();return m.useEffect(()=>{const a=s==="dark"?"#020817":"#fff",l=document.querySelector("meta[name='theme-color']");l&&l.setAttribute("content",a)},[s]),e.jsxs(e.Fragment,{children:[e.jsx(E,{size:"icon",variant:"ghost",className:"rounded-full",onClick:()=>n(s==="light"?"dark":"light"),children:s==="light"?e.jsx(oo,{size:20}):e.jsx(io,{size:20})}),e.jsx(tr,{})]})}const cr=m.forwardRef(({className:s,...n},a)=>e.jsx(dn,{ref:a,className:y("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...n}));cr.displayName=dn.displayName;const dr=m.forwardRef(({className:s,...n},a)=>e.jsx(mn,{ref:a,className:y("aspect-square h-full w-full",s),...n}));dr.displayName=mn.displayName;const mr=m.forwardRef(({className:s,...n},a)=>e.jsx(un,{ref:a,className:y("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...n}));mr.displayName=un.displayName;function Ee(){const s=is(),n=Ha(),a=co(Gi),{t:l}=I(["common"]),r=()=>{Wn(),n(Bi()),s("/sign-in")},i=a?.email?.split("@")[0]||l("common:user"),c=i.substring(0,2).toUpperCase();return e.jsxs(ys,{children:[e.jsx(Ns,{asChild:!0,children:e.jsx(E,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(cr,{className:"h-8 w-8",children:[e.jsx(dr,{src:a?.avatar_url,alt:i}),e.jsx(mr,{children:c})]})})}),e.jsxs(os,{className:"w-56",align:"end",forceMount:!0,children:[e.jsx(oa,{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:a?.email||l("common:defaultEmail")})]})}),e.jsx(at,{}),e.jsx(fe,{asChild:!0,children:e.jsxs(Rs,{to:"/config/system",children:[l("common:settings"),e.jsx(Yt,{children:"⌘S"})]})}),e.jsx(at,{}),e.jsxs(fe,{onClick:r,children:[l("common:logout"),e.jsx(Yt,{children:"⇧⌘Q"})]})]})]})}const Qe=window?.settings?.secure_path,ur=5*60*1e3,Jt=new Map,Nc=s=>{const n=Jt.get(s);return n?Date.now()-n.timestamp>ur?(Jt.delete(s),null):n.data:null},_c=(s,n)=>{Jt.set(s,{data:n,timestamp:Date.now()})},wc=async(s,n=ur)=>{const a=Nc(s);if(a)return a;const l=await O.get(s);return _c(s,l),l},Cc={getList:()=>wc(`${Qe}/notice/fetch`),save:s=>O.post(`${Qe}/notice/save`,s),drop:s=>O.post(`${Qe}/notice/drop`,{id:s}),updateStatus:s=>O.post(`${Qe}/notice/show`,{id:s}),sort:s=>O.post(`${Qe}/notice/sort`,{ids:s})},Va={getSystemStatus:()=>O.get(`${Qe}/system/getSystemStatus`),getQueueStats:()=>O.get(`${Qe}/system/getQueueStats`),getQueueWorkload:()=>O.get(`${Qe}/system/getQueueWorkload`),getQueueMasters:()=>O.get(`${Qe}/system/getQueueMasters`),getSystemLog:s=>O.get(`${Qe}/system/getSystemLog`,{params:s})},L=window?.settings?.secure_path,Sc=s=>O.get(L+"/stat/getOrder",{params:s}),kc=()=>O.get(L+"/stat/getStats"),Ia=s=>O.get(L+"/stat/getTrafficRank",{params:s}),Dc=()=>O.get(L+"/theme/getThemes"),Tc=s=>O.post(L+"/theme/getThemeConfig",{name:s}),Pc=(s,n)=>O.post(L+"/theme/saveThemeConfig",{name:s,config:n}),Rc=s=>{const n=new FormData;return n.append("file",s),O.post(L+"/theme/upload",n,{headers:{"Content-Type":"multipart/form-data"}})},Ec=s=>O.post(L+"/theme/delete",{name:s}),Vc=s=>O.post(L+"/config/save",s),xr=()=>O.get(L+"/server/manage/getNodes"),Ic=s=>O.post(L+"/server/manage/save",s),Fc=s=>O.post(L+"/server/manage/drop",s),Mc=s=>O.post(L+"/server/manage/copy",s),Oc=s=>O.post(L+"/server/manage/update",s),zc=s=>O.post(L+"/server/manage/sort",s),It=()=>O.get(L+"/server/group/fetch"),Lc=s=>O.post(L+"/server/group/save",s),Ac=s=>O.post(L+"/server/group/drop",s),hr=()=>O.get(L+"/server/route/fetch"),$c=s=>O.post(L+"/server/route/save",s),qc=s=>O.post(L+"/server/route/drop",s),Kc=()=>O.get(L+"/payment/fetch"),Hc=()=>O.get(L+"/payment/getPaymentMethods"),Uc=s=>O.post(L+"/payment/getPaymentForm",s),Bc=s=>O.post(L+"/payment/save",s),Gc=s=>O.post(L+"/payment/drop",s),Wc=s=>O.post(L+"/payment/show",s),Yc=s=>O.post(L+"/payment/sort",s),Jc=()=>O.get(L+"/notice/fetch"),Qc=s=>O.post(L+"/notice/save",s),Zc=s=>O.post(L+"/notice/drop",s),Xc=s=>O.post(L+"/notice/show",s),ed=()=>O.get(L+"/knowledge/fetch"),sd=s=>O.get(L+"/knowledge/fetch?id="+s),td=s=>O.post(L+"/knowledge/save",s),ad=s=>O.post(L+"/knowledge/drop",s),nd=s=>O.post(L+"/knowledge/show",s),rd=s=>O.post(L+"/knowledge/sort",s),Fs=()=>O.get(L+"/plan/fetch"),ld=s=>O.post(L+"/plan/save",s),Lt=s=>O.post(L+"/plan/update",s),od=s=>O.post(L+"/plan/drop",s),id=s=>O.post(L+"/plan/sort",{ids:s}),cd=async s=>O.post(L+"/order/fetch",s),dd=s=>O.post(L+"/order/detail",s),md=s=>O.post(L+"/order/paid",s),ud=s=>O.post(L+"/order/cancel",s),Fa=s=>O.post(L+"/order/update",s),xd=s=>O.post(L+"/order/assign",s),hd=s=>O.post(L+"/coupon/fetch",s),fd=s=>O.post(L+"/coupon/generate",s),pd=s=>O.post(L+"/coupon/drop",s),gd=s=>O.post(L+"/coupon/update",s),jd=s=>O.post(L+"/user/fetch",s),vd=s=>O.post(L+"/user/update",s),bd=s=>O.post(L+"/user/resetSecret",s),yd=s=>O.post(L+"/user/generate",s),Nd=s=>O.post(L+"/stat/getStatUser",s),_d=s=>O.post(L+"/ticket/fetch",s),wd=s=>O.get(L+"/ticket/fetch?id= "+s),Cd=s=>O.post(L+"/ticket/reply",s),fr=s=>O.post(L+"/ticket/close",{id:s}),us=(s="")=>O.get(L+"/config/fetch?key="+s),xs=s=>O.post(L+"/config/save",s),Sd=()=>O.get(L+"/config/getEmailTemplate"),kd=()=>O.post(L+"/config/testSendMail"),Dd=()=>O.post(L+"/config/setTelegramWebhook"),Td=Cc.sort,pr=mo,ia=m.forwardRef(({className:s,...n},a)=>e.jsx(xn,{ref:a,className:y("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...n}));ia.displayName=xn.displayName;const nt=m.forwardRef(({className:s,...n},a)=>e.jsx(hn,{ref:a,className:y("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}));nt.displayName=hn.displayName;const Pd=m.forwardRef(({className:s,...n},a)=>e.jsx(fn,{ref:a,className:y("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...n}));Pd.displayName=fn.displayName;const W=uo,fs=bo,Y=xo,B=m.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(pn,{ref:l,className:y("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),...a,children:[n,e.jsx(ho,{asChild:!0,children:e.jsx(aa,{className:"h-4 w-4 opacity-50"})})]}));B.displayName=pn.displayName;const gr=m.forwardRef(({className:s,...n},a)=>e.jsx(gn,{ref:a,className:y("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(fo,{className:"h-4 w-4"})}));gr.displayName=gn.displayName;const jr=m.forwardRef(({className:s,...n},a)=>e.jsx(jn,{ref:a,className:y("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(aa,{className:"h-4 w-4"})}));jr.displayName=jn.displayName;const G=m.forwardRef(({className:s,children:n,position:a="popper",...l},r)=>e.jsx(po,{children:e.jsxs(vn,{ref:r,className:y("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",a==="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:a,...l,children:[e.jsx(gr,{}),e.jsx(go,{className:y("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx(jr,{})]})}));G.displayName=vn.displayName;const Rd=m.forwardRef(({className:s,...n},a)=>e.jsx(bn,{ref:a,className:y("px-2 py-1.5 text-sm font-semibold",s),...n}));Rd.displayName=bn.displayName;const $=m.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(yn,{ref:l,className:y("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),...a,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(jo,{children:e.jsx(Ps,{className:"h-4 w-4"})})}),e.jsx(vo,{children:n})]}));$.displayName=yn.displayName;const Ed=m.forwardRef(({className:s,...n},a)=>e.jsx(Nn,{ref:a,className:y("-mx-1 my-1 h-px bg-muted",s),...n}));Ed.displayName=Nn.displayName;function Ms({className:s,classNames:n,showOutsideDays:a=!0,...l}){return e.jsx(yo,{showOutsideDays:a,className:y("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:y(qs({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:y("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",l.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:y(qs({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:r,...i})=>e.jsx(_n,{className:y("h-4 w-4",r),...i}),IconRight:({className:r,...i})=>e.jsx(ta,{className:y("h-4 w-4",r),...i})},...l})}Ms.displayName="Calendar";const as=_o,ns=wo,We=m.forwardRef(({className:s,align:n="center",sideOffset:a=4,...l},r)=>e.jsx(No,{children:e.jsx(wn,{ref:r,align:n,sideOffset:a,className:y("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),...l})}));We.displayName=wn.displayName;const ps={income:{main:"hsl(var(--primary))",gradient:{start:"hsl(var(--primary))",end:"transparent"}},commission:{main:"hsl(var(--secondary))",gradient:{start:"hsl(var(--secondary))",end:"transparent"}}},Qs=s=>(s/100).toFixed(2),Vd=({active:s,payload:n,label:a})=>{const{t:l}=I();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:a}),n.map((r,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:r.color}}),e.jsxs("span",{className:"text-muted-foreground",children:[l(r.name),":"]}),e.jsx("span",{className:"font-medium",children:r.name.includes(l("dashboard:overview.amount"))?`¥${Qs(r.value)}`:l("dashboard:overview.transactions",{count:r.value})})]},i))]}):null},Id=[{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"}],Fd=(s,n)=>{const a=new Date;if(s==="custom"&&n)return{startDate:n.from,endDate:n.to};let l;switch(s){case"7d":l=qe(a,7);break;case"30d":l=qe(a,30);break;case"90d":l=qe(a,90);break;case"180d":l=qe(a,180);break;case"365d":l=qe(a,365);break;default:l=qe(a,30)}return{startDate:l,endDate:a}};function Md(){const[s,n]=m.useState("amount"),[a,l]=m.useState("30d"),[r,i]=m.useState({from:qe(new Date,7),to:new Date}),{t:c}=I(),{startDate:u,endDate:x}=Fd(a,r),{data:o}=se({queryKey:["orderStat",{start_date:$e(u,"yyyy-MM-dd"),end_date:$e(x,"yyyy-MM-dd")}],queryFn:async()=>{const{data:d}=await Sc({start_date:$e(u,"yyyy-MM-dd"),end_date:$e(x,"yyyy-MM-dd")});return d},refetchInterval:3e4});return e.jsxs(He,{children:[e.jsx(ss,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(bs,{children:c("dashboard:overview.title")}),e.jsxs(tt,{children:[o?.summary.start_date," ",c("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(W,{value:a,onValueChange:d=>l(d),children:[e.jsx(B,{className:"w-[120px]",children:e.jsx(Y,{placeholder:c("dashboard:overview.selectTimeRange")})}),e.jsx(G,{children:Id.map(d=>e.jsx($,{value:d.value,children:c(d.label)},d.value))})]}),a==="custom"&&e.jsxs(as,{children:[e.jsx(ns,{asChild:!0,children:e.jsxs(J,{variant:"outline",className:y("min-w-0 justify-start text-left font-normal",!r&&"text-muted-foreground"),children:[e.jsx(it,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:r?.from?r.to?e.jsxs(e.Fragment,{children:[$e(r.from,"yyyy-MM-dd")," -"," ",$e(r.to,"yyyy-MM-dd")]}):$e(r.from,"yyyy-MM-dd"):c("dashboard:overview.selectDate")})]})}),e.jsx(We,{className:"w-auto p-0",align:"end",children:e.jsx(Ms,{mode:"range",defaultMonth:r?.from,selected:{from:r?.from,to:r?.to},onSelect:d=>{d?.from&&d?.to&&i({from:d.from,to:d.to})},numberOfMonths:2})})]})]}),e.jsx(pr,{value:s,onValueChange:d=>n(d),children:e.jsxs(ia,{children:[e.jsx(nt,{value:"amount",children:c("dashboard:overview.amount")}),e.jsx(nt,{value:"count",children:c("dashboard:overview.count")})]})})]})]})}),e.jsxs(ts,{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:c("dashboard:overview.totalIncome")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",Qs(o?.summary?.paid_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:c("dashboard:overview.totalTransactions",{count:o?.summary?.paid_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[c("dashboard:overview.avgOrderAmount")," ¥",Qs(o?.summary?.avg_paid_amount||0)]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:c("dashboard:overview.totalCommission")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",Qs(o?.summary?.commission_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:c("dashboard:overview.totalTransactions",{count:o?.summary?.commission_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[c("dashboard:overview.commissionRate")," ",o?.summary?.commission_rate.toFixed(2)||0,"%"]})]})]}),e.jsx("div",{className:"h-[400px] w-full",children:e.jsx(Co,{width:"100%",height:"100%",children:e.jsxs(So,{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:ps.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:ps.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:ps.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:ps.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(ko,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:d=>$e(new Date(d),"MM-dd",{locale:Ro})}),e.jsx(Do,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:d=>s==="amount"?`¥${Qs(d)}`:c("dashboard:overview.transactions",{count:d})}),e.jsx(To,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(Po,{content:e.jsx(Vd,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(wa,{type:"monotone",dataKey:"paid_total",name:c("dashboard:overview.orderAmount"),stroke:ps.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(wa,{type:"monotone",dataKey:"commission_total",name:c("dashboard:overview.commissionAmount"),stroke:ps.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ca,{dataKey:"paid_count",name:c("dashboard:overview.orderCount"),fill:ps.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(Ca,{dataKey:"commission_count",name:c("dashboard:overview.commissionCount"),fill:ps.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})]})]})}function Ve({className:s,...n}){return e.jsx("div",{className:y("animate-pulse rounded-md bg-primary/10",s),...n})}function Od(){return e.jsxs(He,{children:[e.jsxs(ss,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ve,{className:"h-4 w-[120px]"}),e.jsx(Ve,{className:"h-4 w-4"})]}),e.jsxs(ts,{children:[e.jsx(Ve,{className:"h-8 w-[140px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{className:"h-4 w-4"}),e.jsx(Ve,{className:"h-4 w-[100px]"})]})]})]})}function zd(){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(Od,{},n))})}var Z=(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))(Z||{});const Ys={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},Js={0:"yellow-500",1:"blue-500",2:"red-500",3:"green-500",4:"green-500"};var Ke=(s=>(s[s.NEW=1]="NEW",s[s.RENEWAL=2]="RENEWAL",s[s.UPGRADE=3]="UPGRADE",s[s.RESET_FLOW=4]="RESET_FLOW",s))(Ke||{}),ne=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(ne||{});const ut={0:"待确认",1:"发放中",2:"有效",3:"无效"},xt={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var de=(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))(de||{});const Ld={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var ye=(s=>(s.Shadowsocks="shadowsocks",s.Vmess="vmess",s.Trojan="trojan",s.Hysteria="hysteria",s.Vless="vless",s))(ye||{});const Ds=[{type:"shadowsocks",label:"Shadowsocks"},{type:"vmess",label:"VMess"},{type:"trojan",label:"Trojan"},{type:"hysteria",label:"Hysteria"},{type:"vless",label:"VLess"}],ls={shadowsocks:"#489851",vmess:"#CB3180",trojan:"#EBB749",hysteria:"#5684e6",vless:"#1a1a1a"};var js=(s=>(s[s.AMOUNT=1]="AMOUNT",s[s.PERCENTAGE=2]="PERCENTAGE",s))(js||{});const Ad={1:"按金额优惠",2:"按比例优惠"};var et=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(et||{}),Xe=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(Xe||{});function gs({title:s,value:n,icon:a,trend:l,description:r,onClick:i,highlight:c,className:u}){return e.jsxs(He,{className:y("transition-colors",i&&"cursor-pointer hover:bg-muted/50",c&&"border-primary/50",u),onClick:i,children:[e.jsxs(ss,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(bs,{className:"text-sm font-medium",children:s}),a]}),e.jsxs(ts,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n}),l?e.jsxs("div",{className:"flex items-center pt-1",children:[e.jsx(Oo,{className:y("h-4 w-4",l.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:y("ml-1 text-xs",l.isPositive?"text-emerald-500":"text-red-500"),children:[l.isPositive?"+":"-",Math.abs(l.value),"%"]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:l.label})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]})]})}function $d({className:s}){const n=is(),{t:a}=I(),{data:l,isLoading:r}=se({queryKey:["dashboardStats"],queryFn:async()=>(await kc()).data,refetchInterval:1e3*60*5});if(r||!l)return e.jsx(zd,{});const i=()=>{const c=new URLSearchParams;c.set("commission_status",ne.PENDING.toString()),c.set("status",Z.COMPLETED.toString()),c.set("commission_balance","gt:0"),n(`/finance/order?${c.toString()}`)};return e.jsxs("div",{className:y("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(gs,{title:a("dashboard:stats.todayIncome"),value:ks(l.todayIncome),icon:e.jsx(Eo,{className:"h-4 w-4 text-emerald-500"}),trend:{value:l.dayIncomeGrowth,label:a("dashboard:stats.vsYesterday"),isPositive:l.dayIncomeGrowth>0}}),e.jsx(gs,{title:a("dashboard:stats.monthlyIncome"),value:ks(l.currentMonthIncome),icon:e.jsx(Vo,{className:"h-4 w-4 text-blue-500"}),trend:{value:l.monthIncomeGrowth,label:a("dashboard:stats.vsLastMonth"),isPositive:l.monthIncomeGrowth>0}}),e.jsx(gs,{title:a("dashboard:stats.pendingTickets"),value:l.ticketPendingTotal,icon:e.jsx(Io,{className:y("h-4 w-4",l.ticketPendingTotal>0?"text-orange-500":"text-muted-foreground")}),description:l.ticketPendingTotal>0?a("dashboard:stats.hasPendingTickets"):a("dashboard:stats.noPendingTickets"),onClick:()=>n("/user/ticket"),highlight:l.ticketPendingTotal>0}),e.jsx(gs,{title:a("dashboard:stats.pendingCommission"),value:l.commissionPendingTotal,icon:e.jsx(Fo,{className:y("h-4 w-4",l.commissionPendingTotal>0?"text-blue-500":"text-muted-foreground")}),description:l.commissionPendingTotal>0?a("dashboard:stats.hasPendingCommission"):a("dashboard:stats.noPendingCommission"),onClick:i,highlight:l.commissionPendingTotal>0}),e.jsx(gs,{title:a("dashboard:stats.monthlyNewUsers"),value:l.currentMonthNewUsers,icon:e.jsx(Kt,{className:"h-4 w-4 text-blue-500"}),trend:{value:l.userGrowth,label:a("dashboard:stats.vsLastMonth"),isPositive:l.userGrowth>0}}),e.jsx(gs,{title:a("dashboard:stats.totalUsers"),value:l.totalUsers,icon:e.jsx(Kt,{className:"h-4 w-4 text-muted-foreground"}),description:a("dashboard:stats.activeUsers",{count:l.activeUsers})}),e.jsx(gs,{title:a("dashboard:stats.monthlyUpload"),value:Ze(l.monthTraffic.upload),icon:e.jsx(Ht,{className:"h-4 w-4 text-emerald-500"}),description:a("dashboard:stats.todayTraffic",{value:Ze(l.todayTraffic.upload)})}),e.jsx(gs,{title:a("dashboard:stats.monthlyDownload"),value:Ze(l.monthTraffic.download),icon:e.jsx(Mo,{className:"h-4 w-4 text-blue-500"}),description:a("dashboard:stats.todayTraffic",{value:Ze(l.todayTraffic.download)})})]})}const rt=m.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(Cn,{ref:l,className:y("relative overflow-hidden",s),...a,children:[e.jsx(zo,{className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(Ct,{}),e.jsx(Lo,{})]}));rt.displayName=Cn.displayName;const Ct=m.forwardRef(({className:s,orientation:n="vertical",...a},l)=>e.jsx(Sn,{ref:l,orientation:n,className:y("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),...a,children:e.jsx(Ao,{className:"relative flex-1 rounded-full bg-border"})}));Ct.displayName=Sn.displayName;const Qt={today:{getValue:()=>{const s=qo();return{start:s,end:Ko(s,1)}}},last7days:{getValue:()=>{const s=new Date;return{start:qe(s,7),end:s}}},last30days:{getValue:()=>{const s=new Date;return{start:qe(s,30),end:s}}},custom:{getValue:()=>null}};function Ma({selectedRange:s,customDateRange:n,onRangeChange:a,onCustomRangeChange:l}){const{t:r}=I(),i={today:r("dashboard:trafficRank.today"),last7days:r("dashboard:trafficRank.last7days"),last30days:r("dashboard:trafficRank.last30days"),custom:r("dashboard:trafficRank.customRange")};return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsxs(W,{value:s,onValueChange:a,children:[e.jsx(B,{className:"w-[120px]",children:e.jsx(Y,{placeholder:r("dashboard:trafficRank.selectTimeRange")})}),e.jsx(G,{position:"popper",className:"z-50",children:Object.entries(Qt).map(([c])=>e.jsx($,{value:c,children:i[c]},c))})]}),s==="custom"&&e.jsxs(as,{children:[e.jsx(ns,{asChild:!0,children:e.jsxs(J,{variant:"outline",className:y("min-w-0 justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(it,{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:[$e(n.from,"yyyy-MM-dd")," -"," ",$e(n.to,"yyyy-MM-dd")]}):$e(n.from,"yyyy-MM-dd"):e.jsx("span",{children:r("dashboard:trafficRank.selectDateRange")})})]})}),e.jsx(We,{className:"w-auto p-0",align:"end",children:e.jsx(Ms,{mode:"range",defaultMonth:n?.from,selected:{from:n?.from,to:n?.to},onSelect:c=>{c?.from&&c?.to&&l({from:c.from,to:c.to})},numberOfMonths:2})})]})]})}const zs=s=>`${(s/1024/1024/1024).toFixed(2)} GB`;function qd({className:s}){const{t:n}=I(),[a,l]=m.useState("today"),[r,i]=m.useState({from:qe(new Date,7),to:new Date}),[c,u]=m.useState("today"),[x,o]=m.useState({from:qe(new Date,7),to:new Date}),d=m.useMemo(()=>a==="custom"?{start:r.from,end:r.to}:Qt[a].getValue(),[a,r]),p=m.useMemo(()=>c==="custom"?{start:x.from,end:x.to}:Qt[c].getValue(),[c,x]),{data:k}=se({queryKey:["nodeTrafficRank",d.start,d.end],queryFn:()=>Ia({type:"node",start_time:pe.round(d.start.getTime()/1e3),end_time:pe.round(d.end.getTime()/1e3)}),refetchInterval:3e4}),{data:V}=se({queryKey:["userTrafficRank",p.start,p.end],queryFn:()=>Ia({type:"user",start_time:pe.round(p.start.getTime()/1e3),end_time:pe.round(p.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:y("grid gap-4 md:grid-cols-2",s),children:[e.jsxs(He,{children:[e.jsx(ss,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(bs,{className:"flex items-center text-base font-medium",children:[e.jsx($o,{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(Ma,{selectedRange:a,customDateRange:r,onRangeChange:l,onCustomRangeChange:i}),e.jsx(Sa,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(ts,{className:"flex-1",children:k?.data?e.jsxs(rt,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:k.data.map(f=>e.jsx(ie,{delayDuration:200,children:e.jsxs(re,{children:[e.jsx(le,{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:f.name}),e.jsxs("span",{className:y("ml-2 flex items-center text-xs font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?e.jsx(Ut,{className:"mr-1 h-3 w-3"}):e.jsx(Bt,{className:"mr-1 h-3 w-3"}),Math.abs(f.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:`${f.value/k.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:zs(f.value)})]})]})})}),e.jsx(te,{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:zs(f.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:zs(f.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:y("font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?"+":"",f.change,"%"]})]})})]})},f.id))}),e.jsx(Ct,{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(He,{children:[e.jsx(ss,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(bs,{className:"flex items-center text-base font-medium",children:[e.jsx(Kt,{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(Ma,{selectedRange:c,customDateRange:x,onRangeChange:u,onCustomRangeChange:o}),e.jsx(Sa,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(ts,{className:"flex-1",children:V?.data?e.jsxs(rt,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:V.data.map(f=>e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{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:f.name}),e.jsxs("span",{className:y("ml-2 flex items-center text-xs font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?e.jsx(Ut,{className:"mr-1 h-3 w-3"}):e.jsx(Bt,{className:"mr-1 h-3 w-3"}),Math.abs(f.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:`${f.value/V.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:zs(f.value)})]})]})})}),e.jsx(te,{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:zs(f.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:zs(f.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:y("font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?"+":"",f.change,"%"]})]})})]})},f.id))}),e.jsx(Ct,{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 Kd=Ts("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 K({className:s,variant:n,...a}){return e.jsx("div",{className:y(Kd({variant:n}),s),...a})}const vt=m.forwardRef(({className:s,value:n,...a},l)=>e.jsx(kn,{ref:l,className:y("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...a,children:e.jsx(Ho,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(n||0)}%)`}})}));vt.displayName=kn.displayName;function Hd(){const{t:s}=I(),[n,a]=m.useState(null),[l,r]=m.useState(null),[i,c]=m.useState(!0),[u,x]=m.useState(!1),o=async()=>{try{x(!0);const[k,V]=await Promise.all([Va.getSystemStatus(),Va.getQueueStats()]);a(k.data),r(V.data)}catch(k){console.error("Error fetching system data:",k)}finally{c(!1),x(!1)}};m.useEffect(()=>{o();const k=setInterval(o,3e4);return()=>clearInterval(k)},[]);const d=()=>{o()};if(i)return e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx(na,{className:"h-6 w-6 animate-spin"})});const p=k=>k?e.jsx(Dn,{className:"h-5 w-5 text-green-500"}):e.jsx(Tn,{className:"h-5 w-5 text-red-500"});return e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(He,{children:[e.jsxs(ss,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(bs,{className:"flex items-center gap-2",children:[e.jsx(Uo,{className:"h-5 w-5"}),s("dashboard:queue.title")]}),e.jsx(tt,{children:s("dashboard:queue.status.description")})]}),e.jsx(J,{variant:"outline",size:"icon",onClick:d,disabled:u,children:e.jsx(Bo,{className:y("h-4 w-4",u&&"animate-spin")})})]}),e.jsx(ts,{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:[p(l?.status||!1),e.jsx("span",{className:"font-medium",children:s("dashboard:queue.status.running")})]}),e.jsx(K,{variant:l?.status?"secondary":"destructive",children:l?.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:l?.wait?.default||0})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{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:l?.recentJobs||0}),e.jsx(vt,{value:(l?.recentJobs||0)/(l?.periods?.recentJobs||1)*100,className:"h-1"})]})}),e.jsx(te,{children:e.jsx("p",{children:s("dashboard:queue.details.statisticsPeriod",{hours:l?.periods?.recentJobs||0})})})]})}),e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{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:l?.jobsPerMinute||0}),e.jsx(vt,{value:(l?.jobsPerMinute||0)/(l?.queueWithMaxThroughput?.throughput||1)*100,className:"h-1"})]})}),e.jsx(te,{children:e.jsx("p",{children:s("dashboard:queue.details.maxThroughput",{value:l?.queueWithMaxThroughput?.throughput||0})})})]})})]})]})})]}),e.jsxs(He,{children:[e.jsxs(ss,{children:[e.jsxs(bs,{className:"flex items-center gap-2",children:[e.jsx(Go,{className:"h-5 w-5"}),s("dashboard:queue.jobDetails")]}),e.jsx(tt,{children:s("dashboard:queue.details.description")})]}),e.jsx(ts,{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:l?.failedJobs||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("dashboard:queue.details.retentionPeriod",{hours:l?.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:[l?.queueWithMaxRuntime?.runtime||0,"s"]}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:l?.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:[l?.processes||0," /"," ",(l?.processes||0)+(l?.pausedMasters||0)]})]}),e.jsx(vt,{value:(l?.processes||0)/((l?.processes||0)+(l?.pausedMasters||0))*100,className:"mt-2 h-1"})]})]})})]})]})}function Ud(){const{t:s}=I();return e.jsxs(we,{children:[e.jsxs(Ce,{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(Pe,{}),e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsx(ke,{children:e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsx($d,{}),e.jsx(Md,{}),e.jsx(qd,{}),e.jsx(Hd,{})]})})})]})}const Bd=Object.freeze(Object.defineProperty({__proto__:null,default:Ud},Symbol.toStringTag,{value:"Module"})),be=m.forwardRef(({className:s,orientation:n="horizontal",decorative:a=!0,...l},r)=>e.jsx(Pn,{ref:r,decorative:a,orientation:n,className:y("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...l}));be.displayName=Pn.displayName;function Gd({className:s,items:n,...a}){const{pathname:l}=Xt(),r=is(),[i,c]=m.useState(l??"/settings"),u=o=>{c(o),r(o)},{t:x}=I("settings");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-1 md:hidden",children:e.jsxs(W,{value:i,onValueChange:u,children:[e.jsx(B,{className:"h-12 sm:w-48",children:e.jsx(Y,{placeholder:"Theme"})}),e.jsx(G,{children:n.map(o=>e.jsx($,{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:x(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:y("flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",s),...a,children:n.map(o=>e.jsxs(Rs,{to:o.href,className:y(Ks({variant:"ghost"}),l===o.href?"bg-muted hover:bg-muted":"hover:bg-transparent hover:underline","justify-start"),children:[e.jsx("span",{className:"mr-2",children:o.icon}),x(o.title)]},o.href))})})]})}const Wd=[{title:"site.title",key:"site",icon:e.jsx(Wo,{size:18}),href:"/config/system",description:"site.description"},{title:"safe.title",key:"safe",icon:e.jsx(on,{size:18}),href:"/config/system/safe",description:"safe.description"},{title:"subscribe.title",key:"subscribe",icon:e.jsx(cn,{size:18}),href:"/config/system/subscribe",description:"subscribe.description"},{title:"invite.title",key:"invite",icon:e.jsx(Yo,{size:18}),href:"/config/system/invite",description:"invite.description"},{title:"server.title",key:"server",icon:e.jsx(ln,{size:18}),href:"/config/system/server",description:"server.description"},{title:"email.title",key:"email",icon:e.jsx(Jo,{size:18}),href:"/config/system/email",description:"email.description"},{title:"telegram.title",key:"telegram",icon:e.jsx(Qo,{size:18}),href:"/config/system/telegram",description:"telegram.description"},{title:"app.title",key:"app",icon:e.jsx(rn,{size:18}),href:"/config/system/app",description:"app.description"}];function Yd(){const{t:s}=I("settings");return e.jsxs(we,{fadedBelow:!0,fixedHeight:!0,children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(be,{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(Gd,{items:Wd})}),e.jsx("div",{className:"w-full p-1 pr-4 lg:max-w-xl",children:e.jsx("div",{className:"pb-16",children:e.jsx(ea,{})})})]})]})]})}const Jd=Object.freeze(Object.defineProperty({__proto__:null,default:Yd},Symbol.toStringTag,{value:"Module"})),H=m.forwardRef(({className:s,...n},a)=>e.jsx(Rn,{className:y("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:a,children:e.jsx(Zo,{className:y("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")})}));H.displayName=Rn.displayName;const Cs=m.forwardRef(({className:s,...n},a)=>e.jsx("textarea",{className:y("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:a,...n}));Cs.displayName="Textarea";const Qd=h.object({logo:h.string().nullable().default(""),force_https:h.number().nullable().default(0),stop_register:h.number().nullable().default(0),app_name:h.string().nullable().default(""),app_description:h.string().nullable().default(""),app_url:h.string().nullable().default(""),subscribe_url:h.string().nullable().default(""),try_out_plan_id:h.number().nullable().default(0),try_out_hour:h.coerce.number().nullable().default(0),tos_url:h.string().nullable().default(""),currency:h.string().nullable().default(""),currency_symbol:h.string().nullable().default("")});function Zd(){const{t:s}=I("settings"),[n,a]=m.useState(!1),l=m.useRef(null),{data:r}=se({queryKey:["settings","site"],queryFn:()=>us("site")}),{data:i}=se({queryKey:["plans"],queryFn:()=>Fs()}),c=ce({resolver:ue(Qd),defaultValues:{},mode:"onBlur"}),{mutateAsync:u}=es({mutationFn:xs,onSuccess:d=>{d.data&&q.success(s("common.autoSaved"))}});m.useEffect(()=>{if(r?.data?.site){const d=r?.data?.site;Object.entries(d).forEach(([p,k])=>{c.setValue(p,k)}),l.current=d}},[r]);const x=m.useCallback(pe.debounce(async d=>{if(!pe.isEqual(d,l.current)){a(!0);try{const p=Object.entries(d).reduce((k,[V,f])=>(k[V]=f===null?"":f,k),{});await u(p),l.current=d}finally{a(!1)}}},1e3),[u]),o=m.useCallback(d=>{x(d)},[x]);return m.useEffect(()=>{const d=c.watch(p=>{o(p)});return()=>d.unsubscribe()},[c.watch,o]),e.jsx(xe,{...c,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:c.control,name:"app_name",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("site.form.siteName.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.siteName.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.siteName.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:c.control,name:"app_description",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("site.form.siteDescription.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.siteDescription.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.siteDescription.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:c.control,name:"app_url",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("site.form.siteUrl.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.siteUrl.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.siteUrl.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:c.control,name:"force_https",render:({field:d})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("site.form.forceHttps.label")}),e.jsx(F,{children:s("site.form.forceHttps.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:!!d.value,onCheckedChange:p=>{d.onChange(Number(p)),o(c.getValues())}})})]})}),e.jsx(j,{control:c.control,name:"logo",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("site.form.logo.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.logo.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.logo.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:c.control,name:"subscribe_url",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("site.form.subscribeUrl.label")}),e.jsx(N,{children:e.jsx(Cs,{placeholder:s("site.form.subscribeUrl.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.subscribeUrl.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:c.control,name:"tos_url",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("site.form.tosUrl.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.tosUrl.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.tosUrl.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:c.control,name:"stop_register",render:({field:d})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("site.form.stopRegister.label")}),e.jsx(F,{children:s("site.form.stopRegister.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:!!d.value,onCheckedChange:p=>{d.onChange(Number(p)),o(c.getValues())}})})]})}),e.jsx(j,{control:c.control,name:"try_out_plan_id",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("site.form.tryOut.label")}),e.jsx(N,{children:e.jsxs(W,{value:d.value?.toString(),onValueChange:p=>{d.onChange(Number(p)),o(c.getValues())},children:[e.jsx(B,{children:e.jsx(Y,{placeholder:s("site.form.tryOut.placeholder")})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("site.form.tryOut.placeholder")}),i?.data?.map(p=>e.jsx($,{value:p.id.toString(),children:p.name},p.id.toString()))]})]})}),e.jsx(F,{children:s("site.form.tryOut.description")}),e.jsx(P,{})]})}),!!c.watch("try_out_plan_id")&&e.jsx(j,{control:c.control,name:"try_out_hour",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"",children:s("site.form.tryOut.duration.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.tryOut.duration.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.tryOut.duration.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:c.control,name:"currency",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("site.form.currency.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.currency.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.currency.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:c.control,name:"currency_symbol",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("site.form.currencySymbol.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.currencySymbol.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.currencySymbol.description")}),e.jsx(P,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("site.form.saving")})]})})}function Xd(){const{t:s}=I("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(be,{}),e.jsx(Zd,{})]})}const em=Object.freeze(Object.defineProperty({__proto__:null,default:Xd},Symbol.toStringTag,{value:"Module"})),sm=h.object({email_verify:h.boolean().nullable(),safe_mode_enable:h.boolean().nullable(),secure_path:h.string().nullable(),email_whitelist_enable:h.boolean().nullable(),email_whitelist_suffix:h.array(h.string().nullable()).nullable(),email_gmail_limit_enable:h.boolean().nullable(),recaptcha_enable:h.boolean().nullable(),recaptcha_key:h.string().nullable(),recaptcha_site_key:h.string().nullable(),register_limit_by_ip_enable:h.boolean().nullable(),register_limit_count:h.coerce.string().transform(s=>s===""?null:s).nullable(),register_limit_expire:h.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_enable:h.boolean().nullable(),password_limit_count:h.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_expire:h.coerce.string().transform(s=>s===""?null:s).nullable()}),tm={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 am(){const{t:s}=I("settings"),[n,a]=m.useState(!1),l=m.useRef(null),r=ce({resolver:ue(sm),defaultValues:tm,mode:"onBlur"}),{data:i}=se({queryKey:["settings","safe"],queryFn:()=>us("safe")}),{mutateAsync:c}=es({mutationFn:xs,onSuccess:o=>{o.data&&q.success(s("common.autoSaved"))}});m.useEffect(()=>{if(i?.data.safe){const o=i.data.safe;Object.entries(o).forEach(([d,p])=>{typeof p=="number"?r.setValue(d,String(p)):r.setValue(d,p)}),l.current=o}},[i]);const u=m.useCallback(pe.debounce(async o=>{if(!pe.isEqual(o,l.current)){a(!0);try{await c(o),l.current=o}finally{a(!1)}}},1e3),[c]),x=m.useCallback(o=>{u(o)},[u]);return m.useEffect(()=>{const o=r.watch(d=>{x(d)});return()=>o.unsubscribe()},[r.watch,x]),e.jsx(xe,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:r.control,name:"email_verify",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.emailVerify.label")}),e.jsx(F,{children:s("safe.form.emailVerify.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(j,{control:r.control,name:"email_gmail_limit_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.gmailLimit.label")}),e.jsx(F,{children:s("safe.form.gmailLimit.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(j,{control:r.control,name:"safe_mode_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.safeMode.label")}),e.jsx(F,{children:s("safe.form.safeMode.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(j,{control:r.control,name:"secure_path",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.securePath.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.securePath.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.securePath.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"email_whitelist_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.emailWhitelist.label")}),e.jsx(F,{children:s("safe.form.emailWhitelist.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),r.watch("email_whitelist_enable")&&e.jsx(j,{control:r.control,name:"email_whitelist_suffix",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.emailWhitelist.suffixes.label")}),e.jsx(N,{children:e.jsx(Cs,{placeholder:s("safe.form.emailWhitelist.suffixes.placeholder"),...o,value:(o.value||[]).join(` +import{r as u,j as e,t as ll,c as ol,I as Na,a as Ds,S as Zt,u as cs,b as Xt,d as il,O as ea,e as cl,f as q,g as dl,h as ml,i as ul,k as xl,B as hl,l as fl,Q as pl,m as gl,R as jl,n as vl,P as bl,o as yl,p as Nl,q as Ka,F as _l,C as wl,s as Cl,v as Sl,w as kl,x as Tl,y as Ha,z as I,A as h,D as ce,E as ue,G as Ua,H as St,J as kt,K as sa,L as ze,T as Tt,M as Dt,N as Ba,U as Ga,V as Wa,W as ta,X as Ya,Y as Dl,Z as Ja,_ as Qa,$ as Za,a0 as Xa,a1 as Ps,a2 as en,a3 as Pl,a4 as sn,a5 as tn,a6 as Rl,a7 as El,a8 as Vl,a9 as Il,aa as Fl,ab as Ml,ac as Ol,ad as zl,ae as Ll,af as Al,ag as $l,ah as an,ai as ql,aj as Kl,ak as Rs,al as nn,am as Hl,an as Ul,ao as rn,ap as Bl,aq as Gl,ar as _a,as as Wl,at as ln,au as Yl,av as on,aw as Jl,ax as Ql,ay as Zl,az as Xl,aA as eo,aB as so,aC as cn,aD as to,aE as ao,aF as no,aG as Se,aH as ro,aI as lo,aJ as oo,aK as io,aL as dn,aM as mn,aN as un,aO as co,aP as xn,aQ as hn,aR as fn,aS as mo,aT as uo,aU as xo,aV as pn,aW as ho,aX as aa,aY as gn,aZ as fo,a_ as jn,a$ as po,b0 as vn,b1 as go,b2 as bn,b3 as yn,b4 as jo,b5 as vo,b6 as Nn,b7 as bo,b8 as yo,b9 as _n,ba as No,bb as wn,bc as _o,bd as wo,be as Ke,bf as se,bg as qe,bh as it,bi as Co,bj as So,bk as ko,bl as To,bm as Do,bn as Po,bo as wa,bp as Ca,bq as Ro,br as Eo,bs as Vo,bt as Io,bu as Fo,bv as Kt,bw as Ht,bx as Mo,by as Oo,bz as Cn,bA as zo,bB as Lo,bC as Sn,bD as Ao,bE as pe,bF as $o,bG as Sa,bH as Ut,bI as Bt,bJ as qo,bK as Ko,bL as kn,bM as Ho,bN as na,bO as Uo,bP as Bo,bQ as Go,bR as Tn,bS as Dn,bT as Pn,bU as Wo,bV as Yo,bW as Jo,bX as Qo,bY as Rn,bZ as Zo,b_ as ss,b$ as Xo,c0 as ei,c1 as si,c2 as bt,c3 as Ne,c4 as ka,c5 as ti,c6 as En,c7 as Vn,c8 as In,c9 as Fn,ca as Mn,cb as On,cc as ai,cd as ni,ce as ri,cf as Pt,cg as Es,ch as ds,ci as Le,cj as Ae,ck as Be,cl as Ge,cm as We,cn as li,co as oi,cp as ii,cq as Gt,cr as ra,cs as la,ct as ci,cu as ms,cv as us,cw as ct,cx as di,cy as yt,cz as mi,cA as Ta,cB as zn,cC as Da,cD as Nt,cE as ui,cF as xi,cG as hi,cH as fi,cI as Ln,cJ as pi,cK as gi,cL as An,cM as Wt,cN as $n,cO as ji,cP as qn,cQ as Kn,cR as vi,cS as bi,cT as yi,cU as Ni,cV as _i}from"./vendor.js";import"./index.js";var bh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function yh(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function wi(s){if(s.__esModule)return s;var n=s.default;if(typeof n=="function"){var a=function l(){return this instanceof l?Reflect.construct(n,arguments,this.constructor):n.apply(this,arguments)};a.prototype=n.prototype}else a={};return Object.defineProperty(a,"__esModule",{value:!0}),Object.keys(s).forEach(function(l){var r=Object.getOwnPropertyDescriptor(s,l);Object.defineProperty(a,l,r.get?r:{enumerable:!0,get:function(){return s[l]}})}),a}const Ci={theme:"system",setTheme:()=>null},Hn=u.createContext(Ci);function Si({children:s,defaultTheme:n="system",storageKey:a="vite-ui-theme",...l}){const[r,i]=u.useState(()=>localStorage.getItem(a)||n);u.useEffect(()=>{const m=window.document.documentElement;if(m.classList.remove("light","dark"),r==="system"){const x=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";m.classList.add(x);return}m.classList.add(r)},[r]);const c={theme:r,setTheme:m=>{localStorage.setItem(a,m),i(m)}};return e.jsx(Hn.Provider,{...l,value:c,children:s})}const ki=()=>{const s=u.useContext(Hn);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},Ti=function(){const n=typeof document<"u"&&document.createElement("link").relList;return n&&n.supports&&n.supports("modulepreload")?"modulepreload":"preload"}(),Di=function(s,n){return new URL(s,n).href},Pa={},oe=function(n,a,l){let r=Promise.resolve();if(a&&a.length>0){const c=document.getElementsByTagName("link"),m=document.querySelector("meta[property=csp-nonce]"),x=m?.nonce||m?.getAttribute("nonce");r=Promise.allSettled(a.map(o=>{if(o=Di(o,l),o in Pa)return;Pa[o]=!0;const d=o.endsWith(".css"),p=d?'[rel="stylesheet"]':"";if(!!l)for(let f=c.length-1;f>=0;f--){const _=c[f];if(_.href===o&&(!d||_.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${o}"]${p}`))return;const E=document.createElement("link");if(E.rel=d?"stylesheet":Ti,d||(E.as="script"),E.crossOrigin="",E.href=o,x&&E.setAttribute("nonce",x),document.head.appendChild(E),d)return new Promise((f,_)=>{E.addEventListener("load",f),E.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${o}`)))})}))}function i(c){const m=new Event("vite:preloadError",{cancelable:!0});if(m.payload=c,window.dispatchEvent(m),!m.defaultPrevented)throw c}return r.then(c=>{for(const m of c||[])m.status==="rejected"&&i(m.reason);return n().catch(i)})};function y(...s){return ll(ol(s))}const Ks=Ds("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"}}),V=u.forwardRef(({className:s,variant:n,size:a,asChild:l=!1,children:r,disabled:i,loading:c=!1,leftSection:m,rightSection:x,...o},d)=>{const p=l?Zt:"button";return e.jsxs(p,{className:y(Ks({variant:n,size:a,className:s})),disabled:c||i,ref:d,...o,children:[(m&&c||!m&&!x&&c)&&e.jsx(Na,{className:"mr-2 h-4 w-4 animate-spin"}),!c&&m&&e.jsx("div",{className:"mr-2",children:m}),r,!c&&x&&e.jsx("div",{className:"ml-2",children:x}),x&&c&&e.jsx(Na,{className:"ml-2 h-4 w-4 animate-spin"})]})});V.displayName="Button";function Os({className:s,minimal:n=!1}){const a=cs();return e.jsx("div",{className:y("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",{})," Please try again later."]}),!n&&e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(V,{variant:"outline",onClick:()=>a(-1),children:"Go Back"}),e.jsx(V,{onClick:()=>a("/"),children:"Back to Home"})]})]})})}function Ra(){const s=cs();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(V,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(V,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function Pi(){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(V,{variant:"outline",children:"Learn more"})})]})})}function Ri(s){return typeof s>"u"}function Ei(s){return s===null}function Vi(s){return Ei(s)||Ri(s)}class Ii{storage;prefixKey;constructor(n){this.storage=n.storage,this.prefixKey=n.prefixKey}getKey(n){return`${this.prefixKey}${n}`.toUpperCase()}set(n,a,l=null){const r=JSON.stringify({value:a,time:Date.now(),expire:l!==null?new Date().getTime()+l*1e3:null});this.storage.setItem(this.getKey(n),r)}get(n,a=null){const l=this.storage.getItem(this.getKey(n));if(!l)return{value:a,time:0};try{const r=JSON.parse(l),{value:i,time:c,expire:m}=r;return Vi(m)||m>new Date().getTime()?{value:i,time:c}:(this.remove(n),{value:a,time:0})}catch{return this.remove(n),{value:a,time:0}}}remove(n){this.storage.removeItem(this.getKey(n))}clear(){this.storage.clear()}}function Un({prefixKey:s="",storage:n=sessionStorage}){return new Ii({prefixKey:s,storage:n})}const Bn="Xboard_",Fi=function(s={}){return Un({prefixKey:s.prefixKey||"",storage:localStorage})},Mi=function(s={}){return Un({prefixKey:s.prefixKey||"",storage:sessionStorage})},Rt=Fi({prefixKey:Bn});Mi({prefixKey:Bn});const Gn="access_token";function st(){return Rt.get(Gn)}function Wn(){Rt.remove(Gn)}const Ea=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function Oi({children:s}){const n=cs(),a=Xt(),l=st();return u.useEffect(()=>{if(!l.value&&!Ea.includes(a.pathname)){const r=encodeURIComponent(a.pathname+a.search);n(`/sign-in?redirect=${r}`)}},[l.value,a.pathname,a.search,n]),Ea.includes(a.pathname)||l.value?e.jsx(e.Fragment,{children:s}):null}const zi=()=>e.jsx(Oi,{children:e.jsx(ea,{})}),Li=il([{path:"/sign-in",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>dc);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(zi,{}),children:[{path:"/",lazy:async()=>({Component:(await oe(()=>Promise.resolve().then(()=>vc),void 0,import.meta.url)).default}),errorElement:e.jsx(Os,{}),children:[{index:!0,lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Bd);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(Os,{}),children:[{path:"system",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Jd);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>em);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>rm);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>dm);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>fm);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>bm);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Cm);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Pm);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Fm);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Am);return{default:s}},void 0,import.meta.url)).default})}]},{path:"payment",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Zm);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>tu);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>cu);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>gu);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(Os,{}),children:[{path:"manage",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>qu);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Gu);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Xu);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(Os,{}),children:[{path:"plan",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>ix);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Nx);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>Rx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(Os,{}),children:[{path:"manage",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>eh);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await oe(async()=>{const{default:s}=await Promise.resolve().then(()=>gh);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:Os},{path:"/404",Component:Ra},{path:"/503",Component:Pi},{path:"*",Component:Ra}]),Ai="locale";function $i(){return Rt.get(Ai)}function Yn(){Wn();const s=window.location.pathname,n=s&&!["/404","/sign-in"].includes(s),a=new URL(window.location.href),r=`${a.pathname.split("/")[1]?`/${a.pathname.split("/")[1]}`:""}#/sign-in`;window.location.href=r+(n?`?redirect=${s}`:"")}const qi=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function Ki(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const O=cl.create({baseURL:Ki(),timeout:12e3,headers:{"Content-Type":"application/json"}});O.interceptors.request.use(s=>{s.method?.toLowerCase()==="get"&&(s.params={...s.params,t:Date.now()});const n=st();if(!qi.includes(s.url?.split("?")[0]||"")){if(!n.value)return Yn(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=n.value}return s.headers["Content-Language"]=$i().value||"zh-CN",s},s=>Promise.reject(s));O.interceptors.response.use(s=>s?.data||{code:-1,message:"未知错误"},s=>{const n=s.response?.status,a=s.response?.data?.message;return(n===401||n===403)&&Yn(),q.error(a||{401:"登录已过期",403:"没有权限",404:"资源或接口不存在"}[n]||"未知异常"),Promise.reject(s.response?.data||{data:null,code:-1,message:"未知错误"})});function Hi(){return O.get("/user/info")}const Ot={token:st()?.value||"",userInfo:null,isLoggedIn:!!st()?.value,loading:!1,error:null},Xs=dl("user/fetchUserInfo",async()=>(await Hi()).data,{condition:(s,{getState:n})=>{const{user:a}=n();return!!a.token&&!a.loading}}),Jn=ml({name:"user",initialState:Ot,reducers:{setToken(s,n){s.token=n.payload,s.isLoggedIn=!!n.payload},resetUserState:()=>Ot},extraReducers:s=>{s.addCase(Xs.pending,n=>{n.loading=!0,n.error=null}).addCase(Xs.fulfilled,(n,a)=>{n.loading=!1,n.userInfo=a.payload,n.error=null}).addCase(Xs.rejected,(n,a)=>{if(n.loading=!1,n.error=a.error.message||"Failed to fetch user info",!n.token)return Ot})}}),{setToken:Ui,resetUserState:Bi}=Jn.actions,Gi=s=>s.user.userInfo,Wi=Jn.reducer,Qn=ul({reducer:{user:Wi}});st()?.value&&Qn.dispatch(Xs());xl.use(hl).use(fl).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 Yi=new pl;gl.createRoot(document.getElementById("root")).render(e.jsx(jl.StrictMode,{children:e.jsx(vl,{client:Yi,children:e.jsx(bl,{store:Qn,children:e.jsxs(Si,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(yl,{router:Li}),e.jsx(Nl,{richColors:!0,position:"top-right"})]})})})}));const Ue=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:y("rounded-xl border bg-card text-card-foreground shadow",s),...n}));Ue.displayName="Card";const ts=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:y("flex flex-col space-y-1.5 p-6",s),...n}));ts.displayName="CardHeader";const bs=u.forwardRef(({className:s,...n},a)=>e.jsx("h3",{ref:a,className:y("font-semibold leading-none tracking-tight",s),...n}));bs.displayName="CardTitle";const tt=u.forwardRef(({className:s,...n},a)=>e.jsx("p",{ref:a,className:y("text-sm text-muted-foreground",s),...n}));tt.displayName="CardDescription";const as=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:y("p-6 pt-0",s),...n}));as.displayName="CardContent";const Ji=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:y("flex items-center p-6 pt-0",s),...n}));Ji.displayName="CardFooter";const Qi=Ds("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),_t=u.forwardRef(({className:s,...n},a)=>e.jsx(Ka,{ref:a,className:y(Qi(),s),...n}));_t.displayName=Ka.displayName;const xe=_l,Zn=u.createContext({}),v=({...s})=>e.jsx(Zn.Provider,{value:{name:s.name},children:e.jsx(wl,{...s})}),Et=()=>{const s=u.useContext(Zn),n=u.useContext(Xn),{getFieldState:a,formState:l}=Cl(),r=a(s.name,l);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`,...r}},Xn=u.createContext({}),j=u.forwardRef(({className:s,...n},a)=>{const l=u.useId();return e.jsx(Xn.Provider,{value:{id:l},children:e.jsx("div",{ref:a,className:y("space-y-2",s),...n})})});j.displayName="FormItem";const b=u.forwardRef(({className:s,...n},a)=>{const{error:l,formItemId:r}=Et();return e.jsx(_t,{ref:a,className:y(l&&"text-destructive",s),htmlFor:r,...n})});b.displayName="FormLabel";const N=u.forwardRef(({...s},n)=>{const{error:a,formItemId:l,formDescriptionId:r,formMessageId:i}=Et();return e.jsx(Zt,{ref:n,id:l,"aria-describedby":a?`${r} ${i}`:`${r}`,"aria-invalid":!!a,...s})});N.displayName="FormControl";const F=u.forwardRef(({className:s,...n},a)=>{const{formDescriptionId:l}=Et();return e.jsx("p",{ref:a,id:l,className:y("text-[0.8rem] text-muted-foreground",s),...n})});F.displayName="FormDescription";const R=u.forwardRef(({className:s,children:n,...a},l)=>{const{error:r,formMessageId:i}=Et(),c=r?String(r?.message):n;return c?e.jsx("p",{ref:l,id:i,className:y("text-[0.8rem] font-medium text-destructive",s),...a,children:c}):null});R.displayName="FormMessage";const P=u.forwardRef(({className:s,type:n,...a},l)=>e.jsx("input",{type:n,className:y("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:l,...a}));P.displayName="Input";const er=u.forwardRef(({className:s,...n},a)=>{const[l,r]=u.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:l?"text":"password",className:y("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:a,...n}),e.jsx(V,{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:()=>r(i=>!i),children:l?e.jsx(Sl,{size:18}):e.jsx(kl,{size:18})})]})});er.displayName="PasswordInput";const Zi=s=>O({url:"/passport/auth/login",method:"post",data:s});function me(s=void 0,n="YYYY-MM-DD HH:mm:ss"){return s==null?"":(Math.floor(s).toString().length===10&&(s=s*1e3),Tl(s).format(n))}function Xi(s=void 0,n="YYYY-MM-DD"){return me(s,n)}function As(s){const n=typeof s=="string"?parseFloat(s):s;return isNaN(n)?"0.00":n.toFixed(2)}function ks(s,n=!0){if(s==null)return n?"¥0.00":"0.00";const a=typeof s=="string"?parseFloat(s):s;if(isNaN(a))return n?"¥0.00":"0.00";const r=(a/100).toFixed(2).replace(/\.?0+$/,i=>i.includes(".")?".00":i);return n?`¥${r}`:r}function wt(s){return new Promise(n=>{(async()=>{try{if(navigator.clipboard)await navigator.clipboard.writeText(s);else{const l=document.createElement("textarea");l.value=s,l.style.position="fixed",l.style.opacity="0",document.body.appendChild(l),l.select();const r=document.execCommand("copy");if(document.body.removeChild(l),!r)throw new Error("execCommand failed")}n(!0)}catch(l){console.error(l),n(!1)}})()})}function Xe(s){const n=s/1024,a=n/1024,l=a/1024,r=l/1024;return r>=1?As(r)+" TB":l>=1?As(l)+" GB":a>=1?As(a)+" MB":As(n)+" KB"}const ec="access_token";function sc(s){Rt.set(ec,s)}function tc({className:s,onForgotPassword:n,...a}){const l=cs(),r=Ha(),{t:i}=I("auth"),c=h.object({email:h.string().min(1,{message:i("signIn.validation.emailRequired")}),password:h.string().min(1,{message:i("signIn.validation.passwordRequired")}).min(7,{message:i("signIn.validation.passwordLength")})}),m=ce({resolver:ue(c),defaultValues:{email:"",password:""}});async function x(o){try{const{data:d}=await Zi(o);sc(d.auth_data),r(Ui(d.auth_data)),await r(Xs()).unwrap(),l("/")}catch(d){console.error("Login failed:",d),d.response?.data?.message&&m.setError("root",{message:d.response.data.message})}}return e.jsx("div",{className:y("grid gap-6",s),...a,children:e.jsx(xe,{...m,children:e.jsx("form",{onSubmit:m.handleSubmit(x),className:"space-y-4",children:e.jsxs("div",{className:"space-y-4",children:[m.formState.errors.root&&e.jsx("div",{className:"text-sm text-destructive",children:m.formState.errors.root.message}),e.jsx(v,{control:m.control,name:"email",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:i("signIn.email")}),e.jsx(N,{children:e.jsx(P,{placeholder:i("signIn.emailPlaceholder"),autoComplete:"email",...o})}),e.jsx(R,{})]})}),e.jsx(v,{control:m.control,name:"password",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:i("signIn.password")}),e.jsx(N,{children:e.jsx(er,{placeholder:i("signIn.passwordPlaceholder"),autoComplete:"current-password",...o})}),e.jsx(R,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(V,{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(V,{className:"w-full",size:"lg",loading:m.formState.isSubmitting,children:i("signIn.submit")})]})})})})}const ge=Ua,Me=Ba,ac=Ga,dt=sa,sr=u.forwardRef(({className:s,...n},a)=>e.jsx(St,{ref:a,className:y("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}));sr.displayName=St.displayName;const he=u.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(ac,{children:[e.jsx(sr,{}),e.jsxs(kt,{ref:l,className:y("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),...a,children:[n,e.jsxs(sa,{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(ze,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));he.displayName=kt.displayName;const ve=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col space-y-1.5 text-center sm:text-left",s),...n});ve.displayName="DialogHeader";const Oe=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Oe.displayName="DialogFooter";const je=u.forwardRef(({className:s,...n},a)=>e.jsx(Tt,{ref:a,className:y("text-lg font-semibold leading-none tracking-tight",s),...n}));je.displayName=Tt.displayName;const De=u.forwardRef(({className:s,...n},a)=>e.jsx(Dt,{ref:a,className:y("text-sm text-muted-foreground",s),...n}));De.displayName=Dt.displayName;const qs=Ds("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:a,asChild:l=!1,...r},i)=>{const c=l?Zt:"button";return e.jsx(c,{className:y(qs({variant:n,size:a,className:s})),ref:i,...r})});J.displayName="Button";const ys=Rl,Ns=El,nc=Vl,rc=u.forwardRef(({className:s,inset:n,children:a,...l},r)=>e.jsxs(Wa,{ref:r,className:y("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),...l,children:[a,e.jsx(ta,{className:"ml-auto h-4 w-4"})]}));rc.displayName=Wa.displayName;const lc=u.forwardRef(({className:s,...n},a)=>e.jsx(Ya,{ref:a,className:y("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}));lc.displayName=Ya.displayName;const is=u.forwardRef(({className:s,sideOffset:n=4,...a},l)=>e.jsx(Dl,{children:e.jsx(Ja,{ref:l,sideOffset:n,className:y("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),...a})}));is.displayName=Ja.displayName;const fe=u.forwardRef(({className:s,inset:n,...a},l)=>e.jsx(Qa,{ref:l,className:y("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),...a}));fe.displayName=Qa.displayName;const oc=u.forwardRef(({className:s,children:n,checked:a,...l},r)=>e.jsxs(Za,{ref:r,className:y("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:a,...l,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Xa,{children:e.jsx(Ps,{className:"h-4 w-4"})})}),n]}));oc.displayName=Za.displayName;const ic=u.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(en,{ref:l,className:y("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),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Xa,{children:e.jsx(Pl,{className:"h-4 w-4 fill-current"})})}),n]}));ic.displayName=en.displayName;const oa=u.forwardRef(({className:s,inset:n,...a},l)=>e.jsx(sn,{ref:l,className:y("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",s),...a}));oa.displayName=sn.displayName;const at=u.forwardRef(({className:s,...n},a)=>e.jsx(tn,{ref:a,className:y("-mx-1 my-1 h-px bg-muted",s),...n}));at.displayName=tn.displayName;const Yt=({className:s,...n})=>e.jsx("span",{className:y("ml-auto text-xs tracking-widest opacity-60",s),...n});Yt.displayName="DropdownMenuShortcut";const zt=[{code:"en-US",name:"English",flag:Il,shortName:"EN"},{code:"zh-CN",name:"中文",flag:Fl,shortName:"CN"},{code:"ko-KR",name:"한국어",flag:Ml,shortName:"KR"}];function tr(){const{i18n:s}=I(),n=r=>{s.changeLanguage(r)},a=zt.find(r=>r.code===s.language)||zt[1],l=a.flag;return e.jsxs(ys,{children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 px-2 gap-1",children:[e.jsx(l,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:"text-sm font-medium",children:a.shortName})]})}),e.jsx(is,{align:"end",className:"w-[120px]",children:zt.map(r=>{const i=r.flag,c=r.code===s.language;return e.jsxs(fe,{onClick:()=>n(r.code),className:y("flex items-center gap-2 px-2 py-1.5 cursor-pointer",c&&"bg-accent"),children:[e.jsx(i,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:y("text-sm",c&&"font-medium"),children:r.name})]},r.code)})})]})}function cc(){const[s,n]=u.useState(!1),{t:a}=I("auth"),l=a("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(tr,{})}),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(Ue,{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:a("signIn.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("signIn.description")})]}),e.jsx(tc,{onForgotPassword:()=>n(!0)})]})]})]}),e.jsx(ge,{open:s,onOpenChange:n,children:e.jsx(he,{children:e.jsxs(ve,{children:[e.jsx(je,{children:a("signIn.resetPassword.title")}),e.jsx(De,{children:a("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:l}),e.jsx(J,{variant:"ghost",size:"icon",className:"absolute right-2 top-2 h-8 w-8 hover:bg-secondary-foreground/10",onClick:()=>wt(l).then(()=>{q.success(a("common:copy.success"))}),children:e.jsx(Ol,{className:"h-4 w-4"})})]})})]})})})]})}const dc=Object.freeze(Object.defineProperty({__proto__:null,default:cc},Symbol.toStringTag,{value:"Module"})),we=u.forwardRef(({className:s,fadedBelow:n=!1,fixedHeight:a=!1,...l},r)=>e.jsx("div",{ref:r,className:y("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",a&&"md:h-svh",s),...l}));we.displayName="Layout";const Ce=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:y("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...n}));Ce.displayName="LayoutHeader";const ke=u.forwardRef(({className:s,fixedHeight:n,...a},l)=>e.jsx("div",{ref:l,className:y("flex-1 overflow-hidden px-4 py-6 md:px-8",n&&"h-[calc(100%-var(--header-height))]",s),...a}));ke.displayName="LayoutBody";const ar=zl,nr=Ll,rr=Al,ie=$l,re=ql,le=Kl,te=u.forwardRef(({className:s,sideOffset:n=4,...a},l)=>e.jsx(an,{ref:l,sideOffset:n,className:y("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),...a}));te.displayName=an.displayName;function Vt(){const{pathname:s}=Xt();return{checkActiveNav:a=>{if(a==="/"&&s==="/")return!0;const l=a.replace(/^\//,""),r=s.replace(/^\//,"");return l?r.startsWith(l):!1}}}function lr({key:s,defaultValue:n}){const[a,l]=u.useState(()=>{const r=localStorage.getItem(s);return r!==null?JSON.parse(r):n});return u.useEffect(()=>{localStorage.setItem(s,JSON.stringify(a))},[a,s]),[a,l]}function mc(){const[s,n]=lr({key:"collapsed-sidebar-items",defaultValue:[]}),a=r=>!s.includes(r);return{isExpanded:a,toggleItem:r=>{a(r)?n([...s,r]):n(s.filter(i=>i!==r))}}}function uc({links:s,isCollapsed:n,className:a,closeNav:l}){const{t:r}=I(),i=({sub:c,...m})=>{const x=`${r(m.title)}-${m.href}`;return n&&c?u.createElement(fc,{...m,sub:c,key:x,closeNav:l}):n?u.createElement(hc,{...m,key:x,closeNav:l}):c?u.createElement(xc,{...m,sub:c,key:x,closeNav:l}):u.createElement(or,{...m,key:x,closeNav:l})};return e.jsx("div",{"data-collapsed":n,className:y("group border-b bg-background py-2 transition-[max-height,padding] duration-500 data-[collapsed=true]:py-2 md:border-none",a),children:e.jsx(ie,{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 or({title:s,icon:n,label:a,href:l,closeNav:r,subLink:i=!1}){const{checkActiveNav:c}=Vt(),{t:m}=I();return e.jsxs(Rs,{to:l,onClick:r,className:y(Ks({variant:c(l)?"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":c(l)?"page":void 0,children:[e.jsx("div",{className:"mr-2",children:n}),m(s),a&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:m(a)})]})}function xc({title:s,icon:n,label:a,sub:l,closeNav:r}){const{checkActiveNav:i}=Vt(),{isExpanded:c,toggleItem:m}=mc(),{t:x}=I(),o=!!l?.find(k=>i(k.href)),d=x(s),p=c(d)||o;return e.jsxs(ar,{open:p,onOpenChange:()=>m(d),children:[e.jsxs(nr,{className:y(Ks({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}),x(s),a&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:x(a)}),e.jsx("span",{className:y('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(nn,{stroke:1})})]}),e.jsx(rr,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:l.map(k=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(or,{...k,subLink:!0,closeNav:r})},x(k.title)))})})]})}function hc({title:s,icon:n,label:a,href:l,closeNav:r}){const{checkActiveNav:i}=Vt(),{t:c}=I();return e.jsxs(re,{delayDuration:0,children:[e.jsx(le,{asChild:!0,children:e.jsxs(Rs,{to:l,onClick:r,className:y(Ks({variant:i(l)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[n,e.jsx("span",{className:"sr-only",children:c(s)})]})}),e.jsxs(te,{side:"right",className:"flex items-center gap-4",children:[c(s),a&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:c(a)})]})]})}function fc({title:s,icon:n,label:a,sub:l,closeNav:r}){const{checkActiveNav:i}=Vt(),{t:c}=I(),m=!!l?.find(x=>i(x.href));return e.jsxs(ys,{children:[e.jsxs(re,{delayDuration:0,children:[e.jsx(le,{asChild:!0,children:e.jsx(Ns,{asChild:!0,children:e.jsx(V,{variant:m?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:n})})}),e.jsxs(te,{side:"right",className:"flex items-center gap-4",children:[c(s)," ",a&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:c(a)}),e.jsx(nn,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(is,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(oa,{children:[c(s)," ",a?`(${c(a)})`:""]}),e.jsx(at,{}),l.map(({title:x,icon:o,label:d,href:p})=>e.jsx(fe,{asChild:!0,children:e.jsxs(Rs,{to:p,onClick:r,className:`${i(p)?"bg-secondary":""}`,children:[o," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:c(x)}),d&&e.jsx("span",{className:"ml-auto text-xs",children:c(d)})]})},`${c(x)}-${p}`))]})]})}const ir=[{title:"nav:dashboard",label:"",href:"/",icon:e.jsx(Hl,{size:18})},{title:"nav:systemManagement",label:"",href:"",icon:e.jsx(Ul,{size:18}),sub:[{title:"nav:systemConfig",label:"",href:"/config/system",icon:e.jsx(rn,{size:18})},{title:"nav:themeConfig",label:"",href:"/config/theme",icon:e.jsx(Bl,{size:18})},{title:"nav:noticeManagement",label:"",href:"/config/notice",icon:e.jsx(Gl,{size:18})},{title:"nav:paymentConfig",label:"",href:"/config/payment",icon:e.jsx(_a,{size:18})},{title:"nav:knowledgeManagement",label:"",href:"/config/knowledge",icon:e.jsx(Wl,{size:18})}]},{title:"nav:nodeManagement",label:"",href:"",icon:e.jsx(ln,{size:18}),sub:[{title:"nav:nodeManagement",label:"",href:"/server/manage",icon:e.jsx(Yl,{size:18})},{title:"nav:permissionGroupManagement",label:"",href:"/server/group",icon:e.jsx(on,{size:18})},{title:"nav:routeManagement",label:"",href:"/server/route",icon:e.jsx(Jl,{size:18})}]},{title:"nav:subscriptionManagement",label:"",href:"",icon:e.jsx(Ql,{size:18}),sub:[{title:"nav:planManagement",label:"",href:"/finance/plan",icon:e.jsx(Zl,{size:18})},{title:"nav:orderManagement",label:"",href:"/finance/order",icon:e.jsx(_a,{size:18})},{title:"nav:couponManagement",label:"",href:"/finance/coupon",icon:e.jsx(Xl,{size:18})}]},{title:"nav:userManagement",label:"",href:"",icon:e.jsx(eo,{size:18}),sub:[{title:"nav:userManagement",label:"",href:"/user/manage",icon:e.jsx(so,{size:18})},{title:"nav:ticketManagement",label:"",href:"/user/ticket",icon:e.jsx(cn,{size:18})}]}];function pc({className:s,isCollapsed:n,setIsCollapsed:a}){const[l,r]=u.useState(!1),{t:i}=I();return u.useEffect(()=>{l?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[l]),e.jsxs("aside",{className:y(`fixed left-0 right-0 top-0 z-50 w-full 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:()=>r(!1),className:`absolute inset-0 transition-[opacity] delay-100 duration-700 ${l?"h-svh opacity-50":"h-0 opacity-0"} w-full bg-black md:hidden`}),e.jsxs(we,{children:[e.jsxs(Ce,{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(V,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":i("common:toggleNavigation"),"aria-controls":"sidebar-menu","aria-expanded":l,onClick:()=>r(c=>!c),children:l?e.jsx(to,{}):e.jsx(ao,{})})]}),e.jsx(uc,{id:"sidebar-menu",className:`h-full flex-1 overflow-auto ${l?"max-h-screen":"max-h-0 py-0 md:max-h-screen md:py-2"}`,closeNav:()=>r(!1),isCollapsed:n,links:ir}),e.jsx("div",{className:y("px-4 py-3 text-xs text-muted-foreground/70 border-t border-border/50 bg-muted/20","transition-all duration-200 ease-in-out",n?"text-center":"text-left"),children:e.jsxs("div",{className:y("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/70"}),e.jsxs("span",{className:"tracking-wide",children:["v",window?.settings?.version]})]})}),e.jsx(V,{onClick:()=>a(c=>!c),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(no,{stroke:1.5,className:`h-5 w-5 ${n?"rotate-180":""}`})})]})]})}function gc(){const[s,n]=lr({key:"collapsed-sidebar",defaultValue:!1});return u.useEffect(()=>{const a=()=>{n(window.innerWidth<768?!1:s)};return a(),window.addEventListener("resize",a),()=>{window.removeEventListener("resize",a)}},[s,n]),[s,n]}function jc(){const[s,n]=gc();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(pc,{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(ea,{})})]})}const vc=Object.freeze(Object.defineProperty({__proto__:null,default:jc},Symbol.toStringTag,{value:"Module"})),_s=u.forwardRef(({className:s,...n},a)=>e.jsx(Se,{ref:a,className:y("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...n}));_s.displayName=Se.displayName;const bc=({children:s,...n})=>e.jsx(ge,{...n,children:e.jsx(he,{className:"overflow-hidden p-0",children:e.jsx(_s,{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})})}),Vs=u.forwardRef(({className:s,...n},a)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(ro,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(Se.Input,{ref:a,className:y("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})]}));Vs.displayName=Se.Input.displayName;const ws=u.forwardRef(({className:s,...n},a)=>e.jsx(Se.List,{ref:a,className:y("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...n}));ws.displayName=Se.List.displayName;const Is=u.forwardRef((s,n)=>e.jsx(Se.Empty,{ref:n,className:"py-6 text-center text-sm",...s}));Is.displayName=Se.Empty.displayName;const Fe=u.forwardRef(({className:s,...n},a)=>e.jsx(Se.Group,{ref:a,className:y("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}));Fe.displayName=Se.Group.displayName;const Hs=u.forwardRef(({className:s,...n},a)=>e.jsx(Se.Separator,{ref:a,className:y("-mx-1 h-px bg-border",s),...n}));Hs.displayName=Se.Separator.displayName;const _e=u.forwardRef(({className:s,...n},a)=>e.jsx(Se.Item,{ref:a,className:y("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}));_e.displayName=Se.Item.displayName;function yc(){const s=[];for(const n of ir)if(n.href&&s.push(n),n.sub)for(const a of n.sub)s.push({...a,parent:n.title});return s}function Pe(){const[s,n]=u.useState(!1),a=cs(),l=yc(),{t:r}=I("search"),{t:i}=I("nav");u.useEffect(()=>{const m=x=>{x.key==="k"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),n(o=>!o))};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[]);const c=u.useCallback(m=>{n(!1),a(m)},[a]);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(lo,{className:"h-4 w-4 xl:mr-2"}),e.jsx("span",{className:"hidden xl:inline-flex",children:r("placeholder")}),e.jsx("span",{className:"sr-only",children:r("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:r("shortcut.key")})]}),e.jsxs(bc,{open:s,onOpenChange:n,children:[e.jsx(Vs,{placeholder:r("placeholder")}),e.jsxs(ws,{children:[e.jsx(Is,{children:r("noResults")}),e.jsx(Fe,{heading:r("title"),children:l.map(m=>e.jsxs(_e,{value:`${m.parent?m.parent+" ":""}${m.title}`,onSelect:()=>c(m.href),children:[e.jsx("div",{className:"mr-2",children:m.icon}),e.jsx("span",{children:i(m.title)}),m.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:i(m.parent)})]},m.href))})]})]})]})}function Re(){const{theme:s,setTheme:n}=ki();return u.useEffect(()=>{const a=s==="dark"?"#020817":"#fff",l=document.querySelector("meta[name='theme-color']");l&&l.setAttribute("content",a)},[s]),e.jsxs(e.Fragment,{children:[e.jsx(V,{size:"icon",variant:"ghost",className:"rounded-full",onClick:()=>n(s==="light"?"dark":"light"),children:s==="light"?e.jsx(oo,{size:20}):e.jsx(io,{size:20})}),e.jsx(tr,{})]})}const cr=u.forwardRef(({className:s,...n},a)=>e.jsx(dn,{ref:a,className:y("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...n}));cr.displayName=dn.displayName;const dr=u.forwardRef(({className:s,...n},a)=>e.jsx(mn,{ref:a,className:y("aspect-square h-full w-full",s),...n}));dr.displayName=mn.displayName;const mr=u.forwardRef(({className:s,...n},a)=>e.jsx(un,{ref:a,className:y("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...n}));mr.displayName=un.displayName;function Ee(){const s=cs(),n=Ha(),a=co(Gi),{t:l}=I(["common"]),r=()=>{Wn(),n(Bi()),s("/sign-in")},i=a?.email?.split("@")[0]||l("common:user"),c=i.substring(0,2).toUpperCase();return e.jsxs(ys,{children:[e.jsx(Ns,{asChild:!0,children:e.jsx(V,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(cr,{className:"h-8 w-8",children:[e.jsx(dr,{src:a?.avatar_url,alt:i}),e.jsx(mr,{children:c})]})})}),e.jsxs(is,{className:"w-56",align:"end",forceMount:!0,children:[e.jsx(oa,{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:a?.email||l("common:defaultEmail")})]})}),e.jsx(at,{}),e.jsx(fe,{asChild:!0,children:e.jsxs(Rs,{to:"/config/system",children:[l("common:settings"),e.jsx(Yt,{children:"⌘S"})]})}),e.jsx(at,{}),e.jsxs(fe,{onClick:r,children:[l("common:logout"),e.jsx(Yt,{children:"⇧⌘Q"})]})]})]})}const Ze=window?.settings?.secure_path,ur=5*60*1e3,Jt=new Map,Nc=s=>{const n=Jt.get(s);return n?Date.now()-n.timestamp>ur?(Jt.delete(s),null):n.data:null},_c=(s,n)=>{Jt.set(s,{data:n,timestamp:Date.now()})},wc=async(s,n=ur)=>{const a=Nc(s);if(a)return a;const l=await O.get(s);return _c(s,l),l},Cc={getList:()=>wc(`${Ze}/notice/fetch`),save:s=>O.post(`${Ze}/notice/save`,s),drop:s=>O.post(`${Ze}/notice/drop`,{id:s}),updateStatus:s=>O.post(`${Ze}/notice/show`,{id:s}),sort:s=>O.post(`${Ze}/notice/sort`,{ids:s})},Va={getSystemStatus:()=>O.get(`${Ze}/system/getSystemStatus`),getQueueStats:()=>O.get(`${Ze}/system/getQueueStats`),getQueueWorkload:()=>O.get(`${Ze}/system/getQueueWorkload`),getQueueMasters:()=>O.get(`${Ze}/system/getQueueMasters`),getSystemLog:s=>O.get(`${Ze}/system/getSystemLog`,{params:s})},L=window?.settings?.secure_path,Sc=s=>O.get(L+"/stat/getOrder",{params:s}),kc=()=>O.get(L+"/stat/getStats"),Ia=s=>O.get(L+"/stat/getTrafficRank",{params:s}),Tc=()=>O.get(L+"/theme/getThemes"),Dc=s=>O.post(L+"/theme/getThemeConfig",{name:s}),Pc=(s,n)=>O.post(L+"/theme/saveThemeConfig",{name:s,config:n}),Rc=s=>{const n=new FormData;return n.append("file",s),O.post(L+"/theme/upload",n,{headers:{"Content-Type":"multipart/form-data"}})},Ec=s=>O.post(L+"/theme/delete",{name:s}),Vc=s=>O.post(L+"/config/save",s),xr=()=>O.get(L+"/server/manage/getNodes"),Ic=s=>O.post(L+"/server/manage/save",s),Fc=s=>O.post(L+"/server/manage/drop",s),Mc=s=>O.post(L+"/server/manage/copy",s),Oc=s=>O.post(L+"/server/manage/update",s),zc=s=>O.post(L+"/server/manage/sort",s),It=()=>O.get(L+"/server/group/fetch"),Lc=s=>O.post(L+"/server/group/save",s),Ac=s=>O.post(L+"/server/group/drop",s),hr=()=>O.get(L+"/server/route/fetch"),$c=s=>O.post(L+"/server/route/save",s),qc=s=>O.post(L+"/server/route/drop",s),Kc=()=>O.get(L+"/payment/fetch"),Hc=()=>O.get(L+"/payment/getPaymentMethods"),Uc=s=>O.post(L+"/payment/getPaymentForm",s),Bc=s=>O.post(L+"/payment/save",s),Gc=s=>O.post(L+"/payment/drop",s),Wc=s=>O.post(L+"/payment/show",s),Yc=s=>O.post(L+"/payment/sort",s),Jc=()=>O.get(L+"/notice/fetch"),Qc=s=>O.post(L+"/notice/save",s),Zc=s=>O.post(L+"/notice/drop",s),Xc=s=>O.post(L+"/notice/show",s),ed=()=>O.get(L+"/knowledge/fetch"),sd=s=>O.get(L+"/knowledge/fetch?id="+s),td=s=>O.post(L+"/knowledge/save",s),ad=s=>O.post(L+"/knowledge/drop",s),nd=s=>O.post(L+"/knowledge/show",s),rd=s=>O.post(L+"/knowledge/sort",s),Fs=()=>O.get(L+"/plan/fetch"),ld=s=>O.post(L+"/plan/save",s),Lt=s=>O.post(L+"/plan/update",s),od=s=>O.post(L+"/plan/drop",s),id=s=>O.post(L+"/plan/sort",{ids:s}),cd=async s=>O.post(L+"/order/fetch",s),dd=s=>O.post(L+"/order/detail",s),md=s=>O.post(L+"/order/paid",s),ud=s=>O.post(L+"/order/cancel",s),Fa=s=>O.post(L+"/order/update",s),xd=s=>O.post(L+"/order/assign",s),hd=s=>O.post(L+"/coupon/fetch",s),fd=s=>O.post(L+"/coupon/generate",s),pd=s=>O.post(L+"/coupon/drop",s),gd=s=>O.post(L+"/coupon/update",s),jd=s=>O.post(L+"/user/fetch",s),vd=s=>O.post(L+"/user/update",s),bd=s=>O.post(L+"/user/resetSecret",s),yd=s=>O.post(L+"/user/generate",s),Nd=s=>O.post(L+"/stat/getStatUser",s),_d=s=>O.post(L+"/ticket/fetch",s),wd=s=>O.get(L+"/ticket/fetch?id= "+s),Cd=s=>O.post(L+"/ticket/reply",s),fr=s=>O.post(L+"/ticket/close",{id:s}),xs=(s="")=>O.get(L+"/config/fetch?key="+s),hs=s=>O.post(L+"/config/save",s),Sd=()=>O.get(L+"/config/getEmailTemplate"),kd=()=>O.post(L+"/config/testSendMail"),Td=()=>O.post(L+"/config/setTelegramWebhook"),Dd=Cc.sort,pr=mo,ia=u.forwardRef(({className:s,...n},a)=>e.jsx(xn,{ref:a,className:y("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...n}));ia.displayName=xn.displayName;const nt=u.forwardRef(({className:s,...n},a)=>e.jsx(hn,{ref:a,className:y("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}));nt.displayName=hn.displayName;const Pd=u.forwardRef(({className:s,...n},a)=>e.jsx(fn,{ref:a,className:y("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...n}));Pd.displayName=fn.displayName;const W=uo,ps=bo,Y=xo,B=u.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(pn,{ref:l,className:y("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),...a,children:[n,e.jsx(ho,{asChild:!0,children:e.jsx(aa,{className:"h-4 w-4 opacity-50"})})]}));B.displayName=pn.displayName;const gr=u.forwardRef(({className:s,...n},a)=>e.jsx(gn,{ref:a,className:y("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(fo,{className:"h-4 w-4"})}));gr.displayName=gn.displayName;const jr=u.forwardRef(({className:s,...n},a)=>e.jsx(jn,{ref:a,className:y("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(aa,{className:"h-4 w-4"})}));jr.displayName=jn.displayName;const G=u.forwardRef(({className:s,children:n,position:a="popper",...l},r)=>e.jsx(po,{children:e.jsxs(vn,{ref:r,className:y("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",a==="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:a,...l,children:[e.jsx(gr,{}),e.jsx(go,{className:y("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx(jr,{})]})}));G.displayName=vn.displayName;const Rd=u.forwardRef(({className:s,...n},a)=>e.jsx(bn,{ref:a,className:y("px-2 py-1.5 text-sm font-semibold",s),...n}));Rd.displayName=bn.displayName;const $=u.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(yn,{ref:l,className:y("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),...a,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(jo,{children:e.jsx(Ps,{className:"h-4 w-4"})})}),e.jsx(vo,{children:n})]}));$.displayName=yn.displayName;const Ed=u.forwardRef(({className:s,...n},a)=>e.jsx(Nn,{ref:a,className:y("-mx-1 my-1 h-px bg-muted",s),...n}));Ed.displayName=Nn.displayName;function Ms({className:s,classNames:n,showOutsideDays:a=!0,...l}){return e.jsx(yo,{showOutsideDays:a,className:y("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:y(qs({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:y("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",l.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:y(qs({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:r,...i})=>e.jsx(_n,{className:y("h-4 w-4",r),...i}),IconRight:({className:r,...i})=>e.jsx(ta,{className:y("h-4 w-4",r),...i})},...l})}Ms.displayName="Calendar";const ns=_o,rs=wo,Ye=u.forwardRef(({className:s,align:n="center",sideOffset:a=4,...l},r)=>e.jsx(No,{children:e.jsx(wn,{ref:r,align:n,sideOffset:a,className:y("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),...l})}));Ye.displayName=wn.displayName;const gs={income:{main:"hsl(var(--primary))",gradient:{start:"hsl(var(--primary))",end:"transparent"}},commission:{main:"hsl(var(--secondary))",gradient:{start:"hsl(var(--secondary))",end:"transparent"}}},Qs=s=>(s/100).toFixed(2),Vd=({active:s,payload:n,label:a})=>{const{t:l}=I();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:a}),n.map((r,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:r.color}}),e.jsxs("span",{className:"text-muted-foreground",children:[l(r.name),":"]}),e.jsx("span",{className:"font-medium",children:r.name.includes(l("dashboard:overview.amount"))?`¥${Qs(r.value)}`:l("dashboard:overview.transactions",{count:r.value})})]},i))]}):null},Id=[{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"}],Fd=(s,n)=>{const a=new Date;if(s==="custom"&&n)return{startDate:n.from,endDate:n.to};let l;switch(s){case"7d":l=Ke(a,7);break;case"30d":l=Ke(a,30);break;case"90d":l=Ke(a,90);break;case"180d":l=Ke(a,180);break;case"365d":l=Ke(a,365);break;default:l=Ke(a,30)}return{startDate:l,endDate:a}};function Md(){const[s,n]=u.useState("amount"),[a,l]=u.useState("30d"),[r,i]=u.useState({from:Ke(new Date,7),to:new Date}),{t:c}=I(),{startDate:m,endDate:x}=Fd(a,r),{data:o}=se({queryKey:["orderStat",{start_date:qe(m,"yyyy-MM-dd"),end_date:qe(x,"yyyy-MM-dd")}],queryFn:async()=>{const{data:d}=await Sc({start_date:qe(m,"yyyy-MM-dd"),end_date:qe(x,"yyyy-MM-dd")});return d},refetchInterval:3e4});return e.jsxs(Ue,{children:[e.jsx(ts,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(bs,{children:c("dashboard:overview.title")}),e.jsxs(tt,{children:[o?.summary.start_date," ",c("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(W,{value:a,onValueChange:d=>l(d),children:[e.jsx(B,{className:"w-[120px]",children:e.jsx(Y,{placeholder:c("dashboard:overview.selectTimeRange")})}),e.jsx(G,{children:Id.map(d=>e.jsx($,{value:d.value,children:c(d.label)},d.value))})]}),a==="custom"&&e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(J,{variant:"outline",className:y("min-w-0 justify-start text-left font-normal",!r&&"text-muted-foreground"),children:[e.jsx(it,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:r?.from?r.to?e.jsxs(e.Fragment,{children:[qe(r.from,"yyyy-MM-dd")," -"," ",qe(r.to,"yyyy-MM-dd")]}):qe(r.from,"yyyy-MM-dd"):c("dashboard:overview.selectDate")})]})}),e.jsx(Ye,{className:"w-auto p-0",align:"end",children:e.jsx(Ms,{mode:"range",defaultMonth:r?.from,selected:{from:r?.from,to:r?.to},onSelect:d=>{d?.from&&d?.to&&i({from:d.from,to:d.to})},numberOfMonths:2})})]})]}),e.jsx(pr,{value:s,onValueChange:d=>n(d),children:e.jsxs(ia,{children:[e.jsx(nt,{value:"amount",children:c("dashboard:overview.amount")}),e.jsx(nt,{value:"count",children:c("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:c("dashboard:overview.totalIncome")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",Qs(o?.summary?.paid_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:c("dashboard:overview.totalTransactions",{count:o?.summary?.paid_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[c("dashboard:overview.avgOrderAmount")," ¥",Qs(o?.summary?.avg_paid_amount||0)]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:c("dashboard:overview.totalCommission")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",Qs(o?.summary?.commission_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:c("dashboard:overview.totalTransactions",{count:o?.summary?.commission_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[c("dashboard:overview.commissionRate")," ",o?.summary?.commission_rate.toFixed(2)||0,"%"]})]})]}),e.jsx("div",{className:"h-[400px] w-full",children:e.jsx(Co,{width:"100%",height:"100%",children:e.jsxs(So,{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:gs.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:gs.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:gs.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:gs.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(ko,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:d=>qe(new Date(d),"MM-dd",{locale:Ro})}),e.jsx(To,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:d=>s==="amount"?`¥${Qs(d)}`:c("dashboard:overview.transactions",{count:d})}),e.jsx(Do,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(Po,{content:e.jsx(Vd,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(wa,{type:"monotone",dataKey:"paid_total",name:c("dashboard:overview.orderAmount"),stroke:gs.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(wa,{type:"monotone",dataKey:"commission_total",name:c("dashboard:overview.commissionAmount"),stroke:gs.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ca,{dataKey:"paid_count",name:c("dashboard:overview.orderCount"),fill:gs.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(Ca,{dataKey:"commission_count",name:c("dashboard:overview.commissionCount"),fill:gs.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})]})]})}function Ie({className:s,...n}){return e.jsx("div",{className:y("animate-pulse rounded-md bg-primary/10",s),...n})}function Od(){return e.jsxs(Ue,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ie,{className:"h-4 w-[120px]"}),e.jsx(Ie,{className:"h-4 w-4"})]}),e.jsxs(as,{children:[e.jsx(Ie,{className:"h-8 w-[140px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),e.jsx(Ie,{className:"h-4 w-[100px]"})]})]})]})}function zd(){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(Od,{},n))})}var Z=(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))(Z||{});const Ys={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},Js={0:"yellow-500",1:"blue-500",2:"red-500",3:"green-500",4:"green-500"};var He=(s=>(s[s.NEW=1]="NEW",s[s.RENEWAL=2]="RENEWAL",s[s.UPGRADE=3]="UPGRADE",s[s.RESET_FLOW=4]="RESET_FLOW",s))(He||{}),ne=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(ne||{});const ut={0:"待确认",1:"发放中",2:"有效",3:"无效"},xt={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var de=(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))(de||{});const Ld={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var ye=(s=>(s.Shadowsocks="shadowsocks",s.Vmess="vmess",s.Trojan="trojan",s.Hysteria="hysteria",s.Vless="vless",s))(ye||{});const Ts=[{type:"shadowsocks",label:"Shadowsocks"},{type:"vmess",label:"VMess"},{type:"trojan",label:"Trojan"},{type:"hysteria",label:"Hysteria"},{type:"vless",label:"VLess"}],os={shadowsocks:"#489851",vmess:"#CB3180",trojan:"#EBB749",hysteria:"#5684e6",vless:"#1a1a1a"};var Ve=(s=>(s[s.AMOUNT=1]="AMOUNT",s[s.PERCENTAGE=2]="PERCENTAGE",s))(Ve||{});const Ad={1:"按金额优惠",2:"按比例优惠"};var et=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(et||{}),es=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(es||{});function js({title:s,value:n,icon:a,trend:l,description:r,onClick:i,highlight:c,className:m}){return e.jsxs(Ue,{className:y("transition-colors",i&&"cursor-pointer hover:bg-muted/50",c&&"border-primary/50",m),onClick:i,children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(bs,{className:"text-sm font-medium",children:s}),a]}),e.jsxs(as,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n}),l?e.jsxs("div",{className:"flex items-center pt-1",children:[e.jsx(Oo,{className:y("h-4 w-4",l.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:y("ml-1 text-xs",l.isPositive?"text-emerald-500":"text-red-500"),children:[l.isPositive?"+":"-",Math.abs(l.value),"%"]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:l.label})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]})]})}function $d({className:s}){const n=cs(),{t:a}=I(),{data:l,isLoading:r}=se({queryKey:["dashboardStats"],queryFn:async()=>(await kc()).data,refetchInterval:1e3*60*5});if(r||!l)return e.jsx(zd,{});const i=()=>{const c=new URLSearchParams;c.set("commission_status",ne.PENDING.toString()),c.set("status",Z.COMPLETED.toString()),c.set("commission_balance","gt:0"),n(`/finance/order?${c.toString()}`)};return e.jsxs("div",{className:y("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(js,{title:a("dashboard:stats.todayIncome"),value:ks(l.todayIncome),icon:e.jsx(Eo,{className:"h-4 w-4 text-emerald-500"}),trend:{value:l.dayIncomeGrowth,label:a("dashboard:stats.vsYesterday"),isPositive:l.dayIncomeGrowth>0}}),e.jsx(js,{title:a("dashboard:stats.monthlyIncome"),value:ks(l.currentMonthIncome),icon:e.jsx(Vo,{className:"h-4 w-4 text-blue-500"}),trend:{value:l.monthIncomeGrowth,label:a("dashboard:stats.vsLastMonth"),isPositive:l.monthIncomeGrowth>0}}),e.jsx(js,{title:a("dashboard:stats.pendingTickets"),value:l.ticketPendingTotal,icon:e.jsx(Io,{className:y("h-4 w-4",l.ticketPendingTotal>0?"text-orange-500":"text-muted-foreground")}),description:l.ticketPendingTotal>0?a("dashboard:stats.hasPendingTickets"):a("dashboard:stats.noPendingTickets"),onClick:()=>n("/user/ticket"),highlight:l.ticketPendingTotal>0}),e.jsx(js,{title:a("dashboard:stats.pendingCommission"),value:l.commissionPendingTotal,icon:e.jsx(Fo,{className:y("h-4 w-4",l.commissionPendingTotal>0?"text-blue-500":"text-muted-foreground")}),description:l.commissionPendingTotal>0?a("dashboard:stats.hasPendingCommission"):a("dashboard:stats.noPendingCommission"),onClick:i,highlight:l.commissionPendingTotal>0}),e.jsx(js,{title:a("dashboard:stats.monthlyNewUsers"),value:l.currentMonthNewUsers,icon:e.jsx(Kt,{className:"h-4 w-4 text-blue-500"}),trend:{value:l.userGrowth,label:a("dashboard:stats.vsLastMonth"),isPositive:l.userGrowth>0}}),e.jsx(js,{title:a("dashboard:stats.totalUsers"),value:l.totalUsers,icon:e.jsx(Kt,{className:"h-4 w-4 text-muted-foreground"}),description:a("dashboard:stats.activeUsers",{count:l.activeUsers})}),e.jsx(js,{title:a("dashboard:stats.monthlyUpload"),value:Xe(l.monthTraffic.upload),icon:e.jsx(Ht,{className:"h-4 w-4 text-emerald-500"}),description:a("dashboard:stats.todayTraffic",{value:Xe(l.todayTraffic.upload)})}),e.jsx(js,{title:a("dashboard:stats.monthlyDownload"),value:Xe(l.monthTraffic.download),icon:e.jsx(Mo,{className:"h-4 w-4 text-blue-500"}),description:a("dashboard:stats.todayTraffic",{value:Xe(l.todayTraffic.download)})})]})}const rt=u.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(Cn,{ref:l,className:y("relative overflow-hidden",s),...a,children:[e.jsx(zo,{className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(Ct,{}),e.jsx(Lo,{})]}));rt.displayName=Cn.displayName;const Ct=u.forwardRef(({className:s,orientation:n="vertical",...a},l)=>e.jsx(Sn,{ref:l,orientation:n,className:y("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),...a,children:e.jsx(Ao,{className:"relative flex-1 rounded-full bg-border"})}));Ct.displayName=Sn.displayName;const Qt={today:{getValue:()=>{const s=qo();return{start:s,end:Ko(s,1)}}},last7days:{getValue:()=>{const s=new Date;return{start:Ke(s,7),end:s}}},last30days:{getValue:()=>{const s=new Date;return{start:Ke(s,30),end:s}}},custom:{getValue:()=>null}};function Ma({selectedRange:s,customDateRange:n,onRangeChange:a,onCustomRangeChange:l}){const{t:r}=I(),i={today:r("dashboard:trafficRank.today"),last7days:r("dashboard:trafficRank.last7days"),last30days:r("dashboard:trafficRank.last30days"),custom:r("dashboard:trafficRank.customRange")};return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsxs(W,{value:s,onValueChange:a,children:[e.jsx(B,{className:"w-[120px]",children:e.jsx(Y,{placeholder:r("dashboard:trafficRank.selectTimeRange")})}),e.jsx(G,{position:"popper",className:"z-50",children:Object.entries(Qt).map(([c])=>e.jsx($,{value:c,children:i[c]},c))})]}),s==="custom"&&e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(J,{variant:"outline",className:y("min-w-0 justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(it,{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:[qe(n.from,"yyyy-MM-dd")," -"," ",qe(n.to,"yyyy-MM-dd")]}):qe(n.from,"yyyy-MM-dd"):e.jsx("span",{children:r("dashboard:trafficRank.selectDateRange")})})]})}),e.jsx(Ye,{className:"w-auto p-0",align:"end",children:e.jsx(Ms,{mode:"range",defaultMonth:n?.from,selected:{from:n?.from,to:n?.to},onSelect:c=>{c?.from&&c?.to&&l({from:c.from,to:c.to})},numberOfMonths:2})})]})]})}const zs=s=>`${(s/1024/1024/1024).toFixed(2)} GB`;function qd({className:s}){const{t:n}=I(),[a,l]=u.useState("today"),[r,i]=u.useState({from:Ke(new Date,7),to:new Date}),[c,m]=u.useState("today"),[x,o]=u.useState({from:Ke(new Date,7),to:new Date}),d=u.useMemo(()=>a==="custom"?{start:r.from,end:r.to}:Qt[a].getValue(),[a,r]),p=u.useMemo(()=>c==="custom"?{start:x.from,end:x.to}:Qt[c].getValue(),[c,x]),{data:k}=se({queryKey:["nodeTrafficRank",d.start,d.end],queryFn:()=>Ia({type:"node",start_time:pe.round(d.start.getTime()/1e3),end_time:pe.round(d.end.getTime()/1e3)}),refetchInterval:3e4}),{data:E}=se({queryKey:["userTrafficRank",p.start,p.end],queryFn:()=>Ia({type:"user",start_time:pe.round(p.start.getTime()/1e3),end_time:pe.round(p.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:y("grid gap-4 md:grid-cols-2",s),children:[e.jsxs(Ue,{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(bs,{className:"flex items-center text-base font-medium",children:[e.jsx($o,{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(Ma,{selectedRange:a,customDateRange:r,onRangeChange:l,onCustomRangeChange:i}),e.jsx(Sa,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(as,{className:"flex-1",children:k?.data?e.jsxs(rt,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:k.data.map(f=>e.jsx(ie,{delayDuration:200,children:e.jsxs(re,{children:[e.jsx(le,{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:f.name}),e.jsxs("span",{className:y("ml-2 flex items-center text-xs font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?e.jsx(Ut,{className:"mr-1 h-3 w-3"}):e.jsx(Bt,{className:"mr-1 h-3 w-3"}),Math.abs(f.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:`${f.value/k.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:zs(f.value)})]})]})})}),e.jsx(te,{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:zs(f.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:zs(f.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:y("font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?"+":"",f.change,"%"]})]})})]})},f.id))}),e.jsx(Ct,{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(Ue,{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(bs,{className:"flex items-center text-base font-medium",children:[e.jsx(Kt,{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(Ma,{selectedRange:c,customDateRange:x,onRangeChange:m,onCustomRangeChange:o}),e.jsx(Sa,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(as,{className:"flex-1",children:E?.data?e.jsxs(rt,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:E.data.map(f=>e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{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:f.name}),e.jsxs("span",{className:y("ml-2 flex items-center text-xs font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?e.jsx(Ut,{className:"mr-1 h-3 w-3"}):e.jsx(Bt,{className:"mr-1 h-3 w-3"}),Math.abs(f.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:`${f.value/E.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:zs(f.value)})]})]})})}),e.jsx(te,{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:zs(f.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:zs(f.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:y("font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?"+":"",f.change,"%"]})]})})]})},f.id))}),e.jsx(Ct,{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 Kd=Ds("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 K({className:s,variant:n,...a}){return e.jsx("div",{className:y(Kd({variant:n}),s),...a})}const vt=u.forwardRef(({className:s,value:n,...a},l)=>e.jsx(kn,{ref:l,className:y("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...a,children:e.jsx(Ho,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(n||0)}%)`}})}));vt.displayName=kn.displayName;function Hd(){const{t:s}=I(),[n,a]=u.useState(null),[l,r]=u.useState(null),[i,c]=u.useState(!0),[m,x]=u.useState(!1),o=async()=>{try{x(!0);const[k,E]=await Promise.all([Va.getSystemStatus(),Va.getQueueStats()]);a(k.data),r(E.data)}catch(k){console.error("Error fetching system data:",k)}finally{c(!1),x(!1)}};u.useEffect(()=>{o();const k=setInterval(o,3e4);return()=>clearInterval(k)},[]);const d=()=>{o()};if(i)return e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx(na,{className:"h-6 w-6 animate-spin"})});const p=k=>k?e.jsx(Tn,{className:"h-5 w-5 text-green-500"}):e.jsx(Dn,{className:"h-5 w-5 text-red-500"});return e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ue,{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(bs,{className:"flex items-center gap-2",children:[e.jsx(Uo,{className:"h-5 w-5"}),s("dashboard:queue.title")]}),e.jsx(tt,{children:s("dashboard:queue.status.description")})]}),e.jsx(J,{variant:"outline",size:"icon",onClick:d,disabled:m,children:e.jsx(Bo,{className:y("h-4 w-4",m&&"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:[p(l?.status||!1),e.jsx("span",{className:"font-medium",children:s("dashboard:queue.status.running")})]}),e.jsx(K,{variant:l?.status?"secondary":"destructive",children:l?.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:l?.wait?.default||0})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{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:l?.recentJobs||0}),e.jsx(vt,{value:(l?.recentJobs||0)/(l?.periods?.recentJobs||1)*100,className:"h-1"})]})}),e.jsx(te,{children:e.jsx("p",{children:s("dashboard:queue.details.statisticsPeriod",{hours:l?.periods?.recentJobs||0})})})]})}),e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{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:l?.jobsPerMinute||0}),e.jsx(vt,{value:(l?.jobsPerMinute||0)/(l?.queueWithMaxThroughput?.throughput||1)*100,className:"h-1"})]})}),e.jsx(te,{children:e.jsx("p",{children:s("dashboard:queue.details.maxThroughput",{value:l?.queueWithMaxThroughput?.throughput||0})})})]})})]})]})})]}),e.jsxs(Ue,{children:[e.jsxs(ts,{children:[e.jsxs(bs,{className:"flex items-center gap-2",children:[e.jsx(Go,{className:"h-5 w-5"}),s("dashboard:queue.jobDetails")]}),e.jsx(tt,{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:l?.failedJobs||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("dashboard:queue.details.retentionPeriod",{hours:l?.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:[l?.queueWithMaxRuntime?.runtime||0,"s"]}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:l?.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:[l?.processes||0," /"," ",(l?.processes||0)+(l?.pausedMasters||0)]})]}),e.jsx(vt,{value:(l?.processes||0)/((l?.processes||0)+(l?.pausedMasters||0))*100,className:"mt-2 h-1"})]})]})})]})]})}function Ud(){const{t:s}=I();return e.jsxs(we,{children:[e.jsxs(Ce,{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(Pe,{}),e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsx(ke,{children:e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsx($d,{}),e.jsx(Md,{}),e.jsx(qd,{}),e.jsx(Hd,{})]})})})]})}const Bd=Object.freeze(Object.defineProperty({__proto__:null,default:Ud},Symbol.toStringTag,{value:"Module"})),be=u.forwardRef(({className:s,orientation:n="horizontal",decorative:a=!0,...l},r)=>e.jsx(Pn,{ref:r,decorative:a,orientation:n,className:y("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...l}));be.displayName=Pn.displayName;function Gd({className:s,items:n,...a}){const{pathname:l}=Xt(),r=cs(),[i,c]=u.useState(l??"/settings"),m=o=>{c(o),r(o)},{t:x}=I("settings");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-1 md:hidden",children:e.jsxs(W,{value:i,onValueChange:m,children:[e.jsx(B,{className:"h-12 sm:w-48",children:e.jsx(Y,{placeholder:"Theme"})}),e.jsx(G,{children:n.map(o=>e.jsx($,{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:x(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:y("flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",s),...a,children:n.map(o=>e.jsxs(Rs,{to:o.href,className:y(Ks({variant:"ghost"}),l===o.href?"bg-muted hover:bg-muted":"hover:bg-transparent hover:underline","justify-start"),children:[e.jsx("span",{className:"mr-2",children:o.icon}),x(o.title)]},o.href))})})]})}const Wd=[{title:"site.title",key:"site",icon:e.jsx(Wo,{size:18}),href:"/config/system",description:"site.description"},{title:"safe.title",key:"safe",icon:e.jsx(on,{size:18}),href:"/config/system/safe",description:"safe.description"},{title:"subscribe.title",key:"subscribe",icon:e.jsx(cn,{size:18}),href:"/config/system/subscribe",description:"subscribe.description"},{title:"invite.title",key:"invite",icon:e.jsx(Yo,{size:18}),href:"/config/system/invite",description:"invite.description"},{title:"server.title",key:"server",icon:e.jsx(ln,{size:18}),href:"/config/system/server",description:"server.description"},{title:"email.title",key:"email",icon:e.jsx(Jo,{size:18}),href:"/config/system/email",description:"email.description"},{title:"telegram.title",key:"telegram",icon:e.jsx(Qo,{size:18}),href:"/config/system/telegram",description:"telegram.description"},{title:"app.title",key:"app",icon:e.jsx(rn,{size:18}),href:"/config/system/app",description:"app.description"}];function Yd(){const{t:s}=I("settings");return e.jsxs(we,{fadedBelow:!0,fixedHeight:!0,children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(be,{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(Gd,{items:Wd})}),e.jsx("div",{className:"w-full p-1 pr-4 lg:max-w-xl",children:e.jsx("div",{className:"pb-16",children:e.jsx(ea,{})})})]})]})]})}const Jd=Object.freeze(Object.defineProperty({__proto__:null,default:Yd},Symbol.toStringTag,{value:"Module"})),H=u.forwardRef(({className:s,...n},a)=>e.jsx(Rn,{className:y("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:a,children:e.jsx(Zo,{className:y("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")})}));H.displayName=Rn.displayName;const Cs=u.forwardRef(({className:s,...n},a)=>e.jsx("textarea",{className:y("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:a,...n}));Cs.displayName="Textarea";const Qd=h.object({logo:h.string().nullable().default(""),force_https:h.number().nullable().default(0),stop_register:h.number().nullable().default(0),app_name:h.string().nullable().default(""),app_description:h.string().nullable().default(""),app_url:h.string().nullable().default(""),subscribe_url:h.string().nullable().default(""),try_out_plan_id:h.number().nullable().default(0),try_out_hour:h.coerce.number().nullable().default(0),tos_url:h.string().nullable().default(""),currency:h.string().nullable().default(""),currency_symbol:h.string().nullable().default("")});function Zd(){const{t:s}=I("settings"),[n,a]=u.useState(!1),l=u.useRef(null),{data:r}=se({queryKey:["settings","site"],queryFn:()=>xs("site")}),{data:i}=se({queryKey:["plans"],queryFn:()=>Fs()}),c=ce({resolver:ue(Qd),defaultValues:{},mode:"onBlur"}),{mutateAsync:m}=ss({mutationFn:hs,onSuccess:d=>{d.data&&q.success(s("common.autoSaved"))}});u.useEffect(()=>{if(r?.data?.site){const d=r?.data?.site;Object.entries(d).forEach(([p,k])=>{c.setValue(p,k)}),l.current=d}},[r]);const x=u.useCallback(pe.debounce(async d=>{if(!pe.isEqual(d,l.current)){a(!0);try{const p=Object.entries(d).reduce((k,[E,f])=>(k[E]=f===null?"":f,k),{});await m(p),l.current=d}finally{a(!1)}}},1e3),[m]),o=u.useCallback(d=>{x(d)},[x]);return u.useEffect(()=>{const d=c.watch(p=>{o(p)});return()=>d.unsubscribe()},[c.watch,o]),e.jsx(xe,{...c,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:c.control,name:"app_name",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.siteName.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("site.form.siteName.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.siteName.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:c.control,name:"app_description",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.siteDescription.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("site.form.siteDescription.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.siteDescription.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:c.control,name:"app_url",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.siteUrl.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("site.form.siteUrl.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.siteUrl.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:c.control,name:"force_https",render:({field:d})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("site.form.forceHttps.label")}),e.jsx(F,{children:s("site.form.forceHttps.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:!!d.value,onCheckedChange:p=>{d.onChange(Number(p)),o(c.getValues())}})})]})}),e.jsx(v,{control:c.control,name:"logo",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.logo.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("site.form.logo.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.logo.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:c.control,name:"subscribe_url",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.subscribeUrl.label")}),e.jsx(N,{children:e.jsx(Cs,{placeholder:s("site.form.subscribeUrl.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.subscribeUrl.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:c.control,name:"tos_url",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.tosUrl.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("site.form.tosUrl.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.tosUrl.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:c.control,name:"stop_register",render:({field:d})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("site.form.stopRegister.label")}),e.jsx(F,{children:s("site.form.stopRegister.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:!!d.value,onCheckedChange:p=>{d.onChange(Number(p)),o(c.getValues())}})})]})}),e.jsx(v,{control:c.control,name:"try_out_plan_id",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.tryOut.label")}),e.jsx(N,{children:e.jsxs(W,{value:d.value?.toString(),onValueChange:p=>{d.onChange(Number(p)),o(c.getValues())},children:[e.jsx(B,{children:e.jsx(Y,{placeholder:s("site.form.tryOut.placeholder")})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("site.form.tryOut.placeholder")}),i?.data?.map(p=>e.jsx($,{value:p.id.toString(),children:p.name},p.id.toString()))]})]})}),e.jsx(F,{children:s("site.form.tryOut.description")}),e.jsx(R,{})]})}),!!c.watch("try_out_plan_id")&&e.jsx(v,{control:c.control,name:"try_out_hour",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"",children:s("site.form.tryOut.duration.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("site.form.tryOut.duration.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.tryOut.duration.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:c.control,name:"currency",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.currency.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("site.form.currency.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.currency.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:c.control,name:"currency_symbol",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.currencySymbol.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("site.form.currencySymbol.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),o(c.getValues())}})}),e.jsx(F,{children:s("site.form.currencySymbol.description")}),e.jsx(R,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("site.form.saving")})]})})}function Xd(){const{t:s}=I("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(be,{}),e.jsx(Zd,{})]})}const em=Object.freeze(Object.defineProperty({__proto__:null,default:Xd},Symbol.toStringTag,{value:"Module"})),sm=h.object({email_verify:h.boolean().nullable(),safe_mode_enable:h.boolean().nullable(),secure_path:h.string().nullable(),email_whitelist_enable:h.boolean().nullable(),email_whitelist_suffix:h.array(h.string().nullable()).nullable(),email_gmail_limit_enable:h.boolean().nullable(),recaptcha_enable:h.boolean().nullable(),recaptcha_key:h.string().nullable(),recaptcha_site_key:h.string().nullable(),register_limit_by_ip_enable:h.boolean().nullable(),register_limit_count:h.coerce.string().transform(s=>s===""?null:s).nullable(),register_limit_expire:h.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_enable:h.boolean().nullable(),password_limit_count:h.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_expire:h.coerce.string().transform(s=>s===""?null:s).nullable()}),tm={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 am(){const{t:s}=I("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=ce({resolver:ue(sm),defaultValues:tm,mode:"onBlur"}),{data:i}=se({queryKey:["settings","safe"],queryFn:()=>xs("safe")}),{mutateAsync:c}=ss({mutationFn:hs,onSuccess:o=>{o.data&&q.success(s("common.autoSaved"))}});u.useEffect(()=>{if(i?.data.safe){const o=i.data.safe;Object.entries(o).forEach(([d,p])=>{typeof p=="number"?r.setValue(d,String(p)):r.setValue(d,p)}),l.current=o}},[i]);const m=u.useCallback(pe.debounce(async o=>{if(!pe.isEqual(o,l.current)){a(!0);try{await c(o),l.current=o}finally{a(!1)}}},1e3),[c]),x=u.useCallback(o=>{m(o)},[m]);return u.useEffect(()=>{const o=r.watch(d=>{x(d)});return()=>o.unsubscribe()},[r.watch,x]),e.jsx(xe,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:r.control,name:"email_verify",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.emailVerify.label")}),e.jsx(F,{children:s("safe.form.emailVerify.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(v,{control:r.control,name:"email_gmail_limit_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.gmailLimit.label")}),e.jsx(F,{children:s("safe.form.gmailLimit.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(v,{control:r.control,name:"safe_mode_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.safeMode.label")}),e.jsx(F,{children:s("safe.form.safeMode.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(v,{control:r.control,name:"secure_path",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.securePath.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("safe.form.securePath.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.securePath.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"email_whitelist_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.emailWhitelist.label")}),e.jsx(F,{children:s("safe.form.emailWhitelist.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),r.watch("email_whitelist_enable")&&e.jsx(v,{control:r.control,name:"email_whitelist_suffix",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.emailWhitelist.suffixes.label")}),e.jsx(N,{children:e.jsx(Cs,{placeholder:s("safe.form.emailWhitelist.suffixes.placeholder"),...o,value:(o.value||[]).join(` `),onChange:d=>{const p=d.target.value.split(` -`).filter(Boolean);o.onChange(p),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.emailWhitelist.suffixes.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"recaptcha_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.recaptcha.enable.label")}),e.jsx(F,{children:s("safe.form.recaptcha.enable.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),r.watch("recaptcha_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:r.control,name:"recaptcha_key",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.recaptcha.key.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.recaptcha.key.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.recaptcha.key.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"recaptcha_site_key",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.recaptcha.siteKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.recaptcha.siteKey.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.recaptcha.siteKey.description")}),e.jsx(P,{})]})})]}),e.jsx(j,{control:r.control,name:"register_limit_by_ip_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.registerLimit.enable.label")}),e.jsx(F,{children:s("safe.form.registerLimit.enable.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),r.watch("register_limit_by_ip_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:r.control,name:"register_limit_count",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.registerLimit.count.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.registerLimit.count.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.registerLimit.count.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"register_limit_expire",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.registerLimit.expire.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.registerLimit.expire.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.registerLimit.expire.description")}),e.jsx(P,{})]})})]}),e.jsx(j,{control:r.control,name:"password_limit_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.passwordLimit.enable.label")}),e.jsx(F,{children:s("safe.form.passwordLimit.enable.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),r.watch("password_limit_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:r.control,name:"password_limit_count",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.passwordLimit.count.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.passwordLimit.count.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.passwordLimit.count.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"password_limit_expire",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.passwordLimit.expire.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.passwordLimit.expire.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.passwordLimit.expire.description")}),e.jsx(P,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("safe.form.saving")})]})})}function nm(){const{t:s}=I("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(be,{}),e.jsx(am,{})]})}const rm=Object.freeze(Object.defineProperty({__proto__:null,default:nm},Symbol.toStringTag,{value:"Module"})),lm=h.object({plan_change_enable:h.boolean().nullable().default(!1),reset_traffic_method:h.coerce.number().nullable().default(0),surplus_enable:h.boolean().nullable().default(!1),new_order_event_id:h.coerce.number().nullable().default(0),renew_order_event_id:h.coerce.number().nullable().default(0),change_order_event_id:h.coerce.number().nullable().default(0),show_info_to_server_enable:h.boolean().nullable().default(!1),show_protocol_to_server_enable:h.boolean().nullable().default(!1),default_remind_expire:h.boolean().nullable().default(!1),default_remind_traffic:h.boolean().nullable().default(!1),subscribe_path:h.string().nullable().default("s")}),om={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 im(){const{t:s}=I("settings"),[n,a]=m.useState(!1),l=m.useRef(null),r=ce({resolver:ue(lm),defaultValues:om,mode:"onBlur"}),{data:i}=se({queryKey:["settings","subscribe"],queryFn:()=>us("subscribe")}),{mutateAsync:c}=es({mutationFn:xs,onSuccess:o=>{o.data&&q.success(s("common.autoSaved"))}});m.useEffect(()=>{if(i?.data?.subscribe){const o=i?.data?.subscribe;Object.entries(o).forEach(([d,p])=>{r.setValue(d,p)}),l.current=o}},[i]);const u=m.useCallback(pe.debounce(async o=>{if(!pe.isEqual(o,l.current)){a(!0);try{await c(o),l.current=o}finally{a(!1)}}},1e3),[c]),x=m.useCallback(o=>{u(o)},[u]);return m.useEffect(()=>{const o=r.watch(d=>{x(d)});return()=>o.unsubscribe()},[r.watch,x]),e.jsx(xe,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:r.control,name:"plan_change_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.plan_change_enable.title")}),e.jsx(F,{children:s("subscribe.plan_change_enable.description")}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"reset_traffic_method",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.reset_traffic_method.title")}),e.jsxs(W,{onValueChange:o.onChange,value:o.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:"请选择重置方式"})})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("subscribe.reset_traffic_method.options.monthly_first")}),e.jsx($,{value:"1",children:s("subscribe.reset_traffic_method.options.monthly_reset")}),e.jsx($,{value:"2",children:s("subscribe.reset_traffic_method.options.no_reset")}),e.jsx($,{value:"3",children:s("subscribe.reset_traffic_method.options.yearly_first")}),e.jsx($,{value:"4",children:s("subscribe.reset_traffic_method.options.yearly_reset")})]})]}),e.jsx(F,{children:s("subscribe.reset_traffic_method.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"surplus_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.surplus_enable.title")}),e.jsx(F,{children:s("subscribe.surplus_enable.description")}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"new_order_event_id",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.new_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(W,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:"请选择"})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("subscribe.new_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.new_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("subscribe.new_order_event.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"renew_order_event_id",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.renew_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(W,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:"请选择"})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("subscribe.renew_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.renew_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("renew_order_event.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"change_order_event_id",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.change_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(W,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:"请选择"})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("subscribe.change_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.change_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("subscribe.change_order_event.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"subscribe_path",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.subscribe_path.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:"subscribe",...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.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(P,{})]})}),e.jsx(j,{control:r.control,name:"show_info_to_server_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("subscribe.show_info_to_server.title")}),e.jsx(F,{children:s("subscribe.show_info_to_server.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(j,{control:r.control,name:"show_protocol_to_server_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("subscribe.show_protocol_to_server.title")}),e.jsx(F,{children:s("subscribe.show_protocol_to_server.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function cm(){const{t:s}=I("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(be,{}),e.jsx(im,{})]})}const dm=Object.freeze(Object.defineProperty({__proto__:null,default:cm},Symbol.toStringTag,{value:"Module"})),mm=h.object({invite_force:h.boolean().default(!1),invite_commission:h.coerce.string().default("0"),invite_gen_limit:h.coerce.string().default("0"),invite_never_expire:h.boolean().default(!1),commission_first_time_enable:h.boolean().default(!1),commission_auto_check_enable:h.boolean().default(!1),commission_withdraw_limit:h.coerce.string().default("0"),commission_withdraw_method:h.array(h.string()).default(["支付宝","USDT","Paypal"]),withdraw_close_enable:h.boolean().default(!1),commission_distribution_enable:h.boolean().default(!1),commission_distribution_l1:h.coerce.number().default(0),commission_distribution_l2:h.coerce.number().default(0),commission_distribution_l3:h.coerce.number().default(0)}),um={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 xm(){const{t:s}=I("settings"),[n,a]=m.useState(!1),l=m.useRef(null),r=ce({resolver:ue(mm),defaultValues:um,mode:"onBlur"}),{data:i}=se({queryKey:["settings","invite"],queryFn:()=>us("invite")}),{mutateAsync:c}=es({mutationFn:xs,onSuccess:o=>{o.data&&q.success(s("common.autoSaved"))}});m.useEffect(()=>{if(i?.data?.invite){const o=i?.data?.invite;Object.entries(o).forEach(([d,p])=>{typeof p=="number"?r.setValue(d,String(p)):r.setValue(d,p)}),l.current=o}},[i]);const u=m.useCallback(pe.debounce(async o=>{if(!pe.isEqual(o,l.current)){a(!0);try{await c(o),l.current=o}finally{a(!1)}}},1e3),[c]),x=m.useCallback(o=>{u(o)},[u]);return m.useEffect(()=>{const o=r.watch(d=>{x(d)});return()=>o.unsubscribe()},[r.watch,x]),e.jsx(xe,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:r.control,name:"invite_force",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.invite_force.title")}),e.jsx(F,{children:s("invite.invite_force.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(j,{control:r.control,name:"invite_commission",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("invite.invite_commission.title")}),e.jsx(N,{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(P,{})]})}),e.jsx(j,{control:r.control,name:"invite_gen_limit",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("invite.invite_gen_limit.title")}),e.jsx(N,{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(P,{})]})}),e.jsx(j,{control:r.control,name:"invite_never_expire",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.invite_never_expire.title")}),e.jsx(F,{children:s("invite.invite_never_expire.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(j,{control:r.control,name:"commission_first_time_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.commission_first_time.title")}),e.jsx(F,{children:s("invite.commission_first_time.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(j,{control:r.control,name:"commission_auto_check_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.commission_auto_check.title")}),e.jsx(F,{children:s("invite.commission_auto_check.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(j,{control:r.control,name:"commission_withdraw_limit",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("invite.commission_withdraw_limit.title")}),e.jsx(N,{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(P,{})]})}),e.jsx(j,{control:r.control,name:"commission_withdraw_method",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("invite.commission_withdraw_method.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("invite.commission_withdraw_method.placeholder"),...o,value:Array.isArray(o.value)?o.value.join(","):"",onChange:d=>{const p=d.target.value.split(",").filter(Boolean);o.onChange(p),x(r.getValues())}})}),e.jsx(F,{children:s("invite.commission_withdraw_method.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"withdraw_close_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.withdraw_close.title")}),e.jsx(F,{children:s("invite.withdraw_close.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(j,{control:r.control,name:"commission_distribution_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.commission_distribution.title")}),e.jsx(F,{children:s("invite.commission_distribution.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),r.watch("commission_distribution_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:r.control,name:"commission_distribution_l1",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:s("invite.commission_distribution.l1")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:d=>{const p=d.target.value?Number(d.target.value):0;o.onChange(p),x(r.getValues())}})}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"commission_distribution_l2",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:s("invite.commission_distribution.l2")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:d=>{const p=d.target.value?Number(d.target.value):0;o.onChange(p),x(r.getValues())}})}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"commission_distribution_l3",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:s("invite.commission_distribution.l3")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:d=>{const p=d.target.value?Number(d.target.value):0;o.onChange(p),x(r.getValues())}})}),e.jsx(P,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("invite.saving")})]})})}function hm(){const{t:s}=I("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(be,{}),e.jsx(xm,{})]})}const fm=Object.freeze(Object.defineProperty({__proto__:null,default:hm},Symbol.toStringTag,{value:"Module"})),pm=h.object({frontend_theme:h.string().nullable(),frontend_theme_sidebar:h.string().nullable(),frontend_theme_header:h.string().nullable(),frontend_theme_color:h.string().nullable(),frontend_background_url:h.string().url().nullable()}),gm={frontend_theme:"",frontend_theme_sidebar:"",frontend_theme_header:"",frontend_theme_color:"",frontend_background_url:""};function jm(){const{data:s}=se({queryKey:["settings","frontend"],queryFn:()=>us("frontend")}),n=ce({resolver:ue(pm),defaultValues:gm,mode:"onChange"});m.useEffect(()=>{if(s?.data?.frontend){const l=s?.data?.frontend;Object.entries(l).forEach(([r,i])=>{n.setValue(r,i)})}},[s]);function a(l){xs(l).then(({data:r})=>{r&&q.success("更新成功")})}return e.jsx(xe,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(a),className:"space-y-8",children:[e.jsx(j,{control:n.control,name:"frontend_theme_sidebar",render:({field:l})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:"边栏风格"}),e.jsx(F,{children:"边栏风格"})]}),e.jsx(N,{children:e.jsx(H,{checked:l.value,onCheckedChange:l.onChange})})]})}),e.jsx(j,{control:n.control,name:"frontend_theme_header",render:({field:l})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:"头部风格"}),e.jsx(F,{children:"边栏风格"})]}),e.jsx(N,{children:e.jsx(H,{checked:l.value,onCheckedChange:l.onChange})})]})}),e.jsx(j,{control:n.control,name:"frontend_theme_color",render:({field:l})=>e.jsxs(g,{children:[e.jsx(v,{children:"主题色"}),e.jsxs("div",{className:"relative w-max",children:[e.jsx(N,{children:e.jsxs("select",{className:y(Ks({variant:"outline"}),"w-[200px] appearance-none font-normal"),...l,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(aa,{className:"absolute right-3 top-2.5 h-4 w-4 opacity-50"})]}),e.jsx(F,{children:"主题色"}),e.jsx(P,{})]})}),e.jsx(j,{control:n.control,name:"frontend_background_url",render:({field:l})=>e.jsxs(g,{children:[e.jsx(v,{children:"背景"}),e.jsx(N,{children:e.jsx(T,{placeholder:"请输入图片地址",...l})}),e.jsx(F,{children:"将会在后台登录页面进行展示。"}),e.jsx(P,{})]})}),e.jsx(E,{type:"submit",children:"保存设置"})]})})}function vm(){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(be,{}),e.jsx(jm,{})]})}const bm=Object.freeze(Object.defineProperty({__proto__:null,default:vm},Symbol.toStringTag,{value:"Module"})),ym=h.object({server_pull_interval:h.coerce.number().nullable(),server_push_interval:h.coerce.number().nullable(),server_token:h.string().nullable(),device_limit_mode:h.coerce.number().nullable()}),Nm={server_pull_interval:0,server_push_interval:0,server_token:"",device_limit_mode:0};function _m(){const{t:s}=I("settings"),[n,a]=m.useState(!1),l=m.useRef(null),r=ce({resolver:ue(ym),defaultValues:Nm,mode:"onBlur"}),{data:i}=se({queryKey:["settings","server"],queryFn:()=>us("server")}),{mutateAsync:c}=es({mutationFn:xs,onSuccess:d=>{d.data&&q.success(s("common.AutoSaved"))}});m.useEffect(()=>{if(i?.data.server){const d=i.data.server;Object.entries(d).forEach(([p,k])=>{r.setValue(p,k)}),l.current=d}},[i]);const u=m.useCallback(pe.debounce(async d=>{if(!pe.isEqual(d,l.current)){a(!0);try{await c(d),l.current=d}finally{a(!1)}}},1e3),[c]),x=m.useCallback(d=>{u(d)},[u]);m.useEffect(()=>{const d=r.watch(p=>{x(p)});return()=>d.unsubscribe()},[r.watch,x]);const o=()=>{const d=Math.floor(Math.random()*17)+16,p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let k="";for(let V=0;Ve.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("server.server_token.title")}),e.jsx(N,{children:e.jsxs("div",{className:"relative",children:[e.jsx(T,{placeholder:s("server.server_token.placeholder"),...d,value:d.value||"",className:"pr-10"}),e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{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:p=>{p.preventDefault(),o()},children:e.jsx(Xo,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(te,{children:e.jsx("p",{children:s("server.server_token.generate_tooltip")})})]})})]})}),e.jsx(F,{children:s("server.server_token.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"server_pull_interval",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("server.server_pull_interval.title")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("server.server_pull_interval.placeholder"),...d,value:d.value||"",onChange:p=>{const k=p.target.value?Number(p.target.value):null;d.onChange(k)}})}),e.jsx(F,{children:s("server.server_pull_interval.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"server_push_interval",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("server.server_push_interval.title")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("server.server_push_interval.placeholder"),...d,value:d.value||"",onChange:p=>{const k=p.target.value?Number(p.target.value):null;d.onChange(k)}})}),e.jsx(F,{children:s("server.server_push_interval.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"device_limit_mode",render:({field:d})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("server.device_limit_mode.title")}),e.jsxs(W,{onValueChange:d.onChange,value:d.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:s("server.device_limit_mode.placeholder")})})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("server.device_limit_mode.strict")}),e.jsx($,{value:"1",children:s("server.device_limit_mode.relaxed")})]})]}),e.jsx(F,{children:s("server.device_limit_mode.description")}),e.jsx(P,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("server.saving")})]})})}function wm(){const{t:s}=I("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(be,{}),e.jsx(_m,{})]})}const Cm=Object.freeze(Object.defineProperty({__proto__:null,default:wm},Symbol.toStringTag,{value:"Module"}));function Sm({open:s,onOpenChange:n,result:a}){const l=!a.error;return e.jsx(ge,{open:s,onOpenChange:n,children:e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l?e.jsx(Dn,{className:"h-5 w-5 text-green-500"}):e.jsx(Tn,{className:"h-5 w-5 text-destructive"}),e.jsx(je,{children:l?"邮件发送成功":"邮件发送失败"})]}),e.jsx(Te,{children:l?"测试邮件已成功发送,请检查收件箱":"发送测试邮件时遇到错误"})]}),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:a.email}),e.jsx("div",{className:"text-muted-foreground",children:"邮件主题"}),e.jsx("div",{children:a.subject}),e.jsx("div",{className:"text-muted-foreground",children:"模板名称"}),e.jsx("div",{children:a.template_name})]})]}),a.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:a.error})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"配置信息"}),e.jsx(rt,{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:a.config.driver}),e.jsx("div",{className:"text-muted-foreground",children:"服务器"}),e.jsx("div",{children:a.config.host}),e.jsx("div",{className:"text-muted-foreground",children:"端口"}),e.jsx("div",{children:a.config.port}),e.jsx("div",{className:"text-muted-foreground",children:"加密方式"}),e.jsx("div",{children:a.config.encryption||"无"}),e.jsx("div",{className:"text-muted-foreground",children:"发件人"}),e.jsx("div",{children:a.config.from.address?`${a.config.from.address}${a.config.from.name?` (${a.config.from.name})`:""}`:"未设置"}),e.jsx("div",{className:"text-muted-foreground",children:"用户名"}),e.jsx("div",{children:a.config.username||"未设置"})]})})})]})]})]})})}const km=h.object({email_template:h.string().nullable().default("classic"),email_host:h.string().nullable().default(""),email_port:h.coerce.number().nullable().default(465),email_username:h.string().nullable().default(""),email_password:h.string().nullable().default(""),email_encryption:h.string().nullable().default(""),email_from_address:h.string().email().nullable().default(""),remind_mail_enable:h.boolean().nullable().default(!1)});function Dm(){const{t:s}=I("settings"),[n,a]=m.useState(null),[l,r]=m.useState(!1),i=m.useRef(null),[c,u]=m.useState(!1),x=ce({resolver:ue(km),defaultValues:{},mode:"onBlur"}),{data:o}=se({queryKey:["settings","email"],queryFn:()=>us("email")}),{data:d}=se({queryKey:["emailTemplate"],queryFn:()=>Sd()}),{mutateAsync:p}=es({mutationFn:xs,onSuccess:D=>{D.data&&q.success(s("common.autoSaved"))}}),{mutate:k,isPending:V}=es({mutationFn:kd,onMutate:()=>{a(null),r(!1)},onSuccess:D=>{a(D.data),r(!0),D.data.error?q.error(s("email.test.error")):q.success(s("email.test.success"))}});m.useEffect(()=>{if(o?.data.email){const D=o.data.email;Object.entries(D).forEach(([b,w])=>{x.setValue(b,w)}),i.current=D}},[o]);const f=m.useCallback(pe.debounce(async D=>{if(!pe.isEqual(D,i.current)){u(!0);try{await p(D),i.current=D}finally{u(!1)}}},1e3),[p]),_=m.useCallback(D=>{f(D)},[f]);return m.useEffect(()=>{const D=x.watch(b=>{_(b)});return()=>D.unsubscribe()},[x.watch,_]),e.jsxs(e.Fragment,{children:[e.jsx(xe,{...x,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:x.control,name:"email_host",render:({field:D})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("email.email_host.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...D,value:D.value||""})}),e.jsx(F,{children:s("email.email_host.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"email_port",render:({field:D})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("email.email_port.title")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("common.placeholder"),...D,value:D.value||"",onChange:b=>{const w=b.target.value?Number(b.target.value):null;D.onChange(w)}})}),e.jsx(F,{children:s("email.email_port.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"email_encryption",render:({field:D})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("email.email_encryption.title")}),e.jsxs(W,{onValueChange:D.onChange,value:D.value||"none",children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:"请选择加密方式"})})}),e.jsxs(G,{children:[e.jsx($,{value:"none",children:s("email.email_encryption.none")}),e.jsx($,{value:"ssl",children:s("email.email_encryption.ssl")}),e.jsx($,{value:"tls",children:s("email.email_encryption.tls")})]})]}),e.jsx(F,{children:s("email.email_encryption.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"email_username",render:({field:D})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("email.email_username.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...D,value:D.value||""})}),e.jsx(F,{children:s("email.email_username.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"email_password",render:({field:D})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("email.email_password.title")}),e.jsx(N,{children:e.jsx(T,{type:"password",placeholder:s("common.placeholder"),...D,value:D.value||""})}),e.jsx(F,{children:s("email.email_password.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"email_from_address",render:({field:D})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("email.email_from.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...D,value:D.value||""})}),e.jsx(F,{children:s("email.email_from.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"email_template",render:({field:D})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("email.email_template.title")}),e.jsxs(W,{onValueChange:b=>{D.onChange(b),_(x.getValues())},value:D.value||void 0,children:[e.jsx(N,{children:e.jsx(B,{className:"w-[200px]",children:e.jsx(Y,{placeholder:s("email.email_template.placeholder")})})}),e.jsx(G,{children:d?.data?.map(b=>e.jsx($,{value:b,children:b},b))})]}),e.jsx(F,{children:s("email.email_template.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"remind_mail_enable",render:({field:D})=>e.jsxs(g,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("email.remind_mail.title")}),e.jsx(F,{children:s("email.remind_mail.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:D.value||!1,onCheckedChange:b=>{D.onChange(b),_(x.getValues())}})})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(E,{onClick:()=>k(),loading:V,disabled:V,children:s(V?"test.sending":"test.title")})})]})}),c&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("saving")}),n&&e.jsx(Sm,{open:l,onOpenChange:r,result:n})]})}function Tm(){const{t:s}=I("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(be,{}),e.jsx(Dm,{})]})}const Pm=Object.freeze(Object.defineProperty({__proto__:null,default:Tm},Symbol.toStringTag,{value:"Module"})),Rm=h.object({telegram_bot_enable:h.boolean().nullable(),telegram_bot_token:h.string().nullable(),telegram_discuss_link:h.string().nullable()}),Em={telegram_bot_enable:!1,telegram_bot_token:"",telegram_discuss_link:""};function Vm(){const{t:s}=I("settings"),[n,a]=m.useState(!1),l=m.useRef(null),r=ce({resolver:ue(Rm),defaultValues:Em,mode:"onBlur"}),{data:i}=se({queryKey:["settings","telegram"],queryFn:()=>us("telegram")}),{mutateAsync:c}=es({mutationFn:xs,onSuccess:p=>{p.data&&q.success(s("common.autoSaved"))}}),{mutate:u,isPending:x}=es({mutationFn:Dd,onSuccess:p=>{p.data&&q.success(s("telegram.webhook_success"))}});m.useEffect(()=>{if(i?.data.telegram){const p=i.data.telegram;Object.entries(p).forEach(([k,V])=>{r.setValue(k,V)}),l.current=p}},[i]);const o=m.useCallback(pe.debounce(async p=>{if(!pe.isEqual(p,l.current)){a(!0);try{await c(p),l.current=p}finally{a(!1)}}},1e3),[c]),d=m.useCallback(p=>{o(p)},[o]);return m.useEffect(()=>{const p=r.watch(k=>{d(k)});return()=>p.unsubscribe()},[r.watch,d]),e.jsx(xe,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:r.control,name:"telegram_bot_token",render:({field:p})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("telegram.bot_token.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("telegram.bot_token.placeholder"),...p,value:p.value||""})}),e.jsx(F,{children:s("telegram.bot_token.description")}),e.jsx(P,{})]})}),r.watch("telegram_bot_token")&&e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("telegram.webhook.title")}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(E,{loading:x,disabled:x,onClick:()=>u(),children:s(x?"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(P,{})]}),e.jsx(j,{control:r.control,name:"telegram_bot_enable",render:({field:p})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("telegram.bot_enable.title")}),e.jsx(F,{children:s("telegram.bot_enable.description")}),e.jsx(N,{children:e.jsx(H,{checked:p.value||!1,onCheckedChange:k=>{p.onChange(k),d(r.getValues())}})}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"telegram_discuss_link",render:({field:p})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("telegram.discuss_link.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("telegram.discuss_link.placeholder"),...p,value:p.value||""})}),e.jsx(F,{children:s("telegram.discuss_link.description")}),e.jsx(P,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Im(){const{t:s}=I("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(be,{}),e.jsx(Vm,{})]})}const Fm=Object.freeze(Object.defineProperty({__proto__:null,default:Im},Symbol.toStringTag,{value:"Module"})),Mm=h.object({windows_version:h.string().nullable(),windows_download_url:h.string().nullable(),macos_version:h.string().nullable(),macos_download_url:h.string().nullable(),android_version:h.string().nullable(),android_download_url:h.string().nullable()}),Om={windows_version:"",windows_download_url:"",macos_version:"",macos_download_url:"",android_version:"",android_download_url:""};function zm(){const{t:s}=I("settings"),[n,a]=m.useState(!1),l=m.useRef(null),r=ce({resolver:ue(Mm),defaultValues:Om,mode:"onBlur"}),{data:i}=se({queryKey:["settings","app"],queryFn:()=>us("app")}),{mutateAsync:c}=es({mutationFn:xs,onSuccess:o=>{o.data&&q.success(s("app.save_success"))}});m.useEffect(()=>{if(i?.data.app){const o=i.data.app;Object.entries(o).forEach(([d,p])=>{r.setValue(d,p)}),l.current=o}},[i]);const u=m.useCallback(pe.debounce(async o=>{if(!pe.isEqual(o,l.current)){a(!0);try{await c(o),l.current=o}finally{a(!1)}}},1e3),[c]),x=m.useCallback(o=>{u(o)},[u]);return m.useEffect(()=>{const o=r.watch(d=>{x(d)});return()=>o.unsubscribe()},[r.watch,x]),e.jsx(xe,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:r.control,name:"windows_version",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("app.windows.version.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.windows.version.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"windows_download_url",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("app.windows.download.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.windows.download.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"macos_version",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("app.macos.version.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.macos.version.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"macos_download_url",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("app.macos.download.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.macos.download.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"android_version",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("app.android.version.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.android.version.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"android_download_url",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{className:"text-base",children:s("app.android.download.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.android.download.description")}),e.jsx(P,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Lm(){const{t:s}=I("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(be,{}),e.jsx(zm,{})]})}const Am=Object.freeze(Object.defineProperty({__proto__:null,default:Lm},Symbol.toStringTag,{value:"Module"})),ca=m.forwardRef(({className:s,...n},a)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:a,className:y("w-full caption-bottom text-sm",s),...n})}));ca.displayName="Table";const da=m.forwardRef(({className:s,...n},a)=>e.jsx("thead",{ref:a,className:y("[&_tr]:border-b",s),...n}));da.displayName="TableHeader";const ma=m.forwardRef(({className:s,...n},a)=>e.jsx("tbody",{ref:a,className:y("[&_tr:last-child]:border-0",s),...n}));ma.displayName="TableBody";const $m=m.forwardRef(({className:s,...n},a)=>e.jsx("tfoot",{ref:a,className:y("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...n}));$m.displayName="TableFooter";const vs=m.forwardRef(({className:s,...n},a)=>e.jsx("tr",{ref:a,className:y("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...n}));vs.displayName="TableRow";const ua=m.forwardRef(({className:s,...n},a)=>e.jsx("th",{ref:a,className:y("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}));ua.displayName="TableHead";const $s=m.forwardRef(({className:s,...n},a)=>e.jsx("td",{ref:a,className:y("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));$s.displayName="TableCell";const qm=m.forwardRef(({className:s,...n},a)=>e.jsx("caption",{ref:a,className:y("mt-4 text-sm text-muted-foreground",s),...n}));qm.displayName="TableCaption";function Km({table:s}){const[n,a]=m.useState(""),{t:l}=I("common");m.useEffect(()=>{a((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const r=i=>{const c=parseInt(i);!isNaN(c)&&c>=1&&c<=s.getPageCount()?s.setPageIndex(c-1):a((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:l("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:l("table.pagination.itemsPerPage")}),e.jsxs(W,{value:`${s.getState().pagination.pageSize}`,onValueChange:i=>{s.setPageSize(Number(i))},children:[e.jsx(B,{className:"h-8 w-[70px]",children:e.jsx(Y,{placeholder:s.getState().pagination.pageSize})}),e.jsx(G,{side:"top",children:[10,20,30,40,50,100,500].map(i=>e.jsx($,{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:l("table.pagination.page")}),e.jsx(T,{type:"text",value:n,onChange:i=>a(i.target.value),onBlur:i=>r(i.target.value),onKeyDown:i=>{i.key==="Enter"&&r(i.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsx("span",{children:l("table.pagination.pageOf",{total:s.getPageCount()})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(E,{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:l("table.pagination.firstPage")}),e.jsx(ei,{className:"h-4 w-4"})]}),e.jsxs(E,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.previousPage")}),e.jsx(_n,{className:"h-4 w-4"})]}),e.jsxs(E,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.nextPage")}),e.jsx(ta,{className:"h-4 w-4"})]}),e.jsxs(E,{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:l("table.pagination.lastPage")}),e.jsx(si,{className:"h-4 w-4"})]})]})]})]})}function Ye({table:s,toolbar:n,draggable:a=!1,onDragStart:l,onDragEnd:r,onDragOver:i,onDragLeave:c,onDrop:u,showPagination:x=!0,isLoading:o=!1}){const{t:d}=I("common"),p=m.useRef(null),k=s.getAllColumns().filter(D=>D.getIsPinned()==="left"),V=s.getAllColumns().filter(D=>D.getIsPinned()==="right"),f=D=>k.slice(0,D).reduce((b,w)=>b+(w.getSize()??0),0),_=D=>V.slice(D+1).reduce((b,w)=>b+(w.getSize()??0),0);return e.jsxs("div",{className:"space-y-4",children:[typeof n=="function"?n(s):n,e.jsx("div",{ref:p,className:"relative overflow-auto rounded-md border bg-card",children:e.jsx("div",{className:"overflow-auto",children:e.jsxs(ca,{children:[e.jsx(da,{children:s.getHeaderGroups().map(D=>e.jsx(vs,{className:"hover:bg-transparent",children:D.headers.map((b,w)=>{const S=b.column.getIsPinned()==="left",C=b.column.getIsPinned()==="right",R=S?f(k.indexOf(b.column)):void 0,z=C?_(V.indexOf(b.column)):void 0;return e.jsx(ua,{colSpan:b.colSpan,style:{width:b.getSize(),...S&&{left:R},...C&&{right:z}},className:y("h-11 bg-card px-4 text-muted-foreground",(S||C)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",S&&"before:right-0",C&&"before:left-0"]),children:b.isPlaceholder?null:bt(b.column.columnDef.header,b.getContext())},b.id)})},D.id))}),e.jsx(ma,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((D,b)=>e.jsx(vs,{"data-state":D.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:a,onDragStart:w=>l?.(w,b),onDragEnd:r,onDragOver:i,onDragLeave:c,onDrop:w=>u?.(w,b),children:D.getVisibleCells().map((w,S)=>{const C=w.column.getIsPinned()==="left",R=w.column.getIsPinned()==="right",z=C?f(k.indexOf(w.column)):void 0,Q=R?_(V.indexOf(w.column)):void 0;return e.jsx($s,{style:{width:w.column.getSize(),...C&&{left:z},...R&&{right:Q}},className:y("bg-card",(C||R)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",C&&"before:right-0",R&&"before:left-0"]),children:bt(w.column.columnDef.cell,w.getContext())},w.id)})},D.id)):e.jsx(vs,{children:e.jsx($s,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:d("table.noData")})})})]})})}),x&&e.jsx(Km,{table:s})]})}const Hm=s=>h.object({id:h.number().nullable(),name:h.string().min(2,s("form.validation.name.min")).max(30,s("form.validation.name.max")),icon:h.string().optional().nullable(),notify_domain:h.string().refine(a=>!a||/^https?:\/\/\S+/.test(a),s("form.validation.notify_domain.url")).optional().nullable(),handling_fee_fixed:h.coerce.number().min(0).optional().nullable(),handling_fee_percent:h.coerce.number().min(0).max(100).optional().nullable(),payment:h.string().min(1,s("form.validation.payment.required")),config:h.record(h.string(),h.string())}),Oa={id:null,name:"",icon:"",notify_domain:"",handling_fee_fixed:0,handling_fee_percent:0,payment:"",config:{}};function vr({refetch:s,dialogTrigger:n,type:a="add",defaultFormValues:l=Oa}){const{t:r}=I("payment"),[i,c]=m.useState(!1),[u,x]=m.useState(!1),[o,d]=m.useState([]),[p,k]=m.useState([]),V=Hm(r),f=ce({resolver:ue(V),defaultValues:l,mode:"onChange"}),_=f.watch("payment");m.useEffect(()=>{i&&(async()=>{const{data:w}=await Hc();d(w)})()},[i]),m.useEffect(()=>{if(!_||!i)return;(async()=>{const w={payment:_,...a==="edit"&&{id:Number(f.getValues("id"))}};Uc(w).then(({data:S})=>{k(S);const C=S.reduce((R,z)=>(z.field_name&&(R[z.field_name]=z.value??""),R),{});f.setValue("config",C)})})()},[_,i,f,a]);const D=async b=>{x(!0);try{(await Bc(b)).data&&(q.success(r("form.messages.success")),f.reset(Oa),s(),c(!1))}finally{x(!1)}};return e.jsxs(ge,{open:i,onOpenChange:c,children:[e.jsx(Fe,{asChild:!0,children:n||e.jsxs(E,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add.button")})]})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsx(ve,{children:e.jsx(je,{children:r(a==="add"?"form.add.title":"form.edit.title")})}),e.jsx(xe,{...f,children:e.jsxs("form",{onSubmit:f.handleSubmit(D),className:"space-y-4",children:[e.jsx(j,{control:f.control,name:"name",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("form.fields.name.placeholder"),...b})}),e.jsx(F,{children:r("form.fields.name.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:f.control,name:"icon",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.icon.label")}),e.jsx(N,{children:e.jsx(T,{...b,value:b.value||"",placeholder:r("form.fields.icon.placeholder")})}),e.jsx(F,{children:r("form.fields.icon.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:f.control,name:"notify_domain",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.notify_domain.label")}),e.jsx(N,{children:e.jsx(T,{...b,value:b.value||"",placeholder:r("form.fields.notify_domain.placeholder")})}),e.jsx(F,{children:r("form.fields.notify_domain.description")}),e.jsx(P,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:f.control,name:"handling_fee_percent",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.handling_fee_percent.label")}),e.jsx(N,{children:e.jsx(T,{type:"number",...b,value:b.value||"",placeholder:r("form.fields.handling_fee_percent.placeholder")})}),e.jsx(P,{})]})}),e.jsx(j,{control:f.control,name:"handling_fee_fixed",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.handling_fee_fixed.label")}),e.jsx(N,{children:e.jsx(T,{type:"number",...b,value:b.value||"",placeholder:r("form.fields.handling_fee_fixed.placeholder")})}),e.jsx(P,{})]})})]}),e.jsx(j,{control:f.control,name:"payment",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.payment.label")}),e.jsxs(W,{onValueChange:b.onChange,defaultValue:b.value,children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:r("form.fields.payment.placeholder")})})}),e.jsx(G,{children:o.map(w=>e.jsx($,{value:w,children:w},w))})]}),e.jsx(F,{children:r("form.fields.payment.description")}),e.jsx(P,{})]})}),p.length>0&&e.jsx("div",{className:"space-y-4",children:p.map(b=>e.jsx(j,{control:f.control,name:`config.${b.field_name}`,render:({field:w})=>e.jsxs(g,{children:[e.jsx(v,{children:b.label}),e.jsx(N,{children:e.jsx(T,{...w,value:w.value||""})}),e.jsx(P,{})]})},b.field_name))}),e.jsxs(Me,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(E,{type:"button",variant:"outline",children:r("form.buttons.cancel")})}),e.jsx(E,{type:"submit",disabled:u,children:r("form.buttons.submit")})]})]})})]})]})}function M({column:s,title:n,tooltip:a,className:l}){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(E,{variant:"ghost",size:"default",className:y("-ml-3 flex h-8 items-center gap-2 text-nowrap font-medium hover:bg-muted/60",l),onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[e.jsx("span",{children:n}),a&&e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(ka,{className:"h-4 w-4 cursor-pointer text-muted-foreground"})}),e.jsx(te,{children:a})]})}),s.getIsSorted()==="asc"?e.jsx(Ut,{className:"h-4 w-4 text-foreground/70"}):s.getIsSorted()==="desc"?e.jsx(Bt,{className:"h-4 w-4 text-foreground/70"}):e.jsx(ti,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-foreground/70"})]})})}):e.jsxs("div",{className:y("flex items-center space-x-1 text-nowrap py-2 font-medium text-muted-foreground",l),children:[e.jsx("span",{children:n}),a&&e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsx(ka,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(te,{children:a})]})})]})}const Um=ai,Bm=ni,Gm=ri,br=m.forwardRef(({className:s,...n},a)=>e.jsx(En,{className:y("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:a}));br.displayName=En.displayName;const yr=m.forwardRef(({className:s,...n},a)=>e.jsxs(Gm,{children:[e.jsx(br,{}),e.jsx(Vn,{ref:a,className:y("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})]}));yr.displayName=Vn.displayName;const Nr=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col space-y-2 text-center sm:text-left",s),...n});Nr.displayName="AlertDialogHeader";const _r=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});_r.displayName="AlertDialogFooter";const wr=m.forwardRef(({className:s,...n},a)=>e.jsx(In,{ref:a,className:y("text-lg font-semibold",s),...n}));wr.displayName=In.displayName;const Cr=m.forwardRef(({className:s,...n},a)=>e.jsx(Fn,{ref:a,className:y("text-sm text-muted-foreground",s),...n}));Cr.displayName=Fn.displayName;const Sr=m.forwardRef(({className:s,...n},a)=>e.jsx(Mn,{ref:a,className:y(qs(),s),...n}));Sr.displayName=Mn.displayName;const kr=m.forwardRef(({className:s,...n},a)=>e.jsx(On,{ref:a,className:y(qs({variant:"outline"}),"mt-2 sm:mt-0",s),...n}));kr.displayName=On.displayName;function Je({onConfirm:s,children:n,title:a="确认操作",description:l="确定要执行此操作吗?",cancelText:r="取消",confirmText:i="确认",variant:c="default",className:u}){return e.jsxs(Um,{children:[e.jsx(Bm,{asChild:!0,children:n}),e.jsxs(yr,{className:y("sm:max-w-[425px]",u),children:[e.jsxs(Nr,{children:[e.jsx(wr,{children:a}),e.jsx(Cr,{children:l})]}),e.jsxs(_r,{children:[e.jsx(kr,{asChild:!0,children:e.jsx(E,{variant:"outline",children:r})}),e.jsx(Sr,{asChild:!0,children:e.jsx(E,{variant:c,onClick:s,children:i})})]})]})]})}const Dr=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"})}),Wm=({refetch:s,isSortMode:n=!1})=>{const{t:a}=I("payment");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(Pt,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:l})=>e.jsx(M,{column:l,title:a("table.columns.id")}),cell:({row:l})=>e.jsx(K,{variant:"outline",children:l.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"enable",header:({column:l})=>e.jsx(M,{column:l,title:a("table.columns.enable")}),cell:({row:l})=>e.jsx(H,{defaultChecked:l.getValue("enable"),onCheckedChange:async()=>{const{data:r}=await Wc({id:l.original.id});r||s()}}),enableSorting:!1,size:100},{accessorKey:"name",header:({column:l})=>e.jsx(M,{column:l,title:a("table.columns.name")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:l.getValue("name")})}),enableSorting:!1,size:200},{accessorKey:"payment",header:({column:l})=>e.jsx(M,{column:l,title:a("table.columns.payment")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:l.getValue("payment")})}),enableSorting:!1,size:200},{accessorKey:"notify_url",header:({column:l})=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(M,{column:l,title:a("table.columns.notify_url")}),e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{className:"ml-1",children:e.jsx(Dr,{className:"h-4 w-4"})}),e.jsx(te,{children:a("table.columns.notify_url_tooltip")})]})})]}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[300px] truncate font-medium",children:l.getValue("notify_url")})}),enableSorting:!1,size:3e3},{id:"actions",header:({column:l})=>e.jsx(M,{className:"justify-end",column:l,title:a("table.columns.actions")}),cell:({row:l})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(vr,{refetch:s,dialogTrigger:e.jsxs(E,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Es,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("table.actions.edit")})]}),type:"edit",defaultFormValues:l.original}),e.jsx(Je,{title:a("table.actions.delete.title"),description:a("table.actions.delete.description"),onConfirm:async()=>{const{data:r}=await Gc({id:l.original.id});r&&s()},children:e.jsxs(E,{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:a("table.actions.delete.title")})]})})]}),size:100}]};function Ym({table:s,refetch:n,saveOrder:a,isSortMode:l}){const{t:r}=I("payment"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between",children:[l?e.jsx("p",{className:"text-sm text-muted-foreground",children:r("table.toolbar.sort.hint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vr,{refetch:n}),e.jsx(T,{placeholder:r("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:c=>s.getColumn("name")?.setFilterValue(c.target.value),className:"h-8 w-[250px]"}),i&&e.jsxs(E,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[r("table.toolbar.reset"),e.jsx(Oe,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(E,{variant:l?"default":"outline",onClick:a,size:"sm",children:r(l?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}function Jm(){const[s,n]=m.useState([]),[a,l]=m.useState([]),[r,i]=m.useState(!1),[c,u]=m.useState([]),[x,o]=m.useState({"drag-handle":!1}),[d,p]=m.useState({pageSize:20,pageIndex:0}),{refetch:k}=se({queryKey:["paymentList"],queryFn:async()=>{const{data:b}=await Kc();return u(b?.map(w=>({...w,enable:!!w.enable}))||[]),b}});m.useEffect(()=>{o({"drag-handle":r,actions:!r}),p({pageSize:r?99999:10,pageIndex:0})},[r]);const V=(b,w)=>{r&&(b.dataTransfer.setData("text/plain",w.toString()),b.currentTarget.classList.add("opacity-50"))},f=(b,w)=>{if(!r)return;b.preventDefault(),b.currentTarget.classList.remove("bg-muted");const S=parseInt(b.dataTransfer.getData("text/plain"));if(S===w)return;const C=[...c],[R]=C.splice(S,1);C.splice(w,0,R),u(C)},_=async()=>{r?Yc({ids:c.map(b=>b.id)}).then(()=>{k(),i(!1),q.success("排序保存成功")}):i(!0)},D=ze({data:c,columns:Wm({refetch:k,isSortMode:r}),state:{sorting:a,columnFilters:s,columnVisibility:x,pagination:d},onSortingChange:l,onColumnFiltersChange:n,onColumnVisibilityChange:o,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),getSortedRowModel:Ge(),initialState:{columnPinning:{right:["actions"]}},pageCount:r?1:void 0});return e.jsx(Ye,{table:D,toolbar:b=>e.jsx(Ym,{table:b,refetch:k,saveOrder:_,isSortMode:r}),draggable:r,onDragStart:V,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:f,showPagination:!r})}function Qm(){const{t:s}=I("payment");return e.jsxs(we,{children:[e.jsxs(Ce,{className:"flex items-center justify-between",children:[e.jsx(Pe,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(Jm,{})})]})]})}const Zm=Object.freeze(Object.defineProperty({__proto__:null,default:Qm},Symbol.toStringTag,{value:"Module"})),Xm=(s,n)=>{let a=null;switch(s.field_type){case"input":a=e.jsx(T,{placeholder:s.placeholder,...n});break;case"textarea":a=e.jsx(Cs,{placeholder:s.placeholder,...n});break;case"select":a=e.jsx("select",{className:y(qs({variant:"outline"}),"w-full appearance-none font-normal"),...n,children:s.select_options&&Object.keys(s.select_options).map(l=>e.jsx("option",{value:l,children:s.select_options?.[l]},l))});break;default:a=null;break}return a};function eu({themeKey:s,themeInfo:n}){const{t:a}=I("theme"),[l,r]=m.useState(!1),[i,c]=m.useState(!1),[u,x]=m.useState(!1),o=ce({defaultValues:n.configs.reduce((k,V)=>(k[V.field_name]="",k),{})}),d=async()=>{c(!0),Tc(s).then(({data:k})=>{Object.entries(k).forEach(([V,f])=>{o.setValue(V,f)})}).finally(()=>{c(!1)})},p=async k=>{x(!0),Pc(s,k).then(()=>{q.success(a("config.success")),r(!1)}).finally(()=>{x(!1)})};return e.jsxs(ge,{open:l,onOpenChange:k=>{r(k),k?d():o.reset()},children:[e.jsx(Fe,{asChild:!0,children:e.jsx(E,{variant:"outline",children:a("card.configureTheme")})}),e.jsxs(he,{className:"max-h-[90vh] overflow-auto sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:a("config.title",{name:n.name})}),e.jsx(Te,{children:a("config.description")})]}),i?e.jsx("div",{className:"flex h-40 items-center justify-center",children:e.jsx(na,{className:"h-6 w-6 animate-spin"})}):e.jsx(xe,{...o,children:e.jsxs("form",{onSubmit:o.handleSubmit(p),className:"space-y-4",children:[n.configs.map(k=>e.jsx(j,{control:o.control,name:k.field_name,render:({field:V})=>e.jsxs(g,{children:[e.jsx(v,{children:k.label}),e.jsx(N,{children:Xm(k,V)}),e.jsx(P,{})]})},k.field_name)),e.jsxs(Me,{className:"mt-6 gap-2",children:[e.jsx(E,{type:"button",variant:"secondary",onClick:()=>r(!1),children:a("config.cancel")}),e.jsx(E,{type:"submit",loading:u,children:a("config.save")})]})]})})]})]})}function su(){const{t:s}=I("theme"),[n,a]=m.useState(null),[l,r]=m.useState(!1),[i,c]=m.useState(!1),[u,x]=m.useState(!1),[o,d]=m.useState(null),p=m.useRef(null),[k,V]=m.useState(0),{data:f,isLoading:_,refetch:D}=se({queryKey:["themeList"],queryFn:async()=>{const{data:A}=await Dc();return A}}),b=async A=>{a(A),Vc({frontend_theme:A}).then(()=>{q.success("主题切换成功"),D()}).finally(()=>{a(null)})},w=async A=>{if(!A.name.endsWith(".zip")){q.error(s("upload.error.format"));return}r(!0),Rc(A).then(()=>{q.success("主题上传成功"),c(!1),D()}).finally(()=>{r(!1),p.current&&(p.current.value="")})},S=A=>{A.preventDefault(),A.stopPropagation(),A.type==="dragenter"||A.type==="dragover"?x(!0):A.type==="dragleave"&&x(!1)},C=A=>{A.preventDefault(),A.stopPropagation(),x(!1),A.dataTransfer.files&&A.dataTransfer.files[0]&&w(A.dataTransfer.files[0])},R=()=>{o&&V(A=>A===0?o.images.length-1:A-1)},z=()=>{o&&V(A=>A===o.images.length-1?0:A+1)},Q=(A,X)=>{V(0),d({name:A,images:X})};return e.jsxs(we,{children:[e.jsxs(Ce,{className:"flex items-center justify-between",children:[e.jsx(Pe,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(E,{onClick:()=>c(!0),variant:"outline",className:"ml-4 shrink-0",size:"sm",children:[e.jsx(Ht,{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:_?e.jsxs(e.Fragment,{children:[e.jsx(za,{}),e.jsx(za,{})]}):f?.themes&&Object.entries(f.themes).map(([A,X])=>e.jsx(He,{className:"group relative overflow-hidden transition-all hover:shadow-md",style:{backgroundImage:X.background_url?`url(${X.background_url})`:"none",backgroundSize:"cover",backgroundPosition:"center"},children:e.jsxs("div",{className:y("relative z-10 h-full transition-colors",X.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:[!!X.can_delete&&e.jsx("div",{className:"absolute right-2 top-2",children:e.jsx(Je,{title:s("card.delete.title"),description:s("card.delete.description"),confirmText:s("card.delete.button"),variant:"destructive",onConfirm:async()=>{if(A===f?.active){q.error(s("card.delete.error.active"));return}a(A),Ec(A).then(()=>{q.success("主题删除成功"),D()}).finally(()=>{a(null)})},children:e.jsx(E,{disabled:n===A,loading:n===A,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(ss,{children:[e.jsx(bs,{children:X.name}),e.jsx(tt,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{children:X.description}),X.version&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("card.version",{version:X.version})})]})})]}),e.jsxs(ts,{className:"flex items-center justify-end space-x-3",children:[X.images&&Array.isArray(X.images)&&X.images.length>0&&e.jsx(E,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>Q(X.name,X.images),children:e.jsx(li,{className:"h-4 w-4"})}),e.jsx(eu,{themeKey:A,themeInfo:X}),e.jsx(E,{onClick:()=>b(A),disabled:n===A||A===f.active,loading:n===A,variant:A===f.active?"secondary":"default",children:A===f.active?s("card.currentTheme"):s("card.activateTheme")})]})]})},A))}),e.jsx(ge,{open:i,onOpenChange:c,children:e.jsxs(he,{className:"sm:max-w-md",children:[e.jsxs(ve,{children:[e.jsx(je,{children:s("upload.title")}),e.jsx(Te,{children:s("upload.description")})]}),e.jsxs("div",{className:y("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",u&&"border-primary/50 bg-muted/50"),onDragEnter:S,onDragLeave:S,onDragOver:S,onDrop:C,children:[e.jsx("input",{type:"file",ref:p,className:"hidden",accept:".zip",onChange:A=>{const X=A.target.files?.[0];X&&w(X)}}),l?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(Ht,{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:()=>p.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(ge,{open:!!o,onOpenChange:A=>{A||(d(null),V(0))},children:e.jsxs(he,{className:"max-w-4xl",children:[e.jsxs(ve,{children:[e.jsxs(je,{children:[o?.name," ",s("preview.title")]}),e.jsx(Te,{className:"text-center",children:o&&s("preview.imageCount",{current:k+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[k]&&e.jsx("img",{src:o.images[k],alt:`${o.name} 预览图 ${k+1}`,className:"h-full w-full object-contain"})}),o&&o.images.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(E,{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:R,children:e.jsx(oi,{className:"h-4 w-4"})}),e.jsx(E,{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:z,children:e.jsx(ii,{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((A,X)=>e.jsx("button",{onClick:()=>V(X),className:y("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2",k===X?"border-primary":"border-transparent"),children:e.jsx("img",{src:A,alt:`缩略图 ${X+1}`,className:"h-full w-full object-cover"})},X))})]})})]})]})}function za(){return e.jsxs(He,{children:[e.jsxs(ss,{children:[e.jsx(Ve,{className:"h-6 w-[200px]"}),e.jsx(Ve,{className:"h-4 w-[300px]"})]}),e.jsxs(ts,{className:"flex items-center justify-end space-x-3",children:[e.jsx(Ve,{className:"h-10 w-[100px]"}),e.jsx(Ve,{className:"h-10 w-[100px]"})]})]})}const tu=Object.freeze(Object.defineProperty({__proto__:null,default:su},Symbol.toStringTag,{value:"Module"})),xa=m.forwardRef(({className:s,value:n,onChange:a,...l},r)=>{const[i,c]=m.useState("");m.useEffect(()=>{if(i.includes(",")){const x=new Set([...n,...i.split(",").map(o=>o.trim())]);a(Array.from(x)),c("")}},[i,a,n]);const u=()=>{if(i){const x=new Set([...n,i]);a(Array.from(x)),c("")}};return e.jsxs("div",{className:y(" 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(x=>e.jsxs(K,{variant:"secondary",children:[x,e.jsx(J,{variant:"ghost",size:"icon",className:"ml-2 h-3 w-3",onClick:()=>{a(n.filter(o=>o!==x))},children:e.jsx(Gt,{className:"w-3"})})]},x)),e.jsx("input",{className:"flex-1 outline-none placeholder:text-muted-foreground bg-transparent",value:i,onChange:x=>c(x.target.value),onKeyDown:x=>{x.key==="Enter"||x.key===","?(x.preventDefault(),u()):x.key==="Backspace"&&i.length===0&&n.length>0&&(x.preventDefault(),a(n.slice(0,-1)))},...l,ref:r})]})});xa.displayName="InputTags";const au=h.object({id:h.number().nullable(),title:h.string().min(1).max(250),content:h.string().min(1),show:h.boolean(),tags:h.array(h.string()),img_url:h.string().nullable()}),nu={id:null,show:!1,tags:[],img_url:"",title:"",content:""};function Tr({refetch:s,dialogTrigger:n,type:a="add",defaultFormValues:l=nu}){const{t:r}=I("notice"),[i,c]=m.useState(!1),u=ce({resolver:ue(au),defaultValues:l,mode:"onChange",shouldFocusError:!0}),x=new ra({html:!0});return e.jsx(xe,{...u,children:e.jsxs(ge,{onOpenChange:c,open:i,children:[e.jsx(Fe,{asChild:!0,children:n||e.jsxs(E,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add.button")})]})}),e.jsxs(he,{className:"sm:max-w-[1025px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:r(a==="add"?"form.add.title":"form.edit.title")}),e.jsx(Te,{})]}),e.jsx(j,{control:u.control,name:"title",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.title.label")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(T,{placeholder:r("form.fields.title.placeholder"),...o})})}),e.jsx(P,{})]})}),e.jsx(j,{control:u.control,name:"content",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.content.label")}),e.jsx(N,{children:e.jsx(la,{style:{height:"500px"},value:o.value,renderHTML:d=>x.render(d),onChange:({text:d})=>{o.onChange(d)}})}),e.jsx(P,{})]})}),e.jsx(j,{control:u.control,name:"img_url",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.img_url.label")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:r("form.fields.img_url.placeholder"),...o,value:o.value||""})})}),e.jsx(P,{})]})}),e.jsx(j,{control:u.control,name:"show",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.show.label")}),e.jsx("div",{className:"relative py-2",children:e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:o.onChange})})}),e.jsx(P,{})]})}),e.jsx(j,{control:u.control,name:"tags",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.fields.tags.label")}),e.jsx(N,{children:e.jsx(xa,{value:o.value,onChange:o.onChange,placeholder:r("form.fields.tags.placeholder"),className:"w-full"})}),e.jsx(P,{})]})}),e.jsxs(Me,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(E,{type:"button",variant:"outline",children:r("form.buttons.cancel")})}),e.jsx(E,{type:"submit",onClick:o=>{o.preventDefault(),u.handleSubmit(async d=>{Qc(d).then(({data:p})=>{p&&(q.success(r("form.buttons.success")),s(),c(!1))})})()},children:r("form.buttons.submit")})]})]})]})})}function ru({table:s,refetch:n,saveOrder:a,isSortMode:l}){const{t:r}=I("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:[!l&&e.jsx(Tr,{refetch:n}),!l&&e.jsx(T,{placeholder:r("table.toolbar.search"),value:s.getColumn("title")?.getFilterValue()??"",onChange:c=>s.getColumn("title")?.setFilterValue(c.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),i&&!l&&e.jsxs(E,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-9 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(Oe,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(E,{variant:l?"default":"outline",onClick:a,className:"h-8",size:"sm",children:r(l?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}const lu=s=>{const{t:n}=I("notice");return[{id:"drag-handle",header:"",cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(ci,{className:"h-4 w-4 text-muted-foreground cursor-move"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.id")}),cell:({row:a})=>e.jsx(K,{variant:"outline",className:"font-mono",children:a.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"show",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.show")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx(H,{defaultChecked:a.getValue("show"),onCheckedChange:async()=>{const{data:l}=await Xc({id:a.original.id});l||s()}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.title")}),cell:({row:a})=>e.jsx("div",{className:"flex max-w-[500px] items-center",children:e.jsx("span",{className:"truncate font-medium",children:a.getValue("title")})}),enableSorting:!1,size:6e3},{id:"actions",header:({column:a})=>e.jsx(M,{className:"justify-end",column:a,title:n("table.columns.actions")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Tr,{refetch:s,dialogTrigger:e.jsxs(E,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Es,{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:a.original}),e.jsx(Je,{title:n("table.actions.delete.title"),description:n("table.actions.delete.description"),onConfirm:async()=>{Zc({id:a.original.id}).then(()=>{q.success(n("table.actions.delete.success")),s()})},children:e.jsxs(E,{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 ou(){const[s,n]=m.useState({}),[a,l]=m.useState({}),[r,i]=m.useState([]),[c,u]=m.useState([]),[x,o]=m.useState(!1),[d,p]=m.useState({}),[k,V]=m.useState({pageSize:50,pageIndex:0}),[f,_]=m.useState([]),{refetch:D}=se({queryKey:["notices"],queryFn:async()=>{const{data:R}=await Jc();return _(R),R}});m.useEffect(()=>{l({"drag-handle":x,content:!x,created_at:!x,actions:!x}),V({pageSize:x?99999:50,pageIndex:0})},[x]);const b=(R,z)=>{x&&(R.dataTransfer.setData("text/plain",z.toString()),R.currentTarget.classList.add("opacity-50"))},w=(R,z)=>{if(!x)return;R.preventDefault(),R.currentTarget.classList.remove("bg-muted");const Q=parseInt(R.dataTransfer.getData("text/plain"));if(Q===z)return;const A=[...f],[X]=A.splice(Q,1);A.splice(z,0,X),_(A)},S=async()=>{if(!x){o(!0);return}Td(f.map(R=>R.id)).then(()=>{q.success("排序保存成功"),o(!1),D()}).finally(()=>{o(!1)})},C=ze({data:f??[],columns:lu(D),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,columnSizing:d,pagination:k},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:u,onColumnFiltersChange:i,onColumnVisibilityChange:l,onColumnSizingChange:p,onPaginationChange:V,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),getSortedRowModel:Ge(),getFacetedRowModel:ds(),getFacetedUniqueValues:ms(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(Ye,{table:C,toolbar:R=>e.jsx(ru,{table:R,refetch:D,saveOrder:S,isSortMode:x}),draggable:x,onDragStart:b,onDragEnd:R=>R.currentTarget.classList.remove("opacity-50"),onDragOver:R=>{R.preventDefault(),R.currentTarget.classList.add("bg-muted")},onDragLeave:R=>R.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!x})})}function iu(){const{t:s}=I("notice");return e.jsxs(we,{children:[e.jsxs(Ce,{className:"flex items-center justify-between",children:[e.jsx(Pe,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(ou,{})})]})]})}const cu=Object.freeze(Object.defineProperty({__proto__:null,default:iu},Symbol.toStringTag,{value:"Module"})),du=h.object({id:h.number().nullable(),language:h.string().max(250),category:h.string().max(250),title:h.string().min(1).max(250),body:h.string().min(1),show:h.boolean()}),mu={id:null,language:"zh-CN",category:"",title:"",body:"",show:!1};function Pr({refreshData:s,dialogTrigger:n,type:a="add",defaultFormValues:l=mu}){const{t:r}=I("knowledge"),[i,c]=m.useState(!1),u=ce({resolver:ue(du),defaultValues:l,mode:"onChange",shouldFocusError:!0}),x=new ra({html:!0});return m.useEffect(()=>{i&&l.id&&sd(l.id).then(({data:o})=>{u.reset(o)})},[l.id,u,i]),e.jsxs(ge,{onOpenChange:c,open:i,children:[e.jsx(Fe,{asChild:!0,children:n||e.jsxs(E,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add")})]})}),e.jsxs(he,{className:"sm:max-w-[1025px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:r(a==="add"?"form.add":"form.edit")}),e.jsx(Te,{})]}),e.jsxs(xe,{...u,children:[e.jsx(j,{control:u.control,name:"title",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.title")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(T,{placeholder:r("form.titlePlaceholder"),...o})})}),e.jsx(P,{})]})}),e.jsx(j,{control:u.control,name:"category",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.category")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(T,{placeholder:r("form.categoryPlaceholder"),...o})})}),e.jsx(P,{})]})}),e.jsx(j,{control:u.control,name:"language",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.language")}),e.jsx(N,{children:e.jsxs(W,{value:o.value,onValueChange:o.onChange,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:r("form.languagePlaceholder")})}),e.jsx(G,{children:[{value:"en-US"},{value:"ja-JP"},{value:"ko-KR"},{value:"vi-VN"},{value:"zh-CN"},{value:"zh-TW"}].map(d=>e.jsx($,{value:d.value,className:"cursor-pointer",children:r(`languages.${d.value}`)},d.value))})]})})]})}),e.jsx(j,{control:u.control,name:"body",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.content")}),e.jsx(N,{children:e.jsx(la,{style:{height:"500px"},value:o.value,renderHTML:d=>x.render(d),onChange:({text:d})=>{o.onChange(d)}})}),e.jsx(P,{})]})}),e.jsx(j,{control:u.control,name:"show",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.show")}),e.jsx("div",{className:"relative py-2",children:e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:o.onChange})})}),e.jsx(P,{})]})}),e.jsxs(Me,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(E,{type:"button",variant:"outline",children:r("form.cancel")})}),e.jsx(E,{type:"submit",onClick:()=>{u.handleSubmit(o=>{td(o).then(({data:d})=>{d&&(u.reset(),q.success(r("messages.operationSuccess")),c(!1),s())})})()},children:r("form.submit")})]})]})]})]})}function uu({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(as,{children:[e.jsx(ns,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(ct,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(i=>r.has(i.value)).map(i=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(We,{className:"w-[200px] p-0",align:"start",children:e.jsxs(_s,{children:[e.jsx(Vs,{placeholder:n}),e.jsxs(ws,{children:[e.jsx(Is,{children:"No results found."}),e.jsx(Ie,{children:a.map(i=>{const c=r.has(i.value);return e.jsxs(_e,{onSelect:()=>{c?r.delete(i.value):r.add(i.value);const u=Array.from(r);s?.setFilterValue(u.length?u:void 0)},children:[e.jsx("div",{className:y("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ps,{className:y("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}),l?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(i.value)})]},i.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Ie,{children:e.jsx(_e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function xu({table:s,refetch:n,saveOrder:a,isSortMode:l}){const r=s.getState().columnFilters.length>0,{t:i}=I("knowledge");return e.jsxs("div",{className:"flex items-center justify-between",children:[l?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(Pr,{refreshData:n}),e.jsx(T,{placeholder:i("toolbar.searchPlaceholder"),value:s.getColumn("title")?.getFilterValue()??"",onChange:c=>s.getColumn("title")?.setFilterValue(c.target.value),className:"h-8 w-[250px]"}),s.getColumn("category")&&e.jsx(uu,{column:s.getColumn("category"),title:i("columns.category"),options:Array.from(new Set(s.getCoreRowModel().rows.map(c=>c.getValue("category")))).map(c=>({label:c,value:c}))}),r&&e.jsxs(E,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[i("toolbar.reset"),e.jsx(Oe,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(E,{variant:l?"default":"outline",onClick:a,size:"sm",children:i(l?"toolbar.saveSort":"toolbar.editSort")})})]})}const hu=({refetch:s,isSortMode:n=!1})=>{const{t:a}=I("knowledge");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(Pt,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.id")}),cell:({row:l})=>e.jsx(K,{variant:"outline",className:"justify-center",children:l.getValue("id")}),enableSorting:!0,size:70},{accessorKey:"show",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.status")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx(H,{defaultChecked:l.getValue("show"),onCheckedChange:async()=>{nd({id:l.original.id}).then(({data:r})=>{r||s()})}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.title")}),cell:({row:l})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"line-clamp-2 font-medium",children:l.getValue("title")})}),enableSorting:!0,size:600},{accessorKey:"category",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.category")}),cell:({row:l})=>e.jsx(K,{variant:"secondary",className:"max-w-[180px] truncate",children:l.getValue("category")}),enableSorting:!0,size:1800},{id:"actions",header:({column:l})=>e.jsx(M,{className:"justify-end",column:l,title:a("columns.actions")}),cell:({row:l})=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx(Pr,{refreshData:s,dialogTrigger:e.jsxs(E,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Es,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("form.edit")})]}),type:"edit",defaultFormValues:l.original}),e.jsx(Je,{title:a("messages.deleteConfirm"),description:a("messages.deleteDescription"),confirmText:a("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{ad({id:l.original.id}).then(({data:r})=>{r&&(q.success(a("messages.operationSuccess")),s())})},children:e.jsxs(E,{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:a("messages.deleteButton")})]})})]}),size:100}]};function fu(){const[s,n]=m.useState([]),[a,l]=m.useState([]),[r,i]=m.useState(!1),[c,u]=m.useState([]),[x,o]=m.useState({"drag-handle":!1}),[d,p]=m.useState({pageSize:20,pageIndex:0}),{refetch:k,isLoading:V,data:f}=se({queryKey:["knowledge"],queryFn:async()=>{const{data:S}=await ed();return u(S||[]),S}});m.useEffect(()=>{o({"drag-handle":r,actions:!r}),p({pageSize:r?99999:10,pageIndex:0})},[r]);const _=(S,C)=>{r&&(S.dataTransfer.setData("text/plain",C.toString()),S.currentTarget.classList.add("opacity-50"))},D=(S,C)=>{if(!r)return;S.preventDefault(),S.currentTarget.classList.remove("bg-muted");const R=parseInt(S.dataTransfer.getData("text/plain"));if(R===C)return;const z=[...c],[Q]=z.splice(R,1);z.splice(C,0,Q),u(z)},b=async()=>{r?rd({ids:c.map(S=>S.id)}).then(()=>{k(),i(!1),q.success("排序保存成功")}):i(!0)},w=ze({data:c,columns:hu({refetch:k,isSortMode:r}),state:{sorting:a,columnFilters:s,columnVisibility:x,pagination:d},onSortingChange:l,onColumnFiltersChange:n,onColumnVisibilityChange:o,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),getSortedRowModel:Ge(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Ye,{table:w,toolbar:S=>e.jsx(xu,{table:S,refetch:k,saveOrder:b,isSortMode:r}),draggable:r,onDragStart:_,onDragEnd:S=>S.currentTarget.classList.remove("opacity-50"),onDragOver:S=>{S.preventDefault(),S.currentTarget.classList.add("bg-muted")},onDragLeave:S=>S.currentTarget.classList.remove("bg-muted"),onDrop:D,showPagination:!r})}function pu(){const{t:s}=I("knowledge");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(fu,{})})]})]})}const gu=Object.freeze(Object.defineProperty({__proto__:null,default:pu},Symbol.toStringTag,{value:"Module"}));function ju(s,n){const[a,l]=m.useState(s);return m.useEffect(()=>{const r=setTimeout(()=>l(s),n);return()=>{clearTimeout(r)}},[s,n]),a}function At(s,n){if(s.length===0)return{};if(!n)return{"":s};const a={};return s.forEach(l=>{const r=l[n]||"";a[r]||(a[r]=[]),a[r].push(l)}),a}function vu(s,n){const a=JSON.parse(JSON.stringify(s));for(const[l,r]of Object.entries(a))a[l]=r.filter(i=>!n.find(c=>c.value===i.value));return a}function bu(s,n){for(const[,a]of Object.entries(s))if(a.some(l=>n.find(r=>r.value===l.value)))return!0;return!1}const Rr=m.forwardRef(({className:s,...n},a)=>di(r=>r.filtered.count===0)?e.jsx("div",{ref:a,className:y("py-6 text-center text-sm",s),"cmdk-empty":"",role:"presentation",...n}):null);Rr.displayName="CommandEmpty";const lt=m.forwardRef(({value:s,onChange:n,placeholder:a,defaultOptions:l=[],options:r,delay:i,onSearch:c,loadingIndicator:u,emptyIndicator:x,maxSelected:o=Number.MAX_SAFE_INTEGER,onMaxSelected:d,hidePlaceholderWhenSelected:p,disabled:k,groupBy:V,className:f,badgeClassName:_,selectFirstItem:D=!0,creatable:b=!1,triggerSearchOnFocus:w=!1,commandProps:S,inputProps:C,hideClearAllButton:R=!1},z)=>{const Q=m.useRef(null),[A,X]=m.useState(!1),Us=m.useRef(!1),[va,ba]=m.useState(!1),[ee,Bs]=m.useState(s||[]),[Ss,ya]=m.useState(At(l,V)),[hs,Mt]=m.useState(""),Gs=ju(hs,i||500);m.useImperativeHandle(z,()=>({selectedValue:[...ee],input:Q.current,focus:()=>Q.current?.focus()}),[ee]);const mt=m.useCallback(U=>{const ae=ee.filter(De=>De.value!==U.value);Bs(ae),n?.(ae)},[n,ee]),el=m.useCallback(U=>{const ae=Q.current;ae&&((U.key==="Delete"||U.key==="Backspace")&&ae.value===""&&ee.length>0&&(ee[ee.length-1].fixed||mt(ee[ee.length-1])),U.key==="Escape"&&ae.blur())},[mt,ee]);m.useEffect(()=>{s&&Bs(s)},[s]),m.useEffect(()=>{if(!r||c)return;const U=At(r||[],V);JSON.stringify(U)!==JSON.stringify(Ss)&&ya(U)},[l,r,V,c,Ss]),m.useEffect(()=>{const U=async()=>{ba(!0);const De=await c?.(Gs);ya(At(De||[],V)),ba(!1)};(async()=>{!c||!A||(w&&await U(),Gs&&await U())})()},[Gs,V,A,w]);const sl=()=>{if(!b||bu(Ss,[{value:hs,label:hs}])||ee.find(ae=>ae.value===hs))return;const U=e.jsx(_e,{value:hs,className:"cursor-pointer",onMouseDown:ae=>{ae.preventDefault(),ae.stopPropagation()},onSelect:ae=>{if(ee.length>=o){d?.(ee.length);return}Mt("");const De=[...ee,{value:ae,label:ae}];Bs(De),n?.(De)},children:`Create "${hs}"`});if(!c&&hs.length>0||c&&Gs.length>0&&!va)return U},tl=m.useCallback(()=>{if(x)return c&&!b&&Object.keys(Ss).length===0?e.jsx(_e,{value:"-",disabled:!0,children:x}):e.jsx(Rr,{children:x})},[b,x,c,Ss]),al=m.useMemo(()=>vu(Ss,ee),[Ss,ee]),nl=m.useCallback(()=>{if(S?.filter)return S.filter;if(b)return(U,ae)=>U.toLowerCase().includes(ae.toLowerCase())?1:-1},[b,S?.filter]),rl=m.useCallback(()=>{const U=ee.filter(ae=>ae.fixed);Bs(U),n?.(U)},[n,ee]);return e.jsxs(_s,{...S,onKeyDown:U=>{el(U),S?.onKeyDown?.(U)},className:y("h-auto overflow-visible bg-transparent",S?.className),shouldFilter:S?.shouldFilter!==void 0?S.shouldFilter:!c,filter:nl(),children:[e.jsx("div",{className:y("rounded-md border border-input text-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring ",{"px-3 py-2":ee.length!==0,"cursor-text":!k&&ee.length!==0},f),onClick:()=>{k||Q.current?.focus()},children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[ee.map(U=>e.jsxs(K,{className:y("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",_),"data-fixed":U.fixed,"data-disabled":k||void 0,children:[U.label,e.jsx("button",{className:y("ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",(k||U.fixed)&&"hidden"),onKeyDown:ae=>{ae.key==="Enter"&&mt(U)},onMouseDown:ae=>{ae.preventDefault(),ae.stopPropagation()},onClick:()=>mt(U),children:e.jsx(Gt,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},U.value)),e.jsx(Se.Input,{...C,ref:Q,value:hs,disabled:k,onValueChange:U=>{Mt(U),C?.onValueChange?.(U)},onBlur:U=>{Us.current===!1&&X(!1),C?.onBlur?.(U)},onFocus:U=>{X(!0),w&&c?.(Gs),C?.onFocus?.(U)},placeholder:p&&ee.length!==0?"":a,className:y("flex-1 bg-transparent outline-none placeholder:text-muted-foreground",{"w-full":p,"px-3 py-2":ee.length===0,"ml-1":ee.length!==0},C?.className)}),e.jsx("button",{type:"button",onClick:rl,className:y((R||k||ee.length<1||ee.filter(U=>U.fixed).length===ee.length)&&"hidden"),children:e.jsx(Gt,{})})]})}),e.jsx("div",{className:"relative",children:A&&e.jsx(ws,{className:"absolute top-1 z-10 w-full rounded-md border bg-popover text-popover-foreground shadow-md outline-none animate-in",onMouseLeave:()=>{Us.current=!1},onMouseEnter:()=>{Us.current=!0},onMouseUp:()=>{Q.current?.focus()},children:va?e.jsx(e.Fragment,{children:u}):e.jsxs(e.Fragment,{children:[tl(),sl(),!D&&e.jsx(_e,{value:"-",className:"hidden"}),Object.entries(al).map(([U,ae])=>e.jsx(Ie,{heading:U,className:"h-full overflow-auto",children:e.jsx(e.Fragment,{children:ae.map(De=>e.jsx(_e,{value:De.value,disabled:De.disable,onMouseDown:Ws=>{Ws.preventDefault(),Ws.stopPropagation()},onSelect:()=>{if(ee.length>=o){d?.(ee.length);return}Mt("");const Ws=[...ee,De];Bs(Ws),n?.(Ws)},className:y("cursor-pointer",De.disable&&"cursor-default text-muted-foreground"),children:De.label},De.value))})},U))]})})})]})});lt.displayName="MultipleSelector";const yu=s=>h.object({id:h.number().optional(),name:h.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 Ft({refetch:s,dialogTrigger:n,defaultValues:a={name:""},type:l="add"}){const{t:r}=I("group"),i=ce({resolver:ue(yu(r)),defaultValues:a,mode:"onChange"}),[c,u]=m.useState(!1),[x,o]=m.useState(!1),d=async p=>{o(!0),Lc(p).then(()=>{q.success(r(l==="edit"?"messages.updateSuccess":"messages.createSuccess")),s&&s(),i.reset(),u(!1)}).finally(()=>{o(!1)})};return e.jsxs(ge,{open:c,onOpenChange:u,children:[e.jsx(Fe,{asChild:!0,children:n||e.jsxs(E,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("span",{children:r("form.add")})]})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:r(l==="edit"?"form.edit":"form.create")}),e.jsx(Te,{children:r(l==="edit"?"form.editDescription":"form.createDescription")})]}),e.jsx(xe,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(d),className:"space-y-4",children:[e.jsx(j,{control:i.control,name:"name",render:({field:p})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.name")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("form.namePlaceholder"),...p,className:"w-full"})}),e.jsx(F,{children:r("form.nameDescription")}),e.jsx(P,{})]})}),e.jsxs(Me,{className:"gap-2",children:[e.jsx(dt,{asChild:!0,children:e.jsx(E,{type:"button",variant:"outline",children:r("form.cancel")})}),e.jsxs(E,{type:"submit",disabled:x||!i.formState.isValid,children:[x&&e.jsx(na,{className:"mr-2 h-4 w-4 animate-spin"}),r(l==="edit"?"form.update":"form.create")]})]})]})})]})]})}const Er=m.createContext(void 0);function Nu({children:s,refetch:n}){const[a,l]=m.useState(!1),[r,i]=m.useState(null),[c,u]=m.useState(ye.Shadowsocks);return e.jsx(Er.Provider,{value:{isOpen:a,setIsOpen:l,editingServer:r,setEditingServer:i,serverType:c,setServerType:u,refetch:n},children:s})}function Vr(){const s=m.useContext(Er);if(s===void 0)throw new Error("useServerEdit must be used within a ServerEditProvider");return s}function $t({dialogTrigger:s,value:n,setValue:a,templateType:l}){const{t:r}=I("server");m.useEffect(()=>{console.log(n)},[n]);const[i,c]=m.useState(!1),[u,x]=m.useState(()=>{if(!n||Object.keys(n).length===0)return"";try{return JSON.stringify(n,null,2)}catch{return""}}),[o,d]=m.useState(null),p=b=>{if(!b)return null;try{const w=JSON.parse(b);return typeof w!="object"||w===null?r("network_settings.validation.must_be_object"):null}catch{return r("network_settings.validation.invalid_json")}},k={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"}}}},V=()=>{switch(l){case"tcp":return["tcp","tcp-http"];case"grpc":return["grpc"];case"ws":return["ws"];default:return[]}},f=()=>{const b=p(u||"");if(b){q.error(b);return}try{if(!u){a(null),c(!1);return}a(JSON.parse(u)),c(!1)}catch{q.error(r("network_settings.errors.save_failed"))}},_=b=>{x(b),d(p(b))},D=b=>{const w=k[b];if(w){const S=JSON.stringify(w.content,null,2);x(S),d(null)}};return m.useEffect(()=>{i&&console.log(n)},[i,n]),m.useEffect(()=>{i&&n&&Object.keys(n).length>0&&x(JSON.stringify(n,null,2))},[i,n]),e.jsxs(ge,{open:i,onOpenChange:b=>{!b&&i&&f(),c(b)},children:[e.jsx(Fe,{asChild:!0,children:s??e.jsx(J,{variant:"link",children:r("network_settings.edit_protocol")})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsx(ve,{children:e.jsx(je,{children:r("network_settings.edit_protocol_config")})}),e.jsxs("div",{className:"space-y-4",children:[V().length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:V().map(b=>e.jsx(J,{variant:"outline",size:"sm",onClick:()=>D(b),children:r("network_settings.use_template",{template:k[b].label})},b))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Cs,{className:`min-h-[200px] font-mono text-sm ${o?"border-red-500 focus-visible:ring-red-500":""}`,value:u,placeholder:V().length>0?r("network_settings.json_config_placeholder_with_template"):r("network_settings.json_config_placeholder"),onChange:b=>_(b.target.value)}),o&&e.jsx("p",{className:"text-sm text-red-500",children:o})]})]}),e.jsxs(Me,{className:"gap-2",children:[e.jsx(J,{variant:"outline",onClick:()=>c(!1),children:r("common.cancel")}),e.jsx(J,{onClick:f,disabled:!!o,children:r("common.confirm")})]})]})]})}function Nh(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 _u={},wu=Object.freeze(Object.defineProperty({__proto__:null,default:_u},Symbol.toStringTag,{value:"Module"})),_h=wi(wu),La=s=>s.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),Cu=()=>{try{const s=mi.box.keyPair(),n=La(Da.encodeBase64(s.secretKey)),a=La(Da.encodeBase64(s.publicKey));return{privateKey:n,publicKey:a}}catch(s){throw console.error("Error generating x25519 key pair:",s),s}},Su=()=>{try{return Cu()}catch(s){throw console.error("Error generating key pair:",s),s}},ku=s=>{const n=new Uint8Array(Math.ceil(s/2));return window.crypto.getRandomValues(n),Array.from(n).map(a=>a.toString(16).padStart(2,"0")).join("").substring(0,s)},Du=()=>{const s=Math.floor(Math.random()*8)*2+2;return ku(s)},Tu=h.object({cipher:h.string().default("aes-128-gcm"),obfs:h.string().default("0"),obfs_settings:h.object({path:h.string().default(""),host:h.string().default("")}).default({})}),Pu=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({})}),Ru=h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({})}),Eu=h.object({version:h.coerce.number().default(2),alpn:h.string().default("h2"),obfs:h.object({open:h.coerce.boolean().default(!1),type:h.string().default("salamander"),password:h.string().default("")}).default({}),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),bandwidth:h.object({up:h.string().default(""),down:h.string().default("")}).default({})}),Vu=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),reality_settings:h.object({server_port:h.coerce.number().default(443),server_name:h.string().default(""),allow_insecure:h.boolean().default(!1),public_key:h.string().default(""),private_key:h.string().default(""),short_id:h.string().default("")}).default({}),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({}),flow:h.string().default("")}),rs={shadowsocks:{schema:Tu,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:Pu,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},trojan:{schema:Ru,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},hysteria:{schema:Eu,versions:["1","2"],alpnOptions:["hysteria","http/1.1","h2","h3"]},vless:{schema:Vu,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"]}},Iu=({serverType:s,value:n,onChange:a})=>{const{t:l}=I("server"),r=s?rs[s]:null,i=r?.schema||h.record(h.any()),c=s?i.parse({}):{},u=ce({resolver:ue(i),defaultValues:c,mode:"onChange"});if(m.useEffect(()=>{if(!n||Object.keys(n).length===0){if(s){const f=i.parse({});u.reset(f)}}else u.reset(n)},[s,n,a,u,i]),m.useEffect(()=>{const f=u.watch(_=>{a(_)});return()=>f.unsubscribe()},[u,a]),!s||!r)return null;const V={shadowsocks:()=>e.jsxs(e.Fragment,{children:[e.jsx(j,{control:u.control,name:"cipher",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.shadowsocks.cipher.label")}),e.jsx(N,{children:e.jsxs(W,{onValueChange:f.onChange,value:f.value,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.shadowsocks.cipher.placeholder")})}),e.jsx(G,{children:e.jsx(fs,{children:rs.shadowsocks.ciphers.map(_=>e.jsx($,{value:_,children:_},_))})})]})})]})}),e.jsx(j,{control:u.control,name:"obfs",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.shadowsocks.obfs.label")}),e.jsx(N,{children:e.jsxs(W,{onValueChange:f.onChange,value:f.value,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.shadowsocks.obfs.placeholder")})}),e.jsx(G,{children:e.jsxs(fs,{children:[e.jsx($,{value:"0",children:l("dynamic_form.shadowsocks.obfs.none")}),e.jsx($,{value:"http",children:l("dynamic_form.shadowsocks.obfs.http")})]})})]})})]})}),u.watch("obfs")==="http"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:u.control,name:"obfs_settings.path",render:({field:f})=>e.jsxs(g,{className:"flex-1",children:[e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:l("dynamic_form.shadowsocks.obfs_settings.path"),...f})}),e.jsx(P,{})]})}),e.jsx(j,{control:u.control,name:"obfs_settings.host",render:({field:f})=>e.jsxs(g,{className:"flex-[2]",children:[e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:l("dynamic_form.shadowsocks.obfs_settings.host"),...f})}),e.jsx(P,{})]})})]})]}),vmess:()=>e.jsxs(e.Fragment,{children:[e.jsx(j,{control:u.control,name:"tls",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.vmess.tls.label")}),e.jsx(N,{children:e.jsxs(W,{value:f.value?.toString(),onValueChange:_=>f.onChange(Number(_)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.vmess.tls.placeholder")})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:l("dynamic_form.vmess.tls.disabled")}),e.jsx($,{value:"1",children:l("dynamic_form.vmess.tls.enabled")})]})]})})]})}),u.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:u.control,name:"tls_settings.server_name",render:({field:f})=>e.jsxs(g,{className:"flex-[2]",children:[e.jsx(v,{children:l("dynamic_form.vmess.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:l("dynamic_form.vmess.tls_settings.server_name.placeholder"),...f})})]})}),e.jsx(j,{control:u.control,name:"tls_settings.allow_insecure",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.vmess.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value,onCheckedChange:f.onChange})})})]})})]}),e.jsx(j,{control:u.control,name:"network",render:({field:f})=>e.jsxs(g,{children:[e.jsxs(v,{children:[l("dynamic_form.vmess.network.label"),e.jsx($t,{value:u.watch("network_settings"),setValue:_=>u.setValue("network_settings",_),templateType:u.watch("network")})]}),e.jsx(N,{children:e.jsxs(W,{onValueChange:f.onChange,value:f.value,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.vmess.network.placeholder")})}),e.jsx(G,{children:e.jsx(fs,{children:rs.vmess.networkOptions.map(_=>e.jsx($,{value:_.value,className:"cursor-pointer",children:_.label},_.value))})})]})})]})})]}),trojan:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:u.control,name:"server_name",render:({field:f})=>e.jsxs(g,{className:"flex-[2]",children:[e.jsx(v,{children:l("dynamic_form.trojan.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:l("dynamic_form.trojan.server_name.placeholder"),...f,value:f.value||""})})]})}),e.jsx(j,{control:u.control,name:"allow_insecure",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.trojan.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value||!1,onCheckedChange:f.onChange})})})]})})]}),e.jsx(j,{control:u.control,name:"network",render:({field:f})=>e.jsxs(g,{children:[e.jsxs(v,{children:[l("dynamic_form.trojan.network.label"),e.jsx($t,{value:u.watch("network_settings")||{},setValue:_=>u.setValue("network_settings",_),templateType:u.watch("network")||"tcp"})]}),e.jsx(N,{children:e.jsxs(W,{onValueChange:f.onChange,value:f.value||"tcp",children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.trojan.network.placeholder")})}),e.jsx(G,{children:e.jsx(fs,{children:rs.trojan.networkOptions.map(_=>e.jsx($,{value:_.value,className:"cursor-pointer",children:_.label},_.value))})})]})})]})})]}),hysteria:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:u.control,name:"version",render:({field:f})=>e.jsxs(g,{className:"flex-1",children:[e.jsx(v,{children:l("dynamic_form.hysteria.version.label")}),e.jsx(N,{children:e.jsxs(W,{value:(f.value||2).toString(),onValueChange:_=>f.onChange(Number(_)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.hysteria.version.placeholder")})}),e.jsx(G,{children:e.jsx(fs,{children:rs.hysteria.versions.map(_=>e.jsxs($,{value:_,className:"cursor-pointer",children:["V",_]},_))})})]})})]})}),u.watch("version")==1&&e.jsx(j,{control:u.control,name:"alpn",render:({field:f})=>e.jsxs(g,{className:"flex-[2]",children:[e.jsx(v,{children:l("dynamic_form.hysteria.alpn.label")}),e.jsx(N,{children:e.jsxs(W,{value:f.value||"h2",onValueChange:f.onChange,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.hysteria.alpn.placeholder")})}),e.jsx(G,{children:e.jsx(fs,{children:rs.hysteria.alpnOptions.map(_=>e.jsx($,{value:_,children:_},_))})})]})})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:u.control,name:"obfs.open",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.hysteria.obfs.label")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value||!1,onCheckedChange:f.onChange})})})]})}),!!u.watch("obfs.open")&&e.jsxs(e.Fragment,{children:[u.watch("version")=="2"&&e.jsx(j,{control:u.control,name:"obfs.type",render:({field:f})=>e.jsxs(g,{className:"flex-1",children:[e.jsx(v,{children:l("dynamic_form.hysteria.obfs.type.label")}),e.jsx(N,{children:e.jsxs(W,{value:f.value||"salamander",onValueChange:f.onChange,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.hysteria.obfs.type.placeholder")})}),e.jsx(G,{children:e.jsx(fs,{children:e.jsx($,{value:"salamander",children:l("dynamic_form.hysteria.obfs.type.salamander")})})})]})})]})}),e.jsx(j,{control:u.control,name:"obfs.password",render:({field:f})=>e.jsxs(g,{className:u.watch("version")==2?"w-full":"flex-[2]",children:[e.jsx(v,{children:l("dynamic_form.hysteria.obfs.password.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(T,{placeholder:l("dynamic_form.hysteria.obfs.password.placeholder"),...f,value:f.value||"",className:"pr-9"})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const _="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",D=Array.from(crypto.getRandomValues(new Uint8Array(16))).map(b=>_[b%_.length]).join("");u.setValue("obfs.password",D),q.success(l("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(Ne,{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(j,{control:u.control,name:"tls.server_name",render:({field:f})=>e.jsxs(g,{className:"flex-[2]",children:[e.jsx(v,{children:l("dynamic_form.hysteria.tls.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:l("dynamic_form.hysteria.tls.server_name.placeholder"),...f,value:f.value||""})})]})}),e.jsx(j,{control:u.control,name:"tls.allow_insecure",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.hysteria.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value||!1,onCheckedChange:f.onChange})})})]})})]}),e.jsx(j,{control:u.control,name:"bandwidth.up",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.hysteria.bandwidth.up.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:l("dynamic_form.hysteria.bandwidth.up.placeholder")+(u.watch("version")==2?l("dynamic_form.hysteria.bandwidth.up.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...f,value:f.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:l("dynamic_form.hysteria.bandwidth.up.suffix")})})]})]})}),e.jsx(j,{control:u.control,name:"bandwidth.down",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.hysteria.bandwidth.down.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:l("dynamic_form.hysteria.bandwidth.down.placeholder")+(u.watch("version")==2?l("dynamic_form.hysteria.bandwidth.down.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...f,value:f.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:l("dynamic_form.hysteria.bandwidth.down.suffix")})})]})]})})]}),vless:()=>e.jsxs(e.Fragment,{children:[e.jsx(j,{control:u.control,name:"tls",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.vless.tls.label")}),e.jsx(N,{children:e.jsxs(W,{value:f.value?.toString(),onValueChange:_=>f.onChange(Number(_)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.vless.tls.placeholder")})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:l("dynamic_form.vless.tls.none")}),e.jsx($,{value:"1",children:l("dynamic_form.vless.tls.tls")}),e.jsx($,{value:"2",children:l("dynamic_form.vless.tls.reality")})]})]})})]})}),u.watch("tls")=="1"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:u.control,name:"tls_settings.server_name",render:({field:f})=>e.jsxs(g,{className:"flex-[2]",children:[e.jsx(v,{children:l("dynamic_form.vless.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:l("dynamic_form.vless.tls_settings.server_name.placeholder"),...f})})]})}),e.jsx(j,{control:u.control,name:"tls_settings.allow_insecure",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.vless.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value,onCheckedChange:f.onChange})})})]})})]}),u.watch("tls")==2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:u.control,name:"reality_settings.server_name",render:({field:f})=>e.jsxs(g,{className:"flex-[2]",children:[e.jsx(v,{children:l("dynamic_form.vless.reality_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:l("dynamic_form.vless.reality_settings.server_name.placeholder"),...f})})]})}),e.jsx(j,{control:u.control,name:"reality_settings.server_port",render:({field:f})=>e.jsxs(g,{className:"flex-1",children:[e.jsx(v,{children:l("dynamic_form.vless.reality_settings.server_port.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:l("dynamic_form.vless.reality_settings.server_port.placeholder"),...f})})]})}),e.jsx(j,{control:u.control,name:"reality_settings.allow_insecure",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.vless.reality_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value,onCheckedChange:f.onChange})})})]})})]}),e.jsx("div",{className:"flex items-end gap-2",children:e.jsx(j,{control:u.control,name:"reality_settings.private_key",render:({field:f})=>e.jsxs(g,{className:"flex-1",children:[e.jsx(v,{children:l("dynamic_form.vless.reality_settings.private_key.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(T,{...f,className:"pr-9"})}),e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{try{const _=Su();u.setValue("reality_settings.private_key",_.privateKey),u.setValue("reality_settings.public_key",_.publicKey),q.success(l("dynamic_form.vless.reality_settings.key_pair.success"))}catch{q.error(l("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(Ne,{icon:"ion:key-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(yt,{children:e.jsx(te,{children:e.jsx("p",{children:l("dynamic_form.vless.reality_settings.key_pair.generate")})})})]})]})]})})}),e.jsx(j,{control:u.control,name:"reality_settings.public_key",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.vless.reality_settings.public_key.label")}),e.jsx(N,{children:e.jsx(T,{...f})})]})}),e.jsx(j,{control:u.control,name:"reality_settings.short_id",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.vless.reality_settings.short_id.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(T,{...f,className:"pr-9",placeholder:l("dynamic_form.vless.reality_settings.short_id.placeholder")})}),e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const _=Du();u.setValue("reality_settings.short_id",_),q.success(l("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(Ne,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(yt,{children:e.jsx(te,{children:e.jsx("p",{children:l("dynamic_form.vless.reality_settings.short_id.generate")})})})]})]}),e.jsx(F,{className:"text-xs text-muted-foreground",children:l("dynamic_form.vless.reality_settings.short_id.description")})]})})]}),e.jsx(j,{control:u.control,name:"network",render:({field:f})=>e.jsxs(g,{children:[e.jsxs(v,{children:[l("dynamic_form.vless.network.label"),e.jsx($t,{value:u.watch("network_settings"),setValue:_=>u.setValue("network_settings",_),templateType:u.watch("network")})]}),e.jsx(N,{children:e.jsxs(W,{onValueChange:f.onChange,value:f.value,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.vless.network.placeholder")})}),e.jsx(G,{children:e.jsx(fs,{children:rs.vless.networkOptions.map(_=>e.jsx($,{value:_.value,className:"cursor-pointer",children:_.label},_.value))})})]})})]})}),e.jsx(j,{control:u.control,name:"flow",render:({field:f})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dynamic_form.vless.flow.label")}),e.jsx(N,{children:e.jsxs(W,{onValueChange:_=>f.onChange(_==="none"?null:_),value:f.value||"none",children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.vless.flow.placeholder")})}),e.jsx(G,{children:rs.vless.flowOptions.map(_=>e.jsx($,{value:_,children:_},_))})]})})]})})]})};return e.jsx(ie,{children:V[s]?.()})},Fu=h.object({id:h.number().optional().nullable(),code:h.string().optional(),name:h.string().min(1,"form.name.error"),rate:h.string().min(1,"form.rate.error"),tags:h.array(h.string()).default([]),excludes:h.array(h.string()).default([]),ips:h.array(h.string()).default([]),group_ids:h.array(h.string()).default([]),host:h.string().min(1,"form.host.error"),port:h.string().min(1,"form.port.error"),server_port:h.string().min(1,"form.server_port.error"),parent_id:h.string().default("0").nullable(),route_ids:h.array(h.string()).default([]),protocol_settings:h.record(h.any()).default({}).nullable()}),ht={id:null,code:"",name:"",rate:"1",tags:[],excludes:[],ips:[],group_ids:[],host:"",port:"",server_port:"",parent_id:"0",route_ids:[],protocol_settings:null};function Mu(){const{t:s}=I("server"),{isOpen:n,setIsOpen:a,editingServer:l,setEditingServer:r,serverType:i,setServerType:c,refetch:u}=Vr(),[x,o]=m.useState([]),[d,p]=m.useState([]),[k,V]=m.useState([]),f=ce({resolver:ue(Fu),defaultValues:ht,mode:"onChange"});m.useEffect(()=>{_()},[n]),m.useEffect(()=>{l?.type&&l.type!==i&&c(l.type)},[l,i,c]),m.useEffect(()=>{l?l.type===i&&f.reset({...ht,...l}):f.reset({...ht,protocol_settings:rs[i].schema.parse({})})},[l,f,i]);const _=async()=>{if(!n)return;const[C,R,z]=await Promise.all([It(),hr(),xr()]);o(C.data?.map(Q=>({label:Q.name,value:Q.id.toString()}))||[]),p(R.data?.map(Q=>({label:Q.remarks,value:Q.id.toString()}))||[]),V(z.data||[])},D=m.useMemo(()=>k?.filter(C=>(C.parent_id===0||C.parent_id===null)&&C.type===i&&C.id!==f.watch("id")),[i,k,f]),b=()=>e.jsxs(ys,{children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(os,{align:"start",children:e.jsx(nc,{children:Ds.map(({type:C,label:R})=>e.jsx(fe,{onClick:()=>{c(C),a(!0)},className:"cursor-pointer",children:e.jsx(K,{variant:"outline",className:"text-white",style:{background:ls[C]},children:R})},C))})})]}),w=()=>{a(!1),r(null),f.reset(ht)},S=async()=>{const C=f.getValues();(await Ic({...C,type:i})).data&&(w(),q.success(s("form.success")),u())};return e.jsxs(ge,{open:n,onOpenChange:w,children:[b(),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:s(l?"form.edit_node":"form.new_node")}),e.jsx(Te,{})]}),e.jsxs(xe,{...f,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:f.control,name:"name",render:({field:C})=>e.jsxs(g,{className:"flex-[2]",children:[e.jsx(v,{children:s("form.name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.name.placeholder"),...C})}),e.jsx(P,{})]})}),e.jsx(j,{control:f.control,name:"rate",render:({field:C})=>e.jsxs(g,{className:"flex-[1]",children:[e.jsx(v,{children:s("form.rate.label")}),e.jsx("div",{className:"relative flex",children:e.jsx(N,{children:e.jsx(T,{type:"number",min:"0",step:"0.1",...C})})}),e.jsx(P,{})]})})]}),e.jsx(j,{control:f.control,name:"code",render:({field:C})=>e.jsxs(g,{children:[e.jsxs(v,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.code.placeholder"),...C,value:C.value||""})}),e.jsx(P,{})]})}),e.jsx(j,{control:f.control,name:"tags",render:({field:C})=>e.jsxs(g,{children:[e.jsx(v,{children:s("form.tags.label")}),e.jsx(N,{children:e.jsx(xa,{value:C.value,onChange:C.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(P,{})]})}),e.jsx(j,{control:f.control,name:"group_ids",render:({field:C})=>e.jsxs(g,{children:[e.jsxs(v,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(Ft,{dialogTrigger:e.jsx(E,{variant:"link",children:s("form.groups.add")}),refetch:_})]}),e.jsx(N,{children:e.jsx(lt,{options:x,onChange:R=>C.onChange(R.map(z=>z.value)),value:x?.filter(R=>C.value.includes(R.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(P,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:f.control,name:"host",render:({field:C})=>e.jsxs(g,{children:[e.jsx(v,{children:s("form.host.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.host.placeholder"),...C})}),e.jsx(P,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(j,{control:f.control,name:"port",render:({field:C})=>e.jsxs(g,{className:"flex-1",children:[e.jsxs(v,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(Ne,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(yt,{children:e.jsx(te,{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(N,{children:e.jsx(T,{placeholder:s("form.port.placeholder"),...C})}),e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(E,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const R=C.value;R&&f.setValue("server_port",R)},children:e.jsx(Ne,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(te,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(P,{})]})}),e.jsx(j,{control:f.control,name:"server_port",render:({field:C})=>e.jsxs(g,{className:"flex-1",children:[e.jsxs(v,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(Ne,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(yt,{children:e.jsx(te,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.server_port.placeholder"),...C})}),e.jsx(P,{})]})})]})]}),n&&e.jsx(Iu,{serverType:i,value:f.watch("protocol_settings"),onChange:C=>f.setValue("protocol_settings",C,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(j,{control:f.control,name:"parent_id",render:({field:C})=>e.jsxs(g,{children:[e.jsx(v,{children:s("form.parent.label")}),e.jsxs(W,{onValueChange:C.onChange,value:C.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("form.parent.none")}),D?.map(R=>e.jsx($,{value:R.id.toString(),className:"cursor-pointer",children:R.name},R.id))]})]}),e.jsx(P,{})]})}),e.jsx(j,{control:f.control,name:"route_ids",render:({field:C})=>e.jsxs(g,{children:[e.jsx(v,{children:s("form.route.label")}),e.jsx(N,{children:e.jsx(lt,{options:d,onChange:R=>C.onChange(R.map(z=>z.value)),value:d?.filter(R=>C.value.includes(R.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(P,{})]})})]}),e.jsxs(Me,{className:"mt-6",children:[e.jsx(E,{type:"button",variant:"outline",onClick:w,children:s("form.cancel")}),e.jsx(E,{type:"submit",onClick:S,children:s("form.submit")})]})]})]})]})}function Aa({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(as,{children:[e.jsx(ns,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(ct,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(i=>r.has(i.value)).map(i=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(We,{className:"w-[200px] p-0",align:"start",children:e.jsxs(_s,{children:[e.jsx(Vs,{placeholder:n}),e.jsxs(ws,{children:[e.jsx(Is,{children:"No results found."}),e.jsx(Ie,{children:a.map(i=>{const c=r.has(i.value);return e.jsxs(_e,{onSelect:()=>{c?r.delete(i.value):r.add(i.value);const u=Array.from(r);s?.setFilterValue(u.length?u:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:y("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ps,{className:y("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}),l?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(i.value)})]},i.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Ie,{children:e.jsx(_e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const Ou=[{value:ye.Shadowsocks,label:Ds.find(s=>s.type===ye.Shadowsocks)?.label,color:ls[ye.Shadowsocks]},{value:ye.Vmess,label:Ds.find(s=>s.type===ye.Vmess)?.label,color:ls[ye.Vmess]},{value:ye.Trojan,label:Ds.find(s=>s.type===ye.Trojan)?.label,color:ls[ye.Trojan]},{value:ye.Hysteria,label:Ds.find(s=>s.type===ye.Hysteria)?.label,color:ls[ye.Hysteria]},{value:ye.Vless,label:Ds.find(s=>s.type===ye.Vless)?.label,color:ls[ye.Vless]}];function zu({table:s,saveOrder:n,isSortMode:a,groups:l}){const r=s.getState().columnFilters.length>0,{t:i}=I("server"),c=l.map(u=>({label:u,value:u}));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:[!a&&e.jsxs(e.Fragment,{children:[e.jsx(Mu,{}),e.jsx(T,{placeholder:i("toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:u=>s.getColumn("name")?.setFilterValue(u.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(Aa,{column:s.getColumn("type"),title:i("toolbar.type"),options:Ou}),s.getColumn("groups")&&e.jsx(Aa,{column:s.getColumn("groups"),title:i("columns.groups.title"),options:c})]}),r&&e.jsxs(E,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[i("toolbar.reset"),e.jsx(Oe,{className:"ml-2 h-4 w-4"})]})]}),a&&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(E,{variant:a?"default":"outline",onClick:n,size:"sm",children:i(a?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const ot=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"})}),ft={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"},Lu=s=>{const{t:n}=I("server");return[{id:"drag-handle",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Pt,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.nodeId")}),cell:({row:a})=>{const l=a.getValue("id"),r=a.original.code;return e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(K,{variant:"outline",className:y("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:ls[a.original.type]},children:[e.jsx(zn,{className:"size-3"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:r??l}),a.original.parent?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-muted-foreground/30",children:"→"}),e.jsx("span",{children:a.original.parent?.code||a.original.parent?.id})]}):""]})]}),e.jsx(E,{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(),wt(r||l.toString()).then(()=>{q.success(n("common:copy.success"))})},children:e.jsx(Ta,{className:"size-3"})})]})}),e.jsxs(te,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[Ds.find(i=>i.type===a.original.type)?.label,a.original.parent_id?" (子节点)":""]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r?"点击括号内容或复制按钮可复制节点代码":"点击复制按钮可复制节点ID"})]})]})})},size:200,enableSorting:!0},{accessorKey:"show",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.show")}),cell:({row:a})=>{const[l,r]=m.useState(!!a.getValue("show"));return e.jsx(H,{checked:l,onCheckedChange:async i=>{r(i),Oc({id:a.original.id,type:a.original.type,show:i?1:0}).catch(()=>{r(!i),s()})},style:{backgroundColor:l?ls[a.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx(M,{column:a,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:y("h-2.5 w-2.5 rounded-full",ft[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:y("h-2.5 w-2.5 rounded-full",ft[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:y("h-2.5 w-2.5 rounded-full",ft[2])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.2")})]})]})})}),cell:({row:a})=>e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:y("size-2.5 flex-shrink-0 rounded-full transition-all duration-200",ft[a.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:a.getValue("name")})]})}),e.jsx(te,{children:e.jsx("p",{className:"font-medium",children:n(`columns.status.${a.original.available_status}`)})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.address")}),cell:({row:a})=>{const l=`${a.original.host}:${a.original.port}`,r=a.original.port!==a.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:[a.original.host,":",a.original.port]})}),r&&e.jsxs("span",{className:"whitespace-nowrap text-[0.7rem] tracking-tight text-muted-foreground/40",children:["(",n("columns.internalPort")," ",a.original.server_port,")"]})]}),e.jsx("div",{className:"absolute right-0 top-0",children:e.jsx(ie,{delayDuration:0,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(E,{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(),wt(l).then(()=>{q.success(n("common:copy.success"))})},children:e.jsx(Ta,{className:"size-3"})})}),e.jsx(te,{side:"top",sideOffset:10,children:n("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.onlineUsers.title"),tooltip:n("columns.onlineUsers.tooltip")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(ot,{className:"size-4"}),e.jsx("span",{className:"font-medium",children:a.getValue("online")})]}),size:80,enableSorting:!0,enableHiding:!0},{accessorKey:"rate",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.rate.title"),tooltip:n("columns.rate.tooltip")}),cell:({row:a})=>e.jsxs(K,{variant:"secondary",className:"font-medium",children:[a.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"groups",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.groups.title"),tooltip:n("columns.groups.tooltip")}),cell:({row:a})=>{const l=a.getValue("groups")||[];return e.jsx("div",{className:"flex min-w-[300px] max-w-[600px] flex-wrap items-center gap-1.5",children:l.length>0?l.map((r,i)=>e.jsx(K,{variant:"secondary",className:y("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:r.name},i)):e.jsx("span",{className:"text-sm text-muted-foreground",children:n("columns.groups.empty")})})},enableSorting:!1,size:600,filterFn:(a,l,r)=>{const i=a.getValue(l);return i?r.some(c=>i.includes(c)):!1}},{accessorKey:"type",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.type")}),cell:({row:a})=>{const l=a.getValue("type");return e.jsx(K,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:ls[l]},children:l})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:a})=>e.jsx(M,{className:"justify-end",column:a,title:n("columns.actions")}),cell:({row:a})=>{const{setIsOpen:l,setEditingServer:r,setServerType:i}=Vr();return e.jsx("div",{className:"flex justify-center",children:e.jsxs(ys,{modal:!1,children:[e.jsx(Ns,{asChild:!0,children:e.jsx(E,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Nt,{className:"size-4"})})}),e.jsxs(os,{align:"end",className:"w-40",children:[e.jsx(fe,{className:"cursor-pointer",onClick:()=>{i(a.original.type),r(a.original),l(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(ui,{className:"mr-2 size-4"}),n("columns.actions_dropdown.edit")]})}),e.jsxs(fe,{className:"cursor-pointer",onClick:async()=>{Mc({id:a.original.id}).then(({data:c})=>{c&&(q.success(n("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx(xi,{className:"mr-2 size-4"}),n("columns.actions_dropdown.copy")]}),e.jsx(at,{}),e.jsx(fe,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:c=>c.preventDefault(),children:e.jsx(Je,{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()=>{Fc({id:a.original.id}).then(({data:c})=>{c&&(q.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 Au(){const[s,n]=m.useState({}),[a,l]=m.useState({"drag-handle":!1}),[r,i]=m.useState([]),[c,u]=m.useState({pageSize:500,pageIndex:0}),[x,o]=m.useState([]),[d,p]=m.useState(!1),[k,V]=m.useState({}),[f,_]=m.useState([]),{refetch:D}=se({queryKey:["nodeList"],queryFn:async()=>{const{data:z}=await xr();return _(z),z}}),b=m.useMemo(()=>{const z=new Set;return f.forEach(Q=>{Q.groups&&Q.groups.forEach(A=>z.add(A.name))}),Array.from(z).sort()},[f]);m.useEffect(()=>{l({"drag-handle":d,show:!d,host:!d,online:!d,rate:!d,groups:!d,type:!1,actions:!d}),V({name:d?2e3:200}),u({pageSize:d?99999:500,pageIndex:0})},[d]);const w=(z,Q)=>{d&&(z.dataTransfer.setData("text/plain",Q.toString()),z.currentTarget.classList.add("opacity-50"))},S=(z,Q)=>{if(!d)return;z.preventDefault(),z.currentTarget.classList.remove("bg-muted");const A=parseInt(z.dataTransfer.getData("text/plain"));if(A===Q)return;const X=[...f],[Us]=X.splice(A,1);X.splice(Q,0,Us),_(X)},C=async()=>{if(!d){p(!0);return}const z=f?.map((Q,A)=>({id:Q.id,order:A+1}));zc(z).then(()=>{q.success("排序保存成功"),p(!1),D()}).finally(()=>{p(!1)})},R=ze({data:f||[],columns:Lu(D),state:{sorting:x,columnVisibility:a,rowSelection:s,columnFilters:r,columnSizing:k,pagination:c},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:l,onColumnSizingChange:V,onPaginationChange:u,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),getSortedRowModel:Ge(),getFacetedRowModel:ds(),getFacetedUniqueValues:ms(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Nu,{refetch:D,children:e.jsx("div",{className:"space-y-4",children:e.jsx(Ye,{table:R,toolbar:z=>e.jsx(zu,{table:z,refetch:D,saveOrder:C,isSortMode:d,groups:b}),draggable:d,onDragStart:w,onDragEnd:z=>z.currentTarget.classList.remove("opacity-50"),onDragOver:z=>{z.preventDefault(),z.currentTarget.classList.add("bg-muted")},onDragLeave:z=>z.currentTarget.classList.remove("bg-muted"),onDrop:S,showPagination:!d})})})}function $u(){const{t:s}=I("server");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(Au,{})})]})]})}const qu=Object.freeze(Object.defineProperty({__proto__:null,default:$u},Symbol.toStringTag,{value:"Module"}));function Ku({table:s,refetch:n}){const a=s.getState().columnFilters.length>0,{t:l}=I("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(Ft,{refetch:n}),e.jsx(T,{placeholder:l("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:r=>s.getColumn("name")?.setFilterValue(r.target.value),className:y("h-8 w-[150px] lg:w-[250px]",a&&"border-primary/50 ring-primary/20")}),a&&e.jsxs(E,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("toolbar.reset"),e.jsx(Oe,{className:"ml-2 h-4 w-4"})]})]})})}const Hu=s=>{const{t:n}=I("group");return[{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.id")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:a.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.name")}),cell:({row:a})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium",children:a.getValue("name")})})},{accessorKey:"users_count",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.usersCount")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(ot,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:a.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"server_count",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.serverCount")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(zn,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:a.getValue("server_count")})]}),enableSorting:!0,size:8e3},{id:"actions",header:({column:a})=>e.jsx(M,{className:"justify-end",column:a,title:n("columns.actions")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Ft,{defaultValues:a.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(E,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Es,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(Je,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Ac({id:a.original.id}).then(({data:l})=>{l&&(q.success(n("messages.updateSuccess")),s())})},children:e.jsxs(E,{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 Uu(){const[s,n]=m.useState({}),[a,l]=m.useState({}),[r,i]=m.useState([]),[c,u]=m.useState([]),{data:x,refetch:o,isLoading:d}=se({queryKey:["serverGroupList"],queryFn:async()=>{const{data:k}=await It();return k}}),p=ze({data:x||[],columns:Hu(o),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:u,onColumnFiltersChange:i,onColumnVisibilityChange:l,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),getSortedRowModel:Ge(),getFacetedRowModel:ds(),getFacetedUniqueValues:ms(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Ye,{table:p,toolbar:k=>e.jsx(Ku,{table:k,refetch:o}),isLoading:d})}function Bu(){const{t:s}=I("group");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(Uu,{})})]})]})}const Gu=Object.freeze(Object.defineProperty({__proto__:null,default:Bu},Symbol.toStringTag,{value:"Module"})),Wu=s=>h.object({remarks:h.string().min(1,s("form.validation.remarks")),match:h.array(h.string()),action:h.enum(["block","dns"]),action_value:h.string().optional()});function Ir({refetch:s,dialogTrigger:n,defaultValues:a={remarks:"",match:[],action:"block",action_value:""},type:l="add"}){const{t:r}=I("route"),i=ce({resolver:ue(Wu(r)),defaultValues:a,mode:"onChange"}),[c,u]=m.useState(!1);return e.jsxs(ge,{open:c,onOpenChange:u,children:[e.jsx(Fe,{asChild:!0,children:n||e.jsxs(E,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add")})]})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:r(l==="edit"?"form.edit":"form.create")}),e.jsx(Te,{})]}),e.jsxs(xe,{...i,children:[e.jsx(j,{control:i.control,name:"remarks",render:({field:x})=>e.jsxs(g,{className:"flex-[2]",children:[e.jsx(v,{children:r("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:r("form.remarksPlaceholder"),...x})})}),e.jsx(P,{})]})}),e.jsx(j,{control:i.control,name:"match",render:({field:x})=>e.jsxs(g,{className:"flex-[2]",children:[e.jsx(v,{children:r("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(Cs,{className:"min-h-[120px]",placeholder:r("form.matchPlaceholder"),value:x.value.join(` +`).filter(Boolean);o.onChange(p),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.emailWhitelist.suffixes.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"recaptcha_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.recaptcha.enable.label")}),e.jsx(F,{children:s("safe.form.recaptcha.enable.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),r.watch("recaptcha_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:r.control,name:"recaptcha_key",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.recaptcha.key.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("safe.form.recaptcha.key.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.recaptcha.key.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"recaptcha_site_key",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.recaptcha.siteKey.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("safe.form.recaptcha.siteKey.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.recaptcha.siteKey.description")}),e.jsx(R,{})]})})]}),e.jsx(v,{control:r.control,name:"register_limit_by_ip_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.registerLimit.enable.label")}),e.jsx(F,{children:s("safe.form.registerLimit.enable.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),r.watch("register_limit_by_ip_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:r.control,name:"register_limit_count",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.registerLimit.count.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("safe.form.registerLimit.count.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.registerLimit.count.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"register_limit_expire",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.registerLimit.expire.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("safe.form.registerLimit.expire.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.registerLimit.expire.description")}),e.jsx(R,{})]})})]}),e.jsx(v,{control:r.control,name:"password_limit_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.passwordLimit.enable.label")}),e.jsx(F,{children:s("safe.form.passwordLimit.enable.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),r.watch("password_limit_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:r.control,name:"password_limit_count",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.passwordLimit.count.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("safe.form.passwordLimit.count.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.passwordLimit.count.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"password_limit_expire",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.passwordLimit.expire.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("safe.form.passwordLimit.expire.placeholder"),...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(F,{children:s("safe.form.passwordLimit.expire.description")}),e.jsx(R,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("safe.form.saving")})]})})}function nm(){const{t:s}=I("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(be,{}),e.jsx(am,{})]})}const rm=Object.freeze(Object.defineProperty({__proto__:null,default:nm},Symbol.toStringTag,{value:"Module"})),lm=h.object({plan_change_enable:h.boolean().nullable().default(!1),reset_traffic_method:h.coerce.number().nullable().default(0),surplus_enable:h.boolean().nullable().default(!1),new_order_event_id:h.coerce.number().nullable().default(0),renew_order_event_id:h.coerce.number().nullable().default(0),change_order_event_id:h.coerce.number().nullable().default(0),show_info_to_server_enable:h.boolean().nullable().default(!1),show_protocol_to_server_enable:h.boolean().nullable().default(!1),default_remind_expire:h.boolean().nullable().default(!1),default_remind_traffic:h.boolean().nullable().default(!1),subscribe_path:h.string().nullable().default("s")}),om={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 im(){const{t:s}=I("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=ce({resolver:ue(lm),defaultValues:om,mode:"onBlur"}),{data:i}=se({queryKey:["settings","subscribe"],queryFn:()=>xs("subscribe")}),{mutateAsync:c}=ss({mutationFn:hs,onSuccess:o=>{o.data&&q.success(s("common.autoSaved"))}});u.useEffect(()=>{if(i?.data?.subscribe){const o=i?.data?.subscribe;Object.entries(o).forEach(([d,p])=>{r.setValue(d,p)}),l.current=o}},[i]);const m=u.useCallback(pe.debounce(async o=>{if(!pe.isEqual(o,l.current)){a(!0);try{await c(o),l.current=o}finally{a(!1)}}},1e3),[c]),x=u.useCallback(o=>{m(o)},[m]);return u.useEffect(()=>{const o=r.watch(d=>{x(d)});return()=>o.unsubscribe()},[r.watch,x]),e.jsx(xe,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:r.control,name:"plan_change_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.plan_change_enable.title")}),e.jsx(F,{children:s("subscribe.plan_change_enable.description")}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"reset_traffic_method",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.reset_traffic_method.title")}),e.jsxs(W,{onValueChange:o.onChange,value:o.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:"请选择重置方式"})})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("subscribe.reset_traffic_method.options.monthly_first")}),e.jsx($,{value:"1",children:s("subscribe.reset_traffic_method.options.monthly_reset")}),e.jsx($,{value:"2",children:s("subscribe.reset_traffic_method.options.no_reset")}),e.jsx($,{value:"3",children:s("subscribe.reset_traffic_method.options.yearly_first")}),e.jsx($,{value:"4",children:s("subscribe.reset_traffic_method.options.yearly_reset")})]})]}),e.jsx(F,{children:s("subscribe.reset_traffic_method.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"surplus_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.surplus_enable.title")}),e.jsx(F,{children:s("subscribe.surplus_enable.description")}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"new_order_event_id",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.new_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(W,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:"请选择"})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("subscribe.new_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.new_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("subscribe.new_order_event.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"renew_order_event_id",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.renew_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(W,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:"请选择"})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("subscribe.renew_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.renew_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("renew_order_event.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"change_order_event_id",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.change_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(W,{onValueChange:o.onChange,value:o.value?.toString(),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:"请选择"})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("subscribe.change_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.change_order_event.options.reset_traffic")})]})]})})}),e.jsx(F,{children:s("subscribe.change_order_event.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"subscribe_path",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.subscribe_path.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:"subscribe",...o,value:o.value||"",onChange:d=>{o.onChange(d),x(r.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(R,{})]})}),e.jsx(v,{control:r.control,name:"show_info_to_server_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("subscribe.show_info_to_server.title")}),e.jsx(F,{children:s("subscribe.show_info_to_server.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(v,{control:r.control,name:"show_protocol_to_server_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("subscribe.show_protocol_to_server.title")}),e.jsx(F,{children:s("subscribe.show_protocol_to_server.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value||!1,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function cm(){const{t:s}=I("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(be,{}),e.jsx(im,{})]})}const dm=Object.freeze(Object.defineProperty({__proto__:null,default:cm},Symbol.toStringTag,{value:"Module"})),mm=h.object({invite_force:h.boolean().default(!1),invite_commission:h.coerce.string().default("0"),invite_gen_limit:h.coerce.string().default("0"),invite_never_expire:h.boolean().default(!1),commission_first_time_enable:h.boolean().default(!1),commission_auto_check_enable:h.boolean().default(!1),commission_withdraw_limit:h.coerce.string().default("0"),commission_withdraw_method:h.array(h.string()).default(["支付宝","USDT","Paypal"]),withdraw_close_enable:h.boolean().default(!1),commission_distribution_enable:h.boolean().default(!1),commission_distribution_l1:h.coerce.number().default(0),commission_distribution_l2:h.coerce.number().default(0),commission_distribution_l3:h.coerce.number().default(0)}),um={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 xm(){const{t:s}=I("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=ce({resolver:ue(mm),defaultValues:um,mode:"onBlur"}),{data:i}=se({queryKey:["settings","invite"],queryFn:()=>xs("invite")}),{mutateAsync:c}=ss({mutationFn:hs,onSuccess:o=>{o.data&&q.success(s("common.autoSaved"))}});u.useEffect(()=>{if(i?.data?.invite){const o=i?.data?.invite;Object.entries(o).forEach(([d,p])=>{typeof p=="number"?r.setValue(d,String(p)):r.setValue(d,p)}),l.current=o}},[i]);const m=u.useCallback(pe.debounce(async o=>{if(!pe.isEqual(o,l.current)){a(!0);try{await c(o),l.current=o}finally{a(!1)}}},1e3),[c]),x=u.useCallback(o=>{m(o)},[m]);return u.useEffect(()=>{const o=r.watch(d=>{x(d)});return()=>o.unsubscribe()},[r.watch,x]),e.jsx(xe,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:r.control,name:"invite_force",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.invite_force.title")}),e.jsx(F,{children:s("invite.invite_force.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(v,{control:r.control,name:"invite_commission",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("invite.invite_commission.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("invite.invite_commission.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("invite.invite_commission.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"invite_gen_limit",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("invite.invite_gen_limit.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("invite.invite_gen_limit.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("invite.invite_gen_limit.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"invite_never_expire",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.invite_never_expire.title")}),e.jsx(F,{children:s("invite.invite_never_expire.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(v,{control:r.control,name:"commission_first_time_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.commission_first_time.title")}),e.jsx(F,{children:s("invite.commission_first_time.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(v,{control:r.control,name:"commission_auto_check_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.commission_auto_check.title")}),e.jsx(F,{children:s("invite.commission_auto_check.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(v,{control:r.control,name:"commission_withdraw_limit",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("invite.commission_withdraw_limit.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("invite.commission_withdraw_limit.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("invite.commission_withdraw_limit.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"commission_withdraw_method",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("invite.commission_withdraw_method.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("invite.commission_withdraw_method.placeholder"),...o,value:Array.isArray(o.value)?o.value.join(","):"",onChange:d=>{const p=d.target.value.split(",").filter(Boolean);o.onChange(p),x(r.getValues())}})}),e.jsx(F,{children:s("invite.commission_withdraw_method.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"withdraw_close_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.withdraw_close.title")}),e.jsx(F,{children:s("invite.withdraw_close.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),e.jsx(v,{control:r.control,name:"commission_distribution_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.commission_distribution.title")}),e.jsx(F,{children:s("invite.commission_distribution.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:d=>{o.onChange(d),x(r.getValues())}})})]})}),r.watch("commission_distribution_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:r.control,name:"commission_distribution_l1",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("invite.commission_distribution.l1")}),e.jsx(N,{children:e.jsx(P,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:d=>{const p=d.target.value?Number(d.target.value):0;o.onChange(p),x(r.getValues())}})}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"commission_distribution_l2",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("invite.commission_distribution.l2")}),e.jsx(N,{children:e.jsx(P,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:d=>{const p=d.target.value?Number(d.target.value):0;o.onChange(p),x(r.getValues())}})}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"commission_distribution_l3",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("invite.commission_distribution.l3")}),e.jsx(N,{children:e.jsx(P,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...o,value:o.value||"",onChange:d=>{const p=d.target.value?Number(d.target.value):0;o.onChange(p),x(r.getValues())}})}),e.jsx(R,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("invite.saving")})]})})}function hm(){const{t:s}=I("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(be,{}),e.jsx(xm,{})]})}const fm=Object.freeze(Object.defineProperty({__proto__:null,default:hm},Symbol.toStringTag,{value:"Module"})),pm=h.object({frontend_theme:h.string().nullable(),frontend_theme_sidebar:h.string().nullable(),frontend_theme_header:h.string().nullable(),frontend_theme_color:h.string().nullable(),frontend_background_url:h.string().url().nullable()}),gm={frontend_theme:"",frontend_theme_sidebar:"",frontend_theme_header:"",frontend_theme_color:"",frontend_background_url:""};function jm(){const{data:s}=se({queryKey:["settings","frontend"],queryFn:()=>xs("frontend")}),n=ce({resolver:ue(pm),defaultValues:gm,mode:"onChange"});u.useEffect(()=>{if(s?.data?.frontend){const l=s?.data?.frontend;Object.entries(l).forEach(([r,i])=>{n.setValue(r,i)})}},[s]);function a(l){hs(l).then(({data:r})=>{r&&q.success("更新成功")})}return e.jsx(xe,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(a),className:"space-y-8",children:[e.jsx(v,{control:n.control,name:"frontend_theme_sidebar",render:({field:l})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:"边栏风格"}),e.jsx(F,{children:"边栏风格"})]}),e.jsx(N,{children:e.jsx(H,{checked:l.value,onCheckedChange:l.onChange})})]})}),e.jsx(v,{control:n.control,name:"frontend_theme_header",render:({field:l})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:"头部风格"}),e.jsx(F,{children:"边栏风格"})]}),e.jsx(N,{children:e.jsx(H,{checked:l.value,onCheckedChange:l.onChange})})]})}),e.jsx(v,{control:n.control,name:"frontend_theme_color",render:({field:l})=>e.jsxs(j,{children:[e.jsx(b,{children:"主题色"}),e.jsxs("div",{className:"relative w-max",children:[e.jsx(N,{children:e.jsxs("select",{className:y(Ks({variant:"outline"}),"w-[200px] appearance-none font-normal"),...l,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(aa,{className:"absolute right-3 top-2.5 h-4 w-4 opacity-50"})]}),e.jsx(F,{children:"主题色"}),e.jsx(R,{})]})}),e.jsx(v,{control:n.control,name:"frontend_background_url",render:({field:l})=>e.jsxs(j,{children:[e.jsx(b,{children:"背景"}),e.jsx(N,{children:e.jsx(P,{placeholder:"请输入图片地址",...l})}),e.jsx(F,{children:"将会在后台登录页面进行展示。"}),e.jsx(R,{})]})}),e.jsx(V,{type:"submit",children:"保存设置"})]})})}function vm(){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(be,{}),e.jsx(jm,{})]})}const bm=Object.freeze(Object.defineProperty({__proto__:null,default:vm},Symbol.toStringTag,{value:"Module"})),ym=h.object({server_pull_interval:h.coerce.number().nullable(),server_push_interval:h.coerce.number().nullable(),server_token:h.string().nullable(),device_limit_mode:h.coerce.number().nullable()}),Nm={server_pull_interval:0,server_push_interval:0,server_token:"",device_limit_mode:0};function _m(){const{t:s}=I("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=ce({resolver:ue(ym),defaultValues:Nm,mode:"onBlur"}),{data:i}=se({queryKey:["settings","server"],queryFn:()=>xs("server")}),{mutateAsync:c}=ss({mutationFn:hs,onSuccess:d=>{d.data&&q.success(s("common.AutoSaved"))}});u.useEffect(()=>{if(i?.data.server){const d=i.data.server;Object.entries(d).forEach(([p,k])=>{r.setValue(p,k)}),l.current=d}},[i]);const m=u.useCallback(pe.debounce(async d=>{if(!pe.isEqual(d,l.current)){a(!0);try{await c(d),l.current=d}finally{a(!1)}}},1e3),[c]),x=u.useCallback(d=>{m(d)},[m]);u.useEffect(()=>{const d=r.watch(p=>{x(p)});return()=>d.unsubscribe()},[r.watch,x]);const o=()=>{const d=Math.floor(Math.random()*17)+16,p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let k="";for(let E=0;Ee.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("server.server_token.title")}),e.jsx(N,{children:e.jsxs("div",{className:"relative",children:[e.jsx(P,{placeholder:s("server.server_token.placeholder"),...d,value:d.value||"",className:"pr-10"}),e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{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:p=>{p.preventDefault(),o()},children:e.jsx(Xo,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(te,{children:e.jsx("p",{children:s("server.server_token.generate_tooltip")})})]})})]})}),e.jsx(F,{children:s("server.server_token.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"server_pull_interval",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("server.server_pull_interval.title")}),e.jsx(N,{children:e.jsx(P,{type:"number",placeholder:s("server.server_pull_interval.placeholder"),...d,value:d.value||"",onChange:p=>{const k=p.target.value?Number(p.target.value):null;d.onChange(k)}})}),e.jsx(F,{children:s("server.server_pull_interval.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"server_push_interval",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("server.server_push_interval.title")}),e.jsx(N,{children:e.jsx(P,{type:"number",placeholder:s("server.server_push_interval.placeholder"),...d,value:d.value||"",onChange:p=>{const k=p.target.value?Number(p.target.value):null;d.onChange(k)}})}),e.jsx(F,{children:s("server.server_push_interval.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"device_limit_mode",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("server.device_limit_mode.title")}),e.jsxs(W,{onValueChange:d.onChange,value:d.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:s("server.device_limit_mode.placeholder")})})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("server.device_limit_mode.strict")}),e.jsx($,{value:"1",children:s("server.device_limit_mode.relaxed")})]})]}),e.jsx(F,{children:s("server.device_limit_mode.description")}),e.jsx(R,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("server.saving")})]})})}function wm(){const{t:s}=I("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(be,{}),e.jsx(_m,{})]})}const Cm=Object.freeze(Object.defineProperty({__proto__:null,default:wm},Symbol.toStringTag,{value:"Module"}));function Sm({open:s,onOpenChange:n,result:a}){const l=!a.error;return e.jsx(ge,{open:s,onOpenChange:n,children:e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l?e.jsx(Tn,{className:"h-5 w-5 text-green-500"}):e.jsx(Dn,{className:"h-5 w-5 text-destructive"}),e.jsx(je,{children:l?"邮件发送成功":"邮件发送失败"})]}),e.jsx(De,{children:l?"测试邮件已成功发送,请检查收件箱":"发送测试邮件时遇到错误"})]}),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:a.email}),e.jsx("div",{className:"text-muted-foreground",children:"邮件主题"}),e.jsx("div",{children:a.subject}),e.jsx("div",{className:"text-muted-foreground",children:"模板名称"}),e.jsx("div",{children:a.template_name})]})]}),a.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:a.error})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"配置信息"}),e.jsx(rt,{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:a.config.driver}),e.jsx("div",{className:"text-muted-foreground",children:"服务器"}),e.jsx("div",{children:a.config.host}),e.jsx("div",{className:"text-muted-foreground",children:"端口"}),e.jsx("div",{children:a.config.port}),e.jsx("div",{className:"text-muted-foreground",children:"加密方式"}),e.jsx("div",{children:a.config.encryption||"无"}),e.jsx("div",{className:"text-muted-foreground",children:"发件人"}),e.jsx("div",{children:a.config.from.address?`${a.config.from.address}${a.config.from.name?` (${a.config.from.name})`:""}`:"未设置"}),e.jsx("div",{className:"text-muted-foreground",children:"用户名"}),e.jsx("div",{children:a.config.username||"未设置"})]})})})]})]})]})})}const km=h.object({email_template:h.string().nullable().default("classic"),email_host:h.string().nullable().default(""),email_port:h.coerce.number().nullable().default(465),email_username:h.string().nullable().default(""),email_password:h.string().nullable().default(""),email_encryption:h.string().nullable().default(""),email_from_address:h.string().email().nullable().default(""),remind_mail_enable:h.boolean().nullable().default(!1)});function Tm(){const{t:s}=I("settings"),[n,a]=u.useState(null),[l,r]=u.useState(!1),i=u.useRef(null),[c,m]=u.useState(!1),x=ce({resolver:ue(km),defaultValues:{},mode:"onBlur"}),{data:o}=se({queryKey:["settings","email"],queryFn:()=>xs("email")}),{data:d}=se({queryKey:["emailTemplate"],queryFn:()=>Sd()}),{mutateAsync:p}=ss({mutationFn:hs,onSuccess:T=>{T.data&&q.success(s("common.autoSaved"))}}),{mutate:k,isPending:E}=ss({mutationFn:kd,onMutate:()=>{a(null),r(!1)},onSuccess:T=>{a(T.data),r(!0),T.data.error?q.error(s("email.test.error")):q.success(s("email.test.success"))}});u.useEffect(()=>{if(o?.data.email){const T=o.data.email;Object.entries(T).forEach(([g,w])=>{x.setValue(g,w)}),i.current=T}},[o]);const f=u.useCallback(pe.debounce(async T=>{if(!pe.isEqual(T,i.current)){m(!0);try{await p(T),i.current=T}finally{m(!1)}}},1e3),[p]),_=u.useCallback(T=>{f(T)},[f]);return u.useEffect(()=>{const T=x.watch(g=>{_(g)});return()=>T.unsubscribe()},[x.watch,_]),e.jsxs(e.Fragment,{children:[e.jsx(xe,{...x,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:x.control,name:"email_host",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_host.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("common.placeholder"),...T,value:T.value||""})}),e.jsx(F,{children:s("email.email_host.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"email_port",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_port.title")}),e.jsx(N,{children:e.jsx(P,{type:"number",placeholder:s("common.placeholder"),...T,value:T.value||"",onChange:g=>{const w=g.target.value?Number(g.target.value):null;T.onChange(w)}})}),e.jsx(F,{children:s("email.email_port.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"email_encryption",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_encryption.title")}),e.jsxs(W,{onValueChange:T.onChange,value:T.value||"none",children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:"请选择加密方式"})})}),e.jsxs(G,{children:[e.jsx($,{value:"none",children:s("email.email_encryption.none")}),e.jsx($,{value:"ssl",children:s("email.email_encryption.ssl")}),e.jsx($,{value:"tls",children:s("email.email_encryption.tls")})]})]}),e.jsx(F,{children:s("email.email_encryption.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"email_username",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_username.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("common.placeholder"),...T,value:T.value||""})}),e.jsx(F,{children:s("email.email_username.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"email_password",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_password.title")}),e.jsx(N,{children:e.jsx(P,{type:"password",placeholder:s("common.placeholder"),...T,value:T.value||""})}),e.jsx(F,{children:s("email.email_password.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"email_from_address",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_from.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("common.placeholder"),...T,value:T.value||""})}),e.jsx(F,{children:s("email.email_from.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"email_template",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_template.title")}),e.jsxs(W,{onValueChange:g=>{T.onChange(g),_(x.getValues())},value:T.value||void 0,children:[e.jsx(N,{children:e.jsx(B,{className:"w-[200px]",children:e.jsx(Y,{placeholder:s("email.email_template.placeholder")})})}),e.jsx(G,{children:d?.data?.map(g=>e.jsx($,{value:g,children:g},g))})]}),e.jsx(F,{children:s("email.email_template.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"remind_mail_enable",render:({field:T})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("email.remind_mail.title")}),e.jsx(F,{children:s("email.remind_mail.description")})]}),e.jsx(N,{children:e.jsx(H,{checked:T.value||!1,onCheckedChange:g=>{T.onChange(g),_(x.getValues())}})})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(V,{onClick:()=>k(),loading:E,disabled:E,children:s(E?"test.sending":"test.title")})})]})}),c&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("saving")}),n&&e.jsx(Sm,{open:l,onOpenChange:r,result:n})]})}function Dm(){const{t:s}=I("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(be,{}),e.jsx(Tm,{})]})}const Pm=Object.freeze(Object.defineProperty({__proto__:null,default:Dm},Symbol.toStringTag,{value:"Module"})),Rm=h.object({telegram_bot_enable:h.boolean().nullable(),telegram_bot_token:h.string().nullable(),telegram_discuss_link:h.string().nullable()}),Em={telegram_bot_enable:!1,telegram_bot_token:"",telegram_discuss_link:""};function Vm(){const{t:s}=I("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=ce({resolver:ue(Rm),defaultValues:Em,mode:"onBlur"}),{data:i}=se({queryKey:["settings","telegram"],queryFn:()=>xs("telegram")}),{mutateAsync:c}=ss({mutationFn:hs,onSuccess:p=>{p.data&&q.success(s("common.autoSaved"))}}),{mutate:m,isPending:x}=ss({mutationFn:Td,onSuccess:p=>{p.data&&q.success(s("telegram.webhook_success"))}});u.useEffect(()=>{if(i?.data.telegram){const p=i.data.telegram;Object.entries(p).forEach(([k,E])=>{r.setValue(k,E)}),l.current=p}},[i]);const o=u.useCallback(pe.debounce(async p=>{if(!pe.isEqual(p,l.current)){a(!0);try{await c(p),l.current=p}finally{a(!1)}}},1e3),[c]),d=u.useCallback(p=>{o(p)},[o]);return u.useEffect(()=>{const p=r.watch(k=>{d(k)});return()=>p.unsubscribe()},[r.watch,d]),e.jsx(xe,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:r.control,name:"telegram_bot_token",render:({field:p})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("telegram.bot_token.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("telegram.bot_token.placeholder"),...p,value:p.value||""})}),e.jsx(F,{children:s("telegram.bot_token.description")}),e.jsx(R,{})]})}),r.watch("telegram_bot_token")&&e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("telegram.webhook.title")}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(V,{loading:x,disabled:x,onClick:()=>m(),children:s(x?"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(R,{})]}),e.jsx(v,{control:r.control,name:"telegram_bot_enable",render:({field:p})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("telegram.bot_enable.title")}),e.jsx(F,{children:s("telegram.bot_enable.description")}),e.jsx(N,{children:e.jsx(H,{checked:p.value||!1,onCheckedChange:k=>{p.onChange(k),d(r.getValues())}})}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"telegram_discuss_link",render:({field:p})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("telegram.discuss_link.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("telegram.discuss_link.placeholder"),...p,value:p.value||""})}),e.jsx(F,{children:s("telegram.discuss_link.description")}),e.jsx(R,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Im(){const{t:s}=I("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(be,{}),e.jsx(Vm,{})]})}const Fm=Object.freeze(Object.defineProperty({__proto__:null,default:Im},Symbol.toStringTag,{value:"Module"})),Mm=h.object({windows_version:h.string().nullable(),windows_download_url:h.string().nullable(),macos_version:h.string().nullable(),macos_download_url:h.string().nullable(),android_version:h.string().nullable(),android_download_url:h.string().nullable()}),Om={windows_version:"",windows_download_url:"",macos_version:"",macos_download_url:"",android_version:"",android_download_url:""};function zm(){const{t:s}=I("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=ce({resolver:ue(Mm),defaultValues:Om,mode:"onBlur"}),{data:i}=se({queryKey:["settings","app"],queryFn:()=>xs("app")}),{mutateAsync:c}=ss({mutationFn:hs,onSuccess:o=>{o.data&&q.success(s("app.save_success"))}});u.useEffect(()=>{if(i?.data.app){const o=i.data.app;Object.entries(o).forEach(([d,p])=>{r.setValue(d,p)}),l.current=o}},[i]);const m=u.useCallback(pe.debounce(async o=>{if(!pe.isEqual(o,l.current)){a(!0);try{await c(o),l.current=o}finally{a(!1)}}},1e3),[c]),x=u.useCallback(o=>{m(o)},[m]);return u.useEffect(()=>{const o=r.watch(d=>{x(d)});return()=>o.unsubscribe()},[r.watch,x]),e.jsx(xe,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:r.control,name:"windows_version",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.windows.version.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.windows.version.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"windows_download_url",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.windows.download.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.windows.download.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"macos_version",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.macos.version.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.macos.version.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"macos_download_url",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.macos.download.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.macos.download.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"android_version",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.android.version.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.android.version.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"android_download_url",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.android.download.title")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("common.placeholder"),...o,value:o.value||""})}),e.jsx(F,{children:s("app.android.download.description")}),e.jsx(R,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Lm(){const{t:s}=I("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(be,{}),e.jsx(zm,{})]})}const Am=Object.freeze(Object.defineProperty({__proto__:null,default:Lm},Symbol.toStringTag,{value:"Module"})),ca=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:a,className:y("w-full caption-bottom text-sm",s),...n})}));ca.displayName="Table";const da=u.forwardRef(({className:s,...n},a)=>e.jsx("thead",{ref:a,className:y("[&_tr]:border-b",s),...n}));da.displayName="TableHeader";const ma=u.forwardRef(({className:s,...n},a)=>e.jsx("tbody",{ref:a,className:y("[&_tr:last-child]:border-0",s),...n}));ma.displayName="TableBody";const $m=u.forwardRef(({className:s,...n},a)=>e.jsx("tfoot",{ref:a,className:y("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...n}));$m.displayName="TableFooter";const vs=u.forwardRef(({className:s,...n},a)=>e.jsx("tr",{ref:a,className:y("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...n}));vs.displayName="TableRow";const ua=u.forwardRef(({className:s,...n},a)=>e.jsx("th",{ref:a,className:y("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}));ua.displayName="TableHead";const $s=u.forwardRef(({className:s,...n},a)=>e.jsx("td",{ref:a,className:y("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));$s.displayName="TableCell";const qm=u.forwardRef(({className:s,...n},a)=>e.jsx("caption",{ref:a,className:y("mt-4 text-sm text-muted-foreground",s),...n}));qm.displayName="TableCaption";function Km({table:s}){const[n,a]=u.useState(""),{t:l}=I("common");u.useEffect(()=>{a((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const r=i=>{const c=parseInt(i);!isNaN(c)&&c>=1&&c<=s.getPageCount()?s.setPageIndex(c-1):a((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:l("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:l("table.pagination.itemsPerPage")}),e.jsxs(W,{value:`${s.getState().pagination.pageSize}`,onValueChange:i=>{s.setPageSize(Number(i))},children:[e.jsx(B,{className:"h-8 w-[70px]",children:e.jsx(Y,{placeholder:s.getState().pagination.pageSize})}),e.jsx(G,{side:"top",children:[10,20,30,40,50,100,500].map(i=>e.jsx($,{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:l("table.pagination.page")}),e.jsx(P,{type:"text",value:n,onChange:i=>a(i.target.value),onBlur:i=>r(i.target.value),onKeyDown:i=>{i.key==="Enter"&&r(i.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsx("span",{children:l("table.pagination.pageOf",{total:s.getPageCount()})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(V,{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:l("table.pagination.firstPage")}),e.jsx(ei,{className:"h-4 w-4"})]}),e.jsxs(V,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.previousPage")}),e.jsx(_n,{className:"h-4 w-4"})]}),e.jsxs(V,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.nextPage")}),e.jsx(ta,{className:"h-4 w-4"})]}),e.jsxs(V,{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:l("table.pagination.lastPage")}),e.jsx(si,{className:"h-4 w-4"})]})]})]})]})}function Je({table:s,toolbar:n,draggable:a=!1,onDragStart:l,onDragEnd:r,onDragOver:i,onDragLeave:c,onDrop:m,showPagination:x=!0,isLoading:o=!1}){const{t:d}=I("common"),p=u.useRef(null),k=s.getAllColumns().filter(T=>T.getIsPinned()==="left"),E=s.getAllColumns().filter(T=>T.getIsPinned()==="right"),f=T=>k.slice(0,T).reduce((g,w)=>g+(w.getSize()??0),0),_=T=>E.slice(T+1).reduce((g,w)=>g+(w.getSize()??0),0);return e.jsxs("div",{className:"space-y-4",children:[typeof n=="function"?n(s):n,e.jsx("div",{ref:p,className:"relative overflow-auto rounded-md border bg-card",children:e.jsx("div",{className:"overflow-auto",children:e.jsxs(ca,{children:[e.jsx(da,{children:s.getHeaderGroups().map(T=>e.jsx(vs,{className:"hover:bg-transparent",children:T.headers.map((g,w)=>{const S=g.column.getIsPinned()==="left",C=g.column.getIsPinned()==="right",D=S?f(k.indexOf(g.column)):void 0,z=C?_(E.indexOf(g.column)):void 0;return e.jsx(ua,{colSpan:g.colSpan,style:{width:g.getSize(),...S&&{left:D},...C&&{right:z}},className:y("h-11 bg-card px-4 text-muted-foreground",(S||C)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",S&&"before:right-0",C&&"before:left-0"]),children:g.isPlaceholder?null:bt(g.column.columnDef.header,g.getContext())},g.id)})},T.id))}),e.jsx(ma,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((T,g)=>e.jsx(vs,{"data-state":T.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:a,onDragStart:w=>l?.(w,g),onDragEnd:r,onDragOver:i,onDragLeave:c,onDrop:w=>m?.(w,g),children:T.getVisibleCells().map((w,S)=>{const C=w.column.getIsPinned()==="left",D=w.column.getIsPinned()==="right",z=C?f(k.indexOf(w.column)):void 0,Q=D?_(E.indexOf(w.column)):void 0;return e.jsx($s,{style:{width:w.column.getSize(),...C&&{left:z},...D&&{right:Q}},className:y("bg-card",(C||D)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",C&&"before:right-0",D&&"before:left-0"]),children:bt(w.column.columnDef.cell,w.getContext())},w.id)})},T.id)):e.jsx(vs,{children:e.jsx($s,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:d("table.noData")})})})]})})}),x&&e.jsx(Km,{table:s})]})}const Hm=s=>h.object({id:h.number().nullable(),name:h.string().min(2,s("form.validation.name.min")).max(30,s("form.validation.name.max")),icon:h.string().optional().nullable(),notify_domain:h.string().refine(a=>!a||/^https?:\/\/\S+/.test(a),s("form.validation.notify_domain.url")).optional().nullable(),handling_fee_fixed:h.coerce.number().min(0).optional().nullable(),handling_fee_percent:h.coerce.number().min(0).max(100).optional().nullable(),payment:h.string().min(1,s("form.validation.payment.required")),config:h.record(h.string(),h.string())}),Oa={id:null,name:"",icon:"",notify_domain:"",handling_fee_fixed:0,handling_fee_percent:0,payment:"",config:{}};function vr({refetch:s,dialogTrigger:n,type:a="add",defaultFormValues:l=Oa}){const{t:r}=I("payment"),[i,c]=u.useState(!1),[m,x]=u.useState(!1),[o,d]=u.useState([]),[p,k]=u.useState([]),E=Hm(r),f=ce({resolver:ue(E),defaultValues:l,mode:"onChange"}),_=f.watch("payment");u.useEffect(()=>{i&&(async()=>{const{data:w}=await Hc();d(w)})()},[i]),u.useEffect(()=>{if(!_||!i)return;(async()=>{const w={payment:_,...a==="edit"&&{id:Number(f.getValues("id"))}};Uc(w).then(({data:S})=>{k(S);const C=S.reduce((D,z)=>(z.field_name&&(D[z.field_name]=z.value??""),D),{});f.setValue("config",C)})})()},[_,i,f,a]);const T=async g=>{x(!0);try{(await Bc(g)).data&&(q.success(r("form.messages.success")),f.reset(Oa),s(),c(!1))}finally{x(!1)}};return e.jsxs(ge,{open:i,onOpenChange:c,children:[e.jsx(Me,{asChild:!0,children:n||e.jsxs(V,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add.button")})]})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsx(ve,{children:e.jsx(je,{children:r(a==="add"?"form.add.title":"form.edit.title")})}),e.jsx(xe,{...f,children:e.jsxs("form",{onSubmit:f.handleSubmit(T),className:"space-y-4",children:[e.jsx(v,{control:f.control,name:"name",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.name.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:r("form.fields.name.placeholder"),...g})}),e.jsx(F,{children:r("form.fields.name.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:f.control,name:"icon",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.icon.label")}),e.jsx(N,{children:e.jsx(P,{...g,value:g.value||"",placeholder:r("form.fields.icon.placeholder")})}),e.jsx(F,{children:r("form.fields.icon.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:f.control,name:"notify_domain",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.notify_domain.label")}),e.jsx(N,{children:e.jsx(P,{...g,value:g.value||"",placeholder:r("form.fields.notify_domain.placeholder")})}),e.jsx(F,{children:r("form.fields.notify_domain.description")}),e.jsx(R,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(v,{control:f.control,name:"handling_fee_percent",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.handling_fee_percent.label")}),e.jsx(N,{children:e.jsx(P,{type:"number",...g,value:g.value||"",placeholder:r("form.fields.handling_fee_percent.placeholder")})}),e.jsx(R,{})]})}),e.jsx(v,{control:f.control,name:"handling_fee_fixed",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.handling_fee_fixed.label")}),e.jsx(N,{children:e.jsx(P,{type:"number",...g,value:g.value||"",placeholder:r("form.fields.handling_fee_fixed.placeholder")})}),e.jsx(R,{})]})})]}),e.jsx(v,{control:f.control,name:"payment",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.payment.label")}),e.jsxs(W,{onValueChange:g.onChange,defaultValue:g.value,children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:r("form.fields.payment.placeholder")})})}),e.jsx(G,{children:o.map(w=>e.jsx($,{value:w,children:w},w))})]}),e.jsx(F,{children:r("form.fields.payment.description")}),e.jsx(R,{})]})}),p.length>0&&e.jsx("div",{className:"space-y-4",children:p.map(g=>e.jsx(v,{control:f.control,name:`config.${g.field_name}`,render:({field:w})=>e.jsxs(j,{children:[e.jsx(b,{children:g.label}),e.jsx(N,{children:e.jsx(P,{...w,value:w.value||""})}),e.jsx(R,{})]})},g.field_name))}),e.jsxs(Oe,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(V,{type:"button",variant:"outline",children:r("form.buttons.cancel")})}),e.jsx(V,{type:"submit",disabled:m,children:r("form.buttons.submit")})]})]})})]})]})}function M({column:s,title:n,tooltip:a,className:l}){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(V,{variant:"ghost",size:"default",className:y("-ml-3 flex h-8 items-center gap-2 text-nowrap font-medium hover:bg-muted/60",l),onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[e.jsx("span",{children:n}),a&&e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(ka,{className:"h-4 w-4 cursor-pointer text-muted-foreground"})}),e.jsx(te,{children:a})]})}),s.getIsSorted()==="asc"?e.jsx(Ut,{className:"h-4 w-4 text-foreground/70"}):s.getIsSorted()==="desc"?e.jsx(Bt,{className:"h-4 w-4 text-foreground/70"}):e.jsx(ti,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-foreground/70"})]})})}):e.jsxs("div",{className:y("flex items-center space-x-1 text-nowrap py-2 font-medium text-muted-foreground",l),children:[e.jsx("span",{children:n}),a&&e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsx(ka,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(te,{children:a})]})})]})}const Um=ai,Bm=ni,Gm=ri,br=u.forwardRef(({className:s,...n},a)=>e.jsx(En,{className:y("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:a}));br.displayName=En.displayName;const yr=u.forwardRef(({className:s,...n},a)=>e.jsxs(Gm,{children:[e.jsx(br,{}),e.jsx(Vn,{ref:a,className:y("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})]}));yr.displayName=Vn.displayName;const Nr=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col space-y-2 text-center sm:text-left",s),...n});Nr.displayName="AlertDialogHeader";const _r=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});_r.displayName="AlertDialogFooter";const wr=u.forwardRef(({className:s,...n},a)=>e.jsx(In,{ref:a,className:y("text-lg font-semibold",s),...n}));wr.displayName=In.displayName;const Cr=u.forwardRef(({className:s,...n},a)=>e.jsx(Fn,{ref:a,className:y("text-sm text-muted-foreground",s),...n}));Cr.displayName=Fn.displayName;const Sr=u.forwardRef(({className:s,...n},a)=>e.jsx(Mn,{ref:a,className:y(qs(),s),...n}));Sr.displayName=Mn.displayName;const kr=u.forwardRef(({className:s,...n},a)=>e.jsx(On,{ref:a,className:y(qs({variant:"outline"}),"mt-2 sm:mt-0",s),...n}));kr.displayName=On.displayName;function Qe({onConfirm:s,children:n,title:a="确认操作",description:l="确定要执行此操作吗?",cancelText:r="取消",confirmText:i="确认",variant:c="default",className:m}){return e.jsxs(Um,{children:[e.jsx(Bm,{asChild:!0,children:n}),e.jsxs(yr,{className:y("sm:max-w-[425px]",m),children:[e.jsxs(Nr,{children:[e.jsx(wr,{children:a}),e.jsx(Cr,{children:l})]}),e.jsxs(_r,{children:[e.jsx(kr,{asChild:!0,children:e.jsx(V,{variant:"outline",children:r})}),e.jsx(Sr,{asChild:!0,children:e.jsx(V,{variant:c,onClick:s,children:i})})]})]})]})}const Tr=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"})}),Wm=({refetch:s,isSortMode:n=!1})=>{const{t:a}=I("payment");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(Pt,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:l})=>e.jsx(M,{column:l,title:a("table.columns.id")}),cell:({row:l})=>e.jsx(K,{variant:"outline",children:l.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"enable",header:({column:l})=>e.jsx(M,{column:l,title:a("table.columns.enable")}),cell:({row:l})=>e.jsx(H,{defaultChecked:l.getValue("enable"),onCheckedChange:async()=>{const{data:r}=await Wc({id:l.original.id});r||s()}}),enableSorting:!1,size:100},{accessorKey:"name",header:({column:l})=>e.jsx(M,{column:l,title:a("table.columns.name")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:l.getValue("name")})}),enableSorting:!1,size:200},{accessorKey:"payment",header:({column:l})=>e.jsx(M,{column:l,title:a("table.columns.payment")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:l.getValue("payment")})}),enableSorting:!1,size:200},{accessorKey:"notify_url",header:({column:l})=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(M,{column:l,title:a("table.columns.notify_url")}),e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{className:"ml-1",children:e.jsx(Tr,{className:"h-4 w-4"})}),e.jsx(te,{children:a("table.columns.notify_url_tooltip")})]})})]}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[300px] truncate font-medium",children:l.getValue("notify_url")})}),enableSorting:!1,size:3e3},{id:"actions",header:({column:l})=>e.jsx(M,{className:"justify-end",column:l,title:a("table.columns.actions")}),cell:({row:l})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(vr,{refetch:s,dialogTrigger:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Es,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("table.actions.edit")})]}),type:"edit",defaultFormValues:l.original}),e.jsx(Qe,{title:a("table.actions.delete.title"),description:a("table.actions.delete.description"),onConfirm:async()=>{const{data:r}=await Gc({id:l.original.id});r&&s()},children:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-destructive"}),e.jsx("span",{className:"sr-only",children:a("table.actions.delete.title")})]})})]}),size:100}]};function Ym({table:s,refetch:n,saveOrder:a,isSortMode:l}){const{t:r}=I("payment"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between",children:[l?e.jsx("p",{className:"text-sm text-muted-foreground",children:r("table.toolbar.sort.hint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vr,{refetch:n}),e.jsx(P,{placeholder:r("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:c=>s.getColumn("name")?.setFilterValue(c.target.value),className:"h-8 w-[250px]"}),i&&e.jsxs(V,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[r("table.toolbar.reset"),e.jsx(ze,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(V,{variant:l?"default":"outline",onClick:a,size:"sm",children:r(l?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}function Jm(){const[s,n]=u.useState([]),[a,l]=u.useState([]),[r,i]=u.useState(!1),[c,m]=u.useState([]),[x,o]=u.useState({"drag-handle":!1}),[d,p]=u.useState({pageSize:20,pageIndex:0}),{refetch:k}=se({queryKey:["paymentList"],queryFn:async()=>{const{data:g}=await Kc();return m(g?.map(w=>({...w,enable:!!w.enable}))||[]),g}});u.useEffect(()=>{o({"drag-handle":r,actions:!r}),p({pageSize:r?99999:10,pageIndex:0})},[r]);const E=(g,w)=>{r&&(g.dataTransfer.setData("text/plain",w.toString()),g.currentTarget.classList.add("opacity-50"))},f=(g,w)=>{if(!r)return;g.preventDefault(),g.currentTarget.classList.remove("bg-muted");const S=parseInt(g.dataTransfer.getData("text/plain"));if(S===w)return;const C=[...c],[D]=C.splice(S,1);C.splice(w,0,D),m(C)},_=async()=>{r?Yc({ids:c.map(g=>g.id)}).then(()=>{k(),i(!1),q.success("排序保存成功")}):i(!0)},T=Le({data:c,columns:Wm({refetch:k,isSortMode:r}),state:{sorting:a,columnFilters:s,columnVisibility:x,pagination:d},onSortingChange:l,onColumnFiltersChange:n,onColumnVisibilityChange:o,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),getSortedRowModel:We(),initialState:{columnPinning:{right:["actions"]}},pageCount:r?1:void 0});return e.jsx(Je,{table:T,toolbar:g=>e.jsx(Ym,{table:g,refetch:k,saveOrder:_,isSortMode:r}),draggable:r,onDragStart:E,onDragEnd:g=>g.currentTarget.classList.remove("opacity-50"),onDragOver:g=>{g.preventDefault(),g.currentTarget.classList.add("bg-muted")},onDragLeave:g=>g.currentTarget.classList.remove("bg-muted"),onDrop:f,showPagination:!r})}function Qm(){const{t:s}=I("payment");return e.jsxs(we,{children:[e.jsxs(Ce,{className:"flex items-center justify-between",children:[e.jsx(Pe,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(Jm,{})})]})]})}const Zm=Object.freeze(Object.defineProperty({__proto__:null,default:Qm},Symbol.toStringTag,{value:"Module"})),Xm=(s,n)=>{let a=null;switch(s.field_type){case"input":a=e.jsx(P,{placeholder:s.placeholder,...n});break;case"textarea":a=e.jsx(Cs,{placeholder:s.placeholder,...n});break;case"select":a=e.jsx("select",{className:y(qs({variant:"outline"}),"w-full appearance-none font-normal"),...n,children:s.select_options&&Object.keys(s.select_options).map(l=>e.jsx("option",{value:l,children:s.select_options?.[l]},l))});break;default:a=null;break}return a};function eu({themeKey:s,themeInfo:n}){const{t:a}=I("theme"),[l,r]=u.useState(!1),[i,c]=u.useState(!1),[m,x]=u.useState(!1),o=ce({defaultValues:n.configs.reduce((k,E)=>(k[E.field_name]="",k),{})}),d=async()=>{c(!0),Dc(s).then(({data:k})=>{Object.entries(k).forEach(([E,f])=>{o.setValue(E,f)})}).finally(()=>{c(!1)})},p=async k=>{x(!0),Pc(s,k).then(()=>{q.success(a("config.success")),r(!1)}).finally(()=>{x(!1)})};return e.jsxs(ge,{open:l,onOpenChange:k=>{r(k),k?d():o.reset()},children:[e.jsx(Me,{asChild:!0,children:e.jsx(V,{variant:"outline",children:a("card.configureTheme")})}),e.jsxs(he,{className:"max-h-[90vh] overflow-auto sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:a("config.title",{name:n.name})}),e.jsx(De,{children:a("config.description")})]}),i?e.jsx("div",{className:"flex h-40 items-center justify-center",children:e.jsx(na,{className:"h-6 w-6 animate-spin"})}):e.jsx(xe,{...o,children:e.jsxs("form",{onSubmit:o.handleSubmit(p),className:"space-y-4",children:[n.configs.map(k=>e.jsx(v,{control:o.control,name:k.field_name,render:({field:E})=>e.jsxs(j,{children:[e.jsx(b,{children:k.label}),e.jsx(N,{children:Xm(k,E)}),e.jsx(R,{})]})},k.field_name)),e.jsxs(Oe,{className:"mt-6 gap-2",children:[e.jsx(V,{type:"button",variant:"secondary",onClick:()=>r(!1),children:a("config.cancel")}),e.jsx(V,{type:"submit",loading:m,children:a("config.save")})]})]})})]})]})}function su(){const{t:s}=I("theme"),[n,a]=u.useState(null),[l,r]=u.useState(!1),[i,c]=u.useState(!1),[m,x]=u.useState(!1),[o,d]=u.useState(null),p=u.useRef(null),[k,E]=u.useState(0),{data:f,isLoading:_,refetch:T}=se({queryKey:["themeList"],queryFn:async()=>{const{data:A}=await Tc();return A}}),g=async A=>{a(A),Vc({frontend_theme:A}).then(()=>{q.success("主题切换成功"),T()}).finally(()=>{a(null)})},w=async A=>{if(!A.name.endsWith(".zip")){q.error(s("upload.error.format"));return}r(!0),Rc(A).then(()=>{q.success("主题上传成功"),c(!1),T()}).finally(()=>{r(!1),p.current&&(p.current.value="")})},S=A=>{A.preventDefault(),A.stopPropagation(),A.type==="dragenter"||A.type==="dragover"?x(!0):A.type==="dragleave"&&x(!1)},C=A=>{A.preventDefault(),A.stopPropagation(),x(!1),A.dataTransfer.files&&A.dataTransfer.files[0]&&w(A.dataTransfer.files[0])},D=()=>{o&&E(A=>A===0?o.images.length-1:A-1)},z=()=>{o&&E(A=>A===o.images.length-1?0:A+1)},Q=(A,X)=>{E(0),d({name:A,images:X})};return e.jsxs(we,{children:[e.jsxs(Ce,{className:"flex items-center justify-between",children:[e.jsx(Pe,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(V,{onClick:()=>c(!0),variant:"outline",className:"ml-4 shrink-0",size:"sm",children:[e.jsx(Ht,{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:_?e.jsxs(e.Fragment,{children:[e.jsx(za,{}),e.jsx(za,{})]}):f?.themes&&Object.entries(f.themes).map(([A,X])=>e.jsx(Ue,{className:"group relative overflow-hidden transition-all hover:shadow-md",style:{backgroundImage:X.background_url?`url(${X.background_url})`:"none",backgroundSize:"cover",backgroundPosition:"center"},children:e.jsxs("div",{className:y("relative z-10 h-full transition-colors",X.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:[!!X.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(A===f?.active){q.error(s("card.delete.error.active"));return}a(A),Ec(A).then(()=>{q.success("主题删除成功"),T()}).finally(()=>{a(null)})},children:e.jsx(V,{disabled:n===A,loading:n===A,variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",children:e.jsx(ds,{className:"h-4 w-4"})})})}),e.jsxs(ts,{children:[e.jsx(bs,{children:X.name}),e.jsx(tt,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{children:X.description}),X.version&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("card.version",{version:X.version})})]})})]}),e.jsxs(as,{className:"flex items-center justify-end space-x-3",children:[X.images&&Array.isArray(X.images)&&X.images.length>0&&e.jsx(V,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>Q(X.name,X.images),children:e.jsx(li,{className:"h-4 w-4"})}),e.jsx(eu,{themeKey:A,themeInfo:X}),e.jsx(V,{onClick:()=>g(A),disabled:n===A||A===f.active,loading:n===A,variant:A===f.active?"secondary":"default",children:A===f.active?s("card.currentTheme"):s("card.activateTheme")})]})]})},A))}),e.jsx(ge,{open:i,onOpenChange:c,children:e.jsxs(he,{className:"sm:max-w-md",children:[e.jsxs(ve,{children:[e.jsx(je,{children:s("upload.title")}),e.jsx(De,{children:s("upload.description")})]}),e.jsxs("div",{className:y("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",m&&"border-primary/50 bg-muted/50"),onDragEnter:S,onDragLeave:S,onDragOver:S,onDrop:C,children:[e.jsx("input",{type:"file",ref:p,className:"hidden",accept:".zip",onChange:A=>{const X=A.target.files?.[0];X&&w(X)}}),l?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(Ht,{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:()=>p.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(ge,{open:!!o,onOpenChange:A=>{A||(d(null),E(0))},children:e.jsxs(he,{className:"max-w-4xl",children:[e.jsxs(ve,{children:[e.jsxs(je,{children:[o?.name," ",s("preview.title")]}),e.jsx(De,{className:"text-center",children:o&&s("preview.imageCount",{current:k+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[k]&&e.jsx("img",{src:o.images[k],alt:`${o.name} 预览图 ${k+1}`,className:"h-full w-full object-contain"})}),o&&o.images.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(V,{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:D,children:e.jsx(oi,{className:"h-4 w-4"})}),e.jsx(V,{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:z,children:e.jsx(ii,{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((A,X)=>e.jsx("button",{onClick:()=>E(X),className:y("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2",k===X?"border-primary":"border-transparent"),children:e.jsx("img",{src:A,alt:`缩略图 ${X+1}`,className:"h-full w-full object-cover"})},X))})]})})]})]})}function za(){return e.jsxs(Ue,{children:[e.jsxs(ts,{children:[e.jsx(Ie,{className:"h-6 w-[200px]"}),e.jsx(Ie,{className:"h-4 w-[300px]"})]}),e.jsxs(as,{className:"flex items-center justify-end space-x-3",children:[e.jsx(Ie,{className:"h-10 w-[100px]"}),e.jsx(Ie,{className:"h-10 w-[100px]"})]})]})}const tu=Object.freeze(Object.defineProperty({__proto__:null,default:su},Symbol.toStringTag,{value:"Module"})),xa=u.forwardRef(({className:s,value:n,onChange:a,...l},r)=>{const[i,c]=u.useState("");u.useEffect(()=>{if(i.includes(",")){const x=new Set([...n,...i.split(",").map(o=>o.trim())]);a(Array.from(x)),c("")}},[i,a,n]);const m=()=>{if(i){const x=new Set([...n,i]);a(Array.from(x)),c("")}};return e.jsxs("div",{className:y(" 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(x=>e.jsxs(K,{variant:"secondary",children:[x,e.jsx(J,{variant:"ghost",size:"icon",className:"ml-2 h-3 w-3",onClick:()=>{a(n.filter(o=>o!==x))},children:e.jsx(Gt,{className:"w-3"})})]},x)),e.jsx("input",{className:"flex-1 outline-none placeholder:text-muted-foreground bg-transparent",value:i,onChange:x=>c(x.target.value),onKeyDown:x=>{x.key==="Enter"||x.key===","?(x.preventDefault(),m()):x.key==="Backspace"&&i.length===0&&n.length>0&&(x.preventDefault(),a(n.slice(0,-1)))},...l,ref:r})]})});xa.displayName="InputTags";const au=h.object({id:h.number().nullable(),title:h.string().min(1).max(250),content:h.string().min(1),show:h.boolean(),tags:h.array(h.string()),img_url:h.string().nullable()}),nu={id:null,show:!1,tags:[],img_url:"",title:"",content:""};function Dr({refetch:s,dialogTrigger:n,type:a="add",defaultFormValues:l=nu}){const{t:r}=I("notice"),[i,c]=u.useState(!1),m=ce({resolver:ue(au),defaultValues:l,mode:"onChange",shouldFocusError:!0}),x=new ra({html:!0});return e.jsx(xe,{...m,children:e.jsxs(ge,{onOpenChange:c,open:i,children:[e.jsx(Me,{asChild:!0,children:n||e.jsxs(V,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add.button")})]})}),e.jsxs(he,{className:"sm:max-w-[1025px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:r(a==="add"?"form.add.title":"form.edit.title")}),e.jsx(De,{})]}),e.jsx(v,{control:m.control,name:"title",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.title.label")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(P,{placeholder:r("form.fields.title.placeholder"),...o})})}),e.jsx(R,{})]})}),e.jsx(v,{control:m.control,name:"content",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.content.label")}),e.jsx(N,{children:e.jsx(la,{style:{height:"500px"},value:o.value,renderHTML:d=>x.render(d),onChange:({text:d})=>{o.onChange(d)}})}),e.jsx(R,{})]})}),e.jsx(v,{control:m.control,name:"img_url",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.img_url.label")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(P,{type:"text",placeholder:r("form.fields.img_url.placeholder"),...o,value:o.value||""})})}),e.jsx(R,{})]})}),e.jsx(v,{control:m.control,name:"show",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.show.label")}),e.jsx("div",{className:"relative py-2",children:e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:o.onChange})})}),e.jsx(R,{})]})}),e.jsx(v,{control:m.control,name:"tags",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.fields.tags.label")}),e.jsx(N,{children:e.jsx(xa,{value:o.value,onChange:o.onChange,placeholder:r("form.fields.tags.placeholder"),className:"w-full"})}),e.jsx(R,{})]})}),e.jsxs(Oe,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(V,{type:"button",variant:"outline",children:r("form.buttons.cancel")})}),e.jsx(V,{type:"submit",onClick:o=>{o.preventDefault(),m.handleSubmit(async d=>{Qc(d).then(({data:p})=>{p&&(q.success(r("form.buttons.success")),s(),c(!1))})})()},children:r("form.buttons.submit")})]})]})]})})}function ru({table:s,refetch:n,saveOrder:a,isSortMode:l}){const{t:r}=I("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:[!l&&e.jsx(Dr,{refetch:n}),!l&&e.jsx(P,{placeholder:r("table.toolbar.search"),value:s.getColumn("title")?.getFilterValue()??"",onChange:c=>s.getColumn("title")?.setFilterValue(c.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),i&&!l&&e.jsxs(V,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-9 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(ze,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(V,{variant:l?"default":"outline",onClick:a,className:"h-8",size:"sm",children:r(l?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}const lu=s=>{const{t:n}=I("notice");return[{id:"drag-handle",header:"",cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(ci,{className:"h-4 w-4 text-muted-foreground cursor-move"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.id")}),cell:({row:a})=>e.jsx(K,{variant:"outline",className:"font-mono",children:a.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"show",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.show")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx(H,{defaultChecked:a.getValue("show"),onCheckedChange:async()=>{const{data:l}=await Xc({id:a.original.id});l||s()}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.title")}),cell:({row:a})=>e.jsx("div",{className:"flex max-w-[500px] items-center",children:e.jsx("span",{className:"truncate font-medium",children:a.getValue("title")})}),enableSorting:!1,size:6e3},{id:"actions",header:({column:a})=>e.jsx(M,{className:"justify-end",column:a,title:n("table.columns.actions")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Dr,{refetch:s,dialogTrigger:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Es,{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:a.original}),e.jsx(Qe,{title:n("table.actions.delete.title"),description:n("table.actions.delete.description"),onConfirm:async()=>{Zc({id:a.original.id}).then(()=>{q.success(n("table.actions.delete.success")),s()})},children:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{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 ou(){const[s,n]=u.useState({}),[a,l]=u.useState({}),[r,i]=u.useState([]),[c,m]=u.useState([]),[x,o]=u.useState(!1),[d,p]=u.useState({}),[k,E]=u.useState({pageSize:50,pageIndex:0}),[f,_]=u.useState([]),{refetch:T}=se({queryKey:["notices"],queryFn:async()=>{const{data:D}=await Jc();return _(D),D}});u.useEffect(()=>{l({"drag-handle":x,content:!x,created_at:!x,actions:!x}),E({pageSize:x?99999:50,pageIndex:0})},[x]);const g=(D,z)=>{x&&(D.dataTransfer.setData("text/plain",z.toString()),D.currentTarget.classList.add("opacity-50"))},w=(D,z)=>{if(!x)return;D.preventDefault(),D.currentTarget.classList.remove("bg-muted");const Q=parseInt(D.dataTransfer.getData("text/plain"));if(Q===z)return;const A=[...f],[X]=A.splice(Q,1);A.splice(z,0,X),_(A)},S=async()=>{if(!x){o(!0);return}Dd(f.map(D=>D.id)).then(()=>{q.success("排序保存成功"),o(!1),T()}).finally(()=>{o(!1)})},C=Le({data:f??[],columns:lu(T),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,columnSizing:d,pagination:k},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:i,onColumnVisibilityChange:l,onColumnSizingChange:p,onPaginationChange:E,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),getSortedRowModel:We(),getFacetedRowModel:ms(),getFacetedUniqueValues:us(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(Je,{table:C,toolbar:D=>e.jsx(ru,{table:D,refetch:T,saveOrder:S,isSortMode:x}),draggable:x,onDragStart:g,onDragEnd:D=>D.currentTarget.classList.remove("opacity-50"),onDragOver:D=>{D.preventDefault(),D.currentTarget.classList.add("bg-muted")},onDragLeave:D=>D.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!x})})}function iu(){const{t:s}=I("notice");return e.jsxs(we,{children:[e.jsxs(Ce,{className:"flex items-center justify-between",children:[e.jsx(Pe,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(ou,{})})]})]})}const cu=Object.freeze(Object.defineProperty({__proto__:null,default:iu},Symbol.toStringTag,{value:"Module"})),du=h.object({id:h.number().nullable(),language:h.string().max(250),category:h.string().max(250),title:h.string().min(1).max(250),body:h.string().min(1),show:h.boolean()}),mu={id:null,language:"zh-CN",category:"",title:"",body:"",show:!1};function Pr({refreshData:s,dialogTrigger:n,type:a="add",defaultFormValues:l=mu}){const{t:r}=I("knowledge"),[i,c]=u.useState(!1),m=ce({resolver:ue(du),defaultValues:l,mode:"onChange",shouldFocusError:!0}),x=new ra({html:!0});return u.useEffect(()=>{i&&l.id&&sd(l.id).then(({data:o})=>{m.reset(o)})},[l.id,m,i]),e.jsxs(ge,{onOpenChange:c,open:i,children:[e.jsx(Me,{asChild:!0,children:n||e.jsxs(V,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add")})]})}),e.jsxs(he,{className:"sm:max-w-[1025px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:r(a==="add"?"form.add":"form.edit")}),e.jsx(De,{})]}),e.jsxs(xe,{...m,children:[e.jsx(v,{control:m.control,name:"title",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.title")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(P,{placeholder:r("form.titlePlaceholder"),...o})})}),e.jsx(R,{})]})}),e.jsx(v,{control:m.control,name:"category",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.category")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(P,{placeholder:r("form.categoryPlaceholder"),...o})})}),e.jsx(R,{})]})}),e.jsx(v,{control:m.control,name:"language",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.language")}),e.jsx(N,{children:e.jsxs(W,{value:o.value,onValueChange:o.onChange,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:r("form.languagePlaceholder")})}),e.jsx(G,{children:[{value:"en-US"},{value:"ja-JP"},{value:"ko-KR"},{value:"vi-VN"},{value:"zh-CN"},{value:"zh-TW"}].map(d=>e.jsx($,{value:d.value,className:"cursor-pointer",children:r(`languages.${d.value}`)},d.value))})]})})]})}),e.jsx(v,{control:m.control,name:"body",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.content")}),e.jsx(N,{children:e.jsx(la,{style:{height:"500px"},value:o.value,renderHTML:d=>x.render(d),onChange:({text:d})=>{o.onChange(d)}})}),e.jsx(R,{})]})}),e.jsx(v,{control:m.control,name:"show",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.show")}),e.jsx("div",{className:"relative py-2",children:e.jsx(N,{children:e.jsx(H,{checked:o.value,onCheckedChange:o.onChange})})}),e.jsx(R,{})]})}),e.jsxs(Oe,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(V,{type:"button",variant:"outline",children:r("form.cancel")})}),e.jsx(V,{type:"submit",onClick:()=>{m.handleSubmit(o=>{td(o).then(({data:d})=>{d&&(m.reset(),q.success(r("messages.operationSuccess")),c(!1),s())})})()},children:r("form.submit")})]})]})]})]})}function uu({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(V,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(ct,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(i=>r.has(i.value)).map(i=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ye,{className:"w-[200px] p-0",align:"start",children:e.jsxs(_s,{children:[e.jsx(Vs,{placeholder:n}),e.jsxs(ws,{children:[e.jsx(Is,{children:"No results found."}),e.jsx(Fe,{children:a.map(i=>{const c=r.has(i.value);return e.jsxs(_e,{onSelect:()=>{c?r.delete(i.value):r.add(i.value);const m=Array.from(r);s?.setFilterValue(m.length?m:void 0)},children:[e.jsx("div",{className:y("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ps,{className:y("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}),l?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(i.value)})]},i.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Fe,{children:e.jsx(_e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function xu({table:s,refetch:n,saveOrder:a,isSortMode:l}){const r=s.getState().columnFilters.length>0,{t:i}=I("knowledge");return e.jsxs("div",{className:"flex items-center justify-between",children:[l?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(Pr,{refreshData:n}),e.jsx(P,{placeholder:i("toolbar.searchPlaceholder"),value:s.getColumn("title")?.getFilterValue()??"",onChange:c=>s.getColumn("title")?.setFilterValue(c.target.value),className:"h-8 w-[250px]"}),s.getColumn("category")&&e.jsx(uu,{column:s.getColumn("category"),title:i("columns.category"),options:Array.from(new Set(s.getCoreRowModel().rows.map(c=>c.getValue("category")))).map(c=>({label:c,value:c}))}),r&&e.jsxs(V,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[i("toolbar.reset"),e.jsx(ze,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(V,{variant:l?"default":"outline",onClick:a,size:"sm",children:i(l?"toolbar.saveSort":"toolbar.editSort")})})]})}const hu=({refetch:s,isSortMode:n=!1})=>{const{t:a}=I("knowledge");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(Pt,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.id")}),cell:({row:l})=>e.jsx(K,{variant:"outline",className:"justify-center",children:l.getValue("id")}),enableSorting:!0,size:70},{accessorKey:"show",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.status")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx(H,{defaultChecked:l.getValue("show"),onCheckedChange:async()=>{nd({id:l.original.id}).then(({data:r})=>{r||s()})}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.title")}),cell:({row:l})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"line-clamp-2 font-medium",children:l.getValue("title")})}),enableSorting:!0,size:600},{accessorKey:"category",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.category")}),cell:({row:l})=>e.jsx(K,{variant:"secondary",className:"max-w-[180px] truncate",children:l.getValue("category")}),enableSorting:!0,size:1800},{id:"actions",header:({column:l})=>e.jsx(M,{className:"justify-end",column:l,title:a("columns.actions")}),cell:({row:l})=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx(Pr,{refreshData:s,dialogTrigger:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Es,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("form.edit")})]}),type:"edit",defaultFormValues:l.original}),e.jsx(Qe,{title:a("messages.deleteConfirm"),description:a("messages.deleteDescription"),confirmText:a("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{ad({id:l.original.id}).then(({data:r})=>{r&&(q.success(a("messages.operationSuccess")),s())})},children:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("messages.deleteButton")})]})})]}),size:100}]};function fu(){const[s,n]=u.useState([]),[a,l]=u.useState([]),[r,i]=u.useState(!1),[c,m]=u.useState([]),[x,o]=u.useState({"drag-handle":!1}),[d,p]=u.useState({pageSize:20,pageIndex:0}),{refetch:k,isLoading:E,data:f}=se({queryKey:["knowledge"],queryFn:async()=>{const{data:S}=await ed();return m(S||[]),S}});u.useEffect(()=>{o({"drag-handle":r,actions:!r}),p({pageSize:r?99999:10,pageIndex:0})},[r]);const _=(S,C)=>{r&&(S.dataTransfer.setData("text/plain",C.toString()),S.currentTarget.classList.add("opacity-50"))},T=(S,C)=>{if(!r)return;S.preventDefault(),S.currentTarget.classList.remove("bg-muted");const D=parseInt(S.dataTransfer.getData("text/plain"));if(D===C)return;const z=[...c],[Q]=z.splice(D,1);z.splice(C,0,Q),m(z)},g=async()=>{r?rd({ids:c.map(S=>S.id)}).then(()=>{k(),i(!1),q.success("排序保存成功")}):i(!0)},w=Le({data:c,columns:hu({refetch:k,isSortMode:r}),state:{sorting:a,columnFilters:s,columnVisibility:x,pagination:d},onSortingChange:l,onColumnFiltersChange:n,onColumnVisibilityChange:o,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),getSortedRowModel:We(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Je,{table:w,toolbar:S=>e.jsx(xu,{table:S,refetch:k,saveOrder:g,isSortMode:r}),draggable:r,onDragStart:_,onDragEnd:S=>S.currentTarget.classList.remove("opacity-50"),onDragOver:S=>{S.preventDefault(),S.currentTarget.classList.add("bg-muted")},onDragLeave:S=>S.currentTarget.classList.remove("bg-muted"),onDrop:T,showPagination:!r})}function pu(){const{t:s}=I("knowledge");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(fu,{})})]})]})}const gu=Object.freeze(Object.defineProperty({__proto__:null,default:pu},Symbol.toStringTag,{value:"Module"}));function ju(s,n){const[a,l]=u.useState(s);return u.useEffect(()=>{const r=setTimeout(()=>l(s),n);return()=>{clearTimeout(r)}},[s,n]),a}function At(s,n){if(s.length===0)return{};if(!n)return{"":s};const a={};return s.forEach(l=>{const r=l[n]||"";a[r]||(a[r]=[]),a[r].push(l)}),a}function vu(s,n){const a=JSON.parse(JSON.stringify(s));for(const[l,r]of Object.entries(a))a[l]=r.filter(i=>!n.find(c=>c.value===i.value));return a}function bu(s,n){for(const[,a]of Object.entries(s))if(a.some(l=>n.find(r=>r.value===l.value)))return!0;return!1}const Rr=u.forwardRef(({className:s,...n},a)=>di(r=>r.filtered.count===0)?e.jsx("div",{ref:a,className:y("py-6 text-center text-sm",s),"cmdk-empty":"",role:"presentation",...n}):null);Rr.displayName="CommandEmpty";const lt=u.forwardRef(({value:s,onChange:n,placeholder:a,defaultOptions:l=[],options:r,delay:i,onSearch:c,loadingIndicator:m,emptyIndicator:x,maxSelected:o=Number.MAX_SAFE_INTEGER,onMaxSelected:d,hidePlaceholderWhenSelected:p,disabled:k,groupBy:E,className:f,badgeClassName:_,selectFirstItem:T=!0,creatable:g=!1,triggerSearchOnFocus:w=!1,commandProps:S,inputProps:C,hideClearAllButton:D=!1},z)=>{const Q=u.useRef(null),[A,X]=u.useState(!1),Us=u.useRef(!1),[va,ba]=u.useState(!1),[ee,Bs]=u.useState(s||[]),[Ss,ya]=u.useState(At(l,E)),[fs,Mt]=u.useState(""),Gs=ju(fs,i||500);u.useImperativeHandle(z,()=>({selectedValue:[...ee],input:Q.current,focus:()=>Q.current?.focus()}),[ee]);const mt=u.useCallback(U=>{const ae=ee.filter(Te=>Te.value!==U.value);Bs(ae),n?.(ae)},[n,ee]),el=u.useCallback(U=>{const ae=Q.current;ae&&((U.key==="Delete"||U.key==="Backspace")&&ae.value===""&&ee.length>0&&(ee[ee.length-1].fixed||mt(ee[ee.length-1])),U.key==="Escape"&&ae.blur())},[mt,ee]);u.useEffect(()=>{s&&Bs(s)},[s]),u.useEffect(()=>{if(!r||c)return;const U=At(r||[],E);JSON.stringify(U)!==JSON.stringify(Ss)&&ya(U)},[l,r,E,c,Ss]),u.useEffect(()=>{const U=async()=>{ba(!0);const Te=await c?.(Gs);ya(At(Te||[],E)),ba(!1)};(async()=>{!c||!A||(w&&await U(),Gs&&await U())})()},[Gs,E,A,w]);const sl=()=>{if(!g||bu(Ss,[{value:fs,label:fs}])||ee.find(ae=>ae.value===fs))return;const U=e.jsx(_e,{value:fs,className:"cursor-pointer",onMouseDown:ae=>{ae.preventDefault(),ae.stopPropagation()},onSelect:ae=>{if(ee.length>=o){d?.(ee.length);return}Mt("");const Te=[...ee,{value:ae,label:ae}];Bs(Te),n?.(Te)},children:`Create "${fs}"`});if(!c&&fs.length>0||c&&Gs.length>0&&!va)return U},tl=u.useCallback(()=>{if(x)return c&&!g&&Object.keys(Ss).length===0?e.jsx(_e,{value:"-",disabled:!0,children:x}):e.jsx(Rr,{children:x})},[g,x,c,Ss]),al=u.useMemo(()=>vu(Ss,ee),[Ss,ee]),nl=u.useCallback(()=>{if(S?.filter)return S.filter;if(g)return(U,ae)=>U.toLowerCase().includes(ae.toLowerCase())?1:-1},[g,S?.filter]),rl=u.useCallback(()=>{const U=ee.filter(ae=>ae.fixed);Bs(U),n?.(U)},[n,ee]);return e.jsxs(_s,{...S,onKeyDown:U=>{el(U),S?.onKeyDown?.(U)},className:y("h-auto overflow-visible bg-transparent",S?.className),shouldFilter:S?.shouldFilter!==void 0?S.shouldFilter:!c,filter:nl(),children:[e.jsx("div",{className:y("rounded-md border border-input text-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring ",{"px-3 py-2":ee.length!==0,"cursor-text":!k&&ee.length!==0},f),onClick:()=>{k||Q.current?.focus()},children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[ee.map(U=>e.jsxs(K,{className:y("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",_),"data-fixed":U.fixed,"data-disabled":k||void 0,children:[U.label,e.jsx("button",{className:y("ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",(k||U.fixed)&&"hidden"),onKeyDown:ae=>{ae.key==="Enter"&&mt(U)},onMouseDown:ae=>{ae.preventDefault(),ae.stopPropagation()},onClick:()=>mt(U),children:e.jsx(Gt,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},U.value)),e.jsx(Se.Input,{...C,ref:Q,value:fs,disabled:k,onValueChange:U=>{Mt(U),C?.onValueChange?.(U)},onBlur:U=>{Us.current===!1&&X(!1),C?.onBlur?.(U)},onFocus:U=>{X(!0),w&&c?.(Gs),C?.onFocus?.(U)},placeholder:p&&ee.length!==0?"":a,className:y("flex-1 bg-transparent outline-none placeholder:text-muted-foreground",{"w-full":p,"px-3 py-2":ee.length===0,"ml-1":ee.length!==0},C?.className)}),e.jsx("button",{type:"button",onClick:rl,className:y((D||k||ee.length<1||ee.filter(U=>U.fixed).length===ee.length)&&"hidden"),children:e.jsx(Gt,{})})]})}),e.jsx("div",{className:"relative",children:A&&e.jsx(ws,{className:"absolute top-1 z-10 w-full rounded-md border bg-popover text-popover-foreground shadow-md outline-none animate-in",onMouseLeave:()=>{Us.current=!1},onMouseEnter:()=>{Us.current=!0},onMouseUp:()=>{Q.current?.focus()},children:va?e.jsx(e.Fragment,{children:m}):e.jsxs(e.Fragment,{children:[tl(),sl(),!T&&e.jsx(_e,{value:"-",className:"hidden"}),Object.entries(al).map(([U,ae])=>e.jsx(Fe,{heading:U,className:"h-full overflow-auto",children:e.jsx(e.Fragment,{children:ae.map(Te=>e.jsx(_e,{value:Te.value,disabled:Te.disable,onMouseDown:Ws=>{Ws.preventDefault(),Ws.stopPropagation()},onSelect:()=>{if(ee.length>=o){d?.(ee.length);return}Mt("");const Ws=[...ee,Te];Bs(Ws),n?.(Ws)},className:y("cursor-pointer",Te.disable&&"cursor-default text-muted-foreground"),children:Te.label},Te.value))})},U))]})})})]})});lt.displayName="MultipleSelector";const yu=s=>h.object({id:h.number().optional(),name:h.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 Ft({refetch:s,dialogTrigger:n,defaultValues:a={name:""},type:l="add"}){const{t:r}=I("group"),i=ce({resolver:ue(yu(r)),defaultValues:a,mode:"onChange"}),[c,m]=u.useState(!1),[x,o]=u.useState(!1),d=async p=>{o(!0),Lc(p).then(()=>{q.success(r(l==="edit"?"messages.updateSuccess":"messages.createSuccess")),s&&s(),i.reset(),m(!1)}).finally(()=>{o(!1)})};return e.jsxs(ge,{open:c,onOpenChange:m,children:[e.jsx(Me,{asChild:!0,children:n||e.jsxs(V,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("span",{children:r("form.add")})]})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:r(l==="edit"?"form.edit":"form.create")}),e.jsx(De,{children:r(l==="edit"?"form.editDescription":"form.createDescription")})]}),e.jsx(xe,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(d),className:"space-y-4",children:[e.jsx(v,{control:i.control,name:"name",render:({field:p})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.name")}),e.jsx(N,{children:e.jsx(P,{placeholder:r("form.namePlaceholder"),...p,className:"w-full"})}),e.jsx(F,{children:r("form.nameDescription")}),e.jsx(R,{})]})}),e.jsxs(Oe,{className:"gap-2",children:[e.jsx(dt,{asChild:!0,children:e.jsx(V,{type:"button",variant:"outline",children:r("form.cancel")})}),e.jsxs(V,{type:"submit",disabled:x||!i.formState.isValid,children:[x&&e.jsx(na,{className:"mr-2 h-4 w-4 animate-spin"}),r(l==="edit"?"form.update":"form.create")]})]})]})})]})]})}const Er=u.createContext(void 0);function Nu({children:s,refetch:n}){const[a,l]=u.useState(!1),[r,i]=u.useState(null),[c,m]=u.useState(ye.Shadowsocks);return e.jsx(Er.Provider,{value:{isOpen:a,setIsOpen:l,editingServer:r,setEditingServer:i,serverType:c,setServerType:m,refetch:n},children:s})}function Vr(){const s=u.useContext(Er);if(s===void 0)throw new Error("useServerEdit must be used within a ServerEditProvider");return s}function $t({dialogTrigger:s,value:n,setValue:a,templateType:l}){const{t:r}=I("server");u.useEffect(()=>{console.log(n)},[n]);const[i,c]=u.useState(!1),[m,x]=u.useState(()=>{if(!n||Object.keys(n).length===0)return"";try{return JSON.stringify(n,null,2)}catch{return""}}),[o,d]=u.useState(null),p=g=>{if(!g)return null;try{const w=JSON.parse(g);return typeof w!="object"||w===null?r("network_settings.validation.must_be_object"):null}catch{return r("network_settings.validation.invalid_json")}},k={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"}}}},E=()=>{switch(l){case"tcp":return["tcp","tcp-http"];case"grpc":return["grpc"];case"ws":return["ws"];default:return[]}},f=()=>{const g=p(m||"");if(g){q.error(g);return}try{if(!m){a(null),c(!1);return}a(JSON.parse(m)),c(!1)}catch{q.error(r("network_settings.errors.save_failed"))}},_=g=>{x(g),d(p(g))},T=g=>{const w=k[g];if(w){const S=JSON.stringify(w.content,null,2);x(S),d(null)}};return u.useEffect(()=>{i&&console.log(n)},[i,n]),u.useEffect(()=>{i&&n&&Object.keys(n).length>0&&x(JSON.stringify(n,null,2))},[i,n]),e.jsxs(ge,{open:i,onOpenChange:g=>{!g&&i&&f(),c(g)},children:[e.jsx(Me,{asChild:!0,children:s??e.jsx(J,{variant:"link",children:r("network_settings.edit_protocol")})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsx(ve,{children:e.jsx(je,{children:r("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(g=>e.jsx(J,{variant:"outline",size:"sm",onClick:()=>T(g),children:r("network_settings.use_template",{template:k[g].label})},g))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Cs,{className:`min-h-[200px] font-mono text-sm ${o?"border-red-500 focus-visible:ring-red-500":""}`,value:m,placeholder:E().length>0?r("network_settings.json_config_placeholder_with_template"):r("network_settings.json_config_placeholder"),onChange:g=>_(g.target.value)}),o&&e.jsx("p",{className:"text-sm text-red-500",children:o})]})]}),e.jsxs(Oe,{className:"gap-2",children:[e.jsx(J,{variant:"outline",onClick:()=>c(!1),children:r("common.cancel")}),e.jsx(J,{onClick:f,disabled:!!o,children:r("common.confirm")})]})]})]})}function Nh(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 _u={},wu=Object.freeze(Object.defineProperty({__proto__:null,default:_u},Symbol.toStringTag,{value:"Module"})),_h=wi(wu),La=s=>s.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),Cu=()=>{try{const s=mi.box.keyPair(),n=La(Ta.encodeBase64(s.secretKey)),a=La(Ta.encodeBase64(s.publicKey));return{privateKey:n,publicKey:a}}catch(s){throw console.error("Error generating x25519 key pair:",s),s}},Su=()=>{try{return Cu()}catch(s){throw console.error("Error generating key pair:",s),s}},ku=s=>{const n=new Uint8Array(Math.ceil(s/2));return window.crypto.getRandomValues(n),Array.from(n).map(a=>a.toString(16).padStart(2,"0")).join("").substring(0,s)},Tu=()=>{const s=Math.floor(Math.random()*8)*2+2;return ku(s)},Du=h.object({cipher:h.string().default("aes-128-gcm"),obfs:h.string().default("0"),obfs_settings:h.object({path:h.string().default(""),host:h.string().default("")}).default({})}),Pu=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({})}),Ru=h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({})}),Eu=h.object({version:h.coerce.number().default(2),alpn:h.string().default("h2"),obfs:h.object({open:h.coerce.boolean().default(!1),type:h.string().default("salamander"),password:h.string().default("")}).default({}),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),bandwidth:h.object({up:h.string().default(""),down:h.string().default("")}).default({})}),Vu=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),reality_settings:h.object({server_port:h.coerce.number().default(443),server_name:h.string().default(""),allow_insecure:h.boolean().default(!1),public_key:h.string().default(""),private_key:h.string().default(""),short_id:h.string().default("")}).default({}),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({}),flow:h.string().default("")}),ls={shadowsocks:{schema:Du,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:Pu,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},trojan:{schema:Ru,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},hysteria:{schema:Eu,versions:["1","2"],alpnOptions:["hysteria","http/1.1","h2","h3"]},vless:{schema:Vu,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"]}},Iu=({serverType:s,value:n,onChange:a})=>{const{t:l}=I("server"),r=s?ls[s]:null,i=r?.schema||h.record(h.any()),c=s?i.parse({}):{},m=ce({resolver:ue(i),defaultValues:c,mode:"onChange"});if(u.useEffect(()=>{if(!n||Object.keys(n).length===0){if(s){const f=i.parse({});m.reset(f)}}else m.reset(n)},[s,n,a,m,i]),u.useEffect(()=>{const f=m.watch(_=>{a(_)});return()=>f.unsubscribe()},[m,a]),!s||!r)return null;const E={shadowsocks:()=>e.jsxs(e.Fragment,{children:[e.jsx(v,{control:m.control,name:"cipher",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.shadowsocks.cipher.label")}),e.jsx(N,{children:e.jsxs(W,{onValueChange:f.onChange,value:f.value,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.shadowsocks.cipher.placeholder")})}),e.jsx(G,{children:e.jsx(ps,{children:ls.shadowsocks.ciphers.map(_=>e.jsx($,{value:_,children:_},_))})})]})})]})}),e.jsx(v,{control:m.control,name:"obfs",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.shadowsocks.obfs.label")}),e.jsx(N,{children:e.jsxs(W,{onValueChange:f.onChange,value:f.value,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.shadowsocks.obfs.placeholder")})}),e.jsx(G,{children:e.jsxs(ps,{children:[e.jsx($,{value:"0",children:l("dynamic_form.shadowsocks.obfs.none")}),e.jsx($,{value:"http",children:l("dynamic_form.shadowsocks.obfs.http")})]})})]})})]})}),m.watch("obfs")==="http"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:m.control,name:"obfs_settings.path",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(N,{children:e.jsx(P,{type:"text",placeholder:l("dynamic_form.shadowsocks.obfs_settings.path"),...f})}),e.jsx(R,{})]})}),e.jsx(v,{control:m.control,name:"obfs_settings.host",render:({field:f})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(N,{children:e.jsx(P,{type:"text",placeholder:l("dynamic_form.shadowsocks.obfs_settings.host"),...f})}),e.jsx(R,{})]})})]})]}),vmess:()=>e.jsxs(e.Fragment,{children:[e.jsx(v,{control:m.control,name:"tls",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.vmess.tls.label")}),e.jsx(N,{children:e.jsxs(W,{value:f.value?.toString(),onValueChange:_=>f.onChange(Number(_)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.vmess.tls.placeholder")})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:l("dynamic_form.vmess.tls.disabled")}),e.jsx($,{value:"1",children:l("dynamic_form.vmess.tls.enabled")})]})]})})]})}),m.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:m.control,name:"tls_settings.server_name",render:({field:f})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:l("dynamic_form.vmess.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:l("dynamic_form.vmess.tls_settings.server_name.placeholder"),...f})})]})}),e.jsx(v,{control:m.control,name:"tls_settings.allow_insecure",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.vmess.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value,onCheckedChange:f.onChange})})})]})})]}),e.jsx(v,{control:m.control,name:"network",render:({field:f})=>e.jsxs(j,{children:[e.jsxs(b,{children:[l("dynamic_form.vmess.network.label"),e.jsx($t,{value:m.watch("network_settings"),setValue:_=>m.setValue("network_settings",_),templateType:m.watch("network")})]}),e.jsx(N,{children:e.jsxs(W,{onValueChange:f.onChange,value:f.value,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.vmess.network.placeholder")})}),e.jsx(G,{children:e.jsx(ps,{children:ls.vmess.networkOptions.map(_=>e.jsx($,{value:_.value,className:"cursor-pointer",children:_.label},_.value))})})]})})]})})]}),trojan:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:m.control,name:"server_name",render:({field:f})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:l("dynamic_form.trojan.server_name.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:l("dynamic_form.trojan.server_name.placeholder"),...f,value:f.value||""})})]})}),e.jsx(v,{control:m.control,name:"allow_insecure",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.trojan.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value||!1,onCheckedChange:f.onChange})})})]})})]}),e.jsx(v,{control:m.control,name:"network",render:({field:f})=>e.jsxs(j,{children:[e.jsxs(b,{children:[l("dynamic_form.trojan.network.label"),e.jsx($t,{value:m.watch("network_settings")||{},setValue:_=>m.setValue("network_settings",_),templateType:m.watch("network")||"tcp"})]}),e.jsx(N,{children:e.jsxs(W,{onValueChange:f.onChange,value:f.value||"tcp",children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.trojan.network.placeholder")})}),e.jsx(G,{children:e.jsx(ps,{children:ls.trojan.networkOptions.map(_=>e.jsx($,{value:_.value,className:"cursor-pointer",children:_.label},_.value))})})]})})]})})]}),hysteria:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:m.control,name:"version",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:l("dynamic_form.hysteria.version.label")}),e.jsx(N,{children:e.jsxs(W,{value:(f.value||2).toString(),onValueChange:_=>f.onChange(Number(_)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.hysteria.version.placeholder")})}),e.jsx(G,{children:e.jsx(ps,{children:ls.hysteria.versions.map(_=>e.jsxs($,{value:_,className:"cursor-pointer",children:["V",_]},_))})})]})})]})}),m.watch("version")==1&&e.jsx(v,{control:m.control,name:"alpn",render:({field:f})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:l("dynamic_form.hysteria.alpn.label")}),e.jsx(N,{children:e.jsxs(W,{value:f.value||"h2",onValueChange:f.onChange,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.hysteria.alpn.placeholder")})}),e.jsx(G,{children:e.jsx(ps,{children:ls.hysteria.alpnOptions.map(_=>e.jsx($,{value:_,children:_},_))})})]})})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:m.control,name:"obfs.open",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.hysteria.obfs.label")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value||!1,onCheckedChange:f.onChange})})})]})}),!!m.watch("obfs.open")&&e.jsxs(e.Fragment,{children:[m.watch("version")=="2"&&e.jsx(v,{control:m.control,name:"obfs.type",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:l("dynamic_form.hysteria.obfs.type.label")}),e.jsx(N,{children:e.jsxs(W,{value:f.value||"salamander",onValueChange:f.onChange,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.hysteria.obfs.type.placeholder")})}),e.jsx(G,{children:e.jsx(ps,{children:e.jsx($,{value:"salamander",children:l("dynamic_form.hysteria.obfs.type.salamander")})})})]})})]})}),e.jsx(v,{control:m.control,name:"obfs.password",render:({field:f})=>e.jsxs(j,{className:m.watch("version")==2?"w-full":"flex-[2]",children:[e.jsx(b,{children:l("dynamic_form.hysteria.obfs.password.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(P,{placeholder:l("dynamic_form.hysteria.obfs.password.placeholder"),...f,value:f.value||"",className:"pr-9"})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const _="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",T=Array.from(crypto.getRandomValues(new Uint8Array(16))).map(g=>_[g%_.length]).join("");m.setValue("obfs.password",T),q.success(l("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(Ne,{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(v,{control:m.control,name:"tls.server_name",render:({field:f})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:l("dynamic_form.hysteria.tls.server_name.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:l("dynamic_form.hysteria.tls.server_name.placeholder"),...f,value:f.value||""})})]})}),e.jsx(v,{control:m.control,name:"tls.allow_insecure",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.hysteria.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value||!1,onCheckedChange:f.onChange})})})]})})]}),e.jsx(v,{control:m.control,name:"bandwidth.up",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.hysteria.bandwidth.up.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(P,{type:"number",placeholder:l("dynamic_form.hysteria.bandwidth.up.placeholder")+(m.watch("version")==2?l("dynamic_form.hysteria.bandwidth.up.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...f,value:f.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:l("dynamic_form.hysteria.bandwidth.up.suffix")})})]})]})}),e.jsx(v,{control:m.control,name:"bandwidth.down",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.hysteria.bandwidth.down.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(P,{type:"number",placeholder:l("dynamic_form.hysteria.bandwidth.down.placeholder")+(m.watch("version")==2?l("dynamic_form.hysteria.bandwidth.down.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...f,value:f.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:l("dynamic_form.hysteria.bandwidth.down.suffix")})})]})]})})]}),vless:()=>e.jsxs(e.Fragment,{children:[e.jsx(v,{control:m.control,name:"tls",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.vless.tls.label")}),e.jsx(N,{children:e.jsxs(W,{value:f.value?.toString(),onValueChange:_=>f.onChange(Number(_)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.vless.tls.placeholder")})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:l("dynamic_form.vless.tls.none")}),e.jsx($,{value:"1",children:l("dynamic_form.vless.tls.tls")}),e.jsx($,{value:"2",children:l("dynamic_form.vless.tls.reality")})]})]})})]})}),m.watch("tls")=="1"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:m.control,name:"tls_settings.server_name",render:({field:f})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:l("dynamic_form.vless.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:l("dynamic_form.vless.tls_settings.server_name.placeholder"),...f})})]})}),e.jsx(v,{control:m.control,name:"tls_settings.allow_insecure",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.vless.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value,onCheckedChange:f.onChange})})})]})})]}),m.watch("tls")==2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:m.control,name:"reality_settings.server_name",render:({field:f})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:l("dynamic_form.vless.reality_settings.server_name.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:l("dynamic_form.vless.reality_settings.server_name.placeholder"),...f})})]})}),e.jsx(v,{control:m.control,name:"reality_settings.server_port",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:l("dynamic_form.vless.reality_settings.server_port.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:l("dynamic_form.vless.reality_settings.server_port.placeholder"),...f})})]})}),e.jsx(v,{control:m.control,name:"reality_settings.allow_insecure",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.vless.reality_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(H,{checked:f.value,onCheckedChange:f.onChange})})})]})})]}),e.jsx("div",{className:"flex items-end gap-2",children:e.jsx(v,{control:m.control,name:"reality_settings.private_key",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:l("dynamic_form.vless.reality_settings.private_key.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(P,{...f,className:"pr-9"})}),e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{try{const _=Su();m.setValue("reality_settings.private_key",_.privateKey),m.setValue("reality_settings.public_key",_.publicKey),q.success(l("dynamic_form.vless.reality_settings.key_pair.success"))}catch{q.error(l("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(Ne,{icon:"ion:key-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(yt,{children:e.jsx(te,{children:e.jsx("p",{children:l("dynamic_form.vless.reality_settings.key_pair.generate")})})})]})]})]})})}),e.jsx(v,{control:m.control,name:"reality_settings.public_key",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.vless.reality_settings.public_key.label")}),e.jsx(N,{children:e.jsx(P,{...f})})]})}),e.jsx(v,{control:m.control,name:"reality_settings.short_id",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.vless.reality_settings.short_id.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(P,{...f,className:"pr-9",placeholder:l("dynamic_form.vless.reality_settings.short_id.placeholder")})}),e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const _=Tu();m.setValue("reality_settings.short_id",_),q.success(l("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(Ne,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(yt,{children:e.jsx(te,{children:e.jsx("p",{children:l("dynamic_form.vless.reality_settings.short_id.generate")})})})]})]}),e.jsx(F,{className:"text-xs text-muted-foreground",children:l("dynamic_form.vless.reality_settings.short_id.description")})]})})]}),e.jsx(v,{control:m.control,name:"network",render:({field:f})=>e.jsxs(j,{children:[e.jsxs(b,{children:[l("dynamic_form.vless.network.label"),e.jsx($t,{value:m.watch("network_settings"),setValue:_=>m.setValue("network_settings",_),templateType:m.watch("network")})]}),e.jsx(N,{children:e.jsxs(W,{onValueChange:f.onChange,value:f.value,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.vless.network.placeholder")})}),e.jsx(G,{children:e.jsx(ps,{children:ls.vless.networkOptions.map(_=>e.jsx($,{value:_.value,className:"cursor-pointer",children:_.label},_.value))})})]})})]})}),e.jsx(v,{control:m.control,name:"flow",render:({field:f})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dynamic_form.vless.flow.label")}),e.jsx(N,{children:e.jsxs(W,{onValueChange:_=>f.onChange(_==="none"?null:_),value:f.value||"none",children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dynamic_form.vless.flow.placeholder")})}),e.jsx(G,{children:ls.vless.flowOptions.map(_=>e.jsx($,{value:_,children:_},_))})]})})]})})]})};return e.jsx(ie,{children:E[s]?.()})},Fu=h.object({id:h.number().optional().nullable(),code:h.string().optional(),name:h.string().min(1,"form.name.error"),rate:h.string().min(1,"form.rate.error"),tags:h.array(h.string()).default([]),excludes:h.array(h.string()).default([]),ips:h.array(h.string()).default([]),group_ids:h.array(h.string()).default([]),host:h.string().min(1,"form.host.error"),port:h.string().min(1,"form.port.error"),server_port:h.string().min(1,"form.server_port.error"),parent_id:h.string().default("0").nullable(),route_ids:h.array(h.string()).default([]),protocol_settings:h.record(h.any()).default({}).nullable()}),ht={id:null,code:"",name:"",rate:"1",tags:[],excludes:[],ips:[],group_ids:[],host:"",port:"",server_port:"",parent_id:"0",route_ids:[],protocol_settings:null};function Mu(){const{t:s}=I("server"),{isOpen:n,setIsOpen:a,editingServer:l,setEditingServer:r,serverType:i,setServerType:c,refetch:m}=Vr(),[x,o]=u.useState([]),[d,p]=u.useState([]),[k,E]=u.useState([]),f=ce({resolver:ue(Fu),defaultValues:ht,mode:"onChange"});u.useEffect(()=>{_()},[n]),u.useEffect(()=>{l?.type&&l.type!==i&&c(l.type)},[l,i,c]),u.useEffect(()=>{l?l.type===i&&f.reset({...ht,...l}):f.reset({...ht,protocol_settings:ls[i].schema.parse({})})},[l,f,i]);const _=async()=>{if(!n)return;const[C,D,z]=await Promise.all([It(),hr(),xr()]);o(C.data?.map(Q=>({label:Q.name,value:Q.id.toString()}))||[]),p(D.data?.map(Q=>({label:Q.remarks,value:Q.id.toString()}))||[]),E(z.data||[])},T=u.useMemo(()=>k?.filter(C=>(C.parent_id===0||C.parent_id===null)&&C.type===i&&C.id!==f.watch("id")),[i,k,f]),g=()=>e.jsxs(ys,{children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(V,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(is,{align:"start",children:e.jsx(nc,{children:Ts.map(({type:C,label:D})=>e.jsx(fe,{onClick:()=>{c(C),a(!0)},className:"cursor-pointer",children:e.jsx(K,{variant:"outline",className:"text-white",style:{background:os[C]},children:D})},C))})})]}),w=()=>{a(!1),r(null),f.reset(ht)},S=async()=>{const C=f.getValues();(await Ic({...C,type:i})).data&&(w(),q.success(s("form.success")),m())};return e.jsxs(ge,{open:n,onOpenChange:w,children:[g(),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:s(l?"form.edit_node":"form.new_node")}),e.jsx(De,{})]}),e.jsxs(xe,{...f,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:f.control,name:"name",render:({field:C})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:s("form.name.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("form.name.placeholder"),...C})}),e.jsx(R,{})]})}),e.jsx(v,{control:f.control,name:"rate",render:({field:C})=>e.jsxs(j,{className:"flex-[1]",children:[e.jsx(b,{children:s("form.rate.label")}),e.jsx("div",{className:"relative flex",children:e.jsx(N,{children:e.jsx(P,{type:"number",min:"0",step:"0.1",...C})})}),e.jsx(R,{})]})})]}),e.jsx(v,{control:f.control,name:"code",render:({field:C})=>e.jsxs(j,{children:[e.jsxs(b,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(N,{children:e.jsx(P,{placeholder:s("form.code.placeholder"),...C,value:C.value||""})}),e.jsx(R,{})]})}),e.jsx(v,{control:f.control,name:"tags",render:({field:C})=>e.jsxs(j,{children:[e.jsx(b,{children:s("form.tags.label")}),e.jsx(N,{children:e.jsx(xa,{value:C.value,onChange:C.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(R,{})]})}),e.jsx(v,{control:f.control,name:"group_ids",render:({field:C})=>e.jsxs(j,{children:[e.jsxs(b,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(Ft,{dialogTrigger:e.jsx(V,{variant:"link",children:s("form.groups.add")}),refetch:_})]}),e.jsx(N,{children:e.jsx(lt,{options:x,onChange:D=>C.onChange(D.map(z=>z.value)),value:x?.filter(D=>C.value.includes(D.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(R,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:f.control,name:"host",render:({field:C})=>e.jsxs(j,{children:[e.jsx(b,{children:s("form.host.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:s("form.host.placeholder"),...C})}),e.jsx(R,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(v,{control:f.control,name:"port",render:({field:C})=>e.jsxs(j,{className:"flex-1",children:[e.jsxs(b,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(Ne,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(yt,{children:e.jsx(te,{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(N,{children:e.jsx(P,{placeholder:s("form.port.placeholder"),...C})}),e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(V,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const D=C.value;D&&f.setValue("server_port",D)},children:e.jsx(Ne,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(te,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(R,{})]})}),e.jsx(v,{control:f.control,name:"server_port",render:({field:C})=>e.jsxs(j,{className:"flex-1",children:[e.jsxs(b,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(Ne,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(yt,{children:e.jsx(te,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(N,{children:e.jsx(P,{placeholder:s("form.server_port.placeholder"),...C})}),e.jsx(R,{})]})})]})]}),n&&e.jsx(Iu,{serverType:i,value:f.watch("protocol_settings"),onChange:C=>f.setValue("protocol_settings",C,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(v,{control:f.control,name:"parent_id",render:({field:C})=>e.jsxs(j,{children:[e.jsx(b,{children:s("form.parent.label")}),e.jsxs(W,{onValueChange:C.onChange,value:C.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:s("form.parent.none")}),T?.map(D=>e.jsx($,{value:D.id.toString(),className:"cursor-pointer",children:D.name},D.id))]})]}),e.jsx(R,{})]})}),e.jsx(v,{control:f.control,name:"route_ids",render:({field:C})=>e.jsxs(j,{children:[e.jsx(b,{children:s("form.route.label")}),e.jsx(N,{children:e.jsx(lt,{options:d,onChange:D=>C.onChange(D.map(z=>z.value)),value:d?.filter(D=>C.value.includes(D.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(R,{})]})})]}),e.jsxs(Oe,{className:"mt-6",children:[e.jsx(V,{type:"button",variant:"outline",onClick:w,children:s("form.cancel")}),e.jsx(V,{type:"submit",onClick:S,children:s("form.submit")})]})]})]})]})}function Aa({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(V,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(ct,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(i=>r.has(i.value)).map(i=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ye,{className:"w-[200px] p-0",align:"start",children:e.jsxs(_s,{children:[e.jsx(Vs,{placeholder:n}),e.jsxs(ws,{children:[e.jsx(Is,{children:"No results found."}),e.jsx(Fe,{children:a.map(i=>{const c=r.has(i.value);return e.jsxs(_e,{onSelect:()=>{c?r.delete(i.value):r.add(i.value);const m=Array.from(r);s?.setFilterValue(m.length?m:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:y("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ps,{className:y("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}),l?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(i.value)})]},i.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Fe,{children:e.jsx(_e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const Ou=[{value:ye.Shadowsocks,label:Ts.find(s=>s.type===ye.Shadowsocks)?.label,color:os[ye.Shadowsocks]},{value:ye.Vmess,label:Ts.find(s=>s.type===ye.Vmess)?.label,color:os[ye.Vmess]},{value:ye.Trojan,label:Ts.find(s=>s.type===ye.Trojan)?.label,color:os[ye.Trojan]},{value:ye.Hysteria,label:Ts.find(s=>s.type===ye.Hysteria)?.label,color:os[ye.Hysteria]},{value:ye.Vless,label:Ts.find(s=>s.type===ye.Vless)?.label,color:os[ye.Vless]}];function zu({table:s,saveOrder:n,isSortMode:a,groups:l}){const r=s.getState().columnFilters.length>0,{t:i}=I("server"),c=l.map(m=>({label:m,value:m}));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:[!a&&e.jsxs(e.Fragment,{children:[e.jsx(Mu,{}),e.jsx(P,{placeholder:i("toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:m=>s.getColumn("name")?.setFilterValue(m.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(Aa,{column:s.getColumn("type"),title:i("toolbar.type"),options:Ou}),s.getColumn("groups")&&e.jsx(Aa,{column:s.getColumn("groups"),title:i("columns.groups.title"),options:c})]}),r&&e.jsxs(V,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[i("toolbar.reset"),e.jsx(ze,{className:"ml-2 h-4 w-4"})]})]}),a&&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(V,{variant:a?"default":"outline",onClick:n,size:"sm",children:i(a?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const ot=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"})}),ft={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"},Lu=s=>{const{t:n}=I("server");return[{id:"drag-handle",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Pt,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.nodeId")}),cell:({row:a})=>{const l=a.getValue("id"),r=a.original.code;return e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(K,{variant:"outline",className:y("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:os[a.original.type]},children:[e.jsx(zn,{className:"size-3"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:r??l}),a.original.parent?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-muted-foreground/30",children:"→"}),e.jsx("span",{children:a.original.parent?.code||a.original.parent?.id})]}):""]})]}),e.jsx(V,{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(),wt(r||l.toString()).then(()=>{q.success(n("common:copy.success"))})},children:e.jsx(Da,{className:"size-3"})})]})}),e.jsxs(te,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[Ts.find(i=>i.type===a.original.type)?.label,a.original.parent_id?" (子节点)":""]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r?"点击括号内容或复制按钮可复制节点代码":"点击复制按钮可复制节点ID"})]})]})})},size:200,enableSorting:!0},{accessorKey:"show",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.show")}),cell:({row:a})=>{const[l,r]=u.useState(!!a.getValue("show"));return e.jsx(H,{checked:l,onCheckedChange:async i=>{r(i),Oc({id:a.original.id,type:a.original.type,show:i?1:0}).catch(()=>{r(!i),s()})},style:{backgroundColor:l?os[a.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx(M,{column:a,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:y("h-2.5 w-2.5 rounded-full",ft[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:y("h-2.5 w-2.5 rounded-full",ft[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:y("h-2.5 w-2.5 rounded-full",ft[2])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.2")})]})]})})}),cell:({row:a})=>e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:y("size-2.5 flex-shrink-0 rounded-full transition-all duration-200",ft[a.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:a.getValue("name")})]})}),e.jsx(te,{children:e.jsx("p",{className:"font-medium",children:n(`columns.status.${a.original.available_status}`)})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.address")}),cell:({row:a})=>{const l=`${a.original.host}:${a.original.port}`,r=a.original.port!==a.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:[a.original.host,":",a.original.port]})}),r&&e.jsxs("span",{className:"whitespace-nowrap text-[0.7rem] tracking-tight text-muted-foreground/40",children:["(",n("columns.internalPort")," ",a.original.server_port,")"]})]}),e.jsx("div",{className:"absolute right-0 top-0",children:e.jsx(ie,{delayDuration:0,children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(V,{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(),wt(l).then(()=>{q.success(n("common:copy.success"))})},children:e.jsx(Da,{className:"size-3"})})}),e.jsx(te,{side:"top",sideOffset:10,children:n("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.onlineUsers.title"),tooltip:n("columns.onlineUsers.tooltip")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(ot,{className:"size-4"}),e.jsx("span",{className:"font-medium",children:a.getValue("online")})]}),size:80,enableSorting:!0,enableHiding:!0},{accessorKey:"rate",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.rate.title"),tooltip:n("columns.rate.tooltip")}),cell:({row:a})=>e.jsxs(K,{variant:"secondary",className:"font-medium",children:[a.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"groups",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.groups.title"),tooltip:n("columns.groups.tooltip")}),cell:({row:a})=>{const l=a.getValue("groups")||[];return e.jsx("div",{className:"flex min-w-[300px] max-w-[600px] flex-wrap items-center gap-1.5",children:l.length>0?l.map((r,i)=>e.jsx(K,{variant:"secondary",className:y("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:r.name},i)):e.jsx("span",{className:"text-sm text-muted-foreground",children:n("columns.groups.empty")})})},enableSorting:!1,size:600,filterFn:(a,l,r)=>{const i=a.getValue(l);return i?r.some(c=>i.includes(c)):!1}},{accessorKey:"type",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.type")}),cell:({row:a})=>{const l=a.getValue("type");return e.jsx(K,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:os[l]},children:l})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:a})=>e.jsx(M,{className:"justify-end",column:a,title:n("columns.actions")}),cell:({row:a})=>{const{setIsOpen:l,setEditingServer:r,setServerType:i}=Vr();return e.jsx("div",{className:"flex justify-center",children:e.jsxs(ys,{modal:!1,children:[e.jsx(Ns,{asChild:!0,children:e.jsx(V,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Nt,{className:"size-4"})})}),e.jsxs(is,{align:"end",className:"w-40",children:[e.jsx(fe,{className:"cursor-pointer",onClick:()=>{i(a.original.type),r(a.original),l(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(ui,{className:"mr-2 size-4"}),n("columns.actions_dropdown.edit")]})}),e.jsxs(fe,{className:"cursor-pointer",onClick:async()=>{Mc({id:a.original.id}).then(({data:c})=>{c&&(q.success(n("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx(xi,{className:"mr-2 size-4"}),n("columns.actions_dropdown.copy")]}),e.jsx(at,{}),e.jsx(fe,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:c=>c.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()=>{Fc({id:a.original.id}).then(({data:c})=>{c&&(q.success(n("columns.actions_dropdown.delete_success")),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(ds,{className:"mr-2 size-4"}),n("columns.actions_dropdown.delete.confirm")]})})})]})]})})},size:50}]};function Au(){const[s,n]=u.useState({}),[a,l]=u.useState({"drag-handle":!1}),[r,i]=u.useState([]),[c,m]=u.useState({pageSize:500,pageIndex:0}),[x,o]=u.useState([]),[d,p]=u.useState(!1),[k,E]=u.useState({}),[f,_]=u.useState([]),{refetch:T}=se({queryKey:["nodeList"],queryFn:async()=>{const{data:z}=await xr();return _(z),z}}),g=u.useMemo(()=>{const z=new Set;return f.forEach(Q=>{Q.groups&&Q.groups.forEach(A=>z.add(A.name))}),Array.from(z).sort()},[f]);u.useEffect(()=>{l({"drag-handle":d,show:!d,host:!d,online:!d,rate:!d,groups:!d,type:!1,actions:!d}),E({name:d?2e3:200}),m({pageSize:d?99999:500,pageIndex:0})},[d]);const w=(z,Q)=>{d&&(z.dataTransfer.setData("text/plain",Q.toString()),z.currentTarget.classList.add("opacity-50"))},S=(z,Q)=>{if(!d)return;z.preventDefault(),z.currentTarget.classList.remove("bg-muted");const A=parseInt(z.dataTransfer.getData("text/plain"));if(A===Q)return;const X=[...f],[Us]=X.splice(A,1);X.splice(Q,0,Us),_(X)},C=async()=>{if(!d){p(!0);return}const z=f?.map((Q,A)=>({id:Q.id,order:A+1}));zc(z).then(()=>{q.success("排序保存成功"),p(!1),T()}).finally(()=>{p(!1)})},D=Le({data:f||[],columns:Lu(T),state:{sorting:x,columnVisibility:a,rowSelection:s,columnFilters:r,columnSizing:k,pagination:c},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:l,onColumnSizingChange:E,onPaginationChange:m,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),getSortedRowModel:We(),getFacetedRowModel:ms(),getFacetedUniqueValues:us(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Nu,{refetch:T,children:e.jsx("div",{className:"space-y-4",children:e.jsx(Je,{table:D,toolbar:z=>e.jsx(zu,{table:z,refetch:T,saveOrder:C,isSortMode:d,groups:g}),draggable:d,onDragStart:w,onDragEnd:z=>z.currentTarget.classList.remove("opacity-50"),onDragOver:z=>{z.preventDefault(),z.currentTarget.classList.add("bg-muted")},onDragLeave:z=>z.currentTarget.classList.remove("bg-muted"),onDrop:S,showPagination:!d})})})}function $u(){const{t:s}=I("server");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(Au,{})})]})]})}const qu=Object.freeze(Object.defineProperty({__proto__:null,default:$u},Symbol.toStringTag,{value:"Module"}));function Ku({table:s,refetch:n}){const a=s.getState().columnFilters.length>0,{t:l}=I("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(Ft,{refetch:n}),e.jsx(P,{placeholder:l("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:r=>s.getColumn("name")?.setFilterValue(r.target.value),className:y("h-8 w-[150px] lg:w-[250px]",a&&"border-primary/50 ring-primary/20")}),a&&e.jsxs(V,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("toolbar.reset"),e.jsx(ze,{className:"ml-2 h-4 w-4"})]})]})})}const Hu=s=>{const{t:n}=I("group");return[{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.id")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:a.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.name")}),cell:({row:a})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium",children:a.getValue("name")})})},{accessorKey:"users_count",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.usersCount")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(ot,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:a.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"server_count",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.serverCount")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(zn,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:a.getValue("server_count")})]}),enableSorting:!0,size:8e3},{id:"actions",header:({column:a})=>e.jsx(M,{className:"justify-end",column:a,title:n("columns.actions")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Ft,{defaultValues:a.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Es,{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()=>{Ac({id:a.original.id}).then(({data:l})=>{l&&(q.success(n("messages.updateSuccess")),s())})},children:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{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 Uu(){const[s,n]=u.useState({}),[a,l]=u.useState({}),[r,i]=u.useState([]),[c,m]=u.useState([]),{data:x,refetch:o,isLoading:d}=se({queryKey:["serverGroupList"],queryFn:async()=>{const{data:k}=await It();return k}}),p=Le({data:x||[],columns:Hu(o),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:i,onColumnVisibilityChange:l,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),getSortedRowModel:We(),getFacetedRowModel:ms(),getFacetedUniqueValues:us(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Je,{table:p,toolbar:k=>e.jsx(Ku,{table:k,refetch:o}),isLoading:d})}function Bu(){const{t:s}=I("group");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(Uu,{})})]})]})}const Gu=Object.freeze(Object.defineProperty({__proto__:null,default:Bu},Symbol.toStringTag,{value:"Module"})),Wu=s=>h.object({remarks:h.string().min(1,s("form.validation.remarks")),match:h.array(h.string()),action:h.enum(["block","dns"]),action_value:h.string().optional()});function Ir({refetch:s,dialogTrigger:n,defaultValues:a={remarks:"",match:[],action:"block",action_value:""},type:l="add"}){const{t:r}=I("route"),i=ce({resolver:ue(Wu(r)),defaultValues:a,mode:"onChange"}),[c,m]=u.useState(!1);return e.jsxs(ge,{open:c,onOpenChange:m,children:[e.jsx(Me,{asChild:!0,children:n||e.jsxs(V,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ne,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add")})]})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:r(l==="edit"?"form.edit":"form.create")}),e.jsx(De,{})]}),e.jsxs(xe,{...i,children:[e.jsx(v,{control:i.control,name:"remarks",render:({field:x})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(P,{type:"text",placeholder:r("form.remarksPlaceholder"),...x})})}),e.jsx(R,{})]})}),e.jsx(v,{control:i.control,name:"match",render:({field:x})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(Cs,{className:"min-h-[120px]",placeholder:r("form.matchPlaceholder"),value:x.value.join(` `),onChange:o=>{x.onChange(o.target.value.split(` -`))}})})}),e.jsx(P,{})]})}),e.jsx(j,{control:i.control,name:"action",render:({field:x})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsxs(W,{onValueChange:x.onChange,defaultValue:x.value,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:r("form.actionPlaceholder")})}),e.jsxs(G,{children:[e.jsx($,{value:"block",children:r("actions.block")}),e.jsx($,{value:"dns",children:r("actions.dns")})]})]})})}),e.jsx(P,{})]})}),i.watch("action")==="dns"&&e.jsx(j,{control:i.control,name:"action_value",render:({field:x})=>e.jsxs(g,{children:[e.jsx(v,{children:r("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:r("form.dnsPlaceholder"),...x})})})]})}),e.jsxs(Me,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(E,{variant:"outline",children:r("form.cancel")})}),e.jsx(E,{type:"submit",onClick:()=>{$c(i.getValues()).then(({data:x})=>{x&&(u(!1),s&&s(),toast.success(r(l==="edit"?"messages.updateSuccess":"messages.createSuccess")),i.reset())})},children:r("form.submit")})]})]})]})]})}function Yu({table:s,refetch:n}){const a=s.getState().columnFilters.length>0,{t:l}=I("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(Ir,{refetch:n}),e.jsx(T,{placeholder:l("toolbar.searchPlaceholder"),value:s.getColumn("remarks")?.getFilterValue()??"",onChange:r=>s.getColumn("remarks")?.setFilterValue(r.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),a&&e.jsxs(E,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("toolbar.reset"),e.jsx(Oe,{className:"ml-2 h-4 w-4"})]})]})})}function Ju({columns:s,data:n,refetch:a}){const[l,r]=m.useState({}),[i,c]=m.useState({}),[u,x]=m.useState([]),[o,d]=m.useState([]),p=ze({data:n,columns:s,state:{sorting:o,columnVisibility:i,rowSelection:l,columnFilters:u},enableRowSelection:!0,onRowSelectionChange:r,onSortingChange:d,onColumnFiltersChange:x,onColumnVisibilityChange:c,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),getSortedRowModel:Ge(),getFacetedRowModel:ds(),getFacetedUniqueValues:ms(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Ye,{table:p,toolbar:k=>e.jsx(Yu,{table:k,refetch:a})})}const Qu=s=>{const{t:n}=I("route"),a={block:{icon:hi,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:fi,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:l})=>e.jsx(M,{column:l,title:n("columns.id")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:l.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:l})=>e.jsx(M,{column:l,title:n("columns.remarks")}),cell:({row:l})=>{const r=l.original.match?.length||0;return 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:n("columns.matchRules",{count:r})})})},enableHiding:!1,enableSorting:!1},{accessorKey:"action",header:({column:l})=>e.jsx(M,{column:l,title:n("columns.action")}),cell:({row:l})=>{const r=l.getValue("action"),i=a[r]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(K,{variant:a[r]?.variant||"default",className:y("flex items-center gap-1.5 px-3 py-1 capitalize",a[r]?.className),children:[i&&e.jsx(i,{className:"h-3.5 w-3.5"}),n(`actions.${r}`)]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:n("columns.actions")}),cell:({row:l})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Ir,{defaultValues:l.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(E,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Es,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(Je,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{qc({id:l.original.id}).then(({data:r})=>{r&&(q.success(n("messages.deleteSuccess")),s())})},children:e.jsxs(E,{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 Zu(){const{t:s}=I("route"),[n,a]=m.useState([]);function l(){hr().then(({data:r})=>{a(r)})}return m.useEffect(()=>{l()},[]),e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(Ju,{data:n,columns:Qu(l),refetch:l})})]})]})}const Xu=Object.freeze(Object.defineProperty({__proto__:null,default:Zu},Symbol.toStringTag,{value:"Module"})),Fr=m.createContext(void 0);function ex({children:s,refreshData:n}){const[a,l]=m.useState(!1),[r,i]=m.useState(null);return e.jsx(Fr.Provider,{value:{isOpen:a,setIsOpen:l,editingPlan:r,setEditingPlan:i,refreshData:n},children:s})}function ha(){const s=m.useContext(Fr);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function sx({table:s,saveOrder:n,isSortMode:a}){const{setIsOpen:l}=ha(),{t:r}=I("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(E,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>l(!0),children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("div",{children:r("plan.add")})]}),e.jsx(T,{placeholder:r("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(E,{variant:a?"default":"outline",onClick:n,size:"sm",children:r(a?"plan.sort.save":"plan.sort.edit")})})]})}const $a={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"}},tx=s=>{const{t:n}=I("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(Pt,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.id")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:a.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.show")}),cell:({row:a})=>e.jsx(H,{defaultChecked:a.getValue("show"),onCheckedChange:l=>{Lt({id:a.original.id,show:l}).then(({data:r})=>{!r&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.sell")}),cell:({row:a})=>e.jsx(H,{defaultChecked:a.getValue("sell"),onCheckedChange:l=>{Lt({id:a.original.id,sell:l}).then(({data:r})=>{!r&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.renew"),tooltip:n("plan.columns.renew_tooltip")}),cell:({row:a})=>e.jsx(H,{defaultChecked:a.getValue("renew"),onCheckedChange:l=>{Lt({id:a.original.id,renew:l}).then(({data:r})=>{!r&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.name")}),cell:({row:a})=>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:a.getValue("name")})}),enableSorting:!1,enableHiding:!1,size:900},{accessorKey:"users_count",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.stats")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-2",children:[e.jsx(ot,{}),e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:a.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"group",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.group")}),cell:({row:a})=>e.jsx("div",{className:"flex max-w-[600px] flex-wrap items-center gap-1.5 text-nowrap",children:e.jsx(K,{variant:"secondary",className:y("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.getValue("group")?.name})}),enableSorting:!1,enableHiding:!1},{accessorKey:"prices",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.price")}),cell:({row:a})=>{const l=a.getValue("prices"),r=[{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:r.map(({period:i,key:c,unit:u})=>l[c]!=null&&e.jsxs(K,{variant:"secondary",className:y("px-2 py-0.5 font-medium transition-colors text-nowrap",$a[c].color,$a[c].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[i," ¥",l[c],u]},c))})},enableSorting:!1,size:9e3},{id:"actions",header:({column:a})=>e.jsx(M,{className:"justify-end",column:a,title:n("plan.columns.actions")}),cell:({row:a})=>{const{setIsOpen:l,setEditingPlan:r}=ha();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(E,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{r(a.original),l(!0)},children:[e.jsx(Es,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.edit")})]}),e.jsx(Je,{title:n("plan.columns.delete_confirm.title"),description:n("plan.columns.delete_confirm.description"),confirmText:n("plan.columns.delete"),variant:"destructive",onConfirm:async()=>{od({id:a.original.id}).then(({data:i})=>{i&&(q.success(n("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(E,{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=h.object({id:h.number().nullable(),group_id:h.union([h.number(),h.string()]).nullable().optional(),name:h.string().min(1).max(250),content:h.string().nullable().optional(),transfer_enable:h.union([h.number().min(0),h.string().min(1)]),prices:h.object({monthly:h.union([h.number(),h.string()]).nullable().optional(),quarterly:h.union([h.number(),h.string()]).nullable().optional(),half_yearly:h.union([h.number(),h.string()]).nullable().optional(),yearly:h.union([h.number(),h.string()]).nullable().optional(),two_yearly:h.union([h.number(),h.string()]).nullable().optional(),three_yearly:h.union([h.number(),h.string()]).nullable().optional(),onetime:h.union([h.number(),h.string()]).nullable().optional(),reset_traffic:h.union([h.number(),h.string()]).nullable().optional()}).default({}),speed_limit:h.union([h.number(),h.string()]).nullable().optional(),capacity_limit:h.union([h.number(),h.string()]).nullable().optional(),device_limit:h.union([h.number(),h.string()]).nullable().optional(),force_update:h.boolean().optional(),reset_traffic_method:h.number().nullable(),users_count:h.number().optional()}),Mr=m.forwardRef(({className:s,...n},a)=>e.jsx(Ln,{ref:a,className:y("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(pi,{className:y("flex items-center justify-center text-current"),children:e.jsx(Ps,{className:"h-4 w-4"})})}));Mr.displayName=Ln.displayName;const pt={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},gt={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}},nx=[{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 rx(){const{isOpen:s,setIsOpen:n,editingPlan:a,setEditingPlan:l,refreshData:r}=ha(),[i,c]=m.useState(!1),{t:u}=I("subscribe"),x=ce({resolver:ue(ax),defaultValues:{...pt,...a||{}},mode:"onChange"});m.useEffect(()=>{a?x.reset({...pt,...a}):x.reset(pt)},[a,x]);const o=new ra({html:!0}),[d,p]=m.useState();async function k(){It().then(({data:_})=>{p(_)})}m.useEffect(()=>{s&&k()},[s]);const V=_=>{if(isNaN(_))return;const D=Object.entries(gt).reduce((b,[w,S])=>{const C=_*S.months*S.discount;return{...b,[w]:C.toFixed(2)}},{});x.setValue("prices",D,{shouldDirty:!0})},f=()=>{n(!1),l(null),x.reset(pt)};return e.jsx(ge,{open:s,onOpenChange:f,children:e.jsxs(he,{children:[e.jsxs(ve,{children:[e.jsx(je,{children:u(a?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(Te,{})]}),e.jsxs(xe,{...x,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:x.control,name:"name",render:({field:_})=>e.jsxs(g,{children:[e.jsx(v,{children:u("plan.form.name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:u("plan.form.name.placeholder"),..._})}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"group_id",render:({field:_})=>e.jsxs(g,{children:[e.jsxs(v,{className:"flex items-center justify-between",children:[u("plan.form.group.label"),e.jsx(Ft,{dialogTrigger:e.jsx(E,{variant:"link",children:u("plan.form.group.add")}),refetch:k})]}),e.jsxs(W,{value:_.value?.toString()??"",onValueChange:D=>_.onChange(D?Number(D):null),children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:u("plan.form.group.placeholder")})})}),e.jsx(G,{children:d?.map(D=>e.jsx($,{value:D.id.toString(),children:D.name},D.id))})]}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"transfer_enable",render:({field:_})=>e.jsxs(g,{className:"flex-1",children:[e.jsx(v,{children:u("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:u("plan.form.transfer.placeholder"),className:"rounded-r-none",..._})}),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:u("plan.form.transfer.unit")})]}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"speed_limit",render:({field:_})=>e.jsxs(g,{className:"flex-1",children:[e.jsx(v,{children:u("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:u("plan.form.speed.placeholder"),className:"rounded-r-none",..._,value:_.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:u("plan.form.speed.unit")})]}),e.jsx(P,{})]})}),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:u("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:u("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:_=>{const D=parseFloat(_.target.value);V(D)}})]}),e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const _=Object.keys(gt).reduce((D,b)=>({...D,[b]:""}),{});x.setValue("prices",_,{shouldDirty:!0})},children:u("plan.form.price.clear.button")})}),e.jsx(te,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:u("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(gt).filter(([_])=>!["onetime","reset_traffic"].includes(_)).map(([_,D])=>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(j,{control:x.control,name:`prices.${_}`,render:({field:b})=>e.jsxs(g,{children:[e.jsxs(v,{className:"text-xs font-medium text-muted-foreground",children:[u(`plan.columns.price_period.${_}`),e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",D.months===1?u("plan.form.price.period.monthly"):u("plan.form.price.period.months",{count:D.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(N,{children:e.jsx(T,{type:"number",placeholder:"0.00",min:0,...b,value:b.value??"",onChange:w=>b.onChange(w.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"})})]})]})})},_))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(gt).filter(([_])=>["onetime","reset_traffic"].includes(_)).map(([_,D])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(j,{control:x.control,name:`prices.${_}`,render:({field:b})=>e.jsx(g,{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(v,{className:"text-xs font-medium",children:u(`plan.columns.price_period.${_}`)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:u(_==="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(N,{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"})})]})]})})})},_))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(j,{control:x.control,name:"device_limit",render:({field:_})=>e.jsxs(g,{className:"flex-1",children:[e.jsx(v,{children:u("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:u("plan.form.device.placeholder"),className:"rounded-r-none",..._,value:_.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:u("plan.form.device.unit")})]}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"capacity_limit",render:({field:_})=>e.jsxs(g,{className:"flex-1",children:[e.jsx(v,{children:u("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:u("plan.form.capacity.placeholder"),className:"rounded-r-none",..._,value:_.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:u("plan.form.capacity.unit")})]}),e.jsx(P,{})]})})]}),e.jsx(j,{control:x.control,name:"reset_traffic_method",render:({field:_})=>e.jsxs(g,{children:[e.jsx(v,{children:u("plan.form.reset_method.label")}),e.jsxs(W,{value:_.value?.toString()??"null",onValueChange:D=>_.onChange(D=="null"?null:Number(D)),children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:u("plan.form.reset_method.placeholder")})})}),e.jsx(G,{children:nx.map(D=>e.jsx($,{value:D.value?.toString()??"null",children:u(`plan.form.reset_method.options.${D.label}`)},D.value))})]}),e.jsx(F,{className:"text-xs",children:u("plan.form.reset_method.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:x.control,name:"content",render:({field:_})=>{const[D,b]=m.useState(!1);return e.jsxs(g,{className:"space-y-2",children:[e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[u("plan.form.content.label"),e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(E,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>b(!D),children:D?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(te,{side:"top",children:e.jsx("p",{className:"text-xs",children:u(D?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"sm",onClick:()=>{_.onChange(u("plan.form.content.template.content"))},children:u("plan.form.content.template.button")})}),e.jsx(te,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:u("plan.form.content.template.tooltip")})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${D?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(N,{children:e.jsx(la,{style:{height:"400px"},value:_.value||"",renderHTML:w=>o.render(w),onChange:({text:w})=>_.onChange(w),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:u("plan.form.content.placeholder"),className:"rounded-md border"})})}),D&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:u("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(_.value||"")}})})]})]}),e.jsx(F,{className:"text-xs",children:u("plan.form.content.description")}),e.jsx(P,{})]})}})]}),e.jsx(Me,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:a&&e.jsx(j,{control:x.control,name:"force_update",render:({field:_})=>e.jsxs(g,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(N,{children:e.jsx(Mr,{checked:_.value,onCheckedChange:_.onChange})}),e.jsx("div",{className:"",children:e.jsx(v,{className:"text-sm",children:u("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(E,{type:"button",variant:"outline",onClick:f,children:u("plan.form.submit.cancel")}),e.jsx(E,{type:"submit",disabled:i,onClick:()=>{x.handleSubmit(async _=>{c(!0),(await ld(_)).data&&(q.success(u(a?"plan.form.submit.success.update":"plan.form.submit.success.add")),f(),r()),c(!1)})()},children:u(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})]})})}function lx(){const[s,n]=m.useState({}),[a,l]=m.useState({"drag-handle":!1}),[r,i]=m.useState([]),[c,u]=m.useState([]),[x,o]=m.useState(!1),[d,p]=m.useState({pageSize:20,pageIndex:0}),[k,V]=m.useState([]),{refetch:f}=se({queryKey:["planList"],queryFn:async()=>{const{data:S}=await Fs();return V(S),S}});m.useEffect(()=>{l({"drag-handle":x}),p({pageSize:x?99999:10,pageIndex:0})},[x]);const _=(S,C)=>{x&&(S.dataTransfer.setData("text/plain",C.toString()),S.currentTarget.classList.add("opacity-50"))},D=(S,C)=>{if(!x)return;S.preventDefault(),S.currentTarget.classList.remove("bg-muted");const R=parseInt(S.dataTransfer.getData("text/plain"));if(R===C)return;const z=[...k],[Q]=z.splice(R,1);z.splice(C,0,Q),V(z)},b=async()=>{if(!x){o(!0);return}const S=k?.map(C=>C.id);id(S).then(()=>{q.success("排序保存成功"),o(!1),f()}).finally(()=>{o(!1)})},w=ze({data:k||[],columns:tx(f),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:d},enableRowSelection:!0,onPaginationChange:p,onRowSelectionChange:n,onSortingChange:u,onColumnFiltersChange:i,onColumnVisibilityChange:l,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),getSortedRowModel:Ge(),getFacetedRowModel:ds(),getFacetedUniqueValues:ms(),initialState:{columnPinning:{right:["actions"]}},pageCount:x?1:void 0});return e.jsx(ex,{refreshData:f,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ye,{table:w,toolbar:S=>e.jsx(sx,{table:S,refetch:f,saveOrder:b,isSortMode:x}),draggable:x,onDragStart:_,onDragEnd:S=>S.currentTarget.classList.remove("opacity-50"),onDragOver:S=>{S.preventDefault(),S.currentTarget.classList.add("bg-muted")},onDragLeave:S=>S.currentTarget.classList.remove("bg-muted"),onDrop:D,showPagination:!x}),e.jsx(rx,{})]})})}function ox(){const{t:s}=I("subscribe");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(lx,{})})]})]})}const ix=Object.freeze(Object.defineProperty({__proto__:null,default:ox},Symbol.toStringTag,{value:"Module"})),Ls=[{value:Z.PENDING,label:Ys[Z.PENDING],icon:gi,color:Js[Z.PENDING]},{value:Z.PROCESSING,label:Ys[Z.PROCESSING],icon:An,color:Js[Z.PROCESSING]},{value:Z.COMPLETED,label:Ys[Z.COMPLETED],icon:Wt,color:Js[Z.COMPLETED]},{value:Z.CANCELLED,label:Ys[Z.CANCELLED],icon:$n,color:Js[Z.CANCELLED]},{value:Z.DISCOUNTED,label:Ys[Z.DISCOUNTED],icon:Wt,color:Js[Z.DISCOUNTED]}],Zs=[{value:ne.PENDING,label:ut[ne.PENDING],icon:ji,color:xt[ne.PENDING]},{value:ne.PROCESSING,label:ut[ne.PROCESSING],icon:An,color:xt[ne.PROCESSING]},{value:ne.VALID,label:ut[ne.VALID],icon:Wt,color:xt[ne.VALID]},{value:ne.INVALID,label:ut[ne.INVALID],icon:$n,color:xt[ne.INVALID]}];function jt({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=s?.getFilterValue(),i=Array.isArray(r)?new Set(r):r!==void 0?new Set([r]):new Set;return e.jsxs(as,{children:[e.jsx(ns,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(ct,{className:"mr-2 h-4 w-4"}),n,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{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(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):a.filter(c=>i.has(c.value)).map(c=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:c.label},c.value))})]})]})}),e.jsx(We,{className:"w-[200px] p-0",align:"start",children:e.jsxs(_s,{children:[e.jsx(Vs,{placeholder:n}),e.jsxs(ws,{children:[e.jsx(Is,{children:"No results found."}),e.jsx(Ie,{children:a.map(c=>{const u=i.has(c.value);return e.jsxs(_e,{onSelect:()=>{const x=new Set(i);u?x.delete(c.value):x.add(c.value);const o=Array.from(x);s?.setFilterValue(o.length?o:void 0)},children:[e.jsx("div",{className:y("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",u?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ps,{className:y("h-4 w-4")})}),c.icon&&e.jsx(c.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${c.color}`}),e.jsx("span",{children:c.label}),l?.get(c.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(c.value)})]},c.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Ie,{children:e.jsx(_e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const cx=h.object({email:h.string().min(1),plan_id:h.number(),period:h.string(),total_amount:h.number()}),dx={email:"",plan_id:0,total_amount:0,period:""};function Or({refetch:s,trigger:n,defaultValues:a}){const{t:l}=I("order"),[r,i]=m.useState(!1),c=ce({resolver:ue(cx),defaultValues:{...dx,...a},mode:"onChange"}),[u,x]=m.useState([]);return m.useEffect(()=>{r&&Fs().then(({data:o})=>{x(o)})},[r]),e.jsxs(ge,{open:r,onOpenChange:i,children:[e.jsx(Fe,{asChild:!0,children:n||e.jsxs(E,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("div",{children:l("dialog.addOrder")})]})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:l("dialog.assignOrder")}),e.jsx(Te,{})]}),e.jsxs(xe,{...c,children:[e.jsx(j,{control:c.control,name:"email",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dialog.fields.userEmail")}),e.jsx(N,{children:e.jsx(T,{placeholder:l("dialog.placeholders.email"),...o})})]})}),e.jsx(j,{control:c.control,name:"plan_id",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dialog.fields.subscriptionPlan")}),e.jsx(N,{children:e.jsxs(W,{value:o.value?o.value?.toString():void 0,onValueChange:d=>o.onChange(parseInt(d)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dialog.placeholders.plan")})}),e.jsx(G,{children:u.map(d=>e.jsx($,{value:d.id.toString(),children:d.name},d.id))})]})})]})}),e.jsx(j,{control:c.control,name:"period",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dialog.fields.orderPeriod")}),e.jsx(N,{children:e.jsxs(W,{value:o.value,onValueChange:o.onChange,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dialog.placeholders.period")})}),e.jsx(G,{children:Object.keys(Ld).map(d=>e.jsx($,{value:d,children:l(`period.${d}`)},d))})]})})]})}),e.jsx(j,{control:c.control,name:"total_amount",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:l("dialog.fields.paymentAmount")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:l("dialog.placeholders.amount"),value:o.value/100,onChange:d=>o.onChange(parseFloat(d.currentTarget.value)*100)})}),e.jsx(P,{})]})}),e.jsxs(Me,{children:[e.jsx(E,{variant:"outline",onClick:()=>i(!1),children:l("dialog.actions.cancel")}),e.jsx(E,{type:"submit",onClick:()=>{c.handleSubmit(o=>{xd(o).then(({data:d})=>{d&&(s&&s(),c.reset(),i(!1),q.success(l("dialog.messages.addSuccess")))})})()},children:l("dialog.actions.confirm")})]})]})]})]})}function mx({table:s,refetch:n}){const{t:a}=I("order"),l=s.getState().columnFilters.length>0,r=Object.values(Ke).filter(x=>typeof x=="number").map(x=>({label:a(`type.${Ke[x]}`),value:x,color:x===Ke.NEW?"green-500":x===Ke.RENEWAL?"blue-500":x===Ke.UPGRADE?"purple-500":"orange-500"})),i=Object.values(de).map(x=>({label:a(`period.${x}`),value:x,color:x===de.MONTH_PRICE?"slate-500":x===de.QUARTER_PRICE?"cyan-500":x===de.HALF_YEAR_PRICE?"indigo-500":x===de.YEAR_PRICE?"violet-500":x===de.TWO_YEAR_PRICE?"fuchsia-500":x===de.THREE_YEAR_PRICE?"pink-500":x===de.ONETIME_PRICE?"rose-500":"orange-500"})),c=Object.values(Z).filter(x=>typeof x=="number").map(x=>({label:a(`status.${Z[x]}`),value:x,icon:x===Z.PENDING?Ls[0].icon:x===Z.PROCESSING?Ls[1].icon:x===Z.COMPLETED?Ls[2].icon:x===Z.CANCELLED?Ls[3].icon:Ls[4].icon,color:x===Z.PENDING?"yellow-500":x===Z.PROCESSING?"blue-500":x===Z.COMPLETED?"green-500":x===Z.CANCELLED?"red-500":"green-500"})),u=Object.values(ne).filter(x=>typeof x=="number").map(x=>({label:a(`commission.${ne[x]}`),value:x,icon:x===ne.PENDING?Zs[0].icon:x===ne.PROCESSING?Zs[1].icon:x===ne.VALID?Zs[2].icon:Zs[3].icon,color:x===ne.PENDING?"yellow-500":x===ne.PROCESSING?"blue-500":x===ne.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Or,{refetch:n}),e.jsx(T,{placeholder:a("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:x=>s.getColumn("trade_no")?.setFilterValue(x.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(jt,{column:s.getColumn("type"),title:a("table.columns.type"),options:r}),s.getColumn("period")&&e.jsx(jt,{column:s.getColumn("period"),title:a("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(jt,{column:s.getColumn("status"),title:a("table.columns.status"),options:c}),s.getColumn("commission_status")&&e.jsx(jt,{column:s.getColumn("commission_status"),title:a("table.columns.commissionStatus"),options:u})]}),l&&e.jsxs(E,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[a("actions.reset"),e.jsx(Oe,{className:"ml-2 h-4 w-4"})]})]})}function Ae({label:s,value:n,className:a,valueClassName:l}){return e.jsxs("div",{className:y("flex items-center py-1.5",a),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:y("text-sm",l),children:n||"-"})]})}function ux({status:s}){const{t:n}=I("order"),a={[Z.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[Z.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[Z.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[Z.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[Z.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(K,{variant:"secondary",className:y("font-medium",a[s]),children:n(`status.${Z[s]}`)})}function xx({id:s,trigger:n}){const[a,l]=m.useState(!1),[r,i]=m.useState(),{t:c}=I("order");return m.useEffect(()=>{(async()=>{if(a){const{data:x}=await dd({id:s});i(x)}})()},[a,s]),e.jsxs(ge,{onOpenChange:l,open:a,children:[e.jsx(Fe,{asChild:!0,children:n}),e.jsxs(he,{className:"max-w-xl",children:[e.jsxs(ve,{className:"space-y-2",children:[e.jsx(je,{className:"text-lg font-medium",children:c("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:[c("table.columns.tradeNo"),":",r?.trade_no]}),r?.status&&e.jsx(ux,{status:r.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:c("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ae,{label:c("dialog.fields.userEmail"),value:r?.user?.email?e.jsxs(Rs,{to:`/user/manage?email=${r.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[r.user.email,e.jsx(qn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(Ae,{label:c("dialog.fields.orderPeriod"),value:r&&c(`period.${r.period}`)}),e.jsx(Ae,{label:c("dialog.fields.subscriptionPlan"),value:r?.plan?.name,valueClassName:"font-medium"}),e.jsx(Ae,{label:c("dialog.fields.callbackNo"),value:r?.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:c("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ae,{label:c("dialog.fields.paymentAmount"),value:ks(r?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(be,{className:"my-2"}),e.jsx(Ae,{label:c("dialog.fields.balancePayment"),value:ks(r?.balance_amount||0)}),e.jsx(Ae,{label:c("dialog.fields.discountAmount"),value:ks(r?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(Ae,{label:c("dialog.fields.refundAmount"),value:ks(r?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(Ae,{label:c("dialog.fields.deductionAmount"),value:ks(r?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:c("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ae,{label:c("dialog.fields.createdAt"),value:me(r?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(Ae,{label:c("dialog.fields.updatedAt"),value:me(r?.updated_at),valueClassName:"font-mono text-xs"})]})]})]})]})]})}const hx={[Ke.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ke.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ke.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ke.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},fx={[de.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},px=s=>Z[s],gx=s=>ne[s],jx=s=>Ke[s],vx=s=>{const{t:n}=I("order");return[{accessorKey:"trade_no",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.tradeNo")}),cell:({row:a})=>{const l=a.original.trade_no,r=l.length>6?`${l.slice(0,3)}...${l.slice(-3)}`:l;return e.jsx("div",{className:"flex items-center",children:e.jsx(xx,{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:r}),e.jsx(qn,{className:"h-3.5 w-3.5 opacity-70"})]}),id:a.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.type")}),cell:({row:a})=>{const l=a.getValue("type"),r=hx[l];return e.jsx(K,{variant:"secondary",className:y("font-medium transition-colors text-nowrap",r.color,r.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:n(`type.${jx(l)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.plan")}),cell:({row:a})=>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:a.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.period")}),cell:({row:a})=>{const l=a.getValue("period"),r=fx[l];return e.jsx(K,{variant:"secondary",className:y("font-medium transition-colors text-nowrap",r.color,r.bgColor,"hover:bg-opacity-80"),children:n(`period.${l}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.amount")}),cell:({row:a})=>{const l=a.getValue("total_amount"),r=typeof l=="number"?(l/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",r]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:a})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(M,{column:a,title:n("table.columns.status")}),e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsx(Dr,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(te,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:a})=>{const l=Ls.find(r=>r.value===a.getValue("status"));return l?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l.icon&&e.jsx(l.icon,{className:`h-4 w-4 text-${l.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`status.${px(l.value)}`)})]}),l.value===Z.PENDING&&e.jsxs(ys,{modal:!0,children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Nt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(os,{align:"end",className:"w-[140px]",children:[e.jsx(fe,{className:"cursor-pointer",onClick:async()=>{await md({trade_no:a.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(fe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await ud({trade_no:a.original.trade_no}),s()},children:n("actions.cancel")})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.commission")}),cell:({row:a})=>{const l=a.getValue("commission_balance"),r=l?(l/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:l?`¥${r}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.commissionStatus")}),cell:({row:a})=>{const l=a.original.status,r=a.original.commission_balance,i=Zs.find(c=>c.value===a.getValue("commission_status"));return r==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.${gx(i.value)}`)})]}),i.value===ne.PENDING&&l===Z.COMPLETED&&e.jsxs(ys,{modal:!0,children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Nt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(os,{align:"end",className:"w-[120px]",children:[e.jsx(fe,{className:"cursor-pointer",onClick:async()=>{await Fa({trade_no:a.original.trade_no,commission_status:ne.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(fe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await Fa({trade_no:a.original.trade_no,commission_status:ne.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.createdAt")}),cell:({row:a})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:me(a.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function bx(){const[s]=Kn(),[n,a]=m.useState({}),[l,r]=m.useState({}),[i,c]=m.useState([]),[u,x]=m.useState([]),[o,d]=m.useState({pageIndex:0,pageSize:20});m.useEffect(()=>{const D=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([b,w])=>{const S=s.get(b);return S?{id:b,value:w==="number"?parseInt(S):S}:null}).filter(Boolean);D.length>0&&c(D)},[s]);const{refetch:p,data:k,isLoading:V}=se({queryKey:["orderList",o,i,u],queryFn:()=>cd({pageSize:o.pageSize,current:o.pageIndex+1,filter:i,sort:u})}),f=ze({data:k?.data??[],columns:vx(p),state:{sorting:u,columnVisibility:l,rowSelection:n,columnFilters:i,pagination:o},rowCount:k?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:x,onColumnFiltersChange:c,onColumnVisibilityChange:r,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),onPaginationChange:d,getSortedRowModel:Ge(),getFacetedRowModel:ds(),getFacetedUniqueValues:ms(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Ye,{table:f,toolbar:e.jsx(mx,{table:f,refetch:p}),showPagination:!0})}function yx(){const{t:s}=I("order");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(bx,{})})]})]})}const Nx=Object.freeze(Object.defineProperty({__proto__:null,default:yx},Symbol.toStringTag,{value:"Module"}));function _x({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(as,{children:[e.jsx(ns,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(ct,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(i=>r.has(i.value)).map(i=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(We,{className:"w-[200px] p-0",align:"start",children:e.jsxs(_s,{children:[e.jsx(Vs,{placeholder:n}),e.jsxs(ws,{children:[e.jsx(Is,{children:"No results found."}),e.jsx(Ie,{children:a.map(i=>{const c=r.has(i.value);return e.jsxs(_e,{onSelect:()=>{c?r.delete(i.value):r.add(i.value);const u=Array.from(r);s?.setFilterValue(u.length?u:void 0)},children:[e.jsx("div",{className:y("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ps,{className:y("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}),l?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(i.value)})]},i.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Ie,{children:e.jsx(_e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const wx=h.object({id:h.coerce.number().nullable().optional(),name:h.string().min(1,"请输入优惠券名称"),code:h.string().nullable(),type:h.union([h.string(),h.nativeEnum(js)]),value:h.coerce.number(),started_at:h.coerce.number(),ended_at:h.coerce.number(),limit_use:h.union([h.string(),h.number()]).nullable(),limit_use_with_user:h.union([h.string(),h.number()]).nullable(),generate_count:h.coerce.number().nullable().optional(),limit_plan_ids:h.array(h.number()).default([]).nullable(),limit_period:h.array(h.nativeEnum(de)).default([]).nullable()}).refine(s=>s.ended_at>s.started_at,{message:"结束时间必须晚于开始时间",path:["ended_at"]}),qa={name:"",code:"",type:js.AMOUNT,value:0,started_at:Math.floor(Date.now()/1e3),ended_at:Math.floor(Date.now()/1e3)+7*24*60*60,limit_use:"",limit_use_with_user:"",limit_plan_ids:[],limit_period:[],generate_count:""};function zr({defaultValues:s,refetch:n,type:a="create",dialogTrigger:l=null,open:r,onOpenChange:i}){const{t:c}=I("coupon"),[u,x]=m.useState(!1),o=r??u,d=i??x,[p,k]=m.useState([]),V=ce({resolver:ue(wx),defaultValues:s||qa});m.useEffect(()=>{s&&V.reset(s)},[s,V]),m.useEffect(()=>{Fs().then(({data:b})=>k(b))},[]);const f=b=>{if(!b)return;const w=(S,C)=>{const R=new Date(C*1e3);return S.setHours(R.getHours(),R.getMinutes(),R.getSeconds()),Math.floor(S.getTime()/1e3)};b.from&&V.setValue("started_at",w(b.from,V.watch("started_at"))),b.to&&V.setValue("ended_at",w(b.to,V.watch("ended_at")))},_=async b=>{fd(b).then(()=>{d(!1),a==="create"&&V.reset(qa),n()})},D=(b,w)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:w}),e.jsx(T,{type:"datetime-local",step:"1",value:me(V.watch(b),"YYYY-MM-DDTHH:mm:ss"),onChange:S=>{const C=new Date(S.target.value);V.setValue(b,Math.floor(C.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(ge,{open:o,onOpenChange:d,children:[l&&e.jsx(Fe,{asChild:!0,children:l}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsx(ve,{children:e.jsx(je,{children:c(a==="create"?"form.add":"form.edit")})}),e.jsx(xe,{...V,children:e.jsxs("form",{onSubmit:V.handleSubmit(_),className:"space-y-4",children:[e.jsx(j,{control:V.control,name:"name",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:c("form.name.label")}),e.jsx(T,{placeholder:c("form.name.placeholder"),...b}),e.jsx(P,{})]})}),e.jsx(j,{control:V.control,name:"code",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:c("form.code.label")}),e.jsx(T,{placeholder:c("form.code.placeholder"),...b,className:"h-9"}),e.jsx(F,{className:"text-xs",children:c("form.code.description")}),e.jsx(P,{})]})}),e.jsxs(g,{children:[e.jsx(v,{children:c("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(j,{control:V.control,name:"type",render:({field:b})=>e.jsxs(W,{value:b.value.toString(),onValueChange:b.onChange,children:[e.jsx(B,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Y,{placeholder:c("form.type.placeholder")})}),e.jsx(G,{children:Object.entries(Ad).map(([w,S])=>e.jsx($,{value:w,children:c(`table.toolbar.types.${w}`)},w))})]})}),e.jsx(j,{control:V.control,name:"value",render:({field:b})=>e.jsx(T,{type:"number",placeholder:c("form.value.placeholder"),...b,onChange:w=>b.onChange(w.target.value===""?"":w.target.value),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:V.watch("type")===js.AMOUNT?"¥":"%"})})]})]}),e.jsxs(g,{children:[e.jsx(v,{children:c("form.validity.label")}),e.jsxs(as,{children:[e.jsx(ns,{asChild:!0,children:e.jsxs(E,{variant:"outline",className:y("w-full justify-start text-left font-normal",!V.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(it,{className:"mr-2 h-4 w-4"}),me(V.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",c("form.validity.to")," ",me(V.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})}),e.jsxs(We,{className:"w-auto p-0",align:"start",children:[e.jsx("div",{className:"border-b border-border",children:e.jsx(Ms,{mode:"range",selected:{from:new Date(V.watch("started_at")*1e3),to:new Date(V.watch("ended_at")*1e3)},onSelect:f,numberOfMonths:2})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-4",children:[D("started_at",c("table.validity.startTime")),e.jsx("div",{className:"mt-6 text-sm text-muted-foreground",children:c("form.validity.to")}),D("ended_at",c("table.validity.endTime"))]})})]})]}),e.jsx(P,{})]}),e.jsx(j,{control:V.control,name:"limit_use",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:c("form.limitUse.label")}),e.jsx(T,{type:"number",min:0,placeholder:c("form.limitUse.placeholder"),...b,value:b.value===void 0?"":b.value,onChange:w=>b.onChange(w.target.value===""?"":w.target.value),className:"h-9"}),e.jsx(F,{className:"text-xs",children:c("form.limitUse.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:V.control,name:"limit_use_with_user",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:c("form.limitUseWithUser.label")}),e.jsx(T,{type:"number",min:0,placeholder:c("form.limitUseWithUser.placeholder"),...b,value:b.value===void 0?"":b.value,onChange:w=>b.onChange(w.target.value===""?"":w.target.value),className:"h-9"}),e.jsx(F,{className:"text-xs",children:c("form.limitUseWithUser.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:V.control,name:"limit_period",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:c("form.limitPeriod.label")}),e.jsx(lt,{options:Object.entries(de).filter(([w])=>isNaN(Number(w))).map(([w,S])=>({label:S,value:w})),onChange:w=>{if(w.length===0){b.onChange([]);return}const S=w.map(C=>de[C.value]);b.onChange(S)},value:(b.value||[]).map(w=>({label:Object.entries(de).find(([S,C])=>C===w)?.[1]||"",value:Object.entries(de).find(([S,C])=>C===w)?.[0]||""})),placeholder:c("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:c("form.limitPeriod.empty")})}),e.jsx(F,{className:"text-xs",children:c("form.limitPeriod.description")}),e.jsx(P,{})]})}),e.jsx(j,{control:V.control,name:"limit_plan_ids",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:c("form.limitPlan.label")}),e.jsx(lt,{options:p?.map(w=>({label:w.name,value:w.id.toString()}))||[],onChange:w=>b.onChange(w.map(S=>Number(S.value))),value:(p||[]).filter(w=>(b.value||[]).includes(w.id)).map(w=>({label:w.name,value:w.id.toString()})),placeholder:c("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:c("form.limitPlan.empty")})}),e.jsx(P,{})]})}),a==="create"&&e.jsx(e.Fragment,{children:e.jsx(j,{control:V.control,name:"generate_count",render:({field:b})=>e.jsxs(g,{children:[e.jsx(v,{children:c("form.generateCount.label")}),e.jsx(T,{type:"number",min:0,placeholder:c("form.generateCount.placeholder"),...b,value:b.value===void 0?"":b.value,onChange:w=>b.onChange(w.target.value===""?"":w.target.value),className:"h-9"}),e.jsx(F,{className:"text-xs",children:c("form.generateCount.description")}),e.jsx(P,{})]})})}),e.jsx(Me,{children:e.jsx(E,{type:"submit",disabled:V.formState.isSubmitting,children:V.formState.isSubmitting?c("form.submit.saving"):c("form.submit.save")})})]})})]})]})}function Cx({table:s,refetch:n}){const a=s.getState().columnFilters.length>0,{t:l}=I("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(zr,{refetch:n,dialogTrigger:e.jsxs(E,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("div",{children:l("form.add")})]})}),e.jsx(T,{placeholder:l("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:r=>s.getColumn("name")?.setFilterValue(r.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(_x,{column:s.getColumn("type"),title:l("table.toolbar.type"),options:[{value:js.AMOUNT,label:l(`table.toolbar.types.${js.AMOUNT}`)},{value:js.PERCENTAGE,label:l(`table.toolbar.types.${js.PERCENTAGE}`)}]}),a&&e.jsxs(E,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("table.toolbar.reset"),e.jsx(Oe,{className:"ml-2 h-4 w-4"})]})]})}const Lr=m.createContext(void 0);function Sx({children:s,refetch:n}){const[a,l]=m.useState(!1),[r,i]=m.useState(null),c=x=>{i(x),l(!0)},u=()=>{l(!1),i(null)};return e.jsxs(Lr.Provider,{value:{isOpen:a,currentCoupon:r,openEdit:c,closeEdit:u},children:[s,r&&e.jsx(zr,{defaultValues:r,refetch:n,type:"edit",open:a,onOpenChange:l})]})}function kx(){const s=m.useContext(Lr);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const Dx=s=>{const{t:n}=I("coupon");return[{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.id")}),cell:({row:a})=>e.jsx(K,{children:a.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.show")}),cell:({row:a})=>e.jsx(H,{defaultChecked:a.original.show,onCheckedChange:l=>{gd({id:a.original.id,show:l}).then(({data:r})=>!r&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.name")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:a.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.type")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:n(`table.toolbar.types.${a.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.code")}),cell:({row:a})=>e.jsx(K,{variant:"secondary",children:a.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.limitUse")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:a.original.limit_use===null?n("table.validity.unlimited"):a.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.limitUseWithUser")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:a.original.limit_use_with_user===null?n("table.validity.noLimit"):a.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.validity")}),cell:({row:a})=>{const[l,r]=m.useState(!1),i=Date.now(),c=a.original.started_at*1e3,u=a.original.ended_at*1e3,x=i>u,o=ie.jsx(M,{className:"justify-end",column:a,title:n("table.columns.actions")}),cell:({row:a})=>{const{openEdit:l}=kx();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(E,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>l(a.original),children:[e.jsx(Es,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),e.jsx(Je,{title:n("table.actions.deleteConfirm.title"),description:n("table.actions.deleteConfirm.description"),confirmText:n("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{pd({id:a.original.id}).then(({data:r})=>{r&&(q.success("删除成功"),s())})},children:e.jsxs(E,{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 Tx(){const[s,n]=m.useState({}),[a,l]=m.useState({}),[r,i]=m.useState([]),[c,u]=m.useState([]),[x,o]=m.useState({pageIndex:0,pageSize:20}),{refetch:d,data:p}=se({queryKey:["couponList",x,r,c],queryFn:()=>hd({pageSize:x.pageSize,current:x.pageIndex+1,filter:r,sort:c})}),k=ze({data:p?.data??[],columns:Dx(d),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:x},pageCount:Math.ceil((p?.total??0)/x.pageSize),rowCount:p?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:u,onColumnFiltersChange:i,onColumnVisibilityChange:l,onPaginationChange:o,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),getSortedRowModel:Ge(),getFacetedRowModel:ds(),getFacetedUniqueValues:ms(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Sx,{refetch:d,children:e.jsx("div",{className:"space-y-4",children:e.jsx(Ye,{table:k,toolbar:e.jsx(Cx,{table:k,refetch:d})})})})}function Px(){const{t:s}=I("coupon");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(Tx,{})})]})]})}const Rx=Object.freeze(Object.defineProperty({__proto__:null,default:Px},Symbol.toStringTag,{value:"Module"})),Ex=h.object({email_prefix:h.string().optional(),email_suffix:h.string().min(1),password:h.string().optional(),expired_at:h.number().optional().nullable(),plan_id:h.number().nullable(),generate_count:h.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"]}),Vx={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0};function Ix({refetch:s}){const{t:n}=I("user"),[a,l]=m.useState(!1),r=ce({resolver:ue(Ex),defaultValues:Vx,mode:"onChange"}),[i,c]=m.useState([]);return m.useEffect(()=>{a&&Fs().then(({data:u})=>{u&&c(u)})},[a]),e.jsxs(ge,{open:a,onOpenChange:l,children:[e.jsx(Fe,{asChild:!0,children:e.jsxs(J,{size:"sm",variant:"outline",className:"space-x-2 gap-0",children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:n("generate.title")}),e.jsx(Te,{})]}),e.jsxs(xe,{...r,children:[e.jsxs(g,{children:[e.jsx(v,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!r.watch("generate_count")&&e.jsx(j,{control:r.control,name:"email_prefix",render:({field:u})=>e.jsx(T,{className:"flex-[5] rounded-r-none",placeholder:n("generate.form.email_prefix"),...u})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${r.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(j,{control:r.control,name:"email_suffix",render:({field:u})=>e.jsx(T,{className:"flex-[4] rounded-l-none",placeholder:n("generate.form.email_domain"),...u})})]})]}),e.jsx(j,{control:r.control,name:"password",render:({field:u})=>e.jsxs(g,{children:[e.jsx(v,{children:n("generate.form.password")}),e.jsx(T,{placeholder:n("generate.form.password_placeholder"),...u}),e.jsx(P,{})]})}),e.jsx(j,{control:r.control,name:"expired_at",render:({field:u})=>e.jsxs(g,{className:"flex flex-col",children:[e.jsx(v,{children:n("generate.form.expire_time")}),e.jsxs(as,{children:[e.jsx(ns,{asChild:!0,children:e.jsx(N,{children:e.jsxs(J,{variant:"outline",className:y("w-full pl-3 text-left font-normal",!u.value&&"text-muted-foreground"),children:[u.value?me(u.value):e.jsx("span",{children:n("generate.form.expire_time_placeholder")}),e.jsx(it,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(We,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(bi,{asChild:!0,children:e.jsx(J,{variant:"outline",className:"w-full",onClick:()=>{u.onChange(null)},children:n("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Ms,{mode:"single",selected:u.value?new Date(u.value*1e3):void 0,onSelect:x=>{x&&u.onChange(x?.getTime()/1e3)}})})]})]})]})}),e.jsx(j,{control:r.control,name:"plan_id",render:({field:u})=>e.jsxs(g,{children:[e.jsx(v,{children:n("generate.form.subscription")}),e.jsx(N,{children:e.jsxs(W,{value:u.value?u.value.toString():"null",onValueChange:x=>u.onChange(x==="null"?null:parseInt(x)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(G,{children:[e.jsx($,{value:"null",children:n("generate.form.subscription_none")}),i.map(x=>e.jsx($,{value:x.id.toString(),children:x.name},x.id))]})]})})]})}),!r.watch("email_prefix")&&e.jsx(j,{control:r.control,name:"generate_count",render:({field:u})=>e.jsxs(g,{children:[e.jsx(v,{children:n("generate.form.generate_count")}),e.jsx(T,{type:"number",placeholder:n("generate.form.generate_count_placeholder"),value:u.value||"",onChange:x=>u.onChange(x.target.value?parseInt(x.target.value):null)})]})})]}),e.jsxs(Me,{children:[e.jsx(J,{variant:"outline",onClick:()=>l(!1),children:n("generate.form.cancel")}),e.jsx(J,{onClick:()=>r.handleSubmit(u=>{yd(u).then(({data:x})=>{x&&(q.success(n("generate.form.success")),r.reset(),s(),l(!1))})})(),children:n("generate.form.submit")})]})]})]})}const Ar=Ua,$r=Ba,Fx=Ga,qr=m.forwardRef(({className:s,...n},a)=>e.jsx(St,{className:y("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:a}));qr.displayName=St.displayName;const Mx=Ts("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"}}),fa=m.forwardRef(({side:s="right",className:n,children:a,...l},r)=>e.jsxs(Fx,{children:[e.jsx(qr,{}),e.jsxs(kt,{ref:r,className:y(Mx({side:s}),n),...l,children:[e.jsxs(sa,{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(Oe,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),a]})]}));fa.displayName=kt.displayName;const pa=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col space-y-2 text-center sm:text-left",s),...n});pa.displayName="SheetHeader";const Kr=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Kr.displayName="SheetFooter";const ga=m.forwardRef(({className:s,...n},a)=>e.jsx(Dt,{ref:a,className:y("text-lg font-semibold text-foreground",s),...n}));ga.displayName=Dt.displayName;const ja=m.forwardRef(({className:s,...n},a)=>e.jsx(Tt,{ref:a,className:y("text-sm text-muted-foreground",s),...n}));ja.displayName=Tt.displayName;function Ox({table:s,refetch:n,permissionGroups:a=[],subscriptionPlans:l=[]}){const{t:r}=I("user"),i=s.getState().columnFilters.length>0,[c,u]=m.useState([]),[x,o]=m.useState(!1),d=[{label:r("filter.fields.email"),value:"email",type:"text",operators:[{label:r("filter.operators.contains"),value:"contains"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.id"),value:"id",type:"number",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.plan_id"),value:"plan_id",type:"select",operators:[{label:r("filter.operators.eq"),value:"eq"}],useOptions:!0},{label:r("filter.fields.transfer_enable"),value:"transfer_enable",type:"number",unit:"GB",operators:[{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.lt"),value:"lt"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.total_used"),value:"total_used",type:"number",unit:"GB",operators:[{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.lt"),value:"lt"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.online_count"),value:"online_count",type:"number",operators:[{label:r("filter.operators.eq"),value:"eq"},{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.lt"),value:"lt"}]},{label:r("filter.fields.expired_at"),value:"expired_at",type:"date",operators:[{label:r("filter.operators.lt"),value:"lt"},{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.uuid"),value:"uuid",type:"text",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.token"),value:"token",type:"text",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.banned"),value:"banned",type:"select",operators:[{label:r("filter.operators.eq"),value:"eq"}],options:[{label:r("filter.status.normal"),value:"0"},{label:r("filter.status.banned"),value:"1"}]},{label:r("filter.fields.remark"),value:"remark",type:"text",operators:[{label:r("filter.operators.contains"),value:"contains"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.inviter_email"),value:"inviter_email",type:"text",operators:[{label:r("filter.operators.contains"),value:"contains"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.invite_user_id"),value:"invite_user_id",type:"number",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.is_admin"),value:"is_admin",type:"boolean",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.is_staff"),value:"is_staff",type:"boolean",operators:[{label:r("filter.operators.eq"),value:"eq"}]}],p=w=>w*1024*1024*1024,k=w=>w/(1024*1024*1024),V=()=>{u([...c,{field:"",operator:"",value:""}])},f=w=>{u(c.filter((S,C)=>C!==w))},_=(w,S,C)=>{const R=[...c];if(R[w]={...R[w],[S]:C},S==="field"){const z=d.find(Q=>Q.value===C);z&&(R[w].operator=z.operators[0].value,R[w].value=z.type==="boolean"?!1:"")}u(R)},D=(w,S)=>{const C=d.find(R=>R.value===w.field);if(!C)return null;switch(C.type){case"text":return e.jsx(T,{placeholder:r("filter.sheet.value"),value:w.value,onChange:R=>_(S,"value",R.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(T,{type:"number",placeholder:r("filter.sheet.value_number",{unit:C.unit}),value:C.unit==="GB"?k(w.value||0):w.value,onChange:R=>{const z=Number(R.target.value);_(S,"value",C.unit==="GB"?p(z):z)}}),C.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:C.unit})]});case"date":return e.jsx(Ms,{mode:"single",selected:w.value,onSelect:R=>_(S,"value",R),className:"rounded-md border"});case"select":return e.jsxs(W,{value:w.value,onValueChange:R=>_(S,"value",R),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:r("filter.sheet.value")})}),e.jsx(G,{children:C.useOptions?l.map(R=>e.jsx($,{value:R.value.toString(),children:R.label},R.value)):C.options?.map(R=>e.jsx($,{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(H,{checked:w.value,onCheckedChange:R=>_(S,"value",R)}),e.jsx(_t,{children:w.value?r("filter.boolean.true"):r("filter.boolean.false")})]});default:return null}},b=()=>{const w=c.filter(S=>S.field&&S.operator&&S.value!=="").map(S=>{const C=d.find(z=>z.value===S.field);let R=S.value;return S.operator==="contains"?{id:S.field,value:R}:(C?.type==="date"&&R instanceof Date&&(R=Math.floor(R.getTime()/1e3)),C?.type==="boolean"&&(R=R?1:0),{id:S.field,value:`${S.operator}:${R}`})});s.setColumnFilters(w),o(!1)};return e.jsx("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(Ix,{refetch:n}),e.jsx(T,{placeholder:r("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:w=>s.getColumn("email")?.setFilterValue(w.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(Ar,{open:x,onOpenChange:o,children:[e.jsx($r,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(yi,{className:"mr-2 h-4 w-4"}),r("filter.advanced"),c.length>0&&e.jsx(K,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:c.length})]})}),e.jsxs(fa,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(pa,{children:[e.jsx(ga,{children:r("filter.sheet.title")}),e.jsx(ja,{children:r("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:r("filter.sheet.conditions")}),e.jsx(E,{variant:"outline",size:"sm",onClick:V,children:r("filter.sheet.add")})]}),e.jsx(rt,{className:"h-[calc(100vh-280px)] pr-4",children:e.jsx("div",{className:"space-y-4",children:c.map((w,S)=>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(_t,{children:r("filter.sheet.condition",{number:S+1})}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>f(S),children:e.jsx(Oe,{className:"h-4 w-4"})})]}),e.jsxs(W,{value:w.field,onValueChange:C=>_(S,"field",C),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:r("filter.sheet.field")})}),e.jsx(G,{children:d.map(C=>e.jsx($,{value:C.value,children:C.label},C.value))})]}),w.field&&e.jsxs(W,{value:w.operator,onValueChange:C=>_(S,"operator",C),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:r("filter.sheet.operator")})}),e.jsx(G,{children:d.find(C=>C.value===w.field)?.operators.map(C=>e.jsx($,{value:C.value,children:C.label},C.value))})]}),w.field&&w.operator&&D(w,S)]},S))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(E,{variant:"outline",onClick:()=>{u([]),o(!1)},children:r("filter.sheet.reset")}),e.jsx(E,{onClick:b,children:r("filter.sheet.apply")})]})]})]})]}),i&&e.jsxs(E,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),u([])},className:"h-8 px-2 lg:px-3",children:[r("filter.reset"),e.jsx(Oe,{className:"ml-2 h-4 w-4"})]})]})})}const zx=h.object({id:h.number(),email:h.string().email(),invite_user_email:h.string().email().nullable().optional(),password:h.string().optional().nullable(),balance:h.coerce.number(),commission_balance:h.coerce.number(),u:h.number(),d:h.number(),transfer_enable:h.number(),expired_at:h.number().nullable(),plan_id:h.number().nullable(),banned:h.number(),commission_type:h.number(),commission_rate:h.number().nullable(),discount:h.number().nullable(),speed_limit:h.number().nullable(),device_limit:h.number().nullable(),is_admin:h.number(),is_staff:h.number(),remarks:h.string().nullable()}),Hr=m.createContext(void 0);function Lx({children:s,defaultValues:n,open:a,onOpenChange:l}){const[r,i]=m.useState(!1),[c,u]=m.useState(!1),[x,o]=m.useState([]),d=ce({resolver:ue(zx),defaultValues:n,mode:"onChange"});m.useEffect(()=>{a!==void 0&&i(a)},[a]);const p=k=>{i(k),l?.(k)};return e.jsx(Hr.Provider,{value:{form:d,formOpen:r,setFormOpen:p,datePickerOpen:c,setDatePickerOpen:u,planList:x,setPlanList:o},children:s})}function Ax(){const s=m.useContext(Hr);if(!s)throw new Error("useUserForm must be used within a UserFormProvider");return s}function $x({refetch:s}){const{t:n}=I("user"),{form:a,formOpen:l,setFormOpen:r,datePickerOpen:i,setDatePickerOpen:c,planList:u,setPlanList:x}=Ax();return m.useEffect(()=>{l&&Fs().then(({data:o})=>{x(o)})},[l,x]),e.jsxs(xe,{...a,children:[e.jsx(j,{control:a.control,name:"email",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.email")}),e.jsx(N,{children:e.jsx(T,{...o,placeholder:n("edit.form.email_placeholder")})}),e.jsx(P,{...o})]})}),e.jsx(j,{control:a.control,name:"invite_user_email",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.inviter_email")}),e.jsx(N,{children:e.jsx(T,{value:o.value||"",onChange:d=>o.onChange(d.target.value?d.target.value:null),placeholder:n("edit.form.inviter_email_placeholder")})}),e.jsx(P,{...o})]})}),e.jsx(j,{control:a.control,name:"password",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.password")}),e.jsx(N,{children:e.jsx(T,{value:o.value||"",onChange:o.onChange,placeholder:n("edit.form.password_placeholder")})}),e.jsx(P,{...o})]})}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsx(j,{control:a.control,name:"balance",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.balance")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:o.value||"",onChange:o.onChange,placeholder:n("edit.form.balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(P,{...o})]})}),e.jsx(j,{control:a.control,name:"commission_balance",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.commission_balance")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:o.value||"",onChange:o.onChange,placeholder:n("edit.form.commission_balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(P,{...o})]})}),e.jsx(j,{control:a.control,name:"u",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.upload")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{value:o.value/1024/1024/1024||"",onChange:d=>o.onChange(parseInt(d.target.value)*1024*1024*1024),placeholder:n("edit.form.upload_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{...o})]})}),e.jsx(j,{control:a.control,name:"d",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.download")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:o.value/1024/1024/1024||"",onChange:d=>o.onChange(parseInt(d.target.value)*1024*1024*1024),placeholder:n("edit.form.download_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{...o})]})})]}),e.jsx(j,{control:a.control,name:"transfer_enable",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.total_traffic")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:o.value/1024/1024/1024||"",onChange:d=>o.onChange(parseInt(d.target.value)*1024*1024*1024),placeholder:n("edit.form.total_traffic_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{})]})}),e.jsx(j,{control:a.control,name:"expired_at",render:({field:o})=>e.jsxs(g,{className:"flex flex-col",children:[e.jsx(v,{children:n("edit.form.expire_time")}),e.jsxs(as,{open:i,onOpenChange:c,children:[e.jsx(ns,{asChild:!0,children:e.jsx(N,{children:e.jsxs(E,{type:"button",variant:"outline",className:y("w-full pl-3 text-left font-normal",!o.value&&"text-muted-foreground"),onClick:()=>c(!0),children:[o.value?me(o.value):e.jsx("span",{children:n("edit.form.expire_time_placeholder")}),e.jsx(it,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(We,{className:"w-auto p-0",align:"start",side:"top",sideOffset:4,onInteractOutside:d=>{d.preventDefault()},onEscapeKeyDown:d=>{d.preventDefault()},children:e.jsxs("div",{className:"flex flex-col space-y-3 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{o.onChange(null),c(!1)},children:n("edit.form.expire_time_permanent")}),e.jsx(E,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const d=new Date;d.setMonth(d.getMonth()+1),d.setHours(23,59,59,999),o.onChange(Math.floor(d.getTime()/1e3)),c(!1)},children:n("edit.form.expire_time_1month")}),e.jsx(E,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const d=new Date;d.setMonth(d.getMonth()+3),d.setHours(23,59,59,999),o.onChange(Math.floor(d.getTime()/1e3)),c(!1)},children:n("edit.form.expire_time_3months")})]}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Ms,{mode:"single",selected:o.value?new Date(o.value*1e3):void 0,onSelect:d=>{if(d){const p=new Date(o.value?o.value*1e3:Date.now());d.setHours(p.getHours(),p.getMinutes(),p.getSeconds()),o.onChange(Math.floor(d.getTime()/1e3))}},disabled:d=>d{const d=new Date;d.setHours(23,59,59,999),o.onChange(Math.floor(d.getTime()/1e3))},className:"h-6 px-2 text-xs",children:n("edit.form.expire_time_today")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{type:"datetime-local",step:"1",value:me(o.value,"YYYY-MM-DDTHH:mm:ss"),onChange:d=>{const p=new Date(d.target.value);isNaN(p.getTime())||o.onChange(Math.floor(p.getTime()/1e3))},className:"flex-1"}),e.jsx(E,{type:"button",variant:"outline",onClick:()=>c(!1),children:n("edit.form.expire_time_confirm")})]})]})]})})]}),e.jsx(P,{})]})}),e.jsx(j,{control:a.control,name:"plan_id",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.subscription")}),e.jsx(N,{children:e.jsxs(W,{value:o.value?o.value.toString():"null",onValueChange:d=>o.onChange(d==="null"?null:parseInt(d)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:n("edit.form.subscription_none")})}),e.jsxs(G,{children:[e.jsx($,{value:"null",children:n("edit.form.subscription_none")}),u.map(d=>e.jsx($,{value:d.id.toString(),children:d.name},d.id))]})]})})]})}),e.jsx(j,{control:a.control,name:"banned",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.account_status")}),e.jsx(N,{children:e.jsxs(W,{value:o.value.toString(),onValueChange:d=>o.onChange(parseInt(d)),children:[e.jsx(B,{children:e.jsx(Y,{})}),e.jsxs(G,{children:[e.jsx($,{value:"1",children:n("columns.status_text.banned")}),e.jsx($,{value:"0",children:n("columns.status_text.normal")})]})]})})]})}),e.jsx(j,{control:a.control,name:"commission_type",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.commission_type")}),e.jsx(N,{children:e.jsxs(W,{value:o.value.toString(),onValueChange:d=>o.onChange(parseInt(d)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:n("edit.form.subscription_none")})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:n("edit.form.commission_type_system")}),e.jsx($,{value:"1",children:n("edit.form.commission_type_cycle")}),e.jsx($,{value:"2",children:n("edit.form.commission_type_onetime")})]})]})})]})}),e.jsx(j,{control:a.control,name:"commission_rate",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.commission_rate")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:o.value||"",onChange:d=>o.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.commission_rate_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})})]})}),e.jsx(j,{control:a.control,name:"discount",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.discount")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:o.value||"",onChange:d=>o.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.discount_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})}),e.jsx(P,{})]})}),e.jsx(j,{control:a.control,name:"speed_limit",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.speed_limit")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:o.value||"",onChange:d=>o.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.speed_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"Mbps"})]})}),e.jsx(P,{})]})}),e.jsx(j,{control:a.control,name:"device_limit",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.device_limit")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:o.value||"",onChange:d=>o.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.device_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"台"})]})}),e.jsx(P,{})]})}),e.jsx(j,{control:a.control,name:"is_admin",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.is_admin")}),e.jsx("div",{className:"py-2",children:e.jsx(N,{children:e.jsx(H,{checked:o.value===1,onCheckedChange:d=>o.onChange(d?1:0)})})})]})}),e.jsx(j,{control:a.control,name:"is_staff",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.is_staff")}),e.jsx("div",{className:"py-2",children:e.jsx(N,{children:e.jsx(H,{checked:o.value===1,onCheckedChange:d=>o.onChange(d?1:0)})})})]})}),e.jsx(j,{control:a.control,name:"remarks",render:({field:o})=>e.jsxs(g,{children:[e.jsx(v,{children:n("edit.form.remarks")}),e.jsx(N,{children:e.jsx(Cs,{className:"h-24",value:o.value||"",onChange:d=>o.onChange(d.currentTarget.value??null),placeholder:n("edit.form.remarks_placeholder")})}),e.jsx(P,{})]})}),e.jsxs(Kr,{children:[e.jsx(E,{variant:"outline",onClick:()=>r(!1),children:n("edit.form.cancel")}),e.jsx(E,{type:"submit",onClick:()=>{a.handleSubmit(o=>{vd(o).then(({data:d})=>{d&&(q.success(n("edit.form.success")),r(!1),s())})})()},children:n("edit.form.submit")})]})]})}function Ur({refetch:s,defaultValues:n,dialogTrigger:a=e.jsxs(E,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(ct,{className:"mr-2 h-4 w-4"}),t("edit.button")]})}){const{t:l}=I("user"),[r,i]=m.useState(!1);return e.jsx(Lx,{defaultValues:n,open:r,onOpenChange:i,children:e.jsxs(Ar,{open:r,onOpenChange:i,children:[e.jsx($r,{asChild:!0,children:a}),e.jsxs(fa,{className:"max-w-[90%] space-y-4",children:[e.jsxs(pa,{children:[e.jsx(ga,{children:l("edit.title")}),e.jsx(ja,{})]}),e.jsx($x,{refetch:s})]})]})})}const Br=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"})}),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:"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"})}),qx=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"})}),Kx=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"})}),qt=[{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:Xi(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Br,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:Ze(s.original.u)})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Gr,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:Ze(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(K,{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:Ze(n)})}}];function Wr({user_id:s,dialogTrigger:n}){const{t:a}=I(["traffic"]),[l,r]=m.useState(!1),[i,c]=m.useState({pageIndex:0,pageSize:20}),{data:u,isLoading:x}=se({queryKey:["userStats",s,i,l],queryFn:()=>l?Nd({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),o=ze({data:u?.data??[],columns:qt,pageCount:Math.ceil((u?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:Le(),onPaginationChange:c});return e.jsxs(ge,{open:l,onOpenChange:r,children:[e.jsx(Fe,{asChild:!0,children:n}),e.jsxs(he,{className:"sm:max-w-[700px]",children:[e.jsx(ve,{children:e.jsx(je,{children:a("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(ca,{children:[e.jsx(da,{children:o.getHeaderGroups().map(d=>e.jsx(vs,{children:d.headers.map(p=>e.jsx(ua,{className:y("h-10 px-2 text-xs",p.id==="total"&&"text-right"),children:p.isPlaceholder?null:bt(p.column.columnDef.header,p.getContext())},p.id))},d.id))}),e.jsx(ma,{children:x?Array.from({length:i.pageSize}).map((d,p)=>e.jsx(vs,{children:Array.from({length:qt.length}).map((k,V)=>e.jsx($s,{className:"p-2",children:e.jsx(Ve,{className:"h-6 w-full"})},V))},p)):o.getRowModel().rows?.length?o.getRowModel().rows.map(d=>e.jsx(vs,{"data-state":d.getIsSelected()&&"selected",className:"h-10",children:d.getVisibleCells().map(p=>e.jsx($s,{className:"px-2",children:bt(p.column.columnDef.cell,p.getContext())},p.id))},d.id)):e.jsx(vs,{children:e.jsx($s,{colSpan:qt.length,className:"h-24 text-center",children:a("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:a("trafficRecord.perPage")}),e.jsxs(W,{value:`${o.getState().pagination.pageSize}`,onValueChange:d=>{o.setPageSize(Number(d))},children:[e.jsx(B,{className:"h-8 w-[70px]",children:e.jsx(Y,{placeholder:o.getState().pagination.pageSize})}),e.jsx(G,{side:"top",children:[10,20,30,40,50].map(d=>e.jsx($,{value:`${d}`,children:d},d))})]}),e.jsx("p",{className:"text-sm font-medium",children:a("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:a("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()||x,children:e.jsx(qx,{className:"h-4 w-4"})}),e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>o.nextPage(),disabled:!o.getCanNextPage()||x,children:e.jsx(Kx,{className:"h-4 w-4"})})]})]})]})]})]})]})}const Hx=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"})}),Ux=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"})}),Bx=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"})}),Gx=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"})}),Wx=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"})}),Yx=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"})}),Jx=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"})}),Qx=(s,n)=>{const{t:a}=I("user");return[{accessorKey:"is_admin",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(l,r,i)=>i.includes(l.getValue(r)),size:0},{accessorKey:"is_staff",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(l,r,i)=>i.includes(l.getValue(r)),size:0},{accessorKey:"id",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.id")}),cell:({row:l})=>e.jsx(K,{variant:"outline",children:l.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.email")}),cell:({row:l})=>{const r=l.original.t||0,i=Date.now()/1e3-r<120,c=Math.floor(Date.now()/1e3-r);let u=i?a("columns.online_status.online"):r===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:me(r)});if(!i&&r!==0){const x=Math.floor(c/60),o=Math.floor(x/60),d=Math.floor(o/24);d>0?u+=` -`+a("columns.online_status.offline_duration.days",{count:d}):o>0?u+=` -`+a("columns.online_status.offline_duration.hours",{count:o}):x>0?u+=` -`+a("columns.online_status.offline_duration.minutes",{count:x}):u+=` -`+a("columns.online_status.offline_duration.seconds",{count:c})}return e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:y("size-2.5 rounded-full ring-2 ring-offset-2",i?"bg-green-500 ring-green-500/20":"bg-gray-300 ring-gray-300/20","transition-all duration-300")}),e.jsx("span",{className:"font-medium text-foreground/90",children:l.original.email})]})}),e.jsx(te,{side:"bottom",className:"max-w-[280px]",children:e.jsx("p",{className:"whitespace-pre-line text-sm",children:u})})]})})},enableSorting:!1,enableHiding:!1},{accessorKey:"online_count",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.online_count")}),cell:({row:l})=>{const r=l.original.device_limit,i=l.original.online_count||0;return e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(K,{variant:"outline",className:y("min-w-[4rem] justify-center",r!==null&&i>=r?"border-destructive/50 bg-destructive/10 text-destructive":"border-primary/40 bg-primary/5 text-primary/90"),children:[i," / ",r===null?"∞":r]})})}),e.jsx(te,{side:"bottom",children:e.jsx("p",{className:"text-sm",children:r===null?a("columns.device_limit.unlimited"):a("columns.device_limit.limited",{count:r})})})]})})},enableSorting:!0,enableHiding:!1},{accessorKey:"banned",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.status")}),cell:({row:l})=>{const r=l.original.banned;return e.jsx("div",{className:"flex justify-center",children:e.jsx(K,{className:y("min-w-20 justify-center transition-colors",r?"bg-destructive/15 text-destructive hover:bg-destructive/25":"bg-success/15 text-success hover:bg-success/25"),children:a(r?"columns.status_text.banned":"columns.status_text.normal")})})},enableSorting:!0,filterFn:(l,r,i)=>i.includes(l.getValue(r))},{accessorKey:"plan_id",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.subscription")}),cell:({row:l})=>e.jsx("div",{className:"min-w-[10em] break-all",children:l.original?.plan?.name||"-"}),enableSorting:!1,enableHiding:!1},{accessorKey:"group_id",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.group")}),cell:({row:l})=>e.jsx("div",{className:"flex flex-wrap gap-1",children:e.jsx(K,{variant:"outline",className:y("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 whitespace-nowrap"),children:l.original?.group?.name||"-"})}),enableSorting:!1},{accessorKey:"total_used",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.used_traffic")}),cell:({row:l})=>{const r=Ze(l.original?.total_used),i=Ze(l.original?.transfer_enable),c=l.original?.total_used/l.original?.transfer_enable*100||0;return e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{className:"w-full",children:e.jsxs("div",{className:"w-full space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:r}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[c.toFixed(1),"%"]})]}),e.jsx("div",{className:"h-1.5 w-full rounded-full bg-secondary",children:e.jsx("div",{className:y("h-full rounded-full transition-all",c>90?"bg-destructive":"bg-primary"),style:{width:`${Math.min(c,100)}%`}})})]})}),e.jsx(te,{side:"bottom",children:e.jsxs("p",{className:"text-sm",children:[a("columns.total_traffic"),": ",i]})})]})})}},{accessorKey:"transfer_enable",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.total_traffic")}),cell:({row:l})=>e.jsx("div",{className:"font-medium text-muted-foreground",children:Ze(l.original?.transfer_enable)})},{accessorKey:"expired_at",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.expire_time")}),cell:({row:l})=>{const r=l.original.expired_at,i=Date.now()/1e3,c=r!=null&&re.jsx(M,{column:l,title:a("columns.balance")}),cell:({row:l})=>{const r=As(l.original?.balance);return e.jsxs("div",{className:"flex items-center gap-1 font-medium",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"¥"}),e.jsx("span",{className:"tabular-nums text-foreground",children:r})]})}},{accessorKey:"commission_balance",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.commission")}),cell:({row:l})=>{const r=As(l.original?.commission_balance);return e.jsxs("div",{className:"flex items-center gap-1 font-medium",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"¥"}),e.jsx("span",{className:"tabular-nums text-foreground",children:r})]})}},{accessorKey:"created_at",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.register_time")}),cell:({row:l})=>e.jsx("div",{className:"truncate",children:me(l.original?.created_at)}),size:1e3},{id:"actions",header:({column:l})=>e.jsx(M,{column:l,className:"justify-end",title:a("columns.actions")}),cell:({row:l,table:r})=>e.jsxs(ys,{modal:!0,children:[e.jsx(Ns,{asChild:!0,children:e.jsx("div",{className:"text-center",children:e.jsx(J,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":a("columns.actions"),children:e.jsx(Nt,{className:"size-4"})})})}),e.jsxs(os,{align:"end",className:"min-w-[40px]",children:[e.jsx(fe,{onSelect:i=>{i.preventDefault()},className:"p-0",children:e.jsx(Ur,{defaultValues:{...l.original,invite_user_email:l.original.invite_user?.email},refetch:s,dialogTrigger:e.jsxs(J,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Hx,{className:"mr-2"}),a("columns.actions_menu.edit")]})})}),e.jsx(fe,{onSelect:i=>i.preventDefault(),className:"p-0",children:e.jsx(Or,{defaultValues:{email:l.original.email},trigger:e.jsxs(J,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Ux,{className:"mr-2 "}),a("columns.actions_menu.assign_order")]})})}),e.jsx(fe,{onSelect:()=>{wt(l.original.subscribe_url).then(()=>{q.success(a("common:copy.success"))})},className:"p-0",children:e.jsxs(J,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Bx,{className:"mr-2"}),a("columns.actions_menu.copy_url")]})}),e.jsx(fe,{onSelect:()=>{bd({id:l.original.id}).then(({data:i})=>{i&&q.success("重置成功")})},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Gx,{className:"mr-2 "}),a("columns.actions_menu.reset_secret")]})}),e.jsx(fe,{onSelect:()=>{},className:"p-0",children:e.jsxs(Rs,{className:"flex items-center px-2 py-1.5",to:`/finance/order?user_id=${l.original?.id}`,children:[e.jsx(Wx,{className:"mr-2"}),a("columns.actions_menu.orders")]})}),e.jsx(fe,{onSelect:()=>{r.setColumnFilters([{id:"invite_user_id",value:l.original?.id}])},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Yx,{className:"mr-2 "}),a("columns.actions_menu.invites")]})}),e.jsx(fe,{onSelect:i=>i.preventDefault(),className:"p-0",children:e.jsx(Wr,{user_id:l.original?.id,dialogTrigger:e.jsxs(J,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Jx,{className:"mr-2 "}),a("columns.actions_menu.traffic_records")]})})})]})]})}]};function Zx(){const[s]=Kn(),[n,a]=m.useState({}),[l,r]=m.useState({is_admin:!1,is_staff:!1}),[i,c]=m.useState([]),[u,x]=m.useState([]),[o,d]=m.useState({pageIndex:0,pageSize:20});m.useEffect(()=>{const R=s.get("email");R&&c(z=>z.some(A=>A.id==="email")?z:[...z,{id:"email",value:R}])},[s]);const{refetch:p,data:k,isLoading:V}=se({queryKey:["userList",o,i,u],queryFn:()=>jd({pageSize:o.pageSize,current:o.pageIndex+1,filter:i,sort:u})}),[f,_]=m.useState([]),[D,b]=m.useState([]);m.useEffect(()=>{It().then(({data:R})=>{_(R)}),Fs().then(({data:R})=>{b(R)})},[]);const w=f.map(R=>({label:R.name,value:R.id})),S=D.map(R=>({label:R.name,value:R.id})),C=ze({data:k?.data??[],columns:Qx(p),state:{sorting:u,columnVisibility:l,rowSelection:n,columnFilters:i,pagination:o},rowCount:k?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:x,onColumnFiltersChange:c,onColumnVisibilityChange:r,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),onPaginationChange:d,getSortedRowModel:Ge(),getFacetedRowModel:ds(),getFacetedUniqueValues:ms(),initialState:{columnVisibility:{commission_balance:!1,created_at:!1,is_admin:!1,is_staff:!1,permission_group:!1,plan_id:!1},columnPinning:{right:["actions"]}}});return e.jsx(Ye,{table:C,toolbar:e.jsx(Ox,{table:C,refetch:p,serverGroupList:f,permissionGroups:w,subscriptionPlans:S})})}function Xx(){const{t:s}=I("user");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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:"mt-2 text-muted-foreground",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("div",{className:"w-full",children:e.jsx(Zx,{})})})]})]})}const eh=Object.freeze(Object.defineProperty({__proto__:null,default:Xx},Symbol.toStringTag,{value:"Module"}));function sh({column:s,title:n,options:a}){const l=new Set(s?.getFilterValue());return e.jsxs(as,{children:[e.jsx(ns,{asChild:!0,children:e.jsxs(J,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Ni,{className:"mr-2 h-4 w-4"}),n,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:l.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:l.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[l.size," selected"]}):a.filter(r=>l.has(r.value)).map(r=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:r.label},`selected-${r.value}`))})]})]})}),e.jsx(We,{className:"w-[200px] p-0",align:"start",children:e.jsxs(_s,{children:[e.jsx(Vs,{placeholder:n}),e.jsxs(ws,{children:[e.jsx(Is,{children:"No results found."}),e.jsx(Ie,{children:a.map(r=>{const i=l.has(r.value);return e.jsxs(_e,{onSelect:()=>{i?l.delete(r.value):l.add(r.value);const c=Array.from(l);s?.setFilterValue(c.length?c:void 0)},children:[e.jsx("div",{className:y("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",i?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(_i,{className:y("h-4 w-4")})}),r.icon&&e.jsx(r.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:r.label})]},`option-${r.value}`)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Ie,{children:e.jsx(_e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const 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:"M19 11H5a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2"})});function ah({table:s}){const{t:n}=I("ticket");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-4",children:[e.jsx(pr,{defaultValue:s.getColumn("status")?.getFilterValue(),onValueChange:a=>s.getColumn("status")?.setFilterValue(a),children:e.jsxs(ia,{className:"grid w-full grid-cols-2",children:[e.jsx(nt,{value:"0",children:n("status.pending")}),e.jsx(nt,{value:"1",children:n("status.closed")})]})}),s.getColumn("level")&&e.jsx(sh,{column:s.getColumn("level"),title:n("columns.level"),options:[{label:n("level.low"),value:Xe.LOW,icon:th,color:"gray"},{label:n("level.medium"),value:Xe.MIDDLE,icon:Br,color:"yellow"},{label:n("level.high"),value:Xe.HIGH,icon:Gr,color:"red"}]})]})})}function nh(){return e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",className:"text-foreground",children:[e.jsx("circle",{cx:"4",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{id:"spinner_qFRN",begin:"0;spinner_OcgL.end+0.25s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})}),e.jsx("circle",{cx:"12",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{begin:"spinner_qFRN.begin+0.1s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})}),e.jsx("circle",{cx:"20",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{id:"spinner_OcgL",begin:"spinner_qFRN.begin+0.2s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})})]})}const rh=Ts("flex gap-2 max-w-[60%] items-end relative group",{variants:{variant:{received:"self-start",sent:"self-end flex-row-reverse"},layout:{default:"",ai:"max-w-full w-full items-center"}},defaultVariants:{variant:"received",layout:"default"}}),Yr=m.forwardRef(({className:s,variant:n,layout:a,children:l,...r},i)=>e.jsx("div",{className:y(rh({variant:n,layout:a,className:s}),"relative group"),ref:i,...r,children:m.Children.map(l,c=>m.isValidElement(c)&&typeof c.type!="string"?m.cloneElement(c,{variant:n,layout:a}):c)}));Yr.displayName="ChatBubble";const lh=Ts("p-4",{variants:{variant:{received:"bg-secondary text-secondary-foreground rounded-r-lg rounded-tl-lg",sent:"bg-primary text-primary-foreground rounded-l-lg rounded-tr-lg"},layout:{default:"",ai:"border-t w-full rounded-none bg-transparent"}},defaultVariants:{variant:"received",layout:"default"}}),Jr=m.forwardRef(({className:s,variant:n,layout:a,isLoading:l=!1,children:r,...i},c)=>e.jsx("div",{className:y(lh({variant:n,layout:a,className:s}),"break-words max-w-full whitespace-pre-wrap"),ref:c,...i,children:l?e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(nh,{})}):r}));Jr.displayName="ChatBubbleMessage";const oh=m.forwardRef(({variant:s,className:n,children:a,...l},r)=>e.jsx("div",{ref:r,className:y("absolute top-1/2 -translate-y-1/2 flex opacity-0 group-hover:opacity-100 transition-opacity duration-200",s==="sent"?"-left-1 -translate-x-full flex-row-reverse":"-right-1 translate-x-full",n),...l,children:a}));oh.displayName="ChatBubbleActionWrapper";const Qr=m.forwardRef(({className:s,...n},a)=>e.jsx(Cs,{autoComplete:"off",ref:a,name:"message",className:y("max-h-12 px-4 py-3 bg-background text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 w-full rounded-md flex items-center h-16 resize-none",s),...n}));Qr.displayName="ChatInput";const Zr=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:"m13.41 12l4.3-4.29a1 1 0 1 0-1.42-1.42L12 10.59l-4.29-4.3a1 1 0 0 0-1.42 1.42l4.3 4.29l-4.3 4.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0l4.29-4.3l4.29 4.3a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42Z"})}),Xr=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.098 12.634L13 11.423V7a1 1 0 0 0-2 0v5a1 1 0 0 0 .5.866l2.598 1.5a1 1 0 1 0 1-1.732M12 2a10 10 0 1 0 10 10A10.01 10.01 0 0 0 12 2m0 18a8 8 0 1 1 8-8a8.01 8.01 0 0 1-8 8"})}),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:"M3.71 16.29a1 1 0 0 0-.33-.21a1 1 0 0 0-.76 0a1 1 0 0 0-.33.21a1 1 0 0 0-.21.33a1 1 0 0 0 .21 1.09a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21a1 1 0 0 0 .21-1.09a1 1 0 0 0-.21-.33M7 8h14a1 1 0 0 0 0-2H7a1 1 0 0 0 0 2m-3.29 3.29a1 1 0 0 0-1.09-.21a1.2 1.2 0 0 0-.33.21a1 1 0 0 0-.21.33a.94.94 0 0 0 0 .76a1.2 1.2 0 0 0 .21.33a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21a1.2 1.2 0 0 0 .21-.33a.94.94 0 0 0 0-.76a1 1 0 0 0-.21-.33M21 11H7a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2M3.71 6.29a1 1 0 0 0-.33-.21a1 1 0 0 0-1.09.21a1.2 1.2 0 0 0-.21.33a.94.94 0 0 0 0 .76a1.2 1.2 0 0 0 .21.33a1.2 1.2 0 0 0 .33.21a1 1 0 0 0 1.09-.21a1.2 1.2 0 0 0 .21-.33a.94.94 0 0 0 0-.76a1.2 1.2 0 0 0-.21-.33M21 16H7a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2"})}),ch=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 12H7a1 1 0 0 0 0 2h2a1 1 0 0 0 0-2m-1-2h4a1 1 0 0 0 0-2H8a1 1 0 0 0 0 2m1 6H7a1 1 0 0 0 0 2h2a1 1 0 0 0 0-2m12-4h-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-5h2Zm-6.44-2.83a.8.8 0 0 0-.18-.09a.6.6 0 0 0-.19-.06a1 1 0 0 0-.9.27A1.05 1.05 0 0 0 12 17a1 1 0 0 0 .07.38a1.2 1.2 0 0 0 .22.33a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21A1 1 0 0 0 14 17a1.05 1.05 0 0 0-.29-.71a2 2 0 0 0-.15-.12m.14-3.88a1 1 0 0 0-1.62.33A1 1 0 0 0 13 14a1 1 0 0 0 1-1a1 1 0 0 0-.08-.38a.9.9 0 0 0-.22-.33"})});function dh(){return e.jsxs("div",{className:"flex h-full flex-col space-y-4 p-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ve,{className:"h-8 w-3/4"}),e.jsx(Ve,{className:"h-4 w-1/2"})]}),e.jsx("div",{className:"flex-1 space-y-4",children:[1,2,3].map(s=>e.jsx(Ve,{className:"h-20 w-2/3"},s))})]})}function mh({ticketId:s,dialogTrigger:n}){const{t:a}=I("ticket"),l=is(),r=m.useRef(null),[i,c]=m.useState(!1),[u,x]=m.useState(""),[o,d]=m.useState(!1),{data:p,refetch:k,isLoading:V}=se({queryKey:["ticket",s,i],queryFn:()=>i?wd(s):Promise.resolve(null),refetchInterval:i?5e3:!1,retry:3}),f=p?.data,_=(C="smooth")=>{if(r.current){const{scrollHeight:R,clientHeight:z}=r.current;r.current.scrollTo({top:R-z,behavior:C})}};m.useEffect(()=>{if(!i)return;const C=requestAnimationFrame(()=>{_("instant"),setTimeout(()=>_(),1e3)});return()=>{cancelAnimationFrame(C)}},[i,f?.messages]);const D=async()=>{const C=u.trim();!C||o||(d(!0),Cd({id:s,message:C}).then(()=>{x(""),k(),_()}).finally(()=>{d(!1)}))},b=async()=>{fr(s).then(()=>{q.success(a("actions.close_success")),k()})},w=()=>{f?.user&&l("/finance/order?user_id="+f.user.id)},S=f?.status===et.CLOSED;return e.jsxs(ge,{open:i,onOpenChange:c,children:[e.jsx(Fe,{asChild:!0,children:n??e.jsx(J,{variant:"outline",children:a("actions.view_ticket")})}),e.jsxs(he,{className:"flex h-[90vh] max-w-4xl flex-col gap-0 p-0",children:[e.jsx(je,{}),V?e.jsx(dh,{}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-col space-y-4 border-b p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("h2",{className:"text-2xl font-semibold",children:f?.subject}),e.jsx(K,{variant:S?"secondary":"default",children:a(S?"status.closed":"status.processing")}),!S&&e.jsx(Je,{title:a("actions.close_confirm_title"),description:a("actions.close_confirm_description"),confirmText:a("actions.close_confirm_button"),variant:"destructive",onConfirm:b,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"gap-1 text-muted-foreground hover:text-destructive",children:[e.jsx(Zr,{className:"h-4 w-4"}),a("actions.close_ticket")]})})]}),e.jsxs("div",{className:"flex items-center space-x-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(ot,{className:"h-4 w-4"}),e.jsx("span",{children:f?.user?.email})]}),e.jsx(be,{orientation:"vertical",className:"h-4"}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Xr,{className:"h-4 w-4"}),e.jsxs("span",{children:[a("detail.created_at")," ",me(f?.created_at)]})]}),e.jsx(be,{orientation:"vertical",className:"h-4"}),e.jsx(K,{variant:"outline",children:f?.level!=null&&a(`level.${f.level===Xe.LOW?"low":f.level===Xe.MIDDLE?"medium":"high"}`)})]})]}),f?.user&&e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(Ur,{defaultValues:f.user,refetch:k,dialogTrigger:e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",title:a("detail.user_info"),children:e.jsx(ot,{className:"h-4 w-4"})})}),e.jsx(Wr,{user_id:f.user.id,dialogTrigger:e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",title:a("detail.traffic_records"),children:e.jsx(ih,{className:"h-4 w-4"})})}),e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",title:a("detail.order_records"),onClick:w,children:e.jsx(ch,{className:"h-4 w-4"})})]})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{ref:r,className:"h-full space-y-4 overflow-y-auto p-6",children:f?.messages?.length===0?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:a("detail.no_messages")}):f?.messages?.map(C=>e.jsx(Yr,{variant:C.is_me?"sent":"received",className:C.is_me?"ml-auto":"mr-auto",children:e.jsx(Jr,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"whitespace-pre-wrap break-words",children:C.message}),e.jsx("div",{className:"text-right",children:e.jsx("time",{className:"text-[10px] text-muted-foreground",children:me(C.created_at)})})]})})},C.id))})}),e.jsx("div",{className:"border-t p-4",children:e.jsxs("div",{className:"relative flex items-center space-x-2",children:[e.jsx(Qr,{disabled:S||o,placeholder:a(S?"detail.input.closed_placeholder":"detail.input.reply_placeholder"),className:"flex-1 resize-none rounded-lg border bg-background p-3 focus-visible:ring-1",value:u,onChange:C=>x(C.target.value),onKeyDown:C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),D())}}),e.jsx(J,{disabled:S||o||!u.trim(),onClick:D,children:a(o?"detail.input.sending":"detail.input.send")})]})})]})]})]})}const uh=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 4H5a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3V7a3 3 0 0 0-3-3m-.41 2l-5.88 5.88a1 1 0 0 1-1.42 0L5.41 6ZM20 17a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7.41l5.88 5.88a3 3 0 0 0 4.24 0L20 7.41Z"})}),xh=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.92 11.6C19.9 6.91 16.1 4 12 4s-7.9 2.91-9.92 7.6a1 1 0 0 0 0 .8C4.1 17.09 7.9 20 12 20s7.9-2.91 9.92-7.6a1 1 0 0 0 0-.8M12 18c-3.17 0-6.17-2.29-7.9-6C5.83 8.29 8.83 6 12 6s6.17 2.29 7.9 6c-1.73 3.71-4.73 6-7.9 6m0-10a4 4 0 1 0 4 4a4 4 0 0 0-4-4m0 6a2 2 0 1 1 2-2a2 2 0 0 1-2 2"})}),hh=s=>{const{t:n}=I("ticket");return[{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.id")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:a.getValue("id")}),enableSorting:!1,enableHiding:!1},{accessorKey:"subject",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.subject")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(uh,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"max-w-[500px] truncate font-medium",children:a.getValue("subject")})]}),enableSorting:!1,enableHiding:!1,size:4e3},{accessorKey:"level",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.level")}),cell:({row:a})=>{const l=a.getValue("level"),r=l===Xe.LOW?"default":l===Xe.MIDDLE?"secondary":"destructive";return e.jsx(K,{variant:r,className:"whitespace-nowrap",children:n(`level.${l===Xe.LOW?"low":l===Xe.MIDDLE?"medium":"high"}`)})},filterFn:(a,l,r)=>r.includes(a.getValue(l))},{accessorKey:"status",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.status")}),cell:({row:a})=>{const l=a.getValue("status"),r=a.original.reply_status,i=l===et.CLOSED?n("status.closed"):n(r===0?"status.replied":"status.pending"),c=l===et.CLOSED?"default":r===0?"secondary":"destructive";return e.jsx(K,{variant:c,className:"whitespace-nowrap",children:i})}},{accessorKey:"updated_at",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.updated_at")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[e.jsx(Xr,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:me(a.getValue("updated_at"))})]}),enableSorting:!0},{accessorKey:"created_at",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.created_at")}),cell:({row:a})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:me(a.getValue("created_at"))}),enableSorting:!0,meta:{isFlexGrow:!0}},{id:"actions",header:({column:a})=>e.jsx(M,{className:"justify-end",column:a,title:n("columns.actions")}),cell:({row:a})=>{const l=a.original.status!==et.CLOSED;return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(mh,{ticketId:a.original.id,dialogTrigger:e.jsx(J,{variant:"ghost",size:"icon",className:"h-8 w-8",title:n("actions.view_details"),children:e.jsx(xh,{className:"h-4 w-4"})})}),l&&e.jsx(Je,{title:n("actions.close_confirm_title"),description:n("actions.close_confirm_description"),confirmText:n("actions.close_confirm_button"),variant:"destructive",onConfirm:async()=>{fr(a.original.id).then(()=>{q.success(n("actions.close_success")),s()})},children:e.jsx(J,{variant:"ghost",size:"icon",className:"h-8 w-8",title:n("actions.close_ticket"),children:e.jsx(Zr,{className:"h-4 w-4"})})})]})}}]};function fh(){const[s,n]=m.useState({}),[a,l]=m.useState({}),[r,i]=m.useState([{id:"status",value:"0"}]),[c,u]=m.useState([]),[x,o]=m.useState({pageIndex:0,pageSize:20}),{refetch:d,data:p,isLoading:k}=se({queryKey:["orderList",x,r,c],queryFn:()=>_d({pageSize:x.pageSize,current:x.pageIndex+1,filter:r,sort:c})}),V=ze({data:p?.data??[],columns:hh(d),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:x},rowCount:p?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:u,onColumnFiltersChange:i,onColumnVisibilityChange:l,getCoreRowModel:Le(),getFilteredRowModel:Ue(),getPaginationRowModel:Be(),onPaginationChange:o,getSortedRowModel:Ge(),getFacetedRowModel:ds(),getFacetedUniqueValues:ms(),initialState:{columnPinning:{right:["actions"]}}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(ah,{table:V,refetch:d}),e.jsx(Ye,{table:V,showPagination:!0})]})}function ph(){const{t:s}=I("ticket");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(fh,{})})]})]})}const gh=Object.freeze(Object.defineProperty({__proto__:null,default:ph},Symbol.toStringTag,{value:"Module"}));export{Nh as a,bh as c,yh as g,_h as r}; +`))}})})}),e.jsx(R,{})]})}),e.jsx(v,{control:i.control,name:"action",render:({field:x})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsxs(W,{onValueChange:x.onChange,defaultValue:x.value,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:r("form.actionPlaceholder")})}),e.jsxs(G,{children:[e.jsx($,{value:"block",children:r("actions.block")}),e.jsx($,{value:"dns",children:r("actions.dns")})]})]})})}),e.jsx(R,{})]})}),i.watch("action")==="dns"&&e.jsx(v,{control:i.control,name:"action_value",render:({field:x})=>e.jsxs(j,{children:[e.jsx(b,{children:r("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(P,{type:"text",placeholder:r("form.dnsPlaceholder"),...x})})})]})}),e.jsxs(Oe,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(V,{variant:"outline",children:r("form.cancel")})}),e.jsx(V,{type:"submit",onClick:()=>{$c(i.getValues()).then(({data:x})=>{x&&(m(!1),s&&s(),toast.success(r(l==="edit"?"messages.updateSuccess":"messages.createSuccess")),i.reset())})},children:r("form.submit")})]})]})]})]})}function Yu({table:s,refetch:n}){const a=s.getState().columnFilters.length>0,{t:l}=I("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(Ir,{refetch:n}),e.jsx(P,{placeholder:l("toolbar.searchPlaceholder"),value:s.getColumn("remarks")?.getFilterValue()??"",onChange:r=>s.getColumn("remarks")?.setFilterValue(r.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),a&&e.jsxs(V,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("toolbar.reset"),e.jsx(ze,{className:"ml-2 h-4 w-4"})]})]})})}function Ju({columns:s,data:n,refetch:a}){const[l,r]=u.useState({}),[i,c]=u.useState({}),[m,x]=u.useState([]),[o,d]=u.useState([]),p=Le({data:n,columns:s,state:{sorting:o,columnVisibility:i,rowSelection:l,columnFilters:m},enableRowSelection:!0,onRowSelectionChange:r,onSortingChange:d,onColumnFiltersChange:x,onColumnVisibilityChange:c,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),getSortedRowModel:We(),getFacetedRowModel:ms(),getFacetedUniqueValues:us(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Je,{table:p,toolbar:k=>e.jsx(Yu,{table:k,refetch:a})})}const Qu=s=>{const{t:n}=I("route"),a={block:{icon:hi,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:fi,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:l})=>e.jsx(M,{column:l,title:n("columns.id")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:l.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:l})=>e.jsx(M,{column:l,title:n("columns.remarks")}),cell:({row:l})=>{const r=l.original.match?.length||0;return 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:n("columns.matchRules",{count:r})})})},enableHiding:!1,enableSorting:!1},{accessorKey:"action",header:({column:l})=>e.jsx(M,{column:l,title:n("columns.action")}),cell:({row:l})=>{const r=l.getValue("action"),i=a[r]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(K,{variant:a[r]?.variant||"default",className:y("flex items-center gap-1.5 px-3 py-1 capitalize",a[r]?.className),children:[i&&e.jsx(i,{className:"h-3.5 w-3.5"}),n(`actions.${r}`)]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:n("columns.actions")}),cell:({row:l})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Ir,{defaultValues:l.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Es,{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()=>{qc({id:l.original.id}).then(({data:r})=>{r&&(q.success(n("messages.deleteSuccess")),s())})},children:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{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 Zu(){const{t:s}=I("route"),[n,a]=u.useState([]);function l(){hr().then(({data:r})=>{a(r)})}return u.useEffect(()=>{l()},[]),e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(Ju,{data:n,columns:Qu(l),refetch:l})})]})]})}const Xu=Object.freeze(Object.defineProperty({__proto__:null,default:Zu},Symbol.toStringTag,{value:"Module"})),Fr=u.createContext(void 0);function ex({children:s,refreshData:n}){const[a,l]=u.useState(!1),[r,i]=u.useState(null);return e.jsx(Fr.Provider,{value:{isOpen:a,setIsOpen:l,editingPlan:r,setEditingPlan:i,refreshData:n},children:s})}function ha(){const s=u.useContext(Fr);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function sx({table:s,saveOrder:n,isSortMode:a}){const{setIsOpen:l}=ha(),{t:r}=I("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(V,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>l(!0),children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("div",{children:r("plan.add")})]}),e.jsx(P,{placeholder:r("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(V,{variant:a?"default":"outline",onClick:n,size:"sm",children:r(a?"plan.sort.save":"plan.sort.edit")})})]})}const $a={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"}},tx=s=>{const{t:n}=I("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(Pt,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.id")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:a.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.show")}),cell:({row:a})=>e.jsx(H,{defaultChecked:a.getValue("show"),onCheckedChange:l=>{Lt({id:a.original.id,show:l}).then(({data:r})=>{!r&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.sell")}),cell:({row:a})=>e.jsx(H,{defaultChecked:a.getValue("sell"),onCheckedChange:l=>{Lt({id:a.original.id,sell:l}).then(({data:r})=>{!r&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.renew"),tooltip:n("plan.columns.renew_tooltip")}),cell:({row:a})=>e.jsx(H,{defaultChecked:a.getValue("renew"),onCheckedChange:l=>{Lt({id:a.original.id,renew:l}).then(({data:r})=>{!r&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.name")}),cell:({row:a})=>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:a.getValue("name")})}),enableSorting:!1,enableHiding:!1,size:900},{accessorKey:"users_count",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.stats")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-2",children:[e.jsx(ot,{}),e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:a.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"group",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.group")}),cell:({row:a})=>e.jsx("div",{className:"flex max-w-[600px] flex-wrap items-center gap-1.5 text-nowrap",children:e.jsx(K,{variant:"secondary",className:y("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.getValue("group")?.name})}),enableSorting:!1,enableHiding:!1},{accessorKey:"prices",header:({column:a})=>e.jsx(M,{column:a,title:n("plan.columns.price")}),cell:({row:a})=>{const l=a.getValue("prices"),r=[{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:r.map(({period:i,key:c,unit:m})=>l[c]!=null&&e.jsxs(K,{variant:"secondary",className:y("px-2 py-0.5 font-medium transition-colors text-nowrap",$a[c].color,$a[c].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[i," ¥",l[c],m]},c))})},enableSorting:!1,size:9e3},{id:"actions",header:({column:a})=>e.jsx(M,{className:"justify-end",column:a,title:n("plan.columns.actions")}),cell:({row:a})=>{const{setIsOpen:l,setEditingPlan:r}=ha();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{r(a.original),l(!0)},children:[e.jsx(Es,{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()=>{od({id:a.original.id}).then(({data:i})=>{i&&(q.success(n("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{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=h.object({id:h.number().nullable(),group_id:h.union([h.number(),h.string()]).nullable().optional(),name:h.string().min(1).max(250),content:h.string().nullable().optional(),transfer_enable:h.union([h.number().min(0),h.string().min(1)]),prices:h.object({monthly:h.union([h.number(),h.string()]).nullable().optional(),quarterly:h.union([h.number(),h.string()]).nullable().optional(),half_yearly:h.union([h.number(),h.string()]).nullable().optional(),yearly:h.union([h.number(),h.string()]).nullable().optional(),two_yearly:h.union([h.number(),h.string()]).nullable().optional(),three_yearly:h.union([h.number(),h.string()]).nullable().optional(),onetime:h.union([h.number(),h.string()]).nullable().optional(),reset_traffic:h.union([h.number(),h.string()]).nullable().optional()}).default({}),speed_limit:h.union([h.number(),h.string()]).nullable().optional(),capacity_limit:h.union([h.number(),h.string()]).nullable().optional(),device_limit:h.union([h.number(),h.string()]).nullable().optional(),force_update:h.boolean().optional(),reset_traffic_method:h.number().nullable(),users_count:h.number().optional()}),Mr=u.forwardRef(({className:s,...n},a)=>e.jsx(Ln,{ref:a,className:y("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(pi,{className:y("flex items-center justify-center text-current"),children:e.jsx(Ps,{className:"h-4 w-4"})})}));Mr.displayName=Ln.displayName;const pt={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},gt={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}},nx=[{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 rx(){const{isOpen:s,setIsOpen:n,editingPlan:a,setEditingPlan:l,refreshData:r}=ha(),[i,c]=u.useState(!1),{t:m}=I("subscribe"),x=ce({resolver:ue(ax),defaultValues:{...pt,...a||{}},mode:"onChange"});u.useEffect(()=>{a?x.reset({...pt,...a}):x.reset(pt)},[a,x]);const o=new ra({html:!0}),[d,p]=u.useState();async function k(){It().then(({data:_})=>{p(_)})}u.useEffect(()=>{s&&k()},[s]);const E=_=>{if(isNaN(_))return;const T=Object.entries(gt).reduce((g,[w,S])=>{const C=_*S.months*S.discount;return{...g,[w]:C.toFixed(2)}},{});x.setValue("prices",T,{shouldDirty:!0})},f=()=>{n(!1),l(null),x.reset(pt)};return e.jsx(ge,{open:s,onOpenChange:f,children:e.jsxs(he,{children:[e.jsxs(ve,{children:[e.jsx(je,{children:m(a?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(De,{})]}),e.jsxs(xe,{...x,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:x.control,name:"name",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:m("plan.form.name.label")}),e.jsx(N,{children:e.jsx(P,{placeholder:m("plan.form.name.placeholder"),..._})}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"group_id",render:({field:_})=>e.jsxs(j,{children:[e.jsxs(b,{className:"flex items-center justify-between",children:[m("plan.form.group.label"),e.jsx(Ft,{dialogTrigger:e.jsx(V,{variant:"link",children:m("plan.form.group.add")}),refetch:k})]}),e.jsxs(W,{value:_.value?.toString()??"",onValueChange:T=>_.onChange(T?Number(T):null),children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:m("plan.form.group.placeholder")})})}),e.jsx(G,{children:d?.map(T=>e.jsx($,{value:T.id.toString(),children:T.name},T.id))})]}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"transfer_enable",render:({field:_})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:m("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(P,{type:"number",min:0,placeholder:m("plan.form.transfer.placeholder"),className:"rounded-r-none",..._})}),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:m("plan.form.transfer.unit")})]}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"speed_limit",render:({field:_})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:m("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(P,{type:"number",min:0,placeholder:m("plan.form.speed.placeholder"),className:"rounded-r-none",..._,value:_.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:m("plan.form.speed.unit")})]}),e.jsx(R,{})]})}),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:m("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(P,{type:"number",placeholder:m("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:_=>{const T=parseFloat(_.target.value);E(T)}})]}),e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(V,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const _=Object.keys(gt).reduce((T,g)=>({...T,[g]:""}),{});x.setValue("prices",_,{shouldDirty:!0})},children:m("plan.form.price.clear.button")})}),e.jsx(te,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:m("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(gt).filter(([_])=>!["onetime","reset_traffic"].includes(_)).map(([_,T])=>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(v,{control:x.control,name:`prices.${_}`,render:({field:g})=>e.jsxs(j,{children:[e.jsxs(b,{className:"text-xs font-medium text-muted-foreground",children:[m(`plan.columns.price_period.${_}`),e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",T.months===1?m("plan.form.price.period.monthly"):m("plan.form.price.period.months",{count:T.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(N,{children:e.jsx(P,{type:"number",placeholder:"0.00",min:0,...g,value:g.value??"",onChange:w=>g.onChange(w.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"})})]})]})})},_))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(gt).filter(([_])=>["onetime","reset_traffic"].includes(_)).map(([_,T])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(v,{control:x.control,name:`prices.${_}`,render:({field:g})=>e.jsx(j,{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(b,{className:"text-xs font-medium",children:m(`plan.columns.price_period.${_}`)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:m(_==="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(N,{children:e.jsx(P,{type:"number",placeholder:"0.00",min:0,...g,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"})})]})]})})})},_))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(v,{control:x.control,name:"device_limit",render:({field:_})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:m("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(P,{type:"number",min:0,placeholder:m("plan.form.device.placeholder"),className:"rounded-r-none",..._,value:_.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:m("plan.form.device.unit")})]}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"capacity_limit",render:({field:_})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:m("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(P,{type:"number",min:0,placeholder:m("plan.form.capacity.placeholder"),className:"rounded-r-none",..._,value:_.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:m("plan.form.capacity.unit")})]}),e.jsx(R,{})]})})]}),e.jsx(v,{control:x.control,name:"reset_traffic_method",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:m("plan.form.reset_method.label")}),e.jsxs(W,{value:_.value?.toString()??"null",onValueChange:T=>_.onChange(T=="null"?null:Number(T)),children:[e.jsx(N,{children:e.jsx(B,{children:e.jsx(Y,{placeholder:m("plan.form.reset_method.placeholder")})})}),e.jsx(G,{children:nx.map(T=>e.jsx($,{value:T.value?.toString()??"null",children:m(`plan.form.reset_method.options.${T.label}`)},T.value))})]}),e.jsx(F,{className:"text-xs",children:m("plan.form.reset_method.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:x.control,name:"content",render:({field:_})=>{const[T,g]=u.useState(!1);return e.jsxs(j,{className:"space-y-2",children:[e.jsxs(b,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[m("plan.form.content.label"),e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(V,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>g(!T),children:T?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(te,{side:"top",children:e.jsx("p",{className:"text-xs",children:m(T?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(ie,{children:e.jsxs(re,{children:[e.jsx(le,{asChild:!0,children:e.jsx(V,{variant:"outline",size:"sm",onClick:()=>{_.onChange(m("plan.form.content.template.content"))},children:m("plan.form.content.template.button")})}),e.jsx(te,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:m("plan.form.content.template.tooltip")})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${T?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(N,{children:e.jsx(la,{style:{height:"400px"},value:_.value||"",renderHTML:w=>o.render(w),onChange:({text:w})=>_.onChange(w),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:m("plan.form.content.placeholder"),className:"rounded-md border"})})}),T&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:m("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(_.value||"")}})})]})]}),e.jsx(F,{className:"text-xs",children:m("plan.form.content.description")}),e.jsx(R,{})]})}})]}),e.jsx(Oe,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:a&&e.jsx(v,{control:x.control,name:"force_update",render:({field:_})=>e.jsxs(j,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(N,{children:e.jsx(Mr,{checked:_.value,onCheckedChange:_.onChange})}),e.jsx("div",{className:"",children:e.jsx(b,{className:"text-sm",children:m("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(V,{type:"button",variant:"outline",onClick:f,children:m("plan.form.submit.cancel")}),e.jsx(V,{type:"submit",disabled:i,onClick:()=>{x.handleSubmit(async _=>{c(!0),(await ld(_)).data&&(q.success(m(a?"plan.form.submit.success.update":"plan.form.submit.success.add")),f(),r()),c(!1)})()},children:m(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})]})})}function lx(){const[s,n]=u.useState({}),[a,l]=u.useState({"drag-handle":!1}),[r,i]=u.useState([]),[c,m]=u.useState([]),[x,o]=u.useState(!1),[d,p]=u.useState({pageSize:20,pageIndex:0}),[k,E]=u.useState([]),{refetch:f}=se({queryKey:["planList"],queryFn:async()=>{const{data:S}=await Fs();return E(S),S}});u.useEffect(()=>{l({"drag-handle":x}),p({pageSize:x?99999:10,pageIndex:0})},[x]);const _=(S,C)=>{x&&(S.dataTransfer.setData("text/plain",C.toString()),S.currentTarget.classList.add("opacity-50"))},T=(S,C)=>{if(!x)return;S.preventDefault(),S.currentTarget.classList.remove("bg-muted");const D=parseInt(S.dataTransfer.getData("text/plain"));if(D===C)return;const z=[...k],[Q]=z.splice(D,1);z.splice(C,0,Q),E(z)},g=async()=>{if(!x){o(!0);return}const S=k?.map(C=>C.id);id(S).then(()=>{q.success("排序保存成功"),o(!1),f()}).finally(()=>{o(!1)})},w=Le({data:k||[],columns:tx(f),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:d},enableRowSelection:!0,onPaginationChange:p,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:i,onColumnVisibilityChange:l,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),getSortedRowModel:We(),getFacetedRowModel:ms(),getFacetedUniqueValues:us(),initialState:{columnPinning:{right:["actions"]}},pageCount:x?1:void 0});return e.jsx(ex,{refreshData:f,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Je,{table:w,toolbar:S=>e.jsx(sx,{table:S,refetch:f,saveOrder:g,isSortMode:x}),draggable:x,onDragStart:_,onDragEnd:S=>S.currentTarget.classList.remove("opacity-50"),onDragOver:S=>{S.preventDefault(),S.currentTarget.classList.add("bg-muted")},onDragLeave:S=>S.currentTarget.classList.remove("bg-muted"),onDrop:T,showPagination:!x}),e.jsx(rx,{})]})})}function ox(){const{t:s}=I("subscribe");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(lx,{})})]})]})}const ix=Object.freeze(Object.defineProperty({__proto__:null,default:ox},Symbol.toStringTag,{value:"Module"})),Ls=[{value:Z.PENDING,label:Ys[Z.PENDING],icon:gi,color:Js[Z.PENDING]},{value:Z.PROCESSING,label:Ys[Z.PROCESSING],icon:An,color:Js[Z.PROCESSING]},{value:Z.COMPLETED,label:Ys[Z.COMPLETED],icon:Wt,color:Js[Z.COMPLETED]},{value:Z.CANCELLED,label:Ys[Z.CANCELLED],icon:$n,color:Js[Z.CANCELLED]},{value:Z.DISCOUNTED,label:Ys[Z.DISCOUNTED],icon:Wt,color:Js[Z.DISCOUNTED]}],Zs=[{value:ne.PENDING,label:ut[ne.PENDING],icon:ji,color:xt[ne.PENDING]},{value:ne.PROCESSING,label:ut[ne.PROCESSING],icon:An,color:xt[ne.PROCESSING]},{value:ne.VALID,label:ut[ne.VALID],icon:Wt,color:xt[ne.VALID]},{value:ne.INVALID,label:ut[ne.INVALID],icon:$n,color:xt[ne.INVALID]}];function jt({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=s?.getFilterValue(),i=Array.isArray(r)?new Set(r):r!==void 0?new Set([r]):new Set;return e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(V,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(ct,{className:"mr-2 h-4 w-4"}),n,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{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(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):a.filter(c=>i.has(c.value)).map(c=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:c.label},c.value))})]})]})}),e.jsx(Ye,{className:"w-[200px] p-0",align:"start",children:e.jsxs(_s,{children:[e.jsx(Vs,{placeholder:n}),e.jsxs(ws,{children:[e.jsx(Is,{children:"No results found."}),e.jsx(Fe,{children:a.map(c=>{const m=i.has(c.value);return e.jsxs(_e,{onSelect:()=>{const x=new Set(i);m?x.delete(c.value):x.add(c.value);const o=Array.from(x);s?.setFilterValue(o.length?o:void 0)},children:[e.jsx("div",{className:y("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",m?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ps,{className:y("h-4 w-4")})}),c.icon&&e.jsx(c.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${c.color}`}),e.jsx("span",{children:c.label}),l?.get(c.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(c.value)})]},c.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Fe,{children:e.jsx(_e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const cx=h.object({email:h.string().min(1),plan_id:h.number(),period:h.string(),total_amount:h.number()}),dx={email:"",plan_id:0,total_amount:0,period:""};function Or({refetch:s,trigger:n,defaultValues:a}){const{t:l}=I("order"),[r,i]=u.useState(!1),c=ce({resolver:ue(cx),defaultValues:{...dx,...a},mode:"onChange"}),[m,x]=u.useState([]);return u.useEffect(()=>{r&&Fs().then(({data:o})=>{x(o)})},[r]),e.jsxs(ge,{open:r,onOpenChange:i,children:[e.jsx(Me,{asChild:!0,children:n||e.jsxs(V,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("div",{children:l("dialog.addOrder")})]})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:l("dialog.assignOrder")}),e.jsx(De,{})]}),e.jsxs(xe,{...c,children:[e.jsx(v,{control:c.control,name:"email",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dialog.fields.userEmail")}),e.jsx(N,{children:e.jsx(P,{placeholder:l("dialog.placeholders.email"),...o})})]})}),e.jsx(v,{control:c.control,name:"plan_id",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dialog.fields.subscriptionPlan")}),e.jsx(N,{children:e.jsxs(W,{value:o.value?o.value?.toString():void 0,onValueChange:d=>o.onChange(parseInt(d)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dialog.placeholders.plan")})}),e.jsx(G,{children:m.map(d=>e.jsx($,{value:d.id.toString(),children:d.name},d.id))})]})})]})}),e.jsx(v,{control:c.control,name:"period",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dialog.fields.orderPeriod")}),e.jsx(N,{children:e.jsxs(W,{value:o.value,onValueChange:o.onChange,children:[e.jsx(B,{children:e.jsx(Y,{placeholder:l("dialog.placeholders.period")})}),e.jsx(G,{children:Object.keys(Ld).map(d=>e.jsx($,{value:d,children:l(`period.${d}`)},d))})]})})]})}),e.jsx(v,{control:c.control,name:"total_amount",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:l("dialog.fields.paymentAmount")}),e.jsx(N,{children:e.jsx(P,{type:"number",placeholder:l("dialog.placeholders.amount"),value:o.value/100,onChange:d=>o.onChange(parseFloat(d.currentTarget.value)*100)})}),e.jsx(R,{})]})}),e.jsxs(Oe,{children:[e.jsx(V,{variant:"outline",onClick:()=>i(!1),children:l("dialog.actions.cancel")}),e.jsx(V,{type:"submit",onClick:()=>{c.handleSubmit(o=>{xd(o).then(({data:d})=>{d&&(s&&s(),c.reset(),i(!1),q.success(l("dialog.messages.addSuccess")))})})()},children:l("dialog.actions.confirm")})]})]})]})]})}function mx({table:s,refetch:n}){const{t:a}=I("order"),l=s.getState().columnFilters.length>0,r=Object.values(He).filter(x=>typeof x=="number").map(x=>({label:a(`type.${He[x]}`),value:x,color:x===He.NEW?"green-500":x===He.RENEWAL?"blue-500":x===He.UPGRADE?"purple-500":"orange-500"})),i=Object.values(de).map(x=>({label:a(`period.${x}`),value:x,color:x===de.MONTH_PRICE?"slate-500":x===de.QUARTER_PRICE?"cyan-500":x===de.HALF_YEAR_PRICE?"indigo-500":x===de.YEAR_PRICE?"violet-500":x===de.TWO_YEAR_PRICE?"fuchsia-500":x===de.THREE_YEAR_PRICE?"pink-500":x===de.ONETIME_PRICE?"rose-500":"orange-500"})),c=Object.values(Z).filter(x=>typeof x=="number").map(x=>({label:a(`status.${Z[x]}`),value:x,icon:x===Z.PENDING?Ls[0].icon:x===Z.PROCESSING?Ls[1].icon:x===Z.COMPLETED?Ls[2].icon:x===Z.CANCELLED?Ls[3].icon:Ls[4].icon,color:x===Z.PENDING?"yellow-500":x===Z.PROCESSING?"blue-500":x===Z.COMPLETED?"green-500":x===Z.CANCELLED?"red-500":"green-500"})),m=Object.values(ne).filter(x=>typeof x=="number").map(x=>({label:a(`commission.${ne[x]}`),value:x,icon:x===ne.PENDING?Zs[0].icon:x===ne.PROCESSING?Zs[1].icon:x===ne.VALID?Zs[2].icon:Zs[3].icon,color:x===ne.PENDING?"yellow-500":x===ne.PROCESSING?"blue-500":x===ne.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Or,{refetch:n}),e.jsx(P,{placeholder:a("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:x=>s.getColumn("trade_no")?.setFilterValue(x.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(jt,{column:s.getColumn("type"),title:a("table.columns.type"),options:r}),s.getColumn("period")&&e.jsx(jt,{column:s.getColumn("period"),title:a("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(jt,{column:s.getColumn("status"),title:a("table.columns.status"),options:c}),s.getColumn("commission_status")&&e.jsx(jt,{column:s.getColumn("commission_status"),title:a("table.columns.commissionStatus"),options:m})]}),l&&e.jsxs(V,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[a("actions.reset"),e.jsx(ze,{className:"ml-2 h-4 w-4"})]})]})}function $e({label:s,value:n,className:a,valueClassName:l}){return e.jsxs("div",{className:y("flex items-center py-1.5",a),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:y("text-sm",l),children:n||"-"})]})}function ux({status:s}){const{t:n}=I("order"),a={[Z.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[Z.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[Z.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[Z.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[Z.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(K,{variant:"secondary",className:y("font-medium",a[s]),children:n(`status.${Z[s]}`)})}function xx({id:s,trigger:n}){const[a,l]=u.useState(!1),[r,i]=u.useState(),{t:c}=I("order");return u.useEffect(()=>{(async()=>{if(a){const{data:x}=await dd({id:s});i(x)}})()},[a,s]),e.jsxs(ge,{onOpenChange:l,open:a,children:[e.jsx(Me,{asChild:!0,children:n}),e.jsxs(he,{className:"max-w-xl",children:[e.jsxs(ve,{className:"space-y-2",children:[e.jsx(je,{className:"text-lg font-medium",children:c("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:[c("table.columns.tradeNo"),":",r?.trade_no]}),r?.status&&e.jsx(ux,{status:r.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:c("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx($e,{label:c("dialog.fields.userEmail"),value:r?.user?.email?e.jsxs(Rs,{to:`/user/manage?email=${r.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[r.user.email,e.jsx(qn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx($e,{label:c("dialog.fields.orderPeriod"),value:r&&c(`period.${r.period}`)}),e.jsx($e,{label:c("dialog.fields.subscriptionPlan"),value:r?.plan?.name,valueClassName:"font-medium"}),e.jsx($e,{label:c("dialog.fields.callbackNo"),value:r?.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:c("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx($e,{label:c("dialog.fields.paymentAmount"),value:ks(r?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(be,{className:"my-2"}),e.jsx($e,{label:c("dialog.fields.balancePayment"),value:ks(r?.balance_amount||0)}),e.jsx($e,{label:c("dialog.fields.discountAmount"),value:ks(r?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx($e,{label:c("dialog.fields.refundAmount"),value:ks(r?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx($e,{label:c("dialog.fields.deductionAmount"),value:ks(r?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:c("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx($e,{label:c("dialog.fields.createdAt"),value:me(r?.created_at),valueClassName:"font-mono text-xs"}),e.jsx($e,{label:c("dialog.fields.updatedAt"),value:me(r?.updated_at),valueClassName:"font-mono text-xs"})]})]})]})]})]})}const hx={[He.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[He.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[He.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[He.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},fx={[de.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[de.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},px=s=>Z[s],gx=s=>ne[s],jx=s=>He[s],vx=s=>{const{t:n}=I("order");return[{accessorKey:"trade_no",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.tradeNo")}),cell:({row:a})=>{const l=a.original.trade_no,r=l.length>6?`${l.slice(0,3)}...${l.slice(-3)}`:l;return e.jsx("div",{className:"flex items-center",children:e.jsx(xx,{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:r}),e.jsx(qn,{className:"h-3.5 w-3.5 opacity-70"})]}),id:a.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.type")}),cell:({row:a})=>{const l=a.getValue("type"),r=hx[l];return e.jsx(K,{variant:"secondary",className:y("font-medium transition-colors text-nowrap",r.color,r.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:n(`type.${jx(l)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.plan")}),cell:({row:a})=>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:a.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.period")}),cell:({row:a})=>{const l=a.getValue("period"),r=fx[l];return e.jsx(K,{variant:"secondary",className:y("font-medium transition-colors text-nowrap",r.color,r.bgColor,"hover:bg-opacity-80"),children:n(`period.${l}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.amount")}),cell:({row:a})=>{const l=a.getValue("total_amount"),r=typeof l=="number"?(l/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",r]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:a})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(M,{column:a,title:n("table.columns.status")}),e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsx(Tr,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(te,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:a})=>{const l=Ls.find(r=>r.value===a.getValue("status"));return l?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l.icon&&e.jsx(l.icon,{className:`h-4 w-4 text-${l.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`status.${px(l.value)}`)})]}),l.value===Z.PENDING&&e.jsxs(ys,{modal:!0,children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Nt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(is,{align:"end",className:"w-[140px]",children:[e.jsx(fe,{className:"cursor-pointer",onClick:async()=>{await md({trade_no:a.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(fe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await ud({trade_no:a.original.trade_no}),s()},children:n("actions.cancel")})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.commission")}),cell:({row:a})=>{const l=a.getValue("commission_balance"),r=l?(l/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:l?`¥${r}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.commissionStatus")}),cell:({row:a})=>{const l=a.original.status,r=a.original.commission_balance,i=Zs.find(c=>c.value===a.getValue("commission_status"));return r==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.${gx(i.value)}`)})]}),i.value===ne.PENDING&&l===Z.COMPLETED&&e.jsxs(ys,{modal:!0,children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Nt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(is,{align:"end",className:"w-[120px]",children:[e.jsx(fe,{className:"cursor-pointer",onClick:async()=>{await Fa({trade_no:a.original.trade_no,commission_status:ne.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(fe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await Fa({trade_no:a.original.trade_no,commission_status:ne.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.createdAt")}),cell:({row:a})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:me(a.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function bx(){const[s]=Kn(),[n,a]=u.useState({}),[l,r]=u.useState({}),[i,c]=u.useState([]),[m,x]=u.useState([]),[o,d]=u.useState({pageIndex:0,pageSize:20});u.useEffect(()=>{const T=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([g,w])=>{const S=s.get(g);return S?{id:g,value:w==="number"?parseInt(S):S}:null}).filter(Boolean);T.length>0&&c(T)},[s]);const{refetch:p,data:k,isLoading:E}=se({queryKey:["orderList",o,i,m],queryFn:()=>cd({pageSize:o.pageSize,current:o.pageIndex+1,filter:i,sort:m})}),f=Le({data:k?.data??[],columns:vx(p),state:{sorting:m,columnVisibility:l,rowSelection:n,columnFilters:i,pagination:o},rowCount:k?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:x,onColumnFiltersChange:c,onColumnVisibilityChange:r,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),onPaginationChange:d,getSortedRowModel:We(),getFacetedRowModel:ms(),getFacetedUniqueValues:us(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Je,{table:f,toolbar:e.jsx(mx,{table:f,refetch:p}),showPagination:!0})}function yx(){const{t:s}=I("order");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(bx,{})})]})]})}const Nx=Object.freeze(Object.defineProperty({__proto__:null,default:yx},Symbol.toStringTag,{value:"Module"}));function _x({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(V,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(ct,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(i=>r.has(i.value)).map(i=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ye,{className:"w-[200px] p-0",align:"start",children:e.jsxs(_s,{children:[e.jsx(Vs,{placeholder:n}),e.jsxs(ws,{children:[e.jsx(Is,{children:"No results found."}),e.jsx(Fe,{children:a.map(i=>{const c=r.has(i.value);return e.jsxs(_e,{onSelect:()=>{c?r.delete(i.value):r.add(i.value);const m=Array.from(r);s?.setFilterValue(m.length?m:void 0)},children:[e.jsx("div",{className:y("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ps,{className:y("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}),l?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(i.value)})]},i.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Fe,{children:e.jsx(_e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const wx=h.object({id:h.coerce.number().nullable().optional(),name:h.string().min(1,"请输入优惠券名称"),code:h.string().nullable(),type:h.coerce.number(),value:h.coerce.number(),started_at:h.coerce.number(),ended_at:h.coerce.number(),limit_use:h.union([h.string(),h.number()]).nullable(),limit_use_with_user:h.union([h.string(),h.number()]).nullable(),generate_count:h.coerce.number().nullable().optional(),limit_plan_ids:h.array(h.number()).default([]).nullable(),limit_period:h.array(h.nativeEnum(de)).default([]).nullable()}).refine(s=>s.ended_at>s.started_at,{message:"结束时间必须晚于开始时间",path:["ended_at"]}),qa={name:"",code:"",type:Ve.AMOUNT,value:0,started_at:Math.floor(Date.now()/1e3),ended_at:Math.floor(Date.now()/1e3)+7*24*60*60,limit_use:"",limit_use_with_user:"",limit_plan_ids:[],limit_period:[],generate_count:""};function zr({defaultValues:s,refetch:n,type:a="create",dialogTrigger:l=null,open:r,onOpenChange:i}){const{t:c}=I("coupon"),[m,x]=u.useState(!1),o=r??m,d=i??x,[p,k]=u.useState([]),E=ce({resolver:ue(wx),defaultValues:s||qa});u.useEffect(()=>{s&&E.reset(s)},[s,E]),u.useEffect(()=>{Fs().then(({data:g})=>k(g))},[]);const f=g=>{if(!g)return;const w=(S,C)=>{const D=new Date(C*1e3);return S.setHours(D.getHours(),D.getMinutes(),D.getSeconds()),Math.floor(S.getTime()/1e3)};g.from&&E.setValue("started_at",w(g.from,E.watch("started_at"))),g.to&&E.setValue("ended_at",w(g.to,E.watch("ended_at")))},_=async g=>{fd(g).then(()=>{d(!1),a==="create"&&E.reset(qa),n()})},T=(g,w)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:w}),e.jsx(P,{type:"datetime-local",step:"1",value:me(E.watch(g),"YYYY-MM-DDTHH:mm:ss"),onChange:S=>{const C=new Date(S.target.value);E.setValue(g,Math.floor(C.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(ge,{open:o,onOpenChange:d,children:[l&&e.jsx(Me,{asChild:!0,children:l}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsx(ve,{children:e.jsx(je,{children:c(a==="create"?"form.add":"form.edit")})}),e.jsx(xe,{...E,children:e.jsxs("form",{onSubmit:E.handleSubmit(_),className:"space-y-4",children:[e.jsx(v,{control:E.control,name:"name",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:c("form.name.label")}),e.jsx(P,{placeholder:c("form.name.placeholder"),...g}),e.jsx(R,{})]})}),e.jsx(v,{control:E.control,name:"code",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:c("form.code.label")}),e.jsx(P,{placeholder:c("form.code.placeholder"),...g,className:"h-9"}),e.jsx(F,{className:"text-xs",children:c("form.code.description")}),e.jsx(R,{})]})}),e.jsxs(j,{children:[e.jsx(b,{children:c("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(v,{control:E.control,name:"type",render:({field:g})=>e.jsxs(W,{value:g.value.toString(),onValueChange:w=>{const S=g.value,C=parseInt(w);g.onChange(C);const D=E.getValues("value");D&&(S===Ve.AMOUNT&&C===Ve.PERCENT?E.setValue("value",D/100):S===Ve.PERCENT&&C===Ve.AMOUNT&&E.setValue("value",D*100))},children:[e.jsx(B,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Y,{placeholder:c("form.type.placeholder")})}),e.jsx(G,{children:Object.entries(Ad).map(([w,S])=>e.jsx($,{value:w,children:c(`table.toolbar.types.${w}`)},w))})]})}),e.jsx(v,{control:E.control,name:"value",render:({field:g})=>{const w=g.value===""?"":E.watch("type")===Ve.AMOUNT&&typeof g.value=="number"?(g.value/100).toString():g.value.toString();return e.jsx(P,{type:"number",placeholder:c("form.value.placeholder"),...g,value:w,onChange:S=>{const C=S.target.value;if(C===""){g.onChange("");return}const D=parseFloat(C);isNaN(D)||g.onChange(E.watch("type")===Ve.AMOUNT?Math.round(D*100):D)},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")==Ve.AMOUNT?"¥":"%"})})]})]}),e.jsxs(j,{children:[e.jsx(b,{children:c("form.validity.label")}),e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(V,{variant:"outline",className:y("w-full justify-start text-left font-normal",!E.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(it,{className:"mr-2 h-4 w-4"}),me(E.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",c("form.validity.to")," ",me(E.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})}),e.jsxs(Ye,{className:"w-auto p-0",align:"start",children:[e.jsx("div",{className:"border-b border-border",children:e.jsx(Ms,{mode:"range",selected:{from:new Date(E.watch("started_at")*1e3),to:new Date(E.watch("ended_at")*1e3)},onSelect:f,numberOfMonths:2})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-4",children:[T("started_at",c("table.validity.startTime")),e.jsx("div",{className:"mt-6 text-sm text-muted-foreground",children:c("form.validity.to")}),T("ended_at",c("table.validity.endTime"))]})})]})]}),e.jsx(R,{})]}),e.jsx(v,{control:E.control,name:"limit_use",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:c("form.limitUse.label")}),e.jsx(P,{type:"number",min:0,placeholder:c("form.limitUse.placeholder"),...g,value:g.value===void 0?"":g.value,onChange:w=>g.onChange(w.target.value===""?"":w.target.value),className:"h-9"}),e.jsx(F,{className:"text-xs",children:c("form.limitUse.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:E.control,name:"limit_use_with_user",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:c("form.limitUseWithUser.label")}),e.jsx(P,{type:"number",min:0,placeholder:c("form.limitUseWithUser.placeholder"),...g,value:g.value===void 0?"":g.value,onChange:w=>g.onChange(w.target.value===""?"":w.target.value),className:"h-9"}),e.jsx(F,{className:"text-xs",children:c("form.limitUseWithUser.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:E.control,name:"limit_period",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:c("form.limitPeriod.label")}),e.jsx(lt,{options:Object.entries(de).filter(([w])=>isNaN(Number(w))).map(([w,S])=>({label:S,value:w})),onChange:w=>{if(w.length===0){g.onChange([]);return}const S=w.map(C=>de[C.value]);g.onChange(S)},value:(g.value||[]).map(w=>({label:Object.entries(de).find(([S,C])=>C===w)?.[1]||"",value:Object.entries(de).find(([S,C])=>C===w)?.[0]||""})),placeholder:c("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:c("form.limitPeriod.empty")})}),e.jsx(F,{className:"text-xs",children:c("form.limitPeriod.description")}),e.jsx(R,{})]})}),e.jsx(v,{control:E.control,name:"limit_plan_ids",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:c("form.limitPlan.label")}),e.jsx(lt,{options:p?.map(w=>({label:w.name,value:w.id.toString()}))||[],onChange:w=>g.onChange(w.map(S=>Number(S.value))),value:(p||[]).filter(w=>(g.value||[]).includes(w.id)).map(w=>({label:w.name,value:w.id.toString()})),placeholder:c("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:c("form.limitPlan.empty")})}),e.jsx(R,{})]})}),a==="create"&&e.jsx(e.Fragment,{children:e.jsx(v,{control:E.control,name:"generate_count",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:c("form.generateCount.label")}),e.jsx(P,{type:"number",min:0,placeholder:c("form.generateCount.placeholder"),...g,value:g.value===void 0?"":g.value,onChange:w=>g.onChange(w.target.value===""?"":w.target.value),className:"h-9"}),e.jsx(F,{className:"text-xs",children:c("form.generateCount.description")}),e.jsx(R,{})]})})}),e.jsx(Oe,{children:e.jsx(V,{type:"submit",disabled:E.formState.isSubmitting,children:E.formState.isSubmitting?c("form.submit.saving"):c("form.submit.save")})})]})})]})]})}function Cx({table:s,refetch:n}){const a=s.getState().columnFilters.length>0,{t:l}=I("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(zr,{refetch:n,dialogTrigger:e.jsxs(V,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("div",{children:l("form.add")})]})}),e.jsx(P,{placeholder:l("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:r=>s.getColumn("name")?.setFilterValue(r.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(_x,{column:s.getColumn("type"),title:l("table.toolbar.type"),options:[{value:Ve.AMOUNT,label:l(`table.toolbar.types.${Ve.AMOUNT}`)},{value:Ve.PERCENTAGE,label:l(`table.toolbar.types.${Ve.PERCENTAGE}`)}]}),a&&e.jsxs(V,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("table.toolbar.reset"),e.jsx(ze,{className:"ml-2 h-4 w-4"})]})]})}const Lr=u.createContext(void 0);function Sx({children:s,refetch:n}){const[a,l]=u.useState(!1),[r,i]=u.useState(null),c=x=>{i(x),l(!0)},m=()=>{l(!1),i(null)};return e.jsxs(Lr.Provider,{value:{isOpen:a,currentCoupon:r,openEdit:c,closeEdit:m},children:[s,r&&e.jsx(zr,{defaultValues:r,refetch:n,type:"edit",open:a,onOpenChange:l})]})}function kx(){const s=u.useContext(Lr);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const Tx=s=>{const{t:n}=I("coupon");return[{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.id")}),cell:({row:a})=>e.jsx(K,{children:a.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.show")}),cell:({row:a})=>e.jsx(H,{defaultChecked:a.original.show,onCheckedChange:l=>{gd({id:a.original.id,show:l}).then(({data:r})=>!r&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.name")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:a.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.type")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:n(`table.toolbar.types.${a.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.code")}),cell:({row:a})=>e.jsx(K,{variant:"secondary",children:a.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.limitUse")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:a.original.limit_use===null?n("table.validity.unlimited"):a.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.limitUseWithUser")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:a.original.limit_use_with_user===null?n("table.validity.noLimit"):a.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:a})=>e.jsx(M,{column:a,title:n("table.columns.validity")}),cell:({row:a})=>{const[l,r]=u.useState(!1),i=Date.now(),c=a.original.started_at*1e3,m=a.original.ended_at*1e3,x=i>m,o=ie.jsx(M,{className:"justify-end",column:a,title:n("table.columns.actions")}),cell:({row:a})=>{const{openEdit:l}=kx();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>l(a.original),children:[e.jsx(Es,{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()=>{pd({id:a.original.id}).then(({data:r})=>{r&&(q.success("删除成功"),s())})},children:e.jsxs(V,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{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 Dx(){const[s,n]=u.useState({}),[a,l]=u.useState({}),[r,i]=u.useState([]),[c,m]=u.useState([]),[x,o]=u.useState({pageIndex:0,pageSize:20}),{refetch:d,data:p}=se({queryKey:["couponList",x,r,c],queryFn:()=>hd({pageSize:x.pageSize,current:x.pageIndex+1,filter:r,sort:c})}),k=Le({data:p?.data??[],columns:Tx(d),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:x},pageCount:Math.ceil((p?.total??0)/x.pageSize),rowCount:p?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:i,onColumnVisibilityChange:l,onPaginationChange:o,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),getSortedRowModel:We(),getFacetedRowModel:ms(),getFacetedUniqueValues:us(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Sx,{refetch:d,children:e.jsx("div",{className:"space-y-4",children:e.jsx(Je,{table:k,toolbar:e.jsx(Cx,{table:k,refetch:d})})})})}function Px(){const{t:s}=I("coupon");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(Dx,{})})]})]})}const Rx=Object.freeze(Object.defineProperty({__proto__:null,default:Px},Symbol.toStringTag,{value:"Module"})),Ex=h.object({email_prefix:h.string().optional(),email_suffix:h.string().min(1),password:h.string().optional(),expired_at:h.number().optional().nullable(),plan_id:h.number().nullable(),generate_count:h.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"]}),Vx={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0};function Ix({refetch:s}){const{t:n}=I("user"),[a,l]=u.useState(!1),r=ce({resolver:ue(Ex),defaultValues:Vx,mode:"onChange"}),[i,c]=u.useState([]);return u.useEffect(()=>{a&&Fs().then(({data:m})=>{m&&c(m)})},[a]),e.jsxs(ge,{open:a,onOpenChange:l,children:[e.jsx(Me,{asChild:!0,children:e.jsxs(J,{size:"sm",variant:"outline",className:"space-x-2 gap-0",children:[e.jsx(Ne,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(he,{className:"sm:max-w-[425px]",children:[e.jsxs(ve,{children:[e.jsx(je,{children:n("generate.title")}),e.jsx(De,{})]}),e.jsxs(xe,{...r,children:[e.jsxs(j,{children:[e.jsx(b,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!r.watch("generate_count")&&e.jsx(v,{control:r.control,name:"email_prefix",render:({field:m})=>e.jsx(P,{className:"flex-[5] rounded-r-none",placeholder:n("generate.form.email_prefix"),...m})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${r.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(v,{control:r.control,name:"email_suffix",render:({field:m})=>e.jsx(P,{className:"flex-[4] rounded-l-none",placeholder:n("generate.form.email_domain"),...m})})]})]}),e.jsx(v,{control:r.control,name:"password",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:n("generate.form.password")}),e.jsx(P,{placeholder:n("generate.form.password_placeholder"),...m}),e.jsx(R,{})]})}),e.jsx(v,{control:r.control,name:"expired_at",render:({field:m})=>e.jsxs(j,{className:"flex flex-col",children:[e.jsx(b,{children:n("generate.form.expire_time")}),e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(N,{children:e.jsxs(J,{variant:"outline",className:y("w-full pl-3 text-left font-normal",!m.value&&"text-muted-foreground"),children:[m.value?me(m.value):e.jsx("span",{children:n("generate.form.expire_time_placeholder")}),e.jsx(it,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(Ye,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(bi,{asChild:!0,children:e.jsx(J,{variant:"outline",className:"w-full",onClick:()=>{m.onChange(null)},children:n("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Ms,{mode:"single",selected:m.value?new Date(m.value*1e3):void 0,onSelect:x=>{x&&m.onChange(x?.getTime()/1e3)}})})]})]})]})}),e.jsx(v,{control:r.control,name:"plan_id",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:n("generate.form.subscription")}),e.jsx(N,{children:e.jsxs(W,{value:m.value?m.value.toString():"null",onValueChange:x=>m.onChange(x==="null"?null:parseInt(x)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(G,{children:[e.jsx($,{value:"null",children:n("generate.form.subscription_none")}),i.map(x=>e.jsx($,{value:x.id.toString(),children:x.name},x.id))]})]})})]})}),!r.watch("email_prefix")&&e.jsx(v,{control:r.control,name:"generate_count",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:n("generate.form.generate_count")}),e.jsx(P,{type:"number",placeholder:n("generate.form.generate_count_placeholder"),value:m.value||"",onChange:x=>m.onChange(x.target.value?parseInt(x.target.value):null)})]})})]}),e.jsxs(Oe,{children:[e.jsx(J,{variant:"outline",onClick:()=>l(!1),children:n("generate.form.cancel")}),e.jsx(J,{onClick:()=>r.handleSubmit(m=>{yd(m).then(({data:x})=>{x&&(q.success(n("generate.form.success")),r.reset(),s(),l(!1))})})(),children:n("generate.form.submit")})]})]})]})}const Ar=Ua,$r=Ba,Fx=Ga,qr=u.forwardRef(({className:s,...n},a)=>e.jsx(St,{className:y("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:a}));qr.displayName=St.displayName;const Mx=Ds("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"}}),fa=u.forwardRef(({side:s="right",className:n,children:a,...l},r)=>e.jsxs(Fx,{children:[e.jsx(qr,{}),e.jsxs(kt,{ref:r,className:y(Mx({side:s}),n),...l,children:[e.jsxs(sa,{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(ze,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),a]})]}));fa.displayName=kt.displayName;const pa=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col space-y-2 text-center sm:text-left",s),...n});pa.displayName="SheetHeader";const Kr=({className:s,...n})=>e.jsx("div",{className:y("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Kr.displayName="SheetFooter";const ga=u.forwardRef(({className:s,...n},a)=>e.jsx(Tt,{ref:a,className:y("text-lg font-semibold text-foreground",s),...n}));ga.displayName=Tt.displayName;const ja=u.forwardRef(({className:s,...n},a)=>e.jsx(Dt,{ref:a,className:y("text-sm text-muted-foreground",s),...n}));ja.displayName=Dt.displayName;function Ox({table:s,refetch:n,permissionGroups:a=[],subscriptionPlans:l=[]}){const{t:r}=I("user"),i=s.getState().columnFilters.length>0,[c,m]=u.useState([]),[x,o]=u.useState(!1),d=[{label:r("filter.fields.email"),value:"email",type:"text",operators:[{label:r("filter.operators.contains"),value:"contains"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.id"),value:"id",type:"number",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.plan_id"),value:"plan_id",type:"select",operators:[{label:r("filter.operators.eq"),value:"eq"}],useOptions:!0},{label:r("filter.fields.transfer_enable"),value:"transfer_enable",type:"number",unit:"GB",operators:[{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.lt"),value:"lt"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.total_used"),value:"total_used",type:"number",unit:"GB",operators:[{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.lt"),value:"lt"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.online_count"),value:"online_count",type:"number",operators:[{label:r("filter.operators.eq"),value:"eq"},{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.lt"),value:"lt"}]},{label:r("filter.fields.expired_at"),value:"expired_at",type:"date",operators:[{label:r("filter.operators.lt"),value:"lt"},{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.uuid"),value:"uuid",type:"text",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.token"),value:"token",type:"text",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.banned"),value:"banned",type:"select",operators:[{label:r("filter.operators.eq"),value:"eq"}],options:[{label:r("filter.status.normal"),value:"0"},{label:r("filter.status.banned"),value:"1"}]},{label:r("filter.fields.remark"),value:"remark",type:"text",operators:[{label:r("filter.operators.contains"),value:"contains"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.inviter_email"),value:"inviter_email",type:"text",operators:[{label:r("filter.operators.contains"),value:"contains"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.invite_user_id"),value:"invite_user_id",type:"number",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.is_admin"),value:"is_admin",type:"boolean",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.is_staff"),value:"is_staff",type:"boolean",operators:[{label:r("filter.operators.eq"),value:"eq"}]}],p=w=>w*1024*1024*1024,k=w=>w/(1024*1024*1024),E=()=>{m([...c,{field:"",operator:"",value:""}])},f=w=>{m(c.filter((S,C)=>C!==w))},_=(w,S,C)=>{const D=[...c];if(D[w]={...D[w],[S]:C},S==="field"){const z=d.find(Q=>Q.value===C);z&&(D[w].operator=z.operators[0].value,D[w].value=z.type==="boolean"?!1:"")}m(D)},T=(w,S)=>{const C=d.find(D=>D.value===w.field);if(!C)return null;switch(C.type){case"text":return e.jsx(P,{placeholder:r("filter.sheet.value"),value:w.value,onChange:D=>_(S,"value",D.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(P,{type:"number",placeholder:r("filter.sheet.value_number",{unit:C.unit}),value:C.unit==="GB"?k(w.value||0):w.value,onChange:D=>{const z=Number(D.target.value);_(S,"value",C.unit==="GB"?p(z):z)}}),C.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:C.unit})]});case"date":return e.jsx(Ms,{mode:"single",selected:w.value,onSelect:D=>_(S,"value",D),className:"rounded-md border"});case"select":return e.jsxs(W,{value:w.value,onValueChange:D=>_(S,"value",D),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:r("filter.sheet.value")})}),e.jsx(G,{children:C.useOptions?l.map(D=>e.jsx($,{value:D.value.toString(),children:D.label},D.value)):C.options?.map(D=>e.jsx($,{value:D.value.toString(),children:D.label},D.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(H,{checked:w.value,onCheckedChange:D=>_(S,"value",D)}),e.jsx(_t,{children:w.value?r("filter.boolean.true"):r("filter.boolean.false")})]});default:return null}},g=()=>{const w=c.filter(S=>S.field&&S.operator&&S.value!=="").map(S=>{const C=d.find(z=>z.value===S.field);let D=S.value;return S.operator==="contains"?{id:S.field,value:D}:(C?.type==="date"&&D instanceof Date&&(D=Math.floor(D.getTime()/1e3)),C?.type==="boolean"&&(D=D?1:0),{id:S.field,value:`${S.operator}:${D}`})});s.setColumnFilters(w),o(!1)};return e.jsx("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(Ix,{refetch:n}),e.jsx(P,{placeholder:r("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:w=>s.getColumn("email")?.setFilterValue(w.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(Ar,{open:x,onOpenChange:o,children:[e.jsx($r,{asChild:!0,children:e.jsxs(V,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(yi,{className:"mr-2 h-4 w-4"}),r("filter.advanced"),c.length>0&&e.jsx(K,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:c.length})]})}),e.jsxs(fa,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(pa,{children:[e.jsx(ga,{children:r("filter.sheet.title")}),e.jsx(ja,{children:r("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:r("filter.sheet.conditions")}),e.jsx(V,{variant:"outline",size:"sm",onClick:E,children:r("filter.sheet.add")})]}),e.jsx(rt,{className:"h-[calc(100vh-280px)] pr-4",children:e.jsx("div",{className:"space-y-4",children:c.map((w,S)=>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(_t,{children:r("filter.sheet.condition",{number:S+1})}),e.jsx(V,{variant:"ghost",size:"sm",onClick:()=>f(S),children:e.jsx(ze,{className:"h-4 w-4"})})]}),e.jsxs(W,{value:w.field,onValueChange:C=>_(S,"field",C),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:r("filter.sheet.field")})}),e.jsx(G,{children:d.map(C=>e.jsx($,{value:C.value,children:C.label},C.value))})]}),w.field&&e.jsxs(W,{value:w.operator,onValueChange:C=>_(S,"operator",C),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:r("filter.sheet.operator")})}),e.jsx(G,{children:d.find(C=>C.value===w.field)?.operators.map(C=>e.jsx($,{value:C.value,children:C.label},C.value))})]}),w.field&&w.operator&&T(w,S)]},S))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(V,{variant:"outline",onClick:()=>{m([]),o(!1)},children:r("filter.sheet.reset")}),e.jsx(V,{onClick:g,children:r("filter.sheet.apply")})]})]})]})]}),i&&e.jsxs(V,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),m([])},className:"h-8 px-2 lg:px-3",children:[r("filter.reset"),e.jsx(ze,{className:"ml-2 h-4 w-4"})]})]})})}const zx=h.object({id:h.number(),email:h.string().email(),invite_user_email:h.string().email().nullable().optional(),password:h.string().optional().nullable(),balance:h.coerce.number(),commission_balance:h.coerce.number(),u:h.number(),d:h.number(),transfer_enable:h.number(),expired_at:h.number().nullable(),plan_id:h.number().nullable(),banned:h.number(),commission_type:h.number(),commission_rate:h.number().nullable(),discount:h.number().nullable(),speed_limit:h.number().nullable(),device_limit:h.number().nullable(),is_admin:h.number(),is_staff:h.number(),remarks:h.string().nullable()}),Hr=u.createContext(void 0);function Lx({children:s,defaultValues:n,open:a,onOpenChange:l}){const[r,i]=u.useState(!1),[c,m]=u.useState(!1),[x,o]=u.useState([]),d=ce({resolver:ue(zx),defaultValues:n,mode:"onChange"});u.useEffect(()=>{a!==void 0&&i(a)},[a]);const p=k=>{i(k),l?.(k)};return e.jsx(Hr.Provider,{value:{form:d,formOpen:r,setFormOpen:p,datePickerOpen:c,setDatePickerOpen:m,planList:x,setPlanList:o},children:s})}function Ax(){const s=u.useContext(Hr);if(!s)throw new Error("useUserForm must be used within a UserFormProvider");return s}function $x({refetch:s}){const{t:n}=I("user"),{form:a,formOpen:l,setFormOpen:r,datePickerOpen:i,setDatePickerOpen:c,planList:m,setPlanList:x}=Ax();return u.useEffect(()=>{l&&Fs().then(({data:o})=>{x(o)})},[l,x]),e.jsxs(xe,{...a,children:[e.jsx(v,{control:a.control,name:"email",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.email")}),e.jsx(N,{children:e.jsx(P,{...o,placeholder:n("edit.form.email_placeholder")})}),e.jsx(R,{...o})]})}),e.jsx(v,{control:a.control,name:"invite_user_email",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.inviter_email")}),e.jsx(N,{children:e.jsx(P,{value:o.value||"",onChange:d=>o.onChange(d.target.value?d.target.value:null),placeholder:n("edit.form.inviter_email_placeholder")})}),e.jsx(R,{...o})]})}),e.jsx(v,{control:a.control,name:"password",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.password")}),e.jsx(N,{children:e.jsx(P,{value:o.value||"",onChange:o.onChange,placeholder:n("edit.form.password_placeholder")})}),e.jsx(R,{...o})]})}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsx(v,{control:a.control,name:"balance",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.balance")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(P,{type:"number",value:o.value||"",onChange:o.onChange,placeholder:n("edit.form.balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(R,{...o})]})}),e.jsx(v,{control:a.control,name:"commission_balance",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.commission_balance")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(P,{type:"number",value:o.value||"",onChange:o.onChange,placeholder:n("edit.form.commission_balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(R,{...o})]})}),e.jsx(v,{control:a.control,name:"u",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.upload")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(P,{value:o.value/1024/1024/1024||"",onChange:d=>o.onChange(parseInt(d.target.value)*1024*1024*1024),placeholder:n("edit.form.upload_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(R,{...o})]})}),e.jsx(v,{control:a.control,name:"d",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.download")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(P,{type:"number",value:o.value/1024/1024/1024||"",onChange:d=>o.onChange(parseInt(d.target.value)*1024*1024*1024),placeholder:n("edit.form.download_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(R,{...o})]})})]}),e.jsx(v,{control:a.control,name:"transfer_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.total_traffic")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(P,{type:"number",value:o.value/1024/1024/1024||"",onChange:d=>o.onChange(parseInt(d.target.value)*1024*1024*1024),placeholder:n("edit.form.total_traffic_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(R,{})]})}),e.jsx(v,{control:a.control,name:"expired_at",render:({field:o})=>e.jsxs(j,{className:"flex flex-col",children:[e.jsx(b,{children:n("edit.form.expire_time")}),e.jsxs(ns,{open:i,onOpenChange:c,children:[e.jsx(rs,{asChild:!0,children:e.jsx(N,{children:e.jsxs(V,{type:"button",variant:"outline",className:y("w-full pl-3 text-left font-normal",!o.value&&"text-muted-foreground"),onClick:()=>c(!0),children:[o.value?me(o.value):e.jsx("span",{children:n("edit.form.expire_time_placeholder")}),e.jsx(it,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Ye,{className:"w-auto p-0",align:"start",side:"top",sideOffset:4,onInteractOutside:d=>{d.preventDefault()},onEscapeKeyDown:d=>{d.preventDefault()},children:e.jsxs("div",{className:"flex flex-col space-y-3 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(V,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{o.onChange(null),c(!1)},children:n("edit.form.expire_time_permanent")}),e.jsx(V,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const d=new Date;d.setMonth(d.getMonth()+1),d.setHours(23,59,59,999),o.onChange(Math.floor(d.getTime()/1e3)),c(!1)},children:n("edit.form.expire_time_1month")}),e.jsx(V,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const d=new Date;d.setMonth(d.getMonth()+3),d.setHours(23,59,59,999),o.onChange(Math.floor(d.getTime()/1e3)),c(!1)},children:n("edit.form.expire_time_3months")})]}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Ms,{mode:"single",selected:o.value?new Date(o.value*1e3):void 0,onSelect:d=>{if(d){const p=new Date(o.value?o.value*1e3:Date.now());d.setHours(p.getHours(),p.getMinutes(),p.getSeconds()),o.onChange(Math.floor(d.getTime()/1e3))}},disabled:d=>d{const d=new Date;d.setHours(23,59,59,999),o.onChange(Math.floor(d.getTime()/1e3))},className:"h-6 px-2 text-xs",children:n("edit.form.expire_time_today")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{type:"datetime-local",step:"1",value:me(o.value,"YYYY-MM-DDTHH:mm:ss"),onChange:d=>{const p=new Date(d.target.value);isNaN(p.getTime())||o.onChange(Math.floor(p.getTime()/1e3))},className:"flex-1"}),e.jsx(V,{type:"button",variant:"outline",onClick:()=>c(!1),children:n("edit.form.expire_time_confirm")})]})]})]})})]}),e.jsx(R,{})]})}),e.jsx(v,{control:a.control,name:"plan_id",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.subscription")}),e.jsx(N,{children:e.jsxs(W,{value:o.value?o.value.toString():"null",onValueChange:d=>o.onChange(d==="null"?null:parseInt(d)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:n("edit.form.subscription_none")})}),e.jsxs(G,{children:[e.jsx($,{value:"null",children:n("edit.form.subscription_none")}),m.map(d=>e.jsx($,{value:d.id.toString(),children:d.name},d.id))]})]})})]})}),e.jsx(v,{control:a.control,name:"banned",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.account_status")}),e.jsx(N,{children:e.jsxs(W,{value:o.value.toString(),onValueChange:d=>o.onChange(parseInt(d)),children:[e.jsx(B,{children:e.jsx(Y,{})}),e.jsxs(G,{children:[e.jsx($,{value:"1",children:n("columns.status_text.banned")}),e.jsx($,{value:"0",children:n("columns.status_text.normal")})]})]})})]})}),e.jsx(v,{control:a.control,name:"commission_type",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.commission_type")}),e.jsx(N,{children:e.jsxs(W,{value:o.value.toString(),onValueChange:d=>o.onChange(parseInt(d)),children:[e.jsx(B,{children:e.jsx(Y,{placeholder:n("edit.form.subscription_none")})}),e.jsxs(G,{children:[e.jsx($,{value:"0",children:n("edit.form.commission_type_system")}),e.jsx($,{value:"1",children:n("edit.form.commission_type_cycle")}),e.jsx($,{value:"2",children:n("edit.form.commission_type_onetime")})]})]})})]})}),e.jsx(v,{control:a.control,name:"commission_rate",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.commission_rate")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(P,{type:"number",value:o.value||"",onChange:d=>o.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.commission_rate_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})})]})}),e.jsx(v,{control:a.control,name:"discount",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.discount")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(P,{type:"number",value:o.value||"",onChange:d=>o.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.discount_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})}),e.jsx(R,{})]})}),e.jsx(v,{control:a.control,name:"speed_limit",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.speed_limit")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(P,{type:"number",value:o.value||"",onChange:d=>o.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.speed_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"Mbps"})]})}),e.jsx(R,{})]})}),e.jsx(v,{control:a.control,name:"device_limit",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.device_limit")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(P,{type:"number",value:o.value||"",onChange:d=>o.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.device_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"台"})]})}),e.jsx(R,{})]})}),e.jsx(v,{control:a.control,name:"is_admin",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.is_admin")}),e.jsx("div",{className:"py-2",children:e.jsx(N,{children:e.jsx(H,{checked:o.value===1,onCheckedChange:d=>o.onChange(d?1:0)})})})]})}),e.jsx(v,{control:a.control,name:"is_staff",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.is_staff")}),e.jsx("div",{className:"py-2",children:e.jsx(N,{children:e.jsx(H,{checked:o.value===1,onCheckedChange:d=>o.onChange(d?1:0)})})})]})}),e.jsx(v,{control:a.control,name:"remarks",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:n("edit.form.remarks")}),e.jsx(N,{children:e.jsx(Cs,{className:"h-24",value:o.value||"",onChange:d=>o.onChange(d.currentTarget.value??null),placeholder:n("edit.form.remarks_placeholder")})}),e.jsx(R,{})]})}),e.jsxs(Kr,{children:[e.jsx(V,{variant:"outline",onClick:()=>r(!1),children:n("edit.form.cancel")}),e.jsx(V,{type:"submit",onClick:()=>{a.handleSubmit(o=>{vd(o).then(({data:d})=>{d&&(q.success(n("edit.form.success")),r(!1),s())})})()},children:n("edit.form.submit")})]})]})}function Ur({refetch:s,defaultValues:n,dialogTrigger:a=e.jsxs(V,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(ct,{className:"mr-2 h-4 w-4"}),t("edit.button")]})}){const{t:l}=I("user"),[r,i]=u.useState(!1);return e.jsx(Lx,{defaultValues:n,open:r,onOpenChange:i,children:e.jsxs(Ar,{open:r,onOpenChange:i,children:[e.jsx($r,{asChild:!0,children:a}),e.jsxs(fa,{className:"max-w-[90%] space-y-4",children:[e.jsxs(pa,{children:[e.jsx(ga,{children:l("edit.title")}),e.jsx(ja,{})]}),e.jsx($x,{refetch:s})]})]})})}const Br=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"})}),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:"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"})}),qx=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"})}),Kx=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"})}),qt=[{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:Xi(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Br,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:Xe(s.original.u)})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Gr,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:Xe(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(K,{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:Xe(n)})}}];function Wr({user_id:s,dialogTrigger:n}){const{t:a}=I(["traffic"]),[l,r]=u.useState(!1),[i,c]=u.useState({pageIndex:0,pageSize:20}),{data:m,isLoading:x}=se({queryKey:["userStats",s,i,l],queryFn:()=>l?Nd({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),o=Le({data:m?.data??[],columns:qt,pageCount:Math.ceil((m?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:Ae(),onPaginationChange:c});return e.jsxs(ge,{open:l,onOpenChange:r,children:[e.jsx(Me,{asChild:!0,children:n}),e.jsxs(he,{className:"sm:max-w-[700px]",children:[e.jsx(ve,{children:e.jsx(je,{children:a("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(ca,{children:[e.jsx(da,{children:o.getHeaderGroups().map(d=>e.jsx(vs,{children:d.headers.map(p=>e.jsx(ua,{className:y("h-10 px-2 text-xs",p.id==="total"&&"text-right"),children:p.isPlaceholder?null:bt(p.column.columnDef.header,p.getContext())},p.id))},d.id))}),e.jsx(ma,{children:x?Array.from({length:i.pageSize}).map((d,p)=>e.jsx(vs,{children:Array.from({length:qt.length}).map((k,E)=>e.jsx($s,{className:"p-2",children:e.jsx(Ie,{className:"h-6 w-full"})},E))},p)):o.getRowModel().rows?.length?o.getRowModel().rows.map(d=>e.jsx(vs,{"data-state":d.getIsSelected()&&"selected",className:"h-10",children:d.getVisibleCells().map(p=>e.jsx($s,{className:"px-2",children:bt(p.column.columnDef.cell,p.getContext())},p.id))},d.id)):e.jsx(vs,{children:e.jsx($s,{colSpan:qt.length,className:"h-24 text-center",children:a("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:a("trafficRecord.perPage")}),e.jsxs(W,{value:`${o.getState().pagination.pageSize}`,onValueChange:d=>{o.setPageSize(Number(d))},children:[e.jsx(B,{className:"h-8 w-[70px]",children:e.jsx(Y,{placeholder:o.getState().pagination.pageSize})}),e.jsx(G,{side:"top",children:[10,20,30,40,50].map(d=>e.jsx($,{value:`${d}`,children:d},d))})]}),e.jsx("p",{className:"text-sm font-medium",children:a("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:a("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()||x,children:e.jsx(qx,{className:"h-4 w-4"})}),e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>o.nextPage(),disabled:!o.getCanNextPage()||x,children:e.jsx(Kx,{className:"h-4 w-4"})})]})]})]})]})]})]})}const Hx=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"})}),Ux=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"})}),Bx=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"})}),Gx=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"})}),Wx=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"})}),Yx=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"})}),Jx=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"})}),Qx=(s,n)=>{const{t:a}=I("user");return[{accessorKey:"is_admin",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(l,r,i)=>i.includes(l.getValue(r)),size:0},{accessorKey:"is_staff",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(l,r,i)=>i.includes(l.getValue(r)),size:0},{accessorKey:"id",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.id")}),cell:({row:l})=>e.jsx(K,{variant:"outline",children:l.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.email")}),cell:({row:l})=>{const r=l.original.t||0,i=Date.now()/1e3-r<120,c=Math.floor(Date.now()/1e3-r);let m=i?a("columns.online_status.online"):r===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:me(r)});if(!i&&r!==0){const x=Math.floor(c/60),o=Math.floor(x/60),d=Math.floor(o/24);d>0?m+=` +`+a("columns.online_status.offline_duration.days",{count:d}):o>0?m+=` +`+a("columns.online_status.offline_duration.hours",{count:o}):x>0?m+=` +`+a("columns.online_status.offline_duration.minutes",{count:x}):m+=` +`+a("columns.online_status.offline_duration.seconds",{count:c})}return e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:y("size-2.5 rounded-full ring-2 ring-offset-2",i?"bg-green-500 ring-green-500/20":"bg-gray-300 ring-gray-300/20","transition-all duration-300")}),e.jsx("span",{className:"font-medium text-foreground/90",children:l.original.email})]})}),e.jsx(te,{side:"bottom",className:"max-w-[280px]",children:e.jsx("p",{className:"whitespace-pre-line text-sm",children:m})})]})})},enableSorting:!1,enableHiding:!1},{accessorKey:"online_count",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.online_count")}),cell:({row:l})=>{const r=l.original.device_limit,i=l.original.online_count||0;return e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(K,{variant:"outline",className:y("min-w-[4rem] justify-center",r!==null&&i>=r?"border-destructive/50 bg-destructive/10 text-destructive":"border-primary/40 bg-primary/5 text-primary/90"),children:[i," / ",r===null?"∞":r]})})}),e.jsx(te,{side:"bottom",children:e.jsx("p",{className:"text-sm",children:r===null?a("columns.device_limit.unlimited"):a("columns.device_limit.limited",{count:r})})})]})})},enableSorting:!0,enableHiding:!1},{accessorKey:"banned",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.status")}),cell:({row:l})=>{const r=l.original.banned;return e.jsx("div",{className:"flex justify-center",children:e.jsx(K,{className:y("min-w-20 justify-center transition-colors",r?"bg-destructive/15 text-destructive hover:bg-destructive/25":"bg-success/15 text-success hover:bg-success/25"),children:a(r?"columns.status_text.banned":"columns.status_text.normal")})})},enableSorting:!0,filterFn:(l,r,i)=>i.includes(l.getValue(r))},{accessorKey:"plan_id",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.subscription")}),cell:({row:l})=>e.jsx("div",{className:"min-w-[10em] break-all",children:l.original?.plan?.name||"-"}),enableSorting:!1,enableHiding:!1},{accessorKey:"group_id",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.group")}),cell:({row:l})=>e.jsx("div",{className:"flex flex-wrap gap-1",children:e.jsx(K,{variant:"outline",className:y("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 whitespace-nowrap"),children:l.original?.group?.name||"-"})}),enableSorting:!1},{accessorKey:"total_used",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.used_traffic")}),cell:({row:l})=>{const r=Xe(l.original?.total_used),i=Xe(l.original?.transfer_enable),c=l.original?.total_used/l.original?.transfer_enable*100||0;return e.jsx(ie,{delayDuration:100,children:e.jsxs(re,{children:[e.jsx(le,{className:"w-full",children:e.jsxs("div",{className:"w-full space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:r}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[c.toFixed(1),"%"]})]}),e.jsx("div",{className:"h-1.5 w-full rounded-full bg-secondary",children:e.jsx("div",{className:y("h-full rounded-full transition-all",c>90?"bg-destructive":"bg-primary"),style:{width:`${Math.min(c,100)}%`}})})]})}),e.jsx(te,{side:"bottom",children:e.jsxs("p",{className:"text-sm",children:[a("columns.total_traffic"),": ",i]})})]})})}},{accessorKey:"transfer_enable",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.total_traffic")}),cell:({row:l})=>e.jsx("div",{className:"font-medium text-muted-foreground",children:Xe(l.original?.transfer_enable)})},{accessorKey:"expired_at",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.expire_time")}),cell:({row:l})=>{const r=l.original.expired_at,i=Date.now()/1e3,c=r!=null&&re.jsx(M,{column:l,title:a("columns.balance")}),cell:({row:l})=>{const r=As(l.original?.balance);return e.jsxs("div",{className:"flex items-center gap-1 font-medium",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"¥"}),e.jsx("span",{className:"tabular-nums text-foreground",children:r})]})}},{accessorKey:"commission_balance",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.commission")}),cell:({row:l})=>{const r=As(l.original?.commission_balance);return e.jsxs("div",{className:"flex items-center gap-1 font-medium",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"¥"}),e.jsx("span",{className:"tabular-nums text-foreground",children:r})]})}},{accessorKey:"created_at",header:({column:l})=>e.jsx(M,{column:l,title:a("columns.register_time")}),cell:({row:l})=>e.jsx("div",{className:"truncate",children:me(l.original?.created_at)}),size:1e3},{id:"actions",header:({column:l})=>e.jsx(M,{column:l,className:"justify-end",title:a("columns.actions")}),cell:({row:l,table:r})=>e.jsxs(ys,{modal:!0,children:[e.jsx(Ns,{asChild:!0,children:e.jsx("div",{className:"text-center",children:e.jsx(J,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":a("columns.actions"),children:e.jsx(Nt,{className:"size-4"})})})}),e.jsxs(is,{align:"end",className:"min-w-[40px]",children:[e.jsx(fe,{onSelect:i=>{i.preventDefault()},className:"p-0",children:e.jsx(Ur,{defaultValues:{...l.original,invite_user_email:l.original.invite_user?.email},refetch:s,dialogTrigger:e.jsxs(J,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Hx,{className:"mr-2"}),a("columns.actions_menu.edit")]})})}),e.jsx(fe,{onSelect:i=>i.preventDefault(),className:"p-0",children:e.jsx(Or,{defaultValues:{email:l.original.email},trigger:e.jsxs(J,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Ux,{className:"mr-2 "}),a("columns.actions_menu.assign_order")]})})}),e.jsx(fe,{onSelect:()=>{wt(l.original.subscribe_url).then(()=>{q.success(a("common:copy.success"))})},className:"p-0",children:e.jsxs(J,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Bx,{className:"mr-2"}),a("columns.actions_menu.copy_url")]})}),e.jsx(fe,{onSelect:()=>{bd({id:l.original.id}).then(({data:i})=>{i&&q.success("重置成功")})},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Gx,{className:"mr-2 "}),a("columns.actions_menu.reset_secret")]})}),e.jsx(fe,{onSelect:()=>{},className:"p-0",children:e.jsxs(Rs,{className:"flex items-center px-2 py-1.5",to:`/finance/order?user_id=${l.original?.id}`,children:[e.jsx(Wx,{className:"mr-2"}),a("columns.actions_menu.orders")]})}),e.jsx(fe,{onSelect:()=>{r.setColumnFilters([{id:"invite_user_id",value:l.original?.id}])},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Yx,{className:"mr-2 "}),a("columns.actions_menu.invites")]})}),e.jsx(fe,{onSelect:i=>i.preventDefault(),className:"p-0",children:e.jsx(Wr,{user_id:l.original?.id,dialogTrigger:e.jsxs(J,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Jx,{className:"mr-2 "}),a("columns.actions_menu.traffic_records")]})})})]})]})}]};function Zx(){const[s]=Kn(),[n,a]=u.useState({}),[l,r]=u.useState({is_admin:!1,is_staff:!1}),[i,c]=u.useState([]),[m,x]=u.useState([]),[o,d]=u.useState({pageIndex:0,pageSize:20});u.useEffect(()=>{const D=s.get("email");D&&c(z=>z.some(A=>A.id==="email")?z:[...z,{id:"email",value:D}])},[s]);const{refetch:p,data:k,isLoading:E}=se({queryKey:["userList",o,i,m],queryFn:()=>jd({pageSize:o.pageSize,current:o.pageIndex+1,filter:i,sort:m})}),[f,_]=u.useState([]),[T,g]=u.useState([]);u.useEffect(()=>{It().then(({data:D})=>{_(D)}),Fs().then(({data:D})=>{g(D)})},[]);const w=f.map(D=>({label:D.name,value:D.id})),S=T.map(D=>({label:D.name,value:D.id})),C=Le({data:k?.data??[],columns:Qx(p),state:{sorting:m,columnVisibility:l,rowSelection:n,columnFilters:i,pagination:o},rowCount:k?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:x,onColumnFiltersChange:c,onColumnVisibilityChange:r,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),onPaginationChange:d,getSortedRowModel:We(),getFacetedRowModel:ms(),getFacetedUniqueValues:us(),initialState:{columnVisibility:{commission_balance:!1,created_at:!1,is_admin:!1,is_staff:!1,permission_group:!1,plan_id:!1},columnPinning:{right:["actions"]}}});return e.jsx(Je,{table:C,toolbar:e.jsx(Ox,{table:C,refetch:p,serverGroupList:f,permissionGroups:w,subscriptionPlans:S})})}function Xx(){const{t:s}=I("user");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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:"mt-2 text-muted-foreground",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("div",{className:"w-full",children:e.jsx(Zx,{})})})]})]})}const eh=Object.freeze(Object.defineProperty({__proto__:null,default:Xx},Symbol.toStringTag,{value:"Module"}));function sh({column:s,title:n,options:a}){const l=new Set(s?.getFilterValue());return e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(J,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Ni,{className:"mr-2 h-4 w-4"}),n,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:l.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:l.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[l.size," selected"]}):a.filter(r=>l.has(r.value)).map(r=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:r.label},`selected-${r.value}`))})]})]})}),e.jsx(Ye,{className:"w-[200px] p-0",align:"start",children:e.jsxs(_s,{children:[e.jsx(Vs,{placeholder:n}),e.jsxs(ws,{children:[e.jsx(Is,{children:"No results found."}),e.jsx(Fe,{children:a.map(r=>{const i=l.has(r.value);return e.jsxs(_e,{onSelect:()=>{i?l.delete(r.value):l.add(r.value);const c=Array.from(l);s?.setFilterValue(c.length?c:void 0)},children:[e.jsx("div",{className:y("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",i?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(_i,{className:y("h-4 w-4")})}),r.icon&&e.jsx(r.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:r.label})]},`option-${r.value}`)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Fe,{children:e.jsx(_e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const 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:"M19 11H5a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2"})});function ah({table:s}){const{t:n}=I("ticket");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-4",children:[e.jsx(pr,{defaultValue:s.getColumn("status")?.getFilterValue(),onValueChange:a=>s.getColumn("status")?.setFilterValue(a),children:e.jsxs(ia,{className:"grid w-full grid-cols-2",children:[e.jsx(nt,{value:"0",children:n("status.pending")}),e.jsx(nt,{value:"1",children:n("status.closed")})]})}),s.getColumn("level")&&e.jsx(sh,{column:s.getColumn("level"),title:n("columns.level"),options:[{label:n("level.low"),value:es.LOW,icon:th,color:"gray"},{label:n("level.medium"),value:es.MIDDLE,icon:Br,color:"yellow"},{label:n("level.high"),value:es.HIGH,icon:Gr,color:"red"}]})]})})}function nh(){return e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",className:"text-foreground",children:[e.jsx("circle",{cx:"4",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{id:"spinner_qFRN",begin:"0;spinner_OcgL.end+0.25s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})}),e.jsx("circle",{cx:"12",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{begin:"spinner_qFRN.begin+0.1s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})}),e.jsx("circle",{cx:"20",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{id:"spinner_OcgL",begin:"spinner_qFRN.begin+0.2s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})})]})}const rh=Ds("flex gap-2 max-w-[60%] items-end relative group",{variants:{variant:{received:"self-start",sent:"self-end flex-row-reverse"},layout:{default:"",ai:"max-w-full w-full items-center"}},defaultVariants:{variant:"received",layout:"default"}}),Yr=u.forwardRef(({className:s,variant:n,layout:a,children:l,...r},i)=>e.jsx("div",{className:y(rh({variant:n,layout:a,className:s}),"relative group"),ref:i,...r,children:u.Children.map(l,c=>u.isValidElement(c)&&typeof c.type!="string"?u.cloneElement(c,{variant:n,layout:a}):c)}));Yr.displayName="ChatBubble";const lh=Ds("p-4",{variants:{variant:{received:"bg-secondary text-secondary-foreground rounded-r-lg rounded-tl-lg",sent:"bg-primary text-primary-foreground rounded-l-lg rounded-tr-lg"},layout:{default:"",ai:"border-t w-full rounded-none bg-transparent"}},defaultVariants:{variant:"received",layout:"default"}}),Jr=u.forwardRef(({className:s,variant:n,layout:a,isLoading:l=!1,children:r,...i},c)=>e.jsx("div",{className:y(lh({variant:n,layout:a,className:s}),"break-words max-w-full whitespace-pre-wrap"),ref:c,...i,children:l?e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(nh,{})}):r}));Jr.displayName="ChatBubbleMessage";const oh=u.forwardRef(({variant:s,className:n,children:a,...l},r)=>e.jsx("div",{ref:r,className:y("absolute top-1/2 -translate-y-1/2 flex opacity-0 group-hover:opacity-100 transition-opacity duration-200",s==="sent"?"-left-1 -translate-x-full flex-row-reverse":"-right-1 translate-x-full",n),...l,children:a}));oh.displayName="ChatBubbleActionWrapper";const Qr=u.forwardRef(({className:s,...n},a)=>e.jsx(Cs,{autoComplete:"off",ref:a,name:"message",className:y("max-h-12 px-4 py-3 bg-background text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 w-full rounded-md flex items-center h-16 resize-none",s),...n}));Qr.displayName="ChatInput";const Zr=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:"m13.41 12l4.3-4.29a1 1 0 1 0-1.42-1.42L12 10.59l-4.29-4.3a1 1 0 0 0-1.42 1.42l4.3 4.29l-4.3 4.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0l4.29-4.3l4.29 4.3a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42Z"})}),Xr=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.098 12.634L13 11.423V7a1 1 0 0 0-2 0v5a1 1 0 0 0 .5.866l2.598 1.5a1 1 0 1 0 1-1.732M12 2a10 10 0 1 0 10 10A10.01 10.01 0 0 0 12 2m0 18a8 8 0 1 1 8-8a8.01 8.01 0 0 1-8 8"})}),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:"M3.71 16.29a1 1 0 0 0-.33-.21a1 1 0 0 0-.76 0a1 1 0 0 0-.33.21a1 1 0 0 0-.21.33a1 1 0 0 0 .21 1.09a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21a1 1 0 0 0 .21-1.09a1 1 0 0 0-.21-.33M7 8h14a1 1 0 0 0 0-2H7a1 1 0 0 0 0 2m-3.29 3.29a1 1 0 0 0-1.09-.21a1.2 1.2 0 0 0-.33.21a1 1 0 0 0-.21.33a.94.94 0 0 0 0 .76a1.2 1.2 0 0 0 .21.33a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21a1.2 1.2 0 0 0 .21-.33a.94.94 0 0 0 0-.76a1 1 0 0 0-.21-.33M21 11H7a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2M3.71 6.29a1 1 0 0 0-.33-.21a1 1 0 0 0-1.09.21a1.2 1.2 0 0 0-.21.33a.94.94 0 0 0 0 .76a1.2 1.2 0 0 0 .21.33a1.2 1.2 0 0 0 .33.21a1 1 0 0 0 1.09-.21a1.2 1.2 0 0 0 .21-.33a.94.94 0 0 0 0-.76a1.2 1.2 0 0 0-.21-.33M21 16H7a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2"})}),ch=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 12H7a1 1 0 0 0 0 2h2a1 1 0 0 0 0-2m-1-2h4a1 1 0 0 0 0-2H8a1 1 0 0 0 0 2m1 6H7a1 1 0 0 0 0 2h2a1 1 0 0 0 0-2m12-4h-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-5h2Zm-6.44-2.83a.8.8 0 0 0-.18-.09a.6.6 0 0 0-.19-.06a1 1 0 0 0-.9.27A1.05 1.05 0 0 0 12 17a1 1 0 0 0 .07.38a1.2 1.2 0 0 0 .22.33a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21A1 1 0 0 0 14 17a1.05 1.05 0 0 0-.29-.71a2 2 0 0 0-.15-.12m.14-3.88a1 1 0 0 0-1.62.33A1 1 0 0 0 13 14a1 1 0 0 0 1-1a1 1 0 0 0-.08-.38a.9.9 0 0 0-.22-.33"})});function dh(){return e.jsxs("div",{className:"flex h-full flex-col space-y-4 p-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{className:"h-8 w-3/4"}),e.jsx(Ie,{className:"h-4 w-1/2"})]}),e.jsx("div",{className:"flex-1 space-y-4",children:[1,2,3].map(s=>e.jsx(Ie,{className:"h-20 w-2/3"},s))})]})}function mh({ticketId:s,dialogTrigger:n}){const{t:a}=I("ticket"),l=cs(),r=u.useRef(null),[i,c]=u.useState(!1),[m,x]=u.useState(""),[o,d]=u.useState(!1),{data:p,refetch:k,isLoading:E}=se({queryKey:["ticket",s,i],queryFn:()=>i?wd(s):Promise.resolve(null),refetchInterval:i?5e3:!1,retry:3}),f=p?.data,_=(C="smooth")=>{if(r.current){const{scrollHeight:D,clientHeight:z}=r.current;r.current.scrollTo({top:D-z,behavior:C})}};u.useEffect(()=>{if(!i)return;const C=requestAnimationFrame(()=>{_("instant"),setTimeout(()=>_(),1e3)});return()=>{cancelAnimationFrame(C)}},[i,f?.messages]);const T=async()=>{const C=m.trim();!C||o||(d(!0),Cd({id:s,message:C}).then(()=>{x(""),k(),_()}).finally(()=>{d(!1)}))},g=async()=>{fr(s).then(()=>{q.success(a("actions.close_success")),k()})},w=()=>{f?.user&&l("/finance/order?user_id="+f.user.id)},S=f?.status===et.CLOSED;return e.jsxs(ge,{open:i,onOpenChange:c,children:[e.jsx(Me,{asChild:!0,children:n??e.jsx(J,{variant:"outline",children:a("actions.view_ticket")})}),e.jsxs(he,{className:"flex h-[90vh] max-w-4xl flex-col gap-0 p-0",children:[e.jsx(je,{}),E?e.jsx(dh,{}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-col space-y-4 border-b p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("h2",{className:"text-2xl font-semibold",children:f?.subject}),e.jsx(K,{variant:S?"secondary":"default",children:a(S?"status.closed":"status.processing")}),!S&&e.jsx(Qe,{title:a("actions.close_confirm_title"),description:a("actions.close_confirm_description"),confirmText:a("actions.close_confirm_button"),variant:"destructive",onConfirm:g,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"gap-1 text-muted-foreground hover:text-destructive",children:[e.jsx(Zr,{className:"h-4 w-4"}),a("actions.close_ticket")]})})]}),e.jsxs("div",{className:"flex items-center space-x-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(ot,{className:"h-4 w-4"}),e.jsx("span",{children:f?.user?.email})]}),e.jsx(be,{orientation:"vertical",className:"h-4"}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Xr,{className:"h-4 w-4"}),e.jsxs("span",{children:[a("detail.created_at")," ",me(f?.created_at)]})]}),e.jsx(be,{orientation:"vertical",className:"h-4"}),e.jsx(K,{variant:"outline",children:f?.level!=null&&a(`level.${f.level===es.LOW?"low":f.level===es.MIDDLE?"medium":"high"}`)})]})]}),f?.user&&e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(Ur,{defaultValues:f.user,refetch:k,dialogTrigger:e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",title:a("detail.user_info"),children:e.jsx(ot,{className:"h-4 w-4"})})}),e.jsx(Wr,{user_id:f.user.id,dialogTrigger:e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",title:a("detail.traffic_records"),children:e.jsx(ih,{className:"h-4 w-4"})})}),e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",title:a("detail.order_records"),onClick:w,children:e.jsx(ch,{className:"h-4 w-4"})})]})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{ref:r,className:"h-full space-y-4 overflow-y-auto p-6",children:f?.messages?.length===0?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:a("detail.no_messages")}):f?.messages?.map(C=>e.jsx(Yr,{variant:C.is_me?"sent":"received",className:C.is_me?"ml-auto":"mr-auto",children:e.jsx(Jr,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"whitespace-pre-wrap break-words",children:C.message}),e.jsx("div",{className:"text-right",children:e.jsx("time",{className:"text-[10px] text-muted-foreground",children:me(C.created_at)})})]})})},C.id))})}),e.jsx("div",{className:"border-t p-4",children:e.jsxs("div",{className:"relative flex items-center space-x-2",children:[e.jsx(Qr,{disabled:S||o,placeholder:a(S?"detail.input.closed_placeholder":"detail.input.reply_placeholder"),className:"flex-1 resize-none rounded-lg border bg-background p-3 focus-visible:ring-1",value:m,onChange:C=>x(C.target.value),onKeyDown:C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),T())}}),e.jsx(J,{disabled:S||o||!m.trim(),onClick:T,children:a(o?"detail.input.sending":"detail.input.send")})]})})]})]})]})}const uh=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 4H5a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3V7a3 3 0 0 0-3-3m-.41 2l-5.88 5.88a1 1 0 0 1-1.42 0L5.41 6ZM20 17a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7.41l5.88 5.88a3 3 0 0 0 4.24 0L20 7.41Z"})}),xh=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.92 11.6C19.9 6.91 16.1 4 12 4s-7.9 2.91-9.92 7.6a1 1 0 0 0 0 .8C4.1 17.09 7.9 20 12 20s7.9-2.91 9.92-7.6a1 1 0 0 0 0-.8M12 18c-3.17 0-6.17-2.29-7.9-6C5.83 8.29 8.83 6 12 6s6.17 2.29 7.9 6c-1.73 3.71-4.73 6-7.9 6m0-10a4 4 0 1 0 4 4a4 4 0 0 0-4-4m0 6a2 2 0 1 1 2-2a2 2 0 0 1-2 2"})}),hh=s=>{const{t:n}=I("ticket");return[{accessorKey:"id",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.id")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:a.getValue("id")}),enableSorting:!1,enableHiding:!1},{accessorKey:"subject",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.subject")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(uh,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"max-w-[500px] truncate font-medium",children:a.getValue("subject")})]}),enableSorting:!1,enableHiding:!1,size:4e3},{accessorKey:"level",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.level")}),cell:({row:a})=>{const l=a.getValue("level"),r=l===es.LOW?"default":l===es.MIDDLE?"secondary":"destructive";return e.jsx(K,{variant:r,className:"whitespace-nowrap",children:n(`level.${l===es.LOW?"low":l===es.MIDDLE?"medium":"high"}`)})},filterFn:(a,l,r)=>r.includes(a.getValue(l))},{accessorKey:"status",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.status")}),cell:({row:a})=>{const l=a.getValue("status"),r=a.original.reply_status,i=l===et.CLOSED?n("status.closed"):n(r===0?"status.replied":"status.pending"),c=l===et.CLOSED?"default":r===0?"secondary":"destructive";return e.jsx(K,{variant:c,className:"whitespace-nowrap",children:i})}},{accessorKey:"updated_at",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.updated_at")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[e.jsx(Xr,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:me(a.getValue("updated_at"))})]}),enableSorting:!0},{accessorKey:"created_at",header:({column:a})=>e.jsx(M,{column:a,title:n("columns.created_at")}),cell:({row:a})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:me(a.getValue("created_at"))}),enableSorting:!0,meta:{isFlexGrow:!0}},{id:"actions",header:({column:a})=>e.jsx(M,{className:"justify-end",column:a,title:n("columns.actions")}),cell:({row:a})=>{const l=a.original.status!==et.CLOSED;return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(mh,{ticketId:a.original.id,dialogTrigger:e.jsx(J,{variant:"ghost",size:"icon",className:"h-8 w-8",title:n("actions.view_details"),children:e.jsx(xh,{className:"h-4 w-4"})})}),l&&e.jsx(Qe,{title:n("actions.close_confirm_title"),description:n("actions.close_confirm_description"),confirmText:n("actions.close_confirm_button"),variant:"destructive",onConfirm:async()=>{fr(a.original.id).then(()=>{q.success(n("actions.close_success")),s()})},children:e.jsx(J,{variant:"ghost",size:"icon",className:"h-8 w-8",title:n("actions.close_ticket"),children:e.jsx(Zr,{className:"h-4 w-4"})})})]})}}]};function fh(){const[s,n]=u.useState({}),[a,l]=u.useState({}),[r,i]=u.useState([{id:"status",value:"0"}]),[c,m]=u.useState([]),[x,o]=u.useState({pageIndex:0,pageSize:20}),{refetch:d,data:p,isLoading:k}=se({queryKey:["orderList",x,r,c],queryFn:()=>_d({pageSize:x.pageSize,current:x.pageIndex+1,filter:r,sort:c})}),E=Le({data:p?.data??[],columns:hh(d),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:x},rowCount:p?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:i,onColumnVisibilityChange:l,getCoreRowModel:Ae(),getFilteredRowModel:Be(),getPaginationRowModel:Ge(),onPaginationChange:o,getSortedRowModel:We(),getFacetedRowModel:ms(),getFacetedUniqueValues:us(),initialState:{columnPinning:{right:["actions"]}}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(ah,{table:E,refetch:d}),e.jsx(Je,{table:E,showPagination:!0})]})}function ph(){const{t:s}=I("ticket");return e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Pe,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Re,{}),e.jsx(Ee,{})]})]}),e.jsxs(ke,{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(fh,{})})]})]})}const gh=Object.freeze(Object.defineProperty({__proto__:null,default:ph},Symbol.toStringTag,{value:"Module"}));export{Nh as a,bh as c,yh as g,_h as r}; diff --git a/public/assets/admin/locales/zh-CN.js b/public/assets/admin/locales/zh-CN.js index 5e2b0dd..17a6258 100644 --- a/public/assets/admin/locales/zh-CN.js +++ b/public/assets/admin/locales/zh-CN.js @@ -617,7 +617,8 @@ window.XBOARD_TRANSLATIONS['zh-CN'] = { "common": { "saving": "保存中...", "save_success": "已自动保存", - "placeholder": "请输入" + "placeholder": "请输入", + "autoSaved": "已自动保存" }, "invite": { "title": "邀请&佣金设置",