Xboard/public/assets/admin/assets/index.js
xboard d2462bc683
Some checks are pending
Docker Build and Publish / build (push) Waiting to run
fix: correct know file issues
2025-01-13 20:34:50 +08:00

22 lines
355 KiB
JavaScript
Vendored
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{r as c,j as e,t as xl,c as ml,I as Na,a as Ss,S as Qt,u as ns,b as Zt,d as hl,O as Xt,e as jl,f as A,g as gl,h as fl,i as pl,Q as vl,k as bl,R as yl,l as Nl,P as wl,m as _l,B as Cl,n as Ua,F as Sl,C as kl,o as Tl,p as Dl,q as Pl,s as Vl,v as Il,z as u,w as Ba,x as ae,y as ie,A as Ga,D as _t,E as Ct,G as ea,H as Fe,T as St,J as kt,K as Ya,L as Wa,M as Rl,N as El,U as Fl,V as Ml,W as Ja,X as sa,Y as Qa,Z as zl,_ as Za,$ as Xa,a0 as en,a1 as sn,a2 as ks,a3 as tn,a4 as Ol,a5 as an,a6 as nn,a7 as Ll,a8 as $l,a9 as Al,aa as Hl,ab as rn,ac as Kl,ad as ql,ae as Ts,af as ln,ag as Ul,ah as Bl,ai as on,aj as Gl,ak as Yl,al as wa,am as Wl,an as cn,ao as Jl,ap as dn,aq as Ql,ar as Zl,as as Xl,at as ei,au as si,av as ti,aw as un,ax as ai,ay as ni,az as ri,aA as we,aB as li,aC as ii,aD as oi,aE as ci,aF as xn,aG as mn,aH as hn,aI as di,aJ as jn,aK as gn,aL as fn,aM as ui,aN as xi,aO as mi,aP as pn,aQ as hi,aR as ta,aS as vn,aT as ji,aU as bn,aV as gi,aW as yn,aX as fi,aY as Nn,aZ as wn,a_ as pi,a$ as vi,b0 as _n,b1 as bi,b2 as yi,b3 as Cn,b4 as Ni,b5 as Sn,b6 as wi,b7 as _i,b8 as Le,b9 as Q,ba as Pe,bb as lt,bc as Ci,bd as Si,be as ki,bf as Ti,bg as Di,bh as Pi,bi as _a,bj as Ca,bk as Vi,bl as Ii,bm as Ri,bn as Ei,bo as Fi,bp as At,bq as Ht,br as Mi,bs as zi,bt as kn,bu as Oi,bv as Li,bw as Tn,bx as $i,by as de,bz as Ai,bA as Sa,bB as Kt,bC as qt,bD as Hi,bE as Ki,bF as Dn,bG as qi,bH as aa,bI as Ui,bJ as Bi,bK as Gi,bL as Pn,bM as Vn,bN as In,bO as Yi,bP as Wi,bQ as Ji,bR as Qi,bS as Rn,bT as Zi,bU as We,bV as Xi,bW as eo,bX as vt,bY as ve,bZ as ka,b_ as so,b$ as En,c0 as Fn,c1 as Mn,c2 as zn,c3 as On,c4 as Ln,c5 as to,c6 as ao,c7 as no,c8 as Tt,c9 as Ds,ca as rs,cb as Me,cc as ze,cd as Ae,ce as He,cf as Ke,cg as ro,ch as lo,ci as io,cj as Ut,ck as na,cl as ra,cm as oo,cn as ls,co as is,cp as it,cq as co,cr as uo,cs as Ta,ct as Da,cu as $n,cv as Pa,cw as bt,cx as xo,cy as mo,cz as An,cA as ho,cB as jo,cC as Hn,cD as Bt,cE as Kn,cF as go,cG as qn,cH as Un,cI as fo,cJ as po,cK as vo,cL as bo,cM as yo}from"./vendor.js";import"./index.js";var fh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ph(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function No(s){if(s.__esModule)return s;var t=s.default;if(typeof t=="function"){var a=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};a.prototype=t.prototype}else a={};return Object.defineProperty(a,"__esModule",{value:!0}),Object.keys(s).forEach(function(n){var l=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(a,n,l.get?l:{enumerable:!0,get:function(){return s[n]}})}),a}const wo={theme:"system",setTheme:()=>null},Bn=c.createContext(wo);function _o({children:s,defaultTheme:t="system",storageKey:a="vite-ui-theme",...n}){const[l,o]=c.useState(()=>localStorage.getItem(a)||t);c.useEffect(()=>{const x=window.document.documentElement;if(x.classList.remove("light","dark"),l==="system"){const r=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";x.classList.add(r);return}x.classList.add(l)},[l]);const d={theme:l,setTheme:x=>{localStorage.setItem(a,x),o(x)}};return e.jsx(Bn.Provider,{...n,value:d,children:s})}const Co=()=>{const s=c.useContext(Bn);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},So=function(){const t=typeof document<"u"&&document.createElement("link").relList;return t&&t.supports&&t.supports("modulepreload")?"modulepreload":"preload"}(),ko=function(s,t){return new URL(s,t).href},Va={},X=function(t,a,n){let l=Promise.resolve();if(a&&a.length>0){const d=document.getElementsByTagName("link"),x=document.querySelector("meta[property=csp-nonce]"),r=x?.nonce||x?.getAttribute("nonce");l=Promise.allSettled(a.map(i=>{if(i=ko(i,n),i in Va)return;Va[i]=!0;const h=i.endsWith(".css"),D=h?'[rel="stylesheet"]':"";if(!!n)for(let w=d.length-1;w>=0;w--){const _=d[w];if(_.href===i&&(!h||_.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${i}"]${D}`))return;const m=document.createElement("link");if(m.rel=h?"stylesheet":So,h||(m.as="script"),m.crossOrigin="",m.href=i,r&&m.setAttribute("nonce",r),document.head.appendChild(m),h)return new Promise((w,_)=>{m.addEventListener("load",w),m.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${i}`)))})}))}function o(d){const x=new Event("vite:preloadError",{cancelable:!0});if(x.payload=d,window.dispatchEvent(x),!x.defaultPrevented)throw d}return l.then(d=>{for(const x of d||[])x.status==="rejected"&&o(x.reason);return t().catch(o)})};function v(...s){return xl(ml(s))}const As=Ss("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"}}),T=c.forwardRef(({className:s,variant:t,size:a,asChild:n=!1,children:l,disabled:o,loading:d=!1,leftSection:x,rightSection:r,...i},h)=>{const D=n?Qt:"button";return e.jsxs(D,{className:v(As({variant:t,size:a,className:s})),disabled:d||o,ref:h,...i,children:[(x&&d||!x&&!r&&d)&&e.jsx(Na,{className:"mr-2 h-4 w-4 animate-spin"}),!d&&x&&e.jsx("div",{className:"mr-2",children:x}),l,!d&&r&&e.jsx("div",{className:"ml-2",children:r}),r&&d&&e.jsx(Na,{className:"ml-2 h-4 w-4 animate-spin"})]})});T.displayName="Button";function Es({className:s,minimal:t=!1}){const a=ns();return e.jsx("div",{className:v("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:[!t&&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."]}),!t&&e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(T,{variant:"outline",onClick:()=>a(-1),children:"Go Back"}),e.jsx(T,{onClick:()=>a("/"),children:"Back to Home"})]})]})})}function Ia(){const s=ns();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(T,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(T,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function To(){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(T,{variant:"outline",children:"Learn more"})})]})})}function Do(s){return typeof s>"u"}function Po(s){return s===null}function Vo(s){return Po(s)||Do(s)}class Io{storage;prefixKey;constructor(t){this.storage=t.storage,this.prefixKey=t.prefixKey}getKey(t){return`${this.prefixKey}${t}`.toUpperCase()}set(t,a,n=null){const l=JSON.stringify({value:a,time:Date.now(),expire:n!==null?new Date().getTime()+n*1e3:null});this.storage.setItem(this.getKey(t),l)}get(t,a=null){const n=this.storage.getItem(this.getKey(t));if(!n)return{value:a,time:0};try{const l=JSON.parse(n),{value:o,time:d,expire:x}=l;return Vo(x)||x>new Date().getTime()?{value:o,time:d}:(this.remove(t),{value:a,time:0})}catch{return this.remove(t),{value:a,time:0}}}remove(t){this.storage.removeItem(this.getKey(t))}clear(){this.storage.clear()}}function Gn({prefixKey:s="",storage:t=sessionStorage}){return new Io({prefixKey:s,storage:t})}const Yn="Xboard_",Ro=function(s={}){return Gn({prefixKey:s.prefixKey||"",storage:localStorage})},Eo=function(s={}){return Gn({prefixKey:s.prefixKey||"",storage:sessionStorage})},Dt=Ro({prefixKey:Yn});Eo({prefixKey:Yn});const Wn="access_token";function Zs(){return Dt.get(Wn)}function Jn(){Dt.remove(Wn)}const Ra=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function Fo({children:s}){const t=ns(),a=Zt(),n=Zs();return c.useEffect(()=>{if(!n.value&&!Ra.includes(a.pathname)){const l=encodeURIComponent(a.pathname+a.search);t(`/sign-in?redirect=${l}`)}},[n.value,a.pathname,a.search,t]),Ra.includes(a.pathname)||n.value?e.jsx(e.Fragment,{children:s}):null}const Mo=()=>e.jsx(Fo,{children:e.jsx(Xt,{})}),zo=hl([{path:"/sign-in",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>nc);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(Mo,{}),children:[{path:"/",lazy:async()=>({Component:(await X(()=>Promise.resolve().then(()=>pc),void 0,import.meta.url)).default}),errorElement:e.jsx(Es,{}),children:[{index:!0,lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Ud);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(Es,{}),children:[{path:"system",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Yd);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Xd);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>nu);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>cu);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>hu);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>vu);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>_u);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Du);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Eu);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Lu);return{default:s}},void 0,import.meta.url)).default})}]},{path:"payment",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Qu);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>ex);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>ix);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>jx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(Es,{}),children:[{path:"manage",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>$x);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Ux);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Qx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(Es,{}),children:[{path:"plan",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>lm);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>vm);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Tm);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(Es,{}),children:[{path:"manage",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>Qm);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await X(async()=>{const{default:s}=await Promise.resolve().then(()=>hh);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:Es},{path:"/404",Component:Ia},{path:"/503",Component:To},{path:"*",Component:Ia}]),Oo="locale";function Lo(){return Dt.get(Oo)}function Qn(){Jn();const s=window.location.pathname,t=s&&!["/404","/sign-in"].includes(s),a=new URL(window.location.href),l=`${a.pathname.split("/")[1]?`/${a.pathname.split("/")[1]}`:""}#/sign-in`;window.location.href=l+(t?`?redirect=${s}`:"")}const $o=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function Ao(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const I=jl.create({baseURL:Ao(),timeout:12e3,headers:{"Content-Type":"application/json"}});I.interceptors.request.use(s=>{s.method?.toLowerCase()==="get"&&(s.params={...s.params,t:Date.now()});const t=Zs();if(!$o.includes(s.url?.split("?")[0]||"")){if(!t.value)return Qn(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=t.value}return s.headers["Content-Language"]=Lo().value||"zh-CN",s},s=>Promise.reject(s));I.interceptors.response.use(s=>s?.data||{code:-1,message:"未知错误"},s=>{const t=s.response?.status,a=s.response?.data?.message;return(t===401||t===403)&&Qn(),A.error(a||{401:"登录已过期",403:"没有权限",404:"资源或接口不存在"}[t]||"未知异常"),Promise.reject(s.response?.data||{data:null,code:-1,message:"未知错误"})});function Ho(){return I.get("/user/info")}const Mt={token:Zs()?.value||"",userInfo:null,isLoggedIn:!!Zs()?.value,loading:!1,error:null},Js=gl("user/fetchUserInfo",async()=>(await Ho()).data,{condition:(s,{getState:t})=>{const{user:a}=t();return!!a.token&&!a.loading}}),Zn=fl({name:"user",initialState:Mt,reducers:{setToken(s,t){s.token=t.payload,s.isLoggedIn=!!t.payload},resetUserState:()=>Mt},extraReducers:s=>{s.addCase(Js.pending,t=>{t.loading=!0,t.error=null}).addCase(Js.fulfilled,(t,a)=>{t.loading=!1,t.userInfo=a.payload,t.error=null}).addCase(Js.rejected,(t,a)=>{if(t.loading=!1,t.error=a.error.message||"Failed to fetch user info",!t.token)return Mt})}}),{setToken:Ko,resetUserState:qo}=Zn.actions,Uo=s=>s.user.userInfo,Bo=Zn.reducer,Xn=pl({reducer:{user:Bo}});Zs()?.value&&Xn.dispatch(Js());const Go=new vl;bl.createRoot(document.getElementById("root")).render(e.jsx(yl.StrictMode,{children:e.jsx(Nl,{client:Go,children:e.jsx(wl,{store:Xn,children:e.jsxs(_o,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(_l,{router:zo}),e.jsx(Cl,{richColors:!0,position:"top-right"})]})})})}));const $e=c.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("rounded-xl border bg-card text-card-foreground shadow",s),...t}));$e.displayName="Card";const Je=c.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("flex flex-col space-y-1.5 p-6",s),...t}));Je.displayName="CardHeader";const gs=c.forwardRef(({className:s,...t},a)=>e.jsx("h3",{ref:a,className:v("font-semibold leading-none tracking-tight",s),...t}));gs.displayName="CardTitle";const Xs=c.forwardRef(({className:s,...t},a)=>e.jsx("p",{ref:a,className:v("text-sm text-muted-foreground",s),...t}));Xs.displayName="CardDescription";const Qe=c.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("p-6 pt-0",s),...t}));Qe.displayName="CardContent";const Yo=c.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("flex items-center p-6 pt-0",s),...t}));Yo.displayName="CardFooter";const Wo=Ss("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),yt=c.forwardRef(({className:s,...t},a)=>e.jsx(Ua,{ref:a,className:v(Wo(),s),...t}));yt.displayName=Ua.displayName;const oe=Sl,er=c.createContext({}),g=({...s})=>e.jsx(er.Provider,{value:{name:s.name},children:e.jsx(kl,{...s})}),Pt=()=>{const s=c.useContext(er),t=c.useContext(sr),{getFieldState:a,formState:n}=Tl(),l=a(s.name,n);if(!s)throw new Error("useFormField should be used within <FormField>");const{id:o}=t;return{id:o,name:s.name,formItemId:`${o}-form-item`,formDescriptionId:`${o}-form-item-description`,formMessageId:`${o}-form-item-message`,...l}},sr=c.createContext({}),j=c.forwardRef(({className:s,...t},a)=>{const n=c.useId();return e.jsx(sr.Provider,{value:{id:n},children:e.jsx("div",{ref:a,className:v("space-y-2",s),...t})})});j.displayName="FormItem";const p=c.forwardRef(({className:s,...t},a)=>{const{error:n,formItemId:l}=Pt();return e.jsx(yt,{ref:a,className:v(n&&"text-destructive",s),htmlFor:l,...t})});p.displayName="FormLabel";const y=c.forwardRef(({...s},t)=>{const{error:a,formItemId:n,formDescriptionId:l,formMessageId:o}=Pt();return e.jsx(Qt,{ref:t,id:n,"aria-describedby":a?`${l} ${o}`:`${l}`,"aria-invalid":!!a,...s})});y.displayName="FormControl";const F=c.forwardRef(({className:s,...t},a)=>{const{formDescriptionId:n}=Pt();return e.jsx("p",{ref:a,id:n,className:v("text-[0.8rem] text-muted-foreground",s),...t})});F.displayName="FormDescription";const k=c.forwardRef(({className:s,children:t,...a},n)=>{const{error:l,formMessageId:o}=Pt(),d=l?String(l?.message):t;return d?e.jsx("p",{ref:n,id:o,className:v("text-[0.8rem] font-medium text-destructive",s),...a,children:d}):null});k.displayName="FormMessage";const S=c.forwardRef(({className:s,type:t,...a},n)=>e.jsx("input",{type:t,className:v("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:n,...a}));S.displayName="Input";const tr=c.forwardRef(({className:s,...t},a)=>{const[n,l]=c.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:n?"text":"password",className:v("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,...t}),e.jsx(T,{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:()=>l(o=>!o),children:n?e.jsx(Dl,{size:18}):e.jsx(Pl,{size:18})})]})});tr.displayName="PasswordInput";const Jo=s=>I({url:"/passport/auth/login",method:"post",data:s}),Gt=s=>s;function re(s=void 0,t="YYYY-MM-DD HH:mm:ss"){return s==null?"":(Math.floor(s).toString().length===10&&(s=s*1e3),Il(s).format(t))}function Qo(s=void 0,t="YYYY-MM-DD"){return re(s,t)}function zs(s){const t=typeof s=="string"?parseFloat(s):s;return isNaN(t)?"0.00":t.toFixed(2)}function Ns(s,t=!0){if(s==null)return t?"¥0.00":"0.00";const a=typeof s=="string"?parseFloat(s):s;if(isNaN(a))return t?"¥0.00":"0.00";const l=(a/100).toFixed(2).replace(/\.?0+$/,o=>o.includes(".")?".00":o);return t?`¥${l}`:l}function Nt(s){navigator.clipboard?navigator.clipboard.writeText(s).then(()=>{A.success(Gt("复制成功"))}).catch(t=>{console.error("复制到剪贴板时出错:",t),Ea(s)}):Ea(s)}function Ea(s){const t=document.createElement("button"),a=new Vl(t,{text:()=>s});a.on("success",()=>{A.success(Gt("复制成功")),a.destroy()}),a.on("error",()=>{A.error(Gt("复制失败")),a.destroy()}),t.click()}function Ye(s){const t=s/1024,a=t/1024,n=a/1024,l=n/1024;return l>=1?zs(l)+" TB":n>=1?zs(n)+" GB":a>=1?zs(a)+" MB":zs(t)+" KB"}const Zo="access_token";function Xo(s){Dt.set(Zo,s)}const ec=u.object({email:u.string().min(1,{message:"请输入邮箱地址"}).email({message:"邮箱地址格式不正确"}),password:u.string().min(1,{message:"请输入密码"}).min(7,{message:"密码长度至少为7个字符"})});function sc({className:s,onForgotPassword:t,...a}){const n=ns(),l=Ba(),o=ae({resolver:ie(ec),defaultValues:{email:"",password:""}});async function d(x){Jo(x).then(({data:r})=>{Xo(r.auth_data),l(Ko(r.auth_data)),l(Js()).unwrap(),n("/")})}return e.jsx("div",{className:v("grid gap-6",s),...a,children:e.jsx(oe,{...o,children:e.jsx("form",{onSubmit:o.handleSubmit(d),children:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(g,{control:o.control,name:"email",render:({field:x})=>e.jsxs(j,{className:"space-y-1",children:[e.jsx(p,{children:"邮箱地址"}),e.jsx(y,{children:e.jsx(S,{placeholder:"name@example.com",...x})}),e.jsx(k,{})]})}),e.jsx(g,{control:o.control,name:"password",render:({field:x})=>e.jsxs(j,{className:"space-y-1",children:[e.jsx(p,{children:"密码"}),e.jsx(y,{children:e.jsx(tr,{placeholder:"请输入密码",...x})}),e.jsx(k,{})]})}),e.jsx(T,{className:"mt-2",loading:o.formState.isSubmitting,children:"登录"}),e.jsx(T,{variant:"link",type:"button",className:"mt-1 text-sm text-muted-foreground hover:text-primary",onClick:t,children:"忘记密码?"})]})})})})}const ue=Ga,Ie=Ya,tc=Wa,ot=ea,ar=c.forwardRef(({className:s,...t},a)=>e.jsx(_t,{ref:a,className:v("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),...t}));ar.displayName=_t.displayName;const ce=c.forwardRef(({className:s,children:t,...a},n)=>e.jsxs(tc,{children:[e.jsx(ar,{}),e.jsxs(Ct,{ref:n,className:v("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:[t,e.jsxs(ea,{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(Fe,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ce.displayName=Ct.displayName;const he=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-1.5 text-center sm:text-left",s),...t});he.displayName="DialogHeader";const Re=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});Re.displayName="DialogFooter";const xe=c.forwardRef(({className:s,...t},a)=>e.jsx(St,{ref:a,className:v("text-lg font-semibold leading-none tracking-tight",s),...t}));xe.displayName=St.displayName;const Se=c.forwardRef(({className:s,...t},a)=>e.jsx(kt,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));Se.displayName=kt.displayName;const $s=Ss("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"}}),W=c.forwardRef(({className:s,variant:t,size:a,asChild:n=!1,...l},o)=>{const d=n?Qt:"button";return e.jsx(d,{className:v($s({variant:t,size:a,className:s})),ref:o,...l})});W.displayName="Button";function ac(){const[s,t]=c.useState(!1),a="php artisan reset:password 管理员邮箱";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"container grid h-svh flex-col items-center justify-center bg-primary-foreground lg:max-w-none lg:px-0",children:e.jsxs("div",{className:"mx-auto flex w-full flex-col justify-center space-y-2 sm:w-[480px] lg:p-8",children:[e.jsx("div",{className:"mb-4 flex items-center justify-center",children:e.jsx("h1",{className:"text-3xl font-medium",children:window?.settings?.title})}),e.jsxs($e,{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:"登录"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"请输入您的邮箱和密码登录系统"})]}),e.jsx(sc,{onForgotPassword:()=>t(!0)})]})]})}),e.jsx(ue,{open:s,onOpenChange:t,children:e.jsx(ce,{children:e.jsxs(he,{children:[e.jsx(xe,{children:"忘记密码"}),e.jsx(Se,{children:"在站点目录下执行以下命令找回密码"}),e.jsx("div",{className:"mt-2",children:e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"rounded-md bg-secondary p-4 pr-12",children:a}),e.jsx(W,{variant:"ghost",size:"icon",className:"absolute right-2 top-2 h-8 w-8 hover:bg-secondary-foreground/10",onClick:()=>Nt(a),children:e.jsx(Rl,{className:"h-4 w-4"})})]})})]})})})]})}const nc=Object.freeze(Object.defineProperty({__proto__:null,default:ac},Symbol.toStringTag,{value:"Module"})),ye=c.forwardRef(({className:s,fadedBelow:t=!1,fixedHeight:a=!1,...n},l)=>e.jsx("div",{ref:l,className:v("relative flex h-full w-full flex-col",t&&"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),...n}));ye.displayName="Layout";const Ne=c.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...t}));Ne.displayName="LayoutHeader";const _e=c.forwardRef(({className:s,fixedHeight:t,...a},n)=>e.jsx("div",{ref:n,className:v("flex-1 overflow-hidden px-4 py-6 md:px-8",t&&"h-[calc(100%-var(--header-height))]",s),...a}));_e.displayName="LayoutBody";const nr=El,rr=Fl,lr=Ml,_s=Ll,Cs=$l,rc=Al,lc=c.forwardRef(({className:s,inset:t,children:a,...n},l)=>e.jsxs(Ja,{ref:l,className:v("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",t&&"pl-8",s),...n,children:[a,e.jsx(sa,{className:"ml-auto h-4 w-4"})]}));lc.displayName=Ja.displayName;const ic=c.forwardRef(({className:s,...t},a)=>e.jsx(Qa,{ref:a,className:v("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),...t}));ic.displayName=Qa.displayName;const fs=c.forwardRef(({className:s,sideOffset:t=4,...a},n)=>e.jsx(zl,{children:e.jsx(Za,{ref:n,sideOffset:t,className:v("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})}));fs.displayName=Za.displayName;const me=c.forwardRef(({className:s,inset:t,...a},n)=>e.jsx(Xa,{ref:n,className:v("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",t&&"pl-8",s),...a}));me.displayName=Xa.displayName;const oc=c.forwardRef(({className:s,children:t,checked:a,...n},l)=>e.jsxs(en,{ref:l,className:v("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,...n,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(sn,{children:e.jsx(ks,{className:"h-4 w-4"})})}),t]}));oc.displayName=en.displayName;const cc=c.forwardRef(({className:s,children:t,...a},n)=>e.jsxs(tn,{ref:n,className:v("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(sn,{children:e.jsx(Ol,{className:"h-4 w-4 fill-current"})})}),t]}));cc.displayName=tn.displayName;const la=c.forwardRef(({className:s,inset:t,...a},n)=>e.jsx(an,{ref:n,className:v("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",s),...a}));la.displayName=an.displayName;const et=c.forwardRef(({className:s,...t},a)=>e.jsx(nn,{ref:a,className:v("-mx-1 my-1 h-px bg-muted",s),...t}));et.displayName=nn.displayName;const Yt=({className:s,...t})=>e.jsx("span",{className:v("ml-auto text-xs tracking-widest opacity-60",s),...t});Yt.displayName="DropdownMenuShortcut";const le=Hl,se=Kl,te=ql,ee=c.forwardRef(({className:s,sideOffset:t=4,...a},n)=>e.jsx(rn,{ref:n,sideOffset:t,className:v("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}));ee.displayName=rn.displayName;function Vt(){const{pathname:s}=Zt();return{checkActiveNav:a=>{if(a==="/"&&s==="/")return!0;const n=a.replace(/^\//,""),l=s.replace(/^\//,"");return n?l.startsWith(n):!1}}}function ir({key:s,defaultValue:t}){const[a,n]=c.useState(()=>{const l=localStorage.getItem(s);return l!==null?JSON.parse(l):t});return c.useEffect(()=>{localStorage.setItem(s,JSON.stringify(a))},[a,s]),[a,n]}function dc(){const[s,t]=ir({key:"expanded-sidebar-items",defaultValue:["仪表盘","系统管理","节点管理","订阅管理","用户管理"]});return{expandedItems:s,toggleItem:n=>{t(l=>l.includes(n)?l.filter(o=>o!==n):[...l,n])},isExpanded:n=>s.includes(n)}}function uc({links:s,isCollapsed:t,className:a,closeNav:n}){const l=({sub:o,...d})=>{const x=`${d.title}-${d.href}`;return t&&o?c.createElement(hc,{...d,sub:o,key:x,closeNav:n}):t?c.createElement(mc,{...d,key:x,closeNav:n}):o?c.createElement(xc,{...d,sub:o,key:x,closeNav:n}):c.createElement(or,{...d,key:x,closeNav:n})};return e.jsx("div",{"data-collapsed":t,className:v("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(le,{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(l)})})})}function or({title:s,icon:t,label:a,href:n,closeNav:l,subLink:o=!1}){const{checkActiveNav:d}=Vt();return e.jsxs(Ts,{to:n,onClick:l,className:v(As({variant:d(n)?"secondary":"ghost",size:"sm"}),"h-12 justify-start text-wrap rounded-none px-6",o&&"h-10 w-full border-l border-l-slate-500 px-2"),"aria-current":d(n)?"page":void 0,children:[e.jsx("div",{className:"mr-2",children:t}),s,a&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:a})]})}function xc({title:s,icon:t,label:a,sub:n,closeNav:l}){const{checkActiveNav:o}=Vt(),{isExpanded:d,toggleItem:x}=dc(),r=!!n?.find(h=>o(h.href)),i=d(s)||r;return e.jsxs(nr,{open:i,onOpenChange:()=>x(s),children:[e.jsxs(rr,{className:v(As({variant:"ghost",size:"sm"}),"group h-12 w-full justify-start rounded-none px-6"),children:[e.jsx("div",{className:"mr-2",children:t}),s,a&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:a}),e.jsx("span",{className:v('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(ln,{stroke:1})})]}),e.jsx(lr,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:n.map(h=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(or,{...h,subLink:!0,closeNav:l})},h.title))})})]})}function mc({title:s,icon:t,label:a,href:n}){const{checkActiveNav:l}=Vt();return e.jsxs(se,{delayDuration:0,children:[e.jsx(te,{asChild:!0,children:e.jsxs(Ts,{to:n,className:v(As({variant:l(n)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[t,e.jsx("span",{className:"sr-only",children:s})]})}),e.jsxs(ee,{side:"right",className:"flex items-center gap-4",children:[s,a&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:a})]})]})}function hc({title:s,icon:t,label:a,sub:n}){const{checkActiveNav:l}=Vt(),o=!!n?.find(d=>l(d.href));return e.jsxs(_s,{children:[e.jsxs(se,{delayDuration:0,children:[e.jsx(te,{asChild:!0,children:e.jsx(Cs,{asChild:!0,children:e.jsx(T,{variant:o?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:t})})}),e.jsxs(ee,{side:"right",className:"flex items-center gap-4",children:[s," ",a&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:a}),e.jsx(ln,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(fs,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(la,{children:[s," ",a?`(${a})`:""]}),e.jsx(et,{}),n.map(({title:d,icon:x,label:r,href:i})=>e.jsx(me,{asChild:!0,children:e.jsxs(Ts,{to:i,className:`${l(i)?"bg-secondary":""}`,children:[x," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:d}),r&&e.jsx("span",{className:"ml-auto text-xs",children:r})]})},`${d}-${i}`))]})]})}const cr=[{title:"仪表盘",label:"",href:"/",icon:e.jsx(Ul,{size:18})},{title:"系统管理",label:"",href:"",icon:e.jsx(Bl,{size:18}),sub:[{title:"系统配置",label:"",href:"/config/system",icon:e.jsx(on,{size:18})},{title:"主题配置",label:"",href:"/config/theme",icon:e.jsx(Gl,{size:18})},{title:"公告管理",label:"",href:"/config/notice",icon:e.jsx(Yl,{size:18})},{title:"支付配置",label:"",href:"/config/payment",icon:e.jsx(wa,{size:18})},{title:"知识库管理",label:"",href:"/config/knowledge",icon:e.jsx(Wl,{size:18})}]},{title:"节点管理",label:"",href:"",icon:e.jsx(cn,{size:18}),sub:[{title:"节点管理",label:"",href:"/server/manage",icon:e.jsx(Jl,{size:18})},{title:"权限组管理",label:"",href:"/server/group",icon:e.jsx(dn,{size:18})},{title:"路由管理",label:"",href:"/server/route",icon:e.jsx(Ql,{size:18})}]},{title:"订阅管理",label:"",href:"",icon:e.jsx(Zl,{size:18}),sub:[{title:"套餐管理",label:"",href:"/finance/plan",icon:e.jsx(Xl,{size:18})},{title:"订单管理",label:"",href:"/finance/order",icon:e.jsx(wa,{size:18})},{title:"优惠券管理",label:"",href:"/finance/coupon",icon:e.jsx(ei,{size:18})}]},{title:"用户管理",label:"",href:"",icon:e.jsx(si,{size:18}),sub:[{title:"用户管理",label:"",href:"/user/manage",icon:e.jsx(ti,{size:18})},{title:"工单管理",label:"",href:"/user/ticket",icon:e.jsx(un,{size:18})}]}];function jc({className:s,isCollapsed:t,setIsCollapsed:a}){const[n,l]=c.useState(!1);return c.useEffect(()=>{n?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[n]),e.jsxs("aside",{className:v(`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 ${t?"md:w-14":"md:w-64"}`,s),children:[e.jsx("div",{onClick:()=>l(!1),className:`absolute inset-0 transition-[opacity] delay-100 duration-700 ${n?"h-svh opacity-50":"h-0 opacity-0"} w-full bg-black md:hidden`}),e.jsxs(ye,{children:[e.jsxs(Ne,{className:"sticky top-0 justify-between px-4 py-3 shadow md:px-4",children:[e.jsxs("div",{className:`flex items-center ${t?"":"gap-2"}`,children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",className:`transition-all ${t?"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 ${t?"invisible w-0":"visible w-auto"}`,children:e.jsx("span",{className:"font-medium",children:window?.settings?.title})})]}),e.jsx(T,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":"Toggle Navigation","aria-controls":"sidebar-menu","aria-expanded":n,onClick:()=>l(o=>!o),children:n?e.jsx(ai,{}):e.jsx(ni,{})})]}),e.jsx(uc,{id:"sidebar-menu",className:`h-full flex-1 overflow-auto ${n?"max-h-screen":"max-h-0 py-0 md:max-h-screen md:py-2"}`,closeNav:()=>l(!1),isCollapsed:t,links:cr}),e.jsx(T,{onClick:()=>a(o=>!o),size:"icon",variant:"outline",className:"absolute -right-5 top-1/2 hidden rounded-full md:inline-flex",children:e.jsx(ri,{stroke:1.5,className:`h-5 w-5 ${t?"rotate-180":""}`})})]})]})}function gc(){const[s,t]=ir({key:"collapsed-sidebar",defaultValue:!1});return c.useEffect(()=>{const a=()=>{t(window.innerWidth<768?!1:s)};return a(),window.addEventListener("resize",a),()=>{window.removeEventListener("resize",a)}},[s,t]),[s,t]}function fc(){const[s,t]=gc();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(jc,{isCollapsed:s,setIsCollapsed:t}),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(Xt,{})})]})}const pc=Object.freeze(Object.defineProperty({__proto__:null,default:fc},Symbol.toStringTag,{value:"Module"})),ps=c.forwardRef(({className:s,...t},a)=>e.jsx(we,{ref:a,className:v("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...t}));ps.displayName=we.displayName;const vc=({children:s,...t})=>e.jsx(ue,{...t,children:e.jsx(ce,{className:"overflow-hidden p-0",children:e.jsx(ps,{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})})}),Ps=c.forwardRef(({className:s,...t},a)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(li,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(we.Input,{ref:a,className:v("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),...t})]}));Ps.displayName=we.Input.displayName;const vs=c.forwardRef(({className:s,...t},a)=>e.jsx(we.List,{ref:a,className:v("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...t}));vs.displayName=we.List.displayName;const Vs=c.forwardRef((s,t)=>e.jsx(we.Empty,{ref:t,className:"py-6 text-center text-sm",...s}));Vs.displayName=we.Empty.displayName;const Ve=c.forwardRef(({className:s,...t},a)=>e.jsx(we.Group,{ref:a,className:v("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),...t}));Ve.displayName=we.Group.displayName;const Hs=c.forwardRef(({className:s,...t},a)=>e.jsx(we.Separator,{ref:a,className:v("-mx-1 h-px bg-border",s),...t}));Hs.displayName=we.Separator.displayName;const be=c.forwardRef(({className:s,...t},a)=>e.jsx(we.Item,{ref:a,className:v("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),...t}));be.displayName=we.Item.displayName;function bc(){const s=[];for(const t of cr)if(t.href&&s.push(t),t.sub)for(const a of t.sub)s.push({...a,parent:t.title});return s}function ke(){const[s,t]=c.useState(!1),a=ns(),n=bc();c.useEffect(()=>{const o=d=>{d.key==="k"&&(d.metaKey||d.ctrlKey)&&(d.preventDefault(),t(x=>!x))};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[]);const l=c.useCallback(o=>{t(!1),a(o)},[a]);return e.jsxs(e.Fragment,{children:[e.jsxs(W,{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:()=>t(!0),children:[e.jsx(ii,{className:"h-4 w-4 xl:mr-2"}),e.jsx("span",{className:"hidden xl:inline-flex",children:"搜索..."}),e.jsx("span",{className:"sr-only",children:"搜索"}),e.jsxs("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:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsxs(vc,{open:s,onOpenChange:t,children:[e.jsx(Ps,{placeholder:"搜索所有菜单和功能..."}),e.jsxs(vs,{children:[e.jsx(Vs,{children:"未找到相关结果"}),e.jsx(Ve,{heading:"菜单导航",children:n.map(o=>e.jsxs(be,{value:`${o.parent?o.parent+" ":""}${o.title}`,onSelect:()=>l(o.href),children:[e.jsx("div",{className:"mr-2",children:o.icon}),e.jsx("span",{children:o.title}),o.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:o.parent})]},o.href))})]})]})]})}function Te(){const{theme:s,setTheme:t}=Co();return c.useEffect(()=>{const a=s==="dark"?"#020817":"#fff",n=document.querySelector("meta[name='theme-color']");n&&n.setAttribute("content",a)},[s]),e.jsx(T,{size:"icon",variant:"ghost",className:"rounded-full",onClick:()=>t(s==="light"?"dark":"light"),children:s==="light"?e.jsx(oi,{size:20}):e.jsx(ci,{size:20})})}const dr=c.forwardRef(({className:s,...t},a)=>e.jsx(xn,{ref:a,className:v("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...t}));dr.displayName=xn.displayName;const ur=c.forwardRef(({className:s,...t},a)=>e.jsx(mn,{ref:a,className:v("aspect-square h-full w-full",s),...t}));ur.displayName=mn.displayName;const xr=c.forwardRef(({className:s,...t},a)=>e.jsx(hn,{ref:a,className:v("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...t}));xr.displayName=hn.displayName;function De(){const s=ns(),t=Ba(),a=di(Uo),n=()=>{Jn(),t(qo()),s("/sign-in")},l=a?.email?.split("@")[0]||"User",o=l.substring(0,2).toUpperCase();return e.jsxs(_s,{children:[e.jsx(Cs,{asChild:!0,children:e.jsx(T,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(dr,{className:"h-8 w-8",children:[e.jsx(ur,{src:a?.avatar_url,alt:l}),e.jsx(xr,{children:o})]})})}),e.jsxs(fs,{className:"w-56",align:"end",forceMount:!0,children:[e.jsx(la,{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:l}),e.jsx("p",{className:"text-xs leading-none text-muted-foreground",children:a?.email||"user@example.com"})]})}),e.jsx(et,{}),e.jsx(me,{asChild:!0,children:e.jsxs(Ts,{to:"/config/system",children:["设置",e.jsx(Yt,{children:"⌘S"})]})}),e.jsx(et,{}),e.jsxs(me,{onClick:n,children:["退出登录",e.jsx(Yt,{children:"⇧⌘Q"})]})]})]})}const Ge=window?.settings?.secure_path,mr=5*60*1e3,Wt=new Map,yc=s=>{const t=Wt.get(s);return t?Date.now()-t.timestamp>mr?(Wt.delete(s),null):t.data:null},Nc=(s,t)=>{Wt.set(s,{data:t,timestamp:Date.now()})},wc=async(s,t=mr)=>{const a=yc(s);if(a)return a;const n=await I.get(s);return Nc(s,n),n},_c={getList:()=>wc(`${Ge}/notice/fetch`),save:s=>I.post(`${Ge}/notice/save`,s),drop:s=>I.post(`${Ge}/notice/drop`,{id:s}),updateStatus:s=>I.post(`${Ge}/notice/show`,{id:s}),sort:s=>I.post(`${Ge}/notice/sort`,{ids:s})},Fa={getSystemStatus:()=>I.get(`${Ge}/system/getSystemStatus`),getQueueStats:()=>I.get(`${Ge}/system/getQueueStats`),getQueueWorkload:()=>I.get(`${Ge}/system/getQueueWorkload`),getQueueMasters:()=>I.get(`${Ge}/system/getQueueMasters`),getSystemLog:s=>I.get(`${Ge}/system/getSystemLog`,{params:s})},M=window?.settings?.secure_path,Cc=s=>I.get(M+"/stat/getOrder",{params:s}),Sc=()=>I.get(M+"/stat/getStats"),Ma=s=>I.get(M+"/stat/getTrafficRank",{params:s}),kc=()=>I.get(M+"/theme/getThemes"),Tc=s=>I.post(M+"/theme/getThemeConfig",{name:s}),Dc=(s,t)=>I.post(M+"/theme/saveThemeConfig",{name:s,config:t}),Pc=s=>{const t=new FormData;return t.append("file",s),I.post(M+"/theme/upload",t,{headers:{"Content-Type":"multipart/form-data"}})},Vc=s=>I.post(M+"/theme/delete",{name:s}),Ic=s=>I.post(M+"/config/save",s),hr=()=>I.get(M+"/server/manage/getNodes"),Rc=s=>I.post(M+"/server/manage/save",s),Ec=s=>I.post(M+"/server/manage/drop",s),Fc=s=>I.post(M+"/server/manage/copy",s),Mc=s=>I.post(M+"/server/manage/update",s),zc=s=>I.post(M+"/server/manage/sort",s),It=()=>I.get(M+"/server/group/fetch"),Oc=s=>I.post(M+"/server/group/save",s),Lc=s=>I.post(M+"/server/group/drop",s),jr=()=>I.get(M+"/server/route/fetch"),$c=s=>I.post(M+"/server/route/save",s),Ac=s=>I.post(M+"/server/route/drop",s),Hc=()=>I.get(M+"/payment/fetch"),Kc=()=>I.get(M+"/payment/getPaymentMethods"),qc=s=>I.post(M+"/payment/getPaymentForm",s),Uc=s=>I.post(M+"/payment/save",s),Bc=s=>I.post(M+"/payment/drop",s),Gc=s=>I.post(M+"/payment/show",s),Yc=s=>I.post(M+"/payment/sort",s),Wc=()=>I.get(M+"/notice/fetch"),Jc=s=>I.post(M+"/notice/save",s),Qc=s=>I.post(M+"/notice/drop",s),Zc=s=>I.post(M+"/notice/show",s),Xc=()=>I.get(M+"/knowledge/fetch"),ed=s=>I.get(M+"/knowledge/fetch?id="+s),sd=s=>I.post(M+"/knowledge/save",s),td=s=>I.post(M+"/knowledge/drop",s),ad=s=>I.post(M+"/knowledge/show",s),nd=s=>I.post(M+"/knowledge/sort",s),Is=()=>I.get(M+"/plan/fetch"),rd=s=>I.post(M+"/plan/save",s),zt=s=>I.post(M+"/plan/update",s),ld=s=>I.post(M+"/plan/drop",s),id=s=>I.post(M+"/plan/sort",{ids:s}),od=async s=>I.post(M+"/order/fetch",s),cd=s=>I.post(M+"/order/detail",s),dd=s=>I.post(M+"/order/paid",s),ud=s=>I.post(M+"/order/cancel",s),za=s=>I.post(M+"/order/update",s),xd=s=>I.post(M+"/order/assign",s),md=s=>I.post(M+"/coupon/fetch",s),hd=s=>I.post(M+"/coupon/generate",s),jd=s=>I.post(M+"/coupon/drop",s),gd=s=>I.post(M+"/coupon/update",s),fd=s=>I.post(M+"/user/fetch",s),pd=s=>I.post(M+"/user/update",s),vd=s=>I.post(M+"/user/resetSecret",s),bd=s=>I.post(M+"/user/generate",s),yd=s=>I.post(M+"/stat/getStatUser",s),Nd=s=>I.post(M+"/ticket/fetch",s),wd=s=>I.get(M+"/ticket/fetch?id= "+s),_d=s=>I.post(M+"/ticket/reply",s),gr=s=>I.post(M+"/ticket/close",{id:s}),os=(s="")=>I.get(M+"/config/fetch?key="+s),cs=s=>I.post(M+"/config/save",s),Cd=()=>I.get(M+"/config/getEmailTemplate"),Sd=()=>I.post(M+"/config/testSendMail"),kd=()=>I.post(M+"/config/setTelegramWebhook"),Td=_c.sort,fr=ui,ia=c.forwardRef(({className:s,...t},a)=>e.jsx(jn,{ref:a,className:v("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...t}));ia.displayName=jn.displayName;const st=c.forwardRef(({className:s,...t},a)=>e.jsx(gn,{ref:a,className:v("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),...t}));st.displayName=gn.displayName;const Dd=c.forwardRef(({className:s,...t},a)=>e.jsx(fn,{ref:a,className:v("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...t}));Dd.displayName=fn.displayName;const G=xi,xs=bi,Y=mi,U=c.forwardRef(({className:s,children:t,...a},n)=>e.jsxs(pn,{ref:n,className:v("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:[t,e.jsx(hi,{asChild:!0,children:e.jsx(ta,{className:"h-4 w-4 opacity-50"})})]}));U.displayName=pn.displayName;const pr=c.forwardRef(({className:s,...t},a)=>e.jsx(vn,{ref:a,className:v("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(ji,{className:"h-4 w-4"})}));pr.displayName=vn.displayName;const vr=c.forwardRef(({className:s,...t},a)=>e.jsx(bn,{ref:a,className:v("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(ta,{className:"h-4 w-4"})}));vr.displayName=bn.displayName;const B=c.forwardRef(({className:s,children:t,position:a="popper",...n},l)=>e.jsx(gi,{children:e.jsxs(yn,{ref:l,className:v("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,...n,children:[e.jsx(pr,{}),e.jsx(fi,{className:v("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),e.jsx(vr,{})]})}));B.displayName=yn.displayName;const Pd=c.forwardRef(({className:s,...t},a)=>e.jsx(Nn,{ref:a,className:v("px-2 py-1.5 text-sm font-semibold",s),...t}));Pd.displayName=Nn.displayName;const O=c.forwardRef(({className:s,children:t,...a},n)=>e.jsxs(wn,{ref:n,className:v("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(pi,{children:e.jsx(ks,{className:"h-4 w-4"})})}),e.jsx(vi,{children:t})]}));O.displayName=wn.displayName;const Vd=c.forwardRef(({className:s,...t},a)=>e.jsx(_n,{ref:a,className:v("-mx-1 my-1 h-px bg-muted",s),...t}));Vd.displayName=_n.displayName;function Rs({className:s,classNames:t,showOutsideDays:a=!0,...n}){return e.jsx(yi,{showOutsideDays:a,className:v("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:v($s({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:v("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",n.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:v($s({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",...t},components:{IconLeft:({className:l,...o})=>e.jsx(Cn,{className:v("h-4 w-4",l),...o}),IconRight:({className:l,...o})=>e.jsx(sa,{className:v("h-4 w-4",l),...o})},...n})}Rs.displayName="Calendar";const Ze=wi,Xe=_i,qe=c.forwardRef(({className:s,align:t="center",sideOffset:a=4,...n},l)=>e.jsx(Ni,{children:e.jsx(Sn,{ref:l,align:t,sideOffset:a,className:v("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),...n})}));qe.displayName=Sn.displayName;const ms={income:{main:"hsl(var(--primary))",gradient:{start:"hsl(var(--primary))",end:"transparent"}},commission:{main:"hsl(var(--secondary))",gradient:{start:"hsl(var(--secondary))",end:"transparent"}}},Ws=s=>(s/100).toFixed(2),Id=({active:s,payload:t,label:a})=>s&&t&&t.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}),t.map((n,l)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"h-2 w-2 rounded-full",style:{backgroundColor:n.color}}),e.jsxs("span",{className:"text-muted-foreground",children:[n.name,":"]}),e.jsx("span",{className:"font-medium",children:n.name.includes("金额")?`¥${Ws(n.value)}`:`${n.value}`})]},l))]}):null,Rd=[{value:"7d",label:"最近7天"},{value:"30d",label:"最近30天"},{value:"90d",label:"最近90天"},{value:"180d",label:"最近180天"},{value:"365d",label:"最近一年"},{value:"custom",label:"自定义范围"}],Ed=(s,t)=>{const a=new Date;if(s==="custom"&&t)return{startDate:t.from,endDate:t.to};let n;switch(s){case"7d":n=Le(a,7);break;case"30d":n=Le(a,30);break;case"90d":n=Le(a,90);break;case"180d":n=Le(a,180);break;case"365d":n=Le(a,365);break;default:n=Le(a,30)}return{startDate:n,endDate:a}};function Fd(){const[s,t]=c.useState("amount"),[a,n]=c.useState("30d"),[l,o]=c.useState({from:Le(new Date,7),to:new Date}),{startDate:d,endDate:x}=Ed(a,l),{data:r}=Q({queryKey:["orderStat",{start_date:Pe(d,"yyyy-MM-dd"),end_date:Pe(x,"yyyy-MM-dd")}],queryFn:async()=>{const{data:i}=await Cc({start_date:Pe(d,"yyyy-MM-dd"),end_date:Pe(x,"yyyy-MM-dd")});return i},refetchInterval:3e4});return e.jsxs($e,{children:[e.jsxs(Je,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(gs,{children:"收入趋势"}),e.jsx(Xs,{children:`${r?.summary.start_date||""}${r?.summary.end_date||""}`})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsxs(G,{value:a,onValueChange:i=>n(i),children:[e.jsx(U,{className:"w-[120px]",children:e.jsx(Y,{placeholder:"选择时间范围"})}),e.jsx(B,{children:Rd.map(i=>e.jsx(O,{value:i.value,children:i.label},i.value))})]}),a==="custom"&&e.jsxs(Ze,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(W,{variant:"outline",className:v("min-w-0 justify-start text-left font-normal",!l&&"text-muted-foreground"),children:[e.jsx(lt,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:l?.from?l.to?e.jsxs(e.Fragment,{children:[Pe(l.from,"yyyy-MM-dd")," -"," ",Pe(l.to,"yyyy-MM-dd")]}):Pe(l.from,"yyyy-MM-dd"):e.jsx("span",{children:"选择日期范围"})})]})}),e.jsx(qe,{className:"w-auto p-0",align:"end",children:e.jsx(Rs,{mode:"range",defaultMonth:l?.from,selected:{from:l?.from,to:l?.to},onSelect:i=>{i?.from&&i?.to&&o({from:i.from,to:i.to})},numberOfMonths:2})})]})]}),e.jsx(fr,{value:s,onValueChange:i=>t(i),children:e.jsxs(ia,{children:[e.jsx(st,{value:"amount",children:"金额"}),e.jsx(st,{value:"count",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:"总收入"}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",Ws(r?.summary?.paid_total||0)]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["共 ",r?.summary?.paid_count||0," 笔"]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["平均订单金额 ¥",Ws(r?.summary?.avg_paid_amount||0)]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"总佣金"}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",Ws(r?.summary?.commission_total||0)]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["共 ",r?.summary?.commission_count||0," 笔"]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["佣金比率 ",r?.summary?.commission_rate.toFixed(2)||0,"%"]})]})]})]}),e.jsx(Qe,{children:e.jsx("div",{className:"h-[400px] w-full",children:e.jsx(Ci,{width:"100%",height:"100%",children:e.jsxs(Si,{data:r?.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:ms.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:ms.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:ms.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:ms.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(ki,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:i=>Pe(new Date(i),"MM-dd",{locale:Vi})}),e.jsx(Ti,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:i=>s==="amount"?`¥${Ws(i)}`:`${i}`}),e.jsx(Di,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(Pi,{content:e.jsx(Id,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(_a,{type:"monotone",dataKey:"paid_total",name:"收款金额",stroke:ms.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(_a,{type:"monotone",dataKey:"commission_total",name:"佣金金额",stroke:ms.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ca,{dataKey:"paid_count",name:"收款笔数",fill:ms.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(Ca,{dataKey:"commission_count",name:"佣金笔数",fill:ms.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})})]})}function Ee({className:s,...t}){return e.jsx("div",{className:v("animate-pulse rounded-md bg-primary/10",s),...t})}function Md(){return e.jsxs($e,{children:[e.jsxs(Je,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ee,{className:"h-4 w-[100px]"}),e.jsx(Ee,{className:"h-4 w-4"})]}),e.jsxs(Qe,{children:[e.jsx(Ee,{className:"h-8 w-[120px]"}),e.jsx("div",{className:"flex items-center pt-1",children:e.jsx(Ee,{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:4}).map((s,t)=>e.jsx(Md,{},t))})}var ge=(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))(ge||{});const Ms={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},Gs={0:"yellow-500",1:"blue-500",2:"red-500",3:"green-500",4:"green-500"};var as=(s=>(s[s.NEW=1]="NEW",s[s.RENEWAL=2]="RENEWAL",s[s.UPGRADE=3]="UPGRADE",s[s.RESET_FLOW=4]="RESET_FLOW",s))(as||{});const br={1:"新购",2:"续费",3:"升级",4:"流量重置"};var pe=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(pe||{});const dt={0:"待确认",1:"发放中",2:"有效",3:"无效"},ut={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var ne=(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))(ne||{});const tt={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var fe=(s=>(s.Shadowsocks="shadowsocks",s.Vmess="vmess",s.Trojan="trojan",s.Hysteria="hysteria",s.Vless="vless",s))(fe||{});const ws=[{type:"shadowsocks",label:"Shadowsocks"},{type:"vmess",label:"VMess"},{type:"trojan",label:"Trojan"},{type:"hysteria",label:"Hysteria"},{type:"vless",label:"VLess"}],ts={shadowsocks:"#489851",vmess:"#CB3180",trojan:"#EBB749",hysteria:"#5684e6",vless:"#1a1a1a"};var Rt=(s=>(s[s.AMOUNT=1]="AMOUNT",s[s.PERCENTAGE=2]="PERCENTAGE",s))(Rt||{});const oa={1:"按金额优惠",2:"按比例优惠"},Od={0:"正常",1:"锁定"};var Os=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(Os||{});const Ld={0:"开启",1:"已关闭"};var ss=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(ss||{});const Qs={0:"低",1:"中",2:"高"};function hs({title:s,value:t,icon:a,trend:n,description:l,onClick:o,highlight:d,className:x}){return e.jsxs($e,{className:v("transition-colors",o&&"cursor-pointer hover:bg-muted/50",d&&"border-primary/50",x),onClick:o,children:[e.jsxs(Je,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(gs,{className:"text-sm font-medium",children:s}),a]}),e.jsxs(Qe,{children:[e.jsx("div",{className:"text-2xl font-bold",children:t}),n?e.jsxs("div",{className:"flex items-center pt-1",children:[e.jsx(zi,{className:v("h-4 w-4",n.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:v("ml-1 text-xs",n.isPositive?"text-emerald-500":"text-red-500"),children:[n.isPositive?"+":"-",Math.abs(n.value),"%"]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:n.label})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:l})]})]})}function $d({className:s}){const t=ns(),{data:a,isLoading:n}=Q({queryKey:["dashboardStats"],queryFn:async()=>(await Sc()).data,refetchInterval:1e3*60*5});if(n||!a)return e.jsx(zd,{});const l=()=>{const o=new URLSearchParams;o.set("commission_status",pe.PENDING.toString()),o.set("status",ge.COMPLETED.toString()),o.set("commission_balance","gt:0"),t(`/finance/order?${o.toString()}`)};return e.jsxs("div",{className:v("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(hs,{title:"今日收入",value:Ns(a.todayIncome),icon:e.jsx(Ii,{className:"h-4 w-4 text-emerald-500"}),trend:{value:a.dayIncomeGrowth,label:"vs 昨日",isPositive:a.dayIncomeGrowth>0}}),e.jsx(hs,{title:"本月收入",value:Ns(a.currentMonthIncome),icon:e.jsx(Ri,{className:"h-4 w-4 text-blue-500"}),trend:{value:a.monthIncomeGrowth,label:"vs 上月",isPositive:a.monthIncomeGrowth>0}}),e.jsx(hs,{title:"待处理工单",value:a.ticketPendingTotal,icon:e.jsx(Ei,{className:v("h-4 w-4",a.ticketPendingTotal>0?"text-orange-500":"text-muted-foreground")}),description:a.ticketPendingTotal>0?"有待处理的工单需要关注":"暂无待处理工单",onClick:()=>t("/user/ticket"),highlight:a.ticketPendingTotal>0}),e.jsx(hs,{title:"待处理佣金",value:a.commissionPendingTotal,icon:e.jsx(Fi,{className:v("h-4 w-4",a.commissionPendingTotal>0?"text-blue-500":"text-muted-foreground")}),description:a.commissionPendingTotal>0?"有待处理的佣金需要确认":"暂无待处理佣金",onClick:l,highlight:a.commissionPendingTotal>0}),e.jsx(hs,{title:"本月新增用户",value:a.currentMonthNewUsers,icon:e.jsx(At,{className:"h-4 w-4 text-blue-500"}),trend:{value:a.userGrowth,label:"vs 上月",isPositive:a.userGrowth>0}}),e.jsx(hs,{title:"总用户数",value:a.totalUsers,icon:e.jsx(At,{className:"h-4 w-4 text-muted-foreground"}),description:`有效用户: ${a.activeUsers}`}),e.jsx(hs,{title:"本月上行流量",value:Ye(a.monthTraffic.upload),icon:e.jsx(Ht,{className:"h-4 w-4 text-emerald-500"}),description:`今日: ${Ye(a.todayTraffic.upload)}`}),e.jsx(hs,{title:"本月下行流量",value:Ye(a.monthTraffic.download),icon:e.jsx(Mi,{className:"h-4 w-4 text-blue-500"}),description:`今日: ${Ye(a.todayTraffic.download)}`})]})}const at=c.forwardRef(({className:s,children:t,...a},n)=>e.jsxs(kn,{ref:n,className:v("relative overflow-hidden",s),...a,children:[e.jsx(Oi,{className:"h-full w-full rounded-[inherit]",children:t}),e.jsx(wt,{}),e.jsx(Li,{})]}));at.displayName=kn.displayName;const wt=c.forwardRef(({className:s,orientation:t="vertical",...a},n)=>e.jsx(Tn,{ref:n,orientation:t,className:v("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",s),...a,children:e.jsx($i,{className:"relative flex-1 rounded-full bg-border"})}));wt.displayName=Tn.displayName;const Jt={today:{label:"今天",getValue:()=>{const s=Hi();return{start:s,end:Ki(s,1)}}},last7days:{label:"最近7天",getValue:()=>{const s=new Date;return{start:Le(s,7),end:s}}},last30days:{label:"最近30天",getValue:()=>{const s=new Date;return{start:Le(s,30),end:s}}},custom:{label:"自定义范围",getValue:()=>null}};function Oa({selectedRange:s,customDateRange:t,onRangeChange:a,onCustomRangeChange:n}){return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsxs(G,{value:s,onValueChange:a,children:[e.jsx(U,{className:"w-[120px]",children:e.jsx(Y,{placeholder:"选择时间范围"})}),e.jsx(B,{position:"popper",className:"z-50",children:Object.entries(Jt).map(([l,{label:o}])=>e.jsx(O,{value:l,children:o},l))})]}),s==="custom"&&e.jsxs(Ze,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(W,{variant:"outline",className:v("min-w-0 justify-start text-left font-normal",!t&&"text-muted-foreground"),children:[e.jsx(lt,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t?.from?t.to?e.jsxs(e.Fragment,{children:[Pe(t.from,"yyyy-MM-dd")," -"," ",Pe(t.to,"yyyy-MM-dd")]}):Pe(t.from,"yyyy-MM-dd"):e.jsx("span",{children:"选择日期范围"})})]})}),e.jsx(qe,{className:"w-auto p-0",align:"end",children:e.jsx(Rs,{mode:"range",defaultMonth:t?.from,selected:{from:t?.from,to:t?.to},onSelect:l=>{l?.from&&l?.to&&n({from:l.from,to:l.to})},numberOfMonths:2})})]})]})}const Fs=s=>`${(s/1024/1024/1024).toFixed(2)} GB`;function Ad({className:s}){const[t,a]=c.useState("today"),[n,l]=c.useState({from:Le(new Date,7),to:new Date}),[o,d]=c.useState("today"),[x,r]=c.useState({from:Le(new Date,7),to:new Date}),i=c.useMemo(()=>t==="custom"?{start:n.from,end:n.to}:Jt[t].getValue(),[t,n]),h=c.useMemo(()=>o==="custom"?{start:x.from,end:x.to}:Jt[o].getValue(),[o,x]),{data:D}=Q({queryKey:["nodeTrafficRank",i.start,i.end],queryFn:()=>Ma({type:"node",start_time:de.round(i.start.getTime()/1e3),end_time:de.round(i.end.getTime()/1e3)}),refetchInterval:3e4}),{data:C}=Q({queryKey:["userTrafficRank",h.start,h.end],queryFn:()=>Ma({type:"user",start_time:de.round(h.start.getTime()/1e3),end_time:de.round(h.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:v("grid gap-4 md:grid-cols-2",s),children:[e.jsxs($e,{children:[e.jsx(Je,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(gs,{className:"flex items-center text-base font-medium",children:[e.jsx(Ai,{className:"mr-2 h-4 w-4"}),"节点流量排行"]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx(Oa,{selectedRange:t,customDateRange:n,onRangeChange:a,onCustomRangeChange:l}),e.jsx(Sa,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Qe,{className:"flex-1",children:D?.data?e.jsxs(at,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:D.data.map(m=>e.jsx(le,{children:e.jsxs(se,{children:[e.jsx(te,{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:m.name}),e.jsxs("span",{className:v("ml-2 flex items-center text-xs font-medium",m.change>=0?"text-green-600":"text-red-600"),children:[m.change>=0?e.jsx(Kt,{className:"mr-1 h-3 w-3"}):e.jsx(qt,{className:"mr-1 h-3 w-3"}),Math.abs(m.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:`${m.value/D.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Fs(m.value)})]})]})})}),e.jsx(ee,{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.jsx("span",{className:"text-muted-foreground",children:"当前流量:"}),e.jsx("span",{className:"font-medium",children:Fs(m.value)}),e.jsx("span",{className:"text-muted-foreground",children:"上期流量:"}),e.jsx("span",{className:"font-medium",children:Fs(m.previousValue)}),e.jsx("span",{className:"text-muted-foreground",children:"变化率:"}),e.jsxs("span",{className:v("font-medium",m.change>=0?"text-green-600":"text-red-600"),children:[m.change>=0?"+":"",m.change,"%"]}),e.jsx("span",{className:"text-muted-foreground",children:"记录时间:"}),e.jsx("span",{className:"font-medium",children:Pe(new Date(m.timestamp),"yyyy-MM-dd HH:mm")})]})})]})},m.id))}),e.jsx(wt,{orientation:"vertical"})]}):e.jsx("div",{className:"flex h-[400px] items-center justify-center",children:e.jsx("div",{className:"animate-pulse",children:"Loading..."})})})]}),e.jsxs($e,{children:[e.jsx(Je,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(gs,{className:"flex items-center text-base font-medium",children:[e.jsx(At,{className:"mr-2 h-4 w-4"}),"用户流量排行"]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx(Oa,{selectedRange:o,customDateRange:x,onRangeChange:d,onCustomRangeChange:r}),e.jsx(Sa,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Qe,{className:"flex-1",children:C?.data?e.jsxs(at,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:C.data.map(m=>e.jsx(le,{children:e.jsxs(se,{children:[e.jsx(te,{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:m.name}),e.jsxs("span",{className:v("ml-2 flex items-center text-xs font-medium",m.change>=0?"text-green-600":"text-red-600"),children:[m.change>=0?e.jsx(Kt,{className:"mr-1 h-3 w-3"}):e.jsx(qt,{className:"mr-1 h-3 w-3"}),Math.abs(m.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:`${m.value/C.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Fs(m.value)})]})]})})}),e.jsx(ee,{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.jsx("span",{className:"text-muted-foreground",children:"当前流量:"}),e.jsx("span",{className:"font-medium",children:Fs(m.value)}),e.jsx("span",{className:"text-muted-foreground",children:"上期流量:"}),e.jsx("span",{className:"font-medium",children:Fs(m.previousValue)}),e.jsx("span",{className:"text-muted-foreground",children:"变化率:"}),e.jsxs("span",{className:v("font-medium",m.change>=0?"text-green-600":"text-red-600"),children:[m.change>=0?"+":"",m.change,"%"]}),e.jsx("span",{className:"text-muted-foreground",children:"记录时间:"}),e.jsx("span",{className:"font-medium",children:Pe(new Date(m.timestamp),"yyyy-MM-dd HH:mm")})]})})]})},m.id))}),e.jsx(wt,{orientation:"vertical"})]}):e.jsx("div",{className:"flex h-[400px] items-center justify-center",children:e.jsx("div",{className:"animate-pulse",children:"Loading..."})})})]})]})}const Hd=Ss("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 L({className:s,variant:t,...a}){return e.jsx("div",{className:v(Hd({variant:t}),s),...a})}const pt=c.forwardRef(({className:s,value:t,...a},n)=>e.jsx(Dn,{ref:n,className:v("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...a,children:e.jsx(qi,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(t||0)}%)`}})}));pt.displayName=Dn.displayName;function Kd(){const[s,t]=c.useState(null),[a,n]=c.useState(null),[l,o]=c.useState(!0),[d,x]=c.useState(!1),r=async()=>{try{x(!0);const[D,C]=await Promise.all([Fa.getSystemStatus(),Fa.getQueueStats()]);t(D.data),n(C.data)}catch(D){console.error("Error fetching system data:",D)}finally{o(!1),x(!1)}};c.useEffect(()=>{r();const D=setInterval(r,3e4);return()=>clearInterval(D)},[]);const i=()=>{r()};if(l)return e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx(aa,{className:"h-6 w-6 animate-spin"})});const h=D=>D?e.jsx(Pn,{className:"h-5 w-5 text-green-500"}):e.jsx(Vn,{className:"h-5 w-5 text-red-500"});return e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs($e,{children:[e.jsxs(Je,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(gs,{className:"flex items-center gap-2",children:[e.jsx(Ui,{className:"h-5 w-5"}),"队列状态"]}),e.jsx(Xs,{children:"当前队列运行状态"})]}),e.jsx(W,{variant:"outline",size:"icon",onClick:i,disabled:d,children:e.jsx(Bi,{className:v("h-4 w-4",d&&"animate-spin")})})]}),e.jsx(Qe,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[h(a?.status||!1),e.jsx("span",{className:"font-medium",children:"运行状态"})]}),e.jsx(L,{variant:a?.status?"secondary":"destructive",children:a?.status?"正常":"异常"})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前等待时间:",a?.wait?.default||0," 秒"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(le,{children:e.jsxs(se,{children:[e.jsx(te,{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:"近期任务数"}),e.jsx("p",{className:"text-2xl font-bold",children:a?.recentJobs||0}),e.jsx(pt,{value:(a?.recentJobs||0)/(a?.periods?.recentJobs||1)*100,className:"h-1"})]})}),e.jsx(ee,{children:e.jsxs("p",{children:["统计时间范围: ",a?.periods?.recentJobs||0," 小时"]})})]})}),e.jsx(le,{children:e.jsxs(se,{children:[e.jsx(te,{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:"每分钟处理量"}),e.jsx("p",{className:"text-2xl font-bold",children:a?.jobsPerMinute||0}),e.jsx(pt,{value:(a?.jobsPerMinute||0)/(a?.queueWithMaxThroughput?.throughput||1)*100,className:"h-1"})]})}),e.jsx(ee,{children:e.jsxs("p",{children:["最高吞吐量:"," ",a?.queueWithMaxThroughput?.throughput||0]})})]})})]})]})})]}),e.jsxs($e,{children:[e.jsxs(Je,{children:[e.jsxs(gs,{className:"flex items-center gap-2",children:[e.jsx(Gi,{className:"h-5 w-5"}),"作业详情"]}),e.jsx(Xs,{children:"队列处理详细信息"})]}),e.jsx(Qe,{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:"7日报错数量"}),e.jsx("p",{className:"text-2xl font-bold text-destructive",children:a?.failedJobs||0}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["保留 ",a?.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:"最长运行队列"}),e.jsxs("p",{className:"text-2xl font-bold",children:[a?.queueWithMaxRuntime?.runtime||0,"s"]}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:a?.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:"活跃进程"}),e.jsxs("span",{className:"font-medium",children:[a?.processes||0," /"," ",(a?.processes||0)+(a?.pausedMasters||0)]})]}),e.jsx(pt,{value:(a?.processes||0)/((a?.processes||0)+(a?.pausedMasters||0))*100,className:"mt-2 h-1"})]})]})})]})]})}function qd(){return e.jsxs(ye,{children:[e.jsxs(Ne,{children:[e.jsx("div",{className:"flex items-center",children:e.jsx("h1",{className:"text-2xl font-bold tracking-tight md:text-3xl",children:"仪表盘"})}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ke,{}),e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsx(_e,{children:e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsx($d,{}),e.jsx(Fd,{}),e.jsx(Ad,{}),e.jsx(Kd,{})]})})})]})}const Ud=Object.freeze(Object.defineProperty({__proto__:null,default:qd},Symbol.toStringTag,{value:"Module"})),je=c.forwardRef(({className:s,orientation:t="horizontal",decorative:a=!0,...n},l)=>e.jsx(In,{ref:l,decorative:a,orientation:t,className:v("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...n}));je.displayName=In.displayName;function Bd({className:s,items:t,...a}){const{pathname:n}=Zt(),l=ns(),[o,d]=c.useState(n??"/settings"),x=r=>{d(r),l(r)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-1 md:hidden",children:e.jsxs(G,{value:o,onValueChange:x,children:[e.jsx(U,{className:"h-12 sm:w-48",children:e.jsx(Y,{placeholder:"Theme"})}),e.jsx(B,{children:t.map(r=>e.jsx(O,{value:r.href,children:e.jsxs("div",{className:"flex gap-x-4 px-2 py-1",children:[e.jsx("span",{className:"scale-125",children:r.icon}),e.jsx("span",{className:"text-md",children:r.title})]})},r.href))})]})}),e.jsx("div",{className:"hidden w-full overflow-x-auto bg-background px-1 py-2 md:block",children:e.jsx("nav",{className:v("flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",s),...a,children:t.map(r=>e.jsxs(Ts,{to:r.href,className:v(As({variant:"ghost"}),n===r.href?"bg-muted hover:bg-muted":"hover:bg-transparent hover:underline","justify-start"),children:[e.jsx("span",{className:"mr-2",children:r.icon}),r.title]},r.href))})})]})}const yr=[{title:"站点设置",key:"site",icon:e.jsx(Yi,{size:18}),href:"/config/system",description:"配置站点基本信息,包括站点名称、描述、货币单位等核心设置。"},{title:"安全设置",key:"safe",icon:e.jsx(dn,{size:18}),href:"/config/system/safe",description:"配置系统安全相关选项包括登录验证、密码策略、API访问等安全设置。"},{title:"订阅设置",key:"subscribe",icon:e.jsx(un,{size:18}),href:"/config/system/subscribe",description:"管理用户订阅相关配置,包括订阅链接格式、更新频率、流量统计等设置。"},{title:"邀请&佣金",key:"invite",icon:e.jsx(Wi,{size:18}),href:"/config/system/invite",description:"管理用户邀请和佣金系统,配置邀请奖励、分销规则等。"},{title:"节点配置",key:"server",icon:e.jsx(cn,{size:18}),href:"/config/system/server",description:"配置节点通信和同步设置,包括通信密钥、轮询间隔、负载均衡等高级选项。"},{title:"邮件设置",key:"email",icon:e.jsx(Ji,{size:18}),href:"/config/system/email",description:"配置系统邮件服务用于发送验证码、密码重置、通知等邮件支持多种SMTP服务商。"},{title:"Telegram设置",key:"telegram",icon:e.jsx(Qi,{size:18}),href:"/config/system/telegram",description:"配置Telegram机器人功能实现用户通知、账户绑定、指令交互等自动化服务。"},{title:"APP设置",key:"app",icon:e.jsx(on,{size:18}),href:"/config/system/app",description:"管理移动应用程序相关配置包括API接口、版本控制、推送通知等功能设置。"}];function Gd(){return e.jsxs(ye,{fadedBelow:!0,fixedHeight:!0,children:[e.jsxs(Ne,{children:[e.jsx(ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"系统设置"}),e.jsx("div",{className:"text-muted-foreground",children:"管理系统核心配置,包括站点、安全、订阅、邀请佣金、节点、邮件和通知等设置"})]}),e.jsx(je,{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(Bd,{items:yr})}),e.jsx("div",{className:"w-full p-1 pr-4 lg:max-w-xl",children:e.jsx("div",{className:"pb-16",children:e.jsx(Xt,{})})})]})]})]})}const Yd=Object.freeze(Object.defineProperty({__proto__:null,default:Gd},Symbol.toStringTag,{value:"Module"}));function Wd({title:s,description:t,children:a}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t})]}),e.jsx(je,{}),a]})}const H=c.forwardRef(({className:s,...t},a)=>e.jsx(Rn,{className:v("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),...t,ref:a,children:e.jsx(Zi,{className:v("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 bs=c.forwardRef(({className:s,...t},a)=>e.jsx("textarea",{className:v("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,...t}));bs.displayName="Textarea";const Jd=u.object({logo:u.string().nullable().default(""),force_https:u.number().nullable().default(0),stop_register:u.number().nullable().default(0),app_name:u.string().nullable().default(""),app_description:u.string().nullable().default(""),app_url:u.string().nullable().default(""),subscribe_url:u.string().nullable().default(""),try_out_plan_id:u.number().nullable().default(0),try_out_hour:u.coerce.number().nullable().default(0),tos_url:u.string().nullable().default(""),currency:u.string().nullable().default(""),currency_symbol:u.string().nullable().default("")});function Qd(){const[s,t]=c.useState(!1),a=c.useRef(null),{data:n}=Q({queryKey:["settings","site"],queryFn:()=>os("site")}),{data:l}=Q({queryKey:["plans"],queryFn:()=>Is()}),o=ae({resolver:ie(Jd),defaultValues:{},mode:"onBlur"}),{mutateAsync:d}=We({mutationFn:cs,onSuccess:i=>{i.data&&A.success("已自动保存")}});c.useEffect(()=>{if(n?.data?.site){const i=n?.data?.site;Object.entries(i).forEach(([h,D])=>{o.setValue(h,D)}),a.current=i}},[n]);const x=c.useCallback(de.debounce(async i=>{if(!de.isEqual(i,a.current)){t(!0);try{const h=Object.entries(i).reduce((D,[C,m])=>(D[C]=m===null?"":m,D),{});await d(h),a.current=i}finally{t(!1)}}},1e3),[d]),r=c.useCallback(i=>{x(i)},[x]);return c.useEffect(()=>{const i=o.watch(h=>{r(h)});return()=>i.unsubscribe()},[o.watch,r]),e.jsx(oe,{...o,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:o.control,name:"app_name",render:({field:i})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"站点名称"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入站点名称",...i,value:i.value||"",onChange:h=>{i.onChange(h),r(o.getValues())}})}),e.jsx(F,{children:"用于显示需要站点名称的地方。"}),e.jsx(k,{})]})}),e.jsx(g,{control:o.control,name:"app_description",render:({field:i})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"站点描述"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入站点描述",...i,value:i.value||"",onChange:h=>{i.onChange(h),r(o.getValues())}})}),e.jsx(F,{children:"用于显示需要站点描述的地方。"}),e.jsx(k,{})]})}),e.jsx(g,{control:o.control,name:"app_url",render:({field:i})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"站点网址"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入站点URL末尾不要/",...i,value:i.value||"",onChange:h=>{i.onChange(h),r(o.getValues())}})}),e.jsx(F,{children:"当前网站最新网址,将会在邮件等需要用于网址处体现。"}),e.jsx(k,{})]})}),e.jsx(g,{control:o.control,name:"force_https",render:({field:i})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"强制HTTPS"}),e.jsx(F,{children:"当站点没有使用HTTPSCDN或反代开启强制HTTPS时需要开启。"})]}),e.jsx(y,{children:e.jsx(H,{checked:!!i.value,onCheckedChange:h=>{i.onChange(Number(h)),r(o.getValues())}})})]})}),e.jsx(g,{control:o.control,name:"logo",render:({field:i})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"LOGO"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入LOGO URL末尾不要/",...i,value:i.value||"",onChange:h=>{i.onChange(h),r(o.getValues())}})}),e.jsx(F,{children:"用于显示需要LOGO的地方。"}),e.jsx(k,{})]})}),e.jsx(g,{control:o.control,name:"subscribe_url",render:({field:i})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"订阅URL"}),e.jsx(y,{children:e.jsx(bs,{placeholder:"用于订阅所使用,多个订阅地址用','隔开.留空则为站点URL。",...i,value:i.value||"",onChange:h=>{i.onChange(h),r(o.getValues())}})}),e.jsx(F,{children:"用于订阅所使用留空则为站点URL。"}),e.jsx(k,{})]})}),e.jsx(g,{control:o.control,name:"tos_url",render:({field:i})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"用户条款(TOS)URL"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入用户条款URL末尾不要/",...i,value:i.value||"",onChange:h=>{i.onChange(h),r(o.getValues())}})}),e.jsx(F,{children:"用于跳转到用户条款(TOS)"}),e.jsx(k,{})]})}),e.jsx(g,{control:o.control,name:"stop_register",render:({field:i})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"停止新用户注册"}),e.jsx(F,{children:"开启后任何人都将无法进行注册。"})]}),e.jsx(y,{children:e.jsx(H,{checked:!!i.value,onCheckedChange:h=>{i.onChange(Number(h)),r(o.getValues())}})})]})}),e.jsx(g,{control:o.control,name:"try_out_plan_id",render:({field:i})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"注册试用"}),e.jsx(y,{children:e.jsxs(G,{value:i.value?.toString(),onValueChange:h=>{i.onChange(Number(h)),r(o.getValues())},children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"关闭"})}),e.jsxs(B,{children:[e.jsx(O,{value:"0",children:"关闭"}),l?.data?.map(h=>e.jsx(O,{value:h.id.toString(),children:h.name},h.id.toString()))]})]})}),e.jsx(F,{children:"选择需要试用的订阅,如果没有选项请先前往订阅管理添加。"}),e.jsx(k,{})]})}),!!o.watch("try_out_plan_id")&&e.jsx(g,{control:o.control,name:"try_out_hour",render:({field:i})=>e.jsxs(j,{children:[e.jsx(p,{className:"",children:"注册试用时长"}),e.jsx(y,{children:e.jsx(S,{placeholder:"0",...i,value:i.value||"",onChange:h=>{i.onChange(h),r(o.getValues())}})}),e.jsx(F,{children:"注册试用时长,单位为小时。"}),e.jsx(k,{})]})}),e.jsx(g,{control:o.control,name:"currency",render:({field:i})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"货币单位"}),e.jsx(y,{children:e.jsx(S,{placeholder:"CNY",...i,value:i.value||"",onChange:h=>{i.onChange(h),r(o.getValues())}})}),e.jsx(F,{children:"仅用于展示使用,更改后系统中所有的货币单位都将发生变更。"}),e.jsx(k,{})]})}),e.jsx(g,{control:o.control,name:"currency_symbol",render:({field:i})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"货币符号"}),e.jsx(y,{children:e.jsx(S,{placeholder:"¥",...i,value:i.value||"",onChange:h=>{i.onChange(h),r(o.getValues())}})}),e.jsx(F,{children:"仅用于展示使用,更改后系统中所有的货币单位都将发生变更。"}),e.jsx(k,{})]})}),s&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"保存中..."})]})})}function Zd(){const s=yr.find(t=>t.key==="site");return e.jsx(Wd,{title:s.title,description:s.description,children:e.jsx(Qd,{})})}const Xd=Object.freeze(Object.defineProperty({__proto__:null,default:Zd},Symbol.toStringTag,{value:"Module"})),eu=u.object({email_verify:u.boolean().nullable(),safe_mode_enable:u.boolean().nullable(),secure_path:u.string().nullable(),email_whitelist_enable:u.boolean().nullable(),email_whitelist_suffix:u.array(u.string().nullable()).nullable(),email_gmail_limit_enable:u.boolean().nullable(),recaptcha_enable:u.boolean().nullable(),recaptcha_key:u.string().nullable(),recaptcha_site_key:u.string().nullable(),register_limit_by_ip_enable:u.boolean().nullable(),register_limit_count:u.coerce.string().transform(s=>s===""?null:s).nullable(),register_limit_expire:u.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_enable:u.boolean().nullable(),password_limit_count:u.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_expire:u.coerce.string().transform(s=>s===""?null:s).nullable()}),su={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 tu(){const[s,t]=c.useState(!1),a=c.useRef(null),n=ae({resolver:ie(eu),defaultValues:su,mode:"onBlur"}),{data:l}=Q({queryKey:["settings","safe"],queryFn:()=>os("safe")}),{mutateAsync:o}=We({mutationFn:cs,onSuccess:r=>{r.data&&A.success("已自动保存")}});c.useEffect(()=>{if(l?.data.safe){const r=l.data.safe;Object.entries(r).forEach(([i,h])=>{typeof h=="number"?n.setValue(i,String(h)):n.setValue(i,h)}),a.current=r}},[l]);const d=c.useCallback(de.debounce(async r=>{if(!de.isEqual(r,a.current)){t(!0);try{await o(r),a.current=r}finally{t(!1)}}},1e3),[o]),x=c.useCallback(r=>{d(r)},[d]);return c.useEffect(()=>{const r=n.watch(i=>{x(i)});return()=>r.unsubscribe()},[n.watch,x]),e.jsx(oe,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:n.control,name:"email_verify",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"邮箱验证"}),e.jsx(F,{children:"开启后将会强制要求用户进行邮箱验证。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"email_gmail_limit_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"禁止使用Gmail多别名"}),e.jsx(F,{children:"开启后Gmail多别名将无法注册。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"safe_mode_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"安全模式"}),e.jsx(F,{children:"开启后除了站点URL以外的绑定本站点的域名访问都将会被403。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"secure_path",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"后台路径"}),e.jsx(y,{children:e.jsx(S,{placeholder:"admin",...r,value:r.value||"",onChange:i=>{r.onChange(i),x(n.getValues())}})}),e.jsx(F,{children:"后台管理路径修改后将会改变原有的admin路径"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"email_whitelist_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"邮箱后缀白名单"}),e.jsx(F,{children:"开启后在名单中的邮箱后缀才允许进行注册。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),n.watch("email_whitelist_enable")&&e.jsx(g,{control:n.control,name:"email_whitelist_suffix",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"白名单后缀"}),e.jsx(y,{children:e.jsx(bs,{placeholder:"请输入后缀域名,逗号分割 如qq.com,gmail.com",value:r.value?.length?r.value.join(","):"",onChange:i=>{const h=i.target.value?i.target.value.split(","):[];r.onChange(h),x(n.getValues())}})}),e.jsx(F,{children:"请使用逗号进行分割qq.com,gmail.com。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"recaptcha_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"防机器人"}),e.jsx(F,{children:"开启后将会使用Google reCAPTCHA防止机器人。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),n.watch("recaptcha_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:n.control,name:"recaptcha_key",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"密钥"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入密钥",...r,value:r.value||"",onChange:i=>{r.onChange(i),x(n.getValues())}})}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"recaptcha_site_key",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"站点密钥"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入站点密钥",...r,value:r.value||"",onChange:i=>{r.onChange(i),x(n.getValues())}})}),e.jsx(k,{})]})})]}),e.jsx(g,{control:n.control,name:"register_limit_by_ip_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"IP注册限制"}),e.jsx(F,{children:"开启后同一IP将会被限制注册次数。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),n.watch("register_limit_by_ip_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:n.control,name:"register_limit_count",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"限制次数"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入限制次数",...r,value:r.value||"",onChange:i=>{r.onChange(i),x(n.getValues())}})}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"register_limit_expire",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"限制时长(分钟)"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入限制时长",...r,value:r.value||"",onChange:i=>{r.onChange(i),x(n.getValues())}})}),e.jsx(k,{})]})})]}),e.jsx(g,{control:n.control,name:"password_limit_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"密码错误限制"}),e.jsx(F,{children:"开启后密码错误将会被限制登录。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),n.watch("password_limit_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:n.control,name:"password_limit_count",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"限制次数"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入限制次数",...r,value:r.value||"",onChange:i=>{r.onChange(i),x(n.getValues())}})}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"password_limit_expire",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"限制时长(分钟)"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入限制时长",...r,value:r.value||"",onChange:i=>{r.onChange(i),x(n.getValues())}})}),e.jsx(k,{})]})})]}),s&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"保存中..."})]})})}function au(){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:"配置系统安全相关选项包括登录验证、密码策略、API访问等安全设置。"})]}),e.jsx(je,{}),e.jsx(tu,{})]})}const nu=Object.freeze(Object.defineProperty({__proto__:null,default:au},Symbol.toStringTag,{value:"Module"})),ru=u.object({plan_change_enable:u.boolean().nullable().default(!1),reset_traffic_method:u.coerce.number().nullable().default(0),surplus_enable:u.boolean().nullable().default(!1),new_order_event_id:u.coerce.number().nullable().default(0),renew_order_event_id:u.coerce.number().nullable().default(0),change_order_event_id:u.coerce.number().nullable().default(0),show_info_to_server_enable:u.boolean().nullable().default(!1),show_protocol_to_server_enable:u.boolean().nullable().default(!1),default_remind_expire:u.boolean().nullable().default(!1),default_remind_traffic:u.boolean().nullable().default(!1),remind_mail_enable:u.boolean().nullable().default(!1),subscribe_path:u.string().nullable().default("s")}),lu={plan_change_enable:!1,reset_traffic_method:0,surplus_enable:!1,new_order_event_id:0,renew_order_event_id:0,change_order_event_id:0,show_info_to_server_enable:!1,show_protocol_to_server_enable:!1,default_remind_expire:!1,default_remind_traffic:!1,remind_mail_enable:!1,subscribe_path:"s"};function iu(){const[s,t]=c.useState(!1),a=c.useRef(null),n=ae({resolver:ie(ru),defaultValues:lu,mode:"onBlur"}),{data:l}=Q({queryKey:["settings","subscribe"],queryFn:()=>os("subscribe")}),{mutateAsync:o}=We({mutationFn:cs,onSuccess:r=>{r.data&&A.success("已自动保存")}});c.useEffect(()=>{if(l?.data?.subscribe){const r=l?.data?.subscribe;Object.entries(r).forEach(([i,h])=>{n.setValue(i,h)}),a.current=r}},[l]);const d=c.useCallback(de.debounce(async r=>{if(!de.isEqual(r,a.current)){t(!0);try{await o(r),a.current=r}finally{t(!1)}}},1e3),[o]),x=c.useCallback(r=>{d(r)},[d]);return c.useEffect(()=>{const r=n.watch(i=>{x(i)});return()=>r.unsubscribe()},[n.watch,x]),e.jsx(oe,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:n.control,name:"plan_change_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"允许用户更改订阅"}),e.jsx(F,{children:"开启后用户将会可以对订阅计划进行变更。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"reset_traffic_method",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"月流量重置方式"}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:r.onChange,value:r.value?.toString(),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择"})}),e.jsxs(B,{children:[e.jsx(O,{value:"0",children:"每月1号"}),e.jsx(O,{value:"1",children:"按月重置"}),e.jsx(O,{value:"2",children:"不重置"}),e.jsx(O,{value:"3",children:"每年1月1号"}),e.jsx(O,{value:"4",children:"按年重置"})]})]})})}),e.jsx(F,{children:"全局流量重置方式默认每月1号。可以在订阅管理为订阅单独设置。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"surplus_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"开启折抵方案"}),e.jsx(F,{children:"开启后用户更换订阅将会由系统对原有订阅进行折抵,方案参考文档。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"new_order_event_id",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"当订阅新购时触发事件"}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:r.onChange,value:r.value?.toString(),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择"})}),e.jsxs(B,{children:[e.jsx(O,{value:"0",children:"不执行任何动作"}),e.jsx(O,{value:"1",children:"重置用户流量"})]})]})})}),e.jsx(F,{children:"新购订阅完成时将触发该任务。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"renew_order_event_id",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"当订阅续费时触发事件"}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:r.onChange,value:r.value?.toString(),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择"})}),e.jsxs(B,{children:[e.jsx(O,{value:"0",children:"不执行任何动作"}),e.jsx(O,{value:"1",children:"重置用户流量"})]})]})})}),e.jsx(F,{children:"续费订阅完成时将触发该任务。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"change_order_event_id",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"当订阅变更时触发事件"}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:r.onChange,value:r.value?.toString(),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择"})}),e.jsxs(B,{children:[e.jsx(O,{value:"0",children:"不执行任何动作"}),e.jsx(O,{value:"1",children:"重置用户流量"})]})]})})}),e.jsx(F,{children:"变更订阅完成时将触发该任务。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"subscribe_path",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"订阅路径"}),e.jsx(y,{children:e.jsx(S,{placeholder:"subscribe",...r,value:r.value||"",onChange:i=>{r.onChange(i),x(n.getValues())}})}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["订阅路径修改后将会改变原有的subscribe路径",e.jsx("br",{}),"当前订阅路径格式:",r.value?`${r.value}/xxxxxxxxxx`:"s/xxxxxxxxxx"]}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"show_info_to_server_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"在订阅中展示订阅信息"}),e.jsx(F,{children:"开启后将会在用户订阅节点时输出订阅信息。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"show_protocol_to_server_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"在订阅中线路名称中显示协议名称"}),e.jsx(F,{children:"开启后订阅线路会附带协议名称(例如: [Hy2]香港)"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"remind_mail_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"邮件提醒"}),e.jsx(F,{children:"开启后用户订阅即将到期时和流量告急时时将发送邮件通知。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value||!1,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),s&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"保存中..."})]})})}function ou(){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(je,{}),e.jsx(iu,{})]})}const cu=Object.freeze(Object.defineProperty({__proto__:null,default:ou},Symbol.toStringTag,{value:"Module"})),du=u.object({invite_force:u.boolean().default(!1),invite_commission:u.coerce.string().default("0"),invite_gen_limit:u.coerce.string().default("0"),invite_never_expire:u.boolean().default(!1),commission_first_time_enable:u.boolean().default(!1),commission_auto_check_enable:u.boolean().default(!1),commission_withdraw_limit:u.coerce.string().default("0"),commission_withdraw_method:u.array(u.string()).default(["支付宝","USDT","Paypal"]),withdraw_close_enable:u.boolean().default(!1),commission_distribution_enable:u.boolean().default(!1),commission_distribution_l1:u.coerce.number().default(0),commission_distribution_l2:u.coerce.number().default(0),commission_distribution_l3:u.coerce.number().default(0)}),uu={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 xu(){const[s,t]=c.useState(!1),a=c.useRef(null),n=ae({resolver:ie(du),defaultValues:uu,mode:"onBlur"}),{data:l}=Q({queryKey:["settings","invite"],queryFn:()=>os("invite")}),{mutateAsync:o}=We({mutationFn:cs,onSuccess:r=>{r.data&&A.success("已自动保存")}});c.useEffect(()=>{if(l?.data?.invite){const r=l?.data?.invite;Object.entries(r).forEach(([i,h])=>{typeof h=="number"?n.setValue(i,String(h)):n.setValue(i,h)}),a.current=r}},[l]);const d=c.useCallback(de.debounce(async r=>{if(!de.isEqual(r,a.current)){t(!0);try{await o(r),a.current=r}finally{t(!1)}}},1e3),[o]),x=c.useCallback(r=>{d(r)},[d]);return c.useEffect(()=>{const r=n.watch(i=>{x(i)});return()=>r.unsubscribe()},[n.watch,x]),e.jsx(oe,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:n.control,name:"invite_force",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"开启强制邀请"}),e.jsx(F,{children:"开启后只有被邀请的用户才可以进行注册。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"invite_commission",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:" 邀请佣金百分比"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",...r,value:r.value||""})}),e.jsx(F,{children:"默认全局的佣金分配比例,你可以在用户管理单独配置单个比例。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"invite_gen_limit",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"用户可创建邀请码上限"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",...r,value:r.value||""})}),e.jsx(F,{children:"用户可创建邀请码上限"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"invite_never_expire",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"邀请码永不失效"}),e.jsx(F,{children:"开启后邀请码被使用后将不会失效,否则使用过后即失效。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"commission_first_time_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"佣金仅首次发放"}),e.jsx(F,{children:"开启后被邀请人首次支付时才会产生佣金,可以在用户管理对用户进行单独配置。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"commission_auto_check_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"佣金自动确认"}),e.jsx(F,{children:"开启后佣金将会在订单完成3日后自动进行确认。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"commission_withdraw_limit",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"提现单申请门槛(元)"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",...r,value:r.value||""})}),e.jsx(F,{children:"小于门槛金额的提现单将不会被提交。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"commission_withdraw_method",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"提现方式"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",...r,value:Array.isArray(r.value)?r.value.join(","):"",onChange:i=>{const h=i.target.value.split(",").filter(Boolean);r.onChange(h),x(n.getValues())}})}),e.jsx(F,{children:"可以支持的提现方式,多个用逗号分隔。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"withdraw_close_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"关闭提现"}),e.jsx(F,{children:"关闭后将禁止用户申请提现,且邀请佣金将会直接进入用户余额。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),e.jsx(g,{control:n.control,name:"commission_distribution_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"三级分销"}),e.jsx(F,{children:"开启后将佣金将按照设置的3成比例进行分成三成比例合计请不要大于100%。"})]}),e.jsx(y,{children:e.jsx(H,{checked:r.value,onCheckedChange:i=>{r.onChange(i),x(n.getValues())}})})]})}),n.watch("commission_distribution_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:n.control,name:"commission_distribution_l1",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"一级邀请人比例"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入比例如50",...r,value:r.value||"",onChange:i=>{const h=i.target.value?Number(i.target.value):0;r.onChange(h),x(n.getValues())}})}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"commission_distribution_l2",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"二级邀请人比例"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入比例如50",...r,value:r.value||"",onChange:i=>{const h=i.target.value?Number(i.target.value):0;r.onChange(h),x(n.getValues())}})}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"commission_distribution_l3",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"三级邀请人比例"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入比例如50",...r,value:r.value||"",onChange:i=>{const h=i.target.value?Number(i.target.value):0;r.onChange(h),x(n.getValues())}})}),e.jsx(k,{})]})})]}),s&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"保存中..."})]})})}function mu(){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(je,{}),e.jsx(xu,{})]})}const hu=Object.freeze(Object.defineProperty({__proto__:null,default:mu},Symbol.toStringTag,{value:"Module"})),ju=u.object({frontend_theme:u.string().nullable(),frontend_theme_sidebar:u.string().nullable(),frontend_theme_header:u.string().nullable(),frontend_theme_color:u.string().nullable(),frontend_background_url:u.string().url().nullable()}),gu={frontend_theme:"",frontend_theme_sidebar:"",frontend_theme_header:"",frontend_theme_color:"",frontend_background_url:""};function fu(){const{data:s}=Q({queryKey:["settings","frontend"],queryFn:()=>os("frontend")}),t=ae({resolver:ie(ju),defaultValues:gu,mode:"onChange"});c.useEffect(()=>{if(s?.data?.frontend){const n=s?.data?.frontend;Object.entries(n).forEach(([l,o])=>{t.setValue(l,o)})}},[s]);function a(n){cs(n).then(({data:l})=>{l&&A.success("更新成功")})}return e.jsx(oe,{...t,children:e.jsxs("form",{onSubmit:t.handleSubmit(a),className:"space-y-8",children:[e.jsx(g,{control:t.control,name:"frontend_theme_sidebar",render:({field:n})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"边栏风格"}),e.jsx(F,{children:"边栏风格"})]}),e.jsx(y,{children:e.jsx(H,{checked:n.value,onCheckedChange:n.onChange})})]})}),e.jsx(g,{control:t.control,name:"frontend_theme_header",render:({field:n})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(p,{className:"text-base",children:"头部风格"}),e.jsx(F,{children:"边栏风格"})]}),e.jsx(y,{children:e.jsx(H,{checked:n.value,onCheckedChange:n.onChange})})]})}),e.jsx(g,{control:t.control,name:"frontend_theme_color",render:({field:n})=>e.jsxs(j,{children:[e.jsx(p,{children:"主题色"}),e.jsxs("div",{className:"relative w-max",children:[e.jsx(y,{children:e.jsxs("select",{className:v(As({variant:"outline"}),"w-[200px] appearance-none font-normal"),...n,children:[e.jsx("option",{value:"default",children:"默认"}),e.jsx("option",{value:"black",children:"黑色"}),e.jsx("option",{value:"blackblue",children:"暗蓝色"}),e.jsx("option",{value:"green",children:"奶绿色"})]})}),e.jsx(ta,{className:"absolute right-3 top-2.5 h-4 w-4 opacity-50"})]}),e.jsx(F,{children:"主题色"}),e.jsx(k,{})]})}),e.jsx(g,{control:t.control,name:"frontend_background_url",render:({field:n})=>e.jsxs(j,{children:[e.jsx(p,{children:"背景"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入图片地址",...n})}),e.jsx(F,{children:"将会在后台登录页面进行展示。"}),e.jsx(k,{})]})}),e.jsx(T,{type:"submit",children:"保存设置"})]})})}function pu(){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(je,{}),e.jsx(fu,{})]})}const vu=Object.freeze(Object.defineProperty({__proto__:null,default:pu},Symbol.toStringTag,{value:"Module"})),bu=u.object({server_pull_interval:u.coerce.number().nullable(),server_push_interval:u.coerce.number().nullable(),server_token:u.string().nullable(),device_limit_mode:u.coerce.number().nullable()}),yu={server_pull_interval:0,server_push_interval:0,server_token:"",device_limit_mode:0};function Nu(){const[s,t]=c.useState(!1),a=c.useRef(null),n=ae({resolver:ie(bu),defaultValues:yu,mode:"onBlur"}),{data:l}=Q({queryKey:["settings","server"],queryFn:()=>os("server")}),{mutateAsync:o}=We({mutationFn:cs,onSuccess:r=>{r.data&&A.success("已自动保存")}});c.useEffect(()=>{if(l?.data.server){const r=l.data.server;Object.entries(r).forEach(([i,h])=>{n.setValue(i,h)}),a.current=r}},[l]);const d=c.useCallback(de.debounce(async r=>{if(!de.isEqual(r,a.current)){t(!0);try{await o(r),a.current=r}finally{t(!1)}}},1e3),[o]),x=c.useCallback(r=>{d(r)},[d]);return c.useEffect(()=>{const r=n.watch(i=>{x(i)});return()=>r.unsubscribe()},[n.watch,x]),e.jsx(oe,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:n.control,name:"server_token",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"通讯密钥"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",...r,value:r.value||""})}),e.jsx(F,{children:"Xboard与节点通讯的密钥以便数据不会被他人获取。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"server_pull_interval",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"节点拉取动作轮询间隔"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入",...r,value:r.value||"",onChange:i=>{const h=i.target.value?Number(i.target.value):null;r.onChange(h)}})}),e.jsx(F,{children:"节点从面板获取数据的间隔频率。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"server_push_interval",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"节点推送动作轮询间隔"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入",...r,value:r.value||"",onChange:i=>{const h=i.target.value?Number(i.target.value):null;r.onChange(h)}})}),e.jsx(F,{children:"节点推送数据到面板的间隔频率。"}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"device_limit_mode",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"设备限制模式"}),e.jsxs(G,{onValueChange:r.onChange,value:r.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择设备限制模式"})})}),e.jsxs(B,{children:[e.jsx(O,{value:"0",children:"严格模式"}),e.jsx(O,{value:"1",children:"宽松模式"})]})]}),e.jsx(F,{children:"宽松模式下同一IP地址使用多个节点只统计为一个设备。"}),e.jsx(k,{})]})}),s&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"保存中..."})]})})}function wu(){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(je,{}),e.jsx(Nu,{})]})}const _u=Object.freeze(Object.defineProperty({__proto__:null,default:wu},Symbol.toStringTag,{value:"Module"}));function Cu({open:s,onOpenChange:t,result:a}){const n=!a.error;return e.jsx(ue,{open:s,onOpenChange:t,children:e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[n?e.jsx(Pn,{className:"h-5 w-5 text-green-500"}):e.jsx(Vn,{className:"h-5 w-5 text-destructive"}),e.jsx(xe,{children:n?"邮件发送成功":"邮件发送失败"})]}),e.jsx(Se,{children:n?"测试邮件已成功发送,请检查收件箱":"发送测试邮件时遇到错误"})]}),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(at,{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 Su=u.object({email_template:u.string().nullable().default("classic"),email_host:u.string().nullable().default(""),email_port:u.string().regex(/^\d+$/).nullable().default("465"),email_username:u.string().nullable().default(""),email_password:u.string().nullable().default(""),email_encryption:u.string().nullable().default(""),email_from_address:u.string().email().nullable().default("")});function ku(){const[s,t]=c.useState(null),[a,n]=c.useState(!1),l=c.useRef(null),[o,d]=c.useState(!1),x=ae({resolver:ie(Su),defaultValues:{},mode:"onBlur"}),{data:r}=Q({queryKey:["settings","email"],queryFn:()=>os("email")}),{data:i}=Q({queryKey:["emailTemplate"],queryFn:()=>Cd()}),{mutateAsync:h}=We({mutationFn:cs,onSuccess:_=>{_.data&&A.success("已自动保存")}}),{mutate:D,isPending:C}=We({mutationFn:Sd,onMutate:()=>{t(null),n(!1)},onSuccess:_=>{t(_.data),n(!0),_.data.error||A.success("发送成功")}});c.useEffect(()=>{if(r?.data.email){const _=r.data.email;Object.entries(_).forEach(([b,N])=>{x.setValue(b,N)}),l.current=_}},[r]);const m=c.useCallback(de.debounce(async _=>{if(!de.isEqual(_,l.current)){d(!0);try{await h(_),l.current=_}finally{d(!1)}}},1e3),[h]),w=c.useCallback(_=>{m(_)},[m]);return c.useEffect(()=>{const _=x.watch(b=>{w(b)});return()=>_.unsubscribe()},[x.watch,w]),e.jsxs(e.Fragment,{children:[e.jsx(oe,{...x,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:x.control,name:"email_host",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"SMTP服务器地址"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",..._,value:_.value||""})}),e.jsx(F,{children:"由邮件服务商提供的服务地址"}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"email_port",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"SMTP服务端口"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",..._,value:_.value||""})}),e.jsx(F,{children:"常见的端口有25, 465, 587"}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"email_encryption",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"SMTP加密方式"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",..._,value:_.value||""})}),e.jsx(F,{children:"465端口加密方式一般为SSL587端口加密方式一般为TLS"}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"email_username",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"SMTP账号"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",..._,value:_.value||""})}),e.jsx(F,{children:"由邮件服务商提供的账号"}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"email_password",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"SMTP密码"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",..._,value:_.value||"",type:"password"})}),e.jsx(F,{children:"由邮件服务商提供的密码"}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"email_from_address",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"发件地址"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入",..._,value:_.value||""})}),e.jsx(F,{children:"由邮件服务商提供的发件地址"}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"email_template",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"邮件模板"}),e.jsxs(G,{onValueChange:b=>{_.onChange(b),w(x.getValues())},value:_.value||void 0,children:[e.jsx(y,{children:e.jsx(U,{className:"w-[200px]",children:e.jsx(Y,{placeholder:"选择邮件模板"})})}),e.jsx(B,{children:i?.data?.map(b=>e.jsx(O,{value:b,children:b},b))})]}),e.jsx(F,{children:"你可以在文档查看如何自定义邮件模板"}),e.jsx(k,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(T,{onClick:()=>D(),loading:C,disabled:C,children:C?"发送中...":"发送测试邮件"})})]})}),o&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"保存中..."}),s&&e.jsx(Cu,{open:a,onOpenChange:n,result:s})]})}function Tu(){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:"配置系统邮件服务用于发送验证码、密码重置、通知等邮件支持多种SMTP服务商。"})]}),e.jsx(je,{}),e.jsx(ku,{})]})}const Du=Object.freeze(Object.defineProperty({__proto__:null,default:Tu},Symbol.toStringTag,{value:"Module"})),Pu=u.object({telegram_bot_enable:u.boolean().nullable(),telegram_bot_token:u.string().nullable(),telegram_discuss_link:u.string().nullable()}),Vu={telegram_bot_enable:!1,telegram_bot_token:"",telegram_discuss_link:""};function Iu(){const[s,t]=c.useState(!1),a=c.useRef(null),n=ae({resolver:ie(Pu),defaultValues:Vu,mode:"onBlur"}),{data:l}=Q({queryKey:["settings","telegram"],queryFn:()=>os("telegram")}),{mutateAsync:o}=We({mutationFn:cs,onSuccess:h=>{h.data&&A.success("已自动保存")}}),{mutate:d,isPending:x}=We({mutationFn:kd,onSuccess:h=>{h.data&&A.success("Webhook设置成功")}});c.useEffect(()=>{if(l?.data.telegram){const h=l.data.telegram;Object.entries(h).forEach(([D,C])=>{n.setValue(D,C)}),a.current=h}},[l]);const r=c.useCallback(de.debounce(async h=>{if(!de.isEqual(h,a.current)){t(!0);try{await o(h),a.current=h}finally{t(!1)}}},1e3),[o]),i=c.useCallback(h=>{r(h)},[r]);return c.useEffect(()=>{const h=n.watch(D=>{i(D)});return()=>h.unsubscribe()},[n.watch,i]),e.jsx(oe,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:n.control,name:"telegram_bot_token",render:({field:h})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"机器人Token"}),e.jsx(y,{children:e.jsx(S,{placeholder:"0000000000:xxxxxxxxx_xxxxxxxxxxxxxxx",...h,value:h.value||""})}),e.jsx(F,{children:"请输入由Botfather提供的token。"}),e.jsx(k,{})]})}),n.watch("telegram_bot_token")&&e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"设置Webhook"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(T,{loading:x,disabled:x,onClick:()=>d(),children:x?"Webhook设置中...":"一键设置"}),s&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"保存中..."})]}),e.jsx(F,{children:"对机器人进行Webhook设置不设置将无法收到Telegram通知。"}),e.jsx(k,{})]}),e.jsx(g,{control:n.control,name:"telegram_bot_enable",render:({field:h})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"开启机器人通知"}),e.jsx(F,{children:"开启后bot将会对绑定了telegram的管理员和用户进行基础通知。"}),e.jsx(y,{children:e.jsx(H,{checked:h.value||!1,onCheckedChange:D=>{h.onChange(D),i(n.getValues())}})}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"telegram_discuss_link",render:({field:h})=>e.jsxs(j,{children:[e.jsx(p,{className:"text-base",children:"群组地址"}),e.jsx(y,{children:e.jsx(S,{placeholder:"https://t.me/xxxxxx",...h,value:h.value||""})}),e.jsx(F,{children:"填写后将会在用户端展示,或者被用于需要的地方。"}),e.jsx(k,{})]})}),s&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"保存中..."})]})})}function Ru(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"Telegram设置"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"配置Telegram机器人功能实现用户通知、账户绑定、指令交互等自动化服务。"})]}),e.jsx(je,{}),e.jsx(Iu,{})]})}const Eu=Object.freeze(Object.defineProperty({__proto__:null,default:Ru},Symbol.toStringTag,{value:"Module"})),Fu=u.object({windows_version:u.string().nullable(),windows_download_url:u.string().nullable(),macos_version:u.string().nullable(),macos_download_url:u.string().nullable(),android_version:u.string().nullable(),android_download_url:u.string().nullable()}),Mu={windows_version:"",windows_download_url:"",macos_version:"",macos_download_url:"",android_version:"",android_download_url:""};function zu(){const[s,t]=c.useState(!1),a=c.useRef(null),n=ae({resolver:ie(Fu),defaultValues:Mu,mode:"onBlur"}),{data:l}=Q({queryKey:["settings","app"],queryFn:()=>os("app")}),{mutateAsync:o}=We({mutationFn:cs,onSuccess:r=>{r.data&&A.success("已自动保存")}});c.useEffect(()=>{if(l?.data.app){const r=l.data.app;Object.entries(r).forEach(([i,h])=>{n.setValue(i,h)}),a.current=r}},[l]);const d=c.useCallback(de.debounce(async r=>{if(!de.isEqual(r,a.current)){t(!0);try{await o(r),a.current=r}finally{t(!1)}}},1e3),[o]),x=c.useCallback(r=>{d(r)},[d]);return c.useEffect(()=>{const r=n.watch(i=>{x(i)});return()=>r.unsubscribe()},[n.watch,x]),e.jsx(oe,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-base font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Windows"}),e.jsx("div",{className:"text-[0.8rem] text-muted-foreground",children:"Windows端版本号及下载地址"}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1",children:e.jsx(g,{control:n.control,name:"windows_version",render:({field:r})=>e.jsxs(j,{children:[e.jsx(y,{children:e.jsx(S,{placeholder:"1.0.0",...r,value:r.value||""})}),e.jsx(k,{})]})})}),e.jsx("div",{children:e.jsx(g,{control:n.control,name:"windows_download_url",render:({field:r})=>e.jsxs(j,{children:[e.jsx(y,{children:e.jsx(S,{placeholder:"https://xxx.com/xxx.exe",...r,value:r.value||""})}),e.jsx(k,{})]})})})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-base font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"macOS"}),e.jsx("div",{className:"text-[0.8rem] text-muted-foreground",children:"macOS端版本号及下载地址"}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1",children:e.jsx(g,{control:n.control,name:"macos_version",render:({field:r})=>e.jsxs(j,{children:[e.jsx(y,{children:e.jsx(S,{placeholder:"1.0.0",...r,value:r.value||""})}),e.jsx(k,{})]})})}),e.jsx("div",{children:e.jsx(g,{control:n.control,name:"macos_download_url",render:({field:r})=>e.jsxs(j,{children:[e.jsx(y,{children:e.jsx(S,{placeholder:"https://xxx.com/xxx.dmg",...r,value:r.value||""})}),e.jsx(k,{})]})})})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-base font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Android"}),e.jsx("div",{className:"text-[0.8rem] text-muted-foreground",children:"Android端版本号及下载地址"}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1",children:e.jsx(g,{control:n.control,name:"android_version",render:({field:r})=>e.jsxs(j,{children:[e.jsx(y,{children:e.jsx(S,{placeholder:"1.0.0",...r,value:r.value||""})}),e.jsx(k,{})]})})}),e.jsx("div",{children:e.jsx(g,{control:n.control,name:"android_download_url",render:({field:r})=>e.jsxs(j,{children:[e.jsx(y,{children:e.jsx(S,{placeholder:"https://xxx.com/xxx.apk",...r,value:r.value||""})}),e.jsx(k,{})]})})})]})]}),s&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"保存中..."})]})})}function Ou(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"APP设置"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"管理移动应用程序相关配置包括API接口、版本控制、推送通知等功能设置。"})]}),e.jsx(je,{}),e.jsx(zu,{})]})}const Lu=Object.freeze(Object.defineProperty({__proto__:null,default:Ou},Symbol.toStringTag,{value:"Module"})),ca=c.forwardRef(({className:s,...t},a)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:a,className:v("w-full caption-bottom text-sm",s),...t})}));ca.displayName="Table";const da=c.forwardRef(({className:s,...t},a)=>e.jsx("thead",{ref:a,className:v("[&_tr]:border-b",s),...t}));da.displayName="TableHeader";const ua=c.forwardRef(({className:s,...t},a)=>e.jsx("tbody",{ref:a,className:v("[&_tr:last-child]:border-0",s),...t}));ua.displayName="TableBody";const $u=c.forwardRef(({className:s,...t},a)=>e.jsx("tfoot",{ref:a,className:v("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...t}));$u.displayName="TableFooter";const js=c.forwardRef(({className:s,...t},a)=>e.jsx("tr",{ref:a,className:v("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...t}));js.displayName="TableRow";const xa=c.forwardRef(({className:s,...t},a)=>e.jsx("th",{ref:a,className:v("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t}));xa.displayName="TableHead";const Ls=c.forwardRef(({className:s,...t},a)=>e.jsx("td",{ref:a,className:v("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t}));Ls.displayName="TableCell";const Au=c.forwardRef(({className:s,...t},a)=>e.jsx("caption",{ref:a,className:v("mt-4 text-sm text-muted-foreground",s),...t}));Au.displayName="TableCaption";function Hu({table:s}){const[t,a]=c.useState("");c.useEffect(()=>{a((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const n=l=>{const o=parseInt(l);!isNaN(o)&&o>=1&&o<=s.getPageCount()?s.setPageIndex(o-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.jsxs("div",{className:"flex-1 text-sm text-muted-foreground",children:["已选择 ",s.getFilteredSelectedRowModel().rows.length," 项, 共"," ",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:"每页显示"}),e.jsxs(G,{value:`${s.getState().pagination.pageSize}`,onValueChange:l=>{s.setPageSize(Number(l))},children:[e.jsx(U,{className:"h-8 w-[70px]",children:e.jsx(Y,{placeholder:s.getState().pagination.pageSize})}),e.jsx(B,{side:"top",children:[10,20,30,40,50,100,500].map(l=>e.jsx(O,{value:`${l}`,children:l},l))})]})]}),e.jsxs("div",{className:"flex items-center justify-center space-x-2 text-sm font-medium",children:[e.jsx("span",{children:"第"}),e.jsx(S,{type:"text",value:t,onChange:l=>a(l.target.value),onBlur:l=>n(l.target.value),onKeyDown:l=>{l.key==="Enter"&&n(l.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsxs("span",{children:["页,共 ",s.getPageCount()," 页"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(T,{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:"跳转到第一页"}),e.jsx(Xi,{className:"h-4 w-4"})]}),e.jsxs(T,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:"上一页"}),e.jsx(Cn,{className:"h-4 w-4"})]}),e.jsxs(T,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:"下一页"}),e.jsx(sa,{className:"h-4 w-4"})]}),e.jsxs(T,{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:"跳转到最后一页"}),e.jsx(eo,{className:"h-4 w-4"})]})]})]})]})}function Ue({table:s,toolbar:t,draggable:a=!1,onDragStart:n,onDragEnd:l,onDragOver:o,onDragLeave:d,onDrop:x,showPagination:r=!0,isLoading:i=!1}){const h=c.useRef(null),D=s.getAllColumns().filter(_=>_.getIsPinned()==="left"),C=s.getAllColumns().filter(_=>_.getIsPinned()==="right"),m=_=>D.slice(0,_).reduce((b,N)=>b+(N.getSize()??0),0),w=_=>C.slice(_+1).reduce((b,N)=>b+(N.getSize()??0),0);return e.jsxs("div",{className:"space-y-4",children:[typeof t=="function"?t(s):t,e.jsx("div",{ref:h,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(_=>e.jsx(js,{className:"hover:bg-transparent",children:_.headers.map((b,N)=>{const P=b.column.getIsPinned()==="left",f=b.column.getIsPinned()==="right",R=P?m(D.indexOf(b.column)):void 0,z=f?w(C.indexOf(b.column)):void 0;return e.jsx(xa,{colSpan:b.colSpan,style:{width:b.getSize(),...P&&{left:R},...f&&{right:z}},className:v("h-11 bg-card px-4 text-muted-foreground",(P||f)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",P&&"before:right-0",f&&"before:left-0"]),children:b.isPlaceholder?null:vt(b.column.columnDef.header,b.getContext())},b.id)})},_.id))}),e.jsx(ua,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((_,b)=>e.jsx(js,{"data-state":_.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:a,onDragStart:N=>n?.(N,b),onDragEnd:l,onDragOver:o,onDragLeave:d,onDrop:N=>x?.(N,b),children:_.getVisibleCells().map((N,P)=>{const f=N.column.getIsPinned()==="left",R=N.column.getIsPinned()==="right",z=f?m(D.indexOf(N.column)):void 0,$=R?w(C.indexOf(N.column)):void 0;return e.jsx(Ls,{style:{width:N.column.getSize(),...f&&{left:z},...R&&{right:$}},className:v("bg-card",(f||R)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",f&&"before:right-0",R&&"before:left-0"]),children:vt(N.column.columnDef.cell,N.getContext())},N.id)})},_.id)):e.jsx(js,{children:e.jsx(Ls,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:"暂无数据"})})})]})})}),r&&e.jsx(Hu,{table:s})]})}const Nr=(s,t)=>{let a=null;switch(s.field_type){case"input":a=e.jsx(S,{placeholder:s.placeholder,...t});break;case"textarea":a=e.jsx(bs,{placeholder:s.placeholder,...t});break;case"select":a=e.jsx("select",{className:v($s({variant:"outline"}),"w-full appearance-none font-normal"),...t,children:s.select_options&&Object.keys(s.select_options).map(n=>e.jsx("option",{value:n,children:s.select_options?.[n]},n))});break;default:a=null;break}return a},Ku=u.object({id:u.number().nullable(),name:u.string().min(2,"名称至少需要2个字符").max(30,"名称不能超过30个字符"),icon:u.string().optional().nullable(),notify_domain:u.string().refine(s=>!s||/^https?:\/\/\S+/.test(s),"请输入有效的URL").optional().nullable(),handling_fee_fixed:u.coerce.number().min(0).optional().nullable(),handling_fee_percent:u.coerce.number().min(0).max(100).optional().nullable(),payment:u.string().min(1,"请选择支付接口"),config:u.record(u.string(),u.string())}),La={id:null,name:"",icon:"",notify_domain:"",handling_fee_fixed:0,handling_fee_percent:0,payment:"",config:{}};function wr({refetch:s,dialogTrigger:t,type:a="add",defaultFormValues:n=La}){const[l,o]=c.useState(!1),[d,x]=c.useState(!1),[r,i]=c.useState([]),[h,D]=c.useState([]),C=ae({resolver:ie(Ku),defaultValues:n,mode:"onChange"}),m=C.watch("payment");c.useEffect(()=>{l&&(async()=>{const{data:b}=await Kc();i(b)})()},[l]),c.useEffect(()=>{if(!m||!l)return;(async()=>{const b={payment:m,...a==="edit"&&{id:Number(C.getValues("id"))}};qc(b).then(({data:N})=>{D(N);const P=N.reduce((f,R)=>(R.field_name&&(f[R.field_name]=R.value??""),f),{});C.setValue("config",P)})})()},[m,l,C,a]);const w=async _=>{x(!0),(await Uc(_)).data&&(A.success("保存成功"),C.reset(La),s(),o(!1)),x(!1)};return e.jsxs(ue,{open:l,onOpenChange:o,children:[e.jsx(Ie,{asChild:!0,children:t||e.jsxs(T,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(ve,{icon:"ion:add"})," ",e.jsx("div",{children:"添加支付方式"})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsx(he,{children:e.jsx(xe,{children:a==="add"?"添加支付方式":"编辑支付方式"})}),e.jsx(oe,{...C,children:e.jsxs("form",{onSubmit:C.handleSubmit(w),className:"space-y-4",children:[e.jsx(g,{control:C.control,name:"name",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{children:"显示名称"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入支付名称",..._})}),e.jsx(F,{children:"用于前端显示"}),e.jsx(k,{})]})}),e.jsx(g,{control:C.control,name:"icon",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{children:"图标URL"}),e.jsx(y,{children:e.jsx(S,{placeholder:"https://example.com/icon.svg",..._})}),e.jsx(F,{children:"用于前端显示的图标地址"}),e.jsx(k,{})]})}),e.jsx(g,{control:C.control,name:"notify_domain",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{children:"通知域名"}),e.jsx(y,{children:e.jsx(S,{placeholder:"https://example.com",..._})}),e.jsx(F,{children:"网关通知将发送到该域名"}),e.jsx(k,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:C.control,name:"handling_fee_percent",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{children:"百分比手续费(%)"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"0-100",..._})}),e.jsx(k,{})]})}),e.jsx(g,{control:C.control,name:"handling_fee_fixed",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{children:"固定手续费"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"0",..._})}),e.jsx(k,{})]})})]}),e.jsx(g,{control:C.control,name:"payment",render:({field:_})=>e.jsxs(j,{children:[e.jsx(p,{children:"支付接口"}),e.jsxs(G,{value:_.value,onValueChange:_.onChange,children:[e.jsx(y,{children:e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择支付接口"})})}),e.jsx(B,{children:r.map(b=>e.jsx(O,{value:b,children:b},b))})]}),e.jsx(k,{})]})}),h.map(_=>e.jsx(g,{control:C.control,name:`config.${_.field_name}`,render:({field:b})=>e.jsxs(j,{children:[e.jsx(p,{children:_.label}),e.jsx(y,{children:Nr(_,b)}),e.jsx(k,{})]})},_.field_name)),e.jsxs(Re,{className:"gap-2",children:[e.jsx(ot,{asChild:!0,children:e.jsx(T,{type:"button",variant:"outline",children:"取消"})}),e.jsx(T,{type:"submit",disabled:d,className:v(d&&"cursor-not-allowed opacity-50"),children:d?"保存中...":"提交"})]})]})})]})]})}function V({column:s,title:t,tooltip:a,className:n}){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(T,{variant:"ghost",size:"default",className:v("-ml-3 flex h-8 items-center gap-2 text-nowrap font-medium hover:bg-muted/60",n),onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[e.jsx("span",{children:t}),a&&e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{asChild:!0,children:e.jsx(ka,{className:"h-4 w-4 cursor-pointer text-muted-foreground"})}),e.jsx(ee,{children:a})]})}),s.getIsSorted()==="asc"?e.jsx(Kt,{className:"h-4 w-4 text-foreground/70"}):s.getIsSorted()==="desc"?e.jsx(qt,{className:"h-4 w-4 text-foreground/70"}):e.jsx(so,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-foreground/70"})]})})}):e.jsxs("div",{className:v("flex items-center space-x-1 text-nowrap py-2 font-medium text-muted-foreground",n),children:[e.jsx("span",{children:t}),a&&e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{children:e.jsx(ka,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(ee,{children:a})]})})]})}const qu=to,Uu=ao,Bu=no,_r=c.forwardRef(({className:s,...t},a)=>e.jsx(En,{className:v("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),...t,ref:a}));_r.displayName=En.displayName;const Cr=c.forwardRef(({className:s,...t},a)=>e.jsxs(Bu,{children:[e.jsx(_r,{}),e.jsx(Fn,{ref:a,className:v("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...t})]}));Cr.displayName=Fn.displayName;const Sr=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-2 text-center sm:text-left",s),...t});Sr.displayName="AlertDialogHeader";const kr=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});kr.displayName="AlertDialogFooter";const Tr=c.forwardRef(({className:s,...t},a)=>e.jsx(Mn,{ref:a,className:v("text-lg font-semibold",s),...t}));Tr.displayName=Mn.displayName;const Dr=c.forwardRef(({className:s,...t},a)=>e.jsx(zn,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));Dr.displayName=zn.displayName;const Pr=c.forwardRef(({className:s,...t},a)=>e.jsx(On,{ref:a,className:v($s(),s),...t}));Pr.displayName=On.displayName;const Vr=c.forwardRef(({className:s,...t},a)=>e.jsx(Ln,{ref:a,className:v($s({variant:"outline"}),"mt-2 sm:mt-0",s),...t}));Vr.displayName=Ln.displayName;function Be({onConfirm:s,children:t,title:a="确认操作",description:n="确定要执行此操作吗?",cancelText:l="取消",confirmText:o="确认",variant:d="default",className:x}){return e.jsxs(qu,{children:[e.jsx(Uu,{asChild:!0,children:t}),e.jsxs(Cr,{className:v("sm:max-w-[425px]",x),children:[e.jsxs(Sr,{children:[e.jsx(Tr,{children:a}),e.jsx(Dr,{children:n})]}),e.jsxs(kr,{children:[e.jsx(Vr,{asChild:!0,children:e.jsx(T,{variant:"outline",children:l})}),e.jsx(Pr,{asChild:!0,children:e.jsx(T,{variant:d,onClick:s,children:o})})]})]})]})}const Ir=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"})}),Gu=({refetch:s,isSortMode:t=!1})=>[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:t?"cursor-move":"opacity-0",children:e.jsx(Tt,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:a})=>e.jsx(V,{column:a,title:"ID"}),cell:({row:a})=>e.jsx(L,{variant:"outline",children:a.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"enable",header:({column:a})=>e.jsx(V,{column:a,title:"启用"}),cell:({row:a})=>e.jsx(H,{defaultChecked:a.getValue("enable"),onCheckedChange:async()=>{const{data:n}=await Gc({id:a.original.id});n||s()}}),enableSorting:!1,size:100},{accessorKey:"name",header:({column:a})=>e.jsx(V,{column:a,title:"显示名称"}),cell:({row:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:a.getValue("name")})}),enableSorting:!1,size:200},{accessorKey:"payment",header:({column:a})=>e.jsx(V,{column:a,title:"支付接口"}),cell:({row:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:a.getValue("payment")})}),enableSorting:!1,size:200},{accessorKey:"notify_url",header:({column:a})=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(V,{column:a,title:"通知地址"}),e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{className:"ml-1",children:e.jsx(Ir,{className:"h-4 w-4"})}),e.jsx(ee,{children:"支付网关将会把数据通知到本地址,请通过防火墙放行本地址。"})]})})]}),cell:({row:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[300px] truncate font-medium",children:a.getValue("notify_url")})}),enableSorting:!1,size:3e3},{id:"actions",header:({column:a})=>e.jsx(V,{className:"justify-end",column:a,title:"操作"}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(wr,{refetch:s,dialogTrigger:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Ds,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:"编辑"})]}),type:"edit",defaultFormValues:a.original}),e.jsx(Be,{title:"删除确认",description:"确定要删除该支付方式吗?此操作无法撤销。",onConfirm:async()=>{const{data:n}=await Bc({id:a.original.id});n&&s()},children:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10",children:[e.jsx(rs,{className:"h-4 w-4 text-muted-foreground hover:text-destructive"}),e.jsx("span",{className:"sr-only",children:"删除"})]})})]}),size:100}];function Yu({table:s,refetch:t,saveOrder:a,isSortMode:n}){const l=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between",children:[n?e.jsx("p",{className:"text-sm text-muted-foreground",children:"拖拽支付方式进行排序,完成后点击保存"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wr,{refetch:t}),e.jsx(S,{placeholder:"搜索支付方式...",value:s.getColumn("name")?.getFilterValue()??"",onChange:o=>s.getColumn("name")?.setFilterValue(o.target.value),className:"h-8 w-[250px]"}),l&&e.jsxs(T,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:["重置",e.jsx(Fe,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(T,{variant:n?"default":"outline",onClick:a,size:"sm",children:n?"保存排序":"编辑排序"})})]})}function Wu(){const[s,t]=c.useState([]),[a,n]=c.useState([]),[l,o]=c.useState(!1),[d,x]=c.useState([]),[r,i]=c.useState({"drag-handle":!1}),[h,D]=c.useState({pageSize:20,pageIndex:0}),{refetch:C}=Q({queryKey:["paymentList"],queryFn:async()=>{const{data:N}=await Hc();return x(N?.map(P=>({...P,enable:!!P.enable}))||[]),N}});c.useEffect(()=>{i({"drag-handle":l}),D({pageSize:l?99999:10,pageIndex:0})},[l]);const m=(N,P)=>{l&&(N.dataTransfer.setData("text/plain",P.toString()),N.currentTarget.classList.add("opacity-50"))},w=(N,P)=>{if(!l)return;N.preventDefault(),N.currentTarget.classList.remove("bg-muted");const f=parseInt(N.dataTransfer.getData("text/plain"));if(f===P)return;const R=[...d],[z]=R.splice(f,1);R.splice(P,0,z),x(R)},_=async()=>{l?Yc({ids:d.map(N=>N.id)}).then(()=>{C(),o(!1),A.success("排序保存成功")}):o(!0)},b=Me({data:d,columns:Gu({refetch:C,isSortMode:l}),state:{sorting:a,columnFilters:s,columnVisibility:r,pagination:h},onSortingChange:n,onColumnFiltersChange:t,onColumnVisibilityChange:i,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),getSortedRowModel:Ke(),initialState:{columnPinning:{right:["actions"]}},pageCount:l?1:void 0});return e.jsx(Ue,{table:b,toolbar:N=>e.jsx(Yu,{table:N,refetch:C,saveOrder:_,isSortMode:l}),draggable:l,onDragStart:m,onDragEnd:N=>N.currentTarget.classList.remove("opacity-50"),onDragOver:N=>{N.preventDefault(),N.currentTarget.classList.add("bg-muted")},onDragLeave:N=>N.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!l})}function Ju(){return e.jsxs(ye,{children:[e.jsxs(Ne,{className:"flex items-center justify-between",children:[e.jsx(ke,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"支付配置"})}),e.jsx("p",{className:"text-muted-foreground",children:"在这里可以配置支付方式,包括支付宝、微信等。"})]})}),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(Wu,{})})]})]})}const Qu=Object.freeze(Object.defineProperty({__proto__:null,default:Ju},Symbol.toStringTag,{value:"Module"}));function Zu({themeKey:s,themeInfo:t}){const[a,n]=c.useState(!1),[l,o]=c.useState(!1),[d,x]=c.useState(!1),r=ae({defaultValues:t.configs.reduce((D,C)=>(D[C.field_name]="",D),{})}),i=async()=>{o(!0),Tc(s).then(({data:D})=>{Object.entries(D).forEach(([C,m])=>{r.setValue(C,m)})}).finally(()=>{o(!1)})},h=async D=>{x(!0),Dc(s,D).then(()=>{A.success("保存成功"),n(!1)}).finally(()=>{x(!1)})};return e.jsxs(ue,{open:a,onOpenChange:D=>{n(D),D?i():r.reset()},children:[e.jsx(Ie,{asChild:!0,children:e.jsx(T,{variant:"outline",children:"主题设置"})}),e.jsxs(ce,{className:"max-h-[90vh] overflow-auto sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsxs(xe,{children:["配置",t.name,"主题"]}),e.jsx(Se,{children:"修改主题的样式、布局和其他显示选项。"})]}),l?e.jsx("div",{className:"flex h-40 items-center justify-center",children:e.jsx(aa,{className:"h-6 w-6 animate-spin"})}):e.jsx(oe,{...r,children:e.jsxs("form",{onSubmit:r.handleSubmit(h),className:"space-y-4",children:[t.configs.map(D=>e.jsx(g,{control:r.control,name:D.field_name,render:({field:C})=>e.jsxs(j,{children:[e.jsx(p,{children:D.label}),e.jsx(y,{children:Nr(D,C)}),e.jsx(k,{})]})},D.field_name)),e.jsxs(Re,{className:"mt-6 gap-2",children:[e.jsx(T,{type:"button",variant:"secondary",onClick:()=>n(!1),children:"取消"}),e.jsx(T,{type:"submit",loading:d,children:"保存"})]})]})})]})]})}function Xu(){const[s,t]=c.useState(null),[a,n]=c.useState(!1),[l,o]=c.useState(!1),[d,x]=c.useState(!1),[r,i]=c.useState(null),h=c.useRef(null),[D,C]=c.useState(0),{data:m,isLoading:w,refetch:_}=Q({queryKey:["themeList"],queryFn:async()=>{const{data:E}=await kc();return E}}),b=async E=>{t(E),Ic({frontend_theme:E}).then(()=>{A.success("主题切换成功"),_()}).finally(()=>{t(null)})},N=async E=>{if(!E.name.endsWith(".zip")){A.error("只支持上传 ZIP 格式的主题文件");return}n(!0),Pc(E).then(()=>{A.success("主题上传成功"),o(!1),_()}).finally(()=>{n(!1),h.current&&(h.current.value="")})},P=E=>{E.preventDefault(),E.stopPropagation(),E.type==="dragenter"||E.type==="dragover"?x(!0):E.type==="dragleave"&&x(!1)},f=E=>{E.preventDefault(),E.stopPropagation(),x(!1),E.dataTransfer.files&&E.dataTransfer.files[0]&&N(E.dataTransfer.files[0])},R=()=>{r&&C(E=>E===0?r.images.length-1:E-1)},z=()=>{r&&C(E=>E===r.images.length-1?0:E+1)},$=(E,K)=>{C(0),i({name:E,images:K})};return e.jsxs(ye,{children:[e.jsxs(Ne,{className:"flex items-center justify-between",children:[e.jsx(ke,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"主题配置"})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-muted-foreground",children:"主题配置包括主题色、字体大小等。如果你采用前后分离的方式部署V2board那么主题配置将不会生效。"}),e.jsxs(T,{onClick:()=>o(!0),variant:"outline",className:"ml-4 shrink-0",size:"sm",children:[e.jsx(Ht,{className:"mr-2 h-4 w-4"}),"上传主题"]})]})]}),e.jsx("section",{className:"grid gap-6 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3",children:w?e.jsxs(e.Fragment,{children:[e.jsx($a,{}),e.jsx($a,{})]}):m?.themes&&Object.entries(m.themes).map(([E,K])=>e.jsx($e,{className:"group relative overflow-hidden transition-all hover:shadow-md",style:{backgroundImage:K.background_url?`url(${K.background_url})`:"none",backgroundSize:"cover",backgroundPosition:"center"},children:e.jsxs("div",{className:v("relative z-10 h-full transition-colors",K.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:[!!K.can_delete&&e.jsx("div",{className:"absolute right-2 top-2",children:e.jsx(Be,{title:"删除主题",description:"确定要删除该主题吗?删除后无法恢复。",confirmText:"删除",variant:"destructive",onConfirm:async()=>{if(E===m?.active){A.error("不能删除当前使用的主题");return}t(E),Vc(E).then(()=>{A.success("主题删除成功"),_()}).finally(()=>{t(null)})},children:e.jsx(T,{disabled:s===E,loading:s===E,variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",children:e.jsx(rs,{className:"h-4 w-4"})})})}),e.jsxs(Je,{children:[e.jsx(gs,{children:K.name}),e.jsx(Xs,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{children:K.description}),K.version&&e.jsxs("div",{className:"text-sm text-muted-foreground",children:["版本: ",K.version]})]})})]}),e.jsxs(Qe,{className:"flex items-center justify-end space-x-3",children:[K.images&&Array.isArray(K.images)&&K.images.length>0&&e.jsx(T,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>$(K.name,K.images),children:e.jsx(ro,{className:"h-4 w-4"})}),e.jsx(Zu,{themeKey:E,themeInfo:K}),e.jsx(T,{onClick:()=>b(E),disabled:s===E||E===m.active,loading:s===E,variant:E===m.active?"secondary":"default",children:E===m.active?"当前主题":"激活主题"})]})]})},E))}),e.jsx(ue,{open:l,onOpenChange:o,children:e.jsxs(ce,{className:"sm:max-w-md",children:[e.jsxs(he,{children:[e.jsx(xe,{children:"上传主题"}),e.jsx(Se,{children:"请上传一个有效的主题压缩包(.zip 格式)。主题包应包含完整的主题文件结构。"})]}),e.jsxs("div",{className:v("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",d&&"border-primary/50 bg-muted/50"),onDragEnter:P,onDragLeave:P,onDragOver:P,onDrop:f,children:[e.jsx("input",{type:"file",ref:h,className:"hidden",accept:".zip",onChange:E=>{const K=E.target.files?.[0];K&&N(K)}}),a?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:"正在上传..."})]}):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:["将主题文件拖放到此处,或者",e.jsx("button",{type:"button",onClick:()=>h.current?.click(),className:"mx-1 text-primary hover:underline",children:"点击选择"})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"支持 .zip 格式的主题包"})]})]})})]})]})}),e.jsx(ue,{open:!!r,onOpenChange:E=>{E||(i(null),C(0))},children:e.jsxs(ce,{className:"max-w-4xl",children:[e.jsxs(he,{children:[e.jsxs(xe,{children:[r?.name," 主题预览"]}),e.jsx(Se,{className:"text-center",children:r&&`${D+1} / ${r.images.length}`})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"aspect-[16/9] overflow-hidden rounded-lg border bg-muted",children:r?.images[D]&&e.jsx("img",{src:r.images[D],alt:`${r.name} 预览图 ${D+1}`,className:"h-full w-full object-contain"})}),r&&r.images.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(T,{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(lo,{className:"h-4 w-4"})}),e.jsx(T,{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(io,{className:"h-4 w-4"})})]})]}),r&&r.images.length>1&&e.jsx("div",{className:"mt-4 flex gap-2 overflow-x-auto pb-2",children:r.images.map((E,K)=>e.jsx("button",{onClick:()=>C(K),className:v("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2",D===K?"border-primary":"border-transparent"),children:e.jsx("img",{src:E,alt:`缩略图 ${K+1}`,className:"h-full w-full object-cover"})},K))})]})})]})]})}function $a(){return e.jsxs($e,{children:[e.jsxs(Je,{children:[e.jsx(Ee,{className:"h-6 w-[200px]"}),e.jsx(Ee,{className:"h-4 w-[300px]"})]}),e.jsxs(Qe,{className:"flex items-center justify-end space-x-3",children:[e.jsx(Ee,{className:"h-10 w-[100px]"}),e.jsx(Ee,{className:"h-10 w-[100px]"})]})]})}const ex=Object.freeze(Object.defineProperty({__proto__:null,default:Xu},Symbol.toStringTag,{value:"Module"})),ma=c.forwardRef(({className:s,value:t,onChange:a,...n},l)=>{const[o,d]=c.useState("");c.useEffect(()=>{if(o.includes(",")){const r=new Set([...t,...o.split(",").map(i=>i.trim())]);a(Array.from(r)),d("")}},[o,a,t]);const x=()=>{if(o){const r=new Set([...t,o]);a(Array.from(r)),d("")}};return e.jsxs("div",{className:v(" 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:[t.map(r=>e.jsxs(L,{variant:"secondary",children:[r,e.jsx(W,{variant:"ghost",size:"icon",className:"ml-2 h-3 w-3",onClick:()=>{a(t.filter(i=>i!==r))},children:e.jsx(Ut,{className:"w-3"})})]},r)),e.jsx("input",{className:"flex-1 outline-none placeholder:text-muted-foreground bg-transparent",value:o,onChange:r=>d(r.target.value),onKeyDown:r=>{r.key==="Enter"||r.key===","?(r.preventDefault(),x()):r.key==="Backspace"&&o.length===0&&t.length>0&&(r.preventDefault(),a(t.slice(0,-1)))},...n,ref:l})]})});ma.displayName="InputTags";const sx=u.object({id:u.number().nullable(),title:u.string().min(1).max(250),content:u.string().min(1),show:u.boolean(),tags:u.array(u.string()),img_url:u.string().nullable()}),tx={id:null,show:!1,tags:[],img_url:"",title:"",content:""};function Rr({refetch:s,dialogTrigger:t,type:a="add",defaultFormValues:n=tx}){const[l,o]=c.useState(!1),d=ae({resolver:ie(sx),defaultValues:n,mode:"onChange",shouldFocusError:!0}),x=new na({html:!0});return e.jsx(oe,{...d,children:e.jsxs(ue,{onOpenChange:o,open:l,children:[e.jsx(Ie,{asChild:!0,children:t||e.jsxs(T,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(ve,{icon:"ion:add"})," ",e.jsx("div",{children:"添加公告"})]})}),e.jsxs(ce,{className:"sm:max-w-[1025px]",children:[e.jsxs(he,{children:[e.jsx(xe,{children:a==="add"?"添加公告":"编辑公告"}),e.jsx(Se,{})]}),e.jsx(g,{control:d.control,name:"title",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"标题"}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(S,{placeholder:"请输入公告标题",...r})})}),e.jsx(k,{})]})}),e.jsx(g,{control:d.control,name:"content",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"公告内容"}),e.jsx(y,{children:e.jsx(ra,{style:{height:"500px"},value:r.value,renderHTML:i=>x.render(i),onChange:({text:i})=>{r.onChange(i)}})}),e.jsx(k,{})]})}),e.jsx(g,{control:d.control,name:"img_url",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"公告背景"}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(S,{type:"text",placeholder:"请输入公告背景图片URL",...r,value:r.value||""})})}),e.jsx(k,{})]})}),e.jsx(g,{control:d.control,name:"show",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"显示"}),e.jsx("div",{className:"relative py-2",children:e.jsx(y,{children:e.jsx(H,{checked:r.value,onCheckedChange:r.onChange})})}),e.jsx(k,{})]})}),e.jsx(g,{control:d.control,name:"tags",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"节点标签"}),e.jsx(y,{children:e.jsx(ma,{value:r.value,onChange:r.onChange,placeholder:"输入后回车添加标签",className:"w-full"})}),e.jsx(k,{})]})}),e.jsxs(Re,{children:[e.jsx(ot,{asChild:!0,children:e.jsx(T,{type:"button",variant:"outline",children:"取消"})}),e.jsx(T,{type:"submit",onClick:r=>{r.preventDefault(),d.handleSubmit(async i=>{Jc(i).then(({data:h})=>{h&&(A.success("提交成功"),s(),o(!1))})})()},children:"提交"})]})]})]})})}function ax({table:s,refetch:t,saveOrder:a,isSortMode:n}){const l=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:[!n&&e.jsx(Rr,{refetch:t}),!n&&e.jsx(S,{placeholder:"搜索公告标题...",value:s.getColumn("title")?.getFilterValue()??"",onChange:o=>s.getColumn("title")?.setFilterValue(o.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),l&&!n&&e.jsxs(T,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-9 px-2 lg:px-3",children:["重置",e.jsx(Fe,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(T,{variant:n?"default":"outline",onClick:a,className:"h-8",size:"sm",children:n?"保存排序":"编辑排序"})})]})}const nx=s=>[{id:"drag-handle",header:"",cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(oo,{className:"h-4 w-4 text-muted-foreground cursor-move"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(V,{column:t,title:"ID"}),cell:({row:t})=>e.jsx(L,{variant:"outline",className:"font-mono",children:t.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"show",header:({column:t})=>e.jsx(V,{column:t,title:"显示状态"}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(H,{defaultChecked:t.getValue("show"),onCheckedChange:async()=>{const{data:a}=await Zc({id:t.original.id});a||s()}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:t})=>e.jsx(V,{column:t,title:"标题"}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[500px] items-center",children:e.jsx("span",{className:"truncate font-medium",children:t.getValue("title")})}),enableSorting:!1,size:6e3},{id:"actions",header:({column:t})=>e.jsx(V,{className:"justify-end",column:t,title:"操作"}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Rr,{refetch:s,dialogTrigger:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Ds,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:"编辑"})]}),type:"edit",defaultFormValues:t.original}),e.jsx(Be,{title:"删除确认",description:"确定要删除该条公告吗?此操作无法撤销。",onConfirm:async()=>{Qc({id:t.original.id}).then(()=>{A.success("删除成功"),s()})},children:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(rs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:"删除"})]})})]}),size:100}];function rx(){const[s,t]=c.useState({}),[a,n]=c.useState({}),[l,o]=c.useState([]),[d,x]=c.useState([]),[r,i]=c.useState(!1),[h,D]=c.useState({}),[C,m]=c.useState({pageSize:50,pageIndex:0}),[w,_]=c.useState([]),{refetch:b}=Q({queryKey:["notices"],queryFn:async()=>{const{data:z}=await Wc();return _(z),z}});c.useEffect(()=>{n({"drag-handle":r,content:!r,created_at:!r,actions:!r}),m({pageSize:r?99999:50,pageIndex:0})},[r]);const N=(z,$)=>{r&&(z.dataTransfer.setData("text/plain",$.toString()),z.currentTarget.classList.add("opacity-50"))},P=(z,$)=>{if(!r)return;z.preventDefault(),z.currentTarget.classList.remove("bg-muted");const E=parseInt(z.dataTransfer.getData("text/plain"));if(E===$)return;const K=[...w],[ds]=K.splice(E,1);K.splice($,0,ds),_(K)},f=async()=>{if(!r){i(!0);return}Td(w.map(z=>z.id)).then(()=>{A.success("排序保存成功"),i(!1),b()}).finally(()=>{i(!1)})},R=Me({data:w??[],columns:nx(b),state:{sorting:d,columnVisibility:a,rowSelection:s,columnFilters:l,columnSizing:h,pagination:C},enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:o,onColumnVisibilityChange:n,onColumnSizingChange:D,onPaginationChange:m,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),getSortedRowModel:Ke(),getFacetedRowModel:ls(),getFacetedUniqueValues:is(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(Ue,{table:R,toolbar:z=>e.jsx(ax,{table:z,refetch:b,saveOrder:f,isSortMode:r}),draggable:r,onDragStart:N,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:P,showPagination:!r})})}function lx(){return e.jsxs(ye,{children:[e.jsxs(Ne,{className:"flex items-center justify-between",children:[e.jsx(ke,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"公告管理"})}),e.jsx("p",{className:"text-muted-foreground",children:"在这里可以配置公告,包括添加、删除、编辑等操作。"})]})}),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(rx,{})})]})]})}const ix=Object.freeze(Object.defineProperty({__proto__:null,default:lx},Symbol.toStringTag,{value:"Module"})),ox=u.object({id:u.number().nullable(),language:u.string().max(250),category:u.string().max(250),title:u.string().min(1).max(250),body:u.string().min(1),show:u.boolean()}),cx={id:null,language:"zh-CN",category:"",title:"",body:"",show:!1};function Er({refreshData:s,dialogTrigger:t,type:a="add",defaultFormValues:n=cx}){const[l,o]=c.useState(!1),d=ae({resolver:ie(ox),defaultValues:n,mode:"onChange",shouldFocusError:!0}),x=new na({html:!0});return c.useEffect(()=>{l&&n.id&&ed(n.id).then(({data:r})=>{d.reset(r)})},[n.id,d,l]),e.jsxs(ue,{onOpenChange:o,open:l,children:[e.jsx(Ie,{asChild:!0,children:t||e.jsxs(T,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(ve,{icon:"ion:add"})," ",e.jsx("div",{children:"添加知识"})]})}),e.jsxs(ce,{className:"sm:max-w-[1025px]",children:[e.jsxs(he,{children:[e.jsx(xe,{children:a==="add"?"添加知识":"编辑知识"}),e.jsx(Se,{})]}),e.jsxs(oe,{...d,children:[e.jsx(g,{control:d.control,name:"title",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"标题"}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(S,{placeholder:"请输入知识标题",...r})})}),e.jsx(k,{})]})}),e.jsx(g,{control:d.control,name:"category",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"分类"}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(S,{placeholder:"请输入分类,分类将会自动归类",...r})})}),e.jsx(k,{})]})}),e.jsx(g,{control:d.control,name:"language",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"语言"}),e.jsx(y,{children:e.jsxs(G,{value:r.value,onValueChange:r.onChange,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择语言"})}),e.jsx(B,{children:[{field:"English",value:"en-US"},{field:"日本語",value:"ja-JP"},{field:"한국어",value:"ko-KR"},{field:"Tiếng Việt",value:"vi-VN"},{field:"简体中文",value:"zh-CN"},{field:"繁體中文",value:"zh-TW"}].map(i=>e.jsx(O,{value:i.value,className:"cursor-pointer",children:i.field},i.value))})]})})]})}),e.jsx(g,{control:d.control,name:"body",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"内容"}),e.jsx(y,{children:e.jsx(ra,{style:{height:"500px"},value:r.value,renderHTML:i=>x.render(i),onChange:({text:i})=>{r.onChange(i)}})}),e.jsx(k,{})]})}),e.jsx(g,{control:d.control,name:"show",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"显示"}),e.jsx("div",{className:"relative py-2",children:e.jsx(y,{children:e.jsx(H,{checked:r.value,onCheckedChange:r.onChange})})}),e.jsx(k,{})]})}),e.jsxs(Re,{children:[e.jsx(ot,{asChild:!0,children:e.jsx(T,{type:"button",variant:"outline",children:"取消"})}),e.jsx(T,{type:"submit",onClick:()=>{d.handleSubmit(r=>{sd(r).then(({data:i})=>{i&&(d.reset(),A.success("操作成功"),o(!1),s())})})()},children:"提交"})]})]})]})]})}function dx({column:s,title:t,options:a}){const n=s?.getFacetedUniqueValues(),l=new Set(s?.getFilterValue());return e.jsxs(Ze,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(T,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(it,{className:"mr-2 h-4 w-4"}),t,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(L,{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(L,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[l.size," selected"]}):a.filter(o=>l.has(o.value)).map(o=>e.jsx(L,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:o.label},o.value))})]})]})}),e.jsx(qe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ps,{children:[e.jsx(Ps,{placeholder:t}),e.jsxs(vs,{children:[e.jsx(Vs,{children:"No results found."}),e.jsx(Ve,{children:a.map(o=>{const d=l.has(o.value);return e.jsxs(be,{onSelect:()=>{d?l.delete(o.value):l.add(o.value);const x=Array.from(l);s?.setFilterValue(x.length?x:void 0)},children:[e.jsx("div",{className:v("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",d?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ks,{className:v("h-4 w-4")})}),o.icon&&e.jsx(o.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:o.label}),n?.get(o.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:n.get(o.value)})]},o.value)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Ve,{children:e.jsx(be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function ux({table:s,refetch:t,saveOrder:a,isSortMode:n}){const l=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between",children:[n?e.jsx("p",{className:"text-sm text-muted-foreground",children:"拖拽知识条目进行排序,完成后点击保存"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Er,{refreshData:t}),e.jsx(S,{placeholder:"搜索知识...",value:s.getColumn("title")?.getFilterValue()??"",onChange:o=>s.getColumn("title")?.setFilterValue(o.target.value),className:"h-8 w-[250px]"}),s.getColumn("category")&&e.jsx(dx,{column:s.getColumn("category"),title:"分类",options:Array.from(new Set(s.getCoreRowModel().rows.map(o=>o.getValue("category")))).map(o=>({label:o,value:o}))}),l&&e.jsxs(T,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:["重置",e.jsx(Fe,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(T,{variant:n?"default":"outline",onClick:a,size:"sm",children:n?"保存排序":"编辑排序"})})]})}const xx=({refetch:s,isSortMode:t=!1})=>[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:t?"cursor-move":"opacity-0",children:e.jsx(Tt,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:a})=>e.jsx(V,{column:a,title:"ID"}),cell:({row:a})=>e.jsx(L,{variant:"outline",className:"justify-center",children:a.getValue("id")}),enableSorting:!0,size:70},{accessorKey:"show",header:({column:a})=>e.jsx(V,{column:a,title:"状态"}),cell:({row:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx(H,{defaultChecked:a.getValue("show"),onCheckedChange:async()=>{ad({id:a.original.id}).then(({data:n})=>{n||s()})}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:a})=>e.jsx(V,{column:a,title:"标题"}),cell:({row:a})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"line-clamp-2 font-medium",children:a.getValue("title")})}),enableSorting:!0,size:600},{accessorKey:"category",header:({column:a})=>e.jsx(V,{column:a,title:"分类"}),cell:({row:a})=>e.jsx(L,{variant:"secondary",className:"max-w-[180px] truncate",children:a.getValue("category")}),enableSorting:!0,size:1800},{id:"actions",header:({column:a})=>e.jsx(V,{className:"justify-end",column:a,title:"操作"}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx(Er,{refreshData:s,dialogTrigger:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Ds,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:"编辑"})]}),type:"edit",defaultFormValues:a.original}),e.jsx(Be,{title:"确认删除",description:"此操作将永久删除该知识库记录,删除后无法恢复。确定要继续吗?",confirmText:"删除",variant:"destructive",onConfirm:async()=>{td({id:a.original.id}).then(({data:n})=>{n&&(A.success("删除成功"),s())})},children:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(rs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:"删除"})]})})]}),size:100}];function mx(){const[s,t]=c.useState([]),[a,n]=c.useState([]),[l,o]=c.useState(!1),[d,x]=c.useState([]),[r,i]=c.useState({"drag-handle":!1}),[h,D]=c.useState({pageSize:20,pageIndex:0}),{refetch:C,isLoading:m,data:w}=Q({queryKey:["knowledge"],queryFn:async()=>{const{data:f}=await Xc();return x(f||[]),f}});c.useEffect(()=>{i({"drag-handle":l}),D({pageSize:l?99999:10,pageIndex:0})},[l]);const _=(f,R)=>{l&&(f.dataTransfer.setData("text/plain",R.toString()),f.currentTarget.classList.add("opacity-50"))},b=(f,R)=>{if(!l)return;f.preventDefault(),f.currentTarget.classList.remove("bg-muted");const z=parseInt(f.dataTransfer.getData("text/plain"));if(z===R)return;const $=[...d],[E]=$.splice(z,1);$.splice(R,0,E),x($)},N=async()=>{l?nd({ids:d.map(f=>f.id)}).then(()=>{C(),o(!1),A.success("排序保存成功")}):o(!0)},P=Me({data:d,columns:xx({refetch:C,isSortMode:l}),state:{sorting:a,columnFilters:s,columnVisibility:r,pagination:h},onSortingChange:n,onColumnFiltersChange:t,onColumnVisibilityChange:i,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),getSortedRowModel:Ke(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Ue,{table:P,toolbar:f=>e.jsx(ux,{table:f,refetch:C,saveOrder:N,isSortMode:l}),draggable:l,onDragStart:_,onDragEnd:f=>f.currentTarget.classList.remove("opacity-50"),onDragOver:f=>{f.preventDefault(),f.currentTarget.classList.add("bg-muted")},onDragLeave:f=>f.currentTarget.classList.remove("bg-muted"),onDrop:b,showPagination:!l})}function hx(){return e.jsxs(ye,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"知识库管理"}),e.jsx("p",{className:"text-muted-foreground",children:"在这里可以配置知识库,包括添加、删除、编辑等操作。"})]})}),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(mx,{})})]})]})}const jx=Object.freeze(Object.defineProperty({__proto__:null,default:hx},Symbol.toStringTag,{value:"Module"}));function gx(s,t){const[a,n]=c.useState(s);return c.useEffect(()=>{const l=setTimeout(()=>n(s),t);return()=>{clearTimeout(l)}},[s,t]),a}function Ot(s,t){if(s.length===0)return{};if(!t)return{"":s};const a={};return s.forEach(n=>{const l=n[t]||"";a[l]||(a[l]=[]),a[l].push(n)}),a}function fx(s,t){const a=JSON.parse(JSON.stringify(s));for(const[n,l]of Object.entries(a))a[n]=l.filter(o=>!t.find(d=>d.value===o.value));return a}function px(s,t){for(const[,a]of Object.entries(s))if(a.some(n=>t.find(l=>l.value===n.value)))return!0;return!1}const Fr=c.forwardRef(({className:s,...t},a)=>co(l=>l.filtered.count===0)?e.jsx("div",{ref:a,className:v("py-6 text-center text-sm",s),"cmdk-empty":"",role:"presentation",...t}):null);Fr.displayName="CommandEmpty";const nt=c.forwardRef(({value:s,onChange:t,placeholder:a,defaultOptions:n=[],options:l,delay:o,onSearch:d,loadingIndicator:x,emptyIndicator:r,maxSelected:i=Number.MAX_SAFE_INTEGER,onMaxSelected:h,hidePlaceholderWhenSelected:D,disabled:C,groupBy:m,className:w,badgeClassName:_,selectFirstItem:b=!0,creatable:N=!1,triggerSearchOnFocus:P=!1,commandProps:f,inputProps:R,hideClearAllButton:z=!1},$)=>{const E=c.useRef(null),[K,ds]=c.useState(!1),Ks=c.useRef(!1),[va,ba]=c.useState(!1),[J,qs]=c.useState(s||[]),[ys,ya]=c.useState(Ot(n,m)),[us,Ft]=c.useState(""),Us=gx(us,o||500);c.useImperativeHandle($,()=>({selectedValue:[...J],input:E.current,focus:()=>E.current?.focus()}),[J]);const ct=c.useCallback(q=>{const Z=J.filter(Ce=>Ce.value!==q.value);qs(Z),t?.(Z)},[t,J]),ll=c.useCallback(q=>{const Z=E.current;Z&&((q.key==="Delete"||q.key==="Backspace")&&Z.value===""&&J.length>0&&(J[J.length-1].fixed||ct(J[J.length-1])),q.key==="Escape"&&Z.blur())},[ct,J]);c.useEffect(()=>{s&&qs(s)},[s]),c.useEffect(()=>{if(!l||d)return;const q=Ot(l||[],m);JSON.stringify(q)!==JSON.stringify(ys)&&ya(q)},[n,l,m,d,ys]),c.useEffect(()=>{const q=async()=>{ba(!0);const Ce=await d?.(Us);ya(Ot(Ce||[],m)),ba(!1)};(async()=>{!d||!K||(P&&await q(),Us&&await q())})()},[Us,m,K,P]);const il=()=>{if(!N||px(ys,[{value:us,label:us}])||J.find(Z=>Z.value===us))return;const q=e.jsx(be,{value:us,className:"cursor-pointer",onMouseDown:Z=>{Z.preventDefault(),Z.stopPropagation()},onSelect:Z=>{if(J.length>=i){h?.(J.length);return}Ft("");const Ce=[...J,{value:Z,label:Z}];qs(Ce),t?.(Ce)},children:`Create "${us}"`});if(!d&&us.length>0||d&&Us.length>0&&!va)return q},ol=c.useCallback(()=>{if(r)return d&&!N&&Object.keys(ys).length===0?e.jsx(be,{value:"-",disabled:!0,children:r}):e.jsx(Fr,{children:r})},[N,r,d,ys]),cl=c.useMemo(()=>fx(ys,J),[ys,J]),dl=c.useCallback(()=>{if(f?.filter)return f.filter;if(N)return(q,Z)=>q.toLowerCase().includes(Z.toLowerCase())?1:-1},[N,f?.filter]),ul=c.useCallback(()=>{const q=J.filter(Z=>Z.fixed);qs(q),t?.(q)},[t,J]);return e.jsxs(ps,{...f,onKeyDown:q=>{ll(q),f?.onKeyDown?.(q)},className:v("h-auto overflow-visible bg-transparent",f?.className),shouldFilter:f?.shouldFilter!==void 0?f.shouldFilter:!d,filter:dl(),children:[e.jsx("div",{className:v("rounded-md border border-input text-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring ",{"px-3 py-2":J.length!==0,"cursor-text":!C&&J.length!==0},w),onClick:()=>{C||E.current?.focus()},children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[J.map(q=>e.jsxs(L,{className:v("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":q.fixed,"data-disabled":C||void 0,children:[q.label,e.jsx("button",{className:v("ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",(C||q.fixed)&&"hidden"),onKeyDown:Z=>{Z.key==="Enter"&&ct(q)},onMouseDown:Z=>{Z.preventDefault(),Z.stopPropagation()},onClick:()=>ct(q),children:e.jsx(Ut,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},q.value)),e.jsx(we.Input,{...R,ref:E,value:us,disabled:C,onValueChange:q=>{Ft(q),R?.onValueChange?.(q)},onBlur:q=>{Ks.current===!1&&ds(!1),R?.onBlur?.(q)},onFocus:q=>{ds(!0),P&&d?.(Us),R?.onFocus?.(q)},placeholder:D&&J.length!==0?"":a,className:v("flex-1 bg-transparent outline-none placeholder:text-muted-foreground",{"w-full":D,"px-3 py-2":J.length===0,"ml-1":J.length!==0},R?.className)}),e.jsx("button",{type:"button",onClick:ul,className:v((z||C||J.length<1||J.filter(q=>q.fixed).length===J.length)&&"hidden"),children:e.jsx(Ut,{})})]})}),e.jsx("div",{className:"relative",children:K&&e.jsx(vs,{className:"absolute top-1 z-10 w-full rounded-md border bg-popover text-popover-foreground shadow-md outline-none animate-in",onMouseLeave:()=>{Ks.current=!1},onMouseEnter:()=>{Ks.current=!0},onMouseUp:()=>{E.current?.focus()},children:va?e.jsx(e.Fragment,{children:x}):e.jsxs(e.Fragment,{children:[ol(),il(),!b&&e.jsx(be,{value:"-",className:"hidden"}),Object.entries(cl).map(([q,Z])=>e.jsx(Ve,{heading:q,className:"h-full overflow-auto",children:e.jsx(e.Fragment,{children:Z.map(Ce=>e.jsx(be,{value:Ce.value,disabled:Ce.disable,onMouseDown:Bs=>{Bs.preventDefault(),Bs.stopPropagation()},onSelect:()=>{if(J.length>=i){h?.(J.length);return}Ft("");const Bs=[...J,Ce];qs(Bs),t?.(Bs)},className:v("cursor-pointer",Ce.disable&&"cursor-default text-muted-foreground"),children:Ce.label},Ce.value))})},q))]})})})]})});nt.displayName="MultipleSelector";const vx=u.object({id:u.number().optional(),name:u.string().min(2,"组名至少需要2个字符").max(50,"组名不能超过50个字符").regex(/^[a-zA-Z0-9\u4e00-\u9fa5_-]+$/,"组名只能包含字母、数字、中文、下划线和连字符")});function Et({refetch:s,dialogTrigger:t,defaultValues:a={name:""},type:n="add"}){const l=ae({resolver:ie(vx),defaultValues:a,mode:"onChange"}),[o,d]=c.useState(!1),[x,r]=c.useState(!1),i=async h=>{r(!0),Oc(h).then(()=>{A.success(n==="edit"?"更新成功":"创建成功"),s&&s(),l.reset(),d(!1)}).finally(()=>{r(!1)})};return e.jsxs(ue,{open:o,onOpenChange:d,children:[e.jsx(Ie,{asChild:!0,children:t||e.jsxs(T,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("span",{children:"添加权限组"})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(xe,{children:n==="edit"?"编辑权限组":"创建权限组"}),e.jsx(Se,{children:n==="edit"?"修改权限组信息,更新后会立即生效。":"创建新的权限组,可以为不同的用户分配不同的权限。"})]}),e.jsx(oe,{...l,children:e.jsxs("form",{onSubmit:l.handleSubmit(i),className:"space-y-4",children:[e.jsx(g,{control:l.control,name:"name",render:({field:h})=>e.jsxs(j,{children:[e.jsx(p,{children:"组名称"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入权限组名称",...h,className:"w-full"})}),e.jsx(F,{children:"权限组名称用于标识不同的用户组,建议使用有意义的名称。"}),e.jsx(k,{})]})}),e.jsxs(Re,{className:"gap-2",children:[e.jsx(ot,{asChild:!0,children:e.jsx(T,{type:"button",variant:"outline",children:"取消"})}),e.jsxs(T,{type:"submit",disabled:x||!l.formState.isValid,children:[x&&e.jsx(aa,{className:"mr-2 h-4 w-4 animate-spin"}),n==="edit"?"更新":"创建"]})]})]})})]})]})}const Mr=c.createContext(void 0);function bx({children:s,refetch:t}){const[a,n]=c.useState(!1),[l,o]=c.useState(null),[d,x]=c.useState(fe.Shadowsocks);return e.jsx(Mr.Provider,{value:{isOpen:a,setIsOpen:n,editingServer:l,setEditingServer:o,serverType:d,setServerType:x,refetch:t},children:s})}function zr(){const s=c.useContext(Mr);if(s===void 0)throw new Error("useServerEdit must be used within a ServerEditProvider");return s}function Lt({dialogTrigger:s,value:t,setValue:a,templateType:n}){c.useEffect(()=>{console.log(t)},[t]);const[l,o]=c.useState(!1),[d,x]=c.useState(()=>{if(!t||Object.keys(t).length===0)return"";try{return JSON.stringify(t,null,2)}catch{return""}}),[r,i]=c.useState(null),h=b=>{if(!b)return null;try{const N=JSON.parse(b);return typeof N!="object"||N===null?"配置必须是一个JSON对象":null}catch{return"无效的JSON格式"}},D={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"}}}},C=()=>{switch(n){case"tcp":return["tcp","tcp-http"];case"grpc":return["grpc"];case"ws":return["ws"];default:return[]}},m=()=>{const b=h(d||"");if(b){A.error(b);return}try{if(!d){a(null),o(!1);return}a(JSON.parse(d)),o(!1)}catch{A.error("保存时发生错误")}},w=b=>{x(b),i(h(b))},_=b=>{const N=D[b];if(N){const P=JSON.stringify(N.content,null,2);x(P),i(null)}};return c.useEffect(()=>{l&&console.log(t)},[l,t]),c.useEffect(()=>{l&&t&&Object.keys(t).length>0&&x(JSON.stringify(t,null,2))},[l,t]),e.jsxs(ue,{open:l,onOpenChange:b=>{!b&&l&&m(),o(b)},children:[e.jsx(Ie,{asChild:!0,children:s??e.jsx(W,{variant:"link",children:"编辑协议"})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsx(he,{children:e.jsx(xe,{children:"编辑协议配置"})}),e.jsxs("div",{className:"space-y-4",children:[C().length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:C().map(b=>e.jsxs(W,{variant:"outline",size:"sm",onClick:()=>_(b),children:["使用",D[b].label,"模板"]},b))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(bs,{className:`min-h-[200px] font-mono text-sm ${r?"border-red-500 focus-visible:ring-red-500":""}`,value:d,placeholder:`请输入JSON配置${C().length>0?"或选择上方模板":""}`,onChange:b=>w(b.target.value)}),r&&e.jsx("p",{className:"text-sm text-red-500",children:r})]})]}),e.jsxs(Re,{className:"gap-2",children:[e.jsx(W,{variant:"outline",onClick:()=>o(!1),children:"取消"}),e.jsx(W,{onClick:m,disabled:!!r,children:"确定"})]})]})]})}function vh(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 yx={},Nx=Object.freeze(Object.defineProperty({__proto__:null,default:yx},Symbol.toStringTag,{value:"Module"})),bh=No(Nx),Aa=s=>s.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),wx=()=>{try{const s=uo.box.keyPair(),t=Aa(Ta.encodeBase64(s.secretKey)),a=Aa(Ta.encodeBase64(s.publicKey));return{privateKey:t,publicKey:a}}catch(s){throw console.error("Error generating x25519 key pair:",s),s}},_x=()=>{try{return wx()}catch(s){throw console.error("Error generating key pair:",s),s}},Cx=s=>{const t=new Uint8Array(Math.ceil(s/2));return window.crypto.getRandomValues(t),Array.from(t).map(a=>a.toString(16).padStart(2,"0")).join("").substring(0,s)},Sx=()=>{const s=Math.floor(Math.random()*8)*2+2;return Cx(s)},kx=u.object({cipher:u.string().default("aes-128-gcm"),obfs:u.string().default("0"),obfs_settings:u.object({path:u.string().default(""),host:u.string().default("")}).default({})}),Tx=u.object({tls:u.coerce.number().default(0),tls_settings:u.object({server_name:u.string().default(""),allow_insecure:u.boolean().default(!1)}).default({}),network:u.string().default("tcp"),network_settings:u.record(u.any()).default({})}),Dx=u.object({server_name:u.string().default(""),allow_insecure:u.boolean().default(!1),network:u.string().default("tcp"),network_settings:u.record(u.any()).default({})}),Px=u.object({version:u.coerce.number().default(2),alpn:u.string().default("h2"),obfs:u.object({open:u.coerce.boolean().default(!1),type:u.string().default("salamander"),password:u.string().default("")}).default({}),tls:u.object({server_name:u.string().default(""),allow_insecure:u.boolean().default(!1)}).default({}),bandwidth:u.object({up:u.string().default(""),down:u.string().default("")}).default({})}),Vx=u.object({tls:u.coerce.number().default(0),tls_settings:u.object({server_name:u.string().default(""),allow_insecure:u.boolean().default(!1)}).default({}),reality_settings:u.object({server_port:u.coerce.number().default(443),server_name:u.string().default(""),allow_insecure:u.boolean().default(!1),public_key:u.string().default(""),private_key:u.string().default(""),short_id:u.string().default("")}).default({}),network:u.string().default("tcp"),network_settings:u.record(u.any()).default({}),flow:u.string().default("")}),es={shadowsocks:{schema:kx,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:Tx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},trojan:{schema:Dx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},hysteria:{schema:Px,versions:["1","2"],alpnOptions:["hysteria","http/1.1","h2","h3"]},vless:{schema:Vx,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"]}},Ix=({serverType:s,value:t,onChange:a})=>{const n=s?es[s]:null,l=n?.schema||u.record(u.any()),o=s?l.parse({}):{},d=ae({resolver:ie(l),defaultValues:o,mode:"onChange"});return c.useEffect(()=>{if(!t||Object.keys(t).length===0){if(s){const m=l.parse({});d.reset(m)}}else d.reset(t)},[s,t,a,d,l]),c.useEffect(()=>{const m=d.watch(w=>{a(w)});return()=>m.unsubscribe()},[d,a]),!s||!n?null:{shadowsocks:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"cipher",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"加密算法"}),e.jsx(y,{children:e.jsxs(G,{onValueChange:m.onChange,value:m.value,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"选择加密算法"})}),e.jsx(B,{children:e.jsx(xs,{children:es.shadowsocks.ciphers.map(w=>e.jsx(O,{value:w,children:w},w))})})]})})]})}),e.jsx(g,{control:d.control,name:"obfs",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"混淆"}),e.jsx(y,{children:e.jsxs(G,{onValueChange:m.onChange,value:m.value,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"选择混淆方式"})}),e.jsx(B,{children:e.jsxs(xs,{children:[e.jsx(O,{value:"0",children:"无"}),e.jsx(O,{value:"http",children:"HTTP"})]})})]})})]})}),d.watch("obfs")==="http"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"obfs_settings.path",render:({field:m})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(y,{children:e.jsx(S,{type:"text",placeholder:"路径",...m})}),e.jsx(k,{})]})}),e.jsx(g,{control:d.control,name:"obfs_settings.host",render:({field:m})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(y,{children:e.jsx(S,{type:"text",placeholder:"Host",...m})}),e.jsx(k,{})]})})]})]}),vmess:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"tls",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"TLS"}),e.jsx(y,{children:e.jsxs(G,{value:m.value?.toString(),onValueChange:w=>m.onChange(Number(w)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择安全性"})}),e.jsxs(B,{children:[e.jsx(O,{value:"0",children:"不支持"}),e.jsx(O,{value:"1",children:"支持"})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls_settings.server_name",render:({field:m})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(p,{children:"服务器名称指示(SNI)"}),e.jsx(y,{children:e.jsx(S,{placeholder:"不使用请留空",...m})})]})}),e.jsx(g,{control:d.control,name:"tls_settings.allow_insecure",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"允许不安全?"}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(H,{checked:m.value,onCheckedChange:m.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"network",render:({field:m})=>e.jsxs(j,{children:[e.jsxs(p,{children:["传输协议",e.jsx(Lt,{value:d.watch("network_settings"),setValue:w=>d.setValue("network_settings",w),templateType:d.watch("network")})]}),e.jsx(y,{children:e.jsxs(G,{onValueChange:m.onChange,value:m.value,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"选择传输协议"})}),e.jsx(B,{children:e.jsx(xs,{children:es.vmess.networkOptions.map(w=>e.jsx(O,{value:w.value,className:"cursor-pointer",children:w.label},w.value))})})]})})]})})]}),trojan:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"server_name",render:({field:m})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(p,{children:"服务器名称指示(SNI)"}),e.jsx(y,{children:e.jsx(S,{placeholder:"当节点地址于证书不一致时用于证书验证",...m,value:m.value||""})})]})}),e.jsx(g,{control:d.control,name:"allow_insecure",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"允许不安全?"}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(H,{checked:m.value||!1,onCheckedChange:m.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"network",render:({field:m})=>e.jsxs(j,{children:[e.jsxs(p,{children:["传输协议",e.jsx(Lt,{value:d.watch("network_settings")||{},setValue:w=>d.setValue("network_settings",w),templateType:d.watch("network")||"tcp"})]}),e.jsx(y,{children:e.jsxs(G,{onValueChange:m.onChange,value:m.value||"tcp",children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"选择传输协议"})}),e.jsx(B,{children:e.jsx(xs,{children:es.trojan.networkOptions.map(w=>e.jsx(O,{value:w.value,className:"cursor-pointer",children:w.label},w.value))})})]})})]})})]}),hysteria:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"version",render:({field:m})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(p,{children:"协议版本"}),e.jsx(y,{children:e.jsxs(G,{value:(m.value||2).toString(),onValueChange:w=>m.onChange(Number(w)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"协议版本"})}),e.jsx(B,{children:e.jsx(xs,{children:es.hysteria.versions.map(w=>e.jsxs(O,{value:w,className:"cursor-pointer",children:["V",w]},w))})})]})})]})}),d.watch("version")==1&&e.jsx(g,{control:d.control,name:"alpn",render:({field:m})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(p,{children:"ALPN"}),e.jsx(y,{children:e.jsxs(G,{value:m.value||"h2",onValueChange:m.onChange,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"ALPN"})}),e.jsx(B,{children:e.jsx(xs,{children:es.hysteria.alpnOptions.map(w=>e.jsx(O,{value:w,children:w},w))})})]})})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"obfs.open",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"混淆"}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(H,{checked:m.value||!1,onCheckedChange:m.onChange})})})]})}),!!d.watch("obfs.open")&&e.jsxs(e.Fragment,{children:[d.watch("version")=="2"&&e.jsx(g,{control:d.control,name:"obfs.type",render:({field:m})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(p,{children:"混淆实现"}),e.jsx(y,{children:e.jsxs(G,{value:m.value||"salamander",onValueChange:m.onChange,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"选择混淆实现"})}),e.jsx(B,{children:e.jsx(xs,{children:e.jsx(O,{value:"salamander",children:"Salamander"})})})]})})]})}),e.jsx(g,{control:d.control,name:"obfs.password",render:({field:m})=>e.jsxs(j,{className:d.watch("version")==2?"w-full":"flex-[2]",children:[e.jsx(p,{children:"混淆密码"}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{children:e.jsx(S,{placeholder:"请输入混淆密码",...m,value:m.value||"",className:"pr-9"})}),e.jsx(W,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const w="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",_=Array.from(crypto.getRandomValues(new Uint8Array(16))).map(b=>w[b%w.length]).join("");d.setValue("obfs.password",_),A.success("混淆密码生成成功")},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(ve,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})]})]})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls.server_name",render:({field:m})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(p,{children:"服务器名称指示(SNI)"}),e.jsx(y,{children:e.jsx(S,{placeholder:"当节点地址于证书不一致时用于证书验证",...m,value:m.value||""})})]})}),e.jsx(g,{control:d.control,name:"tls.allow_insecure",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"允许不安全?"}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(H,{checked:m.value||!1,onCheckedChange:m.onChange})})})]})})]}),e.jsx(g,{control:d.control,name:"bandwidth.up",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"上行宽带"}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入上行宽带"+(d.watch("version")==2?"留空则使用BBR":""),className:"rounded-br-none rounded-tr-none",...m,value:m.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:"Mbps"})})]})]})}),e.jsx(g,{control:d.control,name:"bandwidth.down",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"下行宽带"}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入下行宽带"+(d.watch("version")==2?"留空则使用BBR":""),className:"rounded-br-none rounded-tr-none",...m,value:m.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:"Mbps"})})]})]})})]}),vless:()=>e.jsxs(e.Fragment,{children:[e.jsx(g,{control:d.control,name:"tls",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"安全性"}),e.jsx(y,{children:e.jsxs(G,{value:m.value?.toString(),onValueChange:w=>m.onChange(Number(w)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择安全性"})}),e.jsxs(B,{children:[e.jsx(O,{value:"0",children:"无"}),e.jsx(O,{value:"1",children:"TLS"}),e.jsx(O,{value:"2",children:"Reality"})]})]})})]})}),d.watch("tls")=="1"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls_settings.server_name",render:({field:m})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(p,{children:"服务器名称指示(SNI)"}),e.jsx(y,{children:e.jsx(S,{placeholder:"不使用请留空",...m})})]})}),e.jsx(g,{control:d.control,name:"tls_settings.allow_insecure",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"允许不安全?"}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(H,{checked:m.value,onCheckedChange:m.onChange})})})]})})]}),d.watch("tls")==2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"reality_settings.server_name",render:({field:m})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(p,{children:"伪装站点(dest)"}),e.jsx(y,{children:e.jsx(S,{placeholder:"例如example.com",...m})})]})}),e.jsx(g,{control:d.control,name:"reality_settings.server_port",render:({field:m})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(p,{children:"端口(port)"}),e.jsx(y,{children:e.jsx(S,{placeholder:"例如443",...m})})]})}),e.jsx(g,{control:d.control,name:"reality_settings.allow_insecure",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"允许不安全?"}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(H,{checked:m.value,onCheckedChange:m.onChange})})})]})})]}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(g,{control:d.control,name:"reality_settings.private_key",render:({field:m})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(p,{children:"私钥(Private key)"}),e.jsx(y,{children:e.jsx(S,{...m})})]})}),e.jsxs(W,{variant:"outline",className:"",onClick:()=>{try{const m=_x();d.setValue("reality_settings.private_key",m.privateKey),d.setValue("reality_settings.public_key",m.publicKey),A.success("密钥对生成成功")}catch{A.error("生成密钥对失败")}},children:[e.jsx(ve,{icon:"ion:key-outline",className:"mr-2 h-4 w-4"}),"生成密钥对"]})]}),e.jsx(g,{control:d.control,name:"reality_settings.public_key",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"公钥(Public key)"}),e.jsx(y,{children:e.jsx(S,{...m})})]})}),e.jsx(g,{control:d.control,name:"reality_settings.short_id",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"Short ID"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{children:e.jsx(S,{...m,placeholder:"可留空长度为2的倍数最长16位"})}),e.jsxs(W,{variant:"outline",onClick:()=>{const w=Sx();d.setValue("reality_settings.short_id",w),A.success("Short ID 生成成功")},children:[e.jsx(ve,{icon:"ion:refresh-outline",className:"mr-2 h-4 w-4"}),"生成"]})]}),e.jsx(F,{className:"text-xs text-muted-foreground",children:"客户端可用的 shortId 列表可用于区分不同的客户端使用0-f的十六进制字符"})]})})]}),e.jsx(g,{control:d.control,name:"network",render:({field:m})=>e.jsxs(j,{children:[e.jsxs(p,{children:["传输协议",e.jsx(Lt,{value:d.watch("network_settings"),setValue:w=>d.setValue("network_settings",w),templateType:d.watch("network")})]}),e.jsx(y,{children:e.jsxs(G,{onValueChange:m.onChange,value:m.value,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"选择传输协议"})}),e.jsx(B,{children:e.jsx(xs,{children:es.vless.networkOptions.map(w=>e.jsx(O,{value:w.value,className:"cursor-pointer",children:w.label},w.value))})})]})})]})}),e.jsx(g,{control:d.control,name:"flow",render:({field:m})=>e.jsxs(j,{children:[e.jsx(p,{children:"流控"}),e.jsx(y,{children:e.jsxs(G,{onValueChange:w=>m.onChange(w==="none"?null:w),value:m.value||"none",children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"选择流控"})}),e.jsx(B,{children:es.vless.flowOptions.map(w=>e.jsx(O,{value:w,children:w},w))})]})})]})})]})}[s]?.()},Rx=u.object({id:u.number().optional().nullable(),code:u.string().optional(),name:u.string().min(1,"Please enter a valid name."),rate:u.string().min(1,"Please enter a valid rate."),tags:u.array(u.string()).default([]),excludes:u.array(u.string()).default([]),ips:u.array(u.string()).default([]),group_ids:u.array(u.string()).default([]),host:u.string().min(1,"Please enter a valid host."),port:u.string().min(1,"Please enter a valid port."),server_port:u.string().min(1,"Please enter a valid server port."),parent_id:u.string().default("0").nullable(),route_ids:u.array(u.string()).default([]),protocol_settings:u.record(u.any()).default({}).nullable()}),xt={id:null,code:"",name:"",rate:"1",tags:[],excludes:[],ips:[],group_ids:[],host:"",port:"",server_port:"",parent_id:"0",route_ids:[],protocol_settings:null};function Ex(){const{isOpen:s,setIsOpen:t,editingServer:a,setEditingServer:n,serverType:l,setServerType:o,refetch:d}=zr(),[x,r]=c.useState([]),[i,h]=c.useState([]),[D,C]=c.useState([]),m=ae({resolver:ie(Rx),defaultValues:xt,mode:"onChange"});c.useEffect(()=>{w()},[s]),c.useEffect(()=>{a?.type&&a.type!==l&&o(a.type)},[a,l,o]),c.useEffect(()=>{a?a.type===l&&m.reset({...xt,...a}):m.reset({...xt,protocol_settings:es[l].schema.parse({})})},[a,m,l]);const w=async()=>{if(!s)return;const[f,R,z]=await Promise.all([It(),jr(),hr()]);r(f.data?.map($=>({label:$.name,value:$.id.toString()}))||[]),h(R.data?.map($=>({label:$.remarks,value:$.id.toString()}))||[]),C(z.data||[])},_=c.useMemo(()=>D?.filter(f=>(f.parent_id===0||f.parent_id===null)&&f.type===l&&f.id!==m.watch("id")),[l,D,m]),b=()=>e.jsxs(_s,{children:[e.jsx(Cs,{asChild:!0,children:e.jsxs(T,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"添加节点"})]})}),e.jsx(fs,{align:"start",children:e.jsx(rc,{children:ws.map(({type:f,label:R})=>e.jsx(me,{onClick:()=>{o(f),t(!0)},className:"cursor-pointer",children:e.jsx(L,{variant:"outline",className:"text-white",style:{background:ts[f]},children:R})},f))})})]}),N=()=>{t(!1),n(null),m.reset(xt)},P=async()=>{const f=m.getValues();(await Rc({...f,type:l})).data&&(N(),A.success("提交成功"),d())};return e.jsxs(ue,{open:s,onOpenChange:N,children:[b(),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(xe,{children:a?"编辑节点":"新建节点"}),e.jsx(Se,{})]}),e.jsxs(oe,{...m,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:m.control,name:"name",render:({field:f})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(p,{children:"节点名称"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入节点名称",...f})}),e.jsx(k,{})]})}),e.jsx(g,{control:m.control,name:"rate",render:({field:f})=>e.jsxs(j,{className:"flex-[1]",children:[e.jsx(p,{children:"倍率"}),e.jsx("div",{className:"relative flex",children:e.jsx(y,{children:e.jsx(S,{type:"number",min:"0",step:"0.1",...f})})}),e.jsx(k,{})]})})]}),e.jsx(g,{control:m.control,name:"code",render:({field:f})=>e.jsxs(j,{children:[e.jsxs(p,{children:["自定义节点ID",e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:"(选填)"})]}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入自定义节点ID",...f,value:f.value||""})}),e.jsx(k,{})]})}),e.jsx(g,{control:m.control,name:"tags",render:({field:f})=>e.jsxs(j,{children:[e.jsx(p,{children:"节点标签"}),e.jsx(y,{children:e.jsx(ma,{value:f.value,onChange:f.onChange,placeholder:"输入后回车添加标签",className:"w-full"})}),e.jsx(k,{})]})}),e.jsx(g,{control:m.control,name:"group_ids",render:({field:f})=>e.jsxs(j,{children:[e.jsxs(p,{className:"flex items-center justify-between",children:["权限组",e.jsx(Et,{dialogTrigger:e.jsx(T,{variant:"link",children:"添加权限组"}),refetch:w})]}),e.jsx(y,{children:e.jsx(nt,{options:x,onChange:R=>f.onChange(R.map(z=>z.value)),value:x?.filter(R=>f.value.includes(R.value)),placeholder:"请选择权限组",emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:"no results found."})})}),e.jsx(k,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:m.control,name:"host",render:({field:f})=>e.jsxs(j,{children:[e.jsx(p,{children:"节点地址"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入节点域名或者IP",...f})}),e.jsx(k,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(g,{control:m.control,name:"port",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsxs(p,{className:"flex items-center gap-1.5",children:["连接端口",e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{asChild:!0,children:e.jsx(ve,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(Da,{children:e.jsx(ee,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:"用户实际连接使用的端口,这是客户端配置中需要填写的端口号。如果使用了中转或隧道,这个端口可能与服务器实际监听的端口不同。"})})})]})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(y,{children:e.jsx(S,{placeholder:"用户连接端口",...f})}),e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{asChild:!0,children:e.jsx(T,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const R=f.value;R&&m.setValue("server_port",R)},children:e.jsx(ve,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(ee,{side:"right",children:e.jsx("p",{children:"同步到服务端口"})})]})})]}),e.jsx(k,{})]})}),e.jsx(g,{control:m.control,name:"server_port",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsxs(p,{className:"flex items-center gap-1.5",children:["服务端口",e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{asChild:!0,children:e.jsx(ve,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(Da,{children:e.jsx(ee,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:"服务器实际监听的端口,这是在服务器上开放的真实端口。如果使用了中转或隧道,这个端口可能与用户连接端口不同。"})})})]})})]}),e.jsx(y,{children:e.jsx(S,{placeholder:"服务端开放端口",...f})}),e.jsx(k,{})]})})]})]}),s&&e.jsx(Ix,{serverType:l,value:m.watch("protocol_settings"),onChange:f=>m.setValue("protocol_settings",f,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(g,{control:m.control,name:"parent_id",render:({field:f})=>e.jsxs(j,{children:[e.jsx(p,{children:"父节点"}),e.jsxs(G,{onValueChange:f.onChange,value:f.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(U,{children:e.jsx(Y,{placeholder:"选择父节点"})})}),e.jsxs(B,{children:[e.jsx(O,{value:"0",children:"无"}),_?.map(R=>e.jsx(O,{value:R.id.toString(),className:"cursor-pointer",children:R.name},R.id))]})]}),e.jsx(k,{})]})}),e.jsx(g,{control:m.control,name:"route_ids",render:({field:f})=>e.jsxs(j,{children:[e.jsx(p,{children:"路由组"}),e.jsx(y,{children:e.jsx(nt,{options:i,onChange:R=>f.onChange(R.map(z=>z.value)),value:i?.filter(R=>f.value.includes(R.value)),placeholder:"选择路由组",emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:"no results found."})})}),e.jsx(k,{})]})})]}),e.jsxs(Re,{className:"mt-6",children:[e.jsx(T,{type:"button",variant:"outline",onClick:N,children:"取消"}),e.jsx(T,{type:"submit",onClick:P,children:"提交"})]})]})]})]})}function Ha({column:s,title:t,options:a}){const n=s?.getFacetedUniqueValues(),l=new Set(s?.getFilterValue());return e.jsxs(Ze,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(T,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(it,{className:"mr-2 h-4 w-4"}),t,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(L,{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(L,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[l.size," selected"]}):a.filter(o=>l.has(o.value)).map(o=>e.jsx(L,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:o.label},o.value))})]})]})}),e.jsx(qe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ps,{children:[e.jsx(Ps,{placeholder:t}),e.jsxs(vs,{children:[e.jsx(Vs,{children:"No results found."}),e.jsx(Ve,{children:a.map(o=>{const d=l.has(o.value);return e.jsxs(be,{onSelect:()=>{d?l.delete(o.value):l.add(o.value);const x=Array.from(l);s?.setFilterValue(x.length?x:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:v("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",d?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ks,{className:v("h-4 w-4")})}),o.icon&&e.jsx(o.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${o.color}`}),e.jsx("span",{children:o.label}),n?.get(o.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:n.get(o.value)})]},o.value)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Ve,{children:e.jsx(be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const Fx=[{value:fe.Shadowsocks,label:ws.find(s=>s.type===fe.Shadowsocks)?.label,color:ts[fe.Shadowsocks]},{value:fe.Vmess,label:ws.find(s=>s.type===fe.Vmess)?.label,color:ts[fe.Vmess]},{value:fe.Trojan,label:ws.find(s=>s.type===fe.Trojan)?.label,color:ts[fe.Trojan]},{value:fe.Hysteria,label:ws.find(s=>s.type===fe.Hysteria)?.label,color:ts[fe.Hysteria]},{value:fe.Vless,label:ws.find(s=>s.type===fe.Vless)?.label,color:ts[fe.Vless]}];function Mx({table:s,saveOrder:t,isSortMode:a,groups:n}){const l=s.getState().columnFilters.length>0,o=n.map(d=>({label:d,value:d}));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(Ex,{}),e.jsx(S,{placeholder:"搜索节点...",value:s.getColumn("name")?.getFilterValue()??"",onChange:d=>s.getColumn("name")?.setFilterValue(d.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(Ha,{column:s.getColumn("type"),title:"类型",options:Fx}),s.getColumn("groups")&&e.jsx(Ha,{column:s.getColumn("groups"),title:"权限组",options:o})]}),l&&e.jsxs(T,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["重置",e.jsx(Fe,{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:"拖拽节点进行排序,完成后点击保存"})})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(T,{variant:a?"default":"outline",onClick:t,size:"sm",children:a?"保存排序":"编辑排序"})})]})}const rt=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"})}),mt={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"},ht={0:"未运行",1:"无人使用或异常",2:"运行正常"},zx=s=>[{id:"drag-handle",header:({column:t})=>e.jsx(V,{column:t,title:"排序"}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Tt,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:t})=>e.jsx(V,{column:t,title:"节点ID"}),cell:({row:t})=>{const a=t.getValue("id"),n=t.original.code;return e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(L,{variant:"outline",className:v("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:ts[t.original.type]},children:[e.jsx($n,{className:"size-3"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:n??a}),t.original.parent?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-muted-foreground/30",children:"→"}),e.jsx("span",{children:t.original.parent?.code||t.original.parent?.id})]}):""]})]}),e.jsx(T,{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:l=>{l.stopPropagation(),Nt(n||a.toString())},children:e.jsx(Pa,{className:"size-3"})})]})}),e.jsxs(ee,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[ws.find(l=>l.type===t.original.type)?.label,t.original.parent_id?" (子节点)":""]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n?"点击括号内容或复制按钮可复制节点代码":"点击复制按钮可复制节点ID"})]})]})})},size:200,enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(V,{column:t,title:"显隐"}),cell:({row:t})=>{const[a,n]=c.useState(!!t.getValue("show"));return e.jsx(H,{checked:a,onCheckedChange:async l=>{n(l),Mc({id:t.original.id,type:t.original.type,show:l?1:0}).catch(()=>{n(!l),s()})},style:{backgroundColor:a?ts[t.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(V,{column:t,title:"节点",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:v("h-2.5 w-2.5 rounded-full",mt[0])}),e.jsx("span",{className:"text-sm font-medium",children:ht[0]})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:v("h-2.5 w-2.5 rounded-full",mt[1])}),e.jsx("span",{className:"text-sm font-medium",children:ht[1]})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:v("h-2.5 w-2.5 rounded-full",mt[2])}),e.jsx("span",{className:"text-sm font-medium",children:ht[2]})]})]})})}),cell:({row:t})=>e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:v("size-2.5 flex-shrink-0 rounded-full transition-all duration-200",mt[t.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:t.getValue("name")})]})}),e.jsx(ee,{children:e.jsx("p",{className:"font-medium",children:ht[t.original.available_status]})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:t})=>e.jsx(V,{column:t,title:"地址"}),cell:({row:t})=>{const a=`${t.original.host}:${t.original.port}`,n=t.original.port!==t.original.server_port;return e.jsxs("div",{className:"group relative flex min-w-0 items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-1 gap-y-0.5 pr-7",children:[e.jsx("div",{className:"flex items-center ",children:e.jsxs("span",{className:"font-mono text-sm font-medium text-foreground/90",children:[t.original.host,":",t.original.port]})}),n&&e.jsxs("span",{className:"whitespace-nowrap text-[0.7rem] tracking-tight text-muted-foreground/40",children:["(内部端口 ",t.original.server_port,")"]})]}),e.jsx("div",{className:"absolute right-0 top-0",children:e.jsx(le,{delayDuration:0,children:e.jsxs(se,{children:[e.jsx(te,{asChild:!0,children:e.jsx(T,{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:l=>{l.stopPropagation(),Nt(a)},children:e.jsx(Pa,{className:"size-3"})})}),e.jsx(ee,{side:"top",sideOffset:10,children:"复制连接地址"})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:t})=>e.jsx(V,{column:t,title:"在线人数",tooltip:"在线人数根据服务端上报频率而定"}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(rt,{className:"size-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("online")})]}),size:80,enableSorting:!0,enableHiding:!0},{accessorKey:"rate",header:({column:t})=>e.jsx(V,{column:t,title:"倍率",tooltip:"流量扣费倍率"}),cell:({row:t})=>e.jsxs(L,{variant:"secondary",className:"font-medium",children:[t.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"groups",header:({column:t})=>e.jsx(V,{column:t,title:"权限组",tooltip:"可订阅到该节点的权限组"}),cell:({row:t})=>{const a=t.getValue("groups")||[];return e.jsx("div",{className:"flex min-w-[300px] max-w-[600px] flex-wrap items-center gap-1.5",children:a.length>0?a.map((n,l)=>e.jsx(L,{variant:"secondary",className:v("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:n.name},l)):e.jsx("span",{className:"text-sm text-muted-foreground",children:"--"})})},enableSorting:!1,size:600,filterFn:(t,a,n)=>{const l=t.getValue(a);return l?n.some(o=>l.includes(o)):!1}},{accessorKey:"type",header:({column:t})=>e.jsx(V,{column:t,title:"类型"}),cell:({row:t})=>{const a=t.getValue("type");return e.jsx(L,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:ts[a]},children:a})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx(V,{className:"justify-end",column:t,title:"操作"}),cell:({row:t})=>{const{setIsOpen:a,setEditingServer:n,setServerType:l}=zr();return e.jsx("div",{className:"flex justify-center",children:e.jsxs(_s,{modal:!1,children:[e.jsx(Cs,{asChild:!0,children:e.jsx(T,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":"打开操作菜单",children:e.jsx(bt,{className:"size-4"})})}),e.jsxs(fs,{align:"end",className:"w-40",children:[e.jsx(me,{className:"cursor-pointer",onClick:()=>{l(t.original.type),n(t.original),a(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(xo,{className:"mr-2 size-4"}),"编辑"]})}),e.jsxs(me,{className:"cursor-pointer",onClick:async()=>{Fc({id:t.original.id}).then(({data:o})=>{o&&(A.success("复制成功"),s())})},children:[e.jsx(mo,{className:"mr-2 size-4"}),"复制"]}),e.jsx(et,{}),e.jsx(me,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:o=>o.preventDefault(),children:e.jsx(Be,{title:"确认删除",description:"此操作将永久删除该节点,删除后无法恢复。确定要继续吗?",confirmText:"删除",variant:"destructive",onConfirm:async()=>{Ec({id:t.original.id}).then(({data:o})=>{o&&(A.success("删除成功"),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(rs,{className:"mr-2 size-4"}),"删除"]})})})]})]})})},size:50}];function Ox(){const[s,t]=c.useState({}),[a,n]=c.useState({"drag-handle":!1}),[l,o]=c.useState([]),[d,x]=c.useState({pageSize:500,pageIndex:0}),[r,i]=c.useState([]),[h,D]=c.useState(!1),[C,m]=c.useState({}),[w,_]=c.useState([]),{refetch:b}=Q({queryKey:["nodeList"],queryFn:async()=>{const{data:$}=await hr();return _($),$}}),N=c.useMemo(()=>{const $=new Set;return w.forEach(E=>{E.groups&&E.groups.forEach(K=>$.add(K.name))}),Array.from($).sort()},[w]);c.useEffect(()=>{n({"drag-handle":h,show:!h,host:!h,online:!h,rate:!h,groups:!h,type:!1,actions:!h}),m({name:h?2e3:200}),x({pageSize:h?99999:500,pageIndex:0})},[h]);const P=($,E)=>{h&&($.dataTransfer.setData("text/plain",E.toString()),$.currentTarget.classList.add("opacity-50"))},f=($,E)=>{if(!h)return;$.preventDefault(),$.currentTarget.classList.remove("bg-muted");const K=parseInt($.dataTransfer.getData("text/plain"));if(K===E)return;const ds=[...w],[Ks]=ds.splice(K,1);ds.splice(E,0,Ks),_(ds)},R=async()=>{if(!h){D(!0);return}const $=w?.map((E,K)=>({id:E.id,order:K+1}));zc($).then(()=>{A.success("排序保存成功"),D(!1),b()}).finally(()=>{D(!1)})},z=Me({data:w||[],columns:zx(b),state:{sorting:r,columnVisibility:a,rowSelection:s,columnFilters:l,columnSizing:C,pagination:d},enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:i,onColumnFiltersChange:o,onColumnVisibilityChange:n,onColumnSizingChange:m,onPaginationChange:x,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),getSortedRowModel:Ke(),getFacetedRowModel:ls(),getFacetedUniqueValues:is(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(bx,{refetch:b,children:e.jsx("div",{className:"space-y-4",children:e.jsx(Ue,{table:z,toolbar:$=>e.jsx(Mx,{table:$,refetch:b,saveOrder:R,isSortMode:h,groups:N}),draggable:h,onDragStart:P,onDragEnd:$=>$.currentTarget.classList.remove("opacity-50"),onDragOver:$=>{$.preventDefault(),$.currentTarget.classList.add("bg-muted")},onDragLeave:$=>$.currentTarget.classList.remove("bg-muted"),onDrop:f,showPagination:!h})})})}function Lx(){return e.jsxs(ye,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"节点管理"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"管理所有节点,包括添加、删除、编辑等操作。"})]})}),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(Ox,{})})]})]})}const $x=Object.freeze(Object.defineProperty({__proto__:null,default:Lx},Symbol.toStringTag,{value:"Module"}));function Ax({table:s,refetch:t}){const a=s.getState().columnFilters.length>0;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(Et,{refetch:t}),e.jsx(S,{placeholder:"搜索权限组...",value:s.getColumn("name")?.getFilterValue()??"",onChange:n=>s.getColumn("name")?.setFilterValue(n.target.value),className:v("h-8 w-[150px] lg:w-[250px]",a&&"border-primary/50 ring-primary/20")}),a&&e.jsxs(T,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["重置",e.jsx(Fe,{className:"ml-2 h-4 w-4"})]})]})})}const Hx=s=>[{accessorKey:"id",header:({column:t})=>e.jsx(V,{column:t,title:"组ID"}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(L,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:t})=>e.jsx(V,{column:t,title:"组名称"}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium",children:t.getValue("name")})})},{accessorKey:"users_count",header:({column:t})=>e.jsx(V,{column:t,title:"用户数量"}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(rt,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"server_count",header:({column:t})=>e.jsx(V,{column:t,title:"节点数量"}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx($n,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("server_count")})]}),enableSorting:!0,size:8e3},{id:"actions",header:({column:t})=>e.jsx(V,{className:"justify-end",column:t,title:"操作"}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Et,{defaultValues:t.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Ds,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:"编辑"})]})}),e.jsx(Be,{title:"确认删除",description:"此操作将永久删除该权限组,删除后无法恢复。确定要继续吗?",confirmText:"删除",variant:"destructive",onConfirm:async()=>{Lc({id:t.original.id}).then(({data:a})=>{a&&(A.success("删除成功"),s())})},children:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(rs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:"删除"})]})})]})}];function Kx(){const[s,t]=c.useState({}),[a,n]=c.useState({}),[l,o]=c.useState([]),[d,x]=c.useState([]),{data:r,refetch:i,isLoading:h}=Q({queryKey:["serverGroupList"],queryFn:async()=>{const{data:C}=await It();return C}}),D=Me({data:r||[],columns:Hx(i),state:{sorting:d,columnVisibility:a,rowSelection:s,columnFilters:l},enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:o,onColumnVisibilityChange:n,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),getSortedRowModel:Ke(),getFacetedRowModel:ls(),getFacetedUniqueValues:is(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Ue,{table:D,toolbar:C=>e.jsx(Ax,{table:C,refetch:i}),isLoading:h})}function qx(){return e.jsxs(ye,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"权限组管理"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"管理所有权限组,包括添加、删除、编辑等操作。"})]})}),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(Kx,{})})]})]})}const Ux=Object.freeze(Object.defineProperty({__proto__:null,default:qx},Symbol.toStringTag,{value:"Module"})),Bx=u.object({remarks:u.string().min(1,"Please enter a valid remarks."),match:u.array(u.string()),action:u.enum(["block","dns"]),action_value:u.string().optional()});function Or({refetch:s,dialogTrigger:t,defaultValues:a={remarks:"",match:[],action:"block",action_value:""},type:n="add"}){const l=ae({resolver:ie(Bx),defaultValues:a,mode:"onChange"}),[o,d]=c.useState(!1);return e.jsxs(ue,{open:o,onOpenChange:d,children:[e.jsx(Ie,{asChild:!0,children:t||e.jsxs(T,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(ve,{icon:"ion:add"})," ",e.jsx("div",{children:"添加路由"})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(xe,{children:n==="edit"?"编辑路由":"创建路由"}),e.jsx(Se,{})]}),e.jsxs(oe,{...l,children:[e.jsx(g,{control:l.control,name:"remarks",render:({field:x})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(p,{children:"备注"}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(S,{type:"text",placeholder:"请输入备注",...x})})}),e.jsx(k,{})]})}),e.jsx(g,{control:l.control,name:"match",render:({field:x})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(p,{children:"备注"}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(bs,{className:"min-h-[120px]",placeholder:`example.com
*.example.com`,value:x.value.join(`
`),onChange:r=>{x.onChange(r.target.value.split(`
`))}})})}),e.jsx(k,{})]})}),e.jsx(g,{control:l.control,name:"action",render:({field:x})=>e.jsxs(j,{children:[e.jsx(p,{children:"动作"}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsxs(G,{onValueChange:x.onChange,defaultValue:x.value,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择动作"})}),e.jsxs(B,{children:[e.jsx(O,{value:"block",children:"禁止访问"}),e.jsx(O,{value:"dns",children:"指定DNS服务器进行解析"})]})]})})}),e.jsx(k,{})]})}),l.watch("action")==="dns"&&e.jsx(g,{control:l.control,name:"action_value",render:({field:x})=>e.jsxs(j,{children:[e.jsx(p,{children:"DNS服务器"}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(S,{type:"text",placeholder:"请输入DNS服务器",...x})})})]})}),e.jsxs(Re,{children:[e.jsx(ot,{asChild:!0,children:e.jsx(T,{variant:"outline",children:"取消"})}),e.jsx(T,{type:"submit",onClick:()=>{$c(l.getValues()).then(({data:x})=>{x&&(d(!1),s&&s(),l.reset())})},children:"提交"})]})]})]})]})}function Gx({table:s,refetch:t}){const a=s.getState().columnFilters.length>0;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(Or,{refetch:t}),e.jsx(S,{placeholder:"搜索路由...",value:s.getColumn("remarks")?.getFilterValue()??"",onChange:n=>s.getColumn("remarks")?.setFilterValue(n.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),a&&e.jsxs(T,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["Reset",e.jsx(Fe,{className:"ml-2 h-4 w-4"})]})]})})}function Yx({columns:s,data:t,refetch:a}){const[n,l]=c.useState({}),[o,d]=c.useState({}),[x,r]=c.useState([]),[i,h]=c.useState([]),D=Me({data:t,columns:s,state:{sorting:i,columnVisibility:o,rowSelection:n,columnFilters:x},enableRowSelection:!0,onRowSelectionChange:l,onSortingChange:h,onColumnFiltersChange:r,onColumnVisibilityChange:d,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),getSortedRowModel:Ke(),getFacetedRowModel:ls(),getFacetedUniqueValues:is(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Ue,{table:D,toolbar:C=>e.jsx(Gx,{table:C,refetch:a})})}const Wx=s=>[{accessorKey:"id",header:({column:t})=>e.jsx(V,{column:t,title:"组ID"}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(L,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:t})=>e.jsx(V,{column:t,title:"备注"}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsxs("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:["匹配 ",t.original.match?.length," 条规则"]})}),enableHiding:!1,enableSorting:!1},{accessorKey:"action",header:({column:t})=>e.jsx(V,{column:t,title:"动作"}),cell:({row:t})=>{const a={dns:"指定DNS服务器进行解析",block:"禁止访问"};return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(L,{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:a[t.getValue("action")]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:"操作"}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Or,{defaultValues:t.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(Ds,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:"编辑"})]})}),e.jsx(Be,{title:"确认删除",description:"此操作将永久删除该权限组,删除后无法恢复。确定要继续吗?",confirmText:"删除",variant:"destructive",onConfirm:async()=>{Ac({id:t.original.id}).then(({data:a})=>{a&&(A.success("删除成功"),s())})},children:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(rs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:"删除"})]})})]})}];function Jx(){const[s,t]=c.useState([]);function a(){jr().then(({data:n})=>{t(n)})}return c.useEffect(()=>{a()},[]),e.jsxs(ye,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"路由管理"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"管理所有路由组,包括添加、删除、编辑等操作。"})]})}),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(Yx,{data:s,columns:Wx(a),refetch:a})})]})]})}const Qx=Object.freeze(Object.defineProperty({__proto__:null,default:Jx},Symbol.toStringTag,{value:"Module"})),Lr=c.createContext(void 0);function Zx({children:s,refreshData:t}){const[a,n]=c.useState(!1),[l,o]=c.useState(null);return e.jsx(Lr.Provider,{value:{isOpen:a,setIsOpen:n,editingPlan:l,setEditingPlan:o,refreshData:t},children:s})}function ha(){const s=c.useContext(Lr);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function Xx({table:s,saveOrder:t,isSortMode:a}){const{setIsOpen:n}=ha();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(T,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>n(!0),children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"添加套餐"})]}),e.jsx(S,{placeholder:"搜索套餐...",value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.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(T,{variant:a?"default":"outline",onClick:t,size:"sm",children:a?"保存排序":"编辑排序"})})]})}const Ka={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"}},em=s=>[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(Tt,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(V,{column:t,title:"ID"}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(L,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:t})=>e.jsx(V,{column:t,title:"显示"}),cell:({row:t})=>e.jsx(H,{defaultChecked:t.getValue("show"),onCheckedChange:a=>{zt({id:t.original.id,show:a}).then(({data:n})=>{!n&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:t})=>e.jsx(V,{column:t,title:"新购"}),cell:({row:t})=>e.jsx(H,{defaultChecked:t.getValue("sell"),onCheckedChange:a=>{zt({id:t.original.id,sell:a}).then(({data:n})=>{!n&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:t})=>e.jsx(V,{column:t,title:"续费",tooltip:"在订阅停止销售时,已购用户是否可以续费"}),cell:({row:t})=>e.jsx(H,{defaultChecked:t.getValue("renew"),onCheckedChange:a=>{zt({id:t.original.id,renew:a}).then(({data:n})=>{!n&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:t})=>e.jsx(V,{column:t,title:"名称"}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:t.getValue("name")})}),enableSorting:!1,enableHiding:!1,size:900},{accessorKey:"users_count",header:({column:t})=>e.jsx(V,{column:t,title:"统计"}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-2",children:[e.jsx(rt,{}),e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:t.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"group",header:({column:t})=>e.jsx(V,{column:t,title:"权限组"}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[600px] flex-wrap items-center gap-1.5 text-nowrap",children:e.jsx(L,{variant:"secondary",className:v("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:t.getValue("group")?.name})}),enableSorting:!1,enableHiding:!1},{accessorKey:"prices",header:({column:t})=>e.jsx(V,{column:t,title:"价格"}),cell:({row:t})=>{const a=t.getValue("prices"),n=[{period:"月付",key:"monthly",unit:"元/月"},{period:"季付",key:"quarterly",unit:"元/季"},{period:"半年付",key:"half_yearly",unit:"元/半年"},{period:"年付",key:"yearly",unit:"元/年"},{period:"两年付",key:"two_yearly",unit:"元/两年"},{period:"三年付",key:"three_yearly",unit:"元/三年"},{period:"流量包",key:"onetime",unit:"元"},{period:"重置包",key:"reset_traffic",unit:"元/次"}];return e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(({period:l,key:o,unit:d})=>a[o]!=null&&e.jsxs(L,{variant:"secondary",className:v("px-2 py-0.5 font-medium transition-colors text-nowrap",Ka[o].color,Ka[o].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[l," ¥",a[o],d]},o))})},enableSorting:!1,size:9e3},{id:"actions",header:({column:t})=>e.jsx(V,{className:"justify-end",column:t,title:"操作"}),cell:({row:t})=>{const{setIsOpen:a,setEditingPlan:n}=ha();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{n(t.original),a(!0)},children:[e.jsx(Ds,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:"编辑"})]}),e.jsx(Be,{title:"确认删除",description:"此操作将永久删除该订阅,删除后无法恢复。确定要继续吗?",confirmText:"删除",variant:"destructive",onConfirm:async()=>{ld({id:t.original.id}).then(({data:l})=>{l&&(A.success("删除成功"),s())})},children:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(rs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:"删除"})]})})]})}}],sm=u.object({id:u.number().nullable(),group_id:u.union([u.number(),u.string()]).nullable().optional(),name:u.string().min(1).max(250),content:u.string().nullable().optional(),transfer_enable:u.union([u.number().min(0),u.string().min(1)]),prices:u.object({monthly:u.union([u.number(),u.string()]).nullable().optional(),quarterly:u.union([u.number(),u.string()]).nullable().optional(),half_yearly:u.union([u.number(),u.string()]).nullable().optional(),yearly:u.union([u.number(),u.string()]).nullable().optional(),two_yearly:u.union([u.number(),u.string()]).nullable().optional(),three_yearly:u.union([u.number(),u.string()]).nullable().optional(),onetime:u.union([u.number(),u.string()]).nullable().optional(),reset_traffic:u.union([u.number(),u.string()]).nullable().optional()}).default({}),speed_limit:u.union([u.number(),u.string()]).nullable().optional(),capacity_limit:u.union([u.number(),u.string()]).nullable().optional(),device_limit:u.union([u.number(),u.string()]).nullable().optional(),force_update:u.boolean().optional(),reset_traffic_method:u.number().nullable(),users_count:u.number().optional()}),$r=c.forwardRef(({className:s,...t},a)=>e.jsx(An,{ref:a,className:v("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),...t,children:e.jsx(ho,{className:v("flex items-center justify-center text-current"),children:e.jsx(ks,{className:"h-4 w-4"})})}));$r.displayName=An.displayName;const jt={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}},tm=[{value:null,label:"跟随系统设置"},{value:0,label:"每月1号"},{value:1,label:"按月重置"},{value:2,label:"不重置"},{value:3,label:"每年1月1日"},{value:4,label:"按年重置"}];function am(){const{isOpen:s,setIsOpen:t,editingPlan:a,setEditingPlan:n,refreshData:l}=ha(),[o,d]=c.useState(!1),x=ae({resolver:ie(sm),defaultValues:{...jt,...a||{}},mode:"onChange"});c.useEffect(()=>{a?x.reset({...jt,...a}):x.reset(jt)},[a,x]);const r=new na({html:!0}),[i,h]=c.useState();async function D(){It().then(({data:w})=>{h(w)})}c.useEffect(()=>{s&&D()},[s]);const C=w=>{if(isNaN(w))return;const _=Object.entries(gt).reduce((b,[N,P])=>{const f=w*P.months*P.discount;return{...b,[N]:f.toFixed(2)}},{});x.setValue("prices",_,{shouldDirty:!0})},m=()=>{t(!1),n(null),x.reset(jt)};return e.jsx(ue,{open:s,onOpenChange:m,children:e.jsxs(ce,{children:[e.jsxs(he,{children:[e.jsx(xe,{children:a?"编辑套餐":"添加套餐"}),e.jsx(Se,{})]}),e.jsxs(oe,{...x,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:x.control,name:"name",render:({field:w})=>e.jsxs(j,{children:[e.jsx(p,{children:"套餐名称"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入套餐名称",...w})}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"group_id",render:({field:w})=>e.jsxs(j,{children:[e.jsxs(p,{className:"flex items-center justify-between",children:["权限组",e.jsx(Et,{dialogTrigger:e.jsx(T,{variant:"link",children:"添加权限组"}),refetch:D})]}),e.jsxs(G,{value:w.value||"",onValueChange:w.onChange,children:[e.jsx(y,{children:e.jsx(U,{children:e.jsx(Y,{placeholder:"选择权限组"})})}),e.jsx(B,{children:i?.map(_=>e.jsx(O,{value:_.id,children:_.name},_.id))})]}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"transfer_enable",render:({field:w})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(p,{children:"流量"}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(S,{type:"number",min:0,placeholder:"请输入流量大小",className:"rounded-r-none",...w})}),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:"GB"})]}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"speed_limit",render:({field:w})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(p,{children:"限速"}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(S,{type:"number",min:0,placeholder:"请输入限速",className:"rounded-r-none",...w})}),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:"Mbps"})]}),e.jsx(k,{})]})}),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:"售价设置"}),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(S,{type:"number",placeholder:"基础月付价格",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:w=>{const _=parseFloat(w.target.value);C(_)}})]}),e.jsx(le,{children:e.jsxs(se,{children:[e.jsx(te,{asChild:!0,children:e.jsx(T,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const w=Object.keys(gt).reduce((_,b)=>({..._,[b]:""}),{});x.setValue("prices",w,{shouldDirty:!0})},children:"清空价格"})}),e.jsx(ee,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:"清空所有周期的价格设置"})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(gt).filter(([w])=>!["onetime","reset_traffic"].includes(w)).map(([w,_])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(g,{control:x.control,name:`prices.${w}`,render:({field:b})=>e.jsxs(j,{children:[e.jsxs(p,{className:"text-xs font-medium text-muted-foreground",children:[_.label,e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",_.months===1?"每月":`${_.months}个月`,"结算)"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"0.00",min:0,...b,value:b.value??"",onChange:N=>b.onChange(N.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"})})]})]})})},w))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(gt).filter(([w])=>["onetime","reset_traffic"].includes(w)).map(([w,_])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(g,{control:x.control,name:`prices.${w}`,render:({field:b})=>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(p,{className:"text-xs font-medium",children:_.label}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:w==="onetime"?"一次性流量包,购买后立即生效":"用户可随时购买流量重置包,立即重置流量"})]}),e.jsxs("div",{className:"relative w-full md:w-32",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(y,{children:e.jsx(S,{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"})})]})]})})})},w))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(g,{control:x.control,name:"device_limit",render:({field:w})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(p,{children:"设备限制"}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(S,{type:"number",min:0,placeholder:"留空则不限制",className:"rounded-r-none",...w,value:w.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:"台"})]}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"capacity_limit",render:({field:w})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(p,{children:"容量限制"}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(S,{type:"number",min:0,placeholder:"留空则不限制",className:"rounded-r-none",...w,value:w.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:"人"})]}),e.jsx(k,{})]})})]}),e.jsx(g,{control:x.control,name:"reset_traffic_method",render:({field:w})=>e.jsxs(j,{children:[e.jsx(p,{children:"流量重置方式"}),e.jsxs(G,{value:w.value?.toString()??"null",onValueChange:_=>w.onChange(_=="null"?null:Number(_)),children:[e.jsx(y,{children:e.jsx(U,{children:e.jsx(Y,{placeholder:"选择流量重置方式"})})}),e.jsx(B,{children:tm.map(_=>e.jsx(O,{value:_.value?.toString()??"null",children:_.label},_.value))})]}),e.jsx(F,{className:"text-xs",children:"设置订阅流量的重置方式,不同的重置方式会影响用户的流量计算方式"}),e.jsx(k,{})]})}),e.jsx(g,{control:x.control,name:"content",render:({field:w})=>{const[_,b]=c.useState(!1);return e.jsxs(j,{className:"space-y-2",children:[e.jsxs(p,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:["套餐描述",e.jsx(le,{children:e.jsxs(se,{children:[e.jsx(te,{asChild:!0,children:e.jsx(T,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>b(!_),children:_?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(ee,{side:"top",children:e.jsx("p",{className:"text-xs",children:_?"隐藏预览":"显示预览"})})]})})]}),e.jsx(le,{children:e.jsxs(se,{children:[e.jsx(te,{asChild:!0,children:e.jsx(T,{variant:"outline",size:"sm",onClick:()=>{w.onChange(`## 套餐特点
• 高速稳定的全球网络接入
• 支持多设备同时在线
• 无限制的流量重置
## 使用说明
1. 支持设备iOS、Android、Windows、macOS
2. 24/7 技术支持
3. 自动定期流量重置
## 注意事项
- 禁止滥用
- 遵守当地法律法规
- 支持随时更换套餐`)},children:"使用模板"})}),e.jsx(ee,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:"点击使用预设的套餐描述模板"})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${_?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(y,{children:e.jsx(ra,{style:{height:"400px"},value:w.value||"",renderHTML:N=>r.render(N),onChange:({text:N})=>w.onChange(N),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:"在这里编写套餐描述...",className:"rounded-md border"})})}),_&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"预览"}),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:r.render(w.value||"")}})})]})]}),e.jsx(F,{className:"text-xs",children:"支持 Markdown 格式,可以使用标题、列表、粗体、斜体等样式来美化描述内容"}),e.jsx(k,{})]})}})]}),e.jsx(Re,{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(g,{control:x.control,name:"force_update",render:({field:w})=>e.jsxs(j,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(y,{children:e.jsx($r,{checked:w.value,onCheckedChange:w.onChange})}),e.jsx("div",{className:"",children:e.jsx(p,{className:"text-sm",children:"强制更新到用户"})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(T,{type:"button",variant:"outline",onClick:m,children:"取消"}),e.jsx(T,{type:"submit",disabled:o,onClick:()=>{x.handleSubmit(async w=>{d(!0),(await rd(w)).data&&(A.success(a?"套餐更新成功":"套餐添加成功"),m(),l()),d(!1)})()},children:o?"提交中...":"提交"})]})]})})]})]})})}function nm(){const[s,t]=c.useState({}),[a,n]=c.useState({"drag-handle":!1}),[l,o]=c.useState([]),[d,x]=c.useState([]),[r,i]=c.useState(!1),[h,D]=c.useState({pageSize:20,pageIndex:0}),[C,m]=c.useState([]),{refetch:w}=Q({queryKey:["planList"],queryFn:async()=>{const{data:f}=await Is();return m(f),f}});c.useEffect(()=>{n({"drag-handle":r}),D({pageSize:r?99999:10,pageIndex:0})},[r]);const _=(f,R)=>{r&&(f.dataTransfer.setData("text/plain",R.toString()),f.currentTarget.classList.add("opacity-50"))},b=(f,R)=>{if(!r)return;f.preventDefault(),f.currentTarget.classList.remove("bg-muted");const z=parseInt(f.dataTransfer.getData("text/plain"));if(z===R)return;const $=[...C],[E]=$.splice(z,1);$.splice(R,0,E),m($)},N=async()=>{if(!r){i(!0);return}const f=C?.map(R=>R.id);id(f).then(()=>{A.success("排序保存成功"),i(!1),w()}).finally(()=>{i(!1)})},P=Me({data:C||[],columns:em(w),state:{sorting:d,columnVisibility:a,rowSelection:s,columnFilters:l,pagination:h},enableRowSelection:!0,onPaginationChange:D,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:o,onColumnVisibilityChange:n,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),getSortedRowModel:Ke(),getFacetedRowModel:ls(),getFacetedUniqueValues:is(),initialState:{columnPinning:{right:["actions"]}},pageCount:r?1:void 0});return e.jsx(Zx,{refreshData:w,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ue,{table:P,toolbar:f=>e.jsx(Xx,{table:f,refetch:w,saveOrder:N,isSortMode:r}),draggable:r,onDragStart:_,onDragEnd:f=>f.currentTarget.classList.remove("opacity-50"),onDragOver:f=>{f.preventDefault(),f.currentTarget.classList.add("bg-muted")},onDragLeave:f=>f.currentTarget.classList.remove("bg-muted"),onDrop:b,showPagination:!r}),e.jsx(am,{})]})})}function rm(){return e.jsxs(ye,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"订阅管理"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"在这里可以配置订阅计划,包括添加、删除、编辑等操作。"})]})}),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(nm,{})})]})]})}const lm=Object.freeze(Object.defineProperty({__proto__:null,default:rm},Symbol.toStringTag,{value:"Module"})),Ar=[{value:ge.PENDING,label:Ms[ge.PENDING],icon:jo,color:Gs[ge.PENDING]},{value:ge.PROCESSING,label:Ms[ge.PROCESSING],icon:Hn,color:Gs[ge.PROCESSING]},{value:ge.COMPLETED,label:Ms[ge.COMPLETED],icon:Bt,color:Gs[ge.COMPLETED]},{value:ge.CANCELLED,label:Ms[ge.CANCELLED],icon:Kn,color:Gs[ge.CANCELLED]},{value:ge.DISCOUNTED,label:Ms[ge.DISCOUNTED],icon:Bt,color:Gs[ge.DISCOUNTED]}],Hr=[{value:pe.PENDING,label:dt[pe.PENDING],icon:go,color:ut[pe.PENDING]},{value:pe.PROCESSING,label:dt[pe.PROCESSING],icon:Hn,color:ut[pe.PROCESSING]},{value:pe.VALID,label:dt[pe.VALID],icon:Bt,color:ut[pe.VALID]},{value:pe.INVALID,label:dt[pe.INVALID],icon:Kn,color:ut[pe.INVALID]}];function ft({column:s,title:t,options:a}){const n=s?.getFacetedUniqueValues(),l=s?.getFilterValue(),o=Array.isArray(l)?new Set(l):l!==void 0?new Set([l]):new Set;return e.jsxs(Ze,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(T,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(it,{className:"mr-2 h-4 w-4"}),t,o?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(L,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:o.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:o.size>2?e.jsxs(L,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[o.size," selected"]}):a.filter(d=>o.has(d.value)).map(d=>e.jsx(L,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:d.label},d.value))})]})]})}),e.jsx(qe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ps,{children:[e.jsx(Ps,{placeholder:t}),e.jsxs(vs,{children:[e.jsx(Vs,{children:"No results found."}),e.jsx(Ve,{children:a.map(d=>{const x=o.has(d.value);return e.jsxs(be,{onSelect:()=>{const r=new Set(o);x?r.delete(d.value):r.add(d.value);const i=Array.from(r);s?.setFilterValue(i.length?i:void 0)},children:[e.jsx("div",{className:v("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",x?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ks,{className:v("h-4 w-4")})}),d.icon&&e.jsx(d.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${d.color}`}),e.jsx("span",{children:d.label}),n?.get(d.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:n.get(d.value)})]},d.value)})}),o.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Ve,{children:e.jsx(be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const im=u.object({email:u.string().min(1),plan_id:u.number(),period:u.string(),total_amount:u.number()}),om={email:"",plan_id:0,total_amount:0,period:""};function Kr({refetch:s,trigger:t,defaultValues:a}){const[n,l]=c.useState(!1),o=ae({resolver:ie(im),defaultValues:{...om,...a},mode:"onChange"}),[d,x]=c.useState([]);return c.useEffect(()=>{n&&Is().then(({data:r})=>{x(r)})},[n]),e.jsxs(ue,{open:n,onOpenChange:l,children:[e.jsx(Ie,{asChild:!0,children:t||e.jsxs(T,{variant:"outline",size:"sm",className:" h-8 space-x-2",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"添加订单"})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(xe,{children:"订单分配"}),e.jsx(Se,{})]}),e.jsxs(oe,{...o,children:[e.jsx(g,{control:o.control,name:"email",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"用户邮箱"}),e.jsx(y,{children:e.jsx(S,{placeholder:"请输入用户邮箱",...r})})]})}),e.jsx(g,{control:o.control,name:"plan_id",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"订阅计划"}),e.jsx(y,{children:e.jsxs(G,{value:r.value?r.value?.toString():void 0,onValueChange:i=>r.onChange(parseInt(i)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择订阅计划"})}),e.jsx(B,{children:d.map(i=>e.jsx(O,{value:i.id.toString(),children:i.name},i.id))})]})})]})}),e.jsx(g,{control:o.control,name:"period",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"订阅时长"}),e.jsx(y,{children:e.jsxs(G,{value:r.value,onValueChange:r.onChange,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择购买时长"})}),e.jsx(B,{children:Object.keys(tt).map(i=>e.jsx(O,{value:i,children:tt[i]},i))})]})})]})}),e.jsx(g,{control:o.control,name:"total_amount",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"支付金额"}),e.jsx(y,{children:e.jsx(S,{type:"number",placeholder:"请输入需要支付的金额",value:r.value/100,onChange:i=>r.onChange(parseFloat(i.currentTarget.value)*100)})}),e.jsx(k,{})]})}),e.jsxs(Re,{children:[e.jsx(T,{variant:"outline",onClick:()=>l(!1),children:"取消"}),e.jsx(T,{type:"submit",onClick:()=>{o.handleSubmit(r=>{xd(r).then(({data:i})=>{i&&(s&&s(),o.reset(),l(!1),A.success("添加成功"))})})()},children:"确定"})]})]})]})]})}const cm=Object.values(as).filter(s=>typeof s=="number").map(s=>({label:br[s],value:s,color:s===as.NEW?"green-500":s===as.RENEWAL?"blue-500":s===as.UPGRADE?"purple-500":"orange-500"})),dm=Object.values(ne).map(s=>({label:tt[s],value:s,color:s===ne.MONTH_PRICE?"slate-500":s===ne.QUARTER_PRICE?"cyan-500":s===ne.HALF_YEAR_PRICE?"indigo-500":s===ne.YEAR_PRICE?"violet-500":s===ne.TWO_YEAR_PRICE?"fuchsia-500":s===ne.THREE_YEAR_PRICE?"pink-500":s===ne.ONETIME_PRICE?"rose-500":"orange-500"}));function um({table:s,refetch:t}){const a=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Kr,{refetch:t}),e.jsx(S,{placeholder:"搜索订单...",value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:n=>s.getColumn("trade_no")?.setFilterValue(n.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(ft,{column:s.getColumn("type"),title:"订单类型",options:cm}),s.getColumn("period")&&e.jsx(ft,{column:s.getColumn("period"),title:"订单周期",options:dm}),s.getColumn("status")&&e.jsx(ft,{column:s.getColumn("status"),title:"订单状态",options:Ar}),s.getColumn("commission_status")&&e.jsx(ft,{column:s.getColumn("commission_status"),title:"佣金状态",options:Hr})]}),a&&e.jsxs(T,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["重置",e.jsx(Fe,{className:"ml-2 h-4 w-4"})]})]})}function Oe({label:s,value:t,className:a,valueClassName:n}){return e.jsxs("div",{className:v("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:v("text-sm",n),children:t||"-"})]})}function xm({status:s}){const t={PENDING:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",PAID:"bg-green-100 text-green-800 hover:bg-green-100",FAILED:"bg-red-100 text-red-800 hover:bg-red-100",REFUNDED:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(L,{variant:"secondary",className:v("font-medium",t[s]),children:Ms[s]})}function mm({id:s,trigger:t}){const[a,n]=c.useState(!1),[l,o]=c.useState();return c.useEffect(()=>{(async()=>{if(a){const{data:x}=await cd({id:s});o(x)}})()},[a,s]),e.jsxs(ue,{onOpenChange:n,open:a,children:[e.jsx(Ie,{asChild:!0,children:t}),e.jsxs(ce,{className:"max-w-xl",children:[e.jsxs(he,{className:"space-y-2",children:[e.jsx(xe,{className:"text-lg font-medium",children:"订单信息"}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:["订单号:",l?.trade_no]}),l?.status&&e.jsx(xm,{status:l.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:"基本信息"}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Oe,{label:"用户邮箱",value:l?.user?.email?e.jsxs(Ts,{to:`/user/manage?email=${l.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[l.user.email,e.jsx(qn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(Oe,{label:"订单周期",value:l&&tt[l.period]}),e.jsx(Oe,{label:"订阅计划",value:l?.plan?.name,valueClassName:"font-medium"}),e.jsx(Oe,{label:"回调单号",value:l?.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:"金额信息"}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Oe,{label:"支付金额",value:Ns(l?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(je,{className:"my-2"}),e.jsx(Oe,{label:"余额支付",value:Ns(l?.balance_amount||0)}),e.jsx(Oe,{label:"优惠金额",value:Ns(l?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(Oe,{label:"退回金额",value:Ns(l?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(Oe,{label:"折抵金额",value:Ns(l?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"时间信息"}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Oe,{label:"创建时间",value:re(l?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(Oe,{label:"更新时间",value:re(l?.updated_at),valueClassName:"font-mono text-xs"})]})]})]})]})]})}const hm={[as.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[as.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[as.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[as.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},jm={[ne.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ne.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ne.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ne.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ne.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ne.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ne.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ne.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},gm=s=>[{accessorKey:"trade_no",header:({column:t})=>e.jsx(V,{column:t,title:"订单号"}),cell:({row:t})=>{const a=t.original.trade_no,n=a.length>6?`${a.slice(0,3)}...${a.slice(-3)}`:a;return e.jsx("div",{className:"flex items-center",children:e.jsx(mm,{trigger:e.jsxs(W,{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:n}),e.jsx(qn,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(V,{column:t,title:"类型"}),cell:({row:t})=>{const a=t.getValue("type"),n=hm[a]||{color:"text-slate-700",bgColor:"bg-slate-100/80"};return e.jsx(L,{variant:"secondary",className:v("font-medium transition-colors text-nowrap",n.color,n.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:br[a]})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(V,{column:t,title:"订阅计划"}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium text-foreground/90 sm:max-w-72 md:max-w-[31rem]",children:t.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:t})=>e.jsx(V,{column:t,title:"周期"}),cell:({row:t})=>{const a=t.getValue("period"),n=jm[a]||{color:"text-gray-700",bgColor:"bg-gray-50"};return e.jsx(L,{variant:"secondary",className:v("font-medium transition-colors text-nowrap",n.color,n.bgColor,"hover:bg-opacity-80"),children:tt[a]})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx(V,{column:t,title:"支付金额"}),cell:({row:t})=>{const a=t.getValue("total_amount"),n=typeof a=="number"?(a/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",n]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:t})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(V,{column:t,title:"订单状态"}),e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{children:e.jsx(Ir,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(ee,{side:"top",className:"max-w-[200px] text-sm",children:"标记为[已支付]后将会由系统进行开通后并完成"})]})})]}),cell:({row:t})=>{const a=Ar.find(n=>n.value===t.getValue("status"));return a?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[a.icon&&e.jsx(a.icon,{className:`h-4 w-4 text-${a.color}`}),e.jsx("span",{className:"text-sm font-medium",children:a.label})]}),a.value===ge.PENDING&&e.jsxs(_s,{modal:!0,children:[e.jsx(Cs,{asChild:!0,children:e.jsxs(W,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(bt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"打开菜单"})]})}),e.jsxs(fs,{align:"end",className:"w-[140px]",children:[e.jsx(me,{className:"cursor-pointer",onClick:async()=>{await dd({trade_no:t.original.trade_no}),s()},children:"标记为已支付"}),e.jsx(me,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await ud({trade_no:t.original.trade_no}),s()},children:"取消订单"})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx(V,{column:t,title:"佣金金额"}),cell:({row:t})=>{const a=t.getValue("commission_balance"),n=a?(a/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:a?`¥${n}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx(V,{column:t,title:"佣金状态"}),cell:({row:t})=>{const a=t.original.commission_balance,n=Hr.find(l=>l.value===t.getValue("commission_status"));return a==0||!n?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:[n.icon&&e.jsx(n.icon,{className:`h-4 w-4 text-${n.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n.label})]}),n.value===pe.PENDING&&e.jsxs(_s,{modal:!0,children:[e.jsx(Cs,{asChild:!0,children:e.jsxs(W,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(bt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"打开菜单"})]})}),e.jsxs(fs,{align:"end",className:"w-[120px]",children:[e.jsx(me,{className:"cursor-pointer",onClick:async()=>{await za({trade_no:t.original.trade_no,commission_status:pe.PROCESSING}),s()},children:"标记为有效"}),e.jsx(me,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await za({trade_no:t.original.trade_no,commission_status:pe.INVALID}),s()},children:"标记为无效"})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(V,{column:t,title:"创建时间"}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:re(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}];function fm(){const[s]=Un(),[t,a]=c.useState({}),[n,l]=c.useState({}),[o,d]=c.useState([]),[x,r]=c.useState([]),[i,h]=c.useState({pageIndex:0,pageSize:20});c.useEffect(()=>{const b=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([N,P])=>{const f=s.get(N);return f?{id:N,value:P==="number"?parseInt(f):f}:null}).filter(Boolean);b.length>0&&d(b)},[s]);const{refetch:D,data:C,isLoading:m}=Q({queryKey:["orderList",i,o,x],queryFn:()=>od({pageSize:i.pageSize,current:i.pageIndex+1,filter:o,sort:x})}),w=Me({data:C?.data??[],columns:gm(D),state:{sorting:x,columnVisibility:n,rowSelection:t,columnFilters:o,pagination:i},rowCount:C?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:r,onColumnFiltersChange:d,onColumnVisibilityChange:l,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),onPaginationChange:h,getSortedRowModel:Ke(),getFacetedRowModel:ls(),getFacetedUniqueValues:is(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Ue,{table:w,toolbar:e.jsx(um,{table:w,refetch:D}),showPagination:!0})}function pm(){return e.jsxs(ye,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:" 订单管理"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"在这里可以查看用户订单,包括分配、查看、删除等操作。"})]})}),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(fm,{})})]})]})}const vm=Object.freeze(Object.defineProperty({__proto__:null,default:pm},Symbol.toStringTag,{value:"Module"}));function bm({column:s,title:t,options:a}){const n=s?.getFacetedUniqueValues(),l=new Set(s?.getFilterValue());return e.jsxs(Ze,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(T,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(it,{className:"mr-2 h-4 w-4"}),t,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(L,{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(L,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[l.size," selected"]}):a.filter(o=>l.has(o.value)).map(o=>e.jsx(L,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:o.label},o.value))})]})]})}),e.jsx(qe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ps,{children:[e.jsx(Ps,{placeholder:t}),e.jsxs(vs,{children:[e.jsx(Vs,{children:"No results found."}),e.jsx(Ve,{children:a.map(o=>{const d=l.has(o.value);return e.jsxs(be,{onSelect:()=>{d?l.delete(o.value):l.add(o.value);const x=Array.from(l);s?.setFilterValue(x.length?x:void 0)},children:[e.jsx("div",{className:v("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",d?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ks,{className:v("h-4 w-4")})}),o.icon&&e.jsx(o.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${o.color}`}),e.jsx("span",{children:o.label}),n?.get(o.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:n.get(o.value)})]},o.value)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Ve,{children:e.jsx(be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const ym=u.object({id:u.coerce.number().nullable().optional(),name:u.string().min(1,"请输入优惠券名称"),code:u.string().nullable(),type:u.union([u.string(),u.nativeEnum(Rt)]),value:u.coerce.number(),started_at:u.coerce.number(),ended_at:u.coerce.number(),limit_use:u.union([u.string(),u.number()]).nullable(),limit_use_with_user:u.union([u.string(),u.number()]).nullable(),generate_count:u.coerce.number().nullable().optional(),limit_plan_ids:u.array(u.number()).default([]).nullable(),limit_period:u.array(u.nativeEnum(ne)).default([]).nullable()}).refine(s=>s.ended_at>s.started_at,{message:"结束时间必须晚于开始时间",path:["ended_at"]}),qa={name:"",code:"",type:Rt.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 qr({defaultValues:s,refetch:t,type:a="create",dialogTrigger:n=e.jsxs(T,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"添加优惠券"})]}),open:l,onOpenChange:o}){const[d,x]=c.useState(!1),r=l??d,i=o??x,[h,D]=c.useState([]),C=ae({resolver:ie(ym),defaultValues:s||qa});c.useEffect(()=>{s&&C.reset(s)},[s,C]),c.useEffect(()=>{Is().then(({data:b})=>D(b))},[]);const m=b=>{if(!b)return;const N=(P,f)=>{const R=new Date(f*1e3);return P.setHours(R.getHours(),R.getMinutes(),R.getSeconds()),Math.floor(P.getTime()/1e3)};b.from&&C.setValue("started_at",N(b.from,C.watch("started_at"))),b.to&&C.setValue("ended_at",N(b.to,C.watch("ended_at")))},w=async b=>{try{await hd(b),i(!1),a==="create"&&C.reset(qa),t()}catch(N){console.error("保存优惠券失败:",N)}},_=(b,N)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:N}),e.jsx(S,{type:"datetime-local",step:"1",value:re(C.watch(b),"YYYY-MM-DDTHH:mm:ss"),onChange:P=>{const f=new Date(P.target.value);C.setValue(b,Math.floor(f.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(ue,{open:r,onOpenChange:i,children:[n&&e.jsx(Ie,{asChild:!0,children:n}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsx(he,{children:e.jsx(xe,{children:a==="create"?"添加优惠券":"编辑优惠券"})}),e.jsx(oe,{...C,children:e.jsxs("form",{onSubmit:C.handleSubmit(w),className:"space-y-4",children:[e.jsx(g,{control:C.control,name:"name",render:({field:b})=>e.jsxs(j,{children:[e.jsx(p,{children:"优惠券名称"}),e.jsx(S,{placeholder:"请输入优惠券名称",...b}),e.jsx(k,{})]})}),e.jsxs(j,{children:[e.jsx(p,{children:"优惠券类型和值"}),e.jsxs("div",{className:"flex",children:[e.jsx(g,{control:C.control,name:"type",render:({field:b})=>e.jsxs(G,{value:b.value.toString(),onValueChange:b.onChange,children:[e.jsx(U,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Y,{placeholder:"优惠券类型"})}),e.jsx(B,{children:Object.entries(oa).map(([N,P])=>e.jsx(O,{value:N,children:P},N))})]})}),e.jsx(g,{control:C.control,name:"value",render:({field:b})=>e.jsx(S,{type:"number",placeholder:"请输入值",...b,onChange:N=>b.onChange(N.target.value===""?"":N.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:C.watch("type")===Rt.AMOUNT?"¥":"%"})})]})]}),e.jsxs(j,{children:[e.jsx(p,{children:"优惠券有效期"}),e.jsxs(Ze,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(T,{variant:"outline",className:v("w-full justify-start text-left font-normal",!C.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(lt,{className:"mr-2 h-4 w-4"}),re(C.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ","至"," ",re(C.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})}),e.jsxs(qe,{className:"w-auto p-0",align:"start",children:[e.jsx("div",{className:"border-b border-border",children:e.jsx(Rs,{mode:"range",selected:{from:new Date(C.watch("started_at")*1e3),to:new Date(C.watch("ended_at")*1e3)},onSelect:m,numberOfMonths:2})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-4",children:[_("started_at","开始时间"),e.jsx("div",{className:"mt-6 text-sm text-muted-foreground",children:"至"}),_("ended_at","结束时间")]})})]})]}),e.jsx(k,{})]}),e.jsx(g,{control:C.control,name:"limit_use",render:({field:b})=>e.jsxs(j,{children:[e.jsx(p,{children:"最大使用次数"}),e.jsx(S,{type:"number",min:0,placeholder:"限制最大使用次数,留空则不限制",...b,value:b.value===void 0?"":b.value,onChange:N=>b.onChange(N.target.value===""?"":N.target.value),className:"h-9"}),e.jsx(F,{className:"text-xs",children:"设置优惠券的总使用次数限制,留空表示不限制使用次数"}),e.jsx(k,{})]})}),e.jsx(g,{control:C.control,name:"limit_use_with_user",render:({field:b})=>e.jsxs(j,{children:[e.jsx(p,{children:"每个用户可使用次数"}),e.jsx(S,{type:"number",min:0,placeholder:"限制每个用户可使用次数,留空则不限制",...b,value:b.value===void 0?"":b.value,onChange:N=>b.onChange(N.target.value===""?"":N.target.value),className:"h-9"}),e.jsx(F,{className:"text-xs",children:"限制每个用户可使用该优惠券的次数,留空表示不限制单用户使用次数"}),e.jsx(k,{})]})}),e.jsx(g,{control:C.control,name:"limit_period",render:({field:b})=>e.jsxs(j,{children:[e.jsx(p,{children:"指定周期"}),e.jsx(nt,{options:Object.entries(ne).filter(([N])=>isNaN(Number(N))).map(([N,P])=>({label:P,value:N})),onChange:N=>{if(N.length===0){b.onChange([]);return}const P=N.map(f=>ne[f.value]);b.onChange(P)},value:(b.value||[]).map(N=>({label:Object.entries(ne).find(([P,f])=>f===N)?.[1]||"",value:Object.entries(ne).find(([P,f])=>f===N)?.[0]||""})),placeholder:"限制指定周期可以使用优惠,留空则不限制",emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:"没有找到匹配的周期"})}),e.jsx(F,{className:"text-xs",children:"选择可以使用优惠券的订阅周期,留空表示不限制使用周期"}),e.jsx(k,{})]})}),e.jsx(g,{control:C.control,name:"limit_plan_ids",render:({field:b})=>e.jsxs(j,{children:[e.jsx(p,{children:"指定订阅"}),e.jsx(nt,{options:h?.map(N=>({label:N.name,value:N.id.toString()}))||[],onChange:N=>b.onChange(N.map(P=>Number(P.value))),value:(h||[]).filter(N=>(b.value||[]).includes(N.id)).map(N=>({label:N.name,value:N.id.toString()})),placeholder:"限制指定订阅可以使用优惠,留空则不限制",emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:"没有找到匹配的订阅"})}),e.jsx(k,{})]})}),a==="create"&&e.jsxs(e.Fragment,{children:[e.jsx(g,{control:C.control,name:"code",render:({field:b})=>e.jsxs(j,{children:[e.jsx(p,{children:"自定义优惠码"}),e.jsx(S,{placeholder:"自定义优惠码,留空则自动生成",...b,className:"h-9"}),e.jsx(F,{className:"text-xs",children:"可以自定义优惠码,留空则系统自动生成"}),e.jsx(k,{})]})}),e.jsx(g,{control:C.control,name:"generate_count",render:({field:b})=>e.jsxs(j,{children:[e.jsx(p,{children:"批量生成数量"}),e.jsx(S,{type:"number",min:0,placeholder:"批量生成优惠码数量,留空则生成单个",...b,value:b.value===void 0?"":b.value,onChange:N=>b.onChange(N.target.value===""?"":N.target.value),className:"h-9"}),e.jsx(F,{className:"text-xs",children:"批量生成多个优惠码,留空则只生成单个优惠码"}),e.jsx(k,{})]})})]}),e.jsx(Re,{children:e.jsx(T,{type:"submit",disabled:C.formState.isSubmitting,children:C.formState.isSubmitting?"保存中...":"保存"})})]})})]})]})}function Nm({table:s,refetch:t}){const a=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qr,{refetch:t}),e.jsx(S,{placeholder:"搜索优惠券...",value:s.getColumn("name")?.getFilterValue()??"",onChange:n=>s.getColumn("name")?.setFilterValue(n.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(bm,{column:s.getColumn("type"),title:"类型",options:Object.entries(oa).map(([n,l])=>({value:n,label:l}))}),a&&e.jsxs(T,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["重置",e.jsx(Fe,{className:"ml-2 h-4 w-4"})]})]})}const Ur=c.createContext(void 0);function wm({children:s,refetch:t}){const[a,n]=c.useState(!1),[l,o]=c.useState(null),d=r=>{o(r),n(!0)},x=()=>{n(!1),o(null)};return e.jsxs(Ur.Provider,{value:{isOpen:a,currentCoupon:l,openEdit:d,closeEdit:x},children:[s,l&&e.jsx(qr,{defaultValues:l,refetch:t,type:"edit",open:a,onOpenChange:n})]})}function _m(){const s=c.useContext(Ur);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const Cm=s=>[{accessorKey:"id",header:({column:t})=>e.jsx(V,{column:t,title:"ID"}),cell:({row:t})=>e.jsx(L,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(V,{column:t,title:"启用"}),cell:({row:t})=>e.jsx(H,{defaultChecked:t.original.show,onCheckedChange:a=>{gd({id:t.original.id,show:a}).then(({data:n})=>!n&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(V,{column:t,title:"卷名称"}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:t})=>e.jsx(V,{column:t,title:"类型"}),cell:({row:t})=>e.jsx(L,{variant:"outline",children:oa[t.original.type]}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(V,{column:t,title:"卷码"}),cell:({row:t})=>e.jsx(L,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(V,{column:t,title:"剩余次数"}),cell:({row:t})=>e.jsx(L,{variant:"outline",children:t.original.limit_use===null?"无限次":t.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:t})=>e.jsx(V,{column:t,title:"可用次数/用户"}),cell:({row:t})=>e.jsx(L,{variant:"outline",children:t.original.limit_use_with_user===null?"无限制":t.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:t})=>e.jsx(V,{column:t,title:"有效期"}),cell:({row:t})=>{const[a,n]=c.useState(!1),l=Date.now(),o=t.original.started_at*1e3,d=t.original.ended_at*1e3,x=l>d,r=l<o,i=Math.ceil((d-l)/(1e3*60*60*24)),D=x?{label:`已过期${Math.abs(i)}`,color:"bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"}:r?{label:`${Math.abs(Math.ceil((o-l)/(1e3*60*60*24)))}天后开始`,color:"bg-yellow-50 text-yellow-600 dark:bg-yellow-500/10 dark:text-yellow-400"}:{label:`剩余${i}`,color:"bg-green-50 text-green-600 dark:bg-green-500/10 dark:text-green-400"};return e.jsxs(nr,{open:a,onOpenChange:n,children:[e.jsx(rr,{asChild:!0,children:e.jsxs("div",{className:"group -m-0.5 flex max-w-[280px] cursor-pointer items-center gap-2 rounded-md p-0.5 transition-colors hover:bg-muted/40",children:[e.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[e.jsx("div",{className:v("whitespace-nowrap rounded-md px-1.5 py-0.5 text-xs font-medium",D.color),children:D.label}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-muted-foreground",children:[e.jsx("div",{className:"truncate text-xs",children:re(t.original.started_at,"MM/DD HH:mm")}),e.jsx("div",{className:"shrink-0 opacity-30",children:"→"}),e.jsx("div",{className:"truncate text-xs",children:re(t.original.ended_at,"MM/DD HH:mm")})]})]}),e.jsx(fo,{className:v("h-3.5 w-3.5 shrink-0 text-muted-foreground/50 transition-transform duration-200",a&&"rotate-180")})]})}),e.jsx(lr,{children:e.jsx("div",{className:"px-0.5 pb-0.5 pt-1.5",children:e.jsxs("div",{className:"space-y-1.5 border-l-2 border-muted pl-3 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{children:"开始时间"}),e.jsx("span",{className:"font-medium text-foreground",children:re(t.original.started_at,"YYYY/MM/DD HH:mm")})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{children:"结束时间"}),e.jsx("span",{className:"font-medium text-foreground",children:re(t.original.ended_at,"YYYY/MM/DD HH:mm")})]})]})})})]})},enableSorting:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx(V,{className:"justify-end",column:t,title:"操作"}),cell:({row:t})=>{const{openEdit:a}=_m();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>a(t.original),children:[e.jsx(Ds,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:"编辑"})]}),e.jsx(Be,{title:"确认删除",description:"此操作将永久删除该优惠券,删除后无法恢复。确定要继续吗?",confirmText:"删除",variant:"destructive",onConfirm:async()=>{jd({id:t.original.id}).then(({data:n})=>{n&&(A.success("删除成功"),s())})},children:e.jsxs(T,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(rs,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:"删除"})]})})]})}}];function Sm(){const[s,t]=c.useState({}),[a,n]=c.useState({}),[l,o]=c.useState([]),[d,x]=c.useState([]),[r,i]=c.useState({pageIndex:0,pageSize:20}),{refetch:h,data:D}=Q({queryKey:["couponList",r,l,d],queryFn:()=>md({pageSize:r.pageSize,current:r.pageIndex+1,filter:l,sort:d})}),C=Me({data:D?.data??[],columns:Cm(h),state:{sorting:d,columnVisibility:a,rowSelection:s,columnFilters:l,pagination:r},pageCount:Math.ceil((D?.total??0)/r.pageSize),rowCount:D?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:o,onColumnVisibilityChange:n,onPaginationChange:i,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),getSortedRowModel:Ke(),getFacetedRowModel:ls(),getFacetedUniqueValues:is(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(wm,{refetch:h,children:e.jsx("div",{className:"space-y-4",children:e.jsx(Ue,{table:C,toolbar:e.jsx(Nm,{table:C,refetch:h})})})})}function km(){return e.jsxs(ye,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"优惠券管理"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"在这里可以查看优惠券,包括增加、查看、删除等操作。"})]})}),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(Sm,{})})]})]})}const Tm=Object.freeze(Object.defineProperty({__proto__:null,default:km},Symbol.toStringTag,{value:"Module"})),Dm=u.object({email_prefix:u.string().optional(),email_suffix:u.string().min(1),password:u.string().optional(),expired_at:u.number().optional().nullable(),plan_id:u.number().nullable(),generate_count:u.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"]}),Pm={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0};function Vm({refetch:s}){const[t,a]=c.useState(!1),n=ae({resolver:ie(Dm),defaultValues:Pm,mode:"onChange"}),[l,o]=c.useState([]);return c.useEffect(()=>{t&&Is().then(({data:d})=>{d&&o(d)})},[t]),e.jsxs(ue,{open:t,onOpenChange:a,children:[e.jsx(Ie,{asChild:!0,children:e.jsxs(W,{size:"sm",variant:"outline",className:"space-x-2 gap-0",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"创建用户"})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(xe,{children:"创建用户"}),e.jsx(Se,{})]}),e.jsxs(oe,{...n,children:[e.jsxs(j,{children:[e.jsx(p,{children:"邮箱"}),e.jsxs("div",{className:"flex",children:[!n.watch("generate_count")&&e.jsx(g,{control:n.control,name:"email_prefix",render:({field:d})=>e.jsx(S,{className:"flex-[5] rounded-r-none",placeholder:"帐号(批量生成请留空)",...d})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${n.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(g,{control:n.control,name:"email_suffix",render:({field:d})=>e.jsx(S,{className:"flex-[4] rounded-l-none",placeholder:"域",...d})})]})]}),e.jsx(g,{control:n.control,name:"password",render:({field:d})=>e.jsxs(j,{children:[e.jsx(p,{children:"密码"}),e.jsx(S,{placeholder:"留空则密码与邮件相同",...d}),e.jsx(k,{})]})}),e.jsx(g,{control:n.control,name:"expired_at",render:({field:d})=>e.jsxs(j,{className:"flex flex-col",children:[e.jsx(p,{children:"到期时间"}),e.jsxs(Ze,{children:[e.jsx(Xe,{asChild:!0,children:e.jsx(y,{children:e.jsxs(W,{variant:"outline",className:v("w-full pl-3 text-left font-normal",!d.value&&"text-muted-foreground"),children:[d.value?re(d.value):e.jsx("span",{children:"请选择用户到期日期,留空为长期有效"}),e.jsx(lt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(qe,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(po,{asChild:!0,children:e.jsx(W,{variant:"outline",className:"w-full",onClick:()=>{d.onChange(null)},children:"长期有效"})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Rs,{mode:"single",selected:d.value?new Date(d.value*1e3):void 0,onSelect:x=>{x&&d.onChange(x?.getTime()/1e3)}})})]})]})]})}),e.jsx(g,{control:n.control,name:"plan_id",render:({field:d})=>e.jsxs(j,{children:[e.jsx(p,{children:"订阅计划"}),e.jsx(y,{children:e.jsxs(G,{value:d.value?d.value.toString():"null",onValueChange:x=>d.onChange(x==="null"?null:parseInt(x)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"无"})}),e.jsxs(B,{children:[e.jsx(O,{value:"null",children:"无"}),l.map(x=>e.jsx(O,{value:x.id.toString(),children:x.name},x.id))]})]})})]})}),!n.watch("email_prefix")&&e.jsx(g,{control:n.control,name:"generate_count",render:({field:d})=>e.jsxs(j,{children:[e.jsx(p,{children:"生成数量"}),e.jsx(S,{type:"number",placeholder:"如果为批量生产请输入生成数量",value:d.value||"",onChange:x=>d.onChange(x.target.value?parseInt(x.target.value):null)})]})})]}),e.jsxs(Re,{children:[e.jsx(W,{variant:"outline",onClick:()=>a(!1),children:"取消"}),e.jsx(W,{onClick:()=>n.handleSubmit(d=>{bd(d).then(({data:x})=>{x&&(A.success("生成成功"),n.reset(),s(),a(!1))})})(),children:"生成"})]})]})]})}const Br=Ga,Gr=Ya,Im=Wa,Yr=c.forwardRef(({className:s,...t},a)=>e.jsx(_t,{className:v("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),...t,ref:a}));Yr.displayName=_t.displayName;const Rm=Ss("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"}}),ja=c.forwardRef(({side:s="right",className:t,children:a,...n},l)=>e.jsxs(Im,{children:[e.jsx(Yr,{}),e.jsxs(Ct,{ref:l,className:v(Rm({side:s}),t),...n,children:[e.jsxs(ea,{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(Fe,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),a]})]}));ja.displayName=Ct.displayName;const ga=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-2 text-center sm:text-left",s),...t});ga.displayName="SheetHeader";const Wr=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});Wr.displayName="SheetFooter";const fa=c.forwardRef(({className:s,...t},a)=>e.jsx(St,{ref:a,className:v("text-lg font-semibold text-foreground",s),...t}));fa.displayName=St.displayName;const pa=c.forwardRef(({className:s,...t},a)=>e.jsx(kt,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));pa.displayName=kt.displayName;const Ys=[{label:"邮箱",value:"email",type:"text",operators:[{label:"包含",value:"contains"},{label:"等于",value:"eq"}]},{label:"用户ID",value:"id",type:"number",operators:[{label:"等于",value:"eq"}]},{label:"订阅",value:"plan_id",type:"select",operators:[{label:"等于",value:"eq"}],useOptions:!0},{label:"流量",value:"transfer_enable",type:"number",unit:"GB",operators:[{label:"大于",value:"gt"},{label:"小于",value:"lt"},{label:"等于",value:"eq"}]},{label:"已用流量",value:"total_used",type:"number",unit:"GB",operators:[{label:"大于",value:"gt"},{label:"小于",value:"lt"},{label:"等于",value:"eq"}]},{label:"在线设备",value:"online_count",type:"number",operators:[{label:"等于",value:"eq"},{label:"大于",value:"gt"},{label:"小于",value:"lt"}]},{label:"到期时间",value:"expired_at",type:"date",operators:[{label:"早于",value:"lt"},{label:"晚于",value:"gt"},{label:"等于",value:"eq"}]},{label:"UUID",value:"uuid",type:"text",operators:[{label:"等于",value:"eq"}]},{label:"Token",value:"token",type:"text",operators:[{label:"等于",value:"eq"}]},{label:"账号状态",value:"banned",type:"select",operators:[{label:"等于",value:"eq"}],options:[{label:"正常",value:"0"},{label:"禁用",value:"1"}]},{label:"备注",value:"remark",type:"text",operators:[{label:"包含",value:"contains"},{label:"等于",value:"eq"}]},{label:"邀请人邮箱",value:"inviter_email",type:"text",operators:[{label:"包含",value:"contains"},{label:"等于",value:"eq"}]},{label:"邀请人ID",value:"invite_user_id",type:"number",operators:[{label:"等于",value:"eq"}]},{label:"管理员",value:"is_admin",type:"boolean",operators:[{label:"等于",value:"eq"}]},{label:"员工",value:"is_staff",type:"boolean",operators:[{label:"等于",value:"eq"}]}];function Em({table:s,refetch:t,permissionGroups:a=[],subscriptionPlans:n=[]}){const l=s.getState().columnFilters.length>0,[o,d]=c.useState([]),[x,r]=c.useState(!1),i=b=>b*1024*1024*1024,h=b=>b/(1024*1024*1024),D=()=>{d([...o,{field:"",operator:"",value:""}])},C=b=>{d(o.filter((N,P)=>P!==b))},m=(b,N,P)=>{const f=[...o];if(f[b]={...f[b],[N]:P},N==="field"){const R=Ys.find(z=>z.value===P);R&&(f[b].operator=R.operators[0].value,f[b].value=R.type==="boolean"?!1:"")}d(f)},w=(b,N)=>{const P=Ys.find(f=>f.value===b.field);if(!P)return null;switch(P.type){case"text":return e.jsx(S,{placeholder:"输入值",value:b.value,onChange:f=>m(N,"value",f.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(S,{type:"number",placeholder:`输入数值${P.unit?`(${P.unit})`:""}`,value:P.unit==="GB"?h(b.value||0):b.value,onChange:f=>{const R=Number(f.target.value);m(N,"value",P.unit==="GB"?i(R):R)}}),P.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:P.unit})]});case"date":return e.jsx(Rs,{mode:"single",selected:b.value,onSelect:f=>m(N,"value",f),className:"rounded-md border"});case"select":return e.jsxs(G,{value:b.value,onValueChange:f=>m(N,"value",f),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"选择选项"})}),e.jsx(B,{children:P.useOptions?n.map(f=>e.jsx(O,{value:f.value.toString(),children:f.label},f.value)):P.options?.map(f=>e.jsx(O,{value:f.value.toString(),children:f.label},f.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(H,{checked:b.value,onCheckedChange:f=>m(N,"value",f)}),e.jsx(yt,{children:b.value?"是":"否"})]});default:return null}},_=()=>{const b=o.filter(N=>N.field&&N.operator&&N.value!=="").map(N=>{const P=Ys.find(R=>R.value===N.field);let f=N.value;return N.operator==="contains"?{id:N.field,value:f}:(P?.type==="date"&&f instanceof Date&&(f=Math.floor(f.getTime()/1e3)),P?.type==="boolean"&&(f=f?1:0),{id:N.field,value:`${N.operator}:${f}`})});s.setColumnFilters(b),r(!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(Vm,{refetch:t}),e.jsx(S,{placeholder:"搜索用户邮箱...",value:s.getColumn("email")?.getFilterValue()??"",onChange:b=>s.getColumn("email")?.setFilterValue(b.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(Br,{open:x,onOpenChange:r,children:[e.jsx(Gr,{asChild:!0,children:e.jsxs(T,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(vo,{className:"mr-2 h-4 w-4"}),"高级筛选",o.length>0&&e.jsx(L,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:o.length})]})}),e.jsxs(ja,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(ga,{children:[e.jsx(fa,{children:"高级筛选"}),e.jsx(pa,{children:"添加一个或多个筛选条件来精确查找用户"})]}),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:"筛选条件"}),e.jsx(T,{variant:"outline",size:"sm",onClick:D,children:"添加条件"})]}),e.jsx(at,{className:"h-[calc(100vh-280px)] pr-4",children:e.jsx("div",{className:"space-y-4",children:o.map((b,N)=>e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(yt,{children:["条件 ",N+1]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>C(N),children:e.jsx(Fe,{className:"h-4 w-4"})})]}),e.jsxs(G,{value:b.field,onValueChange:P=>m(N,"field",P),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"选择字段"})}),e.jsx(B,{children:Ys.map(P=>e.jsx(O,{value:P.value,children:P.label},P.value))})]}),b.field&&e.jsxs(G,{value:b.operator,onValueChange:P=>m(N,"operator",P),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"选择操作符"})}),e.jsx(B,{children:Ys.find(P=>P.value===b.field)?.operators.map(P=>e.jsx(O,{value:P.value,children:P.label},P.value))})]}),b.field&&b.operator&&w(b,N)]},N))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(T,{variant:"outline",onClick:()=>{d([]),r(!1)},children:"重置"}),e.jsx(T,{onClick:_,children:"应用筛选"})]})]})]})]}),l&&e.jsxs(T,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),d([])},className:"h-8 px-2 lg:px-3",children:["重置筛选",e.jsx(Fe,{className:"ml-2 h-4 w-4"})]})]})})}const Fm=u.object({id:u.number(),email:u.string().email(),invite_user_email:u.string().email().nullable().optional(),password:u.string().optional().nullable(),balance:u.coerce.number(),commission_balance:u.coerce.number(),u:u.number(),d:u.number(),transfer_enable:u.number(),expired_at:u.number().nullable(),plan_id:u.number().nullable(),banned:u.number(),commission_type:u.number(),commission_rate:u.number().nullable(),discount:u.number().nullable(),speed_limit:u.number().nullable(),device_limit:u.number().nullable(),is_admin:u.number(),is_staff:u.number(),remarks:u.string().nullable()}),Jr=c.createContext(void 0);function Mm({children:s,defaultValues:t,open:a,onOpenChange:n}){const[l,o]=c.useState(!1),[d,x]=c.useState(!1),[r,i]=c.useState([]),h=ae({resolver:ie(Fm),defaultValues:t,mode:"onChange"});c.useEffect(()=>{a!==void 0&&o(a)},[a]);const D=C=>{o(C),n?.(C)};return e.jsx(Jr.Provider,{value:{form:h,formOpen:l,setFormOpen:D,datePickerOpen:d,setDatePickerOpen:x,planList:r,setPlanList:i},children:s})}function zm(){const s=c.useContext(Jr);if(!s)throw new Error("useUserForm must be used within a UserFormProvider");return s}function Om({refetch:s}){const{form:t,formOpen:a,setFormOpen:n,datePickerOpen:l,setDatePickerOpen:o,planList:d,setPlanList:x}=zm();return c.useEffect(()=>{a&&Is().then(({data:r})=>{x(r)})},[a,x]),e.jsxs(oe,{...t,children:[e.jsx(g,{control:t.control,name:"email",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"邮箱"}),e.jsx(y,{children:e.jsx(S,{...r,placeholder:"请输入邮箱"})}),e.jsx(k,{...r})]})}),e.jsx(g,{control:t.control,name:"invite_user_email",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"邀请人邮箱"}),e.jsx(y,{children:e.jsx(S,{value:r.value||"",onChange:i=>r.onChange(i.target.value?i.target.value:null),placeholder:"请输入邮箱"})}),e.jsx(k,{...r})]})}),e.jsx(g,{control:t.control,name:"password",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"密码"}),e.jsx(y,{children:e.jsx(S,{value:r.value||"",onChange:r.onChange,placeholder:"如需修改密码请输入"})}),e.jsx(k,{...r})]})}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsx(g,{control:t.control,name:"balance",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"余额"}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(S,{type:"number",value:r.value||"",onChange:r.onChange,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(k,{...r})]})}),e.jsx(g,{control:t.control,name:"commission_balance",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"佣金余额"}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(S,{type:"number",value:r.value||"",onChange:r.onChange,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(k,{...r})]})}),e.jsx(g,{control:t.control,name:"u",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"已用上行"}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(S,{value:r.value/1024/1024/1024||"",onChange:i=>r.onChange(parseInt(i.target.value)*1024*1024*1024),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(k,{...r})]})}),e.jsx(g,{control:t.control,name:"d",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"已用下行"}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(S,{type:"number",value:r.value/1024/1024/1024||"",onChange:i=>r.onChange(parseInt(i.target.value)*1024*1024*1024),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(k,{...r})]})})]}),e.jsx(g,{control:t.control,name:"transfer_enable",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"流量"}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(S,{type:"number",value:r.value/1024/1024/1024||"",onChange:i=>r.onChange(parseInt(i.target.value)*1024*1024*1024),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(k,{})]})}),e.jsx(g,{control:t.control,name:"expired_at",render:({field:r})=>e.jsxs(j,{className:"flex flex-col",children:[e.jsx(p,{children:"到期时间"}),e.jsxs(Ze,{open:l,onOpenChange:o,children:[e.jsx(Xe,{asChild:!0,children:e.jsx(y,{children:e.jsxs(T,{type:"button",variant:"outline",className:v("w-full pl-3 text-left font-normal",!r.value&&"text-muted-foreground"),onClick:()=>o(!0),children:[r.value?re(r.value):e.jsx("span",{children:"请选择用户到期日期,留空为长期有效"}),e.jsx(lt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(qe,{className:"w-auto p-0",align:"start",side:"top",sideOffset:4,onInteractOutside:i=>{i.preventDefault()},onEscapeKeyDown:i=>{i.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(T,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{r.onChange(null),o(!1)},children:"长期有效"}),e.jsx(T,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const i=new Date;i.setMonth(i.getMonth()+1),i.setHours(23,59,59,999),r.onChange(Math.floor(i.getTime()/1e3)),o(!1)},children:"一个月"}),e.jsx(T,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const i=new Date;i.setMonth(i.getMonth()+3),i.setHours(23,59,59,999),r.onChange(Math.floor(i.getTime()/1e3)),o(!1)},children:"三个月"})]}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Rs,{mode:"single",selected:r.value?new Date(r.value*1e3):void 0,onSelect:i=>{if(i){const h=new Date(r.value?r.value*1e3:Date.now());i.setHours(h.getHours(),h.getMinutes(),h.getSeconds()),r.onChange(Math.floor(i.getTime()/1e3))}},disabled:i=>i<new Date,initialFocus:!0,className:"rounded-md border-none"})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:"具体时间"}),e.jsx(T,{type:"button",variant:"ghost",size:"sm",onClick:()=>{const i=new Date;i.setHours(23,59,59,999),r.onChange(Math.floor(i.getTime()/1e3))},className:"h-6 px-2 text-xs",children:"设为当天结束"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{type:"datetime-local",step:"1",value:re(r.value,"YYYY-MM-DDTHH:mm:ss"),onChange:i=>{const h=new Date(i.target.value);isNaN(h.getTime())||r.onChange(Math.floor(h.getTime()/1e3))},className:"flex-1"}),e.jsx(T,{type:"button",variant:"outline",onClick:()=>o(!1),children:"确定"})]})]})]})})]}),e.jsx(k,{})]})}),e.jsx(g,{control:t.control,name:"plan_id",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"订阅计划"}),e.jsx(y,{children:e.jsxs(G,{value:r.value?r.value.toString():"null",onValueChange:i=>r.onChange(i==="null"?null:parseInt(i)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"无"})}),e.jsxs(B,{children:[e.jsx(O,{value:"null",children:"无"}),d.map(i=>e.jsx(O,{value:i.id.toString(),children:i.name},i.id))]})]})})]})}),e.jsx(g,{control:t.control,name:"banned",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"账户状态"}),e.jsx(y,{children:e.jsxs(G,{value:r.value.toString(),onValueChange:i=>r.onChange(parseInt(i)),children:[e.jsx(U,{children:e.jsx(Y,{})}),e.jsxs(B,{children:[e.jsx(O,{value:"1",children:"封禁"}),e.jsx(O,{value:"0",children:"正常"})]})]})})]})}),e.jsx(g,{control:t.control,name:"commission_type",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"佣金类型"}),e.jsx(y,{children:e.jsxs(G,{value:r.value.toString(),onValueChange:i=>r.onChange(parseInt(i)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"无"})}),e.jsxs(B,{children:[e.jsx(O,{value:"0",children:"跟随系统设置"}),e.jsx(O,{value:"1",children:"循环返利"}),e.jsx(O,{value:"2",children:"首次返利"})]})]})})]})}),e.jsx(g,{control:t.control,name:"commission_rate",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"推荐返利比例"}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(S,{type:"number",value:r.value||"",onChange:i=>r.onChange(parseInt(i.currentTarget.value)||null),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(g,{control:t.control,name:"discount",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"专享折扣比例"}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(S,{type:"number",value:r.value||"",onChange:i=>r.onChange(parseInt(i.currentTarget.value)||null),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(k,{})]})}),e.jsx(g,{control:t.control,name:"speed_limit",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"限速"}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(S,{type:"number",value:r.value||"",onChange:i=>r.onChange(parseInt(i.currentTarget.value)||null),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(k,{})]})}),e.jsx(g,{control:t.control,name:"device_limit",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"设备限制"}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(S,{type:"number",value:r.value||"",onChange:i=>r.onChange(parseInt(i.currentTarget.value)||null),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(k,{})]})}),e.jsx(g,{control:t.control,name:"is_admin",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"是否管理员"}),e.jsx("div",{className:"py-2",children:e.jsx(y,{children:e.jsx(H,{checked:r.value===1,onCheckedChange:i=>r.onChange(i?1:0)})})})]})}),e.jsx(g,{control:t.control,name:"is_staff",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"是否员工"}),e.jsx("div",{className:"py-2",children:e.jsx(y,{children:e.jsx(H,{checked:r.value===1,onCheckedChange:i=>r.onChange(i?1:0)})})})]})}),e.jsx(g,{control:t.control,name:"remarks",render:({field:r})=>e.jsxs(j,{children:[e.jsx(p,{children:"备注"}),e.jsx(y,{children:e.jsx(bs,{className:"h-24",value:r.value||"",onChange:i=>r.onChange(i.currentTarget.value??null),placeholder:"请在这里记录"})}),e.jsx(k,{})]})}),e.jsxs(Wr,{children:[e.jsx(T,{variant:"outline",onClick:()=>n(!1),children:"取消"}),e.jsx(T,{type:"submit",onClick:()=>{t.handleSubmit(r=>{pd(r).then(({data:i})=>{i&&(A.success("修改成功"),n(!1),s())})})()},children:"提交"})]})]})}function Qr({refetch:s,defaultValues:t,dialogTrigger:a=e.jsxs(T,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(it,{className:"mr-2 h-4 w-4"}),"编辑用户信息"]})}){const[n,l]=c.useState(!1);return e.jsx(Mm,{defaultValues:t,open:n,onOpenChange:l,children:e.jsxs(Br,{open:n,onOpenChange:l,children:[e.jsx(Gr,{asChild:!0,children:a}),e.jsxs(ja,{className:"max-w-[90%] space-y-4",children:[e.jsxs(ga,{children:[e.jsx(fa,{children:"用户管理"}),e.jsx(pa,{})]}),e.jsx(Om,{refetch:s})]})]})})}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:"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"})}),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:"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"})}),Lm=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"})}),$m=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"})}),$t=[{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:Qo(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Zr,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:Ye(s.original.u)})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xr,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:Ye(s.original.d)})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const t=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(L,{variant:"outline",className:"font-mono",children:[t,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const t=(s.original.u+s.original.d)*s.original.server_rate;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:Ye(t)})}}];function el({user_id:s,dialogTrigger:t}){const[a,n]=c.useState(!1),[l,o]=c.useState({pageIndex:0,pageSize:20}),{data:d,isLoading:x}=Q({queryKey:["userStats",s,l,a],queryFn:()=>a?yd({user_id:s,pageSize:l.pageSize,page:l.pageIndex+1}):null}),r=Me({data:d?.data??[],columns:$t,pageCount:Math.ceil((d?.total??0)/l.pageSize),state:{pagination:l},manualPagination:!0,getCoreRowModel:ze(),onPaginationChange:o});return e.jsxs(ue,{open:a,onOpenChange:n,children:[e.jsx(Ie,{asChild:!0,children:t}),e.jsxs(ce,{className:"sm:max-w-[700px]",children:[e.jsx(he,{children:e.jsx(xe,{children:"流量使用记录"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(ca,{children:[e.jsx(da,{children:r.getHeaderGroups().map(i=>e.jsx(js,{children:i.headers.map(h=>e.jsx(xa,{className:v("h-10 px-2 text-xs",h.id==="total"&&"text-right"),children:h.isPlaceholder?null:vt(h.column.columnDef.header,h.getContext())},h.id))},i.id))}),e.jsx(ua,{children:x?Array.from({length:l.pageSize}).map((i,h)=>e.jsx(js,{children:Array.from({length:$t.length}).map((D,C)=>e.jsx(Ls,{className:"p-2",children:e.jsx(Ee,{className:"h-6 w-full"})},C))},h)):r.getRowModel().rows?.length?r.getRowModel().rows.map(i=>e.jsx(js,{"data-state":i.getIsSelected()&&"selected",className:"h-10",children:i.getVisibleCells().map(h=>e.jsx(Ls,{className:"px-2",children:vt(h.column.columnDef.cell,h.getContext())},h.id))},i.id)):e.jsx(js,{children:e.jsx(Ls,{colSpan:$t.length,className:"h-24 text-center",children:"暂无记录"})})})]})}),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:"每页显示"}),e.jsxs(G,{value:`${r.getState().pagination.pageSize}`,onValueChange:i=>{r.setPageSize(Number(i))},children:[e.jsx(U,{className:"h-8 w-[70px]",children:e.jsx(Y,{placeholder:r.getState().pagination.pageSize})}),e.jsx(B,{side:"top",children:[10,20,30,40,50].map(i=>e.jsx(O,{value:`${i}`,children:i},i))})]}),e.jsx("p",{className:"text-sm font-medium",children:"条记录"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("div",{className:"flex w-[100px] items-center justify-center text-sm",children:["第 ",r.getState().pagination.pageIndex+1," /"," ",r.getPageCount()," 页"]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(W,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>r.previousPage(),disabled:!r.getCanPreviousPage()||x,children:e.jsx(Lm,{className:"h-4 w-4"})}),e.jsx(W,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>r.nextPage(),disabled:!r.getCanNextPage()||x,children:e.jsx($m,{className:"h-4 w-4"})})]})]})]})]})]})]})}const Am=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"})}),Hm=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"})}),Km=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"})}),qm=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"})}),Um=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"})}),Bm=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"})}),Gm=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"})}),Ym=(s,t)=>[{accessorKey:"is_admin",header:({column:a})=>e.jsx(V,{column:a,title:"管理员"}),enableSorting:!1,enableHiding:!0,filterFn:(a,n,l)=>l.includes(a.getValue(n)),size:0},{accessorKey:"is_staff",header:({column:a})=>e.jsx(V,{column:a,title:"员工"}),enableSorting:!1,enableHiding:!0,filterFn:(a,n,l)=>l.includes(a.getValue(n)),size:0},{accessorKey:"id",header:({column:a})=>e.jsx(V,{column:a,title:"ID"}),cell:({row:a})=>e.jsx(L,{variant:"outline",children:a.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:a})=>e.jsx(V,{column:a,title:"邮箱"}),cell:({row:a})=>{const n=a.original.t||0,l=Date.now()/1e3-n<120,o=Math.floor(Date.now()/1e3-n);let d=l?"当前在线":n===0?"从未在线":`最后在线时间: ${re(n)}`;if(!l&&n!==0){const x=Math.floor(o/60),r=Math.floor(x/60),i=Math.floor(r/24);i>0?d+=`
离线时长: ${i}`:r>0?d+=`
离线时长: ${r}小时`:x>0?d+=`
离线时长: ${x}分钟`:d+=`
离线时长: ${o}`}return e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:v("size-2.5 rounded-full ring-2 ring-offset-2",l?"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:a.original.email})]})}),e.jsx(ee,{side:"bottom",className:"max-w-[280px]",children:e.jsx("p",{className:"whitespace-pre-line text-sm",children:d})})]})})},enableSorting:!1,enableHiding:!1},{accessorKey:"online_count",header:({column:a})=>e.jsx(V,{column:a,title:"在线设备"}),cell:({row:a})=>{const n=a.original.device_limit,l=a.original.online_count||0;return e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(L,{variant:"outline",className:v("min-w-[4rem] justify-center",n!==null&&l>=n?"border-destructive/50 bg-destructive/10 text-destructive":"border-primary/40 bg-primary/5 text-primary/90"),children:[l," / ",n===null?"∞":n]})})}),e.jsx(ee,{side:"bottom",children:e.jsx("p",{className:"text-sm",children:n===null?"无设备数限制":`最多可同时在线 ${n} 台设备`})})]})})},enableSorting:!0,enableHiding:!1},{accessorKey:"banned",header:({column:a})=>e.jsx(V,{column:a,title:"状态"}),cell:({row:a})=>{const n=a.original.banned;return e.jsx("div",{className:"flex justify-center",children:e.jsx(L,{className:v("min-w-20 justify-center transition-colors",n?"bg-destructive/15 text-destructive hover:bg-destructive/25":"bg-success/15 text-success hover:bg-success/25"),children:Od[n]})})},enableSorting:!0,filterFn:(a,n,l)=>l.includes(a.getValue(n))},{accessorKey:"plan_id",header:({column:a})=>e.jsx(V,{column:a,title:"订阅"}),cell:({row:a})=>e.jsx("div",{className:"min-w-[10em] break-all",children:a.original?.plan?.name||"-"}),enableSorting:!1,enableHiding:!1},{accessorKey:"group_id",header:({column:a})=>e.jsx(V,{column:a,title:"权限组"}),cell:({row:a})=>e.jsx("div",{className:"flex flex-wrap gap-1",children:e.jsx(L,{variant:"outline",className:v("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:a.original?.group?.name||"-"})}),enableSorting:!1},{accessorKey:"total_used",header:({column:a})=>e.jsx(V,{column:a,title:"已用流量"}),cell:({row:a})=>{const n=Ye(a.original?.total_used),l=Ye(a.original?.transfer_enable),o=a.original?.total_used/a.original?.transfer_enable*100||0;return e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{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:n}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[o.toFixed(1),"%"]})]}),e.jsx("div",{className:"h-1.5 w-full rounded-full bg-secondary",children:e.jsx("div",{className:v("h-full rounded-full transition-all",o>90?"bg-destructive":"bg-primary"),style:{width:`${Math.min(o,100)}%`}})})]})}),e.jsx(ee,{side:"bottom",children:e.jsxs("p",{className:"text-sm",children:["总流量配额: ",l]})})]})})}},{accessorKey:"transfer_enable",header:({column:a})=>e.jsx(V,{column:a,title:"总流量"}),cell:({row:a})=>e.jsx("div",{className:"font-medium text-muted-foreground",children:Ye(a.original?.transfer_enable)})},{accessorKey:"expired_at",header:({column:a})=>e.jsx(V,{column:a,title:"到期时间"}),cell:({row:a})=>{const n=a.original.expired_at,l=Date.now()/1e3,o=n!=null&&n<l,d=n!=null?new Date(n*1e3):null,x=d!=null?Math.ceil((d.getTime()-Date.now())/(1e3*60*60*24)):null;return e.jsx(le,{delayDuration:100,children:e.jsxs(se,{children:[e.jsx(te,{className:"block w-full",children:e.jsx(L,{variant:"outline",className:v("w-full justify-center transition-colors",o?"border-destructive/50 bg-destructive/10 text-destructive":n?"border-success/50 bg-success/10 text-success":"border-primary/40 bg-primary/5 text-primary/90"),children:n==null?"长期有效":re(n,"YYYY-MM-DD")})}),e.jsx(ee,{side:"bottom",className:"space-y-1 p-3",children:n!=null?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["到期时间:",re(n)]}),e.jsx("p",{className:v("text-sm font-medium",o?"text-destructive":"text-success"),children:o?`已过期 ${Math.abs(x??0)}`:`剩余 ${x??0}`})]}):e.jsx("p",{className:"text-sm font-medium",children:"长期有效"})})]})})}},{accessorKey:"balance",header:({column:a})=>e.jsx(V,{column:a,title:"余额"}),cell:({row:a})=>{const n=zs(a.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:n})]})}},{accessorKey:"commission_balance",header:({column:a})=>e.jsx(V,{column:a,title:"佣金"}),cell:({row:a})=>{const n=zs(a.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:n})]})}},{accessorKey:"created_at",header:({column:a})=>e.jsx(V,{column:a,title:"注册时间"}),cell:({row:a})=>e.jsx("div",{className:"truncate",children:re(a.original?.created_at)}),size:1e3},{id:"actions",header:({column:a})=>e.jsx(V,{column:a,className:"justify-end",title:"操作"}),cell:({row:a,table:n})=>e.jsxs(_s,{modal:!0,children:[e.jsx(Cs,{asChild:!0,children:e.jsx("div",{className:"text-center",children:e.jsx(W,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":"打开操作菜单",children:e.jsx(bt,{className:"size-4"})})})}),e.jsxs(fs,{align:"end",className:"min-w-[40px]",children:[e.jsx(me,{onSelect:l=>{l.preventDefault()},className:"p-0",children:e.jsx(Qr,{defaultValues:{...a.original,invite_user_email:a.original.invite_user?.email},refetch:s,dialogTrigger:e.jsxs(W,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Am,{className:"mr-2"}),"编辑"]})})}),e.jsx(me,{onSelect:l=>l.preventDefault(),className:"p-0",children:e.jsx(Kr,{defaultValues:{email:a.original.email},trigger:e.jsxs(W,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Hm,{className:"mr-2 "}),"分配订单"]})})}),e.jsx(me,{onSelect:()=>{Nt(a.original.subscribe_url)},className:"p-0",children:e.jsxs(W,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Km,{className:"mr-2"}),"复制订阅URL"]})}),e.jsx(me,{onSelect:()=>{vd({id:a.original.id}).then(({data:l})=>{l&&A.success("重置成功")})},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(qm,{className:"mr-2 "}),"重置UUID及订阅URL"]})}),e.jsx(me,{onSelect:()=>{},className:"p-0",children:e.jsxs(Ts,{className:"flex items-center px-2 py-1.5",to:`/finance/order?user_id=${a.original?.id}`,children:[e.jsx(Um,{className:"mr-2"}),"TA的订单"]})}),e.jsx(me,{onSelect:()=>{n.setColumnFilters([{id:"invite_user_id",value:a.original?.id}])},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Bm,{className:"mr-2 "}),"TA的邀请"]})}),e.jsx(me,{onSelect:l=>l.preventDefault(),className:"p-0",children:e.jsx(el,{user_id:a.original?.id,dialogTrigger:e.jsxs(W,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Gm,{className:"mr-2 "}),"TA的流量记录"]})})})]})]})}];function Wm(){const[s]=Un(),[t,a]=c.useState({}),[n,l]=c.useState({is_admin:!1,is_staff:!1}),[o,d]=c.useState([]),[x,r]=c.useState([]),[i,h]=c.useState({pageIndex:0,pageSize:20});c.useEffect(()=>{const z=s.get("email");z&&d($=>$.some(K=>K.id==="email")?$:[...$,{id:"email",value:z}])},[s]);const{refetch:D,data:C,isLoading:m}=Q({queryKey:["userList",i,o,x],queryFn:()=>fd({pageSize:i.pageSize,current:i.pageIndex+1,filter:o,sort:x})}),[w,_]=c.useState([]),[b,N]=c.useState([]);c.useEffect(()=>{It().then(({data:z})=>{_(z)}),Is().then(({data:z})=>{N(z)})},[]);const P=w.map(z=>({label:z.name,value:z.id})),f=b.map(z=>({label:z.name,value:z.id})),R=Me({data:C?.data??[],columns:Ym(D),state:{sorting:x,columnVisibility:n,rowSelection:t,columnFilters:o,pagination:i},rowCount:C?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:r,onColumnFiltersChange:d,onColumnVisibilityChange:l,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),onPaginationChange:h,getSortedRowModel:Ke(),getFacetedRowModel:ls(),getFacetedUniqueValues:is(),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(Ue,{table:R,toolbar:e.jsx(Em,{table:R,refetch:D,serverGroupList:w,permissionGroups:P,subscriptionPlans:f})})}function Jm(){return e.jsxs(ye,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:"用户管理"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"在这里可以管理用户,包括增加、删除、编辑、查询等操作。"})]})}),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(Wm,{})})})]})]})}const Qm=Object.freeze(Object.defineProperty({__proto__:null,default:Jm},Symbol.toStringTag,{value:"Module"}));function Zm({column:s,title:t,options:a}){const n=new Set(s?.getFilterValue());return e.jsxs(Ze,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(W,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(bo,{className:"mr-2 h-4 w-4"}),t,n?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(L,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:n.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:n.size>2?e.jsxs(L,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[n.size," selected"]}):a.filter(l=>n.has(l.value)).map(l=>e.jsx(L,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},`selected-${l.value}`))})]})]})}),e.jsx(qe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ps,{children:[e.jsx(Ps,{placeholder:t}),e.jsxs(vs,{children:[e.jsx(Vs,{children:"No results found."}),e.jsx(Ve,{children:a.map(l=>{const o=n.has(l.value);return e.jsxs(be,{onSelect:()=>{o?n.delete(l.value):n.add(l.value);const d=Array.from(n);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:v("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",o?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(yo,{className:v("h-4 w-4")})}),l.icon&&e.jsx(l.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:l.label})]},`option-${l.value}`)})}),n.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Hs,{}),e.jsx(Ve,{children:e.jsx(be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Xm=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 eh({table:s}){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(fr,{defaultValue:s.getColumn("status")?.getFilterValue(),onValueChange:t=>s.getColumn("status")?.setFilterValue(t),children:e.jsxs(ia,{className:"grid w-full grid-cols-2",children:[e.jsx(st,{value:"0",children:"已开始"}),e.jsx(st,{value:"1",children:"已关闭"})]})}),s.getColumn("level")&&e.jsx(Zm,{column:s.getColumn("level"),title:"优先级",options:[{label:Qs[ss.LOW],value:ss.LOW,icon:Xm,color:"gray"},{label:Qs[ss.MEDIUM],value:ss.MEDIUM,icon:Zr,color:"yellow"},{label:Qs[ss.HIGH],value:ss.HIGH,icon:Xr,color:"red"}]})]})})}function sh(){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 th=Ss("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"}}),sl=c.forwardRef(({className:s,variant:t,layout:a,children:n,...l},o)=>e.jsx("div",{className:v(th({variant:t,layout:a,className:s}),"relative group"),ref:o,...l,children:c.Children.map(n,d=>c.isValidElement(d)&&typeof d.type!="string"?c.cloneElement(d,{variant:t,layout:a}):d)}));sl.displayName="ChatBubble";const ah=Ss("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"}}),tl=c.forwardRef(({className:s,variant:t,layout:a,isLoading:n=!1,children:l,...o},d)=>e.jsx("div",{className:v(ah({variant:t,layout:a,className:s}),"break-words max-w-full whitespace-pre-wrap"),ref:d,...o,children:n?e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(sh,{})}):l}));tl.displayName="ChatBubbleMessage";const nh=c.forwardRef(({variant:s,className:t,children:a,...n},l)=>e.jsx("div",{ref:l,className:v("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",t),...n,children:a}));nh.displayName="ChatBubbleActionWrapper";const al=c.forwardRef(({className:s,...t},a)=>e.jsx(bs,{autoComplete:"off",ref:a,name:"message",className:v("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),...t}));al.displayName="ChatInput";const nl=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"})}),rl=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"})}),rh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),lh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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 ih(){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(Ee,{className:"h-8 w-3/4"}),e.jsx(Ee,{className:"h-4 w-1/2"})]}),e.jsx("div",{className:"flex-1 space-y-4",children:[1,2,3].map(s=>e.jsx(Ee,{className:"h-20 w-2/3"},s))})]})}function oh({ticketId:s,dialogTrigger:t}){const a=ns(),n=c.useRef(null),[l,o]=c.useState(!1),[d,x]=c.useState(""),[r,i]=c.useState(!1),{data:h,refetch:D,isLoading:C}=Q({queryKey:["ticket",s,l],queryFn:()=>l?wd(s):Promise.resolve(null),refetchInterval:l?5e3:!1,retry:3}),m=h?.data,w=(f="smooth")=>{if(n.current){const{scrollHeight:R,clientHeight:z}=n.current;n.current.scrollTo({top:R-z,behavior:f})}};c.useEffect(()=>{if(!l)return;const f=requestAnimationFrame(()=>{w("instant"),setTimeout(()=>w(),1e3)});return()=>{cancelAnimationFrame(f)}},[l,m?.messages]);const _=async()=>{const f=d.trim();!f||r||(i(!0),_d({id:s,message:f}).then(()=>{x(""),D(),w()}).finally(()=>{i(!1)}))},b=async()=>{gr(s).then(()=>{A.success("工单已关闭"),D()})},N=()=>{m?.user&&a("/finance/order?user_id="+m.user.id)},P=m?.status===Os.CLOSED;return e.jsxs(ue,{open:l,onOpenChange:o,children:[e.jsx(Ie,{asChild:!0,children:t??e.jsx(W,{variant:"outline",children:"查看工单"})}),e.jsxs(ce,{className:"flex h-[90vh] max-w-4xl flex-col gap-0 p-0",children:[e.jsx(xe,{}),C?e.jsx(ih,{}):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:m?.subject}),e.jsx(L,{variant:P?"secondary":"default",children:P?"已关闭":"处理中"}),!P&&e.jsx(Be,{title:"确认关闭工单",description:"关闭后将无法继续回复,是否确认关闭该工单?",confirmText:"关闭工单",variant:"destructive",onConfirm:b,children:e.jsxs(W,{variant:"ghost",size:"sm",className:"gap-1 text-muted-foreground hover:text-destructive",children:[e.jsx(nl,{className:"h-4 w-4"}),"关闭工单"]})})]}),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(rt,{className:"h-4 w-4"}),e.jsx("span",{children:m?.user?.email})]}),e.jsx(je,{orientation:"vertical",className:"h-4"}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(rl,{className:"h-4 w-4"}),e.jsxs("span",{children:["创建于 ",re(m?.created_at)]})]}),e.jsx(je,{orientation:"vertical",className:"h-4"}),e.jsx(L,{variant:"outline",children:m?.level!=null&&Qs[m.level]})]})]}),m?.user&&e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(Qr,{defaultValues:m.user,refetch:D,dialogTrigger:e.jsx(W,{variant:"outline",size:"icon",className:"h-8 w-8",title:"用户信息",children:e.jsx(rt,{className:"h-4 w-4"})})}),e.jsx(el,{user_id:m.user.id,dialogTrigger:e.jsx(W,{variant:"outline",size:"icon",className:"h-8 w-8",title:"流量记录",children:e.jsx(rh,{className:"h-4 w-4"})})}),e.jsx(W,{variant:"outline",size:"icon",className:"h-8 w-8",title:"订单记录",onClick:N,children:e.jsx(lh,{className:"h-4 w-4"})})]})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{ref:n,className:"h-full space-y-4 overflow-y-auto p-6",children:m?.messages?.length===0?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:"暂无消息记录"}):m?.messages?.map(f=>e.jsx(sl,{variant:f.is_me?"sent":"received",className:f.is_me?"ml-auto":"mr-auto",children:e.jsx(tl,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"whitespace-pre-wrap break-words",children:f.message}),e.jsx("div",{className:"text-right",children:e.jsx("time",{className:"text-[10px] text-muted-foreground",children:re(f.created_at)})})]})})},f.id))})}),e.jsx("div",{className:"border-t p-4",children:e.jsxs("div",{className:"relative flex items-center space-x-2",children:[e.jsx(al,{disabled:P||r,placeholder:P?"工单已关闭":"请输入回复内容...",className:"flex-1 resize-none rounded-lg border bg-background p-3 focus-visible:ring-1",value:d,onChange:f=>x(f.target.value),onKeyDown:f=>{f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),_())}}),e.jsx(W,{disabled:P||r||!d.trim(),onClick:_,children:r?"发送中...":"发送"})]})})]})]})]})}const 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:"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"})}),dh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),uh=s=>[{accessorKey:"id",header:({column:t})=>e.jsx(V,{column:t,title:"工单号"}),cell:({row:t})=>e.jsx(L,{variant:"outline",children:t.getValue("id")}),enableSorting:!1,enableHiding:!1},{accessorKey:"subject",header:({column:t})=>e.jsx(V,{column:t,title:"主题"}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ch,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"max-w-[500px] truncate font-medium",children:t.getValue("subject")})]}),enableSorting:!1,enableHiding:!1,size:4e3},{accessorKey:"level",header:({column:t})=>e.jsx(V,{column:t,title:"优先级"}),cell:({row:t})=>{const a=t.getValue("level"),n=a===ss.LOW?"default":a===ss.MEDIUM?"secondary":"destructive";return e.jsx(L,{variant:n,className:"whitespace-nowrap",children:Qs[a]})},filterFn:(t,a,n)=>n.includes(t.getValue(a))},{accessorKey:"status",header:({column:t})=>e.jsx(V,{column:t,title:"状态"}),cell:({row:t})=>{const a=t.getValue("status"),n=t.original.reply_status,l=a===Os.CLOSED?Ld[Os.CLOSED]:n===0?"已回复":"待回复",o=a===Os.CLOSED?"default":n===0?"secondary":"destructive";return e.jsx(L,{variant:o,className:"whitespace-nowrap",children:l})}},{accessorKey:"updated_at",header:({column:t})=>e.jsx(V,{column:t,title:"最后更新"}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[e.jsx(rl,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:re(t.getValue("updated_at"))})]}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx(V,{column:t,title:"创建时间"}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:re(t.getValue("created_at"))}),enableSorting:!0,meta:{isFlexGrow:!0}},{id:"actions",header:({column:t})=>e.jsx(V,{className:"justify-end",column:t,title:"操作"}),cell:({row:t})=>{const a=t.original.status!==Os.CLOSED;return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(oh,{ticketId:t.original.id,dialogTrigger:e.jsx(W,{variant:"ghost",size:"icon",className:"h-8 w-8",title:"查看详情",children:e.jsx(dh,{className:"h-4 w-4"})})}),a&&e.jsx(Be,{title:"确认关闭工单",description:"关闭后将无法继续回复,是否确认关闭该工单?",confirmText:"关闭工单",variant:"destructive",onConfirm:async()=>{gr(t.original.id).then(()=>{A.success("工单已关闭"),s()})},children:e.jsx(W,{variant:"ghost",size:"icon",className:"h-8 w-8",title:"关闭工单",children:e.jsx(nl,{className:"h-4 w-4"})})})]})}}];function xh(){const[s,t]=c.useState({}),[a,n]=c.useState({}),[l,o]=c.useState([{id:"status",value:"0"}]),[d,x]=c.useState([]),[r,i]=c.useState({pageIndex:0,pageSize:20}),{refetch:h,data:D,isLoading:C}=Q({queryKey:["orderList",r,l,d],queryFn:()=>Nd({pageSize:r.pageSize,current:r.pageIndex+1,filter:l,sort:d})}),m=Me({data:D?.data??[],columns:uh(h),state:{sorting:d,columnVisibility:a,rowSelection:s,columnFilters:l,pagination:r},rowCount:D?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:o,onColumnVisibilityChange:n,getCoreRowModel:ze(),getFilteredRowModel:Ae(),getPaginationRowModel:He(),onPaginationChange:i,getSortedRowModel:Ke(),getFacetedRowModel:ls(),getFacetedUniqueValues:is(),initialState:{columnPinning:{right:["actions"]}}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(eh,{table:m,refetch:h}),e.jsx(Ue,{table:m,showPagination:!0})]})}function mh(){return e.jsxs(ye,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Te,{}),e.jsx(De,{})]})]}),e.jsxs(_e,{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:" 工单管理"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"在这里可以查看用户工单,包括查看、回复、关闭等操作。"})]})}),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(xh,{})})]})]})}const hh=Object.freeze(Object.defineProperty({__proto__:null,default:mh},Symbol.toStringTag,{value:"Module"}));export{vh as a,fh as c,ph as g,bh as r};