mirror of
https://github.com/lkddi/Xboard.git
synced 2026-05-18 13:47:30 +08:00
58868268dd
- Add command support for plugin management - Optimize plugin management page layout - Add email copy functionality for users - Convert payment methods and Telegram Bot to plugin system
22 lines
530 KiB
JavaScript
Vendored
22 lines
530 KiB
JavaScript
Vendored
import{r as u,j as e,t as lo,c as io,I as ea,a as gt,S as kn,u as Gs,b as oo,d as Tn,R as Tr,e as Dr,f as co,F as mo,C as uo,L as Fr,T as Pr,g as Lr,h as xo,i as ho,k as go,l as po,m as z,n as Rr,o as Er,z as h,p as M,q as we,s as Te,v as re,w as Os,x as Re,y as Vr,A as fo,O as Dn,B as jo,D as vo,E as bo,G as yo,H as _o,J as No,Q as wo,K as Co,M as Ir,N as So,P as ko,U as To,V as Do,W as Fo,X as Po,Y as Mr,Z as Or,_ as Va,$ as Ia,a0 as Fn,a1 as os,a2 as Ma,a3 as Oa,a4 as zr,a5 as $r,a6 as Ar,a7 as qr,a8 as Hr,a9 as Lo,aa as Ur,ab as Kr,ac as Br,ad as Gr,ae as pt,af as Wr,ag as Ro,ah as Yr,ai as Jr,aj as Eo,ak as Vo,al as Io,am as Mo,an as Oo,ao as zo,ap as $o,aq as Ao,ar as qo,as as Ho,at as Qr,au as Uo,av as Ko,aw as tt,ax as Xr,ay as Bo,az as Go,aA as Zr,aB as Pn,aC as Wo,aD as Yo,aE as sr,aF as Jo,aG as el,aH as Qo,aI as sl,aJ as Xo,aK as Zo,aL as ec,aM as sc,aN as tc,aO as ac,aP as nc,aQ as tl,aR as rc,aS as lc,aT as ic,aU as xs,aV as oc,aW as Ln,aX as cc,aY as dc,aZ as al,a_ as nl,a$ as rl,b0 as mc,b1 as uc,b2 as xc,b3 as ll,b4 as hc,b5 as Rn,b6 as il,b7 as gc,b8 as ol,b9 as pc,ba as cl,bb as fc,bc as dl,bd as ml,be as jc,bf as vc,bg as ul,bh as bc,bi as xl,bj as yc,bk as hl,bl as gl,bm as pl,bn as _c,bo as fl,bp as Nc,bq as wc,br as Is,bs as Le,bt as Cs,bu as Cc,bv as Sc,bw as kc,bx as Tc,by as Dc,bz as Fc,bA as tr,bB as ar,bC as Pc,bD as Lc,bE as En,bF as Rc,bG as Ec,bH as wa,bI as Lt,bJ as sa,bK as Vc,bL as jl,bM as Ic,bN as Mc,bO as vl,bP as Oc,bQ as zc,bR as nr,bS as fn,bT as jn,bU as $c,bV as Ac,bW as bl,bX as qc,bY as Hc,bZ as Uc,b_ as Kc,b$ as Ca,c0 as vn,c1 as Be,c2 as Sa,c3 as Bc,c4 as nn,c5 as Gc,c6 as bn,c7 as us,c8 as Gt,c9 as Wt,ca as yn,cb as yl,cc as Ge,cd as Ze,ce as _l,cf as Nl,cg as Wc,ch as Yc,ci as Jc,cj as Qc,ck as Xc,cl as wl,cm as Zc,cn as ed,co as sd,cp as Ue,cq as rr,cr as td,cs as Cl,ct as Sl,cu as kl,cv as Tl,cw as Dl,cx as Fl,cy as ad,cz as nd,cA as rd,cB as za,cC as rt,cD as hs,cE as gs,cF as ld,cG as id,cH as od,cI as cd,cJ as dd,cK as ka,cL as md,cM as ud,cN as _n,cO as Vn,cP as In,cQ as xd,cR as Ls,cS as Rs,cT as $a,cU as hd,cV as Ta,cW as gd,cX as lr,cY as Pl,cZ as ir,c_ as Da,c$ as pd,d0 as Mn,d1 as fd,d2 as jd,d3 as vd,d4 as Ll,d5 as bd,d6 as yd,d7 as Rl,d8 as Nn,d9 as El,da as _d,db as wn,dc as Vl,dd as Nd,de as wd,df as Cd,dg as Il,dh as Sd,di as kd,dj as Ml,dk as Yt,dl as On,dm as Td,dn as or,dp as Ol,dq as Dd,dr as cr,ds as Fd,dt as Pd}from"./vendor.js";import"./index.js";var cp=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function dp(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function Ld(s){if(s.__esModule)return s;var n=s.default;if(typeof n=="function"){var t=function r(){return this instanceof r?Reflect.construct(n,arguments,this.constructor):n.apply(this,arguments)};t.prototype=n.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(s).forEach(function(r){var a=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:function(){return s[r]}})}),t}const Rd={theme:"system",setTheme:()=>null},zl=u.createContext(Rd);function Ed({children:s,defaultTheme:n="system",storageKey:t="vite-ui-theme",...r}){const[a,i]=u.useState(()=>localStorage.getItem(t)||n);u.useEffect(()=>{const d=window.document.documentElement;if(d.classList.remove("light","dark"),a==="system"){const x=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";d.classList.add(x);return}d.classList.add(a)},[a]);const l={theme:a,setTheme:d=>{localStorage.setItem(t,d),i(d)}};return e.jsx(zl.Provider,{...r,value:l,children:s})}const Vd=()=>{const s=u.useContext(zl);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},Id=function(){const n=typeof document<"u"&&document.createElement("link").relList;return n&&n.supports&&n.supports("modulepreload")?"modulepreload":"preload"}(),Md=function(s,n){return new URL(s,n).href},dr={},Ne=function(n,t,r){let a=Promise.resolve();if(t&&t.length>0){const l=document.getElementsByTagName("link"),d=document.querySelector("meta[property=csp-nonce]"),x=d?.nonce||d?.getAttribute("nonce");a=Promise.allSettled(t.map(m=>{if(m=Md(m,r),m in dr)return;dr[m]=!0;const o=m.endsWith(".css"),c=o?'[rel="stylesheet"]':"";if(!!r)for(let S=l.length-1;S>=0;S--){const C=l[S];if(C.href===m&&(!o||C.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${m}"]${c}`))return;const D=document.createElement("link");if(D.rel=o?"stylesheet":Id,o||(D.as="script"),D.crossOrigin="",D.href=m,x&&D.setAttribute("nonce",x),document.head.appendChild(D),o)return new Promise((S,C)=>{D.addEventListener("load",S),D.addEventListener("error",()=>C(new Error(`Unable to preload CSS for ${m}`)))})}))}function i(l){const d=new Event("vite:preloadError",{cancelable:!0});if(d.payload=l,window.dispatchEvent(d),!d.defaultPrevented)throw l}return a.then(l=>{for(const d of l||[])d.status==="rejected"&&i(d.reason);return n().catch(i)})};function N(...s){return lo(io(s))}const It=gt("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"}}),F=u.forwardRef(({className:s,variant:n,size:t,asChild:r=!1,children:a,disabled:i,loading:l=!1,leftSection:d,rightSection:x,...m},o)=>{const c=r?kn:"button";return e.jsxs(c,{className:N(It({variant:n,size:t,className:s})),disabled:l||i,ref:o,...m,children:[(d&&l||!d&&!x&&l)&&e.jsx(ea,{className:"mr-2 h-4 w-4 animate-spin"}),!l&&d&&e.jsx("div",{className:"mr-2",children:d}),a,!l&&x&&e.jsx("div",{className:"ml-2",children:x}),x&&l&&e.jsx(ea,{className:"ml-2 h-4 w-4 animate-spin"})]})});F.displayName="Button";function Nt({className:s,minimal:n=!1}){const t=Gs(),r=oo(),a=r?.message||r?.statusText||"Unknown error occurred";return e.jsx("div",{className:N("h-svh w-full",s),children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[!n&&e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"500"}),e.jsxs("span",{className:"font-medium",children:["Oops! Something went wrong ",":')"]}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["We apologize for the inconvenience. ",e.jsx("br",{}),a]}),!n&&e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(F,{variant:"outline",onClick:()=>t(-1),children:"Go Back"}),e.jsx(F,{onClick:()=>t("/"),children:"Back to Home"})]})]})})}function mr(){const s=Gs();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(F,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(F,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function Od(){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(F,{variant:"outline",children:"Learn more"})})]})})}function zd(s){return typeof s>"u"}function $d(s){return s===null}function Ad(s){return $d(s)||zd(s)}class qd{storage;prefixKey;constructor(n){this.storage=n.storage,this.prefixKey=n.prefixKey}getKey(n){return`${this.prefixKey}${n}`.toUpperCase()}set(n,t,r=null){const a=JSON.stringify({value:t,time:Date.now(),expire:r!==null?new Date().getTime()+r*1e3:null});this.storage.setItem(this.getKey(n),a)}get(n,t=null){const r=this.storage.getItem(this.getKey(n));if(!r)return{value:t,time:0};try{const a=JSON.parse(r),{value:i,time:l,expire:d}=a;return Ad(d)||d>new Date().getTime()?{value:i,time:l}:(this.remove(n),{value:t,time:0})}catch{return this.remove(n),{value:t,time:0}}}remove(n){this.storage.removeItem(this.getKey(n))}clear(){this.storage.clear()}}function $l({prefixKey:s="",storage:n=sessionStorage}){return new qd({prefixKey:s,storage:n})}const Al="Xboard_",Hd=function(s={}){return $l({prefixKey:s.prefixKey||"",storage:localStorage})},Ud=function(s={}){return $l({prefixKey:s.prefixKey||"",storage:sessionStorage})},zn=Hd({prefixKey:Al});Ud({prefixKey:Al});const ql="access_token";function ta(){return zn.get(ql)}function Hl(){zn.remove(ql)}const ur=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function Kd({children:s}){const n=Gs(),t=Tn(),r=ta();return u.useEffect(()=>{if(!r.value&&!ur.includes(t.pathname)){const a=encodeURIComponent(t.pathname+t.search);n(`/sign-in?redirect=${a}`)}},[r.value,t.pathname,t.search,n]),ur.includes(t.pathname)||r.value?e.jsx(e.Fragment,{children:s}):null}const Ee=u.forwardRef(({className:s,orientation:n="horizontal",decorative:t=!0,...r},a)=>e.jsx(Tr,{ref:a,decorative:t,orientation:n,className:N("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...r}));Ee.displayName=Tr.displayName;const Bd=gt("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Je=u.forwardRef(({className:s,...n},t)=>e.jsx(Dr,{ref:t,className:N(Bd(),s),...n}));Je.displayName=Dr.displayName;const De=mo,Ul=u.createContext({}),v=({...s})=>e.jsx(Ul.Provider,{value:{name:s.name},children:e.jsx(uo,{...s})}),Aa=()=>{const s=u.useContext(Ul),n=u.useContext(Kl),{getFieldState:t,formState:r}=co(),a=t(s.name,r);if(!s)throw new Error("useFormField should be used within <FormField>");const{id:i}=n;return{id:i,name:s.name,formItemId:`${i}-form-item`,formDescriptionId:`${i}-form-item-description`,formMessageId:`${i}-form-item-message`,...a}},Kl=u.createContext({}),j=u.forwardRef(({className:s,...n},t)=>{const r=u.useId();return e.jsx(Kl.Provider,{value:{id:r},children:e.jsx("div",{ref:t,className:N("space-y-2",s),...n})})});j.displayName="FormItem";const b=u.forwardRef(({className:s,...n},t)=>{const{error:r,formItemId:a}=Aa();return e.jsx(Je,{ref:t,className:N(r&&"text-destructive",s),htmlFor:a,...n})});b.displayName="FormLabel";const y=u.forwardRef(({...s},n)=>{const{error:t,formItemId:r,formDescriptionId:a,formMessageId:i}=Aa();return e.jsx(kn,{ref:n,id:r,"aria-describedby":t?`${a} ${i}`:`${a}`,"aria-invalid":!!t,...s})});y.displayName="FormControl";const $=u.forwardRef(({className:s,...n},t)=>{const{formDescriptionId:r}=Aa();return e.jsx("p",{ref:t,id:r,className:N("text-[0.8rem] text-muted-foreground",s),...n})});$.displayName="FormDescription";const P=u.forwardRef(({className:s,children:n,...t},r)=>{const{error:a,formMessageId:i}=Aa(),l=a?String(a?.message):n;return l?e.jsx("p",{ref:r,id:i,className:N("text-[0.8rem] font-medium text-destructive",s),...t,children:l}):null});P.displayName="FormMessage";const ft=xo,lt=u.forwardRef(({className:s,...n},t)=>e.jsx(Fr,{ref:t,className:N("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...n}));lt.displayName=Fr.displayName;const Ke=u.forwardRef(({className:s,...n},t)=>e.jsx(Pr,{ref:t,className:N("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",s),...n}));Ke.displayName=Pr.displayName;const bs=u.forwardRef(({className:s,...n},t)=>e.jsx(Lr,{ref:t,className:N("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...n}));bs.displayName=Lr.displayName;function oe(s=void 0,n="YYYY-MM-DD HH:mm:ss"){return s==null?"":(Math.floor(s).toString().length===10&&(s=s*1e3),ho(s).format(n))}function Gd(s=void 0,n="YYYY-MM-DD"){return oe(s,n)}function xr(s){const n=typeof s=="string"?parseFloat(s):s;return isNaN(n)?"0.00":n.toFixed(2)}function Ks(s,n=!0){if(s==null)return n?"¥0.00":"0.00";const t=typeof s=="string"?parseFloat(s):s;if(isNaN(t))return n?"¥0.00":"0.00";const a=(t/100).toFixed(2).replace(/\.?0+$/,i=>i.includes(".")?".00":i);return n?`¥${a}`:a}function Rt(s){return new Promise(n=>{try{const t=document.createElement("button");t.style.position="fixed",t.style.left="-9999px",t.style.opacity="0",t.setAttribute("data-clipboard-text",s),document.body.appendChild(t);const r=new go(t);r.on("success",()=>{r.destroy(),document.body.removeChild(t),n(!0)}),r.on("error",a=>{console.error("Clipboard.js failed:",a),r.destroy(),document.body.removeChild(t),n(!1)}),t.click()}catch(t){console.error("copyToClipboard failed:",t),n(!1)}})}function ze(s){if(s==null||s<=0)return"0 B";const n=1024,t=["B","KB","MB","GB","TB"];let r=Math.floor(Math.log(s)/Math.log(n));return r<0?r=0:r>=t.length&&(r=t.length-1),`${parseFloat((s/Math.pow(n,r)).toFixed(2))} ${t[r]}`}const hr="i18nextLng";function Wd(){return console.log(localStorage.getItem(hr)),localStorage.getItem(hr)}function Bl(){Hl();const s=window.location.pathname,n=s&&!["/404","/sign-in"].includes(s),t=new URL(window.location.href),a=`${t.pathname.split("/")[1]?`/${t.pathname.split("/")[1]}`:""}#/sign-in`;window.location.href=a+(n?`?redirect=${s}`:"")}const Yd=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function Jd(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const Dt=po.create({baseURL:Jd(),timeout:12e3,headers:{"Content-Type":"application/json"}});Dt.interceptors.request.use(s=>{s.method?.toLowerCase()==="get"&&(s.params={...s.params,t:Date.now()});const n=ta();if(!Yd.includes(s.url?.split("?")[0]||"")){if(!n.value)return Bl(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=n.value}return s.headers["Content-Language"]=Wd()||"zh-CN",s},s=>Promise.reject(s));Dt.interceptors.response.use(s=>s?.data||{code:-1,message:"未知错误"},s=>{const n=s.response?.status,t=s.response?.data?.message;return(n===401||n===403)&&Bl(),z.error(t||{401:"登录已过期",403:"没有权限",404:"资源或接口不存在"}[n]||"未知异常"),Promise.reject(s.response?.data||{data:null,code:-1,message:"未知错误"})});const I={get:(s,n)=>Dt.get(s,n),post:(s,n,t)=>Dt.post(s,n,t),put:(s,n,t)=>Dt.put(s,n,t),delete:(s,n)=>Dt.delete(s,n)},Qd="access_token";function Xd(s){zn.set(Qd,s)}const ct=window?.settings?.secure_path,Fa={getStats:()=>I.get(ct+"/monitor/api/stats"),getOverride:()=>I.get(ct+"/stat/getOverride"),getOrderStat:s=>I.get(ct+"/stat/getOrder",{params:s}),getStatsData:()=>I.get(ct+"/stat/getStats"),getNodeTrafficData:s=>I.get(ct+"/stat/getTrafficRank",{params:s}),getServerLastRank:()=>I.get(ct+"/stat/getServerLastRank"),getServerYesterdayRank:()=>I.get(ct+"/stat/getServerYesterdayRank")},Ot=window?.settings?.secure_path,Jt={getList:()=>I.get(Ot+"/theme/getThemes"),getConfig:s=>I.post(Ot+"/theme/getThemeConfig",{name:s}),updateConfig:(s,n)=>I.post(Ot+"/theme/saveThemeConfig",{name:s,config:n}),upload:s=>{const n=new FormData;return n.append("file",s),I.post(Ot+"/theme/upload",n,{headers:{"Content-Type":"multipart/form-data"}})},drop:s=>I.post(Ot+"/theme/delete",{name:s})},wt=window?.settings?.secure_path,ut={getList:()=>I.get(wt+"/server/manage/getNodes"),save:s=>I.post(wt+"/server/manage/save",s),drop:s=>I.post(wt+"/server/manage/drop",s),copy:s=>I.post(wt+"/server/manage/copy",s),update:s=>I.post(wt+"/server/manage/update",s),sort:s=>I.post(wt+"/server/manage/sort",s)},rn=window?.settings?.secure_path,jt={getList:()=>I.get(rn+"/server/group/fetch"),save:s=>I.post(rn+"/server/group/save",s),drop:s=>I.post(rn+"/server/group/drop",s)},ln=window?.settings?.secure_path,qa={getList:()=>I.get(ln+"/server/route/fetch"),save:s=>I.post(ln+"/server/route/save",s),drop:s=>I.post(ln+"/server/route/drop",s)},dt=window?.settings?.secure_path,xt={getList:()=>I.get(dt+"/payment/fetch"),getMethodList:()=>I.get(dt+"/payment/getPaymentMethods"),getMethodForm:s=>I.post(dt+"/payment/getPaymentForm",s),save:s=>I.post(dt+"/payment/save",s),drop:s=>I.post(dt+"/payment/drop",s),updateStatus:s=>I.post(dt+"/payment/show",s),sort:s=>I.post(dt+"/payment/sort",s)},zt=window?.settings?.secure_path,aa={getList:()=>I.get(`${zt}/notice/fetch`),save:s=>I.post(`${zt}/notice/save`,s),drop:s=>I.post(`${zt}/notice/drop`,{id:s}),updateStatus:s=>I.post(`${zt}/notice/show`,{id:s}),sort:s=>I.post(`${zt}/notice/sort`,{ids:s})},Ct=window?.settings?.secure_path,Et={getList:()=>I.get(Ct+"/knowledge/fetch"),getInfo:s=>I.get(Ct+"/knowledge/fetch?id="+s),save:s=>I.post(Ct+"/knowledge/save",s),drop:s=>I.post(Ct+"/knowledge/drop",s),updateStatus:s=>I.post(Ct+"/knowledge/show",s),sort:s=>I.post(Ct+"/knowledge/sort",s)},$t=window?.settings?.secure_path,ys={getList:()=>I.get($t+"/plan/fetch"),save:s=>I.post($t+"/plan/save",s),update:s=>I.post($t+"/plan/update",s),drop:s=>I.post($t+"/plan/drop",s),sort:s=>I.post($t+"/plan/sort",{ids:s})},St=window?.settings?.secure_path,mt={getList:s=>I.post(St+"/order/fetch",s),getInfo:s=>I.post(St+"/order/detail",s),markPaid:s=>I.post(St+"/order/paid",s),makeCancel:s=>I.post(St+"/order/cancel",s),update:s=>I.post(St+"/order/update",s),assign:s=>I.post(St+"/order/assign",s)},Ds=window?.settings?.secure_path,Ps={getTemplates:s=>I.post(Ds+"/gift-card/templates",s),createTemplate:s=>I.post(Ds+"/gift-card/create-template",s),updateTemplate:s=>I.post(Ds+"/gift-card/update-template",s),deleteTemplate:s=>I.post(Ds+"/gift-card/delete-template",s),getCodes:s=>I.post(Ds+"/gift-card/codes",s),generateCodes:s=>s.download_csv?I.post(Ds+"/gift-card/generate-codes",s,{responseType:"blob"}):I.post(Ds+"/gift-card/generate-codes",s),toggleCode:s=>I.post(Ds+"/gift-card/toggle-code",s),exportCodes:s=>I.get(Ds+`/gift-card/export-codes?batch_id=${s}`,{responseType:"blob"}),getUsages:s=>I.post(Ds+"/gift-card/usages",s),getStatistics:s=>I.post(Ds+"/gift-card/statistics",s),getTypes:()=>I.get(Ds+"/gift-card/types")},ma=window?.settings?.secure_path,Pa={getList:s=>I.post(ma+"/coupon/fetch",s),save:s=>I.post(ma+"/coupon/generate",s),drop:s=>I.post(ma+"/coupon/drop",s),update:s=>I.post(ma+"/coupon/update",s)},js=window?.settings?.secure_path,qs={getList:s=>I.post(`${js}/user/fetch`,s),update:s=>I.post(`${js}/user/update`,s),resetSecret:s=>I.post(`${js}/user/resetSecret`,{id:s}),generate:s=>s.download_csv?I.post(`${js}/user/generate`,s,{responseType:"blob"}):I.post(`${js}/user/generate`,s),getStats:s=>I.post(`${js}/stat/getStatUser`,s),destroy:s=>I.post(`${js}/user/destroy`,{id:s}),sendMail:s=>I.post(`${js}/user/sendMail`,s),dumpCSV:s=>I.post(`${js}/user/dumpCSV`,s,{responseType:"blob"}),batchBan:s=>I.post(`${js}/user/ban`,s)},na={getLogs:s=>I.get(`${js}/traffic-reset/logs`,{params:s}),getStats:s=>I.get(`${js}/traffic-reset/stats`,{params:s}),resetUser:s=>I.post(`${js}/traffic-reset/reset-user`,s),getUserHistory:(s,n)=>I.get(`${js}/traffic-reset/user/${s}/history`,{params:n})},ua=window?.settings?.secure_path,Ft={getList:s=>I.post(ua+"/ticket/fetch",s),getInfo:s=>I.get(ua+"/ticket/fetch?id= "+s),reply:s=>I.post(ua+"/ticket/reply",s),close:s=>I.post(ua+"/ticket/close",{id:s})},as=window?.settings?.secure_path,ye={getSettings:(s="")=>I.get(as+"/config/fetch?key="+s),saveSettings:s=>I.post(as+"/config/save",s),getEmailTemplate:()=>I.get(as+"/config/getEmailTemplate"),sendTestMail:()=>I.post(as+"/config/testSendMail"),setTelegramWebhook:()=>I.post(as+"/config/setTelegramWebhook"),updateSystemConfig:s=>I.post(as+"/config/save",s),getSystemStatus:()=>I.get(`${as}/system/getSystemStatus`),getQueueStats:()=>I.get(`${as}/system/getQueueStats`),getQueueWorkload:()=>I.get(`${as}/system/getQueueWorkload`),getQueueMasters:()=>I.get(`${as}/system/getQueueMasters`),getHorizonFailedJobs:s=>I.get(`${as}/system/getHorizonFailedJobs`,{params:s}),getSystemLog:s=>I.get(`${as}/system/getSystemLog`,{params:s}),getLogFiles:()=>I.get(`${as}/log/files`),getLogContent:s=>I.get(`${as}/log/fetch`,{params:s}),getLogClearStats:s=>I.get(`${as}/system/getLogClearStats`,{params:s}),clearSystemLog:s=>I.post(`${as}/system/clearSystemLog`,s)},$s=window?.settings?.secure_path,As={getPluginTypes:()=>I.get(`${$s}/plugin/types`),getPluginList:s=>{const n=s?{type:s}:{};return I.get(`${$s}/plugin/getPlugins`,{params:n})},uploadPlugin:s=>{const n=new FormData;return n.append("file",s),I.post(`${$s}/plugin/upload`,n,{headers:{"Content-Type":"multipart/form-data"}})},deletePlugin:s=>I.post(`${$s}/plugin/delete`,{code:s}),installPlugin:s=>I.post(`${$s}/plugin/install`,{code:s}),uninstallPlugin:s=>I.post(`${$s}/plugin/uninstall`,{code:s}),enablePlugin:s=>I.post(`${$s}/plugin/enable`,{code:s}),disablePlugin:s=>I.post(`${$s}/plugin/disable`,{code:s}),getPluginConfig:s=>I.get(`${$s}/plugin/config`,{params:{code:s}}),updatePluginConfig:(s,n)=>I.post(`${$s}/plugin/config`,{code:s,config:n})};window?.settings?.secure_path;Rr.config({monaco:Er});const Zd=h.object({subscribe_template_singbox:h.string().optional().default(""),subscribe_template_clash:h.string().optional().default(""),subscribe_template_clashmeta:h.string().optional().default(""),subscribe_template_stash:h.string().optional().default(""),subscribe_template_surge:h.string().optional().default(""),subscribe_template_surfboard:h.string().optional().default("")}),gr=[{key:"singbox",label:"Sing-box",language:"json"},{key:"clash",label:"Clash",language:"yaml"},{key:"clashmeta",label:"Clash Meta",language:"yaml"},{key:"stash",label:"Stash",language:"yaml"},{key:"surge",label:"Surge",language:"ini"},{key:"surfboard",label:"Surfboard",language:"ini"}],pr={subscribe_template_singbox:"",subscribe_template_clash:"",subscribe_template_clashmeta:"",subscribe_template_stash:"",subscribe_template_surge:"",subscribe_template_surfboard:""};function em(){const{t:s}=M("settings"),[n,t]=u.useState(!1),r=u.useRef(null),[a,i]=u.useState("singbox"),l=we({resolver:Te(Zd),defaultValues:pr,mode:"onChange"}),{data:d,isLoading:x}=re({queryKey:["settings","client"],queryFn:()=>ye.getSettings("subscribe_template")}),{mutateAsync:m}=Os({mutationFn:ye.saveSettings,onSuccess:()=>{z.success(s("common.autoSaved"))},onError:D=>{console.error("保存失败:",D),z.error(s("common.saveFailed"))}});u.useEffect(()=>{if(d?.data?.subscribe_template){const D=d.data.subscribe_template;Object.entries(D).forEach(([S,C])=>{if(S in pr){const T=typeof C=="string"?C:"";l.setValue(S,T)}}),r.current=l.getValues()}},[d,l]);const o=u.useCallback(Re.debounce(async D=>{if(!r.current||!Re.isEqual(D,r.current)){t(!0);try{await m(D),r.current=D}catch(S){console.error("保存设置失败:",S)}finally{t(!1)}}},1500),[m]),c=u.useCallback(()=>{const D=l.getValues();o(D)},[l,o]),f=u.useCallback((D,S)=>e.jsx(v,{control:l.control,name:D,render:({field:C})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s(`subscribe_template.${D.replace("subscribe_template_","")}.title`)}),e.jsx(y,{children:e.jsx(Vr,{height:"500px",defaultLanguage:S,value:C.value||"",onChange:T=>{C.onChange(T||""),c()},options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0}})}),e.jsx($,{children:s(`subscribe_template.${D.replace("subscribe_template_","")}.description`)}),e.jsx(P,{})]})}),[l.control,s,c]);return x?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.loading")})}):e.jsx(De,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(ft,{value:a,onValueChange:i,className:"w-full",children:[e.jsx(lt,{className:"",children:gr.map(({key:D,label:S})=>e.jsx(Ke,{value:D,className:"text-xs",children:S},D))}),gr.map(({key:D,language:S})=>e.jsx(bs,{value:D,className:"mt-4",children:f(`subscribe_template_${D}`,S)},D))]}),n&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"h-2 w-2 animate-pulse rounded-full bg-blue-500"}),s("common.saving")]})]})})}function sm(){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_template.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe_template.description")})]}),e.jsx(Ee,{}),e.jsx(em,{})]})}const tm=()=>e.jsx(Kd,{children:e.jsx(Dn,{})}),am=fo([{path:"/sign-in",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>vm);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(tm,{}),children:[{path:"/",lazy:async()=>({Component:(await Ne(()=>Promise.resolve().then(()=>Tm),void 0,import.meta.url)).default}),errorElement:e.jsx(Nt,{}),children:[{index:!0,lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Ym);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(Nt,{}),children:[{path:"system",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Zm);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>au);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>ou);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>xu);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>ju);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Nu);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Tu);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Ru);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Ou);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Hu);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe-template",element:e.jsx(sm,{})}]},{path:"payment",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Ju);return{default:s}},void 0,import.meta.url)).default})},{path:"plugin",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Zu);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>ax);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>dx);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>jx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(Nt,{}),children:[{path:"manage",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Wx);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Zx);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>rh);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(Nt,{}),children:[{path:"plan",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>hh);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Th);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Oh);return{default:s}},void 0,import.meta.url)).default})},{path:"gift-card",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>ng);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(Nt,{}),children:[{path:"manage",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Eg);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>Zg);return{default:s}},void 0,import.meta.url)).default})},{path:"traffic-reset-logs",lazy:async()=>({Component:(await Ne(async()=>{const{default:s}=await Promise.resolve().then(()=>rp);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:Nt},{path:"/404",Component:mr},{path:"/503",Component:Od},{path:"*",Component:mr}]);function nm(){return I.get("/user/info")}const on={token:ta()?.value||"",userInfo:null,isLoggedIn:!!ta()?.value,loading:!1,error:null},Qt=jo("user/fetchUserInfo",async()=>(await nm()).data,{condition:(s,{getState:n})=>{const{user:t}=n();return!!t.token&&!t.loading}}),Gl=vo({name:"user",initialState:on,reducers:{setToken(s,n){s.token=n.payload,s.isLoggedIn=!!n.payload},resetUserState:()=>on},extraReducers:s=>{s.addCase(Qt.pending,n=>{n.loading=!0,n.error=null}).addCase(Qt.fulfilled,(n,t)=>{n.loading=!1,n.userInfo=t.payload,n.error=null}).addCase(Qt.rejected,(n,t)=>{if(n.loading=!1,n.error=t.error.message||"Failed to fetch user info",!n.token)return on})}}),{setToken:rm,resetUserState:lm}=Gl.actions,im=s=>s.user.userInfo,om=Gl.reducer,Wl=bo({reducer:{user:om}});ta()?.value&&Wl.dispatch(Qt());yo.use(_o).use(No).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 cm=new wo;Co.createRoot(document.getElementById("root")).render(e.jsx(Ir.StrictMode,{children:e.jsx(So,{client:cm,children:e.jsx(ko,{store:Wl,children:e.jsxs(Ed,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(To,{router:am}),e.jsx(Do,{richColors:!0,position:"top-right"})]})})})}));const ke=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:N("rounded-xl border bg-card text-card-foreground shadow",s),...n}));ke.displayName="Card";const Fe=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:N("flex flex-col space-y-1.5 p-6",s),...n}));Fe.displayName="CardHeader";const Ve=u.forwardRef(({className:s,...n},t)=>e.jsx("h3",{ref:t,className:N("font-semibold leading-none tracking-tight",s),...n}));Ve.displayName="CardTitle";const Zs=u.forwardRef(({className:s,...n},t)=>e.jsx("p",{ref:t,className:N("text-sm text-muted-foreground",s),...n}));Zs.displayName="CardDescription";const Pe=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:N("p-6 pt-0",s),...n}));Pe.displayName="CardContent";const dm=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:N("flex items-center p-6 pt-0",s),...n}));dm.displayName="CardFooter";const k=u.forwardRef(({className:s,type:n,...t},r)=>e.jsx("input",{type:n,className:N("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:r,...t}));k.displayName="Input";const Yl=u.forwardRef(({className:s,...n},t)=>{const[r,a]=u.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:r?"text":"password",className:N("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...n}),e.jsx(F,{type:"button",size:"icon",variant:"ghost",className:"absolute right-1 top-1/2 h-6 w-6 -translate-y-1/2 rounded-md text-muted-foreground",onClick:()=>a(i=>!i),children:r?e.jsx(Fo,{size:18}):e.jsx(Po,{size:18})})]})});Yl.displayName="PasswordInput";const mm=s=>I.post("/passport/auth/login",s);function um({className:s,onForgotPassword:n,...t}){const r=Gs(),a=Mr(),{t:i}=M("auth"),l=h.object({email:h.string().min(1,{message:i("signIn.validation.emailRequired")}),password:h.string().min(1,{message:i("signIn.validation.passwordRequired")}).min(7,{message:i("signIn.validation.passwordLength")})}),d=we({resolver:Te(l),defaultValues:{email:"",password:""}});async function x(m){try{const{data:o}=await mm(m);Xd(o.auth_data),a(rm(o.auth_data)),await a(Qt()).unwrap(),r("/")}catch(o){console.error("Login failed:",o),o.response?.data?.message&&d.setError("root",{message:o.response.data.message})}}return e.jsx("div",{className:N("grid gap-6",s),...t,children:e.jsx(De,{...d,children:e.jsx("form",{onSubmit:d.handleSubmit(x),className:"space-y-4",children:e.jsxs("div",{className:"space-y-4",children:[d.formState.errors.root&&e.jsx("div",{className:"text-sm text-destructive",children:d.formState.errors.root.message}),e.jsx(v,{control:d.control,name:"email",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:i("signIn.email")}),e.jsx(y,{children:e.jsx(k,{placeholder:i("signIn.emailPlaceholder"),autoComplete:"email",...m})}),e.jsx(P,{})]})}),e.jsx(v,{control:d.control,name:"password",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:i("signIn.password")}),e.jsx(y,{children:e.jsx(Yl,{placeholder:i("signIn.passwordPlaceholder"),autoComplete:"current-password",...m})}),e.jsx(P,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(F,{variant:"link",type:"button",className:"px-0 text-sm font-normal text-muted-foreground hover:text-primary",onClick:n,children:i("signIn.forgotPassword")})}),e.jsx(F,{className:"w-full",size:"lg",loading:d.formState.isSubmitting,children:i("signIn.submit")})]})})})})}const me=Or,ps=zr,xm=$r,et=Fn,Jl=u.forwardRef(({className:s,...n},t)=>e.jsx(Va,{ref:t,className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n}));Jl.displayName=Va.displayName;const ce=u.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(xm,{children:[e.jsx(Jl,{}),e.jsxs(Ia,{ref:r,className:N("max-h-[95%] overflow-auto fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...t,children:[n,e.jsxs(Fn,{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(os,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ce.displayName=Ia.displayName;const pe=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-1.5 text-center sm:text-left",s),...n});pe.displayName="DialogHeader";const Ie=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Ie.displayName="DialogFooter";const ue=u.forwardRef(({className:s,...n},t)=>e.jsx(Ma,{ref:t,className:N("text-lg font-semibold leading-none tracking-tight",s),...n}));ue.displayName=Ma.displayName;const $e=u.forwardRef(({className:s,...n},t)=>e.jsx(Oa,{ref:t,className:N("text-sm text-muted-foreground",s),...n}));$e.displayName=Oa.displayName;const Vt=gt("inline-flex items-center justify-center gap-2 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:t,asChild:r=!1,...a},i)=>{const l=r?kn:"button";return e.jsx(l,{className:N(Vt({variant:n,size:t,className:s})),ref:i,...a})});G.displayName="Button";const Hs=Eo,Bs=Vo,hm=Io,gm=u.forwardRef(({className:s,inset:n,children:t,...r},a)=>e.jsxs(Ar,{ref:a,className:N("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",n&&"pl-8",s),...r,children:[t,e.jsx(qr,{className:"ml-auto h-4 w-4"})]}));gm.displayName=Ar.displayName;const pm=u.forwardRef(({className:s,...n},t)=>e.jsx(Hr,{ref:t,className:N("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...n}));pm.displayName=Hr.displayName;const zs=u.forwardRef(({className:s,sideOffset:n=4,...t},r)=>e.jsx(Lo,{children:e.jsx(Ur,{ref:r,sideOffset:n,className:N("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...t})}));zs.displayName=Ur.displayName;const Se=u.forwardRef(({className:s,inset:n,...t},r)=>e.jsx(Kr,{ref:r,className:N("relative flex cursor-default cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n&&"pl-8",s),...t}));Se.displayName=Kr.displayName;const Ql=u.forwardRef(({className:s,children:n,checked:t,...r},a)=>e.jsxs(Br,{ref:a,className:N("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:t,...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Gr,{children:e.jsx(pt,{className:"h-4 w-4"})})}),n]}));Ql.displayName=Br.displayName;const fm=u.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(Wr,{ref:r,className:N("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...t,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Gr,{children:e.jsx(Ro,{className:"h-4 w-4 fill-current"})})}),n]}));fm.displayName=Wr.displayName;const Ha=u.forwardRef(({className:s,inset:n,...t},r)=>e.jsx(Yr,{ref:r,className:N("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",s),...t}));Ha.displayName=Yr.displayName;const at=u.forwardRef(({className:s,...n},t)=>e.jsx(Jr,{ref:t,className:N("-mx-1 my-1 h-px bg-muted",s),...n}));at.displayName=Jr.displayName;const Cn=({className:s,...n})=>e.jsx("span",{className:N("ml-auto text-xs tracking-widest opacity-60",s),...n});Cn.displayName="DropdownMenuShortcut";const cn=[{code:"en-US",name:"English",flag:Mo,shortName:"EN"},{code:"zh-CN",name:"中文",flag:Oo,shortName:"CN"}];function Xl(){const{i18n:s}=M(),n=a=>{s.changeLanguage(a)},t=cn.find(a=>a.code===s.language)||cn[1],r=t.flag;return e.jsxs(Hs,{children:[e.jsx(Bs,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 px-2 gap-1",children:[e.jsx(r,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:"text-sm font-medium",children:t.shortName})]})}),e.jsx(zs,{align:"end",className:"w-[120px]",children:cn.map(a=>{const i=a.flag,l=a.code===s.language;return e.jsxs(Se,{onClick:()=>n(a.code),className:N("flex items-center gap-2 px-2 py-1.5 cursor-pointer",l&&"bg-accent"),children:[e.jsx(i,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:N("text-sm",l&&"font-medium"),children:a.name})]},a.code)})})]})}function jm(){const[s,n]=u.useState(!1),{t}=M("auth"),r=t("signIn.resetPassword.command");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"container relative flex min-h-svh flex-col items-center justify-center bg-primary-foreground px-4 py-8 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(Xl,{})}),e.jsxs("div",{className:"mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px] md:w-[420px] lg:p-8",children:[e.jsxs("div",{className:"flex flex-col space-y-2 text-center",children:[e.jsx("h1",{className:"text-2xl font-bold sm:text-3xl",children:window?.settings?.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:window?.settings?.description})]}),e.jsxs(ke,{className:"p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col space-y-2 text-left",children:[e.jsx("h1",{className:"text-xl font-semibold tracking-tight sm:text-2xl",children:t("signIn.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("signIn.description")})]}),e.jsx(um,{onForgotPassword:()=>n(!0)})]})]})]}),e.jsx(me,{open:s,onOpenChange:n,children:e.jsx(ce,{className:"max-w-[90vw] sm:max-w-lg",children:e.jsxs(pe,{children:[e.jsx(ue,{children:t("signIn.resetPassword.title")}),e.jsx($e,{children:t("signIn.resetPassword.description")}),e.jsx("div",{className:"mt-4",children:e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"max-w-full overflow-x-auto rounded-md bg-secondary p-4 pr-12 text-sm",children:r}),e.jsx(G,{variant:"ghost",size:"icon",className:"absolute right-2 top-2 h-8 w-8 hover:bg-secondary-foreground/10",onClick:()=>Rt(r).then(()=>{z.success(t("common:copy.success"))}),children:e.jsx(zo,{className:"h-4 w-4"})})]})})]})})})]})}const vm=Object.freeze(Object.defineProperty({__proto__:null,default:jm},Symbol.toStringTag,{value:"Module"})),Ae=u.forwardRef(({className:s,fadedBelow:n=!1,fixedHeight:t=!1,...r},a)=>e.jsx("div",{ref:a,className:N("relative flex h-full w-full flex-col",n&&"after:pointer-events-none after:absolute after:bottom-0 after:left-0 after:hidden after:h-32 after:w-full after:bg-[linear-gradient(180deg,_transparent_10%,_hsl(var(--background))_70%)] after:md:block",t&&"md:h-svh",s),...r}));Ae.displayName="Layout";const qe=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:N("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...n}));qe.displayName="LayoutHeader";const We=u.forwardRef(({className:s,fixedHeight:n,...t},r)=>e.jsx("div",{ref:r,className:N("flex-1 overflow-hidden px-4 py-6 md:px-8",n&&"h-[calc(100%-var(--header-height))]",s),...t}));We.displayName="LayoutBody";const Zl=$o,ei=Ao,si=qo,fe=Ho,xe=Uo,he=Ko,de=u.forwardRef(({className:s,sideOffset:n=4,...t},r)=>e.jsx(Qr,{ref:r,sideOffset:n,className:N("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...t}));de.displayName=Qr.displayName;function Ua(){const{pathname:s}=Tn();return{checkActiveNav:t=>{if(t==="/"&&s==="/")return!0;const r=t.replace(/^\//,""),a=s.replace(/^\//,"");return r?a.startsWith(r):!1}}}function ti({key:s,defaultValue:n}){const[t,r]=u.useState(()=>{const a=localStorage.getItem(s);return a!==null?JSON.parse(a):n});return u.useEffect(()=>{localStorage.setItem(s,JSON.stringify(t))},[t,s]),[t,r]}function bm(){const[s,n]=ti({key:"collapsed-sidebar-items",defaultValue:[]}),t=a=>!s.includes(a);return{isExpanded:t,toggleItem:a=>{t(a)?n([...s,a]):n(s.filter(i=>i!==a))}}}function ym({links:s,isCollapsed:n,className:t,closeNav:r}){const{t:a}=M(),i=({sub:l,...d})=>{const x=`${a(d.title)}-${d.href}`;return n&&l?u.createElement(wm,{...d,sub:l,key:x,closeNav:r}):n?u.createElement(Nm,{...d,key:x,closeNav:r}):l?u.createElement(_m,{...d,sub:l,key:x,closeNav:r}):u.createElement(ai,{...d,key:x,closeNav:r})};return e.jsx("div",{"data-collapsed":n,className:N("group border-b bg-background py-2 transition-[max-height,padding] duration-500 data-[collapsed=true]:py-2 md:border-none",t),children:e.jsx(fe,{delayDuration:0,children:e.jsx("nav",{className:"grid gap-1 group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2",children:s.map(i)})})})}function ai({title:s,icon:n,label:t,href:r,closeNav:a,subLink:i=!1}){const{checkActiveNav:l}=Ua(),{t:d}=M();return e.jsxs(tt,{to:r,onClick:a,className:N(It({variant:l(r)?"secondary":"ghost",size:"sm"}),"h-12 justify-start text-wrap rounded-none px-6",i&&"h-10 w-full border-l border-l-slate-500 px-2"),"aria-current":l(r)?"page":void 0,children:[e.jsx("div",{className:"mr-2",children:n}),d(s),t&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:d(t)})]})}function _m({title:s,icon:n,label:t,sub:r,closeNav:a}){const{checkActiveNav:i}=Ua(),{isExpanded:l,toggleItem:d}=bm(),{t:x}=M(),m=!!r?.find(f=>i(f.href)),o=x(s),c=l(o)||m;return e.jsxs(Zl,{open:c,onOpenChange:()=>d(o),children:[e.jsxs(ei,{className:N(It({variant:m?"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),t&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:x(t)}),e.jsx("span",{className:N('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(Xr,{stroke:1})})]}),e.jsx(si,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:r.map(f=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(ai,{...f,subLink:!0,closeNav:a})},x(f.title)))})})]})}function Nm({title:s,icon:n,label:t,href:r,closeNav:a}){const{checkActiveNav:i}=Ua(),{t:l}=M();return e.jsxs(xe,{delayDuration:0,children:[e.jsx(he,{asChild:!0,children:e.jsxs(tt,{to:r,onClick:a,className:N(It({variant:i(r)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[n,e.jsx("span",{className:"sr-only",children:l(s)})]})}),e.jsxs(de,{side:"right",className:"flex items-center gap-4",children:[l(s),t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:l(t)})]})]})}function wm({title:s,icon:n,label:t,sub:r,closeNav:a}){const{checkActiveNav:i}=Ua(),{t:l}=M(),d=!!r?.find(x=>i(x.href));return e.jsxs(Hs,{children:[e.jsxs(xe,{delayDuration:0,children:[e.jsx(he,{asChild:!0,children:e.jsx(Bs,{asChild:!0,children:e.jsx(F,{variant:d?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:n})})}),e.jsxs(de,{side:"right",className:"flex items-center gap-4",children:[l(s)," ",t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:l(t)}),e.jsx(Xr,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(zs,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(Ha,{children:[l(s)," ",t?`(${l(t)})`:""]}),e.jsx(at,{}),r.map(({title:x,icon:m,label:o,href:c})=>e.jsx(Se,{asChild:!0,children:e.jsxs(tt,{to:c,onClick:a,className:`${i(c)?"bg-secondary":""}`,children:[m," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:l(x)}),o&&e.jsx("span",{className:"ml-auto text-xs",children:l(o)})]})},`${l(x)}-${c}`))]})]})}const ni=[{title:"nav:dashboard",label:"",href:"/",icon:e.jsx(Bo,{size:18})},{title:"nav:systemManagement",label:"",href:"",icon:e.jsx(Go,{size:18}),sub:[{title:"nav:systemConfig",label:"",href:"/config/system",icon:e.jsx(Zr,{size:18})},{title:"nav:pluginManagement",label:"",href:"/config/plugin",icon:e.jsx(Pn,{size:18})},{title:"nav:themeConfig",label:"",href:"/config/theme",icon:e.jsx(Wo,{size:18})},{title:"nav:noticeManagement",label:"",href:"/config/notice",icon:e.jsx(Yo,{size:18})},{title:"nav:paymentConfig",label:"",href:"/config/payment",icon:e.jsx(sr,{size:18})},{title:"nav:knowledgeManagement",label:"",href:"/config/knowledge",icon:e.jsx(Jo,{size:18})}]},{title:"nav:nodeManagement",label:"",href:"",icon:e.jsx(el,{size:18}),sub:[{title:"nav:nodeManagement",label:"",href:"/server/manage",icon:e.jsx(Qo,{size:18})},{title:"nav:permissionGroupManagement",label:"",href:"/server/group",icon:e.jsx(sl,{size:18})},{title:"nav:routeManagement",label:"",href:"/server/route",icon:e.jsx(Xo,{size:18})}]},{title:"nav:subscriptionManagement",label:"",href:"",icon:e.jsx(Zo,{size:18}),sub:[{title:"nav:planManagement",label:"",href:"/finance/plan",icon:e.jsx(ec,{size:18})},{title:"nav:orderManagement",label:"",href:"/finance/order",icon:e.jsx(sr,{size:18})},{title:"nav:couponManagement",label:"",href:"/finance/coupon",icon:e.jsx(sc,{size:18})},{title:"nav:giftCardManagement",label:"",href:"/finance/gift-card",icon:e.jsx(tc,{size:18})}]},{title:"nav:userManagement",label:"",href:"",icon:e.jsx(ac,{size:18}),sub:[{title:"nav:userManagement",label:"",href:"/user/manage",icon:e.jsx(nc,{size:18})},{title:"nav:ticketManagement",label:"",href:"/user/ticket",icon:e.jsx(tl,{size:18})}]}];function Cm({className:s,isCollapsed:n,setIsCollapsed:t}){const[r,a]=u.useState(!1),{t:i}=M();return u.useEffect(()=>{r?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[r]),e.jsxs("aside",{className:N(`fixed left-0 right-0 top-0 z-50 flex h-auto flex-col border-r-2 border-r-muted transition-[width] md:bottom-0 md:right-auto md:h-svh ${n?"md:w-14":"md:w-64"}`,s),children:[e.jsx("div",{onClick:()=>a(!1),className:`absolute inset-0 transition-[opacity] delay-100 duration-700 ${r?"h-svh opacity-50":"h-0 opacity-0"} w-full bg-black md:hidden`}),e.jsxs(Ae,{className:`flex h-full flex-col ${r?"h-[100vh] md:h-full":""}`,children:[e.jsxs(qe,{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(F,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":i("common:toggleNavigation"),"aria-controls":"sidebar-menu","aria-expanded":r,onClick:()=>a(l=>!l),children:r?e.jsx(rc,{}):e.jsx(lc,{})})]}),e.jsx(ym,{id:"sidebar-menu",className:N("flex-1 overflow-auto overscroll-contain",r?"block":"hidden md:block","md:py-2"),closeNav:()=>a(!1),isCollapsed:n,links:ni}),e.jsx("div",{className:N("border-t border-border/50 bg-background","px-4 py-2.5 text-xs text-muted-foreground",r?"block":"hidden md:block",n?"text-center":"text-left"),children:e.jsxs("div",{className:N("flex items-center gap-1.5",n?"justify-center":"justify-start"),children:[e.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-green-500"}),e.jsxs("span",{className:N("whitespace-nowrap tracking-wide","transition-opacity duration-200",n&&"md:opacity-0"),children:["v",window?.settings?.version]})]})}),e.jsx(F,{onClick:()=>t(l=>!l),size:"icon",variant:"outline",className:"absolute -right-5 top-1/2 hidden rounded-full md:inline-flex","aria-label":i("common:toggleSidebar"),children:e.jsx(ic,{stroke:1.5,className:`h-5 w-5 ${n?"rotate-180":""}`})})]})]})}function Sm(){const[s,n]=ti({key:"collapsed-sidebar",defaultValue:!1});return u.useEffect(()=>{const t=()=>{n(window.innerWidth<768?!1:s)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[s,n]),[s,n]}function km(){const[s,n]=Sm();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(Cm,{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(Dn,{})})]})}const Tm=Object.freeze(Object.defineProperty({__proto__:null,default:km},Symbol.toStringTag,{value:"Module"})),it=u.forwardRef(({className:s,...n},t)=>e.jsx(xs,{ref:t,className:N("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...n}));it.displayName=xs.displayName;const Dm=({children:s,...n})=>e.jsx(me,{...n,children:e.jsx(ce,{className:"overflow-hidden p-0",children:e.jsx(it,{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})})}),vt=u.forwardRef(({className:s,...n},t)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(oc,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(xs.Input,{ref:t,className:N("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",s),...n})]}));vt.displayName=xs.Input.displayName;const ot=u.forwardRef(({className:s,...n},t)=>e.jsx(xs.List,{ref:t,className:N("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...n}));ot.displayName=xs.List.displayName;const bt=u.forwardRef((s,n)=>e.jsx(xs.Empty,{ref:n,className:"py-6 text-center text-sm",...s}));bt.displayName=xs.Empty.displayName;const ks=u.forwardRef(({className:s,...n},t)=>e.jsx(xs.Group,{ref:t,className:N("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",s),...n}));ks.displayName=xs.Group.displayName;const Mt=u.forwardRef(({className:s,...n},t)=>e.jsx(xs.Separator,{ref:t,className:N("-mx-1 h-px bg-border",s),...n}));Mt.displayName=xs.Separator.displayName;const rs=u.forwardRef(({className:s,...n},t)=>e.jsx(xs.Item,{ref:t,className:N("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...n}));rs.displayName=xs.Item.displayName;function Fm(){const s=[];for(const n of ni)if(n.href&&s.push(n),n.sub)for(const t of n.sub)s.push({...t,parent:n.title});return s}function cs(){const[s,n]=u.useState(!1),t=Gs(),r=Fm(),{t:a}=M("search"),{t:i}=M("nav");u.useEffect(()=>{const d=x=>{x.key==="k"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),n(m=>!m))};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[]);const l=u.useCallback(d=>{n(!1),t(d)},[t]);return e.jsxs(e.Fragment,{children:[e.jsxs(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(Ln,{className:"h-4 w-4 xl:mr-2"}),e.jsx("span",{className:"hidden xl:inline-flex",children:a("placeholder")}),e.jsx("span",{className:"sr-only",children:a("shortcut.label")}),e.jsx("kbd",{className:"pointer-events-none absolute right-1.5 top-2 hidden h-6 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium opacity-100 xl:flex",children:a("shortcut.key")})]}),e.jsxs(Dm,{open:s,onOpenChange:n,children:[e.jsx(vt,{placeholder:a("placeholder")}),e.jsxs(ot,{children:[e.jsx(bt,{children:a("noResults")}),e.jsx(ks,{heading:a("title"),children:r.map(d=>e.jsxs(rs,{value:`${d.parent?d.parent+" ":""}${d.title}`,onSelect:()=>l(d.href),children:[e.jsx("div",{className:"mr-2",children:d.icon}),e.jsx("span",{children:i(d.title)}),d.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:i(d.parent)})]},d.href))})]})]})]})}function es(){const{theme:s,setTheme:n}=Vd();return u.useEffect(()=>{const t=s==="dark"?"#020817":"#fff",r=document.querySelector("meta[name='theme-color']");r&&r.setAttribute("content",t)},[s]),e.jsxs(e.Fragment,{children:[e.jsx(F,{size:"icon",variant:"ghost",className:"rounded-full",onClick:()=>n(s==="light"?"dark":"light"),children:s==="light"?e.jsx(cc,{size:20}):e.jsx(dc,{size:20})}),e.jsx(Xl,{})]})}const ri=u.forwardRef(({className:s,...n},t)=>e.jsx(al,{ref:t,className:N("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...n}));ri.displayName=al.displayName;const li=u.forwardRef(({className:s,...n},t)=>e.jsx(nl,{ref:t,className:N("aspect-square h-full w-full",s),...n}));li.displayName=nl.displayName;const ii=u.forwardRef(({className:s,...n},t)=>e.jsx(rl,{ref:t,className:N("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...n}));ii.displayName=rl.displayName;function ss(){const s=Gs(),n=Mr(),t=mc(im),{t:r}=M(["common"]),a=()=>{Hl(),n(lm()),s("/sign-in")},i=t?.email?.split("@")[0]||r("common:user"),l=i.substring(0,2).toUpperCase();return e.jsxs(Hs,{children:[e.jsx(Bs,{asChild:!0,children:e.jsx(F,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(ri,{className:"h-8 w-8",children:[e.jsx(li,{src:t?.avatar_url,alt:i}),e.jsx(ii,{children:l})]})})}),e.jsxs(zs,{className:"w-56",align:"end",forceMount:!0,children:[e.jsx(Ha,{className:"font-normal",children:e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("p",{className:"text-sm font-medium leading-none",children:i}),e.jsx("p",{className:"text-xs leading-none text-muted-foreground",children:t?.email||r("common:defaultEmail")})]})}),e.jsx(at,{}),e.jsx(Se,{asChild:!0,children:e.jsxs(tt,{to:"/config/system",children:[r("common:settings"),e.jsx(Cn,{children:"⌘S"})]})}),e.jsx(at,{}),e.jsxs(Se,{onClick:a,children:[r("common:logout"),e.jsx(Cn,{children:"⇧⌘Q"})]})]})]})}const J=uc,fs=bc,Q=xc,W=u.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(ll,{ref:r,className:N("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",s),...t,children:[n,e.jsx(hc,{asChild:!0,children:e.jsx(Rn,{className:"h-4 w-4 opacity-50"})})]}));W.displayName=ll.displayName;const oi=u.forwardRef(({className:s,...n},t)=>e.jsx(il,{ref:t,className:N("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(gc,{className:"h-4 w-4"})}));oi.displayName=il.displayName;const ci=u.forwardRef(({className:s,...n},t)=>e.jsx(ol,{ref:t,className:N("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(Rn,{className:"h-4 w-4"})}));ci.displayName=ol.displayName;const Y=u.forwardRef(({className:s,children:n,position:t="popper",...r},a)=>e.jsx(pc,{children:e.jsxs(cl,{ref:a,className:N("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",s),position:t,...r,children:[e.jsx(oi,{}),e.jsx(fc,{className:N("p-1",t==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx(ci,{})]})}));Y.displayName=cl.displayName;const Pm=u.forwardRef(({className:s,...n},t)=>e.jsx(dl,{ref:t,className:N("px-2 py-1.5 text-sm font-semibold",s),...n}));Pm.displayName=dl.displayName;const A=u.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(ml,{ref:r,className:N("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...t,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(jc,{children:e.jsx(pt,{className:"h-4 w-4"})})}),e.jsx(vc,{children:n})]}));A.displayName=ml.displayName;const Lm=u.forwardRef(({className:s,...n},t)=>e.jsx(ul,{ref:t,className:N("-mx-1 my-1 h-px bg-muted",s),...n}));Lm.displayName=ul.displayName;function Ss({className:s,classNames:n,showOutsideDays:t=!0,captionLayout:r="label",buttonVariant:a="ghost",formatters:i,components:l,...d}){const x=xl();return e.jsx(yc,{showOutsideDays:t,className:N("bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,s),captionLayout:r,formatters:{formatMonthDropdown:m=>m.toLocaleString("default",{month:"short"}),...i},classNames:{root:N("w-fit",x.root),months:N("relative flex flex-col gap-4 md:flex-row",x.months),month:N("flex w-full flex-col gap-4",x.month),nav:N("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",x.nav),button_previous:N(Vt({variant:a}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_previous),button_next:N(Vt({variant:a}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_next),month_caption:N("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",x.month_caption),dropdowns:N("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",x.dropdowns),dropdown_root:N("has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",x.dropdown_root),dropdown:N("absolute inset-0 opacity-0",x.dropdown),caption_label:N("select-none font-medium",r==="label"?"text-sm":"[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5",x.caption_label),table:"w-full border-collapse",weekdays:N("flex",x.weekdays),weekday:N("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",x.weekday),week:N("mt-2 flex w-full",x.week),week_number_header:N("w-[--cell-size] select-none",x.week_number_header),week_number:N("text-muted-foreground select-none text-[0.8rem]",x.week_number),day:N("group/day relative aspect-square h-full w-full select-none p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md",x.day),range_start:N("bg-accent rounded-l-md",x.range_start),range_middle:N("rounded-none",x.range_middle),range_end:N("bg-accent rounded-r-md",x.range_end),today:N("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",x.today),outside:N("text-muted-foreground aria-selected:text-muted-foreground",x.outside),disabled:N("text-muted-foreground opacity-50",x.disabled),hidden:N("invisible",x.hidden),...n},components:{Root:({className:m,rootRef:o,...c})=>e.jsx("div",{"data-slot":"calendar",ref:o,className:N(m),...c}),Chevron:({className:m,orientation:o,...c})=>o==="left"?e.jsx(hl,{className:N("size-4",m),...c}):o==="right"?e.jsx(gl,{className:N("size-4",m),...c}):e.jsx(pl,{className:N("size-4",m),...c}),DayButton:Rm,WeekNumber:({children:m,...o})=>e.jsx("td",{...o,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:m})}),...l},...d})}function Rm({className:s,day:n,modifiers:t,...r}){const a=xl(),i=u.useRef(null);return u.useEffect(()=>{t.focused&&i.current?.focus()},[t.focused]),e.jsx(G,{ref:i,variant:"ghost",size:"icon","data-day":n.date.toLocaleDateString(),"data-selected-single":t.selected&&!t.range_start&&!t.range_end&&!t.range_middle,"data-range-start":t.range_start,"data-range-end":t.range_end,"data-range-middle":t.range_middle,className:N("data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 flex aspect-square h-auto w-full min-w-[--cell-size] flex-col gap-1 font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] [&>span]:text-xs [&>span]:opacity-70",a.day,s),...r})}const ls=Nc,is=wc,Xe=u.forwardRef(({className:s,align:n="center",sideOffset:t=4,...r},a)=>e.jsx(_c,{children:e.jsx(fl,{ref:a,align:n,sideOffset:t,className:N("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...r})}));Xe.displayName=fl.displayName;const Js={income:{main:"hsl(var(--primary))",gradient:{start:"hsl(var(--primary))",end:"transparent"}},commission:{main:"hsl(var(--secondary))",gradient:{start:"hsl(var(--secondary))",end:"transparent"}}},Kt=s=>(s/100).toFixed(2),Em=({active:s,payload:n,label:t})=>{const{t:r}=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:t}),n.map((a,i)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"h-2 w-2 rounded-full",style:{backgroundColor:a.color}}),e.jsxs("span",{className:"text-muted-foreground",children:[r(a.name),":"]}),e.jsx("span",{className:"font-medium",children:a.name.includes(r("dashboard:overview.amount"))?`¥${Kt(a.value)}`:r("dashboard:overview.transactions",{count:a.value})})]},i))]}):null},Vm=[{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"}],Im=(s,n)=>{const t=new Date;if(s==="custom"&&n)return{startDate:n.from,endDate:n.to};let r;switch(s){case"7d":r=Is(t,7);break;case"30d":r=Is(t,30);break;case"90d":r=Is(t,90);break;case"180d":r=Is(t,180);break;case"365d":r=Is(t,365);break;default:r=Is(t,30)}return{startDate:r,endDate:t}};function Mm(){const[s,n]=u.useState("amount"),[t,r]=u.useState("30d"),[a,i]=u.useState({from:Is(new Date,7),to:new Date}),{t:l}=M(),{startDate:d,endDate:x}=Im(t,a),{data:m}=re({queryKey:["orderStat",{start_date:Le(d,"yyyy-MM-dd"),end_date:Le(x,"yyyy-MM-dd")}],queryFn:async()=>{const{data:o}=await Fa.getOrderStat({start_date:Le(d,"yyyy-MM-dd"),end_date:Le(x,"yyyy-MM-dd")});return o},refetchInterval:3e4});return e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Ve,{children:l("dashboard:overview.title")}),e.jsxs(Zs,{children:[m?.summary.start_date," ",l("dashboard:overview.to")," ",m?.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(J,{value:t,onValueChange:o=>r(o),children:[e.jsx(W,{className:"w-[120px]",children:e.jsx(Q,{placeholder:l("dashboard:overview.selectTimeRange")})}),e.jsx(Y,{children:Vm.map(o=>e.jsx(A,{value:o.value,children:l(o.label)},o.value))})]}),t==="custom"&&e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(G,{variant:"outline",className:N("min-w-0 justify-start text-left font-normal",!a&&"text-muted-foreground"),children:[e.jsx(Cs,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:a?.from?a.to?e.jsxs(e.Fragment,{children:[Le(a.from,"yyyy-MM-dd")," -"," ",Le(a.to,"yyyy-MM-dd")]}):Le(a.from,"yyyy-MM-dd"):l("dashboard:overview.selectDate")})]})}),e.jsx(Xe,{className:"w-auto p-0",align:"end",children:e.jsx(Ss,{mode:"range",defaultMonth:a?.from,selected:{from:a?.from,to:a?.to},onSelect:o=>{o?.from&&o?.to&&i({from:o.from,to:o.to})},captionLayout:"dropdown",numberOfMonths:2})})]})]}),e.jsx(ft,{value:s,onValueChange:o=>n(o),children:e.jsxs(lt,{children:[e.jsx(Ke,{value:"amount",children:l("dashboard:overview.amount")}),e.jsx(Ke,{value:"count",children:l("dashboard:overview.count")})]})})]})]})}),e.jsxs(Pe,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:l("dashboard:overview.totalIncome")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",Kt(m?.summary?.paid_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l("dashboard:overview.totalTransactions",{count:m?.summary?.paid_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l("dashboard:overview.avgOrderAmount")," ¥",Kt(m?.summary?.avg_paid_amount||0)]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:l("dashboard:overview.totalCommission")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",Kt(m?.summary?.commission_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l("dashboard:overview.totalTransactions",{count:m?.summary?.commission_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l("dashboard:overview.commissionRate")," ",m?.summary?.commission_rate.toFixed(2)||0,"%"]})]})]}),e.jsx("div",{className:"h-[400px] w-full",children:e.jsx(Cc,{width:"100%",height:"100%",children:e.jsxs(Sc,{data:m?.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:Js.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Js.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:Js.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Js.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(kc,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:o=>Le(new Date(o),"MM-dd",{locale:Pc})}),e.jsx(Tc,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:o=>s==="amount"?`¥${Kt(o)}`:l("dashboard:overview.transactions",{count:o})}),e.jsx(Dc,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(Fc,{content:e.jsx(Em,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(tr,{type:"monotone",dataKey:"paid_total",name:l("dashboard:overview.orderAmount"),stroke:Js.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(tr,{type:"monotone",dataKey:"commission_total",name:l("dashboard:overview.commissionAmount"),stroke:Js.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(ar,{dataKey:"paid_count",name:l("dashboard:overview.orderCount"),fill:Js.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(ar,{dataKey:"commission_count",name:l("dashboard:overview.commissionCount"),fill:Js.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})]})]})}function be({className:s,...n}){return e.jsx("div",{className:N("animate-pulse rounded-md bg-primary/10",s),...n})}function Om(){return e.jsxs(ke,{children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(be,{className:"h-4 w-[120px]"}),e.jsx(be,{className:"h-4 w-4"})]}),e.jsxs(Pe,{children:[e.jsx(be,{className:"h-8 w-[140px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(be,{className:"h-4 w-4"}),e.jsx(be,{className:"h-4 w-[100px]"})]})]})]})}function zm(){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(Om,{},n))})}var ie=(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))(ie||{});const At={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},qt={0:"yellow-500",1:"blue-500",2:"red-500",3:"green-500",4:"green-500"};var Ms=(s=>(s[s.NEW=1]="NEW",s[s.RENEWAL=2]="RENEWAL",s[s.UPGRADE=3]="UPGRADE",s[s.RESET_FLOW=4]="RESET_FLOW",s))(Ms||{}),Ce=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(Ce||{});const xa={0:"待确认",1:"发放中",2:"有效",3:"无效"},ha={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var Qe=(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))(Qe||{});const $m={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var ge=(s=>(s.Shadowsocks="shadowsocks",s.Vmess="vmess",s.Trojan="trojan",s.Hysteria="hysteria",s.Vless="vless",s.Tuic="tuic",s.Socks="socks",s.Naive="naive",s.Http="http",s.Mieru="mieru",s.AnyTLS="anytls",s))(ge||{});const Fs=[{type:"shadowsocks",label:"Shadowsocks"},{type:"vmess",label:"VMess"},{type:"trojan",label:"Trojan"},{type:"hysteria",label:"Hysteria"},{type:"vless",label:"VLess"},{type:"tuic",label:"TUIC"},{type:"socks",label:"SOCKS"},{type:"naive",label:"Naive"},{type:"http",label:"HTTP"},{type:"mieru",label:"Mieru"},{type:"anytls",label:"AnyTLS"}],vs={shadowsocks:"#489851",vmess:"#CB3180",trojan:"#EBB749",hysteria:"#5684e6",vless:"#1a1a1a",tuic:"#00C853",socks:"#2196F3",naive:"#9C27B0",http:"#FF5722",mieru:"#4CAF50",anytls:"#7E57C2"};var ws=(s=>(s[s.AMOUNT=1]="AMOUNT",s[s.PERCENTAGE=2]="PERCENTAGE",s))(ws||{});const Am={1:"按金额优惠",2:"按比例优惠"};var st=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(st||{}),ms=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(ms||{}),Xt=(s=>(s.MONTH="monthly",s.QUARTER="quarterly",s.HALF_YEAR="half_yearly",s.YEAR="yearly",s.TWO_YEAR="two_yearly",s.THREE_YEAR="three_yearly",s.ONETIME="onetime",s.RESET="reset_traffic",s))(Xt||{});function Qs({title:s,value:n,icon:t,trend:r,description:a,onClick:i,highlight:l,className:d}){return e.jsxs(ke,{className:N("transition-colors",i&&"cursor-pointer hover:bg-muted/50",l&&"border-primary/50",d),onClick:i,children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ve,{className:"text-sm font-medium",children:s}),t]}),e.jsxs(Pe,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n}),r?e.jsxs("div",{className:"flex items-center pt-1",children:[e.jsx(Vc,{className:N("h-4 w-4",r.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:N("ml-1 text-xs",r.isPositive?"text-emerald-500":"text-red-500"),children:[r.isPositive?"+":"-",Math.abs(r.value),"%"]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:r.label})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:a})]})]})}function qm({className:s}){const n=Gs(),{t}=M(),{data:r,isLoading:a}=re({queryKey:["dashboardStats"],queryFn:async()=>(await Fa.getStatsData()).data,refetchInterval:1e3*60*5});if(a||!r)return e.jsx(zm,{});const i=()=>{const l=new URLSearchParams;l.set("commission_status",Ce.PENDING.toString()),l.set("status",ie.COMPLETED.toString()),l.set("commission_balance","gt:0"),n(`/finance/order?${l.toString()}`)};return e.jsxs("div",{className:N("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(Qs,{title:t("dashboard:stats.todayIncome"),value:Ks(r.todayIncome),icon:e.jsx(Lc,{className:"h-4 w-4 text-emerald-500"}),trend:{value:r.dayIncomeGrowth,label:t("dashboard:stats.vsYesterday"),isPositive:r.dayIncomeGrowth>0}}),e.jsx(Qs,{title:t("dashboard:stats.monthlyIncome"),value:Ks(r.currentMonthIncome),icon:e.jsx(En,{className:"h-4 w-4 text-blue-500"}),trend:{value:r.monthIncomeGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:r.monthIncomeGrowth>0}}),e.jsx(Qs,{title:t("dashboard:stats.pendingTickets"),value:r.ticketPendingTotal,icon:e.jsx(Rc,{className:N("h-4 w-4",r.ticketPendingTotal>0?"text-orange-500":"text-muted-foreground")}),description:r.ticketPendingTotal>0?t("dashboard:stats.hasPendingTickets"):t("dashboard:stats.noPendingTickets"),onClick:()=>n("/user/ticket"),highlight:r.ticketPendingTotal>0}),e.jsx(Qs,{title:t("dashboard:stats.pendingCommission"),value:r.commissionPendingTotal,icon:e.jsx(Ec,{className:N("h-4 w-4",r.commissionPendingTotal>0?"text-blue-500":"text-muted-foreground")}),description:r.commissionPendingTotal>0?t("dashboard:stats.hasPendingCommission"):t("dashboard:stats.noPendingCommission"),onClick:i,highlight:r.commissionPendingTotal>0}),e.jsx(Qs,{title:t("dashboard:stats.monthlyNewUsers"),value:r.currentMonthNewUsers,icon:e.jsx(wa,{className:"h-4 w-4 text-blue-500"}),trend:{value:r.userGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:r.userGrowth>0}}),e.jsx(Qs,{title:t("dashboard:stats.totalUsers"),value:r.totalUsers,icon:e.jsx(wa,{className:"h-4 w-4 text-muted-foreground"}),description:t("dashboard:stats.activeUsers",{count:r.activeUsers})}),e.jsx(Qs,{title:t("dashboard:stats.monthlyUpload"),value:ze(r.monthTraffic.upload),icon:e.jsx(Lt,{className:"h-4 w-4 text-emerald-500"}),description:t("dashboard:stats.todayTraffic",{value:ze(r.todayTraffic.upload)})}),e.jsx(Qs,{title:t("dashboard:stats.monthlyDownload"),value:ze(r.monthTraffic.download),icon:e.jsx(sa,{className:"h-4 w-4 text-blue-500"}),description:t("dashboard:stats.todayTraffic",{value:ze(r.todayTraffic.download)})})]})}const ht=u.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(jl,{ref:r,className:N("relative overflow-hidden",s),...t,children:[e.jsx(Ic,{className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(La,{}),e.jsx(Mc,{})]}));ht.displayName=jl.displayName;const La=u.forwardRef(({className:s,orientation:n="vertical",...t},r)=>e.jsx(vl,{ref:r,orientation:n,className:N("flex touch-none select-none transition-colors",n==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",n==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",s),...t,children:e.jsx(Oc,{className:"relative flex-1 rounded-full bg-border"})}));La.displayName=vl.displayName;const Sn={today:{getValue:()=>{const s=$c();return{start:s,end:Ac(s,1)}}},last7days:{getValue:()=>{const s=new Date;return{start:Is(s,7),end:s}}},last30days:{getValue:()=>{const s=new Date;return{start:Is(s,30),end:s}}},custom:{getValue:()=>null}};function fr({selectedRange:s,customDateRange:n,onRangeChange:t,onCustomRangeChange:r}){const{t:a}=M(),i={today:a("dashboard:trafficRank.today"),last7days:a("dashboard:trafficRank.last7days"),last30days:a("dashboard:trafficRank.last30days"),custom:a("dashboard:trafficRank.customRange")};return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsxs(J,{value:s,onValueChange:t,children:[e.jsx(W,{className:"w-[120px]",children:e.jsx(Q,{placeholder:a("dashboard:trafficRank.selectTimeRange")})}),e.jsx(Y,{position:"popper",className:"z-50",children:Object.entries(Sn).map(([l])=>e.jsx(A,{value:l,children:i[l]},l))})]}),s==="custom"&&e.jsxs(ls,{children:[e.jsx(is,{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(Cs,{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:[Le(n.from,"yyyy-MM-dd")," -"," ",Le(n.to,"yyyy-MM-dd")]}):Le(n.from,"yyyy-MM-dd"):e.jsx("span",{children:a("dashboard:trafficRank.selectDateRange")})})]})}),e.jsx(Xe,{className:"w-auto p-0",align:"end",children:e.jsx(Ss,{mode:"range",defaultMonth:n?.from,selected:{from:n?.from,to:n?.to},onSelect:l=>{l?.from&&l?.to&&r({from:l.from,to:l.to})},numberOfMonths:2})})]})]})}const kt=s=>`${(s/1024/1024/1024).toFixed(2)} GB`;function Hm({className:s}){const{t:n}=M(),[t,r]=u.useState("today"),[a,i]=u.useState({from:Is(new Date,7),to:new Date}),[l,d]=u.useState("today"),[x,m]=u.useState({from:Is(new Date,7),to:new Date}),o=u.useMemo(()=>t==="custom"?{start:a.from,end:a.to}:Sn[t].getValue(),[t,a]),c=u.useMemo(()=>l==="custom"?{start:x.from,end:x.to}:Sn[l].getValue(),[l,x]),{data:f}=re({queryKey:["nodeTrafficRank",o.start,o.end],queryFn:()=>Fa.getNodeTrafficData({type:"node",start_time:Re.round(o.start.getTime()/1e3),end_time:Re.round(o.end.getTime()/1e3)}),refetchInterval:3e4}),{data:D}=re({queryKey:["userTrafficRank",c.start,c.end],queryFn:()=>Fa.getNodeTrafficData({type:"user",start_time:Re.round(c.start.getTime()/1e3),end_time:Re.round(c.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:N("grid gap-4 md:grid-cols-2",s),children:[e.jsxs(ke,{children:[e.jsx(Fe,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Ve,{className:"flex items-center text-base font-medium",children:[e.jsx(zc,{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(fr,{selectedRange:t,customDateRange:a,onRangeChange:r,onCustomRangeChange:i}),e.jsx(nr,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Pe,{className:"flex-1",children:f?.data?e.jsxs(ht,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:f.data.map(S=>e.jsx(fe,{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:S.name}),e.jsxs("span",{className:N("ml-2 flex items-center text-xs font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?e.jsx(fn,{className:"mr-1 h-3 w-3"}):e.jsx(jn,{className:"mr-1 h-3 w-3"}),Math.abs(S.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:`${S.value/f.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:kt(S.value)})]})]})})}),e.jsx(de,{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:kt(S.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:kt(S.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:N("font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?"+":"",S.change,"%"]})]})})]})},S.id))}),e.jsx(La,{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(ke,{children:[e.jsx(Fe,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Ve,{className:"flex items-center text-base font-medium",children:[e.jsx(wa,{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(fr,{selectedRange:l,customDateRange:x,onRangeChange:d,onCustomRangeChange:m}),e.jsx(nr,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Pe,{className:"flex-1",children:D?.data?e.jsxs(ht,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:D.data.map(S=>e.jsx(fe,{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:S.name}),e.jsxs("span",{className:N("ml-2 flex items-center text-xs font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?e.jsx(fn,{className:"mr-1 h-3 w-3"}):e.jsx(jn,{className:"mr-1 h-3 w-3"}),Math.abs(S.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:`${S.value/D.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:kt(S.value)})]})]})})}),e.jsx(de,{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:kt(S.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:kt(S.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:N("font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?"+":"",S.change,"%"]})]})})]})},S.id))}),e.jsx(La,{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 Um=gt("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/10",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function q({className:s,variant:n,...t}){return e.jsx("div",{className:N(Um({variant:n}),s),...t})}const ba=u.forwardRef(({className:s,value:n,...t},r)=>e.jsx(bl,{ref:r,className:N("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...t,children:e.jsx(qc,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(n||0)}%)`}})}));ba.displayName=bl.displayName;const $n=u.forwardRef(({className:s,...n},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:N("w-full caption-bottom text-sm",s),...n})}));$n.displayName="Table";const An=u.forwardRef(({className:s,...n},t)=>e.jsx("thead",{ref:t,className:N("[&_tr]:border-b",s),...n}));An.displayName="TableHeader";const qn=u.forwardRef(({className:s,...n},t)=>e.jsx("tbody",{ref:t,className:N("[&_tr:last-child]:border-0",s),...n}));qn.displayName="TableBody";const Km=u.forwardRef(({className:s,...n},t)=>e.jsx("tfoot",{ref:t,className:N("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...n}));Km.displayName="TableFooter";const Xs=u.forwardRef(({className:s,...n},t)=>e.jsx("tr",{ref:t,className:N("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...n}));Xs.displayName="TableRow";const Hn=u.forwardRef(({className:s,...n},t)=>e.jsx("th",{ref:t,className:N("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));Hn.displayName="TableHead";const Pt=u.forwardRef(({className:s,...n},t)=>e.jsx("td",{ref:t,className:N("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));Pt.displayName="TableCell";const Bm=u.forwardRef(({className:s,...n},t)=>e.jsx("caption",{ref:t,className:N("mt-4 text-sm text-muted-foreground",s),...n}));Bm.displayName="TableCaption";function di({table:s}){const[n,t]=u.useState(""),{t:r}=M("common");u.useEffect(()=>{t((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const a=i=>{const l=parseInt(i);!isNaN(l)&&l>=1&&l<=s.getPageCount()?s.setPageIndex(l-1):t((s.getState().pagination.pageIndex+1).toString())};return e.jsxs("div",{className:"flex flex-col-reverse gap-4 px-2 py-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"flex-1 text-sm text-muted-foreground",children:r("table.pagination.selected",{selected:s.getFilteredSelectedRowModel().rows.length,total:s.getFilteredRowModel().rows.length})}),e.jsxs("div",{className:"flex flex-col-reverse items-center gap-4 sm:flex-row sm:gap-6 lg:gap-8",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:r("table.pagination.itemsPerPage")}),e.jsxs(J,{value:`${s.getState().pagination.pageSize}`,onValueChange:i=>{s.setPageSize(Number(i))},children:[e.jsx(W,{className:"h-8 w-[70px]",children:e.jsx(Q,{placeholder:s.getState().pagination.pageSize})}),e.jsx(Y,{side:"top",children:[10,20,30,40,50,100,500].map(i=>e.jsx(A,{value:`${i}`,children:i},i))})]})]}),e.jsxs("div",{className:"flex items-center justify-center space-x-2 text-sm font-medium",children:[e.jsx("span",{children:r("table.pagination.page")}),e.jsx(k,{type:"text",value:n,onChange:i=>t(i.target.value),onBlur:i=>a(i.target.value),onKeyDown:i=>{i.key==="Enter"&&a(i.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsx("span",{children:r("table.pagination.pageOf",{total:s.getPageCount()})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(F,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(0),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.firstPage")}),e.jsx(Hc,{className:"h-4 w-4"})]}),e.jsxs(F,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.previousPage")}),e.jsx(Uc,{className:"h-4 w-4"})]}),e.jsxs(F,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.nextPage")}),e.jsx(qr,{className:"h-4 w-4"})]}),e.jsxs(F,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(s.getPageCount()-1),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.lastPage")}),e.jsx(Kc,{className:"h-4 w-4"})]})]})]})]})}function ts({table:s,toolbar:n,draggable:t=!1,onDragStart:r,onDragEnd:a,onDragOver:i,onDragLeave:l,onDrop:d,showPagination:x=!0,isLoading:m=!1}){const{t:o}=M("common"),c=u.useRef(null),f=s.getAllColumns().filter(T=>T.getIsPinned()==="left"),D=s.getAllColumns().filter(T=>T.getIsPinned()==="right"),S=T=>f.slice(0,T).reduce((w,E)=>w+(E.getSize()??0),0),C=T=>D.slice(T+1).reduce((w,E)=>w+(E.getSize()??0),0);return e.jsxs("div",{className:"space-y-4",children:[typeof n=="function"?n(s):n,e.jsx("div",{ref:c,className:"relative overflow-auto rounded-md border bg-card",children:e.jsx("div",{className:"overflow-auto",children:e.jsxs($n,{children:[e.jsx(An,{children:s.getHeaderGroups().map(T=>e.jsx(Xs,{className:"hover:bg-transparent",children:T.headers.map((w,E)=>{const _=w.column.getIsPinned()==="left",g=w.column.getIsPinned()==="right",p=_?S(f.indexOf(w.column)):void 0,V=g?C(D.indexOf(w.column)):void 0;return e.jsx(Hn,{colSpan:w.colSpan,style:{width:w.getSize(),..._&&{left:p},...g&&{right:V}},className:N("h-11 bg-card px-4 text-muted-foreground",(_||g)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",_&&"before:right-0",g&&"before:left-0"]),children:w.isPlaceholder?null:Ca(w.column.columnDef.header,w.getContext())},w.id)})},T.id))}),e.jsx(qn,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((T,w)=>e.jsx(Xs,{"data-state":T.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:t,onDragStart:E=>r?.(E,w),onDragEnd:a,onDragOver:i,onDragLeave:l,onDrop:E=>d?.(E,w),children:T.getVisibleCells().map((E,_)=>{const g=E.column.getIsPinned()==="left",p=E.column.getIsPinned()==="right",V=g?S(f.indexOf(E.column)):void 0,R=p?C(D.indexOf(E.column)):void 0;return e.jsx(Pt,{style:{width:E.column.getSize(),...g&&{left:V},...p&&{right:R}},className:N("bg-card",(g||p)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",g&&"before:right-0",p&&"before:left-0"]),children:Ca(E.column.columnDef.cell,E.getContext())},E.id)})},T.id)):e.jsx(Xs,{children:e.jsx(Pt,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:o("table.noData")})})})]})})}),x&&e.jsx(di,{table:s})]})}const ya=s=>{if(!s)return"";let n;if(typeof s=="string"){if(n=parseInt(s),isNaN(n))return s}else n=s;return(n.toString().length===10?new Date(n*1e3):new Date(n)).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})},Ht=yl(),Ut=yl();function ga({data:s,isLoading:n,searchKeyword:t,selectedLevel:r,total:a,currentPage:i,pageSize:l,onViewDetail:d,onPageChange:x,onPageSizeChange:m}){const{t:o}=M(),c=S=>{switch(S.toLowerCase()){case"info":return e.jsx(Gt,{className:"h-4 w-4 text-blue-500"});case"warning":return e.jsx(Wt,{className:"h-4 w-4 text-yellow-500"});case"error":return e.jsx(yn,{className:"h-4 w-4 text-red-500"});default:return e.jsx(Gt,{className:"h-4 w-4 text-slate-500"})}},f=u.useMemo(()=>[Ht.accessor("level",{id:"level",header:()=>o("dashboard:systemLog.level"),size:80,cell:({getValue:S,row:C})=>{const T=S();return e.jsxs("div",{className:"flex items-center gap-1",children:[c(T),e.jsx("span",{className:N(T.toLowerCase()==="error"&&"text-red-600",T.toLowerCase()==="warning"&&"text-yellow-600",T.toLowerCase()==="info"&&"text-blue-600"),children:T})]})}}),Ht.accessor("created_at",{id:"created_at",header:()=>o("dashboard:systemLog.time"),size:160,cell:({getValue:S})=>ya(S())}),Ht.accessor(S=>S.title||S.message||"",{id:"title",header:()=>o("dashboard:systemLog.logTitle"),cell:({getValue:S})=>e.jsx("span",{className:"inline-block max-w-[300px] truncate",children:S()})}),Ht.accessor("method",{id:"method",header:()=>o("dashboard:systemLog.method"),size:100,cell:({getValue:S})=>{const C=S();return C?e.jsx(q,{variant:"outline",className:N(C==="GET"&&"border-blue-200 bg-blue-50 text-blue-700",C==="POST"&&"border-green-200 bg-green-50 text-green-700",C==="PUT"&&"border-amber-200 bg-amber-50 text-amber-700",C==="DELETE"&&"border-red-200 bg-red-50 text-red-700"),children:C}):null}}),Ht.display({id:"actions",header:()=>o("dashboard:systemLog.action"),size:80,cell:({row:S})=>e.jsx(G,{variant:"ghost",size:"sm",onClick:()=>d(S.original),"aria-label":o("dashboard:systemLog.viewDetail"),children:e.jsx(vn,{className:"h-4 w-4"})})})],[o,d]),D=Be({data:s,columns:f,getCoreRowModel:Ge(),getPaginationRowModel:Ze(),pageCount:Math.ceil(a/l),manualPagination:!0,state:{pagination:u.useMemo(()=>({pageIndex:i-1,pageSize:l}),[i,l])},onPaginationChange:S=>{let C,T;if(typeof S=="function"){const w=S({pageIndex:i-1,pageSize:l});C=w.pageIndex,T=w.pageSize}else C=S.pageIndex,T=S.pageSize;T!==l?m(T):x(C+1)}});return e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(ts,{table:D,showPagination:!0,isLoading:n}),(t||r&&r!=="all")&&e.jsx("div",{className:"text-center text-sm text-muted-foreground",children:t&&r&&r!=="all"?o("dashboard:systemLog.filter.searchAndLevel",{keyword:t,level:r,count:a}):t?o("dashboard:systemLog.filter.searchOnly",{keyword:t,count:a}):o("dashboard:systemLog.filter.levelOnly",{level:r,count:a})})]})}function Gm(){const{t:s}=M(),[n,t]=u.useState(0),[r,a]=u.useState(!1),[i,l]=u.useState(1),[d]=u.useState(10),[x,m]=u.useState(null),[o,c]=u.useState(!1),[f,D]=u.useState(!1),[S,C]=u.useState(1),[T,w]=u.useState(10),[E,_]=u.useState(null),[g,p]=u.useState(!1),[V,R]=u.useState(""),[L,K]=u.useState(""),[Z,se]=u.useState("all"),[ae,H]=u.useState(!1),[ee,je]=u.useState(0),[ds,Me]=u.useState("all"),[le,Ts]=u.useState(1e3),[Ns,Ws]=u.useState(!1),[Us,Ys]=u.useState(null),[yt,U]=u.useState(!1);u.useEffect(()=>{const B=setTimeout(()=>{K(V),V!==L&&C(1)},500);return()=>clearTimeout(B)},[V]);const{data:te,isLoading:ne,refetch:ve,isRefetching:Ye}=re({queryKey:["systemStatus",n],queryFn:async()=>(await ye.getSystemStatus()).data,refetchInterval:3e4}),{data:_e,isLoading:Ki,refetch:lp,isRefetching:Yn}=re({queryKey:["queueStats",n],queryFn:async()=>(await ye.getQueueStats()).data,refetchInterval:3e4}),{data:Jn,isLoading:Bi,refetch:Gi}=re({queryKey:["failedJobs",i,d],queryFn:async()=>{const B=await ye.getHorizonFailedJobs({current:i,page_size:d});return{data:B.data,total:B.total||0}},enabled:r}),{data:Qn,isLoading:ra,refetch:Wi}=re({queryKey:["systemLogs",S,T,Z,L],queryFn:async()=>{const B={current:S,page_size:T};Z&&Z!=="all"&&(B.level=Z),L.trim()&&(B.keyword=L.trim());const Vs=await ye.getSystemLog(B);return{data:Vs.data,total:Vs.total||0}},enabled:f}),Xn=Jn?.data||[],Yi=Jn?.total||0,la=Qn?.data||[],ia=Qn?.total||0,Ji=u.useMemo(()=>[Ut.display({id:"failed_at",header:()=>s("dashboard:queue.details.time"),cell:({row:B})=>ya(B.original.failed_at)}),Ut.display({id:"queue",header:()=>s("dashboard:queue.details.queue"),cell:({row:B})=>B.original.queue}),Ut.display({id:"name",header:()=>s("dashboard:queue.details.name"),cell:({row:B})=>e.jsx(fe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[150px] truncate",children:B.original.name})}),e.jsx(de,{children:e.jsx("span",{children:B.original.name})})]})})}),Ut.display({id:"exception",header:()=>s("dashboard:queue.details.exception"),cell:({row:B})=>e.jsx(fe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[200px] truncate",children:B.original.exception.split(`
|
||
`)[0]})}),e.jsx(de,{className:"max-w-[300px] whitespace-pre-wrap",children:e.jsx("span",{children:B.original.exception})})]})})}),Ut.display({id:"actions",header:()=>s("dashboard:queue.details.action"),size:80,cell:({row:B})=>e.jsx(G,{variant:"ghost",size:"sm",onClick:()=>eo(B.original),"aria-label":s("dashboard:queue.details.viewDetail"),children:e.jsx(vn,{className:"h-4 w-4"})})})],[s]),Zn=Be({data:Xn,columns:Ji,getCoreRowModel:Ge(),getPaginationRowModel:Ze(),pageCount:Math.ceil(Yi/d),manualPagination:!0,state:{pagination:{pageIndex:i-1,pageSize:d}},onPaginationChange:B=>{if(typeof B=="function"){const Vs=B({pageIndex:i-1,pageSize:d});er(Vs.pageIndex+1)}else er(B.pageIndex+1)}}),Qi=()=>{t(B=>B+1)},er=B=>{l(B)},oa=B=>{C(B)},ca=B=>{w(B),C(1)},Xi=B=>{se(B),C(1)},Zi=()=>{R(""),K(""),se("all"),C(1)},da=B=>{_(B),p(!0)},eo=B=>{m(B),c(!0)},so=async()=>{try{const B=await ye.getLogClearStats({days:ee,level:ds==="all"?void 0:ds});Ys(B.data),U(!0)}catch(B){console.error("Failed to get clear stats:",B),z.error(s("dashboard:systemLog.getStatsFailed"))}},to=async()=>{Ws(!0);try{const{data:B}=await ye.clearSystemLog({days:ee,level:ds==="all"?void 0:ds,limit:le});B&&(z.success(s("dashboard:systemLog.clearSuccess",{count:B.cleared_count}),{duration:3e3}),H(!1),U(!1),Ys(null),ve())}catch(B){console.error("Failed to clear logs:",B),z.error(s("dashboard:systemLog.clearLogsFailed"))}finally{Ws(!1)}};if(ne||Ki)return e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx(Sa,{className:"h-6 w-6 animate-spin"})});const ao=B=>B?e.jsx(_l,{className:"h-5 w-5 text-green-500"}):e.jsx(Nl,{className:"h-5 w-5 text-red-500"});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(ke,{children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Ve,{className:"flex items-center gap-2",children:[e.jsx(Bc,{className:"h-5 w-5"}),s("dashboard:queue.title")]}),e.jsx(Zs,{children:s("dashboard:queue.status.description")})]}),e.jsx(G,{variant:"outline",size:"icon",onClick:Qi,disabled:Ye||Yn,children:e.jsx(nn,{className:N("h-4 w-4",(Ye||Yn)&&"animate-spin")})})]}),e.jsx(Pe,{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:[ao(_e?.status||!1),e.jsx("span",{className:"font-medium",children:s("dashboard:queue.status.running")})]}),e.jsx(q,{variant:_e?.status?"secondary":"destructive",children:_e?.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:_e?.wait?.default||0})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(fe,{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:_e?.recentJobs||0}),e.jsx(ba,{value:(_e?.recentJobs||0)/(_e?.periods?.recentJobs||1)*100,className:"h-1"})]})}),e.jsx(de,{children:e.jsx("p",{children:s("dashboard:queue.details.statisticsPeriod",{hours:_e?.periods?.recentJobs||0})})})]})}),e.jsx(fe,{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:_e?.jobsPerMinute||0}),e.jsx(ba,{value:(_e?.jobsPerMinute||0)/(_e?.queueWithMaxThroughput?.throughput||1)*100,className:"h-1"})]})}),e.jsx(de,{children:e.jsx("p",{children:s("dashboard:queue.details.maxThroughput",{value:_e?.queueWithMaxThroughput?.throughput||0})})})]})})]})]})})]}),e.jsxs(ke,{children:[e.jsxs(Fe,{children:[e.jsxs(Ve,{className:"flex items-center gap-2",children:[e.jsx(Gc,{className:"h-5 w-5"}),s("dashboard:queue.jobDetails")]}),e.jsx(Zs,{children:s("dashboard:queue.details.description")})]}),e.jsx(Pe,{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.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"cursor-pointer text-2xl font-bold text-destructive hover:underline",title:s("dashboard:queue.details.viewFailedJobs"),onClick:()=>a(!0),style:{userSelect:"none"},children:_e?.failedJobs||0}),e.jsx(vn,{className:"h-4 w-4 cursor-pointer text-muted-foreground hover:text-destructive",onClick:()=>a(!0),"aria-label":s("dashboard:queue.details.viewFailedJobs")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("dashboard:queue.details.retentionPeriod",{hours:_e?.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:[_e?.queueWithMaxRuntime?.runtime||0,"s"]}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:_e?.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:[_e?.processes||0," /"," ",(_e?.processes||0)+(_e?.pausedMasters||0)]})]}),e.jsx(ba,{value:(_e?.processes||0)/((_e?.processes||0)+(_e?.pausedMasters||0))*100,className:"mt-2 h-1"})]})]})})]})]}),e.jsxs(ke,{children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Ve,{className:"flex items-center gap-2",children:[e.jsx(bn,{className:"h-5 w-5"}),s("dashboard:systemLog.title")]}),e.jsx(Zs,{children:s("dashboard:systemLog.description")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{variant:"outline",onClick:()=>D(!0),children:s("dashboard:systemLog.viewAll")}),e.jsxs(G,{variant:"outline",onClick:()=>H(!0),className:"text-destructive hover:text-destructive",children:[e.jsx(us,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.clearLogs")]})]})]}),e.jsx(Pe,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg border border-blue-200 bg-blue-50 p-3 dark:border-blue-900 dark:bg-blue-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gt,{className:"h-5 w-5 text-blue-500"}),e.jsx("p",{className:"font-medium text-blue-700 dark:text-blue-300",children:s("dashboard:systemLog.tabs.info")})]}),e.jsx("p",{className:"text-2xl font-bold text-blue-700 dark:text-blue-300",children:te?.logs?.info||0})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-yellow-200 bg-yellow-50 p-3 dark:border-yellow-900 dark:bg-yellow-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Wt,{className:"h-5 w-5 text-yellow-500"}),e.jsx("p",{className:"font-medium text-yellow-700 dark:text-yellow-300",children:s("dashboard:systemLog.tabs.warning")})]}),e.jsx("p",{className:"text-2xl font-bold text-yellow-700 dark:text-yellow-300",children:te?.logs?.warning||0})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-red-200 bg-red-50 p-3 dark:border-red-900 dark:bg-red-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(yn,{className:"h-5 w-5 text-red-500"}),e.jsx("p",{className:"font-medium text-red-700 dark:text-red-300",children:s("dashboard:systemLog.tabs.error")})]}),e.jsx("p",{className:"text-2xl font-bold text-red-700 dark:text-red-300",children:te?.logs?.error||0})]})]}),te?.logs&&te.logs.total>0&&e.jsxs("div",{className:"mt-3 text-center text-sm text-muted-foreground",children:[s("dashboard:systemLog.totalLogs"),": ",te.logs.total]})]})})]}),e.jsx(me,{open:r,onOpenChange:a,children:e.jsxs(ce,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(pe,{children:e.jsx(ue,{children:s("dashboard:queue.details.failedJobsDetailTitle")})}),e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(ts,{table:Zn,showPagination:!1,isLoading:Bi}),e.jsx(di,{table:Zn}),Xn.length===0&&e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:s("dashboard:queue.details.noFailedJobs")})]}),e.jsxs(Ie,{children:[e.jsxs(G,{variant:"outline",onClick:()=>Gi(),children:[e.jsx(nn,{className:"mr-2 h-4 w-4"}),s("dashboard:common.refresh")]}),e.jsx(et,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})]})]})}),e.jsx(me,{open:o,onOpenChange:c,children:e.jsxs(ce,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(pe,{children:e.jsx(ue,{children:s("dashboard:queue.details.jobDetailTitle")})}),x&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.id")}),e.jsx("p",{className:"break-all rounded-md bg-muted/50 p-2 text-sm",children:x.id})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.time")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:x.failed_at})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.queue")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:x.queue})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.connection")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:x.connection})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.name")}),e.jsx("p",{className:"break-all rounded-md bg-muted/50 p-2 text-sm",children:x.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.exception")}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto rounded-md bg-red-50 p-3 dark:bg-red-950/30",children:e.jsx("pre",{className:"whitespace-pre-wrap text-xs text-red-700 dark:text-red-300",children:x.exception})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.payload")}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto rounded-md bg-muted/50 p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs",children:(()=>{try{return JSON.stringify(JSON.parse(x.payload),null,2)}catch{return x.payload}})()})})]})]}),e.jsx(Ie,{children:e.jsx(G,{variant:"outline",onClick:()=>c(!1),children:s("common:close")})})]})}),e.jsx(me,{open:f,onOpenChange:D,children:e.jsxs(ce,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(pe,{children:e.jsx(ue,{children:s("dashboard:systemLog.title")})}),e.jsxs(ft,{value:Z,onValueChange:Xi,className:"w-full overflow-x-auto",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-2 p-1 md:flex-row md:items-center md:justify-between",children:[e.jsxs(lt,{className:"grid w-auto grid-cols-4",children:[e.jsxs(Ke,{value:"all",className:"flex items-center gap-2",children:[e.jsx(bn,{className:"h-4 w-4"}),s("dashboard:systemLog.tabs.all")]}),e.jsxs(Ke,{value:"info",className:"flex items-center gap-2",children:[e.jsx(Gt,{className:"h-4 w-4 text-blue-500"}),s("dashboard:systemLog.tabs.info")]}),e.jsxs(Ke,{value:"warning",className:"flex items-center gap-2",children:[e.jsx(Wt,{className:"h-4 w-4 text-yellow-500"}),s("dashboard:systemLog.tabs.warning")]}),e.jsxs(Ke,{value:"error",className:"flex items-center gap-2",children:[e.jsx(yn,{className:"h-4 w-4 text-red-500"}),s("dashboard:systemLog.tabs.error")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ln,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(k,{placeholder:s("dashboard:systemLog.search"),value:V,onChange:B=>R(B.target.value),className:"w-full md:w-64"})]})]}),e.jsx(bs,{value:"all",className:"mt-0",children:e.jsx(ga,{data:la,isLoading:ra,searchKeyword:L,selectedLevel:Z,total:ia,currentPage:S,pageSize:T,onViewDetail:da,onPageChange:oa,onPageSizeChange:ca})}),e.jsx(bs,{value:"info",className:"mt-0 overflow-x-auto",children:e.jsx(ga,{data:la,isLoading:ra,searchKeyword:L,selectedLevel:Z,total:ia,currentPage:S,pageSize:T,onViewDetail:da,onPageChange:oa,onPageSizeChange:ca})}),e.jsx(bs,{value:"warning",className:"mt-0",children:e.jsx(ga,{data:la,isLoading:ra,searchKeyword:L,selectedLevel:Z,total:ia,currentPage:S,pageSize:T,onViewDetail:da,onPageChange:oa,onPageSizeChange:ca})}),e.jsx(bs,{value:"error",className:"mt-0",children:e.jsx(ga,{data:la,isLoading:ra,searchKeyword:L,selectedLevel:Z,total:ia,currentPage:S,pageSize:T,onViewDetail:da,onPageChange:oa,onPageSizeChange:ca})})]}),e.jsxs(Ie,{children:[e.jsxs(G,{variant:"outline",onClick:()=>Wi(),children:[e.jsx(nn,{className:"mr-2 h-4 w-4"}),s("dashboard:common.refresh")]}),e.jsx(G,{variant:"outline",onClick:Zi,children:s("dashboard:systemLog.filter.reset")}),e.jsx(et,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})]})]})}),e.jsx(me,{open:g,onOpenChange:p,children:e.jsxs(ce,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(pe,{children:e.jsx(ue,{children:s("dashboard:systemLog.detailTitle")})}),E&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.level")}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Gt,{className:"h-4 w-4"}),e.jsx("p",{className:"font-medium",children:E.level})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.time")}),e.jsx("p",{children:ya(E.created_at)||ya(E.updated_at)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.logTitle")}),e.jsx("div",{className:"whitespace-pre-wrap rounded-md bg-muted/50 p-3",children:E.title||E.message||""})]}),(E.host||E.ip)&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[E.host&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.host")}),e.jsx("p",{className:"break-all rounded-md bg-muted/50 p-2 text-sm",children:E.host})]}),E.ip&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.ip")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:E.ip})]})]}),E.uri&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.uri")}),e.jsx("div",{className:"overflow-x-auto rounded-md bg-muted/50 p-3",children:e.jsx("code",{className:"text-sm",children:E.uri})})]}),E.method&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.method")}),e.jsx("div",{children:e.jsx(q,{variant:"outline",className:"text-base font-medium",children:E.method})})]}),E.data&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.requestData")}),e.jsx("div",{className:"max-h-[150px] overflow-y-auto rounded-md bg-muted/50 p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs",children:(()=>{try{return JSON.stringify(JSON.parse(E.data),null,2)}catch{return E.data}})()})})]}),E.context&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.exception")}),e.jsx("div",{className:"max-h-[250px] overflow-y-auto rounded-md bg-red-50 p-3 dark:bg-red-950/30",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs text-red-700 dark:text-red-300",children:(()=>{try{const B=JSON.parse(E.context);if(B.exception){const Vs=B.exception,_t=Vs["\0*\0message"]||"",no=Vs["\0*\0file"]||"",ro=Vs["\0*\0line"]||"";return`${_t}
|
||
|
||
File: ${no}
|
||
Line: ${ro}`}return JSON.stringify(B,null,2)}catch{return E.context}})()})})]})]}),e.jsx(Ie,{children:e.jsx(et,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})})]})}),e.jsx(me,{open:ae,onOpenChange:H,children:e.jsxs(ce,{className:"max-w-2xl",children:[e.jsx(pe,{children:e.jsxs(ue,{className:"flex items-center gap-2",children:[e.jsx(us,{className:"h-5 w-5 text-destructive"}),s("dashboard:systemLog.clearLogs")]})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Je,{htmlFor:"clearDays",children:s("dashboard:systemLog.clearDays")}),e.jsx(k,{id:"clearDays",type:"number",min:"0",max:"365",value:ee,onChange:B=>{const Vs=B.target.value;if(Vs==="")je(0);else{const _t=parseInt(Vs);!isNaN(_t)&&_t>=0&&_t<=365&&je(_t)}},placeholder:"0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("dashboard:systemLog.clearDaysDesc")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Je,{htmlFor:"clearLevel",children:s("dashboard:systemLog.clearLevel")}),e.jsxs(J,{value:ds,onValueChange:Me,children:[e.jsx(W,{children:e.jsx(Q,{})}),e.jsxs(Y,{children:[e.jsx(A,{value:"all",children:s("dashboard:systemLog.tabs.all")}),e.jsx(A,{value:"info",children:s("dashboard:systemLog.tabs.info")}),e.jsx(A,{value:"warning",children:s("dashboard:systemLog.tabs.warning")}),e.jsx(A,{value:"error",children:s("dashboard:systemLog.tabs.error")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Je,{htmlFor:"clearLimit",children:s("dashboard:systemLog.clearLimit")}),e.jsx(k,{id:"clearLimit",type:"number",min:"100",max:"10000",value:le,onChange:B=>Ts(parseInt(B.target.value)||1e3),placeholder:"1000"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("dashboard:systemLog.clearLimitDesc")})]})]}),e.jsxs("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-900 dark:bg-amber-950/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(En,{className:"h-5 w-5 text-amber-600"}),e.jsx("span",{className:"font-medium text-amber-800 dark:text-amber-200",children:s("dashboard:systemLog.clearPreview")})]}),e.jsxs(G,{variant:"outline",size:"sm",onClick:so,disabled:Ns,children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.getStats")]})]}),yt&&Us&&e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:systemLog.cutoffDate")}),e.jsx("p",{className:"font-mono text-sm",children:Us.cutoff_date})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:systemLog.totalLogs")}),e.jsx("p",{className:"font-mono text-sm font-medium",children:Us.total_logs.toLocaleString()})]})]}),e.jsxs("div",{className:"rounded-md bg-red-50 p-3 dark:bg-red-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Wt,{className:"h-4 w-4 text-red-600"}),e.jsxs("span",{className:"text-sm font-medium text-red-800 dark:text-red-200",children:[s("dashboard:systemLog.willClear"),":",e.jsx("span",{className:"ml-1 font-bold",children:Us.logs_to_clear.toLocaleString()}),s("dashboard:systemLog.logsUnit")]})]}),e.jsx("p",{className:"mt-1 text-xs text-red-600 dark:text-red-300",children:s("dashboard:systemLog.clearWarning")})]})]})]})]}),e.jsxs(Ie,{children:[e.jsx(G,{variant:"outline",onClick:()=>{H(!1),U(!1),Ys(null)},children:s("common:cancel")}),e.jsx(G,{variant:"destructive",onClick:to,disabled:Ns||!yt||!Us,children:Ns?e.jsxs(e.Fragment,{children:[e.jsx(Sa,{className:"mr-2 h-4 w-4 animate-spin"}),s("dashboard:systemLog.clearing")]}):e.jsxs(e.Fragment,{children:[e.jsx(us,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.confirmClear")]})})]})]})})]})}function Wm(){const{t:s}=M();return e.jsxs(Ae,{children:[e.jsxs(qe,{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(cs,{}),e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsx(We,{children:e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsx(qm,{}),e.jsx(Mm,{}),e.jsx(Hm,{}),e.jsx(Gm,{})]})})})]})}const Ym=Object.freeze(Object.defineProperty({__proto__:null,default:Wm},Symbol.toStringTag,{value:"Module"}));function Jm({className:s,items:n,...t}){const{pathname:r}=Tn(),a=Gs(),[i,l]=u.useState(r??"/settings"),d=m=>{l(m),a(m)},{t:x}=M("settings");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-1 md:hidden",children:e.jsxs(J,{value:i,onValueChange:d,children:[e.jsx(W,{className:"h-12 sm:w-48",children:e.jsx(Q,{placeholder:"Theme"})}),e.jsx(Y,{children:n.map(m=>e.jsx(A,{value:m.href,children:e.jsxs("div",{className:"flex gap-x-4 px-2 py-1",children:[e.jsx("span",{className:"scale-125",children:m.icon}),e.jsx("span",{className:"text-md",children:x(m.title)})]})},m.href))})]})}),e.jsx("div",{className:"hidden w-full overflow-x-auto bg-background px-1 py-2 md:block",children:e.jsx("nav",{className:N("flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",s),...t,children:n.map(m=>e.jsxs(tt,{to:m.href,className:N(It({variant:"ghost"}),r===m.href?"bg-muted hover:bg-muted":"hover:bg-transparent hover:underline","justify-start"),children:[e.jsx("span",{className:"mr-2",children:m.icon}),x(m.title)]},m.href))})})]})}const Qm=[{title:"site.title",key:"site",icon:e.jsx(Wc,{size:18}),href:"/config/system",description:"site.description"},{title:"safe.title",key:"safe",icon:e.jsx(sl,{size:18}),href:"/config/system/safe",description:"safe.description"},{title:"subscribe.title",key:"subscribe",icon:e.jsx(tl,{size:18}),href:"/config/system/subscribe",description:"subscribe.description"},{title:"invite.title",key:"invite",icon:e.jsx(Yc,{size:18}),href:"/config/system/invite",description:"invite.description"},{title:"server.title",key:"server",icon:e.jsx(el,{size:18}),href:"/config/system/server",description:"server.description"},{title:"email.title",key:"email",icon:e.jsx(Jc,{size:18}),href:"/config/system/email",description:"email.description"},{title:"telegram.title",key:"telegram",icon:e.jsx(Qc,{size:18}),href:"/config/system/telegram",description:"telegram.description"},{title:"app.title",key:"app",icon:e.jsx(Zr,{size:18}),href:"/config/system/app",description:"app.description"},{title:"subscribe_template.title",key:"subscribe_template",icon:e.jsx(Xc,{size:18}),href:"/config/system/subscribe-template",description:"subscribe_template.description"}];function Xm(){const{t:s}=M("settings");return e.jsxs(Ae,{fadedBelow:!0,fixedHeight:!0,children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(Ee,{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(Jm,{items:Qm})}),e.jsx("div",{className:"flex-1 w-full p-1 pr-4",children:e.jsx("div",{className:"pb-16",children:e.jsx(Dn,{})})})]})]})]})}const Zm=Object.freeze(Object.defineProperty({__proto__:null,default:Xm},Symbol.toStringTag,{value:"Module"})),X=u.forwardRef(({className:s,...n},t)=>e.jsx(wl,{className:N("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s),...n,ref:t,children:e.jsx(Zc,{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")})}));X.displayName=wl.displayName;const Es=u.forwardRef(({className:s,...n},t)=>e.jsx("textarea",{className:N("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...n}));Es.displayName="Textarea";const eu=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 su(){const{t:s}=M("settings"),[n,t]=u.useState(!1),r=u.useRef(null),{data:a}=re({queryKey:["settings","site"],queryFn:()=>ye.getSettings("site")}),{data:i}=re({queryKey:["plans"],queryFn:()=>ys.getList()}),l=we({resolver:Te(eu),defaultValues:{},mode:"onBlur"}),{mutateAsync:d}=Os({mutationFn:ye.saveSettings,onSuccess:o=>{o.data&&z.success(s("common.autoSaved"))}});u.useEffect(()=>{if(a?.data?.site){const o=a?.data?.site;Object.entries(o).forEach(([c,f])=>{l.setValue(c,f)}),r.current=o}},[a]);const x=u.useCallback(Re.debounce(async o=>{if(!Re.isEqual(o,r.current)){t(!0);try{const c=Object.entries(o).reduce((f,[D,S])=>(f[D]=S===null?"":S,f),{});await d(c),r.current=o}finally{t(!1)}}},1e3),[d]),m=u.useCallback(o=>{x(o)},[x]);return u.useEffect(()=>{const o=l.watch(c=>{m(c)});return()=>o.unsubscribe()},[l.watch,m]),e.jsx(De,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:l.control,name:"app_name",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.siteName.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("site.form.siteName.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(l.getValues())}})}),e.jsx($,{children:s("site.form.siteName.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"app_description",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.siteDescription.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("site.form.siteDescription.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(l.getValues())}})}),e.jsx($,{children:s("site.form.siteDescription.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"app_url",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.siteUrl.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("site.form.siteUrl.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(l.getValues())}})}),e.jsx($,{children:s("site.form.siteUrl.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"force_https",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("site.form.forceHttps.label")}),e.jsx($,{children:s("site.form.forceHttps.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:!!o.value,onCheckedChange:c=>{o.onChange(Number(c)),m(l.getValues())}})})]})}),e.jsx(v,{control:l.control,name:"logo",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.logo.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("site.form.logo.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(l.getValues())}})}),e.jsx($,{children:s("site.form.logo.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"subscribe_url",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.subscribeUrl.label")}),e.jsx(y,{children:e.jsx(Es,{placeholder:s("site.form.subscribeUrl.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(l.getValues())}})}),e.jsx($,{children:s("site.form.subscribeUrl.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"tos_url",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.tosUrl.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("site.form.tosUrl.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(l.getValues())}})}),e.jsx($,{children:s("site.form.tosUrl.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"stop_register",render:({field:o})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("site.form.stopRegister.label")}),e.jsx($,{children:s("site.form.stopRegister.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:!!o.value,onCheckedChange:c=>{o.onChange(Number(c)),m(l.getValues())}})})]})}),e.jsx(v,{control:l.control,name:"try_out_plan_id",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.tryOut.label")}),e.jsx(y,{children:e.jsxs(J,{value:o.value?.toString(),onValueChange:c=>{o.onChange(Number(c)),m(l.getValues())},children:[e.jsx(W,{children:e.jsx(Q,{placeholder:s("site.form.tryOut.placeholder")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:s("site.form.tryOut.placeholder")}),i?.data?.map(c=>e.jsx(A,{value:c.id.toString(),children:c.name},c.id.toString()))]})]})}),e.jsx($,{children:s("site.form.tryOut.description")}),e.jsx(P,{})]})}),!!l.watch("try_out_plan_id")&&e.jsx(v,{control:l.control,name:"try_out_hour",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"",children:s("site.form.tryOut.duration.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("site.form.tryOut.duration.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(l.getValues())}})}),e.jsx($,{children:s("site.form.tryOut.duration.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"currency",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.currency.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("site.form.currency.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(l.getValues())}})}),e.jsx($,{children:s("site.form.currency.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"currency_symbol",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("site.form.currencySymbol.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("site.form.currencySymbol.placeholder"),...o,value:o.value||"",onChange:c=>{o.onChange(c),m(l.getValues())}})}),e.jsx($,{children:s("site.form.currencySymbol.description")}),e.jsx(P,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("site.form.saving")})]})})}function tu(){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(Ee,{}),e.jsx(su,{})]})}const au=Object.freeze(Object.defineProperty({__proto__:null,default:tu},Symbol.toStringTag,{value:"Module"})),nu=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(),captcha_enable:h.boolean().nullable(),captcha_type:h.string().nullable(),recaptcha_key:h.string().nullable(),recaptcha_site_key:h.string().nullable(),recaptcha_v3_secret_key:h.string().nullable(),recaptcha_v3_site_key:h.string().nullable(),recaptcha_v3_score_threshold:h.coerce.string().transform(s=>s===""?null:s).nullable(),turnstile_secret_key:h.string().nullable(),turnstile_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()}),ru={email_verify:!1,safe_mode_enable:!1,secure_path:"",email_whitelist_enable:!1,email_whitelist_suffix:[],email_gmail_limit_enable:!1,captcha_enable:!1,captcha_type:"recaptcha",recaptcha_key:"",recaptcha_site_key:"",recaptcha_v3_secret_key:"",recaptcha_v3_site_key:"",recaptcha_v3_score_threshold:"0.5",turnstile_secret_key:"",turnstile_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 lu(){const{t:s}=M("settings"),[n,t]=u.useState(!1),[r,a]=u.useState(!1),i=u.useRef(null),l=we({resolver:Te(nu),defaultValues:ru,mode:"onBlur"}),{data:d}=re({queryKey:["settings","safe"],queryFn:()=>ye.getSettings("safe")}),{mutateAsync:x}=Os({mutationFn:ye.saveSettings,onSuccess:c=>{c.data&&z.success(s("common.autoSaved"))}});u.useEffect(()=>{if(d?.data.safe){const c=d.data.safe,f={};Object.entries(c).forEach(([D,S])=>{if(typeof S=="number"){const C=String(S);l.setValue(D,C),f[D]=C}else l.setValue(D,S),f[D]=S}),i.current=f,a(!0)}},[d]);const m=u.useCallback(Re.debounce(async c=>{if(!Re.isEqual(c,i.current)){t(!0);try{const f={...c,email_whitelist_suffix:c.email_whitelist_suffix?.filter(Boolean)||[]};await x(f),i.current=c}finally{t(!1)}}},1e3),[x]),o=u.useCallback(c=>{r&&m(c)},[m,r]);return u.useEffect(()=>{if(!r)return;const c=l.watch(f=>{o(f)});return()=>c.unsubscribe()},[l.watch,o,r]),e.jsx(De,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:l.control,name:"email_verify",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.emailVerify.label")}),e.jsx($,{children:s("safe.form.emailVerify.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value||!1,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),e.jsx(v,{control:l.control,name:"email_gmail_limit_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.gmailLimit.label")}),e.jsx($,{children:s("safe.form.gmailLimit.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value||!1,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),e.jsx(v,{control:l.control,name:"safe_mode_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.safeMode.label")}),e.jsx($,{children:s("safe.form.safeMode.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value||!1,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),e.jsx(v,{control:l.control,name:"secure_path",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.securePath.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.securePath.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.securePath.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"email_whitelist_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.emailWhitelist.label")}),e.jsx($,{children:s("safe.form.emailWhitelist.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value||!1,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),l.watch("email_whitelist_enable")&&e.jsx(v,{control:l.control,name:"email_whitelist_suffix",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.emailWhitelist.suffixes.label")}),e.jsx(y,{children:e.jsx(Es,{placeholder:s("safe.form.emailWhitelist.suffixes.placeholder"),...c,value:(c.value||[]).join(`
|
||
`),onChange:f=>{const D=f.target.value.split(`
|
||
`).filter(Boolean);c.onChange(D),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.emailWhitelist.suffixes.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"captcha_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.captcha.enable.label")}),e.jsx($,{children:s("safe.form.captcha.enable.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value||!1,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),l.watch("captcha_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:l.control,name:"captcha_type",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.captcha.type.label")}),e.jsxs(J,{onValueChange:f=>{c.onChange(f),o(l.getValues())},value:c.value||"recaptcha",children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:s("safe.form.captcha.type.description")})})}),e.jsxs(Y,{children:[e.jsx(A,{value:"recaptcha",children:s("safe.form.captcha.type.options.recaptcha")}),e.jsx(A,{value:"recaptcha-v3",children:s("safe.form.captcha.type.options.recaptcha-v3")}),e.jsx(A,{value:"turnstile",children:s("safe.form.captcha.type.options.turnstile")})]})]}),e.jsx($,{children:s("safe.form.captcha.type.description")}),e.jsx(P,{})]})}),l.watch("captcha_type")==="recaptcha"&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:l.control,name:"recaptcha_site_key",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.captcha.recaptcha.siteKey.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.captcha.recaptcha.siteKey.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.captcha.recaptcha.siteKey.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"recaptcha_key",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.captcha.recaptcha.key.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.captcha.recaptcha.key.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.captcha.recaptcha.key.description")}),e.jsx(P,{})]})})]}),l.watch("captcha_type")==="recaptcha-v3"&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:l.control,name:"recaptcha_v3_site_key",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.siteKey.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.captcha.recaptcha_v3.siteKey.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.captcha.recaptcha_v3.siteKey.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"recaptcha_v3_secret_key",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.secretKey.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.captcha.recaptcha_v3.secretKey.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.captcha.recaptcha_v3.secretKey.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"recaptcha_v3_score_threshold",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.scoreThreshold.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",step:"0.1",min:"0",max:"1",placeholder:s("safe.form.captcha.recaptcha_v3.scoreThreshold.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.captcha.recaptcha_v3.scoreThreshold.description")}),e.jsx(P,{})]})})]}),l.watch("captcha_type")==="turnstile"&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:l.control,name:"turnstile_site_key",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.captcha.turnstile.siteKey.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.captcha.turnstile.siteKey.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.captcha.turnstile.siteKey.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"turnstile_secret_key",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.captcha.turnstile.secretKey.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.captcha.turnstile.secretKey.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.captcha.turnstile.secretKey.description")}),e.jsx(P,{})]})})]})]}),e.jsx(v,{control:l.control,name:"register_limit_by_ip_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.registerLimit.enable.label")}),e.jsx($,{children:s("safe.form.registerLimit.enable.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value||!1,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),l.watch("register_limit_by_ip_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:l.control,name:"register_limit_count",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.registerLimit.count.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.registerLimit.count.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.registerLimit.count.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"register_limit_expire",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.registerLimit.expire.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.registerLimit.expire.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.registerLimit.expire.description")}),e.jsx(P,{})]})})]}),e.jsx(v,{control:l.control,name:"password_limit_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("safe.form.passwordLimit.enable.label")}),e.jsx($,{children:s("safe.form.passwordLimit.enable.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value||!1,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),l.watch("password_limit_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:l.control,name:"password_limit_count",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.passwordLimit.count.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.passwordLimit.count.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.passwordLimit.count.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"password_limit_expire",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("safe.form.passwordLimit.expire.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("safe.form.passwordLimit.expire.placeholder"),...c,value:c.value||"",onChange:f=>{c.onChange(f),o(l.getValues())}})}),e.jsx($,{children:s("safe.form.passwordLimit.expire.description")}),e.jsx(P,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("safe.form.saving")})]})})}function iu(){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(Ee,{}),e.jsx(lu,{})]})}const ou=Object.freeze(Object.defineProperty({__proto__:null,default:iu},Symbol.toStringTag,{value:"Module"})),cu=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")}),du={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 mu(){const{t:s}=M("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=we({resolver:Te(cu),defaultValues:du,mode:"onBlur"}),{data:i}=re({queryKey:["settings","subscribe"],queryFn:()=>ye.getSettings("subscribe")}),{mutateAsync:l}=Os({mutationFn:ye.saveSettings,onSuccess:m=>{m.data&&z.success(s("common.autoSaved"))}});u.useEffect(()=>{if(i?.data?.subscribe){const m=i?.data?.subscribe;Object.entries(m).forEach(([o,c])=>{a.setValue(o,c)}),r.current=m}},[i]);const d=u.useCallback(Re.debounce(async m=>{if(!Re.isEqual(m,r.current)){t(!0);try{await l(m),r.current=m}finally{t(!1)}}},1e3),[l]),x=u.useCallback(m=>{d(m)},[d]);return u.useEffect(()=>{const m=a.watch(o=>{x(o)});return()=>m.unsubscribe()},[a.watch,x]),e.jsx(De,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:a.control,name:"plan_change_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.plan_change_enable.title")}),e.jsx($,{children:s("subscribe.plan_change_enable.description")}),e.jsx(y,{children:e.jsx(X,{checked:m.value||!1,onCheckedChange:o=>{m.onChange(o),x(a.getValues())}})}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"reset_traffic_method",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.reset_traffic_method.title")}),e.jsxs(J,{onValueChange:m.onChange,value:m.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择重置方式"})})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:s("subscribe.reset_traffic_method.options.monthly_first")}),e.jsx(A,{value:"1",children:s("subscribe.reset_traffic_method.options.monthly_reset")}),e.jsx(A,{value:"2",children:s("subscribe.reset_traffic_method.options.no_reset")}),e.jsx(A,{value:"3",children:s("subscribe.reset_traffic_method.options.yearly_first")}),e.jsx(A,{value:"4",children:s("subscribe.reset_traffic_method.options.yearly_reset")})]})]}),e.jsx($,{children:s("subscribe.reset_traffic_method.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"surplus_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.surplus_enable.title")}),e.jsx($,{children:s("subscribe.surplus_enable.description")}),e.jsx(y,{children:e.jsx(X,{checked:m.value||!1,onCheckedChange:o=>{m.onChange(o),x(a.getValues())}})}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"new_order_event_id",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.new_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(J,{onValueChange:m.onChange,value:m.value?.toString(),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择"})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:s("subscribe.new_order_event.options.no_action")}),e.jsx(A,{value:"1",children:s("subscribe.new_order_event.options.reset_traffic")})]})]})})}),e.jsx($,{children:s("subscribe.new_order_event.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"renew_order_event_id",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.renew_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(J,{onValueChange:m.onChange,value:m.value?.toString(),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择"})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:s("subscribe.renew_order_event.options.no_action")}),e.jsx(A,{value:"1",children:s("subscribe.renew_order_event.options.reset_traffic")})]})]})})}),e.jsx($,{children:s("subscribe.renew_order_event.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"change_order_event_id",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.change_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(y,{children:e.jsxs(J,{onValueChange:m.onChange,value:m.value?.toString(),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择"})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:s("subscribe.change_order_event.options.no_action")}),e.jsx(A,{value:"1",children:s("subscribe.change_order_event.options.reset_traffic")})]})]})})}),e.jsx($,{children:s("subscribe.change_order_event.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"subscribe_path",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("subscribe.subscribe_path.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:"subscribe",...m,value:m.value||"",onChange:o=>{m.onChange(o),x(a.getValues())}})}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s("subscribe.subscribe_path.description"),e.jsx("br",{}),s("subscribe.subscribe_path.current_format",{path:m.value||"s"}),e.jsx("br",{}),s("subscribe.subscribe_path.restart_tip")]}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"show_info_to_server_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("subscribe.show_info_to_server.title")}),e.jsx($,{children:s("subscribe.show_info_to_server.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:m.value||!1,onCheckedChange:o=>{m.onChange(o),x(a.getValues())}})})]})}),e.jsx(v,{control:a.control,name:"show_protocol_to_server_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("subscribe.show_protocol_to_server.title")}),e.jsx($,{children:s("subscribe.show_protocol_to_server.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:m.value||!1,onCheckedChange:o=>{m.onChange(o),x(a.getValues())}})})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function uu(){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(Ee,{}),e.jsx(mu,{})]})}const xu=Object.freeze(Object.defineProperty({__proto__:null,default:uu},Symbol.toStringTag,{value:"Module"})),hu=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)}),gu={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 pu(){const{t:s}=M("settings"),[n,t]=u.useState(!1),[r,a]=u.useState(!1),i=u.useRef(null),l=we({resolver:Te(hu),defaultValues:gu,mode:"onBlur"}),{data:d}=re({queryKey:["settings","invite"],queryFn:()=>ye.getSettings("invite")}),{mutateAsync:x}=Os({mutationFn:ye.saveSettings,onSuccess:c=>{c.data&&z.success(s("common.autoSaved"))}});u.useEffect(()=>{if(d?.data?.invite){const c=d?.data?.invite,f={};Object.entries(c).forEach(([D,S])=>{if(typeof S=="number"){const C=String(S);l.setValue(D,C),f[D]=C}else l.setValue(D,S),f[D]=S}),i.current=f,a(!0)}},[d]);const m=u.useCallback(Re.debounce(async c=>{if(!Re.isEqual(c,i.current)){t(!0);try{await x(c),i.current=c}finally{t(!1)}}},1e3),[x]),o=u.useCallback(c=>{r&&m(c)},[m,r]);return u.useEffect(()=>{if(!r)return;const c=l.watch(f=>{o(f)});return()=>c.unsubscribe()},[l.watch,o,r]),e.jsx(De,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:l.control,name:"invite_force",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.invite_force.title")}),e.jsx($,{children:s("invite.invite_force.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),e.jsx(v,{control:l.control,name:"invite_commission",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("invite.invite_commission.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("invite.invite_commission.placeholder"),...c,value:c.value||""})}),e.jsx($,{children:s("invite.invite_commission.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"invite_gen_limit",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("invite.invite_gen_limit.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("invite.invite_gen_limit.placeholder"),...c,value:c.value||""})}),e.jsx($,{children:s("invite.invite_gen_limit.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"invite_never_expire",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.invite_never_expire.title")}),e.jsx($,{children:s("invite.invite_never_expire.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),e.jsx(v,{control:l.control,name:"commission_first_time_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.commission_first_time.title")}),e.jsx($,{children:s("invite.commission_first_time.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),e.jsx(v,{control:l.control,name:"commission_auto_check_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.commission_auto_check.title")}),e.jsx($,{children:s("invite.commission_auto_check.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),e.jsx(v,{control:l.control,name:"commission_withdraw_limit",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("invite.commission_withdraw_limit.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("invite.commission_withdraw_limit.placeholder"),...c,value:c.value||""})}),e.jsx($,{children:s("invite.commission_withdraw_limit.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"commission_withdraw_method",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("invite.commission_withdraw_method.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("invite.commission_withdraw_method.placeholder"),...c,value:Array.isArray(c.value)?c.value.join(","):"",onChange:f=>{const D=f.target.value.split(",").filter(Boolean);c.onChange(D),o(l.getValues())}})}),e.jsx($,{children:s("invite.commission_withdraw_method.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"withdraw_close_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.withdraw_close.title")}),e.jsx($,{children:s("invite.withdraw_close.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),e.jsx(v,{control:l.control,name:"commission_distribution_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("invite.commission_distribution.title")}),e.jsx($,{children:s("invite.commission_distribution.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value,onCheckedChange:f=>{c.onChange(f),o(l.getValues())}})})]})}),l.watch("commission_distribution_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(v,{control:l.control,name:"commission_distribution_l1",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{children:s("invite.commission_distribution.l1")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...c,value:c.value||"",onChange:f=>{const D=f.target.value?Number(f.target.value):0;c.onChange(D),o(l.getValues())}})}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"commission_distribution_l2",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{children:s("invite.commission_distribution.l2")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...c,value:c.value||"",onChange:f=>{const D=f.target.value?Number(f.target.value):0;c.onChange(D),o(l.getValues())}})}),e.jsx(P,{})]})}),e.jsx(v,{control:l.control,name:"commission_distribution_l3",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{children:s("invite.commission_distribution.l3")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...c,value:c.value||"",onChange:f=>{const D=f.target.value?Number(f.target.value):0;c.onChange(D),o(l.getValues())}})}),e.jsx(P,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("invite.saving")})]})})}function fu(){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(Ee,{}),e.jsx(pu,{})]})}const ju=Object.freeze(Object.defineProperty({__proto__:null,default:fu},Symbol.toStringTag,{value:"Module"})),vu=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()}),bu={frontend_theme:"",frontend_theme_sidebar:"",frontend_theme_header:"",frontend_theme_color:"",frontend_background_url:""};function yu(){const{data:s}=re({queryKey:["settings","frontend"],queryFn:()=>ye.getSettings("frontend")}),n=we({resolver:Te(vu),defaultValues:bu,mode:"onChange"});u.useEffect(()=>{if(s?.data?.frontend){const r=s?.data?.frontend;Object.entries(r).forEach(([a,i])=>{n.setValue(a,i)})}},[s]);function t(r){ye.saveSettings(r).then(({data:a})=>{a&&z.success("更新成功")})}return e.jsx(De,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(t),className:"space-y-8",children:[e.jsx(v,{control:n.control,name:"frontend_theme_sidebar",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:"边栏风格"}),e.jsx($,{children:"边栏风格"})]}),e.jsx(y,{children:e.jsx(X,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(v,{control:n.control,name:"frontend_theme_header",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:"头部风格"}),e.jsx($,{children:"边栏风格"})]}),e.jsx(y,{children:e.jsx(X,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(v,{control:n.control,name:"frontend_theme_color",render:({field:r})=>e.jsxs(j,{children:[e.jsx(b,{children:"主题色"}),e.jsxs("div",{className:"relative w-max",children:[e.jsx(y,{children:e.jsxs("select",{className:N(It({variant:"outline"}),"w-[200px] appearance-none font-normal"),...r,children:[e.jsx("option",{value:"default",children:"默认"}),e.jsx("option",{value:"black",children:"黑色"}),e.jsx("option",{value:"blackblue",children:"暗蓝色"}),e.jsx("option",{value:"green",children:"奶绿色"})]})}),e.jsx(Rn,{className:"absolute right-3 top-2.5 h-4 w-4 opacity-50"})]}),e.jsx($,{children:"主题色"}),e.jsx(P,{})]})}),e.jsx(v,{control:n.control,name:"frontend_background_url",render:({field:r})=>e.jsxs(j,{children:[e.jsx(b,{children:"背景"}),e.jsx(y,{children:e.jsx(k,{placeholder:"请输入图片地址",...r})}),e.jsx($,{children:"将会在后台登录页面进行展示。"}),e.jsx(P,{})]})}),e.jsx(F,{type:"submit",children:"保存设置"})]})})}function _u(){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(Ee,{}),e.jsx(yu,{})]})}const Nu=Object.freeze(Object.defineProperty({__proto__:null,default:_u},Symbol.toStringTag,{value:"Module"})),wu=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()}),Cu={server_pull_interval:0,server_push_interval:0,server_token:"",device_limit_mode:0};function Su(){const{t:s}=M("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=we({resolver:Te(wu),defaultValues:Cu,mode:"onBlur"}),{data:i}=re({queryKey:["settings","server"],queryFn:()=>ye.getSettings("server")}),{mutateAsync:l}=Os({mutationFn:ye.saveSettings,onSuccess:o=>{o.data&&z.success(s("common.AutoSaved"))}});u.useEffect(()=>{if(i?.data.server){const o=i.data.server;Object.entries(o).forEach(([c,f])=>{a.setValue(c,f)}),r.current=o}},[i]);const d=u.useCallback(Re.debounce(async o=>{if(!Re.isEqual(o,r.current)){t(!0);try{await l(o),r.current=o}finally{t(!1)}}},1e3),[l]),x=u.useCallback(o=>{d(o)},[d]);u.useEffect(()=>{const o=a.watch(c=>{x(c)});return()=>o.unsubscribe()},[a.watch,x]);const m=()=>{const o=Math.floor(Math.random()*17)+16,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let f="";for(let D=0;D<o;D++)f+=c.charAt(Math.floor(Math.random()*c.length));a.setValue("server_token",f)};return e.jsx(De,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:a.control,name:"server_token",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("server.server_token.title")}),e.jsx(y,{children:e.jsxs("div",{className:"relative",children:[e.jsx(k,{placeholder:s("server.server_token.placeholder"),...o,value:o.value||"",className:"pr-10"}),e.jsx(fe,{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:c=>{c.preventDefault(),m()},children:e.jsx(ed,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(de,{children:e.jsx("p",{children:s("server.server_token.generate_tooltip")})})]})})]})}),e.jsx($,{children:s("server.server_token.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"server_pull_interval",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("server.server_pull_interval.title")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:s("server.server_pull_interval.placeholder"),...o,value:o.value||"",onChange:c=>{const f=c.target.value?Number(c.target.value):null;o.onChange(f)}})}),e.jsx($,{children:s("server.server_pull_interval.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"server_push_interval",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("server.server_push_interval.title")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:s("server.server_push_interval.placeholder"),...o,value:o.value||"",onChange:c=>{const f=c.target.value?Number(c.target.value):null;o.onChange(f)}})}),e.jsx($,{children:s("server.server_push_interval.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"device_limit_mode",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("server.device_limit_mode.title")}),e.jsxs(J,{onValueChange:o.onChange,value:o.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:s("server.device_limit_mode.placeholder")})})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:s("server.device_limit_mode.strict")}),e.jsx(A,{value:"1",children:s("server.device_limit_mode.relaxed")})]})]}),e.jsx($,{children:s("server.device_limit_mode.description")}),e.jsx(P,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("server.saving")})]})})}function ku(){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(Ee,{}),e.jsx(Su,{})]})}const Tu=Object.freeze(Object.defineProperty({__proto__:null,default:ku},Symbol.toStringTag,{value:"Module"}));function Du({open:s,onOpenChange:n,result:t}){const r=!t.error;return e.jsx(me,{open:s,onOpenChange:n,children:e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(pe,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(_l,{className:"h-5 w-5 text-green-500"}):e.jsx(Nl,{className:"h-5 w-5 text-destructive"}),e.jsx(ue,{children:r?"邮件发送成功":"邮件发送失败"})]}),e.jsx($e,{children:r?"测试邮件已成功发送,请检查收件箱":"发送测试邮件时遇到错误"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"发送详情"}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2 text-sm",children:[e.jsx("div",{className:"text-muted-foreground",children:"收件地址"}),e.jsx("div",{children:t.email}),e.jsx("div",{className:"text-muted-foreground",children:"邮件主题"}),e.jsx("div",{children:t.subject}),e.jsx("div",{className:"text-muted-foreground",children:"模板名称"}),e.jsx("div",{children:t.template_name})]})]}),t.error&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium text-destructive",children:"错误信息"}),e.jsx("div",{className:"rounded-md bg-destructive/10 p-3 text-sm text-destructive break-all",children:t.error})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"配置信息"}),e.jsx(ht,{className:"h-[200px] rounded-md border p-4",children:e.jsx("div",{className:"grid gap-2 text-sm",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2",children:[e.jsx("div",{className:"text-muted-foreground",children:"驱动"}),e.jsx("div",{children:t.config.driver}),e.jsx("div",{className:"text-muted-foreground",children:"服务器"}),e.jsx("div",{children:t.config.host}),e.jsx("div",{className:"text-muted-foreground",children:"端口"}),e.jsx("div",{children:t.config.port}),e.jsx("div",{className:"text-muted-foreground",children:"加密方式"}),e.jsx("div",{children:t.config.encryption||"无"}),e.jsx("div",{className:"text-muted-foreground",children:"发件人"}),e.jsx("div",{children:t.config.from.address?`${t.config.from.address}${t.config.from.name?` (${t.config.from.name})`:""}`:"未设置"}),e.jsx("div",{className:"text-muted-foreground",children:"用户名"}),e.jsx("div",{children:t.config.username||"未设置"})]})})})]})]})]})})}const Fu=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 Pu(){const{t:s}=M("settings"),[n,t]=u.useState(null),[r,a]=u.useState(!1),i=u.useRef(null),[l,d]=u.useState(!1),x=we({resolver:Te(Fu),defaultValues:{},mode:"onBlur"}),{data:m}=re({queryKey:["settings","email"],queryFn:()=>ye.getSettings("email")}),{data:o}=re({queryKey:["emailTemplate"],queryFn:()=>ye.getEmailTemplate()}),{mutateAsync:c}=Os({mutationFn:ye.saveSettings,onSuccess:T=>{T.data&&z.success(s("common.autoSaved"))}}),{mutate:f,isPending:D}=Os({mutationFn:ye.sendTestMail,onMutate:()=>{t(null),a(!1)},onSuccess:T=>{t(T.data),a(!0),T.data.error?z.error(s("email.test.error")):z.success(s("email.test.success"))}});u.useEffect(()=>{if(m?.data.email){const T=m.data.email;Object.entries(T).forEach(([w,E])=>{x.setValue(w,E)}),i.current=T}},[m]);const S=u.useCallback(Re.debounce(async T=>{if(!Re.isEqual(T,i.current)){d(!0);try{await c(T),i.current=T}finally{d(!1)}}},1e3),[c]),C=u.useCallback(T=>{S(T)},[S]);return u.useEffect(()=>{const T=x.watch(w=>{C(w)});return()=>T.unsubscribe()},[x.watch,C]),e.jsxs(e.Fragment,{children:[e.jsx(De,{...x,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:x.control,name:"email_host",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_host.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("common.placeholder"),...T,value:T.value||""})}),e.jsx($,{children:s("email.email_host.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"email_port",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_port.title")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:s("common.placeholder"),...T,value:T.value||"",onChange:w=>{const E=w.target.value?Number(w.target.value):null;T.onChange(E)}})}),e.jsx($,{children:s("email.email_port.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"email_encryption",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_encryption.title")}),e.jsxs(J,{onValueChange:w=>{const E=w==="none"?"":w;T.onChange(E)},value:T.value===""||T.value===null||T.value===void 0?"none":T.value,children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择加密方式"})})}),e.jsxs(Y,{children:[e.jsx(A,{value:"none",children:s("email.email_encryption.none")}),e.jsx(A,{value:"ssl",children:s("email.email_encryption.ssl")}),e.jsx(A,{value:"tls",children:s("email.email_encryption.tls")})]})]}),e.jsx($,{children:s("email.email_encryption.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"email_username",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_username.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("common.placeholder"),autoComplete:"off",...T,value:T.value||""})}),e.jsx($,{children:s("email.email_username.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"email_password",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_password.title")}),e.jsx(y,{children:e.jsx(k,{type:"password",placeholder:s("common.placeholder"),autoComplete:"off",...T,value:T.value||""})}),e.jsx($,{children:s("email.email_password.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"email_from_address",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_from.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("common.placeholder"),...T,value:T.value||""})}),e.jsx($,{children:s("email.email_from.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"email_template",render:({field:T})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("email.email_template.title")}),e.jsxs(J,{onValueChange:w=>{T.onChange(w),C(x.getValues())},value:T.value||void 0,children:[e.jsx(y,{children:e.jsx(W,{className:"w-[200px]",children:e.jsx(Q,{placeholder:s("email.email_template.placeholder")})})}),e.jsx(Y,{children:o?.data?.map(w=>e.jsx(A,{value:w,children:w},w))})]}),e.jsx($,{children:s("email.email_template.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"remind_mail_enable",render:({field:T})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:s("email.remind_mail.title")}),e.jsx($,{children:s("email.remind_mail.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:T.value||!1,onCheckedChange:w=>{T.onChange(w),C(x.getValues())}})})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(F,{onClick:()=>f(),loading:D,disabled:D,children:s(D?"email.test.sending":"email.test.title")})})]})}),l&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("saving")}),n&&e.jsx(Du,{open:r,onOpenChange:a,result:n})]})}function Lu(){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(Ee,{}),e.jsx(Pu,{})]})}const Ru=Object.freeze(Object.defineProperty({__proto__:null,default:Lu},Symbol.toStringTag,{value:"Module"})),Eu=h.object({telegram_bot_enable:h.boolean().nullable(),telegram_bot_token:h.string().nullable(),telegram_discuss_link:h.string().nullable()}),Vu={telegram_bot_enable:!1,telegram_bot_token:"",telegram_discuss_link:""};function Iu(){const{t:s}=M("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=we({resolver:Te(Eu),defaultValues:Vu,mode:"onBlur"}),{data:i}=re({queryKey:["settings","telegram"],queryFn:()=>ye.getSettings("telegram")}),{mutateAsync:l}=Os({mutationFn:ye.saveSettings,onSuccess:c=>{c.data&&z.success(s("common.autoSaved"))}}),{mutate:d,isPending:x}=Os({mutationFn:ye.setTelegramWebhook,onSuccess:c=>{c.data&&z.success(s("telegram.webhook.success"))}});u.useEffect(()=>{if(i?.data.telegram){const c=i.data.telegram;Object.entries(c).forEach(([f,D])=>{a.setValue(f,D)}),r.current=c}},[i]);const m=u.useCallback(Re.debounce(async c=>{if(!Re.isEqual(c,r.current)){t(!0);try{await l(c),r.current=c}finally{t(!1)}}},1e3),[l]),o=u.useCallback(c=>{m(c)},[m]);return u.useEffect(()=>{const c=a.watch(f=>{o(f)});return()=>c.unsubscribe()},[a.watch,o]),e.jsx(De,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:a.control,name:"telegram_bot_token",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("telegram.bot_token.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("telegram.bot_token.placeholder"),...c,value:c.value||""})}),e.jsx($,{children:s("telegram.bot_token.description")}),e.jsx(P,{})]})}),a.watch("telegram_bot_token")&&e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("telegram.webhook.title")}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(F,{loading:x,disabled:x,onClick:()=>d(),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($,{children:s("telegram.webhook.description")}),e.jsx(P,{})]}),e.jsx(v,{control:a.control,name:"telegram_bot_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("telegram.bot_enable.title")}),e.jsx($,{children:s("telegram.bot_enable.description")}),e.jsx(y,{children:e.jsx(X,{checked:c.value||!1,onCheckedChange:f=>{c.onChange(f),o(a.getValues())}})}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"telegram_discuss_link",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("telegram.discuss_link.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("telegram.discuss_link.placeholder"),...c,value:c.value||""})}),e.jsx($,{children:s("telegram.discuss_link.description")}),e.jsx(P,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Mu(){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(Ee,{}),e.jsx(Iu,{})]})}const Ou=Object.freeze(Object.defineProperty({__proto__:null,default:Mu},Symbol.toStringTag,{value:"Module"})),zu=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()}),$u={windows_version:"",windows_download_url:"",macos_version:"",macos_download_url:"",android_version:"",android_download_url:""};function Au(){const{t:s}=M("settings"),[n,t]=u.useState(!1),r=u.useRef(null),a=we({resolver:Te(zu),defaultValues:$u,mode:"onBlur"}),{data:i}=re({queryKey:["settings","app"],queryFn:()=>ye.getSettings("app")}),{mutateAsync:l}=Os({mutationFn:ye.saveSettings,onSuccess:m=>{m.data&&z.success(s("app.save_success"))}});u.useEffect(()=>{if(i?.data.app){const m=i.data.app;Object.entries(m).forEach(([o,c])=>{a.setValue(o,c)}),r.current=m}},[i]);const d=u.useCallback(Re.debounce(async m=>{if(!Re.isEqual(m,r.current)){t(!0);try{await l(m),r.current=m}finally{t(!1)}}},1e3),[l]),x=u.useCallback(m=>{d(m)},[d]);return u.useEffect(()=>{const m=a.watch(o=>{x(o)});return()=>m.unsubscribe()},[a.watch,x]),e.jsx(De,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:a.control,name:"windows_version",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.windows.version.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("common.placeholder"),...m,value:m.value||""})}),e.jsx($,{children:s("app.windows.version.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"windows_download_url",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.windows.download.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("common.placeholder"),...m,value:m.value||""})}),e.jsx($,{children:s("app.windows.download.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"macos_version",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.macos.version.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("common.placeholder"),...m,value:m.value||""})}),e.jsx($,{children:s("app.macos.version.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"macos_download_url",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.macos.download.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("common.placeholder"),...m,value:m.value||""})}),e.jsx($,{children:s("app.macos.download.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"android_version",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.android.version.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("common.placeholder"),...m,value:m.value||""})}),e.jsx($,{children:s("app.android.version.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"android_download_url",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-base",children:s("app.android.download.title")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("common.placeholder"),...m,value:m.value||""})}),e.jsx($,{children:s("app.android.download.description")}),e.jsx(P,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function qu(){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(Ee,{}),e.jsx(Au,{})]})}const Hu=Object.freeze(Object.defineProperty({__proto__:null,default:qu},Symbol.toStringTag,{value:"Module"}));Rr.config({monaco:Er});function mi({form:s,config:n,namePrefix:t="",className:r="space-y-4"}){const[a,i]=u.useState({}),l=x=>t?`${t}.${x}`:x,d=(x,m)=>{const o=l(x);switch(m.type){case"string":return e.jsx(v,{control:s.control,name:o,render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{children:m.label||m.description}),e.jsx(y,{children:e.jsx(k,{placeholder:m.placeholder,...c})}),m.description&&m.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:m.description}),e.jsx(P,{})]})},x);case"number":case"percentage":return e.jsx(v,{control:s.control,name:o,render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{children:m.label||m.description}),e.jsx(y,{children:e.jsxs("div",{className:"relative",children:[e.jsx(k,{type:"number",placeholder:m.placeholder,min:m.min??(m.type==="percentage"?0:void 0),max:m.max??(m.type==="percentage"?100:void 0),step:m.step??(m.type==="percentage"?1:void 0),...c,onChange:f=>{const D=Number(f.target.value);m.type==="percentage"?c.onChange(Math.min(100,Math.max(0,D))):c.onChange(D)},className:m.type==="percentage"?"pr-8":""}),m.type==="percentage"&&e.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3",children:e.jsx(sd,{className:"h-4 w-4 text-muted-foreground"})})]})}),m.description&&m.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:m.description}),e.jsx(P,{})]})},x);case"select":return e.jsx(v,{control:s.control,name:o,render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{children:m.label||m.description}),e.jsxs(J,{onValueChange:c.onChange,defaultValue:c.value,children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:m.placeholder})})}),e.jsx(Y,{children:m.options?.map(f=>e.jsx(A,{value:f.value,children:f.label},f.value))})]}),m.description&&m.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:m.description}),e.jsx(P,{})]})},x);case"boolean":return e.jsx(v,{control:s.control,name:o,render:({field:c})=>e.jsxs(j,{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(b,{className:"text-base",children:m.label||m.description}),m.description&&m.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:m.description})]}),e.jsx(y,{children:e.jsx(X,{checked:c.value,onCheckedChange:c.onChange})})]})},x);case"text":return e.jsx(v,{control:s.control,name:o,render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{children:m.label||m.description}),e.jsx(y,{children:e.jsx(Es,{placeholder:m.placeholder,...c})}),m.description&&m.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:m.description}),e.jsx(P,{})]})},x);case"yaml":case"json":return e.jsx(v,{control:s.control,name:o,render:({field:c})=>{const f=(()=>{if(c.value===null||c.value===void 0)return"";if(typeof c.value=="string")return c.value;try{return JSON.stringify(c.value,null,2)}catch{return String(c.value)}})(),D=`${t}_${x}`,S=a[D]||150;return e.jsxs(j,{children:[e.jsx(b,{children:m.label||m.description}),e.jsx(y,{children:e.jsx("div",{className:"resize-y overflow-hidden rounded-md border",style:{height:`${S}px`},onMouseDown:C=>{const T=C.clientY,w=S,E=g=>{const p=g.clientY-T,V=Math.max(100,w+p);i(R=>({...R,[D]:V}))},_=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",_)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",_)},children:e.jsx(Vr,{height:"100%",defaultLanguage:m.type,value:f,onChange:C=>{c.onChange(C||"")},options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0,formatOnPaste:m.type==="json",formatOnType:m.type==="json"}})})}),m.description&&m.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:m.description}),e.jsx(P,{})]})}},x);default:return null}};return e.jsx("div",{className:r,children:Object.entries(n).map(([x,m])=>d(x,m))})}function ui(s){return Object.fromEntries(Object.entries(s).map(([n,t])=>{let r=t.value;if(t.type==="yaml"||t.type==="json"){if(r==null)r="";else if(typeof r!="string")try{r=JSON.stringify(r,null,2)}catch{r=String(r)}}return[n,r]}))}const Uu=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(t=>!t||/^https?:\/\/\S+/.test(t),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())}),jr={id:null,name:"",icon:"",notify_domain:"",handling_fee_fixed:0,handling_fee_percent:0,payment:"",config:{}};function xi({refetch:s,dialogTrigger:n,type:t="add",defaultFormValues:r=jr}){const{t:a}=M("payment"),[i,l]=u.useState(!1),[d,x]=u.useState(!1),[m,o]=u.useState([]),[c,f]=u.useState([]),[D,S]=u.useState({}),C=Uu(a),T=we({resolver:Te(C),defaultValues:r,mode:"onChange"}),w=T.watch("payment");u.useEffect(()=>{i&&(async()=>{const{data:g}=await xt.getMethodList();o(g)})()},[i]),u.useEffect(()=>{if(!w||!i)return;(async()=>{const g={payment:w,...t==="edit"&&{id:Number(T.getValues("id"))}};try{const{data:p}=await xt.getMethodForm(g),V=Object.values(p);f(V);const R=Object.entries(p).reduce((K,[Z,se])=>(K[Z]=se,K),{});S(R);const L=ui(R);T.setValue("config",L)}catch(p){console.error("Failed to fetch payment method form:",p),f([]),S({})}})()},[w,i,T,t]);const E=async _=>{x(!0);try{(await xt.save(_)).data&&(z.success(a("form.messages.success")),T.reset(jr),s(),l(!1))}finally{x(!1)}};return e.jsxs(me,{open:i,onOpenChange:l,children:[e.jsx(ps,{asChild:!0,children:n||e.jsxs(F,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ue,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add.button")})]})}),e.jsxs(ce,{className:"max-h-[90vh] overflow-y-auto sm:max-w-[500px]",children:[e.jsx(pe,{children:e.jsx(ue,{children:a(t==="add"?"form.add.title":"form.edit.title")})}),e.jsx(De,{...T,children:e.jsxs("form",{onSubmit:T.handleSubmit(E),className:"space-y-4",children:[e.jsx(v,{control:T.control,name:"name",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:a("form.fields.name.placeholder"),..._})}),e.jsx($,{children:a("form.fields.name.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:T.control,name:"icon",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.icon.label")}),e.jsx(y,{children:e.jsx(k,{..._,value:_.value||"",placeholder:a("form.fields.icon.placeholder")})}),e.jsx($,{children:a("form.fields.icon.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:T.control,name:"notify_domain",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.notify_domain.label")}),e.jsx(y,{children:e.jsx(k,{..._,value:_.value||"",placeholder:a("form.fields.notify_domain.placeholder")})}),e.jsx($,{children:a("form.fields.notify_domain.description")}),e.jsx(P,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(v,{control:T.control,name:"handling_fee_percent",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.handling_fee_percent.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",..._,value:_.value||"",placeholder:a("form.fields.handling_fee_percent.placeholder")})}),e.jsx(P,{})]})}),e.jsx(v,{control:T.control,name:"handling_fee_fixed",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.handling_fee_fixed.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",..._,value:_.value||"",placeholder:a("form.fields.handling_fee_fixed.placeholder")})}),e.jsx(P,{})]})})]}),e.jsx(v,{control:T.control,name:"payment",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.payment.label")}),e.jsxs(J,{onValueChange:_.onChange,defaultValue:_.value,children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:a("form.fields.payment.placeholder")})})}),e.jsx(Y,{children:m.map(g=>e.jsx(A,{value:g,children:g},g))})]}),e.jsx($,{children:a("form.fields.payment.description")}),e.jsx(P,{})]})}),Object.keys(D).length>0&&e.jsxs("div",{className:"space-y-4 ",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:a("form.sections.payment_config")}),e.jsx(mi,{form:T,config:D,namePrefix:"config",className:"space-y-4"})]}),e.jsxs(Ie,{className:"pt-4",children:[e.jsx(et,{asChild:!0,children:e.jsx(F,{type:"button",variant:"outline",children:a("form.buttons.cancel")})}),e.jsx(F,{type:"submit",disabled:d,children:a("form.buttons.submit")})]})]})})]})]})}function O({column:s,title:n,tooltip:t,className:r}){return s.getCanSort()?e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(F,{variant:"ghost",size:"default",className:N("-ml-3 flex h-8 items-center gap-2 text-nowrap font-medium hover:bg-muted/60",r),onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[e.jsx("span",{children:n}),t&&e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(rr,{className:"h-4 w-4 cursor-pointer text-muted-foreground"})}),e.jsx(de,{children:t})]})}),s.getIsSorted()==="asc"?e.jsx(fn,{className:"h-4 w-4 text-foreground/70"}):s.getIsSorted()==="desc"?e.jsx(jn,{className:"h-4 w-4 text-foreground/70"}):e.jsx(td,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-foreground/70"})]})})}):e.jsxs("div",{className:N("flex items-center space-x-1 text-nowrap py-2 font-medium text-muted-foreground",r),children:[e.jsx("span",{children:n}),t&&e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{children:e.jsx(rr,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(de,{children:t})]})})]})}const Un=ad,hi=nd,Ku=rd,gi=u.forwardRef(({className:s,...n},t)=>e.jsx(Cl,{className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:t}));gi.displayName=Cl.displayName;const Ka=u.forwardRef(({className:s,...n},t)=>e.jsxs(Ku,{children:[e.jsx(gi,{}),e.jsx(Sl,{ref:t,className:N("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...n})]}));Ka.displayName=Sl.displayName;const Ba=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-2 text-center sm:text-left",s),...n});Ba.displayName="AlertDialogHeader";const Ga=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Ga.displayName="AlertDialogFooter";const Wa=u.forwardRef(({className:s,...n},t)=>e.jsx(kl,{ref:t,className:N("text-lg font-semibold",s),...n}));Wa.displayName=kl.displayName;const Ya=u.forwardRef(({className:s,...n},t)=>e.jsx(Tl,{ref:t,className:N("text-sm text-muted-foreground",s),...n}));Ya.displayName=Tl.displayName;const Ja=u.forwardRef(({className:s,...n},t)=>e.jsx(Dl,{ref:t,className:N(Vt(),s),...n}));Ja.displayName=Dl.displayName;const Qa=u.forwardRef(({className:s,...n},t)=>e.jsx(Fl,{ref:t,className:N(Vt({variant:"outline"}),"mt-2 sm:mt-0",s),...n}));Qa.displayName=Fl.displayName;function _s({onConfirm:s,children:n,title:t="确认操作",description:r="确定要执行此操作吗?",cancelText:a="取消",confirmText:i="确认",variant:l="default",className:d}){return e.jsxs(Un,{children:[e.jsx(hi,{asChild:!0,children:n}),e.jsxs(Ka,{className:N("sm:max-w-[425px]",d),children:[e.jsxs(Ba,{children:[e.jsx(Wa,{children:t}),e.jsx(Ya,{children:r})]}),e.jsxs(Ga,{children:[e.jsx(Qa,{asChild:!0,children:e.jsx(F,{variant:"outline",children:a})}),e.jsx(Ja,{asChild:!0,children:e.jsx(F,{variant:l,onClick:s,children:i})})]})]})]})}const pi=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"})}),Bu=({refetch:s,isSortMode:n=!1})=>{const{t}=M("payment");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(za,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.id")}),cell:({row:r})=>e.jsx(q,{variant:"outline",children:r.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"enable",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.enable")}),cell:({row:r})=>e.jsx(X,{defaultChecked:r.getValue("enable"),onCheckedChange:async()=>{const{data:a}=await xt.updateStatus({id:r.original.id});a||s()}}),enableSorting:!1,size:100},{accessorKey:"name",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.name")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r.getValue("name")})}),enableSorting:!1,size:200},{accessorKey:"payment",header:({column:r})=>e.jsx(O,{column:r,title:t("table.columns.payment")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r.getValue("payment")})}),enableSorting:!1,size:200},{accessorKey:"notify_url",header:({column:r})=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(O,{column:r,title:t("table.columns.notify_url")}),e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{className:"ml-1",children:e.jsx(pi,{className:"h-4 w-4"})}),e.jsx(de,{children:t("table.columns.notify_url_tooltip")})]})})]}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[300px] truncate font-medium",children:r.getValue("notify_url")})}),enableSorting:!1,size:3e3},{id:"actions",header:({column:r})=>e.jsx(O,{className:"justify-end",column:r,title:t("table.columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(xi,{refetch:s,dialogTrigger:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(rt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:t("table.actions.edit")})]}),type:"edit",defaultFormValues:r.original}),e.jsx(_s,{title:t("table.actions.delete.title"),description:t("table.actions.delete.description"),onConfirm:async()=>{const{data:a}=await xt.drop({id:r.original.id});a&&s()},children:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10",children:[e.jsx(us,{className:"h-4 w-4 text-muted-foreground hover:text-destructive"}),e.jsx("span",{className:"sr-only",children:t("table.actions.delete.title")})]})})]}),size:100}]};function Gu({table:s,refetch:n,saveOrder:t,isSortMode:r}){const{t:a}=M("payment"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:a("table.toolbar.sort.hint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xi,{refetch:n}),e.jsx(k,{placeholder:a("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),i&&e.jsxs(F,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[a("table.toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{variant:r?"default":"outline",onClick:t,size:"sm",children:a(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}function Wu(){const[s,n]=u.useState([]),[t,r]=u.useState([]),[a,i]=u.useState(!1),[l,d]=u.useState([]),[x,m]=u.useState({"drag-handle":!1}),[o,c]=u.useState({pageSize:20,pageIndex:0}),{refetch:f}=re({queryKey:["paymentList"],queryFn:async()=>{const{data:w}=await xt.getList();return d(w?.map(E=>({...E,enable:!!E.enable}))||[]),w}});u.useEffect(()=>{m({"drag-handle":a,actions:!a}),c({pageSize:a?99999:10,pageIndex:0})},[a]);const D=(w,E)=>{a&&(w.dataTransfer.setData("text/plain",E.toString()),w.currentTarget.classList.add("opacity-50"))},S=(w,E)=>{if(!a)return;w.preventDefault(),w.currentTarget.classList.remove("bg-muted");const _=parseInt(w.dataTransfer.getData("text/plain"));if(_===E)return;const g=[...l],[p]=g.splice(_,1);g.splice(E,0,p),d(g)},C=async()=>{a?xt.sort({ids:l.map(w=>w.id)}).then(()=>{f(),i(!1),z.success("排序保存成功")}):i(!0)},T=Be({data:l,columns:Bu({refetch:f,isSortMode:a}),state:{sorting:t,columnFilters:s,columnVisibility:x,pagination:o},onSortingChange:r,onColumnFiltersChange:n,onColumnVisibilityChange:m,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),initialState:{columnPinning:{right:["actions"]}},pageCount:a?1:void 0});return e.jsx(ts,{table:T,toolbar:w=>e.jsx(Gu,{table:w,refetch:f,saveOrder:C,isSortMode:a}),draggable:a,onDragStart:D,onDragEnd:w=>w.currentTarget.classList.remove("opacity-50"),onDragOver:w=>{w.preventDefault(),w.currentTarget.classList.add("bg-muted")},onDragLeave:w=>w.currentTarget.classList.remove("bg-muted"),onDrop:S,showPagination:!a})}function Yu(){const{t:s}=M("payment");return e.jsxs(Ae,{children:[e.jsxs(qe,{className:"flex items-center justify-between",children:[e.jsx(cs,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(Wu,{})})]})]})}const Ju=Object.freeze(Object.defineProperty({__proto__:null,default:Yu},Symbol.toStringTag,{value:"Module"}));function Qu({pluginName:s,onClose:n,onSuccess:t}){const{t:r}=M("plugin"),[a,i]=u.useState(!0),[l,d]=u.useState(!1),[x,m]=u.useState(null),o=ld({config:id(od())}),c=we({resolver:Te(o),defaultValues:{config:{}}});u.useEffect(()=>{(async()=>{try{const{data:S}=await As.getPluginConfig(s);m(S);const C=ui(S);c.reset({config:C})}catch{z.error(r("messages.configLoadError"))}finally{i(!1)}})()},[s,c,r]);const f=async D=>{d(!0);try{await As.updatePluginConfig(s,D.config),z.success(r("messages.configSaveSuccess")),t()}catch{z.error(r("messages.configSaveError"))}finally{d(!1)}};return a?e.jsxs("div",{className:"space-y-4",children:[e.jsx(be,{className:"h-4 w-[200px]"}),e.jsx(be,{className:"h-10 w-full"}),e.jsx(be,{className:"h-4 w-[200px]"}),e.jsx(be,{className:"h-10 w-full"})]}):e.jsx(De,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(f),className:"space-y-4",children:[x&&e.jsx(mi,{form:c,config:x,namePrefix:"config"}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(F,{type:"button",variant:"outline",onClick:n,disabled:l,children:r("config.cancel")}),e.jsx(F,{type:"submit",loading:l,disabled:l,children:r("config.save")})]})]})})}function Xu(){const{t:s}=M("plugin"),[n,t]=u.useState(null),[r,a]=u.useState(!1),[i,l]=u.useState(null),[d,x]=u.useState(""),[m,o]=u.useState("feature"),[c,f]=u.useState("all"),[D,S]=u.useState(!1),[C,T]=u.useState(!1),[w,E]=u.useState(!1),_=u.useRef(null),[g,p]=u.useState(!1),[V,R]=u.useState(""),{data:L,isLoading:K}=re({queryKey:["pluginTypes"],queryFn:async()=>{const{data:U}=await As.getPluginTypes();return U}}),{data:Z,isLoading:se,refetch:ae}=re({queryKey:["pluginList"],queryFn:async()=>{const{data:U}=await As.getPluginList();return U}}),H=Z?.filter(U=>U.name.toLowerCase().includes(d.toLowerCase())||U.description.toLowerCase().includes(d.toLowerCase())||U.code.toLowerCase().includes(d.toLowerCase())),ee=()=>{if(!H)return[];let U=H;return m!=="all"&&(U=U.filter(te=>te.type===m)),c==="installed"?U=U.filter(te=>te.is_installed):c==="available"&&(U=U.filter(te=>!te.is_installed)),U},je=U=>L?.find(te=>te.value===U),ds=async U=>{t(U),As.installPlugin(U).then(()=>{z.success(s("messages.installSuccess")),ae()}).catch(te=>{z.error(te.message||s("messages.installError"))}).finally(()=>{t(null)})},Me=async U=>{t(U),As.uninstallPlugin(U).then(()=>{z.success(s("messages.uninstallSuccess")),ae()}).catch(te=>{z.error(te.message||s("messages.uninstallError"))}).finally(()=>{t(null)})},le=async(U,te)=>{t(U),(te?As.disablePlugin:As.enablePlugin)(U).then(()=>{z.success(s(te?"messages.disableSuccess":"messages.enableSuccess")),ae()}).catch(ve=>{z.error(ve.message||s(te?"messages.disableError":"messages.enableError"))}).finally(()=>{t(null)})},Ts=U=>{Z?.find(te=>te.code===U),l(U),a(!0)},Ns=async U=>{if(!U.name.endsWith(".zip")){z.error(s("upload.error.format"));return}S(!0),As.uploadPlugin(U).then(()=>{z.success(s("messages.uploadSuccess")),T(!1),ae()}).catch(te=>{z.error(te.message||s("messages.uploadError"))}).finally(()=>{S(!1),_.current&&(_.current.value="")})},Ws=U=>{U.preventDefault(),U.stopPropagation(),U.type==="dragenter"||U.type==="dragover"?E(!0):U.type==="dragleave"&&E(!1)},Us=U=>{U.preventDefault(),U.stopPropagation(),E(!1),U.dataTransfer.files&&U.dataTransfer.files[0]&&Ns(U.dataTransfer.files[0])},Ys=async U=>{t(U),As.deletePlugin(U).then(()=>{z.success(s("messages.deleteSuccess")),ae()}).catch(te=>{z.error(te.message||s("messages.deleteError"))}).finally(()=>{t(null)})},yt=U=>cd(U||"",{walkTokens(te){(te.type==="image"||te.type==="link")&&(te.type="text",te.raw="",te.text="")}});return e.jsxs(Ae,{children:[e.jsxs(qe,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Pn,{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(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(Ln,{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:d,onChange:U=>x(U.target.value),className:"pl-9"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(J,{value:c,onValueChange:f,children:[e.jsx(W,{className:"w-[140px]",children:e.jsx(Q,{placeholder:s("status.filter_placeholder",{defaultValue:"安装状态"})})}),e.jsxs(Y,{children:[e.jsx(A,{value:"all",children:s("status.all",{defaultValue:"全部状态"})}),e.jsx(A,{value:"installed",children:s("status.installed",{defaultValue:"已安装"})}),e.jsx(A,{value:"available",children:s("status.available",{defaultValue:"可安装"})})]})]}),e.jsxs(F,{onClick:()=>T(!0),variant:"outline",className:"shrink-0",size:"sm",children:[e.jsx(Lt,{className:"mr-2 h-4 w-4"}),s("upload.button")]})]})]}),e.jsxs(ft,{value:m,onValueChange:o,className:"w-full",children:[e.jsxs(lt,{children:[L?.map(U=>e.jsx(Ke,{value:U.value,children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{children:U.label})})},U.value)),e.jsx(Ke,{value:"all",children:s("tabs.all")})]}),e.jsx(bs,{value:"all",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:se||K?e.jsxs(e.Fragment,{children:[e.jsx(dn,{}),e.jsx(dn,{}),e.jsx(dn,{})]}):ee().map(U=>e.jsx(vr,{plugin:U,typeInfo:je(U.type),onInstall:ds,onUninstall:Me,onToggleEnable:le,onOpenConfig:Ts,onDelete:Ys,isLoading:n===U.code,onShowReadme:U.readme?()=>{R(U.readme),p(!0)}:void 0},U.code))})}),L?.map(U=>e.jsx(bs,{value:U.value,className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:ee().map(te=>e.jsx(vr,{plugin:te,typeInfo:je(te.type),onInstall:ds,onUninstall:Me,onToggleEnable:le,onOpenConfig:Ts,onDelete:Ys,isLoading:n===te.code,onShowReadme:te.readme?()=>{R(te.readme),p(!0)}:void 0},te.code))})},U.value))]})]}),e.jsx(me,{open:r,onOpenChange:a,children:e.jsxs(ce,{className:"sm:max-w-lg",children:[e.jsxs(pe,{children:[e.jsxs(ue,{children:[Z?.find(U=>U.code===i)?.name," ",s("config.title")]}),e.jsx($e,{children:s("config.description")})]}),i&&e.jsx(Qu,{pluginName:i,onClose:()=>a(!1),onSuccess:()=>{a(!1),ae()}})]})}),e.jsx(me,{open:C,onOpenChange:T,children:e.jsxs(ce,{className:"sm:max-w-md",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:s("upload.title")}),e.jsx($e,{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",w&&"border-primary/50 bg-muted/50"),onDragEnter:Ws,onDragLeave:Ws,onDragOver:Ws,onDrop:Us,children:[e.jsx("input",{type:"file",ref:_,className:"hidden",accept:".zip",onChange:U=>{const te=U.target.files?.[0];te&&Ns(te)}}),D?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(Lt,{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:()=>_.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(me,{open:g,onOpenChange:p,children:e.jsxs(ce,{className:"max-w-2xl",children:[e.jsx(pe,{children:e.jsx(ue,{children:s("readme.title",{defaultValue:"插件文档"})})}),e.jsx("div",{className:"markdown-body max-h-[60vh] overflow-y-auto",dangerouslySetInnerHTML:{__html:yt(V)}})]})})]})]})}function vr({plugin:s,onInstall:n,onUninstall:t,onToggleEnable:r,onOpenConfig:a,onDelete:i,isLoading:l,onShowReadme:d,typeInfo:x}){const{t:m}=M("plugin");return e.jsx(ke,{className:"group relative overflow-hidden transition-all hover:shadow-md",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("h3",{className:"truncate text-base font-semibold",children:s.name}),x&&e.jsx(q,{variant:"outline",className:"border-primary/20 bg-primary/5 px-1.5 py-0.5 text-xs text-primary",children:x.label}),s.is_installed?e.jsx(q,{variant:s.is_enabled?"default":"outline",className:"px-1.5 py-0.5 text-xs",children:s.is_enabled?m("status.enabled"):m("status.disabled")}):e.jsx(q,{variant:"outline",className:"border-muted-foreground/30 bg-muted/30 px-1.5 py-0.5 text-xs text-muted-foreground",children:m("status.not_installed")})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1.5",children:[s.is_protected&&e.jsx(fe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx("div",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-amber-100 text-amber-600 dark:bg-amber-900/50 dark:text-amber-400",children:e.jsx(dd,{className:"h-3 w-3"})})}),e.jsx(de,{children:e.jsx("p",{children:m("status.protected")})})]})}),s.readme&&e.jsx("button",{type:"button",onClick:d,className:"flex h-5 w-5 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-primary",title:m("button.readme"),children:e.jsx(bn,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"mb-2 flex items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Pn,{className:"h-3 w-3"}),e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-xs",children:s.code})]}),e.jsxs("span",{children:["v",s.version]}),e.jsxs("span",{children:[m("author"),": ",s.author]})]}),e.jsx("p",{className:"mb-3 overflow-hidden text-ellipsis text-sm text-muted-foreground",style:{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:s.description}),e.jsx("div",{className:"flex items-center justify-end gap-2",children:s.is_installed?e.jsxs(e.Fragment,{children:[s.config&&Object.keys(s.config).length>0&&e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>a(s.code),disabled:!s.is_enabled||l,className:"h-7 px-2 text-xs",children:[e.jsx(ka,{className:"mr-1 h-3 w-3"}),m("button.config")]}),e.jsxs(F,{variant:s.is_enabled?"destructive":"default",size:"sm",onClick:()=>r(s.code,s.is_enabled),disabled:l,className:"h-7 px-2 text-xs",children:[e.jsx(md,{className:"mr-1 h-3 w-3"}),s.is_enabled?m("button.disable"):m("button.enable")]}),e.jsx(_s,{title:m("uninstall.title"),description:m("uninstall.description"),cancelText:m("common:cancel"),confirmText:m("uninstall.button"),variant:"destructive",onConfirm:async()=>t(s.code),children:e.jsxs(F,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs text-muted-foreground hover:text-destructive",disabled:l,children:[e.jsx(us,{className:"mr-1 h-3 w-3"}),m("button.uninstall")]})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(F,{onClick:()=>n(s.code),disabled:l,size:"sm",className:"h-7 px-3 text-xs",children:[l?e.jsx("div",{className:"mr-1 h-3 w-3 animate-spin rounded-full border border-current border-t-transparent"}):null,m("button.install")]}),s.can_be_deleted!==!1&&e.jsx(_s,{title:m("delete.title"),description:m("delete.description"),cancelText:m("common:cancel"),confirmText:m("delete.button"),variant:"destructive",onConfirm:async()=>i(s.code),children:e.jsx(F,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground hover:text-destructive",disabled:l,children:e.jsx(us,{className:"h-3 w-3"})})})]})})]})})}function dn(){return e.jsxs(ke,{children:[e.jsxs(Fe,{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(be,{className:"h-6 w-[200px]"}),e.jsx(be,{className:"h-6 w-[80px]"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(be,{className:"h-5 w-[120px]"}),e.jsx(be,{className:"h-5 w-[60px]"})]})]})}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx(be,{className:"h-4 w-[300px]"}),e.jsx(be,{className:"h-4 w-[150px]"})]})]}),e.jsx(Pe,{children:e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(be,{className:"h-9 w-[100px]"}),e.jsx(be,{className:"h-9 w-[100px]"}),e.jsx(be,{className:"h-8 w-8"})]})})]})}const Zu=Object.freeze(Object.defineProperty({__proto__:null,default:Xu},Symbol.toStringTag,{value:"Module"})),ex=(s,n)=>{let t=null;switch(s.field_type){case"input":t=e.jsx(k,{placeholder:s.placeholder,...n});break;case"textarea":t=e.jsx(Es,{placeholder:s.placeholder,...n});break;case"select":t=e.jsx("select",{className:N(Vt({variant:"outline"}),"w-full appearance-none font-normal"),...n,children:s.select_options&&Object.keys(s.select_options).map(r=>e.jsx("option",{value:r,children:s.select_options?.[r]},r))});break;default:t=null;break}return t};function sx({themeKey:s,themeInfo:n}){const{t}=M("theme"),[r,a]=u.useState(!1),[i,l]=u.useState(!1),[d,x]=u.useState(!1),m=we({defaultValues:n.configs.reduce((f,D)=>(f[D.field_name]="",f),{})}),o=async()=>{l(!0),Jt.getConfig(s).then(({data:f})=>{Object.entries(f).forEach(([D,S])=>{m.setValue(D,S)})}).finally(()=>{l(!1)})},c=async f=>{x(!0),Jt.updateConfig(s,f).then(()=>{z.success(t("config.success")),a(!1)}).finally(()=>{x(!1)})};return e.jsxs(me,{open:r,onOpenChange:f=>{a(f),f?o():m.reset()},children:[e.jsx(ps,{asChild:!0,children:e.jsx(F,{variant:"outline",children:t("card.configureTheme")})}),e.jsxs(ce,{className:"max-h-[90vh] overflow-auto sm:max-w-[425px]",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:t("config.title",{name:n.name})}),e.jsx($e,{children:t("config.description")})]}),i?e.jsx("div",{className:"flex h-40 items-center justify-center",children:e.jsx(Sa,{className:"h-6 w-6 animate-spin"})}):e.jsx(De,{...m,children:e.jsxs("form",{onSubmit:m.handleSubmit(c),className:"space-y-4",children:[n.configs.map(f=>e.jsx(v,{control:m.control,name:f.field_name,render:({field:D})=>e.jsxs(j,{children:[e.jsx(b,{children:f.label}),e.jsx(y,{children:ex(f,D)}),e.jsx(P,{})]})},f.field_name)),e.jsxs(Ie,{className:"mt-6 gap-2",children:[e.jsx(F,{type:"button",variant:"secondary",onClick:()=>a(!1),children:t("config.cancel")}),e.jsx(F,{type:"submit",loading:d,children:t("config.save")})]})]})})]})]})}function tx(){const{t:s}=M("theme"),[n,t]=u.useState(null),[r,a]=u.useState(!1),[i,l]=u.useState(!1),[d,x]=u.useState(!1),[m,o]=u.useState(null),c=u.useRef(null),[f,D]=u.useState(0),{data:S,isLoading:C,refetch:T}=re({queryKey:["themeList"],queryFn:async()=>{const{data:L}=await Jt.getList();return L}}),w=async L=>{t(L),ye.updateSystemConfig({frontend_theme:L}).then(()=>{z.success("主题切换成功"),T()}).finally(()=>{t(null)})},E=async L=>{if(!L.name.endsWith(".zip")){z.error(s("upload.error.format"));return}a(!0),Jt.upload(L).then(()=>{z.success("主题上传成功"),l(!1),T()}).finally(()=>{a(!1),c.current&&(c.current.value="")})},_=L=>{L.preventDefault(),L.stopPropagation(),L.type==="dragenter"||L.type==="dragover"?x(!0):L.type==="dragleave"&&x(!1)},g=L=>{L.preventDefault(),L.stopPropagation(),x(!1),L.dataTransfer.files&&L.dataTransfer.files[0]&&E(L.dataTransfer.files[0])},p=()=>{m&&D(L=>L===0?m.images.length-1:L-1)},V=()=>{m&&D(L=>L===m.images.length-1?0:L+1)},R=(L,K)=>{D(0),o({name:L,images:K})};return e.jsxs(Ae,{children:[e.jsxs(qe,{className:"flex items-center justify-between",children:[e.jsx(cs,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(F,{onClick:()=>l(!0),variant:"outline",className:"ml-4 shrink-0",size:"sm",children:[e.jsx(Lt,{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:C?e.jsxs(e.Fragment,{children:[e.jsx(br,{}),e.jsx(br,{})]}):S?.themes&&Object.entries(S.themes).map(([L,K])=>e.jsx(ke,{className:"group relative overflow-hidden transition-all hover:shadow-md",style:{backgroundImage:K.background_url?`url(${K.background_url})`:"none",backgroundSize:"cover",backgroundPosition:"center"},children:e.jsxs("div",{className:N("relative z-10 h-full transition-colors",K.background_url?"group-hover:from-background/98 bg-gradient-to-t from-background/95 via-background/80 to-background/60 backdrop-blur-[1px] group-hover:via-background/90 group-hover:to-background/70":"bg-background"),children:[!!K.can_delete&&e.jsx("div",{className:"absolute right-2 top-2",children:e.jsx(_s,{title:s("card.delete.title"),description:s("card.delete.description"),confirmText:s("card.delete.button"),variant:"destructive",onConfirm:async()=>{if(L===S?.active){z.error(s("card.delete.error.active"));return}t(L),Jt.drop(L).then(()=>{z.success("主题删除成功"),T()}).finally(()=>{t(null)})},children:e.jsx(F,{disabled:n===L,loading:n===L,variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",children:e.jsx(us,{className:"h-4 w-4"})})})}),e.jsxs(Fe,{children:[e.jsx(Ve,{children:K.name}),e.jsx(Zs,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{children:K.description}),K.version&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("card.version",{version:K.version})})]})})]}),e.jsxs(Pe,{className:"flex items-center justify-end space-x-3",children:[K.images&&Array.isArray(K.images)&&K.images.length>0&&e.jsx(F,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>R(K.name,K.images),children:e.jsx(ud,{className:"h-4 w-4"})}),e.jsx(sx,{themeKey:L,themeInfo:K}),e.jsx(F,{onClick:()=>w(L),disabled:n===L||L===S.active,loading:n===L,variant:L===S.active?"secondary":"default",children:L===S.active?s("card.currentTheme"):s("card.activateTheme")})]})]})},L))}),e.jsx(me,{open:i,onOpenChange:l,children:e.jsxs(ce,{className:"sm:max-w-md",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:s("upload.title")}),e.jsx($e,{children:s("upload.description")})]}),e.jsxs("div",{className:N("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",d&&"border-primary/50 bg-muted/50"),onDragEnter:_,onDragLeave:_,onDragOver:_,onDrop:g,children:[e.jsx("input",{type:"file",ref:c,className:"hidden",accept:".zip",onChange:L=>{const K=L.target.files?.[0];K&&E(K)}}),r?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(Lt,{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:()=>c.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(me,{open:!!m,onOpenChange:L=>{L||(o(null),D(0))},children:e.jsxs(ce,{className:"max-w-4xl",children:[e.jsxs(pe,{children:[e.jsxs(ue,{children:[m?.name," ",s("preview.title")]}),e.jsx($e,{className:"text-center",children:m&&s("preview.imageCount",{current:f+1,total:m.images.length})})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"aspect-[16/9] overflow-hidden rounded-lg border bg-muted",children:m?.images[f]&&e.jsx("img",{src:m.images[f],alt:`${m.name} 预览图 ${f+1}`,className:"h-full w-full object-contain"})}),m&&m.images.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(F,{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:p,children:e.jsx(hl,{className:"h-4 w-4"})}),e.jsx(F,{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:V,children:e.jsx(gl,{className:"h-4 w-4"})})]})]}),m&&m.images.length>1&&e.jsx("div",{className:"mt-4 flex gap-2 overflow-x-auto pb-2",children:m.images.map((L,K)=>e.jsx("button",{onClick:()=>D(K),className:N("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2",f===K?"border-primary":"border-transparent"),children:e.jsx("img",{src:L,alt:`缩略图 ${K+1}`,className:"h-full w-full object-cover"})},K))})]})})]})]})}function br(){return e.jsxs(ke,{children:[e.jsxs(Fe,{children:[e.jsx(be,{className:"h-6 w-[200px]"}),e.jsx(be,{className:"h-4 w-[300px]"})]}),e.jsxs(Pe,{className:"flex items-center justify-end space-x-3",children:[e.jsx(be,{className:"h-10 w-[100px]"}),e.jsx(be,{className:"h-10 w-[100px]"})]})]})}const ax=Object.freeze(Object.defineProperty({__proto__:null,default:tx},Symbol.toStringTag,{value:"Module"})),Xa=u.forwardRef(({className:s,value:n=[],onChange:t,...r},a)=>{const[i,l]=u.useState("");u.useEffect(()=>{if(i.includes(",")){const x=new Set([...n,...i.split(",").map(m=>m.trim())]);t(Array.from(x)),l("")}},[i,t,n]);const d=()=>{if(i){const x=new Set([...n,i]);t(Array.from(x)),l("")}};return e.jsxs("div",{className:N(" has-[:focus-visible]:outline-none has-[:focus-visible]:ring-1 has-[:focus-visible]:ring-neutral-950 dark:has-[:focus-visible]:ring-neutral-300 flex w-full flex-wrap gap-2 rounded-md border border-input shadow-sm px-3 py-2 text-sm ring-offset-white disabled:cursor-not-allowed disabled:opacity-50",s),children:[n.map(x=>e.jsxs(q,{variant:"secondary",children:[x,e.jsx(G,{variant:"ghost",size:"icon",className:"ml-2 h-3 w-3",onClick:()=>{t(n.filter(m=>m!==x))},children:e.jsx(_n,{className:"w-3"})})]},x)),e.jsx("input",{className:"flex-1 outline-none placeholder:text-muted-foreground bg-transparent",value:i,onChange:x=>l(x.target.value),onKeyDown:x=>{x.key==="Enter"||x.key===","?(x.preventDefault(),d()):x.key==="Backspace"&&i.length===0&&n.length>0&&(x.preventDefault(),t(n.slice(0,-1)))},...r,ref:a})]})});Xa.displayName="InputTags";const nx=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()}),rx={id:null,show:!1,tags:[],img_url:"",title:"",content:""};function fi({refetch:s,dialogTrigger:n,type:t="add",defaultFormValues:r=rx}){const{t:a}=M("notice"),[i,l]=u.useState(!1),d=we({resolver:Te(nx),defaultValues:r,mode:"onChange",shouldFocusError:!0}),x=new Vn({html:!0});return e.jsx(De,{...d,children:e.jsxs(me,{onOpenChange:l,open:i,children:[e.jsx(ps,{asChild:!0,children:n||e.jsxs(F,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ue,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add.button")})]})}),e.jsxs(ce,{className:"sm:max-w-[1025px]",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:a(t==="add"?"form.add.title":"form.edit.title")}),e.jsx($e,{})]}),e.jsx(v,{control:d.control,name:"title",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.title.label")}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(k,{placeholder:a("form.fields.title.placeholder"),...m})})}),e.jsx(P,{})]})}),e.jsx(v,{control:d.control,name:"content",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.content.label")}),e.jsx(y,{children:e.jsx(In,{style:{height:"500px"},value:m.value,renderHTML:o=>x.render(o),onChange:({text:o})=>{m.onChange(o)}})}),e.jsx(P,{})]})}),e.jsx(v,{control:d.control,name:"img_url",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.img_url.label")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(k,{type:"text",placeholder:a("form.fields.img_url.placeholder"),...m,value:m.value||""})})}),e.jsx(P,{})]})}),e.jsx(v,{control:d.control,name:"show",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.show.label")}),e.jsx("div",{className:"relative py-2",children:e.jsx(y,{children:e.jsx(X,{checked:m.value,onCheckedChange:m.onChange})})}),e.jsx(P,{})]})}),e.jsx(v,{control:d.control,name:"tags",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.fields.tags.label")}),e.jsx(y,{children:e.jsx(Xa,{value:m.value,onChange:m.onChange,placeholder:a("form.fields.tags.placeholder"),className:"w-full"})}),e.jsx(P,{})]})}),e.jsxs(Ie,{children:[e.jsx(et,{asChild:!0,children:e.jsx(F,{type:"button",variant:"outline",children:a("form.buttons.cancel")})}),e.jsx(F,{type:"submit",onClick:m=>{m.preventDefault(),d.handleSubmit(async o=>{aa.save(o).then(({data:c})=>{c&&(z.success(a("form.buttons.success")),s(),l(!1))})})()},children:a("form.buttons.submit")})]})]})]})})}function lx({table:s,refetch:n,saveOrder:t,isSortMode:r}){const{t:a}=M("notice"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between space-x-2 ",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[!r&&e.jsx(fi,{refetch:n}),!r&&e.jsx(k,{placeholder:a("table.toolbar.search"),value:s.getColumn("title")?.getFilterValue()??"",onChange:l=>s.getColumn("title")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),i&&!r&&e.jsxs(F,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-9 px-2 lg:px-3",children:[a("table.toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(F,{variant:r?"default":"outline",onClick:t,className:"h-8",size:"sm",children:a(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}const ix=s=>{const{t:n}=M("notice");return[{id:"drag-handle",header:"",cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(xd,{className:"h-4 w-4 cursor-move text-muted-foreground"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(q,{variant:"outline",className:"font-mono",children:t.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(X,{defaultChecked:t.getValue("show"),onCheckedChange:async()=>{const{data:r}=await aa.updateStatus(t.original.id);r||s()}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.title")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[500px] items-center",children:e.jsx("span",{className:"truncate font-medium",children:t.getValue("title")})}),enableSorting:!1,size:6e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(fi,{refetch:s,dialogTrigger:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(rt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),type:"edit",defaultFormValues:t.original}),e.jsx(_s,{title:n("table.actions.delete.title"),description:n("table.actions.delete.description"),onConfirm:async()=>{aa.drop(t.original.id).then(()=>{z.success(n("table.actions.delete.success")),s()})},children:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{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 ox(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),[x,m]=u.useState(!1),[o,c]=u.useState({}),[f,D]=u.useState({pageSize:50,pageIndex:0}),[S,C]=u.useState([]),{refetch:T}=re({queryKey:["notices"],queryFn:async()=>{const{data:p}=await aa.getList();return C(p),p}});u.useEffect(()=>{r({"drag-handle":x,content:!x,created_at:!x,actions:!x}),D({pageSize:x?99999:50,pageIndex:0})},[x]);const w=(p,V)=>{x&&(p.dataTransfer.setData("text/plain",V.toString()),p.currentTarget.classList.add("opacity-50"))},E=(p,V)=>{if(!x)return;p.preventDefault(),p.currentTarget.classList.remove("bg-muted");const R=parseInt(p.dataTransfer.getData("text/plain"));if(R===V)return;const L=[...S],[K]=L.splice(R,1);L.splice(V,0,K),C(L)},_=async()=>{if(!x){m(!0);return}aa.sort(S.map(p=>p.id)).then(()=>{z.success("排序保存成功"),m(!1),T()}).finally(()=>{m(!1)})},g=Be({data:S??[],columns:ix(T),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,columnSizing:o,pagination:f},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:c,onPaginationChange:D,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:g,toolbar:p=>e.jsx(lx,{table:p,refetch:T,saveOrder:_,isSortMode:x}),draggable:x,onDragStart:w,onDragEnd:p=>p.currentTarget.classList.remove("opacity-50"),onDragOver:p=>{p.preventDefault(),p.currentTarget.classList.add("bg-muted")},onDragLeave:p=>p.currentTarget.classList.remove("bg-muted"),onDrop:E,showPagination:!x})})}function cx(){const{t:s}=M("notice");return e.jsxs(Ae,{children:[e.jsxs(qe,{className:"flex items-center justify-between",children:[e.jsx(cs,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(ox,{})})]})]})}const dx=Object.freeze(Object.defineProperty({__proto__:null,default:cx},Symbol.toStringTag,{value:"Module"})),mx=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()}),ux={id:null,language:"zh-CN",category:"",title:"",body:"",show:!1};function ji({refreshData:s,dialogTrigger:n,type:t="add",defaultFormValues:r=ux}){const{t:a}=M("knowledge"),[i,l]=u.useState(!1),d=we({resolver:Te(mx),defaultValues:r,mode:"onChange",shouldFocusError:!0}),x=new Vn({html:!0});return u.useEffect(()=>{i&&r.id&&Et.getInfo(r.id).then(({data:m})=>{d.reset(m)})},[r.id,d,i]),e.jsxs(me,{onOpenChange:l,open:i,children:[e.jsx(ps,{asChild:!0,children:n||e.jsxs(F,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ue,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add")})]})}),e.jsxs(ce,{className:"sm:max-w-[1025px]",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:a(t==="add"?"form.add":"form.edit")}),e.jsx($e,{})]}),e.jsxs(De,{...d,children:[e.jsx(v,{control:d.control,name:"title",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.title")}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(k,{placeholder:a("form.titlePlaceholder"),...m})})}),e.jsx(P,{})]})}),e.jsx(v,{control:d.control,name:"category",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.category")}),e.jsx("div",{className:"relative ",children:e.jsx(y,{children:e.jsx(k,{placeholder:a("form.categoryPlaceholder"),...m})})}),e.jsx(P,{})]})}),e.jsx(v,{control:d.control,name:"language",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.language")}),e.jsx(y,{children:e.jsxs(J,{value:m.value,onValueChange:m.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("form.languagePlaceholder")})}),e.jsx(Y,{children:[{value:"en-US"},{value:"ja-JP"},{value:"ko-KR"},{value:"vi-VN"},{value:"zh-CN"},{value:"zh-TW"}].map(o=>e.jsx(A,{value:o.value,className:"cursor-pointer",children:a(`languages.${o.value}`)},o.value))})]})})]})}),e.jsx(v,{control:d.control,name:"body",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.content")}),e.jsx(y,{children:e.jsx(In,{style:{height:"500px"},value:m.value,renderHTML:o=>x.render(o),onChange:({text:o})=>{m.onChange(o)}})}),e.jsx(P,{})]})}),e.jsx(v,{control:d.control,name:"show",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.show")}),e.jsx("div",{className:"relative py-2",children:e.jsx(y,{children:e.jsx(X,{checked:m.value,onCheckedChange:m.onChange})})}),e.jsx(P,{})]})}),e.jsxs(Ie,{children:[e.jsx(et,{asChild:!0,children:e.jsx(F,{type:"button",variant:"outline",children:a("form.cancel")})}),e.jsx(F,{type:"submit",onClick:()=>{d.handleSubmit(m=>{Et.save(m).then(({data:o})=>{o&&(d.reset(),z.success(a("messages.operationSuccess")),l(!1),s())})})()},children:a("form.submit")})]})]})]})]})}function xx({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx($a,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ee,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:a.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:a.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(it,{children:[e.jsx(vt,{placeholder:n}),e.jsxs(ot,{children:[e.jsx(bt,{children:"No results found."}),e.jsx(ks,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(rs,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(pt,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Mt,{}),e.jsx(ks,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function hx({table:s,refetch:n,saveOrder:t,isSortMode:r}){const a=s.getState().columnFilters.length>0,{t:i}=M("knowledge");return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sortModeHint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ji,{refreshData:n}),e.jsx(k,{placeholder:i("toolbar.searchPlaceholder"),value:s.getColumn("title")?.getFilterValue()??"",onChange:l=>s.getColumn("title")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),s.getColumn("category")&&e.jsx(xx,{column:s.getColumn("category"),title:i("columns.category"),options:Array.from(new Set(s.getCoreRowModel().rows.map(l=>l.getValue("category")))).map(l=>({label:l,value:l}))}),a&&e.jsxs(F,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[i("toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{variant:r?"default":"outline",onClick:t,size:"sm",children:i(r?"toolbar.saveSort":"toolbar.editSort")})})]})}const gx=({refetch:s,isSortMode:n=!1})=>{const{t}=M("knowledge");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx(za,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.id")}),cell:({row:r})=>e.jsx(q,{variant:"outline",className:"justify-center",children:r.getValue("id")}),enableSorting:!0,size:70},{accessorKey:"show",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.status")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx(X,{defaultChecked:r.getValue("show"),onCheckedChange:async()=>{Et.updateStatus({id:r.original.id}).then(({data:a})=>{a||s()})}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.title")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"line-clamp-2 font-medium",children:r.getValue("title")})}),enableSorting:!0,size:600},{accessorKey:"category",header:({column:r})=>e.jsx(O,{column:r,title:t("columns.category")}),cell:({row:r})=>e.jsx(q,{variant:"secondary",className:"max-w-[180px] truncate",children:r.getValue("category")}),enableSorting:!0,size:1800},{id:"actions",header:({column:r})=>e.jsx(O,{className:"justify-end",column:r,title:t("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx(ji,{refreshData:s,dialogTrigger:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(rt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:t("form.edit")})]}),type:"edit",defaultFormValues:r.original}),e.jsx(_s,{title:t("messages.deleteConfirm"),description:t("messages.deleteDescription"),confirmText:t("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Et.drop({id:r.original.id}).then(({data:a})=>{a&&(z.success(t("messages.operationSuccess")),s())})},children:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:t("messages.deleteButton")})]})})]}),size:100}]};function px(){const[s,n]=u.useState([]),[t,r]=u.useState([]),[a,i]=u.useState(!1),[l,d]=u.useState([]),[x,m]=u.useState({"drag-handle":!1}),[o,c]=u.useState({pageSize:20,pageIndex:0}),{refetch:f,isLoading:D,data:S}=re({queryKey:["knowledge"],queryFn:async()=>{const{data:_}=await Et.getList();return d(_||[]),_}});u.useEffect(()=>{m({"drag-handle":a,actions:!a}),c({pageSize:a?99999:10,pageIndex:0})},[a]);const C=(_,g)=>{a&&(_.dataTransfer.setData("text/plain",g.toString()),_.currentTarget.classList.add("opacity-50"))},T=(_,g)=>{if(!a)return;_.preventDefault(),_.currentTarget.classList.remove("bg-muted");const p=parseInt(_.dataTransfer.getData("text/plain"));if(p===g)return;const V=[...l],[R]=V.splice(p,1);V.splice(g,0,R),d(V)},w=async()=>{a?Et.sort({ids:l.map(_=>_.id)}).then(()=>{f(),i(!1),z.success("排序保存成功")}):i(!0)},E=Be({data:l,columns:gx({refetch:f,isSortMode:a}),state:{sorting:t,columnFilters:s,columnVisibility:x,pagination:o},onSortingChange:r,onColumnFiltersChange:n,onColumnVisibilityChange:m,onPaginationChange:c,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ts,{table:E,toolbar:_=>e.jsx(hx,{table:_,refetch:f,saveOrder:w,isSortMode:a}),draggable:a,onDragStart:C,onDragEnd:_=>_.currentTarget.classList.remove("opacity-50"),onDragOver:_=>{_.preventDefault(),_.currentTarget.classList.add("bg-muted")},onDragLeave:_=>_.currentTarget.classList.remove("bg-muted"),onDrop:T,showPagination:!a})}function fx(){const{t:s}=M("knowledge");return e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(px,{})})]})]})}const jx=Object.freeze(Object.defineProperty({__proto__:null,default:fx},Symbol.toStringTag,{value:"Module"}));function vx(s,n){const[t,r]=u.useState(s);return u.useEffect(()=>{const a=setTimeout(()=>r(s),n);return()=>{clearTimeout(a)}},[s,n]),t}function mn(s,n){if(s.length===0)return{};if(!n)return{"":s};const t={};return s.forEach(r=>{const a=r[n]||"";t[a]||(t[a]=[]),t[a].push(r)}),t}function bx(s,n){const t=JSON.parse(JSON.stringify(s));for(const[r,a]of Object.entries(t))t[r]=a.filter(i=>!n.find(l=>l.value===i.value));return t}function yx(s,n){for(const[,t]of Object.entries(s))if(t.some(r=>n.find(a=>a.value===r.value)))return!0;return!1}const vi=u.forwardRef(({className:s,...n},t)=>hd(a=>a.filtered.count===0)?e.jsx("div",{ref:t,className:N("py-6 text-center text-sm",s),"cmdk-empty":"",role:"presentation",...n}):null);vi.displayName="CommandEmpty";const nt=u.forwardRef(({value:s,onChange:n,placeholder:t,defaultOptions:r=[],options:a,delay:i,onSearch:l,loadingIndicator:d,emptyIndicator:x,maxSelected:m=Number.MAX_SAFE_INTEGER,onMaxSelected:o,hidePlaceholderWhenSelected:c,disabled:f,groupBy:D,className:S,badgeClassName:C,selectFirstItem:T=!0,creatable:w=!1,triggerSearchOnFocus:E=!1,commandProps:_,inputProps:g,hideClearAllButton:p=!1},V)=>{const R=u.useRef(null),[L,K]=u.useState(!1),Z=u.useRef(!1),[se,ae]=u.useState(!1),[H,ee]=u.useState(s||[]),[je,ds]=u.useState(mn(r,D)),[Me,le]=u.useState(""),Ts=vx(Me,i||500);u.useImperativeHandle(V,()=>({selectedValue:[...H],input:R.current,focus:()=>R.current?.focus()}),[H]);const Ns=u.useCallback(ne=>{const ve=H.filter(Ye=>Ye.value!==ne.value);ee(ve),n?.(ve)},[n,H]),Ws=u.useCallback(ne=>{const ve=R.current;ve&&((ne.key==="Delete"||ne.key==="Backspace")&&ve.value===""&&H.length>0&&(H[H.length-1].fixed||Ns(H[H.length-1])),ne.key==="Escape"&&ve.blur())},[Ns,H]);u.useEffect(()=>{s&&ee(s)},[s]),u.useEffect(()=>{if(!a||l)return;const ne=mn(a||[],D);JSON.stringify(ne)!==JSON.stringify(je)&&ds(ne)},[r,a,D,l,je]),u.useEffect(()=>{const ne=async()=>{ae(!0);const Ye=await l?.(Ts);ds(mn(Ye||[],D)),ae(!1)};(async()=>{!l||!L||(E&&await ne(),Ts&&await ne())})()},[Ts,D,L,E]);const Us=()=>{if(!w||yx(je,[{value:Me,label:Me}])||H.find(ve=>ve.value===Me))return;const ne=e.jsx(rs,{value:Me,className:"cursor-pointer",onMouseDown:ve=>{ve.preventDefault(),ve.stopPropagation()},onSelect:ve=>{if(H.length>=m){o?.(H.length);return}le("");const Ye=[...H,{value:ve,label:ve}];ee(Ye),n?.(Ye)},children:`Create "${Me}"`});if(!l&&Me.length>0||l&&Ts.length>0&&!se)return ne},Ys=u.useCallback(()=>{if(x)return l&&!w&&Object.keys(je).length===0?e.jsx(rs,{value:"-",disabled:!0,children:x}):e.jsx(vi,{children:x})},[w,x,l,je]),yt=u.useMemo(()=>bx(je,H),[je,H]),U=u.useCallback(()=>{if(_?.filter)return _.filter;if(w)return(ne,ve)=>ne.toLowerCase().includes(ve.toLowerCase())?1:-1},[w,_?.filter]),te=u.useCallback(()=>{const ne=H.filter(ve=>ve.fixed);ee(ne),n?.(ne)},[n,H]);return e.jsxs(it,{..._,onKeyDown:ne=>{Ws(ne),_?.onKeyDown?.(ne)},className:N("h-auto overflow-visible bg-transparent",_?.className),shouldFilter:_?.shouldFilter!==void 0?_.shouldFilter:!l,filter:U(),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":H.length!==0,"cursor-text":!f&&H.length!==0},S),onClick:()=>{f||R.current?.focus()},children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[H.map(ne=>e.jsxs(q,{className:N("data-[disabled]:bg-muted-foreground data-[disabled]:text-muted data-[disabled]:hover:bg-muted-foreground","data-[fixed]:bg-muted-foreground data-[fixed]:text-muted data-[fixed]:hover:bg-muted-foreground",C),"data-fixed":ne.fixed,"data-disabled":f||void 0,children:[ne.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",(f||ne.fixed)&&"hidden"),onKeyDown:ve=>{ve.key==="Enter"&&Ns(ne)},onMouseDown:ve=>{ve.preventDefault(),ve.stopPropagation()},onClick:()=>Ns(ne),children:e.jsx(_n,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},ne.value)),e.jsx(xs.Input,{...g,ref:R,value:Me,disabled:f,onValueChange:ne=>{le(ne),g?.onValueChange?.(ne)},onBlur:ne=>{Z.current===!1&&K(!1),g?.onBlur?.(ne)},onFocus:ne=>{K(!0),E&&l?.(Ts),g?.onFocus?.(ne)},placeholder:c&&H.length!==0?"":t,className:N("flex-1 bg-transparent outline-none placeholder:text-muted-foreground",{"w-full":c,"px-3 py-2":H.length===0,"ml-1":H.length!==0},g?.className)}),e.jsx("button",{type:"button",onClick:te,className:N((p||f||H.length<1||H.filter(ne=>ne.fixed).length===H.length)&&"hidden"),children:e.jsx(_n,{})})]})}),e.jsx("div",{className:"relative",children:L&&e.jsx(ot,{className:"absolute top-1 z-10 w-full rounded-md border bg-popover text-popover-foreground shadow-md outline-none animate-in",onMouseLeave:()=>{Z.current=!1},onMouseEnter:()=>{Z.current=!0},onMouseUp:()=>{R.current?.focus()},children:se?e.jsx(e.Fragment,{children:d}):e.jsxs(e.Fragment,{children:[Ys(),Us(),!T&&e.jsx(rs,{value:"-",className:"hidden"}),Object.entries(yt).map(([ne,ve])=>e.jsx(ks,{heading:ne,className:"h-full overflow-auto",children:e.jsx(e.Fragment,{children:ve.map(Ye=>e.jsx(rs,{value:Ye.value,disabled:Ye.disable,onMouseDown:_e=>{_e.preventDefault(),_e.stopPropagation()},onSelect:()=>{if(H.length>=m){o?.(H.length);return}le("");const _e=[...H,Ye];ee(_e),n?.(_e)},className:N("cursor-pointer",Ye.disable&&"cursor-default text-muted-foreground"),children:Ye.label},Ye.value))})},ne))]})})})]})});nt.displayName="MultipleSelector";const _x=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 Za({refetch:s,dialogTrigger:n,defaultValues:t={name:""},type:r="add"}){const{t:a}=M("group"),i=we({resolver:Te(_x(a)),defaultValues:t,mode:"onChange"}),[l,d]=u.useState(!1),[x,m]=u.useState(!1),o=async c=>{m(!0),jt.save(c).then(()=>{z.success(a(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),s&&s(),i.reset(),d(!1)}).finally(()=>{m(!1)})};return e.jsxs(me,{open:l,onOpenChange:d,children:[e.jsx(ps,{asChild:!0,children:n||e.jsxs(F,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ue,{icon:"ion:add"}),e.jsx("span",{children:a("form.add")})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:a(r==="edit"?"form.edit":"form.create")}),e.jsx($e,{children:a(r==="edit"?"form.editDescription":"form.createDescription")})]}),e.jsx(De,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(o),className:"space-y-4",children:[e.jsx(v,{control:i.control,name:"name",render:({field:c})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.name")}),e.jsx(y,{children:e.jsx(k,{placeholder:a("form.namePlaceholder"),...c,className:"w-full"})}),e.jsx($,{children:a("form.nameDescription")}),e.jsx(P,{})]})}),e.jsxs(Ie,{className:"gap-2",children:[e.jsx(et,{asChild:!0,children:e.jsx(F,{type:"button",variant:"outline",children:a("form.cancel")})}),e.jsxs(F,{type:"submit",disabled:x||!i.formState.isValid,children:[x&&e.jsx(Sa,{className:"mr-2 h-4 w-4 animate-spin"}),a(r==="edit"?"form.update":"form.create")]})]})]})})]})]})}const bi=u.createContext(void 0);function Nx({children:s,refetch:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(null),[l,d]=u.useState(ge.Shadowsocks);return e.jsx(bi.Provider,{value:{isOpen:t,setIsOpen:r,editingServer:a,setEditingServer:i,serverType:l,setServerType:d,refetch:n},children:s})}function yi(){const s=u.useContext(bi);if(s===void 0)throw new Error("useServerEdit must be used within a ServerEditProvider");return s}function un({dialogTrigger:s,value:n,setValue:t,templateType:r}){const{t:a}=M("server");u.useEffect(()=>{console.log(n)},[n]);const[i,l]=u.useState(!1),[d,x]=u.useState(()=>{if(!n||Object.keys(n).length===0)return"";try{return JSON.stringify(n,null,2)}catch{return""}}),[m,o]=u.useState(null),c=w=>{if(!w)return null;try{const E=JSON.parse(w);return typeof E!="object"||E===null?a("network_settings.validation.must_be_object"):null}catch{return a("network_settings.validation.invalid_json")}},f={tcp:{label:"TCP",content:{acceptProxyProtocol:!1,header:{type:"none"}}},"tcp-http":{label:"TCP + HTTP",content:{acceptProxyProtocol:!1,header:{type:"http",request:{version:"1.1",method:"GET",path:["/"],headers:{Host:["www.example.com"]}},response:{version:"1.1",status:"200",reason:"OK"}}}},grpc:{label:"gRPC",content:{serviceName:"GunService"}},ws:{label:"WebSocket",content:{path:"/",headers:{Host:"v2ray.com"}}},httpupgrade:{label:"HttpUpgrade",content:{acceptProxyProtocol:!1,path:"/",host:"xray.com",headers:{key:"value"}}},xhttp:{label:"XHTTP",content:{host:"example.com",path:"/yourpath",mode:"auto",extra:{headers:{},xPaddingBytes:"100-1000",noGRPCHeader:!1,noSSEHeader:!1,scMaxEachPostBytes:1e6,scMinPostsIntervalMs:30,scMaxBufferedPosts:30,xmux:{maxConcurrency:"16-32",maxConnections:0,cMaxReuseTimes:"64-128",cMaxLifetimeMs:0,hMaxRequestTimes:"800-900",hKeepAlivePeriod:0},downloadSettings:{address:"",port:443,network:"xhttp",security:"tls",tlsSettings:{},xhttpSettings:{path:"/yourpath"},sockopt:{}}}}}},D=()=>{switch(r){case"tcp":return["tcp","tcp-http"];case"grpc":return["grpc"];case"ws":return["ws"];case"httpupgrade":return["httpupgrade"];case"xhttp":return["xhttp"];default:return[]}},S=()=>{const w=c(d||"");if(w){z.error(w);return}try{if(!d){t(null),l(!1);return}t(JSON.parse(d)),l(!1)}catch{z.error(a("network_settings.errors.save_failed"))}},C=w=>{x(w),o(c(w))},T=w=>{const E=f[w];if(E){const _=JSON.stringify(E.content,null,2);x(_),o(null)}};return u.useEffect(()=>{i&&console.log(n)},[i,n]),u.useEffect(()=>{i&&n&&Object.keys(n).length>0&&x(JSON.stringify(n,null,2))},[i,n]),e.jsxs(me,{open:i,onOpenChange:w=>{!w&&i&&S(),l(w)},children:[e.jsx(ps,{asChild:!0,children:s??e.jsx(G,{variant:"link",children:a("network_settings.edit_protocol")})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsx(pe,{children:e.jsx(ue,{children:a("network_settings.edit_protocol_config")})}),e.jsxs("div",{className:"space-y-4",children:[D().length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:D().map(w=>e.jsx(G,{variant:"outline",size:"sm",onClick:()=>T(w),children:a("network_settings.use_template",{template:f[w].label})},w))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Es,{className:`min-h-[200px] font-mono text-sm ${m?"border-red-500 focus-visible:ring-red-500":""}`,value:d,placeholder:D().length>0?a("network_settings.json_config_placeholder_with_template"):a("network_settings.json_config_placeholder"),onChange:w=>C(w.target.value)}),m&&e.jsx("p",{className:"text-sm text-red-500",children:m})]})]}),e.jsxs(Ie,{className:"gap-2",children:[e.jsx(G,{variant:"outline",onClick:()=>l(!1),children:a("common.cancel")}),e.jsx(G,{onClick:S,disabled:!!m,children:a("common.confirm")})]})]})]})}function mp(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 wx={},Cx=Object.freeze(Object.defineProperty({__proto__:null,default:wx},Symbol.toStringTag,{value:"Module"})),up=Ld(Cx),yr=s=>s.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),Sx=()=>{try{const s=gd.box.keyPair(),n=yr(lr.encodeBase64(s.secretKey)),t=yr(lr.encodeBase64(s.publicKey));return{privateKey:n,publicKey:t}}catch(s){throw console.error("Error generating x25519 key pair:",s),s}},kx=()=>{try{return Sx()}catch(s){throw console.error("Error generating key pair:",s),s}},Tx=s=>{const n=new Uint8Array(Math.ceil(s/2));return window.crypto.getRandomValues(n),Array.from(n).map(t=>t.toString(16).padStart(2,"0")).join("").substring(0,s)},Dx=()=>{const s=Math.floor(Math.random()*8)*2+2;return Tx(s)},Fx=h.object({cipher:h.string().default("aes-128-gcm"),plugin:h.string().optional().default(""),plugin_opts:h.string().optional().default(""),client_fingerprint:h.string().optional().default("chrome")}),Px=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({})}),Lx=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({})}),Rx=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({}),hop_interval:h.number().optional(),port_range:h.string().optional()}),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("")}),Vx=h.object({version:h.coerce.number().default(5),congestion_control:h.string().default("bbr"),alpn:h.array(h.string()).default(["h3"]),udp_relay_mode:h.string().default("native"),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),Ix=h.object({}),Mx=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),Ox=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),zx=h.object({transport:h.string().default("tcp"),multiplexing:h.string().default("MULTIPLEXING_LOW")}),$x=h.object({padding_scheme:h.array(h.string()).optional().default([]),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),Oe={shadowsocks:{schema:Fx,ciphers:["aes-128-gcm","aes-192-gcm","aes-256-gcm","chacha20-ietf-poly1305","2022-blake3-aes-128-gcm","2022-blake3-aes-256-gcm"],plugins:[{value:"none",label:"None"},{value:"obfs",label:"Simple Obfs"},{value:"v2ray-plugin",label:"V2Ray Plugin"}],clientFingerprints:[{value:"chrome",label:"Chrome"},{value:"firefox",label:"Firefox"},{value:"safari",label:"Safari"},{value:"ios",label:"iOS"}]},vmess:{schema:Px,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},trojan:{schema:Lx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},hysteria:{schema:Rx,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"]},tuic:{schema:Vx,versions:["5","4"],congestionControls:["bbr","cubic","new_reno"],alpnOptions:[{value:"h3",label:"HTTP/3"},{value:"h2",label:"HTTP/2"},{value:"http/1.1",label:"HTTP/1.1"}],udpRelayModes:[{value:"native",label:"Native"},{value:"quic",label:"QUIC"}]},socks:{schema:Ix},naive:{schema:Ox},http:{schema:Mx},mieru:{schema:zx,transportOptions:[{value:"tcp",label:"TCP"},{value:"udp",label:"UDP"}],multiplexingOptions:[{value:"MULTIPLEXING_OFF",label:"Off"},{value:"MULTIPLEXING_LOW",label:"Low"},{value:"MULTIPLEXING_MIDDLE",label:"Middle"},{value:"MULTIPLEXING_HIGH",label:"High"}]},anytls:{schema:$x,defaultPaddingScheme:["stop=8","0=30-30","1=100-400","2=400-500,c,500-1000,c,500-1000,c,500-1000,c,500-1000","3=9-9,500-1000","4=500-1000","5=500-1000","6=500-1000","7=500-1000"]}},Ax=({serverType:s,value:n,onChange:t})=>{const{t:r}=M("server"),a=s?Oe[s]:null,i=a?.schema||h.record(h.any()),l=s?i.parse({}):{},d=we({resolver:Te(i),defaultValues:l,mode:"onChange"});if(u.useEffect(()=>{if(!n||Object.keys(n).length===0){if(s){const g=i.parse({});d.reset(g)}}else d.reset(n)},[s,n,t,d,i]),u.useEffect(()=>{const g=d.watch(p=>{t(p)});return()=>g.unsubscribe()},[d,t]),!s||!a)return null;const _={shadowsocks:()=>e.jsxs(e.Fragment,{children:[e.jsx(v,{control:d.control,name:"cipher",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.shadowsocks.cipher.label")}),e.jsx(y,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.shadowsocks.cipher.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.shadowsocks.ciphers.map(p=>e.jsx(A,{value:p,children:p},p))})})]})})]})}),e.jsx(v,{control:d.control,name:"plugin",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.shadowsocks.plugin.label","插件")}),e.jsx(y,{children:e.jsxs(J,{onValueChange:p=>g.onChange(p==="none"?"":p),value:g.value===""?"none":g.value||"none",children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.shadowsocks.plugin.placeholder","选择插件")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.shadowsocks.plugins.map(p=>e.jsx(A,{value:p.value,children:p.label},p.value))})})]})}),e.jsx($,{children:g.value&&g.value!=="none"&&g.value!==""&&e.jsxs(e.Fragment,{children:[g.value==="obfs"&&r("dynamic_form.shadowsocks.plugin.obfs_hint","提示:配置格式如 obfs=http;obfs-host=www.bing.com;path=/"),g.value==="v2ray-plugin"&&r("dynamic_form.shadowsocks.plugin.v2ray_hint","提示:WebSocket模式格式为 mode=websocket;host=mydomain.me;path=/;tls=true,QUIC模式格式为 mode=quic;host=mydomain.me")]})})]})}),d.watch("plugin")&&d.watch("plugin")!=="none"&&d.watch("plugin")!==""&&e.jsx(v,{control:d.control,name:"plugin_opts",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.shadowsocks.plugin_opts.label","插件选项")}),e.jsx($,{children:r("dynamic_form.shadowsocks.plugin_opts.description","按照 key=value;key2=value2 格式输入插件选项")}),e.jsx(y,{children:e.jsx(k,{type:"text",placeholder:r("dynamic_form.shadowsocks.plugin_opts.placeholder","例如: mode=tls;host=bing.com"),...g})})]})}),(d.watch("plugin")==="shadow-tls"||d.watch("plugin")==="restls")&&e.jsx(v,{control:d.control,name:"client_fingerprint",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.shadowsocks.client_fingerprint","客户端指纹")}),e.jsx(y,{children:e.jsxs(J,{value:g.value||"chrome",onValueChange:g.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.shadowsocks.client_fingerprint_placeholder","选择客户端指纹")})}),e.jsx(Y,{children:Oe.shadowsocks.clientFingerprints.map(p=>e.jsx(A,{value:p.value,children:p.label},p.value))})]})}),e.jsx($,{children:r("dynamic_form.shadowsocks.client_fingerprint_description","客户端伪装指纹,用于降低被识别风险")})]})})]}),vmess:()=>e.jsxs(e.Fragment,{children:[e.jsx(v,{control:d.control,name:"tls",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.vmess.tls.label")}),e.jsx(y,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:p=>g.onChange(Number(p)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vmess.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:r("dynamic_form.vmess.tls.disabled")}),e.jsx(A,{value:"1",children:r("dynamic_form.vmess.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.vmess.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.vmess.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(v,{control:d.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.vmess.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(X,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx(v,{control:d.control,name:"network",render:({field:g})=>e.jsxs(j,{children:[e.jsxs(b,{children:[r("dynamic_form.vmess.network.label"),e.jsx(un,{value:d.watch("network_settings"),setValue:p=>d.setValue("network_settings",p),templateType:d.watch("network")})]}),e.jsx(y,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vmess.network.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.vmess.networkOptions.map(p=>e.jsx(A,{value:p.value,className:"cursor-pointer",children:p.label},p.value))})})]})})]})})]}),trojan:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.trojan.server_name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.trojan.server_name.placeholder"),...g,value:g.value||""})})]})}),e.jsx(v,{control:d.control,name:"allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.trojan.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(X,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})})]}),e.jsx(v,{control:d.control,name:"network",render:({field:g})=>e.jsxs(j,{children:[e.jsxs(b,{children:[r("dynamic_form.trojan.network.label"),e.jsx(un,{value:d.watch("network_settings")||{},setValue:p=>d.setValue("network_settings",p),templateType:d.watch("network")||"tcp"})]}),e.jsx(y,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value||"tcp",children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.trojan.network.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.trojan.networkOptions.map(p=>e.jsx(A,{value:p.value,className:"cursor-pointer",children:p.label},p.value))})})]})})]})})]}),hysteria:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"version",render:({field:g})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:r("dynamic_form.hysteria.version.label")}),e.jsx(y,{children:e.jsxs(J,{value:(g.value||2).toString(),onValueChange:p=>g.onChange(Number(p)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.hysteria.version.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.hysteria.versions.map(p=>e.jsxs(A,{value:p,className:"cursor-pointer",children:["V",p]},p))})})]})})]})}),d.watch("version")==1&&e.jsx(v,{control:d.control,name:"alpn",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.hysteria.alpn.label")}),e.jsx(y,{children:e.jsxs(J,{value:g.value||"h2",onValueChange:g.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.hysteria.alpn.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.hysteria.alpnOptions.map(p=>e.jsx(A,{value:p,children:p},p))})})]})})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"obfs.open",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.hysteria.obfs.label")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(X,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})}),!!d.watch("obfs.open")&&e.jsxs(e.Fragment,{children:[d.watch("version")=="2"&&e.jsx(v,{control:d.control,name:"obfs.type",render:({field:g})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:r("dynamic_form.hysteria.obfs.type.label")}),e.jsx(y,{children:e.jsxs(J,{value:g.value||"salamander",onValueChange:g.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.hysteria.obfs.type.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:e.jsx(A,{value:"salamander",children:r("dynamic_form.hysteria.obfs.type.salamander")})})})]})})]})}),e.jsx(v,{control:d.control,name:"obfs.password",render:({field:g})=>e.jsxs(j,{className:d.watch("version")==2?"w-full":"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.hysteria.obfs.password.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.hysteria.obfs.password.placeholder"),...g,value:g.value||"",className:"pr-9"})}),e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",V=Array.from(crypto.getRandomValues(new Uint8Array(16))).map(R=>p[R%p.length]).join("");d.setValue("obfs.password",V),z.success(r("dynamic_form.hysteria.obfs.password.generate_success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Ue,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})]})]})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"tls.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.hysteria.tls.server_name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.hysteria.tls.server_name.placeholder"),...g,value:g.value||""})})]})}),e.jsx(v,{control:d.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.hysteria.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(X,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})})]}),e.jsx(v,{control:d.control,name:"bandwidth.up",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.hysteria.bandwidth.up.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:r("dynamic_form.hysteria.bandwidth.up.placeholder")+(d.watch("version")==2?r("dynamic_form.hysteria.bandwidth.up.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...g,value:g.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:r("dynamic_form.hysteria.bandwidth.up.suffix")})})]})]})}),e.jsx(v,{control:d.control,name:"bandwidth.down",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.hysteria.bandwidth.down.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:r("dynamic_form.hysteria.bandwidth.down.placeholder")+(d.watch("version")==2?r("dynamic_form.hysteria.bandwidth.down.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...g,value:g.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:r("dynamic_form.hysteria.bandwidth.down.suffix")})})]})]})}),e.jsx(e.Fragment,{children:e.jsx(v,{control:d.control,name:"hop_interval",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.hysteria.hop_interval.label","Hop 间隔 (秒)")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:r("dynamic_form.hysteria.hop_interval.placeholder","例如: 30"),...g,value:g.value||"",onChange:p=>{const V=p.target.value?parseInt(p.target.value):void 0;g.onChange(V)}})}),e.jsx($,{children:r("dynamic_form.hysteria.hop_interval.description","Hop 间隔时间,单位为秒")})]})})})]}),vless:()=>e.jsxs(e.Fragment,{children:[e.jsx(v,{control:d.control,name:"tls",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.vless.tls.label")}),e.jsx(y,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:p=>g.onChange(Number(p)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vless.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:r("dynamic_form.vless.tls.none")}),e.jsx(A,{value:"1",children:r("dynamic_form.vless.tls.tls")}),e.jsx(A,{value:"2",children:r("dynamic_form.vless.tls.reality")})]})]})})]})}),d.watch("tls")=="1"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.vless.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.vless.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(v,{control:d.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.vless.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(X,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),d.watch("tls")==2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"reality_settings.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.vless.reality_settings.server_name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.vless.reality_settings.server_name.placeholder"),...g})})]})}),e.jsx(v,{control:d.control,name:"reality_settings.server_port",render:({field:g})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:r("dynamic_form.vless.reality_settings.server_port.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.vless.reality_settings.server_port.placeholder"),...g})})]})}),e.jsx(v,{control:d.control,name:"reality_settings.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.vless.reality_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(X,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx("div",{className:"flex items-end gap-2",children:e.jsx(v,{control:d.control,name:"reality_settings.private_key",render:({field:g})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:r("dynamic_form.vless.reality_settings.private_key.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{children:e.jsx(k,{...g,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 p=kx();d.setValue("reality_settings.private_key",p.privateKey),d.setValue("reality_settings.public_key",p.publicKey),z.success(r("dynamic_form.vless.reality_settings.key_pair.success"))}catch{z.error(r("dynamic_form.vless.reality_settings.key_pair.error"))}},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Ue,{icon:"ion:key-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(Ta,{children:e.jsx(de,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.key_pair.generate")})})})]})]})]})})}),e.jsx(v,{control:d.control,name:"reality_settings.public_key",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.vless.reality_settings.public_key.label")}),e.jsx(y,{children:e.jsx(k,{...g})})]})}),e.jsx(v,{control:d.control,name:"reality_settings.short_id",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.vless.reality_settings.short_id.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{children:e.jsx(k,{...g,className:"pr-9",placeholder:r("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 p=Dx();d.setValue("reality_settings.short_id",p),z.success(r("dynamic_form.vless.reality_settings.short_id.success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Ue,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(Ta,{children:e.jsx(de,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.short_id.generate")})})})]})]}),e.jsx($,{className:"text-xs text-muted-foreground",children:r("dynamic_form.vless.reality_settings.short_id.description")})]})})]}),e.jsx(v,{control:d.control,name:"network",render:({field:g})=>e.jsxs(j,{children:[e.jsxs(b,{children:[r("dynamic_form.vless.network.label"),e.jsx(un,{value:d.watch("network_settings"),setValue:p=>d.setValue("network_settings",p),templateType:d.watch("network")})]}),e.jsx(y,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vless.network.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.vless.networkOptions.map(p=>e.jsx(A,{value:p.value,className:"cursor-pointer",children:p.label},p.value))})})]})})]})}),e.jsx(v,{control:d.control,name:"flow",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.vless.flow.label")}),e.jsx(y,{children:e.jsxs(J,{onValueChange:p=>g.onChange(p==="none"?null:p),value:g.value||"none",children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vless.flow.placeholder")})}),e.jsx(Y,{children:Oe.vless.flowOptions.map(p=>e.jsx(A,{value:p,children:p},p))})]})})]})})]}),tuic:()=>e.jsxs(e.Fragment,{children:[e.jsx(v,{control:d.control,name:"version",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.tuic.version.label")}),e.jsx(y,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:p=>g.onChange(Number(p)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.tuic.version.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.tuic.versions.map(p=>e.jsxs(A,{value:p,children:["V",p]},p))})})]})})]})}),e.jsx(v,{control:d.control,name:"congestion_control",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.tuic.congestion_control.label")}),e.jsx(y,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.tuic.congestion_control.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.tuic.congestionControls.map(p=>e.jsx(A,{value:p,children:p.toUpperCase()},p))})})]})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"tls.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.tuic.tls.server_name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.tuic.tls.server_name.placeholder"),...g})})]})}),e.jsx(v,{control:d.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.tuic.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(X,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx(v,{control:d.control,name:"alpn",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.tuic.tls.alpn.label")}),e.jsx(y,{children:e.jsx(nt,{options:Oe.tuic.alpnOptions,onChange:p=>g.onChange(p.map(V=>V.value)),value:Oe.tuic.alpnOptions.filter(p=>g.value?.includes(p.value)),placeholder:r("dynamic_form.tuic.tls.alpn.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:r("dynamic_form.tuic.tls.alpn.empty")})})})]})}),e.jsx(v,{control:d.control,name:"udp_relay_mode",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.tuic.udp_relay_mode.label")}),e.jsx(y,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.tuic.udp_relay_mode.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.tuic.udpRelayModes.map(p=>e.jsx(A,{value:p.value,children:p.label},p.value))})})]})})]})})]}),socks:()=>e.jsx(e.Fragment,{}),naive:()=>e.jsxs(e.Fragment,{children:[e.jsx(v,{control:d.control,name:"tls",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.naive.tls.label")}),e.jsx(y,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:p=>g.onChange(Number(p)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.naive.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:r("dynamic_form.naive.tls.disabled")}),e.jsx(A,{value:"1",children:r("dynamic_form.naive.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.naive.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.naive.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(v,{control:d.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.naive.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(X,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]}),http:()=>e.jsxs(e.Fragment,{children:[e.jsx(v,{control:d.control,name:"tls",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.http.tls.label")}),e.jsx(y,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:p=>g.onChange(Number(p)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.http.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:r("dynamic_form.http.tls.disabled")}),e.jsx(A,{value:"1",children:r("dynamic_form.http.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.http.tls_settings.server_name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.http.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(v,{control:d.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.http.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(X,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]}),mieru:()=>e.jsxs(e.Fragment,{children:[e.jsx(v,{control:d.control,name:"transport",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.mieru.transport.label")}),e.jsx(y,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.mieru.transport.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.mieru.transportOptions.map(p=>e.jsx(A,{value:p.value,children:p.label},p.value))})})]})})]})}),e.jsx(v,{control:d.control,name:"multiplexing",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.mieru.multiplexing.label")}),e.jsx(y,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.mieru.multiplexing.placeholder")})}),e.jsx(Y,{children:e.jsx(fs,{children:Oe.mieru.multiplexingOptions.map(p=>e.jsx(A,{value:p.value,children:p.label},p.value))})})]})})]})})]}),anytls:()=>e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:d.control,name:"padding_scheme",render:({field:g})=>e.jsxs(j,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(b,{children:r("dynamic_form.anytls.padding_scheme.label","AnyTLS 填充方案")}),e.jsx(G,{type:"button",variant:"outline",size:"sm",onClick:()=>{d.setValue("padding_scheme",Oe.anytls.defaultPaddingScheme),z.success(r("dynamic_form.anytls.padding_scheme.default_success","已设置默认填充方案"))},className:"h-7 px-2",children:r("dynamic_form.anytls.padding_scheme.use_default","使用默认方案")})]}),e.jsx($,{children:r("dynamic_form.anytls.padding_scheme.description","每行一个填充规则,格式如: stop=8, 0=30-30")}),e.jsx(y,{children:e.jsx("textarea",{className:"flex min-h-[100px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",placeholder:r("dynamic_form.anytls.padding_scheme.placeholder",`例如:
|
||
stop=8
|
||
0=30-30
|
||
1=100-400
|
||
2=400-500,c,500-1000`),...g,value:Array.isArray(g.value)?g.value.join(`
|
||
`):"",onChange:p=>{const R=p.target.value.split(`
|
||
`).filter(L=>L.trim()!=="");g.onChange(R)}})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:d.control,name:"tls.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:r("dynamic_form.anytls.tls.server_name.label","SNI")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dynamic_form.anytls.tls.server_name.placeholder","服务器名称"),...g})})]})}),e.jsx(v,{control:d.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dynamic_form.anytls.tls.allow_insecure","允许不安全连接")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(y,{children:e.jsx(X,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]})})};return e.jsx(fe,{children:_[s]?.()})};function qx(){const{t:s}=M("server"),n=h.object({start:h.string().min(1,s("form.dynamic_rate.start_time_error")),end:h.string().min(1,s("form.dynamic_rate.end_time_error")),rate:h.string().min(1,s("form.dynamic_rate.multiplier_error")).refine(R=>!isNaN(parseFloat(R))&&isFinite(Number(R)),{message:s("form.dynamic_rate.multiplier_error_numeric")}).refine(R=>parseFloat(R)>=0,{message:s("form.dynamic_rate.multiplier_error_gte_zero")})}),t=h.object({id:h.number().optional().nullable(),specific_key:h.string().optional().nullable(),code:h.string().optional(),show:h.boolean().optional().nullable(),name:h.string().min(1,s("form.name.error")),rate:h.string().min(1,s("form.rate.error")).refine(R=>!isNaN(parseFloat(R))&&isFinite(Number(R)),{message:s("form.rate.error_numeric")}).refine(R=>parseFloat(R)>=0,{message:s("form.rate.error_gte_zero")}),rate_time_enable:h.boolean().default(!1),rate_time_ranges:h.array(n).default([]),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,s("form.host.error")),port:h.string().min(1,s("form.port.error")),server_port:h.string().min(1,s("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()}),r={id:null,specific_key:null,code:"",show:!1,name:"",rate:"1",rate_time_enable:!1,rate_time_ranges:[],tags:[],excludes:[],ips:[],group_ids:[],host:"",port:"",server_port:"",parent_id:"0",route_ids:[],protocol_settings:null},{isOpen:a,setIsOpen:i,editingServer:l,setEditingServer:d,serverType:x,setServerType:m,refetch:o}=yi(),[c,f]=u.useState([]),[D,S]=u.useState([]),[C,T]=u.useState([]),w=we({resolver:Te(t),defaultValues:r,mode:"onChange"});u.useEffect(()=>{E()},[a]),u.useEffect(()=>{l?.type&&l.type!==x&&m(l.type)},[l,x,m]),u.useEffect(()=>{l?l.type===x&&w.reset({...r,...l}):w.reset({...r,protocol_settings:Oe[x].schema.parse({})})},[l,w,x]);const E=async()=>{if(!a)return;const[R,L,K]=await Promise.all([jt.getList(),qa.getList(),ut.getList()]);f(R.data?.map(Z=>({label:Z.name,value:Z.id.toString()}))||[]),S(L.data?.map(Z=>({label:Z.remarks,value:Z.id.toString()}))||[]),T(K.data||[])},_=u.useMemo(()=>C?.filter(R=>(R.parent_id===0||R.parent_id===null)&&R.type===x&&R.id!==w.watch("id")),[x,C,w]),g=()=>e.jsxs(Hs,{children:[e.jsx(Bs,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ue,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(zs,{align:"start",children:e.jsx(hm,{children:Fs.map(({type:R,label:L})=>e.jsx(Se,{onClick:()=>{m(R),i(!0)},className:"cursor-pointer",children:e.jsx(q,{variant:"outline",className:"text-white",style:{background:vs[R]},children:L})},R))})})]}),p=()=>{i(!1),d(null),w.reset(r)},V=async()=>{const R=w.getValues();(await ut.save({...R,type:x})).data&&(p(),z.success(s("form.success")),o())};return e.jsxs(me,{open:a,onOpenChange:p,children:[g(),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:s(l?"form.edit_node":"form.new_node")}),e.jsx($e,{})]}),e.jsxs(De,{...w,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{control:w.control,name:"name",render:({field:R})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:s("form.name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("form.name.placeholder"),...R})}),e.jsx(P,{})]})}),e.jsx(v,{control:w.control,name:"rate",render:({field:R})=>e.jsxs(j,{className:"flex-[1]",children:[e.jsx(b,{children:s("form.rate.label")}),e.jsx("div",{className:"relative flex",children:e.jsx(y,{children:e.jsx(k,{type:"number",min:"0",step:"0.1",...R})})}),e.jsx(P,{})]})})]}),e.jsx(v,{control:w.control,name:"rate_time_enable",render:({field:R})=>e.jsxs(j,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(b,{children:s("form.dynamic_rate.enable_label")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("form.dynamic_rate.enable_description")})]}),e.jsx(y,{children:e.jsx(X,{checked:R.value,onCheckedChange:R.onChange})})]}),e.jsx(P,{})]})}),w.watch("rate_time_enable")&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(b,{className:"",children:s("form.dynamic_rate.rules_label")}),e.jsxs(F,{type:"button",variant:"outline",size:"sm",onClick:()=>{const R=w.getValues("rate_time_ranges")||[];w.setValue("rate_time_ranges",[...R,{start:"00:00",end:"23:59",rate:"1"}])},children:[e.jsx(Ue,{icon:"ion:add",className:"mr-1 size-4"}),s("form.dynamic_rate.add_rule")]})]}),(w.watch("rate_time_ranges")||[]).map((R,L)=>e.jsxs("div",{className:"space-y-2 rounded border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:s("form.dynamic_rate.rule_title",{index:L+1})}),e.jsx(F,{type:"button",variant:"ghost",size:"sm",onClick:()=>{const K=w.getValues("rate_time_ranges")||[];K.splice(L,1),w.setValue("rate_time_ranges",[...K])},children:e.jsx(Ue,{icon:"ion:trash-outline",className:"size-4"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(v,{control:w.control,name:`rate_time_ranges.${L}.start`,render:({field:K})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-xs",children:s("form.dynamic_rate.start_time")}),e.jsx(y,{children:e.jsx(k,{type:"time",...K,className:"text-sm"})}),e.jsx(P,{})]})}),e.jsx(v,{control:w.control,name:`rate_time_ranges.${L}.end`,render:({field:K})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-xs",children:s("form.dynamic_rate.end_time")}),e.jsx(y,{children:e.jsx(k,{type:"time",...K,className:"text-sm"})}),e.jsx(P,{})]})}),e.jsx(v,{control:w.control,name:`rate_time_ranges.${L}.rate`,render:({field:K})=>e.jsxs(j,{children:[e.jsx(b,{className:"text-xs",children:s("form.dynamic_rate.multiplier")}),e.jsx(y,{children:e.jsx(k,{type:"number",min:"0",step:"0.1",...K,className:"text-sm",placeholder:"1.0"})}),e.jsx(P,{})]})})]})]},L)),(w.watch("rate_time_ranges")||[]).length===0&&e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:s("form.dynamic_rate.no_rules")})]}),e.jsx(v,{control:w.control,name:"code",render:({field:R})=>e.jsxs(j,{children:[e.jsxs(b,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(y,{children:e.jsx(k,{placeholder:s("form.code.placeholder"),...R,value:R.value||""})}),e.jsx(P,{})]})}),e.jsx(v,{control:w.control,name:"tags",render:({field:R})=>e.jsxs(j,{children:[e.jsx(b,{children:s("form.tags.label")}),e.jsx(y,{children:e.jsx(Xa,{value:R.value,onChange:R.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(P,{})]})}),e.jsx(v,{control:w.control,name:"group_ids",render:({field:R})=>e.jsxs(j,{children:[e.jsxs(b,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(Za,{dialogTrigger:e.jsx(F,{variant:"link",children:s("form.groups.add")}),refetch:E})]}),e.jsx(y,{children:e.jsx(nt,{options:c,onChange:L=>R.onChange(L.map(K=>K.value)),value:c?.filter(L=>R.value.includes(L.value)),placeholder:s("form.groups.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.groups.empty")})})}),e.jsx(P,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:w.control,name:"host",render:({field:R})=>e.jsxs(j,{children:[e.jsx(b,{children:s("form.host.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:s("form.host.placeholder"),...R})}),e.jsx(P,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(v,{control:w.control,name:"port",render:({field:R})=>e.jsxs(j,{className:"flex-1",children:[e.jsxs(b,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(Ue,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(Ta,{children:e.jsx(de,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.port.tooltip")})})})]})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(y,{children:e.jsx(k,{placeholder:s("form.port.placeholder"),...R})}),e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(F,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const L=R.value;L&&w.setValue("server_port",L)},children:e.jsx(Ue,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(de,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(P,{})]})}),e.jsx(v,{control:w.control,name:"server_port",render:({field:R})=>e.jsxs(j,{className:"flex-1",children:[e.jsxs(b,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(Ue,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(Ta,{children:e.jsx(de,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(y,{children:e.jsx(k,{placeholder:s("form.server_port.placeholder"),...R})}),e.jsx(P,{})]})})]})]}),a&&e.jsx(Ax,{serverType:x,value:w.watch("protocol_settings"),onChange:R=>w.setValue("protocol_settings",R,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(v,{control:w.control,name:"parent_id",render:({field:R})=>e.jsxs(j,{children:[e.jsx(b,{children:s("form.parent.label")}),e.jsxs(J,{onValueChange:R.onChange,value:R.value?.toString()||"0",children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:s("form.parent.none")}),_?.map(L=>e.jsx(A,{value:L.id.toString(),className:"cursor-pointer",children:L.name},L.id))]})]}),e.jsx(P,{})]})}),e.jsx(v,{control:w.control,name:"route_ids",render:({field:R})=>e.jsxs(j,{children:[e.jsx(b,{children:s("form.route.label")}),e.jsx(y,{children:e.jsx(nt,{options:D,onChange:L=>R.onChange(L.map(K=>K.value)),value:D?.filter(L=>R.value.includes(L.value)),placeholder:s("form.route.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.route.empty")})})}),e.jsx(P,{})]})})]}),e.jsxs(Ie,{className:"mt-6 flex flex-col gap-2 sm:flex-row sm:gap-0",children:[e.jsx(F,{type:"button",variant:"outline",onClick:p,className:"w-full sm:w-auto",children:s("form.cancel")}),e.jsx(F,{type:"submit",onClick:V,className:"w-full sm:w-auto",children:s("form.submit")})]})]})]})]})}function _r({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx($a,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ee,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:a.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:a.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(it,{children:[e.jsx(vt,{placeholder:n}),e.jsxs(ot,{children:[e.jsx(bt,{children:"No results found."}),e.jsx(ks,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(rs,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(pt,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Mt,{}),e.jsx(ks,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const Hx=[{value:ge.Shadowsocks,label:Fs.find(s=>s.type===ge.Shadowsocks)?.label,color:vs[ge.Shadowsocks]},{value:ge.Vmess,label:Fs.find(s=>s.type===ge.Vmess)?.label,color:vs[ge.Vmess]},{value:ge.Trojan,label:Fs.find(s=>s.type===ge.Trojan)?.label,color:vs[ge.Trojan]},{value:ge.Hysteria,label:Fs.find(s=>s.type===ge.Hysteria)?.label,color:vs[ge.Hysteria]},{value:ge.Vless,label:Fs.find(s=>s.type===ge.Vless)?.label,color:vs[ge.Vless]},{value:ge.Tuic,label:Fs.find(s=>s.type===ge.Tuic)?.label,color:vs[ge.Tuic]},{value:ge.Socks,label:Fs.find(s=>s.type===ge.Socks)?.label,color:vs[ge.Socks]},{value:ge.Naive,label:Fs.find(s=>s.type===ge.Naive)?.label,color:vs[ge.Naive]},{value:ge.Http,label:Fs.find(s=>s.type===ge.Http)?.label,color:vs[ge.Http]},{value:ge.Mieru,label:Fs.find(s=>s.type===ge.Mieru)?.label,color:vs[ge.Mieru]}];function Ux({table:s,saveOrder:n,isSortMode:t,groups:r}){const a=s.getState().columnFilters.length>0,{t:i}=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:[!t&&e.jsxs(e.Fragment,{children:[e.jsx(qx,{}),e.jsx(k,{placeholder:i("toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(_r,{column:s.getColumn("type"),title:i("toolbar.type"),options:Hx}),s.getColumn("group_ids")&&e.jsx(_r,{column:s.getColumn("group_ids"),title:i("columns.groups.title"),options:r.map(l=>({label:l.name,value:l.id.toString()}))})]}),a&&e.jsxs(F,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[i("toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),t&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sort.tip")})})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{variant:t?"default":"outline",onClick:n,size:"sm",children:i(t?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const Ra=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"})}),pa={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"},He=(s,n)=>n>0?Math.round(s/n*100):0,Kx=s=>{const{t:n}=M("server");return[{id:"drag-handle",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(za,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.nodeId")}),cell:({row:t})=>{const r=t.getValue("id"),a=t.original.code;return e.jsx(fe,{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(q,{variant:"outline",className:N("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:vs[t.original.type]},children:[e.jsx(Pl,{className:"size-3"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:a??r}),t.original.parent?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-muted-foreground/30",children:"→"}),e.jsx("span",{children:t.original.parent?.code||t.original.parent?.id})]}):""]})]}),e.jsx(F,{variant:"ghost",size:"icon",className:"size-5 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:text-muted-foreground group-hover/id:opacity-100",onClick:i=>{i.stopPropagation(),Rt(a||r.toString()).then(()=>{z.success(n("common:copy.success"))})},children:e.jsx(ir,{className:"size-3"})})]})}),e.jsxs(de,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[Fs.find(i=>i.type===t.original.type)?.label,t.original.parent?" (子节点)":""]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a?"点击括号内容或复制按钮可复制节点代码":"点击复制按钮可复制节点ID"})]})]})})},size:50,enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.show")}),cell:({row:t})=>{const[r,a]=u.useState(!!t.getValue("show"));return e.jsx(X,{checked:r,onCheckedChange:async i=>{a(i),ut.update({id:t.original.id,type:t.original.type,show:i?1:0}).catch(()=>{a(!i),s()})},style:{backgroundColor:r?vs[t.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(O,{column:t,title:n("columns.node"),tooltip:e.jsxs("div",{className:"grid grid-cols-1 gap-3 p-2",children:[e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",pa[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",pa[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",pa[2])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.2")})]})]})})}),cell:({row:t})=>e.jsx(fe,{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",pa[t.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:t.getValue("name")})]})}),e.jsx(de,{children:e.jsxs("div",{className:" space-y-3",children:[e.jsx("p",{className:"font-medium",children:n(`columns.status.${t.original.available_status}`)}),t.original.load_status&&e.jsxs("div",{className:"border-t border-border/50 pt-3",children:[e.jsx("p",{className:"mb-3 text-sm font-medium",children:n("columns.loadStatus.details")}),e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsx("div",{children:e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[n("columns.loadStatus.cpu"),":"]}),e.jsxs("div",{className:"ml-2 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:N("h-full transition-all duration-300",t.original.load_status.cpu>=90?"bg-destructive":t.original.load_status.cpu>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Math.min(100,t.original.load_status.cpu)}%`}})}),e.jsxs("span",{className:N("min-w-[3rem] text-right font-semibold",t.original.load_status.cpu>=90?"text-destructive":t.original.load_status.cpu>=70?"text-yellow-600":"text-emerald-600"),children:[Math.round(t.original.load_status.cpu),"%"]})]})]})}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[n("columns.loadStatus.memory"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:N("h-full transition-all duration-300",He(t.original.load_status.mem.used,t.original.load_status.mem.total)>=90?"bg-destructive":He(t.original.load_status.mem.used,t.original.load_status.mem.total)>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${He(t.original.load_status.mem.used,t.original.load_status.mem.total)}%`}})}),e.jsxs("span",{className:N("min-w-[3rem] text-right font-semibold",He(t.original.load_status.mem.used,t.original.load_status.mem.total)>=90?"text-destructive":He(t.original.load_status.mem.used,t.original.load_status.mem.total)>=70?"text-yellow-600":"text-emerald-600"),children:[He(t.original.load_status.mem.used,t.original.load_status.mem.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[ze(t.original.load_status.mem.used)," ","/"," ",ze(t.original.load_status.mem.total)]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[n("columns.loadStatus.swap"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:N("h-full transition-all duration-300",He(t.original.load_status.swap.used,t.original.load_status.swap.total)>=80?"bg-destructive":He(t.original.load_status.swap.used,t.original.load_status.swap.total)>=50?"bg-yellow-500":"bg-emerald-500"),style:{width:`${He(t.original.load_status.swap.used,t.original.load_status.swap.total)}%`}})}),e.jsxs("span",{className:N("min-w-[3rem] text-right font-semibold",He(t.original.load_status.swap.used,t.original.load_status.swap.total)>=80?"text-destructive":He(t.original.load_status.swap.used,t.original.load_status.swap.total)>=50?"text-yellow-600":"text-emerald-600"),children:[He(t.original.load_status.swap.used,t.original.load_status.swap.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[ze(t.original.load_status.swap.used)," ","/"," ",ze(t.original.load_status.swap.total)]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[n("columns.loadStatus.disk"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:N("h-full transition-all duration-300",He(t.original.load_status.disk.used,t.original.load_status.disk.total)>=90?"bg-destructive":He(t.original.load_status.disk.used,t.original.load_status.disk.total)>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${He(t.original.load_status.disk.used,t.original.load_status.disk.total)}%`}})}),e.jsxs("span",{className:N("min-w-[3rem] text-right font-semibold",He(t.original.load_status.disk.used,t.original.load_status.disk.total)>=90?"text-destructive":He(t.original.load_status.disk.used,t.original.load_status.disk.total)>=70?"text-yellow-600":"text-emerald-600"),children:[He(t.original.load_status.disk.used,t.original.load_status.disk.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[ze(t.original.load_status.disk.used)," ","/"," ",ze(t.original.load_status.disk.total)]})]})]})]})]})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.address")}),cell:({row:t})=>{const r=`${t.original.host}:${t.original.port}`,a=t.original.port!==t.original.server_port;return e.jsxs("div",{className:"group relative flex min-w-0 items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-1 gap-y-0.5 pr-7",children:[e.jsx("div",{className:"flex items-center ",children:e.jsxs("span",{className:"font-mono text-sm font-medium text-foreground/90",children:[t.original.host,":",t.original.port]})}),a&&e.jsxs("span",{className:"whitespace-nowrap text-[0.7rem] tracking-tight text-muted-foreground/40",children:["(",n("columns.internalPort")," ",t.original.server_port,")"]})]}),e.jsx("div",{className:"absolute right-0 top-0",children:e.jsx(fe,{delayDuration:0,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(F,{variant:"ghost",size:"icon",className:"size-6 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:bg-muted/50 hover:text-muted-foreground group-hover:opacity-100",onClick:i=>{i.stopPropagation(),Rt(r).then(()=>{z.success(n("common:copy.success"))})},children:e.jsx(ir,{className:"size-3"})})}),e.jsx(de,{side:"top",sideOffset:10,children:n("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.onlineUsers.title"),tooltip:n("columns.onlineUsers.tooltip")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(Ra,{className:"size-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("online")})]}),size:80,enableSorting:!0,enableHiding:!0},{accessorKey:"rate",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.rate.title"),tooltip:n("columns.rate.tooltip")}),cell:({row:t})=>e.jsxs(q,{variant:"secondary",className:"font-medium",children:[t.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"group_ids",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.groups.title"),tooltip:n("columns.groups.tooltip")}),cell:({row:t})=>{const r=t.original.groups||[];return e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.map((a,i)=>e.jsx(q,{variant:"secondary",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:a.name},i)),r.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:n("columns.groups.empty")})]})},enableSorting:!1,filterFn:(t,r,a)=>{const i=t.getValue(r);return i?a.some(l=>i.includes(l)):!1}},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.type")}),cell:({row:t})=>{const r=t.getValue("type");return e.jsx(q,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:vs[r]},children:r})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingServer:a,setServerType:i}=yi();return e.jsx("div",{className:"flex justify-center",children:e.jsxs(Hs,{modal:!1,children:[e.jsx(Bs,{asChild:!0,children:e.jsx(F,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Da,{className:"size-4"})})}),e.jsxs(zs,{align:"end",className:"w-40",children:[e.jsx(Se,{className:"cursor-pointer",onClick:()=>{i(t.original.type),a(t.original),r(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(pd,{className:"mr-2 size-4"}),n("columns.actions_dropdown.edit")]})}),e.jsxs(Se,{className:"cursor-pointer",onClick:async()=>{ut.copy({id:t.original.id}).then(({data:l})=>{l&&(z.success(n("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx(Mn,{className:"mr-2 size-4"}),n("columns.actions_dropdown.copy")]}),e.jsx(at,{}),e.jsx(Se,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:l=>l.preventDefault(),children:e.jsx(_s,{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()=>{ut.drop({id:t.original.id}).then(({data:l})=>{l&&(z.success(n("columns.actions_dropdown.delete_success")),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(us,{className:"mr-2 size-4"}),n("columns.actions_dropdown.delete.confirm")]})})})]})]})})},size:50}]};function Bx(){const[s,n]=u.useState({}),[t,r]=u.useState({"drag-handle":!1}),[a,i]=u.useState([]),[l,d]=u.useState({pageSize:500,pageIndex:0}),[x,m]=u.useState([]),[o,c]=u.useState(!1),[f,D]=u.useState({}),[S,C]=u.useState([]),{refetch:T}=re({queryKey:["nodeList"],queryFn:async()=>{const{data:V}=await ut.getList();return C(V),V}}),{data:w}=re({queryKey:["groups"],queryFn:async()=>{const{data:V}=await jt.getList();return V}});u.useEffect(()=>{r({"drag-handle":o,show:!o,host:!o,online:!o,rate:!o,groups:!o,type:!1,actions:!o}),D({name:o?2e3:200}),d({pageSize:o?99999:500,pageIndex:0})},[o]);const E=(V,R)=>{o&&(V.dataTransfer.setData("text/plain",R.toString()),V.currentTarget.classList.add("opacity-50"))},_=(V,R)=>{if(!o)return;V.preventDefault(),V.currentTarget.classList.remove("bg-muted");const L=parseInt(V.dataTransfer.getData("text/plain"));if(L===R)return;const K=[...S],[Z]=K.splice(L,1);K.splice(R,0,Z),C(K)},g=async()=>{if(!o){c(!0);return}const V=S?.map((R,L)=>({id:R.id,order:L+1}));ut.sort(V).then(()=>{z.success("排序保存成功"),c(!1),T()}).finally(()=>{c(!1)})},p=Be({data:S||[],columns:Kx(T),state:{sorting:x,columnVisibility:t,rowSelection:s,columnFilters:a,columnSizing:f,pagination:l},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:m,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:D,onPaginationChange:d,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Nx,{refetch:T,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:p,toolbar:V=>e.jsx(Ux,{table:V,refetch:T,saveOrder:g,isSortMode:o,groups:w||[]}),draggable:o,onDragStart:E,onDragEnd:V=>V.currentTarget.classList.remove("opacity-50"),onDragOver:V=>{V.preventDefault(),V.currentTarget.classList.add("bg-muted")},onDragLeave:V=>V.currentTarget.classList.remove("bg-muted"),onDrop:_,showPagination:!o})})})}function Gx(){const{t:s}=M("server");return e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(Bx,{})})]})]})}const Wx=Object.freeze(Object.defineProperty({__proto__:null,default:Gx},Symbol.toStringTag,{value:"Module"}));function Yx({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=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(Za,{refetch:n}),e.jsx(k,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:N("h-8 w-[150px] lg:w-[250px]",t&&"border-primary/50 ring-primary/20")}),t&&e.jsxs(F,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]})})}const Jx=s=>{const{t:n}=M("group");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(q,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium",children:t.getValue("name")})})},{accessorKey:"users_count",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.usersCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"server_count",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.serverCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(Pl,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("server_count")})]}),enableSorting:!0,size:8e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Za,{defaultValues:t.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(rt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(_s,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{jt.drop({id:t.original.id}).then(({data:r})=>{r&&(z.success(n("messages.updateSuccess")),s())})},children:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{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 Qx(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),{data:x,refetch:m,isLoading:o}=re({queryKey:["serverGroupList"],queryFn:async()=>{const{data:f}=await jt.getList();return f}}),c=Be({data:x||[],columns:Jx(m),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ts,{table:c,toolbar:f=>e.jsx(Yx,{table:f,refetch:m}),isLoading:o})}function Xx(){const{t:s}=M("group");return e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(Qx,{})})]})]})}const Zx=Object.freeze(Object.defineProperty({__proto__:null,default:Xx},Symbol.toStringTag,{value:"Module"})),eh=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 _i({refetch:s,dialogTrigger:n,defaultValues:t={remarks:"",match:[],action:"block",action_value:""},type:r="create"}){const{t:a}=M("route"),i=we({resolver:Te(eh(a)),defaultValues:t,mode:"onChange"}),[l,d]=u.useState(!1);return e.jsxs(me,{open:l,onOpenChange:d,children:[e.jsx(ps,{asChild:!0,children:n||e.jsxs(F,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ue,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add")})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:a(r==="edit"?"form.edit":"form.create")}),e.jsx($e,{})]}),e.jsxs(De,{...i,children:[e.jsx(v,{control:i.control,name:"remarks",render:({field:x})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:a("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(k,{type:"text",placeholder:a("form.remarksPlaceholder"),...x})})}),e.jsx(P,{})]})}),e.jsx(v,{control:i.control,name:"match",render:({field:x})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(b,{children:a("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(Es,{className:"min-h-[120px]",placeholder:a("form.matchPlaceholder"),value:Array.isArray(x.value)?x.value.join(`
|
||
`):"",onChange:m=>{const o=m.target.value.split(`
|
||
`);x.onChange(o)}})})}),e.jsx(P,{})]})}),e.jsx(v,{control:i.control,name:"action",render:({field:x})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsxs(J,{onValueChange:x.onChange,defaultValue:x.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("form.actionPlaceholder")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"block",children:a("actions.block")}),e.jsx(A,{value:"dns",children:a("actions.dns")})]})]})})}),e.jsx(P,{})]})}),i.watch("action")==="dns"&&e.jsx(v,{control:i.control,name:"action_value",render:({field:x})=>e.jsxs(j,{children:[e.jsx(b,{children:a("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(y,{children:e.jsx(k,{type:"text",placeholder:a("form.dnsPlaceholder"),...x})})})]})}),e.jsxs(Ie,{children:[e.jsx(et,{asChild:!0,children:e.jsx(F,{variant:"outline",children:a("form.cancel")})}),e.jsx(F,{type:"submit",onClick:()=>{const x=i.getValues(),m={...x,match:Array.isArray(x.match)?x.match.filter(o=>o.trim()!==""):[]};qa.save(m).then(({data:o})=>{o&&(d(!1),s&&s(),z.success(a(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),i.reset())})},children:a("form.submit")})]})]})]})]})}function sh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=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(_i,{refetch:n}),e.jsx(k,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("remarks")?.getFilterValue()??"",onChange:a=>s.getColumn("remarks")?.setFilterValue(a.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),t&&e.jsxs(F,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]})})}function th({columns:s,data:n,refetch:t}){const[r,a]=u.useState({}),[i,l]=u.useState({}),[d,x]=u.useState([]),[m,o]=u.useState([]),c=Be({data:n,columns:s,state:{sorting:m,columnVisibility:i,rowSelection:r,columnFilters:d},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:x,onColumnVisibilityChange:l,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ts,{table:c,toolbar:f=>e.jsx(sh,{table:f,refetch:t})})}const ah=s=>{const{t:n}=M("route"),t={block:{icon:fd,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:jd,variant:"secondary",className:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-800"}};return[{accessorKey:"id",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.id")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(q,{variant:"outline",children:r.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.remarks")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:r.original.remarks})}),enableHiding:!1,enableSorting:!1},{accessorKey:"action_value",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.action_value.title")}),cell:({row:r})=>{const a=r.original.action,i=r.original.action_value,l=r.original.match?.length||0;return e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("span",{className:"text-sm font-medium",children:a==="dns"&&i?n("columns.action_value.dns",{value:i}):a==="block"?e.jsx("span",{className:"text-destructive",children:n("columns.action_value.block")}):n("columns.action_value.direct")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("columns.matchRules",{count:l})})]})},enableHiding:!1,enableSorting:!1,size:300},{accessorKey:"action",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.action")}),cell:({row:r})=>{const a=r.getValue("action"),i=t[a]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(q,{variant:t[a]?.variant||"default",className:N("flex items-center gap-1.5 px-3 py-1 capitalize",t[a]?.className),children:[i&&e.jsx(i,{className:"h-3.5 w-3.5"}),n(`actions.${a}`)]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:n("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(_i,{defaultValues:r.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(rt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(_s,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{qa.drop({id:r.original.id}).then(({data:a})=>{a&&(z.success(n("messages.deleteSuccess")),s())})},children:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{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 nh(){const{t:s}=M("route"),[n,t]=u.useState([]);function r(){qa.getList().then(({data:a})=>{t(a)})}return u.useEffect(()=>{r()},[]),e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(th,{data:n,columns:ah(r),refetch:r})})]})]})}const rh=Object.freeze(Object.defineProperty({__proto__:null,default:nh},Symbol.toStringTag,{value:"Module"})),Ni=u.createContext(void 0);function lh({children:s,refreshData:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(null);return e.jsx(Ni.Provider,{value:{isOpen:t,setIsOpen:r,editingPlan:a,setEditingPlan:i,refreshData:n},children:s})}function Kn(){const s=u.useContext(Ni);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function ih({table:s,saveOrder:n,isSortMode:t}){const{setIsOpen:r}=Kn(),{t:a}=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(F,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>r(!0),children:[e.jsx(Ue,{icon:"ion:add"}),e.jsx("div",{children:a("plan.add")})]}),e.jsx(k,{placeholder:a("plan.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:i=>s.getColumn("name")?.setFilterValue(i.target.value),className:"h-8 w-[150px] lg:w-[250px]"})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{variant:t?"default":"outline",onClick:n,size:"sm",children:a(t?"plan.sort.save":"plan.sort.edit")})})]})}const Nr={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"}},oh=s=>{const{t:n}=M("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(za,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(q,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.show")}),cell:({row:t})=>e.jsx(X,{defaultChecked:t.getValue("show"),onCheckedChange:r=>{ys.update({id:t.original.id,show:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.sell")}),cell:({row:t})=>e.jsx(X,{defaultChecked:t.getValue("sell"),onCheckedChange:r=>{ys.update({id:t.original.id,sell:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.renew"),tooltip:n("plan.columns.renew_tooltip")}),cell:({row:t})=>e.jsx(X,{defaultChecked:t.getValue("renew"),onCheckedChange:r=>{ys.update({id:t.original.id,renew:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:t.getValue("name")})}),enableSorting:!1,enableHiding:!1,size:900},{accessorKey:"users_count",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.stats")}),cell:({row:t})=>{const r=t.getValue("users_count")||0,a=t.original.active_users_count||0,i=r>0?Math.round(a/r*100):0;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 rounded-md bg-slate-50 px-2 py-1 hover:bg-slate-100 transition-colors cursor-help",children:[e.jsx(wa,{className:"h-3.5 w-3.5 text-slate-500"}),e.jsx("span",{className:"text-sm font-medium text-slate-700",children:r})]})}),e.jsx(de,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:"总用户数"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"所有使用该套餐的用户(包括已过期)"})]})})]})}),e.jsx(fe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 rounded-md bg-green-50 px-2 py-1 hover:bg-green-100 transition-colors cursor-help",children:[e.jsx(vd,{className:"h-3.5 w-3.5 text-green-600"}),e.jsx("span",{className:"text-sm font-medium text-green-700",children:a})]})}),e.jsx(de,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:"有效期内用户"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"当前仍在有效期内的活跃用户"}),r>0&&e.jsxs("p",{className:"text-xs font-medium text-green-600",children:["活跃率:",i,"%"]})]})})]})})]})},enableSorting:!0,size:120},{accessorKey:"group",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.group")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[600px] flex-wrap items-center gap-1.5 text-nowrap",children:e.jsx(q,{variant:"secondary",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:t.getValue("group")?.name})}),enableSorting:!1,enableHiding:!1},{accessorKey:"prices",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.price")}),cell:({row:t})=>{const r=t.getValue("prices"),a=[{period:n("plan.columns.price_period.monthly"),key:"monthly",unit:n("plan.columns.price_period.unit.month")},{period:n("plan.columns.price_period.quarterly"),key:"quarterly",unit:n("plan.columns.price_period.unit.quarter")},{period:n("plan.columns.price_period.half_yearly"),key:"half_yearly",unit:n("plan.columns.price_period.unit.half_year")},{period:n("plan.columns.price_period.yearly"),key:"yearly",unit:n("plan.columns.price_period.unit.year")},{period:n("plan.columns.price_period.two_yearly"),key:"two_yearly",unit:n("plan.columns.price_period.unit.two_year")},{period:n("plan.columns.price_period.three_yearly"),key:"three_yearly",unit:n("plan.columns.price_period.unit.three_year")},{period:n("plan.columns.price_period.onetime"),key:"onetime",unit:""},{period:n("plan.columns.price_period.reset_traffic"),key:"reset_traffic",unit:n("plan.columns.price_period.unit.times")}];return e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:a.map(({period:i,key:l,unit:d})=>r[l]!=null&&e.jsxs(q,{variant:"secondary",className:N("px-2 py-0.5 font-medium transition-colors text-nowrap",Nr[l].color,Nr[l].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[i," ¥",r[l],d]},l))})},enableSorting:!1,size:9e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("plan.columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingPlan:a}=Kn();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{a(t.original),r(!0)},children:[e.jsx(rt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.edit")})]}),e.jsx(_s,{title:n("plan.columns.delete_confirm.title"),description:n("plan.columns.delete_confirm.description"),confirmText:n("plan.columns.delete"),variant:"destructive",onConfirm:async()=>{ys.drop({id:t.original.id}).then(({data:i})=>{i&&(z.success(n("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{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")})]})})]})}}]},ch=h.object({id:h.number().nullable(),group_id:h.union([h.number(),h.string()]).nullable().optional(),name:h.string().min(1).max(250),tags:h.array(h.string()).nullable().optional(),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(),active_users_count:h.number().optional()}),Bn=u.forwardRef(({className:s,...n},t)=>e.jsx(Ll,{ref:t,className:N("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...n,children:e.jsx(bd,{className:N("flex items-center justify-center text-current"),children:e.jsx(pt,{className:"h-4 w-4"})})}));Bn.displayName=Ll.displayName;const fa={id:null,group_id:null,name:"",tags:[],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},ja={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}},dh=[{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 mh(){const{isOpen:s,setIsOpen:n,editingPlan:t,setEditingPlan:r,refreshData:a}=Kn(),[i,l]=u.useState(!1),{t:d}=M("subscribe"),x=we({resolver:Te(ch),defaultValues:{...fa,...t||{}},mode:"onChange"});u.useEffect(()=>{t?x.reset({...fa,...t}):x.reset(fa)},[t,x]);const m=new Vn({html:!0}),[o,c]=u.useState();async function f(){jt.getList().then(({data:w})=>{c(w)})}u.useEffect(()=>{s&&f()},[s]);const D=async w=>{l(!0),ys.save(w).then(({data:E})=>{E&&(z.success(d(t?"plan.form.submit.success.update":"plan.form.submit.success.add")),T(),a())}).finally(()=>{l(!1)})},S=w=>{const E=Object.values(w).map(_=>_?.message).filter(Boolean);z.error(E.join(`
|
||
`)||d("plan.form.submit.error.validation","表单校验失败"))},C=w=>{if(isNaN(w))return;const E=Object.entries(ja).reduce((_,[g,p])=>{const V=w*p.months*p.discount;return{..._,[g]:V.toFixed(2)}},{});x.setValue("prices",E,{shouldDirty:!0})},T=()=>{n(!1),r(null),x.reset(fa)};return e.jsx(me,{open:s,onOpenChange:T,children:e.jsxs(ce,{children:[e.jsxs(pe,{children:[e.jsx(ue,{children:d(t?"plan.form.edit_title":"plan.form.add_title")}),e.jsx($e,{})]}),e.jsx(De,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(D,S),children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{control:x.control,name:"name",render:({field:w})=>e.jsxs(j,{children:[e.jsx(b,{children:d("plan.form.name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:d("plan.form.name.placeholder"),...w})}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"tags",render:({field:w})=>e.jsxs(j,{children:[e.jsx(b,{children:d("plan.form.tags.label","标签")}),e.jsx(y,{children:e.jsx(Xa,{value:w.value||[],onChange:w.onChange,placeholder:d("plan.form.tags.placeholder","输入标签后按回车确认"),className:"w-full"})}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"group_id",render:({field:w})=>e.jsxs(j,{children:[e.jsxs(b,{className:"flex items-center justify-between",children:[d("plan.form.group.label"),e.jsx(Za,{dialogTrigger:e.jsx(F,{variant:"link",children:d("plan.form.group.add")}),refetch:f})]}),e.jsxs(J,{value:w.value?.toString()??"",onValueChange:E=>w.onChange(E?Number(E):null),children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:d("plan.form.group.placeholder")})})}),e.jsx(Y,{children:o?.map(E=>e.jsx(A,{value:E.id.toString(),children:E.name},E.id))})]}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"transfer_enable",render:({field:w})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:d("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.transfer.placeholder"),className:"rounded-r-none",...w})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.transfer.unit")})]}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"speed_limit",render:({field:w})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:d("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.speed.placeholder"),className:"rounded-r-none",...w,value:w.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.speed.unit")})]}),e.jsx(P,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:d("plan.form.price.title")}),e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(k,{type:"number",step:"0.01",placeholder:d("plan.form.price.base_price"),className:"h-7 w-32 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500",onChange:w=>{const E=parseFloat(w.target.value);C(E)}})]}),e.jsx(fe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(F,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const w=Object.keys(ja).reduce((E,_)=>({...E,[_]:""}),{});x.setValue("prices",w,{shouldDirty:!0})},children:d("plan.form.price.clear.button")})}),e.jsx(de,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:d("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(ja).filter(([w])=>!["onetime","reset_traffic"].includes(w)).map(([w,E])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(v,{control:x.control,name:`prices.${w}`,render:({field:_})=>e.jsxs(j,{children:[e.jsxs(b,{className:"text-xs font-medium text-muted-foreground",children:[d(`plan.columns.price_period.${w}`),e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",E.months===1?d("plan.form.price.period.monthly"):d("plan.form.price.period.months",{count:E.months}),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,step:"0.01",..._,value:_.value??"",onChange:g=>_.onChange(g.target.value),className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})},w))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(ja).filter(([w])=>["onetime","reset_traffic"].includes(w)).map(([w,E])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(v,{control:x.control,name:`prices.${w}`,render:({field:_})=>e.jsx(j,{children:e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-0",children:[e.jsx(b,{className:"text-xs font-medium",children:d(`plan.columns.price_period.${w}`)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:d(w==="onetime"?"plan.form.price.onetime_desc":"plan.form.price.reset_desc")})]}),e.jsxs("div",{className:"relative w-full md:w-32",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,step:"0.01",..._,value:_.value??"",className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})})},w))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(v,{control:x.control,name:"device_limit",render:({field:w})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:d("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.device.placeholder"),className:"rounded-r-none",...w,value:w.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.device.unit")})]}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"capacity_limit",render:({field:w})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(b,{children:d("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(y,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.capacity.placeholder"),className:"rounded-r-none",...w,value:w.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:d("plan.form.capacity.unit")})]}),e.jsx(P,{})]})})]}),e.jsx(v,{control:x.control,name:"reset_traffic_method",render:({field:w})=>e.jsxs(j,{children:[e.jsx(b,{children:d("plan.form.reset_method.label")}),e.jsxs(J,{value:w.value?.toString()??"null",onValueChange:E=>w.onChange(E=="null"?null:Number(E)),children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:d("plan.form.reset_method.placeholder")})})}),e.jsx(Y,{children:dh.map(E=>e.jsx(A,{value:E.value?.toString()??"null",children:d(`plan.form.reset_method.options.${E.label}`)},E.value))})]}),e.jsx($,{className:"text-xs",children:d("plan.form.reset_method.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"content",render:({field:w})=>{const[E,_]=u.useState(!1);return e.jsxs(j,{className:"space-y-2",children:[e.jsxs(b,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d("plan.form.content.label"),e.jsx(fe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(F,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",type:"button",onClick:()=>_(!E),children:E?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(de,{side:"top",children:e.jsx("p",{className:"text-xs",children:d(E?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(fe,{children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(F,{variant:"outline",size:"sm",type:"button",onClick:()=>{w.onChange(d("plan.form.content.template.content"))},children:d("plan.form.content.template.button")})}),e.jsx(de,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:d("plan.form.content.template.tooltip")})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${E?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(y,{children:e.jsx(In,{style:{height:"400px"},value:w.value||"",renderHTML:g=>m.render(g),onChange:({text:g})=>w.onChange(g),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:d("plan.form.content.placeholder"),className:"rounded-md border"})})}),E&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:d("plan.form.content.preview")}),e.jsx("div",{className:"prose prose-sm dark:prose-invert h-[400px] max-w-none overflow-y-auto rounded-md border p-4",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:m.render(w.value||"")}})})]})]}),e.jsx($,{className:"text-xs",children:d("plan.form.content.description")}),e.jsx(P,{})]})}})]}),e.jsx(Ie,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:t&&e.jsx(v,{control:x.control,name:"force_update",render:({field:w})=>e.jsxs(j,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(y,{children:e.jsx(Bn,{checked:w.value,onCheckedChange:w.onChange})}),e.jsx("div",{className:"",children:e.jsx(b,{className:"text-sm",children:d("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(F,{type:"button",variant:"outline",onClick:T,children:d("plan.form.submit.cancel")}),e.jsx(F,{type:"submit",disabled:i,children:d(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})})]})})}function uh(){const[s,n]=u.useState({}),[t,r]=u.useState({"drag-handle":!1}),[a,i]=u.useState([]),[l,d]=u.useState([]),[x,m]=u.useState(!1),[o,c]=u.useState({pageSize:20,pageIndex:0}),[f,D]=u.useState([]),{refetch:S}=re({queryKey:["planList"],queryFn:async()=>{const{data:_}=await ys.getList();return D(_),_}});u.useEffect(()=>{r({"drag-handle":x}),c({pageSize:x?99999:10,pageIndex:0})},[x]);const C=(_,g)=>{x&&(_.dataTransfer.setData("text/plain",g.toString()),_.currentTarget.classList.add("opacity-50"))},T=(_,g)=>{if(!x)return;_.preventDefault(),_.currentTarget.classList.remove("bg-muted");const p=parseInt(_.dataTransfer.getData("text/plain"));if(p===g)return;const V=[...f],[R]=V.splice(p,1);V.splice(g,0,R),D(V)},w=async()=>{if(!x){m(!0);return}const _=f?.map(g=>g.id);ys.sort(_).then(()=>{z.success("排序保存成功"),m(!1),S()}).finally(()=>{m(!1)})},E=Be({data:f||[],columns:oh(S),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:o},enableRowSelection:!0,onPaginationChange:c,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnPinning:{right:["actions"]}},pageCount:x?1:void 0});return e.jsx(lh,{refreshData:S,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(ts,{table:E,toolbar:_=>e.jsx(ih,{table:_,refetch:S,saveOrder:w,isSortMode:x}),draggable:x,onDragStart:C,onDragEnd:_=>_.currentTarget.classList.remove("opacity-50"),onDragOver:_=>{_.preventDefault(),_.currentTarget.classList.add("bg-muted")},onDragLeave:_=>_.currentTarget.classList.remove("bg-muted"),onDrop:T,showPagination:!x}),e.jsx(mh,{})]})})}function xh(){const{t:s}=M("subscribe");return e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(uh,{})})]})]})}const hh=Object.freeze(Object.defineProperty({__proto__:null,default:xh},Symbol.toStringTag,{value:"Module"})),Tt=[{value:ie.PENDING,label:At[ie.PENDING],icon:yd,color:qt[ie.PENDING]},{value:ie.PROCESSING,label:At[ie.PROCESSING],icon:Rl,color:qt[ie.PROCESSING]},{value:ie.COMPLETED,label:At[ie.COMPLETED],icon:Nn,color:qt[ie.COMPLETED]},{value:ie.CANCELLED,label:At[ie.CANCELLED],icon:El,color:qt[ie.CANCELLED]},{value:ie.DISCOUNTED,label:At[ie.DISCOUNTED],icon:Nn,color:qt[ie.DISCOUNTED]}],Bt=[{value:Ce.PENDING,label:xa[Ce.PENDING],icon:_d,color:ha[Ce.PENDING]},{value:Ce.PROCESSING,label:xa[Ce.PROCESSING],icon:Rl,color:ha[Ce.PROCESSING]},{value:Ce.VALID,label:xa[Ce.VALID],icon:Nn,color:ha[Ce.VALID]},{value:Ce.INVALID,label:xa[Ce.INVALID],icon:El,color:ha[Ce.INVALID]}];function va({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=s?.getFilterValue(),i=Array.isArray(a)?new Set(a):a!==void 0?new Set([a]):new Set;return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx($a,{className:"mr-2 h-4 w-4"}),n,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ee,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:i.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:i.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):t.filter(l=>i.has(l.value)).map(l=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(it,{children:[e.jsx(vt,{placeholder:n}),e.jsxs(ot,{children:[e.jsx(bt,{children:"No results found."}),e.jsx(ks,{children:t.map(l=>{const d=i.has(l.value);return e.jsxs(rs,{onSelect:()=>{const x=new Set(i);d?x.delete(l.value):x.add(l.value);const m=Array.from(x);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",d?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(pt,{className:N("h-4 w-4")})}),l.icon&&e.jsx(l.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${l.color}`}),e.jsx("span",{children:l.label}),r?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(l.value)})]},l.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Mt,{}),e.jsx(ks,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const gh=h.object({email:h.string().min(1),plan_id:h.number(),period:h.string(),total_amount:h.number()}),ph={email:"",plan_id:0,total_amount:0,period:""};function wi({refetch:s,trigger:n,defaultValues:t}){const{t:r}=M("order"),[a,i]=u.useState(!1),l=we({resolver:Te(gh),defaultValues:{...ph,...t},mode:"onChange"}),[d,x]=u.useState([]);return u.useEffect(()=>{a&&ys.getList().then(({data:m})=>{x(m)})},[a]),e.jsxs(me,{open:a,onOpenChange:i,children:[e.jsx(ps,{asChild:!0,children:n||e.jsxs(F,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ue,{icon:"ion:add"}),e.jsx("div",{children:r("dialog.addOrder")})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:r("dialog.assignOrder")}),e.jsx($e,{})]}),e.jsxs(De,{...l,children:[e.jsx(v,{control:l.control,name:"email",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dialog.fields.userEmail")}),e.jsx(y,{children:e.jsx(k,{placeholder:r("dialog.placeholders.email"),...m})})]})}),e.jsx(v,{control:l.control,name:"plan_id",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dialog.fields.subscriptionPlan")}),e.jsx(y,{children:e.jsxs(J,{value:m.value?m.value?.toString():void 0,onValueChange:o=>m.onChange(parseInt(o)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dialog.placeholders.plan")})}),e.jsx(Y,{children:d.map(o=>e.jsx(A,{value:o.id.toString(),children:o.name},o.id))})]})})]})}),e.jsx(v,{control:l.control,name:"period",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dialog.fields.orderPeriod")}),e.jsx(y,{children:e.jsxs(J,{value:m.value,onValueChange:m.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dialog.placeholders.period")})}),e.jsx(Y,{children:Object.keys($m).map(o=>e.jsx(A,{value:o,children:r(`period.${o}`)},o))})]})})]})}),e.jsx(v,{control:l.control,name:"total_amount",render:({field:m})=>e.jsxs(j,{children:[e.jsx(b,{children:r("dialog.fields.paymentAmount")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:r("dialog.placeholders.amount"),value:m.value/100,onChange:o=>m.onChange(parseFloat(o.currentTarget.value)*100)})}),e.jsx(P,{})]})}),e.jsxs(Ie,{children:[e.jsx(F,{variant:"outline",onClick:()=>i(!1),children:r("dialog.actions.cancel")}),e.jsx(F,{type:"submit",onClick:()=>{l.handleSubmit(m=>{mt.assign(m).then(({data:o})=>{o&&(s&&s(),l.reset(),i(!1),z.success(r("dialog.messages.addSuccess")))})})()},children:r("dialog.actions.confirm")})]})]})]})]})}function fh({table:s,refetch:n}){const{t}=M("order"),r=s.getState().columnFilters.length>0,a=Object.values(Ms).filter(x=>typeof x=="number").map(x=>({label:t(`type.${Ms[x]}`),value:x,color:x===Ms.NEW?"green-500":x===Ms.RENEWAL?"blue-500":x===Ms.UPGRADE?"purple-500":"orange-500"})),i=Object.values(Qe).map(x=>({label:t(`period.${x}`),value:x,color:x===Qe.MONTH_PRICE?"slate-500":x===Qe.QUARTER_PRICE?"cyan-500":x===Qe.HALF_YEAR_PRICE?"indigo-500":x===Qe.YEAR_PRICE?"violet-500":x===Qe.TWO_YEAR_PRICE?"fuchsia-500":x===Qe.THREE_YEAR_PRICE?"pink-500":x===Qe.ONETIME_PRICE?"rose-500":"orange-500"})),l=Object.values(ie).filter(x=>typeof x=="number").map(x=>({label:t(`status.${ie[x]}`),value:x,icon:x===ie.PENDING?Tt[0].icon:x===ie.PROCESSING?Tt[1].icon:x===ie.COMPLETED?Tt[2].icon:x===ie.CANCELLED?Tt[3].icon:Tt[4].icon,color:x===ie.PENDING?"yellow-500":x===ie.PROCESSING?"blue-500":x===ie.COMPLETED?"green-500":x===ie.CANCELLED?"red-500":"green-500"})),d=Object.values(Ce).filter(x=>typeof x=="number").map(x=>({label:t(`commission.${Ce[x]}`),value:x,icon:x===Ce.PENDING?Bt[0].icon:x===Ce.PROCESSING?Bt[1].icon:x===Ce.VALID?Bt[2].icon:Bt[3].icon,color:x===Ce.PENDING?"yellow-500":x===Ce.PROCESSING?"blue-500":x===Ce.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(wi,{refetch:n}),e.jsx(k,{placeholder:t("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(va,{column:s.getColumn("type"),title:t("table.columns.type"),options:a}),s.getColumn("period")&&e.jsx(va,{column:s.getColumn("period"),title:t("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(va,{column:s.getColumn("status"),title:t("table.columns.status"),options:l}),s.getColumn("commission_status")&&e.jsx(va,{column:s.getColumn("commission_status"),title:t("table.columns.commissionStatus"),options:d})]}),r&&e.jsxs(F,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("actions.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]})}function ns({label:s,value:n,className:t,valueClassName:r}){return e.jsxs("div",{className:N("flex items-center py-1.5",t),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:N("text-sm",r),children:n||"-"})]})}function jh({status:s}){const{t:n}=M("order"),t={[ie.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[ie.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[ie.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[ie.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[ie.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(q,{variant:"secondary",className:N("font-medium",t[s]),children:n(`status.${ie[s]}`)})}function vh({id:s,trigger:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(),{t:l}=M("order");return u.useEffect(()=>{(async()=>{if(t){const{data:x}=await mt.getInfo({id:s});i(x)}})()},[t,s]),e.jsxs(me,{onOpenChange:r,open:t,children:[e.jsx(ps,{asChild:!0,children:n}),e.jsxs(ce,{className:"max-w-xl",children:[e.jsxs(pe,{className:"space-y-2",children:[e.jsx(ue,{className:"text-lg font-medium",children:l("dialog.title")}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:[l("table.columns.tradeNo"),":",a?.trade_no]}),!!a?.status&&e.jsx(jh,{status:a.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.userEmail"),value:a?.user?.email?e.jsxs(tt,{to:`/user/manage?email=${a.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[a.user.email,e.jsx(wn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(ns,{label:l("dialog.fields.orderPeriod"),value:a&&l(`period.${a.period}`)}),e.jsx(ns,{label:l("dialog.fields.subscriptionPlan"),value:a?.plan?.name,valueClassName:"font-medium"}),e.jsx(ns,{label:l("dialog.fields.callbackNo"),value:a?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.paymentAmount"),value:Ks(a?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(Ee,{className:"my-2"}),e.jsx(ns,{label:l("dialog.fields.balancePayment"),value:Ks(a?.balance_amount||0)}),e.jsx(ns,{label:l("dialog.fields.discountAmount"),value:Ks(a?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(ns,{label:l("dialog.fields.refundAmount"),value:Ks(a?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(ns,{label:l("dialog.fields.deductionAmount"),value:Ks(a?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.createdAt"),value:oe(a?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(ns,{label:l("dialog.fields.updatedAt"),value:oe(a?.updated_at),valueClassName:"font-mono text-xs"})]})]}),(a?.commission_status===1||a?.commission_status===2)&&a?.commission_balance&&e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.commissionInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.commissionStatus"),value:e.jsx(q,{variant:"secondary",className:"bg-orange-100 font-medium text-orange-800 hover:bg-orange-100",children:l("dialog.commissionStatusActive")})}),e.jsx(ns,{label:l("dialog.fields.commissionAmount"),value:Ks(a?.commission_balance||0),valueClassName:"font-medium text-orange-600"}),a?.actual_commission_balance&&e.jsx(ns,{label:l("dialog.fields.actualCommissionAmount"),value:Ks(a?.actual_commission_balance||0),valueClassName:"font-medium text-orange-700"}),a?.invite_user&&e.jsxs(e.Fragment,{children:[e.jsx(Ee,{className:"my-2"}),e.jsx(ns,{label:l("dialog.fields.inviteUser"),value:e.jsxs(tt,{to:`/user/manage?email=${a.invite_user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[a.invite_user.email,e.jsx(wn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]})}),e.jsx(ns,{label:l("dialog.fields.inviteUserId"),value:a?.invite_user?.id,valueClassName:"font-mono text-xs"})]})]})]})]})]})]})}const bh={[Ms.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ms.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ms.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ms.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},yh={[Qe.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},_h=s=>ie[s],Nh=s=>Ce[s],wh=s=>Ms[s],Ch=s=>{const{t:n}=M("order");return[{accessorKey:"trade_no",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.tradeNo")}),cell:({row:t})=>{const r=t.original.trade_no,a=r.length>6?`${r.slice(0,3)}...${r.slice(-3)}`:r;return e.jsx("div",{className:"flex items-center",children:e.jsx(vh,{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:a}),e.jsx(wn,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.type")}),cell:({row:t})=>{const r=t.getValue("type"),a=bh[r];return e.jsx(q,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",a.color,a.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:n(`type.${wh(r)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.plan")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium text-foreground/90 sm:max-w-72 md:max-w-[31rem]",children:t.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.period")}),cell:({row:t})=>{const r=t.getValue("period"),a=yh[r];return e.jsx(q,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",a?.color,a?.bgColor,"hover:bg-opacity-80"),children:n(`period.${r}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.amount")}),cell:({row:t})=>{const r=t.getValue("total_amount"),a=typeof r=="number"?(r/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",a]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:t})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(O,{column:t,title:n("table.columns.status")}),e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{children:e.jsx(pi,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(de,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:t})=>{const r=Tt.find(a=>a.value===t.getValue("status"));return r?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r.icon&&e.jsx(r.icon,{className:`h-4 w-4 text-${r.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`status.${_h(r.value)}`)})]}),r.value===ie.PENDING&&e.jsxs(Hs,{modal:!0,children:[e.jsx(Bs,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(zs,{align:"end",className:"w-[140px]",children:[e.jsx(Se,{className:"cursor-pointer",onClick:async()=>{await mt.markPaid({trade_no:t.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(Se,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await mt.makeCancel({trade_no:t.original.trade_no}),s()},children:n("actions.cancel")})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.commission")}),cell:({row:t})=>{const r=t.getValue("commission_balance"),a=r?(r/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:r?`¥${a}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.commissionStatus")}),cell:({row:t})=>{const r=t.original.status,a=t.original.commission_balance,i=Bt.find(l=>l.value===t.getValue("commission_status"));return a==0||!i?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i.icon&&e.jsx(i.icon,{className:`h-4 w-4 text-${i.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`commission.${Nh(i.value)}`)})]}),i.value===Ce.PENDING&&r===ie.COMPLETED&&e.jsxs(Hs,{modal:!0,children:[e.jsx(Bs,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(zs,{align:"end",className:"w-[120px]",children:[e.jsx(Se,{className:"cursor-pointer",onClick:async()=>{await mt.update({trade_no:t.original.trade_no,commission_status:Ce.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(Se,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await mt.update({trade_no:t.original.trade_no,commission_status:Ce.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.createdAt")}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:oe(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function Sh(){const[s]=Vl(),[n,t]=u.useState({}),[r,a]=u.useState({}),[i,l]=u.useState([]),[d,x]=u.useState([]),[m,o]=u.useState({pageIndex:0,pageSize:20});u.useEffect(()=>{const T=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([w,E])=>{const _=s.get(w);return _?{id:w,value:E==="number"?parseInt(_):_}:null}).filter(Boolean);T.length>0&&l(T)},[s]);const{refetch:c,data:f,isLoading:D}=re({queryKey:["orderList",m,i,d],queryFn:()=>mt.getList({pageSize:m.pageSize,current:m.pageIndex+1,filter:i,sort:d})}),S=Be({data:f?.data??[],columns:Ch(c),state:{sorting:d,columnVisibility:r,rowSelection:n,columnFilters:i,pagination:m},rowCount:f?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:l,onColumnVisibilityChange:a,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),onPaginationChange:o,getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ts,{table:S,toolbar:e.jsx(fh,{table:S,refetch:c}),showPagination:!0})}function kh(){const{t:s}=M("order");return e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(Sh,{})})]})]})}const Th=Object.freeze(Object.defineProperty({__proto__:null,default:kh},Symbol.toStringTag,{value:"Module"}));function Dh({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx($a,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ee,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:a.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:a.size>2?e.jsxs(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(it,{children:[e.jsx(vt,{placeholder:n}),e.jsxs(ot,{children:[e.jsx(bt,{children:"No results found."}),e.jsx(ks,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(rs,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(pt,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Mt,{}),e.jsx(ks,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Fh=s=>h.object({id:h.coerce.number().nullable().optional(),name:h.string().min(1,s("form.name.required")),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(Xt)).default([]).nullable()}).refine(n=>n.ended_at>n.started_at,{message:s("form.validity.endTimeError"),path:["ended_at"]}),wr={name:"",code:null,type:ws.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},Ph=s=>[{label:s("form.timeRange.presets.1week"),days:7},{label:s("form.timeRange.presets.2weeks"),days:14},{label:s("form.timeRange.presets.1month"),days:30},{label:s("form.timeRange.presets.3months"),days:90},{label:s("form.timeRange.presets.6months"),days:180},{label:s("form.timeRange.presets.1year"),days:365}];function Ci({defaultValues:s,refetch:n,type:t="create",dialogTrigger:r=null,open:a,onOpenChange:i}){const{t:l}=M("coupon"),[d,x]=u.useState(!1),m=a??d,o=i??x,[c,f]=u.useState([]),D=Fh(l),S=Ph(l),C=we({resolver:Te(D),defaultValues:s||wr});u.useEffect(()=>{s&&C.reset(s)},[s,C]),u.useEffect(()=>{ys.getList().then(({data:g})=>f(g))},[]);const T=g=>{if(!g)return;const p=(V,R)=>{const L=new Date(R*1e3);return V.setHours(L.getHours(),L.getMinutes(),L.getSeconds()),Math.floor(V.getTime()/1e3)};g.from&&C.setValue("started_at",p(g.from,C.watch("started_at"))),g.to&&C.setValue("ended_at",p(g.to,C.watch("ended_at")))},w=g=>{const p=new Date,V=Math.floor(p.getTime()/1e3),R=Math.floor((p.getTime()+g*24*60*60*1e3)/1e3);C.setValue("started_at",V),C.setValue("ended_at",R)},E=async g=>{const p=await Pa.save(g);if(g.generate_count&&typeof p=="string"){const V=new Blob([p],{type:"text/csv;charset=utf-8;"}),R=document.createElement("a");R.href=window.URL.createObjectURL(V),R.download=`coupons_${new Date().getTime()}.csv`,R.click(),window.URL.revokeObjectURL(R.href)}o(!1),t==="create"&&C.reset(wr),n()},_=(g,p)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:p}),e.jsx(k,{type:"datetime-local",step:"1",value:oe(C.watch(g),"YYYY-MM-DDTHH:mm:ss"),onChange:V=>{const R=new Date(V.target.value);C.setValue(g,Math.floor(R.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(me,{open:m,onOpenChange:o,children:[r&&e.jsx(ps,{asChild:!0,children:r}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsx(pe,{children:e.jsx(ue,{children:l(t==="create"?"form.add":"form.edit")})}),e.jsx(De,{...C,children:e.jsxs("form",{onSubmit:C.handleSubmit(E),className:"space-y-4",children:[e.jsx(v,{control:C.control,name:"name",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:l("form.name.label")}),e.jsx(k,{placeholder:l("form.name.placeholder"),...g}),e.jsx(P,{})]})}),t==="create"&&e.jsx(v,{control:C.control,name:"generate_count",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:l("form.generateCount.label")}),e.jsx(k,{type:"number",min:0,placeholder:l("form.generateCount.placeholder"),...g,value:g.value??"",onChange:p=>g.onChange(p.target.value===""?null:parseInt(p.target.value)),className:"h-9"}),e.jsx($,{className:"text-xs",children:l("form.generateCount.description")}),e.jsx(P,{})]})}),(!C.watch("generate_count")||C.watch("generate_count")==null)&&e.jsx(v,{control:C.control,name:"code",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:l("form.code.label")}),e.jsx(k,{placeholder:l("form.code.placeholder"),...g,value:g.value??"",className:"h-9"}),e.jsx($,{className:"text-xs",children:l("form.code.description")}),e.jsx(P,{})]})}),e.jsxs(j,{children:[e.jsx(b,{children:l("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(v,{control:C.control,name:"type",render:({field:g})=>e.jsxs(J,{value:g.value.toString(),onValueChange:p=>{const V=g.value,R=parseInt(p);g.onChange(R);const L=C.getValues("value");L&&(V===ws.AMOUNT&&R===ws.PERCENTAGE?C.setValue("value",L/100):V===ws.PERCENTAGE&&R===ws.AMOUNT&&C.setValue("value",L*100))},children:[e.jsx(W,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Q,{placeholder:l("form.type.placeholder")})}),e.jsx(Y,{children:Object.entries(Am).map(([p,V])=>e.jsx(A,{value:p,children:l(`table.toolbar.types.${p}`)},p))})]})}),e.jsx(v,{control:C.control,name:"value",render:({field:g})=>{const p=g.value==null?"":C.watch("type")===ws.AMOUNT&&typeof g.value=="number"?(g.value/100).toString():g.value.toString();return e.jsx(k,{type:"number",placeholder:l("form.value.placeholder"),...g,value:p,onChange:V=>{const R=V.target.value;if(R===""){g.onChange("");return}const L=parseFloat(R);isNaN(L)||g.onChange(C.watch("type")===ws.AMOUNT?Math.round(L*100):L)},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:C.watch("type")==ws.AMOUNT?"¥":"%"})})]})]}),e.jsxs(j,{children:[e.jsx(b,{children:l("form.validity.label")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(F,{variant:"outline",className:N("w-full justify-start text-left font-normal",!C.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"truncate",children:[oe(C.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",l("form.validity.to")," ",oe(C.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})]})}),e.jsxs(Xe,{className:"w-auto p-0",align:"start",children:[e.jsxs("div",{className:"border-b border-border p-3",children:[e.jsx("div",{className:"mb-2 text-sm font-medium text-muted-foreground",children:l("form.timeRange.quickSet")}),e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-6",children:S.map(g=>e.jsx(F,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>w(g.days),type:"button",children:g.label},g.days))})]}),e.jsx("div",{className:"hidden border-b border-border sm:block",children:e.jsx(Ss,{mode:"range",selected:{from:new Date(C.watch("started_at")*1e3),to:new Date(C.watch("ended_at")*1e3)},onSelect:T,numberOfMonths:2})}),e.jsx("div",{className:"border-b border-border sm:hidden",children:e.jsx(Ss,{mode:"range",selected:{from:new Date(C.watch("started_at")*1e3),to:new Date(C.watch("ended_at")*1e3)},onSelect:T,numberOfMonths:1})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center",children:[_("started_at",l("table.validity.startTime")),e.jsx("div",{className:"text-center text-sm text-muted-foreground sm:mt-6",children:l("form.validity.to")}),_("ended_at",l("table.validity.endTime"))]})})]})]}),e.jsx(P,{})]}),e.jsx(v,{control:C.control,name:"limit_use",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:l("form.limitUse.label")}),e.jsx(k,{type:"number",min:0,placeholder:l("form.limitUse.placeholder"),...g,value:g.value??"",onChange:p=>g.onChange(p.target.value===""?null:parseInt(p.target.value)),className:"h-9"}),e.jsx($,{className:"text-xs",children:l("form.limitUse.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:C.control,name:"limit_use_with_user",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:l("form.limitUseWithUser.label")}),e.jsx(k,{type:"number",min:0,placeholder:l("form.limitUseWithUser.placeholder"),...g,value:g.value??"",onChange:p=>g.onChange(p.target.value===""?null:parseInt(p.target.value)),className:"h-9"}),e.jsx($,{className:"text-xs",children:l("form.limitUseWithUser.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:C.control,name:"limit_period",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:l("form.limitPeriod.label")}),e.jsx(nt,{options:Object.entries(Xt).filter(([p])=>isNaN(Number(p))).map(([p,V])=>({label:l(`coupon:period.${V}`),value:p})),onChange:p=>{if(p.length===0){g.onChange([]);return}const V=p.map(R=>Xt[R.value]);g.onChange(V)},value:(g.value||[]).map(p=>({label:l(`coupon:period.${p}`),value:Object.entries(Xt).find(([V,R])=>R===p)?.[0]||""})),placeholder:l("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPeriod.empty")})}),e.jsx($,{className:"text-xs",children:l("form.limitPeriod.description")}),e.jsx(P,{})]})}),e.jsx(v,{control:C.control,name:"limit_plan_ids",render:({field:g})=>e.jsxs(j,{children:[e.jsx(b,{children:l("form.limitPlan.label")}),e.jsx(nt,{options:c?.map(p=>({label:p.name,value:p.id.toString()}))||[],onChange:p=>g.onChange(p.map(V=>Number(V.value))),value:(c||[]).filter(p=>(g.value||[]).includes(p.id)).map(p=>({label:p.name,value:p.id.toString()})),placeholder:l("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPlan.empty")})}),e.jsx(P,{})]})}),e.jsx(Ie,{children:e.jsx(F,{type:"submit",disabled:C.formState.isSubmitting,children:C.formState.isSubmitting?l("form.submit.saving"):l("form.submit.save")})})]})})]})]})}function Lh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=M("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ci,{refetch:n,dialogTrigger:e.jsxs(F,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ue,{icon:"ion:add"}),e.jsx("div",{children:r("form.add")})]})}),e.jsx(k,{placeholder:r("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(Dh,{column:s.getColumn("type"),title:r("table.toolbar.type"),options:[{value:ws.AMOUNT,label:r(`table.toolbar.types.${ws.AMOUNT}`)},{value:ws.PERCENTAGE,label:r(`table.toolbar.types.${ws.PERCENTAGE}`)}]}),t&&e.jsxs(F,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]})}const Si=u.createContext(void 0);function Rh({children:s,refetch:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(null),l=x=>{i(x),r(!0)},d=()=>{r(!1),i(null)};return e.jsxs(Si.Provider,{value:{isOpen:t,currentCoupon:a,openEdit:l,closeEdit:d},children:[s,a&&e.jsx(Ci,{defaultValues:a,refetch:n,type:"edit",open:t,onOpenChange:r})]})}function Eh(){const s=u.useContext(Si);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const Vh=s=>{const{t:n}=M("coupon");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(q,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx(X,{defaultChecked:t.original.show,onCheckedChange:r=>{Pa.update({id:t.original.id,show:r}).then(({data:a})=>!a&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.type")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:n(`table.toolbar.types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.code")}),cell:({row:t})=>e.jsx(q,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.limitUse")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:t.original.limit_use===null?n("table.validity.unlimited"):t.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.limitUseWithUser")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:t.original.limit_use_with_user===null?n("table.validity.noLimit"):t.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.validity")}),cell:({row:t})=>{const[r,a]=u.useState(!1),i=Date.now(),l=t.original.started_at*1e3,d=t.original.ended_at*1e3,x=i>d,m=i<l,o=Math.ceil((d-i)/(1e3*60*60*24)),f=x?{label:n("table.validity.expired",{days:Math.abs(o)}),color:"bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"}:m?{label:n("table.validity.notStarted",{days:Math.abs(Math.ceil((l-i)/(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:o}),color:"bg-green-50 text-green-600 dark:bg-green-500/10 dark:text-green-400"};return e.jsxs(Zl,{open:r,onOpenChange:a,children:[e.jsx(ei,{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",f.color),children:f.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:oe(t.original.started_at,"MM/DD HH:mm")}),e.jsx("div",{className:"shrink-0 opacity-30",children:"→"}),e.jsx("div",{className:"truncate text-xs",children:oe(t.original.ended_at,"MM/DD HH:mm")})]})]}),e.jsx(pl,{className:N("h-3.5 w-3.5 shrink-0 text-muted-foreground/50 transition-transform duration-200",r&&"rotate-180")})]})}),e.jsx(si,{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:oe(t.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:oe(t.original.ended_at,"YYYY/MM/DD HH:mm")})]})]})})})]})},enableSorting:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>{const{openEdit:r}=Eh();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>r(t.original),children:[e.jsx(rt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),e.jsx(_s,{title:n("table.actions.deleteConfirm.title"),description:n("table.actions.deleteConfirm.description"),confirmText:n("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{Pa.drop({id:t.original.id}).then(({data:a})=>{a&&(z.success("删除成功"),s())})},children:e.jsxs(F,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{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 Ih(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),[x,m]=u.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=re({queryKey:["couponList",x,a,l],queryFn:()=>Pa.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:a,sort:l})}),f=Be({data:c?.data??[],columns:Vh(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:x},pageCount:Math.ceil((c?.total??0)/x.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:m,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Rh,{refetch:o,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:f,toolbar:e.jsx(Lh,{table:f,refetch:o})})})})}function Mh(){const{t:s}=M("coupon");return e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(Ih,{})})]})]})}const Oh=Object.freeze(Object.defineProperty({__proto__:null,default:Mh},Symbol.toStringTag,{value:"Module"})),zh=h.object({name:h.string().min(1,"请输入模板名称"),description:h.string().optional(),type:h.number().min(1).max(4),status:h.boolean(),sort:h.number().min(0),icon:h.string().optional(),background_image:h.string().optional(),conditions:h.object({allowed_plans:h.array(h.number()).optional(),disallowed_plans:h.array(h.number()).optional(),new_user_only:h.boolean().optional(),new_user_max_days:h.number().optional(),paid_user_only:h.boolean().optional(),require_invite:h.boolean().optional()}).optional(),limits:h.object({max_use_per_user:h.number().optional(),cooldown_hours:h.number().optional(),invite_reward_rate:h.number().optional()}).optional(),rewards:h.object({balance:h.number().optional(),transfer_enable:h.number().optional(),expire_days:h.number().optional(),device_limit:h.number().optional(),reset_package:h.boolean().optional(),plan_id:h.number().optional(),plan_validity_days:h.number().optional(),random_rewards:h.array(h.object({weight:h.number(),balance:h.number().optional(),transfer_enable:h.number().optional(),expire_days:h.number().optional(),device_limit:h.number().optional()})).optional()}),special_config:h.object({start_time:h.number().optional(),end_time:h.number().optional(),festival_bonus:h.number().optional()}).optional()});function ki({template:s,refetch:n,open:t,onOpenChange:r}){const{t:a}=M("giftCard"),[i,l]=u.useState(!1),[d,x]=u.useState([]),[m,o]=u.useState([]),c=we({resolver:Te(zh),defaultValues:{name:"",description:"",type:1,status:!0,sort:0,icon:"",background_image:"",conditions:{},limits:{},rewards:{},special_config:{}}}),{fields:f,append:D,remove:S}=Nd({control:c.control,name:"rewards.random_rewards"});u.useEffect(()=>{t&&(async()=>{try{const p=(await ys.getList()).data||[];x(p),o(p.map(V=>({label:V.name,value:V.id.toString()})))}catch(g){console.error("Failed to fetch plans:",g),z.error("Failed to load plan list")}})()},[t]),u.useEffect(()=>{if(s){const _=s.rewards||{};c.reset({name:s.name,description:s.description||"",type:s.type,status:s.status,sort:s.sort,icon:s.icon||"",background_image:s.background_image||"",conditions:s.conditions&&!Array.isArray(s.conditions)?s.conditions:{},limits:s.limits&&!Array.isArray(s.limits)?{...s.limits,invite_reward_rate:s.limits.invite_reward_rate||void 0}:{},rewards:{balance:_.balance?_.balance/100:void 0,transfer_enable:typeof _.transfer_enable=="number"?_.transfer_enable/1024/1024/1024:void 0,expire_days:_.expire_days,device_limit:_.device_limit,reset_package:_.reset_package,plan_id:_.plan_id,plan_validity_days:_.plan_validity_days,random_rewards:_.random_rewards?.map(g=>({weight:g.weight,balance:g.balance?g.balance/100:void 0,transfer_enable:typeof g.transfer_enable=="number"?g.transfer_enable/1024/1024/1024:void 0,expire_days:g.expire_days,device_limit:g.device_limit}))||[]},special_config:s.special_config&&!Array.isArray(s.special_config)?s.special_config:{}})}else c.reset({name:"",description:"",type:1,status:!0,sort:0,icon:"",background_image:"",conditions:{},limits:{},rewards:{random_rewards:[]},special_config:{}})},[s,c]);const C=_=>{console.error("Form validation failed:",_),z.error(a("messages.formInvalid"))},T=async _=>{l(!0);const g=JSON.parse(JSON.stringify(_));g.rewards&&(typeof g.rewards.balance=="number"&&(g.rewards.balance=Math.round(g.rewards.balance*100)),typeof g.rewards.transfer_enable=="number"&&(g.rewards.transfer_enable=Math.round(g.rewards.transfer_enable*1024*1024*1024)),g.rewards.random_rewards&&g.rewards.random_rewards.forEach(V=>{typeof V.balance=="number"&&(V.balance=Math.round(V.balance*100)),typeof V.transfer_enable=="number"&&(V.transfer_enable=Math.round(V.transfer_enable*1024*1024*1024))}));const p={...g,conditions:g.conditions||{},limits:g.limits||{},rewards:g.rewards||{},special_config:g.special_config||{}};try{s?(await Ps.updateTemplate({id:s.id,...p}),z.success(a("messages.templateUpdated"))):(await Ps.createTemplate(p),z.success(a("messages.templateCreated"))),n(),r(!1)}catch(V){const R=V?.response?.data?.errors;R&&Object.keys(R).forEach(L=>{c.setError(L,{type:"manual",message:R[L][0]})}),z.error(a(s?"messages.updateTemplateFailed":"messages.createTemplateFailed"))}finally{l(!1)}},w=c.watch("type"),E=w===1;return e.jsx(me,{open:t,onOpenChange:r,children:e.jsxs(ce,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(pe,{children:e.jsx(ue,{children:a(s?"template.form.edit":"template.form.add")})}),e.jsx(De,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(T,C),className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(v,{control:c.control,name:"name",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.name.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:a("template.form.name.placeholder"),..._})}),e.jsx(P,{})]})}),e.jsx(v,{control:c.control,name:"type",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.type.label")}),e.jsxs(J,{value:_.value.toString(),onValueChange:g=>_.onChange(parseInt(g)),children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:a("template.form.type.placeholder")})})}),e.jsx(Y,{children:[1,2,3].map(g=>e.jsx(A,{value:g.toString(),children:a(`types.${g}`)},g))})]}),e.jsx(P,{})]})})]}),e.jsx(v,{control:c.control,name:"description",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.description.label")}),e.jsx(y,{children:e.jsx(Es,{placeholder:a("template.form.description.placeholder"),..._})}),e.jsx(P,{})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:e.jsx(v,{control:c.control,name:"status",render:({field:_})=>e.jsxs(j,{className:"col-span-3 flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base",children:a("template.form.status.label")}),e.jsx($,{children:a("template.form.status.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:_.value,onCheckedChange:_.onChange})})]})})}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Ve,{children:a("template.form.rewards.title")})}),e.jsxs(Pe,{className:"space-y-4",children:[E&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(v,{control:c.control,name:"rewards.balance",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.rewards.balance.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.balance.placeholder"),..._,value:_.value??"",onChange:g=>{const p=g.target.valueAsNumber;_.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(v,{control:c.control,name:"rewards.transfer_enable",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.rewards.transfer_enable.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.placeholder"),value:_.value??"",onChange:g=>{const p=g.target.valueAsNumber;_.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(v,{control:c.control,name:"rewards.expire_days",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.rewards.expire_days.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.expire_days.placeholder"),..._,value:_.value??"",onChange:g=>{const p=g.target.valueAsNumber;_.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(v,{control:c.control,name:"rewards.device_limit",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.rewards.device_limit.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.device_limit.placeholder"),..._,value:_.value??"",onChange:g=>{const p=g.target.valueAsNumber;_.onChange(isNaN(p)?void 0:p)}})})]})})]}),e.jsx(v,{control:c.control,name:"rewards.reset_package",render:({field:_})=>e.jsxs(j,{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(b,{children:a("template.form.rewards.reset_package.label")}),e.jsx($,{children:a("template.form.rewards.reset_package.description")})]}),e.jsx(y,{children:e.jsx(X,{checked:_.value,onCheckedChange:_.onChange})})]})})]}),w===4&&e.jsx("p",{children:a("template.form.rewards.task_card.description")}),w===2&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(v,{control:c.control,name:"rewards.plan_id",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.rewards.plan_id.label")}),e.jsxs(J,{value:_.value?.toString(),onValueChange:g=>_.onChange(parseInt(g,10)),children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:a("template.form.rewards.plan_id.placeholder")})})}),e.jsx(Y,{children:d.map(g=>e.jsx(A,{value:g.id.toString(),children:g.name},g.id))})]}),e.jsx(P,{})]})}),e.jsx(v,{control:c.control,name:"rewards.plan_validity_days",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.rewards.plan_validity_days.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.plan_validity_days.placeholder"),..._,value:_.value??"",onChange:g=>{const p=g.target.valueAsNumber;_.onChange(isNaN(p)?void 0:p)}})})]})})]}),w===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{children:a("template.form.rewards.random_rewards.label")}),f.map((_,g)=>e.jsxs("div",{className:"flex items-center space-x-2 rounded-md border p-2",children:[e.jsx(v,{control:c.control,name:`rewards.random_rewards.${g}.weight`,render:({field:p})=>e.jsx(j,{children:e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.random_rewards.weight"),...p,value:p.value??"",onChange:V=>{const R=V.target.valueAsNumber;p.onChange(isNaN(R)?0:R)}})})})}),e.jsx(v,{control:c.control,name:`rewards.random_rewards.${g}.balance`,render:({field:p})=>e.jsx(j,{children:e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.balance.label"),...p,value:p.value??"",onChange:V=>{const R=V.target.valueAsNumber;p.onChange(isNaN(R)?void 0:R)}})})})}),e.jsx(v,{control:c.control,name:`rewards.random_rewards.${g}.transfer_enable`,render:({field:p})=>e.jsx(j,{children:e.jsx(y,{children:e.jsx(k,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.label")+" (GB)",value:p.value??"",onChange:V=>{const R=V.target.valueAsNumber;p.onChange(isNaN(R)?void 0:R)}})})})}),e.jsx(v,{control:c.control,name:`rewards.random_rewards.${g}.expire_days`,render:({field:p})=>e.jsx(j,{children:e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.expire_days.label"),...p,value:p.value??"",onChange:V=>{const R=V.target.valueAsNumber;p.onChange(isNaN(R)?void 0:R)}})})})}),e.jsx(v,{control:c.control,name:`rewards.random_rewards.${g}.device_limit`,render:({field:p})=>e.jsx(j,{children:e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.device_limit.label"),...p,value:p.value??"",onChange:V=>{const R=V.target.valueAsNumber;p.onChange(isNaN(R)?void 0:R)}})})})}),e.jsx(F,{type:"button",variant:"ghost",size:"icon",onClick:()=>S(g),children:e.jsx(wd,{className:"h-4 w-4"})})]},_.id)),e.jsx(F,{type:"button",variant:"outline",onClick:()=>D({weight:10,balance:void 0,transfer_enable:void 0,expire_days:void 0,device_limit:void 0}),children:a("template.form.rewards.random_rewards.add")})]})]})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Ve,{children:a("template.form.conditions.title")})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 gap-4",children:e.jsx(v,{control:c.control,name:"conditions.new_user_max_days",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.conditions.new_user_max_days.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.conditions.new_user_max_days.placeholder"),..._,value:_.value??"",onChange:g=>{const p=g.target.valueAsNumber;_.onChange(isNaN(p)?void 0:p)}})})]})})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(v,{control:c.control,name:"conditions.new_user_only",render:({field:_})=>e.jsxs(j,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(b,{children:a("template.form.conditions.new_user_only.label")})}),e.jsx(y,{children:e.jsx(X,{checked:_.value,onCheckedChange:_.onChange})})]})}),e.jsx(v,{control:c.control,name:"conditions.paid_user_only",render:({field:_})=>e.jsxs(j,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(b,{children:a("template.form.conditions.paid_user_only.label")})}),e.jsx(y,{children:e.jsx(X,{checked:_.value,onCheckedChange:_.onChange})})]})}),e.jsx(v,{control:c.control,name:"conditions.require_invite",render:({field:_})=>e.jsxs(j,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(b,{children:a("template.form.conditions.require_invite.label")})}),e.jsx(y,{children:e.jsx(X,{checked:_.value,onCheckedChange:_.onChange})})]})})]}),e.jsx(v,{control:c.control,name:"conditions.allowed_plans",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.conditions.allowed_plans.label")}),e.jsx(y,{children:e.jsx(nt,{value:_.value?.map(g=>({label:d.find(p=>p.id===g)?.name||`ID: ${g}`,value:g.toString()}))??[],onChange:g=>_.onChange(g.map(p=>parseInt(p.value))),options:m,placeholder:a("template.form.conditions.allowed_plans.placeholder")})})]})}),e.jsx(v,{control:c.control,name:"conditions.disallowed_plans",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.conditions.disallowed_plans.label")}),e.jsx(y,{children:e.jsx(nt,{value:_.value?.map(g=>({label:d.find(p=>p.id===g)?.name||`ID: ${g}`,value:g.toString()}))??[],onChange:g=>_.onChange(g.map(p=>parseInt(p.value))),options:m,placeholder:a("template.form.conditions.disallowed_plans.placeholder")})})]})})]})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Ve,{children:a("template.form.limits.title")})}),e.jsx(Pe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(v,{control:c.control,name:"limits.max_use_per_user",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.limits.max_use_per_user.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.limits.max_use_per_user.placeholder"),..._,value:_.value??"",onChange:g=>{const p=g.target.valueAsNumber;_.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(v,{control:c.control,name:"limits.cooldown_hours",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.limits.cooldown_hours.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",placeholder:a("template.form.limits.cooldown_hours.placeholder"),..._,value:_.value??"",onChange:g=>{const p=g.target.valueAsNumber;_.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(v,{control:c.control,name:"limits.invite_reward_rate",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.limits.invite_reward_rate.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",step:"0.01",placeholder:a("template.form.limits.invite_reward_rate.placeholder"),..._,value:_.value??"",onChange:g=>{const p=g.target.valueAsNumber;_.onChange(isNaN(p)?void 0:p)}})}),e.jsx($,{children:a("template.form.limits.invite_reward_rate.description")})]})})]})})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Ve,{children:a("template.form.special_config.title")})}),e.jsx(Pe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-3 items-end gap-4",children:[e.jsx(v,{control:c.control,name:"special_config.start_time",render:({field:_})=>e.jsxs(j,{className:"flex flex-col",children:[e.jsx(b,{children:a("template.form.special_config.start_time.label")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsx(y,{children:e.jsxs(F,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!_.value&&"text-muted-foreground"),children:[_.value?Le(new Date(_.value*1e3),"PPP"):e.jsx("span",{children:a("template.form.special_config.start_time.placeholder")}),e.jsx(Cs,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:_.value?new Date(_.value*1e3):void 0,onSelect:g=>_.onChange(g?Math.floor(g.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(P,{})]})}),e.jsx(v,{control:c.control,name:"special_config.end_time",render:({field:_})=>e.jsxs(j,{className:"flex flex-col",children:[e.jsx(b,{children:a("template.form.special_config.end_time.label")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsx(y,{children:e.jsxs(F,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!_.value&&"text-muted-foreground"),children:[_.value?Le(new Date(_.value*1e3),"PPP"):e.jsx("span",{children:a("template.form.special_config.end_time.placeholder")}),e.jsx(Cs,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:_.value?new Date(_.value*1e3):void 0,onSelect:g=>_.onChange(g?Math.floor(g.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(P,{})]})}),e.jsx(v,{control:c.control,name:"special_config.festival_bonus",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.special_config.festival_bonus.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",step:"0.1",placeholder:a("template.form.special_config.festival_bonus.placeholder"),..._,value:_.value??"",onChange:g=>{const p=g.target.valueAsNumber;_.onChange(isNaN(p)?void 0:p)}})})]})})]})})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Ve,{children:a("template.form.display.title")})}),e.jsx(Pe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(v,{control:c.control,name:"icon",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.icon.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:a("template.form.icon.placeholder"),..._})}),e.jsx(P,{})]})}),e.jsx(v,{control:c.control,name:"background_image",render:({field:_})=>e.jsxs(j,{children:[e.jsx(b,{children:a("template.form.background_image.label")}),e.jsx(y,{children:e.jsx(k,{placeholder:a("template.form.background_image.placeholder"),..._})}),e.jsx(P,{})]})})]})})]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(F,{type:"button",variant:"outline",onClick:()=>r(!1),children:a("common:cancel")}),e.jsx(F,{type:"submit",disabled:i,children:a(i?"common:saving":"common:submit")})]})]})})]})})}const Ti=u.createContext(void 0);function $h({children:s,refetch:n}){const[t,r]=u.useState(!1),[a,i]=u.useState(null),l=x=>{i(x),r(!!x)},d=()=>{r(!1),i(null)};return e.jsxs(Ti.Provider,{value:{isOpen:t,editingTemplate:a,setEditingTemplate:l,closeEdit:d},children:[s,e.jsx(ki,{template:a,refetch:n,open:t,onOpenChange:r})]})}function Ah(){const s=u.useContext(Ti);if(s===void 0)throw new Error("useTemplateEdit must be used within a TemplateEditProvider");return s}function qh({rewards:s,type:n}){const{t}=M(["giftCard","common"]),r=[];return s&&(s.balance&&r.push(`${t("template.form.rewards.balance.short_label")}: ${s.balance/100} ${t("common:currency.yuan","元")}`),s.transfer_enable&&r.push(`${t("template.form.rewards.transfer_enable.short_label")}: ${ze(s.transfer_enable)}`),s.expire_days&&r.push(`${t("template.form.rewards.expire_days.short_label")}: ${s.expire_days}${t("common:time.day","天")}`),s.device_limit&&r.push(`${t("template.form.rewards.device_limit.short_label")}: ${s.device_limit}`),n===2&&s.plan_id&&r.push(`${t("template.form.rewards.plan_id.short_label")}: ${s.plan_id}`),n===2&&s.plan_validity_days&&r.push(`${t("template.form.rewards.plan_validity_days.short_label")}: ${s.plan_validity_days}${t("common:time.day","天")}`),n===3&&s.random_rewards?.length&&r.push(t("types.3"))),r.length===0?e.jsx(q,{variant:"secondary",children:t("template.table.columns.no_rewards")}):e.jsx("div",{className:"flex flex-col space-y-1",children:r.map((a,i)=>e.jsx(q,{variant:"outline",className:"whitespace-nowrap",children:a},i))})}const Hh=s=>{const{t:n}=M("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.id")}),cell:({row:t})=>e.jsx(q,{children:t.original.id}),enableSorting:!0},{accessorKey:"status",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.status")}),cell:({row:t})=>{const[r,a]=u.useState(!1);return e.jsx(X,{checked:t.original.status,disabled:r,onCheckedChange:async i=>{a(!0);try{const{data:l}=await Ps.updateTemplate({id:t.original.id,status:i});l?(z.success(n("messages.templateUpdated")),s()):z.error(n("messages.updateTemplateFailed"))}catch{z.error(n("messages.updateTemplateFailed"))}finally{a(!1)}}})},enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:300},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.type")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:n(`types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"rewards",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.rewards")}),cell:({row:t})=>e.jsx(qh,{rewards:t.original.rewards,type:t.original.type}),enableSorting:!1},{accessorKey:"sort",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.sort")}),cell:({row:t})=>e.jsx(q,{variant:"secondary",children:t.original.sort}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(t.original.created_at)}),enableSorting:!0},{id:"actions",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.actions")}),cell:({row:t})=>{const{setEditingTemplate:r}=Ah();return e.jsxs("div",{className:"flex space-x-2",children:[e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>r(t.original),children:[e.jsx(rt,{className:"h-4 w-4"}),n("template.actions.edit")]}),e.jsx(_s,{title:n("template.actions.deleteConfirm.title"),description:n("template.actions.deleteConfirm.description"),confirmText:n("template.actions.deleteConfirm.confirmText"),onConfirm:async()=>{try{const{data:a}=await Ps.deleteTemplate({id:t.original.id});a?(z.success(n("messages.templateDeleted")),s()):z.error(n("messages.deleteTemplateFailed"))}catch{z.error(n("messages.deleteTemplateFailed"))}},children:e.jsxs(F,{variant:"outline",size:"sm",children:[e.jsx(us,{className:"h-4 w-4"}),n("template.actions.delete")]})})]})},enableSorting:!1}]};function Di({table:s}){return e.jsxs(Hs,{children:[e.jsx(Cd,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(Il,{className:"mr-2 h-4 w-4"}),"显示列"]})}),e.jsxs(zs,{align:"end",className:"w-[150px]",children:[e.jsx(Ha,{children:"切换显示列"}),e.jsx(at,{}),s.getAllColumns().filter(n=>typeof n.accessorFn<"u"&&n.getCanHide()).map(n=>e.jsx(Ql,{className:"capitalize",checked:n.getIsVisible(),onCheckedChange:t=>n.toggleVisibility(!!t),children:n.id},n.id))]})]})}function Ea({column:s,title:n,options:t}){const r=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(G,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Sd,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ee,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(q,{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(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):t.filter(a=>r.has(a.value)).map(a=>e.jsx(q,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:a.label},`selected-${a.value}`))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(it,{children:[e.jsx(vt,{placeholder:n}),e.jsxs(ot,{children:[e.jsx(bt,{children:"No results found."}),e.jsx(ks,{children:t.map(a=>{const i=r.has(a.value);return e.jsxs(rs,{onSelect:()=>{i?r.delete(a.value):r.add(a.value);const l=Array.from(r);s?.setFilterValue(l.length?l:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",i?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(kd,{className:N("h-4 w-4")})}),a.icon&&e.jsx(a.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:a.label})]},`option-${a.value}`)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Mt,{}),e.jsx(ks,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function Uh({table:s,refetch:n}){const{t}=M("giftCard"),[r,a]=u.useState(!1),i=s.getState().columnFilters.length>0,l=[{label:t("types.1"),value:"1"},{label:t("types.2"),value:"2"},{label:t("types.3"),value:"3"},{label:t("types.4"),value:"4"},{label:t("types.5"),value:"5"},{label:t("types.6"),value:"6"},{label:t("types.7"),value:"7"},{label:t("types.8"),value:"8"},{label:t("types.9"),value:"9"},{label:t("types.10"),value:"10"}],d=[{label:t("common.enabled"),value:"true"},{label:t("common.disabled"),value:"false"}];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.jsx(k,{placeholder:t("common.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:x=>s.getColumn("name")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(Ea,{column:s.getColumn("type"),title:t("template.table.columns.type"),options:l}),s.getColumn("status")&&e.jsx(Ea,{column:s.getColumn("status"),title:t("template.table.columns.status"),options:d}),i&&e.jsxs(F,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Ml,{className:"h-4 w-4 mr-2"}),t("template.form.add")]}),e.jsx(Di,{table:s})]}),e.jsx(ki,{template:null,refetch:n,open:r,onOpenChange:a})]})}function Kh(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),[x,m]=u.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=re({queryKey:["giftCardTemplates",x,a,l],queryFn:()=>Ps.getTemplates({per_page:x.pageSize,page:x.pageIndex+1,filter:a,sort:l})});console.log(c);const f=Be({data:c?.data??[],columns:Hh(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:x},pageCount:Math.ceil((c?.total??0)/x.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:m,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx($h,{refetch:o,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:f,toolbar:e.jsx(Uh,{table:f,refetch:o})})})})}const Bh=h.object({template_id:h.number().min(1,"请选择一个模板"),count:h.number().min(1,"生成数量必须大于0").max(1e4,"单次最多生成10000个"),prefix:h.string().optional(),expires_hours:h.number().min(1,"有效期必须大于0"),max_usage:h.number().min(1,"最大使用次数必须大于0"),download_csv:h.boolean().optional()});function Gh({refetch:s,open:n,onOpenChange:t}){const{t:r}=M("giftCard"),[a,i]=u.useState(!1),[l,d]=u.useState([]);u.useEffect(()=>{n&&Ps.getTemplates({per_page:1e3,page:1}).then(({data:o})=>{d(o||[])})},[n]);const x=we({resolver:Te(Bh),defaultValues:{count:10,prefix:"",expires_hours:24*30,max_usage:1,download_csv:!1}}),m=async o=>{i(!0);try{if(o.download_csv){const c=await Ps.generateCodes(o);if(c&&c instanceof Blob){const f=window.URL.createObjectURL(c),D=document.createElement("a");D.href=f,D.download=`gift_codes_${new Date().getTime()}.csv`,document.body.appendChild(D),D.click(),D.remove(),window.URL.revokeObjectURL(f),z.success(r("messages.codesGenerated")),s(),t(!1),x.reset()}}else await Ps.generateCodes(o),z.success(r("messages.codesGenerated")),s(),t(!1),x.reset()}catch{z.error(r("messages.generateCodesFailed"))}finally{i(!1)}};return e.jsx(me,{open:n,onOpenChange:t,children:e.jsxs(ce,{children:[e.jsx(pe,{children:e.jsx(ue,{children:r("code.form.generate")})}),e.jsx(De,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(m),className:"space-y-4",children:[e.jsx(v,{control:x.control,name:"template_id",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("code.form.template_id.label")}),e.jsxs(J,{onValueChange:c=>o.onChange(parseInt(c)),children:[e.jsx(y,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:r("code.form.template_id.placeholder")})})}),e.jsx(Y,{children:l.map(c=>e.jsx(A,{value:c.id.toString(),children:c.name},c.id))})]}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"count",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("code.form.count.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"prefix",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("code.form.prefix.label")}),e.jsx(y,{children:e.jsx(k,{...o})}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"expires_hours",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("code.form.expires_hours.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"max_usage",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:r("code.form.max_usage.label")}),e.jsx(y,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(P,{})]})}),e.jsx(v,{control:x.control,name:"download_csv",render:({field:o})=>e.jsxs(j,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(y,{children:e.jsx("input",{type:"checkbox",checked:o.value,onChange:c=>o.onChange(c.target.checked)})}),e.jsx(b,{children:r("code.form.download_csv")})]})}),e.jsxs(Ie,{children:[e.jsx(F,{type:"button",variant:"outline",onClick:()=>t(!1),children:r("common.cancel")}),e.jsx(F,{type:"submit",disabled:a,children:r(a?"code.form.submit.generating":"code.form.submit.generate")})]})]})})]})})}function Wh({table:s,refetch:n}){const{t}=M("giftCard"),[r,a]=u.useState(!1),i=s.getState().columnFilters.length>0,l=Object.entries(t("code.status",{returnObjects:!0})).map(([d,x])=>({value:d,label:x}));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.jsx(k,{placeholder:t("common.search"),value:s.getColumn("code")?.getFilterValue()??"",onChange:d=>s.getColumn("code")?.setFilterValue(d.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("status")&&e.jsx(Ea,{column:s.getColumn("status"),title:t("code.table.columns.status"),options:l}),i&&e.jsxs(F,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Ml,{className:"h-4 w-4 mr-2"}),t("code.form.generate")]}),e.jsxs(F,{variant:"outline",size:"sm",disabled:!0,children:[e.jsx(sa,{className:"h-4 w-4 mr-2"}),t("common.export")]}),e.jsx(Di,{table:s})]}),e.jsx(Gh,{refetch:n,open:r,onOpenChange:a})]})}const Yh=0,Jh=1,Qh=2,xn=3,Xh=s=>{const{t:n}=M("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.id")}),cell:({row:t})=>e.jsx(q,{children:t.original.id})},{accessorKey:"code",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.code")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(q,{variant:"secondary",children:t.original.code}),e.jsx(F,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>Rt(t.original.code).then(()=>{z.success(n("common:copy.success"))}),children:e.jsx(Mn,{className:"h-4 w-4"})})]})},{accessorKey:"template_name",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.template_name")})},{accessorKey:"status",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.status")}),cell:({row:t})=>{const r=t.original.status,a=r===xn,i=r===Yh||r===xn;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(q,{variant:r===Jh?"secondary":r===Qh||r===xn?"destructive":"default",children:n(`code.status.${r}`)}),i&&e.jsx(X,{checked:!a,onCheckedChange:async l=>{const d=l?"enable":"disable";try{const{data:x}=await Ps.toggleCode({id:t.original.id,action:d});x?(z.success(n("messages.codeStatusUpdated")),s()):z.error(n("messages.updateCodeStatusFailed"))}catch{z.error(n("messages.updateCodeStatusFailed"))}}})]})}},{accessorKey:"expires_at",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.expires_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(t.original.expires_at)})},{accessorKey:"usage_count",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.usage_count")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:t.original.usage_count})},{accessorKey:"max_usage",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.max_usage")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:t.original.max_usage})},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(t.original.created_at)})}]};function Zh(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([]),[l,d]=u.useState([]),[x,m]=u.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=re({queryKey:["giftCardCodes",x,a,l],queryFn:()=>Ps.getCodes({per_page:x.pageSize,page:x.pageIndex+1,filter:a,sort:l})}),f=Be({data:c?.data??[],columns:Xh(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:x},pageCount:Math.ceil((c?.total??0)/x.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:m,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:f,toolbar:e.jsx(Wh,{table:f,refetch:o})})})}const eg=()=>{const{t:s}=M("giftCard");return[{accessorKey:"id",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.id")}),cell:({row:n})=>e.jsx(q,{children:n.original.id})},{accessorKey:"code",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.code")}),cell:({row:n})=>e.jsx(q,{variant:"secondary",children:n.original.code})},{accessorKey:"user_email",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.user_email")})},{accessorKey:"template_name",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.template_name")})},{accessorKey:"created_at",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.created_at")}),cell:({row:n})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(n.original.created_at)})}]};function sg(){const[s,n]=u.useState([]),[t,r]=u.useState([]),[a,i]=u.useState({pageIndex:0,pageSize:20}),{data:l}=re({queryKey:["giftCardUsages",a,s,t],queryFn:()=>Ps.getUsages({per_page:a.pageSize,page:a.pageIndex+1,filter:s,sort:t})}),d=Be({data:l?.data??[],columns:eg(),state:{sorting:t,columnFilters:s,pagination:a},pageCount:Math.ceil((l?.total??0)/a.pageSize),rowCount:l?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,onSortingChange:r,onColumnFiltersChange:n,onPaginationChange:i,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs()});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(k,{placeholder:"搜索用户邮箱...",value:d.getColumn("user_email")?.getFilterValue()??"",onChange:x=>d.getColumn("user_email")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"})}),e.jsx(ts,{table:d})]})}function tg(){const{t:s}=M("giftCard"),{data:n,isLoading:t}=re({queryKey:["giftCardStats"],queryFn:()=>Ps.getStatistics({})}),r=n?.data?.total_stats,a=[{title:s("statistics.total.templates_count"),value:r?.templates_count},{title:s("statistics.total.active_templates_count"),value:r?.active_templates_count},{title:s("statistics.total.codes_count"),value:r?.codes_count},{title:s("statistics.total.used_codes_count"),value:r?.used_codes_count}];return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:a.map((i,l)=>e.jsxs(ke,{children:[e.jsx(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:e.jsx(Ve,{className:"text-sm font-medium",children:i.title})}),e.jsx(Pe,{children:t?e.jsx(be,{className:"h-8 w-1/2"}):e.jsx("div",{className:"text-2xl font-bold",children:i.value??0})})]},l))})}function ag(){const{t:s}=M("giftCard"),[n,t]=u.useState("templates");return e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-6 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.jsxs(ft,{value:n,onValueChange:t,className:"flex-1",children:[e.jsxs(lt,{className:"grid w-full grid-cols-4",children:[e.jsx(Ke,{value:"templates",children:s("tabs.templates")}),e.jsx(Ke,{value:"codes",children:s("tabs.codes")}),e.jsx(Ke,{value:"usages",children:s("tabs.usages")}),e.jsx(Ke,{value:"statistics",children:s("tabs.statistics")})]}),e.jsx(bs,{value:"templates",className:"mt-6 flex-1",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("template.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("template.description")})]})}),e.jsx(Kh,{})]})}),e.jsx(bs,{value:"codes",className:"mt-6 flex-1",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("code.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("code.description")})]})}),e.jsx(Zh,{})]})}),e.jsx(bs,{value:"usages",className:"mt-6 flex-1",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("usage.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("usage.description")})]})}),e.jsx(sg,{})]})}),e.jsx(bs,{value:"statistics",className:"mt-6 flex-1",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("statistics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("statistics.description")})]})}),e.jsx(tg,{})]})})]})]})]})}const ng=Object.freeze(Object.defineProperty({__proto__:null,default:ag},Symbol.toStringTag,{value:"Module"})),rg=1,lg=1e6;let hn=0;function ig(){return hn=(hn+1)%Number.MAX_SAFE_INTEGER,hn.toString()}const gn=new Map,Cr=s=>{if(gn.has(s))return;const n=setTimeout(()=>{gn.delete(s),Zt({type:"REMOVE_TOAST",toastId:s})},lg);gn.set(s,n)},og=(s,n)=>{switch(n.type){case"ADD_TOAST":return{...s,toasts:[n.toast,...s.toasts].slice(0,rg)};case"UPDATE_TOAST":return{...s,toasts:s.toasts.map(t=>t.id===n.toast.id?{...t,...n.toast}:t)};case"DISMISS_TOAST":{const{toastId:t}=n;return t?Cr(t):s.toasts.forEach(r=>{Cr(r.id)}),{...s,toasts:s.toasts.map(r=>r.id===t||t===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return n.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==n.toastId)}}},_a=[];let Na={toasts:[]};function Zt(s){Na=og(Na,s),_a.forEach(n=>{n(Na)})}function cg({...s}){const n=ig(),t=a=>Zt({type:"UPDATE_TOAST",toast:{...a,id:n}}),r=()=>Zt({type:"DISMISS_TOAST",toastId:n});return Zt({type:"ADD_TOAST",toast:{...s,id:n,open:!0,onOpenChange:a=>{a||r()}}}),{id:n,dismiss:r,update:t}}function Fi(){const[s,n]=u.useState(Na);return u.useEffect(()=>(_a.push(n),()=>{const t=_a.indexOf(n);t>-1&&_a.splice(t,1)}),[s]),{...s,toast:cg,dismiss:t=>Zt({type:"DISMISS_TOAST",toastId:t})}}function dg({open:s,onOpenChange:n,table:t}){const{t:r}=M("user"),{toast:a}=Fi(),[i,l]=u.useState(!1),[d,x]=u.useState(""),[m,o]=u.useState(""),c=async()=>{if(!d||!m){a({title:r("messages.error"),description:r("messages.send_mail.required_fields"),variant:"destructive"});return}try{l(!0),await qs.sendMail({subject:d,content:m,filter:t.getState().columnFilters,sort:t.getState().sorting[0]?.id,sort_type:t.getState().sorting[0]?.desc?"DESC":"ASC"}),a({title:r("messages.success"),description:r("messages.send_mail.success")}),n(!1),x(""),o("")}catch{a({title:r("messages.error"),description:r("messages.send_mail.failed"),variant:"destructive"})}finally{l(!1)}};return e.jsx(me,{open:s,onOpenChange:n,children:e.jsxs(ce,{className:"sm:max-w-[500px]",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:r("send_mail.title")}),e.jsx($e,{children:r("send_mail.description")})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"subject",className:"text-right",children:r("send_mail.subject")}),e.jsx(k,{id:"subject",value:d,onChange:f=>x(f.target.value),className:"col-span-3"})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"content",className:"text-right",children:r("send_mail.content")}),e.jsx(Es,{id:"content",value:m,onChange:f=>o(f.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(Ie,{children:e.jsx(G,{type:"submit",onClick:c,disabled:i,children:r(i?"send_mail.sending":"send_mail.send")})})]})})}function mg({trigger:s}){const{t:n}=M("user"),[t,r]=u.useState(!1),[a,i]=u.useState(30),{data:l,isLoading:d}=re({queryKey:["trafficResetStats",a],queryFn:()=>na.getStats({days:a}),enabled:t}),x=[{title:n("traffic_reset.stats.total_resets"),value:l?.data?.total_resets||0,icon:Yt,color:"text-blue-600",bgColor:"bg-blue-100"},{title:n("traffic_reset.stats.auto_resets"),value:l?.data?.auto_resets||0,icon:ka,color:"text-green-600",bgColor:"bg-green-100"},{title:n("traffic_reset.stats.manual_resets"),value:l?.data?.manual_resets||0,icon:Cs,color:"text-orange-600",bgColor:"bg-orange-100"},{title:n("traffic_reset.stats.cron_resets"),value:l?.data?.cron_resets||0,icon:On,color:"text-purple-600",bgColor:"bg-purple-100"}],m=[{value:7,label:n("traffic_reset.stats.days_options.week")},{value:30,label:n("traffic_reset.stats.days_options.month")},{value:90,label:n("traffic_reset.stats.days_options.quarter")},{value:365,label:n("traffic_reset.stats.days_options.year")}];return e.jsxs(me,{open:t,onOpenChange:r,children:[e.jsx(ps,{asChild:!0,children:s}),e.jsxs(ce,{className:"max-w-2xl",children:[e.jsxs(pe,{children:[e.jsxs(ue,{className:"flex items-center gap-2",children:[e.jsx(En,{className:"h-5 w-5"}),n("traffic_reset.stats.title")]}),e.jsx($e,{children:n("traffic_reset.stats.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-medium",children:n("traffic_reset.stats.time_range")}),e.jsxs(J,{value:a.toString(),onValueChange:o=>i(Number(o)),children:[e.jsx(W,{className:"w-[180px]",children:e.jsx(Q,{})}),e.jsx(Y,{children:m.map(o=>e.jsx(A,{value:o.value.toString(),children:o.label},o.value))})]})]}),d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(ea,{className:"h-6 w-6 animate-spin"})}):e.jsx("div",{className:"grid grid-cols-2 gap-4",children:x.map((o,c)=>e.jsxs(ke,{className:"relative overflow-hidden",children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ve,{className:"text-sm font-medium text-muted-foreground",children:o.title}),e.jsx("div",{className:`rounded-lg p-2 ${o.bgColor}`,children:e.jsx(o.icon,{className:`h-4 w-4 ${o.color}`})})]}),e.jsxs(Pe,{children:[e.jsx("div",{className:"text-2xl font-bold",children:o.value.toLocaleString()}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:n("traffic_reset.stats.in_period",{days:a})})]})]},c))}),l?.data&&e.jsxs(ke,{children:[e.jsxs(Fe,{children:[e.jsx(Ve,{className:"text-lg",children:n("traffic_reset.stats.breakdown")}),e.jsx(Zs,{children:n("traffic_reset.stats.breakdown_description")})]}),e.jsx(Pe,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:n("traffic_reset.stats.auto_percentage")}),e.jsxs(q,{variant:"outline",className:"border-green-200 bg-green-50 text-green-700",children:[l.data.total_resets>0?(l.data.auto_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:n("traffic_reset.stats.manual_percentage")}),e.jsxs(q,{variant:"outline",className:"border-orange-200 bg-orange-50 text-orange-700",children:[l.data.total_resets>0?(l.data.manual_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:n("traffic_reset.stats.cron_percentage")}),e.jsxs(q,{variant:"outline",className:"border-purple-200 bg-purple-50 text-purple-700",children:[l.data.total_resets>0?(l.data.cron_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]})]})})]})]})]})]})}const ug=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(),download_csv:h.boolean().optional()}).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"]}),xg={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0,download_csv:!1};function hg({refetch:s}){const{t:n}=M("user"),[t,r]=u.useState(!1),a=we({resolver:Te(ug),defaultValues:xg,mode:"onChange"}),[i,l]=u.useState([]);return u.useEffect(()=>{t&&ys.getList().then(({data:d})=>{d&&l(d)})},[t]),e.jsxs(me,{open:t,onOpenChange:r,children:[e.jsx(ps,{asChild:!0,children:e.jsxs(G,{size:"sm",variant:"outline",className:"gap-0 space-x-2",children:[e.jsx(Ue,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(pe,{children:[e.jsx(ue,{children:n("generate.title")}),e.jsx($e,{})]}),e.jsxs(De,{...a,children:[e.jsxs(j,{children:[e.jsx(b,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!a.watch("generate_count")&&e.jsx(v,{control:a.control,name:"email_prefix",render:({field:d})=>e.jsx(k,{className:"flex-[5] rounded-r-none",placeholder:n("generate.form.email_prefix"),...d})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${a.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(v,{control:a.control,name:"email_suffix",render:({field:d})=>e.jsx(k,{className:"flex-[4] rounded-l-none",placeholder:n("generate.form.email_domain"),...d})})]})]}),e.jsx(v,{control:a.control,name:"password",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{children:n("generate.form.password")}),e.jsx(k,{placeholder:n("generate.form.password_placeholder"),...d}),e.jsx(P,{})]})}),e.jsx(v,{control:a.control,name:"expired_at",render:({field:d})=>e.jsxs(j,{className:"flex flex-col",children:[e.jsx(b,{children:n("generate.form.expire_time")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsx(y,{children:e.jsxs(G,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!d.value&&"text-muted-foreground"),children:[d.value?oe(d.value):e.jsx("span",{children:n("generate.form.expire_time_placeholder")}),e.jsx(Cs,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(Xe,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(Td,{asChild:!0,children:e.jsx(G,{variant:"outline",className:"w-full",onClick:()=>{d.onChange(null)},children:n("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Ss,{mode:"single",selected:d.value?new Date(d.value*1e3):void 0,onSelect:x=>{x&&d.onChange(x?.getTime()/1e3)}})})]})]})]})}),e.jsx(v,{control:a.control,name:"plan_id",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{children:n("generate.form.subscription")}),e.jsx(y,{children:e.jsxs(J,{value:d.value?d.value.toString():"null",onValueChange:x=>d.onChange(x==="null"?null:parseInt(x)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"null",children:n("generate.form.subscription_none")}),i.map(x=>e.jsx(A,{value:x.id.toString(),children:x.name},x.id))]})]})})]})}),!a.watch("email_prefix")&&e.jsx(v,{control:a.control,name:"generate_count",render:({field:d})=>e.jsxs(j,{children:[e.jsx(b,{children:n("generate.form.generate_count")}),e.jsx(k,{type:"number",placeholder:n("generate.form.generate_count_placeholder"),value:d.value||"",onChange:x=>d.onChange(x.target.value?parseInt(x.target.value):null)})]})}),a.watch("generate_count")&&e.jsx(v,{control:a.control,name:"download_csv",render:({field:d})=>e.jsxs(j,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(y,{children:e.jsx(Bn,{checked:d.value,onCheckedChange:d.onChange})}),e.jsx(b,{children:n("generate.form.download_csv")})]})})]}),e.jsxs(Ie,{children:[e.jsx(G,{variant:"outline",onClick:()=>r(!1),children:n("generate.form.cancel")}),e.jsx(G,{onClick:()=>a.handleSubmit(async d=>{if(d.download_csv){const x=await qs.generate(d);if(x&&x instanceof Blob){const m=window.URL.createObjectURL(x),o=document.createElement("a");o.href=m,o.download=`users_${new Date().getTime()}.csv`,document.body.appendChild(o),o.click(),o.remove(),window.URL.revokeObjectURL(m),z.success(n("generate.form.success")),a.reset(),s(),r(!1)}}else{const{data:x}=await qs.generate(d);x&&(z.success(n("generate.form.success")),a.reset(),s(),r(!1))}})(),children:n("generate.form.submit")})]})]})]})}const Gn=Or,Pi=zr,gg=$r,Li=u.forwardRef(({className:s,...n},t)=>e.jsx(Va,{className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:t}));Li.displayName=Va.displayName;const pg=gt("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"}}),en=u.forwardRef(({side:s="right",className:n,children:t,...r},a)=>e.jsxs(gg,{children:[e.jsx(Li,{}),e.jsxs(Ia,{ref:a,className:N(pg({side:s}),n),...r,children:[e.jsxs(Fn,{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(os,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),t]})]}));en.displayName=Ia.displayName;const sn=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-2 text-center sm:text-left",s),...n});sn.displayName="SheetHeader";const Ri=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Ri.displayName="SheetFooter";const tn=u.forwardRef(({className:s,...n},t)=>e.jsx(Ma,{ref:t,className:N("text-lg font-semibold text-foreground",s),...n}));tn.displayName=Ma.displayName;const an=u.forwardRef(({className:s,...n},t)=>e.jsx(Oa,{ref:t,className:N("text-sm text-muted-foreground",s),...n}));an.displayName=Oa.displayName;function fg({table:s,refetch:n,permissionGroups:t=[],subscriptionPlans:r=[]}){const{t:a}=M("user"),{toast:i}=Fi(),l=s.getState().columnFilters.length>0,[d,x]=u.useState([]),[m,o]=u.useState(!1),[c,f]=u.useState(!1),[D,S]=u.useState(!1),[C,T]=u.useState(!1),w=async()=>{try{const se=await qs.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),ae=se;console.log(se);const H=new Blob([ae],{type:"text/csv;charset=utf-8;"}),ee=window.URL.createObjectURL(H),je=document.createElement("a");je.href=ee,je.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(je),je.click(),je.remove(),window.URL.revokeObjectURL(ee),i({title:a("messages.success"),description:a("messages.export.success")})}catch{i({title:a("messages.error"),description:a("messages.export.failed"),variant:"destructive"})}},E=async()=>{try{T(!0),await qs.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),i({title:a("messages.success"),description:a("messages.batch_ban.success")}),n()}catch{i({title:a("messages.error"),description:a("messages.batch_ban.failed"),variant:"destructive"})}finally{T(!1),S(!1)}},_=[{label:a("filter.fields.email"),value:"email",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.id"),value:"id",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.plan_id"),value:"plan_id",type:"select",operators:[{label:a("filter.operators.eq"),value:"eq"}],useOptions:!0},{label:a("filter.fields.transfer_enable"),value:"transfer_enable",type:"number",unit:"GB",operators:[{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.total_used"),value:"total_used",type:"number",unit:"GB",operators:[{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.online_count"),value:"online_count",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"},{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"}]},{label:a("filter.fields.expired_at"),value:"expired_at",type:"date",operators:[{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.uuid"),value:"uuid",type:"text",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.token"),value:"token",type:"text",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.banned"),value:"banned",type:"select",operators:[{label:a("filter.operators.eq"),value:"eq"}],options:[{label:a("filter.status.normal"),value:"0"},{label:a("filter.status.banned"),value:"1"}]},{label:a("filter.fields.remark"),value:"remarks",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.inviter_email"),value:"invite_user.email",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.invite_user_id"),value:"invite_user_id",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.is_admin"),value:"is_admin",type:"boolean",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.is_staff"),value:"is_staff",type:"boolean",operators:[{label:a("filter.operators.eq"),value:"eq"}]}],g=se=>se*1024*1024*1024,p=se=>se/(1024*1024*1024),V=()=>{x([...d,{field:"",operator:"",value:""}])},R=se=>{x(d.filter((ae,H)=>H!==se))},L=(se,ae,H)=>{const ee=[...d];if(ee[se]={...ee[se],[ae]:H},ae==="field"){const je=_.find(ds=>ds.value===H);je&&(ee[se].operator=je.operators[0].value,ee[se].value=je.type==="boolean"?!1:"")}x(ee)},K=(se,ae)=>{const H=_.find(ee=>ee.value===se.field);if(!H)return null;switch(H.type){case"text":return e.jsx(k,{placeholder:a("filter.sheet.value"),value:se.value,onChange:ee=>L(ae,"value",ee.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(k,{type:"number",placeholder:a("filter.sheet.value_number",{unit:H.unit}),value:H.unit==="GB"?p(se.value||0):se.value,onChange:ee=>{const je=Number(ee.target.value);L(ae,"value",H.unit==="GB"?g(je):je)}}),H.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:H.unit})]});case"date":return e.jsx(Ss,{mode:"single",selected:se.value,onSelect:ee=>L(ae,"value",ee),className:"flex flex-1 justify-center rounded-md border"});case"select":return e.jsxs(J,{value:se.value,onValueChange:ee=>L(ae,"value",ee),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("filter.sheet.value")})}),e.jsx(Y,{children:H.useOptions?r.map(ee=>e.jsx(A,{value:ee.value.toString(),children:ee.label},ee.value)):H.options?.map(ee=>e.jsx(A,{value:ee.value.toString(),children:ee.label},ee.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(X,{checked:se.value,onCheckedChange:ee=>L(ae,"value",ee)}),e.jsx(Je,{children:se.value?a("filter.boolean.true"):a("filter.boolean.false")})]});default:return null}},Z=()=>{const se=d.filter(ae=>ae.field&&ae.operator&&ae.value!=="").map(ae=>{const H=_.find(je=>je.value===ae.field);let ee=ae.value;return ae.operator==="contains"?{id:ae.field,value:ee}:(H?.type==="date"&&ee instanceof Date&&(ee=Math.floor(ee.getTime()/1e3)),H?.type==="boolean"&&(ee=ee?1:0),{id:ae.field,value:`${ae.operator}:${ee}`})});s.setColumnFilters(se),o(!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(hg,{refetch:n}),e.jsx(k,{placeholder:a("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:se=>s.getColumn("email")?.setFilterValue(se.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(Gn,{open:m,onOpenChange:o,children:[e.jsx(Pi,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Il,{className:"mr-2 h-4 w-4"}),a("filter.advanced"),d.length>0&&e.jsx(q,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:d.length})]})}),e.jsxs(en,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(sn,{children:[e.jsx(tn,{children:a("filter.sheet.title")}),e.jsx(an,{children:a("filter.sheet.description")})]}),e.jsxs("div",{className:"mt-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:a("filter.sheet.conditions")}),e.jsx(F,{variant:"outline",size:"sm",onClick:V,children:a("filter.sheet.add")})]}),e.jsx(ht,{className:"h-[calc(100vh-280px)] ",children:e.jsx("div",{className:"space-y-4",children:d.map((se,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(Je,{children:a("filter.sheet.condition",{number:ae+1})}),e.jsx(F,{variant:"ghost",size:"sm",onClick:()=>R(ae),children:e.jsx(os,{className:"h-4 w-4"})})]}),e.jsxs(J,{value:se.field,onValueChange:H=>L(ae,"field",H),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("filter.sheet.field")})}),e.jsx(Y,{children:e.jsx(fs,{children:_.map(H=>e.jsx(A,{value:H.value,className:"cursor-pointer",children:H.label},H.value))})})]}),se.field&&e.jsxs(J,{value:se.operator,onValueChange:H=>L(ae,"operator",H),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("filter.sheet.operator")})}),e.jsx(Y,{children:_.find(H=>H.value===se.field)?.operators.map(H=>e.jsx(A,{value:H.value,children:H.label},H.value))})]}),se.field&&se.operator&&K(se,ae)]},ae))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(F,{variant:"outline",onClick:()=>{x([]),o(!1)},children:a("filter.sheet.reset")}),e.jsx(F,{onClick:Z,children:a("filter.sheet.apply")})]})]})]})]}),l&&e.jsxs(F,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),x([])},className:"h-8 px-2 lg:px-3",children:[a("filter.sheet.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]}),e.jsxs(Hs,{modal:!1,children:[e.jsx(Bs,{asChild:!0,children:e.jsx(F,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:a("actions.title")})}),e.jsxs(zs,{children:[e.jsx(Se,{onClick:()=>f(!0),children:a("actions.send_email")}),e.jsx(Se,{onClick:w,children:a("actions.export_csv")}),e.jsx(at,{}),e.jsx(Se,{asChild:!0,children:e.jsx(mg,{trigger:e.jsx("div",{className:"w-full cursor-pointer px-2 py-1.5 text-sm",children:a("actions.traffic_reset_stats")})})}),e.jsx(at,{}),e.jsx(Se,{onClick:()=>S(!0),className:"text-red-600 focus:text-red-600",children:a("actions.batch_ban")})]})]})]}),e.jsx(dg,{open:c,onOpenChange:f,table:s}),e.jsx(Un,{open:D,onOpenChange:S,children:e.jsxs(Ka,{children:[e.jsxs(Ba,{children:[e.jsx(Wa,{children:a("actions.confirm_ban.title")}),e.jsx(Ya,{children:a(l?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(Ga,{children:[e.jsx(Qa,{disabled:C,children:a("actions.confirm_ban.cancel")}),e.jsx(Ja,{onClick:E,disabled:C,className:"bg-red-600 hover:bg-red-700 focus:ring-red-600",children:a(C?"actions.confirm_ban.banning":"actions.confirm_ban.confirm")})]})]})})]})}const Ei=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"})}),Vi=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"})}),jg=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"})}),vg=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"})}),pn=[{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:Gd(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ei,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:ze(s.original.u/parseFloat(s.original.server_rate))})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Vi,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:ze(s.original.d/parseFloat(s.original.server_rate))})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const n=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(q,{variant:"outline",className:"font-mono",children:[n,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const n=s.original.u+s.original.d;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:ze(n)})}}];function Ii({user_id:s,dialogTrigger:n}){const{t}=M(["traffic"]),[r,a]=u.useState(!1),[i,l]=u.useState({pageIndex:0,pageSize:20}),{data:d,isLoading:x}=re({queryKey:["userStats",s,i,r],queryFn:()=>r?qs.getStats({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),m=Be({data:d?.data??[],columns:pn,pageCount:Math.ceil((d?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:Ge(),onPaginationChange:l});return e.jsxs(me,{open:r,onOpenChange:a,children:[e.jsx(ps,{asChild:!0,children:n}),e.jsxs(ce,{className:"sm:max-w-[700px]",children:[e.jsx(pe,{children:e.jsx(ue,{children:t("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs($n,{children:[e.jsx(An,{children:m.getHeaderGroups().map(o=>e.jsx(Xs,{children:o.headers.map(c=>e.jsx(Hn,{className:N("h-10 px-2 text-xs",c.id==="total"&&"text-right"),children:c.isPlaceholder?null:Ca(c.column.columnDef.header,c.getContext())},c.id))},o.id))}),e.jsx(qn,{children:x?Array.from({length:i.pageSize}).map((o,c)=>e.jsx(Xs,{children:Array.from({length:pn.length}).map((f,D)=>e.jsx(Pt,{className:"p-2",children:e.jsx(be,{className:"h-6 w-full"})},D))},c)):m.getRowModel().rows?.length?m.getRowModel().rows.map(o=>e.jsx(Xs,{"data-state":o.getIsSelected()&&"selected",className:"h-10",children:o.getVisibleCells().map(c=>e.jsx(Pt,{className:"px-2",children:Ca(c.column.columnDef.cell,c.getContext())},c.id))},o.id)):e.jsx(Xs,{children:e.jsx(Pt,{colSpan:pn.length,className:"h-24 text-center",children:t("trafficRecord.noRecords")})})})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.perPage")}),e.jsxs(J,{value:`${m.getState().pagination.pageSize}`,onValueChange:o=>{m.setPageSize(Number(o))},children:[e.jsx(W,{className:"h-8 w-[70px]",children:e.jsx(Q,{placeholder:m.getState().pagination.pageSize})}),e.jsx(Y,{side:"top",children:[10,20,30,40,50].map(o=>e.jsx(A,{value:`${o}`,children:o},o))})]}),e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.records")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"flex w-[100px] items-center justify-center text-sm",children:t("trafficRecord.page",{current:m.getState().pagination.pageIndex+1,total:m.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:()=>m.previousPage(),disabled:!m.getCanPreviousPage()||x,children:e.jsx(jg,{className:"h-4 w-4"})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>m.nextPage(),disabled:!m.getCanNextPage()||x,children:e.jsx(vg,{className:"h-4 w-4"})})]})]})]})]})]})]})}function bg({user:s,trigger:n,onSuccess:t}){const{t:r}=M("user"),[a,i]=u.useState(!1),[l,d]=u.useState(""),[x,m]=u.useState(!1),{data:o,isLoading:c}=re({queryKey:["trafficResetHistory",s.id],queryFn:()=>na.getUserHistory(s.id,{limit:10}),enabled:a}),f=async()=>{try{m(!0);const{data:C}=await na.resetUser({user_id:s.id,reason:l.trim()||void 0});C&&(z.success(r("traffic_reset.reset_success")),i(!1),d(""),t?.())}finally{m(!1)}},D=C=>{switch(C){case"manual":return"bg-blue-100 text-blue-800 border-blue-200";case"monthly":return"bg-green-100 text-green-800 border-green-200";case"yearly":return"bg-purple-100 text-purple-800 border-purple-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},S=C=>{switch(C){case"manual":return"bg-orange-100 text-orange-800 border-orange-200";case"cron":return"bg-indigo-100 text-indigo-800 border-indigo-200";case"auto":return"bg-emerald-100 text-emerald-800 border-emerald-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}};return e.jsxs(me,{open:a,onOpenChange:i,children:[e.jsx(ps,{asChild:!0,children:n}),e.jsxs(ce,{className:"max-h-[90vh] max-w-4xl overflow-hidden",children:[e.jsxs(pe,{children:[e.jsxs(ue,{className:"flex items-center gap-2",children:[e.jsx(Yt,{className:"h-5 w-5"}),r("traffic_reset.title")]}),e.jsx($e,{children:r("traffic_reset.description",{email:s.email})})]}),e.jsxs(ft,{defaultValue:"reset",className:"w-full",children:[e.jsxs(lt,{className:"grid w-full grid-cols-2",children:[e.jsxs(Ke,{value:"reset",className:"flex items-center gap-2",children:[e.jsx(Yt,{className:"h-4 w-4"}),r("traffic_reset.tabs.reset")]}),e.jsxs(Ke,{value:"history",className:"flex items-center gap-2",children:[e.jsx(or,{className:"h-4 w-4"}),r("traffic_reset.tabs.history")]})]}),e.jsxs(bs,{value:"reset",className:"space-y-4",children:[e.jsxs(ke,{children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs(Ve,{className:"flex items-center gap-2 text-lg",children:[e.jsx(Ol,{className:"h-5 w-5"}),r("traffic_reset.user_info")]})}),e.jsx(Pe,{className:"space-y-3",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.email")}),e.jsx("p",{className:"font-medium",children:s.email})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.used_traffic")}),e.jsx("p",{className:"font-medium",children:ze(s.total_used)})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.total_traffic")}),e.jsx("p",{className:"font-medium",children:ze(s.transfer_enable)})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.expire_time")}),e.jsx("p",{className:"font-medium",children:s.expired_at?oe(s.expired_at):r("columns.expire_status.permanent")})]})]})})]}),e.jsxs(ke,{className:"border-amber-200 bg-amber-50",children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs(Ve,{className:"flex items-center gap-2 text-lg text-amber-800",children:[e.jsx(Wt,{className:"h-5 w-5"}),r("traffic_reset.warning.title")]})}),e.jsx(Pe,{children:e.jsxs("ul",{className:"space-y-2 text-sm text-amber-700",children:[e.jsxs("li",{children:["• ",r("traffic_reset.warning.irreversible")]}),e.jsxs("li",{children:["• ",r("traffic_reset.warning.reset_to_zero")]}),e.jsxs("li",{children:["• ",r("traffic_reset.warning.logged")]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Je,{htmlFor:"reason",children:r("traffic_reset.reason.label")}),e.jsx(Es,{id:"reason",placeholder:r("traffic_reset.reason.placeholder"),value:l,onChange:C=>d(C.target.value),className:"min-h-[80px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("traffic_reset.reason.optional")})]}),e.jsxs(Ie,{children:[e.jsx(G,{variant:"outline",onClick:()=>i(!1),children:r("common:cancel")}),e.jsx(G,{onClick:f,disabled:x,className:"bg-destructive hover:bg-destructive/90",children:x?e.jsxs(e.Fragment,{children:[e.jsx(ea,{className:"mr-2 h-4 w-4 animate-spin"}),r("traffic_reset.resetting")]}):e.jsxs(e.Fragment,{children:[e.jsx(Yt,{className:"mr-2 h-4 w-4"}),r("traffic_reset.confirm_reset")]})})]})]}),e.jsx(bs,{value:"history",className:"space-y-4",children:c?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(ea,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[o?.data?.user&&e.jsxs(ke,{children:[e.jsx(Fe,{className:"pb-3",children:e.jsx(Ve,{className:"text-lg",children:r("traffic_reset.history.summary")})}),e.jsx(Pe,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.reset_count")}),e.jsx("p",{className:"font-medium",children:o.data.user.reset_count})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.last_reset")}),e.jsx("p",{className:"font-medium",children:o.data.user.last_reset_at?oe(o.data.user.last_reset_at):r("traffic_reset.history.never")})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.next_reset")}),e.jsx("p",{className:"font-medium",children:o.data.user.next_reset_at?oe(o.data.user.next_reset_at):r("traffic_reset.history.no_schedule")})]})]})})]}),e.jsxs(ke,{children:[e.jsxs(Fe,{className:"pb-3",children:[e.jsx(Ve,{className:"text-lg",children:r("traffic_reset.history.records")}),e.jsx(Zs,{children:r("traffic_reset.history.recent_records")})]}),e.jsx(Pe,{children:e.jsx(ht,{className:"h-[300px]",children:o?.data?.history?.length?e.jsx("div",{className:"space-y-3",children:o.data.history.map((C,T)=>e.jsxs("div",{children:[e.jsx("div",{className:"flex items-start justify-between rounded-lg border bg-card p-3",children:e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:D(C.reset_type),children:C.reset_type_name}),e.jsx(q,{variant:"outline",className:S(C.trigger_source),children:C.trigger_source_name})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsxs(Je,{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(On,{className:"h-3 w-3"}),r("traffic_reset.history.reset_time")]}),e.jsx("p",{className:"font-medium",children:oe(C.reset_time)})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.traffic_cleared")}),e.jsx("p",{className:"font-medium text-destructive",children:C.old_traffic.formatted})]})]})]})}),T<o.data.history.length-1&&e.jsx(Ee,{className:"my-2"})]},C.id))}):e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx(or,{className:"mx-auto mb-4 h-12 w-12 opacity-50"}),e.jsx("p",{children:r("traffic_reset.history.no_records")})]})})})]})]})})]})]})]})}function yg({onConfirm:s,children:n,title:t="确认操作",description:r="确定要执行此操作吗?",cancelText:a="取消",confirmText:i="确认",variant:l="default",className:d}){return e.jsxs(Un,{children:[e.jsx(hi,{asChild:!0,children:n}),e.jsxs(Ka,{className:N("sm:max-w-[425px]",d),children:[e.jsxs(Ba,{children:[e.jsx(Wa,{children:t}),e.jsx(Ya,{children:r})]}),e.jsxs(Ga,{children:[e.jsx(Qa,{asChild:!0,children:e.jsx(F,{variant:"outline",children:a})}),e.jsx(Ja,{asChild:!0,children:e.jsx(F,{variant:l,onClick:s,children:i})})]})]})]})}const _g=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"})}),Ng=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"})}),wg=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"})}),Sr=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"})}),Cg=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"})}),Sg=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"})}),kg=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"})}),Tg=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"})}),Dg=(s,n,t,r)=>{const{t:a}=M("user");return[{accessorKey:"is_admin",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l)),size:0},{accessorKey:"is_staff",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l)),size:0},{accessorKey:"id",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.id")}),cell:({row:i})=>e.jsx(q,{variant:"outline",children:i.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.email")}),cell:({row:i})=>{const l=i.original.t||0,d=Date.now()/1e3-l<120,x=Math.floor(Date.now()/1e3-l);let m=d?a("columns.online_status.online"):l===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:oe(l)});if(!d&&l!==0){const D=Math.floor(x/60),S=Math.floor(D/60),C=Math.floor(S/24);C>0?m+=`
|
||
`+a("columns.online_status.offline_duration.days",{count:C}):S>0?m+=`
|
||
`+a("columns.online_status.offline_duration.hours",{count:S}):D>0?m+=`
|
||
`+a("columns.online_status.offline_duration.minutes",{count:D}):m+=`
|
||
`+a("columns.online_status.offline_duration.seconds",{count:x})}const[o,c]=Ir.useState(!1),f=i.original.email;return e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{children:e.jsxs("div",{className:"flex items-center gap-2.5 group",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsx("div",{className:N("size-2.5 rounded-full ring-2 ring-offset-2",d?"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:f}),e.jsx("button",{type:"button",className:N("ml-1 p-1 rounded transition-opacity bg-transparent hover:bg-muted",o?"opacity-100":"opacity-0 pointer-events-none","group-hover:opacity-100 group-hover:pointer-events-auto"),tabIndex:-1,"aria-label":a("columns.actions_menu.copy_email",{defaultValue:"Copy Email"}),onClick:D=>{D.stopPropagation(),Rt(f),z.success(a("common:copy.success"))},style:{lineHeight:0},children:e.jsx(Mn,{className:"h-4 w-4 text-muted-foreground"})})]})}),e.jsx(de,{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:i})=>e.jsx(O,{column:i,title:a("columns.online_count")}),cell:({row:i})=>{const l=i.original.device_limit,d=i.original.online_count||0;return e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(q,{variant:"outline",className:N("min-w-[4rem] justify-center",l!==null&&d>=l?"border-destructive/50 bg-destructive/10 text-destructive":"border-primary/40 bg-primary/5 text-primary/90"),children:[d," / ",l===null?"∞":l]})})}),e.jsx(de,{side:"bottom",children:e.jsx("p",{className:"text-sm",children:l===null?a("columns.device_limit.unlimited"):a("columns.device_limit.limited",{count:l})})})]})})},enableSorting:!0,enableHiding:!1},{accessorKey:"banned",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.status")}),cell:({row:i})=>{const l=i.original.banned;return e.jsx("div",{className:"flex justify-center",children:e.jsx(q,{className:N("min-w-20 justify-center transition-colors",l?"bg-destructive/15 text-destructive hover:bg-destructive/25":"bg-success/15 text-success hover:bg-success/25"),children:a(l?"columns.status_text.banned":"columns.status_text.normal")})})},enableSorting:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l))},{accessorKey:"plan_id",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.subscription")}),cell:({row:i})=>e.jsx("div",{className:"min-w-[10em] break-all",children:i.original?.plan?.name||"-"}),enableSorting:!1,enableHiding:!1},{accessorKey:"group_id",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.group")}),cell:({row:i})=>e.jsx("div",{className:"flex flex-wrap gap-1",children:e.jsx(q,{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:i.original?.group?.name||"-"})}),enableSorting:!1},{accessorKey:"total_used",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.used_traffic")}),cell:({row:i})=>{const l=ze(i.original?.total_used),d=ze(i.original?.transfer_enable),x=i.original?.total_used/i.original?.transfer_enable*100||0;return e.jsx(fe,{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:l}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[x.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",x>90?"bg-destructive":"bg-primary"),style:{width:`${Math.min(x,100)}%`}})})]})}),e.jsx(de,{side:"bottom",children:e.jsxs("p",{className:"text-sm",children:[a("columns.total_traffic"),": ",d]})})]})})}},{accessorKey:"transfer_enable",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.total_traffic")}),cell:({row:i})=>e.jsx("div",{className:"font-medium text-muted-foreground",children:ze(i.original?.transfer_enable)})},{accessorKey:"expired_at",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.expire_time")}),cell:({row:i})=>{const l=i.original.expired_at,d=Date.now()/1e3,x=l!=null&&l<d,m=l!=null?new Date(l*1e3):null,o=m!=null?Math.ceil((m.getTime()-Date.now())/(1e3*60*60*24)):null;return e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{className:"block w-full",children:e.jsx(q,{variant:"outline",className:N("w-full justify-center transition-colors",x?"border-destructive/50 bg-destructive/10 text-destructive":l?"border-success/50 bg-success/10 text-success":"border-primary/40 bg-primary/5 text-primary/90"),children:l==null?a("columns.expire_status.permanent"):oe(l,"YYYY-MM-DD")})}),e.jsx(de,{side:"bottom",className:"space-y-1 p-3",children:l!=null?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[a("columns.expire_time"),": ",oe(l)]}),e.jsx("p",{className:N("text-sm font-medium",x?"text-destructive":"text-success"),children:x?a("columns.expire_status.expired",{days:Math.abs(o??0)}):a("columns.expire_status.remaining",{days:o??0})}),i.original.next_reset_at&&e.jsxs("p",{className:"text-sm",children:[a("columns.next_reset_at"),":"," ",oe(i.original.next_reset_at)]})]}):e.jsx("p",{className:"text-sm font-medium",children:a("columns.expire_status.permanent")})})]})})}},{accessorKey:"balance",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.balance")}),cell:({row:i})=>{const l=xr(i.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:l})]})}},{accessorKey:"commission_balance",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.commission")}),cell:({row:i})=>{const l=xr(i.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:l})]})}},{accessorKey:"created_at",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.register_time")}),cell:({row:i})=>e.jsx("div",{className:"truncate",children:oe(i.original?.created_at)}),size:1e3},{id:"actions",header:({column:i})=>e.jsx(O,{column:i,className:"justify-end",title:a("columns.actions")}),cell:({row:i,table:l})=>e.jsxs(Hs,{modal:!1,children:[e.jsx(Bs,{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(Da,{className:"size-4"})})})}),e.jsxs(zs,{align:"end",className:"min-w-[40px]",children:[e.jsx(Se,{onSelect:d=>{d.preventDefault(),t(i.original),r(!0)},className:"p-0",children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(_g,{className:"mr-2"}),a("columns.actions_menu.edit")]})}),e.jsx(Se,{onSelect:d=>d.preventDefault(),className:"p-0",children:e.jsx(wi,{defaultValues:{email:i.original.email},trigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Ng,{className:"mr-2"}),a("columns.actions_menu.assign_order")]})})}),e.jsx(Se,{onSelect:()=>{Rt(i.original.subscribe_url).then(()=>{z.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(wg,{className:"mr-2"}),a("columns.actions_menu.copy_url")]})}),e.jsxs(Se,{className:"",onSelect:()=>{qs.resetSecret(i.original.id).then(({data:d})=>{d&&z.success("重置成功")})},children:[e.jsx(Sr,{className:"mr-4"}),a("columns.actions_menu.reset_secret")]}),e.jsx(Se,{onSelect:d=>d.preventDefault(),className:"p-0",children:e.jsx(G,{variant:"ghost",className:"h-auto w-full justify-start px-2 py-1.5 font-normal",asChild:!0,children:e.jsxs(tt,{to:`/finance/order?user_id=eq:${i.original.id}`,children:[e.jsx(Cg,{className:"mr-2"}),a("columns.actions_menu.orders")]})})}),e.jsxs(Se,{onSelect:()=>{l.setColumnFilters([{id:"invite_user_id",value:"eq:"+i.original?.id}])},children:[e.jsx(Sg,{className:"mr-4"}),a("columns.actions_menu.invites")]}),e.jsx(Se,{onSelect:d=>d.preventDefault(),className:"p-0",children:e.jsx(Ii,{user_id:i.original?.id,dialogTrigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(kg,{className:"mr-2"}),a("columns.actions_menu.traffic_records")]})})}),e.jsx(Se,{onSelect:d=>d.preventDefault(),className:"p-0",children:e.jsx(bg,{user:i.original,onSuccess:s,trigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Sr,{className:"mr-2"}),a("columns.actions_menu.reset_traffic")]})})}),e.jsx(Se,{onSelect:d=>d.preventDefault(),className:"p-0",children:e.jsx(yg,{title:a("columns.actions_menu.delete_confirm_title"),description:a("columns.actions_menu.delete_confirm_description",{email:i.original.email}),cancelText:a("common:cancel"),confirmText:a("common:confirm"),variant:"destructive",onConfirm:async()=>{try{const{data:d}=await qs.destroy(i.original.id);d&&(z.success(a("common:delete.success")),s())}catch{z.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(Tg,{className:"mr-2"}),a("columns.actions_menu.delete")]})})})]})]})}]},Mi=u.createContext(void 0),Wn=()=>{const s=u.useContext(Mi);if(!s)throw new Error("useUserEdit must be used within an UserEditProvider");return s},Oi=({children:s,refreshData:n})=>{const[t,r]=u.useState(!1),[a,i]=u.useState(null),l={isOpen:t,setIsOpen:r,editingUser:a,setEditingUser:i,refreshData:n};return e.jsx(Mi.Provider,{value:l,children:s})},Fg=h.object({id:h.number().default(0),email:h.string().email().default(""),invite_user_email:h.string().email().nullable().optional().default(null),password:h.string().optional().nullable().default(null),balance:h.coerce.number().default(0),commission_balance:h.coerce.number().default(0),u:h.coerce.number().default(0),d:h.coerce.number().default(0),transfer_enable:h.number().default(0),expired_at:h.number().nullable().default(null),plan_id:h.number().nullable().default(null),banned:h.boolean().default(!1),commission_type:h.number().default(0),commission_rate:h.number().nullable().default(null),discount:h.number().nullable().default(null),speed_limit:h.number().nullable().default(null),device_limit:h.number().nullable().default(null),is_admin:h.boolean().default(!1),is_staff:h.boolean().default(!1),remarks:h.string().nullable().default(null)});function zi(){const{t:s}=M("user"),{isOpen:n,setIsOpen:t,editingUser:r,refreshData:a}=Wn(),[i,l]=u.useState(!1),[d,x]=u.useState([]),m=we({resolver:Te(Fg)});return u.useEffect(()=>{n&&ys.getList().then(({data:o})=>{x(o)})},[n]),u.useEffect(()=>{if(r){const o=r.invite_user?.email,{invite_user:c,...f}=r;m.reset({...f,invite_user_email:o||null,password:null,u:f.u?(f.u/1024/1024/1024).toFixed(3):"",d:f.d?(f.d/1024/1024/1024).toFixed(3):""})}},[r,m]),e.jsx(Gn,{open:n,onOpenChange:t,children:e.jsxs(en,{className:"max-w-[90%] space-y-4",children:[e.jsxs(sn,{children:[e.jsx(tn,{children:s("edit.title")}),e.jsx(an,{})]}),e.jsxs(De,{...m,children:[e.jsx(v,{control:m.control,name:"email",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.email")}),e.jsx(y,{children:e.jsx(k,{...o,placeholder:s("edit.form.email_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(P,{...o})]})}),e.jsx(v,{control:m.control,name:"invite_user_email",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.inviter_email")}),e.jsx(y,{children:e.jsx(k,{value:o.value||"",onChange:c=>o.onChange(c.target.value?c.target.value:null),placeholder:s("edit.form.inviter_email_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(P,{...o})]})}),e.jsx(v,{control:m.control,name:"password",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.password")}),e.jsx(y,{children:e.jsx(k,{type:"password",value:o.value||"",onChange:o.onChange,placeholder:s("edit.form.password_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(P,{...o})]})}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsx(v,{control:m.control,name:"balance",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.balance")}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:o.value||"",onChange:o.onChange,placeholder:s("edit.form.balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(P,{...o})]})}),e.jsx(v,{control:m.control,name:"commission_balance",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.commission_balance")}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:o.value||"",onChange:o.onChange,placeholder:s("edit.form.commission_balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(P,{...o})]})}),e.jsx(v,{control:m.control,name:"u",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.upload")}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",step:"any",value:o.value??"",onChange:c=>o.onChange(c.target.value),placeholder:s("edit.form.upload_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{...o})]})}),e.jsx(v,{control:m.control,name:"d",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.download")}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",step:"any",value:o.value??"",onChange:c=>o.onChange(c.target.value),placeholder:s("edit.form.download_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{...o})]})})]}),e.jsx(v,{control:m.control,name:"transfer_enable",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.total_traffic")}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:o.value/1024/1024/1024||"",onChange:c=>o.onChange(parseInt(c.target.value)*1024*1024*1024),placeholder:s("edit.form.total_traffic_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{})]})}),e.jsx(v,{control:m.control,name:"expired_at",render:({field:o})=>e.jsxs(j,{className:"flex flex-col",children:[e.jsx(b,{children:s("edit.form.expire_time")}),e.jsxs(ls,{open:i,onOpenChange:l,children:[e.jsx(is,{asChild:!0,children:e.jsx(y,{children:e.jsxs(F,{type:"button",variant:"outline",className:N("w-full pl-3 text-left font-normal",!o.value&&"text-muted-foreground"),onClick:()=>l(!0),children:[o.value?oe(o.value):e.jsx("span",{children:s("edit.form.expire_time_placeholder")}),e.jsx(Cs,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",side:"top",sideOffset:4,onInteractOutside:c=>{c.preventDefault()},onEscapeKeyDown:c=>{c.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(F,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{o.onChange(null),l(!1)},children:s("edit.form.expire_time_permanent")}),e.jsx(F,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const c=new Date;c.setMonth(c.getMonth()+1),c.setHours(23,59,59,999),o.onChange(Math.floor(c.getTime()/1e3)),l(!1)},children:s("edit.form.expire_time_1month")}),e.jsx(F,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const c=new Date;c.setMonth(c.getMonth()+3),c.setHours(23,59,59,999),o.onChange(Math.floor(c.getTime()/1e3)),l(!1)},children:s("edit.form.expire_time_3months")})]}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Ss,{mode:"single",selected:o.value?new Date(o.value*1e3):void 0,onSelect:c=>{if(c){const f=new Date(o.value?o.value*1e3:Date.now());c.setHours(f.getHours(),f.getMinutes(),f.getSeconds()),o.onChange(Math.floor(c.getTime()/1e3))}},disabled:c=>c<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:s("edit.form.expire_time_specific")}),e.jsx(F,{type:"button",variant:"ghost",size:"sm",onClick:()=>{const c=new Date;c.setHours(23,59,59,999),o.onChange(Math.floor(c.getTime()/1e3))},className:"h-6 px-2 text-xs",children:s("edit.form.expire_time_today")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{type:"datetime-local",step:"1",value:oe(o.value,"YYYY-MM-DDTHH:mm:ss"),onChange:c=>{const f=new Date(c.target.value);isNaN(f.getTime())||o.onChange(Math.floor(f.getTime()/1e3))},className:"flex-1"}),e.jsx(F,{type:"button",variant:"outline",onClick:()=>l(!1),children:s("edit.form.expire_time_confirm")})]})]})]})})]}),e.jsx(P,{})]})}),e.jsx(v,{control:m.control,name:"plan_id",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.subscription")}),e.jsx(y,{children:e.jsxs(J,{value:o.value!==null?String(o.value):"null",onValueChange:c=>o.onChange(c==="null"?null:parseInt(c)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:s("edit.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"null",children:s("edit.form.subscription_none")}),d.map(c=>e.jsx(A,{value:String(c.id),children:c.name},c.id))]})]})})]})}),e.jsx(v,{control:m.control,name:"banned",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.account_status")}),e.jsx(y,{children:e.jsxs(J,{value:o.value.toString(),onValueChange:c=>o.onChange(c==="true"),children:[e.jsx(W,{children:e.jsx(Q,{})}),e.jsxs(Y,{children:[e.jsx(A,{value:"true",children:s("columns.status_text.banned")}),e.jsx(A,{value:"false",children:s("columns.status_text.normal")})]})]})})]})}),e.jsx(v,{control:m.control,name:"commission_type",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.commission_type")}),e.jsx(y,{children:e.jsxs(J,{value:o.value.toString(),onValueChange:c=>o.onChange(parseInt(c)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:s("edit.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:s("edit.form.commission_type_system")}),e.jsx(A,{value:"1",children:s("edit.form.commission_type_cycle")}),e.jsx(A,{value:"2",children:s("edit.form.commission_type_onetime")})]})]})})]})}),e.jsx(v,{control:m.control,name:"commission_rate",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.commission_rate")}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:o.value||"",onChange:c=>o.onChange(parseInt(c.currentTarget.value)||null),placeholder:s("edit.form.commission_rate_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})})]})}),e.jsx(v,{control:m.control,name:"discount",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.discount")}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:o.value||"",onChange:c=>o.onChange(parseInt(c.currentTarget.value)||null),placeholder:s("edit.form.discount_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})}),e.jsx(P,{})]})}),e.jsx(v,{control:m.control,name:"speed_limit",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.speed_limit")}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:o.value||"",onChange:c=>o.onChange(parseInt(c.currentTarget.value)||null),placeholder:s("edit.form.speed_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"Mbps"})]})}),e.jsx(P,{})]})}),e.jsx(v,{control:m.control,name:"device_limit",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.device_limit")}),e.jsx(y,{children:e.jsxs("div",{className:"flex",children:[e.jsx(k,{type:"number",value:o.value||"",onChange:c=>o.onChange(parseInt(c.currentTarget.value)||null),placeholder:s("edit.form.device_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"台"})]})}),e.jsx(P,{})]})}),e.jsx(v,{control:m.control,name:"is_admin",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.is_admin")}),e.jsx("div",{className:"py-2",children:e.jsx(y,{children:e.jsx(X,{checked:o.value,onCheckedChange:c=>o.onChange(c)})})}),e.jsx(P,{})]})}),e.jsx(v,{control:m.control,name:"is_staff",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.is_staff")}),e.jsx("div",{className:"py-2",children:e.jsx(y,{children:e.jsx(X,{checked:o.value,onCheckedChange:c=>o.onChange(c)})})})]})}),e.jsx(v,{control:m.control,name:"remarks",render:({field:o})=>e.jsxs(j,{children:[e.jsx(b,{children:s("edit.form.remarks")}),e.jsx(y,{children:e.jsx(Es,{className:"h-24",value:o.value||"",onChange:c=>o.onChange(c.currentTarget.value??null),placeholder:s("edit.form.remarks_placeholder")})}),e.jsx(P,{})]})}),e.jsxs(Ri,{children:[e.jsx(F,{variant:"outline",onClick:()=>t(!1),children:s("edit.form.cancel")}),e.jsx(F,{type:"submit",onClick:()=>{m.handleSubmit(o=>{const c={id:o.id};m.formState.dirtyFields.u&&(c.u=Math.round(parseFloat(o.u)*1024*1024*1024)),m.formState.dirtyFields.d&&(c.d=Math.round(parseFloat(o.d)*1024*1024*1024)),Object.keys(o).forEach(f=>{f!=="u"&&f!=="d"&&f!=="id"&&m.formState.dirtyFields[f]&&(c[f]=o[f])}),qs.update(c).then(({data:f})=>{f&&(z.success(s("edit.form.success")),t(!1),a())})})()},children:s("edit.form.submit")})]})]})]})})}function Pg(){const[s]=Vl(),[n,t]=u.useState({}),[r,a]=u.useState({is_admin:!1,is_staff:!1}),[i,l]=u.useState([]),[d,x]=u.useState([]),[m,o]=u.useState({pageIndex:0,pageSize:20});u.useEffect(()=>{const g=s.get("email");g&&l(p=>p.some(R=>R.id==="email")?p:[...p,{id:"email",value:g}])},[s]);const{refetch:c,data:f,isLoading:D}=re({queryKey:["userList",m,i,d],queryFn:()=>qs.getList({pageSize:m.pageSize,current:m.pageIndex+1,filter:i,sort:d})}),[S,C]=u.useState([]),[T,w]=u.useState([]);u.useEffect(()=>{jt.getList().then(({data:g})=>{C(g)}),ys.getList().then(({data:g})=>{w(g)})},[]);const E=S.map(g=>({label:g.name,value:g.id})),_=T.map(g=>({label:g.name,value:g.id}));return e.jsxs(Oi,{refreshData:c,children:[e.jsx(Lg,{data:f?.data??[],rowCount:f?.total??0,sorting:d,setSorting:x,columnVisibility:r,setColumnVisibility:a,rowSelection:n,setRowSelection:t,columnFilters:i,setColumnFilters:l,pagination:m,setPagination:o,refetch:c,serverGroupList:S,permissionGroups:E,subscriptionPlans:_,isLoading:D}),e.jsx(zi,{})]})}function Lg({data:s,rowCount:n,sorting:t,setSorting:r,columnVisibility:a,setColumnVisibility:i,rowSelection:l,setRowSelection:d,columnFilters:x,setColumnFilters:m,pagination:o,setPagination:c,refetch:f,serverGroupList:D,permissionGroups:S,subscriptionPlans:C,isLoading:T}){const{setIsOpen:w,setEditingUser:E}=Wn(),_=Be({data:s,columns:Dg(f,D,E,w),state:{sorting:t,columnVisibility:a,rowSelection:l,columnFilters:x,pagination:o},rowCount:n,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:d,onSortingChange:r,onColumnFiltersChange:m,onColumnVisibilityChange:i,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),onPaginationChange:c,getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),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.jsxs("div",{className:"space-y-4",children:[e.jsx(fg,{table:_,refetch:f,serverGroupList:D,permissionGroups:S,subscriptionPlans:C}),e.jsx(ts,{table:_,isLoading:T})]})}function Rg(){const{t:s}=M("user");return e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(Pg,{})})})]})]})}const Eg=Object.freeze(Object.defineProperty({__proto__:null,default:Rg},Symbol.toStringTag,{value:"Module"})),Vg=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 Ig({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(ft,{defaultValue:s.getColumn("status")?.getFilterValue(),onValueChange:t=>s.getColumn("status")?.setFilterValue(t),children:e.jsxs(lt,{className:"grid w-full grid-cols-2",children:[e.jsx(Ke,{value:"0",children:n("status.pending")}),e.jsx(Ke,{value:"1",children:n("status.closed")})]})}),s.getColumn("level")&&e.jsx(Ea,{column:s.getColumn("level"),title:n("columns.level"),options:[{label:n("level.low"),value:ms.LOW,icon:Vg,color:"gray"},{label:n("level.medium"),value:ms.MIDDLE,icon:Ei,color:"yellow"},{label:n("level.high"),value:ms.HIGH,icon:Vi,color:"red"}]})]})})}function Mg(){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 Og=gt("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"}}),$i=u.forwardRef(({className:s,variant:n,layout:t,children:r,...a},i)=>e.jsx("div",{className:N(Og({variant:n,layout:t,className:s}),"relative group"),ref:i,...a,children:u.Children.map(r,l=>u.isValidElement(l)&&typeof l.type!="string"?u.cloneElement(l,{variant:n,layout:t}):l)}));$i.displayName="ChatBubble";const zg=gt("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"}}),Ai=u.forwardRef(({className:s,variant:n,layout:t,isLoading:r=!1,children:a,...i},l)=>e.jsx("div",{className:N(zg({variant:n,layout:t,className:s}),"break-words max-w-full whitespace-pre-wrap"),ref:l,...i,children:r?e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(Mg,{})}):a}));Ai.displayName="ChatBubbleMessage";const $g=u.forwardRef(({variant:s,className:n,children:t,...r},a)=>e.jsx("div",{ref:a,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),...r,children:t}));$g.displayName="ChatBubbleActionWrapper";const qi=u.forwardRef(({className:s,...n},t)=>e.jsx(Es,{autoComplete:"off",ref:t,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}));qi.displayName="ChatInput";const Hi=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"})}),Ui=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"})}),kr=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"})}),Ag=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"})}),qg=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"})}),Hg=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 Ug(){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(be,{className:"h-8 w-3/4"}),e.jsx(be,{className:"h-4 w-1/2"})]}),e.jsx("div",{className:"flex-1 space-y-4",children:[1,2,3].map(s=>e.jsx(be,{className:"h-20 w-2/3"},s))})]})}function Kg(){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(be,{className:"h-5 w-4/5"}),e.jsx(be,{className:"h-4 w-2/3"}),e.jsx(be,{className:"h-3 w-1/2"})]},s))})}function Bg({ticket:s,isActive:n,onClick:t}){const{t:r}=M("ticket"),a=i=>{switch(i){case ms.HIGH:return"bg-red-50 text-red-600 border-red-200";case ms.MIDDLE:return"bg-yellow-50 text-yellow-600 border-yellow-200";case ms.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:t,children:[e.jsxs("div",{className:"flex max-w-[280px] items-center justify-between gap-2",children:[e.jsx("h4",{className:"flex-1 truncate font-medium",children:s.subject}),e.jsx(q,{variant:s.status===st.CLOSED?"secondary":"default",className:"shrink-0",children:s.status===st.CLOSED?r("status.closed"):r("status.processing")})]}),e.jsx("div",{className:"mt-1 max-w-[280px] truncate text-sm text-muted-foreground",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:oe(s.updated_at)}),e.jsx("div",{className:N("rounded-full border px-2 py-0.5 text-xs font-medium",a(s.level)),children:r(`level.${s.level===ms.LOW?"low":s.level===ms.MIDDLE?"medium":"high"}`)})]})]})}function Gg({ticketId:s,dialogTrigger:n}){const{t}=M("ticket"),r=Gs(),a=u.useRef(null),i=u.useRef(null),[l,d]=u.useState(!1),[x,m]=u.useState(""),[o,c]=u.useState(!1),[f,D]=u.useState(s),[S,C]=u.useState(""),[T,w]=u.useState(!1),{setIsOpen:E,setEditingUser:_}=Wn(),{data:g,isLoading:p,refetch:V}=re({queryKey:["tickets",l],queryFn:()=>l?Ft.getList({filter:[{id:"status",value:[st.OPENING]}]}):Promise.resolve(null),enabled:l}),{data:R,refetch:L,isLoading:K}=re({queryKey:["ticket",f,l],queryFn:()=>l?Ft.getInfo(f):Promise.resolve(null),refetchInterval:l?5e3:!1,retry:3}),Z=R?.data,ae=(g?.data||[]).filter(le=>le.subject.toLowerCase().includes(S.toLowerCase())||le.user?.email.toLowerCase().includes(S.toLowerCase())),H=(le="smooth")=>{if(a.current){const{scrollHeight:Ts,clientHeight:Ns}=a.current;a.current.scrollTo({top:Ts-Ns,behavior:le})}};u.useEffect(()=>{if(!l)return;const le=requestAnimationFrame(()=>{H("instant"),setTimeout(()=>H(),1e3)});return()=>{cancelAnimationFrame(le)}},[l,Z?.messages]);const ee=async()=>{const le=x.trim();!le||o||(c(!0),Ft.reply({id:f,message:le}).then(()=>{m(""),L(),H(),setTimeout(()=>{i.current?.focus()},0)}).finally(()=>{c(!1)}))},je=async()=>{Ft.close(f).then(()=>{z.success(t("actions.close_success")),L(),V()})},ds=()=>{Z?.user&&r("/finance/order?user_id="+Z.user.id)},Me=Z?.status===st.CLOSED;return e.jsxs(me,{open:l,onOpenChange:d,children:[e.jsx(ps,{asChild:!0,children:n??e.jsx(G,{variant:"outline",children:t("actions.view_ticket")})}),e.jsxs(ce,{className:"flex h-[90vh] max-w-6xl flex-col gap-0 p-0",children:[e.jsx(ue,{}),e.jsxs("div",{className:"flex h-full",children:[e.jsx(G,{variant:"ghost",size:"icon",className:"absolute left-2 top-2 z-50 md:hidden",onClick:()=>w(!T),children:e.jsx(kr,{className:N("h-4 w-4 transition-transform",!T&&"rotate-180")})}),e.jsxs("div",{className:N("absolute inset-y-0 left-0 z-40 flex flex-col border-r bg-background transition-transform duration-200 ease-in-out md:relative",T?"-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:t("list.title")}),e.jsx(G,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 md:flex",onClick:()=>w(!T),children:e.jsx(kr,{className:N("h-4 w-4 transition-transform",!T&&"rotate-180")})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Ag,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 transform text-muted-foreground"}),e.jsx(k,{placeholder:t("list.search_placeholder"),value:S,onChange:le=>C(le.target.value),className:"pl-8"})]})]}),e.jsx(ht,{className:"flex-1",children:e.jsx("div",{className:"w-full",children:p?e.jsx(Kg,{}):ae.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-4 text-muted-foreground",children:t(S?"list.no_search_results":"list.no_tickets")}):ae.map(le=>e.jsx(Bg,{ticket:le,isActive:le.id===f,onClick:()=>{D(le.id),window.innerWidth<768&&w(!0)}},le.id))})})]}),e.jsxs("div",{className:"relative flex flex-1 flex-col",children:[!T&&e.jsx("div",{className:"absolute inset-0 z-30 bg-black/20 md:hidden",onClick:()=>w(!0)}),K?e.jsx(Ug,{}):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:Z?.subject}),e.jsx(q,{variant:Me?"secondary":"default",children:t(Me?"status.closed":"status.processing")}),!Me&&e.jsx(_s,{title:t("actions.close_confirm_title"),description:t("actions.close_confirm_description"),confirmText:t("actions.close_confirm_button"),variant:"destructive",onConfirm:je,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"gap-1 text-muted-foreground hover:text-destructive",children:[e.jsx(Hi,{className:"h-4 w-4"}),t("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(Ra,{className:"h-4 w-4"}),e.jsx("span",{children:Z?.user?.email})]}),e.jsx(Ee,{orientation:"vertical",className:"h-4"}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Ui,{className:"h-4 w-4"}),e.jsxs("span",{children:[t("detail.created_at")," ",oe(Z?.created_at)]})]}),e.jsx(Ee,{orientation:"vertical",className:"h-4"}),e.jsx(q,{variant:"outline",children:Z?.level!=null&&t(`level.${Z.level===ms.LOW?"low":Z.level===ms.MIDDLE?"medium":"high"}`)})]})]}),Z?.user&&e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.user_info"),onClick:()=>{_(Z.user),E(!0)},children:e.jsx(Ra,{className:"h-4 w-4"})}),e.jsx(Ii,{user_id:Z.user.id,dialogTrigger:e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.traffic_records"),children:e.jsx(qg,{className:"h-4 w-4"})})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.order_records"),onClick:ds,children:e.jsx(Hg,{className:"h-4 w-4"})})]})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{ref:a,className:"h-full space-y-4 overflow-y-auto p-6",children:Z?.messages?.length===0?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:t("detail.no_messages")}):Z?.messages?.map(le=>e.jsx($i,{variant:le.is_from_admin?"sent":"received",className:le.is_from_admin?"ml-auto":"mr-auto",children:e.jsx(Ai,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"whitespace-pre-wrap break-words",children:le.message}),e.jsx("div",{className:"text-right",children:e.jsx("time",{className:"text-[10px] text-muted-foreground",children:oe(le.created_at)})})]})})},le.id))})}),e.jsx("div",{className:"border-t p-4",children:e.jsxs("div",{className:"relative flex items-center space-x-2",children:[e.jsx(qi,{ref:i,disabled:Me||o,placeholder:t(Me?"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:le=>m(le.target.value),onKeyDown:le=>{le.key==="Enter"&&!le.shiftKey&&(le.preventDefault(),ee())}}),e.jsx(G,{disabled:Me||o||!x.trim(),onClick:ee,children:t(o?"detail.input.sending":"detail.input.send")})]})})]})]})]})]})]})}const Wg=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"})}),Yg=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"})}),Jg=s=>{const{t:n}=M("ticket");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.id")}),cell:({row:t})=>e.jsx(q,{variant:"outline",children:t.getValue("id")}),enableSorting:!1,enableHiding:!1},{accessorKey:"subject",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.subject")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Wg,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"max-w-[500px] truncate font-medium",children:t.getValue("subject")})]}),enableSorting:!1,enableHiding:!1,size:4e3},{accessorKey:"level",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.level")}),cell:({row:t})=>{const r=t.getValue("level"),a=r===ms.LOW?"default":r===ms.MIDDLE?"secondary":"destructive";return e.jsx(q,{variant:a,className:"whitespace-nowrap",children:n(`level.${r===ms.LOW?"low":r===ms.MIDDLE?"medium":"high"}`)})},filterFn:(t,r,a)=>a.includes(t.getValue(r))},{accessorKey:"status",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.status")}),cell:({row:t})=>{const r=t.getValue("status"),a=t.original.reply_status,i=r===st.CLOSED?n("status.closed"):n(a===0?"status.replied":"status.pending"),l=r===st.CLOSED?"default":a===0?"secondary":"destructive";return e.jsx(q,{variant:l,className:"whitespace-nowrap",children:i})}},{accessorKey:"updated_at",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.updated_at")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[e.jsx(Ui,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:oe(t.getValue("updated_at"))})]}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(t.getValue("created_at"))}),enableSorting:!0,meta:{isFlexGrow:!0}},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>{const r=t.original.status!==st.CLOSED;return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Gg,{ticketId:t.original.id,dialogTrigger:e.jsx(G,{variant:"ghost",size:"icon",className:"h-8 w-8",title:n("actions.view_details"),children:e.jsx(Yg,{className:"h-4 w-4"})})}),r&&e.jsx(_s,{title:n("actions.close_confirm_title"),description:n("actions.close_confirm_description"),confirmText:n("actions.close_confirm_button"),variant:"destructive",onConfirm:async()=>{Ft.close(t.original.id).then(()=>{z.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(Hi,{className:"h-4 w-4"})})})]})}}]};function Qg(){const[s,n]=u.useState({}),[t,r]=u.useState({}),[a,i]=u.useState([{id:"status",value:"0"}]),[l,d]=u.useState([]),[x,m]=u.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=re({queryKey:["orderList",x,a,l],queryFn:()=>Ft.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:a,sort:l})}),f=Be({data:c?.data??[],columns:Jg(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:x},rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),onPaginationChange:m,getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ig,{table:f,refetch:o}),e.jsx(ts,{table:f,showPagination:!0})]})}function Xg(){const{t:s}=M("ticket");return e.jsxs(Oi,{refreshData:()=>{},children:[e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{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(Qg,{})})]})]}),e.jsx(zi,{})]})}const Zg=Object.freeze(Object.defineProperty({__proto__:null,default:Xg},Symbol.toStringTag,{value:"Module"}));function ep({table:s,refetch:n}){const{t}=M("user"),r=s.getState().columnFilters.length>0,[a,i]=u.useState(),[l,d]=u.useState(),[x,m]=u.useState(!1),o=[{value:"monthly",label:t("traffic_reset_logs.filters.reset_types.monthly")},{value:"first_day_month",label:t("traffic_reset_logs.filters.reset_types.first_day_month")},{value:"yearly",label:t("traffic_reset_logs.filters.reset_types.yearly")},{value:"first_day_year",label:t("traffic_reset_logs.filters.reset_types.first_day_year")},{value:"manual",label:t("traffic_reset_logs.filters.reset_types.manual")}],c=[{value:"auto",label:t("traffic_reset_logs.filters.trigger_sources.auto")},{value:"manual",label:t("traffic_reset_logs.filters.trigger_sources.manual")},{value:"cron",label:t("traffic_reset_logs.filters.trigger_sources.cron")}],f=()=>{let T=s.getState().columnFilters.filter(w=>w.id!=="date_range");(a||l)&&T.push({id:"date_range",value:{start:a?Le(a,"yyyy-MM-dd"):null,end:l?Le(l,"yyyy-MM-dd"):null}}),s.setColumnFilters(T)},D=async()=>{try{m(!0);const T=s.getState().columnFilters.reduce((L,K)=>{if(K.value)if(K.id==="date_range"){const Z=K.value;Z.start&&(L.start_date=Z.start),Z.end&&(L.end_date=Z.end)}else L[K.id]=K.value;return L},{}),E=(await na.getLogs({...T,page:1,per_page:1e4})).data.map(L=>({ID:L.id,用户邮箱:L.user_email,用户ID:L.user_id,重置类型:L.reset_type_name,触发源:L.trigger_source_name,清零流量:L.old_traffic.formatted,"上传流量(GB)":(L.old_traffic.upload/1024**3).toFixed(2),"下载流量(GB)":(L.old_traffic.download/1024**3).toFixed(2),重置时间:Le(new Date(L.reset_time),"yyyy-MM-dd HH:mm:ss"),记录时间:Le(new Date(L.created_at),"yyyy-MM-dd HH:mm:ss"),原因:L.reason||""})),_=Object.keys(E[0]||{}),g=[_.join(","),...E.map(L=>_.map(K=>{const Z=L[K];return typeof Z=="string"&&Z.includes(",")?`"${Z}"`:Z}).join(","))].join(`
|
||
`),p=new Blob([g],{type:"text/csv;charset=utf-8;"}),V=document.createElement("a"),R=URL.createObjectURL(p);V.setAttribute("href",R),V.setAttribute("download",`traffic-reset-logs-${Le(new Date,"yyyy-MM-dd")}.csv`),V.style.visibility="hidden",document.body.appendChild(V),V.click(),document.body.removeChild(V),z.success(t("traffic_reset_logs.actions.export_success"))}catch(C){console.error("导出失败:",C),z.error(t("traffic_reset_logs.actions.export_failed"))}finally{m(!1)}},S=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.search_user")}),e.jsx(k,{placeholder:t("traffic_reset_logs.filters.search_user"),value:s.getColumn("user_email")?.getFilterValue()??"",onChange:C=>s.getColumn("user_email")?.setFilterValue(C.target.value),className:"h-9"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.reset_type")}),e.jsxs(J,{value:s.getColumn("reset_type")?.getFilterValue()??"",onValueChange:C=>s.getColumn("reset_type")?.setFilterValue(C==="all"?"":C),children:[e.jsx(W,{className:"h-9",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.reset_type")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"all",children:t("traffic_reset_logs.filters.all_types")}),o.map(C=>e.jsx(A,{value:C.value,children:C.label},C.value))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.trigger_source")}),e.jsxs(J,{value:s.getColumn("trigger_source")?.getFilterValue()??"",onValueChange:C=>s.getColumn("trigger_source")?.setFilterValue(C==="all"?"":C),children:[e.jsx(W,{className:"h-9",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.trigger_source")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"all",children:t("traffic_reset_logs.filters.all_sources")}),c.map(C=>e.jsx(A,{value:C.value,children:C.label},C.value))]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.start_date")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(F,{variant:"outline",className:N("h-9 w-full justify-start text-left font-normal",!a&&"text-muted-foreground"),children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),a?Le(a,"MM-dd"):t("traffic_reset_logs.filters.start_date")]})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:a,onSelect:i,initialFocus:!0})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.end_date")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(F,{variant:"outline",className:N("h-9 w-full justify-start text-left font-normal",!l&&"text-muted-foreground"),children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),l?Le(l,"MM-dd"):t("traffic_reset_logs.filters.end_date")]})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:l,onSelect:d,initialFocus:!0})})]})]})]}),(a||l)&&e.jsxs(F,{variant:"outline",className:"w-full",onClick:f,children:[e.jsx(cr,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.apply_date")]}),r&&e.jsxs(F,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),i(void 0),d(void 0)},className:"w-full",children:[t("traffic_reset_logs.filters.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between md:hidden",children:[e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(Gn,{children:[e.jsx(Pi,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",className:"h-8",children:[e.jsx(Dd,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.reset_type"),r&&e.jsx("div",{className:"ml-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-xs text-primary-foreground",children:s.getState().columnFilters.length})]})}),e.jsxs(en,{side:"bottom",className:"h-[85vh]",children:[e.jsxs(sn,{className:"mb-4",children:[e.jsx(tn,{children:t("traffic_reset_logs.filters.filter_title")}),e.jsx(an,{children:t("traffic_reset_logs.filters.filter_description")})]}),e.jsx("div",{className:"max-h-[calc(85vh-120px)] overflow-y-auto",children:e.jsx(S,{})})]})]})}),e.jsxs(F,{variant:"outline",size:"sm",className:"h-8",onClick:D,disabled:x,children:[e.jsx(sa,{className:"mr-2 h-4 w-4"}),t(x?"traffic_reset_logs.actions.exporting":"traffic_reset_logs.actions.export")]})]}),e.jsxs("div",{className:"hidden items-center justify-between md:flex",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(k,{placeholder:t("traffic_reset_logs.filters.search_user"),value:s.getColumn("user_email")?.getFilterValue()??"",onChange:C=>s.getColumn("user_email")?.setFilterValue(C.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(J,{value:s.getColumn("reset_type")?.getFilterValue()??"",onValueChange:C=>s.getColumn("reset_type")?.setFilterValue(C==="all"?"":C),children:[e.jsx(W,{className:"h-8 w-[180px]",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.reset_type")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"all",children:t("traffic_reset_logs.filters.all_types")}),o.map(C=>e.jsx(A,{value:C.value,children:C.label},C.value))]})]}),e.jsxs(J,{value:s.getColumn("trigger_source")?.getFilterValue()??"",onValueChange:C=>s.getColumn("trigger_source")?.setFilterValue(C==="all"?"":C),children:[e.jsx(W,{className:"h-8 w-[180px]",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.trigger_source")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"all",children:t("traffic_reset_logs.filters.all_sources")}),c.map(C=>e.jsx(A,{value:C.value,children:C.label},C.value))]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",className:N("h-8 w-[140px] justify-start text-left font-normal",!a&&"text-muted-foreground"),children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),a?Le(a,"yyyy-MM-dd"):t("traffic_reset_logs.filters.start_date")]})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:a,onSelect:i,initialFocus:!0})})]}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",className:N("h-8 w-[140px] justify-start text-left font-normal",!l&&"text-muted-foreground"),children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),l?Le(l,"yyyy-MM-dd"):t("traffic_reset_logs.filters.end_date")]})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:l,onSelect:d,initialFocus:!0})})]}),(a||l)&&e.jsxs(F,{variant:"outline",size:"sm",className:"h-8",onClick:f,children:[e.jsx(cr,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.apply_date")]})]}),r&&e.jsxs(F,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),i(void 0),d(void 0)},className:"h-8 px-2 lg:px-3",children:[t("traffic_reset_logs.filters.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(F,{variant:"outline",size:"sm",className:"h-8 border-dashed",onClick:D,disabled:x,children:[e.jsx(sa,{className:"mr-2 h-4 w-4"}),t(x?"traffic_reset_logs.actions.exporting":"traffic_reset_logs.actions.export")]})})]})]})}const sp=()=>{const{t:s}=M("user"),n=a=>{switch(a){case"manual":return"bg-blue-100 text-blue-800 border-blue-200";case"monthly":return"bg-green-100 text-green-800 border-green-200";case"yearly":return"bg-purple-100 text-purple-800 border-purple-200";case"first_day_month":return"bg-orange-100 text-orange-800 border-orange-200";case"first_day_year":return"bg-indigo-100 text-indigo-800 border-indigo-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},t=a=>{switch(a){case"manual":return"bg-orange-100 text-orange-800 border-orange-200";case"cron":return"bg-indigo-100 text-indigo-800 border-indigo-200";case"auto":return"bg-emerald-100 text-emerald-800 border-emerald-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},r=a=>{switch(a){case"manual":return e.jsx(ka,{className:"h-3 w-3"});case"cron":return e.jsx(Pd,{className:"h-3 w-3"});case"auto":return e.jsx(Fd,{className:"h-3 w-3"});default:return e.jsx(ka,{className:"h-3 w-3"})}};return[{accessorKey:"id",header:({column:a})=>e.jsx(O,{column:a,title:s("traffic_reset_logs.columns.id"),className:"w-[60px]"}),cell:({row:a})=>e.jsx("div",{className:"w-[60px]",children:e.jsx(q,{variant:"outline",className:"text-xs",children:a.original.id})}),enableSorting:!0,enableHiding:!0,size:60},{accessorKey:"user_email",header:({column:a})=>e.jsx(O,{column:a,title:s("traffic_reset_logs.columns.user"),className:"min-w-[200px]"}),cell:({row:a})=>e.jsxs("div",{className:"flex min-w-[200px] items-start gap-2",children:[e.jsx(Ol,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:a.original.user_email}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",a.original.user_id]})]})]}),enableSorting:!1,enableHiding:!1,size:100},{accessorKey:"trigger_source",header:({column:a})=>e.jsx(O,{column:a,title:s("traffic_reset_logs.columns.trigger_source"),className:"w-[120px]"}),cell:({row:a})=>e.jsx("div",{className:"w-[120px]",children:e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx("div",{className:"cursor-pointer",children:e.jsxs(q,{variant:"outline",className:N("flex items-center gap-1.5 border text-xs",t(a.original.trigger_source)),children:[r(a.original.trigger_source),e.jsx("span",{className:"truncate",children:a.original.trigger_source_name})]})})}),e.jsx(de,{side:"bottom",className:"max-w-[200px]",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm font-medium",children:a.original.trigger_source_name}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[a.original.trigger_source==="manual"&&s("traffic_reset_logs.trigger_descriptions.manual"),a.original.trigger_source==="cron"&&s("traffic_reset_logs.trigger_descriptions.cron"),a.original.trigger_source==="auto"&&s("traffic_reset_logs.trigger_descriptions.auto"),!["manual","cron","auto"].includes(a.original.trigger_source)&&s("traffic_reset_logs.trigger_descriptions.other")]})]})})]})})}),enableSorting:!0,enableHiding:!1,filterFn:(a,i,l)=>l.includes(a.getValue(i)),size:120},{accessorKey:"reset_type",header:({column:a})=>e.jsx(O,{column:a,title:s("traffic_reset_logs.columns.reset_type"),className:"w-[120px]"}),cell:({row:a})=>e.jsx("div",{className:"w-[120px]",children:e.jsx(q,{className:N("border text-xs",n(a.original.reset_type)),children:e.jsx("span",{className:"truncate",children:a.original.reset_type_name})})}),enableSorting:!0,enableHiding:!1,filterFn:(a,i,l)=>l.includes(a.getValue(i)),size:120},{accessorKey:"old_traffic",header:({column:a})=>e.jsx(O,{column:a,title:s("traffic_reset_logs.columns.cleared_traffic"),className:"w-[120px]"}),cell:({row:a})=>{const i=a.original.old_traffic;return e.jsx("div",{className:"w-[120px]",children:e.jsx(fe,{delayDuration:100,children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsxs("div",{className:"cursor-pointer text-center",children:[e.jsx("div",{className:"text-sm font-medium text-destructive",children:i.formatted}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("traffic_reset_logs.columns.cleared")})]})}),e.jsxs(de,{side:"bottom",className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Lt,{className:"h-3 w-3"}),e.jsxs("span",{children:[s("traffic_reset_logs.columns.upload"),":"," ",(i.upload/1024**3).toFixed(2)," GB"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(sa,{className:"h-3 w-3"}),e.jsxs("span",{children:[s("traffic_reset_logs.columns.download"),":"," ",(i.download/1024**3).toFixed(2)," GB"]})]})]})]})})})},enableSorting:!1,enableHiding:!1,size:120},{accessorKey:"reset_time",header:({column:a})=>e.jsx(O,{column:a,title:s("traffic_reset_logs.columns.reset_time"),className:"w-[140px]"}),cell:({row:a})=>e.jsx("div",{className:"w-[140px]",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Yt,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium",children:oe(a.original.reset_time,"MM-DD")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:oe(a.original.reset_time,"HH:mm")})]})]})}),enableSorting:!0,enableHiding:!0,size:140},{accessorKey:"created_at",header:({column:a})=>e.jsx(O,{column:a,title:s("traffic_reset_logs.columns.log_time"),className:"w-[140px]"}),cell:({row:a})=>e.jsx("div",{className:"w-[140px]",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(On,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium",children:oe(a.original.created_at,"YYYY-MM-DD")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:oe(a.original.created_at,"H:m:s")})]})]})}),enableSorting:!0,enableHiding:!1,size:1400}]};function tp(){const[s,n]=u.useState({}),[t,r]=u.useState({reset_time:!1}),[a,i]=u.useState([]),[l,d]=u.useState([{id:"created_at",desc:!0}]),[x,m]=u.useState({pageIndex:0,pageSize:20}),o={page:x.pageIndex+1,per_page:x.pageSize,...a.reduce((S,C)=>{if(C.value)if(C.id==="date_range"){const T=C.value;T.start&&(S.start_date=T.start),T.end&&(S.end_date=T.end)}else S[C.id]=C.value;return S},{})},{refetch:c,data:f,isLoading:D}=re({queryKey:["trafficResetLogs",x,a,l],queryFn:()=>na.getLogs(o)});return e.jsx(ap,{data:f?.data??[],rowCount:f?.total??0,sorting:l,setSorting:d,columnVisibility:t,setColumnVisibility:r,rowSelection:s,setRowSelection:n,columnFilters:a,setColumnFilters:i,pagination:x,setPagination:m,refetch:c,isLoading:D})}function ap({data:s,rowCount:n,sorting:t,setSorting:r,columnVisibility:a,setColumnVisibility:i,rowSelection:l,setRowSelection:d,columnFilters:x,setColumnFilters:m,pagination:o,setPagination:c,refetch:f,isLoading:D}){const S=Be({data:s,columns:sp(),state:{sorting:t,columnVisibility:a,rowSelection:l,columnFilters:x,pagination:o},rowCount:n,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:d,onSortingChange:r,onColumnFiltersChange:m,onColumnVisibilityChange:i,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),onPaginationChange:c,getSortedRowModel:gs(),getFacetedRowModel:Ls(),getFacetedUniqueValues:Rs(),initialState:{columnVisibility:{reset_time:!1}}});return e.jsxs("div",{className:"h-full space-y-4",children:[e.jsx(ep,{table:S,refetch:f}),e.jsx(ts,{table:S,isLoading:D})]})}function np(){const{t:s}=M("user");return e.jsxs(Ae,{children:[e.jsxs(qe,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsx(cs,{})}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-4 space-y-2 md:mb-2 md:flex md:items-center md:justify-between md:space-y-0",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-xl font-bold tracking-tight md:text-2xl",children:s("traffic_reset_logs.title")}),e.jsx("p",{className:"text-sm text-muted-foreground md:mt-2",children:s("traffic_reset_logs.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-hidden px-4 py-1",children:e.jsx("div",{className:"h-full w-full",children:e.jsx(tp,{})})})]})]})}const rp=Object.freeze(Object.defineProperty({__proto__:null,default:np},Symbol.toStringTag,{value:"Module"}));export{Ne as _,mp as a,cp as c,dp as g,up as r};
|