diff --git a/public/assets/admin/assets/index.js b/public/assets/admin/assets/index.js index 8c8f208..2d59f33 100644 --- a/public/assets/admin/assets/index.js +++ b/public/assets/admin/assets/index.js @@ -13,7 +13,7 @@ stop=8 `).filter(P=>P.trim()!=="");g.onChange(E)}})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:d.control,name:"tls.server_name",render:({field:g})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.anytls.tls.server_name.label","SNI")}),e.jsx(_,{children:e.jsx(k,{placeholder:r("dynamic_form.anytls.tls.server_name.placeholder","服务器名称"),...g})})]})}),e.jsx(j,{control:d.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dynamic_form.anytls.tls.allow_insecure","允许不安全连接")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(_,{children:e.jsx(X,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]})})};return e.jsx(be,{children:C[s]?.()})};function Mx(){const{t:s}=M("server"),n=h.object({start:h.string().min(1,s("form.dynamic_rate.start_time_error")),end:h.string().min(1,s("form.dynamic_rate.end_time_error")),rate:h.string().min(1,s("form.dynamic_rate.multiplier_error")).refine(E=>!isNaN(parseFloat(E))&&isFinite(Number(E)),{message:s("form.dynamic_rate.multiplier_error_numeric")}).refine(E=>parseFloat(E)>=0,{message:s("form.dynamic_rate.multiplier_error_gte_zero")})}),t=h.object({id:h.number().optional().nullable(),specific_key:h.string().optional().nullable(),code:h.string().optional(),show:h.boolean().optional().nullable(),name:h.string().min(1,s("form.name.error")),rate:h.string().min(1,s("form.rate.error")).refine(E=>!isNaN(parseFloat(E))&&isFinite(Number(E)),{message:s("form.rate.error_numeric")}).refine(E=>parseFloat(E)>=0,{message:s("form.rate.error_gte_zero")}),rate_time_enable:h.boolean().default(!1),rate_time_ranges:h.array(n).default([]),tags:h.array(h.string()).default([]),excludes:h.array(h.string()).default([]),ips:h.array(h.string()).default([]),group_ids:h.array(h.string()).default([]),host:h.string().min(1,s("form.host.error")),port:h.string().min(1,s("form.port.error")),server_port:h.string().min(1,s("form.server_port.error")),parent_id:h.string().default("0").nullable(),route_ids:h.array(h.string()).default([]),protocol_settings:h.record(h.any()).default({}).nullable()}),r={id:null,specific_key:null,code:"",show:!1,name:"",rate:"1",rate_time_enable:!1,rate_time_ranges:[],tags:[],excludes:[],ips:[],group_ids:[],host:"",port:"",server_port:"",parent_id:"0",route_ids:[],protocol_settings:null},{isOpen:a,setIsOpen:i,editingServer:l,setEditingServer:d,serverType:u,setServerType:x,refetch:o}=gi(),[c,b]=m.useState([]),[F,S]=m.useState([]),[w,T]=m.useState([]),y=we({resolver:Te(t),defaultValues:r,mode:"onChange"});m.useEffect(()=>{L()},[a]),m.useEffect(()=>{l?.type&&l.type!==u&&x(l.type)},[l,u,x]),m.useEffect(()=>{l?l.type===u&&y.reset({...r,...l}):y.reset({...r,protocol_settings:Oe[u].schema.parse({})})},[l,y,u]);const L=async()=>{if(!a)return;const[E,P,K]=await Promise.all([pt.getList(),qa.getList(),dt.getList()]);b(E.data?.map(Z=>({label:Z.name,value:Z.id.toString()}))||[]),S(P.data?.map(Z=>({label:Z.remarks,value:Z.id.toString()}))||[]),T(K.data||[])},C=m.useMemo(()=>w?.filter(E=>(E.parent_id===0||E.parent_id===null)&&E.type===u&&E.id!==y.watch("id")),[u,w,y]),g=()=>e.jsxs(zs,{children:[e.jsx(Ks,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(Ms,{align:"start",children:e.jsx(cm,{children:Ts.map(({type:E,label:P})=>e.jsx(Se,{onClick:()=>{x(E),i(!0)},className:"cursor-pointer",children:e.jsx(U,{variant:"outline",className:"text-white",style:{background:bs[E]},children:P})},E))})})]}),p=()=>{i(!1),d(null),y.reset(r)},V=async()=>{const E=y.getValues();(await dt.save({...E,type:u})).data&&(p(),$.success(s("form.success")),o())};return e.jsxs(de,{open:a,onOpenChange:p,children:[g(),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(me,{children:s(l?"form.edit_node":"form.new_node")}),e.jsx(Ae,{})]}),e.jsxs(De,{...y,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{control:y.control,name:"name",render:({field:E})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:s("form.name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("form.name.placeholder"),...E})}),e.jsx(R,{})]})}),e.jsx(j,{control:y.control,name:"rate",render:({field:E})=>e.jsxs(f,{className:"flex-[1]",children:[e.jsx(v,{children:s("form.rate.label")}),e.jsx("div",{className:"relative flex",children:e.jsx(_,{children:e.jsx(k,{type:"number",min:"0",step:"0.1",...E})})}),e.jsx(R,{})]})})]}),e.jsx(j,{control:y.control,name:"rate_time_enable",render:({field:E})=>e.jsxs(f,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(v,{children:s("form.dynamic_rate.enable_label")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("form.dynamic_rate.enable_description")})]}),e.jsx(_,{children:e.jsx(X,{checked:E.value,onCheckedChange:E.onChange})})]}),e.jsx(R,{})]})}),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(v,{className:"",children:s("form.dynamic_rate.rules_label")}),e.jsxs(D,{type:"button",variant:"outline",size:"sm",onClick:()=>{const E=y.getValues("rate_time_ranges");y.setValue("rate_time_ranges",[...E,{start:"00:00",end:"23:59",rate:"1"}])},children:[e.jsx(Ke,{icon:"ion:add",className:"mr-1 size-4"}),s("form.dynamic_rate.add_rule")]})]}),y.watch("rate_time_ranges").map((E,P)=>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:P+1})}),e.jsx(D,{type:"button",variant:"ghost",size:"sm",onClick:()=>{const K=y.getValues("rate_time_ranges");K.splice(P,1),y.setValue("rate_time_ranges",[...K])},children:e.jsx(Ke,{icon:"ion:trash-outline",className:"size-4"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(j,{control:y.control,name:`rate_time_ranges.${P}.start`,render:({field:K})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-xs",children:s("form.dynamic_rate.start_time")}),e.jsx(_,{children:e.jsx(k,{type:"time",...K,className:"text-sm"})}),e.jsx(R,{})]})}),e.jsx(j,{control:y.control,name:`rate_time_ranges.${P}.end`,render:({field:K})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-xs",children:s("form.dynamic_rate.end_time")}),e.jsx(_,{children:e.jsx(k,{type:"time",...K,className:"text-sm"})}),e.jsx(R,{})]})}),e.jsx(j,{control:y.control,name:`rate_time_ranges.${P}.rate`,render:({field:K})=>e.jsxs(f,{children:[e.jsx(v,{className:"text-xs",children:s("form.dynamic_rate.multiplier")}),e.jsx(_,{children:e.jsx(k,{type:"number",min:"0",step:"0.1",...K,className:"text-sm",placeholder:"1.0"})}),e.jsx(R,{})]})})]})]},P)),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(j,{control:y.control,name:"code",render:({field:E})=>e.jsxs(f,{children:[e.jsxs(v,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(_,{children:e.jsx(k,{placeholder:s("form.code.placeholder"),...E,value:E.value||""})}),e.jsx(R,{})]})}),e.jsx(j,{control:y.control,name:"tags",render:({field:E})=>e.jsxs(f,{children:[e.jsx(v,{children:s("form.tags.label")}),e.jsx(_,{children:e.jsx(Xa,{value:E.value,onChange:E.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(R,{})]})}),e.jsx(j,{control:y.control,name:"group_ids",render:({field:E})=>e.jsxs(f,{children:[e.jsxs(v,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(Za,{dialogTrigger:e.jsx(D,{variant:"link",children:s("form.groups.add")}),refetch:L})]}),e.jsx(_,{children:e.jsx(st,{options:c,onChange:P=>E.onChange(P.map(K=>K.value)),value:c?.filter(P=>E.value.includes(P.value)),placeholder:s("form.groups.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.groups.empty")})})}),e.jsx(R,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:y.control,name:"host",render:({field:E})=>e.jsxs(f,{children:[e.jsx(v,{children:s("form.host.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:s("form.host.placeholder"),...E})}),e.jsx(R,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(j,{control:y.control,name:"port",render:({field:E})=>e.jsxs(f,{className:"flex-1",children:[e.jsxs(v,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(Ke,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(Ta,{children:e.jsx(ue,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.port.tooltip")})})})]})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(_,{children:e.jsx(k,{placeholder:s("form.port.placeholder"),...E})}),e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(D,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const P=E.value;P&&y.setValue("server_port",P)},children:e.jsx(Ke,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(ue,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(R,{})]})}),e.jsx(j,{control:y.control,name:"server_port",render:({field:E})=>e.jsxs(f,{className:"flex-1",children:[e.jsxs(v,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(Ke,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(Ta,{children:e.jsx(ue,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(_,{children:e.jsx(k,{placeholder:s("form.server_port.placeholder"),...E})}),e.jsx(R,{})]})})]})]}),a&&e.jsx(Ix,{serverType:u,value:y.watch("protocol_settings"),onChange:E=>y.setValue("protocol_settings",E,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(j,{control:y.control,name:"parent_id",render:({field:E})=>e.jsxs(f,{children:[e.jsx(v,{children:s("form.parent.label")}),e.jsxs(J,{onValueChange:E.onChange,value:E.value?.toString()||"0",children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(Y,{children:[e.jsx(A,{value:"0",children:s("form.parent.none")}),C?.map(P=>e.jsx(A,{value:P.id.toString(),className:"cursor-pointer",children:P.name},P.id))]})]}),e.jsx(R,{})]})}),e.jsx(j,{control:y.control,name:"route_ids",render:({field:E})=>e.jsxs(f,{children:[e.jsx(v,{children:s("form.route.label")}),e.jsx(_,{children:e.jsx(st,{options:F,onChange:P=>E.onChange(P.map(K=>K.value)),value:F?.filter(P=>E.value.includes(P.value)),placeholder:s("form.route.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.route.empty")})})}),e.jsx(R,{})]})})]}),e.jsxs(Me,{className:"mt-6 flex flex-col gap-2 sm:flex-row sm:gap-0",children:[e.jsx(D,{type:"button",variant:"outline",onClick:p,className:"w-full sm:w-auto",children:s("form.cancel")}),e.jsx(D,{type:"submit",onClick:V,className:"w-full sm:w-auto",children:s("form.submit")})]})]})]})]})}function yr({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx($a,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ve,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{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(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(nt,{children:[e.jsx(ft,{placeholder:n}),e.jsxs(rt,{children:[e.jsx(jt,{children:"No results found."}),e.jsx(Ss,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(rs,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ht,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Lt,{}),e.jsx(Ss,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const Ox=[{value:xe.Shadowsocks,label:Ts.find(s=>s.type===xe.Shadowsocks)?.label,color:bs[xe.Shadowsocks]},{value:xe.Vmess,label:Ts.find(s=>s.type===xe.Vmess)?.label,color:bs[xe.Vmess]},{value:xe.Trojan,label:Ts.find(s=>s.type===xe.Trojan)?.label,color:bs[xe.Trojan]},{value:xe.Hysteria,label:Ts.find(s=>s.type===xe.Hysteria)?.label,color:bs[xe.Hysteria]},{value:xe.Vless,label:Ts.find(s=>s.type===xe.Vless)?.label,color:bs[xe.Vless]},{value:xe.Tuic,label:Ts.find(s=>s.type===xe.Tuic)?.label,color:bs[xe.Tuic]},{value:xe.Socks,label:Ts.find(s=>s.type===xe.Socks)?.label,color:bs[xe.Socks]},{value:xe.Naive,label:Ts.find(s=>s.type===xe.Naive)?.label,color:bs[xe.Naive]},{value:xe.Http,label:Ts.find(s=>s.type===xe.Http)?.label,color:bs[xe.Http]},{value:xe.Mieru,label:Ts.find(s=>s.type===xe.Mieru)?.label,color:bs[xe.Mieru]}];function zx({table:s,saveOrder:n,isSortMode:t,groups:r}){const a=s.getState().columnFilters.length>0,{t:i}=M("server");return e.jsxs("div",{className:"flex items-center justify-between ",children:[e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[!t&&e.jsxs(e.Fragment,{children:[e.jsx(Mx,{}),e.jsx(k,{placeholder:i("toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(yr,{column:s.getColumn("type"),title:i("toolbar.type"),options:Ox}),s.getColumn("group_ids")&&e.jsx(yr,{column:s.getColumn("group_ids"),title:i("columns.groups.title"),options:r.map(l=>({label:l.name,value:l.id.toString()}))})]}),a&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[i("toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),t&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sort.tip")})})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(D,{variant:t?"default":"outline",onClick:n,size:"sm",children:i(t?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const La=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M15.71 12.71a6 6 0 1 0-7.42 0a10 10 0 0 0-6.22 8.18a1 1 0 0 0 2 .22a8 8 0 0 1 15.9 0a1 1 0 0 0 1 .89h.11a1 1 0 0 0 .88-1.1a10 10 0 0 0-6.25-8.19M12 12a4 4 0 1 1 4-4a4 4 0 0 1-4 4"})}),pa={0:"bg-destructive/80 shadow-sm shadow-destructive/50",1:"bg-yellow-500/80 shadow-sm shadow-yellow-500/50",2:"bg-emerald-500/80 shadow-sm shadow-emerald-500/50"},He=(s,n)=>n>0?Math.round(s/n*100):0,$x=s=>{const{t:n}=M("server");return[{id:"drag-handle",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(za,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.nodeId")}),cell:({row:t})=>{const r=t.getValue("id"),a=t.original.code;return e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(U,{variant:"outline",className:N("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:bs[t.original.type]},children:[e.jsx(Sl,{className:"size-3"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:a??r}),t.original.parent?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-muted-foreground/30",children:"→"}),e.jsx("span",{children:t.original.parent?.code||t.original.parent?.id})]}):""]})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"size-5 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:text-muted-foreground group-hover/id:opacity-100",onClick:i=>{i.stopPropagation(),sa(a||r.toString()).then(()=>{$.success(n("common:copy.success"))})},children:e.jsx(ir,{className:"size-3"})})]})}),e.jsxs(ue,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[Ts.find(i=>i.type===t.original.type)?.label,t.original.parent?" (子节点)":""]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a?"点击括号内容或复制按钮可复制节点代码":"点击复制按钮可复制节点ID"})]})]})})},size:50,enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.show")}),cell:({row:t})=>{const[r,a]=m.useState(!!t.getValue("show"));return e.jsx(X,{checked:r,onCheckedChange:async i=>{a(i),dt.update({id:t.original.id,type:t.original.type,show:i?1:0}).catch(()=>{a(!i),s()})},style:{backgroundColor:r?bs[t.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(O,{column:t,title:n("columns.node"),tooltip:e.jsxs("div",{className:"grid grid-cols-1 gap-3 p-2",children:[e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",pa[0])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.0")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",pa[1])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.1")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("h-2.5 w-2.5 rounded-full",pa[2])}),e.jsx("span",{className:"text-sm font-medium",children:n("columns.status.2")})]})]})})}),cell:({row:t})=>e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(pe,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:N("size-2.5 flex-shrink-0 rounded-full transition-all duration-200",pa[t.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:t.getValue("name")})]})}),e.jsx(ue,{children:e.jsxs("div",{className:" space-y-3",children:[e.jsx("p",{className:"font-medium",children:n(`columns.status.${t.original.available_status}`)}),t.original.load_status&&e.jsxs("div",{className:"border-t border-border/50 pt-3",children:[e.jsx("p",{className:"mb-3 text-sm font-medium",children:n("columns.loadStatus.details")}),e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsx("div",{children:e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[n("columns.loadStatus.cpu"),":"]}),e.jsxs("div",{className:"ml-2 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:N("h-full transition-all duration-300",t.original.load_status.cpu>=90?"bg-destructive":t.original.load_status.cpu>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Math.min(100,t.original.load_status.cpu)}%`}})}),e.jsxs("span",{className:N("min-w-[3rem] text-right font-semibold",t.original.load_status.cpu>=90?"text-destructive":t.original.load_status.cpu>=70?"text-yellow-600":"text-emerald-600"),children:[Math.round(t.original.load_status.cpu),"%"]})]})]})}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[n("columns.loadStatus.memory"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:N("h-full transition-all duration-300",He(t.original.load_status.mem.used,t.original.load_status.mem.total)>=90?"bg-destructive":He(t.original.load_status.mem.used,t.original.load_status.mem.total)>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${He(t.original.load_status.mem.used,t.original.load_status.mem.total)}%`}})}),e.jsxs("span",{className:N("min-w-[3rem] text-right font-semibold",He(t.original.load_status.mem.used,t.original.load_status.mem.total)>=90?"text-destructive":He(t.original.load_status.mem.used,t.original.load_status.mem.total)>=70?"text-yellow-600":"text-emerald-600"),children:[He(t.original.load_status.mem.used,t.original.load_status.mem.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[ze(t.original.load_status.mem.used)," ","/"," ",ze(t.original.load_status.mem.total)]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[n("columns.loadStatus.swap"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:N("h-full transition-all duration-300",He(t.original.load_status.swap.used,t.original.load_status.swap.total)>=80?"bg-destructive":He(t.original.load_status.swap.used,t.original.load_status.swap.total)>=50?"bg-yellow-500":"bg-emerald-500"),style:{width:`${He(t.original.load_status.swap.used,t.original.load_status.swap.total)}%`}})}),e.jsxs("span",{className:N("min-w-[3rem] text-right font-semibold",He(t.original.load_status.swap.used,t.original.load_status.swap.total)>=80?"text-destructive":He(t.original.load_status.swap.used,t.original.load_status.swap.total)>=50?"text-yellow-600":"text-emerald-600"),children:[He(t.original.load_status.swap.used,t.original.load_status.swap.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[ze(t.original.load_status.swap.used)," ","/"," ",ze(t.original.load_status.swap.total)]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[n("columns.loadStatus.disk"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:N("h-full transition-all duration-300",He(t.original.load_status.disk.used,t.original.load_status.disk.total)>=90?"bg-destructive":He(t.original.load_status.disk.used,t.original.load_status.disk.total)>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${He(t.original.load_status.disk.used,t.original.load_status.disk.total)}%`}})}),e.jsxs("span",{className:N("min-w-[3rem] text-right font-semibold",He(t.original.load_status.disk.used,t.original.load_status.disk.total)>=90?"text-destructive":He(t.original.load_status.disk.used,t.original.load_status.disk.total)>=70?"text-yellow-600":"text-emerald-600"),children:[He(t.original.load_status.disk.used,t.original.load_status.disk.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[ze(t.original.load_status.disk.used)," ","/"," ",ze(t.original.load_status.disk.total)]})]})]})]})]})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.address")}),cell:({row:t})=>{const r=`${t.original.host}:${t.original.port}`,a=t.original.port!==t.original.server_port;return e.jsxs("div",{className:"group relative flex min-w-0 items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-1 gap-y-0.5 pr-7",children:[e.jsx("div",{className:"flex items-center ",children:e.jsxs("span",{className:"font-mono text-sm font-medium text-foreground/90",children:[t.original.host,":",t.original.port]})}),a&&e.jsxs("span",{className:"whitespace-nowrap text-[0.7rem] tracking-tight text-muted-foreground/40",children:["(",n("columns.internalPort")," ",t.original.server_port,")"]})]}),e.jsx("div",{className:"absolute right-0 top-0",children:e.jsx(be,{delayDuration:0,children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"size-6 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:bg-muted/50 hover:text-muted-foreground group-hover:opacity-100",onClick:i=>{i.stopPropagation(),sa(r).then(()=>{$.success(n("common:copy.success"))})},children:e.jsx(ir,{className:"size-3"})})}),e.jsx(ue,{side:"top",sideOffset:10,children:n("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.onlineUsers.title"),tooltip:n("columns.onlineUsers.tooltip")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(La,{className:"size-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("online")})]}),size:80,enableSorting:!0,enableHiding:!0},{accessorKey:"rate",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.rate.title"),tooltip:n("columns.rate.tooltip")}),cell:({row:t})=>e.jsxs(U,{variant:"secondary",className:"font-medium",children:[t.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"group_ids",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.groups.title"),tooltip:n("columns.groups.tooltip")}),cell:({row:t})=>{const r=t.original.groups||[];return e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.map((a,i)=>e.jsx(U,{variant:"secondary",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:a.name},i)),r.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:n("columns.groups.empty")})]})},enableSorting:!1,filterFn:(t,r,a)=>{const i=t.getValue(r);return i?a.some(l=>i.includes(l)):!1}},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.type")}),cell:({row:t})=>{const r=t.getValue("type");return e.jsx(U,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:bs[r]},children:r})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingServer:a,setServerType:i}=gi();return e.jsx("div",{className:"flex justify-center",children:e.jsxs(zs,{modal:!1,children:[e.jsx(Ks,{asChild:!0,children:e.jsx(D,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Da,{className:"size-4"})})}),e.jsxs(Ms,{align:"end",className:"w-40",children:[e.jsx(Se,{className:"cursor-pointer",onClick:()=>{i(t.original.type),a(t.original),r(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(md,{className:"mr-2 size-4"}),n("columns.actions_dropdown.edit")]})}),e.jsxs(Se,{className:"cursor-pointer",onClick:async()=>{dt.copy({id:t.original.id}).then(({data:l})=>{l&&($.success(n("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx(kl,{className:"mr-2 size-4"}),n("columns.actions_dropdown.copy")]}),e.jsx(et,{}),e.jsx(Se,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:l=>l.preventDefault(),children:e.jsx(_s,{title:n("columns.actions_dropdown.delete.title"),description:n("columns.actions_dropdown.delete.description"),confirmText:n("columns.actions_dropdown.delete.confirm"),variant:"destructive",onConfirm:async()=>{dt.drop({id:t.original.id}).then(({data:l})=>{l&&($.success(n("columns.actions_dropdown.delete_success")),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(us,{className:"mr-2 size-4"}),n("columns.actions_dropdown.delete.confirm")]})})})]})]})})},size:50}]};function Ax(){const[s,n]=m.useState({}),[t,r]=m.useState({"drag-handle":!1}),[a,i]=m.useState([]),[l,d]=m.useState({pageSize:500,pageIndex:0}),[u,x]=m.useState([]),[o,c]=m.useState(!1),[b,F]=m.useState({}),[S,w]=m.useState([]),{refetch:T}=ae({queryKey:["nodeList"],queryFn:async()=>{const{data:V}=await dt.getList();return w(V),V}}),{data:y}=ae({queryKey:["groups"],queryFn:async()=>{const{data:V}=await pt.getList();return V}});m.useEffect(()=>{r({"drag-handle":o,show:!o,host:!o,online:!o,rate:!o,groups:!o,type:!1,actions:!o}),F({name:o?2e3:200}),d({pageSize:o?99999:500,pageIndex:0})},[o]);const L=(V,E)=>{o&&(V.dataTransfer.setData("text/plain",E.toString()),V.currentTarget.classList.add("opacity-50"))},C=(V,E)=>{if(!o)return;V.preventDefault(),V.currentTarget.classList.remove("bg-muted");const P=parseInt(V.dataTransfer.getData("text/plain"));if(P===E)return;const K=[...S],[Z]=K.splice(P,1);K.splice(E,0,Z),w(K)},g=async()=>{if(!o){c(!0);return}const V=S?.map((E,P)=>({id:E.id,order:P+1}));dt.sort(V).then(()=>{$.success("排序保存成功"),c(!1),T()}).finally(()=>{c(!1)})},p=Be({data:S||[],columns:$x(T),state:{sorting:u,columnVisibility:t,rowSelection:s,columnFilters:a,columnSizing:b,pagination:l},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:x,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:F,onPaginationChange:d,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(jx,{refetch:T,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:p,toolbar:V=>e.jsx(zx,{table:V,refetch:T,saveOrder:g,isSortMode:o,groups:y||[]}),draggable:o,onDragStart:L,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:C,showPagination:!o})})})}function qx(){const{t:s}=M("server");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("manage.title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("manage.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Ax,{})})]})]})}const Ux=Object.freeze(Object.defineProperty({__proto__:null,default:qx},Symbol.toStringTag,{value:"Module"}));function Hx({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=M("group");return e.jsx("div",{className:"flex items-center justify-between space-x-4",children:e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(Za,{refetch:n}),e.jsx(k,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:N("h-8 w-[150px] lg:w-[250px]",t&&"border-primary/50 ring-primary/20")}),t&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]})})}const Kx=s=>{const{t:n}=M("group");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(U,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium",children:t.getValue("name")})})},{accessorKey:"users_count",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.usersCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(La,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"server_count",header:({column:t})=>e.jsx(O,{column:t,title:n("columns.serverCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(Sl,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("server_count")})]}),enableSorting:!0,size:8e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Za,{defaultValues:t.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(tt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(_s,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{pt.drop({id:t.original.id}).then(({data:r})=>{r&&($.success(n("messages.updateSuccess")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("messages.deleteButton")})]})})]})}]};function Bx(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,i]=m.useState([]),[l,d]=m.useState([]),{data:u,refetch:x,isLoading:o}=ae({queryKey:["serverGroupList"],queryFn:async()=>{const{data:b}=await pt.getList();return b}}),c=Be({data:u||[],columns:Kx(x),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ts,{table:c,toolbar:b=>e.jsx(Hx,{table:b,refetch:x}),isLoading:o})}function Gx(){const{t:s}=M("group");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Bx,{})})]})]})}const Wx=Object.freeze(Object.defineProperty({__proto__:null,default:Gx},Symbol.toStringTag,{value:"Module"})),Yx=s=>h.object({remarks:h.string().min(1,s("form.validation.remarks")),match:h.array(h.string()),action:h.enum(["block","dns"]),action_value:h.string().optional()});function pi({refetch:s,dialogTrigger:n,defaultValues:t={remarks:"",match:[],action:"block",action_value:""},type:r="create"}){const{t:a}=M("route"),i=we({resolver:Te(Yx(a)),defaultValues:t,mode:"onChange"}),[l,d]=m.useState(!1);return e.jsxs(de,{open:l,onOpenChange:d,children:[e.jsx(ps,{asChild:!0,children:n||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Ke,{icon:"ion:add"})," ",e.jsx("div",{children:a("form.add")})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(me,{children:a(r==="edit"?"form.edit":"form.create")}),e.jsx(Ae,{})]}),e.jsxs(De,{...i,children:[e.jsx(j,{control:i.control,name:"remarks",render:({field:u})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:a("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(_,{children:e.jsx(k,{type:"text",placeholder:a("form.remarksPlaceholder"),...u})})}),e.jsx(R,{})]})}),e.jsx(j,{control:i.control,name:"match",render:({field:u})=>e.jsxs(f,{className:"flex-[2]",children:[e.jsx(v,{children:a("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(_,{children:e.jsx(Rs,{className:"min-h-[120px]",placeholder:a("form.matchPlaceholder"),value:Array.isArray(u.value)?u.value.join(` `):"",onChange:x=>{const o=x.target.value.split(` `);u.onChange(o)}})})}),e.jsx(R,{})]})}),e.jsx(j,{control:i.control,name:"action",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(_,{children:e.jsxs(J,{onValueChange:u.onChange,defaultValue:u.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("form.actionPlaceholder")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"block",children:a("actions.block")}),e.jsx(A,{value:"dns",children:a("actions.dns")})]})]})})}),e.jsx(R,{})]})}),i.watch("action")==="dns"&&e.jsx(j,{control:i.control,name:"action_value",render:({field:u})=>e.jsxs(f,{children:[e.jsx(v,{children:a("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(_,{children:e.jsx(k,{type:"text",placeholder:a("form.dnsPlaceholder"),...u})})})]})}),e.jsxs(Me,{children:[e.jsx(Qs,{asChild:!0,children:e.jsx(D,{variant:"outline",children:a("form.cancel")})}),e.jsx(D,{type:"submit",onClick:()=>{const u=i.getValues(),x={...u,match:Array.isArray(u.match)?u.match.filter(o=>o.trim()!==""):[]};qa.save(x).then(({data:o})=>{o&&(d(!1),s&&s(),$.success(a(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),i.reset())})},children:a("form.submit")})]})]})]})]})}function Jx({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=M("route");return e.jsx("div",{className:"flex items-center justify-between ",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[e.jsx(pi,{refetch:n}),e.jsx(k,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("remarks")?.getFilterValue()??"",onChange:a=>s.getColumn("remarks")?.setFilterValue(a.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),t&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]})})}function Qx({columns:s,data:n,refetch:t}){const[r,a]=m.useState({}),[i,l]=m.useState({}),[d,u]=m.useState([]),[x,o]=m.useState([]),c=Be({data:n,columns:s,state:{sorting:x,columnVisibility:i,rowSelection:r,columnFilters:d},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:u,onColumnVisibilityChange:l,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ts,{table:c,toolbar:b=>e.jsx(Jx,{table:b,refetch:t})})}const Xx=s=>{const{t:n}=M("route"),t={block:{icon:ud,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:xd,variant:"secondary",className:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-800"}};return[{accessorKey:"id",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.id")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(U,{variant:"outline",children:r.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.remarks")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:r.original.remarks})}),enableHiding:!1,enableSorting:!1},{accessorKey:"action_value",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.action_value.title")}),cell:({row:r})=>{const a=r.original.action,i=r.original.action_value,l=r.original.match?.length||0;return e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("span",{className:"text-sm font-medium",children:a==="dns"&&i?n("columns.action_value.dns",{value:i}):a==="block"?e.jsx("span",{className:"text-destructive",children:n("columns.action_value.block")}):n("columns.action_value.direct")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("columns.matchRules",{count:l})})]})},enableHiding:!1,enableSorting:!1,size:300},{accessorKey:"action",header:({column:r})=>e.jsx(O,{column:r,title:n("columns.action")}),cell:({row:r})=>{const a=r.getValue("action"),i=t[a]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(U,{variant:t[a]?.variant||"default",className:N("flex items-center gap-1.5 px-3 py-1 capitalize",t[a]?.className),children:[i&&e.jsx(i,{className:"h-3.5 w-3.5"}),n(`actions.${a}`)]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:n("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(pi,{defaultValues:r.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(tt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("form.edit")})]})}),e.jsx(_s,{title:n("messages.deleteConfirm"),description:n("messages.deleteDescription"),confirmText:n("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{qa.drop({id:r.original.id}).then(({data:a})=>{a&&($.success(n("messages.deleteSuccess")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("messages.deleteButton")})]})})]})}]};function Zx(){const{t:s}=M("route"),[n,t]=m.useState([]);function r(){qa.getList().then(({data:a})=>{t(a)})}return m.useEffect(()=>{r()},[]),e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Qx,{data:n,columns:Xx(r),refetch:r})})]})]})}const eh=Object.freeze(Object.defineProperty({__proto__:null,default:Zx},Symbol.toStringTag,{value:"Module"})),fi=m.createContext(void 0);function sh({children:s,refreshData:n}){const[t,r]=m.useState(!1),[a,i]=m.useState(null);return e.jsx(fi.Provider,{value:{isOpen:t,setIsOpen:r,editingPlan:a,setEditingPlan:i,refreshData:n},children:s})}function Kn(){const s=m.useContext(fi);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function th({table:s,saveOrder:n,isSortMode:t}){const{setIsOpen:r}=Kn(),{t:a}=M("subscribe");return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsxs(D,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>r(!0),children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:a("plan.add")})]}),e.jsx(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(D,{variant:t?"default":"outline",onClick:n,size:"sm",children:a(t?"plan.sort.save":"plan.sort.edit")})})]})}const _r={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"}},ah=s=>{const{t:n}=M("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(za,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(U,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.show")}),cell:({row:t})=>e.jsx(X,{defaultChecked:t.getValue("show"),onCheckedChange:r=>{ys.update({id:t.original.id,show:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.sell")}),cell:({row:t})=>e.jsx(X,{defaultChecked:t.getValue("sell"),onCheckedChange:r=>{ys.update({id:t.original.id,sell:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.renew"),tooltip:n("plan.columns.renew_tooltip")}),cell:({row:t})=>e.jsx(X,{defaultChecked:t.getValue("renew"),onCheckedChange:r=>{ys.update({id:t.original.id,renew:r}).then(({data:a})=>{!a&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:t.getValue("name")})}),enableSorting:!1,enableHiding:!1,size:900},{accessorKey:"users_count",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.stats")}),cell:({row:t})=>{const r=t.getValue("users_count")||0,a=t.original.active_users_count||0,i=r>0?Math.round(a/r*100):0;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 rounded-md bg-slate-50 px-2 py-1 hover:bg-slate-100 transition-colors cursor-help",children:[e.jsx(wa,{className:"h-3.5 w-3.5 text-slate-500"}),e.jsx("span",{className:"text-sm font-medium text-slate-700",children:r})]})}),e.jsx(ue,{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(pe,{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(hd,{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(ue,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:"有效期内用户"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"当前仍在有效期内的活跃用户"}),r>0&&e.jsxs("p",{className:"text-xs font-medium text-green-600",children:["活跃率:",i,"%"]})]})})]})})]})},enableSorting:!0,size:120},{accessorKey:"group",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.group")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[600px] flex-wrap items-center gap-1.5 text-nowrap",children:e.jsx(U,{variant:"secondary",className:N("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:t.getValue("group")?.name})}),enableSorting:!1,enableHiding:!1},{accessorKey:"prices",header:({column:t})=>e.jsx(O,{column:t,title:n("plan.columns.price")}),cell:({row:t})=>{const r=t.getValue("prices"),a=[{period:n("plan.columns.price_period.monthly"),key:"monthly",unit:n("plan.columns.price_period.unit.month")},{period:n("plan.columns.price_period.quarterly"),key:"quarterly",unit:n("plan.columns.price_period.unit.quarter")},{period:n("plan.columns.price_period.half_yearly"),key:"half_yearly",unit:n("plan.columns.price_period.unit.half_year")},{period:n("plan.columns.price_period.yearly"),key:"yearly",unit:n("plan.columns.price_period.unit.year")},{period:n("plan.columns.price_period.two_yearly"),key:"two_yearly",unit:n("plan.columns.price_period.unit.two_year")},{period:n("plan.columns.price_period.three_yearly"),key:"three_yearly",unit:n("plan.columns.price_period.unit.three_year")},{period:n("plan.columns.price_period.onetime"),key:"onetime",unit:""},{period:n("plan.columns.price_period.reset_traffic"),key:"reset_traffic",unit:n("plan.columns.price_period.unit.times")}];return e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:a.map(({period:i,key:l,unit:d})=>r[l]!=null&&e.jsxs(U,{variant:"secondary",className:N("px-2 py-0.5 font-medium transition-colors text-nowrap",_r[l].color,_r[l].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[i," ¥",r[l],d]},l))})},enableSorting:!1,size:9e3},{id:"actions",header:({column:t})=>e.jsx(O,{className:"justify-end",column:t,title:n("plan.columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingPlan:a}=Kn();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{a(t.original),r(!0)},children:[e.jsx(tt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.edit")})]}),e.jsx(_s,{title:n("plan.columns.delete_confirm.title"),description:n("plan.columns.delete_confirm.description"),confirmText:n("plan.columns.delete"),variant:"destructive",onConfirm:async()=>{ys.drop({id:t.original.id}).then(({data:i})=>{i&&($.success(n("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("plan.columns.delete")})]})})]})}}]},nh=h.object({id:h.number().nullable(),group_id:h.union([h.number(),h.string()]).nullable().optional(),name:h.string().min(1).max(250),tags:h.array(h.string()).nullable().optional(),content:h.string().nullable().optional(),transfer_enable:h.union([h.number().min(0),h.string().min(1)]),prices:h.object({monthly:h.union([h.number(),h.string()]).nullable().optional(),quarterly:h.union([h.number(),h.string()]).nullable().optional(),half_yearly:h.union([h.number(),h.string()]).nullable().optional(),yearly:h.union([h.number(),h.string()]).nullable().optional(),two_yearly:h.union([h.number(),h.string()]).nullable().optional(),three_yearly:h.union([h.number(),h.string()]).nullable().optional(),onetime:h.union([h.number(),h.string()]).nullable().optional(),reset_traffic:h.union([h.number(),h.string()]).nullable().optional()}).default({}),speed_limit:h.union([h.number(),h.string()]).nullable().optional(),capacity_limit:h.union([h.number(),h.string()]).nullable().optional(),device_limit:h.union([h.number(),h.string()]).nullable().optional(),force_update:h.boolean().optional(),reset_traffic_method:h.number().nullable(),users_count:h.number().optional(),active_users_count:h.number().optional()}),Bn=m.forwardRef(({className:s,...n},t)=>e.jsx(Tl,{ref:t,className:N("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...n,children:e.jsx(gd,{className:N("flex items-center justify-center text-current"),children:e.jsx(ht,{className:"h-4 w-4"})})}));Bn.displayName=Tl.displayName;const fa={id:null,group_id:null,name:"",tags:[],content:"",transfer_enable:"",prices:{monthly:"",quarterly:"",half_yearly:"",yearly:"",two_yearly:"",three_yearly:"",onetime:"",reset_traffic:""},speed_limit:"",capacity_limit:"",device_limit:"",force_update:!1,reset_traffic_method:null},ja={monthly:{label:"月付",months:1,discount:1},quarterly:{label:"季付",months:3,discount:.95},half_yearly:{label:"半年付",months:6,discount:.9},yearly:{label:"年付",months:12,discount:.85},two_yearly:{label:"两年付",months:24,discount:.8},three_yearly:{label:"三年付",months:36,discount:.75},onetime:{label:"流量包",months:1,discount:1},reset_traffic:{label:"重置包",months:1,discount:1}},rh=[{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 lh(){const{isOpen:s,setIsOpen:n,editingPlan:t,setEditingPlan:r,refreshData:a}=Kn(),[i,l]=m.useState(!1),{t:d}=M("subscribe"),u=we({resolver:Te(nh),defaultValues:{...fa,...t||{}},mode:"onChange"});m.useEffect(()=>{t?u.reset({...fa,...t}):u.reset(fa)},[t,u]);const x=new In({html:!0}),[o,c]=m.useState();async function b(){pt.getList().then(({data:y})=>{c(y)})}m.useEffect(()=>{s&&b()},[s]);const F=async y=>{l(!0),ys.save(y).then(({data:L})=>{L&&($.success(d(t?"plan.form.submit.success.update":"plan.form.submit.success.add")),T(),a())}).finally(()=>{l(!1)})},S=y=>{const L=Object.values(y).map(C=>C?.message).filter(Boolean);$.error(L.join(` -`)||d("plan.form.submit.error.validation","表单校验失败"))},w=y=>{if(isNaN(y))return;const L=Object.entries(ja).reduce((C,[g,p])=>{const V=y*p.months*p.discount;return{...C,[g]:V.toFixed(2)}},{});u.setValue("prices",L,{shouldDirty:!0})},T=()=>{n(!1),r(null),u.reset(fa)};return e.jsx(de,{open:s,onOpenChange:T,children:e.jsxs(ce,{children:[e.jsxs(he,{children:[e.jsx(me,{children:d(t?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(Ae,{})]}),e.jsx(De,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(F,S),children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:u.control,name:"name",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:d("plan.form.name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:d("plan.form.name.placeholder"),...y})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"tags",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:d("plan.form.tags.label","标签")}),e.jsx(_,{children:e.jsx(Xa,{value:y.value||[],onChange:y.onChange,placeholder:d("plan.form.tags.placeholder","输入标签后按回车确认"),className:"w-full"})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"group_id",render:({field:y})=>e.jsxs(f,{children:[e.jsxs(v,{className:"flex items-center justify-between",children:[d("plan.form.group.label"),e.jsx(Za,{dialogTrigger:e.jsx(D,{variant:"link",children:d("plan.form.group.add")}),refetch:b})]}),e.jsxs(J,{value:y.value?.toString()??"",onValueChange:L=>y.onChange(L?Number(L):null),children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:d("plan.form.group.placeholder")})})}),e.jsx(Y,{children:o?.map(L=>e.jsx(A,{value:L.id.toString(),children:L.name},L.id))})]}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"transfer_enable",render:({field:y})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{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(R,{})]})}),e.jsx(j,{control:u.control,name:"speed_limit",render:({field:y})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{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(R,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:d("plan.form.price.title")}),e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(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 L=parseFloat(y.target.value);w(L)}})]}),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const y=Object.keys(ja).reduce((L,C)=>({...L,[C]:""}),{});u.setValue("prices",y,{shouldDirty:!0})},children:d("plan.form.price.clear.button")})}),e.jsx(ue,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:d("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(ja).filter(([y])=>!["onetime","reset_traffic"].includes(y)).map(([y,L])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(j,{control:u.control,name:`prices.${y}`,render:({field:C})=>e.jsxs(f,{children:[e.jsxs(v,{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:["(",L.months===1?d("plan.form.price.period.monthly"):d("plan.form.price.period.months",{count:L.months}),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,step:"0.01",...C,value:C.value??"",onChange:g=>C.onChange(g.target.value),className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})},y))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(ja).filter(([y])=>["onetime","reset_traffic"].includes(y)).map(([y,L])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(j,{control:u.control,name:`prices.${y}`,render:({field:C})=>e.jsx(f,{children:e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-0",children:[e.jsx(v,{className:"text-xs font-medium",children:d(`plan.columns.price_period.${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(_,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,step:"0.01",...C,value:C.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(j,{control:u.control,name:"device_limit",render:({field:y})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{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(R,{})]})}),e.jsx(j,{control:u.control,name:"capacity_limit",render:({field:y})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{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(R,{})]})})]}),e.jsx(j,{control:u.control,name:"reset_traffic_method",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:d("plan.form.reset_method.label")}),e.jsxs(J,{value:y.value?.toString()??"null",onValueChange:L=>y.onChange(L=="null"?null:Number(L)),children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:d("plan.form.reset_method.placeholder")})})}),e.jsx(Y,{children:rh.map(L=>e.jsx(A,{value:L.value?.toString()??"null",children:d(`plan.form.reset_method.options.${L.label}`)},L.value))})]}),e.jsx(z,{className:"text-xs",children:d("plan.form.reset_method.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"content",render:({field:y})=>{const[L,C]=m.useState(!1);return e.jsxs(f,{className:"space-y-2",children:[e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d("plan.form.content.label"),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>C(!L),children:L?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(ue,{side:"top",children:e.jsx("p",{className:"text-xs",children:d(L?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",onClick:()=>{y.onChange(d("plan.form.content.template.content"))},children:d("plan.form.content.template.button")})}),e.jsx(ue,{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 ${L?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(_,{children:e.jsx(Mn,{style:{height:"400px"},value:y.value||"",renderHTML:g=>x.render(g),onChange:({text:g})=>y.onChange(g),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:d("plan.form.content.placeholder"),className:"rounded-md border"})})}),L&&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:x.render(y.value||"")}})})]})]}),e.jsx(z,{className:"text-xs",children:d("plan.form.content.description")}),e.jsx(R,{})]})}})]}),e.jsx(Me,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:t&&e.jsx(j,{control:u.control,name:"force_update",render:({field:y})=>e.jsxs(f,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(_,{children:e.jsx(Bn,{checked:y.value,onCheckedChange:y.onChange})}),e.jsx("div",{className:"",children:e.jsx(v,{className:"text-sm",children:d("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:T,children:d("plan.form.submit.cancel")}),e.jsx(D,{type:"submit",disabled:i,children:d(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})})]})})}function ih(){const[s,n]=m.useState({}),[t,r]=m.useState({"drag-handle":!1}),[a,i]=m.useState([]),[l,d]=m.useState([]),[u,x]=m.useState(!1),[o,c]=m.useState({pageSize:20,pageIndex:0}),[b,F]=m.useState([]),{refetch:S}=ae({queryKey:["planList"],queryFn:async()=>{const{data:C}=await ys.getList();return F(C),C}});m.useEffect(()=>{r({"drag-handle":u}),c({pageSize:u?99999:10,pageIndex:0})},[u]);const w=(C,g)=>{u&&(C.dataTransfer.setData("text/plain",g.toString()),C.currentTarget.classList.add("opacity-50"))},T=(C,g)=>{if(!u)return;C.preventDefault(),C.currentTarget.classList.remove("bg-muted");const p=parseInt(C.dataTransfer.getData("text/plain"));if(p===g)return;const V=[...b],[E]=V.splice(p,1);V.splice(g,0,E),F(V)},y=async()=>{if(!u){x(!0);return}const C=b?.map(g=>g.id);ys.sort(C).then(()=>{$.success("排序保存成功"),x(!1),S()}).finally(()=>{x(!1)})},L=Be({data:b||[],columns:ah(S),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:o},enableRowSelection:!0,onPaginationChange:c,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}},pageCount:u?1:void 0});return e.jsx(sh,{refreshData:S,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(ts,{table:L,toolbar:C=>e.jsx(th,{table:C,refetch:S,saveOrder:y,isSortMode:u}),draggable:u,onDragStart:w,onDragEnd:C=>C.currentTarget.classList.remove("opacity-50"),onDragOver:C=>{C.preventDefault(),C.currentTarget.classList.add("bg-muted")},onDragLeave:C=>C.currentTarget.classList.remove("bg-muted"),onDrop:T,showPagination:!u}),e.jsx(lh,{})]})})}function oh(){const{t:s}=M("subscribe");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("plan.title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("plan.page.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(ih,{})})]})]})}const ch=Object.freeze(Object.defineProperty({__proto__:null,default:oh},Symbol.toStringTag,{value:"Module"})),Ct=[{value:le.PENDING,label:zt[le.PENDING],icon:pd,color:$t[le.PENDING]},{value:le.PROCESSING,label:zt[le.PROCESSING],icon:Dl,color:$t[le.PROCESSING]},{value:le.COMPLETED,label:zt[le.COMPLETED],icon:wn,color:$t[le.COMPLETED]},{value:le.CANCELLED,label:zt[le.CANCELLED],icon:Fl,color:$t[le.CANCELLED]},{value:le.DISCOUNTED,label:zt[le.DISCOUNTED],icon:wn,color:$t[le.DISCOUNTED]}],Ht=[{value:Ce.PENDING,label:xa[Ce.PENDING],icon:fd,color:ha[Ce.PENDING]},{value:Ce.PROCESSING,label:xa[Ce.PROCESSING],icon:Dl,color:ha[Ce.PROCESSING]},{value:Ce.VALID,label:xa[Ce.VALID],icon:wn,color:ha[Ce.VALID]},{value:Ce.INVALID,label:xa[Ce.INVALID],icon:Fl,color:ha[Ce.INVALID]}];function va({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=s?.getFilterValue(),i=Array.isArray(a)?new Set(a):a!==void 0?new Set([a]):new Set;return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx($a,{className:"mr-2 h-4 w-4"}),n,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ve,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{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(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):t.filter(l=>i.has(l.value)).map(l=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(nt,{children:[e.jsx(ft,{placeholder:n}),e.jsxs(rt,{children:[e.jsx(jt,{children:"No results found."}),e.jsx(Ss,{children:t.map(l=>{const d=i.has(l.value);return e.jsxs(rs,{onSelect:()=>{const u=new Set(i);d?u.delete(l.value):u.add(l.value);const x=Array.from(u);s?.setFilterValue(x.length?x:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",d?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ht,{className:N("h-4 w-4")})}),l.icon&&e.jsx(l.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${l.color}`}),e.jsx("span",{children:l.label}),r?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(l.value)})]},l.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Lt,{}),e.jsx(Ss,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const dh=h.object({email:h.string().min(1),plan_id:h.number(),period:h.string(),total_amount:h.number()}),mh={email:"",plan_id:0,total_amount:0,period:""};function ji({refetch:s,trigger:n,defaultValues:t}){const{t:r}=M("order"),[a,i]=m.useState(!1),l=we({resolver:Te(dh),defaultValues:{...mh,...t},mode:"onChange"}),[d,u]=m.useState([]);return m.useEffect(()=>{a&&ys.getList().then(({data:x})=>{u(x)})},[a]),e.jsxs(de,{open:a,onOpenChange:i,children:[e.jsx(ps,{asChild:!0,children:n||e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:r("dialog.addOrder")})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(me,{children:r("dialog.assignOrder")}),e.jsx(Ae,{})]}),e.jsxs(De,{...l,children:[e.jsx(j,{control:l.control,name:"email",render:({field:x})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.userEmail")}),e.jsx(_,{children:e.jsx(k,{placeholder:r("dialog.placeholders.email"),...x})})]})}),e.jsx(j,{control:l.control,name:"plan_id",render:({field:x})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.subscriptionPlan")}),e.jsx(_,{children:e.jsxs(J,{value:x.value?x.value?.toString():void 0,onValueChange:o=>x.onChange(parseInt(o)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dialog.placeholders.plan")})}),e.jsx(Y,{children:d.map(o=>e.jsx(A,{value:o.id.toString(),children:o.name},o.id))})]})})]})}),e.jsx(j,{control:l.control,name:"period",render:({field:x})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.orderPeriod")}),e.jsx(_,{children:e.jsxs(J,{value:x.value,onValueChange:x.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dialog.placeholders.period")})}),e.jsx(Y,{children:Object.keys(Vm).map(o=>e.jsx(A,{value:o,children:r(`period.${o}`)},o))})]})})]})}),e.jsx(j,{control:l.control,name:"total_amount",render:({field:x})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.paymentAmount")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:r("dialog.placeholders.amount"),value:x.value/100,onChange:o=>x.onChange(parseFloat(o.currentTarget.value)*100)})}),e.jsx(R,{})]})}),e.jsxs(Me,{children:[e.jsx(D,{variant:"outline",onClick:()=>i(!1),children:r("dialog.actions.cancel")}),e.jsx(D,{type:"submit",onClick:()=>{l.handleSubmit(x=>{ct.assign(x).then(({data:o})=>{o&&(s&&s(),l.reset(),i(!1),$.success(r("dialog.messages.addSuccess")))})})()},children:r("dialog.actions.confirm")})]})]})]})]})}function uh({table:s,refetch:n}){const{t}=M("order"),r=s.getState().columnFilters.length>0,a=Object.values(Vs).filter(u=>typeof u=="number").map(u=>({label:t(`type.${Vs[u]}`),value:u,color:u===Vs.NEW?"green-500":u===Vs.RENEWAL?"blue-500":u===Vs.UPGRADE?"purple-500":"orange-500"})),i=Object.values(Qe).map(u=>({label:t(`period.${u}`),value:u,color:u===Qe.MONTH_PRICE?"slate-500":u===Qe.QUARTER_PRICE?"cyan-500":u===Qe.HALF_YEAR_PRICE?"indigo-500":u===Qe.YEAR_PRICE?"violet-500":u===Qe.TWO_YEAR_PRICE?"fuchsia-500":u===Qe.THREE_YEAR_PRICE?"pink-500":u===Qe.ONETIME_PRICE?"rose-500":"orange-500"})),l=Object.values(le).filter(u=>typeof u=="number").map(u=>({label:t(`status.${le[u]}`),value:u,icon:u===le.PENDING?Ct[0].icon:u===le.PROCESSING?Ct[1].icon:u===le.COMPLETED?Ct[2].icon:u===le.CANCELLED?Ct[3].icon:Ct[4].icon,color:u===le.PENDING?"yellow-500":u===le.PROCESSING?"blue-500":u===le.COMPLETED?"green-500":u===le.CANCELLED?"red-500":"green-500"})),d=Object.values(Ce).filter(u=>typeof u=="number").map(u=>({label:t(`commission.${Ce[u]}`),value:u,icon:u===Ce.PENDING?Ht[0].icon:u===Ce.PROCESSING?Ht[1].icon:u===Ce.VALID?Ht[2].icon:Ht[3].icon,color:u===Ce.PENDING?"yellow-500":u===Ce.PROCESSING?"blue-500":u===Ce.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ji,{refetch:n}),e.jsx(k,{placeholder:t("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:u=>s.getColumn("trade_no")?.setFilterValue(u.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2",children:[s.getColumn("type")&&e.jsx(va,{column:s.getColumn("type"),title:t("table.columns.type"),options:a}),s.getColumn("period")&&e.jsx(va,{column:s.getColumn("period"),title:t("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(va,{column:s.getColumn("status"),title:t("table.columns.status"),options:l}),s.getColumn("commission_status")&&e.jsx(va,{column:s.getColumn("commission_status"),title:t("table.columns.commissionStatus"),options:d})]}),r&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("actions.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]})}function ns({label:s,value:n,className:t,valueClassName:r}){return e.jsxs("div",{className:N("flex items-center py-1.5",t),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:N("text-sm",r),children:n||"-"})]})}function xh({status:s}){const{t:n}=M("order"),t={[le.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[le.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[le.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[le.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[le.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(U,{variant:"secondary",className:N("font-medium",t[s]),children:n(`status.${le[s]}`)})}function hh({id:s,trigger:n}){const[t,r]=m.useState(!1),[a,i]=m.useState(),{t:l}=M("order");return m.useEffect(()=>{(async()=>{if(t){const{data:u}=await ct.getInfo({id:s});i(u)}})()},[t,s]),e.jsxs(de,{onOpenChange:r,open:t,children:[e.jsx(ps,{asChild:!0,children:n}),e.jsxs(ce,{className:"max-w-xl",children:[e.jsxs(he,{className:"space-y-2",children:[e.jsx(me,{className:"text-lg font-medium",children:l("dialog.title")}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:[l("table.columns.tradeNo"),":",a?.trade_no]}),!!a?.status&&e.jsx(xh,{status:a.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.userEmail"),value:a?.user?.email?e.jsxs(Zs,{to:`/user/manage?email=${a.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[a.user.email,e.jsx(Cn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(ns,{label:l("dialog.fields.orderPeriod"),value:a&&l(`period.${a.period}`)}),e.jsx(ns,{label:l("dialog.fields.subscriptionPlan"),value:a?.plan?.name,valueClassName:"font-medium"}),e.jsx(ns,{label:l("dialog.fields.callbackNo"),value:a?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.paymentAmount"),value:qs(a?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(Ve,{className:"my-2"}),e.jsx(ns,{label:l("dialog.fields.balancePayment"),value:qs(a?.balance_amount||0)}),e.jsx(ns,{label:l("dialog.fields.discountAmount"),value:qs(a?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(ns,{label:l("dialog.fields.refundAmount"),value:qs(a?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(ns,{label:l("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:l("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.createdAt"),value:oe(a?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(ns,{label:l("dialog.fields.updatedAt"),value:oe(a?.updated_at),valueClassName:"font-mono text-xs"})]})]}),a?.commission_status===1&&a?.commission_balance&&e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.commissionInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.commissionStatus"),value:e.jsx(U,{variant:"secondary",className:"bg-orange-100 font-medium text-orange-800 hover:bg-orange-100",children:l("dialog.commissionStatusActive")})}),e.jsx(ns,{label:l("dialog.fields.commissionAmount"),value:qs(a?.commission_balance||0),valueClassName:"font-medium text-orange-600"}),a?.actual_commission_balance&&e.jsx(ns,{label:l("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(Ve,{className:"my-2"}),e.jsx(ns,{label:l("dialog.fields.inviteUser"),value:e.jsxs(Zs,{to:`/user/manage?email=${a.invite_user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[a.invite_user.email,e.jsx(Cn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]})}),e.jsx(ns,{label:l("dialog.fields.inviteUserId"),value:a?.invite_user?.id,valueClassName:"font-mono text-xs"})]})]})]})]})]})]})}const gh={[Vs.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Vs.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Vs.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Vs.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},ph={[Qe.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},fh=s=>le[s],jh=s=>Ce[s],vh=s=>Vs[s],bh=s=>{const{t:n}=M("order");return[{accessorKey:"trade_no",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.tradeNo")}),cell:({row:t})=>{const r=t.original.trade_no,a=r.length>6?`${r.slice(0,3)}...${r.slice(-3)}`:r;return e.jsx("div",{className:"flex items-center",children:e.jsx(hh,{trigger:e.jsxs(G,{variant:"ghost",size:"sm",className:"flex h-8 items-center gap-1.5 px-2 font-medium text-primary transition-colors hover:bg-primary/10 hover:text-primary/80",children:[e.jsx("span",{className:"font-mono",children:a}),e.jsx(Cn,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.type")}),cell:({row:t})=>{const r=t.getValue("type"),a=gh[r];return e.jsx(U,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",a.color,a.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:n(`type.${vh(r)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.plan")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium text-foreground/90 sm:max-w-72 md:max-w-[31rem]",children:t.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.period")}),cell:({row:t})=>{const r=t.getValue("period"),a=ph[r];return e.jsx(U,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",a?.color,a?.bgColor,"hover:bg-opacity-80"),children:n(`period.${r}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.amount")}),cell:({row:t})=>{const r=t.getValue("total_amount"),a=typeof r=="number"?(r/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",a]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:t})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(O,{column:t,title:n("table.columns.status")}),e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(pe,{children:e.jsx(di,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(ue,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:t})=>{const r=Ct.find(a=>a.value===t.getValue("status"));return r?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r.icon&&e.jsx(r.icon,{className:`h-4 w-4 text-${r.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`status.${fh(r.value)}`)})]}),r.value===le.PENDING&&e.jsxs(zs,{modal:!0,children:[e.jsx(Ks,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(Ms,{align:"end",className:"w-[140px]",children:[e.jsx(Se,{className:"cursor-pointer",onClick:async()=>{await ct.markPaid({trade_no:t.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(Se,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await ct.makeCancel({trade_no:t.original.trade_no}),s()},children:n("actions.cancel")})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.commission")}),cell:({row:t})=>{const r=t.getValue("commission_balance"),a=r?(r/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:r?`¥${a}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.commissionStatus")}),cell:({row:t})=>{const r=t.original.status,a=t.original.commission_balance,i=Ht.find(l=>l.value===t.getValue("commission_status"));return a==0||!i?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i.icon&&e.jsx(i.icon,{className:`h-4 w-4 text-${i.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`commission.${jh(i.value)}`)})]}),i.value===Ce.PENDING&&r===le.COMPLETED&&e.jsxs(zs,{modal:!0,children:[e.jsx(Ks,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(Ms,{align:"end",className:"w-[120px]",children:[e.jsx(Se,{className:"cursor-pointer",onClick:async()=>{await ct.update({trade_no:t.original.trade_no,commission_status:Ce.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(Se,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await ct.update({trade_no:t.original.trade_no,commission_status:Ce.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.createdAt")}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:oe(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function yh(){const[s]=Pl(),[n,t]=m.useState({}),[r,a]=m.useState({}),[i,l]=m.useState([]),[d,u]=m.useState([]),[x,o]=m.useState({pageIndex:0,pageSize:20});m.useEffect(()=>{const T=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([y,L])=>{const C=s.get(y);return C?{id:y,value:L==="number"?parseInt(C):C}:null}).filter(Boolean);T.length>0&&l(T)},[s]);const{refetch:c,data:b,isLoading:F}=ae({queryKey:["orderList",x,i,d],queryFn:()=>ct.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:i,sort:d})}),S=Be({data:b?.data??[],columns:bh(c),state:{sorting:d,columnVisibility:r,rowSelection:n,columnFilters:i,pagination:x},rowCount:b?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:u,onColumnFiltersChange:l,onColumnVisibilityChange:a,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),onPaginationChange:o,getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ts,{table:S,toolbar:e.jsx(uh,{table:S,refetch:c}),showPagination:!0})}function _h(){const{t:s}=M("order");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(yh,{})})]})]})}const Nh=Object.freeze(Object.defineProperty({__proto__:null,default:_h},Symbol.toStringTag,{value:"Module"}));function wh({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx($a,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ve,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{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(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(nt,{children:[e.jsx(ft,{placeholder:n}),e.jsxs(rt,{children:[e.jsx(jt,{children:"No results found."}),e.jsx(Ss,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(rs,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ht,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Lt,{}),e.jsx(Ss,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Ch=s=>h.object({id:h.coerce.number().nullable().optional(),name:h.string().min(1,s("form.name.required")),code:h.string().nullable(),type:h.coerce.number(),value:h.coerce.number(),started_at:h.coerce.number(),ended_at:h.coerce.number(),limit_use:h.union([h.string(),h.number()]).nullable(),limit_use_with_user:h.union([h.string(),h.number()]).nullable(),generate_count:h.coerce.number().nullable().optional(),limit_plan_ids:h.array(h.coerce.number()).default([]).nullable(),limit_period:h.array(h.nativeEnum(Jt)).default([]).nullable()}).refine(n=>n.ended_at>n.started_at,{message:s("form.validity.endTimeError"),path:["ended_at"]}),Nr={name:"",code:null,type:Ns.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},Sh=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 vi({defaultValues:s,refetch:n,type:t="create",dialogTrigger:r=null,open:a,onOpenChange:i}){const{t:l}=M("coupon"),[d,u]=m.useState(!1),x=a??d,o=i??u,[c,b]=m.useState([]),F=Ch(l),S=Sh(l),w=we({resolver:Te(F),defaultValues:s||Nr});m.useEffect(()=>{s&&w.reset(s)},[s,w]),m.useEffect(()=>{ys.getList().then(({data:g})=>b(g))},[]);const T=g=>{if(!g)return;const p=(V,E)=>{const P=new Date(E*1e3);return V.setHours(P.getHours(),P.getMinutes(),P.getSeconds()),Math.floor(V.getTime()/1e3)};g.from&&w.setValue("started_at",p(g.from,w.watch("started_at"))),g.to&&w.setValue("ended_at",p(g.to,w.watch("ended_at")))},y=g=>{const p=new Date,V=Math.floor(p.getTime()/1e3),E=Math.floor((p.getTime()+g*24*60*60*1e3)/1e3);w.setValue("started_at",V),w.setValue("ended_at",E)},L=async g=>{const p=await Pa.save(g);if(g.generate_count&&typeof p=="string"){const V=new Blob([p],{type:"text/csv;charset=utf-8;"}),E=document.createElement("a");E.href=window.URL.createObjectURL(V),E.download=`coupons_${new Date().getTime()}.csv`,E.click(),window.URL.revokeObjectURL(E.href)}o(!1),t==="create"&&w.reset(Nr),n()},C=(g,p)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:p}),e.jsx(k,{type:"datetime-local",step:"1",value:oe(w.watch(g),"YYYY-MM-DDTHH:mm:ss"),onChange:V=>{const E=new Date(V.target.value);w.setValue(g,Math.floor(E.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(de,{open:x,onOpenChange:o,children:[r&&e.jsx(ps,{asChild:!0,children:r}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsx(he,{children:e.jsx(me,{children:l(t==="create"?"form.add":"form.edit")})}),e.jsx(De,{...w,children:e.jsxs("form",{onSubmit:w.handleSubmit(L),className:"space-y-4",children:[e.jsx(j,{control:w.control,name:"name",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.name.label")}),e.jsx(k,{placeholder:l("form.name.placeholder"),...g}),e.jsx(R,{})]})}),t==="create"&&e.jsx(j,{control:w.control,name:"generate_count",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.generateCount.label")}),e.jsx(k,{type:"number",min:0,placeholder:l("form.generateCount.placeholder"),...g,value:g.value??"",onChange:p=>g.onChange(p.target.value===""?null:parseInt(p.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.generateCount.description")}),e.jsx(R,{})]})}),(!w.watch("generate_count")||w.watch("generate_count")==null)&&e.jsx(j,{control:w.control,name:"code",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.code.label")}),e.jsx(k,{placeholder:l("form.code.placeholder"),...g,value:g.value??"",className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.code.description")}),e.jsx(R,{})]})}),e.jsxs(f,{children:[e.jsx(v,{children:l("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(j,{control:w.control,name:"type",render:({field:g})=>e.jsxs(J,{value:g.value.toString(),onValueChange:p=>{const V=g.value,E=parseInt(p);g.onChange(E);const P=w.getValues("value");P&&(V===Ns.AMOUNT&&E===Ns.PERCENTAGE?w.setValue("value",P/100):V===Ns.PERCENTAGE&&E===Ns.AMOUNT&&w.setValue("value",P*100))},children:[e.jsx(W,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Q,{placeholder:l("form.type.placeholder")})}),e.jsx(Y,{children:Object.entries(Im).map(([p,V])=>e.jsx(A,{value:p,children:l(`table.toolbar.types.${p}`)},p))})]})}),e.jsx(j,{control:w.control,name:"value",render:({field:g})=>{const p=g.value==null?"":w.watch("type")===Ns.AMOUNT&&typeof g.value=="number"?(g.value/100).toString():g.value.toString();return e.jsx(k,{type:"number",placeholder:l("form.value.placeholder"),...g,value:p,onChange:V=>{const E=V.target.value;if(E===""){g.onChange("");return}const P=parseFloat(E);isNaN(P)||g.onChange(w.watch("type")===Ns.AMOUNT?Math.round(P*100):P)},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")==Ns.AMOUNT?"¥":"%"})})]})]}),e.jsxs(f,{children:[e.jsx(v,{children:l("form.validity.label")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(D,{variant:"outline",className:N("w-full justify-start text-left font-normal",!w.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(ws,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"truncate",children:[oe(w.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",l("form.validity.to")," ",oe(w.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})]})}),e.jsxs(Xe,{className:"w-auto p-0",align:"start",children:[e.jsxs("div",{className:"border-b border-border p-3",children:[e.jsx("div",{className:"mb-2 text-sm font-medium text-muted-foreground",children:l("form.timeRange.quickSet")}),e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-6",children:S.map(g=>e.jsx(D,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>y(g.days),type:"button",children:g.label},g.days))})]}),e.jsx("div",{className:"hidden border-b border-border sm:block",children:e.jsx(Cs,{mode:"range",selected:{from:new Date(w.watch("started_at")*1e3),to:new Date(w.watch("ended_at")*1e3)},onSelect:T,numberOfMonths:2})}),e.jsx("div",{className:"border-b border-border sm:hidden",children:e.jsx(Cs,{mode:"range",selected:{from:new Date(w.watch("started_at")*1e3),to:new Date(w.watch("ended_at")*1e3)},onSelect:T,numberOfMonths:1})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center",children:[C("started_at",l("table.validity.startTime")),e.jsx("div",{className:"text-center text-sm text-muted-foreground sm:mt-6",children:l("form.validity.to")}),C("ended_at",l("table.validity.endTime"))]})})]})]}),e.jsx(R,{})]}),e.jsx(j,{control:w.control,name:"limit_use",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitUse.label")}),e.jsx(k,{type:"number",min:0,placeholder:l("form.limitUse.placeholder"),...g,value:g.value??"",onChange:p=>g.onChange(p.target.value===""?null:parseInt(p.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.limitUse.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"limit_use_with_user",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitUseWithUser.label")}),e.jsx(k,{type:"number",min:0,placeholder:l("form.limitUseWithUser.placeholder"),...g,value:g.value??"",onChange:p=>g.onChange(p.target.value===""?null:parseInt(p.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.limitUseWithUser.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"limit_period",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitPeriod.label")}),e.jsx(st,{options:Object.entries(Jt).filter(([p])=>isNaN(Number(p))).map(([p,V])=>({label:l(`coupon:period.${V}`),value:p})),onChange:p=>{if(p.length===0){g.onChange([]);return}const V=p.map(E=>Jt[E.value]);g.onChange(V)},value:(g.value||[]).map(p=>({label:l(`coupon:period.${p}`),value:Object.entries(Jt).find(([V,E])=>E===p)?.[0]||""})),placeholder:l("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPeriod.empty")})}),e.jsx(z,{className:"text-xs",children:l("form.limitPeriod.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"limit_plan_ids",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitPlan.label")}),e.jsx(st,{options:c?.map(p=>({label:p.name,value:p.id.toString()}))||[],onChange:p=>g.onChange(p.map(V=>Number(V.value))),value:(c||[]).filter(p=>(g.value||[]).includes(p.id)).map(p=>({label:p.name,value:p.id.toString()})),placeholder:l("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPlan.empty")})}),e.jsx(R,{})]})}),e.jsx(Me,{children:e.jsx(D,{type:"submit",disabled:w.formState.isSubmitting,children:w.formState.isSubmitting?l("form.submit.saving"):l("form.submit.save")})})]})})]})]})}function kh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=M("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(vi,{refetch:n,dialogTrigger:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:r("form.add")})]})}),e.jsx(k,{placeholder:r("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(wh,{column:s.getColumn("type"),title:r("table.toolbar.type"),options:[{value:Ns.AMOUNT,label:r(`table.toolbar.types.${Ns.AMOUNT}`)},{value:Ns.PERCENTAGE,label:r(`table.toolbar.types.${Ns.PERCENTAGE}`)}]}),t&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]})}const bi=m.createContext(void 0);function Th({children:s,refetch:n}){const[t,r]=m.useState(!1),[a,i]=m.useState(null),l=u=>{i(u),r(!0)},d=()=>{r(!1),i(null)};return e.jsxs(bi.Provider,{value:{isOpen:t,currentCoupon:a,openEdit:l,closeEdit:d},children:[s,a&&e.jsx(vi,{defaultValues:a,refetch:n,type:"edit",open:t,onOpenChange:r})]})}function Dh(){const s=m.useContext(bi);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const Fh=s=>{const{t:n}=M("coupon");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(U,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx(X,{defaultChecked:t.original.show,onCheckedChange:r=>{Pa.update({id:t.original.id,show:r}).then(({data:a})=>!a&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.type")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:n(`table.toolbar.types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.code")}),cell:({row:t})=>e.jsx(U,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.limitUse")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.original.limit_use===null?n("table.validity.unlimited"):t.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.limitUseWithUser")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.original.limit_use_with_user===null?n("table.validity.noLimit"):t.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.validity")}),cell:({row:t})=>{const[r,a]=m.useState(!1),i=Date.now(),l=t.original.started_at*1e3,d=t.original.ended_at*1e3,u=i>d,x=ie.jsx(O,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>{const{openEdit:r}=Dh();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>r(t.original),children:[e.jsx(tt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),e.jsx(_s,{title:n("table.actions.deleteConfirm.title"),description:n("table.actions.deleteConfirm.description"),confirmText:n("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{Pa.drop({id:t.original.id}).then(({data:a})=>{a&&($.success("删除成功"),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("table.actions.delete")})]})})]})}}]};function Ph(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,i]=m.useState([]),[l,d]=m.useState([]),[u,x]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=ae({queryKey:["couponList",u,a,l],queryFn:()=>Pa.getList({pageSize:u.pageSize,current:u.pageIndex+1,filter:a,sort:l})}),b=Be({data:c?.data??[],columns:Fh(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:u},pageCount:Math.ceil((c?.total??0)/u.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:x,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Th,{refetch:o,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:b,toolbar:e.jsx(kh,{table:b,refetch:o})})})})}function Rh(){const{t:s}=M("coupon");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Ph,{})})]})]})}const Lh=Object.freeze(Object.defineProperty({__proto__:null,default:Rh},Symbol.toStringTag,{value:"Module"})),Eh=h.object({name:h.string().min(1,"请输入模板名称"),description:h.string().optional(),type:h.number().min(1).max(4),status:h.boolean(),sort:h.number().min(0),icon:h.string().optional(),background_image:h.string().optional(),conditions:h.object({allowed_plans:h.array(h.number()).optional(),disallowed_plans:h.array(h.number()).optional(),new_user_only:h.boolean().optional(),new_user_max_days:h.number().optional(),paid_user_only:h.boolean().optional(),require_invite:h.boolean().optional()}).optional(),limits:h.object({max_use_per_user:h.number().optional(),cooldown_hours:h.number().optional(),invite_reward_rate:h.number().optional()}).optional(),rewards:h.object({balance:h.number().optional(),transfer_enable:h.number().optional(),expire_days:h.number().optional(),device_limit:h.number().optional(),reset_package:h.boolean().optional(),plan_id:h.number().optional(),plan_validity_days:h.number().optional(),random_rewards:h.array(h.object({weight:h.number(),balance:h.number().optional(),transfer_enable:h.number().optional(),expire_days:h.number().optional(),device_limit:h.number().optional()})).optional()}),special_config:h.object({start_time:h.number().optional(),end_time:h.number().optional(),festival_bonus:h.number().optional()}).optional()});function yi({template:s,refetch:n,open:t,onOpenChange:r}){const{t:a}=M("giftCard"),[i,l]=m.useState(!1),[d,u]=m.useState([]),[x,o]=m.useState([]),c=we({resolver:Te(Eh),defaultValues:{name:"",description:"",type:1,status:!0,sort:0,icon:"",background_image:"",conditions:{},limits:{},rewards:{},special_config:{}}}),{fields:b,append:F,remove:S}=jd({control:c.control,name:"rewards.random_rewards"});m.useEffect(()=>{t&&(async()=>{try{const p=(await ys.getList()).data||[];u(p),o(p.map(V=>({label:V.name,value:V.id.toString()})))}catch(g){console.error("Failed to fetch plans:",g),$.error("Failed to load plan list")}})()},[t]),m.useEffect(()=>{if(s){const C=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:C.balance?C.balance/100:void 0,transfer_enable:typeof C.transfer_enable=="number"?C.transfer_enable/1024/1024/1024:void 0,expire_days:C.expire_days,device_limit:C.device_limit,reset_package:C.reset_package,plan_id:C.plan_id,plan_validity_days:C.plan_validity_days,random_rewards:C.random_rewards?.map(g=>({weight:g.weight,balance:g.balance?g.balance/100:void 0,transfer_enable:typeof g.transfer_enable=="number"?g.transfer_enable/1024/1024/1024:void 0,expire_days:g.expire_days,device_limit:g.device_limit}))||[]},special_config:s.special_config&&!Array.isArray(s.special_config)?s.special_config:{}})}else c.reset({name:"",description:"",type:1,status:!0,sort:0,icon:"",background_image:"",conditions:{},limits:{},rewards:{random_rewards:[]},special_config:{}})},[s,c]);const w=C=>{console.error("Form validation failed:",C),$.error(a("messages.formInvalid"))},T=async C=>{l(!0);const g=JSON.parse(JSON.stringify(C));g.rewards&&(typeof g.rewards.balance=="number"&&(g.rewards.balance=Math.round(g.rewards.balance*100)),typeof g.rewards.transfer_enable=="number"&&(g.rewards.transfer_enable=Math.round(g.rewards.transfer_enable*1024*1024*1024)),g.rewards.random_rewards&&g.rewards.random_rewards.forEach(V=>{typeof V.balance=="number"&&(V.balance=Math.round(V.balance*100)),typeof V.transfer_enable=="number"&&(V.transfer_enable=Math.round(V.transfer_enable*1024*1024*1024))}));const p={...g,conditions:g.conditions||{},limits:g.limits||{},rewards:g.rewards||{},special_config:g.special_config||{}};try{s?(await Ds.updateTemplate({id:s.id,...p}),$.success(a("messages.templateUpdated"))):(await Ds.createTemplate(p),$.success(a("messages.templateCreated"))),n(),r(!1)}catch(V){const E=V?.response?.data?.errors;E&&Object.keys(E).forEach(P=>{c.setError(P,{type:"manual",message:E[P][0]})}),$.error(a(s?"messages.updateTemplateFailed":"messages.createTemplateFailed"))}finally{l(!1)}},y=c.watch("type"),L=y===1;return e.jsx(de,{open:t,onOpenChange:r,children:e.jsxs(ce,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(he,{children:e.jsx(me,{children:a(s?"template.form.edit":"template.form.add")})}),e.jsx(De,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(T,w),className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"name",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:a("template.form.name.placeholder"),...C})}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"type",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.type.label")}),e.jsxs(J,{value:C.value.toString(),onValueChange:g=>C.onChange(parseInt(g)),children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:a("template.form.type.placeholder")})})}),e.jsx(Y,{children:[1,2,3].map(g=>e.jsx(A,{value:g.toString(),children:a(`types.${g}`)},g))})]}),e.jsx(R,{})]})})]}),e.jsx(j,{control:c.control,name:"description",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.description.label")}),e.jsx(_,{children:e.jsx(Rs,{placeholder:a("template.form.description.placeholder"),...C})}),e.jsx(R,{})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:e.jsx(j,{control:c.control,name:"status",render:({field:C})=>e.jsxs(f,{className:"col-span-3 flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:a("template.form.status.label")}),e.jsx(z,{children:a("template.form.status.description")})]}),e.jsx(_,{children:e.jsx(X,{checked:C.value,onCheckedChange:C.onChange})})]})})}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Le,{children:a("template.form.rewards.title")})}),e.jsxs(Pe,{className:"space-y-4",children:[L&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"rewards.balance",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.balance.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.balance.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(j,{control:c.control,name:"rewards.transfer_enable",render:({field:C})=>e.jsxs(f,{children:[e.jsxs(v,{children:[a("template.form.rewards.transfer_enable.label")," (GB)"]}),e.jsx(_,{children:e.jsx(k,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.placeholder")+" (GB)",value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(j,{control:c.control,name:"rewards.expire_days",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.expire_days.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.expire_days.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(j,{control:c.control,name:"rewards.device_limit",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.device_limit.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.device_limit.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})})]}),e.jsx(j,{control:c.control,name:"rewards.reset_package",render:({field:C})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{children:a("template.form.rewards.reset_package.label")}),e.jsx(z,{children:a("template.form.rewards.reset_package.description")})]}),e.jsx(_,{children:e.jsx(X,{checked:C.value,onCheckedChange:C.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(j,{control:c.control,name:"rewards.plan_id",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.plan_id.label")}),e.jsxs(J,{value:C.value?.toString(),onValueChange:g=>C.onChange(parseInt(g,10)),children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:a("template.form.rewards.plan_id.placeholder")})})}),e.jsx(Y,{children:d.map(g=>e.jsx(A,{value:g.id.toString(),children:g.name},g.id))})]}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"rewards.plan_validity_days",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.plan_validity_days.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.plan_validity_days.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})})]}),y===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{children:a("template.form.rewards.random_rewards.label")}),b.map((C,g)=>e.jsxs("div",{className:"flex items-center space-x-2 rounded-md border p-2",children:[e.jsx(j,{control:c.control,name:`rewards.random_rewards.${g}.weight`,render:({field:p})=>e.jsx(f,{children:e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.random_rewards.weight"),...p,value:p.value??"",onChange:V=>{const E=V.target.valueAsNumber;p.onChange(isNaN(E)?0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${g}.balance`,render:({field:p})=>e.jsx(f,{children:e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.balance.label"),...p,value:p.value??"",onChange:V=>{const E=V.target.valueAsNumber;p.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${g}.transfer_enable`,render:({field:p})=>e.jsx(f,{children:e.jsx(_,{children:e.jsx(k,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.label")+" (GB)",value:p.value??"",onChange:V=>{const E=V.target.valueAsNumber;p.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${g}.expire_days`,render:({field:p})=>e.jsx(f,{children:e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.expire_days.label"),...p,value:p.value??"",onChange:V=>{const E=V.target.valueAsNumber;p.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${g}.device_limit`,render:({field:p})=>e.jsx(f,{children:e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.device_limit.label"),...p,value:p.value??"",onChange:V=>{const E=V.target.valueAsNumber;p.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",onClick:()=>S(g),children:e.jsx(vd,{className:"h-4 w-4"})})]},C.id)),e.jsx(D,{type:"button",variant:"outline",onClick:()=>F({weight:10,balance:void 0,transfer_enable:void 0,expire_days:void 0,device_limit:void 0}),children:a("template.form.rewards.random_rewards.add")})]})]})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Le,{children:a("template.form.conditions.title")})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 gap-4",children:e.jsx(j,{control:c.control,name:"conditions.new_user_max_days",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.conditions.new_user_max_days.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.conditions.new_user_max_days.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(j,{control:c.control,name:"conditions.new_user_only",render:({field:C})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(v,{children:a("template.form.conditions.new_user_only.label")})}),e.jsx(_,{children:e.jsx(X,{checked:C.value,onCheckedChange:C.onChange})})]})}),e.jsx(j,{control:c.control,name:"conditions.paid_user_only",render:({field:C})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(v,{children:a("template.form.conditions.paid_user_only.label")})}),e.jsx(_,{children:e.jsx(X,{checked:C.value,onCheckedChange:C.onChange})})]})}),e.jsx(j,{control:c.control,name:"conditions.require_invite",render:({field:C})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(v,{children:a("template.form.conditions.require_invite.label")})}),e.jsx(_,{children:e.jsx(X,{checked:C.value,onCheckedChange:C.onChange})})]})})]}),e.jsx(j,{control:c.control,name:"conditions.allowed_plans",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.conditions.allowed_plans.label")}),e.jsx(_,{children:e.jsx(st,{value:C.value?.map(g=>({label:d.find(p=>p.id===g)?.name||`ID: ${g}`,value:g.toString()}))??[],onChange:g=>C.onChange(g.map(p=>parseInt(p.value))),options:x,placeholder:a("template.form.conditions.allowed_plans.placeholder")})})]})}),e.jsx(j,{control:c.control,name:"conditions.disallowed_plans",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.conditions.disallowed_plans.label")}),e.jsx(_,{children:e.jsx(st,{value:C.value?.map(g=>({label:d.find(p=>p.id===g)?.name||`ID: ${g}`,value:g.toString()}))??[],onChange:g=>C.onChange(g.map(p=>parseInt(p.value))),options:x,placeholder:a("template.form.conditions.disallowed_plans.placeholder")})})]})})]})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Le,{children:a("template.form.limits.title")})}),e.jsx(Pe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"limits.max_use_per_user",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.limits.max_use_per_user.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.limits.max_use_per_user.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(j,{control:c.control,name:"limits.cooldown_hours",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.limits.cooldown_hours.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.limits.cooldown_hours.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(j,{control:c.control,name:"limits.invite_reward_rate",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.limits.invite_reward_rate.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",step:"0.01",placeholder:a("template.form.limits.invite_reward_rate.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})}),e.jsx(z,{children:a("template.form.limits.invite_reward_rate.description")})]})})]})})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Le,{children:a("template.form.special_config.title")})}),e.jsx(Pe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-3 items-end gap-4",children:[e.jsx(j,{control:c.control,name:"special_config.start_time",render:({field:C})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(v,{children:a("template.form.special_config.start_time.label")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsx(_,{children:e.jsxs(D,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!C.value&&"text-muted-foreground"),children:[C.value?Re(new Date(C.value*1e3),"PPP"):e.jsx("span",{children:a("template.form.special_config.start_time.placeholder")}),e.jsx(ws,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",children:e.jsx(Cs,{mode:"single",selected:C.value?new Date(C.value*1e3):void 0,onSelect:g=>C.onChange(g?Math.floor(g.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"special_config.end_time",render:({field:C})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(v,{children:a("template.form.special_config.end_time.label")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsx(_,{children:e.jsxs(D,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!C.value&&"text-muted-foreground"),children:[C.value?Re(new Date(C.value*1e3),"PPP"):e.jsx("span",{children:a("template.form.special_config.end_time.placeholder")}),e.jsx(ws,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",children:e.jsx(Cs,{mode:"single",selected:C.value?new Date(C.value*1e3):void 0,onSelect:g=>C.onChange(g?Math.floor(g.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"special_config.festival_bonus",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.special_config.festival_bonus.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",step:"0.1",placeholder:a("template.form.special_config.festival_bonus.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})})]})})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Le,{children:a("template.form.display.title")})}),e.jsx(Pe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"icon",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.icon.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:a("template.form.icon.placeholder"),...C})}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"background_image",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.background_image.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:a("template.form.background_image.placeholder"),...C})}),e.jsx(R,{})]})})]})})]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>r(!1),children:a("common:cancel")}),e.jsx(D,{type:"submit",disabled:i,children:a(i?"common:saving":"common:submit")})]})]})})]})})}const _i=m.createContext(void 0);function Vh({children:s,refetch:n}){const[t,r]=m.useState(!1),[a,i]=m.useState(null),l=u=>{i(u),r(!!u)},d=()=>{r(!1),i(null)};return e.jsxs(_i.Provider,{value:{isOpen:t,editingTemplate:a,setEditingTemplate:l,closeEdit:d},children:[s,e.jsx(yi,{template:a,refetch:n,open:t,onOpenChange:r})]})}function Ih(){const s=m.useContext(_i);if(s===void 0)throw new Error("useTemplateEdit must be used within a TemplateEditProvider");return s}function Mh({rewards:s,type:n}){const{t}=M(["giftCard","common"]),r=[];return s&&(s.balance&&r.push(`${t("template.form.rewards.balance.short_label")}: ${s.balance/100} ${t("common:currency.yuan","元")}`),s.transfer_enable&&r.push(`${t("template.form.rewards.transfer_enable.short_label")}: ${ze(s.transfer_enable)}`),s.expire_days&&r.push(`${t("template.form.rewards.expire_days.short_label")}: ${s.expire_days}${t("common:time.day","天")}`),s.device_limit&&r.push(`${t("template.form.rewards.device_limit.short_label")}: ${s.device_limit}`),n===2&&s.plan_id&&r.push(`${t("template.form.rewards.plan_id.short_label")}: ${s.plan_id}`),n===2&&s.plan_validity_days&&r.push(`${t("template.form.rewards.plan_validity_days.short_label")}: ${s.plan_validity_days}${t("common:time.day","天")}`),n===3&&s.random_rewards?.length&&r.push(t("types.3"))),r.length===0?e.jsx(U,{variant:"secondary",children:t("template.table.columns.no_rewards")}):e.jsx("div",{className:"flex flex-col space-y-1",children:r.map((a,i)=>e.jsx(U,{variant:"outline",className:"whitespace-nowrap",children:a},i))})}const Oh=s=>{const{t:n}=M("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.id")}),cell:({row:t})=>e.jsx(U,{children:t.original.id}),enableSorting:!0},{accessorKey:"status",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.status")}),cell:({row:t})=>{const[r,a]=m.useState(!1);return e.jsx(X,{checked:t.original.status,disabled:r,onCheckedChange:async i=>{a(!0);try{const{data:l}=await Ds.updateTemplate({id:t.original.id,status:i});l?($.success(n("messages.templateUpdated")),s()):$.error(n("messages.updateTemplateFailed"))}catch{$.error(n("messages.updateTemplateFailed"))}finally{a(!1)}}})},enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:300},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.type")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:n(`types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"rewards",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.rewards")}),cell:({row:t})=>e.jsx(Mh,{rewards:t.original.rewards,type:t.original.type}),enableSorting:!1},{accessorKey:"sort",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.sort")}),cell:({row:t})=>e.jsx(U,{variant:"secondary",children:t.original.sort}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(t.original.created_at)}),enableSorting:!0},{id:"actions",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.actions")}),cell:({row:t})=>{const{setEditingTemplate:r}=Ih();return e.jsxs("div",{className:"flex space-x-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>r(t.original),children:[e.jsx(tt,{className:"h-4 w-4"}),n("template.actions.edit")]}),e.jsx(_s,{title:n("template.actions.deleteConfirm.title"),description:n("template.actions.deleteConfirm.description"),confirmText:n("template.actions.deleteConfirm.confirmText"),onConfirm:async()=>{try{const{data:a}=await Ds.deleteTemplate({id:t.original.id});a?($.success(n("messages.templateDeleted")),s()):$.error(n("messages.deleteTemplateFailed"))}catch{$.error(n("messages.deleteTemplateFailed"))}},children:e.jsxs(D,{variant:"outline",size:"sm",children:[e.jsx(us,{className:"h-4 w-4"}),n("template.actions.delete")]})})]})},enableSorting:!1}]};function Ni({table:s}){return e.jsxs(zs,{children:[e.jsx(bd,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(Rl,{className:"mr-2 h-4 w-4"}),"显示列"]})}),e.jsxs(Ms,{align:"end",className:"w-[150px]",children:[e.jsx(Ua,{children:"切换显示列"}),e.jsx(et,{}),s.getAllColumns().filter(n=>typeof n.accessorFn<"u"&&n.getCanHide()).map(n=>e.jsx(Gl,{className:"capitalize",checked:n.getIsVisible(),onCheckedChange:t=>n.toggleVisibility(!!t),children:n.id},n.id))]})]})}function Ea({column:s,title:n,options:t}){const r=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(G,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(yd,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ve,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):t.filter(a=>r.has(a.value)).map(a=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:a.label},`selected-${a.value}`))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(nt,{children:[e.jsx(ft,{placeholder:n}),e.jsxs(rt,{children:[e.jsx(jt,{children:"No results found."}),e.jsx(Ss,{children:t.map(a=>{const i=r.has(a.value);return e.jsxs(rs,{onSelect:()=>{i?r.delete(a.value):r.add(a.value);const l=Array.from(r);s?.setFilterValue(l.length?l:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",i?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(_d,{className:N("h-4 w-4")})}),a.icon&&e.jsx(a.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:a.label})]},`option-${a.value}`)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Lt,{}),e.jsx(Ss,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function zh({table:s,refetch:n}){const{t}=M("giftCard"),[r,a]=m.useState(!1),i=s.getState().columnFilters.length>0,l=[{label:t("types.1"),value:"1"},{label:t("types.2"),value:"2"},{label:t("types.3"),value:"3"},{label:t("types.4"),value:"4"},{label:t("types.5"),value:"5"},{label:t("types.6"),value:"6"},{label:t("types.7"),value:"7"},{label:t("types.8"),value:"8"},{label:t("types.9"),value:"9"},{label:t("types.10"),value:"10"}],d=[{label:t("common.enabled"),value:"true"},{label:t("common.disabled"),value:"false"}];return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(k,{placeholder:t("common.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:u=>s.getColumn("name")?.setFilterValue(u.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(Ea,{column:s.getColumn("type"),title:t("template.table.columns.type"),options:l}),s.getColumn("status")&&e.jsx(Ea,{column:s.getColumn("status"),title:t("template.table.columns.status"),options:d}),i&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Ll,{className:"h-4 w-4 mr-2"}),t("template.form.add")]}),e.jsx(Ni,{table:s})]}),e.jsx(yi,{template:null,refetch:n,open:r,onOpenChange:a})]})}function $h(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,i]=m.useState([]),[l,d]=m.useState([]),[u,x]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=ae({queryKey:["giftCardTemplates",u,a,l],queryFn:()=>Ds.getTemplates({per_page:u.pageSize,page:u.pageIndex+1,filter:a,sort:l})});console.log(c);const b=Be({data:c?.data??[],columns:Oh(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:u},pageCount:Math.ceil((c?.total??0)/u.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:x,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Vh,{refetch:o,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:b,toolbar:e.jsx(zh,{table:b,refetch:o})})})})}const Ah=h.object({template_id:h.number().min(1,"请选择一个模板"),count:h.number().min(1,"生成数量必须大于0").max(1e4,"单次最多生成10000个"),prefix:h.string().optional(),expires_hours:h.number().min(1,"有效期必须大于0"),max_usage:h.number().min(1,"最大使用次数必须大于0"),download_csv:h.boolean().optional()});function qh({refetch:s,open:n,onOpenChange:t}){const{t:r}=M("giftCard"),[a,i]=m.useState(!1),[l,d]=m.useState([]);m.useEffect(()=>{n&&Ds.getTemplates({per_page:1e3,page:1}).then(({data:o})=>{d(o||[])})},[n]);const u=we({resolver:Te(Ah),defaultValues:{count:10,prefix:"",expires_hours:24*30,max_usage:1,download_csv:!1}}),x=async o=>{i(!0);try{if(o.download_csv){const c=await Ds.generateCodes(o);if(c&&c instanceof Blob){const b=window.URL.createObjectURL(c),F=document.createElement("a");F.href=b,F.download=`gift_codes_${new Date().getTime()}.csv`,document.body.appendChild(F),F.click(),F.remove(),window.URL.revokeObjectURL(b),$.success(r("messages.codesGenerated")),s(),t(!1),u.reset()}}else await Ds.generateCodes(o),$.success(r("messages.codesGenerated")),s(),t(!1),u.reset()}catch{$.error(r("messages.generateCodesFailed"))}finally{i(!1)}};return e.jsx(de,{open:n,onOpenChange:t,children:e.jsxs(ce,{children:[e.jsx(he,{children:e.jsx(me,{children:r("code.form.generate")})}),e.jsx(De,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(x),className:"space-y-4",children:[e.jsx(j,{control:u.control,name:"template_id",render:({field:o})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.template_id.label")}),e.jsxs(J,{onValueChange:c=>o.onChange(parseInt(c)),children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:r("code.form.template_id.placeholder")})})}),e.jsx(Y,{children:l.map(c=>e.jsx(A,{value:c.id.toString(),children:c.name},c.id))})]}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"count",render:({field:o})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.count.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"prefix",render:({field:o})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.prefix.label")}),e.jsx(_,{children:e.jsx(k,{...o})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"expires_hours",render:({field:o})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.expires_hours.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"max_usage",render:({field:o})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.max_usage.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"download_csv",render:({field:o})=>e.jsxs(f,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(_,{children:e.jsx("input",{type:"checkbox",checked:o.value,onChange:c=>o.onChange(c.target.checked)})}),e.jsx(v,{children:r("code.form.download_csv")})]})}),e.jsxs(Me,{children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>t(!1),children:r("common.cancel")}),e.jsx(D,{type:"submit",disabled:a,children:r(a?"code.form.submit.generating":"code.form.submit.generate")})]})]})})]})})}function Uh({table:s,refetch:n}){const{t}=M("giftCard"),[r,a]=m.useState(!1),i=s.getState().columnFilters.length>0,l=Object.entries(t("code.status",{returnObjects:!0})).map(([d,u])=>({value:d,label:u}));return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(k,{placeholder:t("common.search"),value:s.getColumn("code")?.getFilterValue()??"",onChange:d=>s.getColumn("code")?.setFilterValue(d.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("status")&&e.jsx(Ea,{column:s.getColumn("status"),title:t("code.table.columns.status"),options:l}),i&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Ll,{className:"h-4 w-4 mr-2"}),t("code.form.generate")]}),e.jsxs(D,{variant:"outline",size:"sm",disabled:!0,children:[e.jsx(Zt,{className:"h-4 w-4 mr-2"}),t("common.export")]}),e.jsx(Ni,{table:s})]}),e.jsx(qh,{refetch:n,open:r,onOpenChange:a})]})}const Hh=0,Kh=1,Bh=2,hn=3,Gh=s=>{const{t:n}=M("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.id")}),cell:({row:t})=>e.jsx(U,{children:t.original.id})},{accessorKey:"code",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.code")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{variant:"secondary",children:t.original.code}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>sa(t.original.code).then(()=>{$.success(n("common:copy.success"))}),children:e.jsx(kl,{className:"h-4 w-4"})})]})},{accessorKey:"template_name",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.template_name")})},{accessorKey:"status",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.status")}),cell:({row:t})=>{const r=t.original.status,a=r===hn,i=r===Hh||r===hn;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{variant:r===Kh?"secondary":r===Bh||r===hn?"destructive":"default",children:n(`code.status.${r}`)}),i&&e.jsx(X,{checked:!a,onCheckedChange:async l=>{const d=l?"enable":"disable";try{const{data:u}=await Ds.toggleCode({id:t.original.id,action:d});u?($.success(n("messages.codeStatusUpdated")),s()):$.error(n("messages.updateCodeStatusFailed"))}catch{$.error(n("messages.updateCodeStatusFailed"))}}})]})}},{accessorKey:"expires_at",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.expires_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(t.original.expires_at)})},{accessorKey:"usage_count",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.usage_count")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.original.usage_count})},{accessorKey:"max_usage",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.max_usage")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.original.max_usage})},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(t.original.created_at)})}]};function Wh(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,i]=m.useState([]),[l,d]=m.useState([]),[u,x]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=ae({queryKey:["giftCardCodes",u,a,l],queryFn:()=>Ds.getCodes({per_page:u.pageSize,page:u.pageIndex+1,filter:a,sort:l})}),b=Be({data:c?.data??[],columns:Gh(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:u},pageCount:Math.ceil((c?.total??0)/u.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:x,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:b,toolbar:e.jsx(Uh,{table:b,refetch:o})})})}const Yh=()=>{const{t:s}=M("giftCard");return[{accessorKey:"id",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.id")}),cell:({row:n})=>e.jsx(U,{children:n.original.id})},{accessorKey:"code",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.code")}),cell:({row:n})=>e.jsx(U,{variant:"secondary",children:n.original.code})},{accessorKey:"user_email",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.user_email")})},{accessorKey:"template_name",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.template_name")})},{accessorKey:"created_at",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.created_at")}),cell:({row:n})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(n.original.created_at)})}]};function Jh(){const[s,n]=m.useState([]),[t,r]=m.useState([]),[a,i]=m.useState({pageIndex:0,pageSize:20}),{data:l}=ae({queryKey:["giftCardUsages",a,s,t],queryFn:()=>Ds.getUsages({per_page:a.pageSize,page:a.pageIndex+1,filter:s,sort:t})}),d=Be({data:l?.data??[],columns:Yh(),state:{sorting:t,columnFilters:s,pagination:a},pageCount:Math.ceil((l?.total??0)/a.pageSize),rowCount:l?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,onSortingChange:r,onColumnFiltersChange:n,onPaginationChange:i,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs()});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(k,{placeholder:"搜索用户邮箱...",value:d.getColumn("user_email")?.getFilterValue()??"",onChange:u=>d.getColumn("user_email")?.setFilterValue(u.target.value),className:"h-8 w-[150px] lg:w-[250px]"})}),e.jsx(ts,{table:d})]})}function Qh(){const{t:s}=M("giftCard"),{data:n,isLoading:t}=ae({queryKey:["giftCardStats"],queryFn:()=>Ds.getStatistics({})}),r=n?.data?.total_stats,a=[{title:s("statistics.total.templates_count"),value:r?.templates_count},{title:s("statistics.total.active_templates_count"),value:r?.active_templates_count},{title:s("statistics.total.codes_count"),value:r?.codes_count},{title:s("statistics.total.used_codes_count"),value:r?.used_codes_count}];return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:a.map((i,l)=>e.jsxs(ke,{children:[e.jsx(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:e.jsx(Le,{className:"text-sm font-medium",children:i.title})}),e.jsx(Pe,{children:t?e.jsx(je,{className:"h-8 w-1/2"}):e.jsx("div",{className:"text-2xl font-bold",children:i.value??0})})]},l))})}function Xh(){const{t:s}=M("giftCard"),[n,t]=m.useState("templates");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-6 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsxs(gt,{value:n,onValueChange:t,className:"flex-1",children:[e.jsxs(at,{className:"grid w-full grid-cols-4",children:[e.jsx($e,{value:"templates",children:s("tabs.templates")}),e.jsx($e,{value:"codes",children:s("tabs.codes")}),e.jsx($e,{value:"usages",children:s("tabs.usages")}),e.jsx($e,{value:"statistics",children:s("tabs.statistics")})]}),e.jsx(ms,{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($h,{})]})}),e.jsx(ms,{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(Wh,{})]})}),e.jsx(ms,{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(Jh,{})]})}),e.jsx(ms,{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(Qh,{})]})})]})]})]})}const Zh=Object.freeze(Object.defineProperty({__proto__:null,default:Xh},Symbol.toStringTag,{value:"Module"})),eg=1,sg=1e6;let gn=0;function tg(){return gn=(gn+1)%Number.MAX_SAFE_INTEGER,gn.toString()}const pn=new Map,wr=s=>{if(pn.has(s))return;const n=setTimeout(()=>{pn.delete(s),Qt({type:"REMOVE_TOAST",toastId:s})},sg);pn.set(s,n)},ag=(s,n)=>{switch(n.type){case"ADD_TOAST":return{...s,toasts:[n.toast,...s.toasts].slice(0,eg)};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?wr(t):s.toasts.forEach(r=>{wr(r.id)}),{...s,toasts:s.toasts.map(r=>r.id===t||t===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return n.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==n.toastId)}}},_a=[];let Na={toasts:[]};function Qt(s){Na=ag(Na,s),_a.forEach(n=>{n(Na)})}function ng({...s}){const n=tg(),t=a=>Qt({type:"UPDATE_TOAST",toast:{...a,id:n}}),r=()=>Qt({type:"DISMISS_TOAST",toastId:n});return Qt({type:"ADD_TOAST",toast:{...s,id:n,open:!0,onOpenChange:a=>{a||r()}}}),{id:n,dismiss:r,update:t}}function wi(){const[s,n]=m.useState(Na);return m.useEffect(()=>(_a.push(n),()=>{const t=_a.indexOf(n);t>-1&&_a.splice(t,1)}),[s]),{...s,toast:ng,dismiss:t=>Qt({type:"DISMISS_TOAST",toastId:t})}}function rg({open:s,onOpenChange:n,table:t}){const{t:r}=M("user"),{toast:a}=wi(),[i,l]=m.useState(!1),[d,u]=m.useState(""),[x,o]=m.useState(""),c=async()=>{if(!d||!x){a({title:r("messages.error"),description:r("messages.send_mail.required_fields"),variant:"destructive"});return}try{l(!0),await Os.sendMail({subject:d,content:x,filter:t.getState().columnFilters,sort:t.getState().sorting[0]?.id,sort_type:t.getState().sorting[0]?.desc?"DESC":"ASC"}),a({title:r("messages.success"),description:r("messages.send_mail.success")}),n(!1),u(""),o("")}catch{a({title:r("messages.error"),description:r("messages.send_mail.failed"),variant:"destructive"})}finally{l(!1)}};return e.jsx(de,{open:s,onOpenChange:n,children:e.jsxs(ce,{className:"sm:max-w-[500px]",children:[e.jsxs(he,{children:[e.jsx(me,{children:r("send_mail.title")}),e.jsx(Ae,{children:r("send_mail.description")})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"subject",className:"text-right",children:r("send_mail.subject")}),e.jsx(k,{id:"subject",value:d,onChange:b=>u(b.target.value),className:"col-span-3"})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"content",className:"text-right",children:r("send_mail.content")}),e.jsx(Rs,{id:"content",value:x,onChange:b=>o(b.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(Me,{children:e.jsx(G,{type:"submit",onClick:c,disabled:i,children:r(i?"send_mail.sending":"send_mail.send")})})]})})}function lg({trigger:s}){const{t:n}=M("user"),[t,r]=m.useState(!1),[a,i]=m.useState(30),{data:l,isLoading:d}=ae({queryKey:["trafficResetStats",a],queryFn:()=>aa.getStats({days:a}),enabled:t}),u=[{title:n("traffic_reset.stats.total_resets"),value:l?.data?.total_resets||0,icon:Gt,color:"text-blue-600",bgColor:"bg-blue-100"},{title:n("traffic_reset.stats.auto_resets"),value:l?.data?.auto_resets||0,icon:ka,color:"text-green-600",bgColor:"bg-green-100"},{title:n("traffic_reset.stats.manual_resets"),value:l?.data?.manual_resets||0,icon:ws,color:"text-orange-600",bgColor:"bg-orange-100"},{title:n("traffic_reset.stats.cron_resets"),value:l?.data?.cron_resets||0,icon:On,color:"text-purple-600",bgColor:"bg-purple-100"}],x=[{value:7,label:n("traffic_reset.stats.days_options.week")},{value:30,label:n("traffic_reset.stats.days_options.month")},{value:90,label:n("traffic_reset.stats.days_options.quarter")},{value:365,label:n("traffic_reset.stats.days_options.year")}];return e.jsxs(de,{open:t,onOpenChange:r,children:[e.jsx(ps,{asChild:!0,children:s}),e.jsxs(ce,{className:"max-w-2xl",children:[e.jsxs(he,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(Vn,{className:"h-5 w-5"}),n("traffic_reset.stats.title")]}),e.jsx(Ae,{children:n("traffic_reset.stats.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-medium",children:n("traffic_reset.stats.time_range")}),e.jsxs(J,{value:a.toString(),onValueChange:o=>i(Number(o)),children:[e.jsx(W,{className:"w-[180px]",children:e.jsx(Q,{})}),e.jsx(Y,{children:x.map(o=>e.jsx(A,{value:o.value.toString(),children:o.label},o.value))})]})]}),d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Xt,{className:"h-6 w-6 animate-spin"})}):e.jsx("div",{className:"grid grid-cols-2 gap-4",children:u.map((o,c)=>e.jsxs(ke,{className:"relative overflow-hidden",children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Le,{className:"text-sm font-medium text-muted-foreground",children:o.title}),e.jsx("div",{className:`rounded-lg p-2 ${o.bgColor}`,children:e.jsx(o.icon,{className:`h-4 w-4 ${o.color}`})})]}),e.jsxs(Pe,{children:[e.jsx("div",{className:"text-2xl font-bold",children:o.value.toLocaleString()}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:n("traffic_reset.stats.in_period",{days:a})})]})]},c))}),l?.data&&e.jsxs(ke,{children:[e.jsxs(Fe,{children:[e.jsx(Le,{className:"text-lg",children:n("traffic_reset.stats.breakdown")}),e.jsx(Hs,{children:n("traffic_reset.stats.breakdown_description")})]}),e.jsx(Pe,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:n("traffic_reset.stats.auto_percentage")}),e.jsxs(U,{variant:"outline",className:"border-green-200 bg-green-50 text-green-700",children:[l.data.total_resets>0?(l.data.auto_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:n("traffic_reset.stats.manual_percentage")}),e.jsxs(U,{variant:"outline",className:"border-orange-200 bg-orange-50 text-orange-700",children:[l.data.total_resets>0?(l.data.manual_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:n("traffic_reset.stats.cron_percentage")}),e.jsxs(U,{variant:"outline",className:"border-purple-200 bg-purple-50 text-purple-700",children:[l.data.total_resets>0?(l.data.cron_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]})]})})]})]})]})]})}const ig=h.object({email_prefix:h.string().optional(),email_suffix:h.string().min(1),password:h.string().optional(),expired_at:h.number().optional().nullable(),plan_id:h.number().nullable(),generate_count:h.number().optional().nullable(),download_csv:h.boolean().optional()}).refine(s=>s.generate_count===null?s.email_prefix!==void 0&&s.email_prefix!=="":!0,{message:"Email prefix is required when generate_count is null",path:["email_prefix"]}),og={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0,download_csv:!1};function cg({refetch:s}){const{t:n}=M("user"),[t,r]=m.useState(!1),a=we({resolver:Te(ig),defaultValues:og,mode:"onChange"}),[i,l]=m.useState([]);return m.useEffect(()=>{t&&ys.getList().then(({data:d})=>{d&&l(d)})},[t]),e.jsxs(de,{open:t,onOpenChange:r,children:[e.jsx(ps,{asChild:!0,children:e.jsxs(G,{size:"sm",variant:"outline",className:"gap-0 space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(me,{children:n("generate.title")}),e.jsx(Ae,{})]}),e.jsxs(De,{...a,children:[e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!a.watch("generate_count")&&e.jsx(j,{control:a.control,name:"email_prefix",render:({field:d})=>e.jsx(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(j,{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(j,{control:a.control,name:"password",render:({field:d})=>e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.password")}),e.jsx(k,{placeholder:n("generate.form.password_placeholder"),...d}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"expired_at",render:({field:d})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(v,{children:n("generate.form.expire_time")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsx(_,{children:e.jsxs(G,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!d.value&&"text-muted-foreground"),children:[d.value?oe(d.value):e.jsx("span",{children:n("generate.form.expire_time_placeholder")}),e.jsx(ws,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(Xe,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(Nd,{asChild:!0,children:e.jsx(G,{variant:"outline",className:"w-full",onClick:()=>{d.onChange(null)},children:n("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Cs,{mode:"single",selected:d.value?new Date(d.value*1e3):void 0,onSelect:u=>{u&&d.onChange(u?.getTime()/1e3)}})})]})]})]})}),e.jsx(j,{control:a.control,name:"plan_id",render:({field:d})=>e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.subscription")}),e.jsx(_,{children:e.jsxs(J,{value:d.value?d.value.toString():"null",onValueChange:u=>d.onChange(u==="null"?null:parseInt(u)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"null",children:n("generate.form.subscription_none")}),i.map(u=>e.jsx(A,{value:u.id.toString(),children:u.name},u.id))]})]})})]})}),!a.watch("email_prefix")&&e.jsx(j,{control:a.control,name:"generate_count",render:({field:d})=>e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.generate_count")}),e.jsx(k,{type:"number",placeholder:n("generate.form.generate_count_placeholder"),value:d.value||"",onChange:u=>d.onChange(u.target.value?parseInt(u.target.value):null)})]})}),a.watch("generate_count")&&e.jsx(j,{control:a.control,name:"download_csv",render:({field:d})=>e.jsxs(f,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(_,{children:e.jsx(Bn,{checked:d.value,onCheckedChange:d.onChange})}),e.jsx(v,{children:n("generate.form.download_csv")})]})})]}),e.jsxs(Me,{children:[e.jsx(G,{variant:"outline",onClick:()=>r(!1),children:n("generate.form.cancel")}),e.jsx(G,{onClick:()=>a.handleSubmit(async d=>{if(d.download_csv){const u=await Os.generate(d);if(u&&u instanceof Blob){const x=window.URL.createObjectURL(u),o=document.createElement("a");o.href=x,o.download=`users_${new Date().getTime()}.csv`,document.body.appendChild(o),o.click(),o.remove(),window.URL.revokeObjectURL(x),$.success(n("generate.form.success")),a.reset(),s(),r(!1)}}else{const{data:u}=await Os.generate(d);u&&($.success(n("generate.form.success")),a.reset(),s(),r(!1))}})(),children:n("generate.form.submit")})]})]})]})}const Gn=Lr,Ci=Er,dg=Vr,Si=m.forwardRef(({className:s,...n},t)=>e.jsx(Va,{className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:t}));Si.displayName=Va.displayName;const mg=xt("fixed overflow-y-scroll z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-md",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-md"}},defaultVariants:{side:"right"}}),en=m.forwardRef(({side:s="right",className:n,children:t,...r},a)=>e.jsxs(dg,{children:[e.jsx(Si,{}),e.jsxs(Ia,{ref:a,className:N(mg({side:s}),n),...r,children:[e.jsxs(Pn,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[e.jsx(os,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),t]})]}));en.displayName=Ia.displayName;const sn=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-2 text-center sm:text-left",s),...n});sn.displayName="SheetHeader";const ki=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});ki.displayName="SheetFooter";const tn=m.forwardRef(({className:s,...n},t)=>e.jsx(Ma,{ref:t,className:N("text-lg font-semibold text-foreground",s),...n}));tn.displayName=Ma.displayName;const an=m.forwardRef(({className:s,...n},t)=>e.jsx(Oa,{ref:t,className:N("text-sm text-muted-foreground",s),...n}));an.displayName=Oa.displayName;function ug({table:s,refetch:n,permissionGroups:t=[],subscriptionPlans:r=[]}){const{t:a}=M("user"),{toast:i}=wi(),l=s.getState().columnFilters.length>0,[d,u]=m.useState([]),[x,o]=m.useState(!1),[c,b]=m.useState(!1),[F,S]=m.useState(!1),[w,T]=m.useState(!1),y=async()=>{try{const se=await Os.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),ne=se;console.log(se);const H=new Blob([ne],{type:"text/csv;charset=utf-8;"}),ee=window.URL.createObjectURL(H),fe=document.createElement("a");fe.href=ee,fe.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(fe),fe.click(),fe.remove(),window.URL.revokeObjectURL(ee),i({title:a("messages.success"),description:a("messages.export.success")})}catch{i({title:a("messages.error"),description:a("messages.export.failed"),variant:"destructive"})}},L=async()=>{try{T(!0),await Os.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),i({title:a("messages.success"),description:a("messages.batch_ban.success")}),n()}catch{i({title:a("messages.error"),description:a("messages.batch_ban.failed"),variant:"destructive"})}finally{T(!1),S(!1)}},C=[{label:a("filter.fields.email"),value:"email",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.id"),value:"id",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.plan_id"),value:"plan_id",type:"select",operators:[{label:a("filter.operators.eq"),value:"eq"}],useOptions:!0},{label:a("filter.fields.transfer_enable"),value:"transfer_enable",type:"number",unit:"GB",operators:[{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.total_used"),value:"total_used",type:"number",unit:"GB",operators:[{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.online_count"),value:"online_count",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"},{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"}]},{label:a("filter.fields.expired_at"),value:"expired_at",type:"date",operators:[{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.uuid"),value:"uuid",type:"text",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.token"),value:"token",type:"text",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.banned"),value:"banned",type:"select",operators:[{label:a("filter.operators.eq"),value:"eq"}],options:[{label:a("filter.status.normal"),value:"0"},{label:a("filter.status.banned"),value:"1"}]},{label:a("filter.fields.remark"),value:"remarks",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.inviter_email"),value:"invite_user.email",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.invite_user_id"),value:"invite_user_id",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.is_admin"),value:"is_admin",type:"boolean",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.is_staff"),value:"is_staff",type:"boolean",operators:[{label:a("filter.operators.eq"),value:"eq"}]}],g=se=>se*1024*1024*1024,p=se=>se/(1024*1024*1024),V=()=>{u([...d,{field:"",operator:"",value:""}])},E=se=>{u(d.filter((ne,H)=>H!==se))},P=(se,ne,H)=>{const ee=[...d];if(ee[se]={...ee[se],[ne]:H},ne==="field"){const fe=C.find(fs=>fs.value===H);fe&&(ee[se].operator=fe.operators[0].value,ee[se].value=fe.type==="boolean"?!1:"")}u(ee)},K=(se,ne)=>{const H=C.find(ee=>ee.value===se.field);if(!H)return null;switch(H.type){case"text":return e.jsx(k,{placeholder:a("filter.sheet.value"),value:se.value,onChange:ee=>P(ne,"value",ee.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(k,{type:"number",placeholder:a("filter.sheet.value_number",{unit:H.unit}),value:H.unit==="GB"?p(se.value||0):se.value,onChange:ee=>{const fe=Number(ee.target.value);P(ne,"value",H.unit==="GB"?g(fe):fe)}}),H.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:H.unit})]});case"date":return e.jsx(Cs,{mode:"single",selected:se.value,onSelect:ee=>P(ne,"value",ee),className:"flex flex-1 justify-center rounded-md border"});case"select":return e.jsxs(J,{value:se.value,onValueChange:ee=>P(ne,"value",ee),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("filter.sheet.value")})}),e.jsx(Y,{children:H.useOptions?r.map(ee=>e.jsx(A,{value:ee.value.toString(),children:ee.label},ee.value)):H.options?.map(ee=>e.jsx(A,{value:ee.value.toString(),children:ee.label},ee.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(X,{checked:se.value,onCheckedChange:ee=>P(ne,"value",ee)}),e.jsx(Je,{children:se.value?a("filter.boolean.true"):a("filter.boolean.false")})]});default:return null}},Z=()=>{const se=d.filter(ne=>ne.field&&ne.operator&&ne.value!=="").map(ne=>{const H=C.find(fe=>fe.value===ne.field);let ee=ne.value;return ne.operator==="contains"?{id:ne.field,value:ee}:(H?.type==="date"&&ee instanceof Date&&(ee=Math.floor(ee.getTime()/1e3)),H?.type==="boolean"&&(ee=ee?1:0),{id:ne.field,value:`${ne.operator}:${ee}`})});s.setColumnFilters(se),o(!1)};return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-2",children:[e.jsx(cg,{refetch:n}),e.jsx(k,{placeholder:a("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:se=>s.getColumn("email")?.setFilterValue(se.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(Gn,{open:x,onOpenChange:o,children:[e.jsx(Ci,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Rl,{className:"mr-2 h-4 w-4"}),a("filter.advanced"),d.length>0&&e.jsx(U,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:d.length})]})}),e.jsxs(en,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(sn,{children:[e.jsx(tn,{children:a("filter.sheet.title")}),e.jsx(an,{children:a("filter.sheet.description")})]}),e.jsxs("div",{className:"mt-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:a("filter.sheet.conditions")}),e.jsx(D,{variant:"outline",size:"sm",onClick:V,children:a("filter.sheet.add")})]}),e.jsx(ut,{className:"h-[calc(100vh-280px)] ",children:e.jsx("div",{className:"space-y-4",children:d.map((se,ne)=>e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Je,{children:a("filter.sheet.condition",{number:ne+1})}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>E(ne),children:e.jsx(os,{className:"h-4 w-4"})})]}),e.jsxs(J,{value:se.field,onValueChange:H=>P(ne,"field",H),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("filter.sheet.field")})}),e.jsx(Y,{children:e.jsx(js,{children:C.map(H=>e.jsx(A,{value:H.value,className:"cursor-pointer",children:H.label},H.value))})})]}),se.field&&e.jsxs(J,{value:se.operator,onValueChange:H=>P(ne,"operator",H),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("filter.sheet.operator")})}),e.jsx(Y,{children:C.find(H=>H.value===se.field)?.operators.map(H=>e.jsx(A,{value:H.value,children:H.label},H.value))})]}),se.field&&se.operator&&K(se,ne)]},ne))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(D,{variant:"outline",onClick:()=>{u([]),o(!1)},children:a("filter.sheet.reset")}),e.jsx(D,{onClick:Z,children:a("filter.sheet.apply")})]})]})]})]}),l&&e.jsxs(D,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),u([])},className:"h-8 px-2 lg:px-3",children:[a("filter.sheet.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]}),e.jsxs(zs,{modal:!1,children:[e.jsx(Ks,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:a("actions.title")})}),e.jsxs(Ms,{children:[e.jsx(Se,{onClick:()=>b(!0),children:a("actions.send_email")}),e.jsx(Se,{onClick:y,children:a("actions.export_csv")}),e.jsx(et,{}),e.jsx(Se,{asChild:!0,children:e.jsx(lg,{trigger:e.jsx("div",{className:"w-full cursor-pointer px-2 py-1.5 text-sm",children:a("actions.traffic_reset_stats")})})}),e.jsx(et,{}),e.jsx(Se,{onClick:()=>S(!0),className:"text-red-600 focus:text-red-600",children:a("actions.batch_ban")})]})]})]}),e.jsx(rg,{open:c,onOpenChange:b,table:s}),e.jsx(Hn,{open:F,onOpenChange:S,children:e.jsxs(Ka,{children:[e.jsxs(Ba,{children:[e.jsx(Wa,{children:a("actions.confirm_ban.title")}),e.jsx(Ya,{children:a(l?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(Ga,{children:[e.jsx(Qa,{disabled:w,children:a("actions.confirm_ban.cancel")}),e.jsx(Ja,{onClick:L,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 Ti=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"})}),Di=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"})}),xg=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"})}),hg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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:qd(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ti,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:ze(s.original.u/parseFloat(s.original.server_rate))})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Di,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:ze(s.original.d/parseFloat(s.original.server_rate))})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const n=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(U,{variant:"outline",className:"font-mono",children:[n,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const n=s.original.u+s.original.d;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:ze(n)})}}];function Fi({user_id:s,dialogTrigger:n}){const{t}=M(["traffic"]),[r,a]=m.useState(!1),[i,l]=m.useState({pageIndex:0,pageSize:20}),{data:d,isLoading:u}=ae({queryKey:["userStats",s,i,r],queryFn:()=>r?Os.getStats({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),x=Be({data:d?.data??[],columns:fn,pageCount:Math.ceil((d?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:Ge(),onPaginationChange:l});return e.jsxs(de,{open:r,onOpenChange:a,children:[e.jsx(ps,{asChild:!0,children:n}),e.jsxs(ce,{className:"sm:max-w-[700px]",children:[e.jsx(he,{children:e.jsx(me,{children:t("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs($n,{children:[e.jsx(An,{children:x.getHeaderGroups().map(o=>e.jsx(Js,{children:o.headers.map(c=>e.jsx(Un,{className:N("h-10 px-2 text-xs",c.id==="total"&&"text-right"),children:c.isPlaceholder?null:Ca(c.column.columnDef.header,c.getContext())},c.id))},o.id))}),e.jsx(qn,{children:u?Array.from({length:i.pageSize}).map((o,c)=>e.jsx(Js,{children:Array.from({length:fn.length}).map((b,F)=>e.jsx(Tt,{className:"p-2",children:e.jsx(je,{className:"h-6 w-full"})},F))},c)):x.getRowModel().rows?.length?x.getRowModel().rows.map(o=>e.jsx(Js,{"data-state":o.getIsSelected()&&"selected",className:"h-10",children:o.getVisibleCells().map(c=>e.jsx(Tt,{className:"px-2",children:Ca(c.column.columnDef.cell,c.getContext())},c.id))},o.id)):e.jsx(Js,{children:e.jsx(Tt,{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(J,{value:`${x.getState().pagination.pageSize}`,onValueChange:o=>{x.setPageSize(Number(o))},children:[e.jsx(W,{className:"h-8 w-[70px]",children:e.jsx(Q,{placeholder:x.getState().pagination.pageSize})}),e.jsx(Y,{side:"top",children:[10,20,30,40,50].map(o=>e.jsx(A,{value:`${o}`,children:o},o))})]}),e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.records")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"flex w-[100px] items-center justify-center text-sm",children:t("trafficRecord.page",{current:x.getState().pagination.pageIndex+1,total:x.getPageCount()})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>x.previousPage(),disabled:!x.getCanPreviousPage()||u,children:e.jsx(xg,{className:"h-4 w-4"})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>x.nextPage(),disabled:!x.getCanNextPage()||u,children:e.jsx(hg,{className:"h-4 w-4"})})]})]})]})]})]})]})}function gg({user:s,trigger:n,onSuccess:t}){const{t:r}=M("user"),[a,i]=m.useState(!1),[l,d]=m.useState(""),[u,x]=m.useState(!1),{data:o,isLoading:c}=ae({queryKey:["trafficResetHistory",s.id],queryFn:()=>aa.getUserHistory(s.id,{limit:10}),enabled:a}),b=async()=>{try{x(!0);const{data:w}=await aa.resetUser({user_id:s.id,reason:l.trim()||void 0});w&&($.success(r("traffic_reset.reset_success")),i(!1),d(""),t?.())}finally{x(!1)}},F=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(de,{open:a,onOpenChange:i,children:[e.jsx(ps,{asChild:!0,children:n}),e.jsxs(ce,{className:"max-h-[90vh] max-w-4xl overflow-hidden",children:[e.jsxs(he,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(Gt,{className:"h-5 w-5"}),r("traffic_reset.title")]}),e.jsx(Ae,{children:r("traffic_reset.description",{email:s.email})})]}),e.jsxs(gt,{defaultValue:"reset",className:"w-full",children:[e.jsxs(at,{className:"grid w-full grid-cols-2",children:[e.jsxs($e,{value:"reset",className:"flex items-center gap-2",children:[e.jsx(Gt,{className:"h-4 w-4"}),r("traffic_reset.tabs.reset")]}),e.jsxs($e,{value:"history",className:"flex items-center gap-2",children:[e.jsx(or,{className:"h-4 w-4"}),r("traffic_reset.tabs.history")]})]}),e.jsxs(ms,{value:"reset",className:"space-y-4",children:[e.jsxs(ke,{children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs(Le,{className:"flex items-center gap-2 text-lg",children:[e.jsx(El,{className:"h-5 w-5"}),r("traffic_reset.user_info")]})}),e.jsx(Pe,{className:"space-y-3",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.email")}),e.jsx("p",{className:"font-medium",children:s.email})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.used_traffic")}),e.jsx("p",{className:"font-medium",children:ze(s.total_used)})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.total_traffic")}),e.jsx("p",{className:"font-medium",children:ze(s.transfer_enable)})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.expire_time")}),e.jsx("p",{className:"font-medium",children:s.expired_at?oe(s.expired_at):r("columns.expire_status.permanent")})]})]})})]}),e.jsxs(ke,{className:"border-amber-200 bg-amber-50",children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs(Le,{className:"flex items-center gap-2 text-lg text-amber-800",children:[e.jsx(Bt,{className:"h-5 w-5"}),r("traffic_reset.warning.title")]})}),e.jsx(Pe,{children:e.jsxs("ul",{className:"space-y-2 text-sm text-amber-700",children:[e.jsxs("li",{children:["• ",r("traffic_reset.warning.irreversible")]}),e.jsxs("li",{children:["• ",r("traffic_reset.warning.reset_to_zero")]}),e.jsxs("li",{children:["• ",r("traffic_reset.warning.logged")]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Je,{htmlFor:"reason",children:r("traffic_reset.reason.label")}),e.jsx(Rs,{id:"reason",placeholder:r("traffic_reset.reason.placeholder"),value:l,onChange:w=>d(w.target.value),className:"min-h-[80px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("traffic_reset.reason.optional")})]}),e.jsxs(Me,{children:[e.jsx(G,{variant:"outline",onClick:()=>i(!1),children:r("common:cancel")}),e.jsx(G,{onClick:b,disabled:u,className:"bg-destructive hover:bg-destructive/90",children:u?e.jsxs(e.Fragment,{children:[e.jsx(Xt,{className:"mr-2 h-4 w-4 animate-spin"}),r("traffic_reset.resetting")]}):e.jsxs(e.Fragment,{children:[e.jsx(Gt,{className:"mr-2 h-4 w-4"}),r("traffic_reset.confirm_reset")]})})]})]}),e.jsx(ms,{value:"history",className:"space-y-4",children:c?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Xt,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[o?.data?.user&&e.jsxs(ke,{children:[e.jsx(Fe,{className:"pb-3",children:e.jsx(Le,{className:"text-lg",children:r("traffic_reset.history.summary")})}),e.jsx(Pe,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.reset_count")}),e.jsx("p",{className:"font-medium",children:o.data.user.reset_count})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.last_reset")}),e.jsx("p",{className:"font-medium",children:o.data.user.last_reset_at?oe(o.data.user.last_reset_at):r("traffic_reset.history.never")})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.next_reset")}),e.jsx("p",{className:"font-medium",children:o.data.user.next_reset_at?oe(o.data.user.next_reset_at):r("traffic_reset.history.no_schedule")})]})]})})]}),e.jsxs(ke,{children:[e.jsxs(Fe,{className:"pb-3",children:[e.jsx(Le,{className:"text-lg",children:r("traffic_reset.history.records")}),e.jsx(Hs,{children:r("traffic_reset.history.recent_records")})]}),e.jsx(Pe,{children:e.jsx(ut,{className:"h-[300px]",children:o?.data?.history?.length?e.jsx("div",{className:"space-y-3",children:o.data.history.map((w,T)=>e.jsxs("div",{children:[e.jsx("div",{className:"flex items-start justify-between rounded-lg border bg-card p-3",children:e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:F(w.reset_type),children:w.reset_type_name}),e.jsx(U,{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(Je,{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(On,{className:"h-3 w-3"}),r("traffic_reset.history.reset_time")]}),e.jsx("p",{className:"font-medium",children:oe(w.reset_time)})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.traffic_cleared")}),e.jsx("p",{className:"font-medium text-destructive",children:w.old_traffic.formatted})]})]})]})}),Te.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"})}),jg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 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"})}),vg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),Cr=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"})}),bg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),yg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),_g=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),Ng=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),wg=(s,n,t,r)=>{const{t:a}=M("user");return[{accessorKey:"is_admin",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l)),size:0},{accessorKey:"is_staff",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l)),size:0},{accessorKey:"id",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.id")}),cell:({row:i})=>e.jsx(U,{variant:"outline",children:i.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.email")}),cell:({row:i})=>{const l=i.original.t||0,d=Date.now()/1e3-l<120,u=Math.floor(Date.now()/1e3-l);let x=d?a("columns.online_status.online"):l===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:oe(l)});if(!d&&l!==0){const o=Math.floor(u/60),c=Math.floor(o/60),b=Math.floor(c/24);b>0?x+=` +`)||d("plan.form.submit.error.validation","表单校验失败"))},w=y=>{if(isNaN(y))return;const L=Object.entries(ja).reduce((C,[g,p])=>{const V=y*p.months*p.discount;return{...C,[g]:V.toFixed(2)}},{});u.setValue("prices",L,{shouldDirty:!0})},T=()=>{n(!1),r(null),u.reset(fa)};return e.jsx(de,{open:s,onOpenChange:T,children:e.jsxs(ce,{children:[e.jsxs(he,{children:[e.jsx(me,{children:d(t?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(Ae,{})]}),e.jsx(De,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(F,S),children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{control:u.control,name:"name",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:d("plan.form.name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:d("plan.form.name.placeholder"),...y})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"tags",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:d("plan.form.tags.label","标签")}),e.jsx(_,{children:e.jsx(Xa,{value:y.value||[],onChange:y.onChange,placeholder:d("plan.form.tags.placeholder","输入标签后按回车确认"),className:"w-full"})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"group_id",render:({field:y})=>e.jsxs(f,{children:[e.jsxs(v,{className:"flex items-center justify-between",children:[d("plan.form.group.label"),e.jsx(Za,{dialogTrigger:e.jsx(D,{variant:"link",children:d("plan.form.group.add")}),refetch:b})]}),e.jsxs(J,{value:y.value?.toString()??"",onValueChange:L=>y.onChange(L?Number(L):null),children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:d("plan.form.group.placeholder")})})}),e.jsx(Y,{children:o?.map(L=>e.jsx(A,{value:L.id.toString(),children:L.name},L.id))})]}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"transfer_enable",render:({field:y})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{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(R,{})]})}),e.jsx(j,{control:u.control,name:"speed_limit",render:({field:y})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{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(R,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:d("plan.form.price.title")}),e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(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 L=parseFloat(y.target.value);w(L)}})]}),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const y=Object.keys(ja).reduce((L,C)=>({...L,[C]:""}),{});u.setValue("prices",y,{shouldDirty:!0})},children:d("plan.form.price.clear.button")})}),e.jsx(ue,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:d("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(ja).filter(([y])=>!["onetime","reset_traffic"].includes(y)).map(([y,L])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(j,{control:u.control,name:`prices.${y}`,render:({field:C})=>e.jsxs(f,{children:[e.jsxs(v,{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:["(",L.months===1?d("plan.form.price.period.monthly"):d("plan.form.price.period.months",{count:L.months}),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,step:"0.01",...C,value:C.value??"",onChange:g=>C.onChange(g.target.value),className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})},y))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(ja).filter(([y])=>["onetime","reset_traffic"].includes(y)).map(([y,L])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(j,{control:u.control,name:`prices.${y}`,render:({field:C})=>e.jsx(f,{children:e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-0",children:[e.jsx(v,{className:"text-xs font-medium",children:d(`plan.columns.price_period.${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(_,{children:e.jsx(k,{type:"number",placeholder:"0.00",min:0,step:"0.01",...C,value:C.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(j,{control:u.control,name:"device_limit",render:({field:y})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{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(R,{})]})}),e.jsx(j,{control:u.control,name:"capacity_limit",render:({field:y})=>e.jsxs(f,{className:"flex-1",children:[e.jsx(v,{children:d("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(_,{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(R,{})]})})]}),e.jsx(j,{control:u.control,name:"reset_traffic_method",render:({field:y})=>e.jsxs(f,{children:[e.jsx(v,{children:d("plan.form.reset_method.label")}),e.jsxs(J,{value:y.value?.toString()??"null",onValueChange:L=>y.onChange(L=="null"?null:Number(L)),children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:d("plan.form.reset_method.placeholder")})})}),e.jsx(Y,{children:rh.map(L=>e.jsx(A,{value:L.value?.toString()??"null",children:d(`plan.form.reset_method.options.${L.label}`)},L.value))})]}),e.jsx(z,{className:"text-xs",children:d("plan.form.reset_method.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"content",render:({field:y})=>{const[L,C]=m.useState(!1);return e.jsxs(f,{className:"space-y-2",children:[e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d("plan.form.content.label"),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>C(!L),children:L?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(ue,{side:"top",children:e.jsx("p",{className:"text-xs",children:d(L?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(be,{children:e.jsxs(ge,{children:[e.jsx(pe,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",onClick:()=>{y.onChange(d("plan.form.content.template.content"))},children:d("plan.form.content.template.button")})}),e.jsx(ue,{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 ${L?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(_,{children:e.jsx(Mn,{style:{height:"400px"},value:y.value||"",renderHTML:g=>x.render(g),onChange:({text:g})=>y.onChange(g),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:d("plan.form.content.placeholder"),className:"rounded-md border"})})}),L&&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:x.render(y.value||"")}})})]})]}),e.jsx(z,{className:"text-xs",children:d("plan.form.content.description")}),e.jsx(R,{})]})}})]}),e.jsx(Me,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:t&&e.jsx(j,{control:u.control,name:"force_update",render:({field:y})=>e.jsxs(f,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(_,{children:e.jsx(Bn,{checked:y.value,onCheckedChange:y.onChange})}),e.jsx("div",{className:"",children:e.jsx(v,{className:"text-sm",children:d("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:T,children:d("plan.form.submit.cancel")}),e.jsx(D,{type:"submit",disabled:i,children:d(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})})]})})}function ih(){const[s,n]=m.useState({}),[t,r]=m.useState({"drag-handle":!1}),[a,i]=m.useState([]),[l,d]=m.useState([]),[u,x]=m.useState(!1),[o,c]=m.useState({pageSize:20,pageIndex:0}),[b,F]=m.useState([]),{refetch:S}=ae({queryKey:["planList"],queryFn:async()=>{const{data:C}=await ys.getList();return F(C),C}});m.useEffect(()=>{r({"drag-handle":u}),c({pageSize:u?99999:10,pageIndex:0})},[u]);const w=(C,g)=>{u&&(C.dataTransfer.setData("text/plain",g.toString()),C.currentTarget.classList.add("opacity-50"))},T=(C,g)=>{if(!u)return;C.preventDefault(),C.currentTarget.classList.remove("bg-muted");const p=parseInt(C.dataTransfer.getData("text/plain"));if(p===g)return;const V=[...b],[E]=V.splice(p,1);V.splice(g,0,E),F(V)},y=async()=>{if(!u){x(!0);return}const C=b?.map(g=>g.id);ys.sort(C).then(()=>{$.success("排序保存成功"),x(!1),S()}).finally(()=>{x(!1)})},L=Be({data:b||[],columns:ah(S),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:o},enableRowSelection:!0,onPaginationChange:c,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}},pageCount:u?1:void 0});return e.jsx(sh,{refreshData:S,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(ts,{table:L,toolbar:C=>e.jsx(th,{table:C,refetch:S,saveOrder:y,isSortMode:u}),draggable:u,onDragStart:w,onDragEnd:C=>C.currentTarget.classList.remove("opacity-50"),onDragOver:C=>{C.preventDefault(),C.currentTarget.classList.add("bg-muted")},onDragLeave:C=>C.currentTarget.classList.remove("bg-muted"),onDrop:T,showPagination:!u}),e.jsx(lh,{})]})})}function oh(){const{t:s}=M("subscribe");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("plan.title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("plan.page.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(ih,{})})]})]})}const ch=Object.freeze(Object.defineProperty({__proto__:null,default:oh},Symbol.toStringTag,{value:"Module"})),Ct=[{value:le.PENDING,label:zt[le.PENDING],icon:pd,color:$t[le.PENDING]},{value:le.PROCESSING,label:zt[le.PROCESSING],icon:Dl,color:$t[le.PROCESSING]},{value:le.COMPLETED,label:zt[le.COMPLETED],icon:wn,color:$t[le.COMPLETED]},{value:le.CANCELLED,label:zt[le.CANCELLED],icon:Fl,color:$t[le.CANCELLED]},{value:le.DISCOUNTED,label:zt[le.DISCOUNTED],icon:wn,color:$t[le.DISCOUNTED]}],Ht=[{value:Ce.PENDING,label:xa[Ce.PENDING],icon:fd,color:ha[Ce.PENDING]},{value:Ce.PROCESSING,label:xa[Ce.PROCESSING],icon:Dl,color:ha[Ce.PROCESSING]},{value:Ce.VALID,label:xa[Ce.VALID],icon:wn,color:ha[Ce.VALID]},{value:Ce.INVALID,label:xa[Ce.INVALID],icon:Fl,color:ha[Ce.INVALID]}];function va({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=s?.getFilterValue(),i=Array.isArray(a)?new Set(a):a!==void 0?new Set([a]):new Set;return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx($a,{className:"mr-2 h-4 w-4"}),n,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ve,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{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(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):t.filter(l=>i.has(l.value)).map(l=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(nt,{children:[e.jsx(ft,{placeholder:n}),e.jsxs(rt,{children:[e.jsx(jt,{children:"No results found."}),e.jsx(Ss,{children:t.map(l=>{const d=i.has(l.value);return e.jsxs(rs,{onSelect:()=>{const u=new Set(i);d?u.delete(l.value):u.add(l.value);const x=Array.from(u);s?.setFilterValue(x.length?x:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",d?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ht,{className:N("h-4 w-4")})}),l.icon&&e.jsx(l.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${l.color}`}),e.jsx("span",{children:l.label}),r?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(l.value)})]},l.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Lt,{}),e.jsx(Ss,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const dh=h.object({email:h.string().min(1),plan_id:h.number(),period:h.string(),total_amount:h.number()}),mh={email:"",plan_id:0,total_amount:0,period:""};function ji({refetch:s,trigger:n,defaultValues:t}){const{t:r}=M("order"),[a,i]=m.useState(!1),l=we({resolver:Te(dh),defaultValues:{...mh,...t},mode:"onChange"}),[d,u]=m.useState([]);return m.useEffect(()=>{a&&ys.getList().then(({data:x})=>{u(x)})},[a]),e.jsxs(de,{open:a,onOpenChange:i,children:[e.jsx(ps,{asChild:!0,children:n||e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:r("dialog.addOrder")})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(me,{children:r("dialog.assignOrder")}),e.jsx(Ae,{})]}),e.jsxs(De,{...l,children:[e.jsx(j,{control:l.control,name:"email",render:({field:x})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.userEmail")}),e.jsx(_,{children:e.jsx(k,{placeholder:r("dialog.placeholders.email"),...x})})]})}),e.jsx(j,{control:l.control,name:"plan_id",render:({field:x})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.subscriptionPlan")}),e.jsx(_,{children:e.jsxs(J,{value:x.value?x.value?.toString():void 0,onValueChange:o=>x.onChange(parseInt(o)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dialog.placeholders.plan")})}),e.jsx(Y,{children:d.map(o=>e.jsx(A,{value:o.id.toString(),children:o.name},o.id))})]})})]})}),e.jsx(j,{control:l.control,name:"period",render:({field:x})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.orderPeriod")}),e.jsx(_,{children:e.jsxs(J,{value:x.value,onValueChange:x.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dialog.placeholders.period")})}),e.jsx(Y,{children:Object.keys(Vm).map(o=>e.jsx(A,{value:o,children:r(`period.${o}`)},o))})]})})]})}),e.jsx(j,{control:l.control,name:"total_amount",render:({field:x})=>e.jsxs(f,{children:[e.jsx(v,{children:r("dialog.fields.paymentAmount")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:r("dialog.placeholders.amount"),value:x.value/100,onChange:o=>x.onChange(parseFloat(o.currentTarget.value)*100)})}),e.jsx(R,{})]})}),e.jsxs(Me,{children:[e.jsx(D,{variant:"outline",onClick:()=>i(!1),children:r("dialog.actions.cancel")}),e.jsx(D,{type:"submit",onClick:()=>{l.handleSubmit(x=>{ct.assign(x).then(({data:o})=>{o&&(s&&s(),l.reset(),i(!1),$.success(r("dialog.messages.addSuccess")))})})()},children:r("dialog.actions.confirm")})]})]})]})]})}function uh({table:s,refetch:n}){const{t}=M("order"),r=s.getState().columnFilters.length>0,a=Object.values(Vs).filter(u=>typeof u=="number").map(u=>({label:t(`type.${Vs[u]}`),value:u,color:u===Vs.NEW?"green-500":u===Vs.RENEWAL?"blue-500":u===Vs.UPGRADE?"purple-500":"orange-500"})),i=Object.values(Qe).map(u=>({label:t(`period.${u}`),value:u,color:u===Qe.MONTH_PRICE?"slate-500":u===Qe.QUARTER_PRICE?"cyan-500":u===Qe.HALF_YEAR_PRICE?"indigo-500":u===Qe.YEAR_PRICE?"violet-500":u===Qe.TWO_YEAR_PRICE?"fuchsia-500":u===Qe.THREE_YEAR_PRICE?"pink-500":u===Qe.ONETIME_PRICE?"rose-500":"orange-500"})),l=Object.values(le).filter(u=>typeof u=="number").map(u=>({label:t(`status.${le[u]}`),value:u,icon:u===le.PENDING?Ct[0].icon:u===le.PROCESSING?Ct[1].icon:u===le.COMPLETED?Ct[2].icon:u===le.CANCELLED?Ct[3].icon:Ct[4].icon,color:u===le.PENDING?"yellow-500":u===le.PROCESSING?"blue-500":u===le.COMPLETED?"green-500":u===le.CANCELLED?"red-500":"green-500"})),d=Object.values(Ce).filter(u=>typeof u=="number").map(u=>({label:t(`commission.${Ce[u]}`),value:u,icon:u===Ce.PENDING?Ht[0].icon:u===Ce.PROCESSING?Ht[1].icon:u===Ce.VALID?Ht[2].icon:Ht[3].icon,color:u===Ce.PENDING?"yellow-500":u===Ce.PROCESSING?"blue-500":u===Ce.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ji,{refetch:n}),e.jsx(k,{placeholder:t("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:u=>s.getColumn("trade_no")?.setFilterValue(u.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2",children:[s.getColumn("type")&&e.jsx(va,{column:s.getColumn("type"),title:t("table.columns.type"),options:a}),s.getColumn("period")&&e.jsx(va,{column:s.getColumn("period"),title:t("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(va,{column:s.getColumn("status"),title:t("table.columns.status"),options:l}),s.getColumn("commission_status")&&e.jsx(va,{column:s.getColumn("commission_status"),title:t("table.columns.commissionStatus"),options:d})]}),r&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("actions.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]})}function ns({label:s,value:n,className:t,valueClassName:r}){return e.jsxs("div",{className:N("flex items-center py-1.5",t),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:N("text-sm",r),children:n||"-"})]})}function xh({status:s}){const{t:n}=M("order"),t={[le.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[le.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[le.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[le.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[le.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(U,{variant:"secondary",className:N("font-medium",t[s]),children:n(`status.${le[s]}`)})}function hh({id:s,trigger:n}){const[t,r]=m.useState(!1),[a,i]=m.useState(),{t:l}=M("order");return m.useEffect(()=>{(async()=>{if(t){const{data:u}=await ct.getInfo({id:s});i(u)}})()},[t,s]),e.jsxs(de,{onOpenChange:r,open:t,children:[e.jsx(ps,{asChild:!0,children:n}),e.jsxs(ce,{className:"max-w-xl",children:[e.jsxs(he,{className:"space-y-2",children:[e.jsx(me,{className:"text-lg font-medium",children:l("dialog.title")}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:[l("table.columns.tradeNo"),":",a?.trade_no]}),!!a?.status&&e.jsx(xh,{status:a.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.userEmail"),value:a?.user?.email?e.jsxs(Zs,{to:`/user/manage?email=${a.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[a.user.email,e.jsx(Cn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(ns,{label:l("dialog.fields.orderPeriod"),value:a&&l(`period.${a.period}`)}),e.jsx(ns,{label:l("dialog.fields.subscriptionPlan"),value:a?.plan?.name,valueClassName:"font-medium"}),e.jsx(ns,{label:l("dialog.fields.callbackNo"),value:a?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.paymentAmount"),value:qs(a?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(Ve,{className:"my-2"}),e.jsx(ns,{label:l("dialog.fields.balancePayment"),value:qs(a?.balance_amount||0)}),e.jsx(ns,{label:l("dialog.fields.discountAmount"),value:qs(a?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(ns,{label:l("dialog.fields.refundAmount"),value:qs(a?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(ns,{label:l("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:l("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.createdAt"),value:oe(a?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(ns,{label:l("dialog.fields.updatedAt"),value:oe(a?.updated_at),valueClassName:"font-mono text-xs"})]})]}),a?.commission_status===1&&a?.commission_balance&&e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.commissionInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(ns,{label:l("dialog.fields.commissionStatus"),value:e.jsx(U,{variant:"secondary",className:"bg-orange-100 font-medium text-orange-800 hover:bg-orange-100",children:l("dialog.commissionStatusActive")})}),e.jsx(ns,{label:l("dialog.fields.commissionAmount"),value:qs(a?.commission_balance||0),valueClassName:"font-medium text-orange-600"}),a?.actual_commission_balance&&e.jsx(ns,{label:l("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(Ve,{className:"my-2"}),e.jsx(ns,{label:l("dialog.fields.inviteUser"),value:e.jsxs(Zs,{to:`/user/manage?email=${a.invite_user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[a.invite_user.email,e.jsx(Cn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]})}),e.jsx(ns,{label:l("dialog.fields.inviteUserId"),value:a?.invite_user?.id,valueClassName:"font-mono text-xs"})]})]})]})]})]})]})}const gh={[Vs.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Vs.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Vs.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Vs.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},ph={[Qe.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Qe.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},fh=s=>le[s],jh=s=>Ce[s],vh=s=>Vs[s],bh=s=>{const{t:n}=M("order");return[{accessorKey:"trade_no",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.tradeNo")}),cell:({row:t})=>{const r=t.original.trade_no,a=r.length>6?`${r.slice(0,3)}...${r.slice(-3)}`:r;return e.jsx("div",{className:"flex items-center",children:e.jsx(hh,{trigger:e.jsxs(G,{variant:"ghost",size:"sm",className:"flex h-8 items-center gap-1.5 px-2 font-medium text-primary transition-colors hover:bg-primary/10 hover:text-primary/80",children:[e.jsx("span",{className:"font-mono",children:a}),e.jsx(Cn,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.type")}),cell:({row:t})=>{const r=t.getValue("type"),a=gh[r];return e.jsx(U,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",a.color,a.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:n(`type.${vh(r)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.plan")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium text-foreground/90 sm:max-w-72 md:max-w-[31rem]",children:t.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.period")}),cell:({row:t})=>{const r=t.getValue("period"),a=ph[r];return e.jsx(U,{variant:"secondary",className:N("font-medium transition-colors text-nowrap",a?.color,a?.bgColor,"hover:bg-opacity-80"),children:n(`period.${r}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.amount")}),cell:({row:t})=>{const r=t.getValue("total_amount"),a=typeof r=="number"?(r/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",a]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:t})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(O,{column:t,title:n("table.columns.status")}),e.jsx(be,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(pe,{children:e.jsx(di,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(ue,{side:"top",className:"max-w-[200px] text-sm",children:n("status.tooltip")})]})})]}),cell:({row:t})=>{const r=Ct.find(a=>a.value===t.getValue("status"));return r?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r.icon&&e.jsx(r.icon,{className:`h-4 w-4 text-${r.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`status.${fh(r.value)}`)})]}),r.value===le.PENDING&&e.jsxs(zs,{modal:!0,children:[e.jsx(Ks,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(Ms,{align:"end",className:"w-[140px]",children:[e.jsx(Se,{className:"cursor-pointer",onClick:async()=>{await ct.markPaid({trade_no:t.original.trade_no}),s()},children:n("actions.markAsPaid")}),e.jsx(Se,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await ct.makeCancel({trade_no:t.original.trade_no}),s()},children:n("actions.cancel")})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.commission")}),cell:({row:t})=>{const r=t.getValue("commission_balance"),a=r?(r/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:r?`¥${a}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.commissionStatus")}),cell:({row:t})=>{const r=t.original.status,a=t.original.commission_balance,i=Ht.find(l=>l.value===t.getValue("commission_status"));return a==0||!i?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i.icon&&e.jsx(i.icon,{className:`h-4 w-4 text-${i.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n(`commission.${jh(i.value)}`)})]}),i.value===Ce.PENDING&&r===le.COMPLETED&&e.jsxs(zs,{modal:!0,children:[e.jsx(Ks,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:n("actions.openMenu")})]})}),e.jsxs(Ms,{align:"end",className:"w-[120px]",children:[e.jsx(Se,{className:"cursor-pointer",onClick:async()=>{await ct.update({trade_no:t.original.trade_no,commission_status:Ce.PROCESSING}),s()},children:n("commission.PROCESSING")}),e.jsx(Se,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await ct.update({trade_no:t.original.trade_no,commission_status:Ce.INVALID}),s()},children:n("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.createdAt")}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:oe(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function yh(){const[s]=Pl(),[n,t]=m.useState({}),[r,a]=m.useState({}),[i,l]=m.useState([]),[d,u]=m.useState([]),[x,o]=m.useState({pageIndex:0,pageSize:20});m.useEffect(()=>{const T=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([y,L])=>{const C=s.get(y);return C?{id:y,value:L==="number"?parseInt(C):C}:null}).filter(Boolean);T.length>0&&l(T)},[s]);const{refetch:c,data:b,isLoading:F}=ae({queryKey:["orderList",x,i,d],queryFn:()=>ct.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:i,sort:d})}),S=Be({data:b?.data??[],columns:bh(c),state:{sorting:d,columnVisibility:r,rowSelection:n,columnFilters:i,pagination:x},rowCount:b?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:u,onColumnFiltersChange:l,onColumnVisibilityChange:a,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),onPaginationChange:o,getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(ts,{table:S,toolbar:e.jsx(uh,{table:S,refetch:c}),showPagination:!0})}function _h(){const{t:s}=M("order");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(yh,{})})]})]})}const Nh=Object.freeze(Object.defineProperty({__proto__:null,default:_h},Symbol.toStringTag,{value:"Module"}));function wh({column:s,title:n,options:t}){const r=s?.getFacetedUniqueValues(),a=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx($a,{className:"mr-2 h-4 w-4"}),n,a?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ve,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{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(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[a.size," selected"]}):t.filter(i=>a.has(i.value)).map(i=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(nt,{children:[e.jsx(ft,{placeholder:n}),e.jsxs(rt,{children:[e.jsx(jt,{children:"No results found."}),e.jsx(Ss,{children:t.map(i=>{const l=a.has(i.value);return e.jsxs(rs,{onSelect:()=>{l?a.delete(i.value):a.add(i.value);const d=Array.from(a);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ht,{className:N("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),a.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Lt,{}),e.jsx(Ss,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Ch=s=>h.object({id:h.coerce.number().nullable().optional(),name:h.string().min(1,s("form.name.required")),code:h.string().nullable(),type:h.coerce.number(),value:h.coerce.number(),started_at:h.coerce.number(),ended_at:h.coerce.number(),limit_use:h.union([h.string(),h.number()]).nullable(),limit_use_with_user:h.union([h.string(),h.number()]).nullable(),generate_count:h.coerce.number().nullable().optional(),limit_plan_ids:h.array(h.coerce.number()).default([]).nullable(),limit_period:h.array(h.nativeEnum(Jt)).default([]).nullable()}).refine(n=>n.ended_at>n.started_at,{message:s("form.validity.endTimeError"),path:["ended_at"]}),Nr={name:"",code:null,type:Ns.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},Sh=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 vi({defaultValues:s,refetch:n,type:t="create",dialogTrigger:r=null,open:a,onOpenChange:i}){const{t:l}=M("coupon"),[d,u]=m.useState(!1),x=a??d,o=i??u,[c,b]=m.useState([]),F=Ch(l),S=Sh(l),w=we({resolver:Te(F),defaultValues:s||Nr});m.useEffect(()=>{s&&w.reset(s)},[s,w]),m.useEffect(()=>{ys.getList().then(({data:g})=>b(g))},[]);const T=g=>{if(!g)return;const p=(V,E)=>{const P=new Date(E*1e3);return V.setHours(P.getHours(),P.getMinutes(),P.getSeconds()),Math.floor(V.getTime()/1e3)};g.from&&w.setValue("started_at",p(g.from,w.watch("started_at"))),g.to&&w.setValue("ended_at",p(g.to,w.watch("ended_at")))},y=g=>{const p=new Date,V=Math.floor(p.getTime()/1e3),E=Math.floor((p.getTime()+g*24*60*60*1e3)/1e3);w.setValue("started_at",V),w.setValue("ended_at",E)},L=async g=>{const p=await Pa.save(g);if(g.generate_count&&typeof p=="string"){const V=new Blob([p],{type:"text/csv;charset=utf-8;"}),E=document.createElement("a");E.href=window.URL.createObjectURL(V),E.download=`coupons_${new Date().getTime()}.csv`,E.click(),window.URL.revokeObjectURL(E.href)}o(!1),t==="create"&&w.reset(Nr),n()},C=(g,p)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:p}),e.jsx(k,{type:"datetime-local",step:"1",value:oe(w.watch(g),"YYYY-MM-DDTHH:mm:ss"),onChange:V=>{const E=new Date(V.target.value);w.setValue(g,Math.floor(E.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(de,{open:x,onOpenChange:o,children:[r&&e.jsx(ps,{asChild:!0,children:r}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsx(he,{children:e.jsx(me,{children:l(t==="create"?"form.add":"form.edit")})}),e.jsx(De,{...w,children:e.jsxs("form",{onSubmit:w.handleSubmit(L),className:"space-y-4",children:[e.jsx(j,{control:w.control,name:"name",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.name.label")}),e.jsx(k,{placeholder:l("form.name.placeholder"),...g}),e.jsx(R,{})]})}),t==="create"&&e.jsx(j,{control:w.control,name:"generate_count",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.generateCount.label")}),e.jsx(k,{type:"number",min:0,placeholder:l("form.generateCount.placeholder"),...g,value:g.value??"",onChange:p=>g.onChange(p.target.value===""?null:parseInt(p.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.generateCount.description")}),e.jsx(R,{})]})}),(!w.watch("generate_count")||w.watch("generate_count")==null)&&e.jsx(j,{control:w.control,name:"code",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.code.label")}),e.jsx(k,{placeholder:l("form.code.placeholder"),...g,value:g.value??"",className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.code.description")}),e.jsx(R,{})]})}),e.jsxs(f,{children:[e.jsx(v,{children:l("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(j,{control:w.control,name:"type",render:({field:g})=>e.jsxs(J,{value:g.value.toString(),onValueChange:p=>{const V=g.value,E=parseInt(p);g.onChange(E);const P=w.getValues("value");P&&(V===Ns.AMOUNT&&E===Ns.PERCENTAGE?w.setValue("value",P/100):V===Ns.PERCENTAGE&&E===Ns.AMOUNT&&w.setValue("value",P*100))},children:[e.jsx(W,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Q,{placeholder:l("form.type.placeholder")})}),e.jsx(Y,{children:Object.entries(Im).map(([p,V])=>e.jsx(A,{value:p,children:l(`table.toolbar.types.${p}`)},p))})]})}),e.jsx(j,{control:w.control,name:"value",render:({field:g})=>{const p=g.value==null?"":w.watch("type")===Ns.AMOUNT&&typeof g.value=="number"?(g.value/100).toString():g.value.toString();return e.jsx(k,{type:"number",placeholder:l("form.value.placeholder"),...g,value:p,onChange:V=>{const E=V.target.value;if(E===""){g.onChange("");return}const P=parseFloat(E);isNaN(P)||g.onChange(w.watch("type")===Ns.AMOUNT?Math.round(P*100):P)},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")==Ns.AMOUNT?"¥":"%"})})]})]}),e.jsxs(f,{children:[e.jsx(v,{children:l("form.validity.label")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(D,{variant:"outline",className:N("w-full justify-start text-left font-normal",!w.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(ws,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"truncate",children:[oe(w.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",l("form.validity.to")," ",oe(w.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})]})}),e.jsxs(Xe,{className:"w-auto p-0",align:"start",children:[e.jsxs("div",{className:"border-b border-border p-3",children:[e.jsx("div",{className:"mb-2 text-sm font-medium text-muted-foreground",children:l("form.timeRange.quickSet")}),e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-6",children:S.map(g=>e.jsx(D,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>y(g.days),type:"button",children:g.label},g.days))})]}),e.jsx("div",{className:"hidden border-b border-border sm:block",children:e.jsx(Cs,{mode:"range",selected:{from:new Date(w.watch("started_at")*1e3),to:new Date(w.watch("ended_at")*1e3)},onSelect:T,numberOfMonths:2})}),e.jsx("div",{className:"border-b border-border sm:hidden",children:e.jsx(Cs,{mode:"range",selected:{from:new Date(w.watch("started_at")*1e3),to:new Date(w.watch("ended_at")*1e3)},onSelect:T,numberOfMonths:1})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center",children:[C("started_at",l("table.validity.startTime")),e.jsx("div",{className:"text-center text-sm text-muted-foreground sm:mt-6",children:l("form.validity.to")}),C("ended_at",l("table.validity.endTime"))]})})]})]}),e.jsx(R,{})]}),e.jsx(j,{control:w.control,name:"limit_use",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitUse.label")}),e.jsx(k,{type:"number",min:0,placeholder:l("form.limitUse.placeholder"),...g,value:g.value??"",onChange:p=>g.onChange(p.target.value===""?null:parseInt(p.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.limitUse.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"limit_use_with_user",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitUseWithUser.label")}),e.jsx(k,{type:"number",min:0,placeholder:l("form.limitUseWithUser.placeholder"),...g,value:g.value??"",onChange:p=>g.onChange(p.target.value===""?null:parseInt(p.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.limitUseWithUser.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"limit_period",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitPeriod.label")}),e.jsx(st,{options:Object.entries(Jt).filter(([p])=>isNaN(Number(p))).map(([p,V])=>({label:l(`coupon:period.${V}`),value:p})),onChange:p=>{if(p.length===0){g.onChange([]);return}const V=p.map(E=>Jt[E.value]);g.onChange(V)},value:(g.value||[]).map(p=>({label:l(`coupon:period.${p}`),value:Object.entries(Jt).find(([V,E])=>E===p)?.[0]||""})),placeholder:l("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPeriod.empty")})}),e.jsx(z,{className:"text-xs",children:l("form.limitPeriod.description")}),e.jsx(R,{})]})}),e.jsx(j,{control:w.control,name:"limit_plan_ids",render:({field:g})=>e.jsxs(f,{children:[e.jsx(v,{children:l("form.limitPlan.label")}),e.jsx(st,{options:c?.map(p=>({label:p.name,value:p.id.toString()}))||[],onChange:p=>g.onChange(p.map(V=>Number(V.value))),value:(c||[]).filter(p=>(g.value||[]).includes(p.id)).map(p=>({label:p.name,value:p.id.toString()})),placeholder:l("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPlan.empty")})}),e.jsx(R,{})]})}),e.jsx(Me,{children:e.jsx(D,{type:"submit",disabled:w.formState.isSubmitting,children:w.formState.isSubmitting?l("form.submit.saving"):l("form.submit.save")})})]})})]})]})}function kh({table:s,refetch:n}){const t=s.getState().columnFilters.length>0,{t:r}=M("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(vi,{refetch:n,dialogTrigger:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:r("form.add")})]})}),e.jsx(k,{placeholder:r("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:a=>s.getColumn("name")?.setFilterValue(a.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(wh,{column:s.getColumn("type"),title:r("table.toolbar.type"),options:[{value:Ns.AMOUNT,label:r(`table.toolbar.types.${Ns.AMOUNT}`)},{value:Ns.PERCENTAGE,label:r(`table.toolbar.types.${Ns.PERCENTAGE}`)}]}),t&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]})}const bi=m.createContext(void 0);function Th({children:s,refetch:n}){const[t,r]=m.useState(!1),[a,i]=m.useState(null),l=u=>{i(u),r(!0)},d=()=>{r(!1),i(null)};return e.jsxs(bi.Provider,{value:{isOpen:t,currentCoupon:a,openEdit:l,closeEdit:d},children:[s,a&&e.jsx(vi,{defaultValues:a,refetch:n,type:"edit",open:t,onOpenChange:r})]})}function Dh(){const s=m.useContext(bi);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const Fh=s=>{const{t:n}=M("coupon");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.id")}),cell:({row:t})=>e.jsx(U,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.show")}),cell:({row:t})=>e.jsx(X,{defaultChecked:t.original.show,onCheckedChange:r=>{Pa.update({id:t.original.id,show:r}).then(({data:a})=>!a&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.type")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:n(`table.toolbar.types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.code")}),cell:({row:t})=>e.jsx(U,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.limitUse")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.original.limit_use===null?n("table.validity.unlimited"):t.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.limitUseWithUser")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.original.limit_use_with_user===null?n("table.validity.noLimit"):t.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:t})=>e.jsx(O,{column:t,title:n("table.columns.validity")}),cell:({row:t})=>{const[r,a]=m.useState(!1),i=Date.now(),l=t.original.started_at*1e3,d=t.original.ended_at*1e3,u=i>d,x=ie.jsx(O,{className:"justify-end",column:t,title:n("table.columns.actions")}),cell:({row:t})=>{const{openEdit:r}=Dh();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>r(t.original),children:[e.jsx(tt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:n("table.actions.edit")})]}),e.jsx(_s,{title:n("table.actions.deleteConfirm.title"),description:n("table.actions.deleteConfirm.description"),confirmText:n("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{Pa.drop({id:t.original.id}).then(({data:a})=>{a&&($.success("删除成功"),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(us,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:n("table.actions.delete")})]})})]})}}]};function Ph(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,i]=m.useState([]),[l,d]=m.useState([]),[u,x]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=ae({queryKey:["couponList",u,a,l],queryFn:()=>Pa.getList({pageSize:u.pageSize,current:u.pageIndex+1,filter:a,sort:l})}),b=Be({data:c?.data??[],columns:Fh(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:u},pageCount:Math.ceil((c?.total??0)/u.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:x,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Th,{refetch:o,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:b,toolbar:e.jsx(kh,{table:b,refetch:o})})})})}function Rh(){const{t:s}=M("coupon");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Ph,{})})]})]})}const Lh=Object.freeze(Object.defineProperty({__proto__:null,default:Rh},Symbol.toStringTag,{value:"Module"})),Eh=h.object({name:h.string().min(1,"请输入模板名称"),description:h.string().optional(),type:h.number().min(1).max(4),status:h.boolean(),sort:h.number().min(0),icon:h.string().optional(),background_image:h.string().optional(),conditions:h.object({allowed_plans:h.array(h.number()).optional(),disallowed_plans:h.array(h.number()).optional(),new_user_only:h.boolean().optional(),new_user_max_days:h.number().optional(),paid_user_only:h.boolean().optional(),require_invite:h.boolean().optional()}).optional(),limits:h.object({max_use_per_user:h.number().optional(),cooldown_hours:h.number().optional(),invite_reward_rate:h.number().optional()}).optional(),rewards:h.object({balance:h.number().optional(),transfer_enable:h.number().optional(),expire_days:h.number().optional(),device_limit:h.number().optional(),reset_package:h.boolean().optional(),plan_id:h.number().optional(),plan_validity_days:h.number().optional(),random_rewards:h.array(h.object({weight:h.number(),balance:h.number().optional(),transfer_enable:h.number().optional(),expire_days:h.number().optional(),device_limit:h.number().optional()})).optional()}),special_config:h.object({start_time:h.number().optional(),end_time:h.number().optional(),festival_bonus:h.number().optional()}).optional()});function yi({template:s,refetch:n,open:t,onOpenChange:r}){const{t:a}=M("giftCard"),[i,l]=m.useState(!1),[d,u]=m.useState([]),[x,o]=m.useState([]),c=we({resolver:Te(Eh),defaultValues:{name:"",description:"",type:1,status:!0,sort:0,icon:"",background_image:"",conditions:{},limits:{},rewards:{},special_config:{}}}),{fields:b,append:F,remove:S}=jd({control:c.control,name:"rewards.random_rewards"});m.useEffect(()=>{t&&(async()=>{try{const p=(await ys.getList()).data||[];u(p),o(p.map(V=>({label:V.name,value:V.id.toString()})))}catch(g){console.error("Failed to fetch plans:",g),$.error("Failed to load plan list")}})()},[t]),m.useEffect(()=>{if(s){const C=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:C.balance?C.balance/100:void 0,transfer_enable:typeof C.transfer_enable=="number"?C.transfer_enable/1024/1024/1024:void 0,expire_days:C.expire_days,device_limit:C.device_limit,reset_package:C.reset_package,plan_id:C.plan_id,plan_validity_days:C.plan_validity_days,random_rewards:C.random_rewards?.map(g=>({weight:g.weight,balance:g.balance?g.balance/100:void 0,transfer_enable:typeof g.transfer_enable=="number"?g.transfer_enable/1024/1024/1024:void 0,expire_days:g.expire_days,device_limit:g.device_limit}))||[]},special_config:s.special_config&&!Array.isArray(s.special_config)?s.special_config:{}})}else c.reset({name:"",description:"",type:1,status:!0,sort:0,icon:"",background_image:"",conditions:{},limits:{},rewards:{random_rewards:[]},special_config:{}})},[s,c]);const w=C=>{console.error("Form validation failed:",C),$.error(a("messages.formInvalid"))},T=async C=>{l(!0);const g=JSON.parse(JSON.stringify(C));g.rewards&&(typeof g.rewards.balance=="number"&&(g.rewards.balance=Math.round(g.rewards.balance*100)),typeof g.rewards.transfer_enable=="number"&&(g.rewards.transfer_enable=Math.round(g.rewards.transfer_enable*1024*1024*1024)),g.rewards.random_rewards&&g.rewards.random_rewards.forEach(V=>{typeof V.balance=="number"&&(V.balance=Math.round(V.balance*100)),typeof V.transfer_enable=="number"&&(V.transfer_enable=Math.round(V.transfer_enable*1024*1024*1024))}));const p={...g,conditions:g.conditions||{},limits:g.limits||{},rewards:g.rewards||{},special_config:g.special_config||{}};try{s?(await Ds.updateTemplate({id:s.id,...p}),$.success(a("messages.templateUpdated"))):(await Ds.createTemplate(p),$.success(a("messages.templateCreated"))),n(),r(!1)}catch(V){const E=V?.response?.data?.errors;E&&Object.keys(E).forEach(P=>{c.setError(P,{type:"manual",message:E[P][0]})}),$.error(a(s?"messages.updateTemplateFailed":"messages.createTemplateFailed"))}finally{l(!1)}},y=c.watch("type"),L=y===1;return e.jsx(de,{open:t,onOpenChange:r,children:e.jsxs(ce,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(he,{children:e.jsx(me,{children:a(s?"template.form.edit":"template.form.add")})}),e.jsx(De,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(T,w),className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"name",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.name.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:a("template.form.name.placeholder"),...C})}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"type",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.type.label")}),e.jsxs(J,{value:C.value.toString(),onValueChange:g=>C.onChange(parseInt(g)),children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:a("template.form.type.placeholder")})})}),e.jsx(Y,{children:[1,2,3].map(g=>e.jsx(A,{value:g.toString(),children:a(`types.${g}`)},g))})]}),e.jsx(R,{})]})})]}),e.jsx(j,{control:c.control,name:"description",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.description.label")}),e.jsx(_,{children:e.jsx(Rs,{placeholder:a("template.form.description.placeholder"),...C})}),e.jsx(R,{})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:e.jsx(j,{control:c.control,name:"status",render:({field:C})=>e.jsxs(f,{className:"col-span-3 flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:a("template.form.status.label")}),e.jsx(z,{children:a("template.form.status.description")})]}),e.jsx(_,{children:e.jsx(X,{checked:C.value,onCheckedChange:C.onChange})})]})})}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Le,{children:a("template.form.rewards.title")})}),e.jsxs(Pe,{className:"space-y-4",children:[L&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"rewards.balance",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.balance.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.balance.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(j,{control:c.control,name:"rewards.transfer_enable",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.transfer_enable.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.placeholder"),value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(j,{control:c.control,name:"rewards.expire_days",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.expire_days.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.expire_days.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(j,{control:c.control,name:"rewards.device_limit",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.device_limit.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.device_limit.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})})]}),e.jsx(j,{control:c.control,name:"rewards.reset_package",render:({field:C})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{children:a("template.form.rewards.reset_package.label")}),e.jsx(z,{children:a("template.form.rewards.reset_package.description")})]}),e.jsx(_,{children:e.jsx(X,{checked:C.value,onCheckedChange:C.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(j,{control:c.control,name:"rewards.plan_id",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.plan_id.label")}),e.jsxs(J,{value:C.value?.toString(),onValueChange:g=>C.onChange(parseInt(g,10)),children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:a("template.form.rewards.plan_id.placeholder")})})}),e.jsx(Y,{children:d.map(g=>e.jsx(A,{value:g.id.toString(),children:g.name},g.id))})]}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"rewards.plan_validity_days",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.rewards.plan_validity_days.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.plan_validity_days.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})})]}),y===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{children:a("template.form.rewards.random_rewards.label")}),b.map((C,g)=>e.jsxs("div",{className:"flex items-center space-x-2 rounded-md border p-2",children:[e.jsx(j,{control:c.control,name:`rewards.random_rewards.${g}.weight`,render:({field:p})=>e.jsx(f,{children:e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.random_rewards.weight"),...p,value:p.value??"",onChange:V=>{const E=V.target.valueAsNumber;p.onChange(isNaN(E)?0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${g}.balance`,render:({field:p})=>e.jsx(f,{children:e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.balance.label"),...p,value:p.value??"",onChange:V=>{const E=V.target.valueAsNumber;p.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${g}.transfer_enable`,render:({field:p})=>e.jsx(f,{children:e.jsx(_,{children:e.jsx(k,{type:"number",min:"0",step:"0.01",placeholder:a("template.form.rewards.transfer_enable.label")+" (GB)",value:p.value??"",onChange:V=>{const E=V.target.valueAsNumber;p.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${g}.expire_days`,render:({field:p})=>e.jsx(f,{children:e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.expire_days.label"),...p,value:p.value??"",onChange:V=>{const E=V.target.valueAsNumber;p.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(j,{control:c.control,name:`rewards.random_rewards.${g}.device_limit`,render:({field:p})=>e.jsx(f,{children:e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.rewards.device_limit.label"),...p,value:p.value??"",onChange:V=>{const E=V.target.valueAsNumber;p.onChange(isNaN(E)?void 0:E)}})})})}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",onClick:()=>S(g),children:e.jsx(vd,{className:"h-4 w-4"})})]},C.id)),e.jsx(D,{type:"button",variant:"outline",onClick:()=>F({weight:10,balance:void 0,transfer_enable:void 0,expire_days:void 0,device_limit:void 0}),children:a("template.form.rewards.random_rewards.add")})]})]})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Le,{children:a("template.form.conditions.title")})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 gap-4",children:e.jsx(j,{control:c.control,name:"conditions.new_user_max_days",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.conditions.new_user_max_days.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.conditions.new_user_max_days.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(j,{control:c.control,name:"conditions.new_user_only",render:({field:C})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(v,{children:a("template.form.conditions.new_user_only.label")})}),e.jsx(_,{children:e.jsx(X,{checked:C.value,onCheckedChange:C.onChange})})]})}),e.jsx(j,{control:c.control,name:"conditions.paid_user_only",render:({field:C})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(v,{children:a("template.form.conditions.paid_user_only.label")})}),e.jsx(_,{children:e.jsx(X,{checked:C.value,onCheckedChange:C.onChange})})]})}),e.jsx(j,{control:c.control,name:"conditions.require_invite",render:({field:C})=>e.jsxs(f,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(v,{children:a("template.form.conditions.require_invite.label")})}),e.jsx(_,{children:e.jsx(X,{checked:C.value,onCheckedChange:C.onChange})})]})})]}),e.jsx(j,{control:c.control,name:"conditions.allowed_plans",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.conditions.allowed_plans.label")}),e.jsx(_,{children:e.jsx(st,{value:C.value?.map(g=>({label:d.find(p=>p.id===g)?.name||`ID: ${g}`,value:g.toString()}))??[],onChange:g=>C.onChange(g.map(p=>parseInt(p.value))),options:x,placeholder:a("template.form.conditions.allowed_plans.placeholder")})})]})}),e.jsx(j,{control:c.control,name:"conditions.disallowed_plans",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.conditions.disallowed_plans.label")}),e.jsx(_,{children:e.jsx(st,{value:C.value?.map(g=>({label:d.find(p=>p.id===g)?.name||`ID: ${g}`,value:g.toString()}))??[],onChange:g=>C.onChange(g.map(p=>parseInt(p.value))),options:x,placeholder:a("template.form.conditions.disallowed_plans.placeholder")})})]})})]})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Le,{children:a("template.form.limits.title")})}),e.jsx(Pe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"limits.max_use_per_user",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.limits.max_use_per_user.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.limits.max_use_per_user.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(j,{control:c.control,name:"limits.cooldown_hours",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.limits.cooldown_hours.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",placeholder:a("template.form.limits.cooldown_hours.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})}),e.jsx(j,{control:c.control,name:"limits.invite_reward_rate",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.limits.invite_reward_rate.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",step:"0.01",placeholder:a("template.form.limits.invite_reward_rate.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})}),e.jsx(z,{children:a("template.form.limits.invite_reward_rate.description")})]})})]})})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Le,{children:a("template.form.special_config.title")})}),e.jsx(Pe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-3 items-end gap-4",children:[e.jsx(j,{control:c.control,name:"special_config.start_time",render:({field:C})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(v,{children:a("template.form.special_config.start_time.label")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsx(_,{children:e.jsxs(D,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!C.value&&"text-muted-foreground"),children:[C.value?Re(new Date(C.value*1e3),"PPP"):e.jsx("span",{children:a("template.form.special_config.start_time.placeholder")}),e.jsx(ws,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",children:e.jsx(Cs,{mode:"single",selected:C.value?new Date(C.value*1e3):void 0,onSelect:g=>C.onChange(g?Math.floor(g.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"special_config.end_time",render:({field:C})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(v,{children:a("template.form.special_config.end_time.label")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsx(_,{children:e.jsxs(D,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!C.value&&"text-muted-foreground"),children:[C.value?Re(new Date(C.value*1e3),"PPP"):e.jsx("span",{children:a("template.form.special_config.end_time.placeholder")}),e.jsx(ws,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Xe,{className:"w-auto p-0",align:"start",children:e.jsx(Cs,{mode:"single",selected:C.value?new Date(C.value*1e3):void 0,onSelect:g=>C.onChange(g?Math.floor(g.getTime()/1e3):void 0),initialFocus:!0})})]}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"special_config.festival_bonus",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.special_config.festival_bonus.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",step:"0.1",placeholder:a("template.form.special_config.festival_bonus.placeholder"),...C,value:C.value??"",onChange:g=>{const p=g.target.valueAsNumber;C.onChange(isNaN(p)?void 0:p)}})})]})})]})})]}),e.jsxs(ke,{children:[e.jsx(Fe,{children:e.jsx(Le,{children:a("template.form.display.title")})}),e.jsx(Pe,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:c.control,name:"icon",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.icon.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:a("template.form.icon.placeholder"),...C})}),e.jsx(R,{})]})}),e.jsx(j,{control:c.control,name:"background_image",render:({field:C})=>e.jsxs(f,{children:[e.jsx(v,{children:a("template.form.background_image.label")}),e.jsx(_,{children:e.jsx(k,{placeholder:a("template.form.background_image.placeholder"),...C})}),e.jsx(R,{})]})})]})})]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>r(!1),children:a("common:cancel")}),e.jsx(D,{type:"submit",disabled:i,children:a(i?"common:saving":"common:submit")})]})]})})]})})}const _i=m.createContext(void 0);function Vh({children:s,refetch:n}){const[t,r]=m.useState(!1),[a,i]=m.useState(null),l=u=>{i(u),r(!!u)},d=()=>{r(!1),i(null)};return e.jsxs(_i.Provider,{value:{isOpen:t,editingTemplate:a,setEditingTemplate:l,closeEdit:d},children:[s,e.jsx(yi,{template:a,refetch:n,open:t,onOpenChange:r})]})}function Ih(){const s=m.useContext(_i);if(s===void 0)throw new Error("useTemplateEdit must be used within a TemplateEditProvider");return s}function Mh({rewards:s,type:n}){const{t}=M(["giftCard","common"]),r=[];return s&&(s.balance&&r.push(`${t("template.form.rewards.balance.short_label")}: ${s.balance/100} ${t("common:currency.yuan","元")}`),s.transfer_enable&&r.push(`${t("template.form.rewards.transfer_enable.short_label")}: ${ze(s.transfer_enable)}`),s.expire_days&&r.push(`${t("template.form.rewards.expire_days.short_label")}: ${s.expire_days}${t("common:time.day","天")}`),s.device_limit&&r.push(`${t("template.form.rewards.device_limit.short_label")}: ${s.device_limit}`),n===2&&s.plan_id&&r.push(`${t("template.form.rewards.plan_id.short_label")}: ${s.plan_id}`),n===2&&s.plan_validity_days&&r.push(`${t("template.form.rewards.plan_validity_days.short_label")}: ${s.plan_validity_days}${t("common:time.day","天")}`),n===3&&s.random_rewards?.length&&r.push(t("types.3"))),r.length===0?e.jsx(U,{variant:"secondary",children:t("template.table.columns.no_rewards")}):e.jsx("div",{className:"flex flex-col space-y-1",children:r.map((a,i)=>e.jsx(U,{variant:"outline",className:"whitespace-nowrap",children:a},i))})}const Oh=s=>{const{t:n}=M("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.id")}),cell:({row:t})=>e.jsx(U,{children:t.original.id}),enableSorting:!0},{accessorKey:"status",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.status")}),cell:({row:t})=>{const[r,a]=m.useState(!1);return e.jsx(X,{checked:t.original.status,disabled:r,onCheckedChange:async i=>{a(!0);try{const{data:l}=await Ds.updateTemplate({id:t.original.id,status:i});l?($.success(n("messages.templateUpdated")),s()):$.error(n("messages.updateTemplateFailed"))}catch{$.error(n("messages.updateTemplateFailed"))}finally{a(!1)}}})},enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:300},{accessorKey:"type",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.type")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:n(`types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"rewards",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.rewards")}),cell:({row:t})=>e.jsx(Mh,{rewards:t.original.rewards,type:t.original.type}),enableSorting:!1},{accessorKey:"sort",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.sort")}),cell:({row:t})=>e.jsx(U,{variant:"secondary",children:t.original.sort}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(t.original.created_at)}),enableSorting:!0},{id:"actions",header:({column:t})=>e.jsx(O,{column:t,title:n("template.table.columns.actions")}),cell:({row:t})=>{const{setEditingTemplate:r}=Ih();return e.jsxs("div",{className:"flex space-x-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>r(t.original),children:[e.jsx(tt,{className:"h-4 w-4"}),n("template.actions.edit")]}),e.jsx(_s,{title:n("template.actions.deleteConfirm.title"),description:n("template.actions.deleteConfirm.description"),confirmText:n("template.actions.deleteConfirm.confirmText"),onConfirm:async()=>{try{const{data:a}=await Ds.deleteTemplate({id:t.original.id});a?($.success(n("messages.templateDeleted")),s()):$.error(n("messages.deleteTemplateFailed"))}catch{$.error(n("messages.deleteTemplateFailed"))}},children:e.jsxs(D,{variant:"outline",size:"sm",children:[e.jsx(us,{className:"h-4 w-4"}),n("template.actions.delete")]})})]})},enableSorting:!1}]};function Ni({table:s}){return e.jsxs(zs,{children:[e.jsx(bd,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(Rl,{className:"mr-2 h-4 w-4"}),"显示列"]})}),e.jsxs(Ms,{align:"end",className:"w-[150px]",children:[e.jsx(Ua,{children:"切换显示列"}),e.jsx(et,{}),s.getAllColumns().filter(n=>typeof n.accessorFn<"u"&&n.getCanHide()).map(n=>e.jsx(Gl,{className:"capitalize",checked:n.getIsVisible(),onCheckedChange:t=>n.toggleVisibility(!!t),children:n.id},n.id))]})]})}function Ea({column:s,title:n,options:t}){const r=new Set(s?.getFilterValue());return e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsxs(G,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(yd,{className:"mr-2 h-4 w-4"}),n,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ve,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):t.filter(a=>r.has(a.value)).map(a=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:a.label},`selected-${a.value}`))})]})]})}),e.jsx(Xe,{className:"w-[200px] p-0",align:"start",children:e.jsxs(nt,{children:[e.jsx(ft,{placeholder:n}),e.jsxs(rt,{children:[e.jsx(jt,{children:"No results found."}),e.jsx(Ss,{children:t.map(a=>{const i=r.has(a.value);return e.jsxs(rs,{onSelect:()=>{i?r.delete(a.value):r.add(a.value);const l=Array.from(r);s?.setFilterValue(l.length?l:void 0)},children:[e.jsx("div",{className:N("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",i?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(_d,{className:N("h-4 w-4")})}),a.icon&&e.jsx(a.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:a.label})]},`option-${a.value}`)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Lt,{}),e.jsx(Ss,{children:e.jsx(rs,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function zh({table:s,refetch:n}){const{t}=M("giftCard"),[r,a]=m.useState(!1),i=s.getState().columnFilters.length>0,l=[{label:t("types.1"),value:"1"},{label:t("types.2"),value:"2"},{label:t("types.3"),value:"3"},{label:t("types.4"),value:"4"},{label:t("types.5"),value:"5"},{label:t("types.6"),value:"6"},{label:t("types.7"),value:"7"},{label:t("types.8"),value:"8"},{label:t("types.9"),value:"9"},{label:t("types.10"),value:"10"}],d=[{label:t("common.enabled"),value:"true"},{label:t("common.disabled"),value:"false"}];return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(k,{placeholder:t("common.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:u=>s.getColumn("name")?.setFilterValue(u.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(Ea,{column:s.getColumn("type"),title:t("template.table.columns.type"),options:l}),s.getColumn("status")&&e.jsx(Ea,{column:s.getColumn("status"),title:t("template.table.columns.status"),options:d}),i&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Ll,{className:"h-4 w-4 mr-2"}),t("template.form.add")]}),e.jsx(Ni,{table:s})]}),e.jsx(yi,{template:null,refetch:n,open:r,onOpenChange:a})]})}function $h(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,i]=m.useState([]),[l,d]=m.useState([]),[u,x]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=ae({queryKey:["giftCardTemplates",u,a,l],queryFn:()=>Ds.getTemplates({per_page:u.pageSize,page:u.pageIndex+1,filter:a,sort:l})});console.log(c);const b=Be({data:c?.data??[],columns:Oh(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:u},pageCount:Math.ceil((c?.total??0)/u.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:x,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Vh,{refetch:o,children:e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:b,toolbar:e.jsx(zh,{table:b,refetch:o})})})})}const Ah=h.object({template_id:h.number().min(1,"请选择一个模板"),count:h.number().min(1,"生成数量必须大于0").max(1e4,"单次最多生成10000个"),prefix:h.string().optional(),expires_hours:h.number().min(1,"有效期必须大于0"),max_usage:h.number().min(1,"最大使用次数必须大于0"),download_csv:h.boolean().optional()});function qh({refetch:s,open:n,onOpenChange:t}){const{t:r}=M("giftCard"),[a,i]=m.useState(!1),[l,d]=m.useState([]);m.useEffect(()=>{n&&Ds.getTemplates({per_page:1e3,page:1}).then(({data:o})=>{d(o||[])})},[n]);const u=we({resolver:Te(Ah),defaultValues:{count:10,prefix:"",expires_hours:24*30,max_usage:1,download_csv:!1}}),x=async o=>{i(!0);try{if(o.download_csv){const c=await Ds.generateCodes(o);if(c&&c instanceof Blob){const b=window.URL.createObjectURL(c),F=document.createElement("a");F.href=b,F.download=`gift_codes_${new Date().getTime()}.csv`,document.body.appendChild(F),F.click(),F.remove(),window.URL.revokeObjectURL(b),$.success(r("messages.codesGenerated")),s(),t(!1),u.reset()}}else await Ds.generateCodes(o),$.success(r("messages.codesGenerated")),s(),t(!1),u.reset()}catch{$.error(r("messages.generateCodesFailed"))}finally{i(!1)}};return e.jsx(de,{open:n,onOpenChange:t,children:e.jsxs(ce,{children:[e.jsx(he,{children:e.jsx(me,{children:r("code.form.generate")})}),e.jsx(De,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(x),className:"space-y-4",children:[e.jsx(j,{control:u.control,name:"template_id",render:({field:o})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.template_id.label")}),e.jsxs(J,{onValueChange:c=>o.onChange(parseInt(c)),children:[e.jsx(_,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:r("code.form.template_id.placeholder")})})}),e.jsx(Y,{children:l.map(c=>e.jsx(A,{value:c.id.toString(),children:c.name},c.id))})]}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"count",render:({field:o})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.count.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"prefix",render:({field:o})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.prefix.label")}),e.jsx(_,{children:e.jsx(k,{...o})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"expires_hours",render:({field:o})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.expires_hours.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"max_usage",render:({field:o})=>e.jsxs(f,{children:[e.jsx(v,{children:r("code.form.max_usage.label")}),e.jsx(_,{children:e.jsx(k,{type:"number",...o,onChange:c=>o.onChange(parseInt(c.target.value)||0)})}),e.jsx(R,{})]})}),e.jsx(j,{control:u.control,name:"download_csv",render:({field:o})=>e.jsxs(f,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(_,{children:e.jsx("input",{type:"checkbox",checked:o.value,onChange:c=>o.onChange(c.target.checked)})}),e.jsx(v,{children:r("code.form.download_csv")})]})}),e.jsxs(Me,{children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>t(!1),children:r("common.cancel")}),e.jsx(D,{type:"submit",disabled:a,children:r(a?"code.form.submit.generating":"code.form.submit.generate")})]})]})})]})})}function Uh({table:s,refetch:n}){const{t}=M("giftCard"),[r,a]=m.useState(!1),i=s.getState().columnFilters.length>0,l=Object.entries(t("code.status",{returnObjects:!0})).map(([d,u])=>({value:d,label:u}));return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(k,{placeholder:t("common.search"),value:s.getColumn("code")?.getFilterValue()??"",onChange:d=>s.getColumn("code")?.setFilterValue(d.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("status")&&e.jsx(Ea,{column:s.getColumn("status"),title:t("code.table.columns.status"),options:l}),i&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("common.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>a(!0),children:[e.jsx(Ll,{className:"h-4 w-4 mr-2"}),t("code.form.generate")]}),e.jsxs(D,{variant:"outline",size:"sm",disabled:!0,children:[e.jsx(Zt,{className:"h-4 w-4 mr-2"}),t("common.export")]}),e.jsx(Ni,{table:s})]}),e.jsx(qh,{refetch:n,open:r,onOpenChange:a})]})}const Hh=0,Kh=1,Bh=2,hn=3,Gh=s=>{const{t:n}=M("giftCard");return[{accessorKey:"id",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.id")}),cell:({row:t})=>e.jsx(U,{children:t.original.id})},{accessorKey:"code",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.code")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{variant:"secondary",children:t.original.code}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>sa(t.original.code).then(()=>{$.success(n("common:copy.success"))}),children:e.jsx(kl,{className:"h-4 w-4"})})]})},{accessorKey:"template_name",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.template_name")})},{accessorKey:"status",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.status")}),cell:({row:t})=>{const r=t.original.status,a=r===hn,i=r===Hh||r===hn;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{variant:r===Kh?"secondary":r===Bh||r===hn?"destructive":"default",children:n(`code.status.${r}`)}),i&&e.jsx(X,{checked:!a,onCheckedChange:async l=>{const d=l?"enable":"disable";try{const{data:u}=await Ds.toggleCode({id:t.original.id,action:d});u?($.success(n("messages.codeStatusUpdated")),s()):$.error(n("messages.updateCodeStatusFailed"))}catch{$.error(n("messages.updateCodeStatusFailed"))}}})]})}},{accessorKey:"expires_at",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.expires_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(t.original.expires_at)})},{accessorKey:"usage_count",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.usage_count")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.original.usage_count})},{accessorKey:"max_usage",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.max_usage")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.original.max_usage})},{accessorKey:"created_at",header:({column:t})=>e.jsx(O,{column:t,title:n("code.table.columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(t.original.created_at)})}]};function Wh(){const[s,n]=m.useState({}),[t,r]=m.useState({}),[a,i]=m.useState([]),[l,d]=m.useState([]),[u,x]=m.useState({pageIndex:0,pageSize:20}),{refetch:o,data:c}=ae({queryKey:["giftCardCodes",u,a,l],queryFn:()=>Ds.getCodes({per_page:u.pageSize,page:u.pageIndex+1,filter:a,sort:l})}),b=Be({data:c?.data??[],columns:Gh(o),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:a,pagination:u},pageCount:Math.ceil((c?.total??0)/u.pageSize),rowCount:c?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:d,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:x,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs(),getFacetedRowModel:Fs(),getFacetedUniqueValues:Ps(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(ts,{table:b,toolbar:e.jsx(Uh,{table:b,refetch:o})})})}const Yh=()=>{const{t:s}=M("giftCard");return[{accessorKey:"id",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.id")}),cell:({row:n})=>e.jsx(U,{children:n.original.id})},{accessorKey:"code",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.code")}),cell:({row:n})=>e.jsx(U,{variant:"secondary",children:n.original.code})},{accessorKey:"user_email",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.user_email")})},{accessorKey:"template_name",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.template_name")})},{accessorKey:"created_at",header:({column:n})=>e.jsx(O,{column:n,title:s("usage.table.columns.created_at")}),cell:({row:n})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:oe(n.original.created_at)})}]};function Jh(){const[s,n]=m.useState([]),[t,r]=m.useState([]),[a,i]=m.useState({pageIndex:0,pageSize:20}),{data:l}=ae({queryKey:["giftCardUsages",a,s,t],queryFn:()=>Ds.getUsages({per_page:a.pageSize,page:a.pageIndex+1,filter:s,sort:t})}),d=Be({data:l?.data??[],columns:Yh(),state:{sorting:t,columnFilters:s,pagination:a},pageCount:Math.ceil((l?.total??0)/a.pageSize),rowCount:l?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,onSortingChange:r,onColumnFiltersChange:n,onPaginationChange:i,getCoreRowModel:Ge(),getFilteredRowModel:hs(),getPaginationRowModel:Ze(),getSortedRowModel:gs()});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(k,{placeholder:"搜索用户邮箱...",value:d.getColumn("user_email")?.getFilterValue()??"",onChange:u=>d.getColumn("user_email")?.setFilterValue(u.target.value),className:"h-8 w-[150px] lg:w-[250px]"})}),e.jsx(ts,{table:d})]})}function Qh(){const{t:s}=M("giftCard"),{data:n,isLoading:t}=ae({queryKey:["giftCardStats"],queryFn:()=>Ds.getStatistics({})}),r=n?.data?.total_stats,a=[{title:s("statistics.total.templates_count"),value:r?.templates_count},{title:s("statistics.total.active_templates_count"),value:r?.active_templates_count},{title:s("statistics.total.codes_count"),value:r?.codes_count},{title:s("statistics.total.used_codes_count"),value:r?.used_codes_count}];return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:a.map((i,l)=>e.jsxs(ke,{children:[e.jsx(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:e.jsx(Le,{className:"text-sm font-medium",children:i.title})}),e.jsx(Pe,{children:t?e.jsx(je,{className:"h-8 w-1/2"}):e.jsx("div",{className:"text-2xl font-bold",children:i.value??0})})]},l))})}function Xh(){const{t:s}=M("giftCard"),[n,t]=m.useState("templates");return e.jsxs(qe,{children:[e.jsxs(Ue,{children:[e.jsx(cs,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(es,{}),e.jsx(ss,{})]})]}),e.jsxs(We,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-6 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsxs(gt,{value:n,onValueChange:t,className:"flex-1",children:[e.jsxs(at,{className:"grid w-full grid-cols-4",children:[e.jsx($e,{value:"templates",children:s("tabs.templates")}),e.jsx($e,{value:"codes",children:s("tabs.codes")}),e.jsx($e,{value:"usages",children:s("tabs.usages")}),e.jsx($e,{value:"statistics",children:s("tabs.statistics")})]}),e.jsx(ms,{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($h,{})]})}),e.jsx(ms,{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(Wh,{})]})}),e.jsx(ms,{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(Jh,{})]})}),e.jsx(ms,{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(Qh,{})]})})]})]})]})}const Zh=Object.freeze(Object.defineProperty({__proto__:null,default:Xh},Symbol.toStringTag,{value:"Module"})),eg=1,sg=1e6;let gn=0;function tg(){return gn=(gn+1)%Number.MAX_SAFE_INTEGER,gn.toString()}const pn=new Map,wr=s=>{if(pn.has(s))return;const n=setTimeout(()=>{pn.delete(s),Qt({type:"REMOVE_TOAST",toastId:s})},sg);pn.set(s,n)},ag=(s,n)=>{switch(n.type){case"ADD_TOAST":return{...s,toasts:[n.toast,...s.toasts].slice(0,eg)};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?wr(t):s.toasts.forEach(r=>{wr(r.id)}),{...s,toasts:s.toasts.map(r=>r.id===t||t===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return n.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==n.toastId)}}},_a=[];let Na={toasts:[]};function Qt(s){Na=ag(Na,s),_a.forEach(n=>{n(Na)})}function ng({...s}){const n=tg(),t=a=>Qt({type:"UPDATE_TOAST",toast:{...a,id:n}}),r=()=>Qt({type:"DISMISS_TOAST",toastId:n});return Qt({type:"ADD_TOAST",toast:{...s,id:n,open:!0,onOpenChange:a=>{a||r()}}}),{id:n,dismiss:r,update:t}}function wi(){const[s,n]=m.useState(Na);return m.useEffect(()=>(_a.push(n),()=>{const t=_a.indexOf(n);t>-1&&_a.splice(t,1)}),[s]),{...s,toast:ng,dismiss:t=>Qt({type:"DISMISS_TOAST",toastId:t})}}function rg({open:s,onOpenChange:n,table:t}){const{t:r}=M("user"),{toast:a}=wi(),[i,l]=m.useState(!1),[d,u]=m.useState(""),[x,o]=m.useState(""),c=async()=>{if(!d||!x){a({title:r("messages.error"),description:r("messages.send_mail.required_fields"),variant:"destructive"});return}try{l(!0),await Os.sendMail({subject:d,content:x,filter:t.getState().columnFilters,sort:t.getState().sorting[0]?.id,sort_type:t.getState().sorting[0]?.desc?"DESC":"ASC"}),a({title:r("messages.success"),description:r("messages.send_mail.success")}),n(!1),u(""),o("")}catch{a({title:r("messages.error"),description:r("messages.send_mail.failed"),variant:"destructive"})}finally{l(!1)}};return e.jsx(de,{open:s,onOpenChange:n,children:e.jsxs(ce,{className:"sm:max-w-[500px]",children:[e.jsxs(he,{children:[e.jsx(me,{children:r("send_mail.title")}),e.jsx(Ae,{children:r("send_mail.description")})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"subject",className:"text-right",children:r("send_mail.subject")}),e.jsx(k,{id:"subject",value:d,onChange:b=>u(b.target.value),className:"col-span-3"})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"content",className:"text-right",children:r("send_mail.content")}),e.jsx(Rs,{id:"content",value:x,onChange:b=>o(b.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(Me,{children:e.jsx(G,{type:"submit",onClick:c,disabled:i,children:r(i?"send_mail.sending":"send_mail.send")})})]})})}function lg({trigger:s}){const{t:n}=M("user"),[t,r]=m.useState(!1),[a,i]=m.useState(30),{data:l,isLoading:d}=ae({queryKey:["trafficResetStats",a],queryFn:()=>aa.getStats({days:a}),enabled:t}),u=[{title:n("traffic_reset.stats.total_resets"),value:l?.data?.total_resets||0,icon:Gt,color:"text-blue-600",bgColor:"bg-blue-100"},{title:n("traffic_reset.stats.auto_resets"),value:l?.data?.auto_resets||0,icon:ka,color:"text-green-600",bgColor:"bg-green-100"},{title:n("traffic_reset.stats.manual_resets"),value:l?.data?.manual_resets||0,icon:ws,color:"text-orange-600",bgColor:"bg-orange-100"},{title:n("traffic_reset.stats.cron_resets"),value:l?.data?.cron_resets||0,icon:On,color:"text-purple-600",bgColor:"bg-purple-100"}],x=[{value:7,label:n("traffic_reset.stats.days_options.week")},{value:30,label:n("traffic_reset.stats.days_options.month")},{value:90,label:n("traffic_reset.stats.days_options.quarter")},{value:365,label:n("traffic_reset.stats.days_options.year")}];return e.jsxs(de,{open:t,onOpenChange:r,children:[e.jsx(ps,{asChild:!0,children:s}),e.jsxs(ce,{className:"max-w-2xl",children:[e.jsxs(he,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(Vn,{className:"h-5 w-5"}),n("traffic_reset.stats.title")]}),e.jsx(Ae,{children:n("traffic_reset.stats.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-medium",children:n("traffic_reset.stats.time_range")}),e.jsxs(J,{value:a.toString(),onValueChange:o=>i(Number(o)),children:[e.jsx(W,{className:"w-[180px]",children:e.jsx(Q,{})}),e.jsx(Y,{children:x.map(o=>e.jsx(A,{value:o.value.toString(),children:o.label},o.value))})]})]}),d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Xt,{className:"h-6 w-6 animate-spin"})}):e.jsx("div",{className:"grid grid-cols-2 gap-4",children:u.map((o,c)=>e.jsxs(ke,{className:"relative overflow-hidden",children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Le,{className:"text-sm font-medium text-muted-foreground",children:o.title}),e.jsx("div",{className:`rounded-lg p-2 ${o.bgColor}`,children:e.jsx(o.icon,{className:`h-4 w-4 ${o.color}`})})]}),e.jsxs(Pe,{children:[e.jsx("div",{className:"text-2xl font-bold",children:o.value.toLocaleString()}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:n("traffic_reset.stats.in_period",{days:a})})]})]},c))}),l?.data&&e.jsxs(ke,{children:[e.jsxs(Fe,{children:[e.jsx(Le,{className:"text-lg",children:n("traffic_reset.stats.breakdown")}),e.jsx(Hs,{children:n("traffic_reset.stats.breakdown_description")})]}),e.jsx(Pe,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:n("traffic_reset.stats.auto_percentage")}),e.jsxs(U,{variant:"outline",className:"border-green-200 bg-green-50 text-green-700",children:[l.data.total_resets>0?(l.data.auto_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:n("traffic_reset.stats.manual_percentage")}),e.jsxs(U,{variant:"outline",className:"border-orange-200 bg-orange-50 text-orange-700",children:[l.data.total_resets>0?(l.data.manual_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:n("traffic_reset.stats.cron_percentage")}),e.jsxs(U,{variant:"outline",className:"border-purple-200 bg-purple-50 text-purple-700",children:[l.data.total_resets>0?(l.data.cron_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]})]})})]})]})]})]})}const ig=h.object({email_prefix:h.string().optional(),email_suffix:h.string().min(1),password:h.string().optional(),expired_at:h.number().optional().nullable(),plan_id:h.number().nullable(),generate_count:h.number().optional().nullable(),download_csv:h.boolean().optional()}).refine(s=>s.generate_count===null?s.email_prefix!==void 0&&s.email_prefix!=="":!0,{message:"Email prefix is required when generate_count is null",path:["email_prefix"]}),og={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0,download_csv:!1};function cg({refetch:s}){const{t:n}=M("user"),[t,r]=m.useState(!1),a=we({resolver:Te(ig),defaultValues:og,mode:"onChange"}),[i,l]=m.useState([]);return m.useEffect(()=>{t&&ys.getList().then(({data:d})=>{d&&l(d)})},[t]),e.jsxs(de,{open:t,onOpenChange:r,children:[e.jsx(ps,{asChild:!0,children:e.jsxs(G,{size:"sm",variant:"outline",className:"gap-0 space-x-2",children:[e.jsx(Ke,{icon:"ion:add"}),e.jsx("div",{children:n("generate.button")})]})}),e.jsxs(ce,{className:"sm:max-w-[425px]",children:[e.jsxs(he,{children:[e.jsx(me,{children:n("generate.title")}),e.jsx(Ae,{})]}),e.jsxs(De,{...a,children:[e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!a.watch("generate_count")&&e.jsx(j,{control:a.control,name:"email_prefix",render:({field:d})=>e.jsx(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(j,{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(j,{control:a.control,name:"password",render:({field:d})=>e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.password")}),e.jsx(k,{placeholder:n("generate.form.password_placeholder"),...d}),e.jsx(R,{})]})}),e.jsx(j,{control:a.control,name:"expired_at",render:({field:d})=>e.jsxs(f,{className:"flex flex-col",children:[e.jsx(v,{children:n("generate.form.expire_time")}),e.jsxs(ls,{children:[e.jsx(is,{asChild:!0,children:e.jsx(_,{children:e.jsxs(G,{variant:"outline",className:N("w-full pl-3 text-left font-normal",!d.value&&"text-muted-foreground"),children:[d.value?oe(d.value):e.jsx("span",{children:n("generate.form.expire_time_placeholder")}),e.jsx(ws,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(Xe,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(Nd,{asChild:!0,children:e.jsx(G,{variant:"outline",className:"w-full",onClick:()=>{d.onChange(null)},children:n("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(Cs,{mode:"single",selected:d.value?new Date(d.value*1e3):void 0,onSelect:u=>{u&&d.onChange(u?.getTime()/1e3)}})})]})]})]})}),e.jsx(j,{control:a.control,name:"plan_id",render:({field:d})=>e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.subscription")}),e.jsx(_,{children:e.jsxs(J,{value:d.value?d.value.toString():"null",onValueChange:u=>d.onChange(u==="null"?null:parseInt(u)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("generate.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx(A,{value:"null",children:n("generate.form.subscription_none")}),i.map(u=>e.jsx(A,{value:u.id.toString(),children:u.name},u.id))]})]})})]})}),!a.watch("email_prefix")&&e.jsx(j,{control:a.control,name:"generate_count",render:({field:d})=>e.jsxs(f,{children:[e.jsx(v,{children:n("generate.form.generate_count")}),e.jsx(k,{type:"number",placeholder:n("generate.form.generate_count_placeholder"),value:d.value||"",onChange:u=>d.onChange(u.target.value?parseInt(u.target.value):null)})]})}),a.watch("generate_count")&&e.jsx(j,{control:a.control,name:"download_csv",render:({field:d})=>e.jsxs(f,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(_,{children:e.jsx(Bn,{checked:d.value,onCheckedChange:d.onChange})}),e.jsx(v,{children:n("generate.form.download_csv")})]})})]}),e.jsxs(Me,{children:[e.jsx(G,{variant:"outline",onClick:()=>r(!1),children:n("generate.form.cancel")}),e.jsx(G,{onClick:()=>a.handleSubmit(async d=>{if(d.download_csv){const u=await Os.generate(d);if(u&&u instanceof Blob){const x=window.URL.createObjectURL(u),o=document.createElement("a");o.href=x,o.download=`users_${new Date().getTime()}.csv`,document.body.appendChild(o),o.click(),o.remove(),window.URL.revokeObjectURL(x),$.success(n("generate.form.success")),a.reset(),s(),r(!1)}}else{const{data:u}=await Os.generate(d);u&&($.success(n("generate.form.success")),a.reset(),s(),r(!1))}})(),children:n("generate.form.submit")})]})]})]})}const Gn=Lr,Ci=Er,dg=Vr,Si=m.forwardRef(({className:s,...n},t)=>e.jsx(Va,{className:N("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:t}));Si.displayName=Va.displayName;const mg=xt("fixed overflow-y-scroll z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-md",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-md"}},defaultVariants:{side:"right"}}),en=m.forwardRef(({side:s="right",className:n,children:t,...r},a)=>e.jsxs(dg,{children:[e.jsx(Si,{}),e.jsxs(Ia,{ref:a,className:N(mg({side:s}),n),...r,children:[e.jsxs(Pn,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[e.jsx(os,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),t]})]}));en.displayName=Ia.displayName;const sn=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col space-y-2 text-center sm:text-left",s),...n});sn.displayName="SheetHeader";const ki=({className:s,...n})=>e.jsx("div",{className:N("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});ki.displayName="SheetFooter";const tn=m.forwardRef(({className:s,...n},t)=>e.jsx(Ma,{ref:t,className:N("text-lg font-semibold text-foreground",s),...n}));tn.displayName=Ma.displayName;const an=m.forwardRef(({className:s,...n},t)=>e.jsx(Oa,{ref:t,className:N("text-sm text-muted-foreground",s),...n}));an.displayName=Oa.displayName;function ug({table:s,refetch:n,permissionGroups:t=[],subscriptionPlans:r=[]}){const{t:a}=M("user"),{toast:i}=wi(),l=s.getState().columnFilters.length>0,[d,u]=m.useState([]),[x,o]=m.useState(!1),[c,b]=m.useState(!1),[F,S]=m.useState(!1),[w,T]=m.useState(!1),y=async()=>{try{const se=await Os.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),ne=se;console.log(se);const H=new Blob([ne],{type:"text/csv;charset=utf-8;"}),ee=window.URL.createObjectURL(H),fe=document.createElement("a");fe.href=ee,fe.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(fe),fe.click(),fe.remove(),window.URL.revokeObjectURL(ee),i({title:a("messages.success"),description:a("messages.export.success")})}catch{i({title:a("messages.error"),description:a("messages.export.failed"),variant:"destructive"})}},L=async()=>{try{T(!0),await Os.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),i({title:a("messages.success"),description:a("messages.batch_ban.success")}),n()}catch{i({title:a("messages.error"),description:a("messages.batch_ban.failed"),variant:"destructive"})}finally{T(!1),S(!1)}},C=[{label:a("filter.fields.email"),value:"email",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.id"),value:"id",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.plan_id"),value:"plan_id",type:"select",operators:[{label:a("filter.operators.eq"),value:"eq"}],useOptions:!0},{label:a("filter.fields.transfer_enable"),value:"transfer_enable",type:"number",unit:"GB",operators:[{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.total_used"),value:"total_used",type:"number",unit:"GB",operators:[{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.online_count"),value:"online_count",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"},{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.lt"),value:"lt"}]},{label:a("filter.fields.expired_at"),value:"expired_at",type:"date",operators:[{label:a("filter.operators.lt"),value:"lt"},{label:a("filter.operators.gt"),value:"gt"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.uuid"),value:"uuid",type:"text",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.token"),value:"token",type:"text",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.banned"),value:"banned",type:"select",operators:[{label:a("filter.operators.eq"),value:"eq"}],options:[{label:a("filter.status.normal"),value:"0"},{label:a("filter.status.banned"),value:"1"}]},{label:a("filter.fields.remark"),value:"remarks",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.inviter_email"),value:"invite_user.email",type:"text",operators:[{label:a("filter.operators.contains"),value:"contains"},{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.invite_user_id"),value:"invite_user_id",type:"number",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.is_admin"),value:"is_admin",type:"boolean",operators:[{label:a("filter.operators.eq"),value:"eq"}]},{label:a("filter.fields.is_staff"),value:"is_staff",type:"boolean",operators:[{label:a("filter.operators.eq"),value:"eq"}]}],g=se=>se*1024*1024*1024,p=se=>se/(1024*1024*1024),V=()=>{u([...d,{field:"",operator:"",value:""}])},E=se=>{u(d.filter((ne,H)=>H!==se))},P=(se,ne,H)=>{const ee=[...d];if(ee[se]={...ee[se],[ne]:H},ne==="field"){const fe=C.find(fs=>fs.value===H);fe&&(ee[se].operator=fe.operators[0].value,ee[se].value=fe.type==="boolean"?!1:"")}u(ee)},K=(se,ne)=>{const H=C.find(ee=>ee.value===se.field);if(!H)return null;switch(H.type){case"text":return e.jsx(k,{placeholder:a("filter.sheet.value"),value:se.value,onChange:ee=>P(ne,"value",ee.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(k,{type:"number",placeholder:a("filter.sheet.value_number",{unit:H.unit}),value:H.unit==="GB"?p(se.value||0):se.value,onChange:ee=>{const fe=Number(ee.target.value);P(ne,"value",H.unit==="GB"?g(fe):fe)}}),H.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:H.unit})]});case"date":return e.jsx(Cs,{mode:"single",selected:se.value,onSelect:ee=>P(ne,"value",ee),className:"flex flex-1 justify-center rounded-md border"});case"select":return e.jsxs(J,{value:se.value,onValueChange:ee=>P(ne,"value",ee),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("filter.sheet.value")})}),e.jsx(Y,{children:H.useOptions?r.map(ee=>e.jsx(A,{value:ee.value.toString(),children:ee.label},ee.value)):H.options?.map(ee=>e.jsx(A,{value:ee.value.toString(),children:ee.label},ee.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(X,{checked:se.value,onCheckedChange:ee=>P(ne,"value",ee)}),e.jsx(Je,{children:se.value?a("filter.boolean.true"):a("filter.boolean.false")})]});default:return null}},Z=()=>{const se=d.filter(ne=>ne.field&&ne.operator&&ne.value!=="").map(ne=>{const H=C.find(fe=>fe.value===ne.field);let ee=ne.value;return ne.operator==="contains"?{id:ne.field,value:ee}:(H?.type==="date"&&ee instanceof Date&&(ee=Math.floor(ee.getTime()/1e3)),H?.type==="boolean"&&(ee=ee?1:0),{id:ne.field,value:`${ne.operator}:${ee}`})});s.setColumnFilters(se),o(!1)};return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-2",children:[e.jsx(cg,{refetch:n}),e.jsx(k,{placeholder:a("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:se=>s.getColumn("email")?.setFilterValue(se.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(Gn,{open:x,onOpenChange:o,children:[e.jsx(Ci,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Rl,{className:"mr-2 h-4 w-4"}),a("filter.advanced"),d.length>0&&e.jsx(U,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:d.length})]})}),e.jsxs(en,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(sn,{children:[e.jsx(tn,{children:a("filter.sheet.title")}),e.jsx(an,{children:a("filter.sheet.description")})]}),e.jsxs("div",{className:"mt-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:a("filter.sheet.conditions")}),e.jsx(D,{variant:"outline",size:"sm",onClick:V,children:a("filter.sheet.add")})]}),e.jsx(ut,{className:"h-[calc(100vh-280px)] ",children:e.jsx("div",{className:"space-y-4",children:d.map((se,ne)=>e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Je,{children:a("filter.sheet.condition",{number:ne+1})}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>E(ne),children:e.jsx(os,{className:"h-4 w-4"})})]}),e.jsxs(J,{value:se.field,onValueChange:H=>P(ne,"field",H),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("filter.sheet.field")})}),e.jsx(Y,{children:e.jsx(js,{children:C.map(H=>e.jsx(A,{value:H.value,className:"cursor-pointer",children:H.label},H.value))})})]}),se.field&&e.jsxs(J,{value:se.operator,onValueChange:H=>P(ne,"operator",H),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("filter.sheet.operator")})}),e.jsx(Y,{children:C.find(H=>H.value===se.field)?.operators.map(H=>e.jsx(A,{value:H.value,children:H.label},H.value))})]}),se.field&&se.operator&&K(se,ne)]},ne))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(D,{variant:"outline",onClick:()=>{u([]),o(!1)},children:a("filter.sheet.reset")}),e.jsx(D,{onClick:Z,children:a("filter.sheet.apply")})]})]})]})]}),l&&e.jsxs(D,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),u([])},className:"h-8 px-2 lg:px-3",children:[a("filter.sheet.reset"),e.jsx(os,{className:"ml-2 h-4 w-4"})]}),e.jsxs(zs,{modal:!1,children:[e.jsx(Ks,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:a("actions.title")})}),e.jsxs(Ms,{children:[e.jsx(Se,{onClick:()=>b(!0),children:a("actions.send_email")}),e.jsx(Se,{onClick:y,children:a("actions.export_csv")}),e.jsx(et,{}),e.jsx(Se,{asChild:!0,children:e.jsx(lg,{trigger:e.jsx("div",{className:"w-full cursor-pointer px-2 py-1.5 text-sm",children:a("actions.traffic_reset_stats")})})}),e.jsx(et,{}),e.jsx(Se,{onClick:()=>S(!0),className:"text-red-600 focus:text-red-600",children:a("actions.batch_ban")})]})]})]}),e.jsx(rg,{open:c,onOpenChange:b,table:s}),e.jsx(Hn,{open:F,onOpenChange:S,children:e.jsxs(Ka,{children:[e.jsxs(Ba,{children:[e.jsx(Wa,{children:a("actions.confirm_ban.title")}),e.jsx(Ya,{children:a(l?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(Ga,{children:[e.jsx(Qa,{disabled:w,children:a("actions.confirm_ban.cancel")}),e.jsx(Ja,{onClick:L,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 Ti=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"})}),Di=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"})}),xg=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"})}),hg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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:qd(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ti,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:ze(s.original.u/parseFloat(s.original.server_rate))})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Di,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:ze(s.original.d/parseFloat(s.original.server_rate))})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const n=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(U,{variant:"outline",className:"font-mono",children:[n,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const n=s.original.u+s.original.d;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:ze(n)})}}];function Fi({user_id:s,dialogTrigger:n}){const{t}=M(["traffic"]),[r,a]=m.useState(!1),[i,l]=m.useState({pageIndex:0,pageSize:20}),{data:d,isLoading:u}=ae({queryKey:["userStats",s,i,r],queryFn:()=>r?Os.getStats({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),x=Be({data:d?.data??[],columns:fn,pageCount:Math.ceil((d?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:Ge(),onPaginationChange:l});return e.jsxs(de,{open:r,onOpenChange:a,children:[e.jsx(ps,{asChild:!0,children:n}),e.jsxs(ce,{className:"sm:max-w-[700px]",children:[e.jsx(he,{children:e.jsx(me,{children:t("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs($n,{children:[e.jsx(An,{children:x.getHeaderGroups().map(o=>e.jsx(Js,{children:o.headers.map(c=>e.jsx(Un,{className:N("h-10 px-2 text-xs",c.id==="total"&&"text-right"),children:c.isPlaceholder?null:Ca(c.column.columnDef.header,c.getContext())},c.id))},o.id))}),e.jsx(qn,{children:u?Array.from({length:i.pageSize}).map((o,c)=>e.jsx(Js,{children:Array.from({length:fn.length}).map((b,F)=>e.jsx(Tt,{className:"p-2",children:e.jsx(je,{className:"h-6 w-full"})},F))},c)):x.getRowModel().rows?.length?x.getRowModel().rows.map(o=>e.jsx(Js,{"data-state":o.getIsSelected()&&"selected",className:"h-10",children:o.getVisibleCells().map(c=>e.jsx(Tt,{className:"px-2",children:Ca(c.column.columnDef.cell,c.getContext())},c.id))},o.id)):e.jsx(Js,{children:e.jsx(Tt,{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(J,{value:`${x.getState().pagination.pageSize}`,onValueChange:o=>{x.setPageSize(Number(o))},children:[e.jsx(W,{className:"h-8 w-[70px]",children:e.jsx(Q,{placeholder:x.getState().pagination.pageSize})}),e.jsx(Y,{side:"top",children:[10,20,30,40,50].map(o=>e.jsx(A,{value:`${o}`,children:o},o))})]}),e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.records")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"flex w-[100px] items-center justify-center text-sm",children:t("trafficRecord.page",{current:x.getState().pagination.pageIndex+1,total:x.getPageCount()})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>x.previousPage(),disabled:!x.getCanPreviousPage()||u,children:e.jsx(xg,{className:"h-4 w-4"})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>x.nextPage(),disabled:!x.getCanNextPage()||u,children:e.jsx(hg,{className:"h-4 w-4"})})]})]})]})]})]})]})}function gg({user:s,trigger:n,onSuccess:t}){const{t:r}=M("user"),[a,i]=m.useState(!1),[l,d]=m.useState(""),[u,x]=m.useState(!1),{data:o,isLoading:c}=ae({queryKey:["trafficResetHistory",s.id],queryFn:()=>aa.getUserHistory(s.id,{limit:10}),enabled:a}),b=async()=>{try{x(!0);const{data:w}=await aa.resetUser({user_id:s.id,reason:l.trim()||void 0});w&&($.success(r("traffic_reset.reset_success")),i(!1),d(""),t?.())}finally{x(!1)}},F=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(de,{open:a,onOpenChange:i,children:[e.jsx(ps,{asChild:!0,children:n}),e.jsxs(ce,{className:"max-h-[90vh] max-w-4xl overflow-hidden",children:[e.jsxs(he,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(Gt,{className:"h-5 w-5"}),r("traffic_reset.title")]}),e.jsx(Ae,{children:r("traffic_reset.description",{email:s.email})})]}),e.jsxs(gt,{defaultValue:"reset",className:"w-full",children:[e.jsxs(at,{className:"grid w-full grid-cols-2",children:[e.jsxs($e,{value:"reset",className:"flex items-center gap-2",children:[e.jsx(Gt,{className:"h-4 w-4"}),r("traffic_reset.tabs.reset")]}),e.jsxs($e,{value:"history",className:"flex items-center gap-2",children:[e.jsx(or,{className:"h-4 w-4"}),r("traffic_reset.tabs.history")]})]}),e.jsxs(ms,{value:"reset",className:"space-y-4",children:[e.jsxs(ke,{children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs(Le,{className:"flex items-center gap-2 text-lg",children:[e.jsx(El,{className:"h-5 w-5"}),r("traffic_reset.user_info")]})}),e.jsx(Pe,{className:"space-y-3",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.email")}),e.jsx("p",{className:"font-medium",children:s.email})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.used_traffic")}),e.jsx("p",{className:"font-medium",children:ze(s.total_used)})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.total_traffic")}),e.jsx("p",{className:"font-medium",children:ze(s.transfer_enable)})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("columns.expire_time")}),e.jsx("p",{className:"font-medium",children:s.expired_at?oe(s.expired_at):r("columns.expire_status.permanent")})]})]})})]}),e.jsxs(ke,{className:"border-amber-200 bg-amber-50",children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs(Le,{className:"flex items-center gap-2 text-lg text-amber-800",children:[e.jsx(Bt,{className:"h-5 w-5"}),r("traffic_reset.warning.title")]})}),e.jsx(Pe,{children:e.jsxs("ul",{className:"space-y-2 text-sm text-amber-700",children:[e.jsxs("li",{children:["• ",r("traffic_reset.warning.irreversible")]}),e.jsxs("li",{children:["• ",r("traffic_reset.warning.reset_to_zero")]}),e.jsxs("li",{children:["• ",r("traffic_reset.warning.logged")]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Je,{htmlFor:"reason",children:r("traffic_reset.reason.label")}),e.jsx(Rs,{id:"reason",placeholder:r("traffic_reset.reason.placeholder"),value:l,onChange:w=>d(w.target.value),className:"min-h-[80px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("traffic_reset.reason.optional")})]}),e.jsxs(Me,{children:[e.jsx(G,{variant:"outline",onClick:()=>i(!1),children:r("common:cancel")}),e.jsx(G,{onClick:b,disabled:u,className:"bg-destructive hover:bg-destructive/90",children:u?e.jsxs(e.Fragment,{children:[e.jsx(Xt,{className:"mr-2 h-4 w-4 animate-spin"}),r("traffic_reset.resetting")]}):e.jsxs(e.Fragment,{children:[e.jsx(Gt,{className:"mr-2 h-4 w-4"}),r("traffic_reset.confirm_reset")]})})]})]}),e.jsx(ms,{value:"history",className:"space-y-4",children:c?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Xt,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[o?.data?.user&&e.jsxs(ke,{children:[e.jsx(Fe,{className:"pb-3",children:e.jsx(Le,{className:"text-lg",children:r("traffic_reset.history.summary")})}),e.jsx(Pe,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.reset_count")}),e.jsx("p",{className:"font-medium",children:o.data.user.reset_count})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.last_reset")}),e.jsx("p",{className:"font-medium",children:o.data.user.last_reset_at?oe(o.data.user.last_reset_at):r("traffic_reset.history.never")})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.next_reset")}),e.jsx("p",{className:"font-medium",children:o.data.user.next_reset_at?oe(o.data.user.next_reset_at):r("traffic_reset.history.no_schedule")})]})]})})]}),e.jsxs(ke,{children:[e.jsxs(Fe,{className:"pb-3",children:[e.jsx(Le,{className:"text-lg",children:r("traffic_reset.history.records")}),e.jsx(Hs,{children:r("traffic_reset.history.recent_records")})]}),e.jsx(Pe,{children:e.jsx(ut,{className:"h-[300px]",children:o?.data?.history?.length?e.jsx("div",{className:"space-y-3",children:o.data.history.map((w,T)=>e.jsxs("div",{children:[e.jsx("div",{className:"flex items-start justify-between rounded-lg border bg-card p-3",children:e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:F(w.reset_type),children:w.reset_type_name}),e.jsx(U,{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(Je,{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(On,{className:"h-3 w-3"}),r("traffic_reset.history.reset_time")]}),e.jsx("p",{className:"font-medium",children:oe(w.reset_time)})]}),e.jsxs("div",{children:[e.jsx(Je,{className:"text-muted-foreground",children:r("traffic_reset.history.traffic_cleared")}),e.jsx("p",{className:"font-medium text-destructive",children:w.old_traffic.formatted})]})]})]})}),Te.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"})}),jg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 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"})}),vg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),Cr=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"})}),bg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),yg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),_g=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),Ng=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),wg=(s,n,t,r)=>{const{t:a}=M("user");return[{accessorKey:"is_admin",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l)),size:0},{accessorKey:"is_staff",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,d)=>d.includes(i.getValue(l)),size:0},{accessorKey:"id",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.id")}),cell:({row:i})=>e.jsx(U,{variant:"outline",children:i.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:i})=>e.jsx(O,{column:i,title:a("columns.email")}),cell:({row:i})=>{const l=i.original.t||0,d=Date.now()/1e3-l<120,u=Math.floor(Date.now()/1e3-l);let x=d?a("columns.online_status.online"):l===0?a("columns.online_status.never"):a("columns.online_status.last_online",{time:oe(l)});if(!d&&l!==0){const o=Math.floor(u/60),c=Math.floor(o/60),b=Math.floor(c/24);b>0?x+=` `+a("columns.online_status.offline_duration.days",{count:b}):c>0?x+=` `+a("columns.online_status.offline_duration.hours",{count:c}):o>0?x+=` `+a("columns.online_status.offline_duration.minutes",{count:o}):x+=` diff --git a/public/assets/admin/locales/en-US.js b/public/assets/admin/locales/en-US.js index bd027a3..b1a8b26 100644 --- a/public/assets/admin/locales/en-US.js +++ b/public/assets/admin/locales/en-US.js @@ -1277,9 +1277,9 @@ window.XBOARD_TRANSLATIONS['en-US'] = { "placeholder": "Enter the reward amount in Yuan" }, "transfer_enable": { - "label": "Reward Traffic (in bytes)", + "label": "Reward Traffic (in GB)", "short_label": "Traffic", - "placeholder": "Enter the reward traffic in bytes" + "placeholder": "Enter the reward traffic in GB" }, "expire_days": { "label": "Extend Validity (in days)", diff --git a/public/assets/admin/locales/zh-CN.js b/public/assets/admin/locales/zh-CN.js index ab414c2..43cef3d 100644 --- a/public/assets/admin/locales/zh-CN.js +++ b/public/assets/admin/locales/zh-CN.js @@ -1281,9 +1281,9 @@ window.XBOARD_TRANSLATIONS['zh-CN'] = { "placeholder": "请输入奖励的金额(元)" }, "transfer_enable": { - "label": "奖励流量 (字节)", + "label": "奖励流量 (GB)", "short_label": "流量", - "placeholder": "请输入奖励的流量(字节)" + "placeholder": "请输入奖励的流量(GB)" }, "expire_days": { "label": "延长有效期 (天)",