mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-03 10:30:51 +08:00
- Add chunking and batching for admin email sending - Fix gift card pagination and add per_page limits - Update frontend prompts and complete language packs
22 lines
532 KiB
JavaScript
Vendored
22 lines
532 KiB
JavaScript
Vendored
import{r as m,j as e,t as lo,c as io,I as ea,a as jt,S as Tn,u as Bs,b as oo,d as Dn,R as Dr,e as Fr,f as co,F as mo,C as uo,L as Pr,T as Lr,g as Rr,h as xo,i as ho,k as go,l as po,m as $,n as Er,o as Vr,z as h,p as O,q as Ne,s as ke,v as ne,w as $s,x as Le,y as Ir,A as fo,O as Fn,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 Mr,N as So,P as ko,U as To,V as Do,W as Fo,X as Po,Y as Or,Z as zr,_ as Ia,$ as Ma,a0 as Pn,a1 as is,a2 as Oa,a3 as za,a4 as $r,a5 as Ar,a6 as qr,a7 as Ur,a8 as Hr,a9 as Lo,aa as Kr,ab as Br,ac as Gr,ad as Wr,ae as vt,af as Yr,ag as Ro,ah as Jr,ai as Qr,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 Uo,at as Xr,au as Ho,av as Ko,aw as st,ax as Zr,ay as Bo,az as Go,aA as el,aB as Ln,aC as Wo,aD as Yo,aE as tr,aF as Jo,aG as sl,aH as Qo,aI as tl,aJ as Xo,aK as Zo,aL as ec,aM as sc,aN as tc,aO as ac,aP as nc,aQ as al,aR as rc,aS as lc,aT as ic,aU as hs,aV as oc,aW as Rn,aX as cc,aY as dc,aZ as nl,a_ as rl,a$ as ll,b0 as mc,b1 as uc,b2 as xc,b3 as il,b4 as hc,b5 as En,b6 as ol,b7 as gc,b8 as cl,b9 as pc,ba as dl,bb as fc,bc as ml,bd as ul,be as jc,bf as vc,bg as xl,bh as bc,bi as hl,bj as yc,bk as gl,bl as pl,bm as fl,bn as _c,bo as jl,bp as Nc,bq as wc,br as Os,bs as Pe,bt as Cs,bu as Cc,bv as Sc,bw as kc,bx as Tc,by as Dc,bz as Fc,bA as ar,bB as nr,bC as Pc,bD as Lc,bE as Vn,bF as Rc,bG as Ec,bH as Ca,bI as Lt,bJ as sa,bK as Vc,bL as vl,bM as Ic,bN as Mc,bO as bl,bP as Oc,bQ as zc,bR as rr,bS as jn,bT as vn,bU as $c,bV as Ac,bW as yl,bX as qc,bY as Uc,bZ as Hc,b_ as Kc,b$ as Sa,c0 as bn,c1 as We,c2 as ka,c3 as Bc,c4 as rn,c5 as Gc,c6 as yn,c7 as ms,c8 as Gt,c9 as Wt,ca as _n,cb as _l,cc as Ye,cd as ss,ce as Nl,cf as wl,cg as Wc,ch as Yc,ci as Jc,cj as Qc,ck as Xc,cl as Cl,cm as Zc,cn as ed,co as sd,cp as Ke,cq as lr,cr as td,cs as Sl,ct as kl,cu as Tl,cv as Dl,cw as Fl,cx as Pl,cy as ad,cz as nd,cA as rd,cB as $a,cC as nt,cD as gs,cE as ps,cF as ld,cG as id,cH as od,cI as cd,cJ as dd,cK as md,cL as Ta,cM as ud,cN as xd,cO as Nn,cP as In,cQ as Mn,cR as hd,cS as Ps,cT as Ls,cU as Aa,cV as gd,cW as pd,cX as ba,cY as Da,cZ as fd,c_ as ir,c$ as Ll,d0 as or,d1 as Fa,d2 as jd,d3 as On,d4 as vd,d5 as bd,d6 as yd,d7 as Rl,d8 as _d,d9 as Nd,da as El,db as wn,dc as Vl,dd as wd,de as Cn,df as Il,dg as Cd,dh as Sd,di as kd,dj as Ml,dk as Td,dl as Ol,dm as Yt,dn as zn,dp as Dd,dq as cr,dr as zl,ds as Fd,dt as dr,du as Pd,dv as Ld}from"./vendor.js";import"./index.js";var mp=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function up(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function Rd(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 Ed={theme:"system",setTheme:()=>null},$l=m.createContext(Ed);function Vd({children:s,defaultTheme:n="system",storageKey:t="vite-ui-theme",...r}){const[a,o]=m.useState(()=>localStorage.getItem(t)||n);m.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),o(d)}};return e.jsx($l.Provider,{...r,value:l,children:s})}const Id=()=>{const s=m.useContext($l);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},Md=function(){const n=typeof document<"u"&&document.createElement("link").relList;return n&&n.supports&&n.supports("modulepreload")?"modulepreload":"preload"}(),Od=function(s,n){return new URL(s,n).href},mr={},_e=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(u=>{if(u=Od(u,r),u in mr)return;mr[u]=!0;const i=u.endsWith(".css"),c=i?'[rel="stylesheet"]':"";if(!!r)for(let T=l.length-1;T>=0;T--){const C=l[T];if(C.href===u&&(!i||C.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${c}`))return;const P=document.createElement("link");if(P.rel=i?"stylesheet":Md,i||(P.as="script"),P.crossOrigin="",P.href=u,x&&P.setAttribute("nonce",x),document.head.appendChild(P),i)return new Promise((T,C)=>{P.addEventListener("load",T),P.addEventListener("error",()=>C(new Error(`Unable to preload CSS for ${u}`)))})}))}function o(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"&&o(d.reason);return n().catch(o)})};function _(...s){return lo(io(s))}const It=jt("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"}}),L=m.forwardRef(({className:s,variant:n,size:t,asChild:r=!1,children:a,disabled:o,loading:l=!1,leftSection:d,rightSection:x,...u},i)=>{const c=r?Tn:"button";return e.jsxs(c,{className:_(It({variant:n,size:t,className:s})),disabled:l||o,ref:i,...u,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"})]})});L.displayName="Button";function Nt({className:s,minimal:n=!1}){const t=Bs(),r=oo(),a=r?.message||r?.statusText||"Unknown error occurred";return e.jsx("div",{className:_("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(L,{variant:"outline",onClick:()=>t(-1),children:"Go Back"}),e.jsx(L,{onClick:()=>t("/"),children:"Back to Home"})]})]})})}function ur(){const s=Bs();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(L,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(L,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function zd(){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(L,{variant:"outline",children:"Learn more"})})]})})}function $d(s){return typeof s>"u"}function Ad(s){return s===null}function qd(s){return Ad(s)||$d(s)}class Ud{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:o,time:l,expire:d}=a;return qd(d)||d>new Date().getTime()?{value:o,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 Al({prefixKey:s="",storage:n=sessionStorage}){return new Ud({prefixKey:s,storage:n})}const ql="Xboard_",Hd=function(s={}){return Al({prefixKey:s.prefixKey||"",storage:localStorage})},Kd=function(s={}){return Al({prefixKey:s.prefixKey||"",storage:sessionStorage})},$n=Hd({prefixKey:ql});Kd({prefixKey:ql});const Ul="access_token";function ta(){return $n.get(Ul)}function Hl(){$n.remove(Ul)}const xr=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function Bd({children:s}){const n=Bs(),t=Dn(),r=ta();return m.useEffect(()=>{if(!r.value&&!xr.includes(t.pathname)){const a=encodeURIComponent(t.pathname+t.search);n(`/sign-in?redirect=${a}`)}},[r.value,t.pathname,t.search,n]),xr.includes(t.pathname)||r.value?e.jsx(e.Fragment,{children:s}):null}const Re=m.forwardRef(({className:s,orientation:n="horizontal",decorative:t=!0,...r},a)=>e.jsx(Dr,{ref:a,decorative:t,orientation:n,className:_("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...r}));Re.displayName=Dr.displayName;const Gd=jt("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Qe=m.forwardRef(({className:s,...n},t)=>e.jsx(Fr,{ref:t,className:_(Gd(),s),...n}));Qe.displayName=Fr.displayName;const Te=mo,Kl=m.createContext({}),j=({...s})=>e.jsx(Kl.Provider,{value:{name:s.name},children:e.jsx(uo,{...s})}),qa=()=>{const s=m.useContext(Kl),n=m.useContext(Bl),{getFieldState:t,formState:r}=co(),a=t(s.name,r);if(!s)throw new Error("useFormField should be used within <FormField>");const{id:o}=n;return{id:o,name:s.name,formItemId:`${o}-form-item`,formDescriptionId:`${o}-form-item-description`,formMessageId:`${o}-form-item-message`,...a}},Bl=m.createContext({}),f=m.forwardRef(({className:s,...n},t)=>{const r=m.useId();return e.jsx(Bl.Provider,{value:{id:r},children:e.jsx("div",{ref:t,className:_("space-y-2",s),...n})})});f.displayName="FormItem";const v=m.forwardRef(({className:s,...n},t)=>{const{error:r,formItemId:a}=qa();return e.jsx(Qe,{ref:t,className:_(r&&"text-destructive",s),htmlFor:a,...n})});v.displayName="FormLabel";const b=m.forwardRef(({...s},n)=>{const{error:t,formItemId:r,formDescriptionId:a,formMessageId:o}=qa();return e.jsx(Tn,{ref:n,id:r,"aria-describedby":t?`${a} ${o}`:`${a}`,"aria-invalid":!!t,...s})});b.displayName="FormControl";const A=m.forwardRef(({className:s,...n},t)=>{const{formDescriptionId:r}=qa();return e.jsx("p",{ref:t,id:r,className:_("text-[0.8rem] text-muted-foreground",s),...n})});A.displayName="FormDescription";const R=m.forwardRef(({className:s,children:n,...t},r)=>{const{error:a,formMessageId:o}=qa(),l=a?String(a?.message):n;return l?e.jsx("p",{ref:r,id:o,className:_("text-[0.8rem] font-medium text-destructive",s),...t,children:l}):null});R.displayName="FormMessage";const bt=xo,rt=m.forwardRef(({className:s,...n},t)=>e.jsx(Pr,{ref:t,className:_("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...n}));rt.displayName=Pr.displayName;const Be=m.forwardRef(({className:s,...n},t)=>e.jsx(Lr,{ref:t,className:_("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}));Be.displayName=Lr.displayName;const bs=m.forwardRef(({className:s,...n},t)=>e.jsx(Rr,{ref:t,className:_("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=Rr.displayName;function ie(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 Wd(s=void 0,n="YYYY-MM-DD"){return ie(s,n)}function hr(s){const n=typeof s=="string"?parseFloat(s):s;return isNaN(n)?"0.00":n.toFixed(2)}function Hs(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+$/,o=>o.includes(".")?".00":o);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 gr="i18nextLng";function Yd(){return console.log(localStorage.getItem(gr)),localStorage.getItem(gr)}function Gl(){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 Jd=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function Qd(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const Dt=po.create({baseURL:Qd(),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(!Jd.includes(s.url?.split("?")[0]||"")){if(!n.value)return Gl(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=n.value}return s.headers["Content-Language"]=Yd()||"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)&&Gl(),$.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)},Xd="access_token";function Zd(s){$n.set(Xd,s)}const ut=window?.settings?.secure_path,Pa={getStats:()=>I.get(ut+"/monitor/api/stats"),getOverride:()=>I.get(ut+"/stat/getOverride"),getOrderStat:s=>I.get(ut+"/stat/getOrder",{params:s}),getStatsData:()=>I.get(ut+"/stat/getStats"),getNodeTrafficData:s=>I.get(ut+"/stat/getTrafficRank",{params:s}),getServerLastRank:()=>I.get(ut+"/stat/getServerLastRank"),getServerYesterdayRank:()=>I.get(ut+"/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,gt={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)},ln=window?.settings?.secure_path,yt={getList:()=>I.get(ln+"/server/group/fetch"),save:s=>I.post(ln+"/server/group/save",s),drop:s=>I.post(ln+"/server/group/drop",s)},on=window?.settings?.secure_path,Ua={getList:()=>I.get(on+"/server/route/fetch"),save:s=>I.post(on+"/server/route/save",s),drop:s=>I.post(on+"/server/route/drop",s)},xt=window?.settings?.secure_path,pt={getList:()=>I.get(xt+"/payment/fetch"),getMethodList:()=>I.get(xt+"/payment/getPaymentMethods"),getMethodForm:s=>I.post(xt+"/payment/getPaymentForm",s),save:s=>I.post(xt+"/payment/save",s),drop:s=>I.post(xt+"/payment/drop",s),updateStatus:s=>I.post(xt+"/payment/show",s),sort:s=>I.post(xt+"/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,ht={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)},Ts=window?.settings?.secure_path,Fs={getTemplates:s=>I.post(Ts+"/gift-card/templates",s),createTemplate:s=>I.post(Ts+"/gift-card/create-template",s),updateTemplate:s=>I.post(Ts+"/gift-card/update-template",s),deleteTemplate:s=>I.post(Ts+"/gift-card/delete-template",s),getCodes:s=>I.post(Ts+"/gift-card/codes",s),generateCodes:s=>s.download_csv?I.post(Ts+"/gift-card/generate-codes",s,{responseType:"blob"}):I.post(Ts+"/gift-card/generate-codes",s),toggleCode:s=>I.post(Ts+"/gift-card/toggle-code",s),exportCodes:s=>I.get(Ts+`/gift-card/export-codes?batch_id=${s}`,{responseType:"blob"}),getUsages:s=>I.post(Ts+"/gift-card/usages",s),getStatistics:s=>I.post(Ts+"/gift-card/statistics",s),getTypes:()=>I.get(Ts+"/gift-card/types")},ma=window?.settings?.secure_path,La={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})},rs=window?.settings?.secure_path,ve={getSettings:(s="")=>I.get(rs+"/config/fetch?key="+s),saveSettings:s=>I.post(rs+"/config/save",s),getEmailTemplate:()=>I.get(rs+"/config/getEmailTemplate"),sendTestMail:()=>I.post(rs+"/config/testSendMail"),setTelegramWebhook:()=>I.post(rs+"/config/setTelegramWebhook"),updateSystemConfig:s=>I.post(rs+"/config/save",s),getSystemStatus:()=>I.get(`${rs}/system/getSystemStatus`),getQueueStats:()=>I.get(`${rs}/system/getQueueStats`),getQueueWorkload:()=>I.get(`${rs}/system/getQueueWorkload`),getQueueMasters:()=>I.get(`${rs}/system/getQueueMasters`),getHorizonFailedJobs:s=>I.get(`${rs}/system/getHorizonFailedJobs`,{params:s}),getSystemLog:s=>I.get(`${rs}/system/getSystemLog`,{params:s}),getLogFiles:()=>I.get(`${rs}/log/files`),getLogContent:s=>I.get(`${rs}/log/fetch`,{params:s}),getLogClearStats:s=>I.get(`${rs}/system/getLogClearStats`,{params:s}),clearSystemLog:s=>I.post(`${rs}/system/clearSystemLog`,s)},Is=window?.settings?.secure_path,Ms={getPluginTypes:()=>I.get(`${Is}/plugin/types`),getPluginList:s=>{const n=s?{type:s}:{};return I.get(`${Is}/plugin/getPlugins`,{params:n})},uploadPlugin:s=>{const n=new FormData;return n.append("file",s),I.post(`${Is}/plugin/upload`,n,{headers:{"Content-Type":"multipart/form-data"}})},deletePlugin:s=>I.post(`${Is}/plugin/delete`,{code:s}),installPlugin:s=>I.post(`${Is}/plugin/install`,{code:s}),uninstallPlugin:s=>I.post(`${Is}/plugin/uninstall`,{code:s}),enablePlugin:s=>I.post(`${Is}/plugin/enable`,{code:s}),disablePlugin:s=>I.post(`${Is}/plugin/disable`,{code:s}),getPluginConfig:s=>I.get(`${Is}/plugin/config`,{params:{code:s}}),updatePluginConfig:(s,n)=>I.post(`${Is}/plugin/config`,{code:s,config:n}),upgradePlugin:s=>I.post(`${Is}/plugin/upgrade`,{code:s})};window?.settings?.secure_path;Er.config({monaco:Vr});const em=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("")}),pr=[{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"}],fr={subscribe_template_singbox:"",subscribe_template_clash:"",subscribe_template_clashmeta:"",subscribe_template_stash:"",subscribe_template_surge:"",subscribe_template_surfboard:""};function sm(){const{t:s}=O("settings"),[n,t]=m.useState(!1),r=m.useRef(null),[a,o]=m.useState("singbox"),l=Ne({resolver:ke(em),defaultValues:fr,mode:"onChange"}),{data:d,isLoading:x}=ne({queryKey:["settings","client"],queryFn:()=>ve.getSettings("subscribe_template")}),{mutateAsync:u}=$s({mutationFn:ve.saveSettings,onSuccess:()=>{$.success(s("common.autoSaved"))},onError:P=>{console.error("保存失败:",P),$.error(s("common.saveFailed"))}});m.useEffect(()=>{if(d?.data?.subscribe_template){const P=d.data.subscribe_template;Object.entries(P).forEach(([T,C])=>{if(T in fr){const F=typeof C=="string"?C:"";l.setValue(T,F)}}),r.current=l.getValues()}},[d,l]);const i=m.useCallback(Le.debounce(async P=>{if(!r.current||!Le.isEqual(P,r.current)){t(!0);try{await u(P),r.current=P}catch(T){console.error("保存设置失败:",T)}finally{t(!1)}}},1500),[u]),c=m.useCallback(()=>{const P=l.getValues();i(P)},[l,i]),p=m.useCallback((P,T)=>e.jsx(j,{control:l.control,name:P,render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s(`subscribe_template.${P.replace("subscribe_template_","")}.title`)}),e.jsx(b,{children:e.jsx(Ir,{height:"500px",defaultLanguage:T,value:C.value||"",onChange:F=>{C.onChange(F||""),c()},options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0}})}),e.jsx(A,{children:s(`subscribe_template.${P.replace("subscribe_template_","")}.description`)}),e.jsx(R,{})]})}),[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(Te,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(bt,{value:a,onValueChange:o,className:"w-full",children:[e.jsx(rt,{className:"",children:pr.map(({key:P,label:T})=>e.jsx(Be,{value:P,className:"text-xs",children:T},P))}),pr.map(({key:P,language:T})=>e.jsx(bs,{value:P,className:"mt-4",children:p(`subscribe_template_${P}`,T)},P))]}),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 tm(){const{t:s}=O("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(Re,{}),e.jsx(sm,{})]})}const am=()=>e.jsx(Bd,{children:e.jsx(Fn,{})}),nm=fo([{path:"/sign-in",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>bm);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(am,{}),children:[{path:"/",lazy:async()=>({Component:(await _e(()=>Promise.resolve().then(()=>Dm),void 0,import.meta.url)).default}),errorElement:e.jsx(Nt,{}),children:[{index:!0,lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>Jm);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(Nt,{}),children:[{path:"system",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>eu);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>nu);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>cu);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>hu);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>vu);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>wu);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>Du);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>Eu);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>zu);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>Hu);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe-template",element:e.jsx(tm,{})}]},{path:"payment",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>Qu);return{default:s}},void 0,import.meta.url)).default})},{path:"plugin",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>ex);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>nx);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>mx);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>vx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(Nt,{}),children:[{path:"manage",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>Yx);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>eh);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>lh);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(Nt,{}),children:[{path:"plan",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>gh);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>Dh);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>zh);return{default:s}},void 0,import.meta.url)).default})},{path:"gift-card",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>rg);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(Nt,{}),children:[{path:"manage",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>Ig);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>sp);return{default:s}},void 0,import.meta.url)).default})},{path:"traffic-reset-logs",lazy:async()=>({Component:(await _e(async()=>{const{default:s}=await Promise.resolve().then(()=>ip);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:Nt},{path:"/404",Component:ur},{path:"/503",Component:zd},{path:"*",Component:ur}]);function rm(){return I.get("/user/info")}const cn={token:ta()?.value||"",userInfo:null,isLoggedIn:!!ta()?.value,loading:!1,error:null},Qt=jo("user/fetchUserInfo",async()=>(await rm()).data,{condition:(s,{getState:n})=>{const{user:t}=n();return!!t.token&&!t.loading}}),Wl=vo({name:"user",initialState:cn,reducers:{setToken(s,n){s.token=n.payload,s.isLoggedIn=!!n.payload},resetUserState:()=>cn},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 cn})}}),{setToken:lm,resetUserState:im}=Wl.actions,om=s=>s.user.userInfo,cm=Wl.reducer,Yl=bo({reducer:{user:cm}});ta()?.value&&Yl.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 dm=new wo;Co.createRoot(document.getElementById("root")).render(e.jsx(Mr.StrictMode,{children:e.jsx(So,{client:dm,children:e.jsx(ko,{store:Yl,children:e.jsxs(Vd,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(To,{router:nm}),e.jsx(Do,{richColors:!0,position:"top-right"})]})})})}));const Se=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:_("rounded-xl border bg-card text-card-foreground shadow",s),...n}));Se.displayName="Card";const De=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:_("flex flex-col space-y-1.5 p-6",s),...n}));De.displayName="CardHeader";const Ve=m.forwardRef(({className:s,...n},t)=>e.jsx("h3",{ref:t,className:_("font-semibold leading-none tracking-tight",s),...n}));Ve.displayName="CardTitle";const Xs=m.forwardRef(({className:s,...n},t)=>e.jsx("p",{ref:t,className:_("text-sm text-muted-foreground",s),...n}));Xs.displayName="CardDescription";const Fe=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:_("p-6 pt-0",s),...n}));Fe.displayName="CardContent";const mm=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:_("flex items-center p-6 pt-0",s),...n}));mm.displayName="CardFooter";const D=m.forwardRef(({className:s,type:n,...t},r)=>e.jsx("input",{type:n,className:_("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}));D.displayName="Input";const Jl=m.forwardRef(({className:s,...n},t)=>{const[r,a]=m.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:r?"text":"password",className:_("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(L,{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(o=>!o),children:r?e.jsx(Fo,{size:18}):e.jsx(Po,{size:18})})]})});Jl.displayName="PasswordInput";const um=s=>I.post("/passport/auth/login",s);function xm({className:s,onForgotPassword:n,...t}){const r=Bs(),a=Or(),{t:o}=O("auth"),l=h.object({email:h.string().min(1,{message:o("signIn.validation.emailRequired")}),password:h.string().min(1,{message:o("signIn.validation.passwordRequired")}).min(7,{message:o("signIn.validation.passwordLength")})}),d=Ne({resolver:ke(l),defaultValues:{email:"",password:""}});async function x(u){try{const{data:i}=await um(u);Zd(i.auth_data),a(lm(i.auth_data)),await a(Qt()).unwrap(),r("/")}catch(i){console.error("Login failed:",i),i.response?.data?.message&&d.setError("root",{message:i.response.data.message})}}return e.jsx("div",{className:_("grid gap-6",s),...t,children:e.jsx(Te,{...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(j,{control:d.control,name:"email",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:o("signIn.email")}),e.jsx(b,{children:e.jsx(D,{placeholder:o("signIn.emailPlaceholder"),autoComplete:"email",...u})}),e.jsx(R,{})]})}),e.jsx(j,{control:d.control,name:"password",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:o("signIn.password")}),e.jsx(b,{children:e.jsx(Jl,{placeholder:o("signIn.passwordPlaceholder"),autoComplete:"current-password",...u})}),e.jsx(R,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(L,{variant:"link",type:"button",className:"px-0 text-sm font-normal text-muted-foreground hover:text-primary",onClick:n,children:o("signIn.forgotPassword")})}),e.jsx(L,{className:"w-full",size:"lg",loading:d.formState.isSubmitting,children:o("signIn.submit")})]})})})})}const de=zr,fs=$r,hm=Ar,Zs=Pn,Ql=m.forwardRef(({className:s,...n},t)=>e.jsx(Ia,{ref:t,className:_("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}));Ql.displayName=Ia.displayName;const oe=m.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(hm,{children:[e.jsx(Ql,{}),e.jsxs(Ma,{ref:r,className:_("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(Pn,{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(is,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));oe.displayName=Ma.displayName;const ge=({className:s,...n})=>e.jsx("div",{className:_("flex flex-col space-y-1.5 text-center sm:text-left",s),...n});ge.displayName="DialogHeader";const Ie=({className:s,...n})=>e.jsx("div",{className:_("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Ie.displayName="DialogFooter";const me=m.forwardRef(({className:s,...n},t)=>e.jsx(Oa,{ref:t,className:_("text-lg font-semibold leading-none tracking-tight",s),...n}));me.displayName=Oa.displayName;const Ae=m.forwardRef(({className:s,...n},t)=>e.jsx(za,{ref:t,className:_("text-sm text-muted-foreground",s),...n}));Ae.displayName=za.displayName;const Vt=jt("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=m.forwardRef(({className:s,variant:n,size:t,asChild:r=!1,...a},o)=>{const l=r?Tn:"button";return e.jsx(l,{className:_(Vt({variant:n,size:t,className:s})),ref:o,...a})});G.displayName="Button";const Us=Eo,Ks=Vo,gm=Io,pm=m.forwardRef(({className:s,inset:n,children:t,...r},a)=>e.jsxs(qr,{ref:a,className:_("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(Ur,{className:"ml-auto h-4 w-4"})]}));pm.displayName=qr.displayName;const fm=m.forwardRef(({className:s,...n},t)=>e.jsx(Hr,{ref:t,className:_("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}));fm.displayName=Hr.displayName;const As=m.forwardRef(({className:s,sideOffset:n=4,...t},r)=>e.jsx(Lo,{children:e.jsx(Kr,{ref:r,sideOffset:n,className:_("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})}));As.displayName=Kr.displayName;const Ce=m.forwardRef(({className:s,inset:n,...t},r)=>e.jsx(Br,{ref:r,className:_("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}));Ce.displayName=Br.displayName;const Xl=m.forwardRef(({className:s,children:n,checked:t,...r},a)=>e.jsxs(Gr,{ref:a,className:_("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(Wr,{children:e.jsx(vt,{className:"h-4 w-4"})})}),n]}));Xl.displayName=Gr.displayName;const jm=m.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(Yr,{ref:r,className:_("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(Wr,{children:e.jsx(Ro,{className:"h-4 w-4 fill-current"})})}),n]}));jm.displayName=Yr.displayName;const Ha=m.forwardRef(({className:s,inset:n,...t},r)=>e.jsx(Jr,{ref:r,className:_("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",s),...t}));Ha.displayName=Jr.displayName;const tt=m.forwardRef(({className:s,...n},t)=>e.jsx(Qr,{ref:t,className:_("-mx-1 my-1 h-px bg-muted",s),...n}));tt.displayName=Qr.displayName;const Sn=({className:s,...n})=>e.jsx("span",{className:_("ml-auto text-xs tracking-widest opacity-60",s),...n});Sn.displayName="DropdownMenuShortcut";const dn=[{code:"en-US",name:"English",flag:Mo,shortName:"EN"},{code:"zh-CN",name:"中文",flag:Oo,shortName:"CN"}];function Zl(){const{i18n:s}=O(),n=a=>{s.changeLanguage(a)},t=dn.find(a=>a.code===s.language)||dn[1],r=t.flag;return e.jsxs(Us,{children:[e.jsx(Ks,{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(As,{align:"end",className:"w-[120px]",children:dn.map(a=>{const o=a.flag,l=a.code===s.language;return e.jsxs(Ce,{onClick:()=>n(a.code),className:_("flex items-center gap-2 px-2 py-1.5 cursor-pointer",l&&"bg-accent"),children:[e.jsx(o,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:_("text-sm",l&&"font-medium"),children:a.name})]},a.code)})})]})}function vm(){const[s,n]=m.useState(!1),{t}=O("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(Zl,{})}),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(Se,{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(xm,{onForgotPassword:()=>n(!0)})]})]})]}),e.jsx(de,{open:s,onOpenChange:n,children:e.jsx(oe,{className:"max-w-[90vw] sm:max-w-lg",children:e.jsxs(ge,{children:[e.jsx(me,{children:t("signIn.resetPassword.title")}),e.jsx(Ae,{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(()=>{$.success(t("common:copy.success"))}),children:e.jsx(zo,{className:"h-4 w-4"})})]})})]})})})]})}const bm=Object.freeze(Object.defineProperty({__proto__:null,default:vm},Symbol.toStringTag,{value:"Module"})),qe=m.forwardRef(({className:s,fadedBelow:n=!1,fixedHeight:t=!1,...r},a)=>e.jsx("div",{ref:a,className:_("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}));qe.displayName="Layout";const Ue=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:_("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...n}));Ue.displayName="LayoutHeader";const Je=m.forwardRef(({className:s,fixedHeight:n,...t},r)=>e.jsx("div",{ref:r,className:_("flex-1 overflow-hidden px-4 py-6 md:px-8",n&&"h-[calc(100%-var(--header-height))]",s),...t}));Je.displayName="LayoutBody";const ei=$o,si=Ao,ti=qo,pe=Uo,ue=Ho,xe=Ko,ce=m.forwardRef(({className:s,sideOffset:n=4,...t},r)=>e.jsx(Xr,{ref:r,sideOffset:n,className:_("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...t}));ce.displayName=Xr.displayName;function Ka(){const{pathname:s}=Dn();return{checkActiveNav:t=>{if(t==="/"&&s==="/")return!0;const r=t.replace(/^\//,""),a=s.replace(/^\//,"");return r?a.startsWith(r):!1}}}function ai({key:s,defaultValue:n}){const[t,r]=m.useState(()=>{const a=localStorage.getItem(s);return a!==null?JSON.parse(a):n});return m.useEffect(()=>{localStorage.setItem(s,JSON.stringify(t))},[t,s]),[t,r]}function ym(){const[s,n]=ai({key:"collapsed-sidebar-items",defaultValue:[]}),t=a=>!s.includes(a);return{isExpanded:t,toggleItem:a=>{t(a)?n([...s,a]):n(s.filter(o=>o!==a))}}}function _m({links:s,isCollapsed:n,className:t,closeNav:r}){const{t:a}=O(),o=({sub:l,...d})=>{const x=`${a(d.title)}-${d.href}`;return n&&l?m.createElement(Cm,{...d,sub:l,key:x,closeNav:r}):n?m.createElement(wm,{...d,key:x,closeNav:r}):l?m.createElement(Nm,{...d,sub:l,key:x,closeNav:r}):m.createElement(ni,{...d,key:x,closeNav:r})};return e.jsx("div",{"data-collapsed":n,className:_("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(pe,{delayDuration:0,children:e.jsx("nav",{className:"grid gap-1 group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2",children:s.map(o)})})})}function ni({title:s,icon:n,label:t,href:r,closeNav:a,subLink:o=!1}){const{checkActiveNav:l}=Ka(),{t:d}=O();return e.jsxs(st,{to:r,onClick:a,className:_(It({variant:l(r)?"secondary":"ghost",size:"sm"}),"h-12 justify-start text-wrap rounded-none px-6",o&&"h-10 w-full border-l border-l-slate-500 px-2"),"aria-current":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 Nm({title:s,icon:n,label:t,sub:r,closeNav:a}){const{checkActiveNav:o}=Ka(),{isExpanded:l,toggleItem:d}=ym(),{t:x}=O(),u=!!r?.find(p=>o(p.href)),i=x(s),c=l(i)||u;return e.jsxs(ei,{open:c,onOpenChange:()=>d(i),children:[e.jsxs(si,{className:_(It({variant:u?"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:_('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(Zr,{stroke:1})})]}),e.jsx(ti,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:r.map(p=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(ni,{...p,subLink:!0,closeNav:a})},x(p.title)))})})]})}function wm({title:s,icon:n,label:t,href:r,closeNav:a}){const{checkActiveNav:o}=Ka(),{t:l}=O();return e.jsxs(ue,{delayDuration:0,children:[e.jsx(xe,{asChild:!0,children:e.jsxs(st,{to:r,onClick:a,className:_(It({variant:o(r)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[n,e.jsx("span",{className:"sr-only",children:l(s)})]})}),e.jsxs(ce,{side:"right",className:"flex items-center gap-4",children:[l(s),t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:l(t)})]})]})}function Cm({title:s,icon:n,label:t,sub:r,closeNav:a}){const{checkActiveNav:o}=Ka(),{t:l}=O(),d=!!r?.find(x=>o(x.href));return e.jsxs(Us,{children:[e.jsxs(ue,{delayDuration:0,children:[e.jsx(xe,{asChild:!0,children:e.jsx(Ks,{asChild:!0,children:e.jsx(L,{variant:d?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:n})})}),e.jsxs(ce,{side:"right",className:"flex items-center gap-4",children:[l(s)," ",t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:l(t)}),e.jsx(Zr,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(As,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(Ha,{children:[l(s)," ",t?`(${l(t)})`:""]}),e.jsx(tt,{}),r.map(({title:x,icon:u,label:i,href:c})=>e.jsx(Ce,{asChild:!0,children:e.jsxs(st,{to:c,onClick:a,className:`${o(c)?"bg-secondary":""}`,children:[u," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:l(x)}),i&&e.jsx("span",{className:"ml-auto text-xs",children:l(i)})]})},`${l(x)}-${c}`))]})]})}const ri=[{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(el,{size:18})},{title:"nav:pluginManagement",label:"",href:"/config/plugin",icon:e.jsx(Ln,{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(tr,{size:18})},{title:"nav:knowledgeManagement",label:"",href:"/config/knowledge",icon:e.jsx(Jo,{size:18})}]},{title:"nav:nodeManagement",label:"",href:"",icon:e.jsx(sl,{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(tl,{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(tr,{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(al,{size:18})}]}];function Sm({className:s,isCollapsed:n,setIsCollapsed:t}){const[r,a]=m.useState(!1),{t:o}=O();return m.useEffect(()=>{r?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[r]),e.jsxs("aside",{className:_(`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(qe,{className:`flex h-full flex-col ${r?"h-[100vh] md:h-full":""}`,children:[e.jsxs(Ue,{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(L,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":o("common:toggleNavigation"),"aria-controls":"sidebar-menu","aria-expanded":r,onClick:()=>a(l=>!l),children:r?e.jsx(rc,{}):e.jsx(lc,{})})]}),e.jsx(_m,{id:"sidebar-menu",className:_("flex-1 overflow-auto overscroll-contain",r?"block":"hidden md:block","md:py-2"),closeNav:()=>a(!1),isCollapsed:n,links:ri}),e.jsx("div",{className:_("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:_("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:_("whitespace-nowrap tracking-wide","transition-opacity duration-200",n&&"md:opacity-0"),children:["v",window?.settings?.version]})]})}),e.jsx(L,{onClick:()=>t(l=>!l),size:"icon",variant:"outline",className:"absolute -right-5 top-1/2 hidden rounded-full md:inline-flex","aria-label":o("common:toggleSidebar"),children:e.jsx(ic,{stroke:1.5,className:`h-5 w-5 ${n?"rotate-180":""}`})})]})]})}function km(){const[s,n]=ai({key:"collapsed-sidebar",defaultValue:!1});return m.useEffect(()=>{const t=()=>{n(window.innerWidth<768?!1:s)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[s,n]),[s,n]}function Tm(){const[s,n]=km();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(Sm,{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(Fn,{})})]})}const Dm=Object.freeze(Object.defineProperty({__proto__:null,default:Tm},Symbol.toStringTag,{value:"Module"})),Gs=m.forwardRef(({className:s,...n},t)=>e.jsx(hs,{ref:t,className:_("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...n}));Gs.displayName=hs.displayName;const Fm=({children:s,...n})=>e.jsx(de,{...n,children:e.jsx(oe,{className:"overflow-hidden p-0",children:e.jsx(Gs,{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})})}),lt=m.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(hs.Input,{ref:t,className:_("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})]}));lt.displayName=hs.Input.displayName;const Ws=m.forwardRef(({className:s,...n},t)=>e.jsx(hs.List,{ref:t,className:_("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...n}));Ws.displayName=hs.List.displayName;const it=m.forwardRef((s,n)=>e.jsx(hs.Empty,{ref:n,className:"py-6 text-center text-sm",...s}));it.displayName=hs.Empty.displayName;const xs=m.forwardRef(({className:s,...n},t)=>e.jsx(hs.Group,{ref:t,className:_("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}));xs.displayName=hs.Group.displayName;const Mt=m.forwardRef(({className:s,...n},t)=>e.jsx(hs.Separator,{ref:t,className:_("-mx-1 h-px bg-border",s),...n}));Mt.displayName=hs.Separator.displayName;const $e=m.forwardRef(({className:s,...n},t)=>e.jsx(hs.Item,{ref:t,className:_("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...n}));$e.displayName=hs.Item.displayName;function Pm(){const s=[];for(const n of ri)if(n.href&&s.push(n),n.sub)for(const t of n.sub)s.push({...t,parent:n.title});return s}function os(){const[s,n]=m.useState(!1),t=Bs(),r=Pm(),{t:a}=O("search"),{t:o}=O("nav");m.useEffect(()=>{const d=x=>{x.key==="k"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),n(u=>!u))};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[]);const l=m.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(Rn,{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(Fm,{open:s,onOpenChange:n,children:[e.jsx(lt,{placeholder:a("placeholder")}),e.jsxs(Ws,{children:[e.jsx(it,{children:a("noResults")}),e.jsx(xs,{heading:a("title"),children:r.map(d=>e.jsxs($e,{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:o(d.title)}),d.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:o(d.parent)})]},d.href))})]})]})]})}function ts(){const{theme:s,setTheme:n}=Id();return m.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(L,{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(Zl,{})]})}const li=m.forwardRef(({className:s,...n},t)=>e.jsx(nl,{ref:t,className:_("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...n}));li.displayName=nl.displayName;const ii=m.forwardRef(({className:s,...n},t)=>e.jsx(rl,{ref:t,className:_("aspect-square h-full w-full",s),...n}));ii.displayName=rl.displayName;const oi=m.forwardRef(({className:s,...n},t)=>e.jsx(ll,{ref:t,className:_("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...n}));oi.displayName=ll.displayName;function as(){const s=Bs(),n=Or(),t=mc(om),{t:r}=O(["common"]),a=()=>{Hl(),n(im()),s("/sign-in")},o=t?.email?.split("@")[0]||r("common:user"),l=o.substring(0,2).toUpperCase();return e.jsxs(Us,{children:[e.jsx(Ks,{asChild:!0,children:e.jsx(L,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(li,{className:"h-8 w-8",children:[e.jsx(ii,{src:t?.avatar_url,alt:o}),e.jsx(oi,{children:l})]})})}),e.jsxs(As,{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:o}),e.jsx("p",{className:"text-xs leading-none text-muted-foreground",children:t?.email||r("common:defaultEmail")})]})}),e.jsx(tt,{}),e.jsx(Ce,{asChild:!0,children:e.jsxs(st,{to:"/config/system",children:[r("common:settings"),e.jsx(Sn,{children:"⌘S"})]})}),e.jsx(tt,{}),e.jsxs(Ce,{onClick:a,children:[r("common:logout"),e.jsx(Sn,{children:"⇧⌘Q"})]})]})]})}const X=uc,Ns=bc,Z=xc,J=m.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(il,{ref:r,className:_("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(En,{className:"h-4 w-4 opacity-50"})})]}));J.displayName=il.displayName;const ci=m.forwardRef(({className:s,...n},t)=>e.jsx(ol,{ref:t,className:_("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(gc,{className:"h-4 w-4"})}));ci.displayName=ol.displayName;const di=m.forwardRef(({className:s,...n},t)=>e.jsx(cl,{ref:t,className:_("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(En,{className:"h-4 w-4"})}));di.displayName=cl.displayName;const Q=m.forwardRef(({className:s,children:n,position:t="popper",...r},a)=>e.jsx(pc,{children:e.jsxs(dl,{ref:a,className:_("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(ci,{}),e.jsx(fc,{className:_("p-1",t==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx(di,{})]})}));Q.displayName=dl.displayName;const Lm=m.forwardRef(({className:s,...n},t)=>e.jsx(ml,{ref:t,className:_("px-2 py-1.5 text-sm font-semibold",s),...n}));Lm.displayName=ml.displayName;const q=m.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(ul,{ref:r,className:_("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(vt,{className:"h-4 w-4"})})}),e.jsx(vc,{children:n})]}));q.displayName=ul.displayName;const Rm=m.forwardRef(({className:s,...n},t)=>e.jsx(xl,{ref:t,className:_("-mx-1 my-1 h-px bg-muted",s),...n}));Rm.displayName=xl.displayName;function Ss({className:s,classNames:n,showOutsideDays:t=!0,captionLayout:r="label",buttonVariant:a="ghost",formatters:o,components:l,...d}){const x=hl();return e.jsx(yc,{showOutsideDays:t,className:_("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:u=>u.toLocaleString("default",{month:"short"}),...o},classNames:{root:_("w-fit",x.root),months:_("relative flex flex-col gap-4 md:flex-row",x.months),month:_("flex w-full flex-col gap-4",x.month),nav:_("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",x.nav),button_previous:_(Vt({variant:a}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_previous),button_next:_(Vt({variant:a}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_next),month_caption:_("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",x.month_caption),dropdowns:_("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",x.dropdowns),dropdown_root:_("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:_("absolute inset-0 opacity-0",x.dropdown),caption_label:_("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:_("flex",x.weekdays),weekday:_("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",x.weekday),week:_("mt-2 flex w-full",x.week),week_number_header:_("w-[--cell-size] select-none",x.week_number_header),week_number:_("text-muted-foreground select-none text-[0.8rem]",x.week_number),day:_("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:_("bg-accent rounded-l-md",x.range_start),range_middle:_("rounded-none",x.range_middle),range_end:_("bg-accent rounded-r-md",x.range_end),today:_("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",x.today),outside:_("text-muted-foreground aria-selected:text-muted-foreground",x.outside),disabled:_("text-muted-foreground opacity-50",x.disabled),hidden:_("invisible",x.hidden),...n},components:{Root:({className:u,rootRef:i,...c})=>e.jsx("div",{"data-slot":"calendar",ref:i,className:_(u),...c}),Chevron:({className:u,orientation:i,...c})=>i==="left"?e.jsx(gl,{className:_("size-4",u),...c}):i==="right"?e.jsx(pl,{className:_("size-4",u),...c}):e.jsx(fl,{className:_("size-4",u),...c}),DayButton:Em,WeekNumber:({children:u,...i})=>e.jsx("td",{...i,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:u})}),...l},...d})}function Em({className:s,day:n,modifiers:t,...r}){const a=hl(),o=m.useRef(null);return m.useEffect(()=>{t.focused&&o.current?.focus()},[t.focused]),e.jsx(G,{ref:o,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:_("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 Ze=Nc,es=wc,Ge=m.forwardRef(({className:s,align:n="center",sideOffset:t=4,...r},a)=>e.jsx(_c,{children:e.jsx(jl,{ref:a,align:n,sideOffset:t,className:_("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})}));Ge.displayName=jl.displayName;const Ys={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),Vm=({active:s,payload:n,label:t})=>{const{t:r}=O();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,o)=>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})})]},o))]}):null},Im=[{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"}],Mm=(s,n)=>{const t=new Date;if(s==="custom"&&n)return{startDate:n.from,endDate:n.to};let r;switch(s){case"7d":r=Os(t,7);break;case"30d":r=Os(t,30);break;case"90d":r=Os(t,90);break;case"180d":r=Os(t,180);break;case"365d":r=Os(t,365);break;default:r=Os(t,30)}return{startDate:r,endDate:t}};function Om(){const[s,n]=m.useState("amount"),[t,r]=m.useState("30d"),[a,o]=m.useState({from:Os(new Date,7),to:new Date}),{t:l}=O(),{startDate:d,endDate:x}=Mm(t,a),{data:u}=ne({queryKey:["orderStat",{start_date:Pe(d,"yyyy-MM-dd"),end_date:Pe(x,"yyyy-MM-dd")}],queryFn:async()=>{const{data:i}=await Pa.getOrderStat({start_date:Pe(d,"yyyy-MM-dd"),end_date:Pe(x,"yyyy-MM-dd")});return i},refetchInterval:3e4});return e.jsxs(Se,{children:[e.jsx(De,{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(Xs,{children:[u?.summary.start_date," ",l("dashboard:overview.to")," ",u?.summary.end_date]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsxs(X,{value:t,onValueChange:i=>r(i),children:[e.jsx(J,{className:"w-[120px]",children:e.jsx(Z,{placeholder:l("dashboard:overview.selectTimeRange")})}),e.jsx(Q,{children:Im.map(i=>e.jsx(q,{value:i.value,children:l(i.label)},i.value))})]}),t==="custom"&&e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(G,{variant:"outline",className:_("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:[Pe(a.from,"yyyy-MM-dd")," -"," ",Pe(a.to,"yyyy-MM-dd")]}):Pe(a.from,"yyyy-MM-dd"):l("dashboard:overview.selectDate")})]})}),e.jsx(Ge,{className:"w-auto p-0",align:"end",children:e.jsx(Ss,{mode:"range",defaultMonth:a?.from,selected:{from:a?.from,to:a?.to},onSelect:i=>{i?.from&&i?.to&&o({from:i.from,to:i.to})},captionLayout:"dropdown",numberOfMonths:2})})]})]}),e.jsx(bt,{value:s,onValueChange:i=>n(i),children:e.jsxs(rt,{children:[e.jsx(Be,{value:"amount",children:l("dashboard:overview.amount")}),e.jsx(Be,{value:"count",children:l("dashboard:overview.count")})]})})]})]})}),e.jsxs(Fe,{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(u?.summary?.paid_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l("dashboard:overview.totalTransactions",{count:u?.summary?.paid_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l("dashboard:overview.avgOrderAmount")," ¥",Kt(u?.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(u?.summary?.commission_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l("dashboard:overview.totalTransactions",{count:u?.summary?.commission_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l("dashboard:overview.commissionRate")," ",u?.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:u?.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:Ys.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Ys.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:Ys.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Ys.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(kc,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:i=>Pe(new Date(i),"MM-dd",{locale:Pc})}),e.jsx(Tc,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:i=>s==="amount"?`¥${Kt(i)}`:l("dashboard:overview.transactions",{count:i})}),e.jsx(Dc,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(Fc,{content:e.jsx(Vm,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(ar,{type:"monotone",dataKey:"paid_total",name:l("dashboard:overview.orderAmount"),stroke:Ys.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(ar,{type:"monotone",dataKey:"commission_total",name:l("dashboard:overview.commissionAmount"),stroke:Ys.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(nr,{dataKey:"paid_count",name:l("dashboard:overview.orderCount"),fill:Ys.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(nr,{dataKey:"commission_count",name:l("dashboard:overview.commissionCount"),fill:Ys.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})]})]})}function je({className:s,...n}){return e.jsx("div",{className:_("animate-pulse rounded-md bg-primary/10",s),...n})}function zm(){return e.jsxs(Se,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(je,{className:"h-4 w-[120px]"}),e.jsx(je,{className:"h-4 w-4"})]}),e.jsxs(Fe,{children:[e.jsx(je,{className:"h-8 w-[140px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(je,{className:"h-4 w-4"}),e.jsx(je,{className:"h-4 w-[100px]"})]})]})]})}function $m(){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(zm,{},n))})}var le=(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))(le||{});const At={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},qt={0:"yellow-500",1:"blue-500",2:"red-500",3:"green-500",4:"green-500"};var zs=(s=>(s[s.NEW=1]="NEW",s[s.RENEWAL=2]="RENEWAL",s[s.UPGRADE=3]="UPGRADE",s[s.RESET_FLOW=4]="RESET_FLOW",s))(zs||{}),we=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(we||{});const xa={0:"待确认",1:"发放中",2:"有效",3:"无效"},ha={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var Xe=(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))(Xe||{});const Am={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var he=(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))(he||{});const Ds=[{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 qm={1:"按金额优惠",2:"按比例优惠"};var et=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(et||{}),ds=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(ds||{}),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 Js({title:s,value:n,icon:t,trend:r,description:a,onClick:o,highlight:l,className:d}){return e.jsxs(Se,{className:_("transition-colors",o&&"cursor-pointer hover:bg-muted/50",l&&"border-primary/50",d),onClick:o,children:[e.jsxs(De,{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(Fe,{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:_("h-4 w-4",r.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:_("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 Um({className:s}){const n=Bs(),{t}=O(),{data:r,isLoading:a}=ne({queryKey:["dashboardStats"],queryFn:async()=>(await Pa.getStatsData()).data,refetchInterval:1e3*60*5});if(a||!r)return e.jsx($m,{});const o=()=>{const l=new URLSearchParams;l.set("commission_status",we.PENDING.toString()),l.set("status",le.COMPLETED.toString()),l.set("commission_balance","gt:0"),n(`/finance/order?${l.toString()}`)};return e.jsxs("div",{className:_("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(Js,{title:t("dashboard:stats.todayIncome"),value:Hs(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(Js,{title:t("dashboard:stats.monthlyIncome"),value:Hs(r.currentMonthIncome),icon:e.jsx(Vn,{className:"h-4 w-4 text-blue-500"}),trend:{value:r.monthIncomeGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:r.monthIncomeGrowth>0}}),e.jsx(Js,{title:t("dashboard:stats.pendingTickets"),value:r.ticketPendingTotal,icon:e.jsx(Rc,{className:_("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(Js,{title:t("dashboard:stats.pendingCommission"),value:r.commissionPendingTotal,icon:e.jsx(Ec,{className:_("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:o,highlight:r.commissionPendingTotal>0}),e.jsx(Js,{title:t("dashboard:stats.monthlyNewUsers"),value:r.currentMonthNewUsers,icon:e.jsx(Ca,{className:"h-4 w-4 text-blue-500"}),trend:{value:r.userGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:r.userGrowth>0}}),e.jsx(Js,{title:t("dashboard:stats.totalUsers"),value:r.totalUsers,icon:e.jsx(Ca,{className:"h-4 w-4 text-muted-foreground"}),description:t("dashboard:stats.activeUsers",{count:r.activeUsers})}),e.jsx(Js,{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(Js,{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 ft=m.forwardRef(({className:s,children:n,...t},r)=>e.jsxs(vl,{ref:r,className:_("relative overflow-hidden",s),...t,children:[e.jsx(Ic,{className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(Ra,{}),e.jsx(Mc,{})]}));ft.displayName=vl.displayName;const Ra=m.forwardRef(({className:s,orientation:n="vertical",...t},r)=>e.jsx(bl,{ref:r,orientation:n,className:_("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"})}));Ra.displayName=bl.displayName;const kn={today:{getValue:()=>{const s=$c();return{start:s,end:Ac(s,1)}}},last7days:{getValue:()=>{const s=new Date;return{start:Os(s,7),end:s}}},last30days:{getValue:()=>{const s=new Date;return{start:Os(s,30),end:s}}},custom:{getValue:()=>null}};function jr({selectedRange:s,customDateRange:n,onRangeChange:t,onCustomRangeChange:r}){const{t:a}=O(),o={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(X,{value:s,onValueChange:t,children:[e.jsx(J,{className:"w-[120px]",children:e.jsx(Z,{placeholder:a("dashboard:trafficRank.selectTimeRange")})}),e.jsx(Q,{position:"popper",className:"z-50",children:Object.entries(kn).map(([l])=>e.jsx(q,{value:l,children:o[l]},l))})]}),s==="custom"&&e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(G,{variant:"outline",className:_("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:[Pe(n.from,"yyyy-MM-dd")," -"," ",Pe(n.to,"yyyy-MM-dd")]}):Pe(n.from,"yyyy-MM-dd"):e.jsx("span",{children:a("dashboard:trafficRank.selectDateRange")})})]})}),e.jsx(Ge,{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}=O(),[t,r]=m.useState("today"),[a,o]=m.useState({from:Os(new Date,7),to:new Date}),[l,d]=m.useState("today"),[x,u]=m.useState({from:Os(new Date,7),to:new Date}),i=m.useMemo(()=>t==="custom"?{start:a.from,end:a.to}:kn[t].getValue(),[t,a]),c=m.useMemo(()=>l==="custom"?{start:x.from,end:x.to}:kn[l].getValue(),[l,x]),{data:p}=ne({queryKey:["nodeTrafficRank",i.start,i.end],queryFn:()=>Pa.getNodeTrafficData({type:"node",start_time:Le.round(i.start.getTime()/1e3),end_time:Le.round(i.end.getTime()/1e3)}),refetchInterval:3e4}),{data:P}=ne({queryKey:["userTrafficRank",c.start,c.end],queryFn:()=>Pa.getNodeTrafficData({type:"user",start_time:Le.round(c.start.getTime()/1e3),end_time:Le.round(c.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:_("grid gap-4 md:grid-cols-2",s),children:[e.jsxs(Se,{children:[e.jsx(De,{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(jr,{selectedRange:t,customDateRange:a,onRangeChange:r,onCustomRangeChange:o}),e.jsx(rr,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Fe,{className:"flex-1",children:p?.data?e.jsxs(ft,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:p.data.map(T=>e.jsx(pe,{delayDuration:200,children:e.jsxs(ue,{children:[e.jsx(xe,{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:T.name}),e.jsxs("span",{className:_("ml-2 flex items-center text-xs font-medium",T.change>=0?"text-green-600":"text-red-600"),children:[T.change>=0?e.jsx(jn,{className:"mr-1 h-3 w-3"}):e.jsx(vn,{className:"mr-1 h-3 w-3"}),Math.abs(T.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:`${T.value/p.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:kt(T.value)})]})]})})}),e.jsx(ce,{side:"right",className:"space-y-2 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.currentTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:kt(T.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:kt(T.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:_("font-medium",T.change>=0?"text-green-600":"text-red-600"),children:[T.change>=0?"+":"",T.change,"%"]})]})})]})},T.id))}),e.jsx(Ra,{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(Se,{children:[e.jsx(De,{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(Ca,{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(jr,{selectedRange:l,customDateRange:x,onRangeChange:d,onCustomRangeChange:u}),e.jsx(rr,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Fe,{className:"flex-1",children:P?.data?e.jsxs(ft,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:P.data.map(T=>e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{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:T.name}),e.jsxs("span",{className:_("ml-2 flex items-center text-xs font-medium",T.change>=0?"text-green-600":"text-red-600"),children:[T.change>=0?e.jsx(jn,{className:"mr-1 h-3 w-3"}):e.jsx(vn,{className:"mr-1 h-3 w-3"}),Math.abs(T.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:`${T.value/P.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:kt(T.value)})]})]})})}),e.jsx(ce,{side:"right",className:"space-y-2 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.currentTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:kt(T.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:kt(T.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:_("font-medium",T.change>=0?"text-green-600":"text-red-600"),children:[T.change>=0?"+":"",T.change,"%"]})]})})]})},T.id))}),e.jsx(Ra,{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 Km=jt("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/10",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function K({className:s,variant:n,...t}){return e.jsx("div",{className:_(Km({variant:n}),s),...t})}const ya=m.forwardRef(({className:s,value:n,...t},r)=>e.jsx(yl,{ref:r,className:_("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)}%)`}})}));ya.displayName=yl.displayName;const An=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:_("w-full caption-bottom text-sm",s),...n})}));An.displayName="Table";const qn=m.forwardRef(({className:s,...n},t)=>e.jsx("thead",{ref:t,className:_("[&_tr]:border-b",s),...n}));qn.displayName="TableHeader";const Un=m.forwardRef(({className:s,...n},t)=>e.jsx("tbody",{ref:t,className:_("[&_tr:last-child]:border-0",s),...n}));Un.displayName="TableBody";const Bm=m.forwardRef(({className:s,...n},t)=>e.jsx("tfoot",{ref:t,className:_("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...n}));Bm.displayName="TableFooter";const Qs=m.forwardRef(({className:s,...n},t)=>e.jsx("tr",{ref:t,className:_("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...n}));Qs.displayName="TableRow";const Hn=m.forwardRef(({className:s,...n},t)=>e.jsx("th",{ref:t,className:_("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=m.forwardRef(({className:s,...n},t)=>e.jsx("td",{ref:t,className:_("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));Pt.displayName="TableCell";const Gm=m.forwardRef(({className:s,...n},t)=>e.jsx("caption",{ref:t,className:_("mt-4 text-sm text-muted-foreground",s),...n}));Gm.displayName="TableCaption";function mi({table:s}){const[n,t]=m.useState(""),{t:r}=O("common");m.useEffect(()=>{t((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const a=o=>{const l=parseInt(o);!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(X,{value:`${s.getState().pagination.pageSize}`,onValueChange:o=>{s.setPageSize(Number(o))},children:[e.jsx(J,{className:"h-8 w-[70px]",children:e.jsx(Z,{placeholder:s.getState().pagination.pageSize})}),e.jsx(Q,{side:"top",children:[10,20,30,40,50,100,500].map(o=>e.jsx(q,{value:`${o}`,children:o},o))})]})]}),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(D,{type:"text",value:n,onChange:o=>t(o.target.value),onBlur:o=>a(o.target.value),onKeyDown:o=>{o.key==="Enter"&&a(o.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(L,{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(Uc,{className:"h-4 w-4"})]}),e.jsxs(L,{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(Hc,{className:"h-4 w-4"})]}),e.jsxs(L,{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(Ur,{className:"h-4 w-4"})]}),e.jsxs(L,{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 ns({table:s,toolbar:n,draggable:t=!1,onDragStart:r,onDragEnd:a,onDragOver:o,onDragLeave:l,onDrop:d,showPagination:x=!0,isLoading:u=!1}){const{t:i}=O("common"),c=m.useRef(null),p=s.getAllColumns().filter(F=>F.getIsPinned()==="left"),P=s.getAllColumns().filter(F=>F.getIsPinned()==="right"),T=F=>p.slice(0,F).reduce((w,V)=>w+(V.getSize()??0),0),C=F=>P.slice(F+1).reduce((w,V)=>w+(V.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(An,{children:[e.jsx(qn,{children:s.getHeaderGroups().map(F=>e.jsx(Qs,{className:"hover:bg-transparent",children:F.headers.map((w,V)=>{const y=w.column.getIsPinned()==="left",N=w.column.getIsPinned()==="right",S=y?T(p.indexOf(w.column)):void 0,M=N?C(P.indexOf(w.column)):void 0;return e.jsx(Hn,{colSpan:w.colSpan,style:{width:w.getSize(),...y&&{left:S},...N&&{right:M}},className:_("h-11 bg-card px-4 text-muted-foreground",(y||N)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",y&&"before:right-0",N&&"before:left-0"]),children:w.isPlaceholder?null:Sa(w.column.columnDef.header,w.getContext())},w.id)})},F.id))}),e.jsx(Un,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((F,w)=>e.jsx(Qs,{"data-state":F.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:t,onDragStart:V=>r?.(V,w),onDragEnd:a,onDragOver:o,onDragLeave:l,onDrop:V=>d?.(V,w),children:F.getVisibleCells().map((V,y)=>{const N=V.column.getIsPinned()==="left",S=V.column.getIsPinned()==="right",M=N?T(p.indexOf(V.column)):void 0,E=S?C(P.indexOf(V.column)):void 0;return e.jsx(Pt,{style:{width:V.column.getSize(),...N&&{left:M},...S&&{right:E}},className:_("bg-card",(N||S)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",N&&"before:right-0",S&&"before:left-0"]),children:Sa(V.column.columnDef.cell,V.getContext())},V.id)})},F.id)):e.jsx(Qs,{children:e.jsx(Pt,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:i("table.noData")})})})]})})}),x&&e.jsx(mi,{table:s})]})}const _a=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"})},Ut=_l(),Ht=_l();function ga({data:s,isLoading:n,searchKeyword:t,selectedLevel:r,total:a,currentPage:o,pageSize:l,onViewDetail:d,onPageChange:x,onPageSizeChange:u}){const{t:i}=O(),c=T=>{switch(T.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(_n,{className:"h-4 w-4 text-red-500"});default:return e.jsx(Gt,{className:"h-4 w-4 text-slate-500"})}},p=m.useMemo(()=>[Ut.accessor("level",{id:"level",header:()=>i("dashboard:systemLog.level"),size:80,cell:({getValue:T,row:C})=>{const F=T();return e.jsxs("div",{className:"flex items-center gap-1",children:[c(F),e.jsx("span",{className:_(F.toLowerCase()==="error"&&"text-red-600",F.toLowerCase()==="warning"&&"text-yellow-600",F.toLowerCase()==="info"&&"text-blue-600"),children:F})]})}}),Ut.accessor("created_at",{id:"created_at",header:()=>i("dashboard:systemLog.time"),size:160,cell:({getValue:T})=>_a(T())}),Ut.accessor(T=>T.title||T.message||"",{id:"title",header:()=>i("dashboard:systemLog.logTitle"),cell:({getValue:T})=>e.jsx("span",{className:"inline-block max-w-[300px] truncate",children:T()})}),Ut.accessor("method",{id:"method",header:()=>i("dashboard:systemLog.method"),size:100,cell:({getValue:T})=>{const C=T();return C?e.jsx(K,{variant:"outline",className:_(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}}),Ut.display({id:"actions",header:()=>i("dashboard:systemLog.action"),size:80,cell:({row:T})=>e.jsx(G,{variant:"ghost",size:"sm",onClick:()=>d(T.original),"aria-label":i("dashboard:systemLog.viewDetail"),children:e.jsx(bn,{className:"h-4 w-4"})})})],[i,d]),P=We({data:s,columns:p,getCoreRowModel:Ye(),getPaginationRowModel:ss(),pageCount:Math.ceil(a/l),manualPagination:!0,state:{pagination:m.useMemo(()=>({pageIndex:o-1,pageSize:l}),[o,l])},onPaginationChange:T=>{let C,F;if(typeof T=="function"){const w=T({pageIndex:o-1,pageSize:l});C=w.pageIndex,F=w.pageSize}else C=T.pageIndex,F=T.pageSize;F!==l?u(F):x(C+1)}});return e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(ns,{table:P,showPagination:!0,isLoading:n}),(t||r&&r!=="all")&&e.jsx("div",{className:"text-center text-sm text-muted-foreground",children:t&&r&&r!=="all"?i("dashboard:systemLog.filter.searchAndLevel",{keyword:t,level:r,count:a}):t?i("dashboard:systemLog.filter.searchOnly",{keyword:t,count:a}):i("dashboard:systemLog.filter.levelOnly",{level:r,count:a})})]})}function Wm(){const{t:s}=O(),[n,t]=m.useState(0),[r,a]=m.useState(!1),[o,l]=m.useState(1),[d]=m.useState(10),[x,u]=m.useState(null),[i,c]=m.useState(!1),[p,P]=m.useState(!1),[T,C]=m.useState(1),[F,w]=m.useState(10),[V,y]=m.useState(null),[N,S]=m.useState(!1),[M,E]=m.useState(""),[g,k]=m.useState(""),[W,te]=m.useState("all"),[ae,B]=m.useState(!1),[se,fe]=m.useState(0),[cs,Me]=m.useState("all"),[re,ks]=m.useState(1e3),[_s,ot]=m.useState(!1),[Es,ct]=m.useState(null),[dt,mt]=m.useState(!1);m.useEffect(()=>{const Y=setTimeout(()=>{k(M),M!==g&&C(1)},500);return()=>clearTimeout(Y)},[M]);const{data:H,isLoading:U,refetch:be,isRefetching:Oe}=ne({queryKey:["systemStatus",n],queryFn:async()=>(await ve.getSystemStatus()).data,refetchInterval:3e4}),{data:ye,isLoading:Ki,refetch:op,isRefetching:Jn}=ne({queryKey:["queueStats",n],queryFn:async()=>(await ve.getQueueStats()).data,refetchInterval:3e4}),{data:Qn,isLoading:Bi,refetch:Gi}=ne({queryKey:["failedJobs",o,d],queryFn:async()=>{const Y=await ve.getHorizonFailedJobs({current:o,page_size:d});return{data:Y.data,total:Y.total||0}},enabled:r}),{data:Xn,isLoading:ra,refetch:Wi}=ne({queryKey:["systemLogs",T,F,W,g],queryFn:async()=>{const Y={current:T,page_size:F};W&&W!=="all"&&(Y.level=W),g.trim()&&(Y.keyword=g.trim());const Vs=await ve.getSystemLog(Y);return{data:Vs.data,total:Vs.total||0}},enabled:p}),Zn=Qn?.data||[],Yi=Qn?.total||0,la=Xn?.data||[],ia=Xn?.total||0,Ji=m.useMemo(()=>[Ht.display({id:"failed_at",header:()=>s("dashboard:queue.details.time"),cell:({row:Y})=>_a(Y.original.failed_at)}),Ht.display({id:"queue",header:()=>s("dashboard:queue.details.queue"),cell:({row:Y})=>Y.original.queue}),Ht.display({id:"name",header:()=>s("dashboard:queue.details.name"),cell:({row:Y})=>e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[150px] truncate",children:Y.original.name})}),e.jsx(ce,{children:e.jsx("span",{children:Y.original.name})})]})})}),Ht.display({id:"exception",header:()=>s("dashboard:queue.details.exception"),cell:({row:Y})=>e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[200px] truncate",children:Y.original.exception.split(`
|
||
`)[0]})}),e.jsx(ce,{className:"max-w-[300px] whitespace-pre-wrap",children:e.jsx("span",{children:Y.original.exception})})]})})}),Ht.display({id:"actions",header:()=>s("dashboard:queue.details.action"),size:80,cell:({row:Y})=>e.jsx(G,{variant:"ghost",size:"sm",onClick:()=>eo(Y.original),"aria-label":s("dashboard:queue.details.viewDetail"),children:e.jsx(bn,{className:"h-4 w-4"})})})],[s]),er=We({data:Zn,columns:Ji,getCoreRowModel:Ye(),getPaginationRowModel:ss(),pageCount:Math.ceil(Yi/d),manualPagination:!0,state:{pagination:{pageIndex:o-1,pageSize:d}},onPaginationChange:Y=>{if(typeof Y=="function"){const Vs=Y({pageIndex:o-1,pageSize:d});sr(Vs.pageIndex+1)}else sr(Y.pageIndex+1)}}),Qi=()=>{t(Y=>Y+1)},sr=Y=>{l(Y)},oa=Y=>{C(Y)},ca=Y=>{w(Y),C(1)},Xi=Y=>{te(Y),C(1)},Zi=()=>{E(""),k(""),te("all"),C(1)},da=Y=>{y(Y),S(!0)},eo=Y=>{u(Y),c(!0)},so=async()=>{try{const Y=await ve.getLogClearStats({days:se,level:cs==="all"?void 0:cs});ct(Y.data),mt(!0)}catch(Y){console.error("Failed to get clear stats:",Y),$.error(s("dashboard:systemLog.getStatsFailed"))}},to=async()=>{ot(!0);try{const{data:Y}=await ve.clearSystemLog({days:se,level:cs==="all"?void 0:cs,limit:re});Y&&($.success(s("dashboard:systemLog.clearSuccess",{count:Y.cleared_count}),{duration:3e3}),B(!1),mt(!1),ct(null),be())}catch(Y){console.error("Failed to clear logs:",Y),$.error(s("dashboard:systemLog.clearLogsFailed"))}finally{ot(!1)}};if(U||Ki)return e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx(ka,{className:"h-6 w-6 animate-spin"})});const ao=Y=>Y?e.jsx(Nl,{className:"h-5 w-5 text-green-500"}):e.jsx(wl,{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(Se,{children:[e.jsxs(De,{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(Xs,{children:s("dashboard:queue.status.description")})]}),e.jsx(G,{variant:"outline",size:"icon",onClick:Qi,disabled:Oe||Jn,children:e.jsx(rn,{className:_("h-4 w-4",(Oe||Jn)&&"animate-spin")})})]}),e.jsx(Fe,{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(ye?.status||!1),e.jsx("span",{className:"font-medium",children:s("dashboard:queue.status.running")})]}),e.jsx(K,{variant:ye?.status?"secondary":"destructive",children:ye?.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:ye?.wait?.default||0})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{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:ye?.recentJobs||0}),e.jsx(ya,{value:(ye?.recentJobs||0)/(ye?.periods?.recentJobs||1)*100,className:"h-1"})]})}),e.jsx(ce,{children:e.jsx("p",{children:s("dashboard:queue.details.statisticsPeriod",{hours:ye?.periods?.recentJobs||0})})})]})}),e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{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:ye?.jobsPerMinute||0}),e.jsx(ya,{value:(ye?.jobsPerMinute||0)/(ye?.queueWithMaxThroughput?.throughput||1)*100,className:"h-1"})]})}),e.jsx(ce,{children:e.jsx("p",{children:s("dashboard:queue.details.maxThroughput",{value:ye?.queueWithMaxThroughput?.throughput||0})})})]})})]})]})})]}),e.jsxs(Se,{children:[e.jsxs(De,{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(Xs,{children:s("dashboard:queue.details.description")})]}),e.jsx(Fe,{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:ye?.failedJobs||0}),e.jsx(bn,{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:ye?.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:[ye?.queueWithMaxRuntime?.runtime||0,"s"]}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:ye?.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:[ye?.processes||0," /"," ",(ye?.processes||0)+(ye?.pausedMasters||0)]})]}),e.jsx(ya,{value:(ye?.processes||0)/((ye?.processes||0)+(ye?.pausedMasters||0))*100,className:"mt-2 h-1"})]})]})})]})]}),e.jsxs(Se,{children:[e.jsxs(De,{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(yn,{className:"h-5 w-5"}),s("dashboard:systemLog.title")]}),e.jsx(Xs,{children:s("dashboard:systemLog.description")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{variant:"outline",onClick:()=>P(!0),children:s("dashboard:systemLog.viewAll")}),e.jsxs(G,{variant:"outline",onClick:()=>B(!0),className:"text-destructive hover:text-destructive",children:[e.jsx(ms,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.clearLogs")]})]})]}),e.jsx(Fe,{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:H?.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:H?.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(_n,{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:H?.logs?.error||0})]})]}),H?.logs&&H.logs.total>0&&e.jsxs("div",{className:"mt-3 text-center text-sm text-muted-foreground",children:[s("dashboard:systemLog.totalLogs"),": ",H.logs.total]})]})})]}),e.jsx(de,{open:r,onOpenChange:a,children:e.jsxs(oe,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(ge,{children:e.jsx(me,{children:s("dashboard:queue.details.failedJobsDetailTitle")})}),e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(ns,{table:er,showPagination:!1,isLoading:Bi}),e.jsx(mi,{table:er}),Zn.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(rn,{className:"mr-2 h-4 w-4"}),s("dashboard:common.refresh")]}),e.jsx(Zs,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})]})]})}),e.jsx(de,{open:i,onOpenChange:c,children:e.jsxs(oe,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(ge,{children:e.jsx(me,{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(de,{open:p,onOpenChange:P,children:e.jsxs(oe,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(ge,{children:e.jsx(me,{children:s("dashboard:systemLog.title")})}),e.jsxs(bt,{value:W,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(rt,{className:"grid w-auto grid-cols-4",children:[e.jsxs(Be,{value:"all",className:"flex items-center gap-2",children:[e.jsx(yn,{className:"h-4 w-4"}),s("dashboard:systemLog.tabs.all")]}),e.jsxs(Be,{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(Be,{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(Be,{value:"error",className:"flex items-center gap-2",children:[e.jsx(_n,{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(Rn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(D,{placeholder:s("dashboard:systemLog.search"),value:M,onChange:Y=>E(Y.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:g,selectedLevel:W,total:ia,currentPage:T,pageSize:F,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:g,selectedLevel:W,total:ia,currentPage:T,pageSize:F,onViewDetail:da,onPageChange:oa,onPageSizeChange:ca})}),e.jsx(bs,{value:"warning",className:"mt-0",children:e.jsx(ga,{data:la,isLoading:ra,searchKeyword:g,selectedLevel:W,total:ia,currentPage:T,pageSize:F,onViewDetail:da,onPageChange:oa,onPageSizeChange:ca})}),e.jsx(bs,{value:"error",className:"mt-0",children:e.jsx(ga,{data:la,isLoading:ra,searchKeyword:g,selectedLevel:W,total:ia,currentPage:T,pageSize:F,onViewDetail:da,onPageChange:oa,onPageSizeChange:ca})})]}),e.jsxs(Ie,{children:[e.jsxs(G,{variant:"outline",onClick:()=>Wi(),children:[e.jsx(rn,{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(Zs,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})]})]})}),e.jsx(de,{open:N,onOpenChange:S,children:e.jsxs(oe,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(ge,{children:e.jsx(me,{children:s("dashboard:systemLog.detailTitle")})}),V&&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:V.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:_a(V.created_at)||_a(V.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:V.title||V.message||""})]}),(V.host||V.ip)&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[V.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:V.host})]}),V.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:V.ip})]})]}),V.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:V.uri})})]}),V.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(K,{variant:"outline",className:"text-base font-medium",children:V.method})})]}),V.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(V.data),null,2)}catch{return V.data}})()})})]}),V.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 Y=JSON.parse(V.context);if(Y.exception){const Vs=Y.exception,_t=Vs["\0*\0message"]||"",no=Vs["\0*\0file"]||"",ro=Vs["\0*\0line"]||"";return`${_t}
|
||
|
||
File: ${no}
|
||
Line: ${ro}`}return JSON.stringify(Y,null,2)}catch{return V.context}})()})})]})]}),e.jsx(Ie,{children:e.jsx(Zs,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})})]})}),e.jsx(de,{open:ae,onOpenChange:B,children:e.jsxs(oe,{className:"max-w-2xl",children:[e.jsx(ge,{children:e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(ms,{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(Qe,{htmlFor:"clearDays",children:s("dashboard:systemLog.clearDays")}),e.jsx(D,{id:"clearDays",type:"number",min:"0",max:"365",value:se,onChange:Y=>{const Vs=Y.target.value;if(Vs==="")fe(0);else{const _t=parseInt(Vs);!isNaN(_t)&&_t>=0&&_t<=365&&fe(_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(Qe,{htmlFor:"clearLevel",children:s("dashboard:systemLog.clearLevel")}),e.jsxs(X,{value:cs,onValueChange:Me,children:[e.jsx(J,{children:e.jsx(Z,{})}),e.jsxs(Q,{children:[e.jsx(q,{value:"all",children:s("dashboard:systemLog.tabs.all")}),e.jsx(q,{value:"info",children:s("dashboard:systemLog.tabs.info")}),e.jsx(q,{value:"warning",children:s("dashboard:systemLog.tabs.warning")}),e.jsx(q,{value:"error",children:s("dashboard:systemLog.tabs.error")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Qe,{htmlFor:"clearLimit",children:s("dashboard:systemLog.clearLimit")}),e.jsx(D,{id:"clearLimit",type:"number",min:"100",max:"10000",value:re,onChange:Y=>ks(parseInt(Y.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(Vn,{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:_s,children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.getStats")]})]}),dt&&Es&&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:Es.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:Es.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:Es.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:()=>{B(!1),mt(!1),ct(null)},children:s("common:cancel")}),e.jsx(G,{variant:"destructive",onClick:to,disabled:_s||!dt||!Es,children:_s?e.jsxs(e.Fragment,{children:[e.jsx(ka,{className:"mr-2 h-4 w-4 animate-spin"}),s("dashboard:systemLog.clearing")]}):e.jsxs(e.Fragment,{children:[e.jsx(ms,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.confirmClear")]})})]})]})})]})}function Ym(){const{t:s}=O();return e.jsxs(qe,{children:[e.jsxs(Ue,{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(os,{}),e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsx(Je,{children:e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsx(Um,{}),e.jsx(Om,{}),e.jsx(Hm,{}),e.jsx(Wm,{})]})})})]})}const Jm=Object.freeze(Object.defineProperty({__proto__:null,default:Ym},Symbol.toStringTag,{value:"Module"}));function Qm({className:s,items:n,...t}){const{pathname:r}=Dn(),a=Bs(),[o,l]=m.useState(r??"/settings"),d=u=>{l(u),a(u)},{t:x}=O("settings");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-1 md:hidden",children:e.jsxs(X,{value:o,onValueChange:d,children:[e.jsx(J,{className:"h-12 sm:w-48",children:e.jsx(Z,{placeholder:"Theme"})}),e.jsx(Q,{children:n.map(u=>e.jsx(q,{value:u.href,children:e.jsxs("div",{className:"flex gap-x-4 px-2 py-1",children:[e.jsx("span",{className:"scale-125",children:u.icon}),e.jsx("span",{className:"text-md",children:x(u.title)})]})},u.href))})]})}),e.jsx("div",{className:"hidden w-full overflow-x-auto bg-background px-1 py-2 md:block",children:e.jsx("nav",{className:_("flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",s),...t,children:n.map(u=>e.jsxs(st,{to:u.href,className:_(It({variant:"ghost"}),r===u.href?"bg-muted hover:bg-muted":"hover:bg-transparent hover:underline","justify-start"),children:[e.jsx("span",{className:"mr-2",children:u.icon}),x(u.title)]},u.href))})})]})}const Xm=[{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(tl,{size:18}),href:"/config/system/safe",description:"safe.description"},{title:"subscribe.title",key:"subscribe",icon:e.jsx(al,{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(sl,{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(el,{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 Zm(){const{t:s}=O("settings");return e.jsxs(qe,{fadedBelow:!0,fixedHeight:!0,children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(Re,{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(Qm,{items:Xm})}),e.jsx("div",{className:"flex-1 w-full p-1 pr-4",children:e.jsx("div",{className:"pb-16",children:e.jsx(Fn,{})})})]})]})]})}const eu=Object.freeze(Object.defineProperty({__proto__:null,default:Zm},Symbol.toStringTag,{value:"Module"})),ee=m.forwardRef(({className:s,...n},t)=>e.jsx(Cl,{className:_("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:_("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")})}));ee.displayName=Cl.displayName;const Rs=m.forwardRef(({className:s,...n},t)=>e.jsx("textarea",{className:_("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}));Rs.displayName="Textarea";const su=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 tu(){const{t:s}=O("settings"),[n,t]=m.useState(!1),r=m.useRef(null),{data:a}=ne({queryKey:["settings","site"],queryFn:()=>ve.getSettings("site")}),{data:o}=ne({queryKey:["plans"],queryFn:()=>ys.getList()}),l=Ne({resolver:ke(su),defaultValues:{},mode:"onBlur"}),{mutateAsync:d}=$s({mutationFn:ve.saveSettings,onSuccess:i=>{i.data&&$.success(s("common.autoSaved"))}});m.useEffect(()=>{if(a?.data?.site){const i=a?.data?.site;Object.entries(i).forEach(([c,p])=>{l.setValue(c,p)}),r.current=i}},[a]);const x=m.useCallback(Le.debounce(async i=>{if(!Le.isEqual(i,r.current)){t(!0);try{const c=Object.entries(i).reduce((p,[P,T])=>(p[P]=T===null?"":T,p),{});await d(c),r.current=i}finally{t(!1)}}},1e3),[d]),u=m.useCallback(i=>{x(i)},[x]);return m.useEffect(()=>{const i=l.watch(c=>{u(c)});return()=>i.unsubscribe()},[l.watch,u]),e.jsx(Te,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:l.control,name:"app_name",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("site.form.siteName.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("site.form.siteName.placeholder"),...i,value:i.value||"",onChange:c=>{i.onChange(c),u(l.getValues())}})}),e.jsx(A,{children:s("site.form.siteName.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"app_description",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("site.form.siteDescription.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("site.form.siteDescription.placeholder"),...i,value:i.value||"",onChange:c=>{i.onChange(c),u(l.getValues())}})}),e.jsx(A,{children:s("site.form.siteDescription.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"app_url",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("site.form.siteUrl.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("site.form.siteUrl.placeholder"),...i,value:i.value||"",onChange:c=>{i.onChange(c),u(l.getValues())}})}),e.jsx(A,{children:s("site.form.siteUrl.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"force_https",render:({field:i})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("site.form.forceHttps.label")}),e.jsx(A,{children:s("site.form.forceHttps.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:!!i.value,onCheckedChange:c=>{i.onChange(Number(c)),u(l.getValues())}})})]})}),e.jsx(j,{control:l.control,name:"logo",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("site.form.logo.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("site.form.logo.placeholder"),...i,value:i.value||"",onChange:c=>{i.onChange(c),u(l.getValues())}})}),e.jsx(A,{children:s("site.form.logo.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"subscribe_url",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("site.form.subscribeUrl.label")}),e.jsx(b,{children:e.jsx(Rs,{placeholder:s("site.form.subscribeUrl.placeholder"),...i,value:i.value||"",onChange:c=>{i.onChange(c),u(l.getValues())}})}),e.jsx(A,{children:s("site.form.subscribeUrl.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"tos_url",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("site.form.tosUrl.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("site.form.tosUrl.placeholder"),...i,value:i.value||"",onChange:c=>{i.onChange(c),u(l.getValues())}})}),e.jsx(A,{children:s("site.form.tosUrl.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"stop_register",render:({field:i})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("site.form.stopRegister.label")}),e.jsx(A,{children:s("site.form.stopRegister.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:!!i.value,onCheckedChange:c=>{i.onChange(Number(c)),u(l.getValues())}})})]})}),e.jsx(j,{control:l.control,name:"try_out_plan_id",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("site.form.tryOut.label")}),e.jsx(b,{children:e.jsxs(X,{value:i.value?.toString(),onValueChange:c=>{i.onChange(Number(c)),u(l.getValues())},children:[e.jsx(J,{children:e.jsx(Z,{placeholder:s("site.form.tryOut.placeholder")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:s("site.form.tryOut.placeholder")}),o?.data?.map(c=>e.jsx(q,{value:c.id.toString(),children:c.name},c.id.toString()))]})]})}),e.jsx(A,{children:s("site.form.tryOut.description")}),e.jsx(R,{})]})}),!!l.watch("try_out_plan_id")&&e.jsx(j,{control:l.control,name:"try_out_hour",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"",children:s("site.form.tryOut.duration.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("site.form.tryOut.duration.placeholder"),...i,value:i.value||"",onChange:c=>{i.onChange(c),u(l.getValues())}})}),e.jsx(A,{children:s("site.form.tryOut.duration.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"currency",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("site.form.currency.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("site.form.currency.placeholder"),...i,value:i.value||"",onChange:c=>{i.onChange(c),u(l.getValues())}})}),e.jsx(A,{children:s("site.form.currency.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"currency_symbol",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("site.form.currencySymbol.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("site.form.currencySymbol.placeholder"),...i,value:i.value||"",onChange:c=>{i.onChange(c),u(l.getValues())}})}),e.jsx(A,{children:s("site.form.currencySymbol.description")}),e.jsx(R,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("site.form.saving")})]})})}function au(){const{t:s}=O("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(Re,{}),e.jsx(tu,{})]})}const nu=Object.freeze(Object.defineProperty({__proto__:null,default:au},Symbol.toStringTag,{value:"Module"})),ru=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()}),lu={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 iu(){const{t:s}=O("settings"),[n,t]=m.useState(!1),[r,a]=m.useState(!1),o=m.useRef(null),l=Ne({resolver:ke(ru),defaultValues:lu,mode:"onBlur"}),{data:d}=ne({queryKey:["settings","safe"],queryFn:()=>ve.getSettings("safe")}),{mutateAsync:x}=$s({mutationFn:ve.saveSettings,onSuccess:c=>{c.data&&$.success(s("common.autoSaved"))}});m.useEffect(()=>{if(d?.data.safe){const c=d.data.safe,p={};Object.entries(c).forEach(([P,T])=>{if(typeof T=="number"){const C=String(T);l.setValue(P,C),p[P]=C}else l.setValue(P,T),p[P]=T}),o.current=p,a(!0)}},[d]);const u=m.useCallback(Le.debounce(async c=>{if(!Le.isEqual(c,o.current)){t(!0);try{const p={...c,email_whitelist_suffix:c.email_whitelist_suffix?.filter(Boolean)||[]};await x(p),o.current=c}finally{t(!1)}}},1e3),[x]),i=m.useCallback(c=>{r&&u(c)},[u,r]);return m.useEffect(()=>{if(!r)return;const c=l.watch(p=>{i(p)});return()=>c.unsubscribe()},[l.watch,i,r]),e.jsx(Te,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:l.control,name:"email_verify",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.emailVerify.label")}),e.jsx(A,{children:s("safe.form.emailVerify.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value||!1,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),e.jsx(j,{control:l.control,name:"email_gmail_limit_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.gmailLimit.label")}),e.jsx(A,{children:s("safe.form.gmailLimit.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value||!1,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),e.jsx(j,{control:l.control,name:"safe_mode_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.safeMode.label")}),e.jsx(A,{children:s("safe.form.safeMode.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value||!1,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),e.jsx(j,{control:l.control,name:"secure_path",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.securePath.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.securePath.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.securePath.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"email_whitelist_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.emailWhitelist.label")}),e.jsx(A,{children:s("safe.form.emailWhitelist.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value||!1,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),l.watch("email_whitelist_enable")&&e.jsx(j,{control:l.control,name:"email_whitelist_suffix",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.emailWhitelist.suffixes.label")}),e.jsx(b,{children:e.jsx(Rs,{placeholder:s("safe.form.emailWhitelist.suffixes.placeholder"),...c,value:(c.value||[]).join(`
|
||
`),onChange:p=>{const P=p.target.value.split(`
|
||
`).filter(Boolean);c.onChange(P),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.emailWhitelist.suffixes.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"captcha_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.enable.label")}),e.jsx(A,{children:s("safe.form.captcha.enable.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value||!1,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),l.watch("captcha_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:l.control,name:"captcha_type",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.type.label")}),e.jsxs(X,{onValueChange:p=>{c.onChange(p),i(l.getValues())},value:c.value||"recaptcha",children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:s("safe.form.captcha.type.description")})})}),e.jsxs(Q,{children:[e.jsx(q,{value:"recaptcha",children:s("safe.form.captcha.type.options.recaptcha")}),e.jsx(q,{value:"recaptcha-v3",children:s("safe.form.captcha.type.options.recaptcha-v3")}),e.jsx(q,{value:"turnstile",children:s("safe.form.captcha.type.options.turnstile")})]})]}),e.jsx(A,{children:s("safe.form.captcha.type.description")}),e.jsx(R,{})]})}),l.watch("captcha_type")==="recaptcha"&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:l.control,name:"recaptcha_site_key",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.recaptcha.siteKey.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.captcha.recaptcha.siteKey.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.captcha.recaptcha.siteKey.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"recaptcha_key",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.recaptcha.key.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.captcha.recaptcha.key.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.captcha.recaptcha.key.description")}),e.jsx(R,{})]})})]}),l.watch("captcha_type")==="recaptcha-v3"&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:l.control,name:"recaptcha_v3_site_key",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.siteKey.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.captcha.recaptcha_v3.siteKey.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.captcha.recaptcha_v3.siteKey.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"recaptcha_v3_secret_key",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.secretKey.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.captcha.recaptcha_v3.secretKey.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.captcha.recaptcha_v3.secretKey.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"recaptcha_v3_score_threshold",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.scoreThreshold.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",step:"0.1",min:"0",max:"1",placeholder:s("safe.form.captcha.recaptcha_v3.scoreThreshold.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.captcha.recaptcha_v3.scoreThreshold.description")}),e.jsx(R,{})]})})]}),l.watch("captcha_type")==="turnstile"&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:l.control,name:"turnstile_site_key",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.turnstile.siteKey.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.captcha.turnstile.siteKey.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.captcha.turnstile.siteKey.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"turnstile_secret_key",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.turnstile.secretKey.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.captcha.turnstile.secretKey.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.captcha.turnstile.secretKey.description")}),e.jsx(R,{})]})})]})]}),e.jsx(j,{control:l.control,name:"register_limit_by_ip_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.registerLimit.enable.label")}),e.jsx(A,{children:s("safe.form.registerLimit.enable.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value||!1,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),l.watch("register_limit_by_ip_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:l.control,name:"register_limit_count",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.registerLimit.count.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.registerLimit.count.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.registerLimit.count.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"register_limit_expire",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.registerLimit.expire.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.registerLimit.expire.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.registerLimit.expire.description")}),e.jsx(R,{})]})})]}),e.jsx(j,{control:l.control,name:"password_limit_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.passwordLimit.enable.label")}),e.jsx(A,{children:s("safe.form.passwordLimit.enable.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value||!1,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),l.watch("password_limit_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:l.control,name:"password_limit_count",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.passwordLimit.count.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.passwordLimit.count.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.passwordLimit.count.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"password_limit_expire",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.passwordLimit.expire.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("safe.form.passwordLimit.expire.placeholder"),...c,value:c.value||"",onChange:p=>{c.onChange(p),i(l.getValues())}})}),e.jsx(A,{children:s("safe.form.passwordLimit.expire.description")}),e.jsx(R,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("safe.form.saving")})]})})}function ou(){const{t:s}=O("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(Re,{}),e.jsx(iu,{})]})}const cu=Object.freeze(Object.defineProperty({__proto__:null,default:ou},Symbol.toStringTag,{value:"Module"})),du=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")}),mu={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 uu(){const{t:s}=O("settings"),[n,t]=m.useState(!1),r=m.useRef(null),a=Ne({resolver:ke(du),defaultValues:mu,mode:"onBlur"}),{data:o}=ne({queryKey:["settings","subscribe"],queryFn:()=>ve.getSettings("subscribe")}),{mutateAsync:l}=$s({mutationFn:ve.saveSettings,onSuccess:u=>{u.data&&$.success(s("common.autoSaved"))}});m.useEffect(()=>{if(o?.data?.subscribe){const u=o?.data?.subscribe;Object.entries(u).forEach(([i,c])=>{a.setValue(i,c)}),r.current=u}},[o]);const d=m.useCallback(Le.debounce(async u=>{if(!Le.isEqual(u,r.current)){t(!0);try{await l(u),r.current=u}finally{t(!1)}}},1e3),[l]),x=m.useCallback(u=>{d(u)},[d]);return m.useEffect(()=>{const u=a.watch(i=>{x(i)});return()=>u.unsubscribe()},[a.watch,x]),e.jsx(Te,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:a.control,name:"plan_change_enable",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.plan_change_enable.title")}),e.jsx(A,{children:s("subscribe.plan_change_enable.description")}),e.jsx(b,{children:e.jsx(ee,{checked:u.value||!1,onCheckedChange:i=>{u.onChange(i),x(a.getValues())}})}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"reset_traffic_method",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.reset_traffic_method.title")}),e.jsxs(X,{onValueChange:u.onChange,value:u.value?.toString()||"0",children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:"请选择重置方式"})})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:s("subscribe.reset_traffic_method.options.monthly_first")}),e.jsx(q,{value:"1",children:s("subscribe.reset_traffic_method.options.monthly_reset")}),e.jsx(q,{value:"2",children:s("subscribe.reset_traffic_method.options.no_reset")}),e.jsx(q,{value:"3",children:s("subscribe.reset_traffic_method.options.yearly_first")}),e.jsx(q,{value:"4",children:s("subscribe.reset_traffic_method.options.yearly_reset")})]})]}),e.jsx(A,{children:s("subscribe.reset_traffic_method.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"surplus_enable",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.surplus_enable.title")}),e.jsx(A,{children:s("subscribe.surplus_enable.description")}),e.jsx(b,{children:e.jsx(ee,{checked:u.value||!1,onCheckedChange:i=>{u.onChange(i),x(a.getValues())}})}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"new_order_event_id",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.new_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(b,{children:e.jsxs(X,{onValueChange:u.onChange,value:u.value?.toString(),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:"请选择"})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:s("subscribe.new_order_event.options.no_action")}),e.jsx(q,{value:"1",children:s("subscribe.new_order_event.options.reset_traffic")})]})]})})}),e.jsx(A,{children:s("subscribe.new_order_event.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"renew_order_event_id",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.renew_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(b,{children:e.jsxs(X,{onValueChange:u.onChange,value:u.value?.toString(),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:"请选择"})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:s("subscribe.renew_order_event.options.no_action")}),e.jsx(q,{value:"1",children:s("subscribe.renew_order_event.options.reset_traffic")})]})]})})}),e.jsx(A,{children:s("subscribe.renew_order_event.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"change_order_event_id",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.change_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(b,{children:e.jsxs(X,{onValueChange:u.onChange,value:u.value?.toString(),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:"请选择"})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:s("subscribe.change_order_event.options.no_action")}),e.jsx(q,{value:"1",children:s("subscribe.change_order_event.options.reset_traffic")})]})]})})}),e.jsx(A,{children:s("subscribe.change_order_event.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"subscribe_path",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.subscribe_path.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:"subscribe",...u,value:u.value||"",onChange:i=>{u.onChange(i),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:u.value||"s"}),e.jsx("br",{}),s("subscribe.subscribe_path.restart_tip")]}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"show_info_to_server_enable",render:({field:u})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("subscribe.show_info_to_server.title")}),e.jsx(A,{children:s("subscribe.show_info_to_server.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:u.value||!1,onCheckedChange:i=>{u.onChange(i),x(a.getValues())}})})]})}),e.jsx(j,{control:a.control,name:"show_protocol_to_server_enable",render:({field:u})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("subscribe.show_protocol_to_server.title")}),e.jsx(A,{children:s("subscribe.show_protocol_to_server.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:u.value||!1,onCheckedChange:i=>{u.onChange(i),x(a.getValues())}})})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function xu(){const{t:s}=O("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(Re,{}),e.jsx(uu,{})]})}const hu=Object.freeze(Object.defineProperty({__proto__:null,default:xu},Symbol.toStringTag,{value:"Module"})),gu=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)}),pu={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 fu(){const{t:s}=O("settings"),[n,t]=m.useState(!1),[r,a]=m.useState(!1),o=m.useRef(null),l=Ne({resolver:ke(gu),defaultValues:pu,mode:"onBlur"}),{data:d}=ne({queryKey:["settings","invite"],queryFn:()=>ve.getSettings("invite")}),{mutateAsync:x}=$s({mutationFn:ve.saveSettings,onSuccess:c=>{c.data&&$.success(s("common.autoSaved"))}});m.useEffect(()=>{if(d?.data?.invite){const c=d?.data?.invite,p={};Object.entries(c).forEach(([P,T])=>{if(typeof T=="number"){const C=String(T);l.setValue(P,C),p[P]=C}else l.setValue(P,T),p[P]=T}),o.current=p,a(!0)}},[d]);const u=m.useCallback(Le.debounce(async c=>{if(!Le.isEqual(c,o.current)){t(!0);try{await x(c),o.current=c}finally{t(!1)}}},1e3),[x]),i=m.useCallback(c=>{r&&u(c)},[u,r]);return m.useEffect(()=>{if(!r)return;const c=l.watch(p=>{i(p)});return()=>c.unsubscribe()},[l.watch,i,r]),e.jsx(Te,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:l.control,name:"invite_force",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.invite_force.title")}),e.jsx(A,{children:s("invite.invite_force.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),e.jsx(j,{control:l.control,name:"invite_commission",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("invite.invite_commission.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("invite.invite_commission.placeholder"),...c,value:c.value||""})}),e.jsx(A,{children:s("invite.invite_commission.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"invite_gen_limit",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("invite.invite_gen_limit.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("invite.invite_gen_limit.placeholder"),...c,value:c.value||""})}),e.jsx(A,{children:s("invite.invite_gen_limit.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"invite_never_expire",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.invite_never_expire.title")}),e.jsx(A,{children:s("invite.invite_never_expire.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),e.jsx(j,{control:l.control,name:"commission_first_time_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.commission_first_time.title")}),e.jsx(A,{children:s("invite.commission_first_time.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),e.jsx(j,{control:l.control,name:"commission_auto_check_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.commission_auto_check.title")}),e.jsx(A,{children:s("invite.commission_auto_check.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),e.jsx(j,{control:l.control,name:"commission_withdraw_limit",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("invite.commission_withdraw_limit.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("invite.commission_withdraw_limit.placeholder"),...c,value:c.value||""})}),e.jsx(A,{children:s("invite.commission_withdraw_limit.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"commission_withdraw_method",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("invite.commission_withdraw_method.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("invite.commission_withdraw_method.placeholder"),...c,value:Array.isArray(c.value)?c.value.join(","):"",onChange:p=>{const P=p.target.value.split(",").filter(Boolean);c.onChange(P),i(l.getValues())}})}),e.jsx(A,{children:s("invite.commission_withdraw_method.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"withdraw_close_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.withdraw_close.title")}),e.jsx(A,{children:s("invite.withdraw_close.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),e.jsx(j,{control:l.control,name:"commission_distribution_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.commission_distribution.title")}),e.jsx(A,{children:s("invite.commission_distribution.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value,onCheckedChange:p=>{c.onChange(p),i(l.getValues())}})})]})}),l.watch("commission_distribution_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(j,{control:l.control,name:"commission_distribution_l1",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{children:s("invite.commission_distribution.l1")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...c,value:c.value||"",onChange:p=>{const P=p.target.value?Number(p.target.value):0;c.onChange(P),i(l.getValues())}})}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"commission_distribution_l2",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{children:s("invite.commission_distribution.l2")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...c,value:c.value||"",onChange:p=>{const P=p.target.value?Number(p.target.value):0;c.onChange(P),i(l.getValues())}})}),e.jsx(R,{})]})}),e.jsx(j,{control:l.control,name:"commission_distribution_l3",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{children:s("invite.commission_distribution.l3")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...c,value:c.value||"",onChange:p=>{const P=p.target.value?Number(p.target.value):0;c.onChange(P),i(l.getValues())}})}),e.jsx(R,{})]})})]}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("invite.saving")})]})})}function ju(){const{t:s}=O("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(Re,{}),e.jsx(fu,{})]})}const vu=Object.freeze(Object.defineProperty({__proto__:null,default:ju},Symbol.toStringTag,{value:"Module"})),bu=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()}),yu={frontend_theme:"",frontend_theme_sidebar:"",frontend_theme_header:"",frontend_theme_color:"",frontend_background_url:""};function _u(){const{data:s}=ne({queryKey:["settings","frontend"],queryFn:()=>ve.getSettings("frontend")}),n=Ne({resolver:ke(bu),defaultValues:yu,mode:"onChange"});m.useEffect(()=>{if(s?.data?.frontend){const r=s?.data?.frontend;Object.entries(r).forEach(([a,o])=>{n.setValue(a,o)})}},[s]);function t(r){ve.saveSettings(r).then(({data:a})=>{a&&$.success("更新成功")})}return e.jsx(Te,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(t),className:"space-y-8",children:[e.jsx(j,{control:n.control,name:"frontend_theme_sidebar",render:({field:r})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:"边栏风格"}),e.jsx(A,{children:"边栏风格"})]}),e.jsx(b,{children:e.jsx(ee,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(j,{control:n.control,name:"frontend_theme_header",render:({field:r})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:"头部风格"}),e.jsx(A,{children:"边栏风格"})]}),e.jsx(b,{children:e.jsx(ee,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(j,{control:n.control,name:"frontend_theme_color",render:({field:r})=>e.jsxs(f,{children:[e.jsx(v,{children:"主题色"}),e.jsxs("div",{className:"relative w-max",children:[e.jsx(b,{children:e.jsxs("select",{className:_(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(En,{className:"absolute right-3 top-2.5 h-4 w-4 opacity-50"})]}),e.jsx(A,{children:"主题色"}),e.jsx(R,{})]})}),e.jsx(j,{control:n.control,name:"frontend_background_url",render:({field:r})=>e.jsxs(f,{children:[e.jsx(v,{children:"背景"}),e.jsx(b,{children:e.jsx(D,{placeholder:"请输入图片地址",...r})}),e.jsx(A,{children:"将会在后台登录页面进行展示。"}),e.jsx(R,{})]})}),e.jsx(L,{type:"submit",children:"保存设置"})]})})}function Nu(){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(Re,{}),e.jsx(_u,{})]})}const wu=Object.freeze(Object.defineProperty({__proto__:null,default:Nu},Symbol.toStringTag,{value:"Module"})),Cu=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()}),Su={server_pull_interval:0,server_push_interval:0,server_token:"",device_limit_mode:0};function ku(){const{t:s}=O("settings"),[n,t]=m.useState(!1),r=m.useRef(null),a=Ne({resolver:ke(Cu),defaultValues:Su,mode:"onBlur"}),{data:o}=ne({queryKey:["settings","server"],queryFn:()=>ve.getSettings("server")}),{mutateAsync:l}=$s({mutationFn:ve.saveSettings,onSuccess:i=>{i.data&&$.success(s("common.AutoSaved"))}});m.useEffect(()=>{if(o?.data.server){const i=o.data.server;Object.entries(i).forEach(([c,p])=>{a.setValue(c,p)}),r.current=i}},[o]);const d=m.useCallback(Le.debounce(async i=>{if(!Le.isEqual(i,r.current)){t(!0);try{await l(i),r.current=i}finally{t(!1)}}},1e3),[l]),x=m.useCallback(i=>{d(i)},[d]);m.useEffect(()=>{const i=a.watch(c=>{x(c)});return()=>i.unsubscribe()},[a.watch,x]);const u=()=>{const i=Math.floor(Math.random()*17)+16,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let p="";for(let P=0;P<i;P++)p+=c.charAt(Math.floor(Math.random()*c.length));a.setValue("server_token",p)};return e.jsx(Te,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:a.control,name:"server_token",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("server.server_token.title")}),e.jsx(b,{children:e.jsxs("div",{className:"relative",children:[e.jsx(D,{placeholder:s("server.server_token.placeholder"),...i,value:i.value||"",className:"pr-10"}),e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{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(),u()},children:e.jsx(ed,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(ce,{children:e.jsx("p",{children:s("server.server_token.generate_tooltip")})})]})})]})}),e.jsx(A,{children:s("server.server_token.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"server_pull_interval",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("server.server_pull_interval.title")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:s("server.server_pull_interval.placeholder"),...i,value:i.value||"",onChange:c=>{const p=c.target.value?Number(c.target.value):null;i.onChange(p)}})}),e.jsx(A,{children:s("server.server_pull_interval.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"server_push_interval",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("server.server_push_interval.title")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:s("server.server_push_interval.placeholder"),...i,value:i.value||"",onChange:c=>{const p=c.target.value?Number(c.target.value):null;i.onChange(p)}})}),e.jsx(A,{children:s("server.server_push_interval.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"device_limit_mode",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("server.device_limit_mode.title")}),e.jsxs(X,{onValueChange:i.onChange,value:i.value?.toString()||"0",children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:s("server.device_limit_mode.placeholder")})})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:s("server.device_limit_mode.strict")}),e.jsx(q,{value:"1",children:s("server.device_limit_mode.relaxed")})]})]}),e.jsx(A,{children:s("server.device_limit_mode.description")}),e.jsx(R,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("server.saving")})]})})}function Tu(){const{t:s}=O("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(Re,{}),e.jsx(ku,{})]})}const Du=Object.freeze(Object.defineProperty({__proto__:null,default:Tu},Symbol.toStringTag,{value:"Module"}));function Fu({open:s,onOpenChange:n,result:t}){const r=!t.error;return e.jsx(de,{open:s,onOpenChange:n,children:e.jsxs(oe,{className:"sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(Nl,{className:"h-5 w-5 text-green-500"}):e.jsx(wl,{className:"h-5 w-5 text-destructive"}),e.jsx(me,{children:r?"邮件发送成功":"邮件发送失败"})]}),e.jsx(Ae,{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(ft,{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 Pu=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 Lu(){const{t:s}=O("settings"),[n,t]=m.useState(null),[r,a]=m.useState(!1),o=m.useRef(null),[l,d]=m.useState(!1),x=Ne({resolver:ke(Pu),defaultValues:{},mode:"onBlur"}),{data:u}=ne({queryKey:["settings","email"],queryFn:()=>ve.getSettings("email")}),{data:i}=ne({queryKey:["emailTemplate"],queryFn:()=>ve.getEmailTemplate()}),{mutateAsync:c}=$s({mutationFn:ve.saveSettings,onSuccess:F=>{F.data&&$.success(s("common.autoSaved"))}}),{mutate:p,isPending:P}=$s({mutationFn:ve.sendTestMail,onMutate:()=>{t(null),a(!1)},onSuccess:F=>{t(F.data),a(!0),F.data.error?$.error(s("email.test.error")):$.success(s("email.test.success"))}});m.useEffect(()=>{if(u?.data.email){const F=u.data.email;Object.entries(F).forEach(([w,V])=>{x.setValue(w,V)}),o.current=F}},[u]);const T=m.useCallback(Le.debounce(async F=>{if(!Le.isEqual(F,o.current)){d(!0);try{await c(F),o.current=F}finally{d(!1)}}},1e3),[c]),C=m.useCallback(F=>{T(F)},[T]);return m.useEffect(()=>{const F=x.watch(w=>{C(w)});return()=>F.unsubscribe()},[x.watch,C]),e.jsxs(e.Fragment,{children:[e.jsx(Te,{...x,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:x.control,name:"email_host",render:({field:F})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("email.email_host.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("common.placeholder"),...F,value:F.value||""})}),e.jsx(A,{children:s("email.email_host.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"email_port",render:({field:F})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("email.email_port.title")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:s("common.placeholder"),...F,value:F.value||"",onChange:w=>{const V=w.target.value?Number(w.target.value):null;F.onChange(V)}})}),e.jsx(A,{children:s("email.email_port.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"email_encryption",render:({field:F})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("email.email_encryption.title")}),e.jsxs(X,{onValueChange:w=>{const V=w==="none"?"":w;F.onChange(V)},value:F.value===""||F.value===null||F.value===void 0?"none":F.value,children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:"请选择加密方式"})})}),e.jsxs(Q,{children:[e.jsx(q,{value:"none",children:s("email.email_encryption.none")}),e.jsx(q,{value:"ssl",children:s("email.email_encryption.ssl")}),e.jsx(q,{value:"tls",children:s("email.email_encryption.tls")})]})]}),e.jsx(A,{children:s("email.email_encryption.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"email_username",render:({field:F})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("email.email_username.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("common.placeholder"),autoComplete:"off",...F,value:F.value||""})}),e.jsx(A,{children:s("email.email_username.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"email_password",render:({field:F})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("email.email_password.title")}),e.jsx(b,{children:e.jsx(D,{type:"password",placeholder:s("common.placeholder"),autoComplete:"off",...F,value:F.value||""})}),e.jsx(A,{children:s("email.email_password.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"email_from_address",render:({field:F})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("email.email_from.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("common.placeholder"),...F,value:F.value||""})}),e.jsx(A,{children:s("email.email_from.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"email_template",render:({field:F})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("email.email_template.title")}),e.jsxs(X,{onValueChange:w=>{F.onChange(w),C(x.getValues())},value:F.value||void 0,children:[e.jsx(b,{children:e.jsx(J,{className:"w-[200px]",children:e.jsx(Z,{placeholder:s("email.email_template.placeholder")})})}),e.jsx(Q,{children:i?.data?.map(w=>e.jsx(q,{value:w,children:w},w))})]}),e.jsx(A,{children:s("email.email_template.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"remind_mail_enable",render:({field:F})=>e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("email.remind_mail.title")}),e.jsx(A,{children:s("email.remind_mail.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:F.value||!1,onCheckedChange:w=>{F.onChange(w),C(x.getValues())}})})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(L,{onClick:()=>p(),loading:P,disabled:P,children:s(P?"email.test.sending":"email.test.title")})})]})}),l&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("saving")}),n&&e.jsx(Fu,{open:r,onOpenChange:a,result:n})]})}function Ru(){const{t:s}=O("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(Re,{}),e.jsx(Lu,{})]})}const Eu=Object.freeze(Object.defineProperty({__proto__:null,default:Ru},Symbol.toStringTag,{value:"Module"})),Vu=h.object({telegram_bot_enable:h.boolean().nullable(),telegram_bot_token:h.string().nullable(),telegram_discuss_link:h.string().nullable()}),Iu={telegram_bot_enable:!1,telegram_bot_token:"",telegram_discuss_link:""};function Mu(){const{t:s}=O("settings"),[n,t]=m.useState(!1),r=m.useRef(null),a=Ne({resolver:ke(Vu),defaultValues:Iu,mode:"onBlur"}),{data:o}=ne({queryKey:["settings","telegram"],queryFn:()=>ve.getSettings("telegram")}),{mutateAsync:l}=$s({mutationFn:ve.saveSettings,onSuccess:c=>{c.data&&$.success(s("common.autoSaved"))}}),{mutate:d,isPending:x}=$s({mutationFn:ve.setTelegramWebhook,onSuccess:c=>{c.data&&$.success(s("telegram.webhook.success"))}});m.useEffect(()=>{if(o?.data.telegram){const c=o.data.telegram;Object.entries(c).forEach(([p,P])=>{a.setValue(p,P)}),r.current=c}},[o]);const u=m.useCallback(Le.debounce(async c=>{if(!Le.isEqual(c,r.current)){t(!0);try{await l(c),r.current=c}finally{t(!1)}}},1e3),[l]),i=m.useCallback(c=>{u(c)},[u]);return m.useEffect(()=>{const c=a.watch(p=>{i(p)});return()=>c.unsubscribe()},[a.watch,i]),e.jsx(Te,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:a.control,name:"telegram_bot_token",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("telegram.bot_token.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("telegram.bot_token.placeholder"),...c,value:c.value||""})}),e.jsx(A,{children:s("telegram.bot_token.description")}),e.jsx(R,{})]})}),a.watch("telegram_bot_token")&&e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("telegram.webhook.title")}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(L,{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(A,{children:s("telegram.webhook.description")}),e.jsx(R,{})]}),e.jsx(j,{control:a.control,name:"telegram_bot_enable",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("telegram.bot_enable.title")}),e.jsx(A,{children:s("telegram.bot_enable.description")}),e.jsx(b,{children:e.jsx(ee,{checked:c.value||!1,onCheckedChange:p=>{c.onChange(p),i(a.getValues())}})}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"telegram_discuss_link",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("telegram.discuss_link.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("telegram.discuss_link.placeholder"),...c,value:c.value||""})}),e.jsx(A,{children:s("telegram.discuss_link.description")}),e.jsx(R,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Ou(){const{t:s}=O("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(Re,{}),e.jsx(Mu,{})]})}const zu=Object.freeze(Object.defineProperty({__proto__:null,default:Ou},Symbol.toStringTag,{value:"Module"})),$u=h.object({windows_version:h.string().nullable(),windows_download_url:h.string().nullable(),macos_version:h.string().nullable(),macos_download_url:h.string().nullable(),android_version:h.string().nullable(),android_download_url:h.string().nullable()}),Au={windows_version:"",windows_download_url:"",macos_version:"",macos_download_url:"",android_version:"",android_download_url:""};function qu(){const{t:s}=O("settings"),[n,t]=m.useState(!1),r=m.useRef(null),a=Ne({resolver:ke($u),defaultValues:Au,mode:"onBlur"}),{data:o}=ne({queryKey:["settings","app"],queryFn:()=>ve.getSettings("app")}),{mutateAsync:l}=$s({mutationFn:ve.saveSettings,onSuccess:u=>{u.data&&$.success(s("app.save_success"))}});m.useEffect(()=>{if(o?.data.app){const u=o.data.app;Object.entries(u).forEach(([i,c])=>{a.setValue(i,c)}),r.current=u}},[o]);const d=m.useCallback(Le.debounce(async u=>{if(!Le.isEqual(u,r.current)){t(!0);try{await l(u),r.current=u}finally{t(!1)}}},1e3),[l]),x=m.useCallback(u=>{d(u)},[d]);return m.useEffect(()=>{const u=a.watch(i=>{x(i)});return()=>u.unsubscribe()},[a.watch,x]),e.jsx(Te,{...a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:a.control,name:"windows_version",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("app.windows.version.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(A,{children:s("app.windows.version.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"windows_download_url",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("app.windows.download.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(A,{children:s("app.windows.download.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"macos_version",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("app.macos.version.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(A,{children:s("app.macos.version.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"macos_download_url",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("app.macos.download.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(A,{children:s("app.macos.download.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"android_version",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("app.android.version.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(A,{children:s("app.android.version.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"android_download_url",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-base",children:s("app.android.download.title")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(A,{children:s("app.android.download.description")}),e.jsx(R,{})]})}),n&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Uu(){const{t:s}=O("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(Re,{}),e.jsx(qu,{})]})}const Hu=Object.freeze(Object.defineProperty({__proto__:null,default:Uu},Symbol.toStringTag,{value:"Module"}));Er.config({monaco:Vr});function ui({form:s,config:n,namePrefix:t="",className:r="space-y-4"}){const[a,o]=m.useState({}),l=x=>t?`${t}.${x}`:x,d=(x,u)=>{const i=l(x);switch(u.type){case"string":return e.jsx(j,{control:s.control,name:i,render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{children:u.label||u.description}),e.jsx(b,{children:e.jsx(D,{placeholder:u.placeholder,...c})}),u.description&&u.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:u.description}),e.jsx(R,{})]})},x);case"number":case"percentage":return e.jsx(j,{control:s.control,name:i,render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{children:u.label||u.description}),e.jsx(b,{children:e.jsxs("div",{className:"relative",children:[e.jsx(D,{type:"number",placeholder:u.placeholder,min:u.min??(u.type==="percentage"?0:void 0),max:u.max??(u.type==="percentage"?100:void 0),step:u.step??(u.type==="percentage"?1:void 0),...c,onChange:p=>{const P=Number(p.target.value);u.type==="percentage"?c.onChange(Math.min(100,Math.max(0,P))):c.onChange(P)},className:u.type==="percentage"?"pr-8":""}),u.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"})})]})}),u.description&&u.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:u.description}),e.jsx(R,{})]})},x);case"select":return e.jsx(j,{control:s.control,name:i,render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{children:u.label||u.description}),e.jsxs(X,{onValueChange:c.onChange,defaultValue:c.value,children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:u.placeholder})})}),e.jsx(Q,{children:u.options?.map(p=>e.jsx(q,{value:p.value,children:p.label},p.value))})]}),u.description&&u.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:u.description}),e.jsx(R,{})]})},x);case"boolean":return e.jsx(j,{control:s.control,name:i,render:({field:c})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:u.label||u.description}),u.description&&u.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:u.description})]}),e.jsx(b,{children:e.jsx(ee,{checked:c.value,onCheckedChange:c.onChange})})]})},x);case"text":return e.jsx(j,{control:s.control,name:i,render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{children:u.label||u.description}),e.jsx(b,{children:e.jsx(Rs,{placeholder:u.placeholder,...c})}),u.description&&u.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:u.description}),e.jsx(R,{})]})},x);case"yaml":case"json":return e.jsx(j,{control:s.control,name:i,render:({field:c})=>{const p=(()=>{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)}})(),P=`${t}_${x}`,T=a[P]||150;return e.jsxs(f,{children:[e.jsx(v,{children:u.label||u.description}),e.jsx(b,{children:e.jsx("div",{className:"resize-y overflow-hidden rounded-md border",style:{height:`${T}px`},onMouseDown:C=>{const F=C.clientY,w=T,V=N=>{const S=N.clientY-F,M=Math.max(100,w+S);o(E=>({...E,[P]:M}))},y=()=>{document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",y)};document.addEventListener("mousemove",V),document.addEventListener("mouseup",y)},children:e.jsx(Ir,{height:"100%",defaultLanguage:u.type,value:p,onChange:C=>{c.onChange(C||"")},options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0,formatOnPaste:u.type==="json",formatOnType:u.type==="json"}})})}),u.description&&u.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:u.description}),e.jsx(R,{})]})}},x);default:return null}};return e.jsx("div",{className:r,children:Object.entries(n).map(([x,u])=>d(x,u))})}function xi(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 Ku=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())}),vr={id:null,name:"",icon:"",notify_domain:"",handling_fee_fixed:0,handling_fee_percent:0,payment:"",config:{}};function hi({refetch:s,dialogTrigger:n,type:t="add",defaultFormValues:r=vr}){const{t:a}=O("payment"),[o,l]=m.useState(!1),[d,x]=m.useState(!1),[u,i]=m.useState([]),[c,p]=m.useState([]),[P,T]=m.useState({}),C=Ku(a),F=Ne({resolver:ke(C),defaultValues:r,mode:"onChange"}),w=F.watch("payment");m.useEffect(()=>{o&&(async()=>{const{data:N}=await pt.getMethodList();i(N)})()},[o]),m.useEffect(()=>{if(!w||!o)return;(async()=>{const N={payment:w,...t==="edit"&&{id:Number(F.getValues("id"))}};try{const{data:S}=await pt.getMethodForm(N),M=Object.values(S);p(M);const E=Object.entries(S).reduce((k,[W,te])=>(k[W]=te,k),{});T(E);const g=xi(E);F.setValue("config",g)}catch(S){console.error("Failed to fetch payment method form:",S),p([]),T({})}})()},[w,o,F,t]);const V=async y=>{x(!0);try{(await pt.save(y)).data&&($.success(a("form.messages.success")),F.reset(vr),s(),l(!1))}finally{x(!1)}};return e.jsxs(de,{open:o,onOpenChange:l,children:[e.jsx(fs,{asChild:!0,children:n||e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ke,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add.button")})]})}),e.jsxs(oe,{className:"max-h-[90vh] overflow-y-auto sm:max-w-[500px]",children:[e.jsx(ge,{children:e.jsx(me,{children:a(t==="add"?"form.add.title":"form.edit.title")})}),e.jsx(Te,{...F,children:e.jsxs("form",{onSubmit:F.handleSubmit(V),className:"space-y-4",children:[e.jsx(j,{control:F.control,name:"name",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:a("form.fields.name.placeholder"),...y})}),e.jsx(A,{children:a("form.fields.name.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:F.control,name:"icon",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.icon.label")}),e.jsx(b,{children:e.jsx(D,{...y,value:y.value||"",placeholder:a("form.fields.icon.placeholder")})}),e.jsx(A,{children:a("form.fields.icon.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:F.control,name:"notify_domain",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.notify_domain.label")}),e.jsx(b,{children:e.jsx(D,{...y,value:y.value||"",placeholder:a("form.fields.notify_domain.placeholder")})}),e.jsx(A,{children:a("form.fields.notify_domain.description")}),e.jsx(R,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:F.control,name:"handling_fee_percent",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.handling_fee_percent.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",...y,value:y.value||"",placeholder:a("form.fields.handling_fee_percent.placeholder")})}),e.jsx(R,{})]})}),e.jsx(j,{control:F.control,name:"handling_fee_fixed",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.handling_fee_fixed.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",...y,value:y.value||"",placeholder:a("form.fields.handling_fee_fixed.placeholder")})}),e.jsx(R,{})]})})]}),e.jsx(j,{control:F.control,name:"payment",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.payment.label")}),e.jsxs(X,{onValueChange:y.onChange,defaultValue:y.value,children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:a("form.fields.payment.placeholder")})})}),e.jsx(Q,{children:u.map(N=>e.jsx(q,{value:N,children:N},N))})]}),e.jsx(A,{children:a("form.fields.payment.description")}),e.jsx(R,{})]})}),Object.keys(P).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(ui,{form:F,config:P,namePrefix:"config",className:"space-y-4"})]}),e.jsxs(Ie,{className:"pt-4",children:[e.jsx(Zs,{asChild:!0,children:e.jsx(L,{type:"button",variant:"outline",children:a("form.buttons.cancel")})}),e.jsx(L,{type:"submit",disabled:d,children:a("form.buttons.submit")})]})]})})]})]})}function z({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(L,{variant:"ghost",size:"default",className:_("-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(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(lr,{className:"h-4 w-4 cursor-pointer text-muted-foreground"})}),e.jsx(ce,{children:t})]})}),s.getIsSorted()==="asc"?e.jsx(jn,{className:"h-4 w-4 text-foreground/70"}):s.getIsSorted()==="desc"?e.jsx(vn,{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:_("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(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{children:e.jsx(lr,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(ce,{children:t})]})})]})}const Kn=ad,gi=nd,Bu=rd,pi=m.forwardRef(({className:s,...n},t)=>e.jsx(Sl,{className:_("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}));pi.displayName=Sl.displayName;const Ba=m.forwardRef(({className:s,...n},t)=>e.jsxs(Bu,{children:[e.jsx(pi,{}),e.jsx(kl,{ref:t,className:_("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})]}));Ba.displayName=kl.displayName;const Ga=({className:s,...n})=>e.jsx("div",{className:_("flex flex-col space-y-2 text-center sm:text-left",s),...n});Ga.displayName="AlertDialogHeader";const Wa=({className:s,...n})=>e.jsx("div",{className:_("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Wa.displayName="AlertDialogFooter";const Ya=m.forwardRef(({className:s,...n},t)=>e.jsx(Tl,{ref:t,className:_("text-lg font-semibold",s),...n}));Ya.displayName=Tl.displayName;const Ja=m.forwardRef(({className:s,...n},t)=>e.jsx(Dl,{ref:t,className:_("text-sm text-muted-foreground",s),...n}));Ja.displayName=Dl.displayName;const Qa=m.forwardRef(({className:s,...n},t)=>e.jsx(Fl,{ref:t,className:_(Vt(),s),...n}));Qa.displayName=Fl.displayName;const Xa=m.forwardRef(({className:s,...n},t)=>e.jsx(Pl,{ref:t,className:_(Vt({variant:"outline"}),"mt-2 sm:mt-0",s),...n}));Xa.displayName=Pl.displayName;function us({onConfirm:s,children:n,title:t="确认操作",description:r="确定要执行此操作吗?",cancelText:a="取消",confirmText:o="确认",variant:l="default",className:d}){return e.jsxs(Kn,{children:[e.jsx(gi,{asChild:!0,children:n}),e.jsxs(Ba,{className:_("sm:max-w-[425px]",d),children:[e.jsxs(Ga,{children:[e.jsx(Ya,{children:t}),e.jsx(Ja,{children:r})]}),e.jsxs(Wa,{children:[e.jsx(Xa,{asChild:!0,children:e.jsx(L,{variant:"outline",children:a})}),e.jsx(Qa,{asChild:!0,children:e.jsx(L,{variant:l,onClick:s,children:o})})]})]})]})}const fi=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M11.29 15.29a2 2 0 0 0-.12.15a.8.8 0 0 0-.09.18a.6.6 0 0 0-.06.18a1.4 1.4 0 0 0 0 .2a.84.84 0 0 0 .08.38a.9.9 0 0 0 .54.54a.94.94 0 0 0 .76 0a.9.9 0 0 0 .54-.54A1 1 0 0 0 13 16a1 1 0 0 0-.29-.71a1 1 0 0 0-1.42 0M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2m0 18a8 8 0 1 1 8-8a8 8 0 0 1-8 8m0-13a3 3 0 0 0-2.6 1.5a1 1 0 1 0 1.73 1A1 1 0 0 1 12 9a1 1 0 0 1 0 2a1 1 0 0 0-1 1v1a1 1 0 0 0 2 0v-.18A3 3 0 0 0 12 7"})}),Gu=({refetch:s,isSortMode:n=!1})=>{const{t}=O("payment");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx($a,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(z,{column:r,title:t("table.columns.id")}),cell:({row:r})=>e.jsx(K,{variant:"outline",children:r.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"enable",header:({column:r})=>e.jsx(z,{column:r,title:t("table.columns.enable")}),cell:({row:r})=>e.jsx(ee,{defaultChecked:r.getValue("enable"),onCheckedChange:async()=>{const{data:a}=await pt.updateStatus({id:r.original.id});a||s()}}),enableSorting:!1,size:100},{accessorKey:"name",header:({column:r})=>e.jsx(z,{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(z,{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(z,{column:r,title:t("table.columns.notify_url")}),e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{className:"ml-1",children:e.jsx(fi,{className:"h-4 w-4"})}),e.jsx(ce,{children:t("table.columns.notify_url_tooltip")})]})})]}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[300px] truncate font-medium",children:r.getValue("notify_url")})}),enableSorting:!1,size:3e3},{id:"actions",header:({column:r})=>e.jsx(z,{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(hi,{refetch:s,dialogTrigger:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(nt,{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(us,{title:t("table.actions.delete.title"),description:t("table.actions.delete.description"),onConfirm:async()=>{const{data:a}=await pt.drop({id:r.original.id});a&&s()},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10",children:[e.jsx(ms,{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 Wu({table:s,refetch:n,saveOrder:t,isSortMode:r}){const{t:a}=O("payment"),o=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(hi,{refetch:n}),e.jsx(D,{placeholder:a("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),o&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[a("table.toolbar.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(L,{variant:r?"default":"outline",onClick:t,size:"sm",children:a(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}function Yu(){const[s,n]=m.useState([]),[t,r]=m.useState([]),[a,o]=m.useState(!1),[l,d]=m.useState([]),[x,u]=m.useState({"drag-handle":!1}),[i,c]=m.useState({pageSize:20,pageIndex:0}),{refetch:p}=ne({queryKey:["paymentList"],queryFn:async()=>{const{data:w}=await pt.getList();return d(w?.map(V=>({...V,enable:!!V.enable}))||[]),w}});m.useEffect(()=>{u({"drag-handle":a,actions:!a}),c({pageSize:a?99999:10,pageIndex:0})},[a]);const P=(w,V)=>{a&&(w.dataTransfer.setData("text/plain",V.toString()),w.currentTarget.classList.add("opacity-50"))},T=(w,V)=>{if(!a)return;w.preventDefault(),w.currentTarget.classList.remove("bg-muted");const y=parseInt(w.dataTransfer.getData("text/plain"));if(y===V)return;const N=[...l],[S]=N.splice(y,1);N.splice(V,0,S),d(N)},C=async()=>{a?pt.sort({ids:l.map(w=>w.id)}).then(()=>{p(),o(!1),$.success("排序保存成功")}):o(!0)},F=We({data:l,columns:Gu({refetch:p,isSortMode:a}),state:{sorting:t,columnFilters:s,columnVisibility:x,pagination:i},onSortingChange:r,onColumnFiltersChange:n,onColumnVisibilityChange:u,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps(),initialState:{columnPinning:{right:["actions"]}},pageCount:a?1:void 0});return e.jsx(ns,{table:F,toolbar:w=>e.jsx(Wu,{table:w,refetch:p,saveOrder:C,isSortMode:a}),draggable:a,onDragStart:P,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:T,showPagination:!a})}function Ju(){const{t:s}=O("payment");return e.jsxs(qe,{children:[e.jsxs(Ue,{className:"flex items-center justify-between",children:[e.jsx(os,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(Yu,{})})]})]})}const Qu=Object.freeze(Object.defineProperty({__proto__:null,default:Ju},Symbol.toStringTag,{value:"Module"}));function Xu({pluginName:s,onClose:n,onSuccess:t}){const{t:r}=O("plugin"),[a,o]=m.useState(!0),[l,d]=m.useState(!1),[x,u]=m.useState(null),i=ld({config:id(od())}),c=Ne({resolver:ke(i),defaultValues:{config:{}}});m.useEffect(()=>{(async()=>{try{const{data:T}=await Ms.getPluginConfig(s);u(T);const C=xi(T);c.reset({config:C})}catch{$.error(r("messages.configLoadError"))}finally{o(!1)}})()},[s,c,r]);const p=async P=>{d(!0);try{await Ms.updatePluginConfig(s,P.config),$.success(r("messages.configSaveSuccess")),t()}catch{$.error(r("messages.configSaveError"))}finally{d(!1)}};return a?e.jsxs("div",{className:"space-y-4",children:[e.jsx(je,{className:"h-4 w-[200px]"}),e.jsx(je,{className:"h-10 w-full"}),e.jsx(je,{className:"h-4 w-[200px]"}),e.jsx(je,{className:"h-10 w-full"})]}):e.jsx(Te,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(p),className:"space-y-4",children:[x&&e.jsx(ui,{form:c,config:x,namePrefix:"config"}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(L,{type:"button",variant:"outline",onClick:n,disabled:l,children:r("config.cancel")}),e.jsx(L,{type:"submit",loading:l,disabled:l,children:r("config.save")})]})]})})}function Zu(){const{t:s}=O("plugin"),[n,t]=m.useState(null),[r,a]=m.useState(!1),[o,l]=m.useState(null),[d,x]=m.useState(""),[u,i]=m.useState("feature"),[c,p]=m.useState("all"),[P,T]=m.useState(!1),[C,F]=m.useState(!1),[w,V]=m.useState(!1),y=m.useRef(null),[N,S]=m.useState(!1),[M,E]=m.useState(""),{data:g,isLoading:k}=ne({queryKey:["pluginTypes"],queryFn:async()=>{const{data:H}=await Ms.getPluginTypes();return H}}),{data:W,isLoading:te,refetch:ae}=ne({queryKey:["pluginList"],queryFn:async()=>{const{data:H}=await Ms.getPluginList();return H}}),B=W?.filter(H=>H.name.toLowerCase().includes(d.toLowerCase())||H.description.toLowerCase().includes(d.toLowerCase())||H.code.toLowerCase().includes(d.toLowerCase())),se=()=>{if(!B)return[];let H=B;return u!=="all"&&(H=H.filter(U=>U.type===u)),c==="installed"?H=H.filter(U=>U.is_installed):c==="available"&&(H=H.filter(U=>!U.is_installed)),H},fe=H=>g?.find(U=>U.value===H),cs=async H=>{t(H),Ms.installPlugin(H).then(()=>{$.success(s("messages.installSuccess")),ae()}).catch(U=>{$.error(U.message||s("messages.installError"))}).finally(()=>{t(null)})},Me=async H=>{t(H),Ms.upgradePlugin(H).then(()=>{$.success(s("messages.upgradeSuccess")),ae()}).catch(U=>{$.error(U.message||s("messages.upgradeError"))}).finally(()=>{t(null)})},re=async H=>{t(H),Ms.uninstallPlugin(H).then(()=>{$.success(s("messages.uninstallSuccess")),ae()}).catch(U=>{$.error(U.message||s("messages.uninstallError"))}).finally(()=>{t(null)})},ks=async(H,U)=>{t(H),(U?Ms.disablePlugin:Ms.enablePlugin)(H).then(()=>{$.success(s(U?"messages.disableSuccess":"messages.enableSuccess")),ae()}).catch(Oe=>{$.error(Oe.message||s(U?"messages.disableError":"messages.enableError"))}).finally(()=>{t(null)})},_s=H=>{W?.find(U=>U.code===H),l(H),a(!0)},ot=async H=>{if(!H.name.endsWith(".zip")){$.error(s("upload.error.format"));return}T(!0),Ms.uploadPlugin(H).then(()=>{$.success(s("messages.uploadSuccess")),F(!1),ae()}).catch(U=>{$.error(U.message||s("messages.uploadError"))}).finally(()=>{T(!1),y.current&&(y.current.value="")})},Es=H=>{H.preventDefault(),H.stopPropagation(),H.type==="dragenter"||H.type==="dragover"?V(!0):H.type==="dragleave"&&V(!1)},ct=H=>{H.preventDefault(),H.stopPropagation(),V(!1),H.dataTransfer.files&&H.dataTransfer.files[0]&&ot(H.dataTransfer.files[0])},dt=async H=>{t(H),Ms.deletePlugin(H).then(()=>{$.success(s("messages.deleteSuccess")),ae()}).catch(U=>{$.error(U.message||s("messages.deleteError"))}).finally(()=>{t(null)})},mt=H=>cd(H||"",{walkTokens(U){(U.type==="image"||U.type==="link")&&(U.type="text",U.raw="",U.text="")}});return e.jsxs(qe,{children:[e.jsxs(Ue,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ln,{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(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(Rn,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(D,{placeholder:s("search.placeholder"),value:d,onChange:H=>x(H.target.value),className:"pl-9"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(X,{value:c,onValueChange:p,children:[e.jsx(J,{className:"w-[140px]",children:e.jsx(Z,{placeholder:s("status.filter_placeholder",{defaultValue:"安装状态"})})}),e.jsxs(Q,{children:[e.jsx(q,{value:"all",children:s("status.all",{defaultValue:"全部状态"})}),e.jsx(q,{value:"installed",children:s("status.installed",{defaultValue:"已安装"})}),e.jsx(q,{value:"available",children:s("status.available",{defaultValue:"可安装"})})]})]}),e.jsxs(L,{onClick:()=>F(!0),variant:"outline",className:"shrink-0",size:"sm",children:[e.jsx(Lt,{className:"mr-2 h-4 w-4"}),s("upload.button")]})]})]}),e.jsxs(bt,{value:u,onValueChange:i,className:"w-full",children:[e.jsxs(rt,{children:[g?.map(H=>e.jsx(Be,{value:H.value,children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{children:H.label})})},H.value)),e.jsx(Be,{value:"all",children:s("tabs.all")})]}),e.jsx(bs,{value:"all",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:te||k?e.jsxs(e.Fragment,{children:[e.jsx(mn,{}),e.jsx(mn,{}),e.jsx(mn,{})]}):se().map(H=>e.jsx(br,{plugin:H,typeInfo:fe(H.type),onInstall:cs,onUpgrade:Me,onUninstall:re,onToggleEnable:ks,onOpenConfig:_s,onDelete:dt,isLoading:n===H.code,onShowReadme:H.readme?()=>{E(H.readme),S(!0)}:void 0},H.code))})}),g?.map(H=>e.jsx(bs,{value:H.value,className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:se().map(U=>e.jsx(br,{plugin:U,typeInfo:fe(U.type),onInstall:cs,onUpgrade:Me,onUninstall:re,onToggleEnable:ks,onOpenConfig:_s,onDelete:dt,isLoading:n===U.code,onShowReadme:U.readme?()=>{E(U.readme),S(!0)}:void 0},U.code))})},H.value))]})]}),e.jsx(de,{open:r,onOpenChange:a,children:e.jsxs(oe,{className:"sm:max-w-lg",children:[e.jsxs(ge,{children:[e.jsxs(me,{children:[W?.find(H=>H.code===o)?.name," ",s("config.title")]}),e.jsx(Ae,{children:s("config.description")})]}),o&&e.jsx(Xu,{pluginName:o,onClose:()=>a(!1),onSuccess:()=>{a(!1),ae()}})]})}),e.jsx(de,{open:C,onOpenChange:F,children:e.jsxs(oe,{className:"sm:max-w-md",children:[e.jsxs(ge,{children:[e.jsx(me,{children:s("upload.title")}),e.jsx(Ae,{children:s("upload.description")})]}),e.jsxs("div",{className:_("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:Es,onDragLeave:Es,onDragOver:Es,onDrop:ct,children:[e.jsx("input",{type:"file",ref:y,className:"hidden",accept:".zip",onChange:H=>{const U=H.target.files?.[0];U&&ot(U)}}),P?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(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:()=>y.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(de,{open:N,onOpenChange:S,children:e.jsxs(oe,{className:"max-w-2xl",children:[e.jsx(ge,{children:e.jsx(me,{children:s("readme.title",{defaultValue:"插件文档"})})}),e.jsx("div",{className:"markdown-body max-h-[60vh] overflow-y-auto",dangerouslySetInnerHTML:{__html:mt(M)}})]})})]})]})}function br({plugin:s,onInstall:n,onUpgrade:t,onUninstall:r,onToggleEnable:a,onOpenConfig:o,onDelete:l,isLoading:d,onShowReadme:x,typeInfo:u}){const{t:i}=O("plugin");return e.jsx(Se,{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}),u&&e.jsx(K,{variant:"outline",className:"border-primary/20 bg-primary/5 px-1.5 py-0.5 text-xs text-primary",children:u.label}),s.is_installed?e.jsx(K,{variant:s.is_enabled?"default":"outline",className:"px-1.5 py-0.5 text-xs",children:s.is_enabled?i("status.enabled"):i("status.disabled")}):e.jsx(K,{variant:"outline",className:"border-muted-foreground/30 bg-muted/30 px-1.5 py-0.5 text-xs text-muted-foreground",children:i("status.not_installed")})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1.5",children:[s.is_protected&&e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{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(ce,{children:e.jsx("p",{children:i("status.protected")})})]})}),s.readme&&e.jsx("button",{type:"button",onClick:x,className:"flex h-5 w-5 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-primary",title:i("button.readme"),children:e.jsx(yn,{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(Ln,{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:[i("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.need_upgrade&&e.jsx(us,{title:i("upgrade.title"),description:i("upgrade.description"),cancelText:i("common:cancel"),confirmText:i("upgrade.button"),variant:"default",onConfirm:async()=>t(s.code),children:e.jsxs(L,{variant:"destructive",size:"sm",disabled:d,className:"h-7 px-2 text-xs bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(md,{className:"mr-1 h-3 w-3"}),i("button.upgrade")]})}),s.config&&Object.keys(s.config).length>0&&e.jsxs(L,{variant:"outline",size:"sm",onClick:()=>o(s.code),disabled:!s.is_enabled||d,className:"h-7 px-2 text-xs",children:[e.jsx(Ta,{className:"mr-1 h-3 w-3"}),i("button.config")]}),e.jsxs(L,{variant:s.is_enabled?"destructive":"default",size:"sm",onClick:()=>a(s.code,s.is_enabled),disabled:d,className:"h-7 px-2 text-xs",children:[e.jsx(ud,{className:"mr-1 h-3 w-3"}),s.is_enabled?i("button.disable"):i("button.enable")]}),e.jsx(us,{title:i("uninstall.title"),description:i("uninstall.description"),cancelText:i("common:cancel"),confirmText:i("uninstall.button"),variant:"destructive",onConfirm:async()=>r(s.code),children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs text-muted-foreground hover:text-destructive",disabled:d||s.is_enabled,children:[e.jsx(ms,{className:"mr-1 h-3 w-3"}),i("button.uninstall")]})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(L,{onClick:()=>n(s.code),disabled:d,size:"sm",className:"h-7 px-3 text-xs",children:[d?e.jsx("div",{className:"mr-1 h-3 w-3 animate-spin rounded-full border border-current border-t-transparent"}):null,i("button.install")]}),s.can_be_deleted!==!1&&e.jsx(us,{title:i("delete.title"),description:i("delete.description"),cancelText:i("common:cancel"),confirmText:i("delete.button"),variant:"destructive",onConfirm:async()=>l(s.code),children:e.jsx(L,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground hover:text-destructive",disabled:d,children:e.jsx(ms,{className:"h-3 w-3"})})})]})})]})})}function mn(){return e.jsxs(Se,{children:[e.jsxs(De,{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(je,{className:"h-6 w-[200px]"}),e.jsx(je,{className:"h-6 w-[80px]"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(je,{className:"h-5 w-[120px]"}),e.jsx(je,{className:"h-5 w-[60px]"})]})]})}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx(je,{className:"h-4 w-[300px]"}),e.jsx(je,{className:"h-4 w-[150px]"})]})]}),e.jsx(Fe,{children:e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(je,{className:"h-9 w-[100px]"}),e.jsx(je,{className:"h-9 w-[100px]"}),e.jsx(je,{className:"h-8 w-8"})]})})]})}const ex=Object.freeze(Object.defineProperty({__proto__:null,default:Zu},Symbol.toStringTag,{value:"Module"})),sx=(s,n)=>{let t=null;switch(s.field_type){case"input":t=e.jsx(D,{placeholder:s.placeholder,...n});break;case"textarea":t=e.jsx(Rs,{placeholder:s.placeholder,...n});break;case"select":t=e.jsx("select",{className:_(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 tx({themeKey:s,themeInfo:n}){const{t}=O("theme"),[r,a]=m.useState(!1),[o,l]=m.useState(!1),[d,x]=m.useState(!1),u=Ne({defaultValues:n.configs.reduce((p,P)=>(p[P.field_name]="",p),{})}),i=async()=>{l(!0),Jt.getConfig(s).then(({data:p})=>{Object.entries(p).forEach(([P,T])=>{u.setValue(P,T)})}).finally(()=>{l(!1)})},c=async p=>{x(!0),Jt.updateConfig(s,p).then(()=>{$.success(t("config.success")),a(!1)}).finally(()=>{x(!1)})};return e.jsxs(de,{open:r,onOpenChange:p=>{a(p),p?i():u.reset()},children:[e.jsx(fs,{asChild:!0,children:e.jsx(L,{variant:"outline",children:t("card.configureTheme")})}),e.jsxs(oe,{className:"max-h-[90vh] overflow-auto sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsx(me,{children:t("config.title",{name:n.name})}),e.jsx(Ae,{children:t("config.description")})]}),o?e.jsx("div",{className:"flex h-40 items-center justify-center",children:e.jsx(ka,{className:"h-6 w-6 animate-spin"})}):e.jsx(Te,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(c),className:"space-y-4",children:[n.configs.map(p=>e.jsx(j,{control:u.control,name:p.field_name,render:({field:P})=>e.jsxs(f,{children:[e.jsx(v,{children:p.label}),e.jsx(b,{children:sx(p,P)}),e.jsx(R,{})]})},p.field_name)),e.jsxs(Ie,{className:"mt-6 gap-2",children:[e.jsx(L,{type:"button",variant:"secondary",onClick:()=>a(!1),children:t("config.cancel")}),e.jsx(L,{type:"submit",loading:d,children:t("config.save")})]})]})})]})]})}function ax(){const{t:s}=O("theme"),[n,t]=m.useState(null),[r,a]=m.useState(!1),[o,l]=m.useState(!1),[d,x]=m.useState(!1),[u,i]=m.useState(null),c=m.useRef(null),[p,P]=m.useState(0),{data:T,isLoading:C,refetch:F}=ne({queryKey:["themeList"],queryFn:async()=>{const{data:g}=await Jt.getList();return g}}),w=async g=>{t(g),ve.updateSystemConfig({frontend_theme:g}).then(()=>{$.success("主题切换成功"),F()}).finally(()=>{t(null)})},V=async g=>{if(!g.name.endsWith(".zip")){$.error(s("upload.error.format"));return}a(!0),Jt.upload(g).then(()=>{$.success("主题上传成功"),l(!1),F()}).finally(()=>{a(!1),c.current&&(c.current.value="")})},y=g=>{g.preventDefault(),g.stopPropagation(),g.type==="dragenter"||g.type==="dragover"?x(!0):g.type==="dragleave"&&x(!1)},N=g=>{g.preventDefault(),g.stopPropagation(),x(!1),g.dataTransfer.files&&g.dataTransfer.files[0]&&V(g.dataTransfer.files[0])},S=()=>{u&&P(g=>g===0?u.images.length-1:g-1)},M=()=>{u&&P(g=>g===u.images.length-1?0:g+1)},E=(g,k)=>{P(0),i({name:g,images:k})};return e.jsxs(qe,{children:[e.jsxs(Ue,{className:"flex items-center justify-between",children:[e.jsx(os,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(L,{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(yr,{}),e.jsx(yr,{})]}):T?.themes&&Object.entries(T.themes).map(([g,k])=>e.jsx(Se,{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:_("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(us,{title:s("card.delete.title"),description:s("card.delete.description"),confirmText:s("card.delete.button"),variant:"destructive",onConfirm:async()=>{if(g===T?.active){$.error(s("card.delete.error.active"));return}t(g),Jt.drop(g).then(()=>{$.success("主题删除成功"),F()}).finally(()=>{t(null)})},children:e.jsx(L,{disabled:n===g,loading:n===g,variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",children:e.jsx(ms,{className:"h-4 w-4"})})})}),e.jsxs(De,{children:[e.jsx(Ve,{children:k.name}),e.jsx(Xs,{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(Fe,{className:"flex items-center justify-end space-x-3",children:[k.images&&Array.isArray(k.images)&&k.images.length>0&&e.jsx(L,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>E(k.name,k.images),children:e.jsx(xd,{className:"h-4 w-4"})}),e.jsx(tx,{themeKey:g,themeInfo:k}),e.jsx(L,{onClick:()=>w(g),disabled:n===g||g===T.active,loading:n===g,variant:g===T.active?"secondary":"default",children:g===T.active?s("card.currentTheme"):s("card.activateTheme")})]})]})},g))}),e.jsx(de,{open:o,onOpenChange:l,children:e.jsxs(oe,{className:"sm:max-w-md",children:[e.jsxs(ge,{children:[e.jsx(me,{children:s("upload.title")}),e.jsx(Ae,{children:s("upload.description")})]}),e.jsxs("div",{className:_("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:y,onDragLeave:y,onDragOver:y,onDrop:N,children:[e.jsx("input",{type:"file",ref:c,className:"hidden",accept:".zip",onChange:g=>{const k=g.target.files?.[0];k&&V(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(de,{open:!!u,onOpenChange:g=>{g||(i(null),P(0))},children:e.jsxs(oe,{className:"max-w-4xl",children:[e.jsxs(ge,{children:[e.jsxs(me,{children:[u?.name," ",s("preview.title")]}),e.jsx(Ae,{className:"text-center",children:u&&s("preview.imageCount",{current:p+1,total:u.images.length})})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"aspect-[16/9] overflow-hidden rounded-lg border bg-muted",children:u?.images[p]&&e.jsx("img",{src:u.images[p],alt:`${u.name} 预览图 ${p+1}`,className:"h-full w-full object-contain"})}),u&&u.images.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(L,{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:S,children:e.jsx(gl,{className:"h-4 w-4"})}),e.jsx(L,{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:M,children:e.jsx(pl,{className:"h-4 w-4"})})]})]}),u&&u.images.length>1&&e.jsx("div",{className:"mt-4 flex gap-2 overflow-x-auto pb-2",children:u.images.map((g,k)=>e.jsx("button",{onClick:()=>P(k),className:_("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2",p===k?"border-primary":"border-transparent"),children:e.jsx("img",{src:g,alt:`缩略图 ${k+1}`,className:"h-full w-full object-cover"})},k))})]})})]})]})}function yr(){return e.jsxs(Se,{children:[e.jsxs(De,{children:[e.jsx(je,{className:"h-6 w-[200px]"}),e.jsx(je,{className:"h-4 w-[300px]"})]}),e.jsxs(Fe,{className:"flex items-center justify-end space-x-3",children:[e.jsx(je,{className:"h-10 w-[100px]"}),e.jsx(je,{className:"h-10 w-[100px]"})]})]})}const nx=Object.freeze(Object.defineProperty({__proto__:null,default:ax},Symbol.toStringTag,{value:"Module"})),Za=m.forwardRef(({className:s,value:n=[],onChange:t,...r},a)=>{const[o,l]=m.useState("");m.useEffect(()=>{if(o.includes(",")){const x=new Set([...n,...o.split(",").map(u=>u.trim())]);t(Array.from(x)),l("")}},[o,t,n]);const d=()=>{if(o){const x=new Set([...n,o]);t(Array.from(x)),l("")}};return e.jsxs("div",{className:_(" has-[:focus-visible]:outline-none has-[:focus-visible]:ring-1 has-[:focus-visible]:ring-neutral-950 dark:has-[:focus-visible]:ring-neutral-300 flex w-full flex-wrap gap-2 rounded-md border border-input shadow-sm px-3 py-2 text-sm ring-offset-white disabled:cursor-not-allowed disabled:opacity-50",s),children:[n.map(x=>e.jsxs(K,{variant:"secondary",children:[x,e.jsx(G,{variant:"ghost",size:"icon",className:"ml-2 h-3 w-3",onClick:()=>{t(n.filter(u=>u!==x))},children:e.jsx(Nn,{className:"w-3"})})]},x)),e.jsx("input",{className:"flex-1 outline-none placeholder:text-muted-foreground bg-transparent",value:o,onChange:x=>l(x.target.value),onKeyDown:x=>{x.key==="Enter"||x.key===","?(x.preventDefault(),d()):x.key==="Backspace"&&o.length===0&&n.length>0&&(x.preventDefault(),t(n.slice(0,-1)))},...r,ref:a})]})});Za.displayName="InputTags";const rx=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()}),lx={id:null,show:!1,tags:[],img_url:"",title:"",content:""};function ji({refetch:s,dialogTrigger:n,type:t="add",defaultFormValues:r=lx}){const{t:a}=O("notice"),[o,l]=m.useState(!1),d=Ne({resolver:ke(rx),defaultValues:r,mode:"onChange",shouldFocusError:!0}),x=new In({html:!0});return e.jsx(Te,{...d,children:e.jsxs(de,{onOpenChange:l,open:o,children:[e.jsx(fs,{asChild:!0,children:n||e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ke,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add.button")})]})}),e.jsxs(oe,{className:"sm:max-w-[1025px]",children:[e.jsxs(ge,{children:[e.jsx(me,{children:a(t==="add"?"form.add.title":"form.edit.title")}),e.jsx(Ae,{})]}),e.jsx(j,{control:d.control,name:"title",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.title.label")}),e.jsx("div",{className:"relative ",children:e.jsx(b,{children:e.jsx(D,{placeholder:a("form.fields.title.placeholder"),...u})})}),e.jsx(R,{})]})}),e.jsx(j,{control:d.control,name:"content",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.content.label")}),e.jsx(b,{children:e.jsx(Mn,{style:{height:"500px"},value:u.value,renderHTML:i=>x.render(i),onChange:({text:i})=>{u.onChange(i)}})}),e.jsx(R,{})]})}),e.jsx(j,{control:d.control,name:"img_url",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.img_url.label")}),e.jsx("div",{className:"relative",children:e.jsx(b,{children:e.jsx(D,{type:"text",placeholder:a("form.fields.img_url.placeholder"),...u,value:u.value||""})})}),e.jsx(R,{})]})}),e.jsx(j,{control:d.control,name:"show",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.show.label")}),e.jsx("div",{className:"relative py-2",children:e.jsx(b,{children:e.jsx(ee,{checked:u.value,onCheckedChange:u.onChange})})}),e.jsx(R,{})]})}),e.jsx(j,{control:d.control,name:"tags",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.fields.tags.label")}),e.jsx(b,{children:e.jsx(Za,{value:u.value,onChange:u.onChange,placeholder:a("form.fields.tags.placeholder"),className:"w-full"})}),e.jsx(R,{})]})}),e.jsxs(Ie,{children:[e.jsx(Zs,{asChild:!0,children:e.jsx(L,{type:"button",variant:"outline",children:a("form.buttons.cancel")})}),e.jsx(L,{type:"submit",onClick:u=>{u.preventDefault(),d.handleSubmit(async i=>{aa.save(i).then(({data:c})=>{c&&($.success(a("form.buttons.success")),s(),l(!1))})})()},children:a("form.buttons.submit")})]})]})]})})}function ix({table:s,refetch:n,saveOrder:t,isSortMode:r}){const{t:a}=O("notice"),o=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(ji,{refetch:n}),!r&&e.jsx(D,{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]"}),o&&!r&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-9 px-2 lg:px-3",children:[a("table.toolbar.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(L,{variant:r?"default":"outline",onClick:t,className:"h-8",size:"sm",children:a(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}const ox=s=>{const{t:n}=O("notice");return[{id:"drag-handle",header:"",cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(hd,{className:"h-4 w-4 cursor-move text-muted-foreground"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(z,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(K,{variant:"outline",className:"font-mono",children:t.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"show",header:({column:t})=>e.jsx(z,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(ee,{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(z,{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(z,{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(ji,{refetch:s,dialogTrigger:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(nt,{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(us,{title:n("table.actions.delete.title"),description:n("table.actions.delete.description"),onConfirm:async()=>{aa.drop(t.original.id).then(()=>{$.success(n("table.actions.delete.success")),s()})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ms,{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 cx(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,o]=m.useState([]),[l,d]=m.useState([]),[x,u]=m.useState(!1),[i,c]=m.useState({}),[p,P]=m.useState({pageSize:50,pageIndex:0}),[T,C]=m.useState([]),{refetch:F}=ne({queryKey:["notices"],queryFn:async()=>{const{data:S}=await aa.getList();return C(S),S}});m.useEffect(()=>{r({"drag-handle":x,content:!x,created_at:!x,actions:!x}),P({pageSize:x?99999:50,pageIndex:0})},[x]);const w=(S,M)=>{x&&(S.dataTransfer.setData("text/plain",M.toString()),S.currentTarget.classList.add("opacity-50"))},V=(S,M)=>{if(!x)return;S.preventDefault(),S.currentTarget.classList.remove("bg-muted");const E=parseInt(S.dataTransfer.getData("text/plain"));if(E===M)return;const g=[...T],[k]=g.splice(E,1);g.splice(M,0,k),C(g)},y=async()=>{if(!x){u(!0);return}aa.sort(T.map(S=>S.id)).then(()=>{$.success("排序保存成功"),u(!1),F()}).finally(()=>{u(!1)})},N=We({data:T??[],columns:ox(F),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,columnSizing:i,pagination:p},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:o,onColumnVisibilityChange:r,onColumnSizingChange:c,onPaginationChange:P,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(ns,{table:N,toolbar:S=>e.jsx(ix,{table:S,refetch:F,saveOrder:y,isSortMode:x}),draggable:x,onDragStart:w,onDragEnd:S=>S.currentTarget.classList.remove("opacity-50"),onDragOver:S=>{S.preventDefault(),S.currentTarget.classList.add("bg-muted")},onDragLeave:S=>S.currentTarget.classList.remove("bg-muted"),onDrop:V,showPagination:!x})})}function dx(){const{t:s}=O("notice");return e.jsxs(qe,{children:[e.jsxs(Ue,{className:"flex items-center justify-between",children:[e.jsx(os,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(cx,{})})]})]})}const mx=Object.freeze(Object.defineProperty({__proto__:null,default:dx},Symbol.toStringTag,{value:"Module"})),ux=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()}),xx={id:null,language:"zh-CN",category:"",title:"",body:"",show:!1};function vi({refreshData:s,dialogTrigger:n,type:t="add",defaultFormValues:r=xx}){const{t:a}=O("knowledge"),[o,l]=m.useState(!1),d=Ne({resolver:ke(ux),defaultValues:r,mode:"onChange",shouldFocusError:!0}),x=new In({html:!0});return m.useEffect(()=>{o&&r.id&&Et.getInfo(r.id).then(({data:u})=>{d.reset(u)})},[r.id,d,o]),e.jsxs(de,{onOpenChange:l,open:o,children:[e.jsx(fs,{asChild:!0,children:n||e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ke,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add")})]})}),e.jsxs(oe,{className:"sm:max-w-[1025px]",children:[e.jsxs(ge,{children:[e.jsx(me,{children:a(t==="add"?"form.add":"form.edit")}),e.jsx(Ae,{})]}),e.jsxs(Te,{...d,children:[e.jsx(j,{control:d.control,name:"title",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.title")}),e.jsx("div",{className:"relative ",children:e.jsx(b,{children:e.jsx(D,{placeholder:a("form.titlePlaceholder"),...u})})}),e.jsx(R,{})]})}),e.jsx(j,{control:d.control,name:"category",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.category")}),e.jsx("div",{className:"relative ",children:e.jsx(b,{children:e.jsx(D,{placeholder:a("form.categoryPlaceholder"),...u})})}),e.jsx(R,{})]})}),e.jsx(j,{control:d.control,name:"language",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.language")}),e.jsx(b,{children:e.jsxs(X,{value:u.value,onValueChange:u.onChange,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:a("form.languagePlaceholder")})}),e.jsx(Q,{children:[{value:"en-US"},{value:"ja-JP"},{value:"ko-KR"},{value:"vi-VN"},{value:"zh-CN"},{value:"zh-TW"}].map(i=>e.jsx(q,{value:i.value,className:"cursor-pointer",children:a(`languages.${i.value}`)},i.value))})]})})]})}),e.jsx(j,{control:d.control,name:"body",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.content")}),e.jsx(b,{children:e.jsx(Mn,{style:{height:"500px"},value:u.value,renderHTML:i=>x.render(i),onChange:({text:i})=>{u.onChange(i)}})}),e.jsx(R,{})]})}),e.jsx(j,{control:d.control,name:"show",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.show")}),e.jsx("div",{className:"relative py-2",children:e.jsx(b,{children:e.jsx(ee,{checked:u.value,onCheckedChange:u.onChange})})}),e.jsx(R,{})]})}),e.jsxs(Ie,{children:[e.jsx(Zs,{asChild:!0,children:e.jsx(L,{type:"button",variant:"outline",children:a("form.cancel")})}),e.jsx(L,{type:"submit",onClick:()=>{d.handleSubmit(u=>{Et.save(u).then(({data:i})=>{i&&(d.reset(),$.success(a("messages.operationSuccess")),l(!1),s())})})()},children:a("form.submit")})]})]})]})]})}function hx({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Aa,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{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(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(o=>a.has(o.value)).map(o=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:o.label},o.value))})]})]})}),e.jsx(Ge,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Gs,{children:[e.jsx(lt,{placeholder:n}),e.jsxs(Ws,{children:[e.jsx(it,{children:"No results found."}),e.jsx(xs,{children:t.map(o=>{const l=a.has(o.value);return e.jsxs($e,{onSelect:()=>{l?a.delete(o.value):a.add(o.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:_("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(vt,{className:_("h-4 w-4")})}),o.icon&&e.jsx(o.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:o.label}),r?.get(o.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(o.value)})]},o.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Mt,{}),e.jsx(xs,{children:e.jsx($e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function gx({table:s,refetch:n,saveOrder:t,isSortMode:r}){const a=s.getState().columnFilters.length>0,{t:o}=O("knowledge");return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:o("toolbar.sortModeHint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vi,{refreshData:n}),e.jsx(D,{placeholder:o("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(hx,{column:s.getColumn("category"),title:o("columns.category"),options:Array.from(new Set(s.getCoreRowModel().rows.map(l=>l.getValue("category")))).map(l=>({label:l,value:l}))}),a&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[o("toolbar.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(L,{variant:r?"default":"outline",onClick:t,size:"sm",children:o(r?"toolbar.saveSort":"toolbar.editSort")})})]})}const px=({refetch:s,isSortMode:n=!1})=>{const{t}=O("knowledge");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:n?"cursor-move":"opacity-0",children:e.jsx($a,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(z,{column:r,title:t("columns.id")}),cell:({row:r})=>e.jsx(K,{variant:"outline",className:"justify-center",children:r.getValue("id")}),enableSorting:!0,size:70},{accessorKey:"show",header:({column:r})=>e.jsx(z,{column:r,title:t("columns.status")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx(ee,{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(z,{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(z,{column:r,title:t("columns.category")}),cell:({row:r})=>e.jsx(K,{variant:"secondary",className:"max-w-[180px] truncate",children:r.getValue("category")}),enableSorting:!0,size:1800},{id:"actions",header:({column:r})=>e.jsx(z,{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(vi,{refreshData:s,dialogTrigger:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(nt,{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(us,{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&&($.success(t("messages.operationSuccess")),s())})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ms,{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 fx(){const[s,n]=m.useState([]),[t,r]=m.useState([]),[a,o]=m.useState(!1),[l,d]=m.useState([]),[x,u]=m.useState({"drag-handle":!1}),[i,c]=m.useState({pageSize:20,pageIndex:0}),{refetch:p,isLoading:P,data:T}=ne({queryKey:["knowledge"],queryFn:async()=>{const{data:y}=await Et.getList();return d(y||[]),y}});m.useEffect(()=>{u({"drag-handle":a,actions:!a}),c({pageSize:a?99999:10,pageIndex:0})},[a]);const C=(y,N)=>{a&&(y.dataTransfer.setData("text/plain",N.toString()),y.currentTarget.classList.add("opacity-50"))},F=(y,N)=>{if(!a)return;y.preventDefault(),y.currentTarget.classList.remove("bg-muted");const S=parseInt(y.dataTransfer.getData("text/plain"));if(S===N)return;const M=[...l],[E]=M.splice(S,1);M.splice(N,0,E),d(M)},w=async()=>{a?Et.sort({ids:l.map(y=>y.id)}).then(()=>{p(),o(!1),$.success("排序保存成功")}):o(!0)},V=We({data:l,columns:px({refetch:p,isSortMode:a}),state:{sorting:t,columnFilters:s,columnVisibility:x,pagination:i},onSortingChange:r,onColumnFiltersChange:n,onColumnVisibilityChange:u,onPaginationChange:c,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ns,{table:V,toolbar:y=>e.jsx(gx,{table:y,refetch:p,saveOrder:w,isSortMode:a}),draggable:a,onDragStart:C,onDragEnd:y=>y.currentTarget.classList.remove("opacity-50"),onDragOver:y=>{y.preventDefault(),y.currentTarget.classList.add("bg-muted")},onDragLeave:y=>y.currentTarget.classList.remove("bg-muted"),onDrop:F,showPagination:!a})}function jx(){const{t:s}=O("knowledge");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(fx,{})})]})]})}const vx=Object.freeze(Object.defineProperty({__proto__:null,default:jx},Symbol.toStringTag,{value:"Module"}));function bx(s,n){const[t,r]=m.useState(s);return m.useEffect(()=>{const a=setTimeout(()=>r(s),n);return()=>{clearTimeout(a)}},[s,n]),t}function un(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 yx(s,n){const t=JSON.parse(JSON.stringify(s));for(const[r,a]of Object.entries(t))t[r]=a.filter(o=>!n.find(l=>l.value===o.value));return t}function _x(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 bi=m.forwardRef(({className:s,...n},t)=>gd(a=>a.filtered.count===0)?e.jsx("div",{ref:t,className:_("py-6 text-center text-sm",s),"cmdk-empty":"",role:"presentation",...n}):null);bi.displayName="CommandEmpty";const at=m.forwardRef(({value:s,onChange:n,placeholder:t,defaultOptions:r=[],options:a,delay:o,onSearch:l,loadingIndicator:d,emptyIndicator:x,maxSelected:u=Number.MAX_SAFE_INTEGER,onMaxSelected:i,hidePlaceholderWhenSelected:c,disabled:p,groupBy:P,className:T,badgeClassName:C,selectFirstItem:F=!0,creatable:w=!1,triggerSearchOnFocus:V=!1,commandProps:y,inputProps:N,hideClearAllButton:S=!1},M)=>{const E=m.useRef(null),[g,k]=m.useState(!1),W=m.useRef(!1),[te,ae]=m.useState(!1),[B,se]=m.useState(s||[]),[fe,cs]=m.useState(un(r,P)),[Me,re]=m.useState(""),ks=bx(Me,o||500);m.useImperativeHandle(M,()=>({selectedValue:[...B],input:E.current,focus:()=>E.current?.focus()}),[B]);const _s=m.useCallback(U=>{const be=B.filter(Oe=>Oe.value!==U.value);se(be),n?.(be)},[n,B]),ot=m.useCallback(U=>{const be=E.current;be&&((U.key==="Delete"||U.key==="Backspace")&&be.value===""&&B.length>0&&(B[B.length-1].fixed||_s(B[B.length-1])),U.key==="Escape"&&be.blur())},[_s,B]);m.useEffect(()=>{s&&se(s)},[s]),m.useEffect(()=>{if(!a||l)return;const U=un(a||[],P);JSON.stringify(U)!==JSON.stringify(fe)&&cs(U)},[r,a,P,l,fe]),m.useEffect(()=>{const U=async()=>{ae(!0);const Oe=await l?.(ks);cs(un(Oe||[],P)),ae(!1)};(async()=>{!l||!g||(V&&await U(),ks&&await U())})()},[ks,P,g,V]);const Es=()=>{if(!w||_x(fe,[{value:Me,label:Me}])||B.find(be=>be.value===Me))return;const U=e.jsx($e,{value:Me,className:"cursor-pointer",onMouseDown:be=>{be.preventDefault(),be.stopPropagation()},onSelect:be=>{if(B.length>=u){i?.(B.length);return}re("");const Oe=[...B,{value:be,label:be}];se(Oe),n?.(Oe)},children:`Create "${Me}"`});if(!l&&Me.length>0||l&&ks.length>0&&!te)return U},ct=m.useCallback(()=>{if(x)return l&&!w&&Object.keys(fe).length===0?e.jsx($e,{value:"-",disabled:!0,children:x}):e.jsx(bi,{children:x})},[w,x,l,fe]),dt=m.useMemo(()=>yx(fe,B),[fe,B]),mt=m.useCallback(()=>{if(y?.filter)return y.filter;if(w)return(U,be)=>U.toLowerCase().includes(be.toLowerCase())?1:-1},[w,y?.filter]),H=m.useCallback(()=>{const U=B.filter(be=>be.fixed);se(U),n?.(U)},[n,B]);return e.jsxs(Gs,{...y,onKeyDown:U=>{ot(U),y?.onKeyDown?.(U)},className:_("h-auto overflow-visible bg-transparent",y?.className),shouldFilter:y?.shouldFilter!==void 0?y.shouldFilter:!l,filter:mt(),children:[e.jsx("div",{className:_("rounded-md border border-input text-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring ",{"px-3 py-2":B.length!==0,"cursor-text":!p&&B.length!==0},T),onClick:()=>{p||E.current?.focus()},children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[B.map(U=>e.jsxs(K,{className:_("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":U.fixed,"data-disabled":p||void 0,children:[U.label,e.jsx("button",{className:_("ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",(p||U.fixed)&&"hidden"),onKeyDown:be=>{be.key==="Enter"&&_s(U)},onMouseDown:be=>{be.preventDefault(),be.stopPropagation()},onClick:()=>_s(U),children:e.jsx(Nn,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},U.value)),e.jsx(hs.Input,{...N,ref:E,value:Me,disabled:p,onValueChange:U=>{re(U),N?.onValueChange?.(U)},onBlur:U=>{W.current===!1&&k(!1),N?.onBlur?.(U)},onFocus:U=>{k(!0),V&&l?.(ks),N?.onFocus?.(U)},placeholder:c&&B.length!==0?"":t,className:_("flex-1 bg-transparent outline-none placeholder:text-muted-foreground",{"w-full":c,"px-3 py-2":B.length===0,"ml-1":B.length!==0},N?.className)}),e.jsx("button",{type:"button",onClick:H,className:_((S||p||B.length<1||B.filter(U=>U.fixed).length===B.length)&&"hidden"),children:e.jsx(Nn,{})})]})}),e.jsx("div",{className:"relative",children:g&&e.jsx(Ws,{className:"absolute top-1 z-10 w-full rounded-md border bg-popover text-popover-foreground shadow-md outline-none animate-in",onMouseLeave:()=>{W.current=!1},onMouseEnter:()=>{W.current=!0},onMouseUp:()=>{E.current?.focus()},children:te?e.jsx(e.Fragment,{children:d}):e.jsxs(e.Fragment,{children:[ct(),Es(),!F&&e.jsx($e,{value:"-",className:"hidden"}),Object.entries(dt).map(([U,be])=>e.jsx(xs,{heading:U,className:"h-full overflow-auto",children:e.jsx(e.Fragment,{children:be.map(Oe=>e.jsx($e,{value:Oe.value,disabled:Oe.disable,onMouseDown:ye=>{ye.preventDefault(),ye.stopPropagation()},onSelect:()=>{if(B.length>=u){i?.(B.length);return}re("");const ye=[...B,Oe];se(ye),n?.(ye)},className:_("cursor-pointer",Oe.disable&&"cursor-default text-muted-foreground"),children:Oe.label},Oe.value))})},U))]})})})]})});at.displayName="MultipleSelector";const Nx=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 en({refetch:s,dialogTrigger:n,defaultValues:t={name:""},type:r="add"}){const{t:a}=O("group"),o=Ne({resolver:ke(Nx(a)),defaultValues:t,mode:"onChange"}),[l,d]=m.useState(!1),[x,u]=m.useState(!1),i=async c=>{u(!0),yt.save(c).then(()=>{$.success(a(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),s&&s(),o.reset(),d(!1)}).finally(()=>{u(!1)})};return e.jsxs(de,{open:l,onOpenChange:d,children:[e.jsx(fs,{asChild:!0,children:n||e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("span",{children:a("form.add")})]})}),e.jsxs(oe,{className:"sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsx(me,{children:a(r==="edit"?"form.edit":"form.create")}),e.jsx(Ae,{children:a(r==="edit"?"form.editDescription":"form.createDescription")})]}),e.jsx(Te,{...o,children:e.jsxs("form",{onSubmit:o.handleSubmit(i),className:"space-y-4",children:[e.jsx(j,{control:o.control,name:"name",render:({field:c})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.name")}),e.jsx(b,{children:e.jsx(D,{placeholder:a("form.namePlaceholder"),...c,className:"w-full"})}),e.jsx(A,{children:a("form.nameDescription")}),e.jsx(R,{})]})}),e.jsxs(Ie,{className:"gap-2",children:[e.jsx(Zs,{asChild:!0,children:e.jsx(L,{type:"button",variant:"outline",children:a("form.cancel")})}),e.jsxs(L,{type:"submit",disabled:x||!o.formState.isValid,children:[x&&e.jsx(ka,{className:"mr-2 h-4 w-4 animate-spin"}),a(r==="edit"?"form.update":"form.create")]})]})]})})]})]})}const yi=m.createContext(void 0);function wx({children:s,refetch:n}){const[t,r]=m.useState(!1),[a,o]=m.useState(null),[l,d]=m.useState(he.Shadowsocks);return e.jsx(yi.Provider,{value:{isOpen:t,setIsOpen:r,editingServer:a,setEditingServer:o,serverType:l,setServerType:d,refetch:n},children:s})}function _i(){const s=m.useContext(yi);if(s===void 0)throw new Error("useServerEdit must be used within a ServerEditProvider");return s}function xn({dialogTrigger:s,value:n,setValue:t,templateType:r}){const{t:a}=O("server");m.useEffect(()=>{console.log(n)},[n]);const[o,l]=m.useState(!1),[d,x]=m.useState(()=>{if(!n||Object.keys(n).length===0)return"";try{return JSON.stringify(n,null,2)}catch{return""}}),[u,i]=m.useState(null),c=w=>{if(!w)return null;try{const V=JSON.parse(w);return typeof V!="object"||V===null?a("network_settings.validation.must_be_object"):null}catch{return a("network_settings.validation.invalid_json")}},p={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:{}}}}}},P=()=>{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[]}},T=()=>{const w=c(d||"");if(w){$.error(w);return}try{if(!d){t(null),l(!1);return}t(JSON.parse(d)),l(!1)}catch{$.error(a("network_settings.errors.save_failed"))}},C=w=>{x(w),i(c(w))},F=w=>{const V=p[w];if(V){const y=JSON.stringify(V.content,null,2);x(y),i(null)}};return m.useEffect(()=>{o&&console.log(n)},[o,n]),m.useEffect(()=>{o&&n&&Object.keys(n).length>0&&x(JSON.stringify(n,null,2))},[o,n]),e.jsxs(de,{open:o,onOpenChange:w=>{!w&&o&&T(),l(w)},children:[e.jsx(fs,{asChild:!0,children:s??e.jsx(G,{variant:"link",children:a("network_settings.edit_protocol")})}),e.jsxs(oe,{className:"sm:max-w-[425px]",children:[e.jsx(ge,{children:e.jsx(me,{children:a("network_settings.edit_protocol_config")})}),e.jsxs("div",{className:"space-y-4",children:[P().length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:P().map(w=>e.jsx(G,{variant:"outline",size:"sm",onClick:()=>F(w),children:a("network_settings.use_template",{template:p[w].label})},w))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Rs,{className:`min-h-[200px] font-mono text-sm ${u?"border-red-500 focus-visible:ring-red-500":""}`,value:d,placeholder:P().length>0?a("network_settings.json_config_placeholder_with_template"):a("network_settings.json_config_placeholder"),onChange:w=>C(w.target.value)}),u&&e.jsx("p",{className:"text-sm text-red-500",children:u})]})]}),e.jsxs(Ie,{className:"gap-2",children:[e.jsx(G,{variant:"outline",onClick:()=>l(!1),children:a("common.cancel")}),e.jsx(G,{onClick:T,disabled:!!u,children:a("common.confirm")})]})]})]})}function xp(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 Cx={},Sx=Object.freeze(Object.defineProperty({__proto__:null,default:Cx},Symbol.toStringTag,{value:"Module"})),hp=Rd(Sx),_r=s=>s.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),kx=()=>{try{const s=fd.box.keyPair(),n=_r(ir.encodeBase64(s.secretKey)),t=_r(ir.encodeBase64(s.publicKey));return{privateKey:n,publicKey:t}}catch(s){throw console.error("Error generating x25519 key pair:",s),s}},Tx=()=>{try{return kx()}catch(s){throw console.error("Error generating key pair:",s),s}},Dx=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)},Fx=()=>{const s=Math.floor(Math.random()*8)*2+2;return Dx(s)},Px=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")}),Lx=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({})}),Rx=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({})}),Ex=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()}),Vx=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("")}),Ix=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({})}),Mx=h.object({}),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({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),$x=h.object({transport:h.string().default("tcp"),multiplexing:h.string().default("MULTIPLEXING_LOW")}),Ax=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({})}),Ee={shadowsocks:{schema:Px,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:Lx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},trojan:{schema:Rx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},hysteria:{schema:Ex,versions:["1","2"],alpnOptions:["hysteria","http/1.1","h2","h3"]},vless:{schema:Vx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"},{value:"kcp",label:"mKCP"},{value:"httpupgrade",label:"HttpUpgrade"},{value:"xhttp",label:"XHTTP"}],flowOptions:["none","xtls-rprx-direct","xtls-rprx-splice","xtls-rprx-vision"]},tuic:{schema:Ix,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:Mx},naive:{schema:zx},http:{schema:Ox},mieru:{schema:$x,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:Ax,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"]}},qx=({serverType:s,value:n,onChange:t})=>{const{t:r}=O("server"),a=s?Ee[s]:null,o=a?.schema||h.record(h.any()),l=s?o.parse({}):{},d=Ne({resolver:ke(o),defaultValues:l,mode:"onChange"}),[x,u]=m.useState(!1),[i,c]=m.useState("");if(m.useEffect(()=>{if(!n||Object.keys(n).length===0){if(s){const g=o.parse({});d.reset(g)}}else d.reset(n)},[s,n,t,d,o]),m.useEffect(()=>{const g=d.watch(k=>{t(k)});return()=>g.unsubscribe()},[d,t]),!s||!a)return null;const E={shadowsocks:()=>e.jsxs(e.Fragment,{children:[e.jsx(j,{control:d.control,name:"cipher",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.shadowsocks.cipher.label")}),e.jsx(b,{children:e.jsxs(Ze,{open:x,onOpenChange:u,children:[e.jsx(es,{asChild:!0,children:e.jsxs(G,{variant:"outline",role:"combobox","aria-expanded":x,className:_("w-full justify-between",!g.value&&"text-muted-foreground"),disabled:!1,children:[g.value||r("dynamic_form.shadowsocks.cipher.placeholder"),e.jsx(pd,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(Ge,{className:"w-[400px] p-0",align:"start",children:e.jsxs(Gs,{shouldFilter:!1,children:[e.jsx(lt,{placeholder:r("dynamic_form.shadowsocks.cipher.search_placeholder"),value:i,onValueChange:k=>{c(k),k&&!Ee.shadowsocks.ciphers.includes(k)&&g.onChange(k)}}),e.jsxs(Ws,{children:[e.jsxs(it,{children:[i&&e.jsxs($e,{value:i,onSelect:k=>{g.onChange(k),c(""),u(!1)},children:[e.jsx(ba,{className:"mr-2 h-4 w-4 opacity-100"}),e.jsxs("span",{className:"font-medium text-blue-600",children:[r("dynamic_form.shadowsocks.cipher.use_custom"),' "',i,'"']}),e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",r("dynamic_form.shadowsocks.cipher.custom_label"),")"]})]}),!i&&e.jsxs("div",{className:"p-2 text-sm text-muted-foreground",children:[e.jsx("p",{children:r("dynamic_form.shadowsocks.cipher.no_results")}),e.jsx("p",{className:"mt-1 text-xs",children:r("dynamic_form.shadowsocks.cipher.custom_hint")})]})]}),e.jsx(xs,{heading:r("dynamic_form.shadowsocks.cipher.preset_group"),children:Ee.shadowsocks.ciphers.filter(k=>k.toLowerCase().includes(i.toLowerCase())).map(k=>e.jsxs($e,{value:k,onSelect:W=>{g.onChange(W),c(""),u(!1)},children:[e.jsx(ba,{className:_("mr-2 h-4 w-4",g.value===k?"opacity-100":"opacity-0")}),k]},k))}),g.value&&!Ee.shadowsocks.ciphers.includes(g.value)&&e.jsx(xs,{heading:r("dynamic_form.shadowsocks.cipher.custom_group"),children:e.jsxs($e,{value:g.value,onSelect:()=>{},children:[e.jsx(ba,{className:"mr-2 h-4 w-4 opacity-100"}),e.jsx("span",{className:"font-medium text-blue-600",children:g.value}),e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",r("dynamic_form.shadowsocks.cipher.current_value"),")"]})]})})]})]})})]})}),e.jsx(A,{children:r("dynamic_form.shadowsocks.cipher.description")})]})}),e.jsx(j,{control:d.control,name:"plugin",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.shadowsocks.plugin.label")}),e.jsx(b,{children:e.jsxs(X,{onValueChange:k=>g.onChange(k==="none"?"":k),value:g.value===""?"none":g.value||"none",children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.shadowsocks.plugin.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.shadowsocks.plugins.map(k=>e.jsx(q,{value:k.value,children:k.label},k.value))})})]})}),e.jsx(A,{children:g.value&&g.value!=="none"&&g.value!==""&&e.jsxs(e.Fragment,{children:[g.value==="obfs"&&r("dynamic_form.shadowsocks.plugin.obfs_hint"),g.value==="v2ray-plugin"&&r("dynamic_form.shadowsocks.plugin.v2ray_hint")]})})]})}),d.watch("plugin")&&d.watch("plugin")!=="none"&&d.watch("plugin")!==""&&e.jsx(j,{control:d.control,name:"plugin_opts",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.shadowsocks.plugin_opts.label")}),e.jsx(A,{children:r("dynamic_form.shadowsocks.plugin_opts.description")}),e.jsx(b,{children:e.jsx(D,{type:"text",placeholder:r("dynamic_form.shadowsocks.plugin_opts.placeholder"),...g})})]})}),(d.watch("plugin")==="shadow-tls"||d.watch("plugin")==="restls")&&e.jsx(j,{control:d.control,name:"client_fingerprint",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.shadowsocks.client_fingerprint")}),e.jsx(b,{children:e.jsxs(X,{value:g.value||"chrome",onValueChange:g.onChange,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.shadowsocks.client_fingerprint_placeholder")})}),e.jsx(Q,{children:Ee.shadowsocks.clientFingerprints.map(k=>e.jsx(q,{value:k.value,children:k.label},k.value))})]})}),e.jsx(A,{children:r("dynamic_form.shadowsocks.client_fingerprint_description")})]})})]}),vmess:()=>e.jsxs(e.Fragment,{children:[e.jsx(j,{control:d.control,name:"tls",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.vmess.tls.label")}),e.jsx(b,{children:e.jsxs(X,{value:g.value?.toString(),onValueChange:k=>g.onChange(Number(k)),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.vmess.tls.placeholder")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:r("dynamic_form.vmess.tls.disabled")}),e.jsx(q,{value:"1",children:r("dynamic_form.vmess.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.vmess.tls_settings.server_name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dynamic_form.vmess.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(j,{control:d.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.vmess.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(b,{children:e.jsx(ee,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx(j,{control:d.control,name:"network",render:({field:g})=>e.jsxs(f,{children:[e.jsxs(v,{children:[r("dynamic_form.vmess.network.label"),e.jsx(xn,{value:d.watch("network_settings"),setValue:k=>d.setValue("network_settings",k),templateType:d.watch("network")})]}),e.jsx(b,{children:e.jsxs(X,{onValueChange:g.onChange,value:g.value,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.vmess.network.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.vmess.networkOptions.map(k=>e.jsx(q,{value:k.value,className:"cursor-pointer",children:k.label},k.value))})})]})})]})})]}),trojan:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"server_name",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.trojan.server_name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dynamic_form.trojan.server_name.placeholder"),...g,value:g.value||""})})]})}),e.jsx(j,{control:d.control,name:"allow_insecure",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.trojan.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(b,{children:e.jsx(ee,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})})]}),e.jsx(j,{control:d.control,name:"network",render:({field:g})=>e.jsxs(f,{children:[e.jsxs(v,{children:[r("dynamic_form.trojan.network.label"),e.jsx(xn,{value:d.watch("network_settings")||{},setValue:k=>d.setValue("network_settings",k),templateType:d.watch("network")||"tcp"})]}),e.jsx(b,{children:e.jsxs(X,{onValueChange:g.onChange,value:g.value||"tcp",children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.trojan.network.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.trojan.networkOptions.map(k=>e.jsx(q,{value:k.value,className:"cursor-pointer",children:k.label},k.value))})})]})})]})})]}),hysteria:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"version",render:({field:g})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:r("dynamic_form.hysteria.version.label")}),e.jsx(b,{children:e.jsxs(X,{value:(g.value||2).toString(),onValueChange:k=>g.onChange(Number(k)),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.hysteria.version.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.hysteria.versions.map(k=>e.jsxs(q,{value:k,className:"cursor-pointer",children:["V",k]},k))})})]})})]})}),d.watch("version")==1&&e.jsx(j,{control:d.control,name:"alpn",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.hysteria.alpn.label")}),e.jsx(b,{children:e.jsxs(X,{value:g.value||"h2",onValueChange:g.onChange,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.hysteria.alpn.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.hysteria.alpnOptions.map(k=>e.jsx(q,{value:k,children:k},k))})})]})})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"obfs.open",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.hysteria.obfs.label")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(b,{children:e.jsx(ee,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})}),!!d.watch("obfs.open")&&e.jsxs(e.Fragment,{children:[d.watch("version")=="2"&&e.jsx(j,{control:d.control,name:"obfs.type",render:({field:g})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:r("dynamic_form.hysteria.obfs.type.label")}),e.jsx(b,{children:e.jsxs(X,{value:g.value||"salamander",onValueChange:g.onChange,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.hysteria.obfs.type.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:e.jsx(q,{value:"salamander",children:r("dynamic_form.hysteria.obfs.type.salamander")})})})]})})]})}),e.jsx(j,{control:d.control,name:"obfs.password",render:({field:g})=>e.jsxs(f,{className:d.watch("version")==2?"w-full":"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.hysteria.obfs.password.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(b,{children:e.jsx(D,{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 k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",W=Array.from(crypto.getRandomValues(new Uint8Array(16))).map(te=>k[te%k.length]).join("");d.setValue("obfs.password",W),$.success(r("dynamic_form.hysteria.obfs.password.generate_success"))},className:"absolute right-0 top-0 h-full px-2 transition-transform duration-150 active:scale-90",children:e.jsx(Ke,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform duration-300 hover:rotate-180"})})]})]})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"tls.server_name",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.hysteria.tls.server_name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dynamic_form.hysteria.tls.server_name.placeholder"),...g,value:g.value||""})})]})}),e.jsx(j,{control:d.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.hysteria.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(b,{children:e.jsx(ee,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})})]}),e.jsx(j,{control:d.control,name:"bandwidth.up",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.hysteria.bandwidth.up.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(b,{children:e.jsx(D,{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(j,{control:d.control,name:"bandwidth.down",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.hysteria.bandwidth.down.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(b,{children:e.jsx(D,{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(j,{control:d.control,name:"hop_interval",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.hysteria.hop_interval.label","Hop 间隔 (秒)")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:r("dynamic_form.hysteria.hop_interval.placeholder","例如: 30"),...g,value:g.value||"",onChange:k=>{const W=k.target.value?parseInt(k.target.value):void 0;g.onChange(W)}})}),e.jsx(A,{children:r("dynamic_form.hysteria.hop_interval.description","Hop 间隔时间,单位为秒")})]})})})]}),vless:()=>e.jsxs(e.Fragment,{children:[e.jsx(j,{control:d.control,name:"tls",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.vless.tls.label")}),e.jsx(b,{children:e.jsxs(X,{value:g.value?.toString(),onValueChange:k=>g.onChange(Number(k)),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.vless.tls.placeholder")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:r("dynamic_form.vless.tls.none")}),e.jsx(q,{value:"1",children:r("dynamic_form.vless.tls.tls")}),e.jsx(q,{value:"2",children:r("dynamic_form.vless.tls.reality")})]})]})})]})}),d.watch("tls")=="1"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.vless.tls_settings.server_name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dynamic_form.vless.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(j,{control:d.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.vless.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(b,{children:e.jsx(ee,{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(j,{control:d.control,name:"reality_settings.server_name",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.server_name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dynamic_form.vless.reality_settings.server_name.placeholder"),...g})})]})}),e.jsx(j,{control:d.control,name:"reality_settings.server_port",render:({field:g})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.server_port.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dynamic_form.vless.reality_settings.server_port.placeholder"),...g})})]})}),e.jsx(j,{control:d.control,name:"reality_settings.allow_insecure",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(b,{children:e.jsx(ee,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx("div",{className:"flex items-end gap-2",children:e.jsx(j,{control:d.control,name:"reality_settings.private_key",render:({field:g})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.private_key.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(b,{children:e.jsx(D,{...g,className:"pr-9"})}),e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{try{const k=Tx();d.setValue("reality_settings.private_key",k.privateKey),d.setValue("reality_settings.public_key",k.publicKey),$.success(r("dynamic_form.vless.reality_settings.key_pair.success"))}catch{$.error(r("dynamic_form.vless.reality_settings.key_pair.error"))}},className:"absolute right-0 top-0 h-full px-2 transition-transform duration-150 active:scale-90",children:e.jsx(Ke,{icon:"ion:key-outline",className:"h-4 w-4 transition-transform duration-300 hover:rotate-180"})})}),e.jsx(Da,{children:e.jsx(ce,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.key_pair.generate")})})})]})]})]})})}),e.jsx(j,{control:d.control,name:"reality_settings.public_key",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.public_key.label")}),e.jsx(b,{children:e.jsx(D,{...g})})]})}),e.jsx(j,{control:d.control,name:"reality_settings.short_id",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.short_id.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(b,{children:e.jsx(D,{...g,className:"pr-9",placeholder:r("dynamic_form.vless.reality_settings.short_id.placeholder")})}),e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const k=Fx();d.setValue("reality_settings.short_id",k),$.success(r("dynamic_form.vless.reality_settings.short_id.success"))},className:"absolute right-0 top-0 h-full px-2 transition-transform duration-150 active:scale-90",children:e.jsx(Ke,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform duration-300 hover:rotate-180"})})}),e.jsx(Da,{children:e.jsx(ce,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.short_id.generate")})})})]})]}),e.jsx(A,{className:"text-xs text-muted-foreground",children:r("dynamic_form.vless.reality_settings.short_id.description")})]})})]}),e.jsx(j,{control:d.control,name:"network",render:({field:g})=>e.jsxs(f,{children:[e.jsxs(v,{children:[r("dynamic_form.vless.network.label"),e.jsx(xn,{value:d.watch("network_settings"),setValue:k=>d.setValue("network_settings",k),templateType:d.watch("network")})]}),e.jsx(b,{children:e.jsxs(X,{onValueChange:g.onChange,value:g.value,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.vless.network.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.vless.networkOptions.map(k=>e.jsx(q,{value:k.value,className:"cursor-pointer",children:k.label},k.value))})})]})})]})}),e.jsx(j,{control:d.control,name:"flow",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.vless.flow.label")}),e.jsx(b,{children:e.jsxs(X,{onValueChange:k=>g.onChange(k==="none"?null:k),value:g.value||"none",children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.vless.flow.placeholder")})}),e.jsx(Q,{children:Ee.vless.flowOptions.map(k=>e.jsx(q,{value:k,children:k},k))})]})})]})})]}),tuic:()=>e.jsxs(e.Fragment,{children:[e.jsx(j,{control:d.control,name:"version",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.tuic.version.label")}),e.jsx(b,{children:e.jsxs(X,{value:g.value?.toString(),onValueChange:k=>g.onChange(Number(k)),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.tuic.version.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.tuic.versions.map(k=>e.jsxs(q,{value:k,children:["V",k]},k))})})]})})]})}),e.jsx(j,{control:d.control,name:"congestion_control",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.tuic.congestion_control.label")}),e.jsx(b,{children:e.jsxs(X,{onValueChange:g.onChange,value:g.value,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.tuic.congestion_control.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.tuic.congestionControls.map(k=>e.jsx(q,{value:k,children:k.toUpperCase()},k))})})]})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"tls.server_name",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.tuic.tls.server_name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dynamic_form.tuic.tls.server_name.placeholder"),...g})})]})}),e.jsx(j,{control:d.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.tuic.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(b,{children:e.jsx(ee,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx(j,{control:d.control,name:"alpn",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.tuic.tls.alpn.label")}),e.jsx(b,{children:e.jsx(at,{options:Ee.tuic.alpnOptions,onChange:k=>g.onChange(k.map(W=>W.value)),value:Ee.tuic.alpnOptions.filter(k=>g.value?.includes(k.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(j,{control:d.control,name:"udp_relay_mode",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.tuic.udp_relay_mode.label")}),e.jsx(b,{children:e.jsxs(X,{onValueChange:g.onChange,value:g.value,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.tuic.udp_relay_mode.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.tuic.udpRelayModes.map(k=>e.jsx(q,{value:k.value,children:k.label},k.value))})})]})})]})})]}),socks:()=>e.jsx(e.Fragment,{}),naive:()=>e.jsxs(e.Fragment,{children:[e.jsx(j,{control:d.control,name:"tls",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.naive.tls.label")}),e.jsx(b,{children:e.jsxs(X,{value:g.value?.toString(),onValueChange:k=>g.onChange(Number(k)),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.naive.tls.placeholder")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:r("dynamic_form.naive.tls.disabled")}),e.jsx(q,{value:"1",children:r("dynamic_form.naive.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.naive.tls_settings.server_name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dynamic_form.naive.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(j,{control:d.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.naive.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(b,{children:e.jsx(ee,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]}),http:()=>e.jsxs(e.Fragment,{children:[e.jsx(j,{control:d.control,name:"tls",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.http.tls.label")}),e.jsx(b,{children:e.jsxs(X,{value:g.value?.toString(),onValueChange:k=>g.onChange(Number(k)),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.http.tls.placeholder")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:r("dynamic_form.http.tls.disabled")}),e.jsx(q,{value:"1",children:r("dynamic_form.http.tls.enabled")})]})]})})]})}),d.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.http.tls_settings.server_name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dynamic_form.http.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(j,{control:d.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.http.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(b,{children:e.jsx(ee,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]}),mieru:()=>e.jsxs(e.Fragment,{children:[e.jsx(j,{control:d.control,name:"transport",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.mieru.transport.label")}),e.jsx(b,{children:e.jsxs(X,{onValueChange:g.onChange,value:g.value,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.mieru.transport.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.mieru.transportOptions.map(k=>e.jsx(q,{value:k.value,children:k.label},k.value))})})]})})]})}),e.jsx(j,{control:d.control,name:"multiplexing",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.mieru.multiplexing.label")}),e.jsx(b,{children:e.jsxs(X,{onValueChange:g.onChange,value:g.value,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dynamic_form.mieru.multiplexing.placeholder")})}),e.jsx(Q,{children:e.jsx(Ns,{children:Ee.mieru.multiplexingOptions.map(k=>e.jsx(q,{value:k.value,children:k.label},k.value))})})]})})]})})]}),anytls:()=>e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:d.control,name:"padding_scheme",render:({field:g})=>e.jsxs(f,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(v,{children:r("dynamic_form.anytls.padding_scheme.label","AnyTLS 填充方案")}),e.jsx(G,{type:"button",variant:"outline",size:"sm",onClick:()=>{d.setValue("padding_scheme",Ee.anytls.defaultPaddingScheme),$.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(A,{children:r("dynamic_form.anytls.padding_scheme.description","每行一个填充规则,格式如: stop=8, 0=30-30")}),e.jsx(b,{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:k=>{const te=k.target.value.split(`
|
||
`).filter(ae=>ae.trim()!=="");g.onChange(te)}})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"tls.server_name",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.anytls.tls.server_name.label","SNI")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dynamic_form.anytls.tls.server_name.placeholder","服务器名称"),...g})})]})}),e.jsx(j,{control:d.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.anytls.tls.allow_insecure","允许不安全连接")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(b,{children:e.jsx(ee,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]})})};return e.jsx(pe,{children:E[s]?.()})};function Ux(){const{t:s}=O("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(E=>!isNaN(parseFloat(E))&&isFinite(Number(E)),{message:s("form.dynamic_rate.multiplier_error_numeric")}).refine(E=>parseFloat(E)>=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(E=>!isNaN(parseFloat(E))&&isFinite(Number(E)),{message:s("form.rate.error_numeric")}).refine(E=>parseFloat(E)>=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:o,editingServer:l,setEditingServer:d,serverType:x,setServerType:u,refetch:i}=_i(),[c,p]=m.useState([]),[P,T]=m.useState([]),[C,F]=m.useState([]),w=Ne({resolver:ke(t),defaultValues:r,mode:"onChange"});m.useEffect(()=>{V()},[a]),m.useEffect(()=>{l?.type&&l.type!==x&&u(l.type)},[l,x,u]),m.useEffect(()=>{l?l.type===x&&w.reset({...r,...l}):w.reset({...r,protocol_settings:Ee[x].schema.parse({})})},[l,w,x]);const V=async()=>{if(!a)return;const[E,g,k]=await Promise.all([yt.getList(),Ua.getList(),gt.getList()]);p(E.data?.map(W=>({label:W.name,value:W.id.toString()}))||[]),T(g.data?.map(W=>({label:W.remarks,value:W.id.toString()}))||[]),F(k.data||[])},y=m.useMemo(()=>C?.filter(E=>(E.parent_id===0||E.parent_id===null)&&E.type===x&&E.id!==w.watch("id")),[x,C,w]),N=()=>e.jsxs(Us,{children:[e.jsx(Ks,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(As,{align:"start",children:e.jsx(gm,{children:Ds.map(({type:E,label:g})=>e.jsx(Ce,{onClick:()=>{u(E),o(!0)},className:"cursor-pointer",children:e.jsx(K,{variant:"outline",className:"text-white",style:{background:vs[E]},children:g})},E))})})]}),S=()=>{o(!1),d(null),w.reset(r)},M=async()=>{const E=w.getValues();(await gt.save({...E,type:x})).data&&(S(),$.success(s("form.success")),i())};return e.jsxs(de,{open:a,onOpenChange:S,children:[N(),e.jsxs(oe,{className:"sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsx(me,{children:s(l?"form.edit_node":"form.new_node")}),e.jsx(Ae,{})]}),e.jsxs(Te,{...w,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:w.control,name:"name",render:({field:E})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:s("form.name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("form.name.placeholder"),...E})}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"rate",render:({field:E})=>e.jsxs(f,{className:"flex-[1]",children:[e.jsx(v,{children:s("form.rate.label")}),e.jsx("div",{className:"relative flex",children:e.jsx(b,{children:e.jsx(D,{type:"number",min:"0",step:"0.1",...E})})}),e.jsx(R,{})]})})]}),e.jsx(j,{control:w.control,name:"rate_time_enable",render:({field:E})=>e.jsxs(f,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(v,{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(b,{children:e.jsx(ee,{checked:E.value,onCheckedChange:E.onChange})})]}),e.jsx(R,{})]})}),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(v,{className:"",children:s("form.dynamic_rate.rules_label")}),e.jsxs(L,{type:"button",variant:"outline",size:"sm",onClick:()=>{const E=w.getValues("rate_time_ranges")||[];w.setValue("rate_time_ranges",[...E,{start:"00:00",end:"23:59",rate:"1"}])},children:[e.jsx(Ke,{icon:"ion:add",className:"mr-1 size-4"}),s("form.dynamic_rate.add_rule")]})]}),(w.watch("rate_time_ranges")||[]).map((E,g)=>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:g+1})}),e.jsx(L,{type:"button",variant:"ghost",size:"sm",onClick:()=>{const k=w.getValues("rate_time_ranges")||[];k.splice(g,1),w.setValue("rate_time_ranges",[...k])},children:e.jsx(Ke,{icon:"ion:trash-outline",className:"size-4"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(j,{control:w.control,name:`rate_time_ranges.${g}.start`,render:({field:k})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-xs",children:s("form.dynamic_rate.start_time")}),e.jsx(b,{children:e.jsx(D,{type:"time",...k,className:"text-sm"})}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:`rate_time_ranges.${g}.end`,render:({field:k})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-xs",children:s("form.dynamic_rate.end_time")}),e.jsx(b,{children:e.jsx(D,{type:"time",...k,className:"text-sm"})}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:`rate_time_ranges.${g}.rate`,render:({field:k})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-xs",children:s("form.dynamic_rate.multiplier")}),e.jsx(b,{children:e.jsx(D,{type:"number",min:"0",step:"0.1",...k,className:"text-sm",placeholder:"1.0"})}),e.jsx(R,{})]})})]})]},g)),(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(j,{control:w.control,name:"code",render:({field:E})=>e.jsxs(f,{children:[e.jsxs(v,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(b,{children:e.jsx(D,{placeholder:s("form.code.placeholder"),...E,value:E.value||""})}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"tags",render:({field:E})=>e.jsxs(f,{children:[e.jsx(v,{children:s("form.tags.label")}),e.jsx(b,{children:e.jsx(Za,{value:E.value,onChange:E.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"group_ids",render:({field:E})=>e.jsxs(f,{children:[e.jsxs(v,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(en,{dialogTrigger:e.jsx(L,{variant:"link",children:s("form.groups.add")}),refetch:V})]}),e.jsx(b,{children:e.jsx(at,{options:c,onChange:g=>E.onChange(g.map(k=>k.value)),value:c?.filter(g=>E.value.includes(g.value)),placeholder:s("form.groups.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.groups.empty")})})}),e.jsx(R,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:w.control,name:"host",render:({field:E})=>e.jsxs(f,{children:[e.jsx(v,{children:s("form.host.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:s("form.host.placeholder"),...E})}),e.jsx(R,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(j,{control:w.control,name:"port",render:({field:E})=>e.jsxs(f,{className:"flex-1",children:[e.jsxs(v,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(Ke,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(Da,{children:e.jsx(ce,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.port.tooltip")})})})]})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(b,{children:e.jsx(D,{placeholder:s("form.port.placeholder"),...E})}),e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(L,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const g=E.value;g&&w.setValue("server_port",g)},children:e.jsx(Ke,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(ce,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"server_port",render:({field:E})=>e.jsxs(f,{className:"flex-1",children:[e.jsxs(v,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(Ke,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(Da,{children:e.jsx(ce,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(b,{children:e.jsx(D,{placeholder:s("form.server_port.placeholder"),...E})}),e.jsx(R,{})]})})]})]}),a&&e.jsx(qx,{serverType:x,value:w.watch("protocol_settings"),onChange:E=>w.setValue("protocol_settings",E,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(j,{control:w.control,name:"parent_id",render:({field:E})=>e.jsxs(f,{children:[e.jsx(v,{children:s("form.parent.label")}),e.jsxs(X,{onValueChange:E.onChange,value:E.value?.toString()||"0",children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:s("form.parent.none")}),y?.map(g=>e.jsx(q,{value:g.id.toString(),className:"cursor-pointer",children:g.name},g.id))]})]}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"route_ids",render:({field:E})=>e.jsxs(f,{children:[e.jsx(v,{children:s("form.route.label")}),e.jsx(b,{children:e.jsx(at,{options:P,onChange:g=>E.onChange(g.map(k=>k.value)),value:P?.filter(g=>E.value.includes(g.value)),placeholder:s("form.route.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.route.empty")})})}),e.jsx(R,{})]})})]}),e.jsxs(Ie,{className:"mt-6 flex flex-col gap-2 sm:flex-row sm:gap-0",children:[e.jsx(L,{type:"button",variant:"outline",onClick:S,className:"w-full sm:w-auto",children:s("form.cancel")}),e.jsx(L,{type:"submit",onClick:M,className:"w-full sm:w-auto",children:s("form.submit")})]})]})]})]})}function Nr({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Aa,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{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(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(o=>a.has(o.value)).map(o=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:o.label},o.value))})]})]})}),e.jsx(Ge,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Gs,{children:[e.jsx(lt,{placeholder:n}),e.jsxs(Ws,{children:[e.jsx(it,{children:"No results found."}),e.jsx(xs,{children:t.map(o=>{const l=a.has(o.value);return e.jsxs($e,{onSelect:()=>{l?a.delete(o.value):a.add(o.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:_("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(vt,{className:_("h-4 w-4")})}),o.icon&&e.jsx(o.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${o.color}`}),e.jsx("span",{children:o.label}),r?.get(o.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(o.value)})]},o.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Mt,{}),e.jsx(xs,{children:e.jsx($e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const Hx=[{value:he.Shadowsocks,label:Ds.find(s=>s.type===he.Shadowsocks)?.label,color:vs[he.Shadowsocks]},{value:he.Vmess,label:Ds.find(s=>s.type===he.Vmess)?.label,color:vs[he.Vmess]},{value:he.Trojan,label:Ds.find(s=>s.type===he.Trojan)?.label,color:vs[he.Trojan]},{value:he.Hysteria,label:Ds.find(s=>s.type===he.Hysteria)?.label,color:vs[he.Hysteria]},{value:he.Vless,label:Ds.find(s=>s.type===he.Vless)?.label,color:vs[he.Vless]},{value:he.Tuic,label:Ds.find(s=>s.type===he.Tuic)?.label,color:vs[he.Tuic]},{value:he.Socks,label:Ds.find(s=>s.type===he.Socks)?.label,color:vs[he.Socks]},{value:he.Naive,label:Ds.find(s=>s.type===he.Naive)?.label,color:vs[he.Naive]},{value:he.Http,label:Ds.find(s=>s.type===he.Http)?.label,color:vs[he.Http]},{value:he.Mieru,label:Ds.find(s=>s.type===he.Mieru)?.label,color:vs[he.Mieru]}];function Kx({table:s,saveOrder:n,isSortMode:t,groups:r}){const a=s.getState().columnFilters.length>0,{t:o}=O("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(Ux,{}),e.jsx(D,{placeholder:o("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(Nr,{column:s.getColumn("type"),title:o("toolbar.type"),options:Hx}),s.getColumn("group_ids")&&e.jsx(Nr,{column:s.getColumn("group_ids"),title:o("columns.groups.title"),options:r.map(l=>({label:l.name,value:l.id.toString()}))})]}),a&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[o("toolbar.reset"),e.jsx(is,{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:o("toolbar.sort.tip")})})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(L,{variant:t?"default":"outline",onClick:n,size:"sm",children:o(t?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const Ea=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,Bx=s=>{const{t:n}=O("server");return[{id:"drag-handle",header:({column:t})=>e.jsx(z,{column:t,title:n("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx($a,{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(z,{column:t,title:n("columns.nodeId")}),cell:({row:t})=>{const r=t.getValue("id"),a=t.original.code;return e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(K,{variant:"outline",className:_("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(Ll,{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(L,{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:o=>{o.stopPropagation(),Rt(a||r.toString()).then(()=>{$.success(n("common:copy.success"))})},children:e.jsx(or,{className:"size-3"})})]})}),e.jsxs(ce,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[Ds.find(o=>o.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(z,{column:t,title:n("columns.show")}),cell:({row:t})=>{const[r,a]=m.useState(!!t.getValue("show"));return e.jsx(ee,{checked:r,onCheckedChange:async o=>{a(o),gt.update({id:t.original.id,type:t.original.type,show:o?1:0}).catch(()=>{a(!o),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(z,{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:_("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:_("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:_("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(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:_("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(ce,{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:_("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:_("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:_("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:_("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:_("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:_("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:_("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:_("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(z,{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(pe,{delayDuration:0,children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(L,{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:o=>{o.stopPropagation(),Rt(r).then(()=>{$.success(n("common:copy.success"))})},children:e.jsx(or,{className:"size-3"})})}),e.jsx(ce,{side:"top",sideOffset:10,children:n("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:t})=>e.jsx(z,{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(Ea,{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(z,{column:t,title:n("columns.rate.title"),tooltip:n("columns.rate.tooltip")}),cell:({row:t})=>e.jsxs(K,{variant:"secondary",className:"font-medium",children:[t.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"group_ids",header:({column:t})=>e.jsx(z,{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,o)=>e.jsx(K,{variant:"secondary",className:_("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},o)),r.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:n("columns.groups.empty")})]})},enableSorting:!1,filterFn:(t,r,a)=>{const o=t.getValue(r);return o?a.some(l=>o.includes(l)):!1}},{accessorKey:"type",header:({column:t})=>e.jsx(z,{column:t,title:n("columns.type")}),cell:({row:t})=>{const r=t.getValue("type");return e.jsx(K,{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(z,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingServer:a,setServerType:o}=_i();return e.jsx("div",{className:"flex justify-center",children:e.jsxs(Us,{modal:!1,children:[e.jsx(Ks,{asChild:!0,children:e.jsx(L,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Fa,{className:"size-4"})})}),e.jsxs(As,{align:"end",className:"w-40",children:[e.jsx(Ce,{className:"cursor-pointer",onClick:()=>{o(t.original.type),a(t.original),r(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(jd,{className:"mr-2 size-4"}),n("columns.actions_dropdown.edit")]})}),e.jsxs(Ce,{className:"cursor-pointer",onClick:async()=>{gt.copy({id:t.original.id}).then(({data:l})=>{l&&($.success(n("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx(On,{className:"mr-2 size-4"}),n("columns.actions_dropdown.copy")]}),e.jsx(tt,{}),e.jsx(Ce,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:l=>l.preventDefault(),children:e.jsx(us,{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()=>{gt.drop({id:t.original.id}).then(({data:l})=>{l&&($.success(n("columns.actions_dropdown.delete_success")),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(ms,{className:"mr-2 size-4"}),n("columns.actions_dropdown.delete.confirm")]})})})]})]})})},size:50}]};function Gx(){const[s,n]=m.useState({}),[t,r]=m.useState({"drag-handle":!1}),[a,o]=m.useState([]),[l,d]=m.useState({pageSize:500,pageIndex:0}),[x,u]=m.useState([]),[i,c]=m.useState(!1),[p,P]=m.useState({}),[T,C]=m.useState([]),{refetch:F}=ne({queryKey:["nodeList"],queryFn:async()=>{const{data:M}=await gt.getList();return C(M),M}}),{data:w}=ne({queryKey:["groups"],queryFn:async()=>{const{data:M}=await yt.getList();return M}});m.useEffect(()=>{r({"drag-handle":i,show:!i,host:!i,online:!i,rate:!i,groups:!i,type:!1,actions:!i}),P({name:i?2e3:200}),d({pageSize:i?99999:500,pageIndex:0})},[i]);const V=(M,E)=>{i&&(M.dataTransfer.setData("text/plain",E.toString()),M.currentTarget.classList.add("opacity-50"))},y=(M,E)=>{if(!i)return;M.preventDefault(),M.currentTarget.classList.remove("bg-muted");const g=parseInt(M.dataTransfer.getData("text/plain"));if(g===E)return;const k=[...T],[W]=k.splice(g,1);k.splice(E,0,W),C(k)},N=async()=>{if(!i){c(!0);return}const M=T?.map((E,g)=>({id:E.id,order:g+1}));gt.sort(M).then(()=>{$.success("排序保存成功"),c(!1),F()}).finally(()=>{c(!1)})},S=We({data:T||[],columns:Bx(F),state:{sorting:x,columnVisibility:t,rowSelection:s,columnFilters:a,columnSizing:p,pagination:l},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:u,onColumnFiltersChange:o,onColumnVisibilityChange:r,onColumnSizingChange:P,onPaginationChange:d,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(wx,{refetch:F,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ns,{table:S,toolbar:M=>e.jsx(Kx,{table:M,refetch:F,saveOrder:N,isSortMode:i,groups:w||[]}),draggable:i,onDragStart:V,onDragEnd:M=>M.currentTarget.classList.remove("opacity-50"),onDragOver:M=>{M.preventDefault(),M.currentTarget.classList.add("bg-muted")},onDragLeave:M=>M.currentTarget.classList.remove("bg-muted"),onDrop:y,showPagination:!i})})})}function Wx(){const{t:s}=O("server");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(Gx,{})})]})]})}const Yx=Object.freeze(Object.defineProperty({__proto__:null,default:Wx},Symbol.toStringTag,{value:"Module"}));function Jx({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=O("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(en,{refetch:n}),e.jsx(D,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:_("h-8 w-[150px] lg:w-[250px]",t&&"border-primary/50 ring-primary/20")}),t&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]})]})})}const Qx=s=>{const{t:n}=O("group");return[{accessorKey:"id",header:({column:t})=>e.jsx(z,{column:t,title:n("columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:t})=>e.jsx(z,{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(z,{column:t,title:n("columns.usersCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(Ea,{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(z,{column:t,title:n("columns.serverCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(Ll,{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(z,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(en,{defaultValues:t.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(nt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(us,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{yt.drop({id:t.original.id}).then(({data:r})=>{r&&($.success(n("messages.updateSuccess")),s())})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ms,{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 Xx(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,o]=m.useState([]),[l,d]=m.useState([]),{data:x,refetch:u,isLoading:i}=ne({queryKey:["serverGroupList"],queryFn:async()=>{const{data:p}=await yt.getList();return p}}),c=We({data:x||[],columns:Qx(u),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:o,onColumnVisibilityChange:r,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ns,{table:c,toolbar:p=>e.jsx(Jx,{table:p,refetch:u}),isLoading:i})}function Zx(){const{t:s}=O("group");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(Xx,{})})]})]})}const eh=Object.freeze(Object.defineProperty({__proto__:null,default:Zx},Symbol.toStringTag,{value:"Module"})),sh=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 Ni({refetch:s,dialogTrigger:n,defaultValues:t={remarks:"",match:[],action:"block",action_value:""},type:r="create"}){const{t:a}=O("route"),o=Ne({resolver:ke(sh(a)),defaultValues:t,mode:"onChange"}),[l,d]=m.useState(!1);return e.jsxs(de,{open:l,onOpenChange:d,children:[e.jsx(fs,{asChild:!0,children:n||e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ke,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add")})]})}),e.jsxs(oe,{className:"sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsx(me,{children:a(r==="edit"?"form.edit":"form.create")}),e.jsx(Ae,{})]}),e.jsxs(Te,{...o,children:[e.jsx(j,{control:o.control,name:"remarks",render:({field:x})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:a("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(b,{children:e.jsx(D,{type:"text",placeholder:a("form.remarksPlaceholder"),...x})})}),e.jsx(R,{})]})}),e.jsx(j,{control:o.control,name:"match",render:({field:x})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:a("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(b,{children:e.jsx(Rs,{className:"min-h-[120px]",placeholder:a("form.matchPlaceholder"),value:Array.isArray(x.value)?x.value.join(`
|
||
`):"",onChange:u=>{const i=u.target.value.split(`
|
||
`);x.onChange(i)}})})}),e.jsx(R,{})]})}),e.jsx(j,{control:o.control,name:"action",render:({field:x})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(b,{children:e.jsxs(X,{onValueChange:x.onChange,defaultValue:x.value,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:a("form.actionPlaceholder")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"block",children:a("actions.block")}),e.jsx(q,{value:"dns",children:a("actions.dns")})]})]})})}),e.jsx(R,{})]})}),o.watch("action")==="dns"&&e.jsx(j,{control:o.control,name:"action_value",render:({field:x})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(b,{children:e.jsx(D,{type:"text",placeholder:a("form.dnsPlaceholder"),...x})})})]})}),e.jsxs(Ie,{children:[e.jsx(Zs,{asChild:!0,children:e.jsx(L,{variant:"outline",children:a("form.cancel")})}),e.jsx(L,{type:"submit",onClick:()=>{const x=o.getValues(),u={...x,match:Array.isArray(x.match)?x.match.filter(i=>i.trim()!==""):[]};Ua.save(u).then(({data:i})=>{i&&(d(!1),s&&s(),$.success(a(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),o.reset())})},children:a("form.submit")})]})]})]})]})}function th({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=O("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(Ni,{refetch:n}),e.jsx(D,{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(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]})]})})}function ah({columns:s,data:n,refetch:t}){const[r,a]=m.useState({}),[o,l]=m.useState({}),[d,x]=m.useState([]),[u,i]=m.useState([]),c=We({data:n,columns:s,state:{sorting:u,columnVisibility:o,rowSelection:r,columnFilters:d},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:i,onColumnFiltersChange:x,onColumnVisibilityChange:l,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ns,{table:c,toolbar:p=>e.jsx(th,{table:p,refetch:t})})}const nh=s=>{const{t:n}=O("route"),t={block:{icon:vd,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:bd,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(z,{column:r,title:n("columns.id")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:r.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:r})=>e.jsx(z,{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(z,{column:r,title:n("columns.action_value.title")}),cell:({row:r})=>{const a=r.original.action,o=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"&&o?n("columns.action_value.dns",{value:o}):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(z,{column:r,title:n("columns.action")}),cell:({row:r})=>{const a=r.getValue("action"),o=t[a]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(K,{variant:t[a]?.variant||"default",className:_("flex items-center gap-1.5 px-3 py-1 capitalize",t[a]?.className),children:[o&&e.jsx(o,{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(Ni,{defaultValues:r.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(nt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(us,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Ua.drop({id:r.original.id}).then(({data:a})=>{a&&($.success(n("messages.deleteSuccess")),s())})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ms,{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 rh(){const{t:s}=O("route"),[n,t]=m.useState([]);function r(){Ua.getList().then(({data:a})=>{t(a)})}return m.useEffect(()=>{r()},[]),e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(ah,{data:n,columns:nh(r),refetch:r})})]})]})}const lh=Object.freeze(Object.defineProperty({__proto__:null,default:rh},Symbol.toStringTag,{value:"Module"})),wi=m.createContext(void 0);function ih({children:s,refreshData:n}){const[t,r]=m.useState(!1),[a,o]=m.useState(null);return e.jsx(wi.Provider,{value:{isOpen:t,setIsOpen:r,editingPlan:a,setEditingPlan:o,refreshData:n},children:s})}function Bn(){const s=m.useContext(wi);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function oh({table:s,saveOrder:n,isSortMode:t}){const{setIsOpen:r}=Bn(),{t:a}=O("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(L,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>r(!0),children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:a("plan.add")})]}),e.jsx(D,{placeholder:a("plan.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:o=>s.getColumn("name")?.setFilterValue(o.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(L,{variant:t?"default":"outline",onClick:n,size:"sm",children:a(t?"plan.sort.save":"plan.sort.edit")})})]})}const wr={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"}},ch=s=>{const{t:n}=O("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx($a,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(z,{column:t,title:n("plan.columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:t})=>e.jsx(z,{column:t,title:n("plan.columns.show")}),cell:({row:t})=>e.jsx(ee,{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(z,{column:t,title:n("plan.columns.sell")}),cell:({row:t})=>e.jsx(ee,{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(z,{column:t,title:n("plan.columns.renew"),tooltip:n("plan.columns.renew_tooltip")}),cell:({row:t})=>e.jsx(ee,{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(z,{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(z,{column:t,title:n("plan.columns.stats")}),cell:({row:t})=>{const r=t.getValue("users_count")||0,a=t.original.active_users_count||0,o=r>0?Math.round(a/r*100):0;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{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(Ca,{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(ce,{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(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{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(yd,{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(ce,{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:["活跃率:",o,"%"]})]})})]})})]})},enableSorting:!0,size:120},{accessorKey:"group",header:({column:t})=>e.jsx(z,{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(K,{variant:"secondary",className:_("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(z,{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 r?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:a.map(({period:o,key:l,unit:d})=>r[l]!=null&&e.jsxs(K,{variant:"secondary",className:_("px-2 py-0.5 font-medium transition-colors text-nowrap",wr[l].color,wr[l].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[o," ¥",r[l],d]},l))}):e.jsx("div",{className:"flex items-center",children:e.jsx(K,{variant:"outline",className:"px-2 py-0.5 text-xs text-muted-foreground border-dashed",children:n("plan.columns.price_period.no_price")})})},enableSorting:!1,size:9e3},{id:"actions",header:({column:t})=>e.jsx(z,{className:"justify-end",column:t,title:n("plan.columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingPlan:a}=Bn();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{a(t.original),r(!0)},children:[e.jsx(nt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.edit")})]}),e.jsx(us,{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:o})=>{o&&($.success(n("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ms,{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")})]})})]})}}]},dh=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()}),Gn=m.forwardRef(({className:s,...n},t)=>e.jsx(Rl,{ref:t,className:_("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(_d,{className:_("flex items-center justify-center text-current"),children:e.jsx(vt,{className:"h-4 w-4"})})}));Gn.displayName=Rl.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}},mh=[{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 uh(){const{isOpen:s,setIsOpen:n,editingPlan:t,setEditingPlan:r,refreshData:a}=Bn(),[o,l]=m.useState(!1),{t:d}=O("subscribe"),x=Ne({resolver:ke(dh),defaultValues:{...fa,...t||{}},mode:"onChange"});m.useEffect(()=>{t?x.reset({...fa,...t}):x.reset(fa)},[t,x]);const u=new In({html:!0}),[i,c]=m.useState();async function p(){yt.getList().then(({data:w})=>{c(w)})}m.useEffect(()=>{s&&p()},[s]);const P=async w=>{l(!0),ys.save(w).then(({data:V})=>{V&&($.success(d(t?"plan.form.submit.success.update":"plan.form.submit.success.add")),F(),a())}).finally(()=>{l(!1)})},T=w=>{const V=Object.values(w).map(y=>y?.message).filter(Boolean);$.error(V.join(`
|
||
`)||d("plan.form.submit.error.validation","表单校验失败"))},C=w=>{if(isNaN(w))return;const V=Object.entries(ja).reduce((y,[N,S])=>{const M=w*S.months*S.discount;return{...y,[N]:M.toFixed(2)}},{});x.setValue("prices",V,{shouldDirty:!0})},F=()=>{n(!1),r(null),x.reset(fa)};return e.jsx(de,{open:s,onOpenChange:F,children:e.jsxs(oe,{children:[e.jsxs(ge,{children:[e.jsx(me,{children:d(t?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(Ae,{})]}),e.jsx(Te,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(P,T),children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:x.control,name:"name",render:({field:w})=>e.jsxs(f,{children:[e.jsx(v,{children:d("plan.form.name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:d("plan.form.name.placeholder"),...w})}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"tags",render:({field:w})=>e.jsxs(f,{children:[e.jsx(v,{children:d("plan.form.tags.label","标签")}),e.jsx(b,{children:e.jsx(Za,{value:w.value||[],onChange:w.onChange,placeholder:d("plan.form.tags.placeholder","输入标签后按回车确认"),className:"w-full"})}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"group_id",render:({field:w})=>e.jsxs(f,{children:[e.jsxs(v,{className:"flex items-center justify-between",children:[d("plan.form.group.label"),e.jsx(en,{dialogTrigger:e.jsx(L,{variant:"link",children:d("plan.form.group.add")}),refetch:p})]}),e.jsxs(X,{value:w.value?.toString()??"",onValueChange:V=>w.onChange(V?Number(V):null),children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:d("plan.form.group.placeholder")})})}),e.jsx(Q,{children:i?.map(V=>e.jsx(q,{value:V.id.toString(),children:V.name},V.id))})]}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"transfer_enable",render:({field:w})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(b,{children:e.jsx(D,{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(R,{})]})}),e.jsx(j,{control:x.control,name:"speed_limit",render:({field:w})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(b,{children:e.jsx(D,{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(R,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children: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(D,{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 V=parseFloat(w.target.value);C(V)}})]}),e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(L,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const w=Object.keys(ja).reduce((V,y)=>({...V,[y]:""}),{});x.setValue("prices",w,{shouldDirty:!0})},children:d("plan.form.price.clear.button")})}),e.jsx(ce,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:d("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(ja).filter(([w])=>!["onetime","reset_traffic"].includes(w)).map(([w,V])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(j,{control:x.control,name:`prices.${w}`,render:({field:y})=>e.jsxs(f,{children:[e.jsxs(v,{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:["(",V.months===1?d("plan.form.price.period.monthly"):d("plan.form.price.period.months",{count:V.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(b,{children:e.jsx(D,{type:"number",placeholder:"0.00",min:0,step:"0.01",...y,value:y.value??"",onChange:N=>y.onChange(N.target.value),className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})},w))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(ja).filter(([w])=>["onetime","reset_traffic"].includes(w)).map(([w,V])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(j,{control:x.control,name:`prices.${w}`,render:({field:y})=>e.jsx(f,{children:e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-0",children:[e.jsx(v,{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(b,{children:e.jsx(D,{type:"number",placeholder:"0.00",min:0,step:"0.01",...y,value:y.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(j,{control:x.control,name:"device_limit",render:({field:w})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(b,{children:e.jsx(D,{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(R,{})]})}),e.jsx(j,{control:x.control,name:"capacity_limit",render:({field:w})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(b,{children:e.jsx(D,{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(R,{})]})})]}),e.jsx(j,{control:x.control,name:"reset_traffic_method",render:({field:w})=>e.jsxs(f,{children:[e.jsx(v,{children:d("plan.form.reset_method.label")}),e.jsxs(X,{value:w.value?.toString()??"null",onValueChange:V=>w.onChange(V=="null"?null:Number(V)),children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:d("plan.form.reset_method.placeholder")})})}),e.jsx(Q,{children:mh.map(V=>e.jsx(q,{value:V.value?.toString()??"null",children:d(`plan.form.reset_method.options.${V.label}`)},V.value))})]}),e.jsx(A,{className:"text-xs",children:d("plan.form.reset_method.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"content",render:({field:w})=>{const[V,y]=m.useState(!1);return e.jsxs(f,{className:"space-y-2",children:[e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d("plan.form.content.label"),e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(L,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",type:"button",onClick:()=>y(!V),children:V?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{d:"M10 12.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5z"}),e.jsx("path",{fillRule:"evenodd",d:"M.664 10.59a1.651 1.651 0 010-1.186A10.004 10.004 0 0110 3c4.257 0 7.893 2.66 9.336 6.41.147.381.146.804 0 1.186A10.004 10.004 0 0110 17c-4.257 0-7.893-2.66-9.336-6.41zM14 10a4 4 0 11-8 0 4 4 0 018 0z",clipRule:"evenodd"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{fillRule:"evenodd",d:"M3.28 2.22a.75.75 0 00-1.06 1.06l14.5 14.5a.75.75 0 101.06-1.06l-1.745-1.745a10.029 10.029 0 003.3-4.38 1.651 1.651 0 000-1.185A10.004 10.004 0 009.999 3a9.956 9.956 0 00-4.744 1.194L3.28 2.22zM7.752 6.69l1.092 1.092a2.5 2.5 0 013.374 3.373l1.091 1.092a4 4 0 00-5.557-5.557z",clipRule:"evenodd"}),e.jsx("path",{d:"M10.748 13.93l2.523 2.523a9.987 9.987 0 01-3.27.547c-4.258 0-7.894-2.66-9.337-6.41a1.651 1.651 0 010-1.186A10.007 10.007 0 012.839 6.02L6.07 9.252a4 4 0 004.678 4.678z"})]})})}),e.jsx(ce,{side:"top",children:e.jsx("p",{className:"text-xs",children:d(V?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(pe,{children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(L,{variant:"outline",size:"sm",type:"button",onClick:()=>{w.onChange(d("plan.form.content.template.content"))},children:d("plan.form.content.template.button")})}),e.jsx(ce,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:d("plan.form.content.template.tooltip")})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${V?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(b,{children:e.jsx(Mn,{style:{height:"400px"},value:w.value||"",renderHTML:N=>u.render(N),onChange:({text:N})=>w.onChange(N),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:d("plan.form.content.placeholder"),className:"rounded-md border"})})}),V&&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:u.render(w.value||"")}})})]})]}),e.jsx(A,{className:"text-xs",children:d("plan.form.content.description")}),e.jsx(R,{})]})}})]}),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(j,{control:x.control,name:"force_update",render:({field:w})=>e.jsxs(f,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(b,{children:e.jsx(Gn,{checked:w.value,onCheckedChange:w.onChange})}),e.jsx("div",{className:"",children:e.jsx(v,{className:"text-sm",children:d("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(L,{type:"button",variant:"outline",onClick:F,children:d("plan.form.submit.cancel")}),e.jsx(L,{type:"submit",disabled:o,children:d(o?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})})]})})}function xh(){const[s,n]=m.useState({}),[t,r]=m.useState({"drag-handle":!1}),[a,o]=m.useState([]),[l,d]=m.useState([]),[x,u]=m.useState(!1),[i,c]=m.useState({pageSize:20,pageIndex:0}),[p,P]=m.useState([]),{refetch:T}=ne({queryKey:["planList"],queryFn:async()=>{const{data:y}=await ys.getList();return P(y),y}});m.useEffect(()=>{r({"drag-handle":x}),c({pageSize:x?99999:10,pageIndex:0})},[x]);const C=(y,N)=>{x&&(y.dataTransfer.setData("text/plain",N.toString()),y.currentTarget.classList.add("opacity-50"))},F=(y,N)=>{if(!x)return;y.preventDefault(),y.currentTarget.classList.remove("bg-muted");const S=parseInt(y.dataTransfer.getData("text/plain"));if(S===N)return;const M=[...p],[E]=M.splice(S,1);M.splice(N,0,E),P(M)},w=async()=>{if(!x){u(!0);return}const y=p?.map(N=>N.id);ys.sort(y).then(()=>{$.success("排序保存成功"),u(!1),T()}).finally(()=>{u(!1)})},V=We({data:p||[],columns:ch(T),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:i},enableRowSelection:!0,onPaginationChange:c,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:o,onColumnVisibilityChange:r,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnPinning:{right:["actions"]}},pageCount:x?1:void 0});return e.jsx(ih,{refreshData:T,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(ns,{table:V,toolbar:y=>e.jsx(oh,{table:y,refetch:T,saveOrder:w,isSortMode:x}),draggable:x,onDragStart:C,onDragEnd:y=>y.currentTarget.classList.remove("opacity-50"),onDragOver:y=>{y.preventDefault(),y.currentTarget.classList.add("bg-muted")},onDragLeave:y=>y.currentTarget.classList.remove("bg-muted"),onDrop:F,showPagination:!x}),e.jsx(uh,{})]})})}function hh(){const{t:s}=O("subscribe");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(xh,{})})]})]})}const gh=Object.freeze(Object.defineProperty({__proto__:null,default:hh},Symbol.toStringTag,{value:"Module"})),Tt=[{value:le.PENDING,label:At[le.PENDING],icon:Nd,color:qt[le.PENDING]},{value:le.PROCESSING,label:At[le.PROCESSING],icon:El,color:qt[le.PROCESSING]},{value:le.COMPLETED,label:At[le.COMPLETED],icon:wn,color:qt[le.COMPLETED]},{value:le.CANCELLED,label:At[le.CANCELLED],icon:Vl,color:qt[le.CANCELLED]},{value:le.DISCOUNTED,label:At[le.DISCOUNTED],icon:wn,color:qt[le.DISCOUNTED]}],Bt=[{value:we.PENDING,label:xa[we.PENDING],icon:wd,color:ha[we.PENDING]},{value:we.PROCESSING,label:xa[we.PROCESSING],icon:El,color:ha[we.PROCESSING]},{value:we.VALID,label:xa[we.VALID],icon:wn,color:ha[we.VALID]},{value:we.INVALID,label:xa[we.INVALID],icon:Vl,color:ha[we.INVALID]}];function va({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=s?.getFilterValue(),o=Array.isArray(a)?new Set(a):a!==void 0?new Set([a]):new Set;return e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Aa,{className:"mr-2 h-4 w-4"}),n,o?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:o.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:o.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[o.size," selected"]}):t.filter(l=>o.has(l.value)).map(l=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(Ge,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Gs,{children:[e.jsx(lt,{placeholder:n}),e.jsxs(Ws,{children:[e.jsx(it,{children:"No results found."}),e.jsx(xs,{children:t.map(l=>{const d=o.has(l.value);return e.jsxs($e,{onSelect:()=>{const x=new Set(o);d?x.delete(l.value):x.add(l.value);const u=Array.from(x);s?.setFilterValue(u.length?u:void 0)},children:[e.jsx("div",{className:_("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(vt,{className:_("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)})}),o.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Mt,{}),e.jsx(xs,{children:e.jsx($e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const ph=h.object({email:h.string().min(1),plan_id:h.number(),period:h.string(),total_amount:h.number()}),fh={email:"",plan_id:0,total_amount:0,period:""};function Ci({refetch:s,trigger:n,defaultValues:t}){const{t:r}=O("order"),[a,o]=m.useState(!1),l=Ne({resolver:ke(ph),defaultValues:{...fh,...t},mode:"onChange"}),[d,x]=m.useState([]);return m.useEffect(()=>{a&&ys.getList().then(({data:u})=>{x(u)})},[a]),e.jsxs(de,{open:a,onOpenChange:o,children:[e.jsx(fs,{asChild:!0,children:n||e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:r("dialog.addOrder")})]})}),e.jsxs(oe,{className:"sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsx(me,{children:r("dialog.assignOrder")}),e.jsx(Ae,{})]}),e.jsxs(Te,{...l,children:[e.jsx(j,{control:l.control,name:"email",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.userEmail")}),e.jsx(b,{children:e.jsx(D,{placeholder:r("dialog.placeholders.email"),...u})})]})}),e.jsx(j,{control:l.control,name:"plan_id",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.subscriptionPlan")}),e.jsx(b,{children:e.jsxs(X,{value:u.value?u.value?.toString():void 0,onValueChange:i=>u.onChange(parseInt(i)),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dialog.placeholders.plan")})}),e.jsx(Q,{children:d.map(i=>e.jsx(q,{value:i.id.toString(),children:i.name},i.id))})]})})]})}),e.jsx(j,{control:l.control,name:"period",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.orderPeriod")}),e.jsx(b,{children:e.jsxs(X,{value:u.value,onValueChange:u.onChange,children:[e.jsx(J,{children:e.jsx(Z,{placeholder:r("dialog.placeholders.period")})}),e.jsx(Q,{children:Object.keys(Am).map(i=>e.jsx(q,{value:i,children:r(`period.${i}`)},i))})]})})]})}),e.jsx(j,{control:l.control,name:"total_amount",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.paymentAmount")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:r("dialog.placeholders.amount"),value:u.value/100,onChange:i=>u.onChange(parseFloat(i.currentTarget.value)*100)})}),e.jsx(R,{})]})}),e.jsxs(Ie,{children:[e.jsx(L,{variant:"outline",onClick:()=>o(!1),children:r("dialog.actions.cancel")}),e.jsx(L,{type:"submit",onClick:()=>{l.handleSubmit(u=>{ht.assign(u).then(({data:i})=>{i&&(s&&s(),l.reset(),o(!1),$.success(r("dialog.messages.addSuccess")))})})()},children:r("dialog.actions.confirm")})]})]})]})]})}function jh({table:s,refetch:n}){const{t}=O("order"),r=s.getState().columnFilters.length>0,a=Object.values(zs).filter(x=>typeof x=="number").map(x=>({label:t(`type.${zs[x]}`),value:x,color:x===zs.NEW?"green-500":x===zs.RENEWAL?"blue-500":x===zs.UPGRADE?"purple-500":"orange-500"})),o=Object.values(Xe).map(x=>({label:t(`period.${x}`),value:x,color:x===Xe.MONTH_PRICE?"slate-500":x===Xe.QUARTER_PRICE?"cyan-500":x===Xe.HALF_YEAR_PRICE?"indigo-500":x===Xe.YEAR_PRICE?"violet-500":x===Xe.TWO_YEAR_PRICE?"fuchsia-500":x===Xe.THREE_YEAR_PRICE?"pink-500":x===Xe.ONETIME_PRICE?"rose-500":"orange-500"})),l=Object.values(le).filter(x=>typeof x=="number").map(x=>({label:t(`status.${le[x]}`),value:x,icon:x===le.PENDING?Tt[0].icon:x===le.PROCESSING?Tt[1].icon:x===le.COMPLETED?Tt[2].icon:x===le.CANCELLED?Tt[3].icon:Tt[4].icon,color:x===le.PENDING?"yellow-500":x===le.PROCESSING?"blue-500":x===le.COMPLETED?"green-500":x===le.CANCELLED?"red-500":"green-500"})),d=Object.values(we).filter(x=>typeof x=="number").map(x=>({label:t(`commission.${we[x]}`),value:x,icon:x===we.PENDING?Bt[0].icon:x===we.PROCESSING?Bt[1].icon:x===we.VALID?Bt[2].icon:Bt[3].icon,color:x===we.PENDING?"yellow-500":x===we.PROCESSING?"blue-500":x===we.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ci,{refetch:n}),e.jsx(D,{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:o}),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(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("actions.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]})]})}function ls({label:s,value:n,className:t,valueClassName:r}){return e.jsxs("div",{className:_("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:_("text-sm",r),children:n||"-"})]})}function vh({status:s}){const{t:n}=O("order"),t={[le.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[le.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[le.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[le.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[le.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(K,{variant:"secondary",className:_("font-medium",t[s]),children:n(`status.${le[s]}`)})}function bh({id:s,trigger:n}){const[t,r]=m.useState(!1),[a,o]=m.useState(),{t:l}=O("order");return m.useEffect(()=>{(async()=>{if(t){const{data:x}=await ht.getInfo({id:s});o(x)}})()},[t,s]),e.jsxs(de,{onOpenChange:r,open:t,children:[e.jsx(fs,{asChild:!0,children:n}),e.jsxs(oe,{className:"max-w-xl",children:[e.jsxs(ge,{className:"space-y-2",children:[e.jsx(me,{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(vh,{status:a.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ls,{label:l("dialog.fields.userEmail"),value:a?.user?.email?e.jsxs(st,{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(Cn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(ls,{label:l("dialog.fields.orderPeriod"),value:a&&l(`period.${a.period}`)}),e.jsx(ls,{label:l("dialog.fields.subscriptionPlan"),value:a?.plan?.name,valueClassName:"font-medium"}),e.jsx(ls,{label:l("dialog.fields.callbackNo"),value:a?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ls,{label:l("dialog.fields.paymentAmount"),value:Hs(a?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(Re,{className:"my-2"}),e.jsx(ls,{label:l("dialog.fields.balancePayment"),value:Hs(a?.balance_amount||0)}),e.jsx(ls,{label:l("dialog.fields.discountAmount"),value:Hs(a?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(ls,{label:l("dialog.fields.refundAmount"),value:Hs(a?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(ls,{label:l("dialog.fields.deductionAmount"),value:Hs(a?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ls,{label:l("dialog.fields.createdAt"),value:ie(a?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(ls,{label:l("dialog.fields.updatedAt"),value:ie(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(ls,{label:l("dialog.fields.commissionStatus"),value:e.jsx(K,{variant:"secondary",className:"bg-orange-100 font-medium text-orange-800 hover:bg-orange-100",children:l("dialog.commissionStatusActive")})}),e.jsx(ls,{label:l("dialog.fields.commissionAmount"),value:Hs(a?.commission_balance||0),valueClassName:"font-medium text-orange-600"}),a?.actual_commission_balance&&e.jsx(ls,{label:l("dialog.fields.actualCommissionAmount"),value:Hs(a?.actual_commission_balance||0),valueClassName:"font-medium text-orange-700"}),a?.invite_user&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{className:"my-2"}),e.jsx(ls,{label:l("dialog.fields.inviteUser"),value:e.jsxs(st,{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(Cn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]})}),e.jsx(ls,{label:l("dialog.fields.inviteUserId"),value:a?.invite_user?.id,valueClassName:"font-mono text-xs"})]})]})]})]})]})]})}const yh={[zs.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[zs.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[zs.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[zs.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},_h={[Xe.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Xe.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Xe.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Xe.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Xe.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Xe.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Xe.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Xe.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Nh=s=>le[s],wh=s=>we[s],Ch=s=>zs[s],Sh=s=>{const{t:n}=O("order");return[{accessorKey:"trade_no",header:({column:t})=>e.jsx(z,{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(bh,{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(Cn,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(z,{column:t,title:n("table.columns.type")}),cell:({row:t})=>{const r=t.getValue("type"),a=yh[r];return e.jsx(K,{variant:"secondary",className:_("font-medium transition-colors text-nowrap",a.color,a.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:n(`type.${Ch(r)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(z,{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(z,{column:t,title:n("table.columns.period")}),cell:({row:t})=>{const r=t.getValue("period"),a=_h[r];return e.jsx(K,{variant:"secondary",className:_("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(z,{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(z,{column:t,title:n("table.columns.status")}),e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{children:e.jsx(fi,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(ce,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:t})=>{const r=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.${Nh(r.value)}`)})]}),r.value===le.PENDING&&e.jsxs(Us,{modal:!0,children:[e.jsx(Ks,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Fa,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(As,{align:"end",className:"w-[140px]",children:[e.jsx(Ce,{className:"cursor-pointer",onClick:async()=>{await ht.markPaid({trade_no:t.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(Ce,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await ht.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(z,{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(z,{column:t,title:n("table.columns.commissionStatus")}),cell:({row:t})=>{const r=t.original.status,a=t.original.commission_balance,o=Bt.find(l=>l.value===t.getValue("commission_status"));return a==0||!o?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:[o.icon&&e.jsx(o.icon,{className:`h-4 w-4 text-${o.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`commission.${wh(o.value)}`)})]}),o.value===we.PENDING&&r===le.COMPLETED&&e.jsxs(Us,{modal:!0,children:[e.jsx(Ks,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Fa,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(As,{align:"end",className:"w-[120px]",children:[e.jsx(Ce,{className:"cursor-pointer",onClick:async()=>{await ht.update({trade_no:t.original.trade_no,commission_status:we.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(Ce,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await ht.update({trade_no:t.original.trade_no,commission_status:we.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(z,{column:t,title:n("table.columns.createdAt")}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:ie(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function kh(){const[s]=Il(),[n,t]=m.useState({}),[r,a]=m.useState({}),[o,l]=m.useState([]),[d,x]=m.useState([]),[u,i]=m.useState({pageIndex:0,pageSize:20});m.useEffect(()=>{const F=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([w,V])=>{const y=s.get(w);return y?{id:w,value:V==="number"?parseInt(y):y}:null}).filter(Boolean);F.length>0&&l(F)},[s]);const{refetch:c,data:p,isLoading:P}=ne({queryKey:["orderList",u,o,d],queryFn:()=>ht.getList({pageSize:u.pageSize,current:u.pageIndex+1,filter:o,sort:d})}),T=We({data:p?.data??[],columns:Sh(c),state:{sorting:d,columnVisibility:r,rowSelection:n,columnFilters:o,pagination:u},rowCount:p?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:l,onColumnVisibilityChange:a,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),onPaginationChange:i,getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ns,{table:T,toolbar:e.jsx(jh,{table:T,refetch:c}),showPagination:!0})}function Th(){const{t:s}=O("order");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(kh,{})})]})]})}const Dh=Object.freeze(Object.defineProperty({__proto__:null,default:Th},Symbol.toStringTag,{value:"Module"}));function Fh({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Aa,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{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(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(o=>a.has(o.value)).map(o=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:o.label},o.value))})]})]})}),e.jsx(Ge,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Gs,{children:[e.jsx(lt,{placeholder:n}),e.jsxs(Ws,{children:[e.jsx(it,{children:"No results found."}),e.jsx(xs,{children:t.map(o=>{const l=a.has(o.value);return e.jsxs($e,{onSelect:()=>{l?a.delete(o.value):a.add(o.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:_("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(vt,{className:_("h-4 w-4")})}),o.icon&&e.jsx(o.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${o.color}`}),e.jsx("span",{children:o.label}),r?.get(o.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(o.value)})]},o.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Mt,{}),e.jsx(xs,{children:e.jsx($e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Ph=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"]}),Cr={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},Lh=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 Si({defaultValues:s,refetch:n,type:t="create",dialogTrigger:r=null,open:a,onOpenChange:o}){const{t:l}=O("coupon"),[d,x]=m.useState(!1),u=a??d,i=o??x,[c,p]=m.useState([]),P=Ph(l),T=Lh(l),C=Ne({resolver:ke(P),defaultValues:s||Cr});m.useEffect(()=>{s&&C.reset(s)},[s,C]),m.useEffect(()=>{ys.getList().then(({data:N})=>p(N))},[]);const F=N=>{if(!N)return;const S=(M,E)=>{const g=new Date(E*1e3);return M.setHours(g.getHours(),g.getMinutes(),g.getSeconds()),Math.floor(M.getTime()/1e3)};N.from&&C.setValue("started_at",S(N.from,C.watch("started_at"))),N.to&&C.setValue("ended_at",S(N.to,C.watch("ended_at")))},w=N=>{const S=new Date,M=Math.floor(S.getTime()/1e3),E=Math.floor((S.getTime()+N*24*60*60*1e3)/1e3);C.setValue("started_at",M),C.setValue("ended_at",E)},V=async N=>{const S=await La.save(N);if(N.generate_count&&typeof S=="string"){const M=new Blob([S],{type:"text/csv;charset=utf-8;"}),E=document.createElement("a");E.href=window.URL.createObjectURL(M),E.download=`coupons_${new Date().getTime()}.csv`,E.click(),window.URL.revokeObjectURL(E.href)}i(!1),t==="create"&&C.reset(Cr),n()},y=(N,S)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:S}),e.jsx(D,{type:"datetime-local",step:"1",value:ie(C.watch(N),"YYYY-MM-DDTHH:mm:ss"),onChange:M=>{const E=new Date(M.target.value);C.setValue(N,Math.floor(E.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(de,{open:u,onOpenChange:i,children:[r&&e.jsx(fs,{asChild:!0,children:r}),e.jsxs(oe,{className:"sm:max-w-[425px]",children:[e.jsx(ge,{children:e.jsx(me,{children:l(t==="create"?"form.add":"form.edit")})}),e.jsx(Te,{...C,children:e.jsxs("form",{onSubmit:C.handleSubmit(V),className:"space-y-4",children:[e.jsx(j,{control:C.control,name:"name",render:({field:N})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.name.label")}),e.jsx(D,{placeholder:l("form.name.placeholder"),...N}),e.jsx(R,{})]})}),t==="create"&&e.jsx(j,{control:C.control,name:"generate_count",render:({field:N})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.generateCount.label")}),e.jsx(D,{type:"number",min:0,placeholder:l("form.generateCount.placeholder"),...N,value:N.value??"",onChange:S=>N.onChange(S.target.value===""?null:parseInt(S.target.value)),className:"h-9"}),e.jsx(A,{className:"text-xs",children:l("form.generateCount.description")}),e.jsx(R,{})]})}),(!C.watch("generate_count")||C.watch("generate_count")==null)&&e.jsx(j,{control:C.control,name:"code",render:({field:N})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.code.label")}),e.jsx(D,{placeholder:l("form.code.placeholder"),...N,value:N.value??"",className:"h-9"}),e.jsx(A,{className:"text-xs",children:l("form.code.description")}),e.jsx(R,{})]})}),e.jsxs(f,{children:[e.jsx(v,{children:l("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(j,{control:C.control,name:"type",render:({field:N})=>e.jsxs(X,{value:N.value.toString(),onValueChange:S=>{const M=N.value,E=parseInt(S);N.onChange(E);const g=C.getValues("value");g&&(M===ws.AMOUNT&&E===ws.PERCENTAGE?C.setValue("value",g/100):M===ws.PERCENTAGE&&E===ws.AMOUNT&&C.setValue("value",g*100))},children:[e.jsx(J,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Z,{placeholder:l("form.type.placeholder")})}),e.jsx(Q,{children:Object.entries(qm).map(([S,M])=>e.jsx(q,{value:S,children:l(`table.toolbar.types.${S}`)},S))})]})}),e.jsx(j,{control:C.control,name:"value",render:({field:N})=>{const S=N.value==null?"":C.watch("type")===ws.AMOUNT&&typeof N.value=="number"?(N.value/100).toString():N.value.toString();return e.jsx(D,{type:"number",placeholder:l("form.value.placeholder"),...N,value:S,onChange:M=>{const E=M.target.value;if(E===""){N.onChange("");return}const g=parseFloat(E);isNaN(g)||N.onChange(C.watch("type")===ws.AMOUNT?Math.round(g*100):g)},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(f,{children:[e.jsx(v,{children:l("form.validity.label")}),e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(L,{variant:"outline",className:_("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:[ie(C.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",l("form.validity.to")," ",ie(C.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})]})}),e.jsxs(Ge,{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:T.map(N=>e.jsx(L,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>w(N.days),type:"button",children:N.label},N.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:F,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:F,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:[y("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")}),y("ended_at",l("table.validity.endTime"))]})})]})]}),e.jsx(R,{})]}),e.jsx(j,{control:C.control,name:"limit_use",render:({field:N})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitUse.label")}),e.jsx(D,{type:"number",min:0,placeholder:l("form.limitUse.placeholder"),...N,value:N.value??"",onChange:S=>N.onChange(S.target.value===""?null:parseInt(S.target.value)),className:"h-9"}),e.jsx(A,{className:"text-xs",children:l("form.limitUse.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:C.control,name:"limit_use_with_user",render:({field:N})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitUseWithUser.label")}),e.jsx(D,{type:"number",min:0,placeholder:l("form.limitUseWithUser.placeholder"),...N,value:N.value??"",onChange:S=>N.onChange(S.target.value===""?null:parseInt(S.target.value)),className:"h-9"}),e.jsx(A,{className:"text-xs",children:l("form.limitUseWithUser.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:C.control,name:"limit_period",render:({field:N})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitPeriod.label")}),e.jsx(at,{options:Object.entries(Xt).filter(([S])=>isNaN(Number(S))).map(([S,M])=>({label:l(`coupon:period.${M}`),value:S})),onChange:S=>{if(S.length===0){N.onChange([]);return}const M=S.map(E=>Xt[E.value]);N.onChange(M)},value:(N.value||[]).map(S=>({label:l(`coupon:period.${S}`),value:Object.entries(Xt).find(([M,E])=>E===S)?.[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(A,{className:"text-xs",children:l("form.limitPeriod.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:C.control,name:"limit_plan_ids",render:({field:N})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitPlan.label")}),e.jsx(at,{options:c?.map(S=>({label:S.name,value:S.id.toString()}))||[],onChange:S=>N.onChange(S.map(M=>Number(M.value))),value:(c||[]).filter(S=>(N.value||[]).includes(S.id)).map(S=>({label:S.name,value:S.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(R,{})]})}),e.jsx(Ie,{children:e.jsx(L,{type:"submit",disabled:C.formState.isSubmitting,children:C.formState.isSubmitting?l("form.submit.saving"):l("form.submit.save")})})]})})]})]})}function Rh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=O("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Si,{refetch:n,dialogTrigger:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:r("form.add")})]})}),e.jsx(D,{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(Fh,{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(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]})]})}const ki=m.createContext(void 0);function Eh({children:s,refetch:n}){const[t,r]=m.useState(!1),[a,o]=m.useState(null),l=x=>{o(x),r(!0)},d=()=>{r(!1),o(null)};return e.jsxs(ki.Provider,{value:{isOpen:t,currentCoupon:a,openEdit:l,closeEdit:d},children:[s,a&&e.jsx(Si,{defaultValues:a,refetch:n,type:"edit",open:t,onOpenChange:r})]})}function Vh(){const s=m.useContext(ki);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const Ih=s=>{const{t:n}=O("coupon");return[{accessorKey:"id",header:({column:t})=>e.jsx(z,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(K,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(z,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx(ee,{defaultChecked:t.original.show,onCheckedChange:r=>{La.update({id:t.original.id,show:r}).then(({data:a})=>!a&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(z,{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(z,{column:t,title:n("table.columns.type")}),cell:({row:t})=>e.jsx(K,{variant:"outline",children:n(`table.toolbar.types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(z,{column:t,title:n("table.columns.code")}),cell:({row:t})=>e.jsx(K,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(z,{column:t,title:n("table.columns.limitUse")}),cell:({row:t})=>e.jsx(K,{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(z,{column:t,title:n("table.columns.limitUseWithUser")}),cell:({row:t})=>e.jsx(K,{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(z,{column:t,title:n("table.columns.validity")}),cell:({row:t})=>{const[r,a]=m.useState(!1),o=Date.now(),l=t.original.started_at*1e3,d=t.original.ended_at*1e3,x=o>d,u=o<l,i=Math.ceil((d-o)/(1e3*60*60*24)),p=x?{label:n("table.validity.expired",{days:Math.abs(i)}),color:"bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"}:u?{label:n("table.validity.notStarted",{days:Math.abs(Math.ceil((l-o)/(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:i}),color:"bg-green-50 text-green-600 dark:bg-green-500/10 dark:text-green-400"};return e.jsxs(ei,{open:r,onOpenChange:a,children:[e.jsx(si,{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:_("whitespace-nowrap rounded-md px-1.5 py-0.5 text-xs font-medium",p.color),children:p.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:ie(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:ie(t.original.ended_at,"MM/DD HH:mm")})]})]}),e.jsx(fl,{className:_("h-3.5 w-3.5 shrink-0 text-muted-foreground/50 transition-transform duration-200",r&&"rotate-180")})]})}),e.jsx(ti,{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:ie(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:ie(t.original.ended_at,"YYYY/MM/DD HH:mm")})]})]})})})]})},enableSorting:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx(z,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>{const{openEdit:r}=Vh();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>r(t.original),children:[e.jsx(nt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),e.jsx(us,{title:n("table.actions.deleteConfirm.title"),description:n("table.actions.deleteConfirm.description"),confirmText:n("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{La.drop({id:t.original.id}).then(({data:a})=>{a&&($.success("删除成功"),s())})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ms,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("table.actions.delete")})]})})]})}}]};function Mh(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,o]=m.useState([]),[l,d]=m.useState([]),[x,u]=m.useState({pageIndex:0,pageSize:20}),{refetch:i,data:c}=ne({queryKey:["couponList",x,a,l],queryFn:()=>La.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:a,sort:l})}),p=We({data:c?.data??[],columns:Ih(i),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:o,onColumnVisibilityChange:r,onPaginationChange:u,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Eh,{refetch:i,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ns,{table:p,toolbar:e.jsx(Rh,{table:p,refetch:i})})})})}function Oh(){const{t:s}=O("coupon");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Mh,{})})]})]})}const zh=Object.freeze(Object.defineProperty({__proto__:null,default:Oh},Symbol.toStringTag,{value:"Module"})),$h=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 Ti({template:s,refetch:n,open:t,onOpenChange:r}){const{t:a}=O("giftCard"),[o,l]=m.useState(!1),[d,x]=m.useState([]),[u,i]=m.useState([]),c=Ne({resolver:ke($h),defaultValues:{name:"",description:"",type:1,status:!0,sort:0,icon:"",background_image:"",conditions:{},limits:{},rewards:{},special_config:{}}}),{fields:p,append:P,remove:T}=Cd({control:c.control,name:"rewards.random_rewards"});m.useEffect(()=>{t&&(async()=>{try{const S=(await ys.getList()).data||[];x(S),i(S.map(M=>({label:M.name,value:M.id.toString()})))}catch(N){console.error("Failed to fetch plans:",N),$.error("Failed to load plan list")}})()},[t]),m.useEffect(()=>{if(s){const y=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:y.balance?y.balance/100:void 0,transfer_enable:typeof y.transfer_enable=="number"?y.transfer_enable/1024/1024/1024:void 0,expire_days:y.expire_days,device_limit:y.device_limit,reset_package:y.reset_package,plan_id:y.plan_id,plan_validity_days:y.plan_validity_days,random_rewards:y.random_rewards?.map(N=>({weight:N.weight,balance:N.balance?N.balance/100:void 0,transfer_enable:typeof N.transfer_enable=="number"?N.transfer_enable/1024/1024/1024:void 0,expire_days:N.expire_days,device_limit:N.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=y=>{console.error("Form validation failed:",y),$.error(a("messages.formInvalid"))},F=async y=>{l(!0);const N=JSON.parse(JSON.stringify(y));N.rewards&&(typeof N.rewards.balance=="number"&&(N.rewards.balance=Math.round(N.rewards.balance*100)),typeof N.rewards.transfer_enable=="number"&&(N.rewards.transfer_enable=Math.round(N.rewards.transfer_enable*1024*1024*1024)),N.rewards.random_rewards&&N.rewards.random_rewards.forEach(M=>{typeof M.balance=="number"&&(M.balance=Math.round(M.balance*100)),typeof M.transfer_enable=="number"&&(M.transfer_enable=Math.round(M.transfer_enable*1024*1024*1024))}));const S={...N,conditions:N.conditions||{},limits:N.limits||{},rewards:N.rewards||{},special_config:N.special_config||{}};try{s?(await Fs.updateTemplate({id:s.id,...S}),$.success(a("messages.templateUpdated"))):(await Fs.createTemplate(S),$.success(a("messages.templateCreated"))),n(),r(!1)}catch(M){const E=M?.response?.data?.errors;E&&Object.keys(E).forEach(g=>{c.setError(g,{type:"manual",message:E[g][0]})}),$.error(a(s?"messages.updateTemplateFailed":"messages.createTemplateFailed"))}finally{l(!1)}},w=c.watch("type"),V=w===1;return e.jsx(de,{open:t,onOpenChange:r,children:e.jsxs(oe,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(ge,{children:e.jsx(me,{children:a(s?"template.form.edit":"template.form.add")})}),e.jsx(Te,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(F,C),className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"name",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.name.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:a("template.form.name.placeholder"),...y})}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"type",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.type.label")}),e.jsxs(X,{value:y.value.toString(),onValueChange:N=>y.onChange(parseInt(N)),children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:a("template.form.type.placeholder")})})}),e.jsx(Q,{children:[1,2,3].map(N=>e.jsx(q,{value:N.toString(),children:a(`types.${N}`)},N))})]}),e.jsx(R,{})]})})]}),e.jsx(j,{control:c.control,name:"description",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.description.label")}),e.jsx(b,{children:e.jsx(Rs,{placeholder:a("template.form.description.placeholder"),...y})}),e.jsx(R,{})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:e.jsx(j,{control:c.control,name:"status",render:({field:y})=>e.jsxs(f,{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(v,{className:"text-base",children:a("template.form.status.label")}),e.jsx(A,{children:a("template.form.status.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:y.value,onCheckedChange:y.onChange})})]})})}),e.jsxs(Se,{children:[e.jsx(De,{children:e.jsx(Ve,{children:a("template.form.rewards.title")})}),e.jsxs(Fe,{className:"space-y-4",children:[V&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"rewards.balance",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.balance.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.rewards.balance.placeholder"),...y,value:y.value??"",onChange:N=>{const S=N.target.valueAsNumber;y.onChange(isNaN(S)?void 0:S)}})})]})}),e.jsx(j,{control:c.control,name:"rewards.transfer_enable",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.transfer_enable.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.placeholder"),value:y.value??"",onChange:N=>{const S=N.target.valueAsNumber;y.onChange(isNaN(S)?void 0:S)}})})]})}),e.jsx(j,{control:c.control,name:"rewards.expire_days",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.expire_days.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.rewards.expire_days.placeholder"),...y,value:y.value??"",onChange:N=>{const S=N.target.valueAsNumber;y.onChange(isNaN(S)?void 0:S)}})})]})}),e.jsx(j,{control:c.control,name:"rewards.device_limit",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.device_limit.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.rewards.device_limit.placeholder"),...y,value:y.value??"",onChange:N=>{const S=N.target.valueAsNumber;y.onChange(isNaN(S)?void 0:S)}})})]})})]}),e.jsx(j,{control:c.control,name:"rewards.reset_package",render:({field:y})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{children:a("template.form.rewards.reset_package.label")}),e.jsx(A,{children:a("template.form.rewards.reset_package.description")})]}),e.jsx(b,{children:e.jsx(ee,{checked:y.value,onCheckedChange:y.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(j,{control:c.control,name:"rewards.plan_id",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.plan_id.label")}),e.jsxs(X,{value:y.value?.toString(),onValueChange:N=>y.onChange(parseInt(N,10)),children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:a("template.form.rewards.plan_id.placeholder")})})}),e.jsx(Q,{children:d.map(N=>e.jsx(q,{value:N.id.toString(),children:N.name},N.id))})]}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"rewards.plan_validity_days",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.plan_validity_days.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.rewards.plan_validity_days.placeholder"),...y,value:y.value??"",onChange:N=>{const S=N.target.valueAsNumber;y.onChange(isNaN(S)?void 0:S)}})})]})})]}),w===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{children:a("template.form.rewards.random_rewards.label")}),p.map((y,N)=>e.jsxs("div",{className:"flex items-center space-x-2 rounded-md border p-2",children:[e.jsx(j,{control:c.control,name:`rewards.random_rewards.${N}.weight`,render:({field:S})=>e.jsx(f,{children:e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.rewards.random_rewards.weight"),...S,value:S.value??"",onChange:M=>{const E=M.target.valueAsNumber;S.onChange(isNaN(E)?0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${N}.balance`,render:({field:S})=>e.jsx(f,{children:e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.rewards.balance.label"),...S,value:S.value??"",onChange:M=>{const E=M.target.valueAsNumber;S.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${N}.transfer_enable`,render:({field:S})=>e.jsx(f,{children:e.jsx(b,{children:e.jsx(D,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.label")+" (GB)",value:S.value??"",onChange:M=>{const E=M.target.valueAsNumber;S.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${N}.expire_days`,render:({field:S})=>e.jsx(f,{children:e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.rewards.expire_days.label"),...S,value:S.value??"",onChange:M=>{const E=M.target.valueAsNumber;S.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${N}.device_limit`,render:({field:S})=>e.jsx(f,{children:e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.rewards.device_limit.label"),...S,value:S.value??"",onChange:M=>{const E=M.target.valueAsNumber;S.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(L,{type:"button",variant:"ghost",size:"icon",onClick:()=>T(N),children:e.jsx(Sd,{className:"h-4 w-4"})})]},y.id)),e.jsx(L,{type:"button",variant:"outline",onClick:()=>P({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(Se,{children:[e.jsx(De,{children:e.jsx(Ve,{children:a("template.form.conditions.title")})}),e.jsxs(Fe,{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 gap-4",children:e.jsx(j,{control:c.control,name:"conditions.new_user_max_days",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.conditions.new_user_max_days.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.conditions.new_user_max_days.placeholder"),...y,value:y.value??"",onChange:N=>{const S=N.target.valueAsNumber;y.onChange(isNaN(S)?void 0:S)}})})]})})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(j,{control:c.control,name:"conditions.new_user_only",render:({field:y})=>e.jsxs(f,{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(v,{children:a("template.form.conditions.new_user_only.label")})}),e.jsx(b,{children:e.jsx(ee,{checked:y.value,onCheckedChange:y.onChange})})]})}),e.jsx(j,{control:c.control,name:"conditions.paid_user_only",render:({field:y})=>e.jsxs(f,{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(v,{children:a("template.form.conditions.paid_user_only.label")})}),e.jsx(b,{children:e.jsx(ee,{checked:y.value,onCheckedChange:y.onChange})})]})}),e.jsx(j,{control:c.control,name:"conditions.require_invite",render:({field:y})=>e.jsxs(f,{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(v,{children:a("template.form.conditions.require_invite.label")})}),e.jsx(b,{children:e.jsx(ee,{checked:y.value,onCheckedChange:y.onChange})})]})})]}),e.jsx(j,{control:c.control,name:"conditions.allowed_plans",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.conditions.allowed_plans.label")}),e.jsx(b,{children:e.jsx(at,{value:y.value?.map(N=>({label:d.find(S=>S.id===N)?.name||`ID: ${N}`,value:N.toString()}))??[],onChange:N=>y.onChange(N.map(S=>parseInt(S.value))),options:u,placeholder:a("template.form.conditions.allowed_plans.placeholder")})})]})}),e.jsx(j,{control:c.control,name:"conditions.disallowed_plans",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.conditions.disallowed_plans.label")}),e.jsx(b,{children:e.jsx(at,{value:y.value?.map(N=>({label:d.find(S=>S.id===N)?.name||`ID: ${N}`,value:N.toString()}))??[],onChange:N=>y.onChange(N.map(S=>parseInt(S.value))),options:u,placeholder:a("template.form.conditions.disallowed_plans.placeholder")})})]})})]})]}),e.jsxs(Se,{children:[e.jsx(De,{children:e.jsx(Ve,{children:a("template.form.limits.title")})}),e.jsx(Fe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"limits.max_use_per_user",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.limits.max_use_per_user.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.limits.max_use_per_user.placeholder"),...y,value:y.value??"",onChange:N=>{const S=N.target.valueAsNumber;y.onChange(isNaN(S)?void 0:S)}})})]})}),e.jsx(j,{control:c.control,name:"limits.cooldown_hours",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.limits.cooldown_hours.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",placeholder:a("template.form.limits.cooldown_hours.placeholder"),...y,value:y.value??"",onChange:N=>{const S=N.target.valueAsNumber;y.onChange(isNaN(S)?void 0:S)}})})]})}),e.jsx(j,{control:c.control,name:"limits.invite_reward_rate",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.limits.invite_reward_rate.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",step:"0.01",placeholder:a("template.form.limits.invite_reward_rate.placeholder"),...y,value:y.value??"",onChange:N=>{const S=N.target.valueAsNumber;y.onChange(isNaN(S)?void 0:S)}})}),e.jsx(A,{children:a("template.form.limits.invite_reward_rate.description")})]})})]})})]}),e.jsxs(Se,{children:[e.jsx(De,{children:e.jsx(Ve,{children:a("template.form.special_config.title")})}),e.jsx(Fe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-3 items-end gap-4",children:[e.jsx(j,{control:c.control,name:"special_config.start_time",render:({field:y})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(v,{children:a("template.form.special_config.start_time.label")}),e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{children:e.jsxs(L,{variant:"outline",className:_("w-full pl-3 text-left font-normal",!y.value&&"text-muted-foreground"),children:[y.value?Pe(new Date(y.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(Ge,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:y.value?new Date(y.value*1e3):void 0,onSelect:N=>y.onChange(N?Math.floor(N.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"special_config.end_time",render:({field:y})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(v,{children:a("template.form.special_config.end_time.label")}),e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{children:e.jsxs(L,{variant:"outline",className:_("w-full pl-3 text-left font-normal",!y.value&&"text-muted-foreground"),children:[y.value?Pe(new Date(y.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(Ge,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:y.value?new Date(y.value*1e3):void 0,onSelect:N=>y.onChange(N?Math.floor(N.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"special_config.festival_bonus",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.special_config.festival_bonus.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",step:"0.1",placeholder:a("template.form.special_config.festival_bonus.placeholder"),...y,value:y.value??"",onChange:N=>{const S=N.target.valueAsNumber;y.onChange(isNaN(S)?void 0:S)}})})]})})]})})]}),e.jsxs(Se,{children:[e.jsx(De,{children:e.jsx(Ve,{children:a("template.form.display.title")})}),e.jsx(Fe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"icon",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.icon.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:a("template.form.icon.placeholder"),...y})}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"background_image",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.background_image.label")}),e.jsx(b,{children:e.jsx(D,{placeholder:a("template.form.background_image.placeholder"),...y})}),e.jsx(R,{})]})})]})})]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(L,{type:"button",variant:"outline",onClick:()=>r(!1),children:a("common:cancel")}),e.jsx(L,{type:"submit",disabled:o,children:a(o?"common:saving":"common:submit")})]})]})})]})})}const Di=m.createContext(void 0);function Ah({children:s,refetch:n}){const[t,r]=m.useState(!1),[a,o]=m.useState(null),l=x=>{o(x),r(!!x)},d=()=>{r(!1),o(null)};return e.jsxs(Di.Provider,{value:{isOpen:t,editingTemplate:a,setEditingTemplate:l,closeEdit:d},children:[s,e.jsx(Ti,{template:a,refetch:n,open:t,onOpenChange:r})]})}function qh(){const s=m.useContext(Di);if(s===void 0)throw new Error("useTemplateEdit must be used within a TemplateEditProvider");return s}function Uh({rewards:s,type:n}){const{t}=O(["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(K,{variant:"secondary",children:t("template.table.columns.no_rewards")}):e.jsx("div",{className:"flex flex-col space-y-1",children:r.map((a,o)=>e.jsx(K,{variant:"outline",className:"whitespace-nowrap",children:a},o))})}const Hh=s=>{const{t:n}=O("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx(z,{column:t,title:n("template.table.columns.id")}),cell:({row:t})=>e.jsx(K,{children:t.original.id}),enableSorting:!0},{accessorKey:"status",header:({column:t})=>e.jsx(z,{column:t,title:n("template.table.columns.status")}),cell:({row:t})=>{const[r,a]=m.useState(!1);return e.jsx(ee,{checked:t.original.status,disabled:r,onCheckedChange:async o=>{a(!0);try{const{data:l}=await Fs.updateTemplate({id:t.original.id,status:o});l?($.success(n("messages.templateUpdated")),s()):$.error(n("messages.updateTemplateFailed"))}catch{$.error(n("messages.updateTemplateFailed"))}finally{a(!1)}}})},enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(z,{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(z,{column:t,title:n("template.table.columns.type")}),cell:({row:t})=>e.jsx(K,{variant:"outline",children:n(`types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"rewards",header:({column:t})=>e.jsx(z,{column:t,title:n("template.table.columns.rewards")}),cell:({row:t})=>e.jsx(Uh,{rewards:t.original.rewards,type:t.original.type}),enableSorting:!1},{accessorKey:"sort",header:({column:t})=>e.jsx(z,{column:t,title:n("template.table.columns.sort")}),cell:({row:t})=>e.jsx(K,{variant:"secondary",children:t.original.sort}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx(z,{column:t,title:n("template.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:ie(t.original.created_at)}),enableSorting:!0},{id:"actions",header:({column:t})=>e.jsx(z,{column:t,title:n("template.table.columns.actions")}),cell:({row:t})=>{const{setEditingTemplate:r}=qh();return e.jsxs("div",{className:"flex space-x-2",children:[e.jsxs(L,{variant:"outline",size:"sm",onClick:()=>r(t.original),children:[e.jsx(nt,{className:"h-4 w-4"}),n("template.actions.edit")]}),e.jsx(us,{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 Fs.deleteTemplate({id:t.original.id});a?($.success(n("messages.templateDeleted")),s()):$.error(n("messages.deleteTemplateFailed"))}catch{$.error(n("messages.deleteTemplateFailed"))}},children:e.jsxs(L,{variant:"outline",size:"sm",children:[e.jsx(ms,{className:"h-4 w-4"}),n("template.actions.delete")]})})]})},enableSorting:!1}]};function Fi({table:s}){const{t:n}=O("common");return e.jsxs(Us,{children:[e.jsx(kd,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(Ml,{className:"mr-2 h-4 w-4"}),n("table.viewOptions.button")]})}),e.jsxs(As,{align:"end",className:"w-[150px]",children:[e.jsx(Ha,{children:n("table.viewOptions.label")}),e.jsx(tt,{}),s.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>e.jsx(Xl,{className:"capitalize",checked:t.getIsVisible(),onCheckedChange:r=>t.toggleVisibility(!!r),children:t.id},t.id))]})]})}function Va({column:s,title:n,options:t}){const r=new Set(s?.getFilterValue());return e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(G,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Td,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):t.filter(a=>r.has(a.value)).map(a=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:a.label},`selected-${a.value}`))})]})]})}),e.jsx(Ge,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Gs,{children:[e.jsx(lt,{placeholder:n}),e.jsxs(Ws,{children:[e.jsx(it,{children:"No results found."}),e.jsx(xs,{children:t.map(a=>{const o=r.has(a.value);return e.jsxs($e,{onSelect:()=>{o?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:_("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",o?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ba,{className:_("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(xs,{children:e.jsx($e,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function Kh({table:s,refetch:n}){const{t}=O("giftCard"),[r,a]=m.useState(!1),o=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(D,{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(Va,{column:s.getColumn("type"),title:t("template.table.columns.type"),options:l}),s.getColumn("status")&&e.jsx(Va,{column:s.getColumn("status"),title:t("template.table.columns.status"),options:d}),o&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(L,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Ol,{className:"h-4 w-4 mr-2"}),t("template.form.add")]}),e.jsx(Fi,{table:s})]}),e.jsx(Ti,{template:null,refetch:n,open:r,onOpenChange:a})]})}function Bh(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,o]=m.useState([]),[l,d]=m.useState([]),[x,u]=m.useState({pageIndex:0,pageSize:20}),{refetch:i,data:c}=ne({queryKey:["giftCardTemplates",x,a,l],queryFn:()=>Fs.getTemplates({per_page:x.pageSize,page:x.pageIndex+1,filter:a,sort:l})});console.log(c);const p=We({data:c?.data??[],columns:Hh(i),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:o,onColumnVisibilityChange:r,onPaginationChange:u,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Ah,{refetch:i,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ns,{table:p,toolbar:e.jsx(Kh,{table:p,refetch:i})})})})}const Gh=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 Wh({refetch:s,open:n,onOpenChange:t}){const{t:r}=O("giftCard"),[a,o]=m.useState(!1),[l,d]=m.useState([]);m.useEffect(()=>{n&&Fs.getTemplates({per_page:1e3,page:1}).then(({data:i})=>{d(i||[])})},[n]);const x=Ne({resolver:ke(Gh),defaultValues:{count:10,prefix:"",expires_hours:24*30,max_usage:1,download_csv:!1}}),u=async i=>{o(!0);try{if(i.download_csv){const c=await Fs.generateCodes(i);if(c&&c instanceof Blob){const p=window.URL.createObjectURL(c),P=document.createElement("a");P.href=p,P.download=`gift_codes_${new Date().getTime()}.csv`,document.body.appendChild(P),P.click(),P.remove(),window.URL.revokeObjectURL(p),$.success(r("messages.codesGenerated")),s(),t(!1),x.reset()}}else await Fs.generateCodes(i),$.success(r("messages.codesGenerated")),s(),t(!1),x.reset()}catch{$.error(r("messages.generateCodesFailed"))}finally{o(!1)}};return e.jsx(de,{open:n,onOpenChange:t,children:e.jsxs(oe,{children:[e.jsx(ge,{children:e.jsx(me,{children:r("code.form.generate")})}),e.jsx(Te,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(u),className:"space-y-4",children:[e.jsx(j,{control:x.control,name:"template_id",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.template_id.label")}),e.jsxs(X,{onValueChange:c=>i.onChange(parseInt(c)),children:[e.jsx(b,{children:e.jsx(J,{children:e.jsx(Z,{placeholder:r("code.form.template_id.placeholder")})})}),e.jsx(Q,{children:l.map(c=>e.jsx(q,{value:c.id.toString(),children:c.name},c.id))})]}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"count",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.count.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",...i,onChange:c=>i.onChange(parseInt(c.target.value)||0)})}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"prefix",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.prefix.label")}),e.jsx(b,{children:e.jsx(D,{...i})}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"expires_hours",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.expires_hours.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",...i,onChange:c=>i.onChange(parseInt(c.target.value)||0)})}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"max_usage",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.max_usage.label")}),e.jsx(b,{children:e.jsx(D,{type:"number",...i,onChange:c=>i.onChange(parseInt(c.target.value)||0)})}),e.jsx(R,{})]})}),e.jsx(j,{control:x.control,name:"download_csv",render:({field:i})=>e.jsxs(f,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(b,{children:e.jsx("input",{type:"checkbox",checked:i.value,onChange:c=>i.onChange(c.target.checked)})}),e.jsx(v,{children:r("code.form.download_csv")})]})}),e.jsxs(Ie,{children:[e.jsx(L,{type:"button",variant:"outline",onClick:()=>t(!1),children:r("common.cancel")}),e.jsx(L,{type:"submit",disabled:a,children:r(a?"code.form.submit.generating":"code.form.submit.generate")})]})]})})]})})}function Yh({table:s,refetch:n}){const{t}=O("giftCard"),[r,a]=m.useState(!1),o=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(D,{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(Va,{column:s.getColumn("status"),title:t("code.table.columns.status"),options:l}),o&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(L,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Ol,{className:"h-4 w-4 mr-2"}),t("code.form.generate")]}),e.jsxs(L,{variant:"outline",size:"sm",disabled:!0,children:[e.jsx(sa,{className:"h-4 w-4 mr-2"}),t("common.export")]}),e.jsx(Fi,{table:s})]}),e.jsx(Wh,{refetch:n,open:r,onOpenChange:a})]})}const Jh=0,Qh=1,Xh=2,hn=3,Zh=s=>{const{t:n}=O("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx(z,{column:t,title:n("code.table.columns.id")}),cell:({row:t})=>e.jsx(K,{children:t.original.id})},{accessorKey:"code",header:({column:t})=>e.jsx(z,{column:t,title:n("code.table.columns.code")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(K,{variant:"secondary",children:t.original.code}),e.jsx(L,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>Rt(t.original.code).then(()=>{$.success(n("common:copy.success"))}),children:e.jsx(On,{className:"h-4 w-4"})})]})},{accessorKey:"template_name",header:({column:t})=>e.jsx(z,{column:t,title:n("code.table.columns.template_name")})},{accessorKey:"status",header:({column:t})=>e.jsx(z,{column:t,title:n("code.table.columns.status")}),cell:({row:t})=>{const r=t.original.status,a=r===hn,o=r===Jh||r===hn;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(K,{variant:r===Qh?"secondary":r===Xh||r===hn?"destructive":"default",children:n(`code.status.${r}`)}),o&&e.jsx(ee,{checked:!a,onCheckedChange:async l=>{const d=l?"enable":"disable";try{const{data:x}=await Fs.toggleCode({id:t.original.id,action:d});x?($.success(n("messages.codeStatusUpdated")),s()):$.error(n("messages.updateCodeStatusFailed"))}catch{$.error(n("messages.updateCodeStatusFailed"))}}})]})}},{accessorKey:"expires_at",header:({column:t})=>e.jsx(z,{column:t,title:n("code.table.columns.expires_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:ie(t.original.expires_at)})},{accessorKey:"usage_count",header:({column:t})=>e.jsx(z,{column:t,title:n("code.table.columns.usage_count")}),cell:({row:t})=>e.jsx(K,{variant:"outline",children:t.original.usage_count})},{accessorKey:"max_usage",header:({column:t})=>e.jsx(z,{column:t,title:n("code.table.columns.max_usage")}),cell:({row:t})=>e.jsx(K,{variant:"outline",children:t.original.max_usage})},{accessorKey:"created_at",header:({column:t})=>e.jsx(z,{column:t,title:n("code.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:ie(t.original.created_at)})}]};function eg(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,o]=m.useState([]),[l,d]=m.useState([]),[x,u]=m.useState({pageIndex:0,pageSize:20}),{refetch:i,data:c}=ne({queryKey:["giftCardCodes",x,a,l],queryFn:()=>Fs.getCodes({per_page:x.pageSize,page:x.pageIndex+1,filter:a,sort:l})}),p=We({data:c?.data??[],columns:Zh(i),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:o,onColumnVisibilityChange:r,onPaginationChange:u,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(ns,{table:p,toolbar:e.jsx(Yh,{table:p,refetch:i})})})}const sg=()=>{const{t:s}=O("giftCard");return[{accessorKey:"id",header:({column:n})=>e.jsx(z,{column:n,title:s("usage.table.columns.id")}),cell:({row:n})=>e.jsx(K,{children:n.original.id})},{accessorKey:"code",header:({column:n})=>e.jsx(z,{column:n,title:s("usage.table.columns.code")}),cell:({row:n})=>e.jsx(K,{variant:"secondary",children:n.original.code})},{accessorKey:"user_email",header:({column:n})=>e.jsx(z,{column:n,title:s("usage.table.columns.user_email")})},{accessorKey:"template_name",header:({column:n})=>e.jsx(z,{column:n,title:s("usage.table.columns.template_name")})},{accessorKey:"created_at",header:({column:n})=>e.jsx(z,{column:n,title:s("usage.table.columns.created_at")}),cell:({row:n})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:ie(n.original.created_at)})}]};function tg(){const[s,n]=m.useState([]),[t,r]=m.useState([]),[a,o]=m.useState({pageIndex:0,pageSize:20}),{data:l}=ne({queryKey:["giftCardUsages",a,s,t],queryFn:()=>Fs.getUsages({per_page:a.pageSize,page:a.pageIndex+1,filter:s,sort:t})}),d=We({data:l?.data??[],columns:sg(),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:o,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),getSortedRowModel:ps()});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(D,{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(ns,{table:d})]})}function ag(){const{t:s}=O("giftCard"),{data:n,isLoading:t}=ne({queryKey:["giftCardStats"],queryFn:()=>Fs.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((o,l)=>e.jsxs(Se,{children:[e.jsx(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:e.jsx(Ve,{className:"text-sm font-medium",children:o.title})}),e.jsx(Fe,{children:t?e.jsx(je,{className:"h-8 w-1/2"}):e.jsx("div",{className:"text-2xl font-bold",children:o.value??0})})]},l))})}function ng(){const{t:s}=O("giftCard"),[n,t]=m.useState("templates");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(bt,{value:n,onValueChange:t,className:"flex-1",children:[e.jsxs(rt,{className:"grid w-full grid-cols-4",children:[e.jsx(Be,{value:"templates",children:s("tabs.templates")}),e.jsx(Be,{value:"codes",children:s("tabs.codes")}),e.jsx(Be,{value:"usages",children:s("tabs.usages")}),e.jsx(Be,{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(Bh,{})]})}),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(eg,{})]})}),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(tg,{})]})}),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(ag,{})]})})]})]})]})}const rg=Object.freeze(Object.defineProperty({__proto__:null,default:ng},Symbol.toStringTag,{value:"Module"}));function lg({open:s,onOpenChange:n,table:t}){const{t:r}=O("user"),[a,o]=m.useState(!1),[l,d]=m.useState(""),[x,u]=m.useState(""),i=async()=>{if(!l||!x){$.error(r("messages.send_mail.required_fields"));return}try{o(!0),await qs.sendMail({subject:l,content:x,filter:t.getState().columnFilters,sort:t.getState().sorting[0]?.id,sort_type:t.getState().sorting[0]?.desc?"DESC":"ASC"}),$.success(r("messages.send_mail.success")),n(!1),d(""),u("")}catch{$.error(r("messages.send_mail.failed"))}finally{o(!1)}};return e.jsx(de,{open:s,onOpenChange:n,children:e.jsxs(oe,{className:"sm:max-w-[500px]",children:[e.jsxs(ge,{children:[e.jsx(me,{children:r("send_mail.title")}),e.jsx(Ae,{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(D,{id:"subject",value:l,onChange:c=>d(c.target.value),className:"col-span-3"})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"content",className:"text-right",children:r("send_mail.content")}),e.jsx(Rs,{id:"content",value:x,onChange:c=>u(c.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(Ie,{children:e.jsx(G,{type:"submit",onClick:i,disabled:a,children:r(a?"send_mail.sending":"send_mail.send")})})]})})}function ig({trigger:s}){const{t:n}=O("user"),[t,r]=m.useState(!1),[a,o]=m.useState(30),{data:l,isLoading:d}=ne({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:Ta,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:zn,color:"text-purple-600",bgColor:"bg-purple-100"}],u=[{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(de,{open:t,onOpenChange:r,children:[e.jsx(fs,{asChild:!0,children:s}),e.jsxs(oe,{className:"max-w-2xl",children:[e.jsxs(ge,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(Vn,{className:"h-5 w-5"}),n("traffic_reset.stats.title")]}),e.jsx(Ae,{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(X,{value:a.toString(),onValueChange:i=>o(Number(i)),children:[e.jsx(J,{className:"w-[180px]",children:e.jsx(Z,{})}),e.jsx(Q,{children:u.map(i=>e.jsx(q,{value:i.value.toString(),children:i.label},i.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((i,c)=>e.jsxs(Se,{className:"relative overflow-hidden",children:[e.jsxs(De,{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:i.title}),e.jsx("div",{className:`rounded-lg p-2 ${i.bgColor}`,children:e.jsx(i.icon,{className:`h-4 w-4 ${i.color}`})})]}),e.jsxs(Fe,{children:[e.jsx("div",{className:"text-2xl font-bold",children:i.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(Se,{children:[e.jsxs(De,{children:[e.jsx(Ve,{className:"text-lg",children:n("traffic_reset.stats.breakdown")}),e.jsx(Xs,{children:n("traffic_reset.stats.breakdown_description")})]}),e.jsx(Fe,{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(K,{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(K,{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(K,{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 og=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"]}),cg={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0,download_csv:!1};function dg({refetch:s}){const{t:n}=O("user"),[t,r]=m.useState(!1),a=Ne({resolver:ke(og),defaultValues:cg,mode:"onChange"}),[o,l]=m.useState([]);return m.useEffect(()=>{t&&ys.getList().then(({data:d})=>{d&&l(d)})},[t]),e.jsxs(de,{open:t,onOpenChange:r,children:[e.jsx(fs,{asChild:!0,children:e.jsxs(G,{size:"sm",variant:"outline",className:"gap-0 space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(oe,{className:"sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsx(me,{children:n("generate.title")}),e.jsx(Ae,{})]}),e.jsxs(Te,{...a,children:[e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!a.watch("generate_count")&&e.jsx(j,{control:a.control,name:"email_prefix",render:({field:d})=>e.jsx(D,{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(j,{control:a.control,name:"email_suffix",render:({field:d})=>e.jsx(D,{className:"flex-[4] rounded-l-none",placeholder:n("generate.form.email_domain"),...d})})]})]}),e.jsx(j,{control:a.control,name:"password",render:({field:d})=>e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.password")}),e.jsx(D,{placeholder:n("generate.form.password_placeholder"),...d}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"expired_at",render:({field:d})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(v,{children:n("generate.form.expire_time")}),e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{children:e.jsxs(G,{variant:"outline",className:_("w-full pl-3 text-left font-normal",!d.value&&"text-muted-foreground"),children:[d.value?ie(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(Ge,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(Dd,{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(j,{control:a.control,name:"plan_id",render:({field:d})=>e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.subscription")}),e.jsx(b,{children:e.jsxs(X,{value:d.value?d.value.toString():"null",onValueChange:x=>d.onChange(x==="null"?null:parseInt(x)),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"null",children:n("generate.form.subscription_none")}),o.map(x=>e.jsx(q,{value:x.id.toString(),children:x.name},x.id))]})]})})]})}),!a.watch("email_prefix")&&e.jsx(j,{control:a.control,name:"generate_count",render:({field:d})=>e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.generate_count")}),e.jsx(D,{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(j,{control:a.control,name:"download_csv",render:({field:d})=>e.jsxs(f,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(b,{children:e.jsx(Gn,{checked:d.value,onCheckedChange:d.onChange})}),e.jsx(v,{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 u=window.URL.createObjectURL(x),i=document.createElement("a");i.href=u,i.download=`users_${new Date().getTime()}.csv`,document.body.appendChild(i),i.click(),i.remove(),window.URL.revokeObjectURL(u),$.success(n("generate.form.success")),a.reset(),s(),r(!1)}}else{const{data:x}=await qs.generate(d);x&&($.success(n("generate.form.success")),a.reset(),s(),r(!1))}})(),children:n("generate.form.submit")})]})]})]})}const mg=1,ug=1e6;let gn=0;function xg(){return gn=(gn+1)%Number.MAX_SAFE_INTEGER,gn.toString()}const pn=new Map,Sr=s=>{if(pn.has(s))return;const n=setTimeout(()=>{pn.delete(s),Zt({type:"REMOVE_TOAST",toastId:s})},ug);pn.set(s,n)},hg=(s,n)=>{switch(n.type){case"ADD_TOAST":return{...s,toasts:[n.toast,...s.toasts].slice(0,mg)};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?Sr(t):s.toasts.forEach(r=>{Sr(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)}}},Na=[];let wa={toasts:[]};function Zt(s){wa=hg(wa,s),Na.forEach(n=>{n(wa)})}function gg({...s}){const n=xg(),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 pg(){const[s,n]=m.useState(wa);return m.useEffect(()=>(Na.push(n),()=>{const t=Na.indexOf(n);t>-1&&Na.splice(t,1)}),[s]),{...s,toast:gg,dismiss:t=>Zt({type:"DISMISS_TOAST",toastId:t})}}const Wn=zr,Pi=$r,fg=Ar,Li=m.forwardRef(({className:s,...n},t)=>e.jsx(Ia,{className:_("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=Ia.displayName;const jg=jt("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"}}),sn=m.forwardRef(({side:s="right",className:n,children:t,...r},a)=>e.jsxs(fg,{children:[e.jsx(Li,{}),e.jsxs(Ma,{ref:a,className:_(jg({side:s}),n),...r,children:[e.jsxs(Pn,{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(is,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),t]})]}));sn.displayName=Ma.displayName;const tn=({className:s,...n})=>e.jsx("div",{className:_("flex flex-col space-y-2 text-center sm:text-left",s),...n});tn.displayName="SheetHeader";const Ri=({className:s,...n})=>e.jsx("div",{className:_("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Ri.displayName="SheetFooter";const an=m.forwardRef(({className:s,...n},t)=>e.jsx(Oa,{ref:t,className:_("text-lg font-semibold text-foreground",s),...n}));an.displayName=Oa.displayName;const nn=m.forwardRef(({className:s,...n},t)=>e.jsx(za,{ref:t,className:_("text-sm text-muted-foreground",s),...n}));nn.displayName=za.displayName;function vg({table:s,refetch:n,permissionGroups:t=[],subscriptionPlans:r=[]}){const{t:a}=O("user"),{toast:o}=pg(),l=s.getState().columnFilters.length>0,[d,x]=m.useState([]),[u,i]=m.useState(!1),[c,p]=m.useState(!1),[P,T]=m.useState(!1),[C,F]=m.useState(!1),w=async()=>{try{const te=await qs.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),ae=te;console.log(te);const B=new Blob([ae],{type:"text/csv;charset=utf-8;"}),se=window.URL.createObjectURL(B),fe=document.createElement("a");fe.href=se,fe.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(fe),fe.click(),fe.remove(),window.URL.revokeObjectURL(se),o({title:a("messages.success"),description:a("messages.export.success")})}catch{o({title:a("messages.error"),description:a("messages.export.failed"),variant:"destructive"})}},V=async()=>{try{F(!0),await qs.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),o({title:a("messages.success"),description:a("messages.batch_ban.success")}),n()}catch{o({title:a("messages.error"),description:a("messages.batch_ban.failed"),variant:"destructive"})}finally{F(!1),T(!1)}},y=[{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.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"}]},{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"}]}],N=te=>te*1024*1024*1024,S=te=>te/(1024*1024*1024),M=()=>{x([...d,{field:"",operator:"",value:""}])},E=te=>{x(d.filter((ae,B)=>B!==te))},g=(te,ae,B)=>{const se=[...d];if(se[te]={...se[te],[ae]:B},ae==="field"){const fe=y.find(cs=>cs.value===B);fe&&(se[te].operator=fe.operators[0].value,se[te].value=fe.type==="boolean"?!1:"")}x(se)},k=(te,ae)=>{const B=y.find(se=>se.value===te.field);if(!B)return null;switch(B.type){case"text":return e.jsx(D,{placeholder:a("filter.sheet.value"),value:te.value,onChange:se=>g(ae,"value",se.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(D,{type:"number",placeholder:a("filter.sheet.value_number",{unit:B.unit}),value:B.unit==="GB"?S(te.value||0):te.value,onChange:se=>{const fe=Number(se.target.value);g(ae,"value",B.unit==="GB"?N(fe):fe)}}),B.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:B.unit})]});case"date":return e.jsx(Ss,{mode:"single",selected:te.value,onSelect:se=>g(ae,"value",se),className:"flex flex-1 justify-center rounded-md border"});case"select":return e.jsxs(X,{value:te.value,onValueChange:se=>g(ae,"value",se),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:a("filter.sheet.value")})}),e.jsx(Q,{children:B.useOptions?r.map(se=>e.jsx(q,{value:se.value.toString(),children:se.label},se.value)):B.options?.map(se=>e.jsx(q,{value:se.value.toString(),children:se.label},se.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ee,{checked:te.value,onCheckedChange:se=>g(ae,"value",se)}),e.jsx(Qe,{children:te.value?a("filter.boolean.true"):a("filter.boolean.false")})]});default:return null}},W=()=>{const te=d.filter(ae=>ae.field&&ae.operator&&ae.value!=="").map(ae=>{const B=y.find(fe=>fe.value===ae.field);let se=ae.value;return ae.operator==="contains"?{id:ae.field,value:se}:(B?.type==="date"&&se instanceof Date&&(se=Math.floor(se.getTime()/1e3)),B?.type==="boolean"&&(se=se?1:0),{id:ae.field,value:`${ae.operator}:${se}`})});s.setColumnFilters(te),i(!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(dg,{refetch:n}),e.jsx(D,{placeholder:a("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:te=>s.getColumn("email")?.setFilterValue(te.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(Wn,{open:u,onOpenChange:i,children:[e.jsx(Pi,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Ml,{className:"mr-2 h-4 w-4"}),a("filter.advanced"),d.length>0&&e.jsx(K,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:d.length})]})}),e.jsxs(sn,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(tn,{children:[e.jsx(an,{children:a("filter.sheet.title")}),e.jsx(nn,{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(L,{variant:"outline",size:"sm",onClick:M,children:a("filter.sheet.add")})]}),e.jsx(ft,{className:"h-[calc(100vh-280px)] ",children:e.jsx("div",{className:"space-y-4",children:d.map((te,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(Qe,{children:a("filter.sheet.condition",{number:ae+1})}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>E(ae),children:e.jsx(is,{className:"h-4 w-4"})})]}),e.jsxs(X,{value:te.field,onValueChange:B=>g(ae,"field",B),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:a("filter.sheet.field")})}),e.jsx(Q,{children:e.jsx(Ns,{children:y.map(B=>e.jsx(q,{value:B.value,className:"cursor-pointer",children:B.label},B.value))})})]}),te.field&&e.jsxs(X,{value:te.operator,onValueChange:B=>g(ae,"operator",B),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:a("filter.sheet.operator")})}),e.jsx(Q,{children:y.find(B=>B.value===te.field)?.operators.map(B=>e.jsx(q,{value:B.value,children:B.label},B.value))})]}),te.field&&te.operator&&k(te,ae)]},ae))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(L,{variant:"outline",onClick:()=>{x([]),i(!1)},children:a("filter.sheet.reset")}),e.jsx(L,{onClick:W,children:a("filter.sheet.apply")})]})]})]})]}),l&&e.jsxs(L,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),x([])},className:"h-8 px-2 lg:px-3",children:[a("filter.sheet.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]}),e.jsxs(Us,{modal:!1,children:[e.jsx(Ks,{asChild:!0,children:e.jsx(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:a("actions.title")})}),e.jsxs(As,{children:[e.jsx(Ce,{onClick:()=>p(!0),children:a("actions.send_email")}),e.jsx(Ce,{onClick:w,children:a("actions.export_csv")}),e.jsx(tt,{}),e.jsx(Ce,{asChild:!0,children:e.jsx(ig,{trigger:e.jsx("div",{className:"w-full cursor-pointer px-2 py-1.5 text-sm",children:a("actions.traffic_reset_stats")})})}),e.jsx(tt,{}),e.jsx(Ce,{onClick:()=>T(!0),className:"text-red-600 focus:text-red-600",children:a("actions.batch_ban")})]})]})]}),e.jsx(lg,{open:c,onOpenChange:p,table:s}),e.jsx(Kn,{open:P,onOpenChange:T,children:e.jsxs(Ba,{children:[e.jsxs(Ga,{children:[e.jsx(Ya,{children:a("actions.confirm_ban.title")}),e.jsx(Ja,{children:a(l?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(Wa,{children:[e.jsx(Xa,{disabled:C,children:a("actions.confirm_ban.cancel")}),e.jsx(Qa,{onClick:V,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"})}),bg=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"})}),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:"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"})}),fn=[{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:Wd(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(K,{variant:"outline",className:"font-mono",children:[n,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const n=s.original.u+s.original.d;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:ze(n)})}}];function Ii({user_id:s,dialogTrigger:n}){const{t}=O(["traffic"]),[r,a]=m.useState(!1),[o,l]=m.useState({pageIndex:0,pageSize:20}),{data:d,isLoading:x}=ne({queryKey:["userStats",s,o,r],queryFn:()=>r?qs.getStats({user_id:s,pageSize:o.pageSize,page:o.pageIndex+1}):null}),u=We({data:d?.data??[],columns:fn,pageCount:Math.ceil((d?.total??0)/o.pageSize),state:{pagination:o},manualPagination:!0,getCoreRowModel:Ye(),onPaginationChange:l});return e.jsxs(de,{open:r,onOpenChange:a,children:[e.jsx(fs,{asChild:!0,children:n}),e.jsxs(oe,{className:"sm:max-w-[700px]",children:[e.jsx(ge,{children:e.jsx(me,{children:t("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(An,{children:[e.jsx(qn,{children:u.getHeaderGroups().map(i=>e.jsx(Qs,{children:i.headers.map(c=>e.jsx(Hn,{className:_("h-10 px-2 text-xs",c.id==="total"&&"text-right"),children:c.isPlaceholder?null:Sa(c.column.columnDef.header,c.getContext())},c.id))},i.id))}),e.jsx(Un,{children:x?Array.from({length:o.pageSize}).map((i,c)=>e.jsx(Qs,{children:Array.from({length:fn.length}).map((p,P)=>e.jsx(Pt,{className:"p-2",children:e.jsx(je,{className:"h-6 w-full"})},P))},c)):u.getRowModel().rows?.length?u.getRowModel().rows.map(i=>e.jsx(Qs,{"data-state":i.getIsSelected()&&"selected",className:"h-10",children:i.getVisibleCells().map(c=>e.jsx(Pt,{className:"px-2",children:Sa(c.column.columnDef.cell,c.getContext())},c.id))},i.id)):e.jsx(Qs,{children:e.jsx(Pt,{colSpan:fn.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(X,{value:`${u.getState().pagination.pageSize}`,onValueChange:i=>{u.setPageSize(Number(i))},children:[e.jsx(J,{className:"h-8 w-[70px]",children:e.jsx(Z,{placeholder:u.getState().pagination.pageSize})}),e.jsx(Q,{side:"top",children:[10,20,30,40,50].map(i=>e.jsx(q,{value:`${i}`,children:i},i))})]}),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:u.getState().pagination.pageIndex+1,total:u.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:()=>u.previousPage(),disabled:!u.getCanPreviousPage()||x,children:e.jsx(bg,{className:"h-4 w-4"})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>u.nextPage(),disabled:!u.getCanNextPage()||x,children:e.jsx(yg,{className:"h-4 w-4"})})]})]})]})]})]})]})}function _g({user:s,trigger:n,onSuccess:t}){const{t:r}=O("user"),[a,o]=m.useState(!1),[l,d]=m.useState(""),[x,u]=m.useState(!1),{data:i,isLoading:c}=ne({queryKey:["trafficResetHistory",s.id],queryFn:()=>na.getUserHistory(s.id,{limit:10}),enabled:a}),p=async()=>{try{u(!0);const{data:C}=await na.resetUser({user_id:s.id,reason:l.trim()||void 0});C&&($.success(r("traffic_reset.reset_success")),o(!1),d(""),t?.())}finally{u(!1)}},P=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"}},T=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(de,{open:a,onOpenChange:o,children:[e.jsx(fs,{asChild:!0,children:n}),e.jsxs(oe,{className:"max-h-[90vh] max-w-4xl overflow-hidden",children:[e.jsxs(ge,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(Yt,{className:"h-5 w-5"}),r("traffic_reset.title")]}),e.jsx(Ae,{children:r("traffic_reset.description",{email:s.email})})]}),e.jsxs(bt,{defaultValue:"reset",className:"w-full",children:[e.jsxs(rt,{className:"grid w-full grid-cols-2",children:[e.jsxs(Be,{value:"reset",className:"flex items-center gap-2",children:[e.jsx(Yt,{className:"h-4 w-4"}),r("traffic_reset.tabs.reset")]}),e.jsxs(Be,{value:"history",className:"flex items-center gap-2",children:[e.jsx(cr,{className:"h-4 w-4"}),r("traffic_reset.tabs.history")]})]}),e.jsxs(bs,{value:"reset",className:"space-y-4",children:[e.jsxs(Se,{children:[e.jsx(De,{className:"pb-3",children:e.jsxs(Ve,{className:"flex items-center gap-2 text-lg",children:[e.jsx(zl,{className:"h-5 w-5"}),r("traffic_reset.user_info")]})}),e.jsx(Fe,{className:"space-y-3",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(Qe,{className:"text-muted-foreground",children:r("columns.email")}),e.jsx("p",{className:"font-medium",children:s.email})]}),e.jsxs("div",{children:[e.jsx(Qe,{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(Qe,{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(Qe,{className:"text-muted-foreground",children:r("columns.expire_time")}),e.jsx("p",{className:"font-medium",children:s.expired_at?ie(s.expired_at):r("columns.expire_status.permanent")})]})]})})]}),e.jsxs(Se,{className:"border-amber-200 bg-amber-50",children:[e.jsx(De,{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(Fe,{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(Qe,{htmlFor:"reason",children:r("traffic_reset.reason.label")}),e.jsx(Rs,{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:()=>o(!1),children:r("common:cancel")}),e.jsx(G,{onClick:p,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:[i?.data?.user&&e.jsxs(Se,{children:[e.jsx(De,{className:"pb-3",children:e.jsx(Ve,{className:"text-lg",children:r("traffic_reset.history.summary")})}),e.jsx(Fe,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(Qe,{className:"text-muted-foreground",children:r("traffic_reset.history.reset_count")}),e.jsx("p",{className:"font-medium",children:i.data.user.reset_count})]}),e.jsxs("div",{children:[e.jsx(Qe,{className:"text-muted-foreground",children:r("traffic_reset.history.last_reset")}),e.jsx("p",{className:"font-medium",children:i.data.user.last_reset_at?ie(i.data.user.last_reset_at):r("traffic_reset.history.never")})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Qe,{className:"text-muted-foreground",children:r("traffic_reset.history.next_reset")}),e.jsx("p",{className:"font-medium",children:i.data.user.next_reset_at?ie(i.data.user.next_reset_at):r("traffic_reset.history.no_schedule")})]})]})})]}),e.jsxs(Se,{children:[e.jsxs(De,{className:"pb-3",children:[e.jsx(Ve,{className:"text-lg",children:r("traffic_reset.history.records")}),e.jsx(Xs,{children:r("traffic_reset.history.recent_records")})]}),e.jsx(Fe,{children:e.jsx(ft,{className:"h-[300px]",children:i?.data?.history?.length?e.jsx("div",{className:"space-y-3",children:i.data.history.map((C,F)=>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(K,{className:P(C.reset_type),children:C.reset_type_name}),e.jsx(K,{variant:"outline",className:T(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(Qe,{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(zn,{className:"h-3 w-3"}),r("traffic_reset.history.reset_time")]}),e.jsx("p",{className:"font-medium",children:ie(C.reset_time)})]}),e.jsxs("div",{children:[e.jsx(Qe,{className:"text-muted-foreground",children:r("traffic_reset.history.traffic_cleared")}),e.jsx("p",{className:"font-medium text-destructive",children:C.old_traffic.formatted})]})]})]})}),F<i.data.history.length-1&&e.jsx(Re,{className:"my-2"})]},C.id))}):e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx(cr,{className:"mx-auto mb-4 h-12 w-12 opacity-50"}),e.jsx("p",{children:r("traffic_reset.history.no_records")})]})})})]})]})})]})]})]})}function Ng({onConfirm:s,children:n,title:t="确认操作",description:r="确定要执行此操作吗?",cancelText:a="取消",confirmText:o="确认",variant:l="default",className:d}){return e.jsxs(Kn,{children:[e.jsx(gi,{asChild:!0,children:n}),e.jsxs(Ba,{className:_("sm:max-w-[425px]",d),children:[e.jsxs(Ga,{children:[e.jsx(Ya,{children:t}),e.jsx(Ja,{children:r})]}),e.jsxs(Wa,{children:[e.jsx(Xa,{asChild:!0,children:e.jsx(L,{variant:"outline",children:a})}),e.jsx(Qa,{asChild:!0,children:e.jsx(L,{variant:l,onClick:s,children:o})})]})]})]})}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:"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"})}),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:"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"})}),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:"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"})}),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:"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"})}),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:"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"})}),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:"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"})}),Dg=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"})}),Fg=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"})}),Pg=(s,n,t,r)=>{const{t:a}=O("user");return[{accessorKey:"is_admin",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(o,l,d)=>d.includes(o.getValue(l)),size:0},{accessorKey:"is_staff",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(o,l,d)=>d.includes(o.getValue(l)),size:0},{accessorKey:"id",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.id")}),cell:({row:o})=>e.jsx(K,{variant:"outline",children:o.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.email")}),cell:({row:o})=>{const l=o.original.t||0,d=Date.now()/1e3-l<120,x=Math.floor(Date.now()/1e3-l);let u=d?a("columns.online_status.online"):l===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:ie(l)});if(!d&&l!==0){const P=Math.floor(x/60),T=Math.floor(P/60),C=Math.floor(T/24);C>0?u+=`
|
||
`+a("columns.online_status.offline_duration.days",{count:C}):T>0?u+=`
|
||
`+a("columns.online_status.offline_duration.hours",{count:T}):P>0?u+=`
|
||
`+a("columns.online_status.offline_duration.minutes",{count:P}):u+=`
|
||
`+a("columns.online_status.offline_duration.seconds",{count:x})}const[i,c]=Mr.useState(!1),p=o.original.email;return e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{children:e.jsxs("div",{className:"flex items-center gap-2.5 group",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsx("div",{className:_("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:p}),e.jsx("button",{type:"button",className:_("ml-1 p-1 rounded transition-opacity bg-transparent hover:bg-muted",i?"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:P=>{P.stopPropagation(),Rt(p),$.success(a("common:copy.success"))},style:{lineHeight:0},children:e.jsx(On,{className:"h-4 w-4 text-muted-foreground"})})]})}),e.jsx(ce,{side:"bottom",className:"max-w-[280px]",children:e.jsx("p",{className:"whitespace-pre-line text-sm",children:u})})]})})},enableSorting:!1,enableHiding:!1},{accessorKey:"online_count",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.online_count")}),cell:({row:o})=>{const l=o.original.device_limit,d=o.original.online_count||0;return e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(K,{variant:"outline",className:_("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(ce,{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:o})=>e.jsx(z,{column:o,title:a("columns.status")}),cell:({row:o})=>{const l=o.original.banned;return e.jsx("div",{className:"flex justify-center",children:e.jsx(K,{className:_("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:(o,l,d)=>d.includes(o.getValue(l))},{accessorKey:"plan_id",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.subscription")}),cell:({row:o})=>e.jsx("div",{className:"min-w-[10em] break-all",children:o.original?.plan?.name||"-"}),enableSorting:!1,enableHiding:!1},{accessorKey:"group_id",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.group")}),cell:({row:o})=>e.jsx("div",{className:"flex flex-wrap gap-1",children:e.jsx(K,{variant:"outline",className:_("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:o.original?.group?.name||"-"})}),enableSorting:!1},{accessorKey:"total_used",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.used_traffic")}),cell:({row:o})=>{const l=ze(o.original?.total_used),d=ze(o.original?.transfer_enable),x=o.original?.total_used/o.original?.transfer_enable*100||0;return e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{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:_("h-full rounded-full transition-all",x>90?"bg-destructive":"bg-primary"),style:{width:`${Math.min(x,100)}%`}})})]})}),e.jsx(ce,{side:"bottom",children:e.jsxs("p",{className:"text-sm",children:[a("columns.total_traffic"),": ",d]})})]})})}},{accessorKey:"transfer_enable",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.total_traffic")}),cell:({row:o})=>e.jsx("div",{className:"font-medium text-muted-foreground",children:ze(o.original?.transfer_enable)})},{accessorKey:"expired_at",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.expire_time")}),cell:({row:o})=>{const l=o.original.expired_at,d=Date.now()/1e3,x=l!=null&&l<d,u=l!=null?new Date(l*1e3):null,i=u!=null?Math.ceil((u.getTime()-Date.now())/(1e3*60*60*24)):null;return e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{className:"block w-full",children:e.jsx(K,{variant:"outline",className:_("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"):ie(l,"YYYY-MM-DD")})}),e.jsx(ce,{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"),": ",ie(l)]}),e.jsx("p",{className:_("text-sm font-medium",x?"text-destructive":"text-success"),children:x?a("columns.expire_status.expired",{days:Math.abs(i??0)}):a("columns.expire_status.remaining",{days:i??0})}),o.original.next_reset_at&&e.jsxs("p",{className:"text-sm",children:[a("columns.next_reset_at"),":"," ",ie(o.original.next_reset_at)]})]}):e.jsx("p",{className:"text-sm font-medium",children:a("columns.expire_status.permanent")})})]})})}},{accessorKey:"balance",header:({column:o})=>e.jsx(z,{column:o,title:a("columns.balance")}),cell:({row:o})=>{const l=hr(o.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:o})=>e.jsx(z,{column:o,title:a("columns.commission")}),cell:({row:o})=>{const l=hr(o.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:o})=>e.jsx(z,{column:o,title:a("columns.register_time")}),cell:({row:o})=>e.jsx("div",{className:"truncate",children:ie(o.original?.created_at)}),size:1e3},{id:"actions",header:({column:o})=>e.jsx(z,{column:o,className:"justify-end",title:a("columns.actions")}),cell:({row:o,table:l})=>e.jsxs(Us,{modal:!1,children:[e.jsx(Ks,{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(Fa,{className:"size-4"})})})}),e.jsxs(As,{align:"end",className:"min-w-[40px]",children:[e.jsx(Ce,{onSelect:d=>{d.preventDefault(),t(o.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(wg,{className:"mr-2"}),a("columns.actions_menu.edit")]})}),e.jsx(Ce,{onSelect:d=>d.preventDefault(),className:"p-0",children:e.jsx(Ci,{defaultValues:{email:o.original.email},trigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Cg,{className:"mr-2"}),a("columns.actions_menu.assign_order")]})})}),e.jsx(Ce,{onSelect:()=>{Rt(o.original.subscribe_url).then(()=>{$.success(a("common:copy.success"))})},className:"p-0 ,",children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Sg,{className:"mr-2"}),a("columns.actions_menu.copy_url")]})}),e.jsxs(Ce,{className:"",onSelect:()=>{qs.resetSecret(o.original.id).then(({data:d})=>{d&&$.success("重置成功")})},children:[e.jsx(kr,{className:"mr-4"}),a("columns.actions_menu.reset_secret")]}),e.jsx(Ce,{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(st,{to:`/finance/order?user_id=eq:${o.original.id}`,children:[e.jsx(kg,{className:"mr-2"}),a("columns.actions_menu.orders")]})})}),e.jsxs(Ce,{onSelect:()=>{l.setColumnFilters([{id:"invite_user_id",value:"eq:"+o.original?.id}])},children:[e.jsx(Tg,{className:"mr-4"}),a("columns.actions_menu.invites")]}),e.jsx(Ce,{onSelect:d=>d.preventDefault(),className:"p-0",children:e.jsx(Ii,{user_id:o.original?.id,dialogTrigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Dg,{className:"mr-2"}),a("columns.actions_menu.traffic_records")]})})}),e.jsx(Ce,{onSelect:d=>d.preventDefault(),className:"p-0",children:e.jsx(_g,{user:o.original,onSuccess:s,trigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(kr,{className:"mr-2"}),a("columns.actions_menu.reset_traffic")]})})}),e.jsx(Ce,{onSelect:d=>d.preventDefault(),className:"p-0",children:e.jsx(Ng,{title:a("columns.actions_menu.delete_confirm_title"),description:a("columns.actions_menu.delete_confirm_description",{email:o.original.email}),cancelText:a("common:cancel"),confirmText:a("common:confirm"),variant:"destructive",onConfirm:async()=>{try{const{data:d}=await qs.destroy(o.original.id);d&&($.success(a("common:delete.success")),s())}catch{$.error(a("common:delete.failed"))}},children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5 text-destructive hover:text-destructive",children:[e.jsx(Fg,{className:"mr-2"}),a("columns.actions_menu.delete")]})})})]})]})}]},Mi=m.createContext(void 0),Yn=()=>{const s=m.useContext(Mi);if(!s)throw new Error("useUserEdit must be used within an UserEditProvider");return s},Oi=({children:s,refreshData:n})=>{const[t,r]=m.useState(!1),[a,o]=m.useState(null),l={isOpen:t,setIsOpen:r,editingUser:a,setEditingUser:o,refreshData:n};return e.jsx(Mi.Provider,{value:l,children:s})},Lg=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}=O("user"),{isOpen:n,setIsOpen:t,editingUser:r,refreshData:a}=Yn(),[o,l]=m.useState(!1),[d,x]=m.useState([]),u=Ne({resolver:ke(Lg)});return m.useEffect(()=>{n&&ys.getList().then(({data:i})=>{x(i)})},[n]),m.useEffect(()=>{if(r){const i=r.invite_user?.email,{invite_user:c,...p}=r;u.reset({...p,invite_user_email:i||null,password:null,u:p.u?(p.u/1024/1024/1024).toFixed(3):"",d:p.d?(p.d/1024/1024/1024).toFixed(3):""})}},[r,u]),e.jsx(Wn,{open:n,onOpenChange:t,children:e.jsxs(sn,{className:"max-w-[90%] space-y-4",children:[e.jsxs(tn,{children:[e.jsx(an,{children:s("edit.title")}),e.jsx(nn,{})]}),e.jsxs(Te,{...u,children:[e.jsx(j,{control:u.control,name:"email",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.email")}),e.jsx(b,{children:e.jsx(D,{...i,placeholder:s("edit.form.email_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(R,{...i})]})}),e.jsx(j,{control:u.control,name:"invite_user_email",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.inviter_email")}),e.jsx(b,{children:e.jsx(D,{value:i.value||"",onChange:c=>i.onChange(c.target.value?c.target.value:null),placeholder:s("edit.form.inviter_email_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(R,{...i})]})}),e.jsx(j,{control:u.control,name:"password",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.password")}),e.jsx(b,{children:e.jsx(D,{type:"password",value:i.value||"",onChange:i.onChange,placeholder:s("edit.form.password_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(R,{...i})]})}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsx(j,{control:u.control,name:"balance",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.balance")}),e.jsx(b,{children:e.jsxs("div",{className:"flex",children:[e.jsx(D,{type:"number",value:i.value||"",onChange:i.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(R,{...i})]})}),e.jsx(j,{control:u.control,name:"commission_balance",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.commission_balance")}),e.jsx(b,{children:e.jsxs("div",{className:"flex",children:[e.jsx(D,{type:"number",value:i.value||"",onChange:i.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(R,{...i})]})}),e.jsx(j,{control:u.control,name:"u",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.upload")}),e.jsx(b,{children:e.jsxs("div",{className:"flex",children:[e.jsx(D,{type:"number",step:"any",value:i.value??"",onChange:c=>i.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(R,{...i})]})}),e.jsx(j,{control:u.control,name:"d",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.download")}),e.jsx(b,{children:e.jsxs("div",{className:"flex",children:[e.jsx(D,{type:"number",step:"any",value:i.value??"",onChange:c=>i.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(R,{...i})]})})]}),e.jsx(j,{control:u.control,name:"transfer_enable",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.total_traffic")}),e.jsx(b,{children:e.jsxs("div",{className:"flex",children:[e.jsx(D,{type:"number",value:i.value/1024/1024/1024||"",onChange:c=>i.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(R,{})]})}),e.jsx(j,{control:u.control,name:"expired_at",render:({field:i})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(v,{children:s("edit.form.expire_time")}),e.jsxs(Ze,{open:o,onOpenChange:l,children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{children:e.jsxs(L,{type:"button",variant:"outline",className:_("w-full pl-3 text-left font-normal",!i.value&&"text-muted-foreground"),onClick:()=>l(!0),children:[i.value?ie(i.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(Ge,{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(L,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{i.onChange(null),l(!1)},children:s("edit.form.expire_time_permanent")}),e.jsx(L,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const c=new Date;c.setMonth(c.getMonth()+1),c.setHours(23,59,59,999),i.onChange(Math.floor(c.getTime()/1e3)),l(!1)},children:s("edit.form.expire_time_1month")}),e.jsx(L,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const c=new Date;c.setMonth(c.getMonth()+3),c.setHours(23,59,59,999),i.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:i.value?new Date(i.value*1e3):void 0,onSelect:c=>{if(c){const p=new Date(i.value?i.value*1e3:Date.now());c.setHours(p.getHours(),p.getMinutes(),p.getSeconds()),i.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(L,{type:"button",variant:"ghost",size:"sm",onClick:()=>{const c=new Date;c.setHours(23,59,59,999),i.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(D,{type:"datetime-local",step:"1",value:ie(i.value,"YYYY-MM-DDTHH:mm:ss"),onChange:c=>{const p=new Date(c.target.value);isNaN(p.getTime())||i.onChange(Math.floor(p.getTime()/1e3))},className:"flex-1"}),e.jsx(L,{type:"button",variant:"outline",onClick:()=>l(!1),children:s("edit.form.expire_time_confirm")})]})]})]})})]}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"plan_id",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.subscription")}),e.jsx(b,{children:e.jsxs(X,{value:i.value!==null?String(i.value):"null",onValueChange:c=>i.onChange(c==="null"?null:parseInt(c)),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:s("edit.form.subscription_none")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"null",children:s("edit.form.subscription_none")}),d.map(c=>e.jsx(q,{value:String(c.id),children:c.name},c.id))]})]})})]})}),e.jsx(j,{control:u.control,name:"banned",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.account_status")}),e.jsx(b,{children:e.jsxs(X,{value:i.value.toString(),onValueChange:c=>i.onChange(c==="true"),children:[e.jsx(J,{children:e.jsx(Z,{})}),e.jsxs(Q,{children:[e.jsx(q,{value:"true",children:s("columns.status_text.banned")}),e.jsx(q,{value:"false",children:s("columns.status_text.normal")})]})]})})]})}),e.jsx(j,{control:u.control,name:"commission_type",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.commission_type")}),e.jsx(b,{children:e.jsxs(X,{value:i.value.toString(),onValueChange:c=>i.onChange(parseInt(c)),children:[e.jsx(J,{children:e.jsx(Z,{placeholder:s("edit.form.subscription_none")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"0",children:s("edit.form.commission_type_system")}),e.jsx(q,{value:"1",children:s("edit.form.commission_type_cycle")}),e.jsx(q,{value:"2",children:s("edit.form.commission_type_onetime")})]})]})})]})}),e.jsx(j,{control:u.control,name:"commission_rate",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.commission_rate")}),e.jsx(b,{children:e.jsxs("div",{className:"flex",children:[e.jsx(D,{type:"number",value:i.value||"",onChange:c=>i.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(j,{control:u.control,name:"discount",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.discount")}),e.jsx(b,{children:e.jsxs("div",{className:"flex",children:[e.jsx(D,{type:"number",value:i.value||"",onChange:c=>i.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(R,{})]})}),e.jsx(j,{control:u.control,name:"speed_limit",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.speed_limit")}),e.jsx(b,{children:e.jsxs("div",{className:"flex",children:[e.jsx(D,{type:"number",value:i.value||"",onChange:c=>i.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(R,{})]})}),e.jsx(j,{control:u.control,name:"device_limit",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.device_limit")}),e.jsx(b,{children:e.jsxs("div",{className:"flex",children:[e.jsx(D,{type:"number",value:i.value||"",onChange:c=>i.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(R,{})]})}),e.jsx(j,{control:u.control,name:"is_admin",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.is_admin")}),e.jsx("div",{className:"py-2",children:e.jsx(b,{children:e.jsx(ee,{checked:i.value,onCheckedChange:c=>i.onChange(c)})})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"is_staff",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.is_staff")}),e.jsx("div",{className:"py-2",children:e.jsx(b,{children:e.jsx(ee,{checked:i.value,onCheckedChange:c=>i.onChange(c)})})})]})}),e.jsx(j,{control:u.control,name:"remarks",render:({field:i})=>e.jsxs(f,{children:[e.jsx(v,{children:s("edit.form.remarks")}),e.jsx(b,{children:e.jsx(Rs,{className:"h-24",value:i.value||"",onChange:c=>i.onChange(c.currentTarget.value??null),placeholder:s("edit.form.remarks_placeholder")})}),e.jsx(R,{})]})}),e.jsxs(Ri,{children:[e.jsx(L,{variant:"outline",onClick:()=>t(!1),children:s("edit.form.cancel")}),e.jsx(L,{type:"submit",onClick:()=>{u.handleSubmit(i=>{const c={id:i.id};u.formState.dirtyFields.u&&(c.u=Math.round(parseFloat(i.u)*1024*1024*1024)),u.formState.dirtyFields.d&&(c.d=Math.round(parseFloat(i.d)*1024*1024*1024)),Object.keys(i).forEach(p=>{p!=="u"&&p!=="d"&&p!=="id"&&u.formState.dirtyFields[p]&&(c[p]=i[p])}),qs.update(c).then(({data:p})=>{p&&($.success(s("edit.form.success")),t(!1),a())})})()},children:s("edit.form.submit")})]})]})]})})}function Rg(){const[s]=Il(),[n,t]=m.useState({}),[r,a]=m.useState({is_admin:!1,is_staff:!1}),[o,l]=m.useState([]),[d,x]=m.useState([]),[u,i]=m.useState({pageIndex:0,pageSize:20});m.useEffect(()=>{const N=s.get("email");N&&l(S=>S.some(E=>E.id==="email")?S:[...S,{id:"email",value:N}])},[s]);const{refetch:c,data:p,isLoading:P}=ne({queryKey:["userList",u,o,d],queryFn:()=>qs.getList({pageSize:u.pageSize,current:u.pageIndex+1,filter:o,sort:d})}),[T,C]=m.useState([]),[F,w]=m.useState([]);m.useEffect(()=>{yt.getList().then(({data:N})=>{C(N)}),ys.getList().then(({data:N})=>{w(N)})},[]);const V=T.map(N=>({label:N.name,value:N.id})),y=F.map(N=>({label:N.name,value:N.id}));return e.jsxs(Oi,{refreshData:c,children:[e.jsx(Eg,{data:p?.data??[],rowCount:p?.total??0,sorting:d,setSorting:x,columnVisibility:r,setColumnVisibility:a,rowSelection:n,setRowSelection:t,columnFilters:o,setColumnFilters:l,pagination:u,setPagination:i,refetch:c,serverGroupList:T,permissionGroups:V,subscriptionPlans:y,isLoading:P}),e.jsx(zi,{})]})}function Eg({data:s,rowCount:n,sorting:t,setSorting:r,columnVisibility:a,setColumnVisibility:o,rowSelection:l,setRowSelection:d,columnFilters:x,setColumnFilters:u,pagination:i,setPagination:c,refetch:p,serverGroupList:P,permissionGroups:T,subscriptionPlans:C,isLoading:F}){const{setIsOpen:w,setEditingUser:V}=Yn(),y=We({data:s,columns:Pg(p,P,V,w),state:{sorting:t,columnVisibility:a,rowSelection:l,columnFilters:x,pagination:i},rowCount:n,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:d,onSortingChange:r,onColumnFiltersChange:u,onColumnVisibilityChange:o,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),onPaginationChange:c,getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),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(vg,{table:y,refetch:p,serverGroupList:P,permissionGroups:T,subscriptionPlans:C}),e.jsx(ns,{table:y,isLoading:F})]})}function Vg(){const{t:s}=O("user");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(Rg,{})})})]})]})}const Ig=Object.freeze(Object.defineProperty({__proto__:null,default:Vg},Symbol.toStringTag,{value:"Module"})),Mg=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 Og({table:s}){const{t:n}=O("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(bt,{defaultValue:s.getColumn("status")?.getFilterValue(),onValueChange:t=>s.getColumn("status")?.setFilterValue(t),children:e.jsxs(rt,{className:"grid w-full grid-cols-2",children:[e.jsx(Be,{value:"0",children:n("status.pending")}),e.jsx(Be,{value:"1",children:n("status.closed")})]})}),s.getColumn("level")&&e.jsx(Va,{column:s.getColumn("level"),title:n("columns.level"),options:[{label:n("level.low"),value:ds.LOW,icon:Mg,color:"gray"},{label:n("level.medium"),value:ds.MIDDLE,icon:Ei,color:"yellow"},{label:n("level.high"),value:ds.HIGH,icon:Vi,color:"red"}]})]})})}function zg(){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 $g=jt("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=m.forwardRef(({className:s,variant:n,layout:t,children:r,...a},o)=>e.jsx("div",{className:_($g({variant:n,layout:t,className:s}),"relative group"),ref:o,...a,children:m.Children.map(r,l=>m.isValidElement(l)&&typeof l.type!="string"?m.cloneElement(l,{variant:n,layout:t}):l)}));$i.displayName="ChatBubble";const Ag=jt("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=m.forwardRef(({className:s,variant:n,layout:t,isLoading:r=!1,children:a,...o},l)=>e.jsx("div",{className:_(Ag({variant:n,layout:t,className:s}),"break-words max-w-full whitespace-pre-wrap"),ref:l,...o,children:r?e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(zg,{})}):a}));Ai.displayName="ChatBubbleMessage";const qg=m.forwardRef(({variant:s,className:n,children:t,...r},a)=>e.jsx("div",{ref:a,className:_("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}));qg.displayName="ChatBubbleActionWrapper";const qi=m.forwardRef(({className:s,...n},t)=>e.jsx(Rs,{autoComplete:"off",ref:t,name:"message",className:_("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 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:"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"})}),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:"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"})}),Tr=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"m11.29 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"})}),Ug=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"})}),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:"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"})}),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:"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 Bg(){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(je,{className:"h-8 w-3/4"}),e.jsx(je,{className:"h-4 w-1/2"})]}),e.jsx("div",{className:"flex-1 space-y-4",children:[1,2,3].map(s=>e.jsx(je,{className:"h-20 w-2/3"},s))})]})}function Gg(){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(je,{className:"h-5 w-4/5"}),e.jsx(je,{className:"h-4 w-2/3"}),e.jsx(je,{className:"h-3 w-1/2"})]},s))})}function Wg({ticket:s,isActive:n,onClick:t}){const{t:r}=O("ticket"),a=o=>{switch(o){case ds.HIGH:return"bg-red-50 text-red-600 border-red-200";case ds.MIDDLE:return"bg-yellow-50 text-yellow-600 border-yellow-200";case ds.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:_("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(K,{variant:s.status===et.CLOSED?"secondary":"default",className:"shrink-0",children:s.status===et.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:ie(s.updated_at)}),e.jsx("div",{className:_("rounded-full border px-2 py-0.5 text-xs font-medium",a(s.level)),children:r(`level.${s.level===ds.LOW?"low":s.level===ds.MIDDLE?"medium":"high"}`)})]})]})}function Yg({ticketId:s,dialogTrigger:n}){const{t}=O("ticket"),r=Bs(),a=m.useRef(null),o=m.useRef(null),[l,d]=m.useState(!1),[x,u]=m.useState(""),[i,c]=m.useState(!1),[p,P]=m.useState(s),[T,C]=m.useState(""),[F,w]=m.useState(!1),{setIsOpen:V,setEditingUser:y}=Yn(),{data:N,isLoading:S,refetch:M}=ne({queryKey:["tickets",l],queryFn:()=>l?Ft.getList({filter:[{id:"status",value:[et.OPENING]}]}):Promise.resolve(null),enabled:l}),{data:E,refetch:g,isLoading:k}=ne({queryKey:["ticket",p,l],queryFn:()=>l?Ft.getInfo(p):Promise.resolve(null),refetchInterval:l?5e3:!1,retry:3}),W=E?.data,ae=(N?.data||[]).filter(re=>re.subject.toLowerCase().includes(T.toLowerCase())||re.user?.email.toLowerCase().includes(T.toLowerCase())),B=(re="smooth")=>{if(a.current){const{scrollHeight:ks,clientHeight:_s}=a.current;a.current.scrollTo({top:ks-_s,behavior:re})}};m.useEffect(()=>{if(!l)return;const re=requestAnimationFrame(()=>{B("instant"),setTimeout(()=>B(),1e3)});return()=>{cancelAnimationFrame(re)}},[l,W?.messages]);const se=async()=>{const re=x.trim();!re||i||(c(!0),Ft.reply({id:p,message:re}).then(()=>{u(""),g(),B(),setTimeout(()=>{o.current?.focus()},0)}).finally(()=>{c(!1)}))},fe=async()=>{Ft.close(p).then(()=>{$.success(t("actions.close_success")),g(),M()})},cs=()=>{W?.user&&r("/finance/order?user_id="+W.user.id)},Me=W?.status===et.CLOSED;return e.jsxs(de,{open:l,onOpenChange:d,children:[e.jsx(fs,{asChild:!0,children:n??e.jsx(G,{variant:"outline",children:t("actions.view_ticket")})}),e.jsxs(oe,{className:"flex h-[90vh] max-w-6xl flex-col gap-0 p-0",children:[e.jsx(me,{}),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(!F),children:e.jsx(Tr,{className:_("h-4 w-4 transition-transform",!F&&"rotate-180")})}),e.jsxs("div",{className:_("absolute inset-y-0 left-0 z-40 flex flex-col border-r bg-background transition-transform duration-200 ease-in-out md:relative",F?"-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(!F),children:e.jsx(Tr,{className:_("h-4 w-4 transition-transform",!F&&"rotate-180")})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Ug,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 transform text-muted-foreground"}),e.jsx(D,{placeholder:t("list.search_placeholder"),value:T,onChange:re=>C(re.target.value),className:"pl-8"})]})]}),e.jsx(ft,{className:"flex-1",children:e.jsx("div",{className:"w-full",children:S?e.jsx(Gg,{}):ae.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-4 text-muted-foreground",children:t(T?"list.no_search_results":"list.no_tickets")}):ae.map(re=>e.jsx(Wg,{ticket:re,isActive:re.id===p,onClick:()=>{P(re.id),window.innerWidth<768&&w(!0)}},re.id))})})]}),e.jsxs("div",{className:"relative flex flex-1 flex-col",children:[!F&&e.jsx("div",{className:"absolute inset-0 z-30 bg-black/20 md:hidden",onClick:()=>w(!0)}),k?e.jsx(Bg,{}):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:W?.subject}),e.jsx(K,{variant:Me?"secondary":"default",children:t(Me?"status.closed":"status.processing")}),!Me&&e.jsx(us,{title:t("actions.close_confirm_title"),description:t("actions.close_confirm_description"),confirmText:t("actions.close_confirm_button"),variant:"destructive",onConfirm:fe,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"gap-1 text-muted-foreground hover:text-destructive",children:[e.jsx(Ui,{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(Ea,{className:"h-4 w-4"}),e.jsx("span",{children:W?.user?.email})]}),e.jsx(Re,{orientation:"vertical",className:"h-4"}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Hi,{className:"h-4 w-4"}),e.jsxs("span",{children:[t("detail.created_at")," ",ie(W?.created_at)]})]}),e.jsx(Re,{orientation:"vertical",className:"h-4"}),e.jsx(K,{variant:"outline",children:W?.level!=null&&t(`level.${W.level===ds.LOW?"low":W.level===ds.MIDDLE?"medium":"high"}`)})]})]}),W?.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:()=>{y(W.user),V(!0)},children:e.jsx(Ea,{className:"h-4 w-4"})}),e.jsx(Ii,{user_id:W.user.id,dialogTrigger:e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.traffic_records"),children:e.jsx(Hg,{className:"h-4 w-4"})})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.order_records"),onClick:cs,children:e.jsx(Kg,{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:W?.messages?.length===0?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:t("detail.no_messages")}):W?.messages?.map(re=>e.jsx($i,{variant:re.is_from_admin?"sent":"received",className:re.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:re.message}),e.jsx("div",{className:"text-right",children:e.jsx("time",{className:"text-[10px] text-muted-foreground",children:ie(re.created_at)})})]})})},re.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:o,disabled:Me||i,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:re=>u(re.target.value),onKeyDown:re=>{re.key==="Enter"&&!re.shiftKey&&(re.preventDefault(),se())}}),e.jsx(G,{disabled:Me||i||!x.trim(),onClick:se,children:t(i?"detail.input.sending":"detail.input.send")})]})})]})]})]})]})]})}const 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:"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"})}),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:"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"})}),Xg=s=>{const{t:n}=O("ticket");return[{accessorKey:"id",header:({column:t})=>e.jsx(z,{column:t,title:n("columns.id")}),cell:({row:t})=>e.jsx(K,{variant:"outline",children:t.getValue("id")}),enableSorting:!1,enableHiding:!1},{accessorKey:"subject",header:({column:t})=>e.jsx(z,{column:t,title:n("columns.subject")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Jg,{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(z,{column:t,title:n("columns.level")}),cell:({row:t})=>{const r=t.getValue("level"),a=r===ds.LOW?"default":r===ds.MIDDLE?"secondary":"destructive";return e.jsx(K,{variant:a,className:"whitespace-nowrap",children:n(`level.${r===ds.LOW?"low":r===ds.MIDDLE?"medium":"high"}`)})},filterFn:(t,r,a)=>a.includes(t.getValue(r))},{accessorKey:"status",header:({column:t})=>e.jsx(z,{column:t,title:n("columns.status")}),cell:({row:t})=>{const r=t.getValue("status"),a=t.original.reply_status,o=r===et.CLOSED?n("status.closed"):n(a===0?"status.replied":"status.pending"),l=r===et.CLOSED?"default":a===0?"secondary":"destructive";return e.jsx(K,{variant:l,className:"whitespace-nowrap",children:o})}},{accessorKey:"updated_at",header:({column:t})=>e.jsx(z,{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(Hi,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:ie(t.getValue("updated_at"))})]}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx(z,{column:t,title:n("columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:ie(t.getValue("created_at"))}),enableSorting:!0,meta:{isFlexGrow:!0}},{id:"actions",header:({column:t})=>e.jsx(z,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>{const r=t.original.status!==et.CLOSED;return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Yg,{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(Qg,{className:"h-4 w-4"})})}),r&&e.jsx(us,{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(()=>{$.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(Ui,{className:"h-4 w-4"})})})]})}}]};function Zg(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,o]=m.useState([{id:"status",value:"0"}]),[l,d]=m.useState([]),[x,u]=m.useState({pageIndex:0,pageSize:20}),{refetch:i,data:c}=ne({queryKey:["orderList",x,a,l],queryFn:()=>Ft.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:a,sort:l})}),p=We({data:c?.data??[],columns:Xg(i),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:o,onColumnVisibilityChange:r,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),onPaginationChange:u,getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnPinning:{right:["actions"]}}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Og,{table:p,refetch:i}),e.jsx(ns,{table:p,showPagination:!0})]})}function ep(){const{t:s}=O("ticket");return e.jsxs(Oi,{refreshData:()=>{},children:[e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(os,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(Zg,{})})]})]}),e.jsx(zi,{})]})}const sp=Object.freeze(Object.defineProperty({__proto__:null,default:ep},Symbol.toStringTag,{value:"Module"}));function tp({table:s,refetch:n}){const{t}=O("user"),r=s.getState().columnFilters.length>0,[a,o]=m.useState(),[l,d]=m.useState(),[x,u]=m.useState(!1),i=[{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")}],p=()=>{let F=s.getState().columnFilters.filter(w=>w.id!=="date_range");(a||l)&&F.push({id:"date_range",value:{start:a?Pe(a,"yyyy-MM-dd"):null,end:l?Pe(l,"yyyy-MM-dd"):null}}),s.setColumnFilters(F)},P=async()=>{try{u(!0);const F=s.getState().columnFilters.reduce((g,k)=>{if(k.value)if(k.id==="date_range"){const W=k.value;W.start&&(g.start_date=W.start),W.end&&(g.end_date=W.end)}else g[k.id]=k.value;return g},{}),V=(await na.getLogs({...F,page:1,per_page:1e4})).data.map(g=>({ID:g.id,用户邮箱:g.user_email,用户ID:g.user_id,重置类型:g.reset_type_name,触发源:g.trigger_source_name,清零流量:g.old_traffic.formatted,"上传流量(GB)":(g.old_traffic.upload/1024**3).toFixed(2),"下载流量(GB)":(g.old_traffic.download/1024**3).toFixed(2),重置时间:Pe(new Date(g.reset_time),"yyyy-MM-dd HH:mm:ss"),记录时间:Pe(new Date(g.created_at),"yyyy-MM-dd HH:mm:ss"),原因:g.reason||""})),y=Object.keys(V[0]||{}),N=[y.join(","),...V.map(g=>y.map(k=>{const W=g[k];return typeof W=="string"&&W.includes(",")?`"${W}"`:W}).join(","))].join(`
|
||
`),S=new Blob([N],{type:"text/csv;charset=utf-8;"}),M=document.createElement("a"),E=URL.createObjectURL(S);M.setAttribute("href",E),M.setAttribute("download",`traffic-reset-logs-${Pe(new Date,"yyyy-MM-dd")}.csv`),M.style.visibility="hidden",document.body.appendChild(M),M.click(),document.body.removeChild(M),$.success(t("traffic_reset_logs.actions.export_success"))}catch(C){console.error("导出失败:",C),$.error(t("traffic_reset_logs.actions.export_failed"))}finally{u(!1)}},T=()=>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(D,{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(X,{value:s.getColumn("reset_type")?.getFilterValue()??"",onValueChange:C=>s.getColumn("reset_type")?.setFilterValue(C==="all"?"":C),children:[e.jsx(J,{className:"h-9",children:e.jsx(Z,{placeholder:t("traffic_reset_logs.filters.reset_type")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"all",children:t("traffic_reset_logs.filters.all_types")}),i.map(C=>e.jsx(q,{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(X,{value:s.getColumn("trigger_source")?.getFilterValue()??"",onValueChange:C=>s.getColumn("trigger_source")?.setFilterValue(C==="all"?"":C),children:[e.jsx(J,{className:"h-9",children:e.jsx(Z,{placeholder:t("traffic_reset_logs.filters.trigger_source")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"all",children:t("traffic_reset_logs.filters.all_sources")}),c.map(C=>e.jsx(q,{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(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(L,{variant:"outline",className:_("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?Pe(a,"MM-dd"):t("traffic_reset_logs.filters.start_date")]})}),e.jsx(Ge,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:a,onSelect:o,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(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(L,{variant:"outline",className:_("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?Pe(l,"MM-dd"):t("traffic_reset_logs.filters.end_date")]})}),e.jsx(Ge,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:l,onSelect:d,initialFocus:!0})})]})]})]}),(a||l)&&e.jsxs(L,{variant:"outline",className:"w-full",onClick:p,children:[e.jsx(dr,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.apply_date")]}),r&&e.jsxs(L,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),o(void 0),d(void 0)},className:"w-full",children:[t("traffic_reset_logs.filters.reset"),e.jsx(is,{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(Wn,{children:[e.jsx(Pi,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8",children:[e.jsx(Fd,{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(sn,{side:"bottom",className:"h-[85vh]",children:[e.jsxs(tn,{className:"mb-4",children:[e.jsx(an,{children:t("traffic_reset_logs.filters.filter_title")}),e.jsx(nn,{children:t("traffic_reset_logs.filters.filter_description")})]}),e.jsx("div",{className:"max-h-[calc(85vh-120px)] overflow-y-auto",children:e.jsx(T,{})})]})]})}),e.jsxs(L,{variant:"outline",size:"sm",className:"h-8",onClick:P,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(D,{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(X,{value:s.getColumn("reset_type")?.getFilterValue()??"",onValueChange:C=>s.getColumn("reset_type")?.setFilterValue(C==="all"?"":C),children:[e.jsx(J,{className:"h-8 w-[180px]",children:e.jsx(Z,{placeholder:t("traffic_reset_logs.filters.reset_type")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"all",children:t("traffic_reset_logs.filters.all_types")}),i.map(C=>e.jsx(q,{value:C.value,children:C.label},C.value))]})]}),e.jsxs(X,{value:s.getColumn("trigger_source")?.getFilterValue()??"",onValueChange:C=>s.getColumn("trigger_source")?.setFilterValue(C==="all"?"":C),children:[e.jsx(J,{className:"h-8 w-[180px]",children:e.jsx(Z,{placeholder:t("traffic_reset_logs.filters.trigger_source")})}),e.jsxs(Q,{children:[e.jsx(q,{value:"all",children:t("traffic_reset_logs.filters.all_sources")}),c.map(C=>e.jsx(q,{value:C.value,children:C.label},C.value))]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:_("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?Pe(a,"yyyy-MM-dd"):t("traffic_reset_logs.filters.start_date")]})}),e.jsx(Ge,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:a,onSelect:o,initialFocus:!0})})]}),e.jsxs(Ze,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:_("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?Pe(l,"yyyy-MM-dd"):t("traffic_reset_logs.filters.end_date")]})}),e.jsx(Ge,{className:"w-auto p-0",align:"start",children:e.jsx(Ss,{mode:"single",selected:l,onSelect:d,initialFocus:!0})})]}),(a||l)&&e.jsxs(L,{variant:"outline",size:"sm",className:"h-8",onClick:p,children:[e.jsx(dr,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.apply_date")]})]}),r&&e.jsxs(L,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),o(void 0),d(void 0)},className:"h-8 px-2 lg:px-3",children:[t("traffic_reset_logs.filters.reset"),e.jsx(is,{className:"ml-2 h-4 w-4"})]})]}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",onClick:P,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 ap=()=>{const{t:s}=O("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(Ta,{className:"h-3 w-3"});case"cron":return e.jsx(Ld,{className:"h-3 w-3"});case"auto":return e.jsx(Pd,{className:"h-3 w-3"});default:return e.jsx(Ta,{className:"h-3 w-3"})}};return[{accessorKey:"id",header:({column:a})=>e.jsx(z,{column:a,title:s("traffic_reset_logs.columns.id"),className:"w-[60px]"}),cell:({row:a})=>e.jsx("div",{className:"w-[60px]",children:e.jsx(K,{variant:"outline",className:"text-xs",children:a.original.id})}),enableSorting:!0,enableHiding:!0,size:60},{accessorKey:"user_email",header:({column:a})=>e.jsx(z,{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(zl,{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(z,{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(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsx("div",{className:"cursor-pointer",children:e.jsxs(K,{variant:"outline",className:_("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(ce,{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,o,l)=>l.includes(a.getValue(o)),size:120},{accessorKey:"reset_type",header:({column:a})=>e.jsx(z,{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(K,{className:_("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,o,l)=>l.includes(a.getValue(o)),size:120},{accessorKey:"old_traffic",header:({column:a})=>e.jsx(z,{column:a,title:s("traffic_reset_logs.columns.cleared_traffic"),className:"w-[120px]"}),cell:({row:a})=>{const o=a.original.old_traffic;return e.jsx("div",{className:"w-[120px]",children:e.jsx(pe,{delayDuration:100,children:e.jsxs(ue,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs("div",{className:"cursor-pointer text-center",children:[e.jsx("div",{className:"text-sm font-medium text-destructive",children:o.formatted}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("traffic_reset_logs.columns.cleared")})]})}),e.jsxs(ce,{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"),":"," ",(o.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"),":"," ",(o.download/1024**3).toFixed(2)," GB"]})]})]})]})})})},enableSorting:!1,enableHiding:!1,size:120},{accessorKey:"reset_time",header:({column:a})=>e.jsx(z,{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:ie(a.original.reset_time,"MM-DD")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:ie(a.original.reset_time,"HH:mm")})]})]})}),enableSorting:!0,enableHiding:!0,size:140},{accessorKey:"created_at",header:({column:a})=>e.jsx(z,{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(zn,{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:ie(a.original.created_at,"YYYY-MM-DD")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:ie(a.original.created_at,"H:m:s")})]})]})}),enableSorting:!0,enableHiding:!1,size:1400}]};function np(){const[s,n]=m.useState({}),[t,r]=m.useState({reset_time:!1}),[a,o]=m.useState([]),[l,d]=m.useState([{id:"created_at",desc:!0}]),[x,u]=m.useState({pageIndex:0,pageSize:20}),i={page:x.pageIndex+1,per_page:x.pageSize,...a.reduce((T,C)=>{if(C.value)if(C.id==="date_range"){const F=C.value;F.start&&(T.start_date=F.start),F.end&&(T.end_date=F.end)}else T[C.id]=C.value;return T},{})},{refetch:c,data:p,isLoading:P}=ne({queryKey:["trafficResetLogs",x,a,l],queryFn:()=>na.getLogs(i)});return e.jsx(rp,{data:p?.data??[],rowCount:p?.total??0,sorting:l,setSorting:d,columnVisibility:t,setColumnVisibility:r,rowSelection:s,setRowSelection:n,columnFilters:a,setColumnFilters:o,pagination:x,setPagination:u,refetch:c,isLoading:P})}function rp({data:s,rowCount:n,sorting:t,setSorting:r,columnVisibility:a,setColumnVisibility:o,rowSelection:l,setRowSelection:d,columnFilters:x,setColumnFilters:u,pagination:i,setPagination:c,refetch:p,isLoading:P}){const T=We({data:s,columns:ap(),state:{sorting:t,columnVisibility:a,rowSelection:l,columnFilters:x,pagination:i},rowCount:n,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:d,onSortingChange:r,onColumnFiltersChange:u,onColumnVisibilityChange:o,getCoreRowModel:Ye(),getFilteredRowModel:gs(),getPaginationRowModel:ss(),onPaginationChange:c,getSortedRowModel:ps(),getFacetedRowModel:Ps(),getFacetedUniqueValues:Ls(),initialState:{columnVisibility:{reset_time:!1}}});return e.jsxs("div",{className:"h-full space-y-4",children:[e.jsx(tp,{table:T,refetch:p}),e.jsx(ns,{table:T,isLoading:P})]})}function lp(){const{t:s}=O("user");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsx(os,{})}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ts,{}),e.jsx(as,{})]})]}),e.jsxs(Je,{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(np,{})})})]})]})}const ip=Object.freeze(Object.defineProperty({__proto__:null,default:lp},Symbol.toStringTag,{value:"Module"}));export{_e as _,xp as a,mp as c,up as g,hp as r};
|