diff --git a/app/Http/Controllers/V1/User/StatController.php b/app/Http/Controllers/V1/User/StatController.php index f3bc707..4b3f128 100644 --- a/app/Http/Controllers/V1/User/StatController.php +++ b/app/Http/Controllers/V1/User/StatController.php @@ -19,7 +19,9 @@ class StatController extends Controller ->with(['server:id,name']) ->where('user_id', $userId) ->where('record_at', '>=', $startDate) - ->orderBy('record_at', 'DESC') + ->orderByDesc('updated_at') + ->orderByDesc('created_at') + ->orderByDesc('record_at') ->get(); $deviceMap = $this->buildNodeDeviceMap($userId); diff --git a/app/Http/Controllers/V2/Admin/StatController.php b/app/Http/Controllers/V2/Admin/StatController.php index cfe25f6..39732ce 100644 --- a/app/Http/Controllers/V2/Admin/StatController.php +++ b/app/Http/Controllers/V2/Admin/StatController.php @@ -239,7 +239,9 @@ class StatController extends Controller $userId = (int) $request->input('user_id'); $records = StatUser::query() ->with(['server:id,name']) - ->orderBy('record_at', 'DESC') + ->orderByDesc('updated_at') + ->orderByDesc('created_at') + ->orderByDesc('record_at') ->where('user_id', $userId) ->paginate($pageSize); diff --git a/app/Http/Resources/TrafficLogResource.php b/app/Http/Resources/TrafficLogResource.php index d5333fb..9f2effb 100644 --- a/app/Http/Resources/TrafficLogResource.php +++ b/app/Http/Resources/TrafficLogResource.php @@ -16,6 +16,7 @@ class TrafficLogResource extends JsonResource { $serverId = (int) data_get($this->resource, 'server_id', 0); $serverType = strtolower((string) data_get($this->resource, 'server_type', '')); + $displayAt = $this->resolveDisplayAt(); $serverName = data_get($this->resource, 'server_name') ?: data_get($this->resource, 'node_name') ?: data_get($this->resource, 'server.name'); @@ -39,6 +40,7 @@ class TrafficLogResource extends JsonResource 'd' => (int) data_get($this->resource, 'd', 0), 'u' => (int) data_get($this->resource, 'u', 0), 'record_at' => (int) data_get($this->resource, 'record_at', 0), + 'display_at' => $displayAt, 'record_type' => data_get($this->resource, 'record_type'), 'server_rate' => (float) data_get($this->resource, 'server_rate', 1), 'server_id' => $serverId > 0 ? $serverId : null, @@ -59,4 +61,27 @@ class TrafficLogResource extends JsonResource return $data; } + + private function resolveDisplayAt(): int + { + foreach (['updated_at', 'created_at'] as $field) { + $value = data_get($this->resource, $field); + if ($value instanceof \DateTimeInterface) { + return $value->getTimestamp(); + } + + if (is_numeric($value)) { + return (int) $value; + } + + if (is_string($value) && trim($value) !== '') { + $timestamp = strtotime($value); + if ($timestamp !== false) { + return $timestamp; + } + } + } + + return (int) data_get($this->resource, 'record_at', 0); + } } diff --git a/public/assets/admin/assets/index.js b/public/assets/admin/assets/index.js index c2411e7..823d430 100644 --- a/public/assets/admin/assets/index.js +++ b/public/assets/admin/assets/index.js @@ -1,4 +1,4 @@ -import{r as m,j as e,t as jo,c as vo,S as $n,I as da,a as St,u as et,b as bo,d as An,R as Al,e as ql,f as yo,F as _o,C as No,L as Ul,T as Hl,g as Kl,h as wo,i as Co,k as So,l as ko,m as A,n as Bl,o as Gl,p as le,s as T,q as M,v as De,w as Le,x as oe,y as Gs,z as ze,A as Wl,B as To,O as qn,D as Do,E as Fo,G as Po,H as Lo,J as Ro,K as Eo,Q as Vo,M as Io,N as Ma,P as Mo,U as Oo,V as zo,$ as $o,W as Ao,X as qo,Y as Yl,Z as Jl,_ as Ql,a0 as Ya,a1 as Un,a2 as xs,a3 as Ja,a4 as Qa,a5 as Xl,a6 as Xa,a7 as Uo,a8 as Ho,a9 as Ko,aa as Zl,ab as er,ac as sr,ad as tr,ae as Bo,af as ar,ag as nr,ah as kt,ai as lr,aj as rr,ak as ir,al as or,am as Go,an as Wo,ao as Yo,ap as Jo,aq as Qo,ar as Xo,as as Zo,at as ec,au as sc,av as tc,aw as cr,ax as dr,ay as Xs,az as ac,aA as mr,aB as Hn,aC as nc,aD as lc,aE as hl,aF as rc,aG as ic,aH as oc,aI as ur,aJ as cc,aK as xr,aL as dc,aM as mc,aN as uc,aO as xc,aP as hc,aQ as hr,aR as pc,aS as gc,aT as fc,aU as jc,aV as vc,aW as _s,aX as Kn,aY as bc,aZ as yc,a_ as pr,a$ as gr,b0 as fr,b1 as _c,b2 as Nc,b3 as wc,b4 as jr,b5 as Cc,b6 as Bn,b7 as Sc,b8 as vr,b9 as kc,ba as br,bb as Tc,bc as Dc,bd as yr,be as Fc,bf as _r,bg as Pc,bh as Nr,bi as wr,bj as Cr,bk as Lc,bl as Sr,bm as kr,bn as Tr,bo as Rc,bp as Ec,bq as Vc,br as Dr,bs as Ks,bt as Oe,bu as Ls,bv as Ic,bw as Mc,bx as Oc,by as zc,bz as $c,bA as Ac,bB as pl,bC as gl,bD as qc,bE as Uc,bF as Gn,bG as Hc,bH as Kc,bI as Oa,bJ as At,bK as ma,bL as Bc,bM as Fr,bN as Gc,bO as Wc,bP as Pr,bQ as Yc,bR as Jc,bS as fl,bT as Pn,bU as Ln,bV as Qc,bW as Xc,bX as Lr,bY as Zc,bZ as ed,b_ as sd,b$ as td,c0 as za,c1 as Rr,c2 as Rn,c3 as es,c4 as $a,c5 as ad,c6 as vn,c7 as nd,c8 as En,c9 as vs,ca as aa,cb as na,cc as Vn,cd as Er,ce as Vr,cf as is,cg as ss,ch as ld,ci as rd,cj as id,ck as od,cl as cd,cm as Ir,cn as dd,co as ce,cp as Y,cq as ie,cr as Qe,cs as md,ct as ud,cu as He,cv as Tt,cw as jl,cx as xd,cy as hd,cz as pd,cA as gd,cB as Mr,cC as Or,cD as zr,cE as $r,cF as Ar,cG as qr,cH as Za,cI as ut,cJ as Ns,cK as ws,cL as Ht,cM as fd,cN as jd,cO as vd,cP as Aa,cQ as bd,cR as yd,cS as In,cT as Wn,cU as Yn,cV as _d,cW as Os,cX as zs,cY as en,cZ as Nd,c_ as Kt,c$ as qa,d0 as wd,d1 as La,d2 as Cd,d3 as vl,d4 as Ur,d5 as _a,d6 as Ua,d7 as Sd,d8 as Jn,d9 as kd,da as Td,db as Dd,dc as fs,dd as Hr,de as Fd,df as Pd,dg as Kr,dh as Mn,di as Br,dj as Ld,dk as ua,dl as Gr,dm as Rd,dn as Ed,dp as Vd,dq as Id,dr as Wr,ds as Md,dt as Yr,du as la,dv as Qn,dw as Od,dx as bl,dy as Jr,dz as zd,dA as yl,dB as $d,dC as Ad}from"./vendor.js";import"./index.js";var _g=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ng(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function qd(s){if(s.__esModule)return s;var n=s.default;if(typeof n=="function"){var t=function l(){return this instanceof l?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(l){var a=Object.getOwnPropertyDescriptor(s,l);Object.defineProperty(t,l,a.get?a:{enumerable:!0,get:function(){return s[l]}})}),t}const Ud={theme:"system",setTheme:()=>null},Qr=m.createContext(Ud);function Hd({children:s,defaultTheme:n="system",storageKey:t="vite-ui-theme",...l}){const[a,i]=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 r={theme:a,setTheme:d=>{localStorage.setItem(t,d),i(d)}};return e.jsx(Qr.Provider,{...l,value:r,children:s})}const Kd=()=>{const s=m.useContext(Qr);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},Bd=function(){const n=typeof document<"u"&&document.createElement("link").relList;return n&&n.supports&&n.supports("modulepreload")?"modulepreload":"preload"}(),Gd=function(s,n){return new URL(s,n).href},_l={},Te=function(n,t,l){let a=Promise.resolve();if(t&&t.length>0){const r=document.getElementsByTagName("link"),d=document.querySelector("meta[property=csp-nonce]"),x=d?.nonce||d?.getAttribute("nonce");a=Promise.allSettled(t.map(u=>{if(u=Gd(u,l),u in _l)return;_l[u]=!0;const o=u.endsWith(".css"),c=o?'[rel="stylesheet"]':"";if(!!l)for(let S=r.length-1;S>=0;S--){const w=r[S];if(w.href===u&&(!o||w.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${c}`))return;const D=document.createElement("link");if(D.rel=o?"stylesheet":Bd,o||(D.as="script"),D.crossOrigin="",D.href=u,x&&D.setAttribute("nonce",x),document.head.appendChild(D),o)return new Promise((S,w)=>{D.addEventListener("load",S),D.addEventListener("error",()=>w(new Error(`Unable to preload CSS for ${u}`)))})}))}function i(r){const d=new Event("vite:preloadError",{cancelable:!0});if(d.payload=r,window.dispatchEvent(d),!d.defaultPrevented)throw r}return a.then(r=>{for(const d of r||[])d.status==="rejected"&&i(d.reason);return n().catch(i)})};function b(...s){return jo(vo(s))}const Bt=St("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"}}),P=m.forwardRef(({className:s,variant:n,size:t,asChild:l=!1,children:a,disabled:i,loading:r=!1,leftSection:d,rightSection:x,...u},o)=>{const c=l?$n:"button";return e.jsxs(c,{className:b(Bt({variant:n,size:t,className:s})),disabled:r||i,ref:o,...u,children:[(d&&r||!d&&!x&&r)&&e.jsx(da,{className:"mr-2 h-4 w-4 animate-spin"}),!r&&d&&e.jsx("div",{className:"mr-2",children:d}),a,!r&&x&&e.jsx("div",{className:"ml-2",children:x}),x&&r&&e.jsx(da,{className:"ml-2 h-4 w-4 animate-spin"})]})});P.displayName="Button";function Lt({className:s,minimal:n=!1}){const t=et(),l=bo(),a=l?.message||l?.statusText||"Unknown error occurred";return e.jsx("div",{className:b("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(P,{variant:"outline",onClick:()=>t(-1),children:"Go Back"}),e.jsx(P,{onClick:()=>t("/"),children:"Back to Home"})]})]})})}function Nl(){const s=et();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(P,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(P,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function Wd(){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(P,{variant:"outline",children:"Learn more"})})]})})}function Yd(s){return typeof s>"u"}function Jd(s){return s===null}function Qd(s){return Jd(s)||Yd(s)}class Xd{storage;prefixKey;constructor(n){this.storage=n.storage,this.prefixKey=n.prefixKey}getKey(n){return`${this.prefixKey}${n}`.toUpperCase()}set(n,t,l=null){const a=JSON.stringify({value:t,time:Date.now(),expire:l!==null?new Date().getTime()+l*1e3:null});this.storage.setItem(this.getKey(n),a)}get(n,t=null){const l=this.storage.getItem(this.getKey(n));if(!l)return{value:t,time:0};try{const a=JSON.parse(l),{value:i,time:r,expire:d}=a;return Qd(d)||d>new Date().getTime()?{value:i,time:r}:(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 Xr({prefixKey:s="",storage:n=sessionStorage}){return new Xd({prefixKey:s,storage:n})}const Zr="Xboard_",Zd=function(s={}){return Xr({prefixKey:s.prefixKey||"",storage:localStorage})},em=function(s={}){return Xr({prefixKey:s.prefixKey||"",storage:sessionStorage})},Xn=Zd({prefixKey:Zr});em({prefixKey:Zr});const ei="access_token";function xa(){return Xn.get(ei)}function si(){Xn.remove(ei)}const wl=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function sm({children:s}){const n=et(),t=An(),l=xa();return m.useEffect(()=>{if(!l.value&&!wl.includes(t.pathname)){const a=encodeURIComponent(t.pathname+t.search);n(`/sign-in?redirect=${a}`)}},[l.value,t.pathname,t.search,n]),wl.includes(t.pathname)||l.value?e.jsx(e.Fragment,{children:s}):null}const Me=m.forwardRef(({className:s,orientation:n="horizontal",decorative:t=!0,...l},a)=>e.jsx(Al,{ref:a,decorative:t,orientation:n,className:b("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...l}));Me.displayName=Al.displayName;const tm=St("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),as=m.forwardRef(({className:s,...n},t)=>e.jsx(ql,{ref:t,className:b(tm(),s),...n}));as.displayName=ql.displayName;const Re=_o,ti=m.createContext({}),g=({...s})=>e.jsx(ti.Provider,{value:{name:s.name},children:e.jsx(No,{...s})}),sn=()=>{const s=m.useContext(ti),n=m.useContext(ai),{getFieldState:t,formState:l}=yo(),a=t(s.name,l);if(!s)throw new Error("useFormField should be used within ");const{id:i}=n;return{id:i,name:s.name,formItemId:`${i}-form-item`,formDescriptionId:`${i}-form-item-description`,formMessageId:`${i}-form-item-message`,...a}},ai=m.createContext({}),p=m.forwardRef(({className:s,...n},t)=>{const l=m.useId();return e.jsx(ai.Provider,{value:{id:l},children:e.jsx("div",{ref:t,className:b("space-y-2",s),...n})})});p.displayName="FormItem";const f=m.forwardRef(({className:s,...n},t)=>{const{error:l,formItemId:a}=sn();return e.jsx(as,{ref:t,className:b(l&&"text-destructive",s),htmlFor:a,...n})});f.displayName="FormLabel";const j=m.forwardRef(({...s},n)=>{const{error:t,formItemId:l,formDescriptionId:a,formMessageId:i}=sn();return e.jsx($n,{ref:n,id:l,"aria-describedby":t?`${a} ${i}`:`${a}`,"aria-invalid":!!t,...s})});j.displayName="FormControl";const q=m.forwardRef(({className:s,...n},t)=>{const{formDescriptionId:l}=sn();return e.jsx("p",{ref:t,id:l,className:b("text-[0.8rem] text-muted-foreground",s),...n})});q.displayName="FormDescription";const E=m.forwardRef(({className:s,children:n,...t},l)=>{const{error:a,formMessageId:i}=sn(),r=a?String(a?.message):n;return r?e.jsx("p",{ref:l,id:i,className:b("text-[0.8rem] font-medium text-destructive",s),...t,children:r}):null});E.displayName="FormMessage";const Dt=wo,xt=m.forwardRef(({className:s,...n},t)=>e.jsx(Ul,{ref:t,className:b("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...n}));xt.displayName=Ul.displayName;const Xe=m.forwardRef(({className:s,...n},t)=>e.jsx(Hl,{ref:t,className:b("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}));Xe.displayName=Hl.displayName;const ks=m.forwardRef(({className:s,...n},t)=>e.jsx(Kl,{ref:t,className:b("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...n}));ks.displayName=Kl.displayName;function re(s=void 0,n="YYYY-MM-DD HH:mm:ss"){return s==null?"":(Math.floor(s).toString().length===10&&(s=s*1e3),So(s).format(n))}function am(s=void 0,n="YYYY-MM-DD"){return re(s,n)}function Cl(s){const n=typeof s=="string"?parseFloat(s):s;return isNaN(n)?"0.00":n.toFixed(2)}function Qs(s,n=!0){if(s==null)return n?"¥0.00":"0.00";const t=typeof s=="string"?parseFloat(s):s;if(isNaN(t))return n?"¥0.00":"0.00";const a=(t/100).toFixed(2).replace(/\.?0+$/,i=>i.includes(".")?".00":i);return n?`¥${a}`:a}function lt(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 l=new Co(t);l.on("success",()=>{l.destroy(),document.body.removeChild(t),n(!0)}),l.on("error",a=>{console.error("Clipboard.js failed:",a),l.destroy(),document.body.removeChild(t),n(!1)}),t.click()}catch(t){console.error("copyToClipboard failed:",t),n(!1)}})}function Ie(s){if(s==null||s<=0)return"0 B";const n=1024,t=["B","KB","MB","GB","TB"];let l=Math.floor(Math.log(s)/Math.log(n));return l<0?l=0:l>=t.length&&(l=t.length-1),`${parseFloat((s/Math.pow(n,l)).toFixed(2))} ${t[l]}`}const Sl="i18nextLng";function nm(){return console.log(localStorage.getItem(Sl)),localStorage.getItem(Sl)}function ni(){si();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 lm=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function rm(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const Ot=ko.create({baseURL:rm(),timeout:12e3,headers:{"Content-Type":"application/json"}});Ot.interceptors.request.use(s=>{s.method?.toLowerCase()==="get"&&(s.params={...s.params,t:Date.now()});const n=xa();if(!lm.includes(s.url?.split("?")[0]||"")){if(!n.value)return ni(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=n.value}return s.headers["Content-Language"]=nm()||"zh-CN",s},s=>Promise.reject(s));Ot.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)&&ni(),A.error(t||{401:"登录已过期",403:"没有权限",404:"资源或接口不存在"}[n]||"未知异常"),Promise.reject(s.response?.data||{data:null,code:-1,message:"未知错误"})});const O={get:(s,n)=>Ot.get(s,n),post:(s,n,t)=>Ot.post(s,n,t),put:(s,n,t)=>Ot.put(s,n,t),delete:(s,n)=>Ot.delete(s,n)},im="access_token";function om(s){Xn.set(im,s)}const bt=window?.settings?.secure_path,Ha={getStats:()=>O.get(bt+"/monitor/api/stats"),getOverride:()=>O.get(bt+"/stat/getOverride"),getOrderStat:s=>O.get(bt+"/stat/getOrder",{params:s}),getStatsData:()=>O.get(bt+"/stat/getStats"),getNodeTrafficData:s=>O.get(bt+"/stat/getTrafficRank",{params:s}),getServerLastRank:()=>O.get(bt+"/stat/getServerLastRank"),getServerYesterdayRank:()=>O.get(bt+"/stat/getServerYesterdayRank")},Wt=window?.settings?.secure_path,ra={getList:()=>O.get(Wt+"/theme/getThemes"),getConfig:s=>O.post(Wt+"/theme/getThemeConfig",{name:s}),updateConfig:(s,n)=>O.post(Wt+"/theme/saveThemeConfig",{name:s,config:n}),upload:s=>{const n=new FormData;return n.append("file",s),O.post(Wt+"/theme/upload",n,{headers:{"Content-Type":"multipart/form-data"}})},drop:s=>O.post(Wt+"/theme/delete",{name:s})},Rt=window?.settings?.secure_path,Nt={getList:()=>O.get(Rt+"/server/manage/getNodes"),save:s=>O.post(Rt+"/server/manage/save",s),drop:s=>O.post(Rt+"/server/manage/drop",s),copy:s=>O.post(Rt+"/server/manage/copy",s),update:s=>O.post(Rt+"/server/manage/update",s),sort:s=>O.post(Rt+"/server/manage/sort",s)},bn=window?.settings?.secure_path,Ft={getList:()=>O.get(bn+"/server/group/fetch"),save:s=>O.post(bn+"/server/group/save",s),drop:s=>O.post(bn+"/server/group/drop",s)},yn=window?.settings?.secure_path,tn={getList:()=>O.get(yn+"/server/route/fetch"),save:s=>O.post(yn+"/server/route/save",s),drop:s=>O.post(yn+"/server/route/drop",s)},yt=window?.settings?.secure_path,wt={getList:()=>O.get(yt+"/payment/fetch"),getMethodList:()=>O.get(yt+"/payment/getPaymentMethods"),getMethodForm:s=>O.post(yt+"/payment/getPaymentForm",s),save:s=>O.post(yt+"/payment/save",s),drop:s=>O.post(yt+"/payment/drop",s),updateStatus:s=>O.post(yt+"/payment/show",s),sort:s=>O.post(yt+"/payment/sort",s)},Yt=window?.settings?.secure_path,ha={getList:()=>O.get(`${Yt}/notice/fetch`),save:s=>O.post(`${Yt}/notice/save`,s),drop:s=>O.post(`${Yt}/notice/drop`,{id:s}),updateStatus:s=>O.post(`${Yt}/notice/show`,{id:s}),sort:s=>O.post(`${Yt}/notice/sort`,{ids:s})},Et=window?.settings?.secure_path,qt={getList:()=>O.get(Et+"/knowledge/fetch"),getInfo:s=>O.get(Et+"/knowledge/fetch?id="+s),save:s=>O.post(Et+"/knowledge/save",s),drop:s=>O.post(Et+"/knowledge/drop",s),updateStatus:s=>O.post(Et+"/knowledge/show",s),sort:s=>O.post(Et+"/knowledge/sort",s)},Jt=window?.settings?.secure_path,Ts={getList:()=>O.get(Jt+"/plan/fetch"),save:s=>O.post(Jt+"/plan/save",s),update:s=>O.post(Jt+"/plan/update",s),drop:s=>O.post(Jt+"/plan/drop",s),sort:s=>O.post(Jt+"/plan/sort",{ids:s})},Vt=window?.settings?.secure_path,_t={getList:s=>O.post(Vt+"/order/fetch",s),getInfo:s=>O.post(Vt+"/order/detail",s),markPaid:s=>O.post(Vt+"/order/paid",s),makeCancel:s=>O.post(Vt+"/order/cancel",s),update:s=>O.post(Vt+"/order/update",s),assign:s=>O.post(Vt+"/order/assign",s)},Vs=window?.settings?.secure_path,Ms={getTemplates:s=>O.post(Vs+"/gift-card/templates",s),createTemplate:s=>O.post(Vs+"/gift-card/create-template",s),updateTemplate:s=>O.post(Vs+"/gift-card/update-template",s),deleteTemplate:s=>O.post(Vs+"/gift-card/delete-template",s),getCodes:s=>O.post(Vs+"/gift-card/codes",s),generateCodes:s=>s.download_csv?O.post(Vs+"/gift-card/generate-codes",s,{responseType:"blob"}):O.post(Vs+"/gift-card/generate-codes",s),toggleCode:s=>O.post(Vs+"/gift-card/toggle-code",s),exportCodes:s=>O.get(Vs+`/gift-card/export-codes?batch_id=${s}`,{responseType:"blob"}),getUsages:s=>O.post(Vs+"/gift-card/usages",s),getStatistics:s=>O.post(Vs+"/gift-card/statistics",s),getTypes:()=>O.get(Vs+"/gift-card/types")},Na=window?.settings?.secure_path,Ka={getList:s=>O.post(Na+"/coupon/fetch",s),save:s=>O.post(Na+"/coupon/generate",s),drop:s=>O.post(Na+"/coupon/drop",s),update:s=>O.post(Na+"/coupon/update",s)},Cs=window?.settings?.secure_path,Ys={getList:s=>O.post(`${Cs}/user/fetch`,s),update:s=>O.post(`${Cs}/user/update`,s),resetSecret:s=>O.post(`${Cs}/user/resetSecret`,{id:s}),generate:s=>s.download_csv?O.post(`${Cs}/user/generate`,s,{responseType:"blob"}):O.post(`${Cs}/user/generate`,s),getStats:s=>O.post(`${Cs}/stat/getStatUser`,s),destroy:s=>O.post(`${Cs}/user/destroy`,{id:s}),sendMail:s=>O.post(`${Cs}/user/sendMail`,s),dumpCSV:s=>O.post(`${Cs}/user/dumpCSV`,s,{responseType:"blob"}),batchBan:s=>O.post(`${Cs}/user/ban`,s)},pa={getLogs:s=>O.get(`${Cs}/traffic-reset/logs`,{params:s}),getStats:s=>O.get(`${Cs}/traffic-reset/stats`,{params:s}),resetUser:s=>O.post(`${Cs}/traffic-reset/reset-user`,s),getUserHistory:(s,n)=>O.get(`${Cs}/traffic-reset/user/${s}/history`,{params:n})},wa=window?.settings?.secure_path,zt={getList:s=>O.post(wa+"/ticket/fetch",s),getInfo:s=>O.get(wa+"/ticket/fetch?id= "+s),reply:s=>O.post(wa+"/ticket/reply",s),close:s=>O.post(wa+"/ticket/close",{id:s})},ms=window?.settings?.secure_path,Ce={getSettings:(s="")=>O.get(ms+"/config/fetch?key="+s),saveSettings:s=>O.post(ms+"/config/save",s),getEmailTemplate:()=>O.get(ms+"/config/getEmailTemplate"),sendTestMail:()=>O.post(ms+"/config/testSendMail"),setTelegramWebhook:()=>O.post(ms+"/config/setTelegramWebhook"),updateSystemConfig:s=>O.post(ms+"/config/save",s),getSystemStatus:()=>O.get(`${ms}/system/getSystemStatus`),getQueueStats:()=>O.get(`${ms}/system/getQueueStats`),getQueueWorkload:()=>O.get(`${ms}/system/getQueueWorkload`),getQueueMasters:()=>O.get(`${ms}/system/getQueueMasters`),getHorizonFailedJobs:s=>O.get(`${ms}/system/getHorizonFailedJobs`,{params:s}),getSystemLog:s=>O.get(`${ms}/system/getSystemLog`,{params:s}),getLogFiles:()=>O.get(`${ms}/log/files`),getLogContent:s=>O.get(`${ms}/log/fetch`,{params:s}),getLogClearStats:s=>O.get(`${ms}/system/getLogClearStats`,{params:s}),clearSystemLog:s=>O.post(`${ms}/system/clearSystemLog`,s)},Us=window?.settings?.secure_path,Hs={getPluginTypes:()=>O.get(`${Us}/plugin/types`),getPluginList:s=>{const n=s?{type:s}:{};return O.get(`${Us}/plugin/getPlugins`,{params:n})},uploadPlugin:s=>{const n=new FormData;return n.append("file",s),O.post(`${Us}/plugin/upload`,n,{headers:{"Content-Type":"multipart/form-data"}})},deletePlugin:s=>O.post(`${Us}/plugin/delete`,{code:s}),installPlugin:s=>O.post(`${Us}/plugin/install`,{code:s}),uninstallPlugin:s=>O.post(`${Us}/plugin/uninstall`,{code:s}),enablePlugin:s=>O.post(`${Us}/plugin/enable`,{code:s}),disablePlugin:s=>O.post(`${Us}/plugin/disable`,{code:s}),getPluginConfig:s=>O.get(`${Us}/plugin/config`,{params:{code:s}}),updatePluginConfig:(s,n)=>O.post(`${Us}/plugin/config`,{code:s,config:n}),upgradePlugin:s=>O.post(`${Us}/plugin/upgrade`,{code:s})};window?.settings?.secure_path;Bl.config({monaco:Gl});const cm=le({subscribe_template_singbox:T().optional().default(""),subscribe_template_clash:T().optional().default(""),subscribe_template_clashmeta:T().optional().default(""),subscribe_template_stash:T().optional().default(""),subscribe_template_surge:T().optional().default(""),subscribe_template_surfboard:T().optional().default("")}),kl=[{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"}],Tl={subscribe_template_singbox:"",subscribe_template_clash:"",subscribe_template_clashmeta:"",subscribe_template_stash:"",subscribe_template_surge:"",subscribe_template_surfboard:""};function dm(){const{t:s}=M("settings"),[n,t]=m.useState(!1),l=m.useRef(null),[a,i]=m.useState("singbox"),r=De({resolver:Le(cm),defaultValues:Tl,mode:"onChange"}),{data:d,isLoading:x}=oe({queryKey:["settings","client"],queryFn:()=>Ce.getSettings("subscribe_template")}),{mutateAsync:u}=Gs({mutationFn:Ce.saveSettings,onSuccess:()=>{A.success(s("common.autoSaved"))},onError:D=>{console.error("保存失败:",D),A.error(s("common.saveFailed"))}});m.useEffect(()=>{if(d?.data?.subscribe_template){const D=d.data.subscribe_template;Object.entries(D).forEach(([S,w])=>{if(S in Tl){const F=typeof w=="string"?w:"";r.setValue(S,F)}}),l.current=r.getValues()}},[d,r]);const o=m.useCallback(ze.debounce(async D=>{if(!l.current||!ze.isEqual(D,l.current)){t(!0);try{await u(D),l.current=D}catch(S){console.error("保存设置失败:",S)}finally{t(!1)}}},1500),[u]),c=m.useCallback(()=>{const D=r.getValues();o(D)},[r,o]),h=m.useCallback((D,S)=>e.jsx(g,{control:r.control,name:D,render:({field:w})=>e.jsxs(p,{children:[e.jsx(f,{className:"text-base",children:s(`subscribe_template.${D.replace("subscribe_template_","")}.title`)}),e.jsx(j,{children:e.jsx(Wl,{height:"500px",defaultLanguage:S,value:w.value||"",onChange:F=>{w.onChange(F||""),c()},options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0}})}),e.jsx(q,{children:s(`subscribe_template.${D.replace("subscribe_template_","")}.description`)}),e.jsx(E,{})]})}),[r.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(Re,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Dt,{value:a,onValueChange:i,className:"w-full",children:[e.jsx(xt,{className:"",children:kl.map(({key:D,label:S})=>e.jsx(Xe,{value:D,className:"text-xs",children:S},D))}),kl.map(({key:D,language:S})=>e.jsx(ks,{value:D,className:"mt-4",children:h(`subscribe_template_${D}`,S)},D))]}),n&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"h-2 w-2 animate-pulse rounded-full bg-blue-500"}),s("common.saving")]})]})})}function mm(){const{t:s}=M("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("subscribe_template.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe_template.description")})]}),e.jsx(Me,{}),e.jsx(dm,{})]})}const um=()=>e.jsx(sm,{children:e.jsx(qn,{})}),xm=To([{path:"/sign-in",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Dm);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(um,{}),children:[{path:"/",lazy:async()=>({Component:(await Te(()=>Promise.resolve().then(()=>Om),void 0,import.meta.url)).default}),errorElement:e.jsx(Lt,{}),children:[{index:!0,lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>lu);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(Lt,{}),children:[{path:"system",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>cu);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>xu);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>ju);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Nu);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Tu);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Ru);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Ou);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Uu);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Wu);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Zu);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe-template",element:e.jsx(mm,{})}]},{path:"payment",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>rx);return{default:s}},void 0,import.meta.url)).default})},{path:"plugin",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>cx);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>xx);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>bx);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Tx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(Lt,{}),children:[{path:"manage",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>nh);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>ch);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>ph);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(Lt,{}),children:[{path:"plan",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>wh);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Oh);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Wh);return{default:s}},void 0,import.meta.url)).default})},{path:"gift-card",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>hp);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(Lt,{}),children:[{path:"manage",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Gp);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>ug);return{default:s}},void 0,import.meta.url)).default})},{path:"traffic-reset-logs",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>jg);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:Lt},{path:"/404",Component:Nl},{path:"/503",Component:Wd},{path:"*",Component:Nl}]);function hm(){return O.get("/user/info")}const _n={token:xa()?.value||"",userInfo:null,isLoggedIn:!!xa()?.value,loading:!1,error:null},ia=Do("user/fetchUserInfo",async()=>(await hm()).data,{condition:(s,{getState:n})=>{const{user:t}=n();return!!t.token&&!t.loading}}),li=Fo({name:"user",initialState:_n,reducers:{setToken(s,n){s.token=n.payload,s.isLoggedIn=!!n.payload},resetUserState:()=>_n},extraReducers:s=>{s.addCase(ia.pending,n=>{n.loading=!0,n.error=null}).addCase(ia.fulfilled,(n,t)=>{n.loading=!1,n.userInfo=t.payload,n.error=null}).addCase(ia.rejected,(n,t)=>{if(n.loading=!1,n.error=t.error.message||"Failed to fetch user info",!n.token)return _n})}}),{setToken:pm,resetUserState:gm}=li.actions,fm=s=>s.user.userInfo,jm=li.reducer,ri=Po({reducer:{user:jm}});xa()?.value&&ri.dispatch(ia());Lo.use(Ro).use(Eo).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 vm=new Vo;Io.createRoot(document.getElementById("root")).render(e.jsx(Ma.StrictMode,{children:e.jsx(Mo,{client:vm,children:e.jsx(Oo,{store:ri,children:e.jsxs(Hd,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(zo,{router:xm}),e.jsx($o,{richColors:!0,position:"top-right"})]})})})}));const Pe=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:b("rounded-xl border bg-card text-card-foreground shadow",s),...n}));Pe.displayName="Card";const Ee=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:b("flex flex-col space-y-1.5 p-6",s),...n}));Ee.displayName="CardHeader";const Ae=m.forwardRef(({className:s,...n},t)=>e.jsx("h3",{ref:t,className:b("font-semibold leading-none tracking-tight",s),...n}));Ae.displayName="CardTitle";const it=m.forwardRef(({className:s,...n},t)=>e.jsx("p",{ref:t,className:b("text-sm text-muted-foreground",s),...n}));it.displayName="CardDescription";const Ve=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:b("p-6 pt-0",s),...n}));Ve.displayName="CardContent";const bm=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:b("flex items-center p-6 pt-0",s),...n}));bm.displayName="CardFooter";const k=m.forwardRef(({className:s,type:n,...t},l)=>e.jsx("input",{type:n,className:b("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:l,...t}));k.displayName="Input";const ii=m.forwardRef(({className:s,...n},t)=>{const[l,a]=m.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:l?"text":"password",className:b("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(P,{type:"button",size:"icon",variant:"ghost",className:"absolute right-1 top-1/2 h-6 w-6 -translate-y-1/2 rounded-md text-muted-foreground",onClick:()=>a(i=>!i),children:l?e.jsx(Ao,{size:18}):e.jsx(qo,{size:18})})]})});ii.displayName="PasswordInput";const ym=s=>O.post("/passport/auth/login",s);function _m({className:s,onForgotPassword:n,...t}){const l=et(),a=Yl(),{t:i}=M("auth"),r=le({email:T().min(1,{message:i("signIn.validation.emailRequired")}),password:T().min(1,{message:i("signIn.validation.passwordRequired")}).min(7,{message:i("signIn.validation.passwordLength")})}),d=De({resolver:Le(r),defaultValues:{email:"",password:""}});async function x(u){try{const{data:o}=await ym(u);om(o.auth_data),a(pm(o.auth_data)),await a(ia()).unwrap(),l("/")}catch(o){console.error("Login failed:",o),o.response?.data?.message&&d.setError("root",{message:o.response.data.message})}}return e.jsx("div",{className:b("grid gap-6",s),...t,children:e.jsx(Re,{...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(g,{control:d.control,name:"email",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:i("signIn.email")}),e.jsx(j,{children:e.jsx(k,{placeholder:i("signIn.emailPlaceholder"),autoComplete:"email",...u})}),e.jsx(E,{})]})}),e.jsx(g,{control:d.control,name:"password",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:i("signIn.password")}),e.jsx(j,{children:e.jsx(ii,{placeholder:i("signIn.passwordPlaceholder"),autoComplete:"current-password",...u})}),e.jsx(E,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(P,{variant:"link",type:"button",className:"px-0 text-sm font-normal text-muted-foreground hover:text-primary",onClick:n,children:i("signIn.forgotPassword")})}),e.jsx(P,{className:"w-full",size:"lg",loading:d.formState.isSubmitting,children:i("signIn.submit")})]})})})})}const he=Jl,hs=Xl,Nm=Ql,ot=Un,oi=m.forwardRef(({className:s,...n},t)=>e.jsx(Xa,{ref:t,className:b("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}));oi.displayName=Xa.displayName;const ue=m.forwardRef(({className:s,children:n,...t},l)=>e.jsxs(Nm,{children:[e.jsx(oi,{}),e.jsxs(Ya,{ref:l,className:b("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(Un,{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(xs,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ue.displayName=Ya.displayName;const je=({className:s,...n})=>e.jsx("div",{className:b("flex flex-col space-y-1.5 text-center sm:text-left",s),...n});je.displayName="DialogHeader";const qe=({className:s,...n})=>e.jsx("div",{className:b("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});qe.displayName="DialogFooter";const pe=m.forwardRef(({className:s,...n},t)=>e.jsx(Ja,{ref:t,className:b("text-lg font-semibold leading-none tracking-tight",s),...n}));pe.displayName=Ja.displayName;const Ge=m.forwardRef(({className:s,...n},t)=>e.jsx(Qa,{ref:t,className:b("text-sm text-muted-foreground",s),...n}));Ge.displayName=Qa.displayName;const Ut=St("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"}}),J=m.forwardRef(({className:s,variant:n,size:t,asChild:l=!1,...a},i)=>{const r=l?$n:"button";return e.jsx(r,{className:b(Ut({variant:n,size:t,className:s})),ref:i,...a})});J.displayName="Button";const Js=Uo,Zs=Ho,wm=Bo,Cm=m.forwardRef(({className:s,inset:n,children:t,...l},a)=>e.jsxs(lr,{ref:a,className:b("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",n&&"pl-8",s),...l,children:[t,e.jsx(rr,{className:"ml-auto h-4 w-4"})]}));Cm.displayName=lr.displayName;const Sm=m.forwardRef(({className:s,...n},t)=>e.jsx(ir,{ref:t,className:b("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}));Sm.displayName=ir.displayName;const Ws=m.forwardRef(({className:s,sideOffset:n=4,...t},l)=>e.jsx(Ko,{children:e.jsx(Zl,{ref:l,sideOffset:n,className:b("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})}));Ws.displayName=Zl.displayName;const Fe=m.forwardRef(({className:s,inset:n,...t},l)=>e.jsx(er,{ref:l,className:b("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}));Fe.displayName=er.displayName;const ci=m.forwardRef(({className:s,children:n,checked:t,...l},a)=>e.jsxs(ar,{ref:a,className:b("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,...l,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(nr,{children:e.jsx(kt,{className:"h-4 w-4"})})}),n]}));ci.displayName=ar.displayName;const km=m.forwardRef(({className:s,children:n,...t},l)=>e.jsxs(or,{ref:l,className:b("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(nr,{children:e.jsx(Go,{className:"h-4 w-4 fill-current"})})}),n]}));km.displayName=or.displayName;const an=m.forwardRef(({className:s,inset:n,...t},l)=>e.jsx(sr,{ref:l,className:b("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",s),...t}));an.displayName=sr.displayName;const dt=m.forwardRef(({className:s,...n},t)=>e.jsx(tr,{ref:t,className:b("-mx-1 my-1 h-px bg-muted",s),...n}));dt.displayName=tr.displayName;const On=({className:s,...n})=>e.jsx("span",{className:b("ml-auto text-xs tracking-widest opacity-60",s),...n});On.displayName="DropdownMenuShortcut";const Nn=[{code:"en-US",name:"English",flag:Wo,shortName:"EN"},{code:"zh-CN",name:"中文",flag:Yo,shortName:"CN"}];function di(){const{i18n:s}=M(),n=a=>{s.changeLanguage(a)},t=Nn.find(a=>a.code===s.language)||Nn[1],l=t.flag;return e.jsxs(Js,{children:[e.jsx(Zs,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 px-2 gap-1",children:[e.jsx(l,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:"text-sm font-medium",children:t.shortName})]})}),e.jsx(Ws,{align:"end",className:"w-[120px]",children:Nn.map(a=>{const i=a.flag,r=a.code===s.language;return e.jsxs(Fe,{onClick:()=>n(a.code),className:b("flex items-center gap-2 px-2 py-1.5 cursor-pointer",r&&"bg-accent"),children:[e.jsx(i,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:b("text-sm",r&&"font-medium"),children:a.name})]},a.code)})})]})}function Tm(){const[s,n]=m.useState(!1),{t}=M("auth"),l=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(di,{})}),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(Pe,{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(_m,{onForgotPassword:()=>n(!0)})]})]})]}),e.jsx(he,{open:s,onOpenChange:n,children:e.jsx(ue,{className:"max-w-[90vw] sm:max-w-lg",children:e.jsxs(je,{children:[e.jsx(pe,{children:t("signIn.resetPassword.title")}),e.jsx(Ge,{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:l}),e.jsx(J,{variant:"ghost",size:"icon",className:"absolute right-2 top-2 h-8 w-8 hover:bg-secondary-foreground/10",onClick:()=>lt(l).then(()=>{A.success(t("common:copy.success"))}),children:e.jsx(Jo,{className:"h-4 w-4"})})]})})]})})})]})}const Dm=Object.freeze(Object.defineProperty({__proto__:null,default:Tm},Symbol.toStringTag,{value:"Module"})),We=m.forwardRef(({className:s,fadedBelow:n=!1,fixedHeight:t=!1,...l},a)=>e.jsx("div",{ref:a,className:b("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),...l}));We.displayName="Layout";const Ye=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:b("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...n}));Ye.displayName="LayoutHeader";const ts=m.forwardRef(({className:s,fixedHeight:n,...t},l)=>e.jsx("div",{ref:l,className:b("flex-1 overflow-hidden px-4 py-6 md:px-8",n&&"h-[calc(100%-var(--header-height))]",s),...t}));ts.displayName="LayoutBody";const mi=Qo,ui=Xo,xi=Zo,be=ec,ge=sc,fe=tc,xe=m.forwardRef(({className:s,sideOffset:n=4,...t},l)=>e.jsx(cr,{ref:l,sideOffset:n,className:b("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}));xe.displayName=cr.displayName;function nn(){const{pathname:s}=An();return{checkActiveNav:t=>{if(t==="/"&&s==="/")return!0;const l=t.replace(/^\//,""),a=s.replace(/^\//,"");return l?a.startsWith(l):!1}}}function hi({key:s,defaultValue:n}){const[t,l]=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,l]}function Fm(){const[s,n]=hi({key:"collapsed-sidebar-items",defaultValue:[]}),t=a=>!s.includes(a);return{isExpanded:t,toggleItem:a=>{t(a)?n([...s,a]):n(s.filter(i=>i!==a))}}}function Pm({links:s,isCollapsed:n,className:t,closeNav:l}){const{t:a}=M(),i=({sub:r,...d})=>{const x=`${a(d.title)}-${d.href}`;return n&&r?m.createElement(Em,{...d,sub:r,key:x,closeNav:l}):n?m.createElement(Rm,{...d,key:x,closeNav:l}):r?m.createElement(Lm,{...d,sub:r,key:x,closeNav:l}):m.createElement(pi,{...d,key:x,closeNav:l})};return e.jsx("div",{"data-collapsed":n,className:b("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(be,{delayDuration:0,children:e.jsx("nav",{className:"grid gap-1 group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2",children:s.map(i)})})})}function pi({title:s,icon:n,label:t,href:l,closeNav:a,subLink:i=!1}){const{checkActiveNav:r}=nn(),{t:d}=M();return e.jsxs(Xs,{to:l,onClick:a,className:b(Bt({variant:r(l)?"secondary":"ghost",size:"sm"}),"h-12 justify-start text-wrap rounded-none px-6",i&&"h-10 w-full border-l border-l-slate-500 px-2"),"aria-current":r(l)?"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 Lm({title:s,icon:n,label:t,sub:l,closeNav:a}){const{checkActiveNav:i}=nn(),{isExpanded:r,toggleItem:d}=Fm(),{t:x}=M(),u=!!l?.find(h=>i(h.href)),o=x(s),c=r(o)||u;return e.jsxs(mi,{open:c,onOpenChange:()=>d(o),children:[e.jsxs(ui,{className:b(Bt({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:b('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(dr,{stroke:1})})]}),e.jsx(xi,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:l.map(h=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(pi,{...h,subLink:!0,closeNav:a})},x(h.title)))})})]})}function Rm({title:s,icon:n,label:t,href:l,closeNav:a}){const{checkActiveNav:i}=nn(),{t:r}=M();return e.jsxs(ge,{delayDuration:0,children:[e.jsx(fe,{asChild:!0,children:e.jsxs(Xs,{to:l,onClick:a,className:b(Bt({variant:i(l)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[n,e.jsx("span",{className:"sr-only",children:r(s)})]})}),e.jsxs(xe,{side:"right",className:"flex items-center gap-4",children:[r(s),t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:r(t)})]})]})}function Em({title:s,icon:n,label:t,sub:l,closeNav:a}){const{checkActiveNav:i}=nn(),{t:r}=M(),d=!!l?.find(x=>i(x.href));return e.jsxs(Js,{children:[e.jsxs(ge,{delayDuration:0,children:[e.jsx(fe,{asChild:!0,children:e.jsx(Zs,{asChild:!0,children:e.jsx(P,{variant:d?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:n})})}),e.jsxs(xe,{side:"right",className:"flex items-center gap-4",children:[r(s)," ",t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:r(t)}),e.jsx(dr,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(Ws,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(an,{children:[r(s)," ",t?`(${r(t)})`:""]}),e.jsx(dt,{}),l.map(({title:x,icon:u,label:o,href:c})=>e.jsx(Fe,{asChild:!0,children:e.jsxs(Xs,{to:c,onClick:a,className:`${i(c)?"bg-secondary":""}`,children:[u," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:r(x)}),o&&e.jsx("span",{className:"ml-auto text-xs",children:r(o)})]})},`${r(x)}-${c}`))]})]})}const gi=[{title:"nav:dashboard",label:"",href:"/",icon:e.jsx(ac,{size:18})},{title:"nav:systemManagement",label:"",href:"",icon:e.jsx(ic,{size:18}),sub:[{title:"nav:systemConfig",label:"",href:"/config/system",icon:e.jsx(mr,{size:18})},{title:"nav:pluginManagement",label:"",href:"/config/plugin",icon:e.jsx(Hn,{size:18})},{title:"nav:themeConfig",label:"",href:"/config/theme",icon:e.jsx(nc,{size:18})},{title:"nav:noticeManagement",label:"",href:"/config/notice",icon:e.jsx(lc,{size:18})},{title:"nav:paymentConfig",label:"",href:"/config/payment",icon:e.jsx(hl,{size:18})},{title:"nav:knowledgeManagement",label:"",href:"/config/knowledge",icon:e.jsx(rc,{size:18})}]},{title:"nav:nodeManagement",label:"",href:"",icon:e.jsx(xr,{size:18}),sub:[{title:"nav:nodeManagement",label:"",href:"/server/manage",icon:e.jsx(oc,{size:18})},{title:"nav:permissionGroupManagement",label:"",href:"/server/group",icon:e.jsx(ur,{size:18})},{title:"nav:routeManagement",label:"",href:"/server/route",icon:e.jsx(cc,{size:18})}]},{title:"nav:subscriptionManagement",label:"",href:"",icon:e.jsx(xc,{size:18}),sub:[{title:"nav:planManagement",label:"",href:"/finance/plan",icon:e.jsx(dc,{size:18})},{title:"nav:orderManagement",label:"",href:"/finance/order",icon:e.jsx(hl,{size:18})},{title:"nav:couponManagement",label:"",href:"/finance/coupon",icon:e.jsx(mc,{size:18})},{title:"nav:giftCardManagement",label:"",href:"/finance/gift-card",icon:e.jsx(uc,{size:18})}]},{title:"nav:userManagement",label:"",href:"",icon:e.jsx(pc,{size:18}),sub:[{title:"nav:userManagement",label:"",href:"/user/manage",icon:e.jsx(hc,{size:18})},{title:"nav:ticketManagement",label:"",href:"/user/ticket",icon:e.jsx(hr,{size:18})}]}];function Vm({className:s,isCollapsed:n,setIsCollapsed:t}){const[l,a]=m.useState(!1),{t:i}=M();return m.useEffect(()=>{l?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[l]),e.jsxs("aside",{className:b(`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 ${l?"h-svh opacity-50":"h-0 opacity-0"} w-full bg-black md:hidden`}),e.jsxs(We,{className:`flex h-full flex-col ${l?"h-[100vh] md:h-full":""}`,children:[e.jsxs(Ye,{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(P,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":i("common:toggleNavigation"),"aria-controls":"sidebar-menu","aria-expanded":l,onClick:()=>a(r=>!r),children:l?e.jsx(gc,{}):e.jsx(fc,{})})]}),e.jsx(Pm,{id:"sidebar-menu",className:b("flex-1 overflow-auto overscroll-contain",l?"block":"hidden md:block","md:py-2"),closeNav:()=>a(!1),isCollapsed:n,links:gi}),e.jsx("div",{className:b("border-t border-border/50 bg-background","px-4 py-2.5 text-xs text-muted-foreground",l?"block":"hidden md:block",n?"text-center":"text-left"),children:e.jsxs("div",{className:b("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:b("whitespace-nowrap tracking-wide","transition-opacity duration-200",n&&"md:opacity-0"),children:["v",window?.settings?.version]})]})}),e.jsx(P,{onClick:()=>t(r=>!r),size:"icon",variant:"outline",className:"absolute -right-5 top-1/2 hidden rounded-full md:inline-flex","aria-label":i("common:toggleSidebar"),children:e.jsx(jc,{stroke:1.5,className:`h-5 w-5 ${n?"rotate-180":""}`})})]})]})}function Im(){const[s,n]=hi({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 Mm(){const[s,n]=Im();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(Vm,{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(qn,{})})]})}const Om=Object.freeze(Object.defineProperty({__proto__:null,default:Mm},Symbol.toStringTag,{value:"Module"})),st=m.forwardRef(({className:s,...n},t)=>e.jsx(_s,{ref:t,className:b("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...n}));st.displayName=_s.displayName;const zm=({children:s,...n})=>e.jsx(he,{...n,children:e.jsx(ue,{className:"overflow-hidden p-0",children:e.jsx(st,{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})})}),ht=m.forwardRef(({className:s,...n},t)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(vc,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(_s.Input,{ref:t,className:b("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})]}));ht.displayName=_s.Input.displayName;const tt=m.forwardRef(({className:s,...n},t)=>e.jsx(_s.List,{ref:t,className:b("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...n}));tt.displayName=_s.List.displayName;const pt=m.forwardRef((s,n)=>e.jsx(_s.Empty,{ref:n,className:"py-6 text-center text-sm",...s}));pt.displayName=_s.Empty.displayName;const ys=m.forwardRef(({className:s,...n},t)=>e.jsx(_s.Group,{ref:t,className:b("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}));ys.displayName=_s.Group.displayName;const Gt=m.forwardRef(({className:s,...n},t)=>e.jsx(_s.Separator,{ref:t,className:b("-mx-1 h-px bg-border",s),...n}));Gt.displayName=_s.Separator.displayName;const Be=m.forwardRef(({className:s,...n},t)=>e.jsx(_s.Item,{ref:t,className:b("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}));Be.displayName=_s.Item.displayName;function $m(){const s=[];for(const n of gi)if(n.href&&s.push(n),n.sub)for(const t of n.sub)s.push({...t,parent:n.title});return s}function ps(){const[s,n]=m.useState(!1),t=et(),l=$m(),{t:a}=M("search"),{t:i}=M("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 r=m.useCallback(d=>{n(!1),t(d)},[t]);return e.jsxs(e.Fragment,{children:[e.jsxs(J,{variant:"outline",className:"relative h-9 w-9 p-0 xl:h-10 xl:w-60 xl:justify-start xl:px-3 xl:py-2",onClick:()=>n(!0),children:[e.jsx(Kn,{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(zm,{open:s,onOpenChange:n,children:[e.jsx(ht,{placeholder:a("placeholder")}),e.jsxs(tt,{children:[e.jsx(pt,{children:a("noResults")}),e.jsx(ys,{heading:a("title"),children:l.map(d=>e.jsxs(Be,{value:`${d.parent?d.parent+" ":""}${d.title}`,onSelect:()=>r(d.href),children:[e.jsx("div",{className:"mr-2",children:d.icon}),e.jsx("span",{children:i(d.title)}),d.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:i(d.parent)})]},d.href))})]})]})]})}function os(){const{theme:s,setTheme:n}=Kd();return m.useEffect(()=>{const t=s==="dark"?"#020817":"#fff",l=document.querySelector("meta[name='theme-color']");l&&l.setAttribute("content",t)},[s]),e.jsxs(e.Fragment,{children:[e.jsx(P,{size:"icon",variant:"ghost",className:"rounded-full",onClick:()=>n(s==="light"?"dark":"light"),children:s==="light"?e.jsx(bc,{size:20}):e.jsx(yc,{size:20})}),e.jsx(di,{})]})}const fi=m.forwardRef(({className:s,...n},t)=>e.jsx(pr,{ref:t,className:b("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...n}));fi.displayName=pr.displayName;const ji=m.forwardRef(({className:s,...n},t)=>e.jsx(gr,{ref:t,className:b("aspect-square h-full w-full",s),...n}));ji.displayName=gr.displayName;const vi=m.forwardRef(({className:s,...n},t)=>e.jsx(fr,{ref:t,className:b("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...n}));vi.displayName=fr.displayName;function cs(){const s=et(),n=Yl(),t=_c(fm),{t:l}=M(["common"]),a=()=>{si(),n(gm()),s("/sign-in")},i=t?.email?.split("@")[0]||l("common:user"),r=i.substring(0,2).toUpperCase();return e.jsxs(Js,{children:[e.jsx(Zs,{asChild:!0,children:e.jsx(P,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(fi,{className:"h-8 w-8",children:[e.jsx(ji,{src:t?.avatar_url,alt:i}),e.jsx(vi,{children:r})]})})}),e.jsxs(Ws,{className:"w-56",align:"end",forceMount:!0,children:[e.jsx(an,{className:"font-normal",children:e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("p",{className:"text-sm font-medium leading-none",children:i}),e.jsx("p",{className:"text-xs leading-none text-muted-foreground",children:t?.email||l("common:defaultEmail")})]})}),e.jsx(dt,{}),e.jsx(Fe,{asChild:!0,children:e.jsxs(Xs,{to:"/config/system",children:[l("common:settings"),e.jsx(On,{children:"⌘S"})]})}),e.jsx(dt,{}),e.jsxs(Fe,{onClick:a,children:[l("common:logout"),e.jsx(On,{children:"⇧⌘Q"})]})]})]})}const ee=Nc,Fs=Pc,se=wc,X=m.forwardRef(({className:s,children:n,...t},l)=>e.jsxs(jr,{ref:l,className:b("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(Cc,{asChild:!0,children:e.jsx(Bn,{className:"h-4 w-4 opacity-50"})})]}));X.displayName=jr.displayName;const bi=m.forwardRef(({className:s,...n},t)=>e.jsx(yr,{ref:t,className:b("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(Fc,{className:"h-4 w-4"})}));bi.displayName=yr.displayName;const yi=m.forwardRef(({className:s,...n},t)=>e.jsx(_r,{ref:t,className:b("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(Bn,{className:"h-4 w-4"})}));yi.displayName=_r.displayName;const Z=m.forwardRef(({className:s,children:n,position:t="popper",...l},a)=>e.jsx(Sc,{children:e.jsxs(vr,{ref:a,className:b("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,...l,children:[e.jsx(bi,{}),e.jsx(kc,{className:b("p-1",t==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx(yi,{})]})}));Z.displayName=vr.displayName;const Am=m.forwardRef(({className:s,...n},t)=>e.jsx(Nr,{ref:t,className:b("px-2 py-1.5 text-sm font-semibold",s),...n}));Am.displayName=Nr.displayName;const U=m.forwardRef(({className:s,children:n,...t},l)=>e.jsxs(br,{ref:l,className:b("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(Tc,{children:e.jsx(kt,{className:"h-4 w-4"})})}),e.jsx(Dc,{children:n})]}));U.displayName=br.displayName;const qm=m.forwardRef(({className:s,...n},t)=>e.jsx(wr,{ref:t,className:b("-mx-1 my-1 h-px bg-muted",s),...n}));qm.displayName=wr.displayName;function Rs({className:s,classNames:n,showOutsideDays:t=!0,captionLayout:l="label",buttonVariant:a="ghost",formatters:i,components:r,...d}){const x=Cr();return e.jsx(Lc,{showOutsideDays:t,className:b("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:l,formatters:{formatMonthDropdown:u=>u.toLocaleString("default",{month:"short"}),...i},classNames:{root:b("w-fit",x.root),months:b("relative flex flex-col gap-4 md:flex-row",x.months),month:b("flex w-full flex-col gap-4",x.month),nav:b("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",x.nav),button_previous:b(Ut({variant:a}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_previous),button_next:b(Ut({variant:a}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_next),month_caption:b("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",x.month_caption),dropdowns:b("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",x.dropdowns),dropdown_root:b("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:b("absolute inset-0 opacity-0",x.dropdown),caption_label:b("select-none font-medium",l==="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:b("flex",x.weekdays),weekday:b("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",x.weekday),week:b("mt-2 flex w-full",x.week),week_number_header:b("w-[--cell-size] select-none",x.week_number_header),week_number:b("text-muted-foreground select-none text-[0.8rem]",x.week_number),day:b("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:b("bg-accent rounded-l-md",x.range_start),range_middle:b("rounded-none",x.range_middle),range_end:b("bg-accent rounded-r-md",x.range_end),today:b("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",x.today),outside:b("text-muted-foreground aria-selected:text-muted-foreground",x.outside),disabled:b("text-muted-foreground opacity-50",x.disabled),hidden:b("invisible",x.hidden),...n},components:{Root:({className:u,rootRef:o,...c})=>e.jsx("div",{"data-slot":"calendar",ref:o,className:b(u),...c}),Chevron:({className:u,orientation:o,...c})=>o==="left"?e.jsx(Sr,{className:b("size-4",u),...c}):o==="right"?e.jsx(kr,{className:b("size-4",u),...c}):e.jsx(Tr,{className:b("size-4",u),...c}),DayButton:Um,WeekNumber:({children:u,...o})=>e.jsx("td",{...o,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:u})}),...r},...d})}function Um({className:s,day:n,modifiers:t,...l}){const a=Cr(),i=m.useRef(null);return m.useEffect(()=>{t.focused&&i.current?.focus()},[t.focused]),e.jsx(J,{ref:i,variant:"ghost",size:"icon","data-day":n.date.toLocaleDateString(),"data-selected-single":t.selected&&!t.range_start&&!t.range_end&&!t.range_middle,"data-range-start":t.range_start,"data-range-end":t.range_end,"data-range-middle":t.range_middle,className:b("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),...l})}const ls=Rc,rs=Ec,Ze=m.forwardRef(({className:s,align:n="center",sideOffset:t=4,...l},a)=>e.jsx(Vc,{children:e.jsx(Dr,{ref:a,align:n,sideOffset:t,className:b("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...l})}));Ze.displayName=Dr.displayName;const at={income:{main:"hsl(var(--primary))",gradient:{start:"hsl(var(--primary))",end:"transparent"}},commission:{main:"hsl(var(--secondary))",gradient:{start:"hsl(var(--secondary))",end:"transparent"}}},sa=s=>(s/100).toFixed(2),Hm=({active:s,payload:n,label:t})=>{const{t:l}=M();return s&&n&&n.length?e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-sm",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:t}),n.map((a,i)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"h-2 w-2 rounded-full",style:{backgroundColor:a.color}}),e.jsxs("span",{className:"text-muted-foreground",children:[l(a.name),":"]}),e.jsx("span",{className:"font-medium",children:a.name.includes(l("dashboard:overview.amount"))?`¥${sa(a.value)}`:l("dashboard:overview.transactions",{count:a.value})})]},i))]}):null},Km=[{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"}],Bm=(s,n)=>{const t=new Date;if(s==="custom"&&n)return{startDate:n.from,endDate:n.to};let l;switch(s){case"7d":l=Ks(t,7);break;case"30d":l=Ks(t,30);break;case"90d":l=Ks(t,90);break;case"180d":l=Ks(t,180);break;case"365d":l=Ks(t,365);break;default:l=Ks(t,30)}return{startDate:l,endDate:t}};function Gm(){const[s,n]=m.useState("amount"),[t,l]=m.useState("30d"),[a,i]=m.useState({from:Ks(new Date,7),to:new Date}),{t:r}=M(),{startDate:d,endDate:x}=Bm(t,a),{data:u}=oe({queryKey:["orderStat",{start_date:Oe(d,"yyyy-MM-dd"),end_date:Oe(x,"yyyy-MM-dd")}],queryFn:async()=>{const{data:o}=await Ha.getOrderStat({start_date:Oe(d,"yyyy-MM-dd"),end_date:Oe(x,"yyyy-MM-dd")});return o},refetchInterval:3e4});return e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Ae,{children:r("dashboard:overview.title")}),e.jsxs(it,{children:[u?.summary.start_date," ",r("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(ee,{value:t,onValueChange:o=>l(o),children:[e.jsx(X,{className:"w-[120px]",children:e.jsx(se,{placeholder:r("dashboard:overview.selectTimeRange")})}),e.jsx(Z,{children:Km.map(o=>e.jsx(U,{value:o.value,children:r(o.label)},o.value))})]}),t==="custom"&&e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(J,{variant:"outline",className:b("min-w-0 justify-start text-left font-normal",!a&&"text-muted-foreground"),children:[e.jsx(Ls,{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:[Oe(a.from,"yyyy-MM-dd")," -"," ",Oe(a.to,"yyyy-MM-dd")]}):Oe(a.from,"yyyy-MM-dd"):r("dashboard:overview.selectDate")})]})}),e.jsx(Ze,{className:"w-auto p-0",align:"end",children:e.jsx(Rs,{mode:"range",defaultMonth:a?.from,selected:{from:a?.from,to:a?.to},onSelect:o=>{o?.from&&o?.to&&i({from:o.from,to:o.to})},captionLayout:"dropdown",numberOfMonths:2})})]})]}),e.jsx(Dt,{value:s,onValueChange:o=>n(o),children:e.jsxs(xt,{children:[e.jsx(Xe,{value:"amount",children:r("dashboard:overview.amount")}),e.jsx(Xe,{value:"count",children:r("dashboard:overview.count")})]})})]})]})}),e.jsxs(Ve,{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:r("dashboard:overview.totalIncome")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",sa(u?.summary?.paid_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:r("dashboard:overview.totalTransactions",{count:u?.summary?.paid_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[r("dashboard:overview.avgOrderAmount")," ¥",sa(u?.summary?.avg_paid_amount||0)]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:r("dashboard:overview.totalCommission")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",sa(u?.summary?.commission_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:r("dashboard:overview.totalTransactions",{count:u?.summary?.commission_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[r("dashboard:overview.commissionRate")," ",u?.summary?.commission_rate.toFixed(2)||0,"%"]})]})]}),e.jsx("div",{className:"h-[400px] w-full",children:e.jsx(Ic,{width:"100%",height:"100%",children:e.jsxs(Mc,{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:at.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:at.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:at.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:at.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(Oc,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:o=>Oe(new Date(o),"MM-dd",{locale:qc})}),e.jsx(zc,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:o=>s==="amount"?`¥${sa(o)}`:r("dashboard:overview.transactions",{count:o})}),e.jsx($c,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(Ac,{content:e.jsx(Hm,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(pl,{type:"monotone",dataKey:"paid_total",name:r("dashboard:overview.orderAmount"),stroke:at.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(pl,{type:"monotone",dataKey:"commission_total",name:r("dashboard:overview.commissionAmount"),stroke:at.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(gl,{dataKey:"paid_count",name:r("dashboard:overview.orderCount"),fill:at.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(gl,{dataKey:"commission_count",name:r("dashboard:overview.commissionCount"),fill:at.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})]})]})}function we({className:s,...n}){return e.jsx("div",{className:b("animate-pulse rounded-md bg-primary/10",s),...n})}function Wm(){return e.jsxs(Pe,{children:[e.jsxs(Ee,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(we,{className:"h-4 w-[120px]"}),e.jsx(we,{className:"h-4 w-4"})]}),e.jsxs(Ve,{children:[e.jsx(we,{className:"h-8 w-[140px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(we,{className:"h-4 w-4"}),e.jsx(we,{className:"h-4 w-[100px]"})]})]})]})}function Ym(){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(Wm,{},n))})}var me=(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))(me||{});const Qt={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},Xt={0:"yellow-500",1:"blue-500",2:"red-500",3:"green-500",4:"green-500"};var Bs=(s=>(s[s.NEW=1]="NEW",s[s.RENEWAL=2]="RENEWAL",s[s.UPGRADE=3]="UPGRADE",s[s.RESET_FLOW=4]="RESET_FLOW",s))(Bs||{}),ye=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(ye||{});const Ca={0:"待确认",1:"发放中",2:"有效",3:"无效"},Sa={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var ns=(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))(ns||{});const Jm={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var ve=(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))(ve||{});const Is=[{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"}],Ss={shadowsocks:"#489851",vmess:"#CB3180",trojan:"#EBB749",hysteria:"#5684e6",vless:"#1a1a1a",tuic:"#00C853",socks:"#2196F3",naive:"#9C27B0",http:"#FF5722",mieru:"#4CAF50",anytls:"#7E57C2"};var Ps=(s=>(s[s.AMOUNT=1]="AMOUNT",s[s.PERCENTAGE=2]="PERCENTAGE",s))(Ps||{});const Qm={1:"按金额优惠",2:"按比例优惠"};var ct=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(ct||{}),js=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(js||{}),oa=(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))(oa||{});function nt({title:s,value:n,icon:t,trend:l,description:a,onClick:i,highlight:r,className:d}){return e.jsxs(Pe,{className:b("transition-colors",i&&"cursor-pointer hover:bg-muted/50",r&&"border-primary/50",d),onClick:i,children:[e.jsxs(Ee,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ae,{className:"text-sm font-medium",children:s}),t]}),e.jsxs(Ve,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n}),l?e.jsxs("div",{className:"flex items-center pt-1",children:[e.jsx(Bc,{className:b("h-4 w-4",l.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:b("ml-1 text-xs",l.isPositive?"text-emerald-500":"text-red-500"),children:[l.isPositive?"+":"-",Math.abs(l.value),"%"]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:l.label})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:a})]})]})}function Xm({className:s}){const n=et(),{t}=M(),{data:l,isLoading:a}=oe({queryKey:["dashboardStats"],queryFn:async()=>(await Ha.getStatsData()).data,refetchInterval:1e3*60*5});if(a||!l)return e.jsx(Ym,{});const i=()=>{const r=new URLSearchParams;r.set("commission_status",ye.PENDING.toString()),r.set("status",me.COMPLETED.toString()),r.set("commission_balance","gt:0"),n(`/finance/order?${r.toString()}`)};return e.jsxs("div",{className:b("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(nt,{title:t("dashboard:stats.todayIncome"),value:Qs(l.todayIncome),icon:e.jsx(Uc,{className:"h-4 w-4 text-emerald-500"}),trend:{value:l.dayIncomeGrowth,label:t("dashboard:stats.vsYesterday"),isPositive:l.dayIncomeGrowth>0}}),e.jsx(nt,{title:t("dashboard:stats.monthlyIncome"),value:Qs(l.currentMonthIncome),icon:e.jsx(Gn,{className:"h-4 w-4 text-blue-500"}),trend:{value:l.monthIncomeGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:l.monthIncomeGrowth>0}}),e.jsx(nt,{title:t("dashboard:stats.pendingTickets"),value:l.ticketPendingTotal,icon:e.jsx(Hc,{className:b("h-4 w-4",l.ticketPendingTotal>0?"text-orange-500":"text-muted-foreground")}),description:l.ticketPendingTotal>0?t("dashboard:stats.hasPendingTickets"):t("dashboard:stats.noPendingTickets"),onClick:()=>n("/user/ticket"),highlight:l.ticketPendingTotal>0}),e.jsx(nt,{title:t("dashboard:stats.pendingCommission"),value:l.commissionPendingTotal,icon:e.jsx(Kc,{className:b("h-4 w-4",l.commissionPendingTotal>0?"text-blue-500":"text-muted-foreground")}),description:l.commissionPendingTotal>0?t("dashboard:stats.hasPendingCommission"):t("dashboard:stats.noPendingCommission"),onClick:i,highlight:l.commissionPendingTotal>0}),e.jsx(nt,{title:t("dashboard:stats.monthlyNewUsers"),value:l.currentMonthNewUsers,icon:e.jsx(Oa,{className:"h-4 w-4 text-blue-500"}),trend:{value:l.userGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:l.userGrowth>0}}),e.jsx(nt,{title:t("dashboard:stats.totalUsers"),value:l.totalUsers,icon:e.jsx(Oa,{className:"h-4 w-4 text-muted-foreground"}),description:t("dashboard:stats.activeUsers",{count:l.activeUsers})}),e.jsx(nt,{title:t("dashboard:stats.monthlyUpload"),value:Ie(l.monthTraffic.upload),icon:e.jsx(At,{className:"h-4 w-4 text-emerald-500"}),description:t("dashboard:stats.todayTraffic",{value:Ie(l.todayTraffic.upload)})}),e.jsx(nt,{title:t("dashboard:stats.monthlyDownload"),value:Ie(l.monthTraffic.download),icon:e.jsx(ma,{className:"h-4 w-4 text-blue-500"}),description:t("dashboard:stats.todayTraffic",{value:Ie(l.todayTraffic.download)})})]})}const Ct=m.forwardRef(({className:s,children:n,...t},l)=>e.jsxs(Fr,{ref:l,className:b("relative overflow-hidden",s),...t,children:[e.jsx(Gc,{className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(Ba,{}),e.jsx(Wc,{})]}));Ct.displayName=Fr.displayName;const Ba=m.forwardRef(({className:s,orientation:n="vertical",...t},l)=>e.jsx(Pr,{ref:l,orientation:n,className:b("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(Yc,{className:"relative flex-1 rounded-full bg-border"})}));Ba.displayName=Pr.displayName;const zn={today:{getValue:()=>{const s=Qc();return{start:s,end:Xc(s,1)}}},last7days:{getValue:()=>{const s=new Date;return{start:Ks(s,7),end:s}}},last30days:{getValue:()=>{const s=new Date;return{start:Ks(s,30),end:s}}},custom:{getValue:()=>null}};function Dl({selectedRange:s,customDateRange:n,onRangeChange:t,onCustomRangeChange:l}){const{t:a}=M(),i={today:a("dashboard:trafficRank.today"),last7days:a("dashboard:trafficRank.last7days"),last30days:a("dashboard:trafficRank.last30days"),custom:a("dashboard:trafficRank.customRange")};return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsxs(ee,{value:s,onValueChange:t,children:[e.jsx(X,{className:"w-[120px]",children:e.jsx(se,{placeholder:a("dashboard:trafficRank.selectTimeRange")})}),e.jsx(Z,{position:"popper",className:"z-50",children:Object.entries(zn).map(([r])=>e.jsx(U,{value:r,children:i[r]},r))})]}),s==="custom"&&e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(J,{variant:"outline",className:b("min-w-0 justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(Ls,{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:[Oe(n.from,"yyyy-MM-dd")," -"," ",Oe(n.to,"yyyy-MM-dd")]}):Oe(n.from,"yyyy-MM-dd"):e.jsx("span",{children:a("dashboard:trafficRank.selectDateRange")})})]})}),e.jsx(Ze,{className:"w-auto p-0",align:"end",children:e.jsx(Rs,{mode:"range",defaultMonth:n?.from,selected:{from:n?.from,to:n?.to},onSelect:r=>{r?.from&&r?.to&&l({from:r.from,to:r.to})},numberOfMonths:2})})]})]})}const It=s=>`${(s/1024/1024/1024).toFixed(2)} GB`;function Zm({className:s}){const{t:n}=M(),[t,l]=m.useState("today"),[a,i]=m.useState({from:Ks(new Date,7),to:new Date}),[r,d]=m.useState("today"),[x,u]=m.useState({from:Ks(new Date,7),to:new Date}),o=m.useMemo(()=>t==="custom"?{start:a.from,end:a.to}:zn[t].getValue(),[t,a]),c=m.useMemo(()=>r==="custom"?{start:x.from,end:x.to}:zn[r].getValue(),[r,x]),{data:h}=oe({queryKey:["nodeTrafficRank",o.start,o.end],queryFn:()=>Ha.getNodeTrafficData({type:"node",start_time:ze.round(o.start.getTime()/1e3),end_time:ze.round(o.end.getTime()/1e3)}),refetchInterval:3e4}),{data:D}=oe({queryKey:["userTrafficRank",c.start,c.end],queryFn:()=>Ha.getNodeTrafficData({type:"user",start_time:ze.round(c.start.getTime()/1e3),end_time:ze.round(c.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:b("grid gap-4 md:grid-cols-2",s),children:[e.jsxs(Pe,{children:[e.jsx(Ee,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Ae,{className:"flex items-center text-base font-medium",children:[e.jsx(Jc,{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(Dl,{selectedRange:t,customDateRange:a,onRangeChange:l,onCustomRangeChange:i}),e.jsx(fl,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Ve,{className:"flex-1",children:h?.data?e.jsxs(Ct,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:h.data.map(S=>e.jsx(be,{delayDuration:200,children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:S.name}),e.jsxs("span",{className:b("ml-2 flex items-center text-xs font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?e.jsx(Pn,{className:"mr-1 h-3 w-3"}):e.jsx(Ln,{className:"mr-1 h-3 w-3"}),Math.abs(S.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${S.value/h.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:It(S.value)})]})]})})}),e.jsx(xe,{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:It(S.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:It(S.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:b("font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?"+":"",S.change,"%"]})]})})]})},S.id))}),e.jsx(Ba,{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(Pe,{children:[e.jsx(Ee,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Ae,{className:"flex items-center text-base font-medium",children:[e.jsx(Oa,{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(Dl,{selectedRange:r,customDateRange:x,onRangeChange:d,onCustomRangeChange:u}),e.jsx(fl,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Ve,{className:"flex-1",children:D?.data?e.jsxs(Ct,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:D.data.map(S=>e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:S.name}),e.jsxs("span",{className:b("ml-2 flex items-center text-xs font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?e.jsx(Pn,{className:"mr-1 h-3 w-3"}):e.jsx(Ln,{className:"mr-1 h-3 w-3"}),Math.abs(S.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${S.value/D.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:It(S.value)})]})]})})}),e.jsx(xe,{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:It(S.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:It(S.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:b("font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?"+":"",S.change,"%"]})]})})]})},S.id))}),e.jsx(Ba,{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 eu=St("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 H({className:s,variant:n,...t}){return e.jsx("div",{className:b(eu({variant:n}),s),...t})}const Ra=m.forwardRef(({className:s,value:n,...t},l)=>e.jsx(Lr,{ref:l,className:b("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...t,children:e.jsx(Zc,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(n||0)}%)`}})}));Ra.displayName=Lr.displayName;const Zn=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:b("w-full caption-bottom text-sm",s),...n})}));Zn.displayName="Table";const el=m.forwardRef(({className:s,...n},t)=>e.jsx("thead",{ref:t,className:b("[&_tr]:border-b",s),...n}));el.displayName="TableHeader";const sl=m.forwardRef(({className:s,...n},t)=>e.jsx("tbody",{ref:t,className:b("[&_tr:last-child]:border-0",s),...n}));sl.displayName="TableBody";const su=m.forwardRef(({className:s,...n},t)=>e.jsx("tfoot",{ref:t,className:b("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...n}));su.displayName="TableFooter";const rt=m.forwardRef(({className:s,...n},t)=>e.jsx("tr",{ref:t,className:b("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...n}));rt.displayName="TableRow";const tl=m.forwardRef(({className:s,...n},t)=>e.jsx("th",{ref:t,className:b("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}));tl.displayName="TableHead";const $t=m.forwardRef(({className:s,...n},t)=>e.jsx("td",{ref:t,className:b("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));$t.displayName="TableCell";const tu=m.forwardRef(({className:s,...n},t)=>e.jsx("caption",{ref:t,className:b("mt-4 text-sm text-muted-foreground",s),...n}));tu.displayName="TableCaption";function _i({table:s}){const[n,t]=m.useState(""),{t:l}=M("common");m.useEffect(()=>{t((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const a=i=>{const r=parseInt(i);!isNaN(r)&&r>=1&&r<=s.getPageCount()?s.setPageIndex(r-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:l("table.pagination.selected",{selected:s.getFilteredSelectedRowModel().rows.length,total:s.getFilteredRowModel().rows.length})}),e.jsxs("div",{className:"flex flex-col-reverse items-center gap-4 sm:flex-row sm:gap-6 lg:gap-8",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:l("table.pagination.itemsPerPage")}),e.jsxs(ee,{value:`${s.getState().pagination.pageSize}`,onValueChange:i=>{s.setPageSize(Number(i))},children:[e.jsx(X,{className:"h-8 w-[70px]",children:e.jsx(se,{placeholder:s.getState().pagination.pageSize})}),e.jsx(Z,{side:"top",children:[10,20,30,40,50,100,500].map(i=>e.jsx(U,{value:`${i}`,children:i},i))})]})]}),e.jsxs("div",{className:"flex items-center justify-center space-x-2 text-sm font-medium",children:[e.jsx("span",{children:l("table.pagination.page")}),e.jsx(k,{type:"text",value:n,onChange:i=>t(i.target.value),onBlur:i=>a(i.target.value),onKeyDown:i=>{i.key==="Enter"&&a(i.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsx("span",{children:l("table.pagination.pageOf",{total:s.getPageCount()})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(P,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(0),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.firstPage")}),e.jsx(ed,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.previousPage")}),e.jsx(sd,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.nextPage")}),e.jsx(rr,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(s.getPageCount()-1),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.lastPage")}),e.jsx(td,{className:"h-4 w-4"})]})]})]})]})}function ds({table:s,toolbar:n,draggable:t=!1,onDragStart:l,onDragEnd:a,onDragOver:i,onDragLeave:r,onDrop:d,showPagination:x=!0,isLoading:u=!1}){const{t:o}=M("common"),c=m.useRef(null),h=s.getAllColumns().filter(F=>F.getIsPinned()==="left"),D=s.getAllColumns().filter(F=>F.getIsPinned()==="right"),S=F=>h.slice(0,F).reduce((y,I)=>y+(I.getSize()??0),0),w=F=>D.slice(F+1).reduce((y,I)=>y+(I.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(Zn,{children:[e.jsx(el,{children:s.getHeaderGroups().map(F=>e.jsx(rt,{className:"hover:bg-transparent",children:F.headers.map((y,I)=>{const v=y.column.getIsPinned()==="left",_=y.column.getIsPinned()==="right",C=v?S(h.indexOf(y.column)):void 0,z=_?w(D.indexOf(y.column)):void 0;return e.jsx(tl,{colSpan:y.colSpan,style:{width:y.getSize(),...v&&{left:C},..._&&{right:z}},className:b("h-11 bg-card px-4 text-muted-foreground",(v||_)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",v&&"before:right-0",_&&"before:left-0"]),children:y.isPlaceholder?null:za(y.column.columnDef.header,y.getContext())},y.id)})},F.id))}),e.jsx(sl,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((F,y)=>e.jsx(rt,{"data-state":F.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:t,onDragStart:I=>l?.(I,y),onDragEnd:a,onDragOver:i,onDragLeave:r,onDrop:I=>d?.(I,y),children:F.getVisibleCells().map((I,v)=>{const _=I.column.getIsPinned()==="left",C=I.column.getIsPinned()==="right",z=_?S(h.indexOf(I.column)):void 0,V=C?w(D.indexOf(I.column)):void 0;return e.jsx($t,{style:{width:I.column.getSize(),..._&&{left:z},...C&&{right:V}},className:b("bg-card",(_||C)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",_&&"before:right-0",C&&"before:left-0"]),children:za(I.column.columnDef.cell,I.getContext())},I.id)})},F.id)):e.jsx(rt,{children:e.jsx($t,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:o("table.noData")})})})]})})}),x&&e.jsx(_i,{table:s})]})}const Ea=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"})},Zt=Rr(),ea=Rr();function ka({data:s,isLoading:n,searchKeyword:t,selectedLevel:l,total:a,currentPage:i,pageSize:r,onViewDetail:d,onPageChange:x,onPageSizeChange:u}){const{t:o}=M(),c=S=>{switch(S.toLowerCase()){case"info":return e.jsx(aa,{className:"h-4 w-4 text-blue-500"});case"warning":return e.jsx(na,{className:"h-4 w-4 text-yellow-500"});case"error":return e.jsx(Vn,{className:"h-4 w-4 text-red-500"});default:return e.jsx(aa,{className:"h-4 w-4 text-slate-500"})}},h=m.useMemo(()=>[Zt.accessor("level",{id:"level",header:()=>o("dashboard:systemLog.level"),size:80,cell:({getValue:S,row:w})=>{const F=S();return e.jsxs("div",{className:"flex items-center gap-1",children:[c(F),e.jsx("span",{className:b(F.toLowerCase()==="error"&&"text-red-600",F.toLowerCase()==="warning"&&"text-yellow-600",F.toLowerCase()==="info"&&"text-blue-600"),children:F})]})}}),Zt.accessor("created_at",{id:"created_at",header:()=>o("dashboard:systemLog.time"),size:160,cell:({getValue:S})=>Ea(S())}),Zt.accessor(S=>S.title||S.message||"",{id:"title",header:()=>o("dashboard:systemLog.logTitle"),cell:({getValue:S})=>e.jsx("span",{className:"inline-block max-w-[300px] truncate",children:S()})}),Zt.accessor("method",{id:"method",header:()=>o("dashboard:systemLog.method"),size:100,cell:({getValue:S})=>{const w=S();return w?e.jsx(H,{variant:"outline",className:b(w==="GET"&&"border-blue-200 bg-blue-50 text-blue-700",w==="POST"&&"border-green-200 bg-green-50 text-green-700",w==="PUT"&&"border-amber-200 bg-amber-50 text-amber-700",w==="DELETE"&&"border-red-200 bg-red-50 text-red-700"),children:w}):null}}),Zt.display({id:"actions",header:()=>o("dashboard:systemLog.action"),size:80,cell:({row:S})=>e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>d(S.original),"aria-label":o("dashboard:systemLog.viewDetail"),children:e.jsx(Rn,{className:"h-4 w-4"})})})],[o,d]),D=es({data:s,columns:h,getCoreRowModel:ss(),getPaginationRowModel:is(),pageCount:Math.ceil(a/r),manualPagination:!0,state:{pagination:m.useMemo(()=>({pageIndex:i-1,pageSize:r}),[i,r])},onPaginationChange:S=>{let w,F;if(typeof S=="function"){const y=S({pageIndex:i-1,pageSize:r});w=y.pageIndex,F=y.pageSize}else w=S.pageIndex,F=S.pageSize;F!==r?u(F):x(w+1)}});return e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(ds,{table:D,showPagination:!0,isLoading:n}),(t||l&&l!=="all")&&e.jsx("div",{className:"text-center text-sm text-muted-foreground",children:t&&l&&l!=="all"?o("dashboard:systemLog.filter.searchAndLevel",{keyword:t,level:l,count:a}):t?o("dashboard:systemLog.filter.searchOnly",{keyword:t,count:a}):o("dashboard:systemLog.filter.levelOnly",{level:l,count:a})})]})}function au(){const{t:s}=M(),[n,t]=m.useState(0),[l,a]=m.useState(!1),[i,r]=m.useState(1),[d]=m.useState(10),[x,u]=m.useState(null),[o,c]=m.useState(!1),[h,D]=m.useState(!1),[S,w]=m.useState(1),[F,y]=m.useState(10),[I,v]=m.useState(null),[_,C]=m.useState(!1),[z,V]=m.useState(""),[R,W]=m.useState(""),[N,L]=m.useState("all"),[ae,G]=m.useState(!1),[ne,_e]=m.useState(0),[gs,Ue]=m.useState("all"),[de,Es]=m.useState(1e3),[Ds,gt]=m.useState(!1),[As,ft]=m.useState(null),[jt,vt]=m.useState(!1);m.useEffect(()=>{const Q=setTimeout(()=>{W(z),z!==R&&w(1)},500);return()=>clearTimeout(Q)},[z]);const{data:B,isLoading:K,refetch:Se,isRefetching:Ke}=oe({queryKey:["systemStatus",n],queryFn:async()=>(await Ce.getSystemStatus()).data,refetchInterval:3e4}),{data:ke,isLoading:to,refetch:vg,isRefetching:ol}=oe({queryKey:["queueStats",n],queryFn:async()=>(await Ce.getQueueStats()).data,refetchInterval:3e4}),{data:cl,isLoading:ao,refetch:no}=oe({queryKey:["failedJobs",i,d],queryFn:async()=>{const Q=await Ce.getHorizonFailedJobs({current:i,page_size:d});return{data:Q.data,total:Q.total||0}},enabled:l}),{data:dl,isLoading:ga,refetch:lo}=oe({queryKey:["systemLogs",S,F,N,R],queryFn:async()=>{const Q={current:S,page_size:F};N&&N!=="all"&&(Q.level=N),R.trim()&&(Q.keyword=R.trim());const qs=await Ce.getSystemLog(Q);return{data:qs.data,total:qs.total||0}},enabled:h}),ml=cl?.data||[],ro=cl?.total||0,fa=dl?.data||[],ja=dl?.total||0,io=m.useMemo(()=>[ea.display({id:"failed_at",header:()=>s("dashboard:queue.details.time"),cell:({row:Q})=>Ea(Q.original.failed_at)}),ea.display({id:"queue",header:()=>s("dashboard:queue.details.queue"),cell:({row:Q})=>Q.original.queue}),ea.display({id:"name",header:()=>s("dashboard:queue.details.name"),cell:({row:Q})=>e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[150px] truncate",children:Q.original.name})}),e.jsx(xe,{children:e.jsx("span",{children:Q.original.name})})]})})}),ea.display({id:"exception",header:()=>s("dashboard:queue.details.exception"),cell:({row:Q})=>e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[200px] truncate",children:Q.original.exception.split(` +import{r as m,j as e,t as jo,c as vo,S as $n,I as da,a as St,u as et,b as bo,d as An,R as Al,e as ql,f as yo,F as _o,C as No,L as Ul,T as Hl,g as Kl,h as wo,i as Co,k as So,l as ko,m as A,n as Bl,o as Gl,p as le,s as T,q as M,v as De,w as Le,x as oe,y as Gs,z as ze,A as Wl,B as To,O as qn,D as Do,E as Fo,G as Po,H as Lo,J as Ro,K as Eo,Q as Vo,M as Io,N as Ma,P as Mo,U as Oo,V as zo,$ as $o,W as Ao,X as qo,Y as Yl,Z as Jl,_ as Ql,a0 as Ya,a1 as Un,a2 as xs,a3 as Ja,a4 as Qa,a5 as Xl,a6 as Xa,a7 as Uo,a8 as Ho,a9 as Ko,aa as Zl,ab as er,ac as sr,ad as tr,ae as Bo,af as ar,ag as nr,ah as kt,ai as lr,aj as rr,ak as ir,al as or,am as Go,an as Wo,ao as Yo,ap as Jo,aq as Qo,ar as Xo,as as Zo,at as ec,au as sc,av as tc,aw as cr,ax as dr,ay as Xs,az as ac,aA as mr,aB as Hn,aC as nc,aD as lc,aE as hl,aF as rc,aG as ic,aH as oc,aI as ur,aJ as cc,aK as xr,aL as dc,aM as mc,aN as uc,aO as xc,aP as hc,aQ as hr,aR as pc,aS as gc,aT as fc,aU as jc,aV as vc,aW as _s,aX as Kn,aY as bc,aZ as yc,a_ as pr,a$ as gr,b0 as fr,b1 as _c,b2 as Nc,b3 as wc,b4 as jr,b5 as Cc,b6 as Bn,b7 as Sc,b8 as vr,b9 as kc,ba as br,bb as Tc,bc as Dc,bd as yr,be as Fc,bf as _r,bg as Pc,bh as Nr,bi as wr,bj as Cr,bk as Lc,bl as Sr,bm as kr,bn as Tr,bo as Rc,bp as Ec,bq as Vc,br as Dr,bs as Ks,bt as Oe,bu as Ls,bv as Ic,bw as Mc,bx as Oc,by as zc,bz as $c,bA as Ac,bB as pl,bC as gl,bD as qc,bE as Uc,bF as Gn,bG as Hc,bH as Kc,bI as Oa,bJ as At,bK as ma,bL as Bc,bM as Fr,bN as Gc,bO as Wc,bP as Pr,bQ as Yc,bR as Jc,bS as fl,bT as Pn,bU as Ln,bV as Qc,bW as Xc,bX as Lr,bY as Zc,bZ as ed,b_ as sd,b$ as td,c0 as za,c1 as Rr,c2 as Rn,c3 as es,c4 as $a,c5 as ad,c6 as vn,c7 as nd,c8 as En,c9 as vs,ca as aa,cb as na,cc as Vn,cd as Er,ce as Vr,cf as is,cg as ss,ch as ld,ci as rd,cj as id,ck as od,cl as cd,cm as Ir,cn as dd,co as ce,cp as Y,cq as ie,cr as Qe,cs as md,ct as ud,cu as He,cv as Tt,cw as jl,cx as xd,cy as hd,cz as pd,cA as gd,cB as Mr,cC as Or,cD as zr,cE as $r,cF as Ar,cG as qr,cH as Za,cI as ut,cJ as Ns,cK as ws,cL as Ht,cM as fd,cN as jd,cO as vd,cP as Aa,cQ as bd,cR as yd,cS as In,cT as Wn,cU as Yn,cV as _d,cW as Os,cX as zs,cY as en,cZ as Nd,c_ as Kt,c$ as qa,d0 as wd,d1 as La,d2 as Cd,d3 as vl,d4 as Ur,d5 as _a,d6 as Ua,d7 as Sd,d8 as Jn,d9 as kd,da as Td,db as Dd,dc as fs,dd as Hr,de as Fd,df as Pd,dg as Kr,dh as Mn,di as Br,dj as Ld,dk as ua,dl as Gr,dm as Rd,dn as Ed,dp as Vd,dq as Id,dr as Wr,ds as Md,dt as Yr,du as la,dv as Qn,dw as Od,dx as bl,dy as Jr,dz as zd,dA as yl,dB as $d,dC as Ad}from"./vendor.js";import"./index.js";var _g=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ng(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function qd(s){if(s.__esModule)return s;var n=s.default;if(typeof n=="function"){var t=function l(){return this instanceof l?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(l){var a=Object.getOwnPropertyDescriptor(s,l);Object.defineProperty(t,l,a.get?a:{enumerable:!0,get:function(){return s[l]}})}),t}const Ud={theme:"system",setTheme:()=>null},Qr=m.createContext(Ud);function Hd({children:s,defaultTheme:n="system",storageKey:t="vite-ui-theme",...l}){const[a,i]=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 r={theme:a,setTheme:d=>{localStorage.setItem(t,d),i(d)}};return e.jsx(Qr.Provider,{...l,value:r,children:s})}const Kd=()=>{const s=m.useContext(Qr);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},Bd=function(){const n=typeof document<"u"&&document.createElement("link").relList;return n&&n.supports&&n.supports("modulepreload")?"modulepreload":"preload"}(),Gd=function(s,n){return new URL(s,n).href},_l={},Te=function(n,t,l){let a=Promise.resolve();if(t&&t.length>0){const r=document.getElementsByTagName("link"),d=document.querySelector("meta[property=csp-nonce]"),x=d?.nonce||d?.getAttribute("nonce");a=Promise.allSettled(t.map(u=>{if(u=Gd(u,l),u in _l)return;_l[u]=!0;const o=u.endsWith(".css"),c=o?'[rel="stylesheet"]':"";if(!!l)for(let S=r.length-1;S>=0;S--){const w=r[S];if(w.href===u&&(!o||w.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${c}`))return;const D=document.createElement("link");if(D.rel=o?"stylesheet":Bd,o||(D.as="script"),D.crossOrigin="",D.href=u,x&&D.setAttribute("nonce",x),document.head.appendChild(D),o)return new Promise((S,w)=>{D.addEventListener("load",S),D.addEventListener("error",()=>w(new Error(`Unable to preload CSS for ${u}`)))})}))}function i(r){const d=new Event("vite:preloadError",{cancelable:!0});if(d.payload=r,window.dispatchEvent(d),!d.defaultPrevented)throw r}return a.then(r=>{for(const d of r||[])d.status==="rejected"&&i(d.reason);return n().catch(i)})};function b(...s){return jo(vo(s))}const Bt=St("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"}}),P=m.forwardRef(({className:s,variant:n,size:t,asChild:l=!1,children:a,disabled:i,loading:r=!1,leftSection:d,rightSection:x,...u},o)=>{const c=l?$n:"button";return e.jsxs(c,{className:b(Bt({variant:n,size:t,className:s})),disabled:r||i,ref:o,...u,children:[(d&&r||!d&&!x&&r)&&e.jsx(da,{className:"mr-2 h-4 w-4 animate-spin"}),!r&&d&&e.jsx("div",{className:"mr-2",children:d}),a,!r&&x&&e.jsx("div",{className:"ml-2",children:x}),x&&r&&e.jsx(da,{className:"ml-2 h-4 w-4 animate-spin"})]})});P.displayName="Button";function Lt({className:s,minimal:n=!1}){const t=et(),l=bo(),a=l?.message||l?.statusText||"Unknown error occurred";return e.jsx("div",{className:b("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(P,{variant:"outline",onClick:()=>t(-1),children:"Go Back"}),e.jsx(P,{onClick:()=>t("/"),children:"Back to Home"})]})]})})}function Nl(){const s=et();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(P,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(P,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function Wd(){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(P,{variant:"outline",children:"Learn more"})})]})})}function Yd(s){return typeof s>"u"}function Jd(s){return s===null}function Qd(s){return Jd(s)||Yd(s)}class Xd{storage;prefixKey;constructor(n){this.storage=n.storage,this.prefixKey=n.prefixKey}getKey(n){return`${this.prefixKey}${n}`.toUpperCase()}set(n,t,l=null){const a=JSON.stringify({value:t,time:Date.now(),expire:l!==null?new Date().getTime()+l*1e3:null});this.storage.setItem(this.getKey(n),a)}get(n,t=null){const l=this.storage.getItem(this.getKey(n));if(!l)return{value:t,time:0};try{const a=JSON.parse(l),{value:i,time:r,expire:d}=a;return Qd(d)||d>new Date().getTime()?{value:i,time:r}:(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 Xr({prefixKey:s="",storage:n=sessionStorage}){return new Xd({prefixKey:s,storage:n})}const Zr="Xboard_",Zd=function(s={}){return Xr({prefixKey:s.prefixKey||"",storage:localStorage})},em=function(s={}){return Xr({prefixKey:s.prefixKey||"",storage:sessionStorage})},Xn=Zd({prefixKey:Zr});em({prefixKey:Zr});const ei="access_token";function xa(){return Xn.get(ei)}function si(){Xn.remove(ei)}const wl=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function sm({children:s}){const n=et(),t=An(),l=xa();return m.useEffect(()=>{if(!l.value&&!wl.includes(t.pathname)){const a=encodeURIComponent(t.pathname+t.search);n(`/sign-in?redirect=${a}`)}},[l.value,t.pathname,t.search,n]),wl.includes(t.pathname)||l.value?e.jsx(e.Fragment,{children:s}):null}const Me=m.forwardRef(({className:s,orientation:n="horizontal",decorative:t=!0,...l},a)=>e.jsx(Al,{ref:a,decorative:t,orientation:n,className:b("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...l}));Me.displayName=Al.displayName;const tm=St("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),as=m.forwardRef(({className:s,...n},t)=>e.jsx(ql,{ref:t,className:b(tm(),s),...n}));as.displayName=ql.displayName;const Re=_o,ti=m.createContext({}),g=({...s})=>e.jsx(ti.Provider,{value:{name:s.name},children:e.jsx(No,{...s})}),sn=()=>{const s=m.useContext(ti),n=m.useContext(ai),{getFieldState:t,formState:l}=yo(),a=t(s.name,l);if(!s)throw new Error("useFormField should be used within ");const{id:i}=n;return{id:i,name:s.name,formItemId:`${i}-form-item`,formDescriptionId:`${i}-form-item-description`,formMessageId:`${i}-form-item-message`,...a}},ai=m.createContext({}),p=m.forwardRef(({className:s,...n},t)=>{const l=m.useId();return e.jsx(ai.Provider,{value:{id:l},children:e.jsx("div",{ref:t,className:b("space-y-2",s),...n})})});p.displayName="FormItem";const f=m.forwardRef(({className:s,...n},t)=>{const{error:l,formItemId:a}=sn();return e.jsx(as,{ref:t,className:b(l&&"text-destructive",s),htmlFor:a,...n})});f.displayName="FormLabel";const j=m.forwardRef(({...s},n)=>{const{error:t,formItemId:l,formDescriptionId:a,formMessageId:i}=sn();return e.jsx($n,{ref:n,id:l,"aria-describedby":t?`${a} ${i}`:`${a}`,"aria-invalid":!!t,...s})});j.displayName="FormControl";const q=m.forwardRef(({className:s,...n},t)=>{const{formDescriptionId:l}=sn();return e.jsx("p",{ref:t,id:l,className:b("text-[0.8rem] text-muted-foreground",s),...n})});q.displayName="FormDescription";const E=m.forwardRef(({className:s,children:n,...t},l)=>{const{error:a,formMessageId:i}=sn(),r=a?String(a?.message):n;return r?e.jsx("p",{ref:l,id:i,className:b("text-[0.8rem] font-medium text-destructive",s),...t,children:r}):null});E.displayName="FormMessage";const Dt=wo,xt=m.forwardRef(({className:s,...n},t)=>e.jsx(Ul,{ref:t,className:b("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...n}));xt.displayName=Ul.displayName;const Xe=m.forwardRef(({className:s,...n},t)=>e.jsx(Hl,{ref:t,className:b("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}));Xe.displayName=Hl.displayName;const ks=m.forwardRef(({className:s,...n},t)=>e.jsx(Kl,{ref:t,className:b("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...n}));ks.displayName=Kl.displayName;function re(s=void 0,n="YYYY-MM-DD HH:mm:ss"){return s==null?"":(Math.floor(s).toString().length===10&&(s=s*1e3),So(s).format(n))}function am(s=void 0,n="YYYY-MM-DD"){return re(s,n)}function Cl(s){const n=typeof s=="string"?parseFloat(s):s;return isNaN(n)?"0.00":n.toFixed(2)}function Qs(s,n=!0){if(s==null)return n?"¥0.00":"0.00";const t=typeof s=="string"?parseFloat(s):s;if(isNaN(t))return n?"¥0.00":"0.00";const a=(t/100).toFixed(2).replace(/\.?0+$/,i=>i.includes(".")?".00":i);return n?`¥${a}`:a}function lt(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 l=new Co(t);l.on("success",()=>{l.destroy(),document.body.removeChild(t),n(!0)}),l.on("error",a=>{console.error("Clipboard.js failed:",a),l.destroy(),document.body.removeChild(t),n(!1)}),t.click()}catch(t){console.error("copyToClipboard failed:",t),n(!1)}})}function Ie(s){if(s==null||s<=0)return"0 B";const n=1024,t=["B","KB","MB","GB","TB"];let l=Math.floor(Math.log(s)/Math.log(n));return l<0?l=0:l>=t.length&&(l=t.length-1),`${parseFloat((s/Math.pow(n,l)).toFixed(2))} ${t[l]}`}const Sl="i18nextLng";function nm(){return console.log(localStorage.getItem(Sl)),localStorage.getItem(Sl)}function ni(){si();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 lm=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function rm(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const Ot=ko.create({baseURL:rm(),timeout:12e3,headers:{"Content-Type":"application/json"}});Ot.interceptors.request.use(s=>{s.method?.toLowerCase()==="get"&&(s.params={...s.params,t:Date.now()});const n=xa();if(!lm.includes(s.url?.split("?")[0]||"")){if(!n.value)return ni(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=n.value}return s.headers["Content-Language"]=nm()||"zh-CN",s},s=>Promise.reject(s));Ot.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)&&ni(),A.error(t||{401:"登录已过期",403:"没有权限",404:"资源或接口不存在"}[n]||"未知异常"),Promise.reject(s.response?.data||{data:null,code:-1,message:"未知错误"})});const O={get:(s,n)=>Ot.get(s,n),post:(s,n,t)=>Ot.post(s,n,t),put:(s,n,t)=>Ot.put(s,n,t),delete:(s,n)=>Ot.delete(s,n)},im="access_token";function om(s){Xn.set(im,s)}const bt=window?.settings?.secure_path,Ha={getStats:()=>O.get(bt+"/monitor/api/stats"),getOverride:()=>O.get(bt+"/stat/getOverride"),getOrderStat:s=>O.get(bt+"/stat/getOrder",{params:s}),getStatsData:()=>O.get(bt+"/stat/getStats"),getNodeTrafficData:s=>O.get(bt+"/stat/getTrafficRank",{params:s}),getServerLastRank:()=>O.get(bt+"/stat/getServerLastRank"),getServerYesterdayRank:()=>O.get(bt+"/stat/getServerYesterdayRank")},Wt=window?.settings?.secure_path,ra={getList:()=>O.get(Wt+"/theme/getThemes"),getConfig:s=>O.post(Wt+"/theme/getThemeConfig",{name:s}),updateConfig:(s,n)=>O.post(Wt+"/theme/saveThemeConfig",{name:s,config:n}),upload:s=>{const n=new FormData;return n.append("file",s),O.post(Wt+"/theme/upload",n,{headers:{"Content-Type":"multipart/form-data"}})},drop:s=>O.post(Wt+"/theme/delete",{name:s})},Rt=window?.settings?.secure_path,Nt={getList:()=>O.get(Rt+"/server/manage/getNodes"),save:s=>O.post(Rt+"/server/manage/save",s),drop:s=>O.post(Rt+"/server/manage/drop",s),copy:s=>O.post(Rt+"/server/manage/copy",s),update:s=>O.post(Rt+"/server/manage/update",s),sort:s=>O.post(Rt+"/server/manage/sort",s)},bn=window?.settings?.secure_path,Ft={getList:()=>O.get(bn+"/server/group/fetch"),save:s=>O.post(bn+"/server/group/save",s),drop:s=>O.post(bn+"/server/group/drop",s)},yn=window?.settings?.secure_path,tn={getList:()=>O.get(yn+"/server/route/fetch"),save:s=>O.post(yn+"/server/route/save",s),drop:s=>O.post(yn+"/server/route/drop",s)},yt=window?.settings?.secure_path,wt={getList:()=>O.get(yt+"/payment/fetch"),getMethodList:()=>O.get(yt+"/payment/getPaymentMethods"),getMethodForm:s=>O.post(yt+"/payment/getPaymentForm",s),save:s=>O.post(yt+"/payment/save",s),drop:s=>O.post(yt+"/payment/drop",s),updateStatus:s=>O.post(yt+"/payment/show",s),sort:s=>O.post(yt+"/payment/sort",s)},Yt=window?.settings?.secure_path,ha={getList:()=>O.get(`${Yt}/notice/fetch`),save:s=>O.post(`${Yt}/notice/save`,s),drop:s=>O.post(`${Yt}/notice/drop`,{id:s}),updateStatus:s=>O.post(`${Yt}/notice/show`,{id:s}),sort:s=>O.post(`${Yt}/notice/sort`,{ids:s})},Et=window?.settings?.secure_path,qt={getList:()=>O.get(Et+"/knowledge/fetch"),getInfo:s=>O.get(Et+"/knowledge/fetch?id="+s),save:s=>O.post(Et+"/knowledge/save",s),drop:s=>O.post(Et+"/knowledge/drop",s),updateStatus:s=>O.post(Et+"/knowledge/show",s),sort:s=>O.post(Et+"/knowledge/sort",s)},Jt=window?.settings?.secure_path,Ts={getList:()=>O.get(Jt+"/plan/fetch"),save:s=>O.post(Jt+"/plan/save",s),update:s=>O.post(Jt+"/plan/update",s),drop:s=>O.post(Jt+"/plan/drop",s),sort:s=>O.post(Jt+"/plan/sort",{ids:s})},Vt=window?.settings?.secure_path,_t={getList:s=>O.post(Vt+"/order/fetch",s),getInfo:s=>O.post(Vt+"/order/detail",s),markPaid:s=>O.post(Vt+"/order/paid",s),makeCancel:s=>O.post(Vt+"/order/cancel",s),update:s=>O.post(Vt+"/order/update",s),assign:s=>O.post(Vt+"/order/assign",s)},Vs=window?.settings?.secure_path,Ms={getTemplates:s=>O.post(Vs+"/gift-card/templates",s),createTemplate:s=>O.post(Vs+"/gift-card/create-template",s),updateTemplate:s=>O.post(Vs+"/gift-card/update-template",s),deleteTemplate:s=>O.post(Vs+"/gift-card/delete-template",s),getCodes:s=>O.post(Vs+"/gift-card/codes",s),generateCodes:s=>s.download_csv?O.post(Vs+"/gift-card/generate-codes",s,{responseType:"blob"}):O.post(Vs+"/gift-card/generate-codes",s),toggleCode:s=>O.post(Vs+"/gift-card/toggle-code",s),exportCodes:s=>O.get(Vs+`/gift-card/export-codes?batch_id=${s}`,{responseType:"blob"}),getUsages:s=>O.post(Vs+"/gift-card/usages",s),getStatistics:s=>O.post(Vs+"/gift-card/statistics",s),getTypes:()=>O.get(Vs+"/gift-card/types")},Na=window?.settings?.secure_path,Ka={getList:s=>O.post(Na+"/coupon/fetch",s),save:s=>O.post(Na+"/coupon/generate",s),drop:s=>O.post(Na+"/coupon/drop",s),update:s=>O.post(Na+"/coupon/update",s)},Cs=window?.settings?.secure_path,Ys={getList:s=>O.post(`${Cs}/user/fetch`,s),update:s=>O.post(`${Cs}/user/update`,s),resetSecret:s=>O.post(`${Cs}/user/resetSecret`,{id:s}),generate:s=>s.download_csv?O.post(`${Cs}/user/generate`,s,{responseType:"blob"}):O.post(`${Cs}/user/generate`,s),getStats:s=>O.post(`${Cs}/stat/getStatUser`,s),destroy:s=>O.post(`${Cs}/user/destroy`,{id:s}),sendMail:s=>O.post(`${Cs}/user/sendMail`,s),dumpCSV:s=>O.post(`${Cs}/user/dumpCSV`,s,{responseType:"blob"}),batchBan:s=>O.post(`${Cs}/user/ban`,s)},pa={getLogs:s=>O.get(`${Cs}/traffic-reset/logs`,{params:s}),getStats:s=>O.get(`${Cs}/traffic-reset/stats`,{params:s}),resetUser:s=>O.post(`${Cs}/traffic-reset/reset-user`,s),getUserHistory:(s,n)=>O.get(`${Cs}/traffic-reset/user/${s}/history`,{params:n})},wa=window?.settings?.secure_path,zt={getList:s=>O.post(wa+"/ticket/fetch",s),getInfo:s=>O.get(wa+"/ticket/fetch?id= "+s),reply:s=>O.post(wa+"/ticket/reply",s),close:s=>O.post(wa+"/ticket/close",{id:s})},ms=window?.settings?.secure_path,Ce={getSettings:(s="")=>O.get(ms+"/config/fetch?key="+s),saveSettings:s=>O.post(ms+"/config/save",s),getEmailTemplate:()=>O.get(ms+"/config/getEmailTemplate"),sendTestMail:()=>O.post(ms+"/config/testSendMail"),setTelegramWebhook:()=>O.post(ms+"/config/setTelegramWebhook"),updateSystemConfig:s=>O.post(ms+"/config/save",s),getSystemStatus:()=>O.get(`${ms}/system/getSystemStatus`),getQueueStats:()=>O.get(`${ms}/system/getQueueStats`),getQueueWorkload:()=>O.get(`${ms}/system/getQueueWorkload`),getQueueMasters:()=>O.get(`${ms}/system/getQueueMasters`),getHorizonFailedJobs:s=>O.get(`${ms}/system/getHorizonFailedJobs`,{params:s}),getSystemLog:s=>O.get(`${ms}/system/getSystemLog`,{params:s}),getLogFiles:()=>O.get(`${ms}/log/files`),getLogContent:s=>O.get(`${ms}/log/fetch`,{params:s}),getLogClearStats:s=>O.get(`${ms}/system/getLogClearStats`,{params:s}),clearSystemLog:s=>O.post(`${ms}/system/clearSystemLog`,s)},Us=window?.settings?.secure_path,Hs={getPluginTypes:()=>O.get(`${Us}/plugin/types`),getPluginList:s=>{const n=s?{type:s}:{};return O.get(`${Us}/plugin/getPlugins`,{params:n})},uploadPlugin:s=>{const n=new FormData;return n.append("file",s),O.post(`${Us}/plugin/upload`,n,{headers:{"Content-Type":"multipart/form-data"}})},deletePlugin:s=>O.post(`${Us}/plugin/delete`,{code:s}),installPlugin:s=>O.post(`${Us}/plugin/install`,{code:s}),uninstallPlugin:s=>O.post(`${Us}/plugin/uninstall`,{code:s}),enablePlugin:s=>O.post(`${Us}/plugin/enable`,{code:s}),disablePlugin:s=>O.post(`${Us}/plugin/disable`,{code:s}),getPluginConfig:s=>O.get(`${Us}/plugin/config`,{params:{code:s}}),updatePluginConfig:(s,n)=>O.post(`${Us}/plugin/config`,{code:s,config:n}),upgradePlugin:s=>O.post(`${Us}/plugin/upgrade`,{code:s})};window?.settings?.secure_path;Bl.config({monaco:Gl});const cm=le({subscribe_template_singbox:T().optional().default(""),subscribe_template_clash:T().optional().default(""),subscribe_template_clashmeta:T().optional().default(""),subscribe_template_stash:T().optional().default(""),subscribe_template_surge:T().optional().default(""),subscribe_template_surfboard:T().optional().default("")}),kl=[{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"}],Tl={subscribe_template_singbox:"",subscribe_template_clash:"",subscribe_template_clashmeta:"",subscribe_template_stash:"",subscribe_template_surge:"",subscribe_template_surfboard:""};function dm(){const{t:s}=M("settings"),[n,t]=m.useState(!1),l=m.useRef(null),[a,i]=m.useState("singbox"),r=De({resolver:Le(cm),defaultValues:Tl,mode:"onChange"}),{data:d,isLoading:x}=oe({queryKey:["settings","client"],queryFn:()=>Ce.getSettings("subscribe_template")}),{mutateAsync:u}=Gs({mutationFn:Ce.saveSettings,onSuccess:()=>{A.success(s("common.autoSaved"))},onError:D=>{console.error("保存失败:",D),A.error(s("common.saveFailed"))}});m.useEffect(()=>{if(d?.data?.subscribe_template){const D=d.data.subscribe_template;Object.entries(D).forEach(([S,w])=>{if(S in Tl){const F=typeof w=="string"?w:"";r.setValue(S,F)}}),l.current=r.getValues()}},[d,r]);const o=m.useCallback(ze.debounce(async D=>{if(!l.current||!ze.isEqual(D,l.current)){t(!0);try{await u(D),l.current=D}catch(S){console.error("保存设置失败:",S)}finally{t(!1)}}},1500),[u]),c=m.useCallback(()=>{const D=r.getValues();o(D)},[r,o]),h=m.useCallback((D,S)=>e.jsx(g,{control:r.control,name:D,render:({field:w})=>e.jsxs(p,{children:[e.jsx(f,{className:"text-base",children:s(`subscribe_template.${D.replace("subscribe_template_","")}.title`)}),e.jsx(j,{children:e.jsx(Wl,{height:"500px",defaultLanguage:S,value:w.value||"",onChange:F=>{w.onChange(F||""),c()},options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0}})}),e.jsx(q,{children:s(`subscribe_template.${D.replace("subscribe_template_","")}.description`)}),e.jsx(E,{})]})}),[r.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(Re,{...r,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Dt,{value:a,onValueChange:i,className:"w-full",children:[e.jsx(xt,{className:"",children:kl.map(({key:D,label:S})=>e.jsx(Xe,{value:D,className:"text-xs",children:S},D))}),kl.map(({key:D,language:S})=>e.jsx(ks,{value:D,className:"mt-4",children:h(`subscribe_template_${D}`,S)},D))]}),n&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"h-2 w-2 animate-pulse rounded-full bg-blue-500"}),s("common.saving")]})]})})}function mm(){const{t:s}=M("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("subscribe_template.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe_template.description")})]}),e.jsx(Me,{}),e.jsx(dm,{})]})}const um=()=>e.jsx(sm,{children:e.jsx(qn,{})}),xm=To([{path:"/sign-in",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Dm);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(um,{}),children:[{path:"/",lazy:async()=>({Component:(await Te(()=>Promise.resolve().then(()=>Om),void 0,import.meta.url)).default}),errorElement:e.jsx(Lt,{}),children:[{index:!0,lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>lu);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(Lt,{}),children:[{path:"system",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>cu);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>xu);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>ju);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Nu);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Tu);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Ru);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Ou);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Uu);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Wu);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Zu);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe-template",element:e.jsx(mm,{})}]},{path:"payment",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>rx);return{default:s}},void 0,import.meta.url)).default})},{path:"plugin",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>cx);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>xx);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>bx);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Tx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(Lt,{}),children:[{path:"manage",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>nh);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>ch);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>ph);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(Lt,{}),children:[{path:"plan",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>wh);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Oh);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Wh);return{default:s}},void 0,import.meta.url)).default})},{path:"gift-card",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>hp);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(Lt,{}),children:[{path:"manage",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>Gp);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>ug);return{default:s}},void 0,import.meta.url)).default})},{path:"traffic-reset-logs",lazy:async()=>({Component:(await Te(async()=>{const{default:s}=await Promise.resolve().then(()=>jg);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:Lt},{path:"/404",Component:Nl},{path:"/503",Component:Wd},{path:"*",Component:Nl}]);function hm(){return O.get("/user/info")}const _n={token:xa()?.value||"",userInfo:null,isLoggedIn:!!xa()?.value,loading:!1,error:null},ia=Do("user/fetchUserInfo",async()=>(await hm()).data,{condition:(s,{getState:n})=>{const{user:t}=n();return!!t.token&&!t.loading}}),li=Fo({name:"user",initialState:_n,reducers:{setToken(s,n){s.token=n.payload,s.isLoggedIn=!!n.payload},resetUserState:()=>_n},extraReducers:s=>{s.addCase(ia.pending,n=>{n.loading=!0,n.error=null}).addCase(ia.fulfilled,(n,t)=>{n.loading=!1,n.userInfo=t.payload,n.error=null}).addCase(ia.rejected,(n,t)=>{if(n.loading=!1,n.error=t.error.message||"Failed to fetch user info",!n.token)return _n})}}),{setToken:pm,resetUserState:gm}=li.actions,fm=s=>s.user.userInfo,jm=li.reducer,ri=Po({reducer:{user:jm}});xa()?.value&&ri.dispatch(ia());Lo.use(Ro).use(Eo).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 vm=new Vo;Io.createRoot(document.getElementById("root")).render(e.jsx(Ma.StrictMode,{children:e.jsx(Mo,{client:vm,children:e.jsx(Oo,{store:ri,children:e.jsxs(Hd,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(zo,{router:xm}),e.jsx($o,{richColors:!0,position:"top-right"})]})})})}));const Pe=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:b("rounded-xl border bg-card text-card-foreground shadow",s),...n}));Pe.displayName="Card";const Ee=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:b("flex flex-col space-y-1.5 p-6",s),...n}));Ee.displayName="CardHeader";const Ae=m.forwardRef(({className:s,...n},t)=>e.jsx("h3",{ref:t,className:b("font-semibold leading-none tracking-tight",s),...n}));Ae.displayName="CardTitle";const it=m.forwardRef(({className:s,...n},t)=>e.jsx("p",{ref:t,className:b("text-sm text-muted-foreground",s),...n}));it.displayName="CardDescription";const Ve=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:b("p-6 pt-0",s),...n}));Ve.displayName="CardContent";const bm=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:b("flex items-center p-6 pt-0",s),...n}));bm.displayName="CardFooter";const k=m.forwardRef(({className:s,type:n,...t},l)=>e.jsx("input",{type:n,className:b("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:l,...t}));k.displayName="Input";const ii=m.forwardRef(({className:s,...n},t)=>{const[l,a]=m.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:l?"text":"password",className:b("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(P,{type:"button",size:"icon",variant:"ghost",className:"absolute right-1 top-1/2 h-6 w-6 -translate-y-1/2 rounded-md text-muted-foreground",onClick:()=>a(i=>!i),children:l?e.jsx(Ao,{size:18}):e.jsx(qo,{size:18})})]})});ii.displayName="PasswordInput";const ym=s=>O.post("/passport/auth/login",s);function _m({className:s,onForgotPassword:n,...t}){const l=et(),a=Yl(),{t:i}=M("auth"),r=le({email:T().min(1,{message:i("signIn.validation.emailRequired")}),password:T().min(1,{message:i("signIn.validation.passwordRequired")}).min(7,{message:i("signIn.validation.passwordLength")})}),d=De({resolver:Le(r),defaultValues:{email:"",password:""}});async function x(u){try{const{data:o}=await ym(u);om(o.auth_data),a(pm(o.auth_data)),await a(ia()).unwrap(),l("/")}catch(o){console.error("Login failed:",o),o.response?.data?.message&&d.setError("root",{message:o.response.data.message})}}return e.jsx("div",{className:b("grid gap-6",s),...t,children:e.jsx(Re,{...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(g,{control:d.control,name:"email",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:i("signIn.email")}),e.jsx(j,{children:e.jsx(k,{placeholder:i("signIn.emailPlaceholder"),autoComplete:"email",...u})}),e.jsx(E,{})]})}),e.jsx(g,{control:d.control,name:"password",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:i("signIn.password")}),e.jsx(j,{children:e.jsx(ii,{placeholder:i("signIn.passwordPlaceholder"),autoComplete:"current-password",...u})}),e.jsx(E,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(P,{variant:"link",type:"button",className:"px-0 text-sm font-normal text-muted-foreground hover:text-primary",onClick:n,children:i("signIn.forgotPassword")})}),e.jsx(P,{className:"w-full",size:"lg",loading:d.formState.isSubmitting,children:i("signIn.submit")})]})})})})}const he=Jl,hs=Xl,Nm=Ql,ot=Un,oi=m.forwardRef(({className:s,...n},t)=>e.jsx(Xa,{ref:t,className:b("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}));oi.displayName=Xa.displayName;const ue=m.forwardRef(({className:s,children:n,...t},l)=>e.jsxs(Nm,{children:[e.jsx(oi,{}),e.jsxs(Ya,{ref:l,className:b("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(Un,{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(xs,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ue.displayName=Ya.displayName;const je=({className:s,...n})=>e.jsx("div",{className:b("flex flex-col space-y-1.5 text-center sm:text-left",s),...n});je.displayName="DialogHeader";const qe=({className:s,...n})=>e.jsx("div",{className:b("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});qe.displayName="DialogFooter";const pe=m.forwardRef(({className:s,...n},t)=>e.jsx(Ja,{ref:t,className:b("text-lg font-semibold leading-none tracking-tight",s),...n}));pe.displayName=Ja.displayName;const Ge=m.forwardRef(({className:s,...n},t)=>e.jsx(Qa,{ref:t,className:b("text-sm text-muted-foreground",s),...n}));Ge.displayName=Qa.displayName;const Ut=St("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"}}),J=m.forwardRef(({className:s,variant:n,size:t,asChild:l=!1,...a},i)=>{const r=l?$n:"button";return e.jsx(r,{className:b(Ut({variant:n,size:t,className:s})),ref:i,...a})});J.displayName="Button";const Js=Uo,Zs=Ho,wm=Bo,Cm=m.forwardRef(({className:s,inset:n,children:t,...l},a)=>e.jsxs(lr,{ref:a,className:b("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",n&&"pl-8",s),...l,children:[t,e.jsx(rr,{className:"ml-auto h-4 w-4"})]}));Cm.displayName=lr.displayName;const Sm=m.forwardRef(({className:s,...n},t)=>e.jsx(ir,{ref:t,className:b("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}));Sm.displayName=ir.displayName;const Ws=m.forwardRef(({className:s,sideOffset:n=4,...t},l)=>e.jsx(Ko,{children:e.jsx(Zl,{ref:l,sideOffset:n,className:b("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})}));Ws.displayName=Zl.displayName;const Fe=m.forwardRef(({className:s,inset:n,...t},l)=>e.jsx(er,{ref:l,className:b("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}));Fe.displayName=er.displayName;const ci=m.forwardRef(({className:s,children:n,checked:t,...l},a)=>e.jsxs(ar,{ref:a,className:b("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,...l,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(nr,{children:e.jsx(kt,{className:"h-4 w-4"})})}),n]}));ci.displayName=ar.displayName;const km=m.forwardRef(({className:s,children:n,...t},l)=>e.jsxs(or,{ref:l,className:b("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(nr,{children:e.jsx(Go,{className:"h-4 w-4 fill-current"})})}),n]}));km.displayName=or.displayName;const an=m.forwardRef(({className:s,inset:n,...t},l)=>e.jsx(sr,{ref:l,className:b("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",s),...t}));an.displayName=sr.displayName;const dt=m.forwardRef(({className:s,...n},t)=>e.jsx(tr,{ref:t,className:b("-mx-1 my-1 h-px bg-muted",s),...n}));dt.displayName=tr.displayName;const On=({className:s,...n})=>e.jsx("span",{className:b("ml-auto text-xs tracking-widest opacity-60",s),...n});On.displayName="DropdownMenuShortcut";const Nn=[{code:"en-US",name:"English",flag:Wo,shortName:"EN"},{code:"zh-CN",name:"中文",flag:Yo,shortName:"CN"}];function di(){const{i18n:s}=M(),n=a=>{s.changeLanguage(a)},t=Nn.find(a=>a.code===s.language)||Nn[1],l=t.flag;return e.jsxs(Js,{children:[e.jsx(Zs,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 px-2 gap-1",children:[e.jsx(l,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:"text-sm font-medium",children:t.shortName})]})}),e.jsx(Ws,{align:"end",className:"w-[120px]",children:Nn.map(a=>{const i=a.flag,r=a.code===s.language;return e.jsxs(Fe,{onClick:()=>n(a.code),className:b("flex items-center gap-2 px-2 py-1.5 cursor-pointer",r&&"bg-accent"),children:[e.jsx(i,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:b("text-sm",r&&"font-medium"),children:a.name})]},a.code)})})]})}function Tm(){const[s,n]=m.useState(!1),{t}=M("auth"),l=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(di,{})}),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(Pe,{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(_m,{onForgotPassword:()=>n(!0)})]})]})]}),e.jsx(he,{open:s,onOpenChange:n,children:e.jsx(ue,{className:"max-w-[90vw] sm:max-w-lg",children:e.jsxs(je,{children:[e.jsx(pe,{children:t("signIn.resetPassword.title")}),e.jsx(Ge,{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:l}),e.jsx(J,{variant:"ghost",size:"icon",className:"absolute right-2 top-2 h-8 w-8 hover:bg-secondary-foreground/10",onClick:()=>lt(l).then(()=>{A.success(t("common:copy.success"))}),children:e.jsx(Jo,{className:"h-4 w-4"})})]})})]})})})]})}const Dm=Object.freeze(Object.defineProperty({__proto__:null,default:Tm},Symbol.toStringTag,{value:"Module"})),We=m.forwardRef(({className:s,fadedBelow:n=!1,fixedHeight:t=!1,...l},a)=>e.jsx("div",{ref:a,className:b("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),...l}));We.displayName="Layout";const Ye=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{ref:t,className:b("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...n}));Ye.displayName="LayoutHeader";const ts=m.forwardRef(({className:s,fixedHeight:n,...t},l)=>e.jsx("div",{ref:l,className:b("flex-1 overflow-hidden px-4 py-6 md:px-8",n&&"h-[calc(100%-var(--header-height))]",s),...t}));ts.displayName="LayoutBody";const mi=Qo,ui=Xo,xi=Zo,be=ec,ge=sc,fe=tc,xe=m.forwardRef(({className:s,sideOffset:n=4,...t},l)=>e.jsx(cr,{ref:l,sideOffset:n,className:b("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}));xe.displayName=cr.displayName;function nn(){const{pathname:s}=An();return{checkActiveNav:t=>{if(t==="/"&&s==="/")return!0;const l=t.replace(/^\//,""),a=s.replace(/^\//,"");return l?a.startsWith(l):!1}}}function hi({key:s,defaultValue:n}){const[t,l]=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,l]}function Fm(){const[s,n]=hi({key:"collapsed-sidebar-items",defaultValue:[]}),t=a=>!s.includes(a);return{isExpanded:t,toggleItem:a=>{t(a)?n([...s,a]):n(s.filter(i=>i!==a))}}}function Pm({links:s,isCollapsed:n,className:t,closeNav:l}){const{t:a}=M(),i=({sub:r,...d})=>{const x=`${a(d.title)}-${d.href}`;return n&&r?m.createElement(Em,{...d,sub:r,key:x,closeNav:l}):n?m.createElement(Rm,{...d,key:x,closeNav:l}):r?m.createElement(Lm,{...d,sub:r,key:x,closeNav:l}):m.createElement(pi,{...d,key:x,closeNav:l})};return e.jsx("div",{"data-collapsed":n,className:b("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(be,{delayDuration:0,children:e.jsx("nav",{className:"grid gap-1 group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2",children:s.map(i)})})})}function pi({title:s,icon:n,label:t,href:l,closeNav:a,subLink:i=!1}){const{checkActiveNav:r}=nn(),{t:d}=M();return e.jsxs(Xs,{to:l,onClick:a,className:b(Bt({variant:r(l)?"secondary":"ghost",size:"sm"}),"h-12 justify-start text-wrap rounded-none px-6",i&&"h-10 w-full border-l border-l-slate-500 px-2"),"aria-current":r(l)?"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 Lm({title:s,icon:n,label:t,sub:l,closeNav:a}){const{checkActiveNav:i}=nn(),{isExpanded:r,toggleItem:d}=Fm(),{t:x}=M(),u=!!l?.find(h=>i(h.href)),o=x(s),c=r(o)||u;return e.jsxs(mi,{open:c,onOpenChange:()=>d(o),children:[e.jsxs(ui,{className:b(Bt({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:b('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(dr,{stroke:1})})]}),e.jsx(xi,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:l.map(h=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(pi,{...h,subLink:!0,closeNav:a})},x(h.title)))})})]})}function Rm({title:s,icon:n,label:t,href:l,closeNav:a}){const{checkActiveNav:i}=nn(),{t:r}=M();return e.jsxs(ge,{delayDuration:0,children:[e.jsx(fe,{asChild:!0,children:e.jsxs(Xs,{to:l,onClick:a,className:b(Bt({variant:i(l)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[n,e.jsx("span",{className:"sr-only",children:r(s)})]})}),e.jsxs(xe,{side:"right",className:"flex items-center gap-4",children:[r(s),t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:r(t)})]})]})}function Em({title:s,icon:n,label:t,sub:l,closeNav:a}){const{checkActiveNav:i}=nn(),{t:r}=M(),d=!!l?.find(x=>i(x.href));return e.jsxs(Js,{children:[e.jsxs(ge,{delayDuration:0,children:[e.jsx(fe,{asChild:!0,children:e.jsx(Zs,{asChild:!0,children:e.jsx(P,{variant:d?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:n})})}),e.jsxs(xe,{side:"right",className:"flex items-center gap-4",children:[r(s)," ",t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:r(t)}),e.jsx(dr,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(Ws,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(an,{children:[r(s)," ",t?`(${r(t)})`:""]}),e.jsx(dt,{}),l.map(({title:x,icon:u,label:o,href:c})=>e.jsx(Fe,{asChild:!0,children:e.jsxs(Xs,{to:c,onClick:a,className:`${i(c)?"bg-secondary":""}`,children:[u," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:r(x)}),o&&e.jsx("span",{className:"ml-auto text-xs",children:r(o)})]})},`${r(x)}-${c}`))]})]})}const gi=[{title:"nav:dashboard",label:"",href:"/",icon:e.jsx(ac,{size:18})},{title:"nav:systemManagement",label:"",href:"",icon:e.jsx(ic,{size:18}),sub:[{title:"nav:systemConfig",label:"",href:"/config/system",icon:e.jsx(mr,{size:18})},{title:"nav:pluginManagement",label:"",href:"/config/plugin",icon:e.jsx(Hn,{size:18})},{title:"nav:themeConfig",label:"",href:"/config/theme",icon:e.jsx(nc,{size:18})},{title:"nav:noticeManagement",label:"",href:"/config/notice",icon:e.jsx(lc,{size:18})},{title:"nav:paymentConfig",label:"",href:"/config/payment",icon:e.jsx(hl,{size:18})},{title:"nav:knowledgeManagement",label:"",href:"/config/knowledge",icon:e.jsx(rc,{size:18})}]},{title:"nav:nodeManagement",label:"",href:"",icon:e.jsx(xr,{size:18}),sub:[{title:"nav:nodeManagement",label:"",href:"/server/manage",icon:e.jsx(oc,{size:18})},{title:"nav:permissionGroupManagement",label:"",href:"/server/group",icon:e.jsx(ur,{size:18})},{title:"nav:routeManagement",label:"",href:"/server/route",icon:e.jsx(cc,{size:18})}]},{title:"nav:subscriptionManagement",label:"",href:"",icon:e.jsx(xc,{size:18}),sub:[{title:"nav:planManagement",label:"",href:"/finance/plan",icon:e.jsx(dc,{size:18})},{title:"nav:orderManagement",label:"",href:"/finance/order",icon:e.jsx(hl,{size:18})},{title:"nav:couponManagement",label:"",href:"/finance/coupon",icon:e.jsx(mc,{size:18})},{title:"nav:giftCardManagement",label:"",href:"/finance/gift-card",icon:e.jsx(uc,{size:18})}]},{title:"nav:userManagement",label:"",href:"",icon:e.jsx(pc,{size:18}),sub:[{title:"nav:userManagement",label:"",href:"/user/manage",icon:e.jsx(hc,{size:18})},{title:"nav:ticketManagement",label:"",href:"/user/ticket",icon:e.jsx(hr,{size:18})}]}];function Vm({className:s,isCollapsed:n,setIsCollapsed:t}){const[l,a]=m.useState(!1),{t:i}=M();return m.useEffect(()=>{l?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[l]),e.jsxs("aside",{className:b(`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 ${l?"h-svh opacity-50":"h-0 opacity-0"} w-full bg-black md:hidden`}),e.jsxs(We,{className:`flex h-full flex-col ${l?"h-[100vh] md:h-full":""}`,children:[e.jsxs(Ye,{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(P,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":i("common:toggleNavigation"),"aria-controls":"sidebar-menu","aria-expanded":l,onClick:()=>a(r=>!r),children:l?e.jsx(gc,{}):e.jsx(fc,{})})]}),e.jsx(Pm,{id:"sidebar-menu",className:b("flex-1 overflow-auto overscroll-contain",l?"block":"hidden md:block","md:py-2"),closeNav:()=>a(!1),isCollapsed:n,links:gi}),e.jsx("div",{className:b("border-t border-border/50 bg-background","px-4 py-2.5 text-xs text-muted-foreground",l?"block":"hidden md:block",n?"text-center":"text-left"),children:e.jsxs("div",{className:b("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:b("whitespace-nowrap tracking-wide","transition-opacity duration-200",n&&"md:opacity-0"),children:["v",window?.settings?.version]})]})}),e.jsx(P,{onClick:()=>t(r=>!r),size:"icon",variant:"outline",className:"absolute -right-5 top-1/2 hidden rounded-full md:inline-flex","aria-label":i("common:toggleSidebar"),children:e.jsx(jc,{stroke:1.5,className:`h-5 w-5 ${n?"rotate-180":""}`})})]})]})}function Im(){const[s,n]=hi({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 Mm(){const[s,n]=Im();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(Vm,{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(qn,{})})]})}const Om=Object.freeze(Object.defineProperty({__proto__:null,default:Mm},Symbol.toStringTag,{value:"Module"})),st=m.forwardRef(({className:s,...n},t)=>e.jsx(_s,{ref:t,className:b("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...n}));st.displayName=_s.displayName;const zm=({children:s,...n})=>e.jsx(he,{...n,children:e.jsx(ue,{className:"overflow-hidden p-0",children:e.jsx(st,{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})})}),ht=m.forwardRef(({className:s,...n},t)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(vc,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(_s.Input,{ref:t,className:b("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})]}));ht.displayName=_s.Input.displayName;const tt=m.forwardRef(({className:s,...n},t)=>e.jsx(_s.List,{ref:t,className:b("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...n}));tt.displayName=_s.List.displayName;const pt=m.forwardRef((s,n)=>e.jsx(_s.Empty,{ref:n,className:"py-6 text-center text-sm",...s}));pt.displayName=_s.Empty.displayName;const ys=m.forwardRef(({className:s,...n},t)=>e.jsx(_s.Group,{ref:t,className:b("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}));ys.displayName=_s.Group.displayName;const Gt=m.forwardRef(({className:s,...n},t)=>e.jsx(_s.Separator,{ref:t,className:b("-mx-1 h-px bg-border",s),...n}));Gt.displayName=_s.Separator.displayName;const Be=m.forwardRef(({className:s,...n},t)=>e.jsx(_s.Item,{ref:t,className:b("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}));Be.displayName=_s.Item.displayName;function $m(){const s=[];for(const n of gi)if(n.href&&s.push(n),n.sub)for(const t of n.sub)s.push({...t,parent:n.title});return s}function ps(){const[s,n]=m.useState(!1),t=et(),l=$m(),{t:a}=M("search"),{t:i}=M("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 r=m.useCallback(d=>{n(!1),t(d)},[t]);return e.jsxs(e.Fragment,{children:[e.jsxs(J,{variant:"outline",className:"relative h-9 w-9 p-0 xl:h-10 xl:w-60 xl:justify-start xl:px-3 xl:py-2",onClick:()=>n(!0),children:[e.jsx(Kn,{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(zm,{open:s,onOpenChange:n,children:[e.jsx(ht,{placeholder:a("placeholder")}),e.jsxs(tt,{children:[e.jsx(pt,{children:a("noResults")}),e.jsx(ys,{heading:a("title"),children:l.map(d=>e.jsxs(Be,{value:`${d.parent?d.parent+" ":""}${d.title}`,onSelect:()=>r(d.href),children:[e.jsx("div",{className:"mr-2",children:d.icon}),e.jsx("span",{children:i(d.title)}),d.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:i(d.parent)})]},d.href))})]})]})]})}function os(){const{theme:s,setTheme:n}=Kd();return m.useEffect(()=>{const t=s==="dark"?"#020817":"#fff",l=document.querySelector("meta[name='theme-color']");l&&l.setAttribute("content",t)},[s]),e.jsxs(e.Fragment,{children:[e.jsx(P,{size:"icon",variant:"ghost",className:"rounded-full",onClick:()=>n(s==="light"?"dark":"light"),children:s==="light"?e.jsx(bc,{size:20}):e.jsx(yc,{size:20})}),e.jsx(di,{})]})}const fi=m.forwardRef(({className:s,...n},t)=>e.jsx(pr,{ref:t,className:b("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...n}));fi.displayName=pr.displayName;const ji=m.forwardRef(({className:s,...n},t)=>e.jsx(gr,{ref:t,className:b("aspect-square h-full w-full",s),...n}));ji.displayName=gr.displayName;const vi=m.forwardRef(({className:s,...n},t)=>e.jsx(fr,{ref:t,className:b("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...n}));vi.displayName=fr.displayName;function cs(){const s=et(),n=Yl(),t=_c(fm),{t:l}=M(["common"]),a=()=>{si(),n(gm()),s("/sign-in")},i=t?.email?.split("@")[0]||l("common:user"),r=i.substring(0,2).toUpperCase();return e.jsxs(Js,{children:[e.jsx(Zs,{asChild:!0,children:e.jsx(P,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(fi,{className:"h-8 w-8",children:[e.jsx(ji,{src:t?.avatar_url,alt:i}),e.jsx(vi,{children:r})]})})}),e.jsxs(Ws,{className:"w-56",align:"end",forceMount:!0,children:[e.jsx(an,{className:"font-normal",children:e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("p",{className:"text-sm font-medium leading-none",children:i}),e.jsx("p",{className:"text-xs leading-none text-muted-foreground",children:t?.email||l("common:defaultEmail")})]})}),e.jsx(dt,{}),e.jsx(Fe,{asChild:!0,children:e.jsxs(Xs,{to:"/config/system",children:[l("common:settings"),e.jsx(On,{children:"⌘S"})]})}),e.jsx(dt,{}),e.jsxs(Fe,{onClick:a,children:[l("common:logout"),e.jsx(On,{children:"⇧⌘Q"})]})]})]})}const ee=Nc,Fs=Pc,se=wc,X=m.forwardRef(({className:s,children:n,...t},l)=>e.jsxs(jr,{ref:l,className:b("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(Cc,{asChild:!0,children:e.jsx(Bn,{className:"h-4 w-4 opacity-50"})})]}));X.displayName=jr.displayName;const bi=m.forwardRef(({className:s,...n},t)=>e.jsx(yr,{ref:t,className:b("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(Fc,{className:"h-4 w-4"})}));bi.displayName=yr.displayName;const yi=m.forwardRef(({className:s,...n},t)=>e.jsx(_r,{ref:t,className:b("flex cursor-default items-center justify-center py-1",s),...n,children:e.jsx(Bn,{className:"h-4 w-4"})}));yi.displayName=_r.displayName;const Z=m.forwardRef(({className:s,children:n,position:t="popper",...l},a)=>e.jsx(Sc,{children:e.jsxs(vr,{ref:a,className:b("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,...l,children:[e.jsx(bi,{}),e.jsx(kc,{className:b("p-1",t==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx(yi,{})]})}));Z.displayName=vr.displayName;const Am=m.forwardRef(({className:s,...n},t)=>e.jsx(Nr,{ref:t,className:b("px-2 py-1.5 text-sm font-semibold",s),...n}));Am.displayName=Nr.displayName;const U=m.forwardRef(({className:s,children:n,...t},l)=>e.jsxs(br,{ref:l,className:b("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(Tc,{children:e.jsx(kt,{className:"h-4 w-4"})})}),e.jsx(Dc,{children:n})]}));U.displayName=br.displayName;const qm=m.forwardRef(({className:s,...n},t)=>e.jsx(wr,{ref:t,className:b("-mx-1 my-1 h-px bg-muted",s),...n}));qm.displayName=wr.displayName;function Rs({className:s,classNames:n,showOutsideDays:t=!0,captionLayout:l="label",buttonVariant:a="ghost",formatters:i,components:r,...d}){const x=Cr();return e.jsx(Lc,{showOutsideDays:t,className:b("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:l,formatters:{formatMonthDropdown:u=>u.toLocaleString("default",{month:"short"}),...i},classNames:{root:b("w-fit",x.root),months:b("relative flex flex-col gap-4 md:flex-row",x.months),month:b("flex w-full flex-col gap-4",x.month),nav:b("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",x.nav),button_previous:b(Ut({variant:a}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_previous),button_next:b(Ut({variant:a}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_next),month_caption:b("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",x.month_caption),dropdowns:b("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",x.dropdowns),dropdown_root:b("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:b("absolute inset-0 opacity-0",x.dropdown),caption_label:b("select-none font-medium",l==="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:b("flex",x.weekdays),weekday:b("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",x.weekday),week:b("mt-2 flex w-full",x.week),week_number_header:b("w-[--cell-size] select-none",x.week_number_header),week_number:b("text-muted-foreground select-none text-[0.8rem]",x.week_number),day:b("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:b("bg-accent rounded-l-md",x.range_start),range_middle:b("rounded-none",x.range_middle),range_end:b("bg-accent rounded-r-md",x.range_end),today:b("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",x.today),outside:b("text-muted-foreground aria-selected:text-muted-foreground",x.outside),disabled:b("text-muted-foreground opacity-50",x.disabled),hidden:b("invisible",x.hidden),...n},components:{Root:({className:u,rootRef:o,...c})=>e.jsx("div",{"data-slot":"calendar",ref:o,className:b(u),...c}),Chevron:({className:u,orientation:o,...c})=>o==="left"?e.jsx(Sr,{className:b("size-4",u),...c}):o==="right"?e.jsx(kr,{className:b("size-4",u),...c}):e.jsx(Tr,{className:b("size-4",u),...c}),DayButton:Um,WeekNumber:({children:u,...o})=>e.jsx("td",{...o,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:u})}),...r},...d})}function Um({className:s,day:n,modifiers:t,...l}){const a=Cr(),i=m.useRef(null);return m.useEffect(()=>{t.focused&&i.current?.focus()},[t.focused]),e.jsx(J,{ref:i,variant:"ghost",size:"icon","data-day":n.date.toLocaleDateString(),"data-selected-single":t.selected&&!t.range_start&&!t.range_end&&!t.range_middle,"data-range-start":t.range_start,"data-range-end":t.range_end,"data-range-middle":t.range_middle,className:b("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),...l})}const ls=Rc,rs=Ec,Ze=m.forwardRef(({className:s,align:n="center",sideOffset:t=4,...l},a)=>e.jsx(Vc,{children:e.jsx(Dr,{ref:a,align:n,sideOffset:t,className:b("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...l})}));Ze.displayName=Dr.displayName;const at={income:{main:"hsl(var(--primary))",gradient:{start:"hsl(var(--primary))",end:"transparent"}},commission:{main:"hsl(var(--secondary))",gradient:{start:"hsl(var(--secondary))",end:"transparent"}}},sa=s=>(s/100).toFixed(2),Hm=({active:s,payload:n,label:t})=>{const{t:l}=M();return s&&n&&n.length?e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-sm",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:t}),n.map((a,i)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"h-2 w-2 rounded-full",style:{backgroundColor:a.color}}),e.jsxs("span",{className:"text-muted-foreground",children:[l(a.name),":"]}),e.jsx("span",{className:"font-medium",children:a.name.includes(l("dashboard:overview.amount"))?`¥${sa(a.value)}`:l("dashboard:overview.transactions",{count:a.value})})]},i))]}):null},Km=[{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"}],Bm=(s,n)=>{const t=new Date;if(s==="custom"&&n)return{startDate:n.from,endDate:n.to};let l;switch(s){case"7d":l=Ks(t,7);break;case"30d":l=Ks(t,30);break;case"90d":l=Ks(t,90);break;case"180d":l=Ks(t,180);break;case"365d":l=Ks(t,365);break;default:l=Ks(t,30)}return{startDate:l,endDate:t}};function Gm(){const[s,n]=m.useState("amount"),[t,l]=m.useState("30d"),[a,i]=m.useState({from:Ks(new Date,7),to:new Date}),{t:r}=M(),{startDate:d,endDate:x}=Bm(t,a),{data:u}=oe({queryKey:["orderStat",{start_date:Oe(d,"yyyy-MM-dd"),end_date:Oe(x,"yyyy-MM-dd")}],queryFn:async()=>{const{data:o}=await Ha.getOrderStat({start_date:Oe(d,"yyyy-MM-dd"),end_date:Oe(x,"yyyy-MM-dd")});return o},refetchInterval:3e4});return e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Ae,{children:r("dashboard:overview.title")}),e.jsxs(it,{children:[u?.summary.start_date," ",r("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(ee,{value:t,onValueChange:o=>l(o),children:[e.jsx(X,{className:"w-[120px]",children:e.jsx(se,{placeholder:r("dashboard:overview.selectTimeRange")})}),e.jsx(Z,{children:Km.map(o=>e.jsx(U,{value:o.value,children:r(o.label)},o.value))})]}),t==="custom"&&e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(J,{variant:"outline",className:b("min-w-0 justify-start text-left font-normal",!a&&"text-muted-foreground"),children:[e.jsx(Ls,{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:[Oe(a.from,"yyyy-MM-dd")," -"," ",Oe(a.to,"yyyy-MM-dd")]}):Oe(a.from,"yyyy-MM-dd"):r("dashboard:overview.selectDate")})]})}),e.jsx(Ze,{className:"w-auto p-0",align:"end",children:e.jsx(Rs,{mode:"range",defaultMonth:a?.from,selected:{from:a?.from,to:a?.to},onSelect:o=>{o?.from&&o?.to&&i({from:o.from,to:o.to})},captionLayout:"dropdown",numberOfMonths:2})})]})]}),e.jsx(Dt,{value:s,onValueChange:o=>n(o),children:e.jsxs(xt,{children:[e.jsx(Xe,{value:"amount",children:r("dashboard:overview.amount")}),e.jsx(Xe,{value:"count",children:r("dashboard:overview.count")})]})})]})]})}),e.jsxs(Ve,{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:r("dashboard:overview.totalIncome")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",sa(u?.summary?.paid_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:r("dashboard:overview.totalTransactions",{count:u?.summary?.paid_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[r("dashboard:overview.avgOrderAmount")," ¥",sa(u?.summary?.avg_paid_amount||0)]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:r("dashboard:overview.totalCommission")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",sa(u?.summary?.commission_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:r("dashboard:overview.totalTransactions",{count:u?.summary?.commission_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[r("dashboard:overview.commissionRate")," ",u?.summary?.commission_rate.toFixed(2)||0,"%"]})]})]}),e.jsx("div",{className:"h-[400px] w-full",children:e.jsx(Ic,{width:"100%",height:"100%",children:e.jsxs(Mc,{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:at.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:at.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:at.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:at.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(Oc,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:o=>Oe(new Date(o),"MM-dd",{locale:qc})}),e.jsx(zc,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:o=>s==="amount"?`¥${sa(o)}`:r("dashboard:overview.transactions",{count:o})}),e.jsx($c,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(Ac,{content:e.jsx(Hm,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(pl,{type:"monotone",dataKey:"paid_total",name:r("dashboard:overview.orderAmount"),stroke:at.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(pl,{type:"monotone",dataKey:"commission_total",name:r("dashboard:overview.commissionAmount"),stroke:at.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(gl,{dataKey:"paid_count",name:r("dashboard:overview.orderCount"),fill:at.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(gl,{dataKey:"commission_count",name:r("dashboard:overview.commissionCount"),fill:at.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})]})]})}function we({className:s,...n}){return e.jsx("div",{className:b("animate-pulse rounded-md bg-primary/10",s),...n})}function Wm(){return e.jsxs(Pe,{children:[e.jsxs(Ee,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(we,{className:"h-4 w-[120px]"}),e.jsx(we,{className:"h-4 w-4"})]}),e.jsxs(Ve,{children:[e.jsx(we,{className:"h-8 w-[140px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(we,{className:"h-4 w-4"}),e.jsx(we,{className:"h-4 w-[100px]"})]})]})]})}function Ym(){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(Wm,{},n))})}var me=(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))(me||{});const Qt={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},Xt={0:"yellow-500",1:"blue-500",2:"red-500",3:"green-500",4:"green-500"};var Bs=(s=>(s[s.NEW=1]="NEW",s[s.RENEWAL=2]="RENEWAL",s[s.UPGRADE=3]="UPGRADE",s[s.RESET_FLOW=4]="RESET_FLOW",s))(Bs||{}),ye=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(ye||{});const Ca={0:"待确认",1:"发放中",2:"有效",3:"无效"},Sa={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var ns=(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))(ns||{});const Jm={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var ve=(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))(ve||{});const Is=[{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"}],Ss={shadowsocks:"#489851",vmess:"#CB3180",trojan:"#EBB749",hysteria:"#5684e6",vless:"#1a1a1a",tuic:"#00C853",socks:"#2196F3",naive:"#9C27B0",http:"#FF5722",mieru:"#4CAF50",anytls:"#7E57C2"};var Ps=(s=>(s[s.AMOUNT=1]="AMOUNT",s[s.PERCENTAGE=2]="PERCENTAGE",s))(Ps||{});const Qm={1:"按金额优惠",2:"按比例优惠"};var ct=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(ct||{}),js=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(js||{}),oa=(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))(oa||{});function nt({title:s,value:n,icon:t,trend:l,description:a,onClick:i,highlight:r,className:d}){return e.jsxs(Pe,{className:b("transition-colors",i&&"cursor-pointer hover:bg-muted/50",r&&"border-primary/50",d),onClick:i,children:[e.jsxs(Ee,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ae,{className:"text-sm font-medium",children:s}),t]}),e.jsxs(Ve,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n}),l?e.jsxs("div",{className:"flex items-center pt-1",children:[e.jsx(Bc,{className:b("h-4 w-4",l.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:b("ml-1 text-xs",l.isPositive?"text-emerald-500":"text-red-500"),children:[l.isPositive?"+":"-",Math.abs(l.value),"%"]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:l.label})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:a})]})]})}function Xm({className:s}){const n=et(),{t}=M(),{data:l,isLoading:a}=oe({queryKey:["dashboardStats"],queryFn:async()=>(await Ha.getStatsData()).data,refetchInterval:1e3*60*5});if(a||!l)return e.jsx(Ym,{});const i=()=>{const r=new URLSearchParams;r.set("commission_status",ye.PENDING.toString()),r.set("status",me.COMPLETED.toString()),r.set("commission_balance","gt:0"),n(`/finance/order?${r.toString()}`)};return e.jsxs("div",{className:b("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(nt,{title:t("dashboard:stats.todayIncome"),value:Qs(l.todayIncome),icon:e.jsx(Uc,{className:"h-4 w-4 text-emerald-500"}),trend:{value:l.dayIncomeGrowth,label:t("dashboard:stats.vsYesterday"),isPositive:l.dayIncomeGrowth>0}}),e.jsx(nt,{title:t("dashboard:stats.monthlyIncome"),value:Qs(l.currentMonthIncome),icon:e.jsx(Gn,{className:"h-4 w-4 text-blue-500"}),trend:{value:l.monthIncomeGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:l.monthIncomeGrowth>0}}),e.jsx(nt,{title:t("dashboard:stats.pendingTickets"),value:l.ticketPendingTotal,icon:e.jsx(Hc,{className:b("h-4 w-4",l.ticketPendingTotal>0?"text-orange-500":"text-muted-foreground")}),description:l.ticketPendingTotal>0?t("dashboard:stats.hasPendingTickets"):t("dashboard:stats.noPendingTickets"),onClick:()=>n("/user/ticket"),highlight:l.ticketPendingTotal>0}),e.jsx(nt,{title:t("dashboard:stats.pendingCommission"),value:l.commissionPendingTotal,icon:e.jsx(Kc,{className:b("h-4 w-4",l.commissionPendingTotal>0?"text-blue-500":"text-muted-foreground")}),description:l.commissionPendingTotal>0?t("dashboard:stats.hasPendingCommission"):t("dashboard:stats.noPendingCommission"),onClick:i,highlight:l.commissionPendingTotal>0}),e.jsx(nt,{title:t("dashboard:stats.monthlyNewUsers"),value:l.currentMonthNewUsers,icon:e.jsx(Oa,{className:"h-4 w-4 text-blue-500"}),trend:{value:l.userGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:l.userGrowth>0}}),e.jsx(nt,{title:t("dashboard:stats.totalUsers"),value:l.totalUsers,icon:e.jsx(Oa,{className:"h-4 w-4 text-muted-foreground"}),description:t("dashboard:stats.activeUsers",{count:l.activeUsers})}),e.jsx(nt,{title:t("dashboard:stats.monthlyUpload"),value:Ie(l.monthTraffic.upload),icon:e.jsx(At,{className:"h-4 w-4 text-emerald-500"}),description:t("dashboard:stats.todayTraffic",{value:Ie(l.todayTraffic.upload)})}),e.jsx(nt,{title:t("dashboard:stats.monthlyDownload"),value:Ie(l.monthTraffic.download),icon:e.jsx(ma,{className:"h-4 w-4 text-blue-500"}),description:t("dashboard:stats.todayTraffic",{value:Ie(l.todayTraffic.download)})})]})}const Ct=m.forwardRef(({className:s,children:n,...t},l)=>e.jsxs(Fr,{ref:l,className:b("relative overflow-hidden",s),...t,children:[e.jsx(Gc,{className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(Ba,{}),e.jsx(Wc,{})]}));Ct.displayName=Fr.displayName;const Ba=m.forwardRef(({className:s,orientation:n="vertical",...t},l)=>e.jsx(Pr,{ref:l,orientation:n,className:b("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(Yc,{className:"relative flex-1 rounded-full bg-border"})}));Ba.displayName=Pr.displayName;const zn={today:{getValue:()=>{const s=Qc();return{start:s,end:Xc(s,1)}}},last7days:{getValue:()=>{const s=new Date;return{start:Ks(s,7),end:s}}},last30days:{getValue:()=>{const s=new Date;return{start:Ks(s,30),end:s}}},custom:{getValue:()=>null}};function Dl({selectedRange:s,customDateRange:n,onRangeChange:t,onCustomRangeChange:l}){const{t:a}=M(),i={today:a("dashboard:trafficRank.today"),last7days:a("dashboard:trafficRank.last7days"),last30days:a("dashboard:trafficRank.last30days"),custom:a("dashboard:trafficRank.customRange")};return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsxs(ee,{value:s,onValueChange:t,children:[e.jsx(X,{className:"w-[120px]",children:e.jsx(se,{placeholder:a("dashboard:trafficRank.selectTimeRange")})}),e.jsx(Z,{position:"popper",className:"z-50",children:Object.entries(zn).map(([r])=>e.jsx(U,{value:r,children:i[r]},r))})]}),s==="custom"&&e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(J,{variant:"outline",className:b("min-w-0 justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(Ls,{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:[Oe(n.from,"yyyy-MM-dd")," -"," ",Oe(n.to,"yyyy-MM-dd")]}):Oe(n.from,"yyyy-MM-dd"):e.jsx("span",{children:a("dashboard:trafficRank.selectDateRange")})})]})}),e.jsx(Ze,{className:"w-auto p-0",align:"end",children:e.jsx(Rs,{mode:"range",defaultMonth:n?.from,selected:{from:n?.from,to:n?.to},onSelect:r=>{r?.from&&r?.to&&l({from:r.from,to:r.to})},numberOfMonths:2})})]})]})}const It=s=>`${(s/1024/1024/1024).toFixed(2)} GB`;function Zm({className:s}){const{t:n}=M(),[t,l]=m.useState("today"),[a,i]=m.useState({from:Ks(new Date,7),to:new Date}),[r,d]=m.useState("today"),[x,u]=m.useState({from:Ks(new Date,7),to:new Date}),o=m.useMemo(()=>t==="custom"?{start:a.from,end:a.to}:zn[t].getValue(),[t,a]),c=m.useMemo(()=>r==="custom"?{start:x.from,end:x.to}:zn[r].getValue(),[r,x]),{data:h}=oe({queryKey:["nodeTrafficRank",o.start,o.end],queryFn:()=>Ha.getNodeTrafficData({type:"node",start_time:ze.round(o.start.getTime()/1e3),end_time:ze.round(o.end.getTime()/1e3)}),refetchInterval:3e4}),{data:D}=oe({queryKey:["userTrafficRank",c.start,c.end],queryFn:()=>Ha.getNodeTrafficData({type:"user",start_time:ze.round(c.start.getTime()/1e3),end_time:ze.round(c.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:b("grid gap-4 md:grid-cols-2",s),children:[e.jsxs(Pe,{children:[e.jsx(Ee,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Ae,{className:"flex items-center text-base font-medium",children:[e.jsx(Jc,{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(Dl,{selectedRange:t,customDateRange:a,onRangeChange:l,onCustomRangeChange:i}),e.jsx(fl,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Ve,{className:"flex-1",children:h?.data?e.jsxs(Ct,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:h.data.map(S=>e.jsx(be,{delayDuration:200,children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:S.name}),e.jsxs("span",{className:b("ml-2 flex items-center text-xs font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?e.jsx(Pn,{className:"mr-1 h-3 w-3"}):e.jsx(Ln,{className:"mr-1 h-3 w-3"}),Math.abs(S.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${S.value/h.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:It(S.value)})]})]})})}),e.jsx(xe,{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:It(S.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:It(S.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:b("font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?"+":"",S.change,"%"]})]})})]})},S.id))}),e.jsx(Ba,{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(Pe,{children:[e.jsx(Ee,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Ae,{className:"flex items-center text-base font-medium",children:[e.jsx(Oa,{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(Dl,{selectedRange:r,customDateRange:x,onRangeChange:d,onCustomRangeChange:u}),e.jsx(fl,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Ve,{className:"flex-1",children:D?.data?e.jsxs(Ct,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:D.data.map(S=>e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:S.name}),e.jsxs("span",{className:b("ml-2 flex items-center text-xs font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?e.jsx(Pn,{className:"mr-1 h-3 w-3"}):e.jsx(Ln,{className:"mr-1 h-3 w-3"}),Math.abs(S.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${S.value/D.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:It(S.value)})]})]})})}),e.jsx(xe,{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:It(S.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:It(S.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[n("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:b("font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?"+":"",S.change,"%"]})]})})]})},S.id))}),e.jsx(Ba,{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 eu=St("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 H({className:s,variant:n,...t}){return e.jsx("div",{className:b(eu({variant:n}),s),...t})}const Ra=m.forwardRef(({className:s,value:n,...t},l)=>e.jsx(Lr,{ref:l,className:b("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...t,children:e.jsx(Zc,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(n||0)}%)`}})}));Ra.displayName=Lr.displayName;const Zn=m.forwardRef(({className:s,...n},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:b("w-full caption-bottom text-sm",s),...n})}));Zn.displayName="Table";const el=m.forwardRef(({className:s,...n},t)=>e.jsx("thead",{ref:t,className:b("[&_tr]:border-b",s),...n}));el.displayName="TableHeader";const sl=m.forwardRef(({className:s,...n},t)=>e.jsx("tbody",{ref:t,className:b("[&_tr:last-child]:border-0",s),...n}));sl.displayName="TableBody";const su=m.forwardRef(({className:s,...n},t)=>e.jsx("tfoot",{ref:t,className:b("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...n}));su.displayName="TableFooter";const rt=m.forwardRef(({className:s,...n},t)=>e.jsx("tr",{ref:t,className:b("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...n}));rt.displayName="TableRow";const tl=m.forwardRef(({className:s,...n},t)=>e.jsx("th",{ref:t,className:b("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}));tl.displayName="TableHead";const $t=m.forwardRef(({className:s,...n},t)=>e.jsx("td",{ref:t,className:b("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...n}));$t.displayName="TableCell";const tu=m.forwardRef(({className:s,...n},t)=>e.jsx("caption",{ref:t,className:b("mt-4 text-sm text-muted-foreground",s),...n}));tu.displayName="TableCaption";function _i({table:s}){const[n,t]=m.useState(""),{t:l}=M("common");m.useEffect(()=>{t((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const a=i=>{const r=parseInt(i);!isNaN(r)&&r>=1&&r<=s.getPageCount()?s.setPageIndex(r-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:l("table.pagination.selected",{selected:s.getFilteredSelectedRowModel().rows.length,total:s.getFilteredRowModel().rows.length})}),e.jsxs("div",{className:"flex flex-col-reverse items-center gap-4 sm:flex-row sm:gap-6 lg:gap-8",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:l("table.pagination.itemsPerPage")}),e.jsxs(ee,{value:`${s.getState().pagination.pageSize}`,onValueChange:i=>{s.setPageSize(Number(i))},children:[e.jsx(X,{className:"h-8 w-[70px]",children:e.jsx(se,{placeholder:s.getState().pagination.pageSize})}),e.jsx(Z,{side:"top",children:[10,20,30,40,50,100,500].map(i=>e.jsx(U,{value:`${i}`,children:i},i))})]})]}),e.jsxs("div",{className:"flex items-center justify-center space-x-2 text-sm font-medium",children:[e.jsx("span",{children:l("table.pagination.page")}),e.jsx(k,{type:"text",value:n,onChange:i=>t(i.target.value),onBlur:i=>a(i.target.value),onKeyDown:i=>{i.key==="Enter"&&a(i.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsx("span",{children:l("table.pagination.pageOf",{total:s.getPageCount()})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(P,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(0),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.firstPage")}),e.jsx(ed,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.previousPage")}),e.jsx(sd,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.nextPage")}),e.jsx(rr,{className:"h-4 w-4"})]}),e.jsxs(P,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(s.getPageCount()-1),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:l("table.pagination.lastPage")}),e.jsx(td,{className:"h-4 w-4"})]})]})]})]})}function ds({table:s,toolbar:n,draggable:t=!1,onDragStart:l,onDragEnd:a,onDragOver:i,onDragLeave:r,onDrop:d,showPagination:x=!0,isLoading:u=!1}){const{t:o}=M("common"),c=m.useRef(null),h=s.getAllColumns().filter(F=>F.getIsPinned()==="left"),D=s.getAllColumns().filter(F=>F.getIsPinned()==="right"),S=F=>h.slice(0,F).reduce((y,I)=>y+(I.getSize()??0),0),w=F=>D.slice(F+1).reduce((y,I)=>y+(I.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(Zn,{children:[e.jsx(el,{children:s.getHeaderGroups().map(F=>e.jsx(rt,{className:"hover:bg-transparent",children:F.headers.map((y,I)=>{const v=y.column.getIsPinned()==="left",_=y.column.getIsPinned()==="right",C=v?S(h.indexOf(y.column)):void 0,z=_?w(D.indexOf(y.column)):void 0;return e.jsx(tl,{colSpan:y.colSpan,style:{width:y.getSize(),...v&&{left:C},..._&&{right:z}},className:b("h-11 bg-card px-4 text-muted-foreground",(v||_)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",v&&"before:right-0",_&&"before:left-0"]),children:y.isPlaceholder?null:za(y.column.columnDef.header,y.getContext())},y.id)})},F.id))}),e.jsx(sl,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((F,y)=>e.jsx(rt,{"data-state":F.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:t,onDragStart:I=>l?.(I,y),onDragEnd:a,onDragOver:i,onDragLeave:r,onDrop:I=>d?.(I,y),children:F.getVisibleCells().map((I,v)=>{const _=I.column.getIsPinned()==="left",C=I.column.getIsPinned()==="right",z=_?S(h.indexOf(I.column)):void 0,V=C?w(D.indexOf(I.column)):void 0;return e.jsx($t,{style:{width:I.column.getSize(),..._&&{left:z},...C&&{right:V}},className:b("bg-card",(_||C)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",_&&"before:right-0",C&&"before:left-0"]),children:za(I.column.columnDef.cell,I.getContext())},I.id)})},F.id)):e.jsx(rt,{children:e.jsx($t,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:o("table.noData")})})})]})})}),x&&e.jsx(_i,{table:s})]})}const Ea=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"})},Zt=Rr(),ea=Rr();function ka({data:s,isLoading:n,searchKeyword:t,selectedLevel:l,total:a,currentPage:i,pageSize:r,onViewDetail:d,onPageChange:x,onPageSizeChange:u}){const{t:o}=M(),c=S=>{switch(S.toLowerCase()){case"info":return e.jsx(aa,{className:"h-4 w-4 text-blue-500"});case"warning":return e.jsx(na,{className:"h-4 w-4 text-yellow-500"});case"error":return e.jsx(Vn,{className:"h-4 w-4 text-red-500"});default:return e.jsx(aa,{className:"h-4 w-4 text-slate-500"})}},h=m.useMemo(()=>[Zt.accessor("level",{id:"level",header:()=>o("dashboard:systemLog.level"),size:80,cell:({getValue:S,row:w})=>{const F=S();return e.jsxs("div",{className:"flex items-center gap-1",children:[c(F),e.jsx("span",{className:b(F.toLowerCase()==="error"&&"text-red-600",F.toLowerCase()==="warning"&&"text-yellow-600",F.toLowerCase()==="info"&&"text-blue-600"),children:F})]})}}),Zt.accessor("created_at",{id:"created_at",header:()=>o("dashboard:systemLog.time"),size:160,cell:({getValue:S})=>Ea(S())}),Zt.accessor(S=>S.title||S.message||"",{id:"title",header:()=>o("dashboard:systemLog.logTitle"),cell:({getValue:S})=>e.jsx("span",{className:"inline-block max-w-[300px] truncate",children:S()})}),Zt.accessor("method",{id:"method",header:()=>o("dashboard:systemLog.method"),size:100,cell:({getValue:S})=>{const w=S();return w?e.jsx(H,{variant:"outline",className:b(w==="GET"&&"border-blue-200 bg-blue-50 text-blue-700",w==="POST"&&"border-green-200 bg-green-50 text-green-700",w==="PUT"&&"border-amber-200 bg-amber-50 text-amber-700",w==="DELETE"&&"border-red-200 bg-red-50 text-red-700"),children:w}):null}}),Zt.display({id:"actions",header:()=>o("dashboard:systemLog.action"),size:80,cell:({row:S})=>e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>d(S.original),"aria-label":o("dashboard:systemLog.viewDetail"),children:e.jsx(Rn,{className:"h-4 w-4"})})})],[o,d]),D=es({data:s,columns:h,getCoreRowModel:ss(),getPaginationRowModel:is(),pageCount:Math.ceil(a/r),manualPagination:!0,state:{pagination:m.useMemo(()=>({pageIndex:i-1,pageSize:r}),[i,r])},onPaginationChange:S=>{let w,F;if(typeof S=="function"){const y=S({pageIndex:i-1,pageSize:r});w=y.pageIndex,F=y.pageSize}else w=S.pageIndex,F=S.pageSize;F!==r?u(F):x(w+1)}});return e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(ds,{table:D,showPagination:!0,isLoading:n}),(t||l&&l!=="all")&&e.jsx("div",{className:"text-center text-sm text-muted-foreground",children:t&&l&&l!=="all"?o("dashboard:systemLog.filter.searchAndLevel",{keyword:t,level:l,count:a}):t?o("dashboard:systemLog.filter.searchOnly",{keyword:t,count:a}):o("dashboard:systemLog.filter.levelOnly",{level:l,count:a})})]})}function au(){const{t:s}=M(),[n,t]=m.useState(0),[l,a]=m.useState(!1),[i,r]=m.useState(1),[d]=m.useState(10),[x,u]=m.useState(null),[o,c]=m.useState(!1),[h,D]=m.useState(!1),[S,w]=m.useState(1),[F,y]=m.useState(10),[I,v]=m.useState(null),[_,C]=m.useState(!1),[z,V]=m.useState(""),[R,W]=m.useState(""),[N,L]=m.useState("all"),[ae,G]=m.useState(!1),[ne,_e]=m.useState(0),[gs,Ue]=m.useState("all"),[de,Es]=m.useState(1e3),[Ds,gt]=m.useState(!1),[As,ft]=m.useState(null),[jt,vt]=m.useState(!1);m.useEffect(()=>{const Q=setTimeout(()=>{W(z),z!==R&&w(1)},500);return()=>clearTimeout(Q)},[z]);const{data:B,isLoading:K,refetch:Se,isRefetching:Ke}=oe({queryKey:["systemStatus",n],queryFn:async()=>(await Ce.getSystemStatus()).data,refetchInterval:3e4}),{data:ke,isLoading:to,refetch:vg,isRefetching:ol}=oe({queryKey:["queueStats",n],queryFn:async()=>(await Ce.getQueueStats()).data,refetchInterval:3e4}),{data:cl,isLoading:ao,refetch:no}=oe({queryKey:["failedJobs",i,d],queryFn:async()=>{const Q=await Ce.getHorizonFailedJobs({current:i,page_size:d});return{data:Q.data,total:Q.total||0}},enabled:l}),{data:dl,isLoading:ga,refetch:lo}=oe({queryKey:["systemLogs",S,F,N,R],queryFn:async()=>{const Q={current:S,page_size:F};N&&N!=="all"&&(Q.level=N),R.trim()&&(Q.keyword=R.trim());const qs=await Ce.getSystemLog(Q);return{data:qs.data,total:qs.total||0}},enabled:h}),ml=cl?.data||[],ro=cl?.total||0,fa=dl?.data||[],ja=dl?.total||0,io=m.useMemo(()=>[ea.display({id:"failed_at",header:()=>s("dashboard:queue.details.time"),cell:({row:Q})=>Ea(Q.original.failed_at)}),ea.display({id:"queue",header:()=>s("dashboard:queue.details.queue"),cell:({row:Q})=>Q.original.queue}),ea.display({id:"name",header:()=>s("dashboard:queue.details.name"),cell:({row:Q})=>e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[150px] truncate",children:Q.original.name})}),e.jsx(xe,{children:e.jsx("span",{children:Q.original.name})})]})})}),ea.display({id:"exception",header:()=>s("dashboard:queue.details.exception"),cell:({row:Q})=>e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[200px] truncate",children:Q.original.exception.split(` `)[0]})}),e.jsx(xe,{className:"max-w-[300px] whitespace-pre-wrap",children:e.jsx("span",{children:Q.original.exception})})]})})}),ea.display({id:"actions",header:()=>s("dashboard:queue.details.action"),size:80,cell:({row:Q})=>e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>uo(Q.original),"aria-label":s("dashboard:queue.details.viewDetail"),children:e.jsx(Rn,{className:"h-4 w-4"})})})],[s]),ul=es({data:ml,columns:io,getCoreRowModel:ss(),getPaginationRowModel:is(),pageCount:Math.ceil(ro/d),manualPagination:!0,state:{pagination:{pageIndex:i-1,pageSize:d}},onPaginationChange:Q=>{if(typeof Q=="function"){const qs=Q({pageIndex:i-1,pageSize:d});xl(qs.pageIndex+1)}else xl(Q.pageIndex+1)}}),oo=()=>{t(Q=>Q+1)},xl=Q=>{r(Q)},va=Q=>{w(Q)},ba=Q=>{y(Q),w(1)},co=Q=>{L(Q),w(1)},mo=()=>{V(""),W(""),L("all"),w(1)},ya=Q=>{v(Q),C(!0)},uo=Q=>{u(Q),c(!0)},xo=async()=>{try{const Q=await Ce.getLogClearStats({days:ne,level:gs==="all"?void 0:gs});ft(Q.data),vt(!0)}catch(Q){console.error("Failed to get clear stats:",Q),A.error(s("dashboard:systemLog.getStatsFailed"))}},ho=async()=>{gt(!0);try{const{data:Q}=await Ce.clearSystemLog({days:ne,level:gs==="all"?void 0:gs,limit:de});Q&&(A.success(s("dashboard:systemLog.clearSuccess",{count:Q.cleared_count}),{duration:3e3}),G(!1),vt(!1),ft(null),Se())}catch(Q){console.error("Failed to clear logs:",Q),A.error(s("dashboard:systemLog.clearLogsFailed"))}finally{gt(!1)}};if(K||to)return e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx($a,{className:"h-6 w-6 animate-spin"})});const po=Q=>Q?e.jsx(Er,{className:"h-5 w-5 text-green-500"}):e.jsx(Vr,{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(Pe,{children:[e.jsxs(Ee,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(ad,{className:"h-5 w-5"}),s("dashboard:queue.title")]}),e.jsx(it,{children:s("dashboard:queue.status.description")})]}),e.jsx(J,{variant:"outline",size:"icon",onClick:oo,disabled:Ke||ol,children:e.jsx(vn,{className:b("h-4 w-4",(Ke||ol)&&"animate-spin")})})]}),e.jsx(Ve,{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:[po(ke?.status||!1),e.jsx("span",{className:"font-medium",children:s("dashboard:queue.status.running")})]}),e.jsx(H,{variant:ke?.status?"secondary":"destructive",children:ke?.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:ke?.wait?.default||0})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{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:ke?.recentJobs||0}),e.jsx(Ra,{value:(ke?.recentJobs||0)/(ke?.periods?.recentJobs||1)*100,className:"h-1"})]})}),e.jsx(xe,{children:e.jsx("p",{children:s("dashboard:queue.details.statisticsPeriod",{hours:ke?.periods?.recentJobs||0})})})]})}),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{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:ke?.jobsPerMinute||0}),e.jsx(Ra,{value:(ke?.jobsPerMinute||0)/(ke?.queueWithMaxThroughput?.throughput||1)*100,className:"h-1"})]})}),e.jsx(xe,{children:e.jsx("p",{children:s("dashboard:queue.details.maxThroughput",{value:ke?.queueWithMaxThroughput?.throughput||0})})})]})})]})]})})]}),e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(nd,{className:"h-5 w-5"}),s("dashboard:queue.jobDetails")]}),e.jsx(it,{children:s("dashboard:queue.details.description")})]}),e.jsx(Ve,{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:ke?.failedJobs||0}),e.jsx(Rn,{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:ke?.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:[ke?.queueWithMaxRuntime?.runtime||0,"s"]}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:ke?.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:[ke?.processes||0," /"," ",(ke?.processes||0)+(ke?.pausedMasters||0)]})]}),e.jsx(Ra,{value:(ke?.processes||0)/((ke?.processes||0)+(ke?.pausedMasters||0))*100,className:"mt-2 h-1"})]})]})})]})]}),e.jsxs(Pe,{children:[e.jsxs(Ee,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(En,{className:"h-5 w-5"}),s("dashboard:systemLog.title")]}),e.jsx(it,{children:s("dashboard:systemLog.description")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(J,{variant:"outline",onClick:()=>D(!0),children:s("dashboard:systemLog.viewAll")}),e.jsxs(J,{variant:"outline",onClick:()=>G(!0),className:"text-destructive hover:text-destructive",children:[e.jsx(vs,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.clearLogs")]})]})]}),e.jsx(Ve,{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(aa,{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:B?.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(na,{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:B?.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(Vn,{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:B?.logs?.error||0})]})]}),B?.logs&&B.logs.total>0&&e.jsxs("div",{className:"mt-3 text-center text-sm text-muted-foreground",children:[s("dashboard:systemLog.totalLogs"),": ",B.logs.total]})]})})]}),e.jsx(he,{open:l,onOpenChange:a,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(je,{children:e.jsx(pe,{children:s("dashboard:queue.details.failedJobsDetailTitle")})}),e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(ds,{table:ul,showPagination:!1,isLoading:ao}),e.jsx(_i,{table:ul}),ml.length===0&&e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:s("dashboard:queue.details.noFailedJobs")})]}),e.jsxs(qe,{children:[e.jsxs(J,{variant:"outline",onClick:()=>no(),children:[e.jsx(vn,{className:"mr-2 h-4 w-4"}),s("dashboard:common.refresh")]}),e.jsx(ot,{asChild:!0,children:e.jsx(J,{variant:"outline",children:s("common:close")})})]})]})}),e.jsx(he,{open:o,onOpenChange:c,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(je,{children:e.jsx(pe,{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(qe,{children:e.jsx(J,{variant:"outline",onClick:()=>c(!1),children:s("common:close")})})]})}),e.jsx(he,{open:h,onOpenChange:D,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(je,{children:e.jsx(pe,{children:s("dashboard:systemLog.title")})}),e.jsxs(Dt,{value:N,onValueChange:co,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(xt,{className:"grid w-auto grid-cols-4",children:[e.jsxs(Xe,{value:"all",className:"flex items-center gap-2",children:[e.jsx(En,{className:"h-4 w-4"}),s("dashboard:systemLog.tabs.all")]}),e.jsxs(Xe,{value:"info",className:"flex items-center gap-2",children:[e.jsx(aa,{className:"h-4 w-4 text-blue-500"}),s("dashboard:systemLog.tabs.info")]}),e.jsxs(Xe,{value:"warning",className:"flex items-center gap-2",children:[e.jsx(na,{className:"h-4 w-4 text-yellow-500"}),s("dashboard:systemLog.tabs.warning")]}),e.jsxs(Xe,{value:"error",className:"flex items-center gap-2",children:[e.jsx(Vn,{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(Kn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(k,{placeholder:s("dashboard:systemLog.search"),value:z,onChange:Q=>V(Q.target.value),className:"w-full md:w-64"})]})]}),e.jsx(ks,{value:"all",className:"mt-0",children:e.jsx(ka,{data:fa,isLoading:ga,searchKeyword:R,selectedLevel:N,total:ja,currentPage:S,pageSize:F,onViewDetail:ya,onPageChange:va,onPageSizeChange:ba})}),e.jsx(ks,{value:"info",className:"mt-0 overflow-x-auto",children:e.jsx(ka,{data:fa,isLoading:ga,searchKeyword:R,selectedLevel:N,total:ja,currentPage:S,pageSize:F,onViewDetail:ya,onPageChange:va,onPageSizeChange:ba})}),e.jsx(ks,{value:"warning",className:"mt-0",children:e.jsx(ka,{data:fa,isLoading:ga,searchKeyword:R,selectedLevel:N,total:ja,currentPage:S,pageSize:F,onViewDetail:ya,onPageChange:va,onPageSizeChange:ba})}),e.jsx(ks,{value:"error",className:"mt-0",children:e.jsx(ka,{data:fa,isLoading:ga,searchKeyword:R,selectedLevel:N,total:ja,currentPage:S,pageSize:F,onViewDetail:ya,onPageChange:va,onPageSizeChange:ba})})]}),e.jsxs(qe,{children:[e.jsxs(J,{variant:"outline",onClick:()=>lo(),children:[e.jsx(vn,{className:"mr-2 h-4 w-4"}),s("dashboard:common.refresh")]}),e.jsx(J,{variant:"outline",onClick:mo,children:s("dashboard:systemLog.filter.reset")}),e.jsx(ot,{asChild:!0,children:e.jsx(J,{variant:"outline",children:s("common:close")})})]})]})}),e.jsx(he,{open:_,onOpenChange:C,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(je,{children:e.jsx(pe,{children:s("dashboard:systemLog.detailTitle")})}),I&&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(aa,{className:"h-4 w-4"}),e.jsx("p",{className:"font-medium",children:I.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:Ea(I.created_at)||Ea(I.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:I.title||I.message||""})]}),(I.host||I.ip)&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[I.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:I.host})]}),I.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:I.ip})]})]}),I.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:I.uri})})]}),I.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(H,{variant:"outline",className:"text-base font-medium",children:I.method})})]}),I.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(I.data),null,2)}catch{return I.data}})()})})]}),I.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 Q=JSON.parse(I.context);if(Q.exception){const qs=Q.exception,Pt=qs["\0*\0message"]||"",go=qs["\0*\0file"]||"",fo=qs["\0*\0line"]||"";return`${Pt} File: ${go} @@ -13,7 +13,7 @@ stop=8 `).filter(ne=>ne.trim()!=="");N.onChange(G)}})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:d.control,name:"tls.server_name",render:({field:N})=>e.jsxs(p,{className:"flex-[2]",children:[e.jsx(f,{children:l("dynamic_form.anytls.tls.server_name.label","SNI")}),e.jsx(j,{children:e.jsx(k,{placeholder:l("dynamic_form.anytls.tls.server_name.placeholder","服务器名称"),...N})})]})}),e.jsx(g,{control:d.control,name:"tls.allow_insecure",render:({field:N})=>e.jsxs(p,{children:[e.jsx(f,{children:l("dynamic_form.anytls.tls.allow_insecure","允许不安全连接")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(j,{children:e.jsx(te,{checked:N.value,onCheckedChange:N.onChange})})})]})})]})]})})};return e.jsx(be,{children:W[s]?.()})};function Xx(){const{t:s}=M("server"),n=le({start:T().min(1,s("form.dynamic_rate.start_time_error")),end:T().min(1,s("form.dynamic_rate.end_time_error")),rate:T().min(1,s("form.dynamic_rate.multiplier_error")).refine(V=>!isNaN(parseFloat(V))&&isFinite(Number(V)),{message:s("form.dynamic_rate.multiplier_error_numeric")}).refine(V=>parseFloat(V)>=0,{message:s("form.dynamic_rate.multiplier_error_gte_zero")})}),t=le({id:Y().optional().nullable(),specific_key:T().optional().nullable(),code:T().optional(),show:ie().optional().nullable(),name:T().min(1,s("form.name.error")),rate:T().min(1,s("form.rate.error")).refine(V=>!isNaN(parseFloat(V))&&isFinite(Number(V)),{message:s("form.rate.error_numeric")}).refine(V=>parseFloat(V)>=0,{message:s("form.rate.error_gte_zero")}),rate_time_enable:ie().default(!1),rate_time_ranges:Qe(n).default([]),tags:Qe(T()).default([]),excludes:Qe(T()).default([]),ips:Qe(T()).default([]),group_ids:Qe(T()).default([]),host:T().min(1,s("form.host.error")),port:T().min(1,s("form.port.error")),server_port:T().min(1,s("form.server_port.error")),parent_id:T().default("0").nullable(),route_ids:Qe(T()).default([]),protocol_settings:Tt(Ht()).default({}).nullable(),listen_address:T().optional().default("")}),l={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,listen_address:""},{isOpen:a,setIsOpen:i,editingServer:r,setEditingServer:d,serverType:x,setServerType:u,refetch:o}=Ri(),[c,h]=m.useState([]),[D,S]=m.useState([]),[w,F]=m.useState([]),y=De({resolver:Le(t),defaultValues:l,mode:"onChange"});m.useEffect(()=>{I()},[a]),m.useEffect(()=>{r?.type&&r.type!==x&&u(r.type)},[r,x,u]),m.useEffect(()=>{r?r.type===x&&y.reset({...l,...r}):y.reset({...l,protocol_settings:$e[x].schema.parse({})})},[r,y,x]);const I=async()=>{if(!a)return;const[V,R,W]=await Promise.all([Ft.getList(),tn.getList(),Nt.getList()]);h(V.data?.map(N=>({label:N.name,value:N.id.toString()}))||[]),S(R.data?.map(N=>({label:N.remarks,value:N.id.toString()}))||[]),F(W.data||[])},v=m.useMemo(()=>w?.filter(V=>(V.parent_id===0||V.parent_id===null)&&V.type===x&&V.id!==y.watch("id")),[x,w,y]),_=()=>e.jsxs(Js,{children:[e.jsx(Zs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(He,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(Ws,{align:"start",children:e.jsx(wm,{children:Is.map(({type:V,label:R})=>e.jsx(Fe,{onClick:()=>{u(V),i(!0)},className:"cursor-pointer",children:e.jsx(H,{variant:"outline",className:"text-white",style:{background:Ss[V]},children:R})},V))})})]}),C=()=>{i(!1),d(null),y.reset(l)},z=async()=>{const V=y.getValues();(await Nt.save({...V,type:x})).data&&(C(),A.success(s("form.success")),o())};return e.jsxs(he,{open:a,onOpenChange:C,children:[_(),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(je,{children:[e.jsx(pe,{children:s(r?"form.edit_node":"form.new_node")}),e.jsx(Ge,{})]}),e.jsxs(Re,{...y,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{control:y.control,name:"name",render:({field:V})=>e.jsxs(p,{className:"flex-[2]",children:[e.jsx(f,{children:s("form.name.label")}),e.jsx(j,{children:e.jsx(k,{placeholder:s("form.name.placeholder"),...V})}),e.jsx(E,{})]})}),e.jsx(g,{control:y.control,name:"rate",render:({field:V})=>{const R=y.watch("parent_id")!="0"&&y.watch("parent_id")!==null;return e.jsxs(p,{className:"flex-[1]",children:[e.jsx("div",{className:"relative",children:e.jsx(f,{children:s("form.rate.label")})}),e.jsx(j,{children:e.jsxs("div",{className:"relative",children:[e.jsx(k,{type:"number",min:"0",step:"0.1",...V,disabled:R,className:R?"cursor-not-allowed bg-muted/50":""}),R&&e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2",children:e.jsx(He,{icon:"ph:lock-simple",className:"size-4 text-muted-foreground/60"})})]})}),e.jsx(E,{})]})}})]}),y.watch("parent_id")!="0"&&y.watch("parent_id")!==null&&e.jsxs("div",{className:"ml-auto flex w-fit items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(He,{icon:"ph:info",className:"size-3"}),s("form.rate.child_node_note")]})]}),e.jsx(g,{control:y.control,name:"rate_time_enable",render:({field:V})=>e.jsxs(p,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(f,{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(j,{children:e.jsx(te,{checked:V.value,onCheckedChange:V.onChange})})]}),e.jsx(E,{})]})}),y.watch("rate_time_enable")&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"",children:s("form.dynamic_rate.rules_label")}),e.jsxs(P,{type:"button",variant:"outline",size:"sm",onClick:()=>{const V=y.getValues("rate_time_ranges")||[];y.setValue("rate_time_ranges",[...V,{start:"00:00",end:"23:59",rate:"1"}])},children:[e.jsx(He,{icon:"ion:add",className:"mr-1 size-4"}),s("form.dynamic_rate.add_rule")]})]}),(y.watch("rate_time_ranges")||[]).map((V,R)=>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:R+1})}),e.jsx(P,{type:"button",variant:"ghost",size:"sm",onClick:()=>{const W=y.getValues("rate_time_ranges")||[];W.splice(R,1),y.setValue("rate_time_ranges",[...W])},children:e.jsx(He,{icon:"ion:trash-outline",className:"size-4"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(g,{control:y.control,name:`rate_time_ranges.${R}.start`,render:({field:W})=>e.jsxs(p,{children:[e.jsx(f,{className:"text-xs",children:s("form.dynamic_rate.start_time")}),e.jsx(j,{children:e.jsx(k,{type:"time",...W,className:"text-sm"})}),e.jsx(E,{})]})}),e.jsx(g,{control:y.control,name:`rate_time_ranges.${R}.end`,render:({field:W})=>e.jsxs(p,{children:[e.jsx(f,{className:"text-xs",children:s("form.dynamic_rate.end_time")}),e.jsx(j,{children:e.jsx(k,{type:"time",...W,className:"text-sm"})}),e.jsx(E,{})]})}),e.jsx(g,{control:y.control,name:`rate_time_ranges.${R}.rate`,render:({field:W})=>e.jsxs(p,{children:[e.jsx(f,{className:"text-xs",children:s("form.dynamic_rate.multiplier")}),e.jsx(j,{children:e.jsx(k,{type:"number",min:"0",step:"0.1",...W,className:"text-sm",placeholder:"1.0"})}),e.jsx(E,{})]})})]})]},R)),(y.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(g,{control:y.control,name:"code",render:({field:V})=>e.jsxs(p,{children:[e.jsxs(f,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(j,{children:e.jsx(k,{placeholder:s("form.code.placeholder"),...V,value:V.value||""})}),e.jsx(E,{})]})}),e.jsx(g,{control:y.control,name:"tags",render:({field:V})=>e.jsxs(p,{children:[e.jsx(f,{children:s("form.tags.label")}),e.jsx(j,{children:e.jsx(xn,{value:V.value,onChange:V.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(E,{})]})}),e.jsx(g,{control:y.control,name:"group_ids",render:({field:V})=>e.jsxs(p,{children:[e.jsxs(f,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(hn,{dialogTrigger:e.jsx(P,{variant:"link",children:s("form.groups.add")}),refetch:I})]}),e.jsx(j,{children:e.jsx(mt,{options:c,onChange:R=>V.onChange(R.map(W=>W.value)),value:c?.filter(R=>V.value.includes(R.value)),placeholder:s("form.groups.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.groups.empty")})})}),e.jsx(E,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex space-x-2",children:e.jsx(g,{control:y.control,name:"host",render:({field:V})=>e.jsxs(p,{className:"flex-1",children:[e.jsx(f,{children:s("form.host.label")}),e.jsx(j,{children:e.jsx(k,{placeholder:s("form.host.placeholder"),...V})}),e.jsx(E,{})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(g,{control:y.control,name:"port",render:({field:V})=>e.jsxs(p,{className:"flex-1",children:[e.jsxs(f,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(He,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(qa,{children:e.jsx(xe,{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(j,{children:e.jsx(k,{placeholder:s("form.port.placeholder"),...V})}),e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(P,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const R=V.value;R&&y.setValue("server_port",R)},children:e.jsx(He,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(xe,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(E,{})]})}),e.jsx(g,{control:y.control,name:"server_port",render:({field:V})=>e.jsxs(p,{className:"flex-1",children:[e.jsxs(f,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(He,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(qa,{children:e.jsx(xe,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(j,{children:e.jsx(k,{placeholder:s("form.server_port.placeholder"),...V})}),e.jsx(E,{})]})})]})]}),a&&e.jsx(Qx,{serverType:x,value:y.watch("protocol_settings"),onChange:V=>y.setValue("protocol_settings",V,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(g,{control:y.control,name:"parent_id",render:({field:V})=>e.jsxs(p,{children:[e.jsx(f,{children:s("form.parent.label")}),e.jsxs(ee,{onValueChange:V.onChange,value:V.value?.toString()||"0",children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(Z,{children:[e.jsx(U,{value:"0",children:s("form.parent.none")}),v?.map(R=>e.jsx(U,{value:R.id.toString(),className:"cursor-pointer",children:R.name},R.id))]})]}),e.jsx(E,{})]})}),e.jsx(g,{control:y.control,name:"route_ids",render:({field:V})=>e.jsxs(p,{children:[e.jsx(f,{children:s("form.route.label")}),e.jsx(j,{children:e.jsx(mt,{options:D,onChange:R=>V.onChange(R.map(W=>W.value)),value:D?.filter(R=>V.value.includes(R.value)),placeholder:s("form.route.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.route.empty")})})}),e.jsx(E,{})]})})]}),e.jsxs(qe,{className:"mt-6 flex flex-col gap-2 sm:flex-row sm:gap-0",children:[e.jsx(P,{type:"button",variant:"outline",onClick:C,className:"w-full sm:w-auto",children:s("form.cancel")}),e.jsx(P,{type:"submit",onClick:z,className:"w-full sm:w-auto",children:s("form.submit")})]})]})]})]})}function El({column:s,title:n,options:t}){const l=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(en,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(H,{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(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(st,{children:[e.jsx(ht,{placeholder:n}),e.jsxs(tt,{children:[e.jsx(pt,{children:"No results found."}),e.jsx(ys,{children:t.map(i=>{const r=a.has(i.value);return e.jsxs(Be,{onSelect:()=>{r?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:b("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",r?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(kt,{className:b("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),l?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Gt,{}),e.jsx(ys,{children:e.jsx(Be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const Zx=[{value:ve.Shadowsocks,label:Is.find(s=>s.type===ve.Shadowsocks)?.label,color:Ss[ve.Shadowsocks]},{value:ve.Vmess,label:Is.find(s=>s.type===ve.Vmess)?.label,color:Ss[ve.Vmess]},{value:ve.Trojan,label:Is.find(s=>s.type===ve.Trojan)?.label,color:Ss[ve.Trojan]},{value:ve.Hysteria,label:Is.find(s=>s.type===ve.Hysteria)?.label,color:Ss[ve.Hysteria]},{value:ve.Vless,label:Is.find(s=>s.type===ve.Vless)?.label,color:Ss[ve.Vless]},{value:ve.Tuic,label:Is.find(s=>s.type===ve.Tuic)?.label,color:Ss[ve.Tuic]},{value:ve.Socks,label:Is.find(s=>s.type===ve.Socks)?.label,color:Ss[ve.Socks]},{value:ve.Naive,label:Is.find(s=>s.type===ve.Naive)?.label,color:Ss[ve.Naive]},{value:ve.Http,label:Is.find(s=>s.type===ve.Http)?.label,color:Ss[ve.Http]},{value:ve.Mieru,label:Is.find(s=>s.type===ve.Mieru)?.label,color:Ss[ve.Mieru]}];function eh({table:s,saveOrder:n,isSortMode:t,groups:l}){const a=s.getState().columnFilters.length>0,{t:i}=M("server");return e.jsxs("div",{className:"flex items-center justify-between ",children:[e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[!t&&e.jsxs(e.Fragment,{children:[e.jsx(Xx,{}),e.jsx(k,{placeholder:i("toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:r=>s.getColumn("name")?.setFilterValue(r.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(El,{column:s.getColumn("type"),title:i("toolbar.type"),options:Zx}),s.getColumn("group_ids")&&e.jsx(El,{column:s.getColumn("group_ids"),title:i("columns.groups.title"),options:l.map(r=>({label:r.name,value:r.id.toString()}))})]}),a&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[i("toolbar.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]}),t&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sort.tip")})})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{variant:t?"default":"outline",onClick:n,size:"sm",children:i(t?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const Ga=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"})}),Ta={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"},Je=(s,n)=>n>0?Math.round(s/n*100):0,sh=s=>{const{t:n}=M("server");return[{id:"drag-handle",header:({column:t})=>e.jsx($,{column:t,title:n("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Za,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:t})=>e.jsx($,{column:t,title:n("columns.nodeId")}),cell:({row:t})=>{const l=t.getValue("id"),a=t.original.code;return e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(H,{variant:"outline",className:b("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:Ss[t.original.type]},children:[e.jsx(Ur,{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??l}),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(P,{variant:"ghost",size:"icon",className:"size-5 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:text-muted-foreground group-hover/id:opacity-100",onClick:i=>{i.stopPropagation(),lt(a||l.toString()).then(()=>{A.success(n("common:copy.success"))})},children:e.jsx(_a,{className:"size-3"})})]})}),e.jsxs(xe,{side:"top",className:"flex flex-col gap-2 p-3 ",children:[e.jsxs("p",{className:"font-medium",children:[Is.find(i=>i.type===t.original.type)?.label,t.original.parent?" (子节点)":""]}),e.jsxs("div",{className:"mt-1 grid gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:n("columns.customId")}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-mono text-xs font-medium max-w-[120px] truncate",children:a??"—"}),e.jsx(P,{variant:"ghost",size:"icon",className:"size-6 text-muted-foreground/60 hover:text-muted-foreground",onClick:i=>{i.stopPropagation(),a&<(a).then(()=>{A.success(n("common:copy.success"))})},disabled:!a,children:e.jsx(_a,{className:"size-3"})})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:n("columns.originalId")}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-mono text-xs font-semibold ",children:t.original.id}),e.jsx(P,{variant:"ghost",size:"icon",className:"size-6 text-muted-foreground/60 hover:text-muted-foreground",onClick:i=>{i.stopPropagation(),lt(String(t.original.id)).then(()=>{A.success(n("common:copy.success"))})},children:e.jsx(_a,{className:"size-3"})})]})]})]})]})]})})},size:50,enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx($,{column:t,title:n("columns.show")}),cell:({row:t})=>{const[l,a]=m.useState(!!t.getValue("show"));return e.jsx(te,{checked:l,onCheckedChange:async i=>{a(i),Nt.update({id:t.original.id,type:t.original.type,show:i?1:0}).catch(()=>{a(!i),s()})},style:{backgroundColor:l?Ss[t.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx($,{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:b("h-2.5 w-2.5 rounded-full",Ta[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:b("h-2.5 w-2.5 rounded-full",Ta[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:b("h-2.5 w-2.5 rounded-full",Ta[2])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.2")})]})]})})}),cell:({row:t})=>e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(fe,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:b("size-2.5 flex-shrink-0 rounded-full transition-all duration-200",Ta[t.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:t.getValue("name")})]})}),e.jsx(xe,{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:b("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:b("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:b("h-full transition-all duration-300",Je(t.original.load_status.mem.used,t.original.load_status.mem.total)>=90?"bg-destructive":Je(t.original.load_status.mem.used,t.original.load_status.mem.total)>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Je(t.original.load_status.mem.used,t.original.load_status.mem.total)}%`}})}),e.jsxs("span",{className:b("min-w-[3rem] text-right font-semibold",Je(t.original.load_status.mem.used,t.original.load_status.mem.total)>=90?"text-destructive":Je(t.original.load_status.mem.used,t.original.load_status.mem.total)>=70?"text-yellow-600":"text-emerald-600"),children:[Je(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:[Ie(t.original.load_status.mem.used)," ","/"," ",Ie(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:b("h-full transition-all duration-300",Je(t.original.load_status.swap.used,t.original.load_status.swap.total)>=80?"bg-destructive":Je(t.original.load_status.swap.used,t.original.load_status.swap.total)>=50?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Je(t.original.load_status.swap.used,t.original.load_status.swap.total)}%`}})}),e.jsxs("span",{className:b("min-w-[3rem] text-right font-semibold",Je(t.original.load_status.swap.used,t.original.load_status.swap.total)>=80?"text-destructive":Je(t.original.load_status.swap.used,t.original.load_status.swap.total)>=50?"text-yellow-600":"text-emerald-600"),children:[Je(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:[Ie(t.original.load_status.swap.used)," ","/"," ",Ie(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:b("h-full transition-all duration-300",Je(t.original.load_status.disk.used,t.original.load_status.disk.total)>=90?"bg-destructive":Je(t.original.load_status.disk.used,t.original.load_status.disk.total)>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Je(t.original.load_status.disk.used,t.original.load_status.disk.total)}%`}})}),e.jsxs("span",{className:b("min-w-[3rem] text-right font-semibold",Je(t.original.load_status.disk.used,t.original.load_status.disk.total)>=90?"text-destructive":Je(t.original.load_status.disk.used,t.original.load_status.disk.total)>=70?"text-yellow-600":"text-emerald-600"),children:[Je(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:[Ie(t.original.load_status.disk.used)," ","/"," ",Ie(t.original.load_status.disk.total)]})]})]})]})]})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:t})=>e.jsx($,{column:t,title:n("columns.address")}),cell:({row:t})=>{const l=`${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(be,{delayDuration:0,children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"icon",className:"size-6 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:bg-muted/50 hover:text-muted-foreground group-hover:opacity-100",onClick:i=>{i.stopPropagation(),lt(l).then(()=>{A.success(n("common:copy.success"))})},children:e.jsx(_a,{className:"size-3"})})}),e.jsx(xe,{side:"top",sideOffset:10,children:n("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:t})=>e.jsx($,{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(Ga,{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($,{column:t,title:n("columns.rate.title"),tooltip:n("columns.rate.tooltip")}),cell:({row:t})=>e.jsxs(H,{variant:"secondary",className:"font-medium",children:[t.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"group_ids",header:({column:t})=>e.jsx($,{column:t,title:n("columns.groups.title"),tooltip:n("columns.groups.tooltip")}),cell:({row:t})=>{const l=t.original.groups||[];return e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[l.map((a,i)=>e.jsx(H,{variant:"secondary",className:b("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:a.name},i)),l.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:n("columns.groups.empty")})]})},enableSorting:!1,filterFn:(t,l,a)=>{const i=t.getValue(l);return i?a.some(r=>i.includes(r)):!1}},{accessorKey:"type",header:({column:t})=>e.jsx($,{column:t,title:n("columns.type")}),cell:({row:t})=>{const l=t.getValue("type");return e.jsx(H,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:Ss[l]},children:l})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx($,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>{const{setIsOpen:l,setEditingServer:a,setServerType:i}=Ri();return e.jsx("div",{className:"flex justify-center",children:e.jsxs(Js,{modal:!1,children:[e.jsx(Zs,{asChild:!0,children:e.jsx(P,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Ua,{className:"size-4"})})}),e.jsxs(Ws,{align:"end",className:"w-40",children:[e.jsx(Fe,{className:"cursor-pointer",onClick:()=>{i(t.original.type),a(t.original),l(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(Sd,{className:"mr-2 size-4"}),n("columns.actions_dropdown.edit")]})}),e.jsxs(Fe,{className:"cursor-pointer",onClick:async()=>{Nt.copy({id:t.original.id}).then(({data:r})=>{r&&(A.success(n("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx(Jn,{className:"mr-2 size-4"}),n("columns.actions_dropdown.copy")]}),e.jsx(dt,{}),e.jsx(Fe,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:r=>r.preventDefault(),children:e.jsx(bs,{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()=>{Nt.drop({id:t.original.id}).then(({data:r})=>{r&&(A.success(n("columns.actions_dropdown.delete_success")),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(vs,{className:"mr-2 size-4"}),n("columns.actions_dropdown.delete.confirm")]})})})]})]})})},size:50}]};function th(){const[s,n]=m.useState({}),[t,l]=m.useState({"drag-handle":!1}),[a,i]=m.useState([]),[r,d]=m.useState({pageSize:500,pageIndex:0}),[x,u]=m.useState([]),[o,c]=m.useState(!1),[h,D]=m.useState({}),[S,w]=m.useState([]),{refetch:F}=oe({queryKey:["nodeList"],queryFn:async()=>{const{data:z}=await Nt.getList();return w(z),z}}),{data:y}=oe({queryKey:["groups"],queryFn:async()=>{const{data:z}=await Ft.getList();return z}});m.useEffect(()=>{l({"drag-handle":o,show:!o,host:!o,online:!o,rate:!o,groups:!o,type:!1,actions:!o}),D({name:o?2e3:200}),d({pageSize:o?99999:500,pageIndex:0})},[o]);const I=(z,V)=>{o&&(z.dataTransfer.setData("text/plain",V.toString()),z.currentTarget.classList.add("opacity-50"))},v=(z,V)=>{if(!o)return;z.preventDefault(),z.currentTarget.classList.remove("bg-muted");const R=parseInt(z.dataTransfer.getData("text/plain"));if(R===V)return;const W=[...S],[N]=W.splice(R,1);W.splice(V,0,N),w(W)},_=async()=>{if(!o){c(!0);return}const z=S?.map((V,R)=>({id:V.id,order:R+1}));Nt.sort(z).then(()=>{A.success("排序保存成功"),c(!1),F()}).finally(()=>{c(!1)})},C=es({data:S||[],columns:sh(F),state:{sorting:x,columnVisibility:t,rowSelection:s,columnFilters:a,columnSizing:h,pagination:r},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:u,onColumnFiltersChange:i,onColumnVisibilityChange:l,onColumnSizingChange:D,onPaginationChange:d,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Rx,{refetch:F,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ds,{table:C,toolbar:z=>e.jsx(eh,{table:z,refetch:F,saveOrder:_,isSortMode:o,groups:y||[]}),draggable:o,onDragStart:I,onDragEnd:z=>z.currentTarget.classList.remove("opacity-50"),onDragOver:z=>{z.preventDefault(),z.currentTarget.classList.add("bg-muted")},onDragLeave:z=>z.currentTarget.classList.remove("bg-muted"),onDrop:v,showPagination:!o})})})}function ah(){const{t:s}=M("server");return e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{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(th,{})})]})]})}const nh=Object.freeze(Object.defineProperty({__proto__:null,default:ah},Symbol.toStringTag,{value:"Module"}));function lh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:l}=M("group");return e.jsx("div",{className:"flex items-center justify-between space-x-4",children:e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(hn,{refetch:n}),e.jsx(k,{placeholder:l("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:b("h-8 w-[150px] lg:w-[250px]",t&&"border-primary/50 ring-primary/20")}),t&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("toolbar.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]})})}const rh=s=>{const{t:n}=M("group");return[{accessorKey:"id",header:({column:t})=>e.jsx($,{column:t,title:n("columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(H,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:t})=>e.jsx($,{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($,{column:t,title:n("columns.usersCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(Ga,{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($,{column:t,title:n("columns.serverCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(Ur,{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($,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(hn,{defaultValues:t.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ut,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(bs,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Ft.drop({id:t.original.id}).then(({data:l})=>{l&&(A.success(n("messages.updateSuccess")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(vs,{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 ih(){const[s,n]=m.useState({}),[t,l]=m.useState({}),[a,i]=m.useState([]),[r,d]=m.useState([]),{data:x,refetch:u,isLoading:o}=oe({queryKey:["serverGroupList"],queryFn:async()=>{const{data:h}=await Ft.getList();return h}}),c=es({data:x||[],columns:rh(u),state:{sorting:r,columnVisibility:t,rowSelection:s,columnFilters:a},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:l,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ds,{table:c,toolbar:h=>e.jsx(lh,{table:h,refetch:u}),isLoading:o})}function oh(){const{t:s}=M("group");return e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{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(ih,{})})]})]})}const ch=Object.freeze(Object.defineProperty({__proto__:null,default:oh},Symbol.toStringTag,{value:"Module"})),dh=s=>le({remarks:T().min(1,s("form.validation.remarks")),match:Qe(T()),action:Kt(["block","dns"]),action_value:T().optional()});function Ei({refetch:s,dialogTrigger:n,defaultValues:t={remarks:"",match:[],action:"block",action_value:""},type:l="create"}){const{t:a}=M("route"),i=De({resolver:Le(dh(a)),defaultValues:t,mode:"onChange"}),[r,d]=m.useState(!1);return e.jsxs(he,{open:r,onOpenChange:d,children:[e.jsx(hs,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(He,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(je,{children:[e.jsx(pe,{children:a(l==="edit"?"form.edit":"form.create")}),e.jsx(Ge,{})]}),e.jsxs(Re,{...i,children:[e.jsx(g,{control:i.control,name:"remarks",render:({field:x})=>e.jsxs(p,{className:"flex-[2]",children:[e.jsx(f,{children:a("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(j,{children:e.jsx(k,{type:"text",placeholder:a("form.remarksPlaceholder"),...x})})}),e.jsx(E,{})]})}),e.jsx(g,{control:i.control,name:"match",render:({field:x})=>e.jsxs(p,{className:"flex-[2]",children:[e.jsx(f,{children:a("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(j,{children:e.jsx($s,{className:"min-h-[120px]",placeholder:a("form.matchPlaceholder"),value:Array.isArray(x.value)?x.value.join(` `):"",onChange:u=>{const o=u.target.value.split(` `);x.onChange(o)}})})}),e.jsx(E,{})]})}),e.jsx(g,{control:i.control,name:"action",render:({field:x})=>e.jsxs(p,{children:[e.jsx(f,{children:a("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(j,{children:e.jsxs(ee,{onValueChange:x.onChange,defaultValue:x.value,children:[e.jsx(X,{children:e.jsx(se,{placeholder:a("form.actionPlaceholder")})}),e.jsxs(Z,{children:[e.jsx(U,{value:"block",children:a("actions.block")}),e.jsx(U,{value:"dns",children:a("actions.dns")})]})]})})}),e.jsx(E,{})]})}),i.watch("action")==="dns"&&e.jsx(g,{control:i.control,name:"action_value",render:({field:x})=>e.jsxs(p,{children:[e.jsx(f,{children:a("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(j,{children:e.jsx(k,{type:"text",placeholder:a("form.dnsPlaceholder"),...x})})})]})}),e.jsxs(qe,{children:[e.jsx(ot,{asChild:!0,children:e.jsx(P,{variant:"outline",children:a("form.cancel")})}),e.jsx(P,{type:"submit",onClick:()=>{const x=i.getValues(),u={...x,match:Array.isArray(x.match)?x.match.filter(o=>o.trim()!==""):[]};tn.save(u).then(({data:o})=>{o&&(d(!1),s&&s(),A.success(a(l==="edit"?"messages.updateSuccess":"messages.createSuccess")),i.reset())})},children:a("form.submit")})]})]})]})]})}function mh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:l}=M("route");return e.jsx("div",{className:"flex items-center justify-between ",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[e.jsx(Ei,{refetch:n}),e.jsx(k,{placeholder:l("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(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("toolbar.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]})})}function uh({columns:s,data:n,refetch:t}){const[l,a]=m.useState({}),[i,r]=m.useState({}),[d,x]=m.useState([]),[u,o]=m.useState([]),c=es({data:n,columns:s,state:{sorting:u,columnVisibility:i,rowSelection:l,columnFilters:d},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:x,onColumnVisibilityChange:r,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ds,{table:c,toolbar:h=>e.jsx(mh,{table:h,refetch:t})})}const xh=s=>{const{t:n}=M("route"),t={block:{icon:Td,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:kd,variant:"secondary",className:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-800"}};return[{accessorKey:"id",header:({column:l})=>e.jsx($,{column:l,title:n("columns.id")}),cell:({row:l})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(H,{variant:"outline",children:l.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:l})=>e.jsx($,{column:l,title:n("columns.remarks")}),cell:({row:l})=>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:l.original.remarks})}),enableHiding:!1,enableSorting:!1},{accessorKey:"action_value",header:({column:l})=>e.jsx($,{column:l,title:n("columns.action_value.title")}),cell:({row:l})=>{const a=l.original.action,i=l.original.action_value,r=l.original.match?.length||0;return e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("span",{className:"text-sm font-medium",children:a==="dns"&&i?n("columns.action_value.dns",{value:i}):a==="block"?e.jsx("span",{className:"text-destructive",children:n("columns.action_value.block")}):n("columns.action_value.direct")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("columns.matchRules",{count:r})})]})},enableHiding:!1,enableSorting:!1,size:300},{accessorKey:"action",header:({column:l})=>e.jsx($,{column:l,title:n("columns.action")}),cell:({row:l})=>{const a=l.getValue("action"),i=t[a]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(H,{variant:t[a]?.variant||"default",className:b("flex items-center gap-1.5 px-3 py-1 capitalize",t[a]?.className),children:[i&&e.jsx(i,{className:"h-3.5 w-3.5"}),n(`actions.${a}`)]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:n("columns.actions")}),cell:({row:l})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Ei,{defaultValues:l.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ut,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(bs,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{tn.drop({id:l.original.id}).then(({data:a})=>{a&&(A.success(n("messages.deleteSuccess")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(vs,{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 hh(){const{t:s}=M("route"),[n,t]=m.useState([]);function l(){tn.getList().then(({data:a})=>{t(a)})}return m.useEffect(()=>{l()},[]),e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{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(uh,{data:n,columns:xh(l),refetch:l})})]})]})}const ph=Object.freeze(Object.defineProperty({__proto__:null,default:hh},Symbol.toStringTag,{value:"Module"})),Vi=m.createContext(void 0);function gh({children:s,refreshData:n}){const[t,l]=m.useState(!1),[a,i]=m.useState(null);return e.jsx(Vi.Provider,{value:{isOpen:t,setIsOpen:l,editingPlan:a,setEditingPlan:i,refreshData:n},children:s})}function nl(){const s=m.useContext(Vi);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function fh({table:s,saveOrder:n,isSortMode:t}){const{setIsOpen:l}=nl(),{t:a}=M("subscribe");return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsxs(P,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>l(!0),children:[e.jsx(He,{icon:"ion:add"}),e.jsx("div",{children:a("plan.add")})]}),e.jsx(k,{placeholder:a("plan.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:i=>s.getColumn("name")?.setFilterValue(i.target.value),className:"h-8 w-[150px] lg:w-[250px]"})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{variant:t?"default":"outline",onClick:n,size:"sm",children:a(t?"plan.sort.save":"plan.sort.edit")})})]})}const Vl={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"}},jh=s=>{const{t:n}=M("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(Za,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx($,{column:t,title:n("plan.columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(H,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:t})=>e.jsx($,{column:t,title:n("plan.columns.show")}),cell:({row:t})=>e.jsx(te,{defaultChecked:t.getValue("show"),onCheckedChange:l=>{Ts.update({id:t.original.id,show:l}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:t})=>e.jsx($,{column:t,title:n("plan.columns.sell")}),cell:({row:t})=>e.jsx(te,{defaultChecked:t.getValue("sell"),onCheckedChange:l=>{Ts.update({id:t.original.id,sell:l}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:t})=>e.jsx($,{column:t,title:n("plan.columns.renew"),tooltip:n("plan.columns.renew_tooltip")}),cell:({row:t})=>e.jsx(te,{defaultChecked:t.getValue("renew"),onCheckedChange:l=>{Ts.update({id:t.original.id,renew:l}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:t})=>e.jsx($,{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($,{column:t,title:n("plan.columns.stats")}),cell:({row:t})=>{const l=t.getValue("users_count")||0,a=t.original.active_users_count||0,i=l>0?Math.round(a/l*100):0;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{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(Oa,{className:"h-3.5 w-3.5 text-slate-500"}),e.jsx("span",{className:"text-sm font-medium text-slate-700",children:l})]})}),e.jsx(xe,{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(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{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(Dd,{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(xe,{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:"当前仍在有效期内的活跃用户"}),l>0&&e.jsxs("p",{className:"text-xs font-medium text-green-600",children:["活跃率:",i,"%"]})]})})]})})]})},enableSorting:!0,size:120},{accessorKey:"group",header:({column:t})=>e.jsx($,{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(H,{variant:"secondary",className:b("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($,{column:t,title:n("plan.columns.price")}),cell:({row:t})=>{const l=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 l?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:a.map(({period:i,key:r,unit:d})=>l[r]!=null&&e.jsxs(H,{variant:"secondary",className:b("px-2 py-0.5 font-medium transition-colors text-nowrap",Vl[r].color,Vl[r].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[i," ¥",l[r],d]},r))}):e.jsx("div",{className:"flex items-center",children:e.jsx(H,{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($,{className:"justify-end",column:t,title:n("plan.columns.actions")}),cell:({row:t})=>{const{setIsOpen:l,setEditingPlan:a}=nl();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{a(t.original),l(!0)},children:[e.jsx(ut,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.edit")})]}),e.jsx(bs,{title:n("plan.columns.delete_confirm.title"),description:n("plan.columns.delete_confirm.description"),confirmText:n("plan.columns.delete"),variant:"destructive",onConfirm:async()=>{Ts.drop({id:t.original.id}).then(({data:i})=>{i&&(A.success(n("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(vs,{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")})]})})]})}}]},vh=le({id:Y().nullable(),group_id:fs([Y(),T()]).nullable().optional(),name:T().min(1).max(250),tags:Qe(T()).nullable().optional(),content:T().nullable().optional(),transfer_enable:fs([Y().min(0),T().min(1)]),prices:le({monthly:fs([Y(),T()]).nullable().optional(),quarterly:fs([Y(),T()]).nullable().optional(),half_yearly:fs([Y(),T()]).nullable().optional(),yearly:fs([Y(),T()]).nullable().optional(),two_yearly:fs([Y(),T()]).nullable().optional(),three_yearly:fs([Y(),T()]).nullable().optional(),onetime:fs([Y(),T()]).nullable().optional(),reset_traffic:fs([Y(),T()]).nullable().optional()}).default({}),speed_limit:fs([Y(),T()]).nullable().optional(),capacity_limit:fs([Y(),T()]).nullable().optional(),device_limit:fs([Y(),T()]).nullable().optional(),force_update:ie().optional(),reset_traffic_method:Y().nullable(),users_count:Y().optional(),active_users_count:Y().optional()}),ll=m.forwardRef(({className:s,...n},t)=>e.jsx(Hr,{ref:t,className:b("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(Fd,{className:b("flex items-center justify-center text-current"),children:e.jsx(kt,{className:"h-4 w-4"})})}));ll.displayName=Hr.displayName;const Da={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},Fa={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}},bh=[{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 yh(){const{isOpen:s,setIsOpen:n,editingPlan:t,setEditingPlan:l,refreshData:a}=nl(),[i,r]=m.useState(!1),{t:d}=M("subscribe"),x=De({resolver:Le(vh),defaultValues:{...Da,...t||{}},mode:"onChange"});m.useEffect(()=>{t?x.reset({...Da,...t}):x.reset(Da)},[t,x]);const u=new Wn({html:!0}),[o,c]=m.useState();async function h(){Ft.getList().then(({data:y})=>{c(y)})}m.useEffect(()=>{s&&h()},[s]);const D=async y=>{r(!0),Ts.save(y).then(({data:I})=>{I&&(A.success(d(t?"plan.form.submit.success.update":"plan.form.submit.success.add")),F(),a())}).finally(()=>{r(!1)})},S=y=>{const I=Object.values(y).map(v=>v?.message).filter(Boolean);A.error(I.join(` -`)||d("plan.form.submit.error.validation","表单校验失败"))},w=y=>{if(isNaN(y))return;const I=Object.entries(Fa).reduce((v,[_,C])=>{const z=y*C.months*C.discount;return{...v,[_]:z.toFixed(2)}},{});x.setValue("prices",I,{shouldDirty:!0})},F=()=>{n(!1),l(null),x.reset(Da)};return e.jsx(he,{open:s,onOpenChange:F,children:e.jsxs(ue,{children:[e.jsxs(je,{children:[e.jsx(pe,{children:d(t?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(Ge,{})]}),e.jsx(Re,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(D,S),children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:x.control,name:"name",render:({field:y})=>e.jsxs(p,{children:[e.jsx(f,{children:d("plan.form.name.label")}),e.jsx(j,{children:e.jsx(k,{placeholder:d("plan.form.name.placeholder"),...y})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"tags",render:({field:y})=>e.jsxs(p,{children:[e.jsx(f,{children:d("plan.form.tags.label","标签")}),e.jsx(j,{children:e.jsx(xn,{value:y.value||[],onChange:y.onChange,placeholder:d("plan.form.tags.placeholder","输入标签后按回车确认"),className:"w-full"})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"group_id",render:({field:y})=>e.jsxs(p,{children:[e.jsxs(f,{className:"flex items-center justify-between",children:[d("plan.form.group.label"),e.jsx(hn,{dialogTrigger:e.jsx(P,{variant:"link",children:d("plan.form.group.add")}),refetch:h})]}),e.jsxs(ee,{value:y.value?.toString()??"",onValueChange:I=>y.onChange(I?Number(I):null),children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:d("plan.form.group.placeholder")})})}),e.jsx(Z,{children:o?.map(I=>e.jsx(U,{value:I.id.toString(),children:I.name},I.id))})]}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"transfer_enable",render:({field:y})=>e.jsxs(p,{className:"flex-1",children:[e.jsx(f,{children:d("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(j,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.transfer.placeholder"),className:"rounded-r-none",...y})}),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(E,{})]})}),e.jsx(g,{control:x.control,name:"speed_limit",render:({field:y})=>e.jsxs(p,{className:"flex-1",children:[e.jsx(f,{children:d("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(j,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.speed.placeholder"),className:"rounded-r-none",...y,value:y.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(E,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:d("plan.form.price.title")}),e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(k,{type:"number",step:"0.01",placeholder:d("plan.form.price.base_price"),className:"h-7 w-32 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500",onChange:y=>{const I=parseFloat(y.target.value);w(I)}})]}),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const y=Object.keys(Fa).reduce((I,v)=>({...I,[v]:""}),{});x.setValue("prices",y,{shouldDirty:!0})},children:d("plan.form.price.clear.button")})}),e.jsx(xe,{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(Fa).filter(([y])=>!["onetime","reset_traffic"].includes(y)).map(([y,I])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(g,{control:x.control,name:`prices.${y}`,render:({field:v})=>e.jsxs(p,{children:[e.jsxs(f,{className:"text-xs font-medium text-muted-foreground",children:[d(`plan.columns.price_period.${y}`),e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",I.months===1?d("plan.form.price.period.monthly"):d("plan.form.price.period.months",{count:I.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(j,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,step:"0.01",...v,value:v.value??"",onChange:_=>v.onChange(_.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"})})]})]})})},y))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(Fa).filter(([y])=>["onetime","reset_traffic"].includes(y)).map(([y,I])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(g,{control:x.control,name:`prices.${y}`,render:({field:v})=>e.jsx(p,{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(f,{className:"text-xs font-medium",children:d(`plan.columns.price_period.${y}`)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:d(y==="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(j,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,step:"0.01",...v,value:v.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"})})]})]})})})},y))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(g,{control:x.control,name:"device_limit",render:({field:y})=>e.jsxs(p,{className:"flex-1",children:[e.jsx(f,{children:d("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(j,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.device.placeholder"),className:"rounded-r-none",...y,value:y.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(E,{})]})}),e.jsx(g,{control:x.control,name:"capacity_limit",render:({field:y})=>e.jsxs(p,{className:"flex-1",children:[e.jsx(f,{children:d("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(j,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.capacity.placeholder"),className:"rounded-r-none",...y,value:y.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(E,{})]})})]}),e.jsx(g,{control:x.control,name:"reset_traffic_method",render:({field:y})=>e.jsxs(p,{children:[e.jsx(f,{children:d("plan.form.reset_method.label")}),e.jsxs(ee,{value:y.value?.toString()??"null",onValueChange:I=>y.onChange(I=="null"?null:Number(I)),children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:d("plan.form.reset_method.placeholder")})})}),e.jsx(Z,{children:bh.map(I=>e.jsx(U,{value:I.value?.toString()??"null",children:d(`plan.form.reset_method.options.${I.label}`)},I.value))})]}),e.jsx(q,{className:"text-xs",children:d("plan.form.reset_method.description")}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"content",render:({field:y})=>{const[I,v]=m.useState(!1);return e.jsxs(p,{className:"space-y-2",children:[e.jsxs(f,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d("plan.form.content.label"),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",type:"button",onClick:()=>v(!I),children:I?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(xe,{side:"top",children:e.jsx("p",{className:"text-xs",children:d(I?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",type:"button",onClick:()=>{y.onChange(d("plan.form.content.template.content"))},children:d("plan.form.content.template.button")})}),e.jsx(xe,{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 ${I?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(j,{children:e.jsx(Yn,{style:{height:"400px"},value:y.value||"",renderHTML:_=>u.render(_),onChange:({text:_})=>y.onChange(_),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"})})}),I&&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(y.value||"")}})})]})]}),e.jsx(q,{className:"text-xs",children:d("plan.form.content.description")}),e.jsx(E,{})]})}})]}),e.jsx(qe,{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(g,{control:x.control,name:"force_update",render:({field:y})=>e.jsxs(p,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(j,{children:e.jsx(ll,{checked:y.value,onCheckedChange:y.onChange})}),e.jsx("div",{className:"",children:e.jsx(f,{className:"text-sm",children:d("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(P,{type:"button",variant:"outline",onClick:F,children:d("plan.form.submit.cancel")}),e.jsx(P,{type:"submit",disabled:i,children:d(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})})]})})}function _h(){const[s,n]=m.useState({}),[t,l]=m.useState({"drag-handle":!1}),[a,i]=m.useState([]),[r,d]=m.useState([]),[x,u]=m.useState(!1),[o,c]=m.useState({pageSize:20,pageIndex:0}),[h,D]=m.useState([]),{refetch:S}=oe({queryKey:["planList"],queryFn:async()=>{const{data:v}=await Ts.getList();return D(v),v}});m.useEffect(()=>{l({"drag-handle":x}),c({pageSize:x?99999:10,pageIndex:0})},[x]);const w=(v,_)=>{x&&(v.dataTransfer.setData("text/plain",_.toString()),v.currentTarget.classList.add("opacity-50"))},F=(v,_)=>{if(!x)return;v.preventDefault(),v.currentTarget.classList.remove("bg-muted");const C=parseInt(v.dataTransfer.getData("text/plain"));if(C===_)return;const z=[...h],[V]=z.splice(C,1);z.splice(_,0,V),D(z)},y=async()=>{if(!x){u(!0);return}const v=h?.map(_=>_.id);Ts.sort(v).then(()=>{A.success("排序保存成功"),u(!1),S()}).finally(()=>{u(!1)})},I=es({data:h||[],columns:jh(S),state:{sorting:r,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:o},enableRowSelection:!0,onPaginationChange:c,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:l,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}},pageCount:x?1:void 0});return e.jsx(gh,{refreshData:S,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(ds,{table:I,toolbar:v=>e.jsx(fh,{table:v,refetch:S,saveOrder:y,isSortMode:x}),draggable:x,onDragStart:w,onDragEnd:v=>v.currentTarget.classList.remove("opacity-50"),onDragOver:v=>{v.preventDefault(),v.currentTarget.classList.add("bg-muted")},onDragLeave:v=>v.currentTarget.classList.remove("bg-muted"),onDrop:F,showPagination:!x}),e.jsx(yh,{})]})})}function Nh(){const{t:s}=M("subscribe");return e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{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(_h,{})})]})]})}const wh=Object.freeze(Object.defineProperty({__proto__:null,default:Nh},Symbol.toStringTag,{value:"Module"})),Mt=[{value:me.PENDING,label:Qt[me.PENDING],icon:Pd,color:Xt[me.PENDING]},{value:me.PROCESSING,label:Qt[me.PROCESSING],icon:Kr,color:Xt[me.PROCESSING]},{value:me.COMPLETED,label:Qt[me.COMPLETED],icon:Mn,color:Xt[me.COMPLETED]},{value:me.CANCELLED,label:Qt[me.CANCELLED],icon:Br,color:Xt[me.CANCELLED]},{value:me.DISCOUNTED,label:Qt[me.DISCOUNTED],icon:Mn,color:Xt[me.DISCOUNTED]}],ta=[{value:ye.PENDING,label:Ca[ye.PENDING],icon:Ld,color:Sa[ye.PENDING]},{value:ye.PROCESSING,label:Ca[ye.PROCESSING],icon:Kr,color:Sa[ye.PROCESSING]},{value:ye.VALID,label:Ca[ye.VALID],icon:Mn,color:Sa[ye.VALID]},{value:ye.INVALID,label:Ca[ye.INVALID],icon:Br,color:Sa[ye.INVALID]}];function Pa({column:s,title:n,options:t}){const l=s?.getFacetedUniqueValues(),a=s?.getFilterValue(),i=Array.isArray(a)?new Set(a):a!==void 0?new Set([a]):new Set;return e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(en,{className:"mr-2 h-4 w-4"}),n,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:i.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:i.size>2?e.jsxs(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):t.filter(r=>i.has(r.value)).map(r=>e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:r.label},r.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(st,{children:[e.jsx(ht,{placeholder:n}),e.jsxs(tt,{children:[e.jsx(pt,{children:"No results found."}),e.jsx(ys,{children:t.map(r=>{const d=i.has(r.value);return e.jsxs(Be,{onSelect:()=>{const x=new Set(i);d?x.delete(r.value):x.add(r.value);const u=Array.from(x);s?.setFilterValue(u.length?u:void 0)},children:[e.jsx("div",{className:b("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(kt,{className:b("h-4 w-4")})}),r.icon&&e.jsx(r.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${r.color}`}),e.jsx("span",{children:r.label}),l?.get(r.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(r.value)})]},r.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Gt,{}),e.jsx(ys,{children:e.jsx(Be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Ch=le({email:T().min(1),plan_id:Y(),period:T(),total_amount:Y()}),Sh={email:"",plan_id:0,total_amount:0,period:""};function Ii({refetch:s,trigger:n,defaultValues:t}){const{t:l}=M("order"),[a,i]=m.useState(!1),r=De({resolver:Le(Ch),defaultValues:{...Sh,...t},mode:"onChange"}),[d,x]=m.useState([]);return m.useEffect(()=>{a&&Ts.getList().then(({data:u})=>{x(u)})},[a]),e.jsxs(he,{open:a,onOpenChange:i,children:[e.jsx(hs,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(He,{icon:"ion:add"}),e.jsx("div",{children:l("dialog.addOrder")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(je,{children:[e.jsx(pe,{children:l("dialog.assignOrder")}),e.jsx(Ge,{})]}),e.jsxs(Re,{...r,children:[e.jsx(g,{control:r.control,name:"email",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:l("dialog.fields.userEmail")}),e.jsx(j,{children:e.jsx(k,{placeholder:l("dialog.placeholders.email"),...u})})]})}),e.jsx(g,{control:r.control,name:"plan_id",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:l("dialog.fields.subscriptionPlan")}),e.jsx(j,{children:e.jsxs(ee,{value:u.value?u.value?.toString():void 0,onValueChange:o=>u.onChange(parseInt(o)),children:[e.jsx(X,{children:e.jsx(se,{placeholder:l("dialog.placeholders.plan")})}),e.jsx(Z,{children:d.map(o=>e.jsx(U,{value:o.id.toString(),children:o.name},o.id))})]})})]})}),e.jsx(g,{control:r.control,name:"period",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:l("dialog.fields.orderPeriod")}),e.jsx(j,{children:e.jsxs(ee,{value:u.value,onValueChange:u.onChange,children:[e.jsx(X,{children:e.jsx(se,{placeholder:l("dialog.placeholders.period")})}),e.jsx(Z,{children:Object.keys(Jm).map(o=>e.jsx(U,{value:o,children:l(`period.${o}`)},o))})]})})]})}),e.jsx(g,{control:r.control,name:"total_amount",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:l("dialog.fields.paymentAmount")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:l("dialog.placeholders.amount"),value:u.value/100,onChange:o=>u.onChange(parseFloat(o.currentTarget.value)*100)})}),e.jsx(E,{})]})}),e.jsxs(qe,{children:[e.jsx(P,{variant:"outline",onClick:()=>i(!1),children:l("dialog.actions.cancel")}),e.jsx(P,{type:"submit",onClick:()=>{r.handleSubmit(u=>{_t.assign(u).then(({data:o})=>{o&&(s&&s(),r.reset(),i(!1),A.success(l("dialog.messages.addSuccess")))})})()},children:l("dialog.actions.confirm")})]})]})]})]})}function kh({table:s,refetch:n}){const{t}=M("order"),l=s.getState().columnFilters.length>0,a=Object.values(Bs).filter(x=>typeof x=="number").map(x=>({label:t(`type.${Bs[x]}`),value:x,color:x===Bs.NEW?"green-500":x===Bs.RENEWAL?"blue-500":x===Bs.UPGRADE?"purple-500":"orange-500"})),i=Object.values(ns).map(x=>({label:t(`period.${x}`),value:x,color:x===ns.MONTH_PRICE?"slate-500":x===ns.QUARTER_PRICE?"cyan-500":x===ns.HALF_YEAR_PRICE?"indigo-500":x===ns.YEAR_PRICE?"violet-500":x===ns.TWO_YEAR_PRICE?"fuchsia-500":x===ns.THREE_YEAR_PRICE?"pink-500":x===ns.ONETIME_PRICE?"rose-500":"orange-500"})),r=Object.values(me).filter(x=>typeof x=="number").map(x=>({label:t(`status.${me[x]}`),value:x,icon:x===me.PENDING?Mt[0].icon:x===me.PROCESSING?Mt[1].icon:x===me.COMPLETED?Mt[2].icon:x===me.CANCELLED?Mt[3].icon:Mt[4].icon,color:x===me.PENDING?"yellow-500":x===me.PROCESSING?"blue-500":x===me.COMPLETED?"green-500":x===me.CANCELLED?"red-500":"green-500"})),d=Object.values(ye).filter(x=>typeof x=="number").map(x=>({label:t(`commission.${ye[x]}`),value:x,icon:x===ye.PENDING?ta[0].icon:x===ye.PROCESSING?ta[1].icon:x===ye.VALID?ta[2].icon:ta[3].icon,color:x===ye.PENDING?"yellow-500":x===ye.PROCESSING?"blue-500":x===ye.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ii,{refetch:n}),e.jsx(k,{placeholder:t("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:x=>s.getColumn("trade_no")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2",children:[s.getColumn("type")&&e.jsx(Pa,{column:s.getColumn("type"),title:t("table.columns.type"),options:a}),s.getColumn("period")&&e.jsx(Pa,{column:s.getColumn("period"),title:t("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(Pa,{column:s.getColumn("status"),title:t("table.columns.status"),options:r}),s.getColumn("commission_status")&&e.jsx(Pa,{column:s.getColumn("commission_status"),title:t("table.columns.commissionStatus"),options:d})]}),l&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("actions.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]})}function us({label:s,value:n,className:t,valueClassName:l}){return e.jsxs("div",{className:b("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:b("text-sm",l),children:n||"-"})]})}function Th({status:s}){const{t:n}=M("order"),t={[me.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[me.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[me.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[me.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[me.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(H,{variant:"secondary",className:b("font-medium",t[s]),children:n(`status.${me[s]}`)})}function Dh({id:s,trigger:n}){const[t,l]=m.useState(!1),[a,i]=m.useState(),{t:r}=M("order");return m.useEffect(()=>{(async()=>{if(t){const{data:x}=await _t.getInfo({id:s});i(x)}})()},[t,s]),e.jsxs(he,{onOpenChange:l,open:t,children:[e.jsx(hs,{asChild:!0,children:n}),e.jsxs(ue,{className:"max-w-xl",children:[e.jsxs(je,{className:"space-y-2",children:[e.jsx(pe,{className:"text-lg font-medium",children:r("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:[r("table.columns.tradeNo"),":",a?.trade_no]}),!!a?.status&&e.jsx(Th,{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:r("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(us,{label:r("dialog.fields.userEmail"),value:a?.user?.email?e.jsxs(Xs,{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(ua,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(us,{label:r("dialog.fields.orderPeriod"),value:a&&r(`period.${a.period}`)}),e.jsx(us,{label:r("dialog.fields.subscriptionPlan"),value:a?.plan?.name,valueClassName:"font-medium"}),e.jsx(us,{label:r("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:r("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(us,{label:r("dialog.fields.paymentAmount"),value:Qs(a?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(Me,{className:"my-2"}),e.jsx(us,{label:r("dialog.fields.balancePayment"),value:Qs(a?.balance_amount||0)}),e.jsx(us,{label:r("dialog.fields.discountAmount"),value:Qs(a?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(us,{label:r("dialog.fields.refundAmount"),value:Qs(a?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(us,{label:r("dialog.fields.deductionAmount"),value:Qs(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:r("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(us,{label:r("dialog.fields.createdAt"),value:re(a?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(us,{label:r("dialog.fields.updatedAt"),value:re(a?.updated_at),valueClassName:"font-mono text-xs"})]})]}),a?.commission_status!==void 0&&a?.commission_balance&&e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:r("dialog.commissionInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(us,{label:r("dialog.fields.commissionStatus"),value:e.jsx(H,{variant:"secondary",className:b("font-medium",a?.commission_status===ye.PENDING?"bg-yellow-100 text-yellow-800 hover:bg-yellow-100":a?.commission_status===ye.PROCESSING?"bg-blue-100 text-blue-800 hover:bg-blue-100":a?.commission_status===ye.VALID?"bg-green-100 text-green-800 hover:bg-green-100":a?.commission_status===ye.INVALID?"bg-red-100 text-red-800 hover:bg-red-100":"bg-orange-100 text-orange-800 hover:bg-orange-100"),children:a?.commission_status!==void 0?r(`commission.${ye[a.commission_status]}`):r("dialog.commissionStatusActive")})}),e.jsx(us,{label:r("dialog.fields.commissionAmount"),value:Qs(a?.commission_balance||0),valueClassName:"font-medium text-orange-600"}),a?.actual_commission_balance&&e.jsx(us,{label:r("dialog.fields.actualCommissionAmount"),value:Qs(a?.actual_commission_balance||0),valueClassName:"font-medium text-orange-700"}),a?.invite_user&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"my-2"}),e.jsx(us,{label:r("dialog.fields.inviteUser"),value:e.jsxs(Xs,{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(ua,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]})}),e.jsx(us,{label:r("dialog.fields.inviteUserId"),value:a?.invite_user?.id,valueClassName:"font-mono text-xs"})]})]})]})]})]})]})}const Il={color:"text-slate-700",bgColor:"bg-slate-100/80"},Fh={[Bs.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Bs.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Bs.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Bs.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Ph={[ns.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Lh=s=>me[s],Rh=s=>ye[s],Eh=s=>Bs[s],Vh=s=>{const{t:n}=M("order");return[{accessorKey:"trade_no",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.tradeNo")}),cell:({row:t})=>{const l=t.original.trade_no,a=l.length>6?`${l.slice(0,3)}...${l.slice(-3)}`:l;return e.jsx("div",{className:"flex items-center",children:e.jsx(Dh,{trigger:e.jsxs(J,{variant:"ghost",size:"sm",className:"flex h-8 items-center gap-1.5 px-2 font-medium text-primary transition-colors hover:bg-primary/10 hover:text-primary/80",children:[e.jsx("span",{className:"font-mono",children:a}),e.jsx(ua,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.type")}),cell:({row:t})=>{const l=t.getValue("type"),a=l!=null?Fh[l]??Il:Il,i=l!=null?Eh(l):void 0,r=i?n(`type.${i}`,{defaultValue:String(l)}):String(l??"-");return e.jsx(H,{variant:"secondary",className:b("font-medium transition-colors text-nowrap",a.color,a.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:r})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx($,{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($,{column:t,title:n("table.columns.period")}),cell:({row:t})=>{const l=t.getValue("period"),a=l!=null?Ph[l]:void 0;return e.jsx(H,{variant:"secondary",className:b("font-medium transition-colors text-nowrap",a?.color,a?.bgColor,"hover:bg-opacity-80"),children:l!=null?n(`period.${l}`,{defaultValue:String(l)}):"-"})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.amount")}),cell:({row:t})=>{const l=t.getValue("total_amount"),a=typeof l=="number"?(l/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($,{column:t,title:n("table.columns.status")}),e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(fe,{children:e.jsx(Ti,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(xe,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:t})=>{const l=Mt.find(a=>a.value===t.getValue("status"));return l?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l.icon&&e.jsx(l.icon,{className:`h-4 w-4 text-${l.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`status.${Lh(l.value)}`)})]}),l.value===me.PENDING&&e.jsxs(Js,{modal:!0,children:[e.jsx(Zs,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Ua,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(Ws,{align:"end",className:"w-[140px]",children:[e.jsx(Fe,{className:"cursor-pointer",onClick:async()=>{await _t.markPaid({trade_no:t.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(Fe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await _t.makeCancel({trade_no:t.original.trade_no}),s()},children:n("actions.cancel")})]})]})]}):e.jsx("span",{className:"text-muted-foreground",children:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.commission")}),cell:({row:t})=>{const l=t.getValue("commission_balance"),a=l?(l/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:l?`¥${a}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.commissionStatus")}),cell:({row:t})=>{const l=t.original.status,a=t.original.commission_balance,i=ta.find(r=>r.value===t.getValue("commission_status"));return a==0||!i?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i.icon&&e.jsx(i.icon,{className:`h-4 w-4 text-${i.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`commission.${Rh(i.value)}`)})]}),i.value===ye.PENDING&&l===me.COMPLETED&&e.jsxs(Js,{modal:!0,children:[e.jsx(Zs,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Ua,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(Ws,{align:"end",className:"w-[120px]",children:[e.jsx(Fe,{className:"cursor-pointer",onClick:async()=>{await _t.update({trade_no:t.original.trade_no,commission_status:ye.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(Fe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await _t.update({trade_no:t.original.trade_no,commission_status:ye.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.createdAt")}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:re(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function Ih(){const[s]=Gr(),[n,t]=m.useState({}),[l,a]=m.useState({}),[i,r]=m.useState([]),[d,x]=m.useState([]),[u,o]=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(([y,I])=>{const v=s.get(y);return v?{id:y,value:I==="number"?parseInt(v):v}:null}).filter(Boolean);F.length>0&&r(F)},[s]);const{refetch:c,data:h,isLoading:D}=oe({queryKey:["orderList",u,i,d],queryFn:()=>_t.getList({pageSize:u.pageSize,current:u.pageIndex+1,filter:i,sort:d})}),S=es({data:h?.data??[],columns:Vh(c),state:{sorting:d,columnVisibility:l,rowSelection:n,columnFilters:i,pagination:u},rowCount:h?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:r,onColumnVisibilityChange:a,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),onPaginationChange:o,getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ds,{table:S,toolbar:e.jsx(kh,{table:S,refetch:c}),showPagination:!0})}function Mh(){const{t:s}=M("order");return e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Ih,{})})]})]})}const Oh=Object.freeze(Object.defineProperty({__proto__:null,default:Mh},Symbol.toStringTag,{value:"Module"}));function zh({column:s,title:n,options:t}){const l=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(en,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(H,{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(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(st,{children:[e.jsx(ht,{placeholder:n}),e.jsxs(tt,{children:[e.jsx(pt,{children:"No results found."}),e.jsx(ys,{children:t.map(i=>{const r=a.has(i.value);return e.jsxs(Be,{onSelect:()=>{r?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:b("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",r?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(kt,{className:b("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),l?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Gt,{}),e.jsx(ys,{children:e.jsx(Be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const $h=s=>le({id:ce.number().nullable().optional(),name:T().min(1,s("form.name.required")),code:T().nullable(),type:ce.number(),value:ce.number(),started_at:ce.number(),ended_at:ce.number(),limit_use:fs([T(),Y()]).nullable(),limit_use_with_user:fs([T(),Y()]).nullable(),generate_count:ce.number().nullable().optional(),limit_plan_ids:Qe(ce.number()).default([]).nullable(),limit_period:Qe(Rd(oa)).default([]).nullable()}).refine(n=>n.ended_at>n.started_at,{message:s("form.validity.endTimeError"),path:["ended_at"]}),Ml={name:"",code:null,type:Ps.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},Ah=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 Mi({defaultValues:s,refetch:n,type:t="create",dialogTrigger:l=null,open:a,onOpenChange:i}){const{t:r}=M("coupon"),[d,x]=m.useState(!1),u=a??d,o=i??x,[c,h]=m.useState([]),D=$h(r),S=Ah(r),w=De({resolver:Le(D),defaultValues:s||Ml});m.useEffect(()=>{s&&w.reset(s)},[s,w]),m.useEffect(()=>{Ts.getList().then(({data:_})=>h(_))},[]);const F=_=>{if(!_)return;const C=(z,V)=>{const R=new Date(V*1e3);return z.setHours(R.getHours(),R.getMinutes(),R.getSeconds()),Math.floor(z.getTime()/1e3)};_.from&&w.setValue("started_at",C(_.from,w.watch("started_at"))),_.to&&w.setValue("ended_at",C(_.to,w.watch("ended_at")))},y=_=>{const C=new Date,z=Math.floor(C.getTime()/1e3),V=Math.floor((C.getTime()+_*24*60*60*1e3)/1e3);w.setValue("started_at",z),w.setValue("ended_at",V)},I=async _=>{const C=await Ka.save(_);if(_.generate_count&&typeof C=="string"){const z=new Blob([C],{type:"text/csv;charset=utf-8;"}),V=document.createElement("a");V.href=window.URL.createObjectURL(z),V.download=`coupons_${new Date().getTime()}.csv`,V.click(),window.URL.revokeObjectURL(V.href)}o(!1),t==="create"&&w.reset(Ml),n()},v=(_,C)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:C}),e.jsx(k,{type:"datetime-local",step:"1",value:re(w.watch(_),"YYYY-MM-DDTHH:mm:ss"),onChange:z=>{const V=new Date(z.target.value);w.setValue(_,Math.floor(V.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(he,{open:u,onOpenChange:o,children:[l&&e.jsx(hs,{asChild:!0,children:l}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsx(je,{children:e.jsx(pe,{children:r(t==="create"?"form.add":"form.edit")})}),e.jsx(Re,{...w,children:e.jsxs("form",{onSubmit:w.handleSubmit(I),className:"space-y-4",children:[e.jsx(g,{control:w.control,name:"name",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.name.label")}),e.jsx(k,{placeholder:r("form.name.placeholder"),..._}),e.jsx(E,{})]})}),t==="create"&&e.jsx(g,{control:w.control,name:"generate_count",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.generateCount.label")}),e.jsx(k,{type:"number",min:0,placeholder:r("form.generateCount.placeholder"),..._,value:_.value??"",onChange:C=>_.onChange(C.target.value===""?null:parseInt(C.target.value)),className:"h-9"}),e.jsx(q,{className:"text-xs",children:r("form.generateCount.description")}),e.jsx(E,{})]})}),(!w.watch("generate_count")||w.watch("generate_count")==null)&&e.jsx(g,{control:w.control,name:"code",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.code.label")}),e.jsx(k,{placeholder:r("form.code.placeholder"),..._,value:_.value??"",className:"h-9"}),e.jsx(q,{className:"text-xs",children:r("form.code.description")}),e.jsx(E,{})]})}),e.jsxs(p,{children:[e.jsx(f,{children:r("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(g,{control:w.control,name:"type",render:({field:_})=>e.jsxs(ee,{value:_.value.toString(),onValueChange:C=>{const z=_.value,V=parseInt(C);_.onChange(V);const R=w.getValues("value");R&&(z===Ps.AMOUNT&&V===Ps.PERCENTAGE?w.setValue("value",R/100):z===Ps.PERCENTAGE&&V===Ps.AMOUNT&&w.setValue("value",R*100))},children:[e.jsx(X,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(se,{placeholder:r("form.type.placeholder")})}),e.jsx(Z,{children:Object.entries(Qm).map(([C,z])=>e.jsx(U,{value:C,children:r(`table.toolbar.types.${C}`)},C))})]})}),e.jsx(g,{control:w.control,name:"value",render:({field:_})=>{const C=_.value==null?"":w.watch("type")===Ps.AMOUNT&&typeof _.value=="number"?(_.value/100).toString():_.value.toString();return e.jsx(k,{type:"number",placeholder:r("form.value.placeholder"),..._,value:C,onChange:z=>{const V=z.target.value;if(V===""){_.onChange("");return}const R=parseFloat(V);isNaN(R)||_.onChange(w.watch("type")===Ps.AMOUNT?Math.round(R*100):R)},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:w.watch("type")==Ps.AMOUNT?"¥":"%"})})]})]}),e.jsxs(p,{children:[e.jsx(f,{children:r("form.validity.label")}),e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(P,{variant:"outline",className:b("w-full justify-start text-left font-normal",!w.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(Ls,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"truncate",children:[re(w.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",r("form.validity.to")," ",re(w.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})]})}),e.jsxs(Ze,{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:r("form.timeRange.quickSet")}),e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-6",children:S.map(_=>e.jsx(P,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>y(_.days),type:"button",children:_.label},_.days))})]}),e.jsx("div",{className:"hidden border-b border-border sm:block",children:e.jsx(Rs,{mode:"range",selected:{from:new Date(w.watch("started_at")*1e3),to:new Date(w.watch("ended_at")*1e3)},onSelect:F,numberOfMonths:2})}),e.jsx("div",{className:"border-b border-border sm:hidden",children:e.jsx(Rs,{mode:"range",selected:{from:new Date(w.watch("started_at")*1e3),to:new Date(w.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:[v("started_at",r("table.validity.startTime")),e.jsx("div",{className:"text-center text-sm text-muted-foreground sm:mt-6",children:r("form.validity.to")}),v("ended_at",r("table.validity.endTime"))]})})]})]}),e.jsx(E,{})]}),e.jsx(g,{control:w.control,name:"limit_use",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.limitUse.label")}),e.jsx(k,{type:"number",min:0,placeholder:r("form.limitUse.placeholder"),..._,value:_.value??"",onChange:C=>_.onChange(C.target.value===""?null:parseInt(C.target.value)),className:"h-9"}),e.jsx(q,{className:"text-xs",children:r("form.limitUse.description")}),e.jsx(E,{})]})}),e.jsx(g,{control:w.control,name:"limit_use_with_user",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.limitUseWithUser.label")}),e.jsx(k,{type:"number",min:0,placeholder:r("form.limitUseWithUser.placeholder"),..._,value:_.value??"",onChange:C=>_.onChange(C.target.value===""?null:parseInt(C.target.value)),className:"h-9"}),e.jsx(q,{className:"text-xs",children:r("form.limitUseWithUser.description")}),e.jsx(E,{})]})}),e.jsx(g,{control:w.control,name:"limit_period",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.limitPeriod.label")}),e.jsx(mt,{options:Object.entries(oa).filter(([C])=>isNaN(Number(C))).map(([C,z])=>({label:r(`coupon:period.${z}`),value:C})),onChange:C=>{if(C.length===0){_.onChange([]);return}const z=C.map(V=>oa[V.value]);_.onChange(z)},value:(_.value||[]).map(C=>({label:r(`coupon:period.${C}`),value:Object.entries(oa).find(([z,V])=>V===C)?.[0]||""})),placeholder:r("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:r("form.limitPeriod.empty")})}),e.jsx(q,{className:"text-xs",children:r("form.limitPeriod.description")}),e.jsx(E,{})]})}),e.jsx(g,{control:w.control,name:"limit_plan_ids",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.limitPlan.label")}),e.jsx(mt,{options:c?.map(C=>({label:C.name,value:C.id.toString()}))||[],onChange:C=>_.onChange(C.map(z=>Number(z.value))),value:(c||[]).filter(C=>(_.value||[]).includes(C.id)).map(C=>({label:C.name,value:C.id.toString()})),placeholder:r("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:r("form.limitPlan.empty")})}),e.jsx(E,{})]})}),e.jsx(qe,{children:e.jsx(P,{type:"submit",disabled:w.formState.isSubmitting,children:w.formState.isSubmitting?r("form.submit.saving"):r("form.submit.save")})})]})})]})]})}function qh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:l}=M("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Mi,{refetch:n,dialogTrigger:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(He,{icon:"ion:add"}),e.jsx("div",{children:l("form.add")})]})}),e.jsx(k,{placeholder:l("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(zh,{column:s.getColumn("type"),title:l("table.toolbar.type"),options:[{value:Ps.AMOUNT,label:l(`table.toolbar.types.${Ps.AMOUNT}`)},{value:Ps.PERCENTAGE,label:l(`table.toolbar.types.${Ps.PERCENTAGE}`)}]}),t&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("table.toolbar.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]})}const Oi=m.createContext(void 0);function Uh({children:s,refetch:n}){const[t,l]=m.useState(!1),[a,i]=m.useState(null),r=x=>{i(x),l(!0)},d=()=>{l(!1),i(null)};return e.jsxs(Oi.Provider,{value:{isOpen:t,currentCoupon:a,openEdit:r,closeEdit:d},children:[s,a&&e.jsx(Mi,{defaultValues:a,refetch:n,type:"edit",open:t,onOpenChange:l})]})}function Hh(){const s=m.useContext(Oi);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const Kh=s=>{const{t:n}=M("coupon");return[{accessorKey:"id",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(H,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx(te,{defaultChecked:t.original.show,onCheckedChange:l=>{Ka.update({id:t.original.id,show:l}).then(({data:a})=>!a&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx($,{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($,{column:t,title:n("table.columns.type")}),cell:({row:t})=>e.jsx(H,{variant:"outline",children:n(`table.toolbar.types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.code")}),cell:({row:t})=>e.jsx(H,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.limitUse")}),cell:({row:t})=>e.jsx(H,{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($,{column:t,title:n("table.columns.limitUseWithUser")}),cell:({row:t})=>e.jsx(H,{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($,{column:t,title:n("table.columns.validity")}),cell:({row:t})=>{const[l,a]=m.useState(!1),i=Date.now(),r=t.original.started_at*1e3,d=t.original.ended_at*1e3,x=i>d,u=ie.jsx($,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>{const{openEdit:l}=Hh();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>l(t.original),children:[e.jsx(ut,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),e.jsx(bs,{title:n("table.actions.deleteConfirm.title"),description:n("table.actions.deleteConfirm.description"),confirmText:n("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{Ka.drop({id:t.original.id}).then(({data:a})=>{a&&(A.success("删除成功"),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(vs,{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 Bh(){const[s,n]=m.useState({}),[t,l]=m.useState({}),[a,i]=m.useState([]),[r,d]=m.useState([]),[x,u]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=oe({queryKey:["couponList",x,a,r],queryFn:()=>Ka.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:a,sort:r})}),h=es({data:c?.data??[],columns:Kh(o),state:{sorting:r,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:x},pageCount:Math.ceil((c?.total??0)/x.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:l,onPaginationChange:u,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Uh,{refetch:o,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ds,{table:h,toolbar:e.jsx(qh,{table:h,refetch:o})})})})}function Gh(){const{t:s}=M("coupon");return e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{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(Bh,{})})]})]})}const Wh=Object.freeze(Object.defineProperty({__proto__:null,default:Gh},Symbol.toStringTag,{value:"Module"})),Yh=le({name:T().min(1,"请输入模板名称"),description:T().optional(),type:Y().min(1).max(4),status:ie(),sort:Y().min(0),icon:T().optional(),background_image:T().optional(),conditions:le({allowed_plans:Qe(Y()).optional(),disallowed_plans:Qe(Y()).optional(),new_user_only:ie().optional(),new_user_max_days:Y().optional(),paid_user_only:ie().optional(),require_invite:ie().optional()}).optional(),limits:le({max_use_per_user:Y().optional(),cooldown_hours:Y().optional(),invite_reward_rate:Y().optional()}).optional(),rewards:le({balance:Y().optional(),transfer_enable:Y().optional(),expire_days:Y().optional(),device_limit:Y().optional(),reset_package:ie().optional(),plan_id:Y().optional(),plan_validity_days:Y().optional(),random_rewards:Qe(le({weight:Y(),balance:Y().optional(),transfer_enable:Y().optional(),expire_days:Y().optional(),device_limit:Y().optional()})).optional()}),special_config:le({start_time:Y().optional(),end_time:Y().optional(),festival_bonus:Y().optional()}).optional()});function zi({template:s,refetch:n,open:t,onOpenChange:l}){const{t:a}=M("giftCard"),[i,r]=m.useState(!1),[d,x]=m.useState([]),[u,o]=m.useState([]),c=De({resolver:Le(Yh),defaultValues:{name:"",description:"",type:1,status:!0,sort:0,icon:"",background_image:"",conditions:{},limits:{},rewards:{},special_config:{}}}),{fields:h,append:D,remove:S}=Ed({control:c.control,name:"rewards.random_rewards"});m.useEffect(()=>{t&&(async()=>{try{const C=(await Ts.getList()).data||[];x(C),o(C.map(z=>({label:z.name,value:z.id.toString()})))}catch(_){console.error("Failed to fetch plans:",_),A.error("Failed to load plan list")}})()},[t]),m.useEffect(()=>{if(s){const v=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:v.balance?v.balance/100:void 0,transfer_enable:typeof v.transfer_enable=="number"?v.transfer_enable/1024/1024/1024:void 0,expire_days:v.expire_days,device_limit:v.device_limit,reset_package:v.reset_package,plan_id:v.plan_id,plan_validity_days:v.plan_validity_days,random_rewards:v.random_rewards?.map(_=>({weight:_.weight,balance:_.balance?_.balance/100:void 0,transfer_enable:typeof _.transfer_enable=="number"?_.transfer_enable/1024/1024/1024:void 0,expire_days:_.expire_days,device_limit:_.device_limit}))||[]},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 w=v=>{console.error("Form validation failed:",v),A.error(a("messages.formInvalid"))},F=async v=>{r(!0);const _=JSON.parse(JSON.stringify(v));_.rewards&&(typeof _.rewards.balance=="number"&&(_.rewards.balance=Math.round(_.rewards.balance*100)),typeof _.rewards.transfer_enable=="number"&&(_.rewards.transfer_enable=Math.round(_.rewards.transfer_enable*1024*1024*1024)),_.rewards.random_rewards&&_.rewards.random_rewards.forEach(z=>{typeof z.balance=="number"&&(z.balance=Math.round(z.balance*100)),typeof z.transfer_enable=="number"&&(z.transfer_enable=Math.round(z.transfer_enable*1024*1024*1024))}));const C={..._,conditions:_.conditions||{},limits:_.limits||{},rewards:_.rewards||{},special_config:_.special_config||{}};try{s?(await Ms.updateTemplate({id:s.id,...C}),A.success(a("messages.templateUpdated"))):(await Ms.createTemplate(C),A.success(a("messages.templateCreated"))),n(),l(!1)}catch(z){const V=z?.response?.data?.errors;V&&Object.keys(V).forEach(R=>{c.setError(R,{type:"manual",message:V[R][0]})}),A.error(a(s?"messages.updateTemplateFailed":"messages.createTemplateFailed"))}finally{r(!1)}},y=c.watch("type"),I=y===1;return e.jsx(he,{open:t,onOpenChange:l,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(je,{children:e.jsx(pe,{children:a(s?"template.form.edit":"template.form.add")})}),e.jsx(Re,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(F,w),className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:c.control,name:"name",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.name.label")}),e.jsx(j,{children:e.jsx(k,{placeholder:a("template.form.name.placeholder"),...v})}),e.jsx(E,{})]})}),e.jsx(g,{control:c.control,name:"type",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.type.label")}),e.jsxs(ee,{value:v.value.toString(),onValueChange:_=>v.onChange(parseInt(_)),children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:a("template.form.type.placeholder")})})}),e.jsx(Z,{children:[1,2,3].map(_=>e.jsx(U,{value:_.toString(),children:a(`types.${_}`)},_))})]}),e.jsx(E,{})]})})]}),e.jsx(g,{control:c.control,name:"description",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.description.label")}),e.jsx(j,{children:e.jsx($s,{placeholder:a("template.form.description.placeholder"),...v})}),e.jsx(E,{})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:e.jsx(g,{control:c.control,name:"status",render:({field:v})=>e.jsxs(p,{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(f,{className:"text-base",children:a("template.form.status.label")}),e.jsx(q,{children:a("template.form.status.description")})]}),e.jsx(j,{children:e.jsx(te,{checked:v.value,onCheckedChange:v.onChange})})]})})}),e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:a("template.form.rewards.title")})}),e.jsxs(Ve,{className:"space-y-4",children:[I&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:c.control,name:"rewards.balance",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.balance.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.balance.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})}),e.jsx(g,{control:c.control,name:"rewards.transfer_enable",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.transfer_enable.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.placeholder"),value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})}),e.jsx(g,{control:c.control,name:"rewards.expire_days",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.expire_days.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.expire_days.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})}),e.jsx(g,{control:c.control,name:"rewards.device_limit",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.device_limit.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.device_limit.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})})]}),e.jsx(g,{control:c.control,name:"rewards.reset_package",render:({field:v})=>e.jsxs(p,{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(f,{children:a("template.form.rewards.reset_package.label")}),e.jsx(q,{children:a("template.form.rewards.reset_package.description")})]}),e.jsx(j,{children:e.jsx(te,{checked:v.value,onCheckedChange:v.onChange})})]})})]}),y===4&&e.jsx("p",{children:a("template.form.rewards.task_card.description")}),y===2&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:c.control,name:"rewards.plan_id",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.plan_id.label")}),e.jsxs(ee,{value:v.value?.toString(),onValueChange:_=>v.onChange(parseInt(_,10)),children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:a("template.form.rewards.plan_id.placeholder")})})}),e.jsx(Z,{children:d.map(_=>e.jsx(U,{value:_.id.toString(),children:_.name},_.id))})]}),e.jsx(E,{})]})}),e.jsx(g,{control:c.control,name:"rewards.plan_validity_days",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.plan_validity_days.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.plan_validity_days.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})})]}),y===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(f,{children:a("template.form.rewards.random_rewards.label")}),h.map((v,_)=>e.jsxs("div",{className:"flex items-center space-x-2 rounded-md border p-2",children:[e.jsx(g,{control:c.control,name:`rewards.random_rewards.${_}.weight`,render:({field:C})=>e.jsx(p,{children:e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.random_rewards.weight"),...C,value:C.value??"",onChange:z=>{const V=z.target.valueAsNumber;C.onChange(isNaN(V)?0:V)}})})})}),e.jsx(g,{control:c.control,name:`rewards.random_rewards.${_}.balance`,render:({field:C})=>e.jsx(p,{children:e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.balance.label"),...C,value:C.value??"",onChange:z=>{const V=z.target.valueAsNumber;C.onChange(isNaN(V)?void 0:V)}})})})}),e.jsx(g,{control:c.control,name:`rewards.random_rewards.${_}.transfer_enable`,render:({field:C})=>e.jsx(p,{children:e.jsx(j,{children:e.jsx(k,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.label")+" (GB)",value:C.value??"",onChange:z=>{const V=z.target.valueAsNumber;C.onChange(isNaN(V)?void 0:V)}})})})}),e.jsx(g,{control:c.control,name:`rewards.random_rewards.${_}.expire_days`,render:({field:C})=>e.jsx(p,{children:e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.expire_days.label"),...C,value:C.value??"",onChange:z=>{const V=z.target.valueAsNumber;C.onChange(isNaN(V)?void 0:V)}})})})}),e.jsx(g,{control:c.control,name:`rewards.random_rewards.${_}.device_limit`,render:({field:C})=>e.jsx(p,{children:e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.device_limit.label"),...C,value:C.value??"",onChange:z=>{const V=z.target.valueAsNumber;C.onChange(isNaN(V)?void 0:V)}})})})}),e.jsx(P,{type:"button",variant:"ghost",size:"icon",onClick:()=>S(_),children:e.jsx(Vd,{className:"h-4 w-4"})})]},v.id)),e.jsx(P,{type:"button",variant:"outline",onClick:()=>D({weight:10,balance:void 0,transfer_enable:void 0,expire_days:void 0,device_limit:void 0}),children:a("template.form.rewards.random_rewards.add")})]})]})]}),e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:a("template.form.conditions.title")})}),e.jsxs(Ve,{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 gap-4",children:e.jsx(g,{control:c.control,name:"conditions.new_user_max_days",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.conditions.new_user_max_days.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.conditions.new_user_max_days.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(g,{control:c.control,name:"conditions.new_user_only",render:({field:v})=>e.jsxs(p,{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(f,{children:a("template.form.conditions.new_user_only.label")})}),e.jsx(j,{children:e.jsx(te,{checked:v.value,onCheckedChange:v.onChange})})]})}),e.jsx(g,{control:c.control,name:"conditions.paid_user_only",render:({field:v})=>e.jsxs(p,{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(f,{children:a("template.form.conditions.paid_user_only.label")})}),e.jsx(j,{children:e.jsx(te,{checked:v.value,onCheckedChange:v.onChange})})]})}),e.jsx(g,{control:c.control,name:"conditions.require_invite",render:({field:v})=>e.jsxs(p,{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(f,{children:a("template.form.conditions.require_invite.label")})}),e.jsx(j,{children:e.jsx(te,{checked:v.value,onCheckedChange:v.onChange})})]})})]}),e.jsx(g,{control:c.control,name:"conditions.allowed_plans",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.conditions.allowed_plans.label")}),e.jsx(j,{children:e.jsx(mt,{value:v.value?.map(_=>({label:d.find(C=>C.id===_)?.name||`ID: ${_}`,value:_.toString()}))??[],onChange:_=>v.onChange(_.map(C=>parseInt(C.value))),options:u,placeholder:a("template.form.conditions.allowed_plans.placeholder")})})]})}),e.jsx(g,{control:c.control,name:"conditions.disallowed_plans",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.conditions.disallowed_plans.label")}),e.jsx(j,{children:e.jsx(mt,{value:v.value?.map(_=>({label:d.find(C=>C.id===_)?.name||`ID: ${_}`,value:_.toString()}))??[],onChange:_=>v.onChange(_.map(C=>parseInt(C.value))),options:u,placeholder:a("template.form.conditions.disallowed_plans.placeholder")})})]})})]})]}),e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:a("template.form.limits.title")})}),e.jsx(Ve,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:c.control,name:"limits.max_use_per_user",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.limits.max_use_per_user.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.limits.max_use_per_user.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})}),e.jsx(g,{control:c.control,name:"limits.cooldown_hours",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.limits.cooldown_hours.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.limits.cooldown_hours.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})}),e.jsx(g,{control:c.control,name:"limits.invite_reward_rate",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.limits.invite_reward_rate.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",step:"0.01",placeholder:a("template.form.limits.invite_reward_rate.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})}),e.jsx(q,{children:a("template.form.limits.invite_reward_rate.description")})]})})]})})]}),e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:a("template.form.special_config.title")})}),e.jsx(Ve,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-3 items-end gap-4",children:[e.jsx(g,{control:c.control,name:"special_config.start_time",render:({field:v})=>e.jsxs(p,{className:"flex flex-col",children:[e.jsx(f,{children:a("template.form.special_config.start_time.label")}),e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(j,{children:e.jsxs(P,{variant:"outline",className:b("w-full pl-3 text-left font-normal",!v.value&&"text-muted-foreground"),children:[v.value?Oe(new Date(v.value*1e3),"PPP"):e.jsx("span",{children:a("template.form.special_config.start_time.placeholder")}),e.jsx(Ls,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(Rs,{mode:"single",selected:v.value?new Date(v.value*1e3):void 0,onSelect:_=>v.onChange(_?Math.floor(_.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(E,{})]})}),e.jsx(g,{control:c.control,name:"special_config.end_time",render:({field:v})=>e.jsxs(p,{className:"flex flex-col",children:[e.jsx(f,{children:a("template.form.special_config.end_time.label")}),e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(j,{children:e.jsxs(P,{variant:"outline",className:b("w-full pl-3 text-left font-normal",!v.value&&"text-muted-foreground"),children:[v.value?Oe(new Date(v.value*1e3),"PPP"):e.jsx("span",{children:a("template.form.special_config.end_time.placeholder")}),e.jsx(Ls,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(Rs,{mode:"single",selected:v.value?new Date(v.value*1e3):void 0,onSelect:_=>v.onChange(_?Math.floor(_.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(E,{})]})}),e.jsx(g,{control:c.control,name:"special_config.festival_bonus",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.special_config.festival_bonus.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",step:"0.1",placeholder:a("template.form.special_config.festival_bonus.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})})]})})]}),e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:a("template.form.display.title")})}),e.jsx(Ve,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:c.control,name:"icon",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.icon.label")}),e.jsx(j,{children:e.jsx(k,{placeholder:a("template.form.icon.placeholder"),...v})}),e.jsx(E,{})]})}),e.jsx(g,{control:c.control,name:"background_image",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.background_image.label")}),e.jsx(j,{children:e.jsx(k,{placeholder:a("template.form.background_image.placeholder"),...v})}),e.jsx(E,{})]})})]})})]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(P,{type:"button",variant:"outline",onClick:()=>l(!1),children:a("common:cancel")}),e.jsx(P,{type:"submit",disabled:i,children:a(i?"common:saving":"common:submit")})]})]})})]})})}const $i=m.createContext(void 0);function Jh({children:s,refetch:n}){const[t,l]=m.useState(!1),[a,i]=m.useState(null),r=x=>{i(x),l(!!x)},d=()=>{l(!1),i(null)};return e.jsxs($i.Provider,{value:{isOpen:t,editingTemplate:a,setEditingTemplate:r,closeEdit:d},children:[s,e.jsx(zi,{template:a,refetch:n,open:t,onOpenChange:l})]})}function Qh(){const s=m.useContext($i);if(s===void 0)throw new Error("useTemplateEdit must be used within a TemplateEditProvider");return s}function Xh({rewards:s,type:n}){const{t}=M(["giftCard","common"]),l=[];return s&&(s.balance&&l.push(`${t("template.form.rewards.balance.short_label")}: ${s.balance/100} ${t("common:currency.yuan","元")}`),s.transfer_enable&&l.push(`${t("template.form.rewards.transfer_enable.short_label")}: ${Ie(s.transfer_enable)}`),s.expire_days&&l.push(`${t("template.form.rewards.expire_days.short_label")}: ${s.expire_days}${t("common:time.day","天")}`),s.device_limit&&l.push(`${t("template.form.rewards.device_limit.short_label")}: ${s.device_limit}`),n===2&&s.plan_id&&l.push(`${t("template.form.rewards.plan_id.short_label")}: ${s.plan_id}`),n===2&&s.plan_validity_days&&l.push(`${t("template.form.rewards.plan_validity_days.short_label")}: ${s.plan_validity_days}${t("common:time.day","天")}`),n===3&&s.random_rewards?.length&&l.push(t("types.3"))),l.length===0?e.jsx(H,{variant:"secondary",children:t("template.table.columns.no_rewards")}):e.jsx("div",{className:"flex flex-col space-y-1",children:l.map((a,i)=>e.jsx(H,{variant:"outline",className:"whitespace-nowrap",children:a},i))})}const Zh=s=>{const{t:n}=M("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.id")}),cell:({row:t})=>e.jsx(H,{children:t.original.id}),enableSorting:!0},{accessorKey:"status",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.status")}),cell:({row:t})=>{const[l,a]=m.useState(!1);return e.jsx(te,{checked:t.original.status,disabled:l,onCheckedChange:async i=>{a(!0);try{const{data:r}=await Ms.updateTemplate({id:t.original.id,status:i});r?(A.success(n("messages.templateUpdated")),s()):A.error(n("messages.updateTemplateFailed"))}catch{A.error(n("messages.updateTemplateFailed"))}finally{a(!1)}}})},enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx($,{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($,{column:t,title:n("template.table.columns.type")}),cell:({row:t})=>e.jsx(H,{variant:"outline",children:n(`types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"rewards",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.rewards")}),cell:({row:t})=>e.jsx(Xh,{rewards:t.original.rewards,type:t.original.type}),enableSorting:!1},{accessorKey:"sort",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.sort")}),cell:({row:t})=>e.jsx(H,{variant:"secondary",children:t.original.sort}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:re(t.original.created_at)}),enableSorting:!0},{id:"actions",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.actions")}),cell:({row:t})=>{const{setEditingTemplate:l}=Qh();return e.jsxs("div",{className:"flex space-x-2",children:[e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>l(t.original),children:[e.jsx(ut,{className:"h-4 w-4"}),n("template.actions.edit")]}),e.jsx(bs,{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 Ms.deleteTemplate({id:t.original.id});a?(A.success(n("messages.templateDeleted")),s()):A.error(n("messages.deleteTemplateFailed"))}catch{A.error(n("messages.deleteTemplateFailed"))}},children:e.jsxs(P,{variant:"outline",size:"sm",children:[e.jsx(vs,{className:"h-4 w-4"}),n("template.actions.delete")]})})]})},enableSorting:!1}]};function Ai({table:s}){const{t:n}=M("common");return e.jsxs(Js,{children:[e.jsx(Id,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(Wr,{className:"mr-2 h-4 w-4"}),n("table.viewOptions.button")]})}),e.jsxs(Ws,{align:"end",className:"w-[150px]",children:[e.jsx(an,{children:n("table.viewOptions.label")}),e.jsx(dt,{}),s.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>e.jsx(ci,{className:"capitalize",checked:t.getIsVisible(),onCheckedChange:l=>t.toggleVisibility(!!l),children:t.id},t.id))]})]})}function Wa({column:s,title:n,options:t}){const l=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(J,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Md,{className:"mr-2 h-4 w-4"}),n,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:l.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:l.size>2?e.jsxs(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[l.size," selected"]}):t.filter(a=>l.has(a.value)).map(a=>e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:a.label},`selected-${a.value}`))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(st,{children:[e.jsx(ht,{placeholder:n}),e.jsxs(tt,{children:[e.jsx(pt,{children:"No results found."}),e.jsx(ys,{children:t.map(a=>{const i=l.has(a.value);return e.jsxs(Be,{onSelect:()=>{i?l.delete(a.value):l.add(a.value);const r=Array.from(l);s?.setFilterValue(r.length?r:void 0)},children:[e.jsx("div",{className:b("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",i?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(La,{className:b("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}`)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Gt,{}),e.jsx(ys,{children:e.jsx(Be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function ep({table:s,refetch:n}){const{t}=M("giftCard"),[l,a]=m.useState(!1),i=s.getState().columnFilters.length>0,r=[{label:t("types.1"),value:"1"},{label:t("types.2"),value:"2"},{label:t("types.3"),value:"3"},{label:t("types.4"),value:"4"},{label:t("types.5"),value:"5"},{label:t("types.6"),value:"6"},{label:t("types.7"),value:"7"},{label:t("types.8"),value:"8"},{label:t("types.9"),value:"9"},{label:t("types.10"),value:"10"}],d=[{label:t("common.enabled"),value:"true"},{label:t("common.disabled"),value:"false"}];return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(k,{placeholder:t("common.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:x=>s.getColumn("name")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(Wa,{column:s.getColumn("type"),title:t("template.table.columns.type"),options:r}),s.getColumn("status")&&e.jsx(Wa,{column:s.getColumn("status"),title:t("template.table.columns.status"),options:d}),i&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Yr,{className:"h-4 w-4 mr-2"}),t("template.form.add")]}),e.jsx(Ai,{table:s})]}),e.jsx(zi,{template:null,refetch:n,open:l,onOpenChange:a})]})}function sp(){const[s,n]=m.useState({}),[t,l]=m.useState({}),[a,i]=m.useState([]),[r,d]=m.useState([]),[x,u]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=oe({queryKey:["giftCardTemplates",x,a,r],queryFn:()=>Ms.getTemplates({per_page:x.pageSize,page:x.pageIndex+1,filter:a,sort:r})});console.log(c);const h=es({data:c?.data??[],columns:Zh(o),state:{sorting:r,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:x},pageCount:Math.ceil((c?.total??0)/x.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:l,onPaginationChange:u,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Jh,{refetch:o,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ds,{table:h,toolbar:e.jsx(ep,{table:h,refetch:o})})})})}const tp=le({template_id:Y().min(1,"请选择一个模板"),count:Y().min(1,"生成数量必须大于0").max(1e4,"单次最多生成10000个"),prefix:T().optional(),expires_hours:Y().min(1,"有效期必须大于0"),max_usage:Y().min(1,"最大使用次数必须大于0"),download_csv:ie().optional()});function ap({refetch:s,open:n,onOpenChange:t}){const{t:l}=M("giftCard"),[a,i]=m.useState(!1),[r,d]=m.useState([]);m.useEffect(()=>{n&&Ms.getTemplates({per_page:1e3,page:1}).then(({data:o})=>{d(o||[])})},[n]);const x=De({resolver:Le(tp),defaultValues:{count:10,prefix:"",expires_hours:24*30,max_usage:1,download_csv:!1}}),u=async o=>{i(!0);try{if(o.download_csv){const c=await Ms.generateCodes(o);if(c&&c instanceof Blob){const h=window.URL.createObjectURL(c),D=document.createElement("a");D.href=h,D.download=`gift_codes_${new Date().getTime()}.csv`,document.body.appendChild(D),D.click(),D.remove(),window.URL.revokeObjectURL(h),A.success(l("messages.codesGenerated")),s(),t(!1),x.reset()}}else await Ms.generateCodes(o),A.success(l("messages.codesGenerated")),s(),t(!1),x.reset()}catch{A.error(l("messages.generateCodesFailed"))}finally{i(!1)}};return e.jsx(he,{open:n,onOpenChange:t,children:e.jsxs(ue,{children:[e.jsx(je,{children:e.jsx(pe,{children:l("code.form.generate")})}),e.jsx(Re,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(u),className:"space-y-4",children:[e.jsx(g,{control:x.control,name:"template_id",render:({field:o})=>e.jsxs(p,{children:[e.jsx(f,{children:l("code.form.template_id.label")}),e.jsxs(ee,{onValueChange:c=>o.onChange(parseInt(c)),children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:l("code.form.template_id.placeholder")})})}),e.jsx(Z,{children:r.map(c=>e.jsx(U,{value:c.id.toString(),children:c.name},c.id))})]}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"count",render:({field:o})=>e.jsxs(p,{children:[e.jsx(f,{children:l("code.form.count.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"prefix",render:({field:o})=>e.jsxs(p,{children:[e.jsx(f,{children:l("code.form.prefix.label")}),e.jsx(j,{children:e.jsx(k,{...o})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"expires_hours",render:({field:o})=>e.jsxs(p,{children:[e.jsx(f,{children:l("code.form.expires_hours.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"max_usage",render:({field:o})=>e.jsxs(p,{children:[e.jsx(f,{children:l("code.form.max_usage.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"download_csv",render:({field:o})=>e.jsxs(p,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(j,{children:e.jsx("input",{type:"checkbox",checked:o.value,onChange:c=>o.onChange(c.target.checked)})}),e.jsx(f,{children:l("code.form.download_csv")})]})}),e.jsxs(qe,{children:[e.jsx(P,{type:"button",variant:"outline",onClick:()=>t(!1),children:l("common.cancel")}),e.jsx(P,{type:"submit",disabled:a,children:l(a?"code.form.submit.generating":"code.form.submit.generate")})]})]})})]})})}function np({table:s,refetch:n}){const{t}=M("giftCard"),[l,a]=m.useState(!1),i=s.getState().columnFilters.length>0,r=Object.entries(t("code.status",{returnObjects:!0})).map(([d,x])=>({value:d,label:x}));return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(k,{placeholder:t("common.search"),value:s.getColumn("code")?.getFilterValue()??"",onChange:d=>s.getColumn("code")?.setFilterValue(d.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("status")&&e.jsx(Wa,{column:s.getColumn("status"),title:t("code.table.columns.status"),options:r}),i&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Yr,{className:"h-4 w-4 mr-2"}),t("code.form.generate")]}),e.jsxs(P,{variant:"outline",size:"sm",disabled:!0,children:[e.jsx(ma,{className:"h-4 w-4 mr-2"}),t("common.export")]}),e.jsx(Ai,{table:s})]}),e.jsx(ap,{refetch:n,open:l,onOpenChange:a})]})}const lp=0,rp=1,ip=2,kn=3,op=s=>{const{t:n}=M("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.id")}),cell:({row:t})=>e.jsx(H,{children:t.original.id})},{accessorKey:"code",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.code")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(H,{variant:"secondary",children:t.original.code}),e.jsx(P,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>lt(t.original.code).then(()=>{A.success(n("common:copy.success"))}),children:e.jsx(Jn,{className:"h-4 w-4"})})]})},{accessorKey:"template_name",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.template_name")})},{accessorKey:"status",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.status")}),cell:({row:t})=>{const l=t.original.status,a=l===kn,i=l===lp||l===kn;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(H,{variant:l===rp?"secondary":l===ip||l===kn?"destructive":"default",children:n(`code.status.${l}`)}),i&&e.jsx(te,{checked:!a,onCheckedChange:async r=>{const d=r?"enable":"disable";try{const{data:x}=await Ms.toggleCode({id:t.original.id,action:d});x?(A.success(n("messages.codeStatusUpdated")),s()):A.error(n("messages.updateCodeStatusFailed"))}catch{A.error(n("messages.updateCodeStatusFailed"))}}})]})}},{accessorKey:"expires_at",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.expires_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:re(t.original.expires_at)})},{accessorKey:"usage_count",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.usage_count")}),cell:({row:t})=>e.jsx(H,{variant:"outline",children:t.original.usage_count})},{accessorKey:"max_usage",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.max_usage")}),cell:({row:t})=>e.jsx(H,{variant:"outline",children:t.original.max_usage})},{accessorKey:"created_at",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:re(t.original.created_at)})}]};function cp(){const[s,n]=m.useState({}),[t,l]=m.useState({}),[a,i]=m.useState([]),[r,d]=m.useState([]),[x,u]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=oe({queryKey:["giftCardCodes",x,a,r],queryFn:()=>Ms.getCodes({per_page:x.pageSize,page:x.pageIndex+1,filter:a,sort:r})}),h=es({data:c?.data??[],columns:op(o),state:{sorting:r,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:x},pageCount:Math.ceil((c?.total??0)/x.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:l,onPaginationChange:u,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(ds,{table:h,toolbar:e.jsx(np,{table:h,refetch:o})})})}const dp=()=>{const{t:s}=M("giftCard");return[{accessorKey:"id",header:({column:n})=>e.jsx($,{column:n,title:s("usage.table.columns.id")}),cell:({row:n})=>e.jsx(H,{children:n.original.id})},{accessorKey:"code",header:({column:n})=>e.jsx($,{column:n,title:s("usage.table.columns.code")}),cell:({row:n})=>e.jsx(H,{variant:"secondary",children:n.original.code})},{accessorKey:"user_email",header:({column:n})=>e.jsx($,{column:n,title:s("usage.table.columns.user_email")})},{accessorKey:"template_name",header:({column:n})=>e.jsx($,{column:n,title:s("usage.table.columns.template_name")})},{accessorKey:"created_at",header:({column:n})=>e.jsx($,{column:n,title:s("usage.table.columns.created_at")}),cell:({row:n})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:re(n.original.created_at)})}]};function mp(){const[s,n]=m.useState([]),[t,l]=m.useState([]),[a,i]=m.useState({pageIndex:0,pageSize:20}),{data:r}=oe({queryKey:["giftCardUsages",a,s,t],queryFn:()=>Ms.getUsages({per_page:a.pageSize,page:a.pageIndex+1,filter:s,sort:t})}),d=es({data:r?.data??[],columns:dp(),state:{sorting:t,columnFilters:s,pagination:a},pageCount:Math.ceil((r?.total??0)/a.pageSize),rowCount:r?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,onSortingChange:l,onColumnFiltersChange:n,onPaginationChange:i,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns()});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(k,{placeholder:"搜索用户邮箱...",value:d.getColumn("user_email")?.getFilterValue()??"",onChange:x=>d.getColumn("user_email")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"})}),e.jsx(ds,{table:d})]})}function up(){const{t:s}=M("giftCard"),{data:n,isLoading:t}=oe({queryKey:["giftCardStats"],queryFn:()=>Ms.getStatistics({})}),l=n?.data?.total_stats,a=[{title:s("statistics.total.templates_count"),value:l?.templates_count},{title:s("statistics.total.active_templates_count"),value:l?.active_templates_count},{title:s("statistics.total.codes_count"),value:l?.codes_count},{title:s("statistics.total.used_codes_count"),value:l?.used_codes_count}];return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:a.map((i,r)=>e.jsxs(Pe,{children:[e.jsx(Ee,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:e.jsx(Ae,{className:"text-sm font-medium",children:i.title})}),e.jsx(Ve,{children:t?e.jsx(we,{className:"h-8 w-1/2"}):e.jsx("div",{className:"text-2xl font-bold",children:i.value??0})})]},r))})}function xp(){const{t:s}=M("giftCard"),[n,t]=m.useState("templates");return e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{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(Dt,{value:n,onValueChange:t,className:"flex-1",children:[e.jsxs(xt,{className:"grid w-full grid-cols-4",children:[e.jsx(Xe,{value:"templates",children:s("tabs.templates")}),e.jsx(Xe,{value:"codes",children:s("tabs.codes")}),e.jsx(Xe,{value:"usages",children:s("tabs.usages")}),e.jsx(Xe,{value:"statistics",children:s("tabs.statistics")})]}),e.jsx(ks,{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(sp,{})]})}),e.jsx(ks,{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(cp,{})]})}),e.jsx(ks,{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(mp,{})]})}),e.jsx(ks,{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(up,{})]})})]})]})]})}const hp=Object.freeze(Object.defineProperty({__proto__:null,default:xp},Symbol.toStringTag,{value:"Module"}));function pp({open:s,onOpenChange:n,table:t}){const{t:l}=M("user"),[a,i]=m.useState(!1),[r,d]=m.useState(""),[x,u]=m.useState(""),o=async()=>{if(!r||!x){A.error(l("messages.send_mail.required_fields"));return}try{i(!0),await Ys.sendMail({subject:r,content:x,filter:t.getState().columnFilters,sort:t.getState().sorting[0]?.id,sort_type:t.getState().sorting[0]?.desc?"DESC":"ASC"}),A.success(l("messages.send_mail.success")),n(!1),d(""),u("")}catch{A.error(l("messages.send_mail.failed"))}finally{i(!1)}};return e.jsx(he,{open:s,onOpenChange:n,children:e.jsxs(ue,{className:"sm:max-w-[500px]",children:[e.jsxs(je,{children:[e.jsx(pe,{children:l("send_mail.title")}),e.jsx(Ge,{children:l("send_mail.description")})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"subject",className:"text-right",children:l("send_mail.subject")}),e.jsx(k,{id:"subject",value:r,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:l("send_mail.content")}),e.jsx($s,{id:"content",value:x,onChange:c=>u(c.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(qe,{children:e.jsx(J,{type:"submit",onClick:o,disabled:a,children:l(a?"send_mail.sending":"send_mail.send")})})]})})}function gp({trigger:s}){const{t:n}=M("user"),[t,l]=m.useState(!1),[a,i]=m.useState(30),{data:r,isLoading:d}=oe({queryKey:["trafficResetStats",a],queryFn:()=>pa.getStats({days:a}),enabled:t}),x=[{title:n("traffic_reset.stats.total_resets"),value:r?.data?.total_resets||0,icon:la,color:"text-blue-600",bgColor:"bg-blue-100"},{title:n("traffic_reset.stats.auto_resets"),value:r?.data?.auto_resets||0,icon:Aa,color:"text-green-600",bgColor:"bg-green-100"},{title:n("traffic_reset.stats.manual_resets"),value:r?.data?.manual_resets||0,icon:Ls,color:"text-orange-600",bgColor:"bg-orange-100"},{title:n("traffic_reset.stats.cron_resets"),value:r?.data?.cron_resets||0,icon:Qn,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(he,{open:t,onOpenChange:l,children:[e.jsx(hs,{asChild:!0,children:s}),e.jsxs(ue,{className:"max-w-2xl",children:[e.jsxs(je,{children:[e.jsxs(pe,{className:"flex items-center gap-2",children:[e.jsx(Gn,{className:"h-5 w-5"}),n("traffic_reset.stats.title")]}),e.jsx(Ge,{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(ee,{value:a.toString(),onValueChange:o=>i(Number(o)),children:[e.jsx(X,{className:"w-[180px]",children:e.jsx(se,{})}),e.jsx(Z,{children:u.map(o=>e.jsx(U,{value:o.value.toString(),children:o.label},o.value))})]})]}),d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(da,{className:"h-6 w-6 animate-spin"})}):e.jsx("div",{className:"grid grid-cols-2 gap-4",children:x.map((o,c)=>e.jsxs(Pe,{className:"relative overflow-hidden",children:[e.jsxs(Ee,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ae,{className:"text-sm font-medium text-muted-foreground",children:o.title}),e.jsx("div",{className:`rounded-lg p-2 ${o.bgColor}`,children:e.jsx(o.icon,{className:`h-4 w-4 ${o.color}`})})]}),e.jsxs(Ve,{children:[e.jsx("div",{className:"text-2xl font-bold",children:o.value.toLocaleString()}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:n("traffic_reset.stats.in_period",{days:a})})]})]},c))}),r?.data&&e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx(Ae,{className:"text-lg",children:n("traffic_reset.stats.breakdown")}),e.jsx(it,{children:n("traffic_reset.stats.breakdown_description")})]}),e.jsx(Ve,{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(H,{variant:"outline",className:"border-green-200 bg-green-50 text-green-700",children:[r.data.total_resets>0?(r.data.auto_resets/r.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(H,{variant:"outline",className:"border-orange-200 bg-orange-50 text-orange-700",children:[r.data.total_resets>0?(r.data.manual_resets/r.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(H,{variant:"outline",className:"border-purple-200 bg-purple-50 text-purple-700",children:[r.data.total_resets>0?(r.data.cron_resets/r.data.total_resets*100).toFixed(1):0,"%"]})]})]})})]})]})]})]})}const fp=le({email_prefix:T().optional(),email_suffix:T().min(1),password:T().optional(),expired_at:Y().optional().nullable(),plan_id:Y().nullable(),generate_count:Y().optional().nullable(),download_csv:ie().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"]}),jp={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0,download_csv:!1};function vp({refetch:s}){const{t:n}=M("user"),[t,l]=m.useState(!1),a=De({resolver:Le(fp),defaultValues:jp,mode:"onChange"}),[i,r]=m.useState([]);return m.useEffect(()=>{t&&Ts.getList().then(({data:d})=>{d&&r(d)})},[t]),e.jsxs(he,{open:t,onOpenChange:l,children:[e.jsx(hs,{asChild:!0,children:e.jsxs(J,{size:"sm",variant:"outline",className:"gap-0 space-x-2",children:[e.jsx(He,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(je,{children:[e.jsx(pe,{children:n("generate.title")}),e.jsx(Ge,{})]}),e.jsxs(Re,{...a,children:[e.jsxs(p,{children:[e.jsx(f,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!a.watch("generate_count")&&e.jsx(g,{control:a.control,name:"email_prefix",render:({field:d})=>e.jsx(k,{className:"flex-[5] rounded-r-none",placeholder:n("generate.form.email_prefix"),...d})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${a.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(g,{control:a.control,name:"email_suffix",render:({field:d})=>e.jsx(k,{className:"flex-[4] rounded-l-none",placeholder:n("generate.form.email_domain"),...d})})]})]}),e.jsx(g,{control:a.control,name:"password",render:({field:d})=>e.jsxs(p,{children:[e.jsx(f,{children:n("generate.form.password")}),e.jsx(k,{placeholder:n("generate.form.password_placeholder"),...d}),e.jsx(E,{})]})}),e.jsx(g,{control:a.control,name:"expired_at",render:({field:d})=>e.jsxs(p,{className:"flex flex-col",children:[e.jsx(f,{children:n("generate.form.expire_time")}),e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(j,{children:e.jsxs(J,{variant:"outline",className:b("w-full pl-3 text-left font-normal",!d.value&&"text-muted-foreground"),children:[d.value?re(d.value):e.jsx("span",{children:n("generate.form.expire_time_placeholder")}),e.jsx(Ls,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(Ze,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(Od,{asChild:!0,children:e.jsx(J,{variant:"outline",className:"w-full",onClick:()=>{d.onChange(null)},children:n("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Rs,{mode:"single",selected:d.value?new Date(d.value*1e3):void 0,onSelect:x=>{x&&d.onChange(x?.getTime()/1e3)}})})]})]})]})}),e.jsx(g,{control:a.control,name:"plan_id",render:({field:d})=>e.jsxs(p,{children:[e.jsx(f,{children:n("generate.form.subscription")}),e.jsx(j,{children:e.jsxs(ee,{value:d.value?d.value.toString():"null",onValueChange:x=>d.onChange(x==="null"?null:parseInt(x)),children:[e.jsx(X,{children:e.jsx(se,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(Z,{children:[e.jsx(U,{value:"null",children:n("generate.form.subscription_none")}),i.map(x=>e.jsx(U,{value:x.id.toString(),children:x.name},x.id))]})]})})]})}),!a.watch("email_prefix")&&e.jsx(g,{control:a.control,name:"generate_count",render:({field:d})=>e.jsxs(p,{children:[e.jsx(f,{children:n("generate.form.generate_count")}),e.jsx(k,{type:"number",placeholder:n("generate.form.generate_count_placeholder"),value:d.value||"",onChange:x=>d.onChange(x.target.value?parseInt(x.target.value):null)})]})}),a.watch("generate_count")&&e.jsx(g,{control:a.control,name:"download_csv",render:({field:d})=>e.jsxs(p,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(j,{children:e.jsx(ll,{checked:d.value,onCheckedChange:d.onChange})}),e.jsx(f,{children:n("generate.form.download_csv")})]})})]}),e.jsxs(qe,{children:[e.jsx(J,{variant:"outline",onClick:()=>l(!1),children:n("generate.form.cancel")}),e.jsx(J,{onClick:()=>a.handleSubmit(async d=>{if(d.download_csv){const x=await Ys.generate(d);if(x&&x instanceof Blob){const u=window.URL.createObjectURL(x),o=document.createElement("a");o.href=u,o.download=`users_${new Date().getTime()}.csv`,document.body.appendChild(o),o.click(),o.remove(),window.URL.revokeObjectURL(u),A.success(n("generate.form.success")),a.reset(),s(),l(!1)}}else{const{data:x}=await Ys.generate(d);x&&(A.success(n("generate.form.success")),a.reset(),s(),l(!1))}})(),children:n("generate.form.submit")})]})]})]})}const bp=1,yp=1e6;let Tn=0;function _p(){return Tn=(Tn+1)%Number.MAX_SAFE_INTEGER,Tn.toString()}const Dn=new Map,Ol=s=>{if(Dn.has(s))return;const n=setTimeout(()=>{Dn.delete(s),ca({type:"REMOVE_TOAST",toastId:s})},yp);Dn.set(s,n)},Np=(s,n)=>{switch(n.type){case"ADD_TOAST":return{...s,toasts:[n.toast,...s.toasts].slice(0,bp)};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?Ol(t):s.toasts.forEach(l=>{Ol(l.id)}),{...s,toasts:s.toasts.map(l=>l.id===t||t===void 0?{...l,open:!1}:l)}}case"REMOVE_TOAST":return n.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==n.toastId)}}},Va=[];let Ia={toasts:[]};function ca(s){Ia=Np(Ia,s),Va.forEach(n=>{n(Ia)})}function wp({...s}){const n=_p(),t=a=>ca({type:"UPDATE_TOAST",toast:{...a,id:n}}),l=()=>ca({type:"DISMISS_TOAST",toastId:n});return ca({type:"ADD_TOAST",toast:{...s,id:n,open:!0,onOpenChange:a=>{a||l()}}}),{id:n,dismiss:l,update:t}}function Cp(){const[s,n]=m.useState(Ia);return m.useEffect(()=>(Va.push(n),()=>{const t=Va.indexOf(n);t>-1&&Va.splice(t,1)}),[s]),{...s,toast:wp,dismiss:t=>ca({type:"DISMISS_TOAST",toastId:t})}}const rl=Jl,qi=Xl,Sp=Ql,Ui=m.forwardRef(({className:s,...n},t)=>e.jsx(Xa,{className:b("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}));Ui.displayName=Xa.displayName;const kp=St("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"}}),pn=m.forwardRef(({side:s="right",className:n,children:t,...l},a)=>e.jsxs(Sp,{children:[e.jsx(Ui,{}),e.jsxs(Ya,{ref:a,className:b(kp({side:s}),n),...l,children:[e.jsxs(Un,{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(xs,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),t]})]}));pn.displayName=Ya.displayName;const gn=({className:s,...n})=>e.jsx("div",{className:b("flex flex-col space-y-2 text-center sm:text-left",s),...n});gn.displayName="SheetHeader";const Hi=({className:s,...n})=>e.jsx("div",{className:b("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Hi.displayName="SheetFooter";const fn=m.forwardRef(({className:s,...n},t)=>e.jsx(Ja,{ref:t,className:b("text-lg font-semibold text-foreground",s),...n}));fn.displayName=Ja.displayName;const jn=m.forwardRef(({className:s,...n},t)=>e.jsx(Qa,{ref:t,className:b("text-sm text-muted-foreground",s),...n}));jn.displayName=Qa.displayName;function Tp({table:s,refetch:n,permissionGroups:t=[],subscriptionPlans:l=[]}){const{t:a}=M("user"),{toast:i}=Cp(),r=s.getState().columnFilters.length>0,[d,x]=m.useState([]),[u,o]=m.useState(!1),[c,h]=m.useState(!1),[D,S]=m.useState(!1),[w,F]=m.useState(!1),y=async()=>{try{const L=await Ys.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),ae=L;console.log(L);const G=new Blob([ae],{type:"text/csv;charset=utf-8;"}),ne=window.URL.createObjectURL(G),_e=document.createElement("a");_e.href=ne,_e.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(_e),_e.click(),_e.remove(),window.URL.revokeObjectURL(ne),i({title:a("messages.success"),description:a("messages.export.success")})}catch{i({title:a("messages.error"),description:a("messages.export.failed"),variant:"destructive"})}},I=async()=>{try{F(!0),await Ys.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),i({title:a("messages.success"),description:a("messages.batch_ban.success")}),n()}catch{i({title:a("messages.error"),description:a("messages.batch_ban.failed"),variant:"destructive"})}finally{F(!1),S(!1)}},v=[{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"}]}],_=L=>L*1024*1024*1024,C=L=>L/(1024*1024*1024),z=()=>{x([...d,{field:"",operator:"",value:""}])},V=L=>{x(d.filter((ae,G)=>G!==L))},R=(L,ae,G)=>{const ne=[...d];if(ne[L]={...ne[L],[ae]:G},ae==="field"){const _e=v.find(gs=>gs.value===G);_e&&(ne[L].operator=_e.operators[0].value,ne[L].value=_e.type==="boolean"?!1:"")}x(ne)},W=(L,ae)=>{const G=v.find(ne=>ne.value===L.field);if(!G)return null;switch(G.type){case"text":return e.jsx(k,{placeholder:a("filter.sheet.value"),value:L.value,onChange:ne=>R(ae,"value",ne.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(k,{type:"number",placeholder:a("filter.sheet.value_number",{unit:G.unit}),value:G.unit==="GB"?C(L.value||0):L.value,onChange:ne=>{const _e=Number(ne.target.value);R(ae,"value",G.unit==="GB"?_(_e):_e)}}),G.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:G.unit})]});case"date":return e.jsx(Rs,{mode:"single",selected:L.value,onSelect:ne=>R(ae,"value",ne),className:"flex flex-1 justify-center rounded-md border"});case"select":return e.jsxs(ee,{value:L.value,onValueChange:ne=>R(ae,"value",ne),children:[e.jsx(X,{children:e.jsx(se,{placeholder:a("filter.sheet.value")})}),e.jsx(Z,{children:G.useOptions?l.map(ne=>e.jsx(U,{value:ne.value.toString(),children:ne.label},ne.value)):G.options?.map(ne=>e.jsx(U,{value:ne.value.toString(),children:ne.label},ne.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(te,{checked:L.value,onCheckedChange:ne=>R(ae,"value",ne)}),e.jsx(as,{children:L.value?a("filter.boolean.true"):a("filter.boolean.false")})]});default:return null}},N=()=>{const L=d.filter(ae=>ae.field&&ae.operator&&ae.value!=="").map(ae=>{const G=v.find(_e=>_e.value===ae.field);let ne=ae.value;return ae.operator==="contains"?{id:ae.field,value:ne}:(G?.type==="date"&&ne instanceof Date&&(ne=Math.floor(ne.getTime()/1e3)),G?.type==="boolean"&&(ne=ne?1:0),{id:ae.field,value:`${ae.operator}:${ne}`})});s.setColumnFilters(L),o(!1)};return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-2",children:[e.jsx(vp,{refetch:n}),e.jsx(k,{placeholder:a("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:L=>s.getColumn("email")?.setFilterValue(L.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(rl,{open:u,onOpenChange:o,children:[e.jsx(qi,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Wr,{className:"mr-2 h-4 w-4"}),a("filter.advanced"),d.length>0&&e.jsx(H,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:d.length})]})}),e.jsxs(pn,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(gn,{children:[e.jsx(fn,{children:a("filter.sheet.title")}),e.jsx(jn,{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(P,{variant:"outline",size:"sm",onClick:z,children:a("filter.sheet.add")})]}),e.jsx(Ct,{className:"h-[calc(100vh-280px)] ",children:e.jsx("div",{className:"space-y-4",children:d.map((L,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(as,{children:a("filter.sheet.condition",{number:ae+1})}),e.jsx(P,{variant:"ghost",size:"sm",onClick:()=>V(ae),children:e.jsx(xs,{className:"h-4 w-4"})})]}),e.jsxs(ee,{value:L.field,onValueChange:G=>R(ae,"field",G),children:[e.jsx(X,{children:e.jsx(se,{placeholder:a("filter.sheet.field")})}),e.jsx(Z,{children:e.jsx(Fs,{children:v.map(G=>e.jsx(U,{value:G.value,className:"cursor-pointer",children:G.label},G.value))})})]}),L.field&&e.jsxs(ee,{value:L.operator,onValueChange:G=>R(ae,"operator",G),children:[e.jsx(X,{children:e.jsx(se,{placeholder:a("filter.sheet.operator")})}),e.jsx(Z,{children:v.find(G=>G.value===L.field)?.operators.map(G=>e.jsx(U,{value:G.value,children:G.label},G.value))})]}),L.field&&L.operator&&W(L,ae)]},ae))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(P,{variant:"outline",onClick:()=>{x([]),o(!1)},children:a("filter.sheet.reset")}),e.jsx(P,{onClick:N,children:a("filter.sheet.apply")})]})]})]})]}),r&&e.jsxs(P,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),x([])},className:"h-8 px-2 lg:px-3",children:[a("filter.sheet.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]}),e.jsxs(Js,{modal:!1,children:[e.jsx(Zs,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:a("actions.title")})}),e.jsxs(Ws,{children:[e.jsx(Fe,{onClick:()=>h(!0),children:a("actions.send_email")}),e.jsx(Fe,{onClick:y,children:a("actions.export_csv")}),e.jsx(dt,{}),e.jsx(Fe,{asChild:!0,children:e.jsx(gp,{trigger:e.jsx("div",{className:"w-full cursor-pointer px-2 py-1.5 text-sm",children:a("actions.traffic_reset_stats")})})}),e.jsx(dt,{}),e.jsx(Fe,{onClick:()=>S(!0),className:"text-red-600 focus:text-red-600",children:a("actions.batch_ban")})]})]})]}),e.jsx(pp,{open:c,onOpenChange:h,table:s}),e.jsx(al,{open:D,onOpenChange:S,children:e.jsxs(ln,{children:[e.jsxs(rn,{children:[e.jsx(cn,{children:a("actions.confirm_ban.title")}),e.jsx(dn,{children:a(r?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(on,{children:[e.jsx(un,{disabled:w,children:a("actions.confirm_ban.cancel")}),e.jsx(mn,{onClick:I,disabled:w,className:"bg-red-600 hover:bg-red-700 focus:ring-red-600",children:a(w?"actions.confirm_ban.banning":"actions.confirm_ban.confirm")})]})]})})]})}const Ki=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"})}),Bi=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"})}),Dp=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"})}),Fp=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:am(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ki,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:Ie(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(Bi,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:Ie(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(H,{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:Ie(n)})}}];function Gi({user_id:s,dialogTrigger:n}){const{t}=M(["traffic"]),[l,a]=m.useState(!1),[i,r]=m.useState({pageIndex:0,pageSize:20}),{data:d,isLoading:x}=oe({queryKey:["userStats",s,i,l],queryFn:()=>l?Ys.getStats({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),u=es({data:d?.data??[],columns:Fn,pageCount:Math.ceil((d?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:ss(),onPaginationChange:r});return e.jsxs(he,{open:l,onOpenChange:a,children:[e.jsx(hs,{asChild:!0,children:n}),e.jsxs(ue,{className:"sm:max-w-[700px]",children:[e.jsx(je,{children:e.jsx(pe,{children:t("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Zn,{children:[e.jsx(el,{children:u.getHeaderGroups().map(o=>e.jsx(rt,{children:o.headers.map(c=>e.jsx(tl,{className:b("h-10 px-2 text-xs",c.id==="total"&&"text-right"),children:c.isPlaceholder?null:za(c.column.columnDef.header,c.getContext())},c.id))},o.id))}),e.jsx(sl,{children:x?Array.from({length:i.pageSize}).map((o,c)=>e.jsx(rt,{children:Array.from({length:Fn.length}).map((h,D)=>e.jsx($t,{className:"p-2",children:e.jsx(we,{className:"h-6 w-full"})},D))},c)):u.getRowModel().rows?.length?u.getRowModel().rows.map(o=>e.jsx(rt,{"data-state":o.getIsSelected()&&"selected",className:"h-10",children:o.getVisibleCells().map(c=>e.jsx($t,{className:"px-2",children:za(c.column.columnDef.cell,c.getContext())},c.id))},o.id)):e.jsx(rt,{children:e.jsx($t,{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(ee,{value:`${u.getState().pagination.pageSize}`,onValueChange:o=>{u.setPageSize(Number(o))},children:[e.jsx(X,{className:"h-8 w-[70px]",children:e.jsx(se,{placeholder:u.getState().pagination.pageSize})}),e.jsx(Z,{side:"top",children:[10,20,30,40,50].map(o=>e.jsx(U,{value:`${o}`,children:o},o))})]}),e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.records")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"flex w-[100px] items-center justify-center text-sm",children:t("trafficRecord.page",{current:u.getState().pagination.pageIndex+1,total:u.getPageCount()})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>u.previousPage(),disabled:!u.getCanPreviousPage()||x,children:e.jsx(Dp,{className:"h-4 w-4"})}),e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>u.nextPage(),disabled:!u.getCanNextPage()||x,children:e.jsx(Fp,{className:"h-4 w-4"})})]})]})]})]})]})]})}function Pp({user:s,trigger:n,onSuccess:t}){const{t:l}=M("user"),[a,i]=m.useState(!1),[r,d]=m.useState(""),[x,u]=m.useState(!1),{data:o,isLoading:c}=oe({queryKey:["trafficResetHistory",s.id],queryFn:()=>pa.getUserHistory(s.id,{limit:10}),enabled:a}),h=async()=>{try{u(!0);const{data:w}=await pa.resetUser({user_id:s.id,reason:r.trim()||void 0});w&&(A.success(l("traffic_reset.reset_success")),i(!1),d(""),t?.())}finally{u(!1)}},D=w=>{switch(w){case"manual":return"bg-blue-100 text-blue-800 border-blue-200";case"monthly":return"bg-green-100 text-green-800 border-green-200";case"yearly":return"bg-purple-100 text-purple-800 border-purple-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},S=w=>{switch(w){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(he,{open:a,onOpenChange:i,children:[e.jsx(hs,{asChild:!0,children:n}),e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-hidden",children:[e.jsxs(je,{children:[e.jsxs(pe,{className:"flex items-center gap-2",children:[e.jsx(la,{className:"h-5 w-5"}),l("traffic_reset.title")]}),e.jsx(Ge,{children:l("traffic_reset.description",{email:s.email})})]}),e.jsxs(Dt,{defaultValue:"reset",className:"w-full",children:[e.jsxs(xt,{className:"grid w-full grid-cols-2",children:[e.jsxs(Xe,{value:"reset",className:"flex items-center gap-2",children:[e.jsx(la,{className:"h-4 w-4"}),l("traffic_reset.tabs.reset")]}),e.jsxs(Xe,{value:"history",className:"flex items-center gap-2",children:[e.jsx(bl,{className:"h-4 w-4"}),l("traffic_reset.tabs.history")]})]}),e.jsxs(ks,{value:"reset",className:"space-y-4",children:[e.jsxs(Pe,{children:[e.jsx(Ee,{className:"pb-3",children:e.jsxs(Ae,{className:"flex items-center gap-2 text-lg",children:[e.jsx(Jr,{className:"h-5 w-5"}),l("traffic_reset.user_info")]})}),e.jsx(Ve,{className:"space-y-3",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("columns.email")}),e.jsx("p",{className:"font-medium",children:s.email})]}),e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("columns.used_traffic")}),e.jsx("p",{className:"font-medium",children:Ie(s.total_used)})]}),e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("columns.total_traffic")}),e.jsx("p",{className:"font-medium",children:Ie(s.transfer_enable)})]}),e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("columns.expire_time")}),e.jsx("p",{className:"font-medium",children:s.expired_at?re(s.expired_at):l("columns.expire_status.permanent")})]})]})})]}),e.jsxs(Pe,{className:"border-amber-200 bg-amber-50",children:[e.jsx(Ee,{className:"pb-3",children:e.jsxs(Ae,{className:"flex items-center gap-2 text-lg text-amber-800",children:[e.jsx(na,{className:"h-5 w-5"}),l("traffic_reset.warning.title")]})}),e.jsx(Ve,{children:e.jsxs("ul",{className:"space-y-2 text-sm text-amber-700",children:[e.jsxs("li",{children:["• ",l("traffic_reset.warning.irreversible")]}),e.jsxs("li",{children:["• ",l("traffic_reset.warning.reset_to_zero")]}),e.jsxs("li",{children:["• ",l("traffic_reset.warning.logged")]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(as,{htmlFor:"reason",children:l("traffic_reset.reason.label")}),e.jsx($s,{id:"reason",placeholder:l("traffic_reset.reason.placeholder"),value:r,onChange:w=>d(w.target.value),className:"min-h-[80px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("traffic_reset.reason.optional")})]}),e.jsxs(qe,{children:[e.jsx(J,{variant:"outline",onClick:()=>i(!1),children:l("common:cancel")}),e.jsx(J,{onClick:h,disabled:x,className:"bg-destructive hover:bg-destructive/90",children:x?e.jsxs(e.Fragment,{children:[e.jsx(da,{className:"mr-2 h-4 w-4 animate-spin"}),l("traffic_reset.resetting")]}):e.jsxs(e.Fragment,{children:[e.jsx(la,{className:"mr-2 h-4 w-4"}),l("traffic_reset.confirm_reset")]})})]})]}),e.jsx(ks,{value:"history",className:"space-y-4",children:c?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(da,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[o?.data?.user&&e.jsxs(Pe,{children:[e.jsx(Ee,{className:"pb-3",children:e.jsx(Ae,{className:"text-lg",children:l("traffic_reset.history.summary")})}),e.jsx(Ve,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("traffic_reset.history.reset_count")}),e.jsx("p",{className:"font-medium",children:o.data.user.reset_count})]}),e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("traffic_reset.history.last_reset")}),e.jsx("p",{className:"font-medium",children:o.data.user.last_reset_at?re(o.data.user.last_reset_at):l("traffic_reset.history.never")})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(as,{className:"text-muted-foreground",children:l("traffic_reset.history.next_reset")}),e.jsx("p",{className:"font-medium",children:o.data.user.next_reset_at?re(o.data.user.next_reset_at):l("traffic_reset.history.no_schedule")})]})]})})]}),e.jsxs(Pe,{children:[e.jsxs(Ee,{className:"pb-3",children:[e.jsx(Ae,{className:"text-lg",children:l("traffic_reset.history.records")}),e.jsx(it,{children:l("traffic_reset.history.recent_records")})]}),e.jsx(Ve,{children:e.jsx(Ct,{className:"h-[300px]",children:o?.data?.history?.length?e.jsx("div",{className:"space-y-3",children:o.data.history.map((w,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(H,{className:D(w.reset_type),children:w.reset_type_name}),e.jsx(H,{variant:"outline",className:S(w.trigger_source),children:w.trigger_source_name})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsxs(as,{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(Qn,{className:"h-3 w-3"}),l("traffic_reset.history.reset_time")]}),e.jsx("p",{className:"font-medium",children:re(w.reset_time)})]}),e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("traffic_reset.history.traffic_cleared")}),e.jsx("p",{className:"font-medium text-destructive",children:w.old_traffic.formatted})]})]})]})}),F{i(s)},[s]),e.jsxs(he,{children:[e.jsx(hs,{asChild:!0,children:n}),e.jsxs(ue,{className:"max-w-xl",children:[e.jsxs(je,{className:"space-y-2",children:[e.jsx(pe,{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("dialog.fields.userId"),":",a.id]}),e.jsx(Rp,{banned:a.banned,isAdmin:a.is_admin,isStaff:a.is_staff})]})})]}),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(Ne,{label:l("dialog.fields.email"),value:a.email,valueClassName:"font-medium"}),e.jsx(Ne,{label:l("dialog.fields.uuid"),value:a.uuid,valueClassName:"font-mono text-xs"}),e.jsx(Ne,{label:l("dialog.fields.token"),value:a.token,valueClassName:"font-mono text-xs"}),e.jsx(Ne,{label:l("dialog.fields.remarks"),value:a.remarks}),e.jsx(Ne,{label:l("dialog.fields.telegramId"),value:a.telegram_id?e.jsx("span",{className:"font-mono text-xs",children:a.telegram_id}):"-"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.subscriptionInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ne,{label:l("dialog.fields.subscriptionPlan"),value:a.plan?.name,valueClassName:"font-medium"}),e.jsx(Ne,{label:l("dialog.fields.permissionGroup"),value:a.group?.name,valueClassName:"font-medium"}),e.jsx(Ne,{label:l("dialog.fields.expiredAt"),value:e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(fe,{children:e.jsx("span",{className:"font-mono text-xs",children:a.expired_at==null?l("columns.expire_status.permanent"):re(a.expired_at,"YYYY-MM-DD")})}),e.jsx(xe,{side:"bottom",className:"space-y-1 p-3",children:a.expired_at!=null?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[l("columns.expire_time"),":"," ",re(a.expired_at)]}),e.jsx("p",{className:b("text-sm font-medium",a.expired_ate.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"})}),Ip=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"})}),Mp=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"})}),zl=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"})}),Op=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"})}),zp=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"})}),$p=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"})}),Ap=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"})}),qp=(s,n,t,l)=>{const{t:a}=M("user");return[{accessorKey:"is_admin",header:({column:i})=>e.jsx($,{column:i,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(i,r,d)=>d.includes(i.getValue(r)),size:0},{accessorKey:"is_staff",header:({column:i})=>e.jsx($,{column:i,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(i,r,d)=>d.includes(i.getValue(r)),size:0},{accessorKey:"id",header:({column:i})=>e.jsx($,{column:i,title:a("columns.id")}),cell:({row:i})=>e.jsx(H,{variant:"outline",children:i.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:i})=>e.jsx($,{column:i,title:a("columns.email")}),cell:({row:i})=>{const r=i.original.t||0,d=Date.now()/1e3-r<120,x=Math.floor(Date.now()/1e3-r);let u=d?a("columns.online_status.online"):r===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:re(r)});if(!d&&r!==0){const D=Math.floor(x/60),S=Math.floor(D/60),w=Math.floor(S/24);w>0?u+=` +`)||d("plan.form.submit.error.validation","表单校验失败"))},w=y=>{if(isNaN(y))return;const I=Object.entries(Fa).reduce((v,[_,C])=>{const z=y*C.months*C.discount;return{...v,[_]:z.toFixed(2)}},{});x.setValue("prices",I,{shouldDirty:!0})},F=()=>{n(!1),l(null),x.reset(Da)};return e.jsx(he,{open:s,onOpenChange:F,children:e.jsxs(ue,{children:[e.jsxs(je,{children:[e.jsx(pe,{children:d(t?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(Ge,{})]}),e.jsx(Re,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(D,S),children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(g,{control:x.control,name:"name",render:({field:y})=>e.jsxs(p,{children:[e.jsx(f,{children:d("plan.form.name.label")}),e.jsx(j,{children:e.jsx(k,{placeholder:d("plan.form.name.placeholder"),...y})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"tags",render:({field:y})=>e.jsxs(p,{children:[e.jsx(f,{children:d("plan.form.tags.label","标签")}),e.jsx(j,{children:e.jsx(xn,{value:y.value||[],onChange:y.onChange,placeholder:d("plan.form.tags.placeholder","输入标签后按回车确认"),className:"w-full"})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"group_id",render:({field:y})=>e.jsxs(p,{children:[e.jsxs(f,{className:"flex items-center justify-between",children:[d("plan.form.group.label"),e.jsx(hn,{dialogTrigger:e.jsx(P,{variant:"link",children:d("plan.form.group.add")}),refetch:h})]}),e.jsxs(ee,{value:y.value?.toString()??"",onValueChange:I=>y.onChange(I?Number(I):null),children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:d("plan.form.group.placeholder")})})}),e.jsx(Z,{children:o?.map(I=>e.jsx(U,{value:I.id.toString(),children:I.name},I.id))})]}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"transfer_enable",render:({field:y})=>e.jsxs(p,{className:"flex-1",children:[e.jsx(f,{children:d("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(j,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.transfer.placeholder"),className:"rounded-r-none",...y})}),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(E,{})]})}),e.jsx(g,{control:x.control,name:"speed_limit",render:({field:y})=>e.jsxs(p,{className:"flex-1",children:[e.jsx(f,{children:d("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(j,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.speed.placeholder"),className:"rounded-r-none",...y,value:y.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(E,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:d("plan.form.price.title")}),e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(k,{type:"number",step:"0.01",placeholder:d("plan.form.price.base_price"),className:"h-7 w-32 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500",onChange:y=>{const I=parseFloat(y.target.value);w(I)}})]}),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const y=Object.keys(Fa).reduce((I,v)=>({...I,[v]:""}),{});x.setValue("prices",y,{shouldDirty:!0})},children:d("plan.form.price.clear.button")})}),e.jsx(xe,{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(Fa).filter(([y])=>!["onetime","reset_traffic"].includes(y)).map(([y,I])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(g,{control:x.control,name:`prices.${y}`,render:({field:v})=>e.jsxs(p,{children:[e.jsxs(f,{className:"text-xs font-medium text-muted-foreground",children:[d(`plan.columns.price_period.${y}`),e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",I.months===1?d("plan.form.price.period.monthly"):d("plan.form.price.period.months",{count:I.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(j,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,step:"0.01",...v,value:v.value??"",onChange:_=>v.onChange(_.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"})})]})]})})},y))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(Fa).filter(([y])=>["onetime","reset_traffic"].includes(y)).map(([y,I])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(g,{control:x.control,name:`prices.${y}`,render:({field:v})=>e.jsx(p,{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(f,{className:"text-xs font-medium",children:d(`plan.columns.price_period.${y}`)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:d(y==="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(j,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,step:"0.01",...v,value:v.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"})})]})]})})})},y))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(g,{control:x.control,name:"device_limit",render:({field:y})=>e.jsxs(p,{className:"flex-1",children:[e.jsx(f,{children:d("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(j,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.device.placeholder"),className:"rounded-r-none",...y,value:y.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(E,{})]})}),e.jsx(g,{control:x.control,name:"capacity_limit",render:({field:y})=>e.jsxs(p,{className:"flex-1",children:[e.jsx(f,{children:d("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(j,{children:e.jsx(k,{type:"number",min:0,placeholder:d("plan.form.capacity.placeholder"),className:"rounded-r-none",...y,value:y.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(E,{})]})})]}),e.jsx(g,{control:x.control,name:"reset_traffic_method",render:({field:y})=>e.jsxs(p,{children:[e.jsx(f,{children:d("plan.form.reset_method.label")}),e.jsxs(ee,{value:y.value?.toString()??"null",onValueChange:I=>y.onChange(I=="null"?null:Number(I)),children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:d("plan.form.reset_method.placeholder")})})}),e.jsx(Z,{children:bh.map(I=>e.jsx(U,{value:I.value?.toString()??"null",children:d(`plan.form.reset_method.options.${I.label}`)},I.value))})]}),e.jsx(q,{className:"text-xs",children:d("plan.form.reset_method.description")}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"content",render:({field:y})=>{const[I,v]=m.useState(!1);return e.jsxs(p,{className:"space-y-2",children:[e.jsxs(f,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d("plan.form.content.label"),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",type:"button",onClick:()=>v(!I),children:I?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(xe,{side:"top",children:e.jsx("p",{className:"text-xs",children:d(I?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",type:"button",onClick:()=>{y.onChange(d("plan.form.content.template.content"))},children:d("plan.form.content.template.button")})}),e.jsx(xe,{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 ${I?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(j,{children:e.jsx(Yn,{style:{height:"400px"},value:y.value||"",renderHTML:_=>u.render(_),onChange:({text:_})=>y.onChange(_),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"})})}),I&&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(y.value||"")}})})]})]}),e.jsx(q,{className:"text-xs",children:d("plan.form.content.description")}),e.jsx(E,{})]})}})]}),e.jsx(qe,{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(g,{control:x.control,name:"force_update",render:({field:y})=>e.jsxs(p,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(j,{children:e.jsx(ll,{checked:y.value,onCheckedChange:y.onChange})}),e.jsx("div",{className:"",children:e.jsx(f,{className:"text-sm",children:d("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(P,{type:"button",variant:"outline",onClick:F,children:d("plan.form.submit.cancel")}),e.jsx(P,{type:"submit",disabled:i,children:d(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})})]})})}function _h(){const[s,n]=m.useState({}),[t,l]=m.useState({"drag-handle":!1}),[a,i]=m.useState([]),[r,d]=m.useState([]),[x,u]=m.useState(!1),[o,c]=m.useState({pageSize:20,pageIndex:0}),[h,D]=m.useState([]),{refetch:S}=oe({queryKey:["planList"],queryFn:async()=>{const{data:v}=await Ts.getList();return D(v),v}});m.useEffect(()=>{l({"drag-handle":x}),c({pageSize:x?99999:10,pageIndex:0})},[x]);const w=(v,_)=>{x&&(v.dataTransfer.setData("text/plain",_.toString()),v.currentTarget.classList.add("opacity-50"))},F=(v,_)=>{if(!x)return;v.preventDefault(),v.currentTarget.classList.remove("bg-muted");const C=parseInt(v.dataTransfer.getData("text/plain"));if(C===_)return;const z=[...h],[V]=z.splice(C,1);z.splice(_,0,V),D(z)},y=async()=>{if(!x){u(!0);return}const v=h?.map(_=>_.id);Ts.sort(v).then(()=>{A.success("排序保存成功"),u(!1),S()}).finally(()=>{u(!1)})},I=es({data:h||[],columns:jh(S),state:{sorting:r,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:o},enableRowSelection:!0,onPaginationChange:c,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:l,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}},pageCount:x?1:void 0});return e.jsx(gh,{refreshData:S,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(ds,{table:I,toolbar:v=>e.jsx(fh,{table:v,refetch:S,saveOrder:y,isSortMode:x}),draggable:x,onDragStart:w,onDragEnd:v=>v.currentTarget.classList.remove("opacity-50"),onDragOver:v=>{v.preventDefault(),v.currentTarget.classList.add("bg-muted")},onDragLeave:v=>v.currentTarget.classList.remove("bg-muted"),onDrop:F,showPagination:!x}),e.jsx(yh,{})]})})}function Nh(){const{t:s}=M("subscribe");return e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{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(_h,{})})]})]})}const wh=Object.freeze(Object.defineProperty({__proto__:null,default:Nh},Symbol.toStringTag,{value:"Module"})),Mt=[{value:me.PENDING,label:Qt[me.PENDING],icon:Pd,color:Xt[me.PENDING]},{value:me.PROCESSING,label:Qt[me.PROCESSING],icon:Kr,color:Xt[me.PROCESSING]},{value:me.COMPLETED,label:Qt[me.COMPLETED],icon:Mn,color:Xt[me.COMPLETED]},{value:me.CANCELLED,label:Qt[me.CANCELLED],icon:Br,color:Xt[me.CANCELLED]},{value:me.DISCOUNTED,label:Qt[me.DISCOUNTED],icon:Mn,color:Xt[me.DISCOUNTED]}],ta=[{value:ye.PENDING,label:Ca[ye.PENDING],icon:Ld,color:Sa[ye.PENDING]},{value:ye.PROCESSING,label:Ca[ye.PROCESSING],icon:Kr,color:Sa[ye.PROCESSING]},{value:ye.VALID,label:Ca[ye.VALID],icon:Mn,color:Sa[ye.VALID]},{value:ye.INVALID,label:Ca[ye.INVALID],icon:Br,color:Sa[ye.INVALID]}];function Pa({column:s,title:n,options:t}){const l=s?.getFacetedUniqueValues(),a=s?.getFilterValue(),i=Array.isArray(a)?new Set(a):a!==void 0?new Set([a]):new Set;return e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(en,{className:"mr-2 h-4 w-4"}),n,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:i.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:i.size>2?e.jsxs(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):t.filter(r=>i.has(r.value)).map(r=>e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:r.label},r.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(st,{children:[e.jsx(ht,{placeholder:n}),e.jsxs(tt,{children:[e.jsx(pt,{children:"No results found."}),e.jsx(ys,{children:t.map(r=>{const d=i.has(r.value);return e.jsxs(Be,{onSelect:()=>{const x=new Set(i);d?x.delete(r.value):x.add(r.value);const u=Array.from(x);s?.setFilterValue(u.length?u:void 0)},children:[e.jsx("div",{className:b("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(kt,{className:b("h-4 w-4")})}),r.icon&&e.jsx(r.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${r.color}`}),e.jsx("span",{children:r.label}),l?.get(r.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(r.value)})]},r.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Gt,{}),e.jsx(ys,{children:e.jsx(Be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Ch=le({email:T().min(1),plan_id:Y(),period:T(),total_amount:Y()}),Sh={email:"",plan_id:0,total_amount:0,period:""};function Ii({refetch:s,trigger:n,defaultValues:t}){const{t:l}=M("order"),[a,i]=m.useState(!1),r=De({resolver:Le(Ch),defaultValues:{...Sh,...t},mode:"onChange"}),[d,x]=m.useState([]);return m.useEffect(()=>{a&&Ts.getList().then(({data:u})=>{x(u)})},[a]),e.jsxs(he,{open:a,onOpenChange:i,children:[e.jsx(hs,{asChild:!0,children:n||e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(He,{icon:"ion:add"}),e.jsx("div",{children:l("dialog.addOrder")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(je,{children:[e.jsx(pe,{children:l("dialog.assignOrder")}),e.jsx(Ge,{})]}),e.jsxs(Re,{...r,children:[e.jsx(g,{control:r.control,name:"email",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:l("dialog.fields.userEmail")}),e.jsx(j,{children:e.jsx(k,{placeholder:l("dialog.placeholders.email"),...u})})]})}),e.jsx(g,{control:r.control,name:"plan_id",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:l("dialog.fields.subscriptionPlan")}),e.jsx(j,{children:e.jsxs(ee,{value:u.value?u.value?.toString():void 0,onValueChange:o=>u.onChange(parseInt(o)),children:[e.jsx(X,{children:e.jsx(se,{placeholder:l("dialog.placeholders.plan")})}),e.jsx(Z,{children:d.map(o=>e.jsx(U,{value:o.id.toString(),children:o.name},o.id))})]})})]})}),e.jsx(g,{control:r.control,name:"period",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:l("dialog.fields.orderPeriod")}),e.jsx(j,{children:e.jsxs(ee,{value:u.value,onValueChange:u.onChange,children:[e.jsx(X,{children:e.jsx(se,{placeholder:l("dialog.placeholders.period")})}),e.jsx(Z,{children:Object.keys(Jm).map(o=>e.jsx(U,{value:o,children:l(`period.${o}`)},o))})]})})]})}),e.jsx(g,{control:r.control,name:"total_amount",render:({field:u})=>e.jsxs(p,{children:[e.jsx(f,{children:l("dialog.fields.paymentAmount")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:l("dialog.placeholders.amount"),value:u.value/100,onChange:o=>u.onChange(parseFloat(o.currentTarget.value)*100)})}),e.jsx(E,{})]})}),e.jsxs(qe,{children:[e.jsx(P,{variant:"outline",onClick:()=>i(!1),children:l("dialog.actions.cancel")}),e.jsx(P,{type:"submit",onClick:()=>{r.handleSubmit(u=>{_t.assign(u).then(({data:o})=>{o&&(s&&s(),r.reset(),i(!1),A.success(l("dialog.messages.addSuccess")))})})()},children:l("dialog.actions.confirm")})]})]})]})]})}function kh({table:s,refetch:n}){const{t}=M("order"),l=s.getState().columnFilters.length>0,a=Object.values(Bs).filter(x=>typeof x=="number").map(x=>({label:t(`type.${Bs[x]}`),value:x,color:x===Bs.NEW?"green-500":x===Bs.RENEWAL?"blue-500":x===Bs.UPGRADE?"purple-500":"orange-500"})),i=Object.values(ns).map(x=>({label:t(`period.${x}`),value:x,color:x===ns.MONTH_PRICE?"slate-500":x===ns.QUARTER_PRICE?"cyan-500":x===ns.HALF_YEAR_PRICE?"indigo-500":x===ns.YEAR_PRICE?"violet-500":x===ns.TWO_YEAR_PRICE?"fuchsia-500":x===ns.THREE_YEAR_PRICE?"pink-500":x===ns.ONETIME_PRICE?"rose-500":"orange-500"})),r=Object.values(me).filter(x=>typeof x=="number").map(x=>({label:t(`status.${me[x]}`),value:x,icon:x===me.PENDING?Mt[0].icon:x===me.PROCESSING?Mt[1].icon:x===me.COMPLETED?Mt[2].icon:x===me.CANCELLED?Mt[3].icon:Mt[4].icon,color:x===me.PENDING?"yellow-500":x===me.PROCESSING?"blue-500":x===me.COMPLETED?"green-500":x===me.CANCELLED?"red-500":"green-500"})),d=Object.values(ye).filter(x=>typeof x=="number").map(x=>({label:t(`commission.${ye[x]}`),value:x,icon:x===ye.PENDING?ta[0].icon:x===ye.PROCESSING?ta[1].icon:x===ye.VALID?ta[2].icon:ta[3].icon,color:x===ye.PENDING?"yellow-500":x===ye.PROCESSING?"blue-500":x===ye.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ii,{refetch:n}),e.jsx(k,{placeholder:t("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:x=>s.getColumn("trade_no")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2",children:[s.getColumn("type")&&e.jsx(Pa,{column:s.getColumn("type"),title:t("table.columns.type"),options:a}),s.getColumn("period")&&e.jsx(Pa,{column:s.getColumn("period"),title:t("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(Pa,{column:s.getColumn("status"),title:t("table.columns.status"),options:r}),s.getColumn("commission_status")&&e.jsx(Pa,{column:s.getColumn("commission_status"),title:t("table.columns.commissionStatus"),options:d})]}),l&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("actions.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]})}function us({label:s,value:n,className:t,valueClassName:l}){return e.jsxs("div",{className:b("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:b("text-sm",l),children:n||"-"})]})}function Th({status:s}){const{t:n}=M("order"),t={[me.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[me.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[me.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[me.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[me.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(H,{variant:"secondary",className:b("font-medium",t[s]),children:n(`status.${me[s]}`)})}function Dh({id:s,trigger:n}){const[t,l]=m.useState(!1),[a,i]=m.useState(),{t:r}=M("order");return m.useEffect(()=>{(async()=>{if(t){const{data:x}=await _t.getInfo({id:s});i(x)}})()},[t,s]),e.jsxs(he,{onOpenChange:l,open:t,children:[e.jsx(hs,{asChild:!0,children:n}),e.jsxs(ue,{className:"max-w-xl",children:[e.jsxs(je,{className:"space-y-2",children:[e.jsx(pe,{className:"text-lg font-medium",children:r("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:[r("table.columns.tradeNo"),":",a?.trade_no]}),!!a?.status&&e.jsx(Th,{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:r("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(us,{label:r("dialog.fields.userEmail"),value:a?.user?.email?e.jsxs(Xs,{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(ua,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(us,{label:r("dialog.fields.orderPeriod"),value:a&&r(`period.${a.period}`)}),e.jsx(us,{label:r("dialog.fields.subscriptionPlan"),value:a?.plan?.name,valueClassName:"font-medium"}),e.jsx(us,{label:r("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:r("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(us,{label:r("dialog.fields.paymentAmount"),value:Qs(a?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(Me,{className:"my-2"}),e.jsx(us,{label:r("dialog.fields.balancePayment"),value:Qs(a?.balance_amount||0)}),e.jsx(us,{label:r("dialog.fields.discountAmount"),value:Qs(a?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(us,{label:r("dialog.fields.refundAmount"),value:Qs(a?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(us,{label:r("dialog.fields.deductionAmount"),value:Qs(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:r("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(us,{label:r("dialog.fields.createdAt"),value:re(a?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(us,{label:r("dialog.fields.updatedAt"),value:re(a?.updated_at),valueClassName:"font-mono text-xs"})]})]}),a?.commission_status!==void 0&&a?.commission_balance&&e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:r("dialog.commissionInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(us,{label:r("dialog.fields.commissionStatus"),value:e.jsx(H,{variant:"secondary",className:b("font-medium",a?.commission_status===ye.PENDING?"bg-yellow-100 text-yellow-800 hover:bg-yellow-100":a?.commission_status===ye.PROCESSING?"bg-blue-100 text-blue-800 hover:bg-blue-100":a?.commission_status===ye.VALID?"bg-green-100 text-green-800 hover:bg-green-100":a?.commission_status===ye.INVALID?"bg-red-100 text-red-800 hover:bg-red-100":"bg-orange-100 text-orange-800 hover:bg-orange-100"),children:a?.commission_status!==void 0?r(`commission.${ye[a.commission_status]}`):r("dialog.commissionStatusActive")})}),e.jsx(us,{label:r("dialog.fields.commissionAmount"),value:Qs(a?.commission_balance||0),valueClassName:"font-medium text-orange-600"}),a?.actual_commission_balance&&e.jsx(us,{label:r("dialog.fields.actualCommissionAmount"),value:Qs(a?.actual_commission_balance||0),valueClassName:"font-medium text-orange-700"}),a?.invite_user&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"my-2"}),e.jsx(us,{label:r("dialog.fields.inviteUser"),value:e.jsxs(Xs,{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(ua,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]})}),e.jsx(us,{label:r("dialog.fields.inviteUserId"),value:a?.invite_user?.id,valueClassName:"font-mono text-xs"})]})]})]})]})]})]})}const Il={color:"text-slate-700",bgColor:"bg-slate-100/80"},Fh={[Bs.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Bs.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Bs.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Bs.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Ph={[ns.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[ns.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Lh=s=>me[s],Rh=s=>ye[s],Eh=s=>Bs[s],Vh=s=>{const{t:n}=M("order");return[{accessorKey:"trade_no",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.tradeNo")}),cell:({row:t})=>{const l=t.original.trade_no,a=l.length>6?`${l.slice(0,3)}...${l.slice(-3)}`:l;return e.jsx("div",{className:"flex items-center",children:e.jsx(Dh,{trigger:e.jsxs(J,{variant:"ghost",size:"sm",className:"flex h-8 items-center gap-1.5 px-2 font-medium text-primary transition-colors hover:bg-primary/10 hover:text-primary/80",children:[e.jsx("span",{className:"font-mono",children:a}),e.jsx(ua,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.type")}),cell:({row:t})=>{const l=t.getValue("type"),a=l!=null?Fh[l]??Il:Il,i=l!=null?Eh(l):void 0,r=i?n(`type.${i}`,{defaultValue:String(l)}):String(l??"-");return e.jsx(H,{variant:"secondary",className:b("font-medium transition-colors text-nowrap",a.color,a.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:r})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx($,{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($,{column:t,title:n("table.columns.period")}),cell:({row:t})=>{const l=t.getValue("period"),a=l!=null?Ph[l]:void 0;return e.jsx(H,{variant:"secondary",className:b("font-medium transition-colors text-nowrap",a?.color,a?.bgColor,"hover:bg-opacity-80"),children:l!=null?n(`period.${l}`,{defaultValue:String(l)}):"-"})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.amount")}),cell:({row:t})=>{const l=t.getValue("total_amount"),a=typeof l=="number"?(l/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($,{column:t,title:n("table.columns.status")}),e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(fe,{children:e.jsx(Ti,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(xe,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:t})=>{const l=Mt.find(a=>a.value===t.getValue("status"));return l?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l.icon&&e.jsx(l.icon,{className:`h-4 w-4 text-${l.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`status.${Lh(l.value)}`)})]}),l.value===me.PENDING&&e.jsxs(Js,{modal:!0,children:[e.jsx(Zs,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Ua,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(Ws,{align:"end",className:"w-[140px]",children:[e.jsx(Fe,{className:"cursor-pointer",onClick:async()=>{await _t.markPaid({trade_no:t.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(Fe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await _t.makeCancel({trade_no:t.original.trade_no}),s()},children:n("actions.cancel")})]})]})]}):e.jsx("span",{className:"text-muted-foreground",children:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.commission")}),cell:({row:t})=>{const l=t.getValue("commission_balance"),a=l?(l/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:l?`¥${a}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.commissionStatus")}),cell:({row:t})=>{const l=t.original.status,a=t.original.commission_balance,i=ta.find(r=>r.value===t.getValue("commission_status"));return a==0||!i?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i.icon&&e.jsx(i.icon,{className:`h-4 w-4 text-${i.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`commission.${Rh(i.value)}`)})]}),i.value===ye.PENDING&&l===me.COMPLETED&&e.jsxs(Js,{modal:!0,children:[e.jsx(Zs,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Ua,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(Ws,{align:"end",className:"w-[120px]",children:[e.jsx(Fe,{className:"cursor-pointer",onClick:async()=>{await _t.update({trade_no:t.original.trade_no,commission_status:ye.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(Fe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await _t.update({trade_no:t.original.trade_no,commission_status:ye.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.createdAt")}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:re(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function Ih(){const[s]=Gr(),[n,t]=m.useState({}),[l,a]=m.useState({}),[i,r]=m.useState([]),[d,x]=m.useState([]),[u,o]=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(([y,I])=>{const v=s.get(y);return v?{id:y,value:I==="number"?parseInt(v):v}:null}).filter(Boolean);F.length>0&&r(F)},[s]);const{refetch:c,data:h,isLoading:D}=oe({queryKey:["orderList",u,i,d],queryFn:()=>_t.getList({pageSize:u.pageSize,current:u.pageIndex+1,filter:i,sort:d})}),S=es({data:h?.data??[],columns:Vh(c),state:{sorting:d,columnVisibility:l,rowSelection:n,columnFilters:i,pagination:u},rowCount:h?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:r,onColumnVisibilityChange:a,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),onPaginationChange:o,getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ds,{table:S,toolbar:e.jsx(kh,{table:S,refetch:c}),showPagination:!0})}function Mh(){const{t:s}=M("order");return e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Ih,{})})]})]})}const Oh=Object.freeze(Object.defineProperty({__proto__:null,default:Mh},Symbol.toStringTag,{value:"Module"}));function zh({column:s,title:n,options:t}){const l=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(en,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(H,{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(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(st,{children:[e.jsx(ht,{placeholder:n}),e.jsxs(tt,{children:[e.jsx(pt,{children:"No results found."}),e.jsx(ys,{children:t.map(i=>{const r=a.has(i.value);return e.jsxs(Be,{onSelect:()=>{r?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:b("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",r?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(kt,{className:b("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),l?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:l.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Gt,{}),e.jsx(ys,{children:e.jsx(Be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const $h=s=>le({id:ce.number().nullable().optional(),name:T().min(1,s("form.name.required")),code:T().nullable(),type:ce.number(),value:ce.number(),started_at:ce.number(),ended_at:ce.number(),limit_use:fs([T(),Y()]).nullable(),limit_use_with_user:fs([T(),Y()]).nullable(),generate_count:ce.number().nullable().optional(),limit_plan_ids:Qe(ce.number()).default([]).nullable(),limit_period:Qe(Rd(oa)).default([]).nullable()}).refine(n=>n.ended_at>n.started_at,{message:s("form.validity.endTimeError"),path:["ended_at"]}),Ml={name:"",code:null,type:Ps.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},Ah=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 Mi({defaultValues:s,refetch:n,type:t="create",dialogTrigger:l=null,open:a,onOpenChange:i}){const{t:r}=M("coupon"),[d,x]=m.useState(!1),u=a??d,o=i??x,[c,h]=m.useState([]),D=$h(r),S=Ah(r),w=De({resolver:Le(D),defaultValues:s||Ml});m.useEffect(()=>{s&&w.reset(s)},[s,w]),m.useEffect(()=>{Ts.getList().then(({data:_})=>h(_))},[]);const F=_=>{if(!_)return;const C=(z,V)=>{const R=new Date(V*1e3);return z.setHours(R.getHours(),R.getMinutes(),R.getSeconds()),Math.floor(z.getTime()/1e3)};_.from&&w.setValue("started_at",C(_.from,w.watch("started_at"))),_.to&&w.setValue("ended_at",C(_.to,w.watch("ended_at")))},y=_=>{const C=new Date,z=Math.floor(C.getTime()/1e3),V=Math.floor((C.getTime()+_*24*60*60*1e3)/1e3);w.setValue("started_at",z),w.setValue("ended_at",V)},I=async _=>{const C=await Ka.save(_);if(_.generate_count&&typeof C=="string"){const z=new Blob([C],{type:"text/csv;charset=utf-8;"}),V=document.createElement("a");V.href=window.URL.createObjectURL(z),V.download=`coupons_${new Date().getTime()}.csv`,V.click(),window.URL.revokeObjectURL(V.href)}o(!1),t==="create"&&w.reset(Ml),n()},v=(_,C)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:C}),e.jsx(k,{type:"datetime-local",step:"1",value:re(w.watch(_),"YYYY-MM-DDTHH:mm:ss"),onChange:z=>{const V=new Date(z.target.value);w.setValue(_,Math.floor(V.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(he,{open:u,onOpenChange:o,children:[l&&e.jsx(hs,{asChild:!0,children:l}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsx(je,{children:e.jsx(pe,{children:r(t==="create"?"form.add":"form.edit")})}),e.jsx(Re,{...w,children:e.jsxs("form",{onSubmit:w.handleSubmit(I),className:"space-y-4",children:[e.jsx(g,{control:w.control,name:"name",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.name.label")}),e.jsx(k,{placeholder:r("form.name.placeholder"),..._}),e.jsx(E,{})]})}),t==="create"&&e.jsx(g,{control:w.control,name:"generate_count",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.generateCount.label")}),e.jsx(k,{type:"number",min:0,placeholder:r("form.generateCount.placeholder"),..._,value:_.value??"",onChange:C=>_.onChange(C.target.value===""?null:parseInt(C.target.value)),className:"h-9"}),e.jsx(q,{className:"text-xs",children:r("form.generateCount.description")}),e.jsx(E,{})]})}),(!w.watch("generate_count")||w.watch("generate_count")==null)&&e.jsx(g,{control:w.control,name:"code",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.code.label")}),e.jsx(k,{placeholder:r("form.code.placeholder"),..._,value:_.value??"",className:"h-9"}),e.jsx(q,{className:"text-xs",children:r("form.code.description")}),e.jsx(E,{})]})}),e.jsxs(p,{children:[e.jsx(f,{children:r("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(g,{control:w.control,name:"type",render:({field:_})=>e.jsxs(ee,{value:_.value.toString(),onValueChange:C=>{const z=_.value,V=parseInt(C);_.onChange(V);const R=w.getValues("value");R&&(z===Ps.AMOUNT&&V===Ps.PERCENTAGE?w.setValue("value",R/100):z===Ps.PERCENTAGE&&V===Ps.AMOUNT&&w.setValue("value",R*100))},children:[e.jsx(X,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(se,{placeholder:r("form.type.placeholder")})}),e.jsx(Z,{children:Object.entries(Qm).map(([C,z])=>e.jsx(U,{value:C,children:r(`table.toolbar.types.${C}`)},C))})]})}),e.jsx(g,{control:w.control,name:"value",render:({field:_})=>{const C=_.value==null?"":w.watch("type")===Ps.AMOUNT&&typeof _.value=="number"?(_.value/100).toString():_.value.toString();return e.jsx(k,{type:"number",placeholder:r("form.value.placeholder"),..._,value:C,onChange:z=>{const V=z.target.value;if(V===""){_.onChange("");return}const R=parseFloat(V);isNaN(R)||_.onChange(w.watch("type")===Ps.AMOUNT?Math.round(R*100):R)},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:w.watch("type")==Ps.AMOUNT?"¥":"%"})})]})]}),e.jsxs(p,{children:[e.jsx(f,{children:r("form.validity.label")}),e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(P,{variant:"outline",className:b("w-full justify-start text-left font-normal",!w.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(Ls,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"truncate",children:[re(w.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",r("form.validity.to")," ",re(w.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})]})}),e.jsxs(Ze,{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:r("form.timeRange.quickSet")}),e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-6",children:S.map(_=>e.jsx(P,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>y(_.days),type:"button",children:_.label},_.days))})]}),e.jsx("div",{className:"hidden border-b border-border sm:block",children:e.jsx(Rs,{mode:"range",selected:{from:new Date(w.watch("started_at")*1e3),to:new Date(w.watch("ended_at")*1e3)},onSelect:F,numberOfMonths:2})}),e.jsx("div",{className:"border-b border-border sm:hidden",children:e.jsx(Rs,{mode:"range",selected:{from:new Date(w.watch("started_at")*1e3),to:new Date(w.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:[v("started_at",r("table.validity.startTime")),e.jsx("div",{className:"text-center text-sm text-muted-foreground sm:mt-6",children:r("form.validity.to")}),v("ended_at",r("table.validity.endTime"))]})})]})]}),e.jsx(E,{})]}),e.jsx(g,{control:w.control,name:"limit_use",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.limitUse.label")}),e.jsx(k,{type:"number",min:0,placeholder:r("form.limitUse.placeholder"),..._,value:_.value??"",onChange:C=>_.onChange(C.target.value===""?null:parseInt(C.target.value)),className:"h-9"}),e.jsx(q,{className:"text-xs",children:r("form.limitUse.description")}),e.jsx(E,{})]})}),e.jsx(g,{control:w.control,name:"limit_use_with_user",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.limitUseWithUser.label")}),e.jsx(k,{type:"number",min:0,placeholder:r("form.limitUseWithUser.placeholder"),..._,value:_.value??"",onChange:C=>_.onChange(C.target.value===""?null:parseInt(C.target.value)),className:"h-9"}),e.jsx(q,{className:"text-xs",children:r("form.limitUseWithUser.description")}),e.jsx(E,{})]})}),e.jsx(g,{control:w.control,name:"limit_period",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.limitPeriod.label")}),e.jsx(mt,{options:Object.entries(oa).filter(([C])=>isNaN(Number(C))).map(([C,z])=>({label:r(`coupon:period.${z}`),value:C})),onChange:C=>{if(C.length===0){_.onChange([]);return}const z=C.map(V=>oa[V.value]);_.onChange(z)},value:(_.value||[]).map(C=>({label:r(`coupon:period.${C}`),value:Object.entries(oa).find(([z,V])=>V===C)?.[0]||""})),placeholder:r("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:r("form.limitPeriod.empty")})}),e.jsx(q,{className:"text-xs",children:r("form.limitPeriod.description")}),e.jsx(E,{})]})}),e.jsx(g,{control:w.control,name:"limit_plan_ids",render:({field:_})=>e.jsxs(p,{children:[e.jsx(f,{children:r("form.limitPlan.label")}),e.jsx(mt,{options:c?.map(C=>({label:C.name,value:C.id.toString()}))||[],onChange:C=>_.onChange(C.map(z=>Number(z.value))),value:(c||[]).filter(C=>(_.value||[]).includes(C.id)).map(C=>({label:C.name,value:C.id.toString()})),placeholder:r("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:r("form.limitPlan.empty")})}),e.jsx(E,{})]})}),e.jsx(qe,{children:e.jsx(P,{type:"submit",disabled:w.formState.isSubmitting,children:w.formState.isSubmitting?r("form.submit.saving"):r("form.submit.save")})})]})})]})]})}function qh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:l}=M("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Mi,{refetch:n,dialogTrigger:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(He,{icon:"ion:add"}),e.jsx("div",{children:l("form.add")})]})}),e.jsx(k,{placeholder:l("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(zh,{column:s.getColumn("type"),title:l("table.toolbar.type"),options:[{value:Ps.AMOUNT,label:l(`table.toolbar.types.${Ps.AMOUNT}`)},{value:Ps.PERCENTAGE,label:l(`table.toolbar.types.${Ps.PERCENTAGE}`)}]}),t&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[l("table.toolbar.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]})}const Oi=m.createContext(void 0);function Uh({children:s,refetch:n}){const[t,l]=m.useState(!1),[a,i]=m.useState(null),r=x=>{i(x),l(!0)},d=()=>{l(!1),i(null)};return e.jsxs(Oi.Provider,{value:{isOpen:t,currentCoupon:a,openEdit:r,closeEdit:d},children:[s,a&&e.jsx(Mi,{defaultValues:a,refetch:n,type:"edit",open:t,onOpenChange:l})]})}function Hh(){const s=m.useContext(Oi);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const Kh=s=>{const{t:n}=M("coupon");return[{accessorKey:"id",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(H,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx(te,{defaultChecked:t.original.show,onCheckedChange:l=>{Ka.update({id:t.original.id,show:l}).then(({data:a})=>!a&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx($,{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($,{column:t,title:n("table.columns.type")}),cell:({row:t})=>e.jsx(H,{variant:"outline",children:n(`table.toolbar.types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.code")}),cell:({row:t})=>e.jsx(H,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx($,{column:t,title:n("table.columns.limitUse")}),cell:({row:t})=>e.jsx(H,{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($,{column:t,title:n("table.columns.limitUseWithUser")}),cell:({row:t})=>e.jsx(H,{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($,{column:t,title:n("table.columns.validity")}),cell:({row:t})=>{const[l,a]=m.useState(!1),i=Date.now(),r=t.original.started_at*1e3,d=t.original.ended_at*1e3,x=i>d,u=ie.jsx($,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>{const{openEdit:l}=Hh();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>l(t.original),children:[e.jsx(ut,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),e.jsx(bs,{title:n("table.actions.deleteConfirm.title"),description:n("table.actions.deleteConfirm.description"),confirmText:n("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{Ka.drop({id:t.original.id}).then(({data:a})=>{a&&(A.success("删除成功"),s())})},children:e.jsxs(P,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(vs,{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 Bh(){const[s,n]=m.useState({}),[t,l]=m.useState({}),[a,i]=m.useState([]),[r,d]=m.useState([]),[x,u]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=oe({queryKey:["couponList",x,a,r],queryFn:()=>Ka.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:a,sort:r})}),h=es({data:c?.data??[],columns:Kh(o),state:{sorting:r,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:x},pageCount:Math.ceil((c?.total??0)/x.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:l,onPaginationChange:u,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Uh,{refetch:o,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ds,{table:h,toolbar:e.jsx(qh,{table:h,refetch:o})})})})}function Gh(){const{t:s}=M("coupon");return e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{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(Bh,{})})]})]})}const Wh=Object.freeze(Object.defineProperty({__proto__:null,default:Gh},Symbol.toStringTag,{value:"Module"})),Yh=le({name:T().min(1,"请输入模板名称"),description:T().optional(),type:Y().min(1).max(4),status:ie(),sort:Y().min(0),icon:T().optional(),background_image:T().optional(),conditions:le({allowed_plans:Qe(Y()).optional(),disallowed_plans:Qe(Y()).optional(),new_user_only:ie().optional(),new_user_max_days:Y().optional(),paid_user_only:ie().optional(),require_invite:ie().optional()}).optional(),limits:le({max_use_per_user:Y().optional(),cooldown_hours:Y().optional(),invite_reward_rate:Y().optional()}).optional(),rewards:le({balance:Y().optional(),transfer_enable:Y().optional(),expire_days:Y().optional(),device_limit:Y().optional(),reset_package:ie().optional(),plan_id:Y().optional(),plan_validity_days:Y().optional(),random_rewards:Qe(le({weight:Y(),balance:Y().optional(),transfer_enable:Y().optional(),expire_days:Y().optional(),device_limit:Y().optional()})).optional()}),special_config:le({start_time:Y().optional(),end_time:Y().optional(),festival_bonus:Y().optional()}).optional()});function zi({template:s,refetch:n,open:t,onOpenChange:l}){const{t:a}=M("giftCard"),[i,r]=m.useState(!1),[d,x]=m.useState([]),[u,o]=m.useState([]),c=De({resolver:Le(Yh),defaultValues:{name:"",description:"",type:1,status:!0,sort:0,icon:"",background_image:"",conditions:{},limits:{},rewards:{},special_config:{}}}),{fields:h,append:D,remove:S}=Ed({control:c.control,name:"rewards.random_rewards"});m.useEffect(()=>{t&&(async()=>{try{const C=(await Ts.getList()).data||[];x(C),o(C.map(z=>({label:z.name,value:z.id.toString()})))}catch(_){console.error("Failed to fetch plans:",_),A.error("Failed to load plan list")}})()},[t]),m.useEffect(()=>{if(s){const v=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:v.balance?v.balance/100:void 0,transfer_enable:typeof v.transfer_enable=="number"?v.transfer_enable/1024/1024/1024:void 0,expire_days:v.expire_days,device_limit:v.device_limit,reset_package:v.reset_package,plan_id:v.plan_id,plan_validity_days:v.plan_validity_days,random_rewards:v.random_rewards?.map(_=>({weight:_.weight,balance:_.balance?_.balance/100:void 0,transfer_enable:typeof _.transfer_enable=="number"?_.transfer_enable/1024/1024/1024:void 0,expire_days:_.expire_days,device_limit:_.device_limit}))||[]},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 w=v=>{console.error("Form validation failed:",v),A.error(a("messages.formInvalid"))},F=async v=>{r(!0);const _=JSON.parse(JSON.stringify(v));_.rewards&&(typeof _.rewards.balance=="number"&&(_.rewards.balance=Math.round(_.rewards.balance*100)),typeof _.rewards.transfer_enable=="number"&&(_.rewards.transfer_enable=Math.round(_.rewards.transfer_enable*1024*1024*1024)),_.rewards.random_rewards&&_.rewards.random_rewards.forEach(z=>{typeof z.balance=="number"&&(z.balance=Math.round(z.balance*100)),typeof z.transfer_enable=="number"&&(z.transfer_enable=Math.round(z.transfer_enable*1024*1024*1024))}));const C={..._,conditions:_.conditions||{},limits:_.limits||{},rewards:_.rewards||{},special_config:_.special_config||{}};try{s?(await Ms.updateTemplate({id:s.id,...C}),A.success(a("messages.templateUpdated"))):(await Ms.createTemplate(C),A.success(a("messages.templateCreated"))),n(),l(!1)}catch(z){const V=z?.response?.data?.errors;V&&Object.keys(V).forEach(R=>{c.setError(R,{type:"manual",message:V[R][0]})}),A.error(a(s?"messages.updateTemplateFailed":"messages.createTemplateFailed"))}finally{r(!1)}},y=c.watch("type"),I=y===1;return e.jsx(he,{open:t,onOpenChange:l,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(je,{children:e.jsx(pe,{children:a(s?"template.form.edit":"template.form.add")})}),e.jsx(Re,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(F,w),className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:c.control,name:"name",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.name.label")}),e.jsx(j,{children:e.jsx(k,{placeholder:a("template.form.name.placeholder"),...v})}),e.jsx(E,{})]})}),e.jsx(g,{control:c.control,name:"type",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.type.label")}),e.jsxs(ee,{value:v.value.toString(),onValueChange:_=>v.onChange(parseInt(_)),children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:a("template.form.type.placeholder")})})}),e.jsx(Z,{children:[1,2,3].map(_=>e.jsx(U,{value:_.toString(),children:a(`types.${_}`)},_))})]}),e.jsx(E,{})]})})]}),e.jsx(g,{control:c.control,name:"description",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.description.label")}),e.jsx(j,{children:e.jsx($s,{placeholder:a("template.form.description.placeholder"),...v})}),e.jsx(E,{})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:e.jsx(g,{control:c.control,name:"status",render:({field:v})=>e.jsxs(p,{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(f,{className:"text-base",children:a("template.form.status.label")}),e.jsx(q,{children:a("template.form.status.description")})]}),e.jsx(j,{children:e.jsx(te,{checked:v.value,onCheckedChange:v.onChange})})]})})}),e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:a("template.form.rewards.title")})}),e.jsxs(Ve,{className:"space-y-4",children:[I&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:c.control,name:"rewards.balance",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.balance.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.balance.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})}),e.jsx(g,{control:c.control,name:"rewards.transfer_enable",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.transfer_enable.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.placeholder"),value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})}),e.jsx(g,{control:c.control,name:"rewards.expire_days",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.expire_days.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.expire_days.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})}),e.jsx(g,{control:c.control,name:"rewards.device_limit",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.device_limit.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.device_limit.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})})]}),e.jsx(g,{control:c.control,name:"rewards.reset_package",render:({field:v})=>e.jsxs(p,{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(f,{children:a("template.form.rewards.reset_package.label")}),e.jsx(q,{children:a("template.form.rewards.reset_package.description")})]}),e.jsx(j,{children:e.jsx(te,{checked:v.value,onCheckedChange:v.onChange})})]})})]}),y===4&&e.jsx("p",{children:a("template.form.rewards.task_card.description")}),y===2&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:c.control,name:"rewards.plan_id",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.plan_id.label")}),e.jsxs(ee,{value:v.value?.toString(),onValueChange:_=>v.onChange(parseInt(_,10)),children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:a("template.form.rewards.plan_id.placeholder")})})}),e.jsx(Z,{children:d.map(_=>e.jsx(U,{value:_.id.toString(),children:_.name},_.id))})]}),e.jsx(E,{})]})}),e.jsx(g,{control:c.control,name:"rewards.plan_validity_days",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.rewards.plan_validity_days.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.plan_validity_days.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})})]}),y===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(f,{children:a("template.form.rewards.random_rewards.label")}),h.map((v,_)=>e.jsxs("div",{className:"flex items-center space-x-2 rounded-md border p-2",children:[e.jsx(g,{control:c.control,name:`rewards.random_rewards.${_}.weight`,render:({field:C})=>e.jsx(p,{children:e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.random_rewards.weight"),...C,value:C.value??"",onChange:z=>{const V=z.target.valueAsNumber;C.onChange(isNaN(V)?0:V)}})})})}),e.jsx(g,{control:c.control,name:`rewards.random_rewards.${_}.balance`,render:({field:C})=>e.jsx(p,{children:e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.balance.label"),...C,value:C.value??"",onChange:z=>{const V=z.target.valueAsNumber;C.onChange(isNaN(V)?void 0:V)}})})})}),e.jsx(g,{control:c.control,name:`rewards.random_rewards.${_}.transfer_enable`,render:({field:C})=>e.jsx(p,{children:e.jsx(j,{children:e.jsx(k,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.label")+" (GB)",value:C.value??"",onChange:z=>{const V=z.target.valueAsNumber;C.onChange(isNaN(V)?void 0:V)}})})})}),e.jsx(g,{control:c.control,name:`rewards.random_rewards.${_}.expire_days`,render:({field:C})=>e.jsx(p,{children:e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.expire_days.label"),...C,value:C.value??"",onChange:z=>{const V=z.target.valueAsNumber;C.onChange(isNaN(V)?void 0:V)}})})})}),e.jsx(g,{control:c.control,name:`rewards.random_rewards.${_}.device_limit`,render:({field:C})=>e.jsx(p,{children:e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.device_limit.label"),...C,value:C.value??"",onChange:z=>{const V=z.target.valueAsNumber;C.onChange(isNaN(V)?void 0:V)}})})})}),e.jsx(P,{type:"button",variant:"ghost",size:"icon",onClick:()=>S(_),children:e.jsx(Vd,{className:"h-4 w-4"})})]},v.id)),e.jsx(P,{type:"button",variant:"outline",onClick:()=>D({weight:10,balance:void 0,transfer_enable:void 0,expire_days:void 0,device_limit:void 0}),children:a("template.form.rewards.random_rewards.add")})]})]})]}),e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:a("template.form.conditions.title")})}),e.jsxs(Ve,{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 gap-4",children:e.jsx(g,{control:c.control,name:"conditions.new_user_max_days",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.conditions.new_user_max_days.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.conditions.new_user_max_days.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(g,{control:c.control,name:"conditions.new_user_only",render:({field:v})=>e.jsxs(p,{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(f,{children:a("template.form.conditions.new_user_only.label")})}),e.jsx(j,{children:e.jsx(te,{checked:v.value,onCheckedChange:v.onChange})})]})}),e.jsx(g,{control:c.control,name:"conditions.paid_user_only",render:({field:v})=>e.jsxs(p,{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(f,{children:a("template.form.conditions.paid_user_only.label")})}),e.jsx(j,{children:e.jsx(te,{checked:v.value,onCheckedChange:v.onChange})})]})}),e.jsx(g,{control:c.control,name:"conditions.require_invite",render:({field:v})=>e.jsxs(p,{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(f,{children:a("template.form.conditions.require_invite.label")})}),e.jsx(j,{children:e.jsx(te,{checked:v.value,onCheckedChange:v.onChange})})]})})]}),e.jsx(g,{control:c.control,name:"conditions.allowed_plans",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.conditions.allowed_plans.label")}),e.jsx(j,{children:e.jsx(mt,{value:v.value?.map(_=>({label:d.find(C=>C.id===_)?.name||`ID: ${_}`,value:_.toString()}))??[],onChange:_=>v.onChange(_.map(C=>parseInt(C.value))),options:u,placeholder:a("template.form.conditions.allowed_plans.placeholder")})})]})}),e.jsx(g,{control:c.control,name:"conditions.disallowed_plans",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.conditions.disallowed_plans.label")}),e.jsx(j,{children:e.jsx(mt,{value:v.value?.map(_=>({label:d.find(C=>C.id===_)?.name||`ID: ${_}`,value:_.toString()}))??[],onChange:_=>v.onChange(_.map(C=>parseInt(C.value))),options:u,placeholder:a("template.form.conditions.disallowed_plans.placeholder")})})]})})]})]}),e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:a("template.form.limits.title")})}),e.jsx(Ve,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:c.control,name:"limits.max_use_per_user",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.limits.max_use_per_user.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.limits.max_use_per_user.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})}),e.jsx(g,{control:c.control,name:"limits.cooldown_hours",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.limits.cooldown_hours.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",placeholder:a("template.form.limits.cooldown_hours.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})}),e.jsx(g,{control:c.control,name:"limits.invite_reward_rate",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.limits.invite_reward_rate.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",step:"0.01",placeholder:a("template.form.limits.invite_reward_rate.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})}),e.jsx(q,{children:a("template.form.limits.invite_reward_rate.description")})]})})]})})]}),e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:a("template.form.special_config.title")})}),e.jsx(Ve,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-3 items-end gap-4",children:[e.jsx(g,{control:c.control,name:"special_config.start_time",render:({field:v})=>e.jsxs(p,{className:"flex flex-col",children:[e.jsx(f,{children:a("template.form.special_config.start_time.label")}),e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(j,{children:e.jsxs(P,{variant:"outline",className:b("w-full pl-3 text-left font-normal",!v.value&&"text-muted-foreground"),children:[v.value?Oe(new Date(v.value*1e3),"PPP"):e.jsx("span",{children:a("template.form.special_config.start_time.placeholder")}),e.jsx(Ls,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(Rs,{mode:"single",selected:v.value?new Date(v.value*1e3):void 0,onSelect:_=>v.onChange(_?Math.floor(_.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(E,{})]})}),e.jsx(g,{control:c.control,name:"special_config.end_time",render:({field:v})=>e.jsxs(p,{className:"flex flex-col",children:[e.jsx(f,{children:a("template.form.special_config.end_time.label")}),e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(j,{children:e.jsxs(P,{variant:"outline",className:b("w-full pl-3 text-left font-normal",!v.value&&"text-muted-foreground"),children:[v.value?Oe(new Date(v.value*1e3),"PPP"):e.jsx("span",{children:a("template.form.special_config.end_time.placeholder")}),e.jsx(Ls,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(Rs,{mode:"single",selected:v.value?new Date(v.value*1e3):void 0,onSelect:_=>v.onChange(_?Math.floor(_.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(E,{})]})}),e.jsx(g,{control:c.control,name:"special_config.festival_bonus",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.special_config.festival_bonus.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",step:"0.1",placeholder:a("template.form.special_config.festival_bonus.placeholder"),...v,value:v.value??"",onChange:_=>{const C=_.target.valueAsNumber;v.onChange(isNaN(C)?void 0:C)}})})]})})]})})]}),e.jsxs(Pe,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:a("template.form.display.title")})}),e.jsx(Ve,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(g,{control:c.control,name:"icon",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.icon.label")}),e.jsx(j,{children:e.jsx(k,{placeholder:a("template.form.icon.placeholder"),...v})}),e.jsx(E,{})]})}),e.jsx(g,{control:c.control,name:"background_image",render:({field:v})=>e.jsxs(p,{children:[e.jsx(f,{children:a("template.form.background_image.label")}),e.jsx(j,{children:e.jsx(k,{placeholder:a("template.form.background_image.placeholder"),...v})}),e.jsx(E,{})]})})]})})]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(P,{type:"button",variant:"outline",onClick:()=>l(!1),children:a("common:cancel")}),e.jsx(P,{type:"submit",disabled:i,children:a(i?"common:saving":"common:submit")})]})]})})]})})}const $i=m.createContext(void 0);function Jh({children:s,refetch:n}){const[t,l]=m.useState(!1),[a,i]=m.useState(null),r=x=>{i(x),l(!!x)},d=()=>{l(!1),i(null)};return e.jsxs($i.Provider,{value:{isOpen:t,editingTemplate:a,setEditingTemplate:r,closeEdit:d},children:[s,e.jsx(zi,{template:a,refetch:n,open:t,onOpenChange:l})]})}function Qh(){const s=m.useContext($i);if(s===void 0)throw new Error("useTemplateEdit must be used within a TemplateEditProvider");return s}function Xh({rewards:s,type:n}){const{t}=M(["giftCard","common"]),l=[];return s&&(s.balance&&l.push(`${t("template.form.rewards.balance.short_label")}: ${s.balance/100} ${t("common:currency.yuan","元")}`),s.transfer_enable&&l.push(`${t("template.form.rewards.transfer_enable.short_label")}: ${Ie(s.transfer_enable)}`),s.expire_days&&l.push(`${t("template.form.rewards.expire_days.short_label")}: ${s.expire_days}${t("common:time.day","天")}`),s.device_limit&&l.push(`${t("template.form.rewards.device_limit.short_label")}: ${s.device_limit}`),n===2&&s.plan_id&&l.push(`${t("template.form.rewards.plan_id.short_label")}: ${s.plan_id}`),n===2&&s.plan_validity_days&&l.push(`${t("template.form.rewards.plan_validity_days.short_label")}: ${s.plan_validity_days}${t("common:time.day","天")}`),n===3&&s.random_rewards?.length&&l.push(t("types.3"))),l.length===0?e.jsx(H,{variant:"secondary",children:t("template.table.columns.no_rewards")}):e.jsx("div",{className:"flex flex-col space-y-1",children:l.map((a,i)=>e.jsx(H,{variant:"outline",className:"whitespace-nowrap",children:a},i))})}const Zh=s=>{const{t:n}=M("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.id")}),cell:({row:t})=>e.jsx(H,{children:t.original.id}),enableSorting:!0},{accessorKey:"status",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.status")}),cell:({row:t})=>{const[l,a]=m.useState(!1);return e.jsx(te,{checked:t.original.status,disabled:l,onCheckedChange:async i=>{a(!0);try{const{data:r}=await Ms.updateTemplate({id:t.original.id,status:i});r?(A.success(n("messages.templateUpdated")),s()):A.error(n("messages.updateTemplateFailed"))}catch{A.error(n("messages.updateTemplateFailed"))}finally{a(!1)}}})},enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx($,{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($,{column:t,title:n("template.table.columns.type")}),cell:({row:t})=>e.jsx(H,{variant:"outline",children:n(`types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"rewards",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.rewards")}),cell:({row:t})=>e.jsx(Xh,{rewards:t.original.rewards,type:t.original.type}),enableSorting:!1},{accessorKey:"sort",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.sort")}),cell:({row:t})=>e.jsx(H,{variant:"secondary",children:t.original.sort}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:re(t.original.created_at)}),enableSorting:!0},{id:"actions",header:({column:t})=>e.jsx($,{column:t,title:n("template.table.columns.actions")}),cell:({row:t})=>{const{setEditingTemplate:l}=Qh();return e.jsxs("div",{className:"flex space-x-2",children:[e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>l(t.original),children:[e.jsx(ut,{className:"h-4 w-4"}),n("template.actions.edit")]}),e.jsx(bs,{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 Ms.deleteTemplate({id:t.original.id});a?(A.success(n("messages.templateDeleted")),s()):A.error(n("messages.deleteTemplateFailed"))}catch{A.error(n("messages.deleteTemplateFailed"))}},children:e.jsxs(P,{variant:"outline",size:"sm",children:[e.jsx(vs,{className:"h-4 w-4"}),n("template.actions.delete")]})})]})},enableSorting:!1}]};function Ai({table:s}){const{t:n}=M("common");return e.jsxs(Js,{children:[e.jsx(Id,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(Wr,{className:"mr-2 h-4 w-4"}),n("table.viewOptions.button")]})}),e.jsxs(Ws,{align:"end",className:"w-[150px]",children:[e.jsx(an,{children:n("table.viewOptions.label")}),e.jsx(dt,{}),s.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>e.jsx(ci,{className:"capitalize",checked:t.getIsVisible(),onCheckedChange:l=>t.toggleVisibility(!!l),children:t.id},t.id))]})]})}function Wa({column:s,title:n,options:t}){const l=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsxs(J,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Md,{className:"mr-2 h-4 w-4"}),n,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:l.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:l.size>2?e.jsxs(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[l.size," selected"]}):t.filter(a=>l.has(a.value)).map(a=>e.jsx(H,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:a.label},`selected-${a.value}`))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(st,{children:[e.jsx(ht,{placeholder:n}),e.jsxs(tt,{children:[e.jsx(pt,{children:"No results found."}),e.jsx(ys,{children:t.map(a=>{const i=l.has(a.value);return e.jsxs(Be,{onSelect:()=>{i?l.delete(a.value):l.add(a.value);const r=Array.from(l);s?.setFilterValue(r.length?r:void 0)},children:[e.jsx("div",{className:b("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",i?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(La,{className:b("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}`)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Gt,{}),e.jsx(ys,{children:e.jsx(Be,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function ep({table:s,refetch:n}){const{t}=M("giftCard"),[l,a]=m.useState(!1),i=s.getState().columnFilters.length>0,r=[{label:t("types.1"),value:"1"},{label:t("types.2"),value:"2"},{label:t("types.3"),value:"3"},{label:t("types.4"),value:"4"},{label:t("types.5"),value:"5"},{label:t("types.6"),value:"6"},{label:t("types.7"),value:"7"},{label:t("types.8"),value:"8"},{label:t("types.9"),value:"9"},{label:t("types.10"),value:"10"}],d=[{label:t("common.enabled"),value:"true"},{label:t("common.disabled"),value:"false"}];return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(k,{placeholder:t("common.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:x=>s.getColumn("name")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(Wa,{column:s.getColumn("type"),title:t("template.table.columns.type"),options:r}),s.getColumn("status")&&e.jsx(Wa,{column:s.getColumn("status"),title:t("template.table.columns.status"),options:d}),i&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Yr,{className:"h-4 w-4 mr-2"}),t("template.form.add")]}),e.jsx(Ai,{table:s})]}),e.jsx(zi,{template:null,refetch:n,open:l,onOpenChange:a})]})}function sp(){const[s,n]=m.useState({}),[t,l]=m.useState({}),[a,i]=m.useState([]),[r,d]=m.useState([]),[x,u]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=oe({queryKey:["giftCardTemplates",x,a,r],queryFn:()=>Ms.getTemplates({per_page:x.pageSize,page:x.pageIndex+1,filter:a,sort:r})});console.log(c);const h=es({data:c?.data??[],columns:Zh(o),state:{sorting:r,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:x},pageCount:Math.ceil((c?.total??0)/x.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:l,onPaginationChange:u,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Jh,{refetch:o,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ds,{table:h,toolbar:e.jsx(ep,{table:h,refetch:o})})})})}const tp=le({template_id:Y().min(1,"请选择一个模板"),count:Y().min(1,"生成数量必须大于0").max(1e4,"单次最多生成10000个"),prefix:T().optional(),expires_hours:Y().min(1,"有效期必须大于0"),max_usage:Y().min(1,"最大使用次数必须大于0"),download_csv:ie().optional()});function ap({refetch:s,open:n,onOpenChange:t}){const{t:l}=M("giftCard"),[a,i]=m.useState(!1),[r,d]=m.useState([]);m.useEffect(()=>{n&&Ms.getTemplates({per_page:1e3,page:1}).then(({data:o})=>{d(o||[])})},[n]);const x=De({resolver:Le(tp),defaultValues:{count:10,prefix:"",expires_hours:24*30,max_usage:1,download_csv:!1}}),u=async o=>{i(!0);try{if(o.download_csv){const c=await Ms.generateCodes(o);if(c&&c instanceof Blob){const h=window.URL.createObjectURL(c),D=document.createElement("a");D.href=h,D.download=`gift_codes_${new Date().getTime()}.csv`,document.body.appendChild(D),D.click(),D.remove(),window.URL.revokeObjectURL(h),A.success(l("messages.codesGenerated")),s(),t(!1),x.reset()}}else await Ms.generateCodes(o),A.success(l("messages.codesGenerated")),s(),t(!1),x.reset()}catch{A.error(l("messages.generateCodesFailed"))}finally{i(!1)}};return e.jsx(he,{open:n,onOpenChange:t,children:e.jsxs(ue,{children:[e.jsx(je,{children:e.jsx(pe,{children:l("code.form.generate")})}),e.jsx(Re,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(u),className:"space-y-4",children:[e.jsx(g,{control:x.control,name:"template_id",render:({field:o})=>e.jsxs(p,{children:[e.jsx(f,{children:l("code.form.template_id.label")}),e.jsxs(ee,{onValueChange:c=>o.onChange(parseInt(c)),children:[e.jsx(j,{children:e.jsx(X,{children:e.jsx(se,{placeholder:l("code.form.template_id.placeholder")})})}),e.jsx(Z,{children:r.map(c=>e.jsx(U,{value:c.id.toString(),children:c.name},c.id))})]}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"count",render:({field:o})=>e.jsxs(p,{children:[e.jsx(f,{children:l("code.form.count.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"prefix",render:({field:o})=>e.jsxs(p,{children:[e.jsx(f,{children:l("code.form.prefix.label")}),e.jsx(j,{children:e.jsx(k,{...o})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"expires_hours",render:({field:o})=>e.jsxs(p,{children:[e.jsx(f,{children:l("code.form.expires_hours.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"max_usage",render:({field:o})=>e.jsxs(p,{children:[e.jsx(f,{children:l("code.form.max_usage.label")}),e.jsx(j,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(E,{})]})}),e.jsx(g,{control:x.control,name:"download_csv",render:({field:o})=>e.jsxs(p,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(j,{children:e.jsx("input",{type:"checkbox",checked:o.value,onChange:c=>o.onChange(c.target.checked)})}),e.jsx(f,{children:l("code.form.download_csv")})]})}),e.jsxs(qe,{children:[e.jsx(P,{type:"button",variant:"outline",onClick:()=>t(!1),children:l("common.cancel")}),e.jsx(P,{type:"submit",disabled:a,children:l(a?"code.form.submit.generating":"code.form.submit.generate")})]})]})})]})})}function np({table:s,refetch:n}){const{t}=M("giftCard"),[l,a]=m.useState(!1),i=s.getState().columnFilters.length>0,r=Object.entries(t("code.status",{returnObjects:!0})).map(([d,x])=>({value:d,label:x}));return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(k,{placeholder:t("common.search"),value:s.getColumn("code")?.getFilterValue()??"",onChange:d=>s.getColumn("code")?.setFilterValue(d.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("status")&&e.jsx(Wa,{column:s.getColumn("status"),title:t("code.table.columns.status"),options:r}),i&&e.jsxs(P,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Yr,{className:"h-4 w-4 mr-2"}),t("code.form.generate")]}),e.jsxs(P,{variant:"outline",size:"sm",disabled:!0,children:[e.jsx(ma,{className:"h-4 w-4 mr-2"}),t("common.export")]}),e.jsx(Ai,{table:s})]}),e.jsx(ap,{refetch:n,open:l,onOpenChange:a})]})}const lp=0,rp=1,ip=2,kn=3,op=s=>{const{t:n}=M("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.id")}),cell:({row:t})=>e.jsx(H,{children:t.original.id})},{accessorKey:"code",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.code")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(H,{variant:"secondary",children:t.original.code}),e.jsx(P,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>lt(t.original.code).then(()=>{A.success(n("common:copy.success"))}),children:e.jsx(Jn,{className:"h-4 w-4"})})]})},{accessorKey:"template_name",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.template_name")})},{accessorKey:"status",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.status")}),cell:({row:t})=>{const l=t.original.status,a=l===kn,i=l===lp||l===kn;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(H,{variant:l===rp?"secondary":l===ip||l===kn?"destructive":"default",children:n(`code.status.${l}`)}),i&&e.jsx(te,{checked:!a,onCheckedChange:async r=>{const d=r?"enable":"disable";try{const{data:x}=await Ms.toggleCode({id:t.original.id,action:d});x?(A.success(n("messages.codeStatusUpdated")),s()):A.error(n("messages.updateCodeStatusFailed"))}catch{A.error(n("messages.updateCodeStatusFailed"))}}})]})}},{accessorKey:"expires_at",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.expires_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:re(t.original.expires_at)})},{accessorKey:"usage_count",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.usage_count")}),cell:({row:t})=>e.jsx(H,{variant:"outline",children:t.original.usage_count})},{accessorKey:"max_usage",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.max_usage")}),cell:({row:t})=>e.jsx(H,{variant:"outline",children:t.original.max_usage})},{accessorKey:"created_at",header:({column:t})=>e.jsx($,{column:t,title:n("code.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:re(t.original.created_at)})}]};function cp(){const[s,n]=m.useState({}),[t,l]=m.useState({}),[a,i]=m.useState([]),[r,d]=m.useState([]),[x,u]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=oe({queryKey:["giftCardCodes",x,a,r],queryFn:()=>Ms.getCodes({per_page:x.pageSize,page:x.pageIndex+1,filter:a,sort:r})}),h=es({data:c?.data??[],columns:op(o),state:{sorting:r,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:x},pageCount:Math.ceil((c?.total??0)/x.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:l,onPaginationChange:u,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns(),getFacetedRowModel:zs(),getFacetedUniqueValues:Os(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(ds,{table:h,toolbar:e.jsx(np,{table:h,refetch:o})})})}const dp=()=>{const{t:s}=M("giftCard");return[{accessorKey:"id",header:({column:n})=>e.jsx($,{column:n,title:s("usage.table.columns.id")}),cell:({row:n})=>e.jsx(H,{children:n.original.id})},{accessorKey:"code",header:({column:n})=>e.jsx($,{column:n,title:s("usage.table.columns.code")}),cell:({row:n})=>e.jsx(H,{variant:"secondary",children:n.original.code})},{accessorKey:"user_email",header:({column:n})=>e.jsx($,{column:n,title:s("usage.table.columns.user_email")})},{accessorKey:"template_name",header:({column:n})=>e.jsx($,{column:n,title:s("usage.table.columns.template_name")})},{accessorKey:"created_at",header:({column:n})=>e.jsx($,{column:n,title:s("usage.table.columns.created_at")}),cell:({row:n})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:re(n.original.created_at)})}]};function mp(){const[s,n]=m.useState([]),[t,l]=m.useState([]),[a,i]=m.useState({pageIndex:0,pageSize:20}),{data:r}=oe({queryKey:["giftCardUsages",a,s,t],queryFn:()=>Ms.getUsages({per_page:a.pageSize,page:a.pageIndex+1,filter:s,sort:t})}),d=es({data:r?.data??[],columns:dp(),state:{sorting:t,columnFilters:s,pagination:a},pageCount:Math.ceil((r?.total??0)/a.pageSize),rowCount:r?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,onSortingChange:l,onColumnFiltersChange:n,onPaginationChange:i,getCoreRowModel:ss(),getFilteredRowModel:ws(),getPaginationRowModel:is(),getSortedRowModel:Ns()});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(k,{placeholder:"搜索用户邮箱...",value:d.getColumn("user_email")?.getFilterValue()??"",onChange:x=>d.getColumn("user_email")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"})}),e.jsx(ds,{table:d})]})}function up(){const{t:s}=M("giftCard"),{data:n,isLoading:t}=oe({queryKey:["giftCardStats"],queryFn:()=>Ms.getStatistics({})}),l=n?.data?.total_stats,a=[{title:s("statistics.total.templates_count"),value:l?.templates_count},{title:s("statistics.total.active_templates_count"),value:l?.active_templates_count},{title:s("statistics.total.codes_count"),value:l?.codes_count},{title:s("statistics.total.used_codes_count"),value:l?.used_codes_count}];return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:a.map((i,r)=>e.jsxs(Pe,{children:[e.jsx(Ee,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:e.jsx(Ae,{className:"text-sm font-medium",children:i.title})}),e.jsx(Ve,{children:t?e.jsx(we,{className:"h-8 w-1/2"}):e.jsx("div",{className:"text-2xl font-bold",children:i.value??0})})]},r))})}function xp(){const{t:s}=M("giftCard"),[n,t]=m.useState("templates");return e.jsxs(We,{children:[e.jsxs(Ye,{children:[e.jsx(ps,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(os,{}),e.jsx(cs,{})]})]}),e.jsxs(ts,{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(Dt,{value:n,onValueChange:t,className:"flex-1",children:[e.jsxs(xt,{className:"grid w-full grid-cols-4",children:[e.jsx(Xe,{value:"templates",children:s("tabs.templates")}),e.jsx(Xe,{value:"codes",children:s("tabs.codes")}),e.jsx(Xe,{value:"usages",children:s("tabs.usages")}),e.jsx(Xe,{value:"statistics",children:s("tabs.statistics")})]}),e.jsx(ks,{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(sp,{})]})}),e.jsx(ks,{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(cp,{})]})}),e.jsx(ks,{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(mp,{})]})}),e.jsx(ks,{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(up,{})]})})]})]})]})}const hp=Object.freeze(Object.defineProperty({__proto__:null,default:xp},Symbol.toStringTag,{value:"Module"}));function pp({open:s,onOpenChange:n,table:t}){const{t:l}=M("user"),[a,i]=m.useState(!1),[r,d]=m.useState(""),[x,u]=m.useState(""),o=async()=>{if(!r||!x){A.error(l("messages.send_mail.required_fields"));return}try{i(!0),await Ys.sendMail({subject:r,content:x,filter:t.getState().columnFilters,sort:t.getState().sorting[0]?.id,sort_type:t.getState().sorting[0]?.desc?"DESC":"ASC"}),A.success(l("messages.send_mail.success")),n(!1),d(""),u("")}catch{A.error(l("messages.send_mail.failed"))}finally{i(!1)}};return e.jsx(he,{open:s,onOpenChange:n,children:e.jsxs(ue,{className:"sm:max-w-[500px]",children:[e.jsxs(je,{children:[e.jsx(pe,{children:l("send_mail.title")}),e.jsx(Ge,{children:l("send_mail.description")})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"subject",className:"text-right",children:l("send_mail.subject")}),e.jsx(k,{id:"subject",value:r,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:l("send_mail.content")}),e.jsx($s,{id:"content",value:x,onChange:c=>u(c.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(qe,{children:e.jsx(J,{type:"submit",onClick:o,disabled:a,children:l(a?"send_mail.sending":"send_mail.send")})})]})})}function gp({trigger:s}){const{t:n}=M("user"),[t,l]=m.useState(!1),[a,i]=m.useState(30),{data:r,isLoading:d}=oe({queryKey:["trafficResetStats",a],queryFn:()=>pa.getStats({days:a}),enabled:t}),x=[{title:n("traffic_reset.stats.total_resets"),value:r?.data?.total_resets||0,icon:la,color:"text-blue-600",bgColor:"bg-blue-100"},{title:n("traffic_reset.stats.auto_resets"),value:r?.data?.auto_resets||0,icon:Aa,color:"text-green-600",bgColor:"bg-green-100"},{title:n("traffic_reset.stats.manual_resets"),value:r?.data?.manual_resets||0,icon:Ls,color:"text-orange-600",bgColor:"bg-orange-100"},{title:n("traffic_reset.stats.cron_resets"),value:r?.data?.cron_resets||0,icon:Qn,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(he,{open:t,onOpenChange:l,children:[e.jsx(hs,{asChild:!0,children:s}),e.jsxs(ue,{className:"max-w-2xl",children:[e.jsxs(je,{children:[e.jsxs(pe,{className:"flex items-center gap-2",children:[e.jsx(Gn,{className:"h-5 w-5"}),n("traffic_reset.stats.title")]}),e.jsx(Ge,{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(ee,{value:a.toString(),onValueChange:o=>i(Number(o)),children:[e.jsx(X,{className:"w-[180px]",children:e.jsx(se,{})}),e.jsx(Z,{children:u.map(o=>e.jsx(U,{value:o.value.toString(),children:o.label},o.value))})]})]}),d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(da,{className:"h-6 w-6 animate-spin"})}):e.jsx("div",{className:"grid grid-cols-2 gap-4",children:x.map((o,c)=>e.jsxs(Pe,{className:"relative overflow-hidden",children:[e.jsxs(Ee,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ae,{className:"text-sm font-medium text-muted-foreground",children:o.title}),e.jsx("div",{className:`rounded-lg p-2 ${o.bgColor}`,children:e.jsx(o.icon,{className:`h-4 w-4 ${o.color}`})})]}),e.jsxs(Ve,{children:[e.jsx("div",{className:"text-2xl font-bold",children:o.value.toLocaleString()}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:n("traffic_reset.stats.in_period",{days:a})})]})]},c))}),r?.data&&e.jsxs(Pe,{children:[e.jsxs(Ee,{children:[e.jsx(Ae,{className:"text-lg",children:n("traffic_reset.stats.breakdown")}),e.jsx(it,{children:n("traffic_reset.stats.breakdown_description")})]}),e.jsx(Ve,{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(H,{variant:"outline",className:"border-green-200 bg-green-50 text-green-700",children:[r.data.total_resets>0?(r.data.auto_resets/r.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(H,{variant:"outline",className:"border-orange-200 bg-orange-50 text-orange-700",children:[r.data.total_resets>0?(r.data.manual_resets/r.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(H,{variant:"outline",className:"border-purple-200 bg-purple-50 text-purple-700",children:[r.data.total_resets>0?(r.data.cron_resets/r.data.total_resets*100).toFixed(1):0,"%"]})]})]})})]})]})]})]})}const fp=le({email_prefix:T().optional(),email_suffix:T().min(1),password:T().optional(),expired_at:Y().optional().nullable(),plan_id:Y().nullable(),generate_count:Y().optional().nullable(),download_csv:ie().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"]}),jp={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0,download_csv:!1};function vp({refetch:s}){const{t:n}=M("user"),[t,l]=m.useState(!1),a=De({resolver:Le(fp),defaultValues:jp,mode:"onChange"}),[i,r]=m.useState([]);return m.useEffect(()=>{t&&Ts.getList().then(({data:d})=>{d&&r(d)})},[t]),e.jsxs(he,{open:t,onOpenChange:l,children:[e.jsx(hs,{asChild:!0,children:e.jsxs(J,{size:"sm",variant:"outline",className:"gap-0 space-x-2",children:[e.jsx(He,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(je,{children:[e.jsx(pe,{children:n("generate.title")}),e.jsx(Ge,{})]}),e.jsxs(Re,{...a,children:[e.jsxs(p,{children:[e.jsx(f,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!a.watch("generate_count")&&e.jsx(g,{control:a.control,name:"email_prefix",render:({field:d})=>e.jsx(k,{className:"flex-[5] rounded-r-none",placeholder:n("generate.form.email_prefix"),...d})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${a.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(g,{control:a.control,name:"email_suffix",render:({field:d})=>e.jsx(k,{className:"flex-[4] rounded-l-none",placeholder:n("generate.form.email_domain"),...d})})]})]}),e.jsx(g,{control:a.control,name:"password",render:({field:d})=>e.jsxs(p,{children:[e.jsx(f,{children:n("generate.form.password")}),e.jsx(k,{placeholder:n("generate.form.password_placeholder"),...d}),e.jsx(E,{})]})}),e.jsx(g,{control:a.control,name:"expired_at",render:({field:d})=>e.jsxs(p,{className:"flex flex-col",children:[e.jsx(f,{children:n("generate.form.expire_time")}),e.jsxs(ls,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(j,{children:e.jsxs(J,{variant:"outline",className:b("w-full pl-3 text-left font-normal",!d.value&&"text-muted-foreground"),children:[d.value?re(d.value):e.jsx("span",{children:n("generate.form.expire_time_placeholder")}),e.jsx(Ls,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(Ze,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(Od,{asChild:!0,children:e.jsx(J,{variant:"outline",className:"w-full",onClick:()=>{d.onChange(null)},children:n("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Rs,{mode:"single",selected:d.value?new Date(d.value*1e3):void 0,onSelect:x=>{x&&d.onChange(x?.getTime()/1e3)}})})]})]})]})}),e.jsx(g,{control:a.control,name:"plan_id",render:({field:d})=>e.jsxs(p,{children:[e.jsx(f,{children:n("generate.form.subscription")}),e.jsx(j,{children:e.jsxs(ee,{value:d.value?d.value.toString():"null",onValueChange:x=>d.onChange(x==="null"?null:parseInt(x)),children:[e.jsx(X,{children:e.jsx(se,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(Z,{children:[e.jsx(U,{value:"null",children:n("generate.form.subscription_none")}),i.map(x=>e.jsx(U,{value:x.id.toString(),children:x.name},x.id))]})]})})]})}),!a.watch("email_prefix")&&e.jsx(g,{control:a.control,name:"generate_count",render:({field:d})=>e.jsxs(p,{children:[e.jsx(f,{children:n("generate.form.generate_count")}),e.jsx(k,{type:"number",placeholder:n("generate.form.generate_count_placeholder"),value:d.value||"",onChange:x=>d.onChange(x.target.value?parseInt(x.target.value):null)})]})}),a.watch("generate_count")&&e.jsx(g,{control:a.control,name:"download_csv",render:({field:d})=>e.jsxs(p,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(j,{children:e.jsx(ll,{checked:d.value,onCheckedChange:d.onChange})}),e.jsx(f,{children:n("generate.form.download_csv")})]})})]}),e.jsxs(qe,{children:[e.jsx(J,{variant:"outline",onClick:()=>l(!1),children:n("generate.form.cancel")}),e.jsx(J,{onClick:()=>a.handleSubmit(async d=>{if(d.download_csv){const x=await Ys.generate(d);if(x&&x instanceof Blob){const u=window.URL.createObjectURL(x),o=document.createElement("a");o.href=u,o.download=`users_${new Date().getTime()}.csv`,document.body.appendChild(o),o.click(),o.remove(),window.URL.revokeObjectURL(u),A.success(n("generate.form.success")),a.reset(),s(),l(!1)}}else{const{data:x}=await Ys.generate(d);x&&(A.success(n("generate.form.success")),a.reset(),s(),l(!1))}})(),children:n("generate.form.submit")})]})]})]})}const bp=1,yp=1e6;let Tn=0;function _p(){return Tn=(Tn+1)%Number.MAX_SAFE_INTEGER,Tn.toString()}const Dn=new Map,Ol=s=>{if(Dn.has(s))return;const n=setTimeout(()=>{Dn.delete(s),ca({type:"REMOVE_TOAST",toastId:s})},yp);Dn.set(s,n)},Np=(s,n)=>{switch(n.type){case"ADD_TOAST":return{...s,toasts:[n.toast,...s.toasts].slice(0,bp)};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?Ol(t):s.toasts.forEach(l=>{Ol(l.id)}),{...s,toasts:s.toasts.map(l=>l.id===t||t===void 0?{...l,open:!1}:l)}}case"REMOVE_TOAST":return n.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==n.toastId)}}},Va=[];let Ia={toasts:[]};function ca(s){Ia=Np(Ia,s),Va.forEach(n=>{n(Ia)})}function wp({...s}){const n=_p(),t=a=>ca({type:"UPDATE_TOAST",toast:{...a,id:n}}),l=()=>ca({type:"DISMISS_TOAST",toastId:n});return ca({type:"ADD_TOAST",toast:{...s,id:n,open:!0,onOpenChange:a=>{a||l()}}}),{id:n,dismiss:l,update:t}}function Cp(){const[s,n]=m.useState(Ia);return m.useEffect(()=>(Va.push(n),()=>{const t=Va.indexOf(n);t>-1&&Va.splice(t,1)}),[s]),{...s,toast:wp,dismiss:t=>ca({type:"DISMISS_TOAST",toastId:t})}}const rl=Jl,qi=Xl,Sp=Ql,Ui=m.forwardRef(({className:s,...n},t)=>e.jsx(Xa,{className:b("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}));Ui.displayName=Xa.displayName;const kp=St("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"}}),pn=m.forwardRef(({side:s="right",className:n,children:t,...l},a)=>e.jsxs(Sp,{children:[e.jsx(Ui,{}),e.jsxs(Ya,{ref:a,className:b(kp({side:s}),n),...l,children:[e.jsxs(Un,{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(xs,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),t]})]}));pn.displayName=Ya.displayName;const gn=({className:s,...n})=>e.jsx("div",{className:b("flex flex-col space-y-2 text-center sm:text-left",s),...n});gn.displayName="SheetHeader";const Hi=({className:s,...n})=>e.jsx("div",{className:b("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});Hi.displayName="SheetFooter";const fn=m.forwardRef(({className:s,...n},t)=>e.jsx(Ja,{ref:t,className:b("text-lg font-semibold text-foreground",s),...n}));fn.displayName=Ja.displayName;const jn=m.forwardRef(({className:s,...n},t)=>e.jsx(Qa,{ref:t,className:b("text-sm text-muted-foreground",s),...n}));jn.displayName=Qa.displayName;function Tp({table:s,refetch:n,permissionGroups:t=[],subscriptionPlans:l=[]}){const{t:a}=M("user"),{toast:i}=Cp(),r=s.getState().columnFilters.length>0,[d,x]=m.useState([]),[u,o]=m.useState(!1),[c,h]=m.useState(!1),[D,S]=m.useState(!1),[w,F]=m.useState(!1),y=async()=>{try{const L=await Ys.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),ae=L;console.log(L);const G=new Blob([ae],{type:"text/csv;charset=utf-8;"}),ne=window.URL.createObjectURL(G),_e=document.createElement("a");_e.href=ne,_e.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(_e),_e.click(),_e.remove(),window.URL.revokeObjectURL(ne),i({title:a("messages.success"),description:a("messages.export.success")})}catch{i({title:a("messages.error"),description:a("messages.export.failed"),variant:"destructive"})}},I=async()=>{try{F(!0),await Ys.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),i({title:a("messages.success"),description:a("messages.batch_ban.success")}),n()}catch{i({title:a("messages.error"),description:a("messages.batch_ban.failed"),variant:"destructive"})}finally{F(!1),S(!1)}},v=[{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"}]}],_=L=>L*1024*1024*1024,C=L=>L/(1024*1024*1024),z=()=>{x([...d,{field:"",operator:"",value:""}])},V=L=>{x(d.filter((ae,G)=>G!==L))},R=(L,ae,G)=>{const ne=[...d];if(ne[L]={...ne[L],[ae]:G},ae==="field"){const _e=v.find(gs=>gs.value===G);_e&&(ne[L].operator=_e.operators[0].value,ne[L].value=_e.type==="boolean"?!1:"")}x(ne)},W=(L,ae)=>{const G=v.find(ne=>ne.value===L.field);if(!G)return null;switch(G.type){case"text":return e.jsx(k,{placeholder:a("filter.sheet.value"),value:L.value,onChange:ne=>R(ae,"value",ne.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(k,{type:"number",placeholder:a("filter.sheet.value_number",{unit:G.unit}),value:G.unit==="GB"?C(L.value||0):L.value,onChange:ne=>{const _e=Number(ne.target.value);R(ae,"value",G.unit==="GB"?_(_e):_e)}}),G.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:G.unit})]});case"date":return e.jsx(Rs,{mode:"single",selected:L.value,onSelect:ne=>R(ae,"value",ne),className:"flex flex-1 justify-center rounded-md border"});case"select":return e.jsxs(ee,{value:L.value,onValueChange:ne=>R(ae,"value",ne),children:[e.jsx(X,{children:e.jsx(se,{placeholder:a("filter.sheet.value")})}),e.jsx(Z,{children:G.useOptions?l.map(ne=>e.jsx(U,{value:ne.value.toString(),children:ne.label},ne.value)):G.options?.map(ne=>e.jsx(U,{value:ne.value.toString(),children:ne.label},ne.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(te,{checked:L.value,onCheckedChange:ne=>R(ae,"value",ne)}),e.jsx(as,{children:L.value?a("filter.boolean.true"):a("filter.boolean.false")})]});default:return null}},N=()=>{const L=d.filter(ae=>ae.field&&ae.operator&&ae.value!=="").map(ae=>{const G=v.find(_e=>_e.value===ae.field);let ne=ae.value;return ae.operator==="contains"?{id:ae.field,value:ne}:(G?.type==="date"&&ne instanceof Date&&(ne=Math.floor(ne.getTime()/1e3)),G?.type==="boolean"&&(ne=ne?1:0),{id:ae.field,value:`${ae.operator}:${ne}`})});s.setColumnFilters(L),o(!1)};return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-2",children:[e.jsx(vp,{refetch:n}),e.jsx(k,{placeholder:a("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:L=>s.getColumn("email")?.setFilterValue(L.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(rl,{open:u,onOpenChange:o,children:[e.jsx(qi,{asChild:!0,children:e.jsxs(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Wr,{className:"mr-2 h-4 w-4"}),a("filter.advanced"),d.length>0&&e.jsx(H,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:d.length})]})}),e.jsxs(pn,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(gn,{children:[e.jsx(fn,{children:a("filter.sheet.title")}),e.jsx(jn,{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(P,{variant:"outline",size:"sm",onClick:z,children:a("filter.sheet.add")})]}),e.jsx(Ct,{className:"h-[calc(100vh-280px)] ",children:e.jsx("div",{className:"space-y-4",children:d.map((L,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(as,{children:a("filter.sheet.condition",{number:ae+1})}),e.jsx(P,{variant:"ghost",size:"sm",onClick:()=>V(ae),children:e.jsx(xs,{className:"h-4 w-4"})})]}),e.jsxs(ee,{value:L.field,onValueChange:G=>R(ae,"field",G),children:[e.jsx(X,{children:e.jsx(se,{placeholder:a("filter.sheet.field")})}),e.jsx(Z,{children:e.jsx(Fs,{children:v.map(G=>e.jsx(U,{value:G.value,className:"cursor-pointer",children:G.label},G.value))})})]}),L.field&&e.jsxs(ee,{value:L.operator,onValueChange:G=>R(ae,"operator",G),children:[e.jsx(X,{children:e.jsx(se,{placeholder:a("filter.sheet.operator")})}),e.jsx(Z,{children:v.find(G=>G.value===L.field)?.operators.map(G=>e.jsx(U,{value:G.value,children:G.label},G.value))})]}),L.field&&L.operator&&W(L,ae)]},ae))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(P,{variant:"outline",onClick:()=>{x([]),o(!1)},children:a("filter.sheet.reset")}),e.jsx(P,{onClick:N,children:a("filter.sheet.apply")})]})]})]})]}),r&&e.jsxs(P,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),x([])},className:"h-8 px-2 lg:px-3",children:[a("filter.sheet.reset"),e.jsx(xs,{className:"ml-2 h-4 w-4"})]}),e.jsxs(Js,{modal:!1,children:[e.jsx(Zs,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:a("actions.title")})}),e.jsxs(Ws,{children:[e.jsx(Fe,{onClick:()=>h(!0),children:a("actions.send_email")}),e.jsx(Fe,{onClick:y,children:a("actions.export_csv")}),e.jsx(dt,{}),e.jsx(Fe,{asChild:!0,children:e.jsx(gp,{trigger:e.jsx("div",{className:"w-full cursor-pointer px-2 py-1.5 text-sm",children:a("actions.traffic_reset_stats")})})}),e.jsx(dt,{}),e.jsx(Fe,{onClick:()=>S(!0),className:"text-red-600 focus:text-red-600",children:a("actions.batch_ban")})]})]})]}),e.jsx(pp,{open:c,onOpenChange:h,table:s}),e.jsx(al,{open:D,onOpenChange:S,children:e.jsxs(ln,{children:[e.jsxs(rn,{children:[e.jsx(cn,{children:a("actions.confirm_ban.title")}),e.jsx(dn,{children:a(r?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(on,{children:[e.jsx(un,{disabled:w,children:a("actions.confirm_ban.cancel")}),e.jsx(mn,{onClick:I,disabled:w,className:"bg-red-600 hover:bg-red-700 focus:ring-red-600",children:a(w?"actions.confirm_ban.banning":"actions.confirm_ban.confirm")})]})]})})]})}const Ki=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"})}),Bi=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"})}),Dp=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"})}),Fp=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})=>{const n=s.original.display_at??s.original.updated_at??s.original.created_at??s.original.record_at;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("time",{className:"text-sm text-muted-foreground",children:re(n,"YYYY/MM/DD HH:mm")})})}},{accessorKey:"u",header:"上行流量",cell:({row:s})=>{const n=parseFloat(s.original.server_rate||1)||1;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ki,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:Ie(s.original.u/n)})]})}},{accessorKey:"d",header:"下行流量",cell:({row:s})=>{const n=parseFloat(s.original.server_rate||1)||1;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Bi,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:Ie(s.original.d/n)})]})}},{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(H,{variant:"outline",className:"font-mono",children:[n,"x"]})})}},{accessorKey:"node_name",header:"节点",cell:({row:s})=>{const n=s.original.node_name||s.original.server_name||"-";return e.jsx("div",{className:"max-w-[200px] truncate text-sm",title:n,children:n})}},{accessorKey:"device_name",header:"设备",cell:({row:s})=>{const n=s.original.device_name||"Unknown";return e.jsx("div",{className:"max-w-[150px] truncate text-sm text-muted-foreground",title:n,children:n})}},{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:Ie(n)})}}];function Gi({user_id:s,dialogTrigger:n}){const{t}=M(["traffic"]),[l,a]=m.useState(!1),[i,r]=m.useState({pageIndex:0,pageSize:20}),{data:d,isLoading:x}=oe({queryKey:["userStats",s,i,l],queryFn:()=>l?Ys.getStats({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),u=es({data:d?.data??[],columns:Fn,pageCount:Math.ceil((d?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:ss(),onPaginationChange:r});return e.jsxs(he,{open:l,onOpenChange:a,children:[e.jsx(hs,{asChild:!0,children:n}),e.jsxs(ue,{className:"sm:max-w-[700px]",children:[e.jsx(je,{children:e.jsx(pe,{children:t("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Zn,{children:[e.jsx(el,{children:u.getHeaderGroups().map(o=>e.jsx(rt,{children:o.headers.map(c=>e.jsx(tl,{className:b("h-10 px-2 text-xs",c.id==="total"&&"text-right"),children:c.isPlaceholder?null:za(c.column.columnDef.header,c.getContext())},c.id))},o.id))}),e.jsx(sl,{children:x?Array.from({length:i.pageSize}).map((o,c)=>e.jsx(rt,{children:Array.from({length:Fn.length}).map((h,D)=>e.jsx($t,{className:"p-2",children:e.jsx(we,{className:"h-6 w-full"})},D))},c)):u.getRowModel().rows?.length?u.getRowModel().rows.map(o=>e.jsx(rt,{"data-state":o.getIsSelected()&&"selected",className:"h-10",children:o.getVisibleCells().map(c=>e.jsx($t,{className:"px-2",children:za(c.column.columnDef.cell,c.getContext())},c.id))},o.id)):e.jsx(rt,{children:e.jsx($t,{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(ee,{value:`${u.getState().pagination.pageSize}`,onValueChange:o=>{u.setPageSize(Number(o))},children:[e.jsx(X,{className:"h-8 w-[70px]",children:e.jsx(se,{placeholder:u.getState().pagination.pageSize})}),e.jsx(Z,{side:"top",children:[10,20,30,40,50].map(o=>e.jsx(U,{value:`${o}`,children:o},o))})]}),e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.records")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"flex w-[100px] items-center justify-center text-sm",children:t("trafficRecord.page",{current:u.getState().pagination.pageIndex+1,total:u.getPageCount()})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>u.previousPage(),disabled:!u.getCanPreviousPage()||x,children:e.jsx(Dp,{className:"h-4 w-4"})}),e.jsx(J,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>u.nextPage(),disabled:!u.getCanNextPage()||x,children:e.jsx(Fp,{className:"h-4 w-4"})})]})]})]})]})]})]})}function Pp({user:s,trigger:n,onSuccess:t}){const{t:l}=M("user"),[a,i]=m.useState(!1),[r,d]=m.useState(""),[x,u]=m.useState(!1),{data:o,isLoading:c}=oe({queryKey:["trafficResetHistory",s.id],queryFn:()=>pa.getUserHistory(s.id,{limit:10}),enabled:a}),h=async()=>{try{u(!0);const{data:w}=await pa.resetUser({user_id:s.id,reason:r.trim()||void 0});w&&(A.success(l("traffic_reset.reset_success")),i(!1),d(""),t?.())}finally{u(!1)}},D=w=>{switch(w){case"manual":return"bg-blue-100 text-blue-800 border-blue-200";case"monthly":return"bg-green-100 text-green-800 border-green-200";case"yearly":return"bg-purple-100 text-purple-800 border-purple-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},S=w=>{switch(w){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(he,{open:a,onOpenChange:i,children:[e.jsx(hs,{asChild:!0,children:n}),e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-hidden",children:[e.jsxs(je,{children:[e.jsxs(pe,{className:"flex items-center gap-2",children:[e.jsx(la,{className:"h-5 w-5"}),l("traffic_reset.title")]}),e.jsx(Ge,{children:l("traffic_reset.description",{email:s.email})})]}),e.jsxs(Dt,{defaultValue:"reset",className:"w-full",children:[e.jsxs(xt,{className:"grid w-full grid-cols-2",children:[e.jsxs(Xe,{value:"reset",className:"flex items-center gap-2",children:[e.jsx(la,{className:"h-4 w-4"}),l("traffic_reset.tabs.reset")]}),e.jsxs(Xe,{value:"history",className:"flex items-center gap-2",children:[e.jsx(bl,{className:"h-4 w-4"}),l("traffic_reset.tabs.history")]})]}),e.jsxs(ks,{value:"reset",className:"space-y-4",children:[e.jsxs(Pe,{children:[e.jsx(Ee,{className:"pb-3",children:e.jsxs(Ae,{className:"flex items-center gap-2 text-lg",children:[e.jsx(Jr,{className:"h-5 w-5"}),l("traffic_reset.user_info")]})}),e.jsx(Ve,{className:"space-y-3",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("columns.email")}),e.jsx("p",{className:"font-medium",children:s.email})]}),e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("columns.used_traffic")}),e.jsx("p",{className:"font-medium",children:Ie(s.total_used)})]}),e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("columns.total_traffic")}),e.jsx("p",{className:"font-medium",children:Ie(s.transfer_enable)})]}),e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("columns.expire_time")}),e.jsx("p",{className:"font-medium",children:s.expired_at?re(s.expired_at):l("columns.expire_status.permanent")})]})]})})]}),e.jsxs(Pe,{className:"border-amber-200 bg-amber-50",children:[e.jsx(Ee,{className:"pb-3",children:e.jsxs(Ae,{className:"flex items-center gap-2 text-lg text-amber-800",children:[e.jsx(na,{className:"h-5 w-5"}),l("traffic_reset.warning.title")]})}),e.jsx(Ve,{children:e.jsxs("ul",{className:"space-y-2 text-sm text-amber-700",children:[e.jsxs("li",{children:["• ",l("traffic_reset.warning.irreversible")]}),e.jsxs("li",{children:["• ",l("traffic_reset.warning.reset_to_zero")]}),e.jsxs("li",{children:["• ",l("traffic_reset.warning.logged")]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(as,{htmlFor:"reason",children:l("traffic_reset.reason.label")}),e.jsx($s,{id:"reason",placeholder:l("traffic_reset.reason.placeholder"),value:r,onChange:w=>d(w.target.value),className:"min-h-[80px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("traffic_reset.reason.optional")})]}),e.jsxs(qe,{children:[e.jsx(J,{variant:"outline",onClick:()=>i(!1),children:l("common:cancel")}),e.jsx(J,{onClick:h,disabled:x,className:"bg-destructive hover:bg-destructive/90",children:x?e.jsxs(e.Fragment,{children:[e.jsx(da,{className:"mr-2 h-4 w-4 animate-spin"}),l("traffic_reset.resetting")]}):e.jsxs(e.Fragment,{children:[e.jsx(la,{className:"mr-2 h-4 w-4"}),l("traffic_reset.confirm_reset")]})})]})]}),e.jsx(ks,{value:"history",className:"space-y-4",children:c?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(da,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[o?.data?.user&&e.jsxs(Pe,{children:[e.jsx(Ee,{className:"pb-3",children:e.jsx(Ae,{className:"text-lg",children:l("traffic_reset.history.summary")})}),e.jsx(Ve,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("traffic_reset.history.reset_count")}),e.jsx("p",{className:"font-medium",children:o.data.user.reset_count})]}),e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("traffic_reset.history.last_reset")}),e.jsx("p",{className:"font-medium",children:o.data.user.last_reset_at?re(o.data.user.last_reset_at):l("traffic_reset.history.never")})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(as,{className:"text-muted-foreground",children:l("traffic_reset.history.next_reset")}),e.jsx("p",{className:"font-medium",children:o.data.user.next_reset_at?re(o.data.user.next_reset_at):l("traffic_reset.history.no_schedule")})]})]})})]}),e.jsxs(Pe,{children:[e.jsxs(Ee,{className:"pb-3",children:[e.jsx(Ae,{className:"text-lg",children:l("traffic_reset.history.records")}),e.jsx(it,{children:l("traffic_reset.history.recent_records")})]}),e.jsx(Ve,{children:e.jsx(Ct,{className:"h-[300px]",children:o?.data?.history?.length?e.jsx("div",{className:"space-y-3",children:o.data.history.map((w,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(H,{className:D(w.reset_type),children:w.reset_type_name}),e.jsx(H,{variant:"outline",className:S(w.trigger_source),children:w.trigger_source_name})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsxs(as,{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(Qn,{className:"h-3 w-3"}),l("traffic_reset.history.reset_time")]}),e.jsx("p",{className:"font-medium",children:re(w.reset_time)})]}),e.jsxs("div",{children:[e.jsx(as,{className:"text-muted-foreground",children:l("traffic_reset.history.traffic_cleared")}),e.jsx("p",{className:"font-medium text-destructive",children:w.old_traffic.formatted})]})]})]})}),F{i(s)},[s]),e.jsxs(he,{children:[e.jsx(hs,{asChild:!0,children:n}),e.jsxs(ue,{className:"max-w-xl",children:[e.jsxs(je,{className:"space-y-2",children:[e.jsx(pe,{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("dialog.fields.userId"),":",a.id]}),e.jsx(Rp,{banned:a.banned,isAdmin:a.is_admin,isStaff:a.is_staff})]})})]}),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(Ne,{label:l("dialog.fields.email"),value:a.email,valueClassName:"font-medium"}),e.jsx(Ne,{label:l("dialog.fields.uuid"),value:a.uuid,valueClassName:"font-mono text-xs"}),e.jsx(Ne,{label:l("dialog.fields.token"),value:a.token,valueClassName:"font-mono text-xs"}),e.jsx(Ne,{label:l("dialog.fields.remarks"),value:a.remarks}),e.jsx(Ne,{label:l("dialog.fields.telegramId"),value:a.telegram_id?e.jsx("span",{className:"font-mono text-xs",children:a.telegram_id}):"-"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.subscriptionInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ne,{label:l("dialog.fields.subscriptionPlan"),value:a.plan?.name,valueClassName:"font-medium"}),e.jsx(Ne,{label:l("dialog.fields.permissionGroup"),value:a.group?.name,valueClassName:"font-medium"}),e.jsx(Ne,{label:l("dialog.fields.expiredAt"),value:e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(fe,{children:e.jsx("span",{className:"font-mono text-xs",children:a.expired_at==null?l("columns.expire_status.permanent"):re(a.expired_at,"YYYY-MM-DD")})}),e.jsx(xe,{side:"bottom",className:"space-y-1 p-3",children:a.expired_at!=null?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[l("columns.expire_time"),":"," ",re(a.expired_at)]}),e.jsx("p",{className:b("text-sm font-medium",a.expired_ate.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"})}),Ip=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"})}),Mp=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"})}),zl=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"})}),Op=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"})}),zp=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"})}),$p=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"})}),Ap=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"})}),qp=(s,n,t,l)=>{const{t:a}=M("user");return[{accessorKey:"is_admin",header:({column:i})=>e.jsx($,{column:i,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(i,r,d)=>d.includes(i.getValue(r)),size:0},{accessorKey:"is_staff",header:({column:i})=>e.jsx($,{column:i,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(i,r,d)=>d.includes(i.getValue(r)),size:0},{accessorKey:"id",header:({column:i})=>e.jsx($,{column:i,title:a("columns.id")}),cell:({row:i})=>e.jsx(H,{variant:"outline",children:i.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:i})=>e.jsx($,{column:i,title:a("columns.email")}),cell:({row:i})=>{const r=i.original.t||0,d=Date.now()/1e3-r<120,x=Math.floor(Date.now()/1e3-r);let u=d?a("columns.online_status.online"):r===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:re(r)});if(!d&&r!==0){const D=Math.floor(x/60),S=Math.floor(D/60),w=Math.floor(S/24);w>0?u+=` `+a("columns.online_status.offline_duration.days",{count:w}):S>0?u+=` `+a("columns.online_status.offline_duration.hours",{count:S}):D>0?u+=` `+a("columns.online_status.offline_duration.minutes",{count:D}):u+=`