New Features: - Add bulk ban and email notification in user management - Add CSV export for batch coupon generation - Optimize subscription description template Bug Fixes: - Fix knowledge base pagination issue - Fix permission group filtering in node management - Fix unauthorized order placement for free subscription periods
10 lines
396 KiB
JavaScript
Vendored
10 lines
396 KiB
JavaScript
Vendored
import{r as u,j as e,t as Cl,c as Sl,I as Ha,a as Fs,S as ya,u as Ns,b as Na,d as kl,O as _a,e as Tl,f as $,g as Dl,h as Pl,i as El,k as Rl,B as Il,l as Vl,Q as Ol,m as Ml,R as Fl,n as zl,P as Ll,o as Al,p as $l,q as fn,F as ql,C as Ul,s as Hl,v as Kl,w as Bl,x as Gl,y as pn,z as M,A as h,D as je,E as Ne,G as gn,H as Lt,J as At,K as wa,L as Ye,T as $t,M as qt,N as jn,U as vn,V as bn,W as Ca,X as yn,Y as Wl,Z as Nn,_ as _n,$ as wn,a0 as Cn,a1 as zs,a2 as Sn,a3 as Yl,a4 as kn,a5 as Tn,a6 as Ql,a7 as Jl,a8 as Zl,a9 as Xl,aa as ei,ab as si,ac as ti,ad as ai,ae as ni,af as ri,ag as li,ah as Dn,ai as ii,aj as oi,ak as Ls,al as Pn,am as ci,an as di,ao as En,ap as Sa,aq as mi,ar as ui,as as Ka,at as xi,au as Rn,av as hi,aw as In,ax as fi,ay as pi,az as gi,aA as ji,aB as vi,aC as bi,aD as Vn,aE as yi,aF as Ni,aG as _i,aH as Me,aI as wi,aJ as On,aK as Ci,aL as Si,aM as Mn,aN as Fn,aO as zn,aP as ki,aQ as Ti,aR as Ln,aS as An,aT as $n,aU as Di,aV as Pi,aW as qn,aX as Ei,aY as ka,aZ as Un,a_ as Ri,a$ as Hn,b0 as Ii,b1 as Kn,b2 as Vi,b3 as Bn,b4 as Gn,b5 as Oi,b6 as Mi,b7 as Wn,b8 as Fi,b9 as zi,ba as Yn,bb as Li,bc as Qn,bd as Ai,be as $i,bf as ts,bg as ie,bh as ss,bi as pt,bj as qi,bk as Ui,bl as Hi,bm as Ki,bn as Bi,bo as Gi,bp as Ba,bq as Ga,br as Wi,bs as Yi,bt as Qi,bu as Ji,bv as Zi,bw as xa,bx as ut,by as Xi,bz as eo,bA as Jn,bB as so,bC as to,bD as Zn,bE as ao,bF as Ce,bG as no,bH as Wa,bI as ha,bJ as fa,bK as ro,bL as lo,bM as Xn,bN as io,bO as Ta,bP as oo,bQ as co,bR as mo,bS as er,bT as sr,bU as tr,bV as uo,bW as xo,bX as ho,bY as fo,bZ as ar,b_ as po,b$ as ms,c0 as go,c1 as jo,c2 as vo,c3 as Rt,c4 as Re,c5 as Ya,c6 as bo,c7 as nr,c8 as rr,c9 as lr,ca as ir,cb as or,cc as cr,cd as yo,ce as No,cf as _o,cg as Ut,ch as As,ci as ns,cj as Ze,ck as Xe,cl as rs,cm as ls,cn as is,co as wo,cp as Co,cq as So,cr as ko,cs as To,ct as Do,cu as Po,cv as Eo,cw as Ro,cx as pa,cy as Da,cz as Pa,cA as Io,cB as _s,cC as ws,cD as gt,cE as Vo,cF as It,cG as Oo,cH as Qa,cI as dr,cJ as Ja,cK as Vt,cL as Mo,cM as Fo,cN as zo,cO as Lo,cP as mr,cQ as Ao,cR as $o,cS as ur,cT as ga,cU as xr,cV as qo,cW as hr,cX as fr,cY as Uo,cZ as Ho,c_ as Ko,c$ as Bo,d0 as Go}from"./vendor.js";import"./index.js";var Zh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Xh(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function Wo(s){if(s.__esModule)return s;var n=s.default;if(typeof n=="function"){var a=function l(){return this instanceof l?Reflect.construct(n,arguments,this.constructor):n.apply(this,arguments)};a.prototype=n.prototype}else a={};return Object.defineProperty(a,"__esModule",{value:!0}),Object.keys(s).forEach(function(l){var r=Object.getOwnPropertyDescriptor(s,l);Object.defineProperty(a,l,r.get?r:{enumerable:!0,get:function(){return s[l]}})}),a}const Yo={theme:"system",setTheme:()=>null},pr=u.createContext(Yo);function Qo({children:s,defaultTheme:n="system",storageKey:a="vite-ui-theme",...l}){const[r,c]=u.useState(()=>localStorage.getItem(a)||n);u.useEffect(()=>{const m=window.document.documentElement;if(m.classList.remove("light","dark"),r==="system"){const x=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";m.classList.add(x);return}m.classList.add(r)},[r]);const o={theme:r,setTheme:m=>{localStorage.setItem(a,m),c(m)}};return e.jsx(pr.Provider,{...l,value:o,children:s})}const Jo=()=>{const s=u.useContext(pr);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},Zo=function(){const n=typeof document<"u"&&document.createElement("link").relList;return n&&n.supports&&n.supports("modulepreload")?"modulepreload":"preload"}(),Xo=function(s,n){return new URL(s,n).href},Za={},me=function(n,a,l){let r=Promise.resolve();if(a&&a.length>0){const o=document.getElementsByTagName("link"),m=document.querySelector("meta[property=csp-nonce]"),x=m?.nonce||m?.getAttribute("nonce");r=Promise.allSettled(a.map(i=>{if(i=Xo(i,l),i in Za)return;Za[i]=!0;const d=i.endsWith(".css"),p=d?'[rel="stylesheet"]':"";if(!!l)for(let f=o.length-1;f>=0;f--){const j=o[f];if(j.href===i&&(!d||j.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${i}"]${p}`))return;const P=document.createElement("link");if(P.rel=d?"stylesheet":Zo,d||(P.as="script"),P.crossOrigin="",P.href=i,x&&P.setAttribute("nonce",x),document.head.appendChild(P),d)return new Promise((f,j)=>{P.addEventListener("load",f),P.addEventListener("error",()=>j(new Error(`Unable to preload CSS for ${i}`)))})}))}function c(o){const m=new Event("vite:preloadError",{cancelable:!0});if(m.payload=o,window.dispatchEvent(m),!m.defaultPrevented)throw o}return r.then(o=>{for(const m of o||[])m.status==="rejected"&&c(m.reason);return n().catch(c)})};function N(...s){return Cl(Sl(s))}const et=Fs("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"}}),D=u.forwardRef(({className:s,variant:n,size:a,asChild:l=!1,children:r,disabled:c,loading:o=!1,leftSection:m,rightSection:x,...i},d)=>{const p=l?ya:"button";return e.jsxs(p,{className:N(et({variant:n,size:a,className:s})),disabled:o||c,ref:d,...i,children:[(m&&o||!m&&!x&&o)&&e.jsx(Ha,{className:"mr-2 h-4 w-4 animate-spin"}),!o&&m&&e.jsx("div",{className:"mr-2",children:m}),r,!o&&x&&e.jsx("div",{className:"ml-2",children:x}),x&&o&&e.jsx(Ha,{className:"ml-2 h-4 w-4 animate-spin"})]})});D.displayName="Button";function Ks({className:s,minimal:n=!1}){const a=Ns();return e.jsx("div",{className:N("h-svh w-full",s),children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[!n&&e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"500"}),e.jsxs("span",{className:"font-medium",children:["Oops! Something went wrong ",":')"]}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["We apologize for the inconvenience. ",e.jsx("br",{})," Please try again later."]}),!n&&e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(D,{variant:"outline",onClick:()=>a(-1),children:"Go Back"}),e.jsx(D,{onClick:()=>a("/"),children:"Back to Home"})]})]})})}function Xa(){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(D,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(D,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function ec(){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(D,{variant:"outline",children:"Learn more"})})]})})}function sc(s){return typeof s>"u"}function tc(s){return s===null}function ac(s){return tc(s)||sc(s)}class nc{storage;prefixKey;constructor(n){this.storage=n.storage,this.prefixKey=n.prefixKey}getKey(n){return`${this.prefixKey}${n}`.toUpperCase()}set(n,a,l=null){const r=JSON.stringify({value:a,time:Date.now(),expire:l!==null?new Date().getTime()+l*1e3:null});this.storage.setItem(this.getKey(n),r)}get(n,a=null){const l=this.storage.getItem(this.getKey(n));if(!l)return{value:a,time:0};try{const r=JSON.parse(l),{value:c,time:o,expire:m}=r;return ac(m)||m>new Date().getTime()?{value:c,time:o}:(this.remove(n),{value:a,time:0})}catch{return this.remove(n),{value:a,time:0}}}remove(n){this.storage.removeItem(this.getKey(n))}clear(){this.storage.clear()}}function gr({prefixKey:s="",storage:n=sessionStorage}){return new nc({prefixKey:s,storage:n})}const jr="Xboard_",rc=function(s={}){return gr({prefixKey:s.prefixKey||"",storage:localStorage})},lc=function(s={}){return gr({prefixKey:s.prefixKey||"",storage:sessionStorage})},Ht=rc({prefixKey:jr});lc({prefixKey:jr});const vr="access_token";function xt(){return Ht.get(vr)}function br(){Ht.remove(vr)}const en=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function ic({children:s}){const n=Ns(),a=Na(),l=xt();return u.useEffect(()=>{if(!l.value&&!en.includes(a.pathname)){const r=encodeURIComponent(a.pathname+a.search);n(`/sign-in?redirect=${r}`)}},[l.value,a.pathname,a.search,n]),en.includes(a.pathname)||l.value?e.jsx(e.Fragment,{children:s}):null}const oc=()=>e.jsx(ic,{children:e.jsx(_a,{})}),cc=kl([{path:"/sign-in",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Vc);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(oc,{}),children:[{path:"/",lazy:async()=>({Component:(await me(()=>Promise.resolve().then(()=>Uc),void 0,import.meta.url)).default}),errorElement:e.jsx(Ks,{}),children:[{index:!0,lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>um);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(Ks,{}),children:[{path:"system",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>pm);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>bm);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Cm);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Pm);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Om);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Am);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Km);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Qm);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>su);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>lu);return{default:s}},void 0,import.meta.url)).default})}]},{path:"payment",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>pu);return{default:s}},void 0,import.meta.url)).default})},{path:"plugin",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>vu);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>_u);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Pu);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>zu);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(Ks,{}),children:[{path:"manage",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>cx);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>hx);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>bx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(Ks,{}),children:[{path:"plan",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Dx);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Ux);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Zx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(Ks,{}),children:[{path:"manage",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Dh);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await me(async()=>{const{default:s}=await Promise.resolve().then(()=>Yh);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:Ks},{path:"/404",Component:Xa},{path:"/503",Component:ec},{path:"*",Component:Xa}]),dc="locale";function mc(){return Ht.get(dc)}function yr(){br();const s=window.location.pathname,n=s&&!["/404","/sign-in"].includes(s),a=new URL(window.location.href),r=`${a.pathname.split("/")[1]?`/${a.pathname.split("/")[1]}`:""}#/sign-in`;window.location.href=r+(n?`?redirect=${s}`:"")}const uc=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function xc(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const V=Tl.create({baseURL:xc(),timeout:12e3,headers:{"Content-Type":"application/json"}});V.interceptors.request.use(s=>{s.method?.toLowerCase()==="get"&&(s.params={...s.params,t:Date.now()});const n=xt();if(!uc.includes(s.url?.split("?")[0]||"")){if(!n.value)return yr(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=n.value}return s.headers["Content-Language"]=mc().value||"zh-CN",s},s=>Promise.reject(s));V.interceptors.response.use(s=>s?.data||{code:-1,message:"未知错误"},s=>{const n=s.response?.status,a=s.response?.data?.message;return(n===401||n===403)&&yr(),$.error(a||{401:"登录已过期",403:"没有权限",404:"资源或接口不存在"}[n]||"未知异常"),Promise.reject(s.response?.data||{data:null,code:-1,message:"未知错误"})});function hc(){return V.get("/user/info")}const ta={token:xt()?.value||"",userInfo:null,isLoggedIn:!!xt()?.value,loading:!1,error:null},ct=Dl("user/fetchUserInfo",async()=>(await hc()).data,{condition:(s,{getState:n})=>{const{user:a}=n();return!!a.token&&!a.loading}}),Nr=Pl({name:"user",initialState:ta,reducers:{setToken(s,n){s.token=n.payload,s.isLoggedIn=!!n.payload},resetUserState:()=>ta},extraReducers:s=>{s.addCase(ct.pending,n=>{n.loading=!0,n.error=null}).addCase(ct.fulfilled,(n,a)=>{n.loading=!1,n.userInfo=a.payload,n.error=null}).addCase(ct.rejected,(n,a)=>{if(n.loading=!1,n.error=a.error.message||"Failed to fetch user info",!n.token)return ta})}}),{setToken:fc,resetUserState:pc}=Nr.actions,gc=s=>s.user.userInfo,jc=Nr.reducer,_r=El({reducer:{user:jc}});xt()?.value&&_r.dispatch(ct());Rl.use(Il).use(Vl).init({resources:{"en-US":window.XBOARD_TRANSLATIONS?.["en-US"]||{},"zh-CN":window.XBOARD_TRANSLATIONS?.["zh-CN"]||{},"ko-KR":window.XBOARD_TRANSLATIONS?.["ko-KR"]||{}},fallbackLng:"zh-CN",supportedLngs:["en-US","zh-CN","ko-KR"],detection:{order:["querystring","localStorage","navigator"],lookupQuerystring:"lang",lookupLocalStorage:"i18nextLng",caches:["localStorage"]},interpolation:{escapeValue:!1}});const vc=new Ol;Ml.createRoot(document.getElementById("root")).render(e.jsx(Fl.StrictMode,{children:e.jsx(zl,{client:vc,children:e.jsx(Ll,{store:_r,children:e.jsxs(Qo,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(Al,{router:cc}),e.jsx($l,{richColors:!0,position:"top-right"})]})})})}));const He=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:N("rounded-xl border bg-card text-card-foreground shadow",s),...n}));He.displayName="Card";const Qe=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:N("flex flex-col space-y-1.5 p-6",s),...n}));Qe.displayName="CardHeader";const vs=u.forwardRef(({className:s,...n},a)=>e.jsx("h3",{ref:a,className:N("font-semibold leading-none tracking-tight",s),...n}));vs.displayName="CardTitle";const Qs=u.forwardRef(({className:s,...n},a)=>e.jsx("p",{ref:a,className:N("text-sm text-muted-foreground",s),...n}));Qs.displayName="CardDescription";const Je=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:N("p-6 pt-0",s),...n}));Je.displayName="CardContent";const bc=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:N("flex items-center p-6 pt-0",s),...n}));bc.displayName="CardFooter";const yc=Fs("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ot=u.forwardRef(({className:s,...n},a)=>e.jsx(fn,{ref:a,className:N(yc(),s),...n}));Ot.displayName=fn.displayName;const _e=ql,wr=u.createContext({}),b=({...s})=>e.jsx(wr.Provider,{value:{name:s.name},children:e.jsx(Ul,{...s})}),Kt=()=>{const s=u.useContext(wr),n=u.useContext(Cr),{getFieldState:a,formState:l}=Hl(),r=a(s.name,l);if(!s)throw new Error("useFormField should be used within <FormField>");const{id:c}=n;return{id:c,name:s.name,formItemId:`${c}-form-item`,formDescriptionId:`${c}-form-item-description`,formMessageId:`${c}-form-item-message`,...r}},Cr=u.createContext({}),v=u.forwardRef(({className:s,...n},a)=>{const l=u.useId();return e.jsx(Cr.Provider,{value:{id:l},children:e.jsx("div",{ref:a,className:N("space-y-2",s),...n})})});v.displayName="FormItem";const y=u.forwardRef(({className:s,...n},a)=>{const{error:l,formItemId:r}=Kt();return e.jsx(Ot,{ref:a,className:N(l&&"text-destructive",s),htmlFor:r,...n})});y.displayName="FormLabel";const _=u.forwardRef(({...s},n)=>{const{error:a,formItemId:l,formDescriptionId:r,formMessageId:c}=Kt();return e.jsx(ya,{ref:n,id:l,"aria-describedby":a?`${r} ${c}`:`${r}`,"aria-invalid":!!a,...s})});_.displayName="FormControl";const z=u.forwardRef(({className:s,...n},a)=>{const{formDescriptionId:l}=Kt();return e.jsx("p",{ref:a,id:l,className:N("text-[0.8rem] text-muted-foreground",s),...n})});z.displayName="FormDescription";const T=u.forwardRef(({className:s,children:n,...a},l)=>{const{error:r,formMessageId:c}=Kt(),o=r?String(r?.message):n;return o?e.jsx("p",{ref:l,id:c,className:N("text-[0.8rem] font-medium text-destructive",s),...a,children:o}):null});T.displayName="FormMessage";const k=u.forwardRef(({className:s,type:n,...a},l)=>e.jsx("input",{type:n,className:N("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:l,...a}));k.displayName="Input";const Sr=u.forwardRef(({className:s,...n},a)=>{const[l,r]=u.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:l?"text":"password",className:N("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:a,...n}),e.jsx(D,{type:"button",size:"icon",variant:"ghost",className:"absolute right-1 top-1/2 h-6 w-6 -translate-y-1/2 rounded-md text-muted-foreground",onClick:()=>r(c=>!c),children:l?e.jsx(Kl,{size:18}):e.jsx(Bl,{size:18})})]})});Sr.displayName="PasswordInput";const Nc=s=>V({url:"/passport/auth/login",method:"post",data:s});function ve(s=void 0,n="YYYY-MM-DD HH:mm:ss"){return s==null?"":(Math.floor(s).toString().length===10&&(s=s*1e3),Gl(s).format(n))}function _c(s=void 0,n="YYYY-MM-DD"){return ve(s,n)}function Ws(s){const n=typeof s=="string"?parseFloat(s):s;return isNaN(n)?"0.00":n.toFixed(2)}function Os(s,n=!0){if(s==null)return n?"¥0.00":"0.00";const a=typeof s=="string"?parseFloat(s):s;if(isNaN(a))return n?"¥0.00":"0.00";const r=(a/100).toFixed(2).replace(/\.?0+$/,c=>c.includes(".")?".00":c);return n?`¥${r}`:r}function Mt(s){return new Promise(n=>{(async()=>{try{if(navigator.clipboard)await navigator.clipboard.writeText(s);else{const l=document.createElement("textarea");l.value=s,l.style.position="fixed",l.style.opacity="0",document.body.appendChild(l),l.select();const r=document.execCommand("copy");if(document.body.removeChild(l),!r)throw new Error("execCommand failed")}n(!0)}catch(l){console.error(l),n(!1)}})()})}function ds(s){const n=s/1024,a=n/1024,l=a/1024,r=l/1024;return r>=1?Ws(r)+" TB":l>=1?Ws(l)+" GB":a>=1?Ws(a)+" MB":Ws(n)+" KB"}const wc="access_token";function Cc(s){Ht.set(wc,s)}function Sc({className:s,onForgotPassword:n,...a}){const l=Ns(),r=pn(),{t:c}=M("auth"),o=h.object({email:h.string().min(1,{message:c("signIn.validation.emailRequired")}),password:h.string().min(1,{message:c("signIn.validation.passwordRequired")}).min(7,{message:c("signIn.validation.passwordLength")})}),m=je({resolver:Ne(o),defaultValues:{email:"",password:""}});async function x(i){try{const{data:d}=await Nc(i);Cc(d.auth_data),r(fc(d.auth_data)),await r(ct()).unwrap(),l("/")}catch(d){console.error("Login failed:",d),d.response?.data?.message&&m.setError("root",{message:d.response.data.message})}}return e.jsx("div",{className:N("grid gap-6",s),...a,children:e.jsx(_e,{...m,children:e.jsx("form",{onSubmit:m.handleSubmit(x),className:"space-y-4",children:e.jsxs("div",{className:"space-y-4",children:[m.formState.errors.root&&e.jsx("div",{className:"text-sm text-destructive",children:m.formState.errors.root.message}),e.jsx(b,{control:m.control,name:"email",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:c("signIn.email")}),e.jsx(_,{children:e.jsx(k,{placeholder:c("signIn.emailPlaceholder"),autoComplete:"email",...i})}),e.jsx(T,{})]})}),e.jsx(b,{control:m.control,name:"password",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:c("signIn.password")}),e.jsx(_,{children:e.jsx(Sr,{placeholder:c("signIn.passwordPlaceholder"),autoComplete:"current-password",...i})}),e.jsx(T,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(D,{variant:"link",type:"button",className:"px-0 text-sm font-normal text-muted-foreground hover:text-primary",onClick:n,children:c("signIn.forgotPassword")})}),e.jsx(D,{className:"w-full",size:"lg",loading:m.formState.isSubmitting,children:c("signIn.submit")})]})})})})}const be=gn,Ge=jn,kc=vn,jt=wa,kr=u.forwardRef(({className:s,...n},a)=>e.jsx(Lt,{ref:a,className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n}));kr.displayName=Lt.displayName;const ge=u.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(kc,{children:[e.jsx(kr,{}),e.jsxs(At,{ref:l,className:N("max-h-[95%] overflow-auto fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...a,children:[n,e.jsxs(wa,{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(Ye,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ge.displayName=At.displayName;const we=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-1.5 text-center sm:text-left",s),...n});we.displayName="DialogHeader";const Ae=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Ae.displayName="DialogFooter";const ye=u.forwardRef(({className:s,...n},a)=>e.jsx($t,{ref:a,className:N("text-lg font-semibold leading-none tracking-tight",s),...n}));ye.displayName=$t.displayName;const De=u.forwardRef(({className:s,...n},a)=>e.jsx(qt,{ref:a,className:N("text-sm text-muted-foreground",s),...n}));De.displayName=qt.displayName;const Js=Fs("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"}}),G=u.forwardRef(({className:s,variant:n,size:a,asChild:l=!1,...r},c)=>{const o=l?ya:"button";return e.jsx(o,{className:N(Js({variant:n,size:a,className:s})),ref:c,...r})});G.displayName="Button";const bs=Ql,ys=Jl,Tc=Zl,Dc=u.forwardRef(({className:s,inset:n,children:a,...l},r)=>e.jsxs(bn,{ref:r,className:N("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",n&&"pl-8",s),...l,children:[a,e.jsx(Ca,{className:"ml-auto h-4 w-4"})]}));Dc.displayName=bn.displayName;const Pc=u.forwardRef(({className:s,...n},a)=>e.jsx(yn,{ref:a,className:N("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...n}));Pc.displayName=yn.displayName;const us=u.forwardRef(({className:s,sideOffset:n=4,...a},l)=>e.jsx(Wl,{children:e.jsx(Nn,{ref:l,sideOffset:n,className:N("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...a})}));us.displayName=Nn.displayName;const fe=u.forwardRef(({className:s,inset:n,...a},l)=>e.jsx(_n,{ref:l,className:N("relative flex cursor-default cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n&&"pl-8",s),...a}));fe.displayName=_n.displayName;const Ec=u.forwardRef(({className:s,children:n,checked:a,...l},r)=>e.jsxs(wn,{ref:r,className:N("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:a,...l,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Cn,{children:e.jsx(zs,{className:"h-4 w-4"})})}),n]}));Ec.displayName=wn.displayName;const Rc=u.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(Sn,{ref:l,className:N("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Cn,{children:e.jsx(Yl,{className:"h-4 w-4 fill-current"})})}),n]}));Rc.displayName=Sn.displayName;const Ea=u.forwardRef(({className:s,inset:n,...a},l)=>e.jsx(kn,{ref:l,className:N("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",s),...a}));Ea.displayName=kn.displayName;const Zs=u.forwardRef(({className:s,...n},a)=>e.jsx(Tn,{ref:a,className:N("-mx-1 my-1 h-px bg-muted",s),...n}));Zs.displayName=Tn.displayName;const ja=({className:s,...n})=>e.jsx("span",{className:N("ml-auto text-xs tracking-widest opacity-60",s),...n});ja.displayName="DropdownMenuShortcut";const aa=[{code:"en-US",name:"English",flag:Xl,shortName:"EN"},{code:"zh-CN",name:"中文",flag:ei,shortName:"CN"},{code:"ko-KR",name:"한국어",flag:si,shortName:"KR"}];function Tr(){const{i18n:s}=M(),n=r=>{s.changeLanguage(r)},a=aa.find(r=>r.code===s.language)||aa[1],l=a.flag;return e.jsxs(bs,{children:[e.jsx(ys,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 px-2 gap-1",children:[e.jsx(l,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:"text-sm font-medium",children:a.shortName})]})}),e.jsx(us,{align:"end",className:"w-[120px]",children:aa.map(r=>{const c=r.flag,o=r.code===s.language;return e.jsxs(fe,{onClick:()=>n(r.code),className:N("flex items-center gap-2 px-2 py-1.5 cursor-pointer",o&&"bg-accent"),children:[e.jsx(c,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:N("text-sm",o&&"font-medium"),children:r.name})]},r.code)})})]})}function Ic(){const[s,n]=u.useState(!1),{t:a}=M("auth"),l=a("signIn.resetPassword.command");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"container relative grid h-svh flex-col items-center justify-center bg-primary-foreground lg:max-w-none lg:px-0",children:[e.jsx("div",{className:"absolute right-4 top-4 md:right-8 md:top-8",children:e.jsx(Tr,{})}),e.jsxs("div",{className:"mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[480px] lg:p-8",children:[e.jsxs("div",{className:"flex flex-col space-y-2 text-center",children:[e.jsx("h1",{className:"text-3xl font-bold",children:window?.settings?.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:window?.settings?.description})]}),e.jsxs(He,{className:"p-6",children:[e.jsxs("div",{className:"flex flex-col space-y-2 text-left",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:a("signIn.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("signIn.description")})]}),e.jsx(Sc,{onForgotPassword:()=>n(!0)})]})]})]}),e.jsx(be,{open:s,onOpenChange:n,children:e.jsx(ge,{children:e.jsxs(we,{children:[e.jsx(ye,{children:a("signIn.resetPassword.title")}),e.jsx(De,{children:a("signIn.resetPassword.description")}),e.jsx("div",{className:"mt-4",children:e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"rounded-md bg-secondary p-4 pr-12 text-sm",children:l}),e.jsx(G,{variant:"ghost",size:"icon",className:"absolute right-2 top-2 h-8 w-8 hover:bg-secondary-foreground/10",onClick:()=>Mt(l).then(()=>{$.success(a("common:copy.success"))}),children:e.jsx(ti,{className:"h-4 w-4"})})]})})]})})})]})}const Vc=Object.freeze(Object.defineProperty({__proto__:null,default:Ic},Symbol.toStringTag,{value:"Module"})),Pe=u.forwardRef(({className:s,fadedBelow:n=!1,fixedHeight:a=!1,...l},r)=>e.jsx("div",{ref:r,className:N("relative flex h-full w-full flex-col",n&&"after:pointer-events-none after:absolute after:bottom-0 after:left-0 after:hidden after:h-32 after:w-full after:bg-[linear-gradient(180deg,_transparent_10%,_hsl(var(--background))_70%)] after:md:block",a&&"md:h-svh",s),...l}));Pe.displayName="Layout";const Ee=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{ref:a,className:N("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...n}));Ee.displayName="LayoutHeader";const Ve=u.forwardRef(({className:s,fixedHeight:n,...a},l)=>e.jsx("div",{ref:l,className:N("flex-1 overflow-hidden px-4 py-6 md:px-8",n&&"h-[calc(100%-var(--header-height))]",s),...a}));Ve.displayName="LayoutBody";const Dr=ai,Pr=ni,Er=ri,pe=li,xe=ii,he=oi,ce=u.forwardRef(({className:s,sideOffset:n=4,...a},l)=>e.jsx(Dn,{ref:l,sideOffset:n,className:N("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...a}));ce.displayName=Dn.displayName;function Bt(){const{pathname:s}=Na();return{checkActiveNav:a=>{if(a==="/"&&s==="/")return!0;const l=a.replace(/^\//,""),r=s.replace(/^\//,"");return l?r.startsWith(l):!1}}}function Rr({key:s,defaultValue:n}){const[a,l]=u.useState(()=>{const r=localStorage.getItem(s);return r!==null?JSON.parse(r):n});return u.useEffect(()=>{localStorage.setItem(s,JSON.stringify(a))},[a,s]),[a,l]}function Oc(){const[s,n]=Rr({key:"collapsed-sidebar-items",defaultValue:[]}),a=r=>!s.includes(r);return{isExpanded:a,toggleItem:r=>{a(r)?n([...s,r]):n(s.filter(c=>c!==r))}}}function Mc({links:s,isCollapsed:n,className:a,closeNav:l}){const{t:r}=M(),c=({sub:o,...m})=>{const x=`${r(m.title)}-${m.href}`;return n&&o?u.createElement(Lc,{...m,sub:o,key:x,closeNav:l}):n?u.createElement(zc,{...m,key:x,closeNav:l}):o?u.createElement(Fc,{...m,sub:o,key:x,closeNav:l}):u.createElement(Ir,{...m,key:x,closeNav:l})};return e.jsx("div",{"data-collapsed":n,className:N("group border-b bg-background py-2 transition-[max-height,padding] duration-500 data-[collapsed=true]:py-2 md:border-none",a),children:e.jsx(pe,{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(c)})})})}function Ir({title:s,icon:n,label:a,href:l,closeNav:r,subLink:c=!1}){const{checkActiveNav:o}=Bt(),{t:m}=M();return e.jsxs(Ls,{to:l,onClick:r,className:N(et({variant:o(l)?"secondary":"ghost",size:"sm"}),"h-12 justify-start text-wrap rounded-none px-6",c&&"h-10 w-full border-l border-l-slate-500 px-2"),"aria-current":o(l)?"page":void 0,children:[e.jsx("div",{className:"mr-2",children:n}),m(s),a&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:m(a)})]})}function Fc({title:s,icon:n,label:a,sub:l,closeNav:r}){const{checkActiveNav:c}=Bt(),{isExpanded:o,toggleItem:m}=Oc(),{t:x}=M(),i=!!l?.find(C=>c(C.href)),d=x(s),p=o(d)||i;return e.jsxs(Dr,{open:p,onOpenChange:()=>m(d),children:[e.jsxs(Pr,{className:N(et({variant:i?"secondary":"ghost",size:"sm"}),"group h-12 w-full justify-start rounded-none px-6"),children:[e.jsx("div",{className:"mr-2",children:n}),x(s),a&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:x(a)}),e.jsx("span",{className:N('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(Pn,{stroke:1})})]}),e.jsx(Er,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:l.map(C=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(Ir,{...C,subLink:!0,closeNav:r})},x(C.title)))})})]})}function zc({title:s,icon:n,label:a,href:l,closeNav:r}){const{checkActiveNav:c}=Bt(),{t:o}=M();return e.jsxs(xe,{delayDuration:0,children:[e.jsx(he,{asChild:!0,children:e.jsxs(Ls,{to:l,onClick:r,className:N(et({variant:c(l)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[n,e.jsx("span",{className:"sr-only",children:o(s)})]})}),e.jsxs(ce,{side:"right",className:"flex items-center gap-4",children:[o(s),a&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:o(a)})]})]})}function Lc({title:s,icon:n,label:a,sub:l,closeNav:r}){const{checkActiveNav:c}=Bt(),{t:o}=M(),m=!!l?.find(x=>c(x.href));return e.jsxs(bs,{children:[e.jsxs(xe,{delayDuration:0,children:[e.jsx(he,{asChild:!0,children:e.jsx(ys,{asChild:!0,children:e.jsx(D,{variant:m?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:n})})}),e.jsxs(ce,{side:"right",className:"flex items-center gap-4",children:[o(s)," ",a&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:o(a)}),e.jsx(Pn,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(us,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(Ea,{children:[o(s)," ",a?`(${o(a)})`:""]}),e.jsx(Zs,{}),l.map(({title:x,icon:i,label:d,href:p})=>e.jsx(fe,{asChild:!0,children:e.jsxs(Ls,{to:p,onClick:r,className:`${c(p)?"bg-secondary":""}`,children:[i," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:o(x)}),d&&e.jsx("span",{className:"ml-auto text-xs",children:o(d)})]})},`${o(x)}-${p}`))]})]})}const Vr=[{title:"nav:dashboard",label:"",href:"/",icon:e.jsx(ci,{size:18})},{title:"nav:systemManagement",label:"",href:"",icon:e.jsx(di,{size:18}),sub:[{title:"nav:systemConfig",label:"",href:"/config/system",icon:e.jsx(En,{size:18})},{title:"nav:pluginManagement",label:"",href:"/config/plugin",icon:e.jsx(Sa,{size:18})},{title:"nav:themeConfig",label:"",href:"/config/theme",icon:e.jsx(mi,{size:18})},{title:"nav:noticeManagement",label:"",href:"/config/notice",icon:e.jsx(ui,{size:18})},{title:"nav:paymentConfig",label:"",href:"/config/payment",icon:e.jsx(Ka,{size:18})},{title:"nav:knowledgeManagement",label:"",href:"/config/knowledge",icon:e.jsx(xi,{size:18})}]},{title:"nav:nodeManagement",label:"",href:"",icon:e.jsx(Rn,{size:18}),sub:[{title:"nav:nodeManagement",label:"",href:"/server/manage",icon:e.jsx(hi,{size:18})},{title:"nav:permissionGroupManagement",label:"",href:"/server/group",icon:e.jsx(In,{size:18})},{title:"nav:routeManagement",label:"",href:"/server/route",icon:e.jsx(fi,{size:18})}]},{title:"nav:subscriptionManagement",label:"",href:"",icon:e.jsx(pi,{size:18}),sub:[{title:"nav:planManagement",label:"",href:"/finance/plan",icon:e.jsx(gi,{size:18})},{title:"nav:orderManagement",label:"",href:"/finance/order",icon:e.jsx(Ka,{size:18})},{title:"nav:couponManagement",label:"",href:"/finance/coupon",icon:e.jsx(ji,{size:18})}]},{title:"nav:userManagement",label:"",href:"",icon:e.jsx(vi,{size:18}),sub:[{title:"nav:userManagement",label:"",href:"/user/manage",icon:e.jsx(bi,{size:18})},{title:"nav:ticketManagement",label:"",href:"/user/ticket",icon:e.jsx(Vn,{size:18})}]}];function Ac({className:s,isCollapsed:n,setIsCollapsed:a}){const[l,r]=u.useState(!1),{t:c}=M();return u.useEffect(()=>{l?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[l]),e.jsxs("aside",{className:N(`fixed left-0 right-0 top-0 z-50 w-full border-r-2 border-r-muted transition-[width] md:bottom-0 md:right-auto md:h-svh ${n?"md:w-14":"md:w-64"}`,s),children:[e.jsx("div",{onClick:()=>r(!1),className:`absolute inset-0 transition-[opacity] delay-100 duration-700 ${l?"h-svh opacity-50":"h-0 opacity-0"} w-full bg-black md:hidden`}),e.jsxs(Pe,{children:[e.jsxs(Ee,{className:"sticky top-0 justify-between px-4 py-3 shadow md:px-4",children:[e.jsxs("div",{className:`flex items-center ${n?"":"gap-2"}`,children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",className:`transition-all ${n?"h-6 w-6":"h-8 w-8"}`,children:[e.jsx("rect",{width:"256",height:"256",fill:"none"}),e.jsx("line",{x1:"208",y1:"128",x2:"128",y2:"208",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"16"}),e.jsx("line",{x1:"192",y1:"40",x2:"40",y2:"192",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"16"}),e.jsx("span",{className:"sr-only",children:"Website Name"})]}),e.jsx("div",{className:`flex flex-col justify-end truncate ${n?"invisible w-0":"visible w-auto"}`,children:e.jsx("span",{className:"font-medium",children:window?.settings?.title})})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":c("common:toggleNavigation"),"aria-controls":"sidebar-menu","aria-expanded":l,onClick:()=>r(o=>!o),children:l?e.jsx(yi,{}):e.jsx(Ni,{})})]}),e.jsx(Mc,{id:"sidebar-menu",className:`h-full flex-1 overflow-auto ${l?"max-h-screen":"max-h-0 py-0 md:max-h-screen md:py-2"}`,closeNav:()=>r(!1),isCollapsed:n,links:Vr}),e.jsx("div",{className:N("px-4 py-3 text-xs text-muted-foreground/70 border-t border-border/50 bg-muted/20","transition-all duration-200 ease-in-out",n?"text-center":"text-left"),children:e.jsxs("div",{className:N("flex items-center gap-1.5",n?"justify-center":"justify-start"),children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-green-500/70"}),e.jsxs("span",{className:"tracking-wide",children:["v",window?.settings?.version]})]})}),e.jsx(D,{onClick:()=>a(o=>!o),size:"icon",variant:"outline",className:"absolute -right-5 top-1/2 hidden rounded-full md:inline-flex","aria-label":c("common:toggleSidebar"),children:e.jsx(_i,{stroke:1.5,className:`h-5 w-5 ${n?"rotate-180":""}`})})]})]})}function $c(){const[s,n]=Rr({key:"collapsed-sidebar",defaultValue:!1});return u.useEffect(()=>{const a=()=>{n(window.innerWidth<768?!1:s)};return a(),window.addEventListener("resize",a),()=>{window.removeEventListener("resize",a)}},[s,n]),[s,n]}function qc(){const[s,n]=$c();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(Ac,{isCollapsed:s,setIsCollapsed:n}),e.jsx("main",{id:"content",className:`overflow-x-hidden pt-16 transition-[margin] md:overflow-y-hidden md:pt-0 ${s?"md:ml-14":"md:ml-64"} h-full`,children:e.jsx(_a,{})})]})}const Uc=Object.freeze(Object.defineProperty({__proto__:null,default:qc},Symbol.toStringTag,{value:"Module"})),Is=u.forwardRef(({className:s,...n},a)=>e.jsx(Me,{ref:a,className:N("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...n}));Is.displayName=Me.displayName;const Hc=({children:s,...n})=>e.jsx(be,{...n,children:e.jsx(ge,{className:"overflow-hidden p-0",children:e.jsx(Is,{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})})}),$s=u.forwardRef(({className:s,...n},a)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(wi,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(Me.Input,{ref:a,className:N("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",s),...n})]}));$s.displayName=Me.Input.displayName;const Vs=u.forwardRef(({className:s,...n},a)=>e.jsx(Me.List,{ref:a,className:N("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...n}));Vs.displayName=Me.List.displayName;const qs=u.forwardRef((s,n)=>e.jsx(Me.Empty,{ref:n,className:"py-6 text-center text-sm",...s}));qs.displayName=Me.Empty.displayName;const Ke=u.forwardRef(({className:s,...n},a)=>e.jsx(Me.Group,{ref:a,className:N("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",s),...n}));Ke.displayName=Me.Group.displayName;const st=u.forwardRef(({className:s,...n},a)=>e.jsx(Me.Separator,{ref:a,className:N("-mx-1 h-px bg-border",s),...n}));st.displayName=Me.Separator.displayName;const Ie=u.forwardRef(({className:s,...n},a)=>e.jsx(Me.Item,{ref:a,className:N("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...n}));Ie.displayName=Me.Item.displayName;function Kc(){const s=[];for(const n of Vr)if(n.href&&s.push(n),n.sub)for(const a of n.sub)s.push({...a,parent:n.title});return s}function $e(){const[s,n]=u.useState(!1),a=Ns(),l=Kc(),{t:r}=M("search"),{t:c}=M("nav");u.useEffect(()=>{const m=x=>{x.key==="k"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),n(i=>!i))};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[]);const o=u.useCallback(m=>{n(!1),a(m)},[a]);return e.jsxs(e.Fragment,{children:[e.jsxs(G,{variant:"outline",className:"relative h-9 w-9 p-0 xl:h-10 xl:w-60 xl:justify-start xl:px-3 xl:py-2",onClick:()=>n(!0),children:[e.jsx(On,{className:"h-4 w-4 xl:mr-2"}),e.jsx("span",{className:"hidden xl:inline-flex",children:r("placeholder")}),e.jsx("span",{className:"sr-only",children:r("shortcut.label")}),e.jsx("kbd",{className:"pointer-events-none absolute right-1.5 top-2 hidden h-6 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium opacity-100 xl:flex",children:r("shortcut.key")})]}),e.jsxs(Hc,{open:s,onOpenChange:n,children:[e.jsx($s,{placeholder:r("placeholder")}),e.jsxs(Vs,{children:[e.jsx(qs,{children:r("noResults")}),e.jsx(Ke,{heading:r("title"),children:l.map(m=>e.jsxs(Ie,{value:`${m.parent?m.parent+" ":""}${m.title}`,onSelect:()=>o(m.href),children:[e.jsx("div",{className:"mr-2",children:m.icon}),e.jsx("span",{children:c(m.title)}),m.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:c(m.parent)})]},m.href))})]})]})]})}function Fe(){const{theme:s,setTheme:n}=Jo();return u.useEffect(()=>{const a=s==="dark"?"#020817":"#fff",l=document.querySelector("meta[name='theme-color']");l&&l.setAttribute("content",a)},[s]),e.jsxs(e.Fragment,{children:[e.jsx(D,{size:"icon",variant:"ghost",className:"rounded-full",onClick:()=>n(s==="light"?"dark":"light"),children:s==="light"?e.jsx(Ci,{size:20}):e.jsx(Si,{size:20})}),e.jsx(Tr,{})]})}const Or=u.forwardRef(({className:s,...n},a)=>e.jsx(Mn,{ref:a,className:N("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...n}));Or.displayName=Mn.displayName;const Mr=u.forwardRef(({className:s,...n},a)=>e.jsx(Fn,{ref:a,className:N("aspect-square h-full w-full",s),...n}));Mr.displayName=Fn.displayName;const Fr=u.forwardRef(({className:s,...n},a)=>e.jsx(zn,{ref:a,className:N("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...n}));Fr.displayName=zn.displayName;function ze(){const s=Ns(),n=pn(),a=ki(gc),{t:l}=M(["common"]),r=()=>{br(),n(pc()),s("/sign-in")},c=a?.email?.split("@")[0]||l("common:user"),o=c.substring(0,2).toUpperCase();return e.jsxs(bs,{children:[e.jsx(ys,{asChild:!0,children:e.jsx(D,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(Or,{className:"h-8 w-8",children:[e.jsx(Mr,{src:a?.avatar_url,alt:c}),e.jsx(Fr,{children:o})]})})}),e.jsxs(us,{className:"w-56",align:"end",forceMount:!0,children:[e.jsx(Ea,{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:c}),e.jsx("p",{className:"text-xs leading-none text-muted-foreground",children:a?.email||l("common:defaultEmail")})]})}),e.jsx(Zs,{}),e.jsx(fe,{asChild:!0,children:e.jsxs(Ls,{to:"/config/system",children:[l("common:settings"),e.jsx(ja,{children:"⌘S"})]})}),e.jsx(Zs,{}),e.jsxs(fe,{onClick:r,children:[l("common:logout"),e.jsx(ja,{children:"⇧⌘Q"})]})]})]})}const H=window?.settings?.secure_path,Bc=s=>V.get(H+"/stat/getOrder",{params:s}),Gc=()=>V.get(H+"/stat/getStats"),sn=s=>V.get(H+"/stat/getTrafficRank",{params:s}),Wc=()=>V.get(H+"/theme/getThemes"),Yc=s=>V.post(H+"/theme/getThemeConfig",{name:s}),Qc=(s,n)=>V.post(H+"/theme/saveThemeConfig",{name:s,config:n}),Jc=s=>{const n=new FormData;return n.append("file",s),V.post(H+"/theme/upload",n,{headers:{"Content-Type":"multipart/form-data"}})},Zc=s=>V.post(H+"/theme/delete",{name:s}),Xc=s=>V.post(H+"/config/save",s),zr=()=>V.get(H+"/server/manage/getNodes"),ed=s=>V.post(H+"/server/manage/save",s),sd=s=>V.post(H+"/server/manage/drop",s),td=s=>V.post(H+"/server/manage/copy",s),ad=s=>V.post(H+"/server/manage/update",s),nd=s=>V.post(H+"/server/manage/sort",s),vt=()=>V.get(H+"/server/group/fetch"),rd=s=>V.post(H+"/server/group/save",s),ld=s=>V.post(H+"/server/group/drop",s),Lr=()=>V.get(H+"/server/route/fetch"),id=s=>V.post(H+"/server/route/save",s),od=s=>V.post(H+"/server/route/drop",s),cd=()=>V.get(H+"/payment/fetch"),dd=()=>V.get(H+"/payment/getPaymentMethods"),md=s=>V.post(H+"/payment/getPaymentForm",s),ud=s=>V.post(H+"/payment/save",s),xd=s=>V.post(H+"/payment/drop",s),hd=s=>V.post(H+"/payment/show",s),fd=s=>V.post(H+"/payment/sort",s),pd=s=>V.post(H+"/notice/save",s),gd=s=>V.post(H+"/notice/drop",s),jd=s=>V.post(H+"/notice/show",s),vd=()=>V.get(H+"/knowledge/fetch"),bd=s=>V.get(H+"/knowledge/fetch?id="+s),yd=s=>V.post(H+"/knowledge/save",s),Nd=s=>V.post(H+"/knowledge/drop",s),_d=s=>V.post(H+"/knowledge/show",s),wd=s=>V.post(H+"/knowledge/sort",s),Us=()=>V.get(H+"/plan/fetch"),Cd=s=>V.post(H+"/plan/save",s),na=s=>V.post(H+"/plan/update",s),Sd=s=>V.post(H+"/plan/drop",s),kd=s=>V.post(H+"/plan/sort",{ids:s}),Td=async s=>V.post(H+"/order/fetch",s),Dd=s=>V.post(H+"/order/detail",s),Pd=s=>V.post(H+"/order/paid",s),Ed=s=>V.post(H+"/order/cancel",s),tn=s=>V.post(H+"/order/update",s),Rd=s=>V.post(H+"/order/assign",s),Id=s=>V.post(H+"/coupon/fetch",s),Vd=s=>V.post(H+"/coupon/generate",s),Od=s=>V.post(H+"/coupon/drop",s),Md=s=>V.post(H+"/coupon/update",s),Fd=s=>V.post(H+"/user/fetch",s),zd=s=>V.post(H+"/user/update",s),Ld=s=>V.post(H+"/user/resetSecret",s),Ad=s=>V.post(H+"/user/generate",s),$d=s=>V.post(H+"/stat/getStatUser",s),qd=s=>V.post(H+"/ticket/fetch",s),Ud=s=>V.get(H+"/ticket/fetch?id= "+s),Hd=s=>V.post(H+"/ticket/close",{id:s}),Cs=(s="")=>V.get(H+"/config/fetch?key="+s),Ss=s=>V.post(H+"/config/save",s),Kd=()=>V.get(H+"/config/getEmailTemplate"),Bd=()=>V.post(H+"/config/testSendMail"),Gd=()=>V.post(H+"/config/setTelegramWebhook"),Ra=Ti,Gt=u.forwardRef(({className:s,...n},a)=>e.jsx(Ln,{ref:a,className:N("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...n}));Gt.displayName=Ln.displayName;const Es=u.forwardRef(({className:s,...n},a)=>e.jsx(An,{ref:a,className:N("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",s),...n}));Es.displayName=An.displayName;const Tt=u.forwardRef(({className:s,...n},a)=>e.jsx($n,{ref:a,className:N("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...n}));Tt.displayName=$n.displayName;const X=Di,ks=Fi,ee=Pi,Q=u.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(qn,{ref:l,className:N("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",s),...a,children:[n,e.jsx(Ei,{asChild:!0,children:e.jsx(ka,{className:"h-4 w-4 opacity-50"})})]}));Q.displayName=qn.displayName;const Ar=u.forwardRef(({className:s,...n},a)=>e.jsx(Un,{ref:a,className:N("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(Ri,{className:"h-4 w-4"})}));Ar.displayName=Un.displayName;const $r=u.forwardRef(({className:s,...n},a)=>e.jsx(Hn,{ref:a,className:N("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(ka,{className:"h-4 w-4"})}));$r.displayName=Hn.displayName;const J=u.forwardRef(({className:s,children:n,position:a="popper",...l},r)=>e.jsx(Ii,{children:e.jsxs(Kn,{ref:r,className:N("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",s),position:a,...l,children:[e.jsx(Ar,{}),e.jsx(Vi,{className:N("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx($r,{})]})}));J.displayName=Kn.displayName;const Wd=u.forwardRef(({className:s,...n},a)=>e.jsx(Bn,{ref:a,className:N("px-2 py-1.5 text-sm font-semibold",s),...n}));Wd.displayName=Bn.displayName;const U=u.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(Gn,{ref:l,className:N("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...a,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Oi,{children:e.jsx(zs,{className:"h-4 w-4"})})}),e.jsx(Mi,{children:n})]}));U.displayName=Gn.displayName;const Yd=u.forwardRef(({className:s,...n},a)=>e.jsx(Wn,{ref:a,className:N("-mx-1 my-1 h-px bg-muted",s),...n}));Yd.displayName=Wn.displayName;function Hs({className:s,classNames:n,showOutsideDays:a=!0,...l}){return e.jsx(zi,{showOutsideDays:a,className:N("p-3",s),classNames:{months:"flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",month:"space-y-4",caption:"flex justify-center pt-1 relative items-center",caption_label:"text-sm font-medium",nav:"space-x-1 flex items-center",nav_button:N(Js({variant:"outline"}),"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"),nav_button_previous:"absolute left-1",nav_button_next:"absolute right-1",table:"w-full border-collapse space-y-1",head_row:"flex",head_cell:"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",row:"flex w-full mt-2",cell:N("relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md",l.mode==="range"?"[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md":"[&:has([aria-selected])]:rounded-md"),day:N(Js({variant:"ghost"}),"h-8 w-8 p-0 font-normal aria-selected:opacity-100"),day_range_start:"day-range-start",day_range_end:"day-range-end",day_selected:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",day_today:"bg-accent text-accent-foreground",day_outside:"day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground",day_disabled:"text-muted-foreground opacity-50",day_range_middle:"aria-selected:bg-accent aria-selected:text-accent-foreground",day_hidden:"invisible",...n},components:{IconLeft:({className:r,...c})=>e.jsx(Yn,{className:N("h-4 w-4",r),...c}),IconRight:({className:r,...c})=>e.jsx(Ca,{className:N("h-4 w-4",r),...c})},...l})}Hs.displayName="Calendar";const xs=Ai,hs=$i,os=u.forwardRef(({className:s,align:n="center",sideOffset:a=4,...l},r)=>e.jsx(Li,{children:e.jsx(Qn,{ref:r,align:n,sideOffset:a,className:N("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...l})}));os.displayName=Qn.displayName;const Ts={income:{main:"hsl(var(--primary))",gradient:{start:"hsl(var(--primary))",end:"transparent"}},commission:{main:"hsl(var(--secondary))",gradient:{start:"hsl(var(--secondary))",end:"transparent"}}},it=s=>(s/100).toFixed(2),Qd=({active:s,payload:n,label:a})=>{const{t:l}=M();return s&&n&&n.length?e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-sm",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:a}),n.map((r,c)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"h-2 w-2 rounded-full",style:{backgroundColor:r.color}}),e.jsxs("span",{className:"text-muted-foreground",children:[l(r.name),":"]}),e.jsx("span",{className:"font-medium",children:r.name.includes(l("dashboard:overview.amount"))?`¥${it(r.value)}`:l("dashboard:overview.transactions",{count:r.value})})]},c))]}):null},Jd=[{value:"7d",label:"dashboard:overview.last7Days"},{value:"30d",label:"dashboard:overview.last30Days"},{value:"90d",label:"dashboard:overview.last90Days"},{value:"180d",label:"dashboard:overview.last180Days"},{value:"365d",label:"dashboard:overview.lastYear"},{value:"custom",label:"dashboard:overview.customRange"}],Zd=(s,n)=>{const a=new Date;if(s==="custom"&&n)return{startDate:n.from,endDate:n.to};let l;switch(s){case"7d":l=ts(a,7);break;case"30d":l=ts(a,30);break;case"90d":l=ts(a,90);break;case"180d":l=ts(a,180);break;case"365d":l=ts(a,365);break;default:l=ts(a,30)}return{startDate:l,endDate:a}};function Xd(){const[s,n]=u.useState("amount"),[a,l]=u.useState("30d"),[r,c]=u.useState({from:ts(new Date,7),to:new Date}),{t:o}=M(),{startDate:m,endDate:x}=Zd(a,r),{data:i}=ie({queryKey:["orderStat",{start_date:ss(m,"yyyy-MM-dd"),end_date:ss(x,"yyyy-MM-dd")}],queryFn:async()=>{const{data:d}=await Bc({start_date:ss(m,"yyyy-MM-dd"),end_date:ss(x,"yyyy-MM-dd")});return d},refetchInterval:3e4});return e.jsxs(He,{children:[e.jsx(Qe,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(vs,{children:o("dashboard:overview.title")}),e.jsxs(Qs,{children:[i?.summary.start_date," ",o("dashboard:overview.to")," ",i?.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(X,{value:a,onValueChange:d=>l(d),children:[e.jsx(Q,{className:"w-[120px]",children:e.jsx(ee,{placeholder:o("dashboard:overview.selectTimeRange")})}),e.jsx(J,{children:Jd.map(d=>e.jsx(U,{value:d.value,children:o(d.label)},d.value))})]}),a==="custom"&&e.jsxs(xs,{children:[e.jsx(hs,{asChild:!0,children:e.jsxs(G,{variant:"outline",className:N("min-w-0 justify-start text-left font-normal",!r&&"text-muted-foreground"),children:[e.jsx(pt,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:r?.from?r.to?e.jsxs(e.Fragment,{children:[ss(r.from,"yyyy-MM-dd")," -"," ",ss(r.to,"yyyy-MM-dd")]}):ss(r.from,"yyyy-MM-dd"):o("dashboard:overview.selectDate")})]})}),e.jsx(os,{className:"w-auto p-0",align:"end",children:e.jsx(Hs,{mode:"range",defaultMonth:r?.from,selected:{from:r?.from,to:r?.to},onSelect:d=>{d?.from&&d?.to&&c({from:d.from,to:d.to})},numberOfMonths:2})})]})]}),e.jsx(Ra,{value:s,onValueChange:d=>n(d),children:e.jsxs(Gt,{children:[e.jsx(Es,{value:"amount",children:o("dashboard:overview.amount")}),e.jsx(Es,{value:"count",children:o("dashboard:overview.count")})]})})]})]})}),e.jsxs(Je,{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:o("dashboard:overview.totalIncome")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",it(i?.summary?.paid_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:o("dashboard:overview.totalTransactions",{count:i?.summary?.paid_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[o("dashboard:overview.avgOrderAmount")," ¥",it(i?.summary?.avg_paid_amount||0)]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:o("dashboard:overview.totalCommission")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",it(i?.summary?.commission_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:o("dashboard:overview.totalTransactions",{count:i?.summary?.commission_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[o("dashboard:overview.commissionRate")," ",i?.summary?.commission_rate.toFixed(2)||0,"%"]})]})]}),e.jsx("div",{className:"h-[400px] w-full",children:e.jsx(qi,{width:"100%",height:"100%",children:e.jsxs(Ui,{data:i?.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:Ts.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Ts.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:Ts.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Ts.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(Hi,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:d=>ss(new Date(d),"MM-dd",{locale:Wi})}),e.jsx(Ki,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:d=>s==="amount"?`¥${it(d)}`:o("dashboard:overview.transactions",{count:d})}),e.jsx(Bi,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(Gi,{content:e.jsx(Qd,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(Ba,{type:"monotone",dataKey:"paid_total",name:o("dashboard:overview.orderAmount"),stroke:Ts.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(Ba,{type:"monotone",dataKey:"commission_total",name:o("dashboard:overview.commissionAmount"),stroke:Ts.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ga,{dataKey:"paid_count",name:o("dashboard:overview.orderCount"),fill:Ts.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(Ga,{dataKey:"commission_count",name:o("dashboard:overview.commissionCount"),fill:Ts.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})]})]})}function oe({className:s,...n}){return e.jsx("div",{className:N("animate-pulse rounded-md bg-primary/10",s),...n})}function em(){return e.jsxs(He,{children:[e.jsxs(Qe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(oe,{className:"h-4 w-[120px]"}),e.jsx(oe,{className:"h-4 w-4"})]}),e.jsxs(Je,{children:[e.jsx(oe,{className:"h-8 w-[140px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx(oe,{className:"h-4 w-[100px]"})]})]})]})}function sm(){return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:Array.from({length:8}).map((s,n)=>e.jsx(em,{},n))})}var re=(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))(re||{});const rt={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},lt={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||{}),ue=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(ue||{});const yt={0:"待确认",1:"发放中",2:"有效",3:"无效"},Nt={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var Te=(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))(Te||{});const tm={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var ke=(s=>(s.Shadowsocks="shadowsocks",s.Vmess="vmess",s.Trojan="trojan",s.Hysteria="hysteria",s.Vless="vless",s))(ke||{});const Ms=[{type:"shadowsocks",label:"Shadowsocks"},{type:"vmess",label:"VMess"},{type:"trojan",label:"Trojan"},{type:"hysteria",label:"Hysteria"},{type:"vless",label:"VLess"}],js={shadowsocks:"#489851",vmess:"#CB3180",trojan:"#EBB749",hysteria:"#5684e6",vless:"#1a1a1a"};var Ue=(s=>(s[s.AMOUNT=1]="AMOUNT",s[s.PERCENTAGE=2]="PERCENTAGE",s))(Ue||{});const am={1:"按金额优惠",2:"按比例优惠"};var Rs=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(Rs||{}),Oe=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(Oe||{}),dt=(s=>(s.MONTH="monthly",s.QUARTER="quarterly",s.HALF_YEAR="half_yearly",s.YEAR="yearly",s.TWO_YEAR="two_yearly",s.THREE_YEAR="three_yearly",s.ONETIME="onetime",s.RESET="reset_traffic",s))(dt||{});function Ds({title:s,value:n,icon:a,trend:l,description:r,onClick:c,highlight:o,className:m}){return e.jsxs(He,{className:N("transition-colors",c&&"cursor-pointer hover:bg-muted/50",o&&"border-primary/50",m),onClick:c,children:[e.jsxs(Qe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(vs,{className:"text-sm font-medium",children:s}),a]}),e.jsxs(Je,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n}),l?e.jsxs("div",{className:"flex items-center pt-1",children:[e.jsx(eo,{className:N("h-4 w-4",l.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:N("ml-1 text-xs",l.isPositive?"text-emerald-500":"text-red-500"),children:[l.isPositive?"+":"-",Math.abs(l.value),"%"]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:l.label})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]})]})}function nm({className:s}){const n=Ns(),{t:a}=M(),{data:l,isLoading:r}=ie({queryKey:["dashboardStats"],queryFn:async()=>(await Gc()).data,refetchInterval:1e3*60*5});if(r||!l)return e.jsx(sm,{});const c=()=>{const o=new URLSearchParams;o.set("commission_status",ue.PENDING.toString()),o.set("status",re.COMPLETED.toString()),o.set("commission_balance","gt:0"),n(`/finance/order?${o.toString()}`)};return e.jsxs("div",{className:N("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(Ds,{title:a("dashboard:stats.todayIncome"),value:Os(l.todayIncome),icon:e.jsx(Yi,{className:"h-4 w-4 text-emerald-500"}),trend:{value:l.dayIncomeGrowth,label:a("dashboard:stats.vsYesterday"),isPositive:l.dayIncomeGrowth>0}}),e.jsx(Ds,{title:a("dashboard:stats.monthlyIncome"),value:Os(l.currentMonthIncome),icon:e.jsx(Qi,{className:"h-4 w-4 text-blue-500"}),trend:{value:l.monthIncomeGrowth,label:a("dashboard:stats.vsLastMonth"),isPositive:l.monthIncomeGrowth>0}}),e.jsx(Ds,{title:a("dashboard:stats.pendingTickets"),value:l.ticketPendingTotal,icon:e.jsx(Ji,{className:N("h-4 w-4",l.ticketPendingTotal>0?"text-orange-500":"text-muted-foreground")}),description:l.ticketPendingTotal>0?a("dashboard:stats.hasPendingTickets"):a("dashboard:stats.noPendingTickets"),onClick:()=>n("/user/ticket"),highlight:l.ticketPendingTotal>0}),e.jsx(Ds,{title:a("dashboard:stats.pendingCommission"),value:l.commissionPendingTotal,icon:e.jsx(Zi,{className:N("h-4 w-4",l.commissionPendingTotal>0?"text-blue-500":"text-muted-foreground")}),description:l.commissionPendingTotal>0?a("dashboard:stats.hasPendingCommission"):a("dashboard:stats.noPendingCommission"),onClick:c,highlight:l.commissionPendingTotal>0}),e.jsx(Ds,{title:a("dashboard:stats.monthlyNewUsers"),value:l.currentMonthNewUsers,icon:e.jsx(xa,{className:"h-4 w-4 text-blue-500"}),trend:{value:l.userGrowth,label:a("dashboard:stats.vsLastMonth"),isPositive:l.userGrowth>0}}),e.jsx(Ds,{title:a("dashboard:stats.totalUsers"),value:l.totalUsers,icon:e.jsx(xa,{className:"h-4 w-4 text-muted-foreground"}),description:a("dashboard:stats.activeUsers",{count:l.activeUsers})}),e.jsx(Ds,{title:a("dashboard:stats.monthlyUpload"),value:ds(l.monthTraffic.upload),icon:e.jsx(ut,{className:"h-4 w-4 text-emerald-500"}),description:a("dashboard:stats.todayTraffic",{value:ds(l.todayTraffic.upload)})}),e.jsx(Ds,{title:a("dashboard:stats.monthlyDownload"),value:ds(l.monthTraffic.download),icon:e.jsx(Xi,{className:"h-4 w-4 text-blue-500"}),description:a("dashboard:stats.todayTraffic",{value:ds(l.todayTraffic.download)})})]})}const Xs=u.forwardRef(({className:s,children:n,...a},l)=>e.jsxs(Jn,{ref:l,className:N("relative overflow-hidden",s),...a,children:[e.jsx(so,{className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(Ft,{}),e.jsx(to,{})]}));Xs.displayName=Jn.displayName;const Ft=u.forwardRef(({className:s,orientation:n="vertical",...a},l)=>e.jsx(Zn,{ref:l,orientation:n,className:N("flex touch-none select-none transition-colors",n==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",n==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",s),...a,children:e.jsx(ao,{className:"relative flex-1 rounded-full bg-border"})}));Ft.displayName=Zn.displayName;const va={today:{getValue:()=>{const s=ro();return{start:s,end:lo(s,1)}}},last7days:{getValue:()=>{const s=new Date;return{start:ts(s,7),end:s}}},last30days:{getValue:()=>{const s=new Date;return{start:ts(s,30),end:s}}},custom:{getValue:()=>null}};function an({selectedRange:s,customDateRange:n,onRangeChange:a,onCustomRangeChange:l}){const{t:r}=M(),c={today:r("dashboard:trafficRank.today"),last7days:r("dashboard:trafficRank.last7days"),last30days:r("dashboard:trafficRank.last30days"),custom:r("dashboard:trafficRank.customRange")};return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsxs(X,{value:s,onValueChange:a,children:[e.jsx(Q,{className:"w-[120px]",children:e.jsx(ee,{placeholder:r("dashboard:trafficRank.selectTimeRange")})}),e.jsx(J,{position:"popper",className:"z-50",children:Object.entries(va).map(([o])=>e.jsx(U,{value:o,children:c[o]},o))})]}),s==="custom"&&e.jsxs(xs,{children:[e.jsx(hs,{asChild:!0,children:e.jsxs(G,{variant:"outline",className:N("min-w-0 justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(pt,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:n?.from?n.to?e.jsxs(e.Fragment,{children:[ss(n.from,"yyyy-MM-dd")," -"," ",ss(n.to,"yyyy-MM-dd")]}):ss(n.from,"yyyy-MM-dd"):e.jsx("span",{children:r("dashboard:trafficRank.selectDateRange")})})]})}),e.jsx(os,{className:"w-auto p-0",align:"end",children:e.jsx(Hs,{mode:"range",defaultMonth:n?.from,selected:{from:n?.from,to:n?.to},onSelect:o=>{o?.from&&o?.to&&l({from:o.from,to:o.to})},numberOfMonths:2})})]})]})}const Bs=s=>`${(s/1024/1024/1024).toFixed(2)} GB`;function rm({className:s}){const{t:n}=M(),[a,l]=u.useState("today"),[r,c]=u.useState({from:ts(new Date,7),to:new Date}),[o,m]=u.useState("today"),[x,i]=u.useState({from:ts(new Date,7),to:new Date}),d=u.useMemo(()=>a==="custom"?{start:r.from,end:r.to}:va[a].getValue(),[a,r]),p=u.useMemo(()=>o==="custom"?{start:x.from,end:x.to}:va[o].getValue(),[o,x]),{data:C}=ie({queryKey:["nodeTrafficRank",d.start,d.end],queryFn:()=>sn({type:"node",start_time:Ce.round(d.start.getTime()/1e3),end_time:Ce.round(d.end.getTime()/1e3)}),refetchInterval:3e4}),{data:P}=ie({queryKey:["userTrafficRank",p.start,p.end],queryFn:()=>sn({type:"user",start_time:Ce.round(p.start.getTime()/1e3),end_time:Ce.round(p.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:N("grid gap-4 md:grid-cols-2",s),children:[e.jsxs(He,{children:[e.jsx(Qe,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(vs,{className:"flex items-center text-base font-medium",children:[e.jsx(no,{className:"mr-2 h-4 w-4"}),n("dashboard:trafficRank.nodeTrafficRank")]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx(an,{selectedRange:a,customDateRange:r,onRangeChange:l,onCustomRangeChange:c}),e.jsx(Wa,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Je,{className:"flex-1",children:C?.data?e.jsxs(Xs,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:C.data.map(f=>e.jsx(pe,{delayDuration:200,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:f.name}),e.jsxs("span",{className:N("ml-2 flex items-center text-xs font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?e.jsx(ha,{className:"mr-1 h-3 w-3"}):e.jsx(fa,{className:"mr-1 h-3 w-3"}),Math.abs(f.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${f.value/C.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Bs(f.value)})]})]})})}),e.jsx(ce,{side:"right",className:"space-y-2 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.currentTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:Bs(f.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:Bs(f.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:N("font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?"+":"",f.change,"%"]})]})})]})},f.id))}),e.jsx(Ft,{orientation:"vertical"})]}):e.jsx("div",{className:"flex h-[400px] items-center justify-center",children:e.jsx("div",{className:"animate-pulse",children:n("common:loading")})})})]}),e.jsxs(He,{children:[e.jsx(Qe,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(vs,{className:"flex items-center text-base font-medium",children:[e.jsx(xa,{className:"mr-2 h-4 w-4"}),n("dashboard:trafficRank.userTrafficRank")]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx(an,{selectedRange:o,customDateRange:x,onRangeChange:m,onCustomRangeChange:i}),e.jsx(Wa,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Je,{className:"flex-1",children:P?.data?e.jsxs(Xs,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:P.data.map(f=>e.jsx(pe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:f.name}),e.jsxs("span",{className:N("ml-2 flex items-center text-xs font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?e.jsx(ha,{className:"mr-1 h-3 w-3"}):e.jsx(fa,{className:"mr-1 h-3 w-3"}),Math.abs(f.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${f.value/P.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Bs(f.value)})]})]})})}),e.jsx(ce,{side:"right",className:"space-y-2 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.currentTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:Bs(f.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:Bs(f.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:N("font-medium",f.change>=0?"text-green-600":"text-red-600"),children:[f.change>=0?"+":"",f.change,"%"]})]})})]})},f.id))}),e.jsx(Ft,{orientation:"vertical"})]}):e.jsx("div",{className:"flex h-[400px] items-center justify-center",children:e.jsx("div",{className:"animate-pulse",children:n("common:loading")})})})]})]})}const lm=Fs("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/10",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function K({className:s,variant:n,...a}){return e.jsx("div",{className:N(lm({variant:n}),s),...a})}const le=window?.settings?.secure_path,qr=5*60*1e3,ba=new Map,im=s=>{const n=ba.get(s);return n?Date.now()-n.timestamp>qr?(ba.delete(s),null):n.data:null},om=(s,n)=>{ba.set(s,{data:n,timestamp:Date.now()})},cm=async(s,n=qr)=>{const a=im(s);if(a)return a;const l=await V.get(s);return om(s,l),l},zt={getList:s=>V.post(`${le}/user/fetch`,s),update:s=>V.post(`${le}/user/update`,s),resetSecret:s=>V.post(`${le}/user/resetSecret`,{id:s}),generate:s=>V.post(`${le}/user/generate`,s),getStats:s=>V.post(`${le}/stat/getStatUser`,s),destroy:s=>V.post(`${le}/user/destroy`,{id:s}),sendMail:s=>V.post(`${le}/user/sendMail`,s),dumpCSV:s=>V.post(`${le}/user/dumpCSV`,s,{responseType:"blob"}),batchBan:s=>V.post(`${le}/user/ban`,s)},nn={getList:()=>cm(`${le}/notice/fetch`),save:s=>V.post(`${le}/notice/save`,s),drop:s=>V.post(`${le}/notice/drop`,{id:s}),updateStatus:s=>V.post(`${le}/notice/show`,{id:s}),sort:s=>V.post(`${le}/notice/sort`,{ids:s})},ra={getList:s=>V.post(`${le}/ticket/fetch`,s),getInfo:s=>V.get(`${le}/ticket/fetch?id=${s}`),reply:s=>V.post(`${le}/ticket/reply`,s),close:s=>V.post(`${le}/ticket/close`,{id:s})},rn={getSystemStatus:()=>V.get(`${le}/system/getSystemStatus`),getQueueStats:()=>V.get(`${le}/system/getQueueStats`),getQueueWorkload:()=>V.get(`${le}/system/getQueueWorkload`),getQueueMasters:()=>V.get(`${le}/system/getQueueMasters`),getSystemLog:s=>V.get(`${le}/system/getSystemLog`,{params:s})},gs={getPluginList:()=>V.get(`${le}/plugin/getPlugins`),uploadPlugin:s=>{const n=new FormData;return n.append("file",s),V.post(`${le}/plugin/upload`,n,{headers:{"Content-Type":"multipart/form-data"}})},deletePlugin:s=>V.post(`${le}/plugin/delete`,{code:s}),installPlugin:s=>V.post(`${le}/plugin/install`,{code:s}),uninstallPlugin:s=>V.post(`${le}/plugin/uninstall`,{code:s}),enablePlugin:s=>V.post(`${le}/plugin/enable`,{code:s}),disablePlugin:s=>V.post(`${le}/plugin/disable`,{code:s}),getPluginConfig:s=>V.get(`${le}/plugin/config`,{params:{code:s}}),updatePluginConfig:(s,n)=>V.post(`${le}/plugin/config`,{code:s,config:n})},Dt=u.forwardRef(({className:s,value:n,...a},l)=>e.jsx(Xn,{ref:l,className:N("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...a,children:e.jsx(io,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(n||0)}%)`}})}));Dt.displayName=Xn.displayName;function dm(){const{t:s}=M(),[n,a]=u.useState(null),[l,r]=u.useState(null),[c,o]=u.useState(!0),[m,x]=u.useState(!1),i=async()=>{try{x(!0);const[C,P]=await Promise.all([rn.getSystemStatus(),rn.getQueueStats()]);a(C.data),r(P.data)}catch(C){console.error("Error fetching system data:",C)}finally{o(!1),x(!1)}};u.useEffect(()=>{i();const C=setInterval(i,3e4);return()=>clearInterval(C)},[]);const d=()=>{i()};if(c)return e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx(Ta,{className:"h-6 w-6 animate-spin"})});const p=C=>C?e.jsx(er,{className:"h-5 w-5 text-green-500"}):e.jsx(sr,{className:"h-5 w-5 text-red-500"});return e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(He,{children:[e.jsxs(Qe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(vs,{className:"flex items-center gap-2",children:[e.jsx(oo,{className:"h-5 w-5"}),s("dashboard:queue.title")]}),e.jsx(Qs,{children:s("dashboard:queue.status.description")})]}),e.jsx(G,{variant:"outline",size:"icon",onClick:d,disabled:m,children:e.jsx(co,{className:N("h-4 w-4",m&&"animate-spin")})})]}),e.jsx(Je,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[p(l?.status||!1),e.jsx("span",{className:"font-medium",children:s("dashboard:queue.status.running")})]}),e.jsx(K,{variant:l?.status?"secondary":"destructive",children:l?.status?s("dashboard:queue.status.normal"):s("dashboard:queue.status.abnormal")})]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.status.waitTime",{seconds:l?.wait?.default||0})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(pe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.recentJobs")}),e.jsx("p",{className:"text-2xl font-bold",children:l?.recentJobs||0}),e.jsx(Dt,{value:(l?.recentJobs||0)/(l?.periods?.recentJobs||1)*100,className:"h-1"})]})}),e.jsx(ce,{children:e.jsx("p",{children:s("dashboard:queue.details.statisticsPeriod",{hours:l?.periods?.recentJobs||0})})})]})}),e.jsx(pe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.jobsPerMinute")}),e.jsx("p",{className:"text-2xl font-bold",children:l?.jobsPerMinute||0}),e.jsx(Dt,{value:(l?.jobsPerMinute||0)/(l?.queueWithMaxThroughput?.throughput||1)*100,className:"h-1"})]})}),e.jsx(ce,{children:e.jsx("p",{children:s("dashboard:queue.details.maxThroughput",{value:l?.queueWithMaxThroughput?.throughput||0})})})]})})]})]})})]}),e.jsxs(He,{children:[e.jsxs(Qe,{children:[e.jsxs(vs,{className:"flex items-center gap-2",children:[e.jsx(mo,{className:"h-5 w-5"}),s("dashboard:queue.jobDetails")]}),e.jsx(Qs,{children:s("dashboard:queue.details.description")})]}),e.jsx(Je,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.failedJobs7Days")}),e.jsx("p",{className:"text-2xl font-bold text-destructive",children:l?.failedJobs||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("dashboard:queue.details.retentionPeriod",{hours:l?.periods?.failedJobs||0})})]}),e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.longestRunningQueue")}),e.jsxs("p",{className:"text-2xl font-bold",children:[l?.queueWithMaxRuntime?.runtime||0,"s"]}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:l?.queueWithMaxRuntime?.name||"N/A"})]})]}),e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.activeProcesses")}),e.jsxs("span",{className:"font-medium",children:[l?.processes||0," /"," ",(l?.processes||0)+(l?.pausedMasters||0)]})]}),e.jsx(Dt,{value:(l?.processes||0)/((l?.processes||0)+(l?.pausedMasters||0))*100,className:"mt-2 h-1"})]})]})})]})]})}function mm(){const{t:s}=M();return e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx("div",{className:"flex items-center",children:e.jsx("h1",{className:"text-2xl font-bold tracking-tight md:text-3xl",children:s("dashboard:title")})}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx($e,{}),e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsx(Ve,{children:e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsx(nm,{}),e.jsx(Xd,{}),e.jsx(rm,{}),e.jsx(dm,{})]})})})]})}const um=Object.freeze(Object.defineProperty({__proto__:null,default:mm},Symbol.toStringTag,{value:"Module"})),Se=u.forwardRef(({className:s,orientation:n="horizontal",decorative:a=!0,...l},r)=>e.jsx(tr,{ref:r,decorative:a,orientation:n,className:N("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...l}));Se.displayName=tr.displayName;function xm({className:s,items:n,...a}){const{pathname:l}=Na(),r=Ns(),[c,o]=u.useState(l??"/settings"),m=i=>{o(i),r(i)},{t:x}=M("settings");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-1 md:hidden",children:e.jsxs(X,{value:c,onValueChange:m,children:[e.jsx(Q,{className:"h-12 sm:w-48",children:e.jsx(ee,{placeholder:"Theme"})}),e.jsx(J,{children:n.map(i=>e.jsx(U,{value:i.href,children:e.jsxs("div",{className:"flex gap-x-4 px-2 py-1",children:[e.jsx("span",{className:"scale-125",children:i.icon}),e.jsx("span",{className:"text-md",children:x(i.title)})]})},i.href))})]})}),e.jsx("div",{className:"hidden w-full overflow-x-auto bg-background px-1 py-2 md:block",children:e.jsx("nav",{className:N("flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",s),...a,children:n.map(i=>e.jsxs(Ls,{to:i.href,className:N(et({variant:"ghost"}),l===i.href?"bg-muted hover:bg-muted":"hover:bg-transparent hover:underline","justify-start"),children:[e.jsx("span",{className:"mr-2",children:i.icon}),x(i.title)]},i.href))})})]})}const hm=[{title:"site.title",key:"site",icon:e.jsx(uo,{size:18}),href:"/config/system",description:"site.description"},{title:"safe.title",key:"safe",icon:e.jsx(In,{size:18}),href:"/config/system/safe",description:"safe.description"},{title:"subscribe.title",key:"subscribe",icon:e.jsx(Vn,{size:18}),href:"/config/system/subscribe",description:"subscribe.description"},{title:"invite.title",key:"invite",icon:e.jsx(xo,{size:18}),href:"/config/system/invite",description:"invite.description"},{title:"server.title",key:"server",icon:e.jsx(Rn,{size:18}),href:"/config/system/server",description:"server.description"},{title:"email.title",key:"email",icon:e.jsx(ho,{size:18}),href:"/config/system/email",description:"email.description"},{title:"telegram.title",key:"telegram",icon:e.jsx(fo,{size:18}),href:"/config/system/telegram",description:"telegram.description"},{title:"app.title",key:"app",icon:e.jsx(En,{size:18}),href:"/config/system/app",description:"app.description"}];function fm(){const{t:s}=M("settings");return e.jsxs(Pe,{fadedBelow:!0,fixedHeight:!0,children:[e.jsxs(Ee,{children:[e.jsx($e,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight md:text-3xl",children:s("title")}),e.jsx("div",{className:"text-muted-foreground",children:s("description")})]}),e.jsx(Se,{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(xm,{items:hm})}),e.jsx("div",{className:"w-full p-1 pr-4 lg:max-w-xl",children:e.jsx("div",{className:"pb-16",children:e.jsx(_a,{})})})]})]})]})}const pm=Object.freeze(Object.defineProperty({__proto__:null,default:fm},Symbol.toStringTag,{value:"Module"})),W=u.forwardRef(({className:s,...n},a)=>e.jsx(ar,{className:N("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s),...n,ref:a,children:e.jsx(po,{className:N("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));W.displayName=ar.displayName;const fs=u.forwardRef(({className:s,...n},a)=>e.jsx("textarea",{className:N("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:a,...n}));fs.displayName="Textarea";const gm=h.object({logo:h.string().nullable().default(""),force_https:h.number().nullable().default(0),stop_register:h.number().nullable().default(0),app_name:h.string().nullable().default(""),app_description:h.string().nullable().default(""),app_url:h.string().nullable().default(""),subscribe_url:h.string().nullable().default(""),try_out_plan_id:h.number().nullable().default(0),try_out_hour:h.coerce.number().nullable().default(0),tos_url:h.string().nullable().default(""),currency:h.string().nullable().default(""),currency_symbol:h.string().nullable().default("")});function jm(){const{t:s}=M("settings"),[n,a]=u.useState(!1),l=u.useRef(null),{data:r}=ie({queryKey:["settings","site"],queryFn:()=>Cs("site")}),{data:c}=ie({queryKey:["plans"],queryFn:()=>Us()}),o=je({resolver:Ne(gm),defaultValues:{},mode:"onBlur"}),{mutateAsync:m}=ms({mutationFn:Ss,onSuccess:d=>{d.data&&$.success(s("common.autoSaved"))}});u.useEffect(()=>{if(r?.data?.site){const d=r?.data?.site;Object.entries(d).forEach(([p,C])=>{o.setValue(p,C)}),l.current=d}},[r]);const x=u.useCallback(Ce.debounce(async d=>{if(!Ce.isEqual(d,l.current)){a(!0);try{const p=Object.entries(d).reduce((C,[P,f])=>(C[P]=f===null?"":f,C),{});await m(p),l.current=d}finally{a(!1)}}},1e3),[m]),i=u.useCallback(d=>{x(d)},[x]);return u.useEffect(()=>{const d=o.watch(p=>{i(p)});return()=>d.unsubscribe()},[o.watch,i]),e.jsx(_e,{...o,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:o.control,name:"app_name",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("site.form.siteName.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("site.form.siteName.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),i(o.getValues())}})}),e.jsx(z,{children:s("site.form.siteName.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:o.control,name:"app_description",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("site.form.siteDescription.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("site.form.siteDescription.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),i(o.getValues())}})}),e.jsx(z,{children:s("site.form.siteDescription.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:o.control,name:"app_url",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("site.form.siteUrl.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("site.form.siteUrl.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),i(o.getValues())}})}),e.jsx(z,{children:s("site.form.siteUrl.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:o.control,name:"force_https",render:({field:d})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("site.form.forceHttps.label")}),e.jsx(z,{children:s("site.form.forceHttps.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:!!d.value,onCheckedChange:p=>{d.onChange(Number(p)),i(o.getValues())}})})]})}),e.jsx(b,{control:o.control,name:"logo",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("site.form.logo.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("site.form.logo.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),i(o.getValues())}})}),e.jsx(z,{children:s("site.form.logo.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:o.control,name:"subscribe_url",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("site.form.subscribeUrl.label")}),e.jsx(_,{children:e.jsx(fs,{placeholder:s("site.form.subscribeUrl.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),i(o.getValues())}})}),e.jsx(z,{children:s("site.form.subscribeUrl.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:o.control,name:"tos_url",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("site.form.tosUrl.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("site.form.tosUrl.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),i(o.getValues())}})}),e.jsx(z,{children:s("site.form.tosUrl.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:o.control,name:"stop_register",render:({field:d})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("site.form.stopRegister.label")}),e.jsx(z,{children:s("site.form.stopRegister.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:!!d.value,onCheckedChange:p=>{d.onChange(Number(p)),i(o.getValues())}})})]})}),e.jsx(b,{control:o.control,name:"try_out_plan_id",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("site.form.tryOut.label")}),e.jsx(_,{children:e.jsxs(X,{value:d.value?.toString(),onValueChange:p=>{d.onChange(Number(p)),i(o.getValues())},children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:s("site.form.tryOut.placeholder")})}),e.jsxs(J,{children:[e.jsx(U,{value:"0",children:s("site.form.tryOut.placeholder")}),c?.data?.map(p=>e.jsx(U,{value:p.id.toString(),children:p.name},p.id.toString()))]})]})}),e.jsx(z,{children:s("site.form.tryOut.description")}),e.jsx(T,{})]})}),!!o.watch("try_out_plan_id")&&e.jsx(b,{control:o.control,name:"try_out_hour",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"",children:s("site.form.tryOut.duration.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("site.form.tryOut.duration.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),i(o.getValues())}})}),e.jsx(z,{children:s("site.form.tryOut.duration.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:o.control,name:"currency",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("site.form.currency.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("site.form.currency.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),i(o.getValues())}})}),e.jsx(z,{children:s("site.form.currency.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:o.control,name:"currency_symbol",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("site.form.currencySymbol.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("site.form.currencySymbol.placeholder"),...d,value:d.value||"",onChange:p=>{d.onChange(p),i(o.getValues())}})}),e.jsx(z,{children:s("site.form.currencySymbol.description")}),e.jsx(T,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("site.form.saving")})]})})}function vm(){const{t:s}=M("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("site.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("site.description")})]}),e.jsx(Se,{}),e.jsx(jm,{})]})}const bm=Object.freeze(Object.defineProperty({__proto__:null,default:vm},Symbol.toStringTag,{value:"Module"})),ym=h.object({email_verify:h.boolean().nullable(),safe_mode_enable:h.boolean().nullable(),secure_path:h.string().nullable(),email_whitelist_enable:h.boolean().nullable(),email_whitelist_suffix:h.array(h.string().nullable()).nullable(),email_gmail_limit_enable:h.boolean().nullable(),recaptcha_enable:h.boolean().nullable(),recaptcha_key:h.string().nullable(),recaptcha_site_key:h.string().nullable(),register_limit_by_ip_enable:h.boolean().nullable(),register_limit_count:h.coerce.string().transform(s=>s===""?null:s).nullable(),register_limit_expire:h.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_enable:h.boolean().nullable(),password_limit_count:h.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_expire:h.coerce.string().transform(s=>s===""?null:s).nullable()}),Nm={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 _m(){const{t:s}=M("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=je({resolver:Ne(ym),defaultValues:Nm,mode:"onBlur"}),{data:c}=ie({queryKey:["settings","safe"],queryFn:()=>Cs("safe")}),{mutateAsync:o}=ms({mutationFn:Ss,onSuccess:i=>{i.data&&$.success(s("common.autoSaved"))}});u.useEffect(()=>{if(c?.data.safe){const i=c.data.safe;Object.entries(i).forEach(([d,p])=>{typeof p=="number"?r.setValue(d,String(p)):r.setValue(d,p)}),l.current=i}},[c]);const m=u.useCallback(Ce.debounce(async i=>{if(!Ce.isEqual(i,l.current)){a(!0);try{await o(i),l.current=i}finally{a(!1)}}},1e3),[o]),x=u.useCallback(i=>{m(i)},[m]);return u.useEffect(()=>{const i=r.watch(d=>{x(d)});return()=>i.unsubscribe()},[r.watch,x]),e.jsx(_e,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:r.control,name:"email_verify",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("safe.form.emailVerify.label")}),e.jsx(z,{children:s("safe.form.emailVerify.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),e.jsx(b,{control:r.control,name:"email_gmail_limit_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("safe.form.gmailLimit.label")}),e.jsx(z,{children:s("safe.form.gmailLimit.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),e.jsx(b,{control:r.control,name:"safe_mode_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("safe.form.safeMode.label")}),e.jsx(z,{children:s("safe.form.safeMode.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),e.jsx(b,{control:r.control,name:"secure_path",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("safe.form.securePath.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("safe.form.securePath.placeholder"),...i,value:i.value||"",onChange:d=>{i.onChange(d),x(r.getValues())}})}),e.jsx(z,{children:s("safe.form.securePath.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"email_whitelist_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("safe.form.emailWhitelist.label")}),e.jsx(z,{children:s("safe.form.emailWhitelist.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),r.watch("email_whitelist_enable")&&e.jsx(b,{control:r.control,name:"email_whitelist_suffix",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("safe.form.emailWhitelist.suffixes.label")}),e.jsx(_,{children:e.jsx(fs,{placeholder:s("safe.form.emailWhitelist.suffixes.placeholder"),...i,value:(i.value||[]).join(`
|
||
`),onChange:d=>{const p=d.target.value.split(`
|
||
`).filter(Boolean);i.onChange(p),x(r.getValues())}})}),e.jsx(z,{children:s("safe.form.emailWhitelist.suffixes.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"recaptcha_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("safe.form.recaptcha.enable.label")}),e.jsx(z,{children:s("safe.form.recaptcha.enable.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),r.watch("recaptcha_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:r.control,name:"recaptcha_key",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("safe.form.recaptcha.key.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("safe.form.recaptcha.key.placeholder"),...i,value:i.value||"",onChange:d=>{i.onChange(d),x(r.getValues())}})}),e.jsx(z,{children:s("safe.form.recaptcha.key.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"recaptcha_site_key",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("safe.form.recaptcha.siteKey.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("safe.form.recaptcha.siteKey.placeholder"),...i,value:i.value||"",onChange:d=>{i.onChange(d),x(r.getValues())}})}),e.jsx(z,{children:s("safe.form.recaptcha.siteKey.description")}),e.jsx(T,{})]})})]}),e.jsx(b,{control:r.control,name:"register_limit_by_ip_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("safe.form.registerLimit.enable.label")}),e.jsx(z,{children:s("safe.form.registerLimit.enable.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),r.watch("register_limit_by_ip_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:r.control,name:"register_limit_count",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("safe.form.registerLimit.count.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("safe.form.registerLimit.count.placeholder"),...i,value:i.value||"",onChange:d=>{i.onChange(d),x(r.getValues())}})}),e.jsx(z,{children:s("safe.form.registerLimit.count.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"register_limit_expire",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("safe.form.registerLimit.expire.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("safe.form.registerLimit.expire.placeholder"),...i,value:i.value||"",onChange:d=>{i.onChange(d),x(r.getValues())}})}),e.jsx(z,{children:s("safe.form.registerLimit.expire.description")}),e.jsx(T,{})]})})]}),e.jsx(b,{control:r.control,name:"password_limit_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("safe.form.passwordLimit.enable.label")}),e.jsx(z,{children:s("safe.form.passwordLimit.enable.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),r.watch("password_limit_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:r.control,name:"password_limit_count",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("safe.form.passwordLimit.count.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("safe.form.passwordLimit.count.placeholder"),...i,value:i.value||"",onChange:d=>{i.onChange(d),x(r.getValues())}})}),e.jsx(z,{children:s("safe.form.passwordLimit.count.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"password_limit_expire",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("safe.form.passwordLimit.expire.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("safe.form.passwordLimit.expire.placeholder"),...i,value:i.value||"",onChange:d=>{i.onChange(d),x(r.getValues())}})}),e.jsx(z,{children:s("safe.form.passwordLimit.expire.description")}),e.jsx(T,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("safe.form.saving")})]})})}function wm(){const{t:s}=M("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("safe.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("safe.description")})]}),e.jsx(Se,{}),e.jsx(_m,{})]})}const Cm=Object.freeze(Object.defineProperty({__proto__:null,default:wm},Symbol.toStringTag,{value:"Module"})),Sm=h.object({plan_change_enable:h.boolean().nullable().default(!1),reset_traffic_method:h.coerce.number().nullable().default(0),surplus_enable:h.boolean().nullable().default(!1),new_order_event_id:h.coerce.number().nullable().default(0),renew_order_event_id:h.coerce.number().nullable().default(0),change_order_event_id:h.coerce.number().nullable().default(0),show_info_to_server_enable:h.boolean().nullable().default(!1),show_protocol_to_server_enable:h.boolean().nullable().default(!1),default_remind_expire:h.boolean().nullable().default(!1),default_remind_traffic:h.boolean().nullable().default(!1),subscribe_path:h.string().nullable().default("s")}),km={plan_change_enable:!1,reset_traffic_method:0,surplus_enable:!1,new_order_event_id:0,renew_order_event_id:0,change_order_event_id:0,show_info_to_server_enable:!1,show_protocol_to_server_enable:!1,default_remind_expire:!1,default_remind_traffic:!1,subscribe_path:"s"};function Tm(){const{t:s}=M("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=je({resolver:Ne(Sm),defaultValues:km,mode:"onBlur"}),{data:c}=ie({queryKey:["settings","subscribe"],queryFn:()=>Cs("subscribe")}),{mutateAsync:o}=ms({mutationFn:Ss,onSuccess:i=>{i.data&&$.success(s("common.autoSaved"))}});u.useEffect(()=>{if(c?.data?.subscribe){const i=c?.data?.subscribe;Object.entries(i).forEach(([d,p])=>{r.setValue(d,p)}),l.current=i}},[c]);const m=u.useCallback(Ce.debounce(async i=>{if(!Ce.isEqual(i,l.current)){a(!0);try{await o(i),l.current=i}finally{a(!1)}}},1e3),[o]),x=u.useCallback(i=>{m(i)},[m]);return u.useEffect(()=>{const i=r.watch(d=>{x(d)});return()=>i.unsubscribe()},[r.watch,x]),e.jsx(_e,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:r.control,name:"plan_change_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("subscribe.plan_change_enable.title")}),e.jsx(z,{children:s("subscribe.plan_change_enable.description")}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"reset_traffic_method",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("subscribe.reset_traffic_method.title")}),e.jsxs(X,{onValueChange:i.onChange,value:i.value?.toString()||"0",children:[e.jsx(_,{children:e.jsx(Q,{children:e.jsx(ee,{placeholder:"请选择重置方式"})})}),e.jsxs(J,{children:[e.jsx(U,{value:"0",children:s("subscribe.reset_traffic_method.options.monthly_first")}),e.jsx(U,{value:"1",children:s("subscribe.reset_traffic_method.options.monthly_reset")}),e.jsx(U,{value:"2",children:s("subscribe.reset_traffic_method.options.no_reset")}),e.jsx(U,{value:"3",children:s("subscribe.reset_traffic_method.options.yearly_first")}),e.jsx(U,{value:"4",children:s("subscribe.reset_traffic_method.options.yearly_reset")})]})]}),e.jsx(z,{children:s("subscribe.reset_traffic_method.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"surplus_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("subscribe.surplus_enable.title")}),e.jsx(z,{children:s("subscribe.surplus_enable.description")}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"new_order_event_id",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("subscribe.new_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(_,{children:e.jsxs(X,{onValueChange:i.onChange,value:i.value?.toString(),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:"请选择"})}),e.jsxs(J,{children:[e.jsx(U,{value:"0",children:s("subscribe.new_order_event.options.no_action")}),e.jsx(U,{value:"1",children:s("subscribe.new_order_event.options.reset_traffic")})]})]})})}),e.jsx(z,{children:s("subscribe.new_order_event.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"renew_order_event_id",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("subscribe.renew_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(_,{children:e.jsxs(X,{onValueChange:i.onChange,value:i.value?.toString(),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:"请选择"})}),e.jsxs(J,{children:[e.jsx(U,{value:"0",children:s("subscribe.renew_order_event.options.no_action")}),e.jsx(U,{value:"1",children:s("subscribe.renew_order_event.options.reset_traffic")})]})]})})}),e.jsx(z,{children:s("renew_order_event.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"change_order_event_id",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("subscribe.change_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(_,{children:e.jsxs(X,{onValueChange:i.onChange,value:i.value?.toString(),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:"请选择"})}),e.jsxs(J,{children:[e.jsx(U,{value:"0",children:s("subscribe.change_order_event.options.no_action")}),e.jsx(U,{value:"1",children:s("subscribe.change_order_event.options.reset_traffic")})]})]})})}),e.jsx(z,{children:s("subscribe.change_order_event.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"subscribe_path",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("subscribe.subscribe_path.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:"subscribe",...i,value:i.value||"",onChange:d=>{i.onChange(d),x(r.getValues())}})}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s("subscribe.subscribe_path.description"),e.jsx("br",{}),s("subscribe.subscribe_path.current_format",{path:i.value||"s"})]}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"show_info_to_server_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("subscribe.show_info_to_server.title")}),e.jsx(z,{children:s("subscribe.show_info_to_server.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),e.jsx(b,{control:r.control,name:"show_protocol_to_server_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("subscribe.show_protocol_to_server.title")}),e.jsx(z,{children:s("subscribe.show_protocol_to_server.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value||!1,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Dm(){const{t:s}=M("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("subscribe.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe.description")})]}),e.jsx(Se,{}),e.jsx(Tm,{})]})}const Pm=Object.freeze(Object.defineProperty({__proto__:null,default:Dm},Symbol.toStringTag,{value:"Module"})),Em=h.object({invite_force:h.boolean().default(!1),invite_commission:h.coerce.string().default("0"),invite_gen_limit:h.coerce.string().default("0"),invite_never_expire:h.boolean().default(!1),commission_first_time_enable:h.boolean().default(!1),commission_auto_check_enable:h.boolean().default(!1),commission_withdraw_limit:h.coerce.string().default("0"),commission_withdraw_method:h.array(h.string()).default(["支付宝","USDT","Paypal"]),withdraw_close_enable:h.boolean().default(!1),commission_distribution_enable:h.boolean().default(!1),commission_distribution_l1:h.coerce.number().default(0),commission_distribution_l2:h.coerce.number().default(0),commission_distribution_l3:h.coerce.number().default(0)}),Rm={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 Im(){const{t:s}=M("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=je({resolver:Ne(Em),defaultValues:Rm,mode:"onBlur"}),{data:c}=ie({queryKey:["settings","invite"],queryFn:()=>Cs("invite")}),{mutateAsync:o}=ms({mutationFn:Ss,onSuccess:i=>{i.data&&$.success(s("common.autoSaved"))}});u.useEffect(()=>{if(c?.data?.invite){const i=c?.data?.invite;Object.entries(i).forEach(([d,p])=>{typeof p=="number"?r.setValue(d,String(p)):r.setValue(d,p)}),l.current=i}},[c]);const m=u.useCallback(Ce.debounce(async i=>{if(!Ce.isEqual(i,l.current)){a(!0);try{await o(i),l.current=i}finally{a(!1)}}},1e3),[o]),x=u.useCallback(i=>{m(i)},[m]);return u.useEffect(()=>{const i=r.watch(d=>{x(d)});return()=>i.unsubscribe()},[r.watch,x]),e.jsx(_e,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:r.control,name:"invite_force",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("invite.invite_force.title")}),e.jsx(z,{children:s("invite.invite_force.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),e.jsx(b,{control:r.control,name:"invite_commission",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("invite.invite_commission.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("invite.invite_commission.placeholder"),...i,value:i.value||""})}),e.jsx(z,{children:s("invite.invite_commission.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"invite_gen_limit",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("invite.invite_gen_limit.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("invite.invite_gen_limit.placeholder"),...i,value:i.value||""})}),e.jsx(z,{children:s("invite.invite_gen_limit.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"invite_never_expire",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("invite.invite_never_expire.title")}),e.jsx(z,{children:s("invite.invite_never_expire.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),e.jsx(b,{control:r.control,name:"commission_first_time_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("invite.commission_first_time.title")}),e.jsx(z,{children:s("invite.commission_first_time.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),e.jsx(b,{control:r.control,name:"commission_auto_check_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("invite.commission_auto_check.title")}),e.jsx(z,{children:s("invite.commission_auto_check.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),e.jsx(b,{control:r.control,name:"commission_withdraw_limit",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("invite.commission_withdraw_limit.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("invite.commission_withdraw_limit.placeholder"),...i,value:i.value||""})}),e.jsx(z,{children:s("invite.commission_withdraw_limit.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"commission_withdraw_method",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("invite.commission_withdraw_method.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("invite.commission_withdraw_method.placeholder"),...i,value:Array.isArray(i.value)?i.value.join(","):"",onChange:d=>{const p=d.target.value.split(",").filter(Boolean);i.onChange(p),x(r.getValues())}})}),e.jsx(z,{children:s("invite.commission_withdraw_method.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"withdraw_close_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("invite.withdraw_close.title")}),e.jsx(z,{children:s("invite.withdraw_close.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),e.jsx(b,{control:r.control,name:"commission_distribution_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("invite.commission_distribution.title")}),e.jsx(z,{children:s("invite.commission_distribution.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:i.value,onCheckedChange:d=>{i.onChange(d),x(r.getValues())}})})]})}),r.watch("commission_distribution_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:r.control,name:"commission_distribution_l1",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:s("invite.commission_distribution.l1")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...i,value:i.value||"",onChange:d=>{const p=d.target.value?Number(d.target.value):0;i.onChange(p),x(r.getValues())}})}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"commission_distribution_l2",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:s("invite.commission_distribution.l2")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...i,value:i.value||"",onChange:d=>{const p=d.target.value?Number(d.target.value):0;i.onChange(p),x(r.getValues())}})}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"commission_distribution_l3",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:s("invite.commission_distribution.l3")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...i,value:i.value||"",onChange:d=>{const p=d.target.value?Number(d.target.value):0;i.onChange(p),x(r.getValues())}})}),e.jsx(T,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("invite.saving")})]})})}function Vm(){const{t:s}=M("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("invite.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("invite.description")})]}),e.jsx(Se,{}),e.jsx(Im,{})]})}const Om=Object.freeze(Object.defineProperty({__proto__:null,default:Vm},Symbol.toStringTag,{value:"Module"})),Mm=h.object({frontend_theme:h.string().nullable(),frontend_theme_sidebar:h.string().nullable(),frontend_theme_header:h.string().nullable(),frontend_theme_color:h.string().nullable(),frontend_background_url:h.string().url().nullable()}),Fm={frontend_theme:"",frontend_theme_sidebar:"",frontend_theme_header:"",frontend_theme_color:"",frontend_background_url:""};function zm(){const{data:s}=ie({queryKey:["settings","frontend"],queryFn:()=>Cs("frontend")}),n=je({resolver:Ne(Mm),defaultValues:Fm,mode:"onChange"});u.useEffect(()=>{if(s?.data?.frontend){const l=s?.data?.frontend;Object.entries(l).forEach(([r,c])=>{n.setValue(r,c)})}},[s]);function a(l){Ss(l).then(({data:r})=>{r&&$.success("更新成功")})}return e.jsx(_e,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(a),className:"space-y-8",children:[e.jsx(b,{control:n.control,name:"frontend_theme_sidebar",render:({field:l})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:"边栏风格"}),e.jsx(z,{children:"边栏风格"})]}),e.jsx(_,{children:e.jsx(W,{checked:l.value,onCheckedChange:l.onChange})})]})}),e.jsx(b,{control:n.control,name:"frontend_theme_header",render:({field:l})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:"头部风格"}),e.jsx(z,{children:"边栏风格"})]}),e.jsx(_,{children:e.jsx(W,{checked:l.value,onCheckedChange:l.onChange})})]})}),e.jsx(b,{control:n.control,name:"frontend_theme_color",render:({field:l})=>e.jsxs(v,{children:[e.jsx(y,{children:"主题色"}),e.jsxs("div",{className:"relative w-max",children:[e.jsx(_,{children:e.jsxs("select",{className:N(et({variant:"outline"}),"w-[200px] appearance-none font-normal"),...l,children:[e.jsx("option",{value:"default",children:"默认"}),e.jsx("option",{value:"black",children:"黑色"}),e.jsx("option",{value:"blackblue",children:"暗蓝色"}),e.jsx("option",{value:"green",children:"奶绿色"})]})}),e.jsx(ka,{className:"absolute right-3 top-2.5 h-4 w-4 opacity-50"})]}),e.jsx(z,{children:"主题色"}),e.jsx(T,{})]})}),e.jsx(b,{control:n.control,name:"frontend_background_url",render:({field:l})=>e.jsxs(v,{children:[e.jsx(y,{children:"背景"}),e.jsx(_,{children:e.jsx(k,{placeholder:"请输入图片地址",...l})}),e.jsx(z,{children:"将会在后台登录页面进行展示。"}),e.jsx(T,{})]})}),e.jsx(D,{type:"submit",children:"保存设置"})]})})}function Lm(){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(Se,{}),e.jsx(zm,{})]})}const Am=Object.freeze(Object.defineProperty({__proto__:null,default:Lm},Symbol.toStringTag,{value:"Module"})),$m=h.object({server_pull_interval:h.coerce.number().nullable(),server_push_interval:h.coerce.number().nullable(),server_token:h.string().nullable(),device_limit_mode:h.coerce.number().nullable()}),qm={server_pull_interval:0,server_push_interval:0,server_token:"",device_limit_mode:0};function Um(){const{t:s}=M("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=je({resolver:Ne($m),defaultValues:qm,mode:"onBlur"}),{data:c}=ie({queryKey:["settings","server"],queryFn:()=>Cs("server")}),{mutateAsync:o}=ms({mutationFn:Ss,onSuccess:d=>{d.data&&$.success(s("common.AutoSaved"))}});u.useEffect(()=>{if(c?.data.server){const d=c.data.server;Object.entries(d).forEach(([p,C])=>{r.setValue(p,C)}),l.current=d}},[c]);const m=u.useCallback(Ce.debounce(async d=>{if(!Ce.isEqual(d,l.current)){a(!0);try{await o(d),l.current=d}finally{a(!1)}}},1e3),[o]),x=u.useCallback(d=>{m(d)},[m]);u.useEffect(()=>{const d=r.watch(p=>{x(p)});return()=>d.unsubscribe()},[r.watch,x]);const i=()=>{const d=Math.floor(Math.random()*17)+16,p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let C="";for(let P=0;P<d;P++)C+=p.charAt(Math.floor(Math.random()*p.length));r.setValue("server_token",C)};return e.jsx(_e,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:r.control,name:"server_token",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("server.server_token.title")}),e.jsx(_,{children:e.jsxs("div",{className:"relative",children:[e.jsx(k,{placeholder:s("server.server_token.placeholder"),...d,value:d.value||"",className:"pr-10"}),e.jsx(pe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3 py-2",onClick:p=>{p.preventDefault(),i()},children:e.jsx(go,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(ce,{children:e.jsx("p",{children:s("server.server_token.generate_tooltip")})})]})})]})}),e.jsx(z,{children:s("server.server_token.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"server_pull_interval",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("server.server_pull_interval.title")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:s("server.server_pull_interval.placeholder"),...d,value:d.value||"",onChange:p=>{const C=p.target.value?Number(p.target.value):null;d.onChange(C)}})}),e.jsx(z,{children:s("server.server_pull_interval.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"server_push_interval",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("server.server_push_interval.title")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:s("server.server_push_interval.placeholder"),...d,value:d.value||"",onChange:p=>{const C=p.target.value?Number(p.target.value):null;d.onChange(C)}})}),e.jsx(z,{children:s("server.server_push_interval.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"device_limit_mode",render:({field:d})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("server.device_limit_mode.title")}),e.jsxs(X,{onValueChange:d.onChange,value:d.value?.toString()||"0",children:[e.jsx(_,{children:e.jsx(Q,{children:e.jsx(ee,{placeholder:s("server.device_limit_mode.placeholder")})})}),e.jsxs(J,{children:[e.jsx(U,{value:"0",children:s("server.device_limit_mode.strict")}),e.jsx(U,{value:"1",children:s("server.device_limit_mode.relaxed")})]})]}),e.jsx(z,{children:s("server.device_limit_mode.description")}),e.jsx(T,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("server.saving")})]})})}function Hm(){const{t:s}=M("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("server.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("server.description")})]}),e.jsx(Se,{}),e.jsx(Um,{})]})}const Km=Object.freeze(Object.defineProperty({__proto__:null,default:Hm},Symbol.toStringTag,{value:"Module"}));function Bm({open:s,onOpenChange:n,result:a}){const l=!a.error;return e.jsx(be,{open:s,onOpenChange:n,children:e.jsxs(ge,{className:"sm:max-w-[425px]",children:[e.jsxs(we,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l?e.jsx(er,{className:"h-5 w-5 text-green-500"}):e.jsx(sr,{className:"h-5 w-5 text-destructive"}),e.jsx(ye,{children:l?"邮件发送成功":"邮件发送失败"})]}),e.jsx(De,{children:l?"测试邮件已成功发送,请检查收件箱":"发送测试邮件时遇到错误"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"发送详情"}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2 text-sm",children:[e.jsx("div",{className:"text-muted-foreground",children:"收件地址"}),e.jsx("div",{children:a.email}),e.jsx("div",{className:"text-muted-foreground",children:"邮件主题"}),e.jsx("div",{children:a.subject}),e.jsx("div",{className:"text-muted-foreground",children:"模板名称"}),e.jsx("div",{children:a.template_name})]})]}),a.error&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium text-destructive",children:"错误信息"}),e.jsx("div",{className:"rounded-md bg-destructive/10 p-3 text-sm text-destructive break-all",children:a.error})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"配置信息"}),e.jsx(Xs,{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 Gm=h.object({email_template:h.string().nullable().default("classic"),email_host:h.string().nullable().default(""),email_port:h.coerce.number().nullable().default(465),email_username:h.string().nullable().default(""),email_password:h.string().nullable().default(""),email_encryption:h.string().nullable().default(""),email_from_address:h.string().email().nullable().default(""),remind_mail_enable:h.boolean().nullable().default(!1)});function Wm(){const{t:s}=M("settings"),[n,a]=u.useState(null),[l,r]=u.useState(!1),c=u.useRef(null),[o,m]=u.useState(!1),x=je({resolver:Ne(Gm),defaultValues:{},mode:"onBlur"}),{data:i}=ie({queryKey:["settings","email"],queryFn:()=>Cs("email")}),{data:d}=ie({queryKey:["emailTemplate"],queryFn:()=>Kd()}),{mutateAsync:p}=ms({mutationFn:Ss,onSuccess:w=>{w.data&&$.success(s("common.autoSaved"))}}),{mutate:C,isPending:P}=ms({mutationFn:Bd,onMutate:()=>{a(null),r(!1)},onSuccess:w=>{a(w.data),r(!0),w.data.error?$.error(s("email.test.error")):$.success(s("email.test.success"))}});u.useEffect(()=>{if(i?.data.email){const w=i.data.email;Object.entries(w).forEach(([g,S])=>{x.setValue(g,S)}),c.current=w}},[i]);const f=u.useCallback(Ce.debounce(async w=>{if(!Ce.isEqual(w,c.current)){m(!0);try{await p(w),c.current=w}finally{m(!1)}}},1e3),[p]),j=u.useCallback(w=>{f(w)},[f]);return u.useEffect(()=>{const w=x.watch(g=>{j(g)});return()=>w.unsubscribe()},[x.watch,j]),e.jsxs(e.Fragment,{children:[e.jsx(_e,{...x,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:x.control,name:"email_host",render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("email.email_host.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(z,{children:s("email.email_host.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"email_port",render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("email.email_port.title")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:s("common.placeholder"),...w,value:w.value||"",onChange:g=>{const S=g.target.value?Number(g.target.value):null;w.onChange(S)}})}),e.jsx(z,{children:s("email.email_port.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"email_encryption",render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("email.email_encryption.title")}),e.jsxs(X,{onValueChange:w.onChange,value:w.value||"none",children:[e.jsx(_,{children:e.jsx(Q,{children:e.jsx(ee,{placeholder:"请选择加密方式"})})}),e.jsxs(J,{children:[e.jsx(U,{value:"none",children:s("email.email_encryption.none")}),e.jsx(U,{value:"ssl",children:s("email.email_encryption.ssl")}),e.jsx(U,{value:"tls",children:s("email.email_encryption.tls")})]})]}),e.jsx(z,{children:s("email.email_encryption.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"email_username",render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("email.email_username.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(z,{children:s("email.email_username.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"email_password",render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("email.email_password.title")}),e.jsx(_,{children:e.jsx(k,{type:"password",placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(z,{children:s("email.email_password.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"email_from_address",render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("email.email_from.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(z,{children:s("email.email_from.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"email_template",render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("email.email_template.title")}),e.jsxs(X,{onValueChange:g=>{w.onChange(g),j(x.getValues())},value:w.value||void 0,children:[e.jsx(_,{children:e.jsx(Q,{className:"w-[200px]",children:e.jsx(ee,{placeholder:s("email.email_template.placeholder")})})}),e.jsx(J,{children:d?.data?.map(g=>e.jsx(U,{value:g,children:g},g))})]}),e.jsx(z,{children:s("email.email_template.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"remind_mail_enable",render:({field:w})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:s("email.remind_mail.title")}),e.jsx(z,{children:s("email.remind_mail.description")})]}),e.jsx(_,{children:e.jsx(W,{checked:w.value||!1,onCheckedChange:g=>{w.onChange(g),j(x.getValues())}})})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(D,{onClick:()=>C(),loading:P,disabled:P,children:s(P?"test.sending":"test.title")})})]})}),o&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("saving")}),n&&e.jsx(Bm,{open:l,onOpenChange:r,result:n})]})}function Ym(){const{t:s}=M("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("email.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("email.description")})]}),e.jsx(Se,{}),e.jsx(Wm,{})]})}const Qm=Object.freeze(Object.defineProperty({__proto__:null,default:Ym},Symbol.toStringTag,{value:"Module"})),Jm=h.object({telegram_bot_enable:h.boolean().nullable(),telegram_bot_token:h.string().nullable(),telegram_discuss_link:h.string().nullable()}),Zm={telegram_bot_enable:!1,telegram_bot_token:"",telegram_discuss_link:""};function Xm(){const{t:s}=M("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=je({resolver:Ne(Jm),defaultValues:Zm,mode:"onBlur"}),{data:c}=ie({queryKey:["settings","telegram"],queryFn:()=>Cs("telegram")}),{mutateAsync:o}=ms({mutationFn:Ss,onSuccess:p=>{p.data&&$.success(s("common.autoSaved"))}}),{mutate:m,isPending:x}=ms({mutationFn:Gd,onSuccess:p=>{p.data&&$.success(s("telegram.webhook.success"))}});u.useEffect(()=>{if(c?.data.telegram){const p=c.data.telegram;Object.entries(p).forEach(([C,P])=>{r.setValue(C,P)}),l.current=p}},[c]);const i=u.useCallback(Ce.debounce(async p=>{if(!Ce.isEqual(p,l.current)){a(!0);try{await o(p),l.current=p}finally{a(!1)}}},1e3),[o]),d=u.useCallback(p=>{i(p)},[i]);return u.useEffect(()=>{const p=r.watch(C=>{d(C)});return()=>p.unsubscribe()},[r.watch,d]),e.jsx(_e,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:r.control,name:"telegram_bot_token",render:({field:p})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("telegram.bot_token.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("telegram.bot_token.placeholder"),...p,value:p.value||""})}),e.jsx(z,{children:s("telegram.bot_token.description")}),e.jsx(T,{})]})}),r.watch("telegram_bot_token")&&e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("telegram.webhook.title")}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(D,{loading:x,disabled:x,onClick:()=>m(),children:s(x?"telegram.webhook.setting":"telegram.webhook.button")}),n&&e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.saving")})]}),e.jsx(z,{children:s("telegram.webhook.description")}),e.jsx(T,{})]}),e.jsx(b,{control:r.control,name:"telegram_bot_enable",render:({field:p})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("telegram.bot_enable.title")}),e.jsx(z,{children:s("telegram.bot_enable.description")}),e.jsx(_,{children:e.jsx(W,{checked:p.value||!1,onCheckedChange:C=>{p.onChange(C),d(r.getValues())}})}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"telegram_discuss_link",render:({field:p})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("telegram.discuss_link.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("telegram.discuss_link.placeholder"),...p,value:p.value||""})}),e.jsx(z,{children:s("telegram.discuss_link.description")}),e.jsx(T,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function eu(){const{t:s}=M("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("telegram.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("telegram.description")})]}),e.jsx(Se,{}),e.jsx(Xm,{})]})}const su=Object.freeze(Object.defineProperty({__proto__:null,default:eu},Symbol.toStringTag,{value:"Module"})),tu=h.object({windows_version:h.string().nullable(),windows_download_url:h.string().nullable(),macos_version:h.string().nullable(),macos_download_url:h.string().nullable(),android_version:h.string().nullable(),android_download_url:h.string().nullable()}),au={windows_version:"",windows_download_url:"",macos_version:"",macos_download_url:"",android_version:"",android_download_url:""};function nu(){const{t:s}=M("settings"),[n,a]=u.useState(!1),l=u.useRef(null),r=je({resolver:Ne(tu),defaultValues:au,mode:"onBlur"}),{data:c}=ie({queryKey:["settings","app"],queryFn:()=>Cs("app")}),{mutateAsync:o}=ms({mutationFn:Ss,onSuccess:i=>{i.data&&$.success(s("app.save_success"))}});u.useEffect(()=>{if(c?.data.app){const i=c.data.app;Object.entries(i).forEach(([d,p])=>{r.setValue(d,p)}),l.current=i}},[c]);const m=u.useCallback(Ce.debounce(async i=>{if(!Ce.isEqual(i,l.current)){a(!0);try{await o(i),l.current=i}finally{a(!1)}}},1e3),[o]),x=u.useCallback(i=>{m(i)},[m]);return u.useEffect(()=>{const i=r.watch(d=>{x(d)});return()=>i.unsubscribe()},[r.watch,x]),e.jsx(_e,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:r.control,name:"windows_version",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("app.windows.version.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("common.placeholder"),...i,value:i.value||""})}),e.jsx(z,{children:s("app.windows.version.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"windows_download_url",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("app.windows.download.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("common.placeholder"),...i,value:i.value||""})}),e.jsx(z,{children:s("app.windows.download.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"macos_version",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("app.macos.version.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("common.placeholder"),...i,value:i.value||""})}),e.jsx(z,{children:s("app.macos.version.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"macos_download_url",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("app.macos.download.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("common.placeholder"),...i,value:i.value||""})}),e.jsx(z,{children:s("app.macos.download.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"android_version",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("app.android.version.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("common.placeholder"),...i,value:i.value||""})}),e.jsx(z,{children:s("app.android.version.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"android_download_url",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{className:"text-base",children:s("app.android.download.title")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("common.placeholder"),...i,value:i.value||""})}),e.jsx(z,{children:s("app.android.download.description")}),e.jsx(T,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function ru(){const{t:s}=M("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("app.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("app.description")})]}),e.jsx(Se,{}),e.jsx(nu,{})]})}const lu=Object.freeze(Object.defineProperty({__proto__:null,default:ru},Symbol.toStringTag,{value:"Module"})),Ia=u.forwardRef(({className:s,...n},a)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:a,className:N("w-full caption-bottom text-sm",s),...n})}));Ia.displayName="Table";const Va=u.forwardRef(({className:s,...n},a)=>e.jsx("thead",{ref:a,className:N("[&_tr]:border-b",s),...n}));Va.displayName="TableHeader";const Oa=u.forwardRef(({className:s,...n},a)=>e.jsx("tbody",{ref:a,className:N("[&_tr:last-child]:border-0",s),...n}));Oa.displayName="TableBody";const iu=u.forwardRef(({className:s,...n},a)=>e.jsx("tfoot",{ref:a,className:N("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...n}));iu.displayName="TableFooter";const Ps=u.forwardRef(({className:s,...n},a)=>e.jsx("tr",{ref:a,className:N("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...n}));Ps.displayName="TableRow";const Ma=u.forwardRef(({className:s,...n},a)=>e.jsx("th",{ref:a,className:N("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));Ma.displayName="TableHead";const Ys=u.forwardRef(({className:s,...n},a)=>e.jsx("td",{ref:a,className:N("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));Ys.displayName="TableCell";const ou=u.forwardRef(({className:s,...n},a)=>e.jsx("caption",{ref:a,className:N("mt-4 text-sm text-muted-foreground",s),...n}));ou.displayName="TableCaption";function cu({table:s}){const[n,a]=u.useState(""),{t:l}=M("common");u.useEffect(()=>{a((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const r=c=>{const o=parseInt(c);!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.jsx("div",{className:"flex-1 text-sm text-muted-foreground",children:l("table.pagination.selected",{selected:s.getFilteredSelectedRowModel().rows.length,total:s.getFilteredRowModel().rows.length})}),e.jsxs("div",{className:"flex flex-col-reverse items-center gap-4 sm:flex-row sm:gap-6 lg:gap-8",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:l("table.pagination.itemsPerPage")}),e.jsxs(X,{value:`${s.getState().pagination.pageSize}`,onValueChange:c=>{s.setPageSize(Number(c))},children:[e.jsx(Q,{className:"h-8 w-[70px]",children:e.jsx(ee,{placeholder:s.getState().pagination.pageSize})}),e.jsx(J,{side:"top",children:[10,20,30,40,50,100,500].map(c=>e.jsx(U,{value:`${c}`,children:c},c))})]})]}),e.jsxs("div",{className:"flex items-center justify-center space-x-2 text-sm font-medium",children:[e.jsx("span",{children:l("table.pagination.page")}),e.jsx(k,{type:"text",value:n,onChange:c=>a(c.target.value),onBlur:c=>r(c.target.value),onKeyDown:c=>{c.key==="Enter"&&r(c.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsx("span",{children:l("table.pagination.pageOf",{total:s.getPageCount()})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(D,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(0),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.firstPage")}),e.jsx(jo,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.previousPage")}),e.jsx(Yn,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.nextPage")}),e.jsx(Ca,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(s.getPageCount()-1),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.lastPage")}),e.jsx(vo,{className:"h-4 w-4"})]})]})]})]})}function cs({table:s,toolbar:n,draggable:a=!1,onDragStart:l,onDragEnd:r,onDragOver:c,onDragLeave:o,onDrop:m,showPagination:x=!0,isLoading:i=!1}){const{t:d}=M("common"),p=u.useRef(null),C=s.getAllColumns().filter(w=>w.getIsPinned()==="left"),P=s.getAllColumns().filter(w=>w.getIsPinned()==="right"),f=w=>C.slice(0,w).reduce((g,S)=>g+(S.getSize()??0),0),j=w=>P.slice(w+1).reduce((g,S)=>g+(S.getSize()??0),0);return e.jsxs("div",{className:"space-y-4",children:[typeof n=="function"?n(s):n,e.jsx("div",{ref:p,className:"relative overflow-auto rounded-md border bg-card",children:e.jsx("div",{className:"overflow-auto",children:e.jsxs(Ia,{children:[e.jsx(Va,{children:s.getHeaderGroups().map(w=>e.jsx(Ps,{className:"hover:bg-transparent",children:w.headers.map((g,S)=>{const R=g.column.getIsPinned()==="left",E=g.column.getIsPinned()==="right",O=R?f(C.indexOf(g.column)):void 0,q=E?j(P.indexOf(g.column)):void 0;return e.jsx(Ma,{colSpan:g.colSpan,style:{width:g.getSize(),...R&&{left:O},...E&&{right:q}},className:N("h-11 bg-card px-4 text-muted-foreground",(R||E)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",R&&"before:right-0",E&&"before:left-0"]),children:g.isPlaceholder?null:Rt(g.column.columnDef.header,g.getContext())},g.id)})},w.id))}),e.jsx(Oa,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((w,g)=>e.jsx(Ps,{"data-state":w.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:a,onDragStart:S=>l?.(S,g),onDragEnd:r,onDragOver:c,onDragLeave:o,onDrop:S=>m?.(S,g),children:w.getVisibleCells().map((S,R)=>{const E=S.column.getIsPinned()==="left",O=S.column.getIsPinned()==="right",q=E?f(C.indexOf(S.column)):void 0,te=O?j(P.indexOf(S.column)):void 0;return e.jsx(Ys,{style:{width:S.column.getSize(),...E&&{left:q},...O&&{right:te}},className:N("bg-card",(E||O)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",E&&"before:right-0",O&&"before:left-0"]),children:Rt(S.column.columnDef.cell,S.getContext())},S.id)})},w.id)):e.jsx(Ps,{children:e.jsx(Ys,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:d("table.noData")})})})]})})}),x&&e.jsx(cu,{table:s})]})}const du=s=>h.object({id:h.number().nullable(),name:h.string().min(2,s("form.validation.name.min")).max(30,s("form.validation.name.max")),icon:h.string().optional().nullable(),notify_domain:h.string().refine(a=>!a||/^https?:\/\/\S+/.test(a),s("form.validation.notify_domain.url")).optional().nullable(),handling_fee_fixed:h.coerce.number().min(0).optional().nullable(),handling_fee_percent:h.coerce.number().min(0).max(100).optional().nullable(),payment:h.string().min(1,s("form.validation.payment.required")),config:h.record(h.string(),h.string())}),ln={id:null,name:"",icon:"",notify_domain:"",handling_fee_fixed:0,handling_fee_percent:0,payment:"",config:{}};function Ur({refetch:s,dialogTrigger:n,type:a="add",defaultFormValues:l=ln}){const{t:r}=M("payment"),[c,o]=u.useState(!1),[m,x]=u.useState(!1),[i,d]=u.useState([]),[p,C]=u.useState([]),P=du(r),f=je({resolver:Ne(P),defaultValues:l,mode:"onChange"}),j=f.watch("payment");u.useEffect(()=>{c&&(async()=>{const{data:S}=await dd();d(S)})()},[c]),u.useEffect(()=>{if(!j||!c)return;(async()=>{const S={payment:j,...a==="edit"&&{id:Number(f.getValues("id"))}};md(S).then(({data:R})=>{C(R);const E=R.reduce((O,q)=>(q.field_name&&(O[q.field_name]=q.value??""),O),{});f.setValue("config",E)})})()},[j,c,f,a]);const w=async g=>{x(!0);try{(await ud(g)).data&&($.success(r("form.messages.success")),f.reset(ln),s(),o(!1))}finally{x(!1)}};return e.jsxs(be,{open:c,onOpenChange:o,children:[e.jsx(Ge,{asChild:!0,children:n||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Re,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add.button")})]})}),e.jsxs(ge,{className:"sm:max-w-[425px]",children:[e.jsx(we,{children:e.jsx(ye,{children:r(a==="add"?"form.add.title":"form.edit.title")})}),e.jsx(_e,{...f,children:e.jsxs("form",{onSubmit:f.handleSubmit(w),className:"space-y-4",children:[e.jsx(b,{control:f.control,name:"name",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:r("form.fields.name.placeholder"),...g})}),e.jsx(z,{children:r("form.fields.name.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:f.control,name:"icon",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.icon.label")}),e.jsx(_,{children:e.jsx(k,{...g,value:g.value||"",placeholder:r("form.fields.icon.placeholder")})}),e.jsx(z,{children:r("form.fields.icon.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:f.control,name:"notify_domain",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.notify_domain.label")}),e.jsx(_,{children:e.jsx(k,{...g,value:g.value||"",placeholder:r("form.fields.notify_domain.placeholder")})}),e.jsx(z,{children:r("form.fields.notify_domain.description")}),e.jsx(T,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(b,{control:f.control,name:"handling_fee_percent",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.handling_fee_percent.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",...g,value:g.value||"",placeholder:r("form.fields.handling_fee_percent.placeholder")})}),e.jsx(T,{})]})}),e.jsx(b,{control:f.control,name:"handling_fee_fixed",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.handling_fee_fixed.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",...g,value:g.value||"",placeholder:r("form.fields.handling_fee_fixed.placeholder")})}),e.jsx(T,{})]})})]}),e.jsx(b,{control:f.control,name:"payment",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.payment.label")}),e.jsxs(X,{onValueChange:g.onChange,defaultValue:g.value,children:[e.jsx(_,{children:e.jsx(Q,{children:e.jsx(ee,{placeholder:r("form.fields.payment.placeholder")})})}),e.jsx(J,{children:i.map(S=>e.jsx(U,{value:S,children:S},S))})]}),e.jsx(z,{children:r("form.fields.payment.description")}),e.jsx(T,{})]})}),p.length>0&&e.jsx("div",{className:"space-y-4",children:p.map(g=>e.jsx(b,{control:f.control,name:`config.${g.field_name}`,render:({field:S})=>e.jsxs(v,{children:[e.jsx(y,{children:g.label}),e.jsx(_,{children:e.jsx(k,{...S,value:S.value||""})}),e.jsx(T,{})]})},g.field_name))}),e.jsxs(Ae,{children:[e.jsx(jt,{asChild:!0,children:e.jsx(D,{type:"button",variant:"outline",children:r("form.buttons.cancel")})}),e.jsx(D,{type:"submit",disabled:m,children:r("form.buttons.submit")})]})]})})]})]})}function L({column:s,title:n,tooltip:a,className:l}){return s.getCanSort()?e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(D,{variant:"ghost",size:"default",className:N("-ml-3 flex h-8 items-center gap-2 text-nowrap font-medium hover:bg-muted/60",l),onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[e.jsx("span",{children:n}),a&&e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(Ya,{className:"h-4 w-4 cursor-pointer text-muted-foreground"})}),e.jsx(ce,{children:a})]})}),s.getIsSorted()==="asc"?e.jsx(ha,{className:"h-4 w-4 text-foreground/70"}):s.getIsSorted()==="desc"?e.jsx(fa,{className:"h-4 w-4 text-foreground/70"}):e.jsx(bo,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-foreground/70"})]})})}):e.jsxs("div",{className:N("flex items-center space-x-1 text-nowrap py-2 font-medium text-muted-foreground",l),children:[e.jsx("span",{children:n}),a&&e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{children:e.jsx(Ya,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(ce,{children:a})]})})]})}const Fa=yo,Hr=No,mu=_o,Kr=u.forwardRef(({className:s,...n},a)=>e.jsx(nr,{className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:a}));Kr.displayName=nr.displayName;const Wt=u.forwardRef(({className:s,...n},a)=>e.jsxs(mu,{children:[e.jsx(Kr,{}),e.jsx(rr,{ref:a,className:N("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...n})]}));Wt.displayName=rr.displayName;const Yt=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-2 text-center sm:text-left",s),...n});Yt.displayName="AlertDialogHeader";const Qt=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Qt.displayName="AlertDialogFooter";const Jt=u.forwardRef(({className:s,...n},a)=>e.jsx(lr,{ref:a,className:N("text-lg font-semibold",s),...n}));Jt.displayName=lr.displayName;const Zt=u.forwardRef(({className:s,...n},a)=>e.jsx(ir,{ref:a,className:N("text-sm text-muted-foreground",s),...n}));Zt.displayName=ir.displayName;const Xt=u.forwardRef(({className:s,...n},a)=>e.jsx(or,{ref:a,className:N(Js(),s),...n}));Xt.displayName=or.displayName;const ea=u.forwardRef(({className:s,...n},a)=>e.jsx(cr,{ref:a,className:N(Js({variant:"outline"}),"mt-2 sm:mt-0",s),...n}));ea.displayName=cr.displayName;function Be({onConfirm:s,children:n,title:a="确认操作",description:l="确定要执行此操作吗?",cancelText:r="取消",confirmText:c="确认",variant:o="default",className:m}){return e.jsxs(Fa,{children:[e.jsx(Hr,{asChild:!0,children:n}),e.jsxs(Wt,{className:N("sm:max-w-[425px]",m),children:[e.jsxs(Yt,{children:[e.jsx(Jt,{children:a}),e.jsx(Zt,{children:l})]}),e.jsxs(Qt,{children:[e.jsx(ea,{asChild:!0,children:e.jsx(D,{variant:"outline",children:r})}),e.jsx(Xt,{asChild:!0,children:e.jsx(D,{variant:o,onClick:s,children:c})})]})]})]})}const Br=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),uu=({refetch:s,isSortMode:n=!1})=>{const{t:a}=M("payment");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(Ut,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:l})=>e.jsx(L,{column:l,title:a("table.columns.id")}),cell:({row:l})=>e.jsx(K,{variant:"outline",children:l.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"enable",header:({column:l})=>e.jsx(L,{column:l,title:a("table.columns.enable")}),cell:({row:l})=>e.jsx(W,{defaultChecked:l.getValue("enable"),onCheckedChange:async()=>{const{data:r}=await hd({id:l.original.id});r||s()}}),enableSorting:!1,size:100},{accessorKey:"name",header:({column:l})=>e.jsx(L,{column:l,title:a("table.columns.name")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:l.getValue("name")})}),enableSorting:!1,size:200},{accessorKey:"payment",header:({column:l})=>e.jsx(L,{column:l,title:a("table.columns.payment")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:l.getValue("payment")})}),enableSorting:!1,size:200},{accessorKey:"notify_url",header:({column:l})=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(L,{column:l,title:a("table.columns.notify_url")}),e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{className:"ml-1",children:e.jsx(Br,{className:"h-4 w-4"})}),e.jsx(ce,{children:a("table.columns.notify_url_tooltip")})]})})]}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[300px] truncate font-medium",children:l.getValue("notify_url")})}),enableSorting:!1,size:3e3},{id:"actions",header:({column:l})=>e.jsx(L,{className:"justify-end",column:l,title:a("table.columns.actions")}),cell:({row:l})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Ur,{refetch:s,dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(As,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("table.actions.edit")})]}),type:"edit",defaultFormValues:l.original}),e.jsx(Be,{title:a("table.actions.delete.title"),description:a("table.actions.delete.description"),onConfirm:async()=>{const{data:r}=await xd({id:l.original.id});r&&s()},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10",children:[e.jsx(ns,{className:"h-4 w-4 text-muted-foreground hover:text-destructive"}),e.jsx("span",{className:"sr-only",children:a("table.actions.delete.title")})]})})]}),size:100}]};function xu({table:s,refetch:n,saveOrder:a,isSortMode:l}){const{t:r}=M("payment"),c=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between",children:[l?e.jsx("p",{className:"text-sm text-muted-foreground",children:r("table.toolbar.sort.hint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ur,{refetch:n}),e.jsx(k,{placeholder:r("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:o=>s.getColumn("name")?.setFilterValue(o.target.value),className:"h-8 w-[250px]"}),c&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[r("table.toolbar.reset"),e.jsx(Ye,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(D,{variant:l?"default":"outline",onClick:a,size:"sm",children:r(l?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}function hu(){const[s,n]=u.useState([]),[a,l]=u.useState([]),[r,c]=u.useState(!1),[o,m]=u.useState([]),[x,i]=u.useState({"drag-handle":!1}),[d,p]=u.useState({pageSize:20,pageIndex:0}),{refetch:C}=ie({queryKey:["paymentList"],queryFn:async()=>{const{data:g}=await cd();return m(g?.map(S=>({...S,enable:!!S.enable}))||[]),g}});u.useEffect(()=>{i({"drag-handle":r,actions:!r}),p({pageSize:r?99999:10,pageIndex:0})},[r]);const P=(g,S)=>{r&&(g.dataTransfer.setData("text/plain",S.toString()),g.currentTarget.classList.add("opacity-50"))},f=(g,S)=>{if(!r)return;g.preventDefault(),g.currentTarget.classList.remove("bg-muted");const R=parseInt(g.dataTransfer.getData("text/plain"));if(R===S)return;const E=[...o],[O]=E.splice(R,1);E.splice(S,0,O),m(E)},j=async()=>{r?fd({ids:o.map(g=>g.id)}).then(()=>{C(),c(!1),$.success("排序保存成功")}):c(!0)},w=Ze({data:o,columns:uu({refetch:C,isSortMode:r}),state:{sorting:a,columnFilters:s,columnVisibility:x,pagination:d},onSortingChange:l,onColumnFiltersChange:n,onColumnVisibilityChange:i,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),getSortedRowModel:is(),initialState:{columnPinning:{right:["actions"]}},pageCount:r?1:void 0});return e.jsx(cs,{table:w,toolbar:g=>e.jsx(xu,{table:g,refetch:C,saveOrder:j,isSortMode:r}),draggable:r,onDragStart:P,onDragEnd:g=>g.currentTarget.classList.remove("opacity-50"),onDragOver:g=>{g.preventDefault(),g.currentTarget.classList.add("bg-muted")},onDragLeave:g=>g.currentTarget.classList.remove("bg-muted"),onDrop:f,showPagination:!r})}function fu(){const{t:s}=M("payment");return e.jsxs(Pe,{children:[e.jsxs(Ee,{className:"flex items-center justify-between",children:[e.jsx($e,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{children:[e.jsx("header",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("section",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(hu,{})})]})]})}const pu=Object.freeze(Object.defineProperty({__proto__:null,default:fu},Symbol.toStringTag,{value:"Module"}));function gu({pluginName:s,onClose:n,onSuccess:a}){const{t:l}=M("plugin"),[r,c]=u.useState(!0),[o,m]=u.useState(!1),[x,i]=u.useState(null),d=wo({config:Co(So())}),p=je({resolver:Ne(d),defaultValues:{config:{}}});u.useEffect(()=>{(async()=>{try{const{data:j}=await gs.getPluginConfig(s);i(j),p.reset({config:Object.fromEntries(Object.entries(j).map(([w,g])=>[w,g.value]))})}catch{$.error(l("messages.configLoadError"))}finally{c(!1)}})()},[s]);const C=async f=>{m(!0);try{await gs.updatePluginConfig(s,f.config),$.success(l("messages.configSaveSuccess")),a()}catch{$.error(l("messages.configSaveError"))}finally{m(!1)}},P=(f,j)=>{switch(j.type){case"string":return e.jsx(b,{control:p.control,name:`config.${f}`,render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{children:j.label||j.description}),e.jsx(_,{children:e.jsx(k,{placeholder:j.placeholder,...w})}),j.description&&j.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:j.description}),e.jsx(T,{})]})},f);case"number":case"percentage":return e.jsx(b,{control:p.control,name:`config.${f}`,render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{children:j.label||j.description}),e.jsx(_,{children:e.jsxs("div",{className:"relative",children:[e.jsx(k,{type:"number",placeholder:j.placeholder,...w,onChange:g=>{const S=Number(g.target.value);j.type==="percentage"?w.onChange(Math.min(100,Math.max(0,S))):w.onChange(S)},className:j.type==="percentage"?"pr-8":"",min:j.type==="percentage"?0:void 0,max:j.type==="percentage"?100:void 0,step:j.type==="percentage"?1:void 0}),j.type==="percentage"&&e.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3",children:e.jsx(ko,{className:"h-4 w-4 text-muted-foreground"})})]})}),j.description&&j.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:j.description}),e.jsx(T,{})]})},f);case"select":return e.jsx(b,{control:p.control,name:`config.${f}`,render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{children:j.label||j.description}),e.jsxs(X,{onValueChange:w.onChange,defaultValue:w.value,children:[e.jsx(_,{children:e.jsx(Q,{children:e.jsx(ee,{placeholder:j.placeholder})})}),e.jsx(J,{children:j.options?.map(g=>e.jsx(U,{value:g.value,children:g.label},g.value))})]}),j.description&&j.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:j.description}),e.jsx(T,{})]})},f);case"boolean":return e.jsx(b,{control:p.control,name:`config.${f}`,render:({field:w})=>e.jsxs(v,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{className:"text-base",children:j.label||j.description}),j.description&&j.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:j.description})]}),e.jsx(_,{children:e.jsx(W,{checked:w.value,onCheckedChange:w.onChange})})]})},f);case"text":return e.jsx(b,{control:p.control,name:`config.${f}`,render:({field:w})=>e.jsxs(v,{children:[e.jsx(y,{children:j.label||j.description}),e.jsx(_,{children:e.jsx(fs,{placeholder:j.placeholder,...w})}),j.description&&j.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:j.description}),e.jsx(T,{})]})},f);default:return null}};return r?e.jsxs("div",{className:"space-y-4",children:[e.jsx(oe,{className:"h-4 w-[200px]"}),e.jsx(oe,{className:"h-10 w-full"}),e.jsx(oe,{className:"h-4 w-[200px]"}),e.jsx(oe,{className:"h-10 w-full"})]}):e.jsx(_e,{...p,children:e.jsxs("form",{onSubmit:p.handleSubmit(C),className:"space-y-4",children:[x&&Object.entries(x).map(([f,j])=>P(f,j)),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:n,disabled:o,children:l("config.cancel")}),e.jsx(D,{type:"submit",loading:o,disabled:o,children:l("config.save")})]})]})})}function ju(){const{t:s}=M("plugin"),[n,a]=u.useState(null),[l,r]=u.useState(!1),[c,o]=u.useState(null),[m,x]=u.useState(""),[i,d]=u.useState("all"),[p,C]=u.useState(!1),[P,f]=u.useState(!1),[j,w]=u.useState(!1),g=u.useRef(null),{data:S,isLoading:R,refetch:E}=ie({queryKey:["pluginList"],queryFn:async()=>{const{data:I}=await gs.getPluginList();return I}});S&&[...new Set(S.map(I=>I.category||"other"))];const O=S?.filter(I=>{const Y=I.name.toLowerCase().includes(m.toLowerCase())||I.description.toLowerCase().includes(m.toLowerCase())||I.code.toLowerCase().includes(m.toLowerCase()),ne=i==="all"||I.category===i;return Y&&ne}),q=async I=>{a(I),gs.installPlugin(I).then(()=>{$.success(s("messages.installSuccess")),E()}).catch(Y=>{$.error(Y.message||s("messages.installError"))}).finally(()=>{a(null)})},te=async I=>{a(I),gs.uninstallPlugin(I).then(()=>{$.success(s("messages.uninstallSuccess")),E()}).catch(Y=>{$.error(Y.message||s("messages.uninstallError"))}).finally(()=>{a(null)})},F=async(I,Y)=>{a(I),(Y?gs.disablePlugin:gs.enablePlugin)(I).then(()=>{$.success(s(Y?"messages.disableSuccess":"messages.enableSuccess")),E()}).catch(We=>{$.error(We.message||s(Y?"messages.disableError":"messages.enableError"))}).finally(()=>{a(null)})},se=I=>{S?.find(Y=>Y.code===I),o(I),r(!0)},qe=async I=>{if(!I.name.endsWith(".zip")){$.error(s("upload.error.format"));return}C(!0),gs.uploadPlugin(I).then(()=>{$.success(s("messages.uploadSuccess")),f(!1),E()}).catch(Y=>{$.error(Y.message||s("messages.uploadError"))}).finally(()=>{C(!1),g.current&&(g.current.value="")})},B=I=>{I.preventDefault(),I.stopPropagation(),I.type==="dragenter"||I.type==="dragover"?w(!0):I.type==="dragleave"&&w(!1)},ae=I=>{I.preventDefault(),I.stopPropagation(),w(!1),I.dataTransfer.files&&I.dataTransfer.files[0]&&qe(I.dataTransfer.files[0])},A=async I=>{a(I),gs.deletePlugin(I).then(()=>{$.success(s("messages.deleteSuccess")),E()}).catch(Y=>{$.error(Y.message||s("messages.deleteError"))}).finally(()=>{a(null)})};return e.jsxs(Pe,{children:[e.jsxs(Ee,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Sa,{className:"h-6 w-6"}),e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("title")})]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{children:[e.jsxs("div",{className:"mb-8 space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"relative max-w-sm flex-1",children:[e.jsx(On,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(k,{placeholder:s("search.placeholder"),value:m,onChange:I=>x(I.target.value),className:"pl-9"})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs(D,{onClick:()=>f(!0),variant:"outline",className:"shrink-0",size:"sm",children:[e.jsx(ut,{className:"mr-2 h-4 w-4"}),s("upload.button")]})})]}),e.jsxs(Ra,{defaultValue:"all",className:"w-full",children:[e.jsxs(Gt,{children:[e.jsx(Es,{value:"all",children:s("tabs.all")}),e.jsx(Es,{value:"installed",children:s("tabs.installed")}),e.jsx(Es,{value:"available",children:s("tabs.available")})]}),e.jsx(Tt,{value:"all",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:R?e.jsxs(e.Fragment,{children:[e.jsx(ia,{}),e.jsx(ia,{}),e.jsx(ia,{})]}):O?.map(I=>e.jsx(la,{plugin:I,onInstall:q,onUninstall:te,onToggleEnable:F,onOpenConfig:se,onDelete:A,isLoading:n===I.name},I.name))})}),e.jsx(Tt,{value:"installed",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:O?.filter(I=>I.is_installed).map(I=>e.jsx(la,{plugin:I,onInstall:q,onUninstall:te,onToggleEnable:F,onOpenConfig:se,onDelete:A,isLoading:n===I.name},I.name))})}),e.jsx(Tt,{value:"available",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:O?.filter(I=>!I.is_installed).map(I=>e.jsx(la,{plugin:I,onInstall:q,onUninstall:te,onToggleEnable:F,onOpenConfig:se,onDelete:A,isLoading:n===I.name},I.code))})})]})]}),e.jsx(be,{open:l,onOpenChange:r,children:e.jsxs(ge,{className:"sm:max-w-lg",children:[e.jsxs(we,{children:[e.jsxs(ye,{children:[S?.find(I=>I.code===c)?.name," ",s("config.title")]}),e.jsx(De,{children:s("config.description")})]}),c&&e.jsx(gu,{pluginName:c,onClose:()=>r(!1),onSuccess:()=>{r(!1),E()}})]})}),e.jsx(be,{open:P,onOpenChange:f,children:e.jsxs(ge,{className:"sm:max-w-md",children:[e.jsxs(we,{children:[e.jsx(ye,{children:s("upload.title")}),e.jsx(De,{children:s("upload.description")})]}),e.jsxs("div",{className:N("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",j&&"border-primary/50 bg-muted/50"),onDragEnter:B,onDragLeave:B,onDragOver:B,onDrop:ae,children:[e.jsx("input",{type:"file",ref:g,className:"hidden",accept:".zip",onChange:I=>{const Y=I.target.files?.[0];Y&&qe(Y)}}),p?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(ut,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[s("upload.dragText")," ",e.jsx("button",{type:"button",onClick:()=>g.current?.click(),className:"mx-1 text-primary hover:underline",children:s("upload.clickText")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("upload.supportText")})]})]})})]})]})})]})]})}function la({plugin:s,onInstall:n,onUninstall:a,onToggleEnable:l,onOpenConfig:r,onDelete:c,isLoading:o}){const{t:m}=M("plugin");return e.jsxs(He,{className:"group relative overflow-hidden transition-all hover:shadow-md",children:[e.jsxs(Qe,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vs,{children:s.name}),s.is_installed&&e.jsx(K,{variant:s.is_enabled?"success":"secondary",children:s.is_enabled?m("status.enabled"):m("status.disabled")})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Sa,{className:"h-4 w-4"}),e.jsx("code",{className:"rounded bg-muted px-1 py-0.5",children:s.code})]}),e.jsxs("div",{children:["v",s.version]})]})]})}),e.jsx(Qs,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"mt-2",children:s.description}),e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1",children:[m("author"),": ",s.author]})})]})})]}),e.jsx(Je,{children:e.jsx("div",{className:"flex items-center justify-end space-x-2",children:s.is_installed?e.jsxs(e.Fragment,{children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>r(s.code),disabled:!s.is_enabled||o,children:[e.jsx(To,{className:"mr-2 h-4 w-4"}),m("button.config")]}),e.jsxs(D,{variant:s.is_enabled?"destructive":"default",size:"sm",onClick:()=>l(s.code,s.is_enabled),disabled:o,children:[e.jsx(Do,{className:"mr-2 h-4 w-4"}),s.is_enabled?m("button.disable"):m("button.enable")]}),e.jsx(Be,{title:m("uninstall.title"),description:m("uninstall.description"),cancelText:m("common:cancel"),confirmText:m("uninstall.button"),variant:"destructive",onConfirm:()=>a(s.code),children:e.jsxs(D,{variant:"outline",size:"sm",className:"text-muted-foreground hover:text-destructive",disabled:o,children:[e.jsx(ns,{className:"mr-2 h-4 w-4"}),m("button.uninstall")]})})]}):e.jsxs(e.Fragment,{children:[e.jsx(D,{onClick:()=>n(s.code),disabled:o,loading:o,children:m("button.install")}),e.jsx(Be,{title:m("delete.title"),description:m("delete.description"),cancelText:m("common:cancel"),confirmText:m("delete.button"),variant:"destructive",onConfirm:()=>c(s.code),children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",disabled:o,children:e.jsx(ns,{className:"h-4 w-4"})})})]})})})]})}function ia(){return e.jsxs(He,{children:[e.jsxs(Qe,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"h-6 w-[200px]"}),e.jsx(oe,{className:"h-6 w-[80px]"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(oe,{className:"h-5 w-[120px]"}),e.jsx(oe,{className:"h-5 w-[60px]"})]})]})}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx(oe,{className:"h-4 w-[300px]"}),e.jsx(oe,{className:"h-4 w-[150px]"})]})]}),e.jsx(Je,{children:e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(oe,{className:"h-9 w-[100px]"}),e.jsx(oe,{className:"h-9 w-[100px]"}),e.jsx(oe,{className:"h-8 w-8"})]})})]})}const vu=Object.freeze(Object.defineProperty({__proto__:null,default:ju},Symbol.toStringTag,{value:"Module"})),bu=(s,n)=>{let a=null;switch(s.field_type){case"input":a=e.jsx(k,{placeholder:s.placeholder,...n});break;case"textarea":a=e.jsx(fs,{placeholder:s.placeholder,...n});break;case"select":a=e.jsx("select",{className:N(Js({variant:"outline"}),"w-full appearance-none font-normal"),...n,children:s.select_options&&Object.keys(s.select_options).map(l=>e.jsx("option",{value:l,children:s.select_options?.[l]},l))});break;default:a=null;break}return a};function yu({themeKey:s,themeInfo:n}){const{t:a}=M("theme"),[l,r]=u.useState(!1),[c,o]=u.useState(!1),[m,x]=u.useState(!1),i=je({defaultValues:n.configs.reduce((C,P)=>(C[P.field_name]="",C),{})}),d=async()=>{o(!0),Yc(s).then(({data:C})=>{Object.entries(C).forEach(([P,f])=>{i.setValue(P,f)})}).finally(()=>{o(!1)})},p=async C=>{x(!0),Qc(s,C).then(()=>{$.success(a("config.success")),r(!1)}).finally(()=>{x(!1)})};return e.jsxs(be,{open:l,onOpenChange:C=>{r(C),C?d():i.reset()},children:[e.jsx(Ge,{asChild:!0,children:e.jsx(D,{variant:"outline",children:a("card.configureTheme")})}),e.jsxs(ge,{className:"max-h-[90vh] overflow-auto sm:max-w-[425px]",children:[e.jsxs(we,{children:[e.jsx(ye,{children:a("config.title",{name:n.name})}),e.jsx(De,{children:a("config.description")})]}),c?e.jsx("div",{className:"flex h-40 items-center justify-center",children:e.jsx(Ta,{className:"h-6 w-6 animate-spin"})}):e.jsx(_e,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(p),className:"space-y-4",children:[n.configs.map(C=>e.jsx(b,{control:i.control,name:C.field_name,render:({field:P})=>e.jsxs(v,{children:[e.jsx(y,{children:C.label}),e.jsx(_,{children:bu(C,P)}),e.jsx(T,{})]})},C.field_name)),e.jsxs(Ae,{className:"mt-6 gap-2",children:[e.jsx(D,{type:"button",variant:"secondary",onClick:()=>r(!1),children:a("config.cancel")}),e.jsx(D,{type:"submit",loading:m,children:a("config.save")})]})]})})]})]})}function Nu(){const{t:s}=M("theme"),[n,a]=u.useState(null),[l,r]=u.useState(!1),[c,o]=u.useState(!1),[m,x]=u.useState(!1),[i,d]=u.useState(null),p=u.useRef(null),[C,P]=u.useState(0),{data:f,isLoading:j,refetch:w}=ie({queryKey:["themeList"],queryFn:async()=>{const{data:F}=await Wc();return F}}),g=async F=>{a(F),Xc({frontend_theme:F}).then(()=>{$.success("主题切换成功"),w()}).finally(()=>{a(null)})},S=async F=>{if(!F.name.endsWith(".zip")){$.error(s("upload.error.format"));return}r(!0),Jc(F).then(()=>{$.success("主题上传成功"),o(!1),w()}).finally(()=>{r(!1),p.current&&(p.current.value="")})},R=F=>{F.preventDefault(),F.stopPropagation(),F.type==="dragenter"||F.type==="dragover"?x(!0):F.type==="dragleave"&&x(!1)},E=F=>{F.preventDefault(),F.stopPropagation(),x(!1),F.dataTransfer.files&&F.dataTransfer.files[0]&&S(F.dataTransfer.files[0])},O=()=>{i&&P(F=>F===0?i.images.length-1:F-1)},q=()=>{i&&P(F=>F===i.images.length-1?0:F+1)},te=(F,se)=>{P(0),d({name:F,images:se})};return e.jsxs(Pe,{children:[e.jsxs(Ee,{className:"flex items-center justify-between",children:[e.jsx($e,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"",children:[e.jsxs("header",{className:"mb-8",children:[e.jsx("div",{className:"mb-2",children:e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-muted-foreground",children:s("description")}),e.jsxs(D,{onClick:()=>o(!0),variant:"outline",className:"ml-4 shrink-0",size:"sm",children:[e.jsx(ut,{className:"mr-2 h-4 w-4"}),s("upload.button")]})]})]}),e.jsx("section",{className:"grid gap-6 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3",children:j?e.jsxs(e.Fragment,{children:[e.jsx(on,{}),e.jsx(on,{})]}):f?.themes&&Object.entries(f.themes).map(([F,se])=>e.jsx(He,{className:"group relative overflow-hidden transition-all hover:shadow-md",style:{backgroundImage:se.background_url?`url(${se.background_url})`:"none",backgroundSize:"cover",backgroundPosition:"center"},children:e.jsxs("div",{className:N("relative z-10 h-full transition-colors",se.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:[!!se.can_delete&&e.jsx("div",{className:"absolute right-2 top-2",children:e.jsx(Be,{title:s("card.delete.title"),description:s("card.delete.description"),confirmText:s("card.delete.button"),variant:"destructive",onConfirm:async()=>{if(F===f?.active){$.error(s("card.delete.error.active"));return}a(F),Zc(F).then(()=>{$.success("主题删除成功"),w()}).finally(()=>{a(null)})},children:e.jsx(D,{disabled:n===F,loading:n===F,variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",children:e.jsx(ns,{className:"h-4 w-4"})})})}),e.jsxs(Qe,{children:[e.jsx(vs,{children:se.name}),e.jsx(Qs,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{children:se.description}),se.version&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("card.version",{version:se.version})})]})})]}),e.jsxs(Je,{className:"flex items-center justify-end space-x-3",children:[se.images&&Array.isArray(se.images)&&se.images.length>0&&e.jsx(D,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>te(se.name,se.images),children:e.jsx(Po,{className:"h-4 w-4"})}),e.jsx(yu,{themeKey:F,themeInfo:se}),e.jsx(D,{onClick:()=>g(F),disabled:n===F||F===f.active,loading:n===F,variant:F===f.active?"secondary":"default",children:F===f.active?s("card.currentTheme"):s("card.activateTheme")})]})]})},F))}),e.jsx(be,{open:c,onOpenChange:o,children:e.jsxs(ge,{className:"sm:max-w-md",children:[e.jsxs(we,{children:[e.jsx(ye,{children:s("upload.title")}),e.jsx(De,{children:s("upload.description")})]}),e.jsxs("div",{className:N("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",m&&"border-primary/50 bg-muted/50"),onDragEnter:R,onDragLeave:R,onDragOver:R,onDrop:E,children:[e.jsx("input",{type:"file",ref:p,className:"hidden",accept:".zip",onChange:F=>{const se=F.target.files?.[0];se&&S(se)}}),l?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(ut,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[s("upload.dragText")," ",e.jsx("button",{type:"button",onClick:()=>p.current?.click(),className:"mx-1 text-primary hover:underline",children:s("upload.clickText")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("upload.supportText")})]})]})})]})]})}),e.jsx(be,{open:!!i,onOpenChange:F=>{F||(d(null),P(0))},children:e.jsxs(ge,{className:"max-w-4xl",children:[e.jsxs(we,{children:[e.jsxs(ye,{children:[i?.name," ",s("preview.title")]}),e.jsx(De,{className:"text-center",children:i&&s("preview.imageCount",{current:C+1,total:i.images.length})})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"aspect-[16/9] overflow-hidden rounded-lg border bg-muted",children:i?.images[C]&&e.jsx("img",{src:i.images[C],alt:`${i.name} 预览图 ${C+1}`,className:"h-full w-full object-contain"})}),i&&i.images.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(D,{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:O,children:e.jsx(Eo,{className:"h-4 w-4"})}),e.jsx(D,{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:q,children:e.jsx(Ro,{className:"h-4 w-4"})})]})]}),i&&i.images.length>1&&e.jsx("div",{className:"mt-4 flex gap-2 overflow-x-auto pb-2",children:i.images.map((F,se)=>e.jsx("button",{onClick:()=>P(se),className:N("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2",C===se?"border-primary":"border-transparent"),children:e.jsx("img",{src:F,alt:`缩略图 ${se+1}`,className:"h-full w-full object-cover"})},se))})]})})]})]})}function on(){return e.jsxs(He,{children:[e.jsxs(Qe,{children:[e.jsx(oe,{className:"h-6 w-[200px]"}),e.jsx(oe,{className:"h-4 w-[300px]"})]}),e.jsxs(Je,{className:"flex items-center justify-end space-x-3",children:[e.jsx(oe,{className:"h-10 w-[100px]"}),e.jsx(oe,{className:"h-10 w-[100px]"})]})]})}const _u=Object.freeze(Object.defineProperty({__proto__:null,default:Nu},Symbol.toStringTag,{value:"Module"})),za=u.forwardRef(({className:s,value:n,onChange:a,...l},r)=>{const[c,o]=u.useState("");u.useEffect(()=>{if(c.includes(",")){const x=new Set([...n,...c.split(",").map(i=>i.trim())]);a(Array.from(x)),o("")}},[c,a,n]);const m=()=>{if(c){const x=new Set([...n,c]);a(Array.from(x)),o("")}};return e.jsxs("div",{className:N(" has-[:focus-visible]:outline-none has-[:focus-visible]:ring-1 has-[:focus-visible]:ring-neutral-950 dark:has-[:focus-visible]:ring-neutral-300 flex w-full flex-wrap gap-2 rounded-md border border-input shadow-sm px-3 py-2 text-sm ring-offset-white disabled:cursor-not-allowed disabled:opacity-50",s),children:[n.map(x=>e.jsxs(K,{variant:"secondary",children:[x,e.jsx(G,{variant:"ghost",size:"icon",className:"ml-2 h-3 w-3",onClick:()=>{a(n.filter(i=>i!==x))},children:e.jsx(pa,{className:"w-3"})})]},x)),e.jsx("input",{className:"flex-1 outline-none placeholder:text-muted-foreground bg-transparent",value:c,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"||x.key===","?(x.preventDefault(),m()):x.key==="Backspace"&&c.length===0&&n.length>0&&(x.preventDefault(),a(n.slice(0,-1)))},...l,ref:r})]})});za.displayName="InputTags";const wu=h.object({id:h.number().nullable(),title:h.string().min(1).max(250),content:h.string().min(1),show:h.boolean(),tags:h.array(h.string()),img_url:h.string().nullable()}),Cu={id:null,show:!1,tags:[],img_url:"",title:"",content:""};function Gr({refetch:s,dialogTrigger:n,type:a="add",defaultFormValues:l=Cu}){const{t:r}=M("notice"),[c,o]=u.useState(!1),m=je({resolver:Ne(wu),defaultValues:l,mode:"onChange",shouldFocusError:!0}),x=new Da({html:!0});return e.jsx(_e,{...m,children:e.jsxs(be,{onOpenChange:o,open:c,children:[e.jsx(Ge,{asChild:!0,children:n||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Re,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add.button")})]})}),e.jsxs(ge,{className:"sm:max-w-[1025px]",children:[e.jsxs(we,{children:[e.jsx(ye,{children:r(a==="add"?"form.add.title":"form.edit.title")}),e.jsx(De,{})]}),e.jsx(b,{control:m.control,name:"title",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.title.label")}),e.jsx("div",{className:"relative ",children:e.jsx(_,{children:e.jsx(k,{placeholder:r("form.fields.title.placeholder"),...i})})}),e.jsx(T,{})]})}),e.jsx(b,{control:m.control,name:"content",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.content.label")}),e.jsx(_,{children:e.jsx(Pa,{style:{height:"500px"},value:i.value,renderHTML:d=>x.render(d),onChange:({text:d})=>{i.onChange(d)}})}),e.jsx(T,{})]})}),e.jsx(b,{control:m.control,name:"img_url",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.img_url.label")}),e.jsx("div",{className:"relative",children:e.jsx(_,{children:e.jsx(k,{type:"text",placeholder:r("form.fields.img_url.placeholder"),...i,value:i.value||""})})}),e.jsx(T,{})]})}),e.jsx(b,{control:m.control,name:"show",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.show.label")}),e.jsx("div",{className:"relative py-2",children:e.jsx(_,{children:e.jsx(W,{checked:i.value,onCheckedChange:i.onChange})})}),e.jsx(T,{})]})}),e.jsx(b,{control:m.control,name:"tags",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.fields.tags.label")}),e.jsx(_,{children:e.jsx(za,{value:i.value,onChange:i.onChange,placeholder:r("form.fields.tags.placeholder"),className:"w-full"})}),e.jsx(T,{})]})}),e.jsxs(Ae,{children:[e.jsx(jt,{asChild:!0,children:e.jsx(D,{type:"button",variant:"outline",children:r("form.buttons.cancel")})}),e.jsx(D,{type:"submit",onClick:i=>{i.preventDefault(),m.handleSubmit(async d=>{pd(d).then(({data:p})=>{p&&($.success(r("form.buttons.success")),s(),o(!1))})})()},children:r("form.buttons.submit")})]})]})]})})}function Su({table:s,refetch:n,saveOrder:a,isSortMode:l}){const{t:r}=M("notice"),c=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between space-x-2 ",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[!l&&e.jsx(Gr,{refetch:n}),!l&&e.jsx(k,{placeholder:r("table.toolbar.search"),value:s.getColumn("title")?.getFilterValue()??"",onChange:o=>s.getColumn("title")?.setFilterValue(o.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),c&&!l&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-9 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(Ye,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(D,{variant:l?"default":"outline",onClick:a,className:"h-8",size:"sm",children:r(l?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}const ku=s=>{const{t:n}=M("notice");return[{id:"drag-handle",header:"",cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Io,{className:"h-4 w-4 text-muted-foreground cursor-move"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.id")}),cell:({row:a})=>e.jsx(K,{variant:"outline",className:"font-mono",children:a.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"show",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.show")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx(W,{defaultChecked:a.getValue("show"),onCheckedChange:async()=>{const{data:l}=await jd({id:a.original.id});l||s()}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.title")}),cell:({row:a})=>e.jsx("div",{className:"flex max-w-[500px] items-center",children:e.jsx("span",{className:"truncate font-medium",children:a.getValue("title")})}),enableSorting:!1,size:6e3},{id:"actions",header:({column:a})=>e.jsx(L,{className:"justify-end",column:a,title:n("table.columns.actions")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Gr,{refetch:s,dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(As,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),type:"edit",defaultFormValues:a.original}),e.jsx(Be,{title:n("table.actions.delete.title"),description:n("table.actions.delete.description"),onConfirm:async()=>{gd({id:a.original.id}).then(()=>{$.success(n("table.actions.delete.success")),s()})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ns,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("table.actions.delete.title")})]})})]}),size:100}]};function Tu(){const[s,n]=u.useState({}),[a,l]=u.useState({}),[r,c]=u.useState([]),[o,m]=u.useState([]),[x,i]=u.useState(!1),[d,p]=u.useState({}),[C,P]=u.useState({pageSize:50,pageIndex:0}),[f,j]=u.useState([]),{refetch:w}=ie({queryKey:["notices"],queryFn:async()=>{const{data:O}=await nn.getList();return j(O),O}});u.useEffect(()=>{l({"drag-handle":x,content:!x,created_at:!x,actions:!x}),P({pageSize:x?99999:50,pageIndex:0})},[x]);const g=(O,q)=>{x&&(O.dataTransfer.setData("text/plain",q.toString()),O.currentTarget.classList.add("opacity-50"))},S=(O,q)=>{if(!x)return;O.preventDefault(),O.currentTarget.classList.remove("bg-muted");const te=parseInt(O.dataTransfer.getData("text/plain"));if(te===q)return;const F=[...f],[se]=F.splice(te,1);F.splice(q,0,se),j(F)},R=async()=>{if(!x){i(!0);return}nn.sort(f.map(O=>O.id)).then(()=>{$.success("排序保存成功"),i(!1),w()}).finally(()=>{i(!1)})},E=Ze({data:f??[],columns:ku(w),state:{sorting:o,columnVisibility:a,rowSelection:s,columnFilters:r,columnSizing:d,pagination:C},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:c,onColumnVisibilityChange:l,onColumnSizingChange:p,onPaginationChange:P,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),getSortedRowModel:is(),getFacetedRowModel:_s(),getFacetedUniqueValues:ws(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(cs,{table:E,toolbar:O=>e.jsx(Su,{table:O,refetch:w,saveOrder:R,isSortMode:x}),draggable:x,onDragStart:g,onDragEnd:O=>O.currentTarget.classList.remove("opacity-50"),onDragOver:O=>{O.preventDefault(),O.currentTarget.classList.add("bg-muted")},onDragLeave:O=>O.currentTarget.classList.remove("bg-muted"),onDrop:S,showPagination:!x})})}function Du(){const{t:s}=M("notice");return e.jsxs(Pe,{children:[e.jsxs(Ee,{className:"flex items-center justify-between",children:[e.jsx($e,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Tu,{})})]})]})}const Pu=Object.freeze(Object.defineProperty({__proto__:null,default:Du},Symbol.toStringTag,{value:"Module"})),Eu=h.object({id:h.number().nullable(),language:h.string().max(250),category:h.string().max(250),title:h.string().min(1).max(250),body:h.string().min(1),show:h.boolean()}),Ru={id:null,language:"zh-CN",category:"",title:"",body:"",show:!1};function Wr({refreshData:s,dialogTrigger:n,type:a="add",defaultFormValues:l=Ru}){const{t:r}=M("knowledge"),[c,o]=u.useState(!1),m=je({resolver:Ne(Eu),defaultValues:l,mode:"onChange",shouldFocusError:!0}),x=new Da({html:!0});return u.useEffect(()=>{c&&l.id&&bd(l.id).then(({data:i})=>{m.reset(i)})},[l.id,m,c]),e.jsxs(be,{onOpenChange:o,open:c,children:[e.jsx(Ge,{asChild:!0,children:n||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Re,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add")})]})}),e.jsxs(ge,{className:"sm:max-w-[1025px]",children:[e.jsxs(we,{children:[e.jsx(ye,{children:r(a==="add"?"form.add":"form.edit")}),e.jsx(De,{})]}),e.jsxs(_e,{...m,children:[e.jsx(b,{control:m.control,name:"title",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.title")}),e.jsx("div",{className:"relative ",children:e.jsx(_,{children:e.jsx(k,{placeholder:r("form.titlePlaceholder"),...i})})}),e.jsx(T,{})]})}),e.jsx(b,{control:m.control,name:"category",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.category")}),e.jsx("div",{className:"relative ",children:e.jsx(_,{children:e.jsx(k,{placeholder:r("form.categoryPlaceholder"),...i})})}),e.jsx(T,{})]})}),e.jsx(b,{control:m.control,name:"language",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.language")}),e.jsx(_,{children:e.jsxs(X,{value:i.value,onValueChange:i.onChange,children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:r("form.languagePlaceholder")})}),e.jsx(J,{children:[{value:"en-US"},{value:"ja-JP"},{value:"ko-KR"},{value:"vi-VN"},{value:"zh-CN"},{value:"zh-TW"}].map(d=>e.jsx(U,{value:d.value,className:"cursor-pointer",children:r(`languages.${d.value}`)},d.value))})]})})]})}),e.jsx(b,{control:m.control,name:"body",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.content")}),e.jsx(_,{children:e.jsx(Pa,{style:{height:"500px"},value:i.value,renderHTML:d=>x.render(d),onChange:({text:d})=>{i.onChange(d)}})}),e.jsx(T,{})]})}),e.jsx(b,{control:m.control,name:"show",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.show")}),e.jsx("div",{className:"relative py-2",children:e.jsx(_,{children:e.jsx(W,{checked:i.value,onCheckedChange:i.onChange})})}),e.jsx(T,{})]})}),e.jsxs(Ae,{children:[e.jsx(jt,{asChild:!0,children:e.jsx(D,{type:"button",variant:"outline",children:r("form.cancel")})}),e.jsx(D,{type:"submit",onClick:()=>{m.handleSubmit(i=>{yd(i).then(({data:d})=>{d&&(m.reset(),$.success(r("messages.operationSuccess")),o(!1),s())})})()},children:r("form.submit")})]})]})]})]})}function Iu({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(xs,{children:[e.jsx(hs,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(gt,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Se,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(c=>r.has(c.value)).map(c=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:c.label},c.value))})]})]})}),e.jsx(os,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Is,{children:[e.jsx($s,{placeholder:n}),e.jsxs(Vs,{children:[e.jsx(qs,{children:"No results found."}),e.jsx(Ke,{children:a.map(c=>{const o=r.has(c.value);return e.jsxs(Ie,{onSelect:()=>{o?r.delete(c.value):r.add(c.value);const m=Array.from(r);s?.setFilterValue(m.length?m:void 0)},children:[e.jsx("div",{className:N("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(zs,{className:N("h-4 w-4")})}),c.icon&&e.jsx(c.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:c.label}),l?.get(c.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(c.value)})]},c.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(st,{}),e.jsx(Ke,{children:e.jsx(Ie,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function Vu({table:s,refetch:n,saveOrder:a,isSortMode:l}){const r=s.getState().columnFilters.length>0,{t:c}=M("knowledge");return e.jsxs("div",{className:"flex items-center justify-between",children:[l?e.jsx("p",{className:"text-sm text-muted-foreground",children:c("toolbar.sortModeHint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Wr,{refreshData:n}),e.jsx(k,{placeholder:c("toolbar.searchPlaceholder"),value:s.getColumn("title")?.getFilterValue()??"",onChange:o=>s.getColumn("title")?.setFilterValue(o.target.value),className:"h-8 w-[250px]"}),s.getColumn("category")&&e.jsx(Iu,{column:s.getColumn("category"),title:c("columns.category"),options:Array.from(new Set(s.getCoreRowModel().rows.map(o=>o.getValue("category")))).map(o=>({label:o,value:o}))}),r&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[c("toolbar.reset"),e.jsx(Ye,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(D,{variant:l?"default":"outline",onClick:a,size:"sm",children:c(l?"toolbar.saveSort":"toolbar.editSort")})})]})}const Ou=({refetch:s,isSortMode:n=!1})=>{const{t:a}=M("knowledge");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(Ut,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.id")}),cell:({row:l})=>e.jsx(K,{variant:"outline",className:"justify-center",children:l.getValue("id")}),enableSorting:!0,size:70},{accessorKey:"show",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.status")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center",children:e.jsx(W,{defaultChecked:l.getValue("show"),onCheckedChange:async()=>{_d({id:l.original.id}).then(({data:r})=>{r||s()})}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.title")}),cell:({row:l})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"line-clamp-2 font-medium",children:l.getValue("title")})}),enableSorting:!0,size:600},{accessorKey:"category",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.category")}),cell:({row:l})=>e.jsx(K,{variant:"secondary",className:"max-w-[180px] truncate",children:l.getValue("category")}),enableSorting:!0,size:1800},{id:"actions",header:({column:l})=>e.jsx(L,{className:"justify-end",column:l,title:a("columns.actions")}),cell:({row:l})=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx(Wr,{refreshData:s,dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(As,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("form.edit")})]}),type:"edit",defaultFormValues:l.original}),e.jsx(Be,{title:a("messages.deleteConfirm"),description:a("messages.deleteDescription"),confirmText:a("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Nd({id:l.original.id}).then(({data:r})=>{r&&($.success(a("messages.operationSuccess")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ns,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("messages.deleteButton")})]})})]}),size:100}]};function Mu(){const[s,n]=u.useState([]),[a,l]=u.useState([]),[r,c]=u.useState(!1),[o,m]=u.useState([]),[x,i]=u.useState({"drag-handle":!1}),[d,p]=u.useState({pageSize:20,pageIndex:0}),{refetch:C,isLoading:P,data:f}=ie({queryKey:["knowledge"],queryFn:async()=>{const{data:R}=await vd();return m(R||[]),R}});u.useEffect(()=>{i({"drag-handle":r,actions:!r}),p({pageSize:r?99999:10,pageIndex:0})},[r]);const j=(R,E)=>{r&&(R.dataTransfer.setData("text/plain",E.toString()),R.currentTarget.classList.add("opacity-50"))},w=(R,E)=>{if(!r)return;R.preventDefault(),R.currentTarget.classList.remove("bg-muted");const O=parseInt(R.dataTransfer.getData("text/plain"));if(O===E)return;const q=[...o],[te]=q.splice(O,1);q.splice(E,0,te),m(q)},g=async()=>{r?wd({ids:o.map(R=>R.id)}).then(()=>{C(),c(!1),$.success("排序保存成功")}):c(!0)},S=Ze({data:o,columns:Ou({refetch:C,isSortMode:r}),state:{sorting:a,columnFilters:s,columnVisibility:x,pagination:d},onSortingChange:l,onColumnFiltersChange:n,onColumnVisibilityChange:i,onPaginationChange:p,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),getSortedRowModel:is(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(cs,{table:S,toolbar:R=>e.jsx(Vu,{table:R,refetch:C,saveOrder:g,isSortMode:r}),draggable:r,onDragStart:j,onDragEnd:R=>R.currentTarget.classList.remove("opacity-50"),onDragOver:R=>{R.preventDefault(),R.currentTarget.classList.add("bg-muted")},onDragLeave:R=>R.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!r})}function Fu(){const{t:s}=M("knowledge");return e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx($e,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight mb-2",children:s("title")}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Mu,{})})]})]})}const zu=Object.freeze(Object.defineProperty({__proto__:null,default:Fu},Symbol.toStringTag,{value:"Module"}));function Lu(s,n){const[a,l]=u.useState(s);return u.useEffect(()=>{const r=setTimeout(()=>l(s),n);return()=>{clearTimeout(r)}},[s,n]),a}function oa(s,n){if(s.length===0)return{};if(!n)return{"":s};const a={};return s.forEach(l=>{const r=l[n]||"";a[r]||(a[r]=[]),a[r].push(l)}),a}function Au(s,n){const a=JSON.parse(JSON.stringify(s));for(const[l,r]of Object.entries(a))a[l]=r.filter(c=>!n.find(o=>o.value===c.value));return a}function $u(s,n){for(const[,a]of Object.entries(s))if(a.some(l=>n.find(r=>r.value===l.value)))return!0;return!1}const Yr=u.forwardRef(({className:s,...n},a)=>Vo(r=>r.filtered.count===0)?e.jsx("div",{ref:a,className:N("py-6 text-center text-sm",s),"cmdk-empty":"",role:"presentation",...n}):null);Yr.displayName="CommandEmpty";const ht=u.forwardRef(({value:s,onChange:n,placeholder:a,defaultOptions:l=[],options:r,delay:c,onSearch:o,loadingIndicator:m,emptyIndicator:x,maxSelected:i=Number.MAX_SAFE_INTEGER,onMaxSelected:d,hidePlaceholderWhenSelected:p,disabled:C,groupBy:P,className:f,badgeClassName:j,selectFirstItem:w=!0,creatable:g=!1,triggerSearchOnFocus:S=!1,commandProps:R,inputProps:E,hideClearAllButton:O=!1},q)=>{const te=u.useRef(null),[F,se]=u.useState(!1),qe=u.useRef(!1),[B,ae]=u.useState(!1),[A,I]=u.useState(s||[]),[Y,ne]=u.useState(oa(l,P)),[We,tt]=u.useState(""),at=Lu(We,c||500);u.useImperativeHandle(q,()=>({selectedValue:[...A],input:te.current,focus:()=>te.current?.focus()}),[A]);const bt=u.useCallback(Z=>{const de=A.filter(Le=>Le.value!==Z.value);I(de),n?.(de)},[n,A]),vl=u.useCallback(Z=>{const de=te.current;de&&((Z.key==="Delete"||Z.key==="Backspace")&&de.value===""&&A.length>0&&(A[A.length-1].fixed||bt(A[A.length-1])),Z.key==="Escape"&&de.blur())},[bt,A]);u.useEffect(()=>{s&&I(s)},[s]),u.useEffect(()=>{if(!r||o)return;const Z=oa(r||[],P);JSON.stringify(Z)!==JSON.stringify(Y)&&ne(Z)},[l,r,P,o,Y]),u.useEffect(()=>{const Z=async()=>{ae(!0);const Le=await o?.(at);ne(oa(Le||[],P)),ae(!1)};(async()=>{!o||!F||(S&&await Z(),at&&await Z())})()},[at,P,F,S]);const bl=()=>{if(!g||$u(Y,[{value:We,label:We}])||A.find(de=>de.value===We))return;const Z=e.jsx(Ie,{value:We,className:"cursor-pointer",onMouseDown:de=>{de.preventDefault(),de.stopPropagation()},onSelect:de=>{if(A.length>=i){d?.(A.length);return}tt("");const Le=[...A,{value:de,label:de}];I(Le),n?.(Le)},children:`Create "${We}"`});if(!o&&We.length>0||o&&at.length>0&&!B)return Z},yl=u.useCallback(()=>{if(x)return o&&!g&&Object.keys(Y).length===0?e.jsx(Ie,{value:"-",disabled:!0,children:x}):e.jsx(Yr,{children:x})},[g,x,o,Y]),Nl=u.useMemo(()=>Au(Y,A),[Y,A]),_l=u.useCallback(()=>{if(R?.filter)return R.filter;if(g)return(Z,de)=>Z.toLowerCase().includes(de.toLowerCase())?1:-1},[g,R?.filter]),wl=u.useCallback(()=>{const Z=A.filter(de=>de.fixed);I(Z),n?.(Z)},[n,A]);return e.jsxs(Is,{...R,onKeyDown:Z=>{vl(Z),R?.onKeyDown?.(Z)},className:N("h-auto overflow-visible bg-transparent",R?.className),shouldFilter:R?.shouldFilter!==void 0?R.shouldFilter:!o,filter:_l(),children:[e.jsx("div",{className:N("rounded-md border border-input text-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring ",{"px-3 py-2":A.length!==0,"cursor-text":!C&&A.length!==0},f),onClick:()=>{C||te.current?.focus()},children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[A.map(Z=>e.jsxs(K,{className:N("data-[disabled]:bg-muted-foreground data-[disabled]:text-muted data-[disabled]:hover:bg-muted-foreground","data-[fixed]:bg-muted-foreground data-[fixed]:text-muted data-[fixed]:hover:bg-muted-foreground",j),"data-fixed":Z.fixed,"data-disabled":C||void 0,children:[Z.label,e.jsx("button",{className:N("ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",(C||Z.fixed)&&"hidden"),onKeyDown:de=>{de.key==="Enter"&&bt(Z)},onMouseDown:de=>{de.preventDefault(),de.stopPropagation()},onClick:()=>bt(Z),children:e.jsx(pa,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},Z.value)),e.jsx(Me.Input,{...E,ref:te,value:We,disabled:C,onValueChange:Z=>{tt(Z),E?.onValueChange?.(Z)},onBlur:Z=>{qe.current===!1&&se(!1),E?.onBlur?.(Z)},onFocus:Z=>{se(!0),S&&o?.(at),E?.onFocus?.(Z)},placeholder:p&&A.length!==0?"":a,className:N("flex-1 bg-transparent outline-none placeholder:text-muted-foreground",{"w-full":p,"px-3 py-2":A.length===0,"ml-1":A.length!==0},E?.className)}),e.jsx("button",{type:"button",onClick:wl,className:N((O||C||A.length<1||A.filter(Z=>Z.fixed).length===A.length)&&"hidden"),children:e.jsx(pa,{})})]})}),e.jsx("div",{className:"relative",children:F&&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:()=>{qe.current=!1},onMouseEnter:()=>{qe.current=!0},onMouseUp:()=>{te.current?.focus()},children:B?e.jsx(e.Fragment,{children:m}):e.jsxs(e.Fragment,{children:[yl(),bl(),!w&&e.jsx(Ie,{value:"-",className:"hidden"}),Object.entries(Nl).map(([Z,de])=>e.jsx(Ke,{heading:Z,className:"h-full overflow-auto",children:e.jsx(e.Fragment,{children:de.map(Le=>e.jsx(Ie,{value:Le.value,disabled:Le.disable,onMouseDown:nt=>{nt.preventDefault(),nt.stopPropagation()},onSelect:()=>{if(A.length>=i){d?.(A.length);return}tt("");const nt=[...A,Le];I(nt),n?.(nt)},className:N("cursor-pointer",Le.disable&&"cursor-default text-muted-foreground"),children:Le.label},Le.value))})},Z))]})})})]})});ht.displayName="MultipleSelector";const qu=s=>h.object({id:h.number().optional(),name:h.string().min(2,s("messages.nameValidation.min")).max(50,s("messages.nameValidation.max")).regex(/^[a-zA-Z0-9\u4e00-\u9fa5_-]+$/,s("messages.nameValidation.pattern"))});function sa({refetch:s,dialogTrigger:n,defaultValues:a={name:""},type:l="add"}){const{t:r}=M("group"),c=je({resolver:Ne(qu(r)),defaultValues:a,mode:"onChange"}),[o,m]=u.useState(!1),[x,i]=u.useState(!1),d=async p=>{i(!0),rd(p).then(()=>{$.success(r(l==="edit"?"messages.updateSuccess":"messages.createSuccess")),s&&s(),c.reset(),m(!1)}).finally(()=>{i(!1)})};return e.jsxs(be,{open:o,onOpenChange:m,children:[e.jsx(Ge,{asChild:!0,children:n||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Re,{icon:"ion:add"}),e.jsx("span",{children:r("form.add")})]})}),e.jsxs(ge,{className:"sm:max-w-[425px]",children:[e.jsxs(we,{children:[e.jsx(ye,{children:r(l==="edit"?"form.edit":"form.create")}),e.jsx(De,{children:r(l==="edit"?"form.editDescription":"form.createDescription")})]}),e.jsx(_e,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(d),className:"space-y-4",children:[e.jsx(b,{control:c.control,name:"name",render:({field:p})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.name")}),e.jsx(_,{children:e.jsx(k,{placeholder:r("form.namePlaceholder"),...p,className:"w-full"})}),e.jsx(z,{children:r("form.nameDescription")}),e.jsx(T,{})]})}),e.jsxs(Ae,{className:"gap-2",children:[e.jsx(jt,{asChild:!0,children:e.jsx(D,{type:"button",variant:"outline",children:r("form.cancel")})}),e.jsxs(D,{type:"submit",disabled:x||!c.formState.isValid,children:[x&&e.jsx(Ta,{className:"mr-2 h-4 w-4 animate-spin"}),r(l==="edit"?"form.update":"form.create")]})]})]})})]})]})}const Qr=u.createContext(void 0);function Uu({children:s,refetch:n}){const[a,l]=u.useState(!1),[r,c]=u.useState(null),[o,m]=u.useState(ke.Shadowsocks);return e.jsx(Qr.Provider,{value:{isOpen:a,setIsOpen:l,editingServer:r,setEditingServer:c,serverType:o,setServerType:m,refetch:n},children:s})}function Jr(){const s=u.useContext(Qr);if(s===void 0)throw new Error("useServerEdit must be used within a ServerEditProvider");return s}function ca({dialogTrigger:s,value:n,setValue:a,templateType:l}){const{t:r}=M("server");u.useEffect(()=>{console.log(n)},[n]);const[c,o]=u.useState(!1),[m,x]=u.useState(()=>{if(!n||Object.keys(n).length===0)return"";try{return JSON.stringify(n,null,2)}catch{return""}}),[i,d]=u.useState(null),p=g=>{if(!g)return null;try{const S=JSON.parse(g);return typeof S!="object"||S===null?r("network_settings.validation.must_be_object"):null}catch{return r("network_settings.validation.invalid_json")}},C={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"}}}},P=()=>{switch(l){case"tcp":return["tcp","tcp-http"];case"grpc":return["grpc"];case"ws":return["ws"];default:return[]}},f=()=>{const g=p(m||"");if(g){$.error(g);return}try{if(!m){a(null),o(!1);return}a(JSON.parse(m)),o(!1)}catch{$.error(r("network_settings.errors.save_failed"))}},j=g=>{x(g),d(p(g))},w=g=>{const S=C[g];if(S){const R=JSON.stringify(S.content,null,2);x(R),d(null)}};return u.useEffect(()=>{c&&console.log(n)},[c,n]),u.useEffect(()=>{c&&n&&Object.keys(n).length>0&&x(JSON.stringify(n,null,2))},[c,n]),e.jsxs(be,{open:c,onOpenChange:g=>{!g&&c&&f(),o(g)},children:[e.jsx(Ge,{asChild:!0,children:s??e.jsx(G,{variant:"link",children:r("network_settings.edit_protocol")})}),e.jsxs(ge,{className:"sm:max-w-[425px]",children:[e.jsx(we,{children:e.jsx(ye,{children:r("network_settings.edit_protocol_config")})}),e.jsxs("div",{className:"space-y-4",children:[P().length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:P().map(g=>e.jsx(G,{variant:"outline",size:"sm",onClick:()=>w(g),children:r("network_settings.use_template",{template:C[g].label})},g))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(fs,{className:`min-h-[200px] font-mono text-sm ${i?"border-red-500 focus-visible:ring-red-500":""}`,value:m,placeholder:P().length>0?r("network_settings.json_config_placeholder_with_template"):r("network_settings.json_config_placeholder"),onChange:g=>j(g.target.value)}),i&&e.jsx("p",{className:"text-sm text-red-500",children:i})]})]}),e.jsxs(Ae,{className:"gap-2",children:[e.jsx(G,{variant:"outline",onClick:()=>o(!1),children:r("common.cancel")}),e.jsx(G,{onClick:f,disabled:!!i,children:r("common.confirm")})]})]})]})}function ef(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 Hu={},Ku=Object.freeze(Object.defineProperty({__proto__:null,default:Hu},Symbol.toStringTag,{value:"Module"})),sf=Wo(Ku),cn=s=>s.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),Bu=()=>{try{const s=Oo.box.keyPair(),n=cn(Qa.encodeBase64(s.secretKey)),a=cn(Qa.encodeBase64(s.publicKey));return{privateKey:n,publicKey:a}}catch(s){throw console.error("Error generating x25519 key pair:",s),s}},Gu=()=>{try{return Bu()}catch(s){throw console.error("Error generating key pair:",s),s}},Wu=s=>{const n=new Uint8Array(Math.ceil(s/2));return window.crypto.getRandomValues(n),Array.from(n).map(a=>a.toString(16).padStart(2,"0")).join("").substring(0,s)},Yu=()=>{const s=Math.floor(Math.random()*8)*2+2;return Wu(s)},Qu=h.object({cipher:h.string().default("aes-128-gcm"),obfs:h.string().default("0"),obfs_settings:h.object({path:h.string().default(""),host:h.string().default("")}).default({})}),Ju=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({})}),Zu=h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({})}),Xu=h.object({version:h.coerce.number().default(2),alpn:h.string().default("h2"),obfs:h.object({open:h.coerce.boolean().default(!1),type:h.string().default("salamander"),password:h.string().default("")}).default({}),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),bandwidth:h.object({up:h.string().default(""),down:h.string().default("")}).default({})}),ex=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),reality_settings:h.object({server_port:h.coerce.number().default(443),server_name:h.string().default(""),allow_insecure:h.boolean().default(!1),public_key:h.string().default(""),private_key:h.string().default(""),short_id:h.string().default("")}).default({}),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({}),flow:h.string().default("")}),ps={shadowsocks:{schema:Qu,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:Ju,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},trojan:{schema:Zu,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},hysteria:{schema:Xu,versions:["1","2"],alpnOptions:["hysteria","http/1.1","h2","h3"]},vless:{schema:ex,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"]}},sx=({serverType:s,value:n,onChange:a})=>{const{t:l}=M("server"),r=s?ps[s]:null,c=r?.schema||h.record(h.any()),o=s?c.parse({}):{},m=je({resolver:Ne(c),defaultValues:o,mode:"onChange"});if(u.useEffect(()=>{if(!n||Object.keys(n).length===0){if(s){const f=c.parse({});m.reset(f)}}else m.reset(n)},[s,n,a,m,c]),u.useEffect(()=>{const f=m.watch(j=>{a(j)});return()=>f.unsubscribe()},[m,a]),!s||!r)return null;const P={shadowsocks:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:m.control,name:"cipher",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.shadowsocks.cipher.label")}),e.jsx(_,{children:e.jsxs(X,{onValueChange:f.onChange,value:f.value,children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.shadowsocks.cipher.placeholder")})}),e.jsx(J,{children:e.jsx(ks,{children:ps.shadowsocks.ciphers.map(j=>e.jsx(U,{value:j,children:j},j))})})]})})]})}),e.jsx(b,{control:m.control,name:"obfs",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.shadowsocks.obfs.label")}),e.jsx(_,{children:e.jsxs(X,{onValueChange:f.onChange,value:f.value,children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.shadowsocks.obfs.placeholder")})}),e.jsx(J,{children:e.jsxs(ks,{children:[e.jsx(U,{value:"0",children:l("dynamic_form.shadowsocks.obfs.none")}),e.jsx(U,{value:"http",children:l("dynamic_form.shadowsocks.obfs.http")})]})})]})})]})}),m.watch("obfs")==="http"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:m.control,name:"obfs_settings.path",render:({field:f})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(_,{children:e.jsx(k,{type:"text",placeholder:l("dynamic_form.shadowsocks.obfs_settings.path"),...f})}),e.jsx(T,{})]})}),e.jsx(b,{control:m.control,name:"obfs_settings.host",render:({field:f})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(_,{children:e.jsx(k,{type:"text",placeholder:l("dynamic_form.shadowsocks.obfs_settings.host"),...f})}),e.jsx(T,{})]})})]})]}),vmess:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:m.control,name:"tls",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.vmess.tls.label")}),e.jsx(_,{children:e.jsxs(X,{value:f.value?.toString(),onValueChange:j=>f.onChange(Number(j)),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.vmess.tls.placeholder")})}),e.jsxs(J,{children:[e.jsx(U,{value:"0",children:l("dynamic_form.vmess.tls.disabled")}),e.jsx(U,{value:"1",children:l("dynamic_form.vmess.tls.enabled")})]})]})})]})}),m.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:m.control,name:"tls_settings.server_name",render:({field:f})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(y,{children:l("dynamic_form.vmess.tls_settings.server_name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:l("dynamic_form.vmess.tls_settings.server_name.placeholder"),...f})})]})}),e.jsx(b,{control:m.control,name:"tls_settings.allow_insecure",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.vmess.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(_,{children:e.jsx(W,{checked:f.value,onCheckedChange:f.onChange})})})]})})]}),e.jsx(b,{control:m.control,name:"network",render:({field:f})=>e.jsxs(v,{children:[e.jsxs(y,{children:[l("dynamic_form.vmess.network.label"),e.jsx(ca,{value:m.watch("network_settings"),setValue:j=>m.setValue("network_settings",j),templateType:m.watch("network")})]}),e.jsx(_,{children:e.jsxs(X,{onValueChange:f.onChange,value:f.value,children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.vmess.network.placeholder")})}),e.jsx(J,{children:e.jsx(ks,{children:ps.vmess.networkOptions.map(j=>e.jsx(U,{value:j.value,className:"cursor-pointer",children:j.label},j.value))})})]})})]})})]}),trojan:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:m.control,name:"server_name",render:({field:f})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(y,{children:l("dynamic_form.trojan.server_name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:l("dynamic_form.trojan.server_name.placeholder"),...f,value:f.value||""})})]})}),e.jsx(b,{control:m.control,name:"allow_insecure",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.trojan.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(_,{children:e.jsx(W,{checked:f.value||!1,onCheckedChange:f.onChange})})})]})})]}),e.jsx(b,{control:m.control,name:"network",render:({field:f})=>e.jsxs(v,{children:[e.jsxs(y,{children:[l("dynamic_form.trojan.network.label"),e.jsx(ca,{value:m.watch("network_settings")||{},setValue:j=>m.setValue("network_settings",j),templateType:m.watch("network")||"tcp"})]}),e.jsx(_,{children:e.jsxs(X,{onValueChange:f.onChange,value:f.value||"tcp",children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.trojan.network.placeholder")})}),e.jsx(J,{children:e.jsx(ks,{children:ps.trojan.networkOptions.map(j=>e.jsx(U,{value:j.value,className:"cursor-pointer",children:j.label},j.value))})})]})})]})})]}),hysteria:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:m.control,name:"version",render:({field:f})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(y,{children:l("dynamic_form.hysteria.version.label")}),e.jsx(_,{children:e.jsxs(X,{value:(f.value||2).toString(),onValueChange:j=>f.onChange(Number(j)),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.hysteria.version.placeholder")})}),e.jsx(J,{children:e.jsx(ks,{children:ps.hysteria.versions.map(j=>e.jsxs(U,{value:j,className:"cursor-pointer",children:["V",j]},j))})})]})})]})}),m.watch("version")==1&&e.jsx(b,{control:m.control,name:"alpn",render:({field:f})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(y,{children:l("dynamic_form.hysteria.alpn.label")}),e.jsx(_,{children:e.jsxs(X,{value:f.value||"h2",onValueChange:f.onChange,children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.hysteria.alpn.placeholder")})}),e.jsx(J,{children:e.jsx(ks,{children:ps.hysteria.alpnOptions.map(j=>e.jsx(U,{value:j,children:j},j))})})]})})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:m.control,name:"obfs.open",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.hysteria.obfs.label")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(_,{children:e.jsx(W,{checked:f.value||!1,onCheckedChange:f.onChange})})})]})}),!!m.watch("obfs.open")&&e.jsxs(e.Fragment,{children:[m.watch("version")=="2"&&e.jsx(b,{control:m.control,name:"obfs.type",render:({field:f})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(y,{children:l("dynamic_form.hysteria.obfs.type.label")}),e.jsx(_,{children:e.jsxs(X,{value:f.value||"salamander",onValueChange:f.onChange,children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.hysteria.obfs.type.placeholder")})}),e.jsx(J,{children:e.jsx(ks,{children:e.jsx(U,{value:"salamander",children:l("dynamic_form.hysteria.obfs.type.salamander")})})})]})})]})}),e.jsx(b,{control:m.control,name:"obfs.password",render:({field:f})=>e.jsxs(v,{className:m.watch("version")==2?"w-full":"flex-[2]",children:[e.jsx(y,{children:l("dynamic_form.hysteria.obfs.password.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(_,{children:e.jsx(k,{placeholder:l("dynamic_form.hysteria.obfs.password.placeholder"),...f,value:f.value||"",className:"pr-9"})}),e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",w=Array.from(crypto.getRandomValues(new Uint8Array(16))).map(g=>j[g%j.length]).join("");m.setValue("obfs.password",w),$.success(l("dynamic_form.hysteria.obfs.password.generate_success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Re,{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(b,{control:m.control,name:"tls.server_name",render:({field:f})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(y,{children:l("dynamic_form.hysteria.tls.server_name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:l("dynamic_form.hysteria.tls.server_name.placeholder"),...f,value:f.value||""})})]})}),e.jsx(b,{control:m.control,name:"tls.allow_insecure",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.hysteria.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(_,{children:e.jsx(W,{checked:f.value||!1,onCheckedChange:f.onChange})})})]})})]}),e.jsx(b,{control:m.control,name:"bandwidth.up",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.hysteria.bandwidth.up.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:l("dynamic_form.hysteria.bandwidth.up.placeholder")+(m.watch("version")==2?l("dynamic_form.hysteria.bandwidth.up.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...f,value:f.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:l("dynamic_form.hysteria.bandwidth.up.suffix")})})]})]})}),e.jsx(b,{control:m.control,name:"bandwidth.down",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.hysteria.bandwidth.down.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:l("dynamic_form.hysteria.bandwidth.down.placeholder")+(m.watch("version")==2?l("dynamic_form.hysteria.bandwidth.down.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...f,value:f.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:l("dynamic_form.hysteria.bandwidth.down.suffix")})})]})]})})]}),vless:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:m.control,name:"tls",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.vless.tls.label")}),e.jsx(_,{children:e.jsxs(X,{value:f.value?.toString(),onValueChange:j=>f.onChange(Number(j)),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.vless.tls.placeholder")})}),e.jsxs(J,{children:[e.jsx(U,{value:"0",children:l("dynamic_form.vless.tls.none")}),e.jsx(U,{value:"1",children:l("dynamic_form.vless.tls.tls")}),e.jsx(U,{value:"2",children:l("dynamic_form.vless.tls.reality")})]})]})})]})}),m.watch("tls")=="1"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:m.control,name:"tls_settings.server_name",render:({field:f})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(y,{children:l("dynamic_form.vless.tls_settings.server_name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:l("dynamic_form.vless.tls_settings.server_name.placeholder"),...f})})]})}),e.jsx(b,{control:m.control,name:"tls_settings.allow_insecure",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.vless.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(_,{children:e.jsx(W,{checked:f.value,onCheckedChange:f.onChange})})})]})})]}),m.watch("tls")==2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:m.control,name:"reality_settings.server_name",render:({field:f})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(y,{children:l("dynamic_form.vless.reality_settings.server_name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:l("dynamic_form.vless.reality_settings.server_name.placeholder"),...f})})]})}),e.jsx(b,{control:m.control,name:"reality_settings.server_port",render:({field:f})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(y,{children:l("dynamic_form.vless.reality_settings.server_port.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:l("dynamic_form.vless.reality_settings.server_port.placeholder"),...f})})]})}),e.jsx(b,{control:m.control,name:"reality_settings.allow_insecure",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.vless.reality_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(_,{children:e.jsx(W,{checked:f.value,onCheckedChange:f.onChange})})})]})})]}),e.jsx("div",{className:"flex items-end gap-2",children:e.jsx(b,{control:m.control,name:"reality_settings.private_key",render:({field:f})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(y,{children:l("dynamic_form.vless.reality_settings.private_key.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(_,{children:e.jsx(k,{...f,className:"pr-9"})}),e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{try{const j=Gu();m.setValue("reality_settings.private_key",j.privateKey),m.setValue("reality_settings.public_key",j.publicKey),$.success(l("dynamic_form.vless.reality_settings.key_pair.success"))}catch{$.error(l("dynamic_form.vless.reality_settings.key_pair.error"))}},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Re,{icon:"ion:key-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(It,{children:e.jsx(ce,{children:e.jsx("p",{children:l("dynamic_form.vless.reality_settings.key_pair.generate")})})})]})]})]})})}),e.jsx(b,{control:m.control,name:"reality_settings.public_key",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.vless.reality_settings.public_key.label")}),e.jsx(_,{children:e.jsx(k,{...f})})]})}),e.jsx(b,{control:m.control,name:"reality_settings.short_id",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.vless.reality_settings.short_id.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(_,{children:e.jsx(k,{...f,className:"pr-9",placeholder:l("dynamic_form.vless.reality_settings.short_id.placeholder")})}),e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const j=Yu();m.setValue("reality_settings.short_id",j),$.success(l("dynamic_form.vless.reality_settings.short_id.success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Re,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(It,{children:e.jsx(ce,{children:e.jsx("p",{children:l("dynamic_form.vless.reality_settings.short_id.generate")})})})]})]}),e.jsx(z,{className:"text-xs text-muted-foreground",children:l("dynamic_form.vless.reality_settings.short_id.description")})]})})]}),e.jsx(b,{control:m.control,name:"network",render:({field:f})=>e.jsxs(v,{children:[e.jsxs(y,{children:[l("dynamic_form.vless.network.label"),e.jsx(ca,{value:m.watch("network_settings"),setValue:j=>m.setValue("network_settings",j),templateType:m.watch("network")})]}),e.jsx(_,{children:e.jsxs(X,{onValueChange:f.onChange,value:f.value,children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.vless.network.placeholder")})}),e.jsx(J,{children:e.jsx(ks,{children:ps.vless.networkOptions.map(j=>e.jsx(U,{value:j.value,className:"cursor-pointer",children:j.label},j.value))})})]})})]})}),e.jsx(b,{control:m.control,name:"flow",render:({field:f})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dynamic_form.vless.flow.label")}),e.jsx(_,{children:e.jsxs(X,{onValueChange:j=>f.onChange(j==="none"?null:j),value:f.value||"none",children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dynamic_form.vless.flow.placeholder")})}),e.jsx(J,{children:ps.vless.flowOptions.map(j=>e.jsx(U,{value:j,children:j},j))})]})})]})})]})};return e.jsx(pe,{children:P[s]?.()})},tx=h.object({id:h.number().optional().nullable(),code:h.string().optional(),name:h.string().min(1,"form.name.error"),rate:h.string().min(1,"form.rate.error"),tags:h.array(h.string()).default([]),excludes:h.array(h.string()).default([]),ips:h.array(h.string()).default([]),group_ids:h.array(h.string()).default([]),host:h.string().min(1,"form.host.error"),port:h.string().min(1,"form.port.error"),server_port:h.string().min(1,"form.server_port.error"),parent_id:h.string().default("0").nullable(),route_ids:h.array(h.string()).default([]),protocol_settings:h.record(h.any()).default({}).nullable()}),_t={id:null,code:"",name:"",rate:"1",tags:[],excludes:[],ips:[],group_ids:[],host:"",port:"",server_port:"",parent_id:"0",route_ids:[],protocol_settings:null};function ax(){const{t:s}=M("server"),{isOpen:n,setIsOpen:a,editingServer:l,setEditingServer:r,serverType:c,setServerType:o,refetch:m}=Jr(),[x,i]=u.useState([]),[d,p]=u.useState([]),[C,P]=u.useState([]),f=je({resolver:Ne(tx),defaultValues:_t,mode:"onChange"});u.useEffect(()=>{j()},[n]),u.useEffect(()=>{l?.type&&l.type!==c&&o(l.type)},[l,c,o]),u.useEffect(()=>{l?l.type===c&&f.reset({..._t,...l}):f.reset({..._t,protocol_settings:ps[c].schema.parse({})})},[l,f,c]);const j=async()=>{if(!n)return;const[E,O,q]=await Promise.all([vt(),Lr(),zr()]);i(E.data?.map(te=>({label:te.name,value:te.id.toString()}))||[]),p(O.data?.map(te=>({label:te.remarks,value:te.id.toString()}))||[]),P(q.data||[])},w=u.useMemo(()=>C?.filter(E=>(E.parent_id===0||E.parent_id===null)&&E.type===c&&E.id!==f.watch("id")),[c,C,f]),g=()=>e.jsxs(bs,{children:[e.jsx(ys,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Re,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(us,{align:"start",children:e.jsx(Tc,{children:Ms.map(({type:E,label:O})=>e.jsx(fe,{onClick:()=>{o(E),a(!0)},className:"cursor-pointer",children:e.jsx(K,{variant:"outline",className:"text-white",style:{background:js[E]},children:O})},E))})})]}),S=()=>{a(!1),r(null),f.reset(_t)},R=async()=>{const E=f.getValues();(await ed({...E,type:c})).data&&(S(),$.success(s("form.success")),m())};return e.jsxs(be,{open:n,onOpenChange:S,children:[g(),e.jsxs(ge,{className:"sm:max-w-[425px]",children:[e.jsxs(we,{children:[e.jsx(ye,{children:s(l?"form.edit_node":"form.new_node")}),e.jsx(De,{})]}),e.jsxs(_e,{...f,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:f.control,name:"name",render:({field:E})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(y,{children:s("form.name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("form.name.placeholder"),...E})}),e.jsx(T,{})]})}),e.jsx(b,{control:f.control,name:"rate",render:({field:E})=>e.jsxs(v,{className:"flex-[1]",children:[e.jsx(y,{children:s("form.rate.label")}),e.jsx("div",{className:"relative flex",children:e.jsx(_,{children:e.jsx(k,{type:"number",min:"0",step:"0.1",...E})})}),e.jsx(T,{})]})})]}),e.jsx(b,{control:f.control,name:"code",render:({field:E})=>e.jsxs(v,{children:[e.jsxs(y,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(_,{children:e.jsx(k,{placeholder:s("form.code.placeholder"),...E,value:E.value||""})}),e.jsx(T,{})]})}),e.jsx(b,{control:f.control,name:"tags",render:({field:E})=>e.jsxs(v,{children:[e.jsx(y,{children:s("form.tags.label")}),e.jsx(_,{children:e.jsx(za,{value:E.value,onChange:E.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(T,{})]})}),e.jsx(b,{control:f.control,name:"group_ids",render:({field:E})=>e.jsxs(v,{children:[e.jsxs(y,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(sa,{dialogTrigger:e.jsx(D,{variant:"link",children:s("form.groups.add")}),refetch:j})]}),e.jsx(_,{children:e.jsx(ht,{options:x,onChange:O=>E.onChange(O.map(q=>q.value)),value:x?.filter(O=>E.value.includes(O.value)),placeholder:s("form.groups.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.groups.empty")})})}),e.jsx(T,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:f.control,name:"host",render:({field:E})=>e.jsxs(v,{children:[e.jsx(y,{children:s("form.host.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("form.host.placeholder"),...E})}),e.jsx(T,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(b,{control:f.control,name:"port",render:({field:E})=>e.jsxs(v,{className:"flex-1",children:[e.jsxs(y,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(Re,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(It,{children:e.jsx(ce,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.port.tooltip")})})})]})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(_,{children:e.jsx(k,{placeholder:s("form.port.placeholder"),...E})}),e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(D,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const O=E.value;O&&f.setValue("server_port",O)},children:e.jsx(Re,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(ce,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(T,{})]})}),e.jsx(b,{control:f.control,name:"server_port",render:({field:E})=>e.jsxs(v,{className:"flex-1",children:[e.jsxs(y,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(Re,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(It,{children:e.jsx(ce,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(_,{children:e.jsx(k,{placeholder:s("form.server_port.placeholder"),...E})}),e.jsx(T,{})]})})]})]}),n&&e.jsx(sx,{serverType:c,value:f.watch("protocol_settings"),onChange:E=>f.setValue("protocol_settings",E,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(b,{control:f.control,name:"parent_id",render:({field:E})=>e.jsxs(v,{children:[e.jsx(y,{children:s("form.parent.label")}),e.jsxs(X,{onValueChange:E.onChange,value:E.value?.toString()||"0",children:[e.jsx(_,{children:e.jsx(Q,{children:e.jsx(ee,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(J,{children:[e.jsx(U,{value:"0",children:s("form.parent.none")}),w?.map(O=>e.jsx(U,{value:O.id.toString(),className:"cursor-pointer",children:O.name},O.id))]})]}),e.jsx(T,{})]})}),e.jsx(b,{control:f.control,name:"route_ids",render:({field:E})=>e.jsxs(v,{children:[e.jsx(y,{children:s("form.route.label")}),e.jsx(_,{children:e.jsx(ht,{options:d,onChange:O=>E.onChange(O.map(q=>q.value)),value:d?.filter(O=>E.value.includes(O.value)),placeholder:s("form.route.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.route.empty")})})}),e.jsx(T,{})]})})]}),e.jsxs(Ae,{className:"mt-6",children:[e.jsx(D,{type:"button",variant:"outline",onClick:S,children:s("form.cancel")}),e.jsx(D,{type:"submit",onClick:R,children:s("form.submit")})]})]})]})]})}function dn({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(xs,{children:[e.jsx(hs,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(gt,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Se,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(c=>r.has(c.value)).map(c=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:c.label},c.value))})]})]})}),e.jsx(os,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Is,{children:[e.jsx($s,{placeholder:n}),e.jsxs(Vs,{children:[e.jsx(qs,{children:"No results found."}),e.jsx(Ke,{children:a.map(c=>{const o=r.has(c.value);return e.jsxs(Ie,{onSelect:()=>{o?r.delete(c.value):r.add(c.value);const m=Array.from(r);s?.setFilterValue(m.length?m:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",o?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(zs,{className:N("h-4 w-4")})}),c.icon&&e.jsx(c.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${c.color}`}),e.jsx("span",{children:c.label}),l?.get(c.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(c.value)})]},c.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(st,{}),e.jsx(Ke,{children:e.jsx(Ie,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const nx=[{value:ke.Shadowsocks,label:Ms.find(s=>s.type===ke.Shadowsocks)?.label,color:js[ke.Shadowsocks]},{value:ke.Vmess,label:Ms.find(s=>s.type===ke.Vmess)?.label,color:js[ke.Vmess]},{value:ke.Trojan,label:Ms.find(s=>s.type===ke.Trojan)?.label,color:js[ke.Trojan]},{value:ke.Hysteria,label:Ms.find(s=>s.type===ke.Hysteria)?.label,color:js[ke.Hysteria]},{value:ke.Vless,label:Ms.find(s=>s.type===ke.Vless)?.label,color:js[ke.Vless]}];function rx({table:s,saveOrder:n,isSortMode:a,groups:l}){const r=s.getState().columnFilters.length>0,{t:c}=M("server");return e.jsxs("div",{className:"flex items-center justify-between ",children:[e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[!a&&e.jsxs(e.Fragment,{children:[e.jsx(ax,{}),e.jsx(k,{placeholder:c("toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:o=>s.getColumn("name")?.setFilterValue(o.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(dn,{column:s.getColumn("type"),title:c("toolbar.type"),options:nx}),s.getColumn("group_ids")&&e.jsx(dn,{column:s.getColumn("group_ids"),title:c("columns.groups.title"),options:l.map(o=>({label:o.name,value:o.id.toString()}))})]}),r&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[c("toolbar.reset"),e.jsx(Ye,{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:c("toolbar.sort.tip")})})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(D,{variant:a?"default":"outline",onClick:n,size:"sm",children:c(a?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const ft=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"})}),wt={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"},lx=s=>{const{t:n}=M("server");return[{id:"drag-handle",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Ut,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.nodeId")}),cell:({row:a})=>{const l=a.getValue("id"),r=a.original.code;return e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(K,{variant:"outline",className:N("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:js[a.original.type]},children:[e.jsx(dr,{className:"size-3"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:r??l}),a.original.parent?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-muted-foreground/30",children:"→"}),e.jsx("span",{children:a.original.parent?.code||a.original.parent?.id})]}):""]})]}),e.jsx(D,{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:c=>{c.stopPropagation(),Mt(r||l.toString()).then(()=>{$.success(n("common:copy.success"))})},children:e.jsx(Ja,{className:"size-3"})})]})}),e.jsxs(ce,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[Ms.find(c=>c.type===a.original.type)?.label,a.original.parent_id?" (子节点)":""]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r?"点击括号内容或复制按钮可复制节点代码":"点击复制按钮可复制节点ID"})]})]})})},size:200,enableSorting:!0},{accessorKey:"show",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.show")}),cell:({row:a})=>{const[l,r]=u.useState(!!a.getValue("show"));return e.jsx(W,{checked:l,onCheckedChange:async c=>{r(c),ad({id:a.original.id,type:a.original.type,show:c?1:0}).catch(()=>{r(!c),s()})},style:{backgroundColor:l?js[a.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx(L,{column:a,title:n("columns.node"),tooltip:e.jsxs("div",{className:"grid grid-cols-1 gap-3 p-2",children:[e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",wt[0])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.0")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",wt[1])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.1")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",wt[2])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.2")})]})]})})}),cell:({row:a})=>e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("size-2.5 flex-shrink-0 rounded-full transition-all duration-200",wt[a.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:a.getValue("name")})]})}),e.jsx(ce,{children:e.jsx("p",{className:"font-medium",children:n(`columns.status.${a.original.available_status}`)})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.address")}),cell:({row:a})=>{const l=`${a.original.host}:${a.original.port}`,r=a.original.port!==a.original.server_port;return e.jsxs("div",{className:"group relative flex min-w-0 items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-1 gap-y-0.5 pr-7",children:[e.jsx("div",{className:"flex items-center ",children:e.jsxs("span",{className:"font-mono text-sm font-medium text-foreground/90",children:[a.original.host,":",a.original.port]})}),r&&e.jsxs("span",{className:"whitespace-nowrap text-[0.7rem] tracking-tight text-muted-foreground/40",children:["(",n("columns.internalPort")," ",a.original.server_port,")"]})]}),e.jsx("div",{className:"absolute right-0 top-0",children:e.jsx(pe,{delayDuration:0,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(D,{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:c=>{c.stopPropagation(),Mt(l).then(()=>{$.success(n("common:copy.success"))})},children:e.jsx(Ja,{className:"size-3"})})}),e.jsx(ce,{side:"top",sideOffset:10,children:n("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.onlineUsers.title"),tooltip:n("columns.onlineUsers.tooltip")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(ft,{className:"size-4"}),e.jsx("span",{className:"font-medium",children:a.getValue("online")})]}),size:80,enableSorting:!0,enableHiding:!0},{accessorKey:"rate",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.rate.title"),tooltip:n("columns.rate.tooltip")}),cell:({row:a})=>e.jsxs(K,{variant:"secondary",className:"font-medium",children:[a.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"group_ids",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.groups.title"),tooltip:n("columns.groups.tooltip")}),cell:({row:a})=>{const l=a.original.groups||[];return e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[l.map((r,c)=>e.jsx(K,{variant:"secondary",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:r.name},c)),l.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:n("columns.groups.empty")})]})},enableSorting:!1,filterFn:(a,l,r)=>{const c=a.getValue(l);return c?r.some(o=>c.includes(o)):!1}},{accessorKey:"type",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.type")}),cell:({row:a})=>{const l=a.getValue("type");return e.jsx(K,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:js[l]},children:l})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:a})=>e.jsx(L,{className:"justify-end",column:a,title:n("columns.actions")}),cell:({row:a})=>{const{setIsOpen:l,setEditingServer:r,setServerType:c}=Jr();return e.jsx("div",{className:"flex justify-center",children:e.jsxs(bs,{modal:!1,children:[e.jsx(ys,{asChild:!0,children:e.jsx(D,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Vt,{className:"size-4"})})}),e.jsxs(us,{align:"end",className:"w-40",children:[e.jsx(fe,{className:"cursor-pointer",onClick:()=>{c(a.original.type),r(a.original),l(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(Mo,{className:"mr-2 size-4"}),n("columns.actions_dropdown.edit")]})}),e.jsxs(fe,{className:"cursor-pointer",onClick:async()=>{td({id:a.original.id}).then(({data:o})=>{o&&($.success(n("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx(Fo,{className:"mr-2 size-4"}),n("columns.actions_dropdown.copy")]}),e.jsx(Zs,{}),e.jsx(fe,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:o=>o.preventDefault(),children:e.jsx(Be,{title:n("columns.actions_dropdown.delete.title"),description:n("columns.actions_dropdown.delete.description"),confirmText:n("columns.actions_dropdown.delete.confirm"),variant:"destructive",onConfirm:async()=>{sd({id:a.original.id}).then(({data:o})=>{o&&($.success(n("columns.actions_dropdown.delete_success")),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(ns,{className:"mr-2 size-4"}),n("columns.actions_dropdown.delete.confirm")]})})})]})]})})},size:50}]};function ix(){const[s,n]=u.useState({}),[a,l]=u.useState({"drag-handle":!1}),[r,c]=u.useState([]),[o,m]=u.useState({pageSize:500,pageIndex:0}),[x,i]=u.useState([]),[d,p]=u.useState(!1),[C,P]=u.useState({}),[f,j]=u.useState([]),{refetch:w}=ie({queryKey:["nodeList"],queryFn:async()=>{const{data:q}=await zr();return j(q),q}}),{data:g}=ie({queryKey:["groups"],queryFn:async()=>{const{data:q}=await vt();return q}});u.useEffect(()=>{l({"drag-handle":d,show:!d,host:!d,online:!d,rate:!d,groups:!d,type:!1,actions:!d}),P({name:d?2e3:200}),m({pageSize:d?99999:500,pageIndex:0})},[d]);const S=(q,te)=>{d&&(q.dataTransfer.setData("text/plain",te.toString()),q.currentTarget.classList.add("opacity-50"))},R=(q,te)=>{if(!d)return;q.preventDefault(),q.currentTarget.classList.remove("bg-muted");const F=parseInt(q.dataTransfer.getData("text/plain"));if(F===te)return;const se=[...f],[qe]=se.splice(F,1);se.splice(te,0,qe),j(se)},E=async()=>{if(!d){p(!0);return}const q=f?.map((te,F)=>({id:te.id,order:F+1}));nd(q).then(()=>{$.success("排序保存成功"),p(!1),w()}).finally(()=>{p(!1)})},O=Ze({data:f||[],columns:lx(w),state:{sorting:x,columnVisibility:a,rowSelection:s,columnFilters:r,columnSizing:C,pagination:o},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:i,onColumnFiltersChange:c,onColumnVisibilityChange:l,onColumnSizingChange:P,onPaginationChange:m,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),getSortedRowModel:is(),getFacetedRowModel:_s(),getFacetedUniqueValues:ws(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Uu,{refetch:w,children:e.jsx("div",{className:"space-y-4",children:e.jsx(cs,{table:O,toolbar:q=>e.jsx(rx,{table:q,refetch:w,saveOrder:E,isSortMode:d,groups:g||[]}),draggable:d,onDragStart:S,onDragEnd:q=>q.currentTarget.classList.remove("opacity-50"),onDragOver:q=>{q.preventDefault(),q.currentTarget.classList.add("bg-muted")},onDragLeave:q=>q.currentTarget.classList.remove("bg-muted"),onDrop:R,showPagination:!d})})})}function ox(){const{t:s}=M("server");return e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx($e,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("manage.title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("manage.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(ix,{})})]})]})}const cx=Object.freeze(Object.defineProperty({__proto__:null,default:ox},Symbol.toStringTag,{value:"Module"}));function dx({table:s,refetch:n}){const a=s.getState().columnFilters.length>0,{t:l}=M("group");return e.jsx("div",{className:"flex items-center justify-between space-x-4",children:e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(sa,{refetch:n}),e.jsx(k,{placeholder:l("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:r=>s.getColumn("name")?.setFilterValue(r.target.value),className:N("h-8 w-[150px] lg:w-[250px]",a&&"border-primary/50 ring-primary/20")}),a&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("toolbar.reset"),e.jsx(Ye,{className:"ml-2 h-4 w-4"})]})]})})}const mx=s=>{const{t:n}=M("group");return[{accessorKey:"id",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.id")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:a.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.name")}),cell:({row:a})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium",children:a.getValue("name")})})},{accessorKey:"users_count",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.usersCount")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(ft,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:a.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"server_count",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.serverCount")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(dr,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:a.getValue("server_count")})]}),enableSorting:!0,size:8e3},{id:"actions",header:({column:a})=>e.jsx(L,{className:"justify-end",column:a,title:n("columns.actions")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(sa,{defaultValues:a.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(As,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(Be,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{ld({id:a.original.id}).then(({data:l})=>{l&&($.success(n("messages.updateSuccess")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ns,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("messages.deleteButton")})]})})]})}]};function ux(){const[s,n]=u.useState({}),[a,l]=u.useState({}),[r,c]=u.useState([]),[o,m]=u.useState([]),{data:x,refetch:i,isLoading:d}=ie({queryKey:["serverGroupList"],queryFn:async()=>{const{data:C}=await vt();return C}}),p=Ze({data:x||[],columns:mx(i),state:{sorting:o,columnVisibility:a,rowSelection:s,columnFilters:r},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:c,onColumnVisibilityChange:l,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),getSortedRowModel:is(),getFacetedRowModel:_s(),getFacetedUniqueValues:ws(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(cs,{table:p,toolbar:C=>e.jsx(dx,{table:C,refetch:i}),isLoading:d})}function xx(){const{t:s}=M("group");return e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx($e,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(ux,{})})]})]})}const hx=Object.freeze(Object.defineProperty({__proto__:null,default:xx},Symbol.toStringTag,{value:"Module"})),fx=s=>h.object({remarks:h.string().min(1,s("form.validation.remarks")),match:h.array(h.string()),action:h.enum(["block","dns"]),action_value:h.string().optional()});function Zr({refetch:s,dialogTrigger:n,defaultValues:a={remarks:"",match:[],action:"block",action_value:""},type:l="add"}){const{t:r}=M("route"),c=je({resolver:Ne(fx(r)),defaultValues:a,mode:"onChange"}),[o,m]=u.useState(!1);return e.jsxs(be,{open:o,onOpenChange:m,children:[e.jsx(Ge,{asChild:!0,children:n||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Re,{icon:"ion:add"})," ",e.jsx("div",{children:r("form.add")})]})}),e.jsxs(ge,{className:"sm:max-w-[425px]",children:[e.jsxs(we,{children:[e.jsx(ye,{children:r(l==="edit"?"form.edit":"form.create")}),e.jsx(De,{})]}),e.jsxs(_e,{...c,children:[e.jsx(b,{control:c.control,name:"remarks",render:({field:x})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(y,{children:r("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(_,{children:e.jsx(k,{type:"text",placeholder:r("form.remarksPlaceholder"),...x})})}),e.jsx(T,{})]})}),e.jsx(b,{control:c.control,name:"match",render:({field:x})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(y,{children:r("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(_,{children:e.jsx(fs,{className:"min-h-[120px]",placeholder:r("form.matchPlaceholder"),value:x.value.join(`
|
||
`),onChange:i=>{x.onChange(i.target.value.split(`
|
||
`))}})})}),e.jsx(T,{})]})}),e.jsx(b,{control:c.control,name:"action",render:({field:x})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(_,{children:e.jsxs(X,{onValueChange:x.onChange,defaultValue:x.value,children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:r("form.actionPlaceholder")})}),e.jsxs(J,{children:[e.jsx(U,{value:"block",children:r("actions.block")}),e.jsx(U,{value:"dns",children:r("actions.dns")})]})]})})}),e.jsx(T,{})]})}),c.watch("action")==="dns"&&e.jsx(b,{control:c.control,name:"action_value",render:({field:x})=>e.jsxs(v,{children:[e.jsx(y,{children:r("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(_,{children:e.jsx(k,{type:"text",placeholder:r("form.dnsPlaceholder"),...x})})})]})}),e.jsxs(Ae,{children:[e.jsx(jt,{asChild:!0,children:e.jsx(D,{variant:"outline",children:r("form.cancel")})}),e.jsx(D,{type:"submit",onClick:()=>{id(c.getValues()).then(({data:x})=>{x&&(m(!1),s&&s(),toast.success(r(l==="edit"?"messages.updateSuccess":"messages.createSuccess")),c.reset())})},children:r("form.submit")})]})]})]})]})}function px({table:s,refetch:n}){const a=s.getState().columnFilters.length>0,{t:l}=M("route");return e.jsx("div",{className:"flex items-center justify-between ",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[e.jsx(Zr,{refetch:n}),e.jsx(k,{placeholder:l("toolbar.searchPlaceholder"),value:s.getColumn("remarks")?.getFilterValue()??"",onChange:r=>s.getColumn("remarks")?.setFilterValue(r.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),a&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("toolbar.reset"),e.jsx(Ye,{className:"ml-2 h-4 w-4"})]})]})})}function gx({columns:s,data:n,refetch:a}){const[l,r]=u.useState({}),[c,o]=u.useState({}),[m,x]=u.useState([]),[i,d]=u.useState([]),p=Ze({data:n,columns:s,state:{sorting:i,columnVisibility:c,rowSelection:l,columnFilters:m},enableRowSelection:!0,onRowSelectionChange:r,onSortingChange:d,onColumnFiltersChange:x,onColumnVisibilityChange:o,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),getSortedRowModel:is(),getFacetedRowModel:_s(),getFacetedUniqueValues:ws(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(cs,{table:p,toolbar:C=>e.jsx(px,{table:C,refetch:a})})}const jx=s=>{const{t:n}=M("route"),a={block:{icon:zo,variant:"destructive",className:"bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-800"},dns:{icon:Lo,variant:"secondary",className:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-800"}};return[{accessorKey:"id",header:({column:l})=>e.jsx(L,{column:l,title:n("columns.id")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:l.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:l})=>e.jsx(L,{column:l,title:n("columns.remarks")}),cell:({row:l})=>{const r=l.original.match?.length||0;return e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:n("columns.matchRules",{count:r})})})},enableHiding:!1,enableSorting:!1},{accessorKey:"action",header:({column:l})=>e.jsx(L,{column:l,title:n("columns.action")}),cell:({row:l})=>{const r=l.getValue("action"),c=a[r]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(K,{variant:a[r]?.variant||"default",className:N("flex items-center gap-1.5 px-3 py-1 capitalize",a[r]?.className),children:[c&&e.jsx(c,{className:"h-3.5 w-3.5"}),n(`actions.${r}`)]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:n("columns.actions")}),cell:({row:l})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Zr,{defaultValues:l.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(As,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(Be,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{od({id:l.original.id}).then(({data:r})=>{r&&($.success(n("messages.deleteSuccess")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ns,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("messages.deleteButton")})]})})]})}]};function vx(){const{t:s}=M("route"),[n,a]=u.useState([]);function l(){Lr().then(({data:r})=>{a(r)})}return u.useEffect(()=>{l()},[]),e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx($e,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(gx,{data:n,columns:jx(l),refetch:l})})]})]})}const bx=Object.freeze(Object.defineProperty({__proto__:null,default:vx},Symbol.toStringTag,{value:"Module"})),Xr=u.createContext(void 0);function yx({children:s,refreshData:n}){const[a,l]=u.useState(!1),[r,c]=u.useState(null);return e.jsx(Xr.Provider,{value:{isOpen:a,setIsOpen:l,editingPlan:r,setEditingPlan:c,refreshData:n},children:s})}function La(){const s=u.useContext(Xr);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function Nx({table:s,saveOrder:n,isSortMode:a}){const{setIsOpen:l}=La(),{t:r}=M("subscribe");return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsxs(D,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>l(!0),children:[e.jsx(Re,{icon:"ion:add"}),e.jsx("div",{children:r("plan.add")})]}),e.jsx(k,{placeholder:r("plan.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:c=>s.getColumn("name")?.setFilterValue(c.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(D,{variant:a?"default":"outline",onClick:n,size:"sm",children:r(a?"plan.sort.save":"plan.sort.edit")})})]})}const mn={monthly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},quarterly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},half_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},two_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},three_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},onetime:{color:"text-slate-700",bgColor:"bg-slate-100/80"},reset_traffic:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},_x=s=>{const{t:n}=M("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(Ut,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:a})=>e.jsx(L,{column:a,title:n("plan.columns.id")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:a.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:a})=>e.jsx(L,{column:a,title:n("plan.columns.show")}),cell:({row:a})=>e.jsx(W,{defaultChecked:a.getValue("show"),onCheckedChange:l=>{na({id:a.original.id,show:l}).then(({data:r})=>{!r&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:a})=>e.jsx(L,{column:a,title:n("plan.columns.sell")}),cell:({row:a})=>e.jsx(W,{defaultChecked:a.getValue("sell"),onCheckedChange:l=>{na({id:a.original.id,sell:l}).then(({data:r})=>{!r&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:a})=>e.jsx(L,{column:a,title:n("plan.columns.renew"),tooltip:n("plan.columns.renew_tooltip")}),cell:({row:a})=>e.jsx(W,{defaultChecked:a.getValue("renew"),onCheckedChange:l=>{na({id:a.original.id,renew:l}).then(({data:r})=>{!r&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:a})=>e.jsx(L,{column:a,title:n("plan.columns.name")}),cell:({row:a})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:a.getValue("name")})}),enableSorting:!1,enableHiding:!1,size:900},{accessorKey:"users_count",header:({column:a})=>e.jsx(L,{column:a,title:n("plan.columns.stats")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 px-2",children:[e.jsx(ft,{}),e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:a.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"group",header:({column:a})=>e.jsx(L,{column:a,title:n("plan.columns.group")}),cell:({row:a})=>e.jsx("div",{className:"flex max-w-[600px] flex-wrap items-center gap-1.5 text-nowrap",children:e.jsx(K,{variant:"secondary",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:a.getValue("group")?.name})}),enableSorting:!1,enableHiding:!1},{accessorKey:"prices",header:({column:a})=>e.jsx(L,{column:a,title:n("plan.columns.price")}),cell:({row:a})=>{const l=a.getValue("prices"),r=[{period:n("plan.columns.price_period.monthly"),key:"monthly",unit:n("plan.columns.price_period.unit.month")},{period:n("plan.columns.price_period.quarterly"),key:"quarterly",unit:n("plan.columns.price_period.unit.quarter")},{period:n("plan.columns.price_period.half_yearly"),key:"half_yearly",unit:n("plan.columns.price_period.unit.half_year")},{period:n("plan.columns.price_period.yearly"),key:"yearly",unit:n("plan.columns.price_period.unit.year")},{period:n("plan.columns.price_period.two_yearly"),key:"two_yearly",unit:n("plan.columns.price_period.unit.two_year")},{period:n("plan.columns.price_period.three_yearly"),key:"three_yearly",unit:n("plan.columns.price_period.unit.three_year")},{period:n("plan.columns.price_period.onetime"),key:"onetime",unit:""},{period:n("plan.columns.price_period.reset_traffic"),key:"reset_traffic",unit:n("plan.columns.price_period.unit.times")}];return e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:r.map(({period:c,key:o,unit:m})=>l[o]!=null&&e.jsxs(K,{variant:"secondary",className:N("px-2 py-0.5 font-medium transition-colors text-nowrap",mn[o].color,mn[o].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[c," ¥",l[o],m]},o))})},enableSorting:!1,size:9e3},{id:"actions",header:({column:a})=>e.jsx(L,{className:"justify-end",column:a,title:n("plan.columns.actions")}),cell:({row:a})=>{const{setIsOpen:l,setEditingPlan:r}=La();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{r(a.original),l(!0)},children:[e.jsx(As,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.edit")})]}),e.jsx(Be,{title:n("plan.columns.delete_confirm.title"),description:n("plan.columns.delete_confirm.description"),confirmText:n("plan.columns.delete"),variant:"destructive",onConfirm:async()=>{Sd({id:a.original.id}).then(({data:c})=>{c&&($.success(n("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ns,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.delete")})]})})]})}}]},wx=h.object({id:h.number().nullable(),group_id:h.union([h.number(),h.string()]).nullable().optional(),name:h.string().min(1).max(250),content:h.string().nullable().optional(),transfer_enable:h.union([h.number().min(0),h.string().min(1)]),prices:h.object({monthly:h.union([h.number(),h.string()]).nullable().optional(),quarterly:h.union([h.number(),h.string()]).nullable().optional(),half_yearly:h.union([h.number(),h.string()]).nullable().optional(),yearly:h.union([h.number(),h.string()]).nullable().optional(),two_yearly:h.union([h.number(),h.string()]).nullable().optional(),three_yearly:h.union([h.number(),h.string()]).nullable().optional(),onetime:h.union([h.number(),h.string()]).nullable().optional(),reset_traffic:h.union([h.number(),h.string()]).nullable().optional()}).default({}),speed_limit:h.union([h.number(),h.string()]).nullable().optional(),capacity_limit:h.union([h.number(),h.string()]).nullable().optional(),device_limit:h.union([h.number(),h.string()]).nullable().optional(),force_update:h.boolean().optional(),reset_traffic_method:h.number().nullable(),users_count:h.number().optional()}),el=u.forwardRef(({className:s,...n},a)=>e.jsx(mr,{ref:a,className:N("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...n,children:e.jsx(Ao,{className:N("flex items-center justify-center text-current"),children:e.jsx(zs,{className:"h-4 w-4"})})}));el.displayName=mr.displayName;const Ct={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},St={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}},Cx=[{value:null,label:"follow_system"},{value:0,label:"monthly_first"},{value:1,label:"monthly_reset"},{value:2,label:"no_reset"},{value:3,label:"yearly_first"},{value:4,label:"yearly_reset"}];function Sx(){const{isOpen:s,setIsOpen:n,editingPlan:a,setEditingPlan:l,refreshData:r}=La(),[c,o]=u.useState(!1),{t:m}=M("subscribe"),x=je({resolver:Ne(wx),defaultValues:{...Ct,...a||{}},mode:"onChange"});u.useEffect(()=>{a?x.reset({...Ct,...a}):x.reset(Ct)},[a,x]);const i=new Da({html:!0}),[d,p]=u.useState();async function C(){vt().then(({data:j})=>{p(j)})}u.useEffect(()=>{s&&C()},[s]);const P=j=>{if(isNaN(j))return;const w=Object.entries(St).reduce((g,[S,R])=>{const E=j*R.months*R.discount;return{...g,[S]:E.toFixed(2)}},{});x.setValue("prices",w,{shouldDirty:!0})},f=()=>{n(!1),l(null),x.reset(Ct)};return e.jsx(be,{open:s,onOpenChange:f,children:e.jsxs(ge,{children:[e.jsxs(we,{children:[e.jsx(ye,{children:m(a?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(De,{})]}),e.jsxs(_e,{...x,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:x.control,name:"name",render:({field:j})=>e.jsxs(v,{children:[e.jsx(y,{children:m("plan.form.name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:m("plan.form.name.placeholder"),...j})}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"group_id",render:({field:j})=>e.jsxs(v,{children:[e.jsxs(y,{className:"flex items-center justify-between",children:[m("plan.form.group.label"),e.jsx(sa,{dialogTrigger:e.jsx(D,{variant:"link",children:m("plan.form.group.add")}),refetch:C})]}),e.jsxs(X,{value:j.value?.toString()??"",onValueChange:w=>j.onChange(w?Number(w):null),children:[e.jsx(_,{children:e.jsx(Q,{children:e.jsx(ee,{placeholder:m("plan.form.group.placeholder")})})}),e.jsx(J,{children:d?.map(w=>e.jsx(U,{value:w.id.toString(),children:w.name},w.id))})]}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"transfer_enable",render:({field:j})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(y,{children:m("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{children:e.jsx(k,{type:"number",min:0,placeholder:m("plan.form.transfer.placeholder"),className:"rounded-r-none",...j})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:m("plan.form.transfer.unit")})]}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"speed_limit",render:({field:j})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(y,{children:m("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{children:e.jsx(k,{type:"number",min:0,placeholder:m("plan.form.speed.placeholder"),className:"rounded-r-none",...j,value:j.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:m("plan.form.speed.unit")})]}),e.jsx(T,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:m("plan.form.price.title")}),e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(k,{type:"number",placeholder:m("plan.form.price.base_price"),className:"h-7 w-32 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500",onChange:j=>{const w=parseFloat(j.target.value);P(w)}})]}),e.jsx(pe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const j=Object.keys(St).reduce((w,g)=>({...w,[g]:""}),{});x.setValue("prices",j,{shouldDirty:!0})},children:m("plan.form.price.clear.button")})}),e.jsx(ce,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:m("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(St).filter(([j])=>!["onetime","reset_traffic"].includes(j)).map(([j,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(b,{control:x.control,name:`prices.${j}`,render:({field:g})=>e.jsxs(v,{children:[e.jsxs(y,{className:"text-xs font-medium text-muted-foreground",children:[m(`plan.columns.price_period.${j}`),e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",w.months===1?m("plan.form.price.period.monthly"):m("plan.form.price.period.months",{count:w.months}),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,...g,value:g.value??"",onChange:S=>g.onChange(S.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"})})]})]})})},j))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(St).filter(([j])=>["onetime","reset_traffic"].includes(j)).map(([j,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(b,{control:x.control,name:`prices.${j}`,render:({field:g})=>e.jsx(v,{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(y,{className:"text-xs font-medium",children:m(`plan.columns.price_period.${j}`)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:m(j==="onetime"?"plan.form.price.onetime_desc":"plan.form.price.reset_desc")})]}),e.jsxs("div",{className:"relative w-full md:w-32",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,...g,className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})})},j))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(b,{control:x.control,name:"device_limit",render:({field:j})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(y,{children:m("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{children:e.jsx(k,{type:"number",min:0,placeholder:m("plan.form.device.placeholder"),className:"rounded-r-none",...j,value:j.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:m("plan.form.device.unit")})]}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"capacity_limit",render:({field:j})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(y,{children:m("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{children:e.jsx(k,{type:"number",min:0,placeholder:m("plan.form.capacity.placeholder"),className:"rounded-r-none",...j,value:j.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:m("plan.form.capacity.unit")})]}),e.jsx(T,{})]})})]}),e.jsx(b,{control:x.control,name:"reset_traffic_method",render:({field:j})=>e.jsxs(v,{children:[e.jsx(y,{children:m("plan.form.reset_method.label")}),e.jsxs(X,{value:j.value?.toString()??"null",onValueChange:w=>j.onChange(w=="null"?null:Number(w)),children:[e.jsx(_,{children:e.jsx(Q,{children:e.jsx(ee,{placeholder:m("plan.form.reset_method.placeholder")})})}),e.jsx(J,{children:Cx.map(w=>e.jsx(U,{value:w.value?.toString()??"null",children:m(`plan.form.reset_method.options.${w.label}`)},w.value))})]}),e.jsx(z,{className:"text-xs",children:m("plan.form.reset_method.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:x.control,name:"content",render:({field:j})=>{const[w,g]=u.useState(!1);return e.jsxs(v,{className:"space-y-2",children:[e.jsxs(y,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[m("plan.form.content.label"),e.jsx(pe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>g(!w),children:w?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{d:"M10 12.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5z"}),e.jsx("path",{fillRule:"evenodd",d:"M.664 10.59a1.651 1.651 0 010-1.186A10.004 10.004 0 0110 3c4.257 0 7.893 2.66 9.336 6.41.147.381.146.804 0 1.186A10.004 10.004 0 0110 17c-4.257 0-7.893-2.66-9.336-6.41zM14 10a4 4 0 11-8 0 4 4 0 018 0z",clipRule:"evenodd"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{fillRule:"evenodd",d:"M3.28 2.22a.75.75 0 00-1.06 1.06l14.5 14.5a.75.75 0 101.06-1.06l-1.745-1.745a10.029 10.029 0 003.3-4.38 1.651 1.651 0 000-1.185A10.004 10.004 0 009.999 3a9.956 9.956 0 00-4.744 1.194L3.28 2.22zM7.752 6.69l1.092 1.092a2.5 2.5 0 013.374 3.373l1.091 1.092a4 4 0 00-5.557-5.557z",clipRule:"evenodd"}),e.jsx("path",{d:"M10.748 13.93l2.523 2.523a9.987 9.987 0 01-3.27.547c-4.258 0-7.894-2.66-9.337-6.41a1.651 1.651 0 010-1.186A10.007 10.007 0 012.839 6.02L6.07 9.252a4 4 0 004.678 4.678z"})]})})}),e.jsx(ce,{side:"top",children:e.jsx("p",{className:"text-xs",children:m(w?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(pe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",onClick:()=>{j.onChange(m("plan.form.content.template.content"))},children:m("plan.form.content.template.button")})}),e.jsx(ce,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:m("plan.form.content.template.tooltip")})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${w?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(_,{children:e.jsx(Pa,{style:{height:"400px"},value:j.value||"",renderHTML:S=>i.render(S),onChange:({text:S})=>j.onChange(S),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:m("plan.form.content.placeholder"),className:"rounded-md border"})})}),w&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:m("plan.form.content.preview")}),e.jsx("div",{className:"prose prose-sm dark:prose-invert h-[400px] max-w-none overflow-y-auto rounded-md border p-4",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:i.render(j.value||"")}})})]})]}),e.jsx(z,{className:"text-xs",children:m("plan.form.content.description")}),e.jsx(T,{})]})}})]}),e.jsx(Ae,{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(b,{control:x.control,name:"force_update",render:({field:j})=>e.jsxs(v,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(_,{children:e.jsx(el,{checked:j.value,onCheckedChange:j.onChange})}),e.jsx("div",{className:"",children:e.jsx(y,{className:"text-sm",children:m("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:f,children:m("plan.form.submit.cancel")}),e.jsx(D,{type:"submit",disabled:c,onClick:()=>{x.handleSubmit(async j=>{o(!0),(await Cd(j)).data&&($.success(m(a?"plan.form.submit.success.update":"plan.form.submit.success.add")),f(),r()),o(!1)})()},children:m(c?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})]})})}function kx(){const[s,n]=u.useState({}),[a,l]=u.useState({"drag-handle":!1}),[r,c]=u.useState([]),[o,m]=u.useState([]),[x,i]=u.useState(!1),[d,p]=u.useState({pageSize:20,pageIndex:0}),[C,P]=u.useState([]),{refetch:f}=ie({queryKey:["planList"],queryFn:async()=>{const{data:R}=await Us();return P(R),R}});u.useEffect(()=>{l({"drag-handle":x}),p({pageSize:x?99999:10,pageIndex:0})},[x]);const j=(R,E)=>{x&&(R.dataTransfer.setData("text/plain",E.toString()),R.currentTarget.classList.add("opacity-50"))},w=(R,E)=>{if(!x)return;R.preventDefault(),R.currentTarget.classList.remove("bg-muted");const O=parseInt(R.dataTransfer.getData("text/plain"));if(O===E)return;const q=[...C],[te]=q.splice(O,1);q.splice(E,0,te),P(q)},g=async()=>{if(!x){i(!0);return}const R=C?.map(E=>E.id);kd(R).then(()=>{$.success("排序保存成功"),i(!1),f()}).finally(()=>{i(!1)})},S=Ze({data:C||[],columns:_x(f),state:{sorting:o,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:d},enableRowSelection:!0,onPaginationChange:p,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:c,onColumnVisibilityChange:l,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),getSortedRowModel:is(),getFacetedRowModel:_s(),getFacetedUniqueValues:ws(),initialState:{columnPinning:{right:["actions"]}},pageCount:x?1:void 0});return e.jsx(yx,{refreshData:f,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(cs,{table:S,toolbar:R=>e.jsx(Nx,{table:R,refetch:f,saveOrder:g,isSortMode:x}),draggable:x,onDragStart:j,onDragEnd:R=>R.currentTarget.classList.remove("opacity-50"),onDragOver:R=>{R.preventDefault(),R.currentTarget.classList.add("bg-muted")},onDragLeave:R=>R.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!x}),e.jsx(Sx,{})]})})}function Tx(){const{t:s}=M("subscribe");return e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx($e,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("plan.title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("plan.page.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(kx,{})})]})]})}const Dx=Object.freeze(Object.defineProperty({__proto__:null,default:Tx},Symbol.toStringTag,{value:"Module"})),Gs=[{value:re.PENDING,label:rt[re.PENDING],icon:$o,color:lt[re.PENDING]},{value:re.PROCESSING,label:rt[re.PROCESSING],icon:ur,color:lt[re.PROCESSING]},{value:re.COMPLETED,label:rt[re.COMPLETED],icon:ga,color:lt[re.COMPLETED]},{value:re.CANCELLED,label:rt[re.CANCELLED],icon:xr,color:lt[re.CANCELLED]},{value:re.DISCOUNTED,label:rt[re.DISCOUNTED],icon:ga,color:lt[re.DISCOUNTED]}],ot=[{value:ue.PENDING,label:yt[ue.PENDING],icon:qo,color:Nt[ue.PENDING]},{value:ue.PROCESSING,label:yt[ue.PROCESSING],icon:ur,color:Nt[ue.PROCESSING]},{value:ue.VALID,label:yt[ue.VALID],icon:ga,color:Nt[ue.VALID]},{value:ue.INVALID,label:yt[ue.INVALID],icon:xr,color:Nt[ue.INVALID]}];function kt({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=s?.getFilterValue(),c=Array.isArray(r)?new Set(r):r!==void 0?new Set([r]):new Set;return e.jsxs(xs,{children:[e.jsx(hs,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(gt,{className:"mr-2 h-4 w-4"}),n,c?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Se,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:c.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:c.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[c.size," selected"]}):a.filter(o=>c.has(o.value)).map(o=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:o.label},o.value))})]})]})}),e.jsx(os,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Is,{children:[e.jsx($s,{placeholder:n}),e.jsxs(Vs,{children:[e.jsx(qs,{children:"No results found."}),e.jsx(Ke,{children:a.map(o=>{const m=c.has(o.value);return e.jsxs(Ie,{onSelect:()=>{const x=new Set(c);m?x.delete(o.value):x.add(o.value);const i=Array.from(x);s?.setFilterValue(i.length?i:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",m?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(zs,{className:N("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}),l?.get(o.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(o.value)})]},o.value)})}),c.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(st,{}),e.jsx(Ke,{children:e.jsx(Ie,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Px=h.object({email:h.string().min(1),plan_id:h.number(),period:h.string(),total_amount:h.number()}),Ex={email:"",plan_id:0,total_amount:0,period:""};function sl({refetch:s,trigger:n,defaultValues:a}){const{t:l}=M("order"),[r,c]=u.useState(!1),o=je({resolver:Ne(Px),defaultValues:{...Ex,...a},mode:"onChange"}),[m,x]=u.useState([]);return u.useEffect(()=>{r&&Us().then(({data:i})=>{x(i)})},[r]),e.jsxs(be,{open:r,onOpenChange:c,children:[e.jsx(Ge,{asChild:!0,children:n||e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Re,{icon:"ion:add"}),e.jsx("div",{children:l("dialog.addOrder")})]})}),e.jsxs(ge,{className:"sm:max-w-[425px]",children:[e.jsxs(we,{children:[e.jsx(ye,{children:l("dialog.assignOrder")}),e.jsx(De,{})]}),e.jsxs(_e,{...o,children:[e.jsx(b,{control:o.control,name:"email",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dialog.fields.userEmail")}),e.jsx(_,{children:e.jsx(k,{placeholder:l("dialog.placeholders.email"),...i})})]})}),e.jsx(b,{control:o.control,name:"plan_id",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dialog.fields.subscriptionPlan")}),e.jsx(_,{children:e.jsxs(X,{value:i.value?i.value?.toString():void 0,onValueChange:d=>i.onChange(parseInt(d)),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dialog.placeholders.plan")})}),e.jsx(J,{children:m.map(d=>e.jsx(U,{value:d.id.toString(),children:d.name},d.id))})]})})]})}),e.jsx(b,{control:o.control,name:"period",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dialog.fields.orderPeriod")}),e.jsx(_,{children:e.jsxs(X,{value:i.value,onValueChange:i.onChange,children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:l("dialog.placeholders.period")})}),e.jsx(J,{children:Object.keys(tm).map(d=>e.jsx(U,{value:d,children:l(`period.${d}`)},d))})]})})]})}),e.jsx(b,{control:o.control,name:"total_amount",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:l("dialog.fields.paymentAmount")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:l("dialog.placeholders.amount"),value:i.value/100,onChange:d=>i.onChange(parseFloat(d.currentTarget.value)*100)})}),e.jsx(T,{})]})}),e.jsxs(Ae,{children:[e.jsx(D,{variant:"outline",onClick:()=>c(!1),children:l("dialog.actions.cancel")}),e.jsx(D,{type:"submit",onClick:()=>{o.handleSubmit(i=>{Rd(i).then(({data:d})=>{d&&(s&&s(),o.reset(),c(!1),$.success(l("dialog.messages.addSuccess")))})})()},children:l("dialog.actions.confirm")})]})]})]})]})}function Rx({table:s,refetch:n}){const{t:a}=M("order"),l=s.getState().columnFilters.length>0,r=Object.values(as).filter(x=>typeof x=="number").map(x=>({label:a(`type.${as[x]}`),value:x,color:x===as.NEW?"green-500":x===as.RENEWAL?"blue-500":x===as.UPGRADE?"purple-500":"orange-500"})),c=Object.values(Te).map(x=>({label:a(`period.${x}`),value:x,color:x===Te.MONTH_PRICE?"slate-500":x===Te.QUARTER_PRICE?"cyan-500":x===Te.HALF_YEAR_PRICE?"indigo-500":x===Te.YEAR_PRICE?"violet-500":x===Te.TWO_YEAR_PRICE?"fuchsia-500":x===Te.THREE_YEAR_PRICE?"pink-500":x===Te.ONETIME_PRICE?"rose-500":"orange-500"})),o=Object.values(re).filter(x=>typeof x=="number").map(x=>({label:a(`status.${re[x]}`),value:x,icon:x===re.PENDING?Gs[0].icon:x===re.PROCESSING?Gs[1].icon:x===re.COMPLETED?Gs[2].icon:x===re.CANCELLED?Gs[3].icon:Gs[4].icon,color:x===re.PENDING?"yellow-500":x===re.PROCESSING?"blue-500":x===re.COMPLETED?"green-500":x===re.CANCELLED?"red-500":"green-500"})),m=Object.values(ue).filter(x=>typeof x=="number").map(x=>({label:a(`commission.${ue[x]}`),value:x,icon:x===ue.PENDING?ot[0].icon:x===ue.PROCESSING?ot[1].icon:x===ue.VALID?ot[2].icon:ot[3].icon,color:x===ue.PENDING?"yellow-500":x===ue.PROCESSING?"blue-500":x===ue.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(sl,{refetch:n}),e.jsx(k,{placeholder:a("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:x=>s.getColumn("trade_no")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2",children:[s.getColumn("type")&&e.jsx(kt,{column:s.getColumn("type"),title:a("table.columns.type"),options:r}),s.getColumn("period")&&e.jsx(kt,{column:s.getColumn("period"),title:a("table.columns.period"),options:c}),s.getColumn("status")&&e.jsx(kt,{column:s.getColumn("status"),title:a("table.columns.status"),options:o}),s.getColumn("commission_status")&&e.jsx(kt,{column:s.getColumn("commission_status"),title:a("table.columns.commissionStatus"),options:m})]}),l&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[a("actions.reset"),e.jsx(Ye,{className:"ml-2 h-4 w-4"})]})]})}function es({label:s,value:n,className:a,valueClassName:l}){return e.jsxs("div",{className:N("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:N("text-sm",l),children:n||"-"})]})}function Ix({status:s}){const{t:n}=M("order"),a={[re.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[re.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[re.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[re.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[re.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(K,{variant:"secondary",className:N("font-medium",a[s]),children:n(`status.${re[s]}`)})}function Vx({id:s,trigger:n}){const[a,l]=u.useState(!1),[r,c]=u.useState(),{t:o}=M("order");return u.useEffect(()=>{(async()=>{if(a){const{data:x}=await Dd({id:s});c(x)}})()},[a,s]),e.jsxs(be,{onOpenChange:l,open:a,children:[e.jsx(Ge,{asChild:!0,children:n}),e.jsxs(ge,{className:"max-w-xl",children:[e.jsxs(we,{className:"space-y-2",children:[e.jsx(ye,{className:"text-lg font-medium",children:o("dialog.title")}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:[o("table.columns.tradeNo"),":",r?.trade_no]}),r?.status&&e.jsx(Ix,{status:r.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:o("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(es,{label:o("dialog.fields.userEmail"),value:r?.user?.email?e.jsxs(Ls,{to:`/user/manage?email=${r.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[r.user.email,e.jsx(hr,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(es,{label:o("dialog.fields.orderPeriod"),value:r&&o(`period.${r.period}`)}),e.jsx(es,{label:o("dialog.fields.subscriptionPlan"),value:r?.plan?.name,valueClassName:"font-medium"}),e.jsx(es,{label:o("dialog.fields.callbackNo"),value:r?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:o("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(es,{label:o("dialog.fields.paymentAmount"),value:Os(r?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(Se,{className:"my-2"}),e.jsx(es,{label:o("dialog.fields.balancePayment"),value:Os(r?.balance_amount||0)}),e.jsx(es,{label:o("dialog.fields.discountAmount"),value:Os(r?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(es,{label:o("dialog.fields.refundAmount"),value:Os(r?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(es,{label:o("dialog.fields.deductionAmount"),value:Os(r?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:o("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(es,{label:o("dialog.fields.createdAt"),value:ve(r?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(es,{label:o("dialog.fields.updatedAt"),value:ve(r?.updated_at),valueClassName:"font-mono text-xs"})]})]})]})]})]})}const Ox={[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"}},Mx={[Te.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Te.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Te.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Te.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Te.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Te.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Te.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Te.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Fx=s=>re[s],zx=s=>ue[s],Lx=s=>as[s],Ax=s=>{const{t:n}=M("order");return[{accessorKey:"trade_no",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.tradeNo")}),cell:({row:a})=>{const l=a.original.trade_no,r=l.length>6?`${l.slice(0,3)}...${l.slice(-3)}`:l;return e.jsx("div",{className:"flex items-center",children:e.jsx(Vx,{trigger:e.jsxs(G,{variant:"ghost",size:"sm",className:"flex h-8 items-center gap-1.5 px-2 font-medium text-primary transition-colors hover:bg-primary/10 hover:text-primary/80",children:[e.jsx("span",{className:"font-mono",children:r}),e.jsx(hr,{className:"h-3.5 w-3.5 opacity-70"})]}),id:a.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.type")}),cell:({row:a})=>{const l=a.getValue("type"),r=Ox[l];return e.jsx(K,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",r.color,r.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:n(`type.${Lx(l)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.plan")}),cell:({row:a})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium text-foreground/90 sm:max-w-72 md:max-w-[31rem]",children:a.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.period")}),cell:({row:a})=>{const l=a.getValue("period"),r=Mx[l];return e.jsx(K,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",r.color,r.bgColor,"hover:bg-opacity-80"),children:n(`period.${l}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.amount")}),cell:({row:a})=>{const l=a.getValue("total_amount"),r=typeof l=="number"?(l/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",r]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:a})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(L,{column:a,title:n("table.columns.status")}),e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{children:e.jsx(Br,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(ce,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:a})=>{const l=Gs.find(r=>r.value===a.getValue("status"));return l?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l.icon&&e.jsx(l.icon,{className:`h-4 w-4 text-${l.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`status.${Fx(l.value)}`)})]}),l.value===re.PENDING&&e.jsxs(bs,{modal:!0,children:[e.jsx(ys,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Vt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(us,{align:"end",className:"w-[140px]",children:[e.jsx(fe,{className:"cursor-pointer",onClick:async()=>{await Pd({trade_no:a.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(fe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await Ed({trade_no:a.original.trade_no}),s()},children:n("actions.cancel")})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.commission")}),cell:({row:a})=>{const l=a.getValue("commission_balance"),r=l?(l/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:l?`¥${r}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.commissionStatus")}),cell:({row:a})=>{const l=a.original.status,r=a.original.commission_balance,c=ot.find(o=>o.value===a.getValue("commission_status"));return r==0||!c?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:[c.icon&&e.jsx(c.icon,{className:`h-4 w-4 text-${c.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`commission.${zx(c.value)}`)})]}),c.value===ue.PENDING&&l===re.COMPLETED&&e.jsxs(bs,{modal:!0,children:[e.jsx(ys,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Vt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(us,{align:"end",className:"w-[120px]",children:[e.jsx(fe,{className:"cursor-pointer",onClick:async()=>{await tn({trade_no:a.original.trade_no,commission_status:ue.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(fe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await tn({trade_no:a.original.trade_no,commission_status:ue.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.createdAt")}),cell:({row:a})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:ve(a.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function $x(){const[s]=fr(),[n,a]=u.useState({}),[l,r]=u.useState({}),[c,o]=u.useState([]),[m,x]=u.useState([]),[i,d]=u.useState({pageIndex:0,pageSize:20});u.useEffect(()=>{const w=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([g,S])=>{const R=s.get(g);return R?{id:g,value:S==="number"?parseInt(R):R}:null}).filter(Boolean);w.length>0&&o(w)},[s]);const{refetch:p,data:C,isLoading:P}=ie({queryKey:["orderList",i,c,m],queryFn:()=>Td({pageSize:i.pageSize,current:i.pageIndex+1,filter:c,sort:m})}),f=Ze({data:C?.data??[],columns:Ax(p),state:{sorting:m,columnVisibility:l,rowSelection:n,columnFilters:c,pagination:i},rowCount:C?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:x,onColumnFiltersChange:o,onColumnVisibilityChange:r,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),onPaginationChange:d,getSortedRowModel:is(),getFacetedRowModel:_s(),getFacetedUniqueValues:ws(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(cs,{table:f,toolbar:e.jsx(Rx,{table:f,refetch:p}),showPagination:!0})}function qx(){const{t:s}=M("order");return e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx($e,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx($x,{})})]})]})}const Ux=Object.freeze(Object.defineProperty({__proto__:null,default:qx},Symbol.toStringTag,{value:"Module"}));function Hx({column:s,title:n,options:a}){const l=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(xs,{children:[e.jsx(hs,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(gt,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Se,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(c=>r.has(c.value)).map(c=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:c.label},c.value))})]})]})}),e.jsx(os,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Is,{children:[e.jsx($s,{placeholder:n}),e.jsxs(Vs,{children:[e.jsx(qs,{children:"No results found."}),e.jsx(Ke,{children:a.map(c=>{const o=r.has(c.value);return e.jsxs(Ie,{onSelect:()=>{o?r.delete(c.value):r.add(c.value);const m=Array.from(r);s?.setFilterValue(m.length?m:void 0)},children:[e.jsx("div",{className:N("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(zs,{className:N("h-4 w-4")})}),c.icon&&e.jsx(c.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${c.color}`}),e.jsx("span",{children:c.label}),l?.get(c.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(c.value)})]},c.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(st,{}),e.jsx(Ke,{children:e.jsx(Ie,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Kx=h.object({id:h.coerce.number().nullable().optional(),name:h.string().min(1,"请输入优惠券名称"),code:h.string().nullable(),type:h.coerce.number(),value:h.coerce.number(),started_at:h.coerce.number(),ended_at:h.coerce.number(),limit_use:h.union([h.string(),h.number()]).nullable(),limit_use_with_user:h.union([h.string(),h.number()]).nullable(),generate_count:h.coerce.number().nullable().optional(),limit_plan_ids:h.array(h.coerce.number()).default([]).nullable(),limit_period:h.array(h.nativeEnum(dt)).default([]).nullable()}).refine(s=>s.ended_at>s.started_at,{message:"结束时间必须晚于开始时间",path:["ended_at"]}),un={name:"",code:null,type:Ue.AMOUNT,value:0,started_at:Math.floor(Date.now()/1e3),ended_at:Math.floor(Date.now()/1e3)+7*24*60*60,limit_use:null,limit_use_with_user:null,limit_plan_ids:[],limit_period:[],generate_count:null};function tl({defaultValues:s,refetch:n,type:a="create",dialogTrigger:l=null,open:r,onOpenChange:c}){const{t:o}=M("coupon"),[m,x]=u.useState(!1),i=r??m,d=c??x,[p,C]=u.useState([]),P=je({resolver:Ne(Kx),defaultValues:s||un});u.useEffect(()=>{s&&P.reset(s)},[s,P]),u.useEffect(()=>{Us().then(({data:g})=>C(g))},[]);const f=g=>{if(!g)return;const S=(R,E)=>{const O=new Date(E*1e3);return R.setHours(O.getHours(),O.getMinutes(),O.getSeconds()),Math.floor(R.getTime()/1e3)};g.from&&P.setValue("started_at",S(g.from,P.watch("started_at"))),g.to&&P.setValue("ended_at",S(g.to,P.watch("ended_at")))},j=async g=>{const S=await Vd(g);if(g.generate_count&&S){const R=new Blob([S],{type:"text/csv;charset=utf-8;"}),E=document.createElement("a");E.href=window.URL.createObjectURL(R),E.download=`coupons_${new Date().getTime()}.csv`,E.click(),window.URL.revokeObjectURL(E.href)}d(!1),a==="create"&&P.reset(un),n()},w=(g,S)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:S}),e.jsx(k,{type:"datetime-local",step:"1",value:ve(P.watch(g),"YYYY-MM-DDTHH:mm:ss"),onChange:R=>{const E=new Date(R.target.value);P.setValue(g,Math.floor(E.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(be,{open:i,onOpenChange:d,children:[l&&e.jsx(Ge,{asChild:!0,children:l}),e.jsxs(ge,{className:"sm:max-w-[425px]",children:[e.jsx(we,{children:e.jsx(ye,{children:o(a==="create"?"form.add":"form.edit")})}),e.jsx(_e,{...P,children:e.jsxs("form",{onSubmit:P.handleSubmit(j),className:"space-y-4",children:[e.jsx(b,{control:P.control,name:"name",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:o("form.name.label")}),e.jsx(k,{placeholder:o("form.name.placeholder"),...g}),e.jsx(T,{})]})}),a==="create"&&e.jsx(b,{control:P.control,name:"generate_count",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:o("form.generateCount.label")}),e.jsx(k,{type:"number",min:0,placeholder:o("form.generateCount.placeholder"),...g,value:g.value===void 0?"":g.value,onChange:S=>g.onChange(S.target.value===""?"":parseInt(S.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:o("form.generateCount.description")}),e.jsx(T,{})]})}),(!P.watch("generate_count")||P.watch("generate_count")==null)&&e.jsx(b,{control:P.control,name:"code",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:o("form.code.label")}),e.jsx(k,{placeholder:o("form.code.placeholder"),...g,className:"h-9"}),e.jsx(z,{className:"text-xs",children:o("form.code.description")}),e.jsx(T,{})]})}),e.jsxs(v,{children:[e.jsx(y,{children:o("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(b,{control:P.control,name:"type",render:({field:g})=>e.jsxs(X,{value:g.value.toString(),onValueChange:S=>{const R=g.value,E=parseInt(S);g.onChange(E);const O=P.getValues("value");O&&(R===Ue.AMOUNT&&E===Ue.PERCENTAGE?P.setValue("value",O/100):R===Ue.PERCENTAGE&&E===Ue.AMOUNT&&P.setValue("value",O*100))},children:[e.jsx(Q,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(ee,{placeholder:o("form.type.placeholder")})}),e.jsx(J,{children:Object.entries(am).map(([S,R])=>e.jsx(U,{value:S,children:o(`table.toolbar.types.${S}`)},S))})]})}),e.jsx(b,{control:P.control,name:"value",render:({field:g})=>{const S=g.value==null?"":P.watch("type")===Ue.AMOUNT&&typeof g.value=="number"?(g.value/100).toString():g.value.toString();return e.jsx(k,{type:"number",placeholder:o("form.value.placeholder"),...g,value:S,onChange:R=>{const E=R.target.value;if(E===""){g.onChange("");return}const O=parseFloat(E);isNaN(O)||g.onChange(P.watch("type")===Ue.AMOUNT?Math.round(O*100):O)},step:"any",min:0,className:"flex-[2] rounded-none border-x-0 text-left"})}}),e.jsx("div",{className:"flex min-w-[40px] items-center justify-center rounded-md rounded-l-none border border-l-0 border-input bg-muted/50 px-3 font-medium text-muted-foreground",children:e.jsx("span",{children:P.watch("type")==Ue.AMOUNT?"¥":"%"})})]})]}),e.jsxs(v,{children:[e.jsx(y,{children:o("form.validity.label")}),e.jsxs(xs,{children:[e.jsx(hs,{asChild:!0,children:e.jsxs(D,{variant:"outline",className:N("w-full justify-start text-left font-normal",!P.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(pt,{className:"mr-2 h-4 w-4"}),ve(P.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",o("form.validity.to")," ",ve(P.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})}),e.jsxs(os,{className:"w-auto p-0",align:"start",children:[e.jsx("div",{className:"border-b border-border",children:e.jsx(Hs,{mode:"range",selected:{from:new Date(P.watch("started_at")*1e3),to:new Date(P.watch("ended_at")*1e3)},onSelect:f,numberOfMonths:2})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-4",children:[w("started_at",o("table.validity.startTime")),e.jsx("div",{className:"mt-6 text-sm text-muted-foreground",children:o("form.validity.to")}),w("ended_at",o("table.validity.endTime"))]})})]})]}),e.jsx(T,{})]}),e.jsx(b,{control:P.control,name:"limit_use",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:o("form.limitUse.label")}),e.jsx(k,{type:"number",min:0,placeholder:o("form.limitUse.placeholder"),...g,value:g.value===null?"":g.value,onChange:S=>g.onChange(S.target.value===""?null:parseInt(S.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:o("form.limitUse.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:P.control,name:"limit_use_with_user",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:o("form.limitUseWithUser.label")}),e.jsx(k,{type:"number",min:0,placeholder:o("form.limitUseWithUser.placeholder"),...g,value:g.value===null?"":g.value,onChange:S=>g.onChange(S.target.value===""?null:parseInt(S.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:o("form.limitUseWithUser.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:P.control,name:"limit_period",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:o("form.limitPeriod.label")}),e.jsx(ht,{options:Object.entries(dt).filter(([S])=>isNaN(Number(S))).map(([S,R])=>({label:o(`coupon:period.${R}`),value:S})),onChange:S=>{if(S.length===0){g.onChange([]);return}const R=S.map(E=>dt[E.value]);g.onChange(R)},value:(g.value||[]).map(S=>({label:o(`coupon:period.${S}`),value:Object.entries(dt).find(([R,E])=>E===S)?.[0]||""})),placeholder:o("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:o("form.limitPeriod.empty")})}),e.jsx(z,{className:"text-xs",children:o("form.limitPeriod.description")}),e.jsx(T,{})]})}),e.jsx(b,{control:P.control,name:"limit_plan_ids",render:({field:g})=>e.jsxs(v,{children:[e.jsx(y,{children:o("form.limitPlan.label")}),e.jsx(ht,{options:p?.map(S=>({label:S.name,value:S.id.toString()}))||[],onChange:S=>g.onChange(S.map(R=>Number(R.value))),value:(p||[]).filter(S=>(g.value||[]).includes(S.id)).map(S=>({label:S.name,value:S.id.toString()})),placeholder:o("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:o("form.limitPlan.empty")})}),e.jsx(T,{})]})}),e.jsx(Ae,{children:e.jsx(D,{type:"submit",disabled:P.formState.isSubmitting,children:P.formState.isSubmitting?o("form.submit.saving"):o("form.submit.save")})})]})})]})]})}function Bx({table:s,refetch:n}){const a=s.getState().columnFilters.length>0,{t:l}=M("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tl,{refetch:n,dialogTrigger:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Re,{icon:"ion:add"}),e.jsx("div",{children:l("form.add")})]})}),e.jsx(k,{placeholder:l("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:r=>s.getColumn("name")?.setFilterValue(r.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(Hx,{column:s.getColumn("type"),title:l("table.toolbar.type"),options:[{value:Ue.AMOUNT,label:l(`table.toolbar.types.${Ue.AMOUNT}`)},{value:Ue.PERCENTAGE,label:l(`table.toolbar.types.${Ue.PERCENTAGE}`)}]}),a&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("table.toolbar.reset"),e.jsx(Ye,{className:"ml-2 h-4 w-4"})]})]})}const al=u.createContext(void 0);function Gx({children:s,refetch:n}){const[a,l]=u.useState(!1),[r,c]=u.useState(null),o=x=>{c(x),l(!0)},m=()=>{l(!1),c(null)};return e.jsxs(al.Provider,{value:{isOpen:a,currentCoupon:r,openEdit:o,closeEdit:m},children:[s,r&&e.jsx(tl,{defaultValues:r,refetch:n,type:"edit",open:a,onOpenChange:l})]})}function Wx(){const s=u.useContext(al);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const Yx=s=>{const{t:n}=M("coupon");return[{accessorKey:"id",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.id")}),cell:({row:a})=>e.jsx(K,{children:a.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.show")}),cell:({row:a})=>e.jsx(W,{defaultChecked:a.original.show,onCheckedChange:l=>{Md({id:a.original.id,show:l}).then(({data:r})=>!r&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.name")}),cell:({row:a})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:a.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.type")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:n(`table.toolbar.types.${a.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.code")}),cell:({row:a})=>e.jsx(K,{variant:"secondary",children:a.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.limitUse")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:a.original.limit_use===null?n("table.validity.unlimited"):a.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.limitUseWithUser")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:a.original.limit_use_with_user===null?n("table.validity.noLimit"):a.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:a})=>e.jsx(L,{column:a,title:n("table.columns.validity")}),cell:({row:a})=>{const[l,r]=u.useState(!1),c=Date.now(),o=a.original.started_at*1e3,m=a.original.ended_at*1e3,x=c>m,i=c<o,d=Math.ceil((m-c)/(1e3*60*60*24)),C=x?{label:n("table.validity.expired",{days:Math.abs(d)}),color:"bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"}:i?{label:n("table.validity.notStarted",{days:Math.abs(Math.ceil((o-c)/(1e3*60*60*24)))}),color:"bg-yellow-50 text-yellow-600 dark:bg-yellow-500/10 dark:text-yellow-400"}:{label:n("table.validity.remaining",{days:d}),color:"bg-green-50 text-green-600 dark:bg-green-500/10 dark:text-green-400"};return e.jsxs(Dr,{open:l,onOpenChange:r,children:[e.jsx(Pr,{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:N("whitespace-nowrap rounded-md px-1.5 py-0.5 text-xs font-medium",C.color),children:C.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:ve(a.original.started_at,"MM/DD HH:mm")}),e.jsx("div",{className:"shrink-0 opacity-30",children:"→"}),e.jsx("div",{className:"truncate text-xs",children:ve(a.original.ended_at,"MM/DD HH:mm")})]})]}),e.jsx(Uo,{className:N("h-3.5 w-3.5 shrink-0 text-muted-foreground/50 transition-transform duration-200",l&&"rotate-180")})]})}),e.jsx(Er,{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:n("table.validity.startTime")}),e.jsx("span",{className:"font-medium text-foreground",children:ve(a.original.started_at,"YYYY/MM/DD HH:mm")})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{children:n("table.validity.endTime")}),e.jsx("span",{className:"font-medium text-foreground",children:ve(a.original.ended_at,"YYYY/MM/DD HH:mm")})]})]})})})]})},enableSorting:!1,size:8e3},{id:"actions",header:({column:a})=>e.jsx(L,{className:"justify-end",column:a,title:n("table.columns.actions")}),cell:({row:a})=>{const{openEdit:l}=Wx();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>l(a.original),children:[e.jsx(As,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),e.jsx(Be,{title:n("table.actions.deleteConfirm.title"),description:n("table.actions.deleteConfirm.description"),confirmText:n("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{Od({id:a.original.id}).then(({data:r})=>{r&&($.success("删除成功"),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ns,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("table.actions.delete")})]})})]})}}]};function Qx(){const[s,n]=u.useState({}),[a,l]=u.useState({}),[r,c]=u.useState([]),[o,m]=u.useState([]),[x,i]=u.useState({pageIndex:0,pageSize:20}),{refetch:d,data:p}=ie({queryKey:["couponList",x,r,o],queryFn:()=>Id({pageSize:x.pageSize,current:x.pageIndex+1,filter:r,sort:o})}),C=Ze({data:p?.data??[],columns:Yx(d),state:{sorting:o,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:x},pageCount:Math.ceil((p?.total??0)/x.pageSize),rowCount:p?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:c,onColumnVisibilityChange:l,onPaginationChange:i,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),getSortedRowModel:is(),getFacetedRowModel:_s(),getFacetedUniqueValues:ws(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Gx,{refetch:d,children:e.jsx("div",{className:"space-y-4",children:e.jsx(cs,{table:C,toolbar:e.jsx(Bx,{table:C,refetch:d})})})})}function Jx(){const{t:s}=M("coupon");return e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx($e,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Qx,{})})]})]})}const Zx=Object.freeze(Object.defineProperty({__proto__:null,default:Jx},Symbol.toStringTag,{value:"Module"})),Xx=1,eh=1e6;let da=0;function sh(){return da=(da+1)%Number.MAX_SAFE_INTEGER,da.toString()}const ma=new Map,xn=s=>{if(ma.has(s))return;const n=setTimeout(()=>{ma.delete(s),mt({type:"REMOVE_TOAST",toastId:s})},eh);ma.set(s,n)},th=(s,n)=>{switch(n.type){case"ADD_TOAST":return{...s,toasts:[n.toast,...s.toasts].slice(0,Xx)};case"UPDATE_TOAST":return{...s,toasts:s.toasts.map(a=>a.id===n.toast.id?{...a,...n.toast}:a)};case"DISMISS_TOAST":{const{toastId:a}=n;return a?xn(a):s.toasts.forEach(l=>{xn(l.id)}),{...s,toasts:s.toasts.map(l=>l.id===a||a===void 0?{...l,open:!1}:l)}}case"REMOVE_TOAST":return n.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(a=>a.id!==n.toastId)}}},Pt=[];let Et={toasts:[]};function mt(s){Et=th(Et,s),Pt.forEach(n=>{n(Et)})}function ah({...s}){const n=sh(),a=r=>mt({type:"UPDATE_TOAST",toast:{...r,id:n}}),l=()=>mt({type:"DISMISS_TOAST",toastId:n});return mt({type:"ADD_TOAST",toast:{...s,id:n,open:!0,onOpenChange:r=>{r||l()}}}),{id:n,dismiss:l,update:a}}function nl(){const[s,n]=u.useState(Et);return u.useEffect(()=>(Pt.push(n),()=>{const a=Pt.indexOf(n);a>-1&&Pt.splice(a,1)}),[s]),{...s,toast:ah,dismiss:a=>mt({type:"DISMISS_TOAST",toastId:a})}}function nh({open:s,onOpenChange:n,table:a}){const{t:l}=M("user"),{toast:r}=nl(),[c,o]=u.useState(!1),[m,x]=u.useState(""),[i,d]=u.useState(""),p=async()=>{if(!m||!i){r({title:l("messages.error"),description:l("messages.send_mail.required_fields"),variant:"destructive"});return}try{o(!0),await zt.sendMail({subject:m,content:i,filter:a.getState().columnFilters,sort:a.getState().sorting[0]?.id,sort_type:a.getState().sorting[0]?.desc?"DESC":"ASC"}),r({title:l("messages.success"),description:l("messages.send_mail.success")}),n(!1),x(""),d("")}catch{r({title:l("messages.error"),description:l("messages.send_mail.failed"),variant:"destructive"})}finally{o(!1)}};return e.jsx(be,{open:s,onOpenChange:n,children:e.jsxs(ge,{className:"sm:max-w-[500px]",children:[e.jsxs(we,{children:[e.jsx(ye,{children:l("send_mail.title")}),e.jsx(De,{children:l("send_mail.description")})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"subject",className:"text-right",children:l("send_mail.subject")}),e.jsx(k,{id:"subject",value:m,onChange:C=>x(C.target.value),className:"col-span-3"})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"content",className:"text-right",children:l("send_mail.content")}),e.jsx(fs,{id:"content",value:i,onChange:C=>d(C.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(Ae,{children:e.jsx(G,{type:"submit",onClick:p,disabled:c,children:l(c?"send_mail.sending":"send_mail.send")})})]})})}const rh=h.object({email_prefix:h.string().optional(),email_suffix:h.string().min(1),password:h.string().optional(),expired_at:h.number().optional().nullable(),plan_id:h.number().nullable(),generate_count:h.number().optional().nullable()}).refine(s=>s.generate_count===null?s.email_prefix!==void 0&&s.email_prefix!=="":!0,{message:"Email prefix is required when generate_count is null",path:["email_prefix"]}),lh={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0};function ih({refetch:s}){const{t:n}=M("user"),[a,l]=u.useState(!1),r=je({resolver:Ne(rh),defaultValues:lh,mode:"onChange"}),[c,o]=u.useState([]);return u.useEffect(()=>{a&&Us().then(({data:m})=>{m&&o(m)})},[a]),e.jsxs(be,{open:a,onOpenChange:l,children:[e.jsx(Ge,{asChild:!0,children:e.jsxs(G,{size:"sm",variant:"outline",className:"space-x-2 gap-0",children:[e.jsx(Re,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(ge,{className:"sm:max-w-[425px]",children:[e.jsxs(we,{children:[e.jsx(ye,{children:n("generate.title")}),e.jsx(De,{})]}),e.jsxs(_e,{...r,children:[e.jsxs(v,{children:[e.jsx(y,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!r.watch("generate_count")&&e.jsx(b,{control:r.control,name:"email_prefix",render:({field:m})=>e.jsx(k,{className:"flex-[5] rounded-r-none",placeholder:n("generate.form.email_prefix"),...m})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${r.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(b,{control:r.control,name:"email_suffix",render:({field:m})=>e.jsx(k,{className:"flex-[4] rounded-l-none",placeholder:n("generate.form.email_domain"),...m})})]})]}),e.jsx(b,{control:r.control,name:"password",render:({field:m})=>e.jsxs(v,{children:[e.jsx(y,{children:n("generate.form.password")}),e.jsx(k,{placeholder:n("generate.form.password_placeholder"),...m}),e.jsx(T,{})]})}),e.jsx(b,{control:r.control,name:"expired_at",render:({field:m})=>e.jsxs(v,{className:"flex flex-col",children:[e.jsx(y,{children:n("generate.form.expire_time")}),e.jsxs(xs,{children:[e.jsx(hs,{asChild:!0,children:e.jsx(_,{children:e.jsxs(G,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!m.value&&"text-muted-foreground"),children:[m.value?ve(m.value):e.jsx("span",{children:n("generate.form.expire_time_placeholder")}),e.jsx(pt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(os,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(Ho,{asChild:!0,children:e.jsx(G,{variant:"outline",className:"w-full",onClick:()=>{m.onChange(null)},children:n("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Hs,{mode:"single",selected:m.value?new Date(m.value*1e3):void 0,onSelect:x=>{x&&m.onChange(x?.getTime()/1e3)}})})]})]})]})}),e.jsx(b,{control:r.control,name:"plan_id",render:({field:m})=>e.jsxs(v,{children:[e.jsx(y,{children:n("generate.form.subscription")}),e.jsx(_,{children:e.jsxs(X,{value:m.value?m.value.toString():"null",onValueChange:x=>m.onChange(x==="null"?null:parseInt(x)),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(J,{children:[e.jsx(U,{value:"null",children:n("generate.form.subscription_none")}),c.map(x=>e.jsx(U,{value:x.id.toString(),children:x.name},x.id))]})]})})]})}),!r.watch("email_prefix")&&e.jsx(b,{control:r.control,name:"generate_count",render:({field:m})=>e.jsxs(v,{children:[e.jsx(y,{children:n("generate.form.generate_count")}),e.jsx(k,{type:"number",placeholder:n("generate.form.generate_count_placeholder"),value:m.value||"",onChange:x=>m.onChange(x.target.value?parseInt(x.target.value):null)})]})})]}),e.jsxs(Ae,{children:[e.jsx(G,{variant:"outline",onClick:()=>l(!1),children:n("generate.form.cancel")}),e.jsx(G,{onClick:()=>r.handleSubmit(m=>{Ad(m).then(({data:x})=>{x&&($.success(n("generate.form.success")),r.reset(),s(),l(!1))})})(),children:n("generate.form.submit")})]})]})]})}const rl=gn,ll=jn,oh=vn,il=u.forwardRef(({className:s,...n},a)=>e.jsx(Lt,{className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:a}));il.displayName=Lt.displayName;const ch=Fs("fixed overflow-y-scroll z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-md",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-md"}},defaultVariants:{side:"right"}}),Aa=u.forwardRef(({side:s="right",className:n,children:a,...l},r)=>e.jsxs(oh,{children:[e.jsx(il,{}),e.jsxs(At,{ref:r,className:N(ch({side:s}),n),...l,children:[e.jsxs(wa,{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(Ye,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),a]})]}));Aa.displayName=At.displayName;const $a=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-2 text-center sm:text-left",s),...n});$a.displayName="SheetHeader";const ol=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});ol.displayName="SheetFooter";const qa=u.forwardRef(({className:s,...n},a)=>e.jsx($t,{ref:a,className:N("text-lg font-semibold text-foreground",s),...n}));qa.displayName=$t.displayName;const Ua=u.forwardRef(({className:s,...n},a)=>e.jsx(qt,{ref:a,className:N("text-sm text-muted-foreground",s),...n}));Ua.displayName=qt.displayName;function dh({table:s,refetch:n,permissionGroups:a=[],subscriptionPlans:l=[]}){const{t:r}=M("user"),{toast:c}=nl(),o=s.getState().columnFilters.length>0,[m,x]=u.useState([]),[i,d]=u.useState(!1),[p,C]=u.useState(!1),[P,f]=u.useState(!1),[j,w]=u.useState(!1),g=async()=>{try{const B=await zt.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),ae=window.URL.createObjectURL(new Blob([B.data])),A=document.createElement("a");A.href=ae,A.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(A),A.click(),A.remove(),window.URL.revokeObjectURL(ae),c({title:r("messages.success"),description:r("messages.export.success")})}catch{c({title:r("messages.error"),description:r("messages.export.failed"),variant:"destructive"})}},S=async()=>{try{w(!0),await zt.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),c({title:r("messages.success"),description:r("messages.batch_ban.success")}),n()}catch{c({title:r("messages.error"),description:r("messages.batch_ban.failed"),variant:"destructive"})}finally{w(!1),f(!1)}},R=[{label:r("filter.fields.email"),value:"email",type:"text",operators:[{label:r("filter.operators.contains"),value:"contains"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.id"),value:"id",type:"number",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.plan_id"),value:"plan_id",type:"select",operators:[{label:r("filter.operators.eq"),value:"eq"}],useOptions:!0},{label:r("filter.fields.transfer_enable"),value:"transfer_enable",type:"number",unit:"GB",operators:[{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.lt"),value:"lt"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.total_used"),value:"total_used",type:"number",unit:"GB",operators:[{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.lt"),value:"lt"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.online_count"),value:"online_count",type:"number",operators:[{label:r("filter.operators.eq"),value:"eq"},{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.lt"),value:"lt"}]},{label:r("filter.fields.expired_at"),value:"expired_at",type:"date",operators:[{label:r("filter.operators.lt"),value:"lt"},{label:r("filter.operators.gt"),value:"gt"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.uuid"),value:"uuid",type:"text",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.token"),value:"token",type:"text",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.banned"),value:"banned",type:"select",operators:[{label:r("filter.operators.eq"),value:"eq"}],options:[{label:r("filter.status.normal"),value:"0"},{label:r("filter.status.banned"),value:"1"}]},{label:r("filter.fields.remark"),value:"remark",type:"text",operators:[{label:r("filter.operators.contains"),value:"contains"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.inviter_email"),value:"inviter_email",type:"text",operators:[{label:r("filter.operators.contains"),value:"contains"},{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.invite_user_id"),value:"invite_user_id",type:"number",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.is_admin"),value:"is_admin",type:"boolean",operators:[{label:r("filter.operators.eq"),value:"eq"}]},{label:r("filter.fields.is_staff"),value:"is_staff",type:"boolean",operators:[{label:r("filter.operators.eq"),value:"eq"}]}],E=B=>B*1024*1024*1024,O=B=>B/(1024*1024*1024),q=()=>{x([...m,{field:"",operator:"",value:""}])},te=B=>{x(m.filter((ae,A)=>A!==B))},F=(B,ae,A)=>{const I=[...m];if(I[B]={...I[B],[ae]:A},ae==="field"){const Y=R.find(ne=>ne.value===A);Y&&(I[B].operator=Y.operators[0].value,I[B].value=Y.type==="boolean"?!1:"")}x(I)},se=(B,ae)=>{const A=R.find(I=>I.value===B.field);if(!A)return null;switch(A.type){case"text":return e.jsx(k,{placeholder:r("filter.sheet.value"),value:B.value,onChange:I=>F(ae,"value",I.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(k,{type:"number",placeholder:r("filter.sheet.value_number",{unit:A.unit}),value:A.unit==="GB"?O(B.value||0):B.value,onChange:I=>{const Y=Number(I.target.value);F(ae,"value",A.unit==="GB"?E(Y):Y)}}),A.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:A.unit})]});case"date":return e.jsx(Hs,{mode:"single",selected:B.value,onSelect:I=>F(ae,"value",I),className:"rounded-md border"});case"select":return e.jsxs(X,{value:B.value,onValueChange:I=>F(ae,"value",I),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:r("filter.sheet.value")})}),e.jsx(J,{children:A.useOptions?l.map(I=>e.jsx(U,{value:I.value.toString(),children:I.label},I.value)):A.options?.map(I=>e.jsx(U,{value:I.value.toString(),children:I.label},I.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(W,{checked:B.value,onCheckedChange:I=>F(ae,"value",I)}),e.jsx(Ot,{children:B.value?r("filter.boolean.true"):r("filter.boolean.false")})]});default:return null}},qe=()=>{const B=m.filter(ae=>ae.field&&ae.operator&&ae.value!=="").map(ae=>{const A=R.find(Y=>Y.value===ae.field);let I=ae.value;return ae.operator==="contains"?{id:ae.field,value:I}:(A?.type==="date"&&I instanceof Date&&(I=Math.floor(I.getTime()/1e3)),A?.type==="boolean"&&(I=I?1:0),{id:ae.field,value:`${ae.operator}:${I}`})});s.setColumnFilters(B),d(!1)};return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-2",children:[e.jsx(ih,{refetch:n}),e.jsx(k,{placeholder:r("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:B=>s.getColumn("email")?.setFilterValue(B.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(rl,{open:i,onOpenChange:d,children:[e.jsx(ll,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Ko,{className:"mr-2 h-4 w-4"}),r("filter.advanced"),m.length>0&&e.jsx(K,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:m.length})]})}),e.jsxs(Aa,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs($a,{children:[e.jsx(qa,{children:r("filter.sheet.title")}),e.jsx(Ua,{children:r("filter.sheet.description")})]}),e.jsxs("div",{className:"mt-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:r("filter.sheet.conditions")}),e.jsx(D,{variant:"outline",size:"sm",onClick:q,children:r("filter.sheet.add")})]}),e.jsx(Xs,{className:"h-[calc(100vh-280px)] pr-4",children:e.jsx("div",{className:"space-y-4",children:m.map((B,ae)=>e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ot,{children:r("filter.sheet.condition",{number:ae+1})}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>te(ae),children:e.jsx(Ye,{className:"h-4 w-4"})})]}),e.jsxs(X,{value:B.field,onValueChange:A=>F(ae,"field",A),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:r("filter.sheet.field")})}),e.jsx(J,{children:R.map(A=>e.jsx(U,{value:A.value,children:A.label},A.value))})]}),B.field&&e.jsxs(X,{value:B.operator,onValueChange:A=>F(ae,"operator",A),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:r("filter.sheet.operator")})}),e.jsx(J,{children:R.find(A=>A.value===B.field)?.operators.map(A=>e.jsx(U,{value:A.value,children:A.label},A.value))})]}),B.field&&B.operator&&se(B,ae)]},ae))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(D,{variant:"outline",onClick:()=>{x([]),d(!1)},children:r("filter.sheet.reset")}),e.jsx(D,{onClick:qe,children:r("filter.sheet.apply")})]})]})]})]}),o&&e.jsxs(D,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),x([])},className:"h-8 px-2 lg:px-3",children:[r("reset"),e.jsx(Ye,{className:"ml-2 h-4 w-4"})]}),e.jsxs(bs,{children:[e.jsx(ys,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:r("actions.title")})}),e.jsxs(us,{children:[e.jsx(fe,{onClick:()=>C(!0),children:r("actions.send_email")}),e.jsx(fe,{onClick:g,children:r("actions.export_csv")}),e.jsx(Zs,{}),e.jsx(fe,{onClick:()=>f(!0),className:"text-red-600 focus:text-red-600",children:r("actions.batch_ban")})]})]})]}),e.jsx(nh,{open:p,onOpenChange:C,table:s}),e.jsx(Fa,{open:P,onOpenChange:f,children:e.jsxs(Wt,{children:[e.jsxs(Yt,{children:[e.jsx(Jt,{children:r("actions.confirm_ban.title")}),e.jsx(Zt,{children:r(o?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(Qt,{children:[e.jsx(ea,{disabled:j,children:r("actions.confirm_ban.cancel")}),e.jsx(Xt,{onClick:S,disabled:j,className:"bg-red-600 hover:bg-red-700 focus:ring-red-600",children:r(j?"actions.confirm_ban.banning":"actions.confirm_ban.confirm")})]})]})})]})}const mh=h.object({id:h.number(),email:h.string().email(),invite_user_email:h.string().email().nullable().optional(),password:h.string().optional().nullable(),balance:h.coerce.number(),commission_balance:h.coerce.number(),u:h.number(),d:h.number(),transfer_enable:h.number(),expired_at:h.number().nullable(),plan_id:h.number().nullable(),banned:h.number(),commission_type:h.number(),commission_rate:h.number().nullable(),discount:h.number().nullable(),speed_limit:h.number().nullable(),device_limit:h.number().nullable(),is_admin:h.number(),is_staff:h.number(),remarks:h.string().nullable()}),cl=u.createContext(void 0);function uh({children:s,defaultValues:n,open:a,onOpenChange:l}){const[r,c]=u.useState(!1),[o,m]=u.useState(!1),[x,i]=u.useState([]),d=je({resolver:Ne(mh),defaultValues:n,mode:"onChange"});u.useEffect(()=>{a!==void 0&&c(a)},[a]);const p=C=>{c(C),l?.(C)};return e.jsx(cl.Provider,{value:{form:d,formOpen:r,setFormOpen:p,datePickerOpen:o,setDatePickerOpen:m,planList:x,setPlanList:i},children:s})}function xh(){const s=u.useContext(cl);if(!s)throw new Error("useUserForm must be used within a UserFormProvider");return s}function hh({refetch:s}){const{t:n}=M("user"),{form:a,formOpen:l,setFormOpen:r,datePickerOpen:c,setDatePickerOpen:o,planList:m,setPlanList:x}=xh();return u.useEffect(()=>{l&&Us().then(({data:i})=>{x(i)})},[l,x]),e.jsxs(_e,{...a,children:[e.jsx(b,{control:a.control,name:"email",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.email")}),e.jsx(_,{children:e.jsx(k,{...i,placeholder:n("edit.form.email_placeholder")})}),e.jsx(T,{...i})]})}),e.jsx(b,{control:a.control,name:"invite_user_email",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.inviter_email")}),e.jsx(_,{children:e.jsx(k,{value:i.value||"",onChange:d=>i.onChange(d.target.value?d.target.value:null),placeholder:n("edit.form.inviter_email_placeholder")})}),e.jsx(T,{...i})]})}),e.jsx(b,{control:a.control,name:"password",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.password")}),e.jsx(_,{children:e.jsx(k,{value:i.value||"",onChange:i.onChange,placeholder:n("edit.form.password_placeholder")})}),e.jsx(T,{...i})]})}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsx(b,{control:a.control,name:"balance",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.balance")}),e.jsx(_,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:i.value||"",onChange:i.onChange,placeholder:n("edit.form.balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(T,{...i})]})}),e.jsx(b,{control:a.control,name:"commission_balance",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.commission_balance")}),e.jsx(_,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:i.value||"",onChange:i.onChange,placeholder:n("edit.form.commission_balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(T,{...i})]})}),e.jsx(b,{control:a.control,name:"u",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.upload")}),e.jsx(_,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{value:i.value/1024/1024/1024||"",onChange:d=>i.onChange(parseInt(d.target.value)*1024*1024*1024),placeholder:n("edit.form.upload_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(T,{...i})]})}),e.jsx(b,{control:a.control,name:"d",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.download")}),e.jsx(_,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:i.value/1024/1024/1024||"",onChange:d=>i.onChange(parseInt(d.target.value)*1024*1024*1024),placeholder:n("edit.form.download_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(T,{...i})]})})]}),e.jsx(b,{control:a.control,name:"transfer_enable",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.total_traffic")}),e.jsx(_,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:i.value/1024/1024/1024||"",onChange:d=>i.onChange(parseInt(d.target.value)*1024*1024*1024),placeholder:n("edit.form.total_traffic_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(T,{})]})}),e.jsx(b,{control:a.control,name:"expired_at",render:({field:i})=>e.jsxs(v,{className:"flex flex-col",children:[e.jsx(y,{children:n("edit.form.expire_time")}),e.jsxs(xs,{open:c,onOpenChange:o,children:[e.jsx(hs,{asChild:!0,children:e.jsx(_,{children:e.jsxs(D,{type:"button",variant:"outline",className:N("w-full pl-3 text-left font-normal",!i.value&&"text-muted-foreground"),onClick:()=>o(!0),children:[i.value?ve(i.value):e.jsx("span",{children:n("edit.form.expire_time_placeholder")}),e.jsx(pt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(os,{className:"w-auto p-0",align:"start",side:"top",sideOffset:4,onInteractOutside:d=>{d.preventDefault()},onEscapeKeyDown:d=>{d.preventDefault()},children:e.jsxs("div",{className:"flex flex-col space-y-3 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(D,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{i.onChange(null),o(!1)},children:n("edit.form.expire_time_permanent")}),e.jsx(D,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const d=new Date;d.setMonth(d.getMonth()+1),d.setHours(23,59,59,999),i.onChange(Math.floor(d.getTime()/1e3)),o(!1)},children:n("edit.form.expire_time_1month")}),e.jsx(D,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const d=new Date;d.setMonth(d.getMonth()+3),d.setHours(23,59,59,999),i.onChange(Math.floor(d.getTime()/1e3)),o(!1)},children:n("edit.form.expire_time_3months")})]}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Hs,{mode:"single",selected:i.value?new Date(i.value*1e3):void 0,onSelect:d=>{if(d){const p=new Date(i.value?i.value*1e3:Date.now());d.setHours(p.getHours(),p.getMinutes(),p.getSeconds()),i.onChange(Math.floor(d.getTime()/1e3))}},disabled:d=>d<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:n("edit.form.expire_time_specific")}),e.jsx(D,{type:"button",variant:"ghost",size:"sm",onClick:()=>{const d=new Date;d.setHours(23,59,59,999),i.onChange(Math.floor(d.getTime()/1e3))},className:"h-6 px-2 text-xs",children:n("edit.form.expire_time_today")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{type:"datetime-local",step:"1",value:ve(i.value,"YYYY-MM-DDTHH:mm:ss"),onChange:d=>{const p=new Date(d.target.value);isNaN(p.getTime())||i.onChange(Math.floor(p.getTime()/1e3))},className:"flex-1"}),e.jsx(D,{type:"button",variant:"outline",onClick:()=>o(!1),children:n("edit.form.expire_time_confirm")})]})]})]})})]}),e.jsx(T,{})]})}),e.jsx(b,{control:a.control,name:"plan_id",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.subscription")}),e.jsx(_,{children:e.jsxs(X,{value:i.value?i.value.toString():"null",onValueChange:d=>i.onChange(d==="null"?null:parseInt(d)),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:n("edit.form.subscription_none")})}),e.jsxs(J,{children:[e.jsx(U,{value:"null",children:n("edit.form.subscription_none")}),m.map(d=>e.jsx(U,{value:d.id.toString(),children:d.name},d.id))]})]})})]})}),e.jsx(b,{control:a.control,name:"banned",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.account_status")}),e.jsx(_,{children:e.jsxs(X,{value:i.value.toString(),onValueChange:d=>i.onChange(parseInt(d)),children:[e.jsx(Q,{children:e.jsx(ee,{})}),e.jsxs(J,{children:[e.jsx(U,{value:"1",children:n("columns.status_text.banned")}),e.jsx(U,{value:"0",children:n("columns.status_text.normal")})]})]})})]})}),e.jsx(b,{control:a.control,name:"commission_type",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.commission_type")}),e.jsx(_,{children:e.jsxs(X,{value:i.value.toString(),onValueChange:d=>i.onChange(parseInt(d)),children:[e.jsx(Q,{children:e.jsx(ee,{placeholder:n("edit.form.subscription_none")})}),e.jsxs(J,{children:[e.jsx(U,{value:"0",children:n("edit.form.commission_type_system")}),e.jsx(U,{value:"1",children:n("edit.form.commission_type_cycle")}),e.jsx(U,{value:"2",children:n("edit.form.commission_type_onetime")})]})]})})]})}),e.jsx(b,{control:a.control,name:"commission_rate",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.commission_rate")}),e.jsx(_,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:i.value||"",onChange:d=>i.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.commission_rate_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})})]})}),e.jsx(b,{control:a.control,name:"discount",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.discount")}),e.jsx(_,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:i.value||"",onChange:d=>i.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.discount_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})}),e.jsx(T,{})]})}),e.jsx(b,{control:a.control,name:"speed_limit",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.speed_limit")}),e.jsx(_,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:i.value||"",onChange:d=>i.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.speed_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"Mbps"})]})}),e.jsx(T,{})]})}),e.jsx(b,{control:a.control,name:"device_limit",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.device_limit")}),e.jsx(_,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:i.value||"",onChange:d=>i.onChange(parseInt(d.currentTarget.value)||null),placeholder:n("edit.form.device_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"台"})]})}),e.jsx(T,{})]})}),e.jsx(b,{control:a.control,name:"is_admin",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.is_admin")}),e.jsx("div",{className:"py-2",children:e.jsx(_,{children:e.jsx(W,{checked:i.value===1,onCheckedChange:d=>i.onChange(d?1:0)})})})]})}),e.jsx(b,{control:a.control,name:"is_staff",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.is_staff")}),e.jsx("div",{className:"py-2",children:e.jsx(_,{children:e.jsx(W,{checked:i.value===1,onCheckedChange:d=>i.onChange(d?1:0)})})})]})}),e.jsx(b,{control:a.control,name:"remarks",render:({field:i})=>e.jsxs(v,{children:[e.jsx(y,{children:n("edit.form.remarks")}),e.jsx(_,{children:e.jsx(fs,{className:"h-24",value:i.value||"",onChange:d=>i.onChange(d.currentTarget.value??null),placeholder:n("edit.form.remarks_placeholder")})}),e.jsx(T,{})]})}),e.jsxs(ol,{children:[e.jsx(D,{variant:"outline",onClick:()=>r(!1),children:n("edit.form.cancel")}),e.jsx(D,{type:"submit",onClick:()=>{a.handleSubmit(i=>{zd(i).then(({data:d})=>{d&&($.success(n("edit.form.success")),r(!1),s())})})()},children:n("edit.form.submit")})]})]})}function dl({refetch:s,defaultValues:n,dialogTrigger:a=e.jsxs(D,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(gt,{className:"mr-2 h-4 w-4"}),t("edit.button")]})}){const{t:l}=M("user"),[r,c]=u.useState(!1);return e.jsx(uh,{defaultValues:n,open:r,onOpenChange:c,children:e.jsxs(rl,{open:r,onOpenChange:c,children:[e.jsx(ll,{asChild:!0,children:a}),e.jsxs(Aa,{className:"max-w-[90%] space-y-4",children:[e.jsxs($a,{children:[e.jsx(qa,{children:l("edit.title")}),e.jsx(Ua,{})]}),e.jsx(hh,{refetch:s})]})]})})}const ml=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"})}),ul=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"})}),fh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),ph=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"})}),ua=[{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:_c(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ml,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:ds(s.original.u)})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ul,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:ds(s.original.d)})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const n=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(K,{variant:"outline",className:"font-mono",children:[n,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const n=s.original.u+s.original.d;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:ds(n)})}}];function xl({user_id:s,dialogTrigger:n}){const{t:a}=M(["traffic"]),[l,r]=u.useState(!1),[c,o]=u.useState({pageIndex:0,pageSize:20}),{data:m,isLoading:x}=ie({queryKey:["userStats",s,c,l],queryFn:()=>l?$d({user_id:s,pageSize:c.pageSize,page:c.pageIndex+1}):null}),i=Ze({data:m?.data??[],columns:ua,pageCount:Math.ceil((m?.total??0)/c.pageSize),state:{pagination:c},manualPagination:!0,getCoreRowModel:Xe(),onPaginationChange:o});return e.jsxs(be,{open:l,onOpenChange:r,children:[e.jsx(Ge,{asChild:!0,children:n}),e.jsxs(ge,{className:"sm:max-w-[700px]",children:[e.jsx(we,{children:e.jsx(ye,{children:a("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Ia,{children:[e.jsx(Va,{children:i.getHeaderGroups().map(d=>e.jsx(Ps,{children:d.headers.map(p=>e.jsx(Ma,{className:N("h-10 px-2 text-xs",p.id==="total"&&"text-right"),children:p.isPlaceholder?null:Rt(p.column.columnDef.header,p.getContext())},p.id))},d.id))}),e.jsx(Oa,{children:x?Array.from({length:c.pageSize}).map((d,p)=>e.jsx(Ps,{children:Array.from({length:ua.length}).map((C,P)=>e.jsx(Ys,{className:"p-2",children:e.jsx(oe,{className:"h-6 w-full"})},P))},p)):i.getRowModel().rows?.length?i.getRowModel().rows.map(d=>e.jsx(Ps,{"data-state":d.getIsSelected()&&"selected",className:"h-10",children:d.getVisibleCells().map(p=>e.jsx(Ys,{className:"px-2",children:Rt(p.column.columnDef.cell,p.getContext())},p.id))},d.id)):e.jsx(Ps,{children:e.jsx(Ys,{colSpan:ua.length,className:"h-24 text-center",children:a("trafficRecord.noRecords")})})})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:a("trafficRecord.perPage")}),e.jsxs(X,{value:`${i.getState().pagination.pageSize}`,onValueChange:d=>{i.setPageSize(Number(d))},children:[e.jsx(Q,{className:"h-8 w-[70px]",children:e.jsx(ee,{placeholder:i.getState().pagination.pageSize})}),e.jsx(J,{side:"top",children:[10,20,30,40,50].map(d=>e.jsx(U,{value:`${d}`,children:d},d))})]}),e.jsx("p",{className:"text-sm font-medium",children:a("trafficRecord.records")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"flex w-[100px] items-center justify-center text-sm",children:a("trafficRecord.page",{current:i.getState().pagination.pageIndex+1,total:i.getPageCount()})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>i.previousPage(),disabled:!i.getCanPreviousPage()||x,children:e.jsx(fh,{className:"h-4 w-4"})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>i.nextPage(),disabled:!i.getCanNextPage()||x,children:e.jsx(ph,{className:"h-4 w-4"})})]})]})]})]})]})]})}function gh({onConfirm:s,children:n,title:a="确认操作",description:l="确定要执行此操作吗?",cancelText:r="取消",confirmText:c="确认",variant:o="default",className:m}){return e.jsxs(Fa,{children:[e.jsx(Hr,{asChild:!0,children:n}),e.jsxs(Wt,{className:N("sm:max-w-[425px]",m),children:[e.jsxs(Yt,{children:[e.jsx(Jt,{children:a}),e.jsx(Zt,{children:l})]}),e.jsxs(Qt,{children:[e.jsx(ea,{asChild:!0,children:e.jsx(D,{variant:"outline",children:r})}),e.jsx(Xt,{asChild:!0,children:e.jsx(D,{variant:o,onClick:s,children:c})})]})]})]})}const jh=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"})}),vh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),bh=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"})}),yh=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"})}),Nh=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"})}),_h=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"})}),wh=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"})}),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:"M20 6h-4V5a3 3 0 0 0-3-3h-2a3 3 0 0 0-3 3v1H4a1 1 0 0 0 0 2h1v11a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3V8h1a1 1 0 0 0 0-2M10 5a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v1h-4Zm7 14a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V8h10Z"})}),Sh=(s,n)=>{const{t:a}=M("user");return[{accessorKey:"is_admin",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(l,r,c)=>c.includes(l.getValue(r)),size:0},{accessorKey:"is_staff",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(l,r,c)=>c.includes(l.getValue(r)),size:0},{accessorKey:"id",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.id")}),cell:({row:l})=>e.jsx(K,{variant:"outline",children:l.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.email")}),cell:({row:l})=>{const r=l.original.t||0,c=Date.now()/1e3-r<120,o=Math.floor(Date.now()/1e3-r);let m=c?a("columns.online_status.online"):r===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:ve(r)});if(!c&&r!==0){const x=Math.floor(o/60),i=Math.floor(x/60),d=Math.floor(i/24);d>0?m+=`
|
||
`+a("columns.online_status.offline_duration.days",{count:d}):i>0?m+=`
|
||
`+a("columns.online_status.offline_duration.hours",{count:i}):x>0?m+=`
|
||
`+a("columns.online_status.offline_duration.minutes",{count:x}):m+=`
|
||
`+a("columns.online_status.offline_duration.seconds",{count:o})}return e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:N("size-2.5 rounded-full ring-2 ring-offset-2",c?"bg-green-500 ring-green-500/20":"bg-gray-300 ring-gray-300/20","transition-all duration-300")}),e.jsx("span",{className:"font-medium text-foreground/90",children:l.original.email})]})}),e.jsx(ce,{side:"bottom",className:"max-w-[280px]",children:e.jsx("p",{className:"whitespace-pre-line text-sm",children:m})})]})})},enableSorting:!1,enableHiding:!1},{accessorKey:"online_count",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.online_count")}),cell:({row:l})=>{const r=l.original.device_limit,c=l.original.online_count||0;return e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(K,{variant:"outline",className:N("min-w-[4rem] justify-center",r!==null&&c>=r?"border-destructive/50 bg-destructive/10 text-destructive":"border-primary/40 bg-primary/5 text-primary/90"),children:[c," / ",r===null?"∞":r]})})}),e.jsx(ce,{side:"bottom",children:e.jsx("p",{className:"text-sm",children:r===null?a("columns.device_limit.unlimited"):a("columns.device_limit.limited",{count:r})})})]})})},enableSorting:!0,enableHiding:!1},{accessorKey:"banned",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.status")}),cell:({row:l})=>{const r=l.original.banned;return e.jsx("div",{className:"flex justify-center",children:e.jsx(K,{className:N("min-w-20 justify-center transition-colors",r?"bg-destructive/15 text-destructive hover:bg-destructive/25":"bg-success/15 text-success hover:bg-success/25"),children:a(r?"columns.status_text.banned":"columns.status_text.normal")})})},enableSorting:!0,filterFn:(l,r,c)=>c.includes(l.getValue(r))},{accessorKey:"plan_id",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.subscription")}),cell:({row:l})=>e.jsx("div",{className:"min-w-[10em] break-all",children:l.original?.plan?.name||"-"}),enableSorting:!1,enableHiding:!1},{accessorKey:"group_id",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.group")}),cell:({row:l})=>e.jsx("div",{className:"flex flex-wrap gap-1",children:e.jsx(K,{variant:"outline",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5 whitespace-nowrap"),children:l.original?.group?.name||"-"})}),enableSorting:!1},{accessorKey:"total_used",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.used_traffic")}),cell:({row:l})=>{const r=ds(l.original?.total_used),c=ds(l.original?.transfer_enable),o=l.original?.total_used/l.original?.transfer_enable*100||0;return e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{className:"w-full",children:e.jsxs("div",{className:"w-full space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:r}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[o.toFixed(1),"%"]})]}),e.jsx("div",{className:"h-1.5 w-full rounded-full bg-secondary",children:e.jsx("div",{className:N("h-full rounded-full transition-all",o>90?"bg-destructive":"bg-primary"),style:{width:`${Math.min(o,100)}%`}})})]})}),e.jsx(ce,{side:"bottom",children:e.jsxs("p",{className:"text-sm",children:[a("columns.total_traffic"),": ",c]})})]})})}},{accessorKey:"transfer_enable",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.total_traffic")}),cell:({row:l})=>e.jsx("div",{className:"font-medium text-muted-foreground",children:ds(l.original?.transfer_enable)})},{accessorKey:"expired_at",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.expire_time")}),cell:({row:l})=>{const r=l.original.expired_at,c=Date.now()/1e3,o=r!=null&&r<c,m=r!=null?new Date(r*1e3):null,x=m!=null?Math.ceil((m.getTime()-Date.now())/(1e3*60*60*24)):null;return e.jsx(pe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{className:"block w-full",children:e.jsx(K,{variant:"outline",className:N("w-full justify-center transition-colors",o?"border-destructive/50 bg-destructive/10 text-destructive":r?"border-success/50 bg-success/10 text-success":"border-primary/40 bg-primary/5 text-primary/90"),children:r==null?a("columns.expire_status.permanent"):ve(r,"YYYY-MM-DD")})}),e.jsx(ce,{side:"bottom",className:"space-y-1 p-3",children:r!=null?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[a("columns.expire_time"),": ",ve(r)]}),e.jsx("p",{className:N("text-sm font-medium",o?"text-destructive":"text-success"),children:o?a("columns.expire_status.expired",{days:Math.abs(x??0)}):a("columns.expire_status.remaining",{days:x??0})})]}):e.jsx("p",{className:"text-sm font-medium",children:a("columns.expire_status.permanent")})})]})})}},{accessorKey:"balance",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.balance")}),cell:({row:l})=>{const r=Ws(l.original?.balance);return e.jsxs("div",{className:"flex items-center gap-1 font-medium",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"¥"}),e.jsx("span",{className:"tabular-nums text-foreground",children:r})]})}},{accessorKey:"commission_balance",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.commission")}),cell:({row:l})=>{const r=Ws(l.original?.commission_balance);return e.jsxs("div",{className:"flex items-center gap-1 font-medium",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"¥"}),e.jsx("span",{className:"tabular-nums text-foreground",children:r})]})}},{accessorKey:"created_at",header:({column:l})=>e.jsx(L,{column:l,title:a("columns.register_time")}),cell:({row:l})=>e.jsx("div",{className:"truncate",children:ve(l.original?.created_at)}),size:1e3},{id:"actions",header:({column:l})=>e.jsx(L,{column:l,className:"justify-end",title:a("columns.actions")}),cell:({row:l,table:r})=>e.jsxs(bs,{modal:!0,children:[e.jsx(ys,{asChild:!0,children:e.jsx("div",{className:"text-center",children:e.jsx(G,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":a("columns.actions"),children:e.jsx(Vt,{className:"size-4"})})})}),e.jsxs(us,{align:"end",className:"min-w-[40px]",children:[e.jsx(fe,{onSelect:c=>{c.preventDefault()},className:"p-0",children:e.jsx(dl,{defaultValues:{...l.original,invite_user_email:l.original.invite_user?.email},refetch:s,dialogTrigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(jh,{className:"mr-2"}),a("columns.actions_menu.edit")]})})}),e.jsx(fe,{onSelect:c=>c.preventDefault(),className:"p-0",children:e.jsx(sl,{defaultValues:{email:l.original.email},trigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(vh,{className:"mr-2 "}),a("columns.actions_menu.assign_order")]})})}),e.jsx(fe,{onSelect:()=>{Mt(l.original.subscribe_url).then(()=>{$.success(a("common:copy.success"))})},className:"p-0",children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(bh,{className:"mr-2"}),a("columns.actions_menu.copy_url")]})}),e.jsx(fe,{onSelect:()=>{Ld({id:l.original.id}).then(({data:c})=>{c&&$.success("重置成功")})},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(yh,{className:"mr-2 "}),a("columns.actions_menu.reset_secret")]})}),e.jsx(fe,{onSelect:()=>{},className:"p-0",children:e.jsxs(Ls,{className:"flex items-center px-2 py-1.5",to:`/finance/order?user_id=${l.original?.id}`,children:[e.jsx(Nh,{className:"mr-2"}),a("columns.actions_menu.orders")]})}),e.jsx(fe,{onSelect:()=>{r.setColumnFilters([{id:"invite_user_id",value:l.original?.id}])},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(_h,{className:"mr-2 "}),a("columns.actions_menu.invites")]})}),e.jsx(fe,{onSelect:c=>c.preventDefault(),className:"p-0",children:e.jsx(xl,{user_id:l.original?.id,dialogTrigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(wh,{className:"mr-2 "}),a("columns.actions_menu.traffic_records")]})})}),e.jsx(fe,{onSelect:c=>c.preventDefault(),className:"p-0",children:e.jsx(gh,{title:a("columns.actions_menu.delete_confirm_title"),description:a("columns.actions_menu.delete_confirm_description",{email:l.original.email}),cancelText:a("common:cancel"),confirmText:a("common:confirm"),variant:"destructive",onConfirm:async()=>{try{const{data:c}=await zt.destroy(l.original.id);c&&($.success(a("common:delete.success")),s())}catch{$.error(a("common:delete.failed"))}},children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5 text-destructive hover:text-destructive",children:[e.jsx(Ch,{className:"mr-2"}),a("columns.actions_menu.delete")]})})})]})]})}]};function kh(){const[s]=fr(),[n,a]=u.useState({}),[l,r]=u.useState({is_admin:!1,is_staff:!1}),[c,o]=u.useState([]),[m,x]=u.useState([]),[i,d]=u.useState({pageIndex:0,pageSize:20});u.useEffect(()=>{const O=s.get("email");O&&o(q=>q.some(F=>F.id==="email")?q:[...q,{id:"email",value:O}])},[s]);const{refetch:p,data:C,isLoading:P}=ie({queryKey:["userList",i,c,m],queryFn:()=>Fd({pageSize:i.pageSize,current:i.pageIndex+1,filter:c,sort:m})}),[f,j]=u.useState([]),[w,g]=u.useState([]);u.useEffect(()=>{vt().then(({data:O})=>{j(O)}),Us().then(({data:O})=>{g(O)})},[]);const S=f.map(O=>({label:O.name,value:O.id})),R=w.map(O=>({label:O.name,value:O.id})),E=Ze({data:C?.data??[],columns:Sh(p),state:{sorting:m,columnVisibility:l,rowSelection:n,columnFilters:c,pagination:i},rowCount:C?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:x,onColumnFiltersChange:o,onColumnVisibilityChange:r,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),onPaginationChange:d,getSortedRowModel:is(),getFacetedRowModel:_s(),getFacetedUniqueValues:ws(),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(cs,{table:E,toolbar:e.jsx(dh,{table:E,refetch:p,serverGroupList:f,permissionGroups:S,subscriptionPlans:R})})}function Th(){const{t:s}=M("user");return e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx($e,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("manage.title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("manage.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx("div",{className:"w-full",children:e.jsx(kh,{})})})]})]})}const Dh=Object.freeze(Object.defineProperty({__proto__:null,default:Th},Symbol.toStringTag,{value:"Module"}));function Ph({column:s,title:n,options:a}){const l=new Set(s?.getFilterValue());return e.jsxs(xs,{children:[e.jsx(hs,{asChild:!0,children:e.jsxs(G,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Bo,{className:"mr-2 h-4 w-4"}),n,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Se,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:l.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:l.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[l.size," selected"]}):a.filter(r=>l.has(r.value)).map(r=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:r.label},`selected-${r.value}`))})]})]})}),e.jsx(os,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Is,{children:[e.jsx($s,{placeholder:n}),e.jsxs(Vs,{children:[e.jsx(qs,{children:"No results found."}),e.jsx(Ke,{children:a.map(r=>{const c=l.has(r.value);return e.jsxs(Ie,{onSelect:()=>{c?l.delete(r.value):l.add(r.value);const o=Array.from(l);s?.setFilterValue(o.length?o:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Go,{className:N("h-4 w-4")})}),r.icon&&e.jsx(r.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:r.label})]},`option-${r.value}`)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(st,{}),e.jsx(Ke,{children:e.jsx(Ie,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Eh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 11H5a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2"})});function Rh({table:s}){const{t:n}=M("ticket");return e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-4",children:[e.jsx(Ra,{defaultValue:s.getColumn("status")?.getFilterValue(),onValueChange:a=>s.getColumn("status")?.setFilterValue(a),children:e.jsxs(Gt,{className:"grid w-full grid-cols-2",children:[e.jsx(Es,{value:"0",children:n("status.pending")}),e.jsx(Es,{value:"1",children:n("status.closed")})]})}),s.getColumn("level")&&e.jsx(Ph,{column:s.getColumn("level"),title:n("columns.level"),options:[{label:n("level.low"),value:Oe.LOW,icon:Eh,color:"gray"},{label:n("level.medium"),value:Oe.MIDDLE,icon:ml,color:"yellow"},{label:n("level.high"),value:Oe.HIGH,icon:ul,color:"red"}]})]})})}function Ih(){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 Vh=Fs("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"}}),hl=u.forwardRef(({className:s,variant:n,layout:a,children:l,...r},c)=>e.jsx("div",{className:N(Vh({variant:n,layout:a,className:s}),"relative group"),ref:c,...r,children:u.Children.map(l,o=>u.isValidElement(o)&&typeof o.type!="string"?u.cloneElement(o,{variant:n,layout:a}):o)}));hl.displayName="ChatBubble";const Oh=Fs("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"}}),fl=u.forwardRef(({className:s,variant:n,layout:a,isLoading:l=!1,children:r,...c},o)=>e.jsx("div",{className:N(Oh({variant:n,layout:a,className:s}),"break-words max-w-full whitespace-pre-wrap"),ref:o,...c,children:l?e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(Ih,{})}):r}));fl.displayName="ChatBubbleMessage";const Mh=u.forwardRef(({variant:s,className:n,children:a,...l},r)=>e.jsx("div",{ref:r,className:N("absolute top-1/2 -translate-y-1/2 flex opacity-0 group-hover:opacity-100 transition-opacity duration-200",s==="sent"?"-left-1 -translate-x-full flex-row-reverse":"-right-1 translate-x-full",n),...l,children:a}));Mh.displayName="ChatBubbleActionWrapper";const pl=u.forwardRef(({className:s,...n},a)=>e.jsx(fs,{autoComplete:"off",ref:a,name:"message",className:N("max-h-12 px-4 py-3 bg-background text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 w-full rounded-md flex items-center h-16 resize-none",s),...n}));pl.displayName="ChatInput";const gl=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"})}),jl=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"})}),hn=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 12l3.54-3.54a1 1 0 0 0 0-1.41a1 1 0 0 0-1.42 0l-4.24 4.24a1 1 0 0 0 0 1.42L13.41 17a1 1 0 0 0 .71.29a1 1 0 0 0 .71-.29a1 1 0 0 0 0-1.41Z"})}),Fh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21.71 20.29L18 16.61A9 9 0 1 0 16.61 18l3.68 3.68a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.39M11 18a7 7 0 1 1 7-7a7 7 0 0 1-7 7"})}),zh=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 Ah(){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(oe,{className:"h-8 w-3/4"}),e.jsx(oe,{className:"h-4 w-1/2"})]}),e.jsx("div",{className:"flex-1 space-y-4",children:[1,2,3].map(s=>e.jsx(oe,{className:"h-20 w-2/3"},s))})]})}function $h(){return e.jsx("div",{className:"space-y-4 p-4",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(oe,{className:"h-5 w-4/5"}),e.jsx(oe,{className:"h-4 w-2/3"}),e.jsx(oe,{className:"h-3 w-1/2"})]},s))})}function qh({ticket:s,isActive:n,onClick:a}){const{t:l}=M("ticket"),r=c=>{switch(c){case Oe.HIGH:return"bg-red-50 text-red-600 border-red-200";case Oe.MIDDLE:return"bg-yellow-50 text-yellow-600 border-yellow-200";case Oe.LOW:return"bg-green-50 text-green-600 border-green-200";default:return"bg-gray-50 text-gray-600 border-gray-200"}};return e.jsxs("div",{className:N("flex cursor-pointer flex-col border-b p-4 hover:bg-accent/50",n&&"bg-accent"),onClick:a,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 max-w-[280px]",children:[e.jsx("h4",{className:"truncate font-medium flex-1",children:s.subject}),e.jsx(K,{variant:s.status===Rs.CLOSED?"secondary":"default",className:"shrink-0",children:s.status===Rs.CLOSED?l("status.closed"):l("status.processing")})]}),e.jsx("div",{className:"mt-1 text-sm text-muted-foreground truncate max-w-[280px]",children:s.user?.email}),e.jsxs("div",{className:"mt-2 flex items-center justify-between text-xs",children:[e.jsx("time",{className:"text-muted-foreground",children:ve(s.updated_at)}),e.jsx("div",{className:N("px-2 py-0.5 rounded-full border text-xs font-medium",r(s.level)),children:l(`level.${s.level===Oe.LOW?"low":s.level===Oe.MIDDLE?"medium":"high"}`)})]})]})}function Uh({ticketId:s,dialogTrigger:n}){const{t:a}=M("ticket"),l=Ns(),r=u.useRef(null),c=u.useRef(null),[o,m]=u.useState(!1),[x,i]=u.useState(""),[d,p]=u.useState(!1),[C,P]=u.useState(s),[f,j]=u.useState(""),[w,g]=u.useState(!1),{data:S,isLoading:R,refetch:E}=ie({queryKey:["tickets",o],queryFn:()=>o?ra.getList({filter:[{id:"status",value:[Rs.OPENING]}]}):Promise.resolve(null),enabled:o}),{data:O,refetch:q,isLoading:te}=ie({queryKey:["ticket",C,o],queryFn:()=>o?Ud(C):Promise.resolve(null),refetchInterval:o?5e3:!1,retry:3}),F=O?.data,qe=(S?.data||[]).filter(ne=>ne.subject.toLowerCase().includes(f.toLowerCase())||ne.user?.email.toLowerCase().includes(f.toLowerCase())),B=(ne="smooth")=>{if(r.current){const{scrollHeight:We,clientHeight:tt}=r.current;r.current.scrollTo({top:We-tt,behavior:ne})}};u.useEffect(()=>{if(!o)return;const ne=requestAnimationFrame(()=>{B("instant"),setTimeout(()=>B(),1e3)});return()=>{cancelAnimationFrame(ne)}},[o,F?.messages]);const ae=async()=>{const ne=x.trim();!ne||d||(p(!0),ra.reply({id:C,message:ne}).then(()=>{i(""),q(),B(),setTimeout(()=>{c.current?.focus()},0)}).finally(()=>{p(!1)}))},A=async()=>{ra.close(C).then(()=>{$.success(a("actions.close_success")),q(),E()})},I=()=>{F?.user&&l("/finance/order?user_id="+F.user.id)},Y=F?.status===Rs.CLOSED;return e.jsxs(be,{open:o,onOpenChange:m,children:[e.jsx(Ge,{asChild:!0,children:n??e.jsx(G,{variant:"outline",children:a("actions.view_ticket")})}),e.jsxs(ge,{className:"flex h-[90vh] max-w-6xl flex-col gap-0 p-0",children:[e.jsx(ye,{}),e.jsxs("div",{className:"flex h-full",children:[e.jsx(G,{variant:"ghost",size:"icon",className:"absolute left-2 top-2 md:hidden z-50",onClick:()=>g(!w),children:e.jsx(hn,{className:N("h-4 w-4 transition-transform",!w&&"rotate-180")})}),e.jsxs("div",{className:N("absolute md:relative inset-y-0 left-0 z-40 flex flex-col border-r bg-background transition-transform duration-200 ease-in-out",w?"-translate-x-full":"translate-x-0","w-80 md:w-80 md:translate-x-0"),children:[e.jsxs("div",{className:"space-y-4 border-b p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold",children:a("list.title")}),e.jsx(G,{variant:"ghost",size:"icon",className:"hidden md:flex h-8 w-8",onClick:()=>g(!w),children:e.jsx(hn,{className:N("h-4 w-4 transition-transform",!w&&"rotate-180")})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Fh,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 transform text-muted-foreground"}),e.jsx(k,{placeholder:a("list.search_placeholder"),value:f,onChange:ne=>j(ne.target.value),className:"pl-8"})]})]}),e.jsx(Xs,{className:"flex-1",children:e.jsx("div",{className:"w-full",children:R?e.jsx($h,{}):qe.length===0?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground p-4",children:a(f?"list.no_search_results":"list.no_tickets")}):qe.map(ne=>e.jsx(qh,{ticket:ne,isActive:ne.id===C,onClick:()=>{P(ne.id),window.innerWidth<768&&g(!0)}},ne.id))})})]}),e.jsxs("div",{className:"flex-1 flex flex-col relative",children:[!w&&e.jsx("div",{className:"absolute inset-0 bg-black/20 z-30 md:hidden",onClick:()=>g(!0)}),te?e.jsx(Ah,{}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-col space-y-4 border-b p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("h2",{className:"text-2xl font-semibold",children:F?.subject}),e.jsx(K,{variant:Y?"secondary":"default",children:a(Y?"status.closed":"status.processing")}),!Y&&e.jsx(Be,{title:a("actions.close_confirm_title"),description:a("actions.close_confirm_description"),confirmText:a("actions.close_confirm_button"),variant:"destructive",onConfirm:A,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"gap-1 text-muted-foreground hover:text-destructive",children:[e.jsx(gl,{className:"h-4 w-4"}),a("actions.close_ticket")]})})]}),e.jsxs("div",{className:"flex items-center space-x-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(ft,{className:"h-4 w-4"}),e.jsx("span",{children:F?.user?.email})]}),e.jsx(Se,{orientation:"vertical",className:"h-4"}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(jl,{className:"h-4 w-4"}),e.jsxs("span",{children:[a("detail.created_at")," ",ve(F?.created_at)]})]}),e.jsx(Se,{orientation:"vertical",className:"h-4"}),e.jsx(K,{variant:"outline",children:F?.level!=null&&a(`level.${F.level===Oe.LOW?"low":F.level===Oe.MIDDLE?"medium":"high"}`)})]})]}),F?.user&&e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(dl,{defaultValues:F.user,refetch:q,dialogTrigger:e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:a("detail.user_info"),children:e.jsx(ft,{className:"h-4 w-4"})})}),e.jsx(xl,{user_id:F.user.id,dialogTrigger:e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:a("detail.traffic_records"),children:e.jsx(zh,{className:"h-4 w-4"})})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:a("detail.order_records"),onClick:I,children:e.jsx(Lh,{className:"h-4 w-4"})})]})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{ref:r,className:"h-full space-y-4 overflow-y-auto p-6",children:F?.messages?.length===0?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:a("detail.no_messages")}):F?.messages?.map(ne=>e.jsx(hl,{variant:ne.is_me?"sent":"received",className:ne.is_me?"ml-auto":"mr-auto",children:e.jsx(fl,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"whitespace-pre-wrap break-words",children:ne.message}),e.jsx("div",{className:"text-right",children:e.jsx("time",{className:"text-[10px] text-muted-foreground",children:ve(ne.created_at)})})]})})},ne.id))})}),e.jsx("div",{className:"border-t p-4",children:e.jsxs("div",{className:"relative flex items-center space-x-2",children:[e.jsx(pl,{ref:c,disabled:Y||d,placeholder:a(Y?"detail.input.closed_placeholder":"detail.input.reply_placeholder"),className:"flex-1 resize-none rounded-lg border bg-background p-3 focus-visible:ring-1",value:x,onChange:ne=>i(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&!ne.shiftKey&&(ne.preventDefault(),ae())}}),e.jsx(G,{disabled:Y||d||!x.trim(),onClick:ae,children:a(d?"detail.input.sending":"detail.input.send")})]})})]})]})]})]})]})}const Hh=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"})}),Kh=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"})}),Bh=s=>{const{t:n}=M("ticket");return[{accessorKey:"id",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.id")}),cell:({row:a})=>e.jsx(K,{variant:"outline",children:a.getValue("id")}),enableSorting:!1,enableHiding:!1},{accessorKey:"subject",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.subject")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Hh,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"max-w-[500px] truncate font-medium",children:a.getValue("subject")})]}),enableSorting:!1,enableHiding:!1,size:4e3},{accessorKey:"level",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.level")}),cell:({row:a})=>{const l=a.getValue("level"),r=l===Oe.LOW?"default":l===Oe.MIDDLE?"secondary":"destructive";return e.jsx(K,{variant:r,className:"whitespace-nowrap",children:n(`level.${l===Oe.LOW?"low":l===Oe.MIDDLE?"medium":"high"}`)})},filterFn:(a,l,r)=>r.includes(a.getValue(l))},{accessorKey:"status",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.status")}),cell:({row:a})=>{const l=a.getValue("status"),r=a.original.reply_status,c=l===Rs.CLOSED?n("status.closed"):n(r===0?"status.replied":"status.pending"),o=l===Rs.CLOSED?"default":r===0?"secondary":"destructive";return e.jsx(K,{variant:o,className:"whitespace-nowrap",children:c})}},{accessorKey:"updated_at",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.updated_at")}),cell:({row:a})=>e.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[e.jsx(jl,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:ve(a.getValue("updated_at"))})]}),enableSorting:!0},{accessorKey:"created_at",header:({column:a})=>e.jsx(L,{column:a,title:n("columns.created_at")}),cell:({row:a})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:ve(a.getValue("created_at"))}),enableSorting:!0,meta:{isFlexGrow:!0}},{id:"actions",header:({column:a})=>e.jsx(L,{className:"justify-end",column:a,title:n("columns.actions")}),cell:({row:a})=>{const l=a.original.status!==Rs.CLOSED;return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Uh,{ticketId:a.original.id,dialogTrigger:e.jsx(G,{variant:"ghost",size:"icon",className:"h-8 w-8",title:n("actions.view_details"),children:e.jsx(Kh,{className:"h-4 w-4"})})}),l&&e.jsx(Be,{title:n("actions.close_confirm_title"),description:n("actions.close_confirm_description"),confirmText:n("actions.close_confirm_button"),variant:"destructive",onConfirm:async()=>{Hd(a.original.id).then(()=>{$.success(n("actions.close_success")),s()})},children:e.jsx(G,{variant:"ghost",size:"icon",className:"h-8 w-8",title:n("actions.close_ticket"),children:e.jsx(gl,{className:"h-4 w-4"})})})]})}}]};function Gh(){const[s,n]=u.useState({}),[a,l]=u.useState({}),[r,c]=u.useState([{id:"status",value:"0"}]),[o,m]=u.useState([]),[x,i]=u.useState({pageIndex:0,pageSize:20}),{refetch:d,data:p,isLoading:C}=ie({queryKey:["orderList",x,r,o],queryFn:()=>qd({pageSize:x.pageSize,current:x.pageIndex+1,filter:r,sort:o})}),P=Ze({data:p?.data??[],columns:Bh(d),state:{sorting:o,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:x},rowCount:p?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:c,onColumnVisibilityChange:l,getCoreRowModel:Xe(),getFilteredRowModel:rs(),getPaginationRowModel:ls(),onPaginationChange:i,getSortedRowModel:is(),getFacetedRowModel:_s(),getFacetedUniqueValues:ws(),initialState:{columnPinning:{right:["actions"]}}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Rh,{table:P,refetch:d}),e.jsx(cs,{table:P,showPagination:!0})]})}function Wh(){const{t:s}=M("ticket");return e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx($e,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Fe,{}),e.jsx(ze,{})]})]}),e.jsxs(Ve,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Gh,{})})]})]})}const Yh=Object.freeze(Object.defineProperty({__proto__:null,default:Wh},Symbol.toStringTag,{value:"Module"}));export{ef as a,Zh as c,Xh as g,sf as r};
|