diff --git a/public/assets/admin/assets/index.js b/public/assets/admin/assets/index.js index 8f4a937..4e13e7e 100644 --- a/public/assets/admin/assets/index.js +++ b/public/assets/admin/assets/index.js @@ -14,7 +14,7 @@ import{r as i,j as e,t as tl,c as al,I as oa,a as ys,S as Ut,u as Ze,b as gt,d a ## 注意事项 - 禁止滥用 - 遵守当地法律法规 -- 支持随时更换套餐`)},children:"使用模板"})}),e.jsx(te,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:"点击使用预设的套餐描述模板"})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${T?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(v,{children:e.jsx(kn,{style:{height:"400px"},value:D.value||"",renderHTML:_=>m.render(_),onChange:({text:_})=>D.onChange(_),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:"在这里编写套餐描述...",className:"rounded-md border"})})}),T&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"预览"}),e.jsx("div",{className:"prose prose-sm dark:prose-invert h-[400px] max-w-none overflow-y-auto rounded-md border p-4",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:m.render(D.value||"")}})})]})]}),e.jsx(P,{className:"text-xs",children:"支持 Markdown 格式,可以使用标题、列表、粗体、斜体等样式来美化描述内容"}),e.jsx(S,{})]})}})]}),e.jsx(Fe,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:a&&e.jsx(h,{control:d.control,name:"force_update",render:({field:D})=>e.jsxs(u,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(v,{children:e.jsx(Dr,{checked:D.value,onCheckedChange:D.onChange})}),e.jsx("div",{className:"",children:e.jsx(g,{className:"text-sm",children:"强制更新到用户"})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{type:"button",variant:"outline",onClick:y,children:"取消"}),e.jsx(k,{type:"submit",disabled:l,onClick:()=>{d.handleSubmit(async D=>{c(!0),(await Hc(D)).data&&(V.success(a?"套餐更新成功":"套餐添加成功"),y(),r()),c(!1)})()},children:l?"提交中...":"提交"})]})]})})]})]})})}function Em(){const[s,t]=i.useState({}),[a,n]=i.useState({"drag-handle":!1}),[r,l]=i.useState([]),[c,d]=i.useState([]),[m,w]=i.useState(!1),[j,b]=i.useState({pageSize:10,pageIndex:0}),[x,y]=i.useState([]),{refetch:D}=K({queryKey:["planList"],queryFn:async()=>{const{data:N}=await zs();return y(N),N}});i.useEffect(()=>{n({"drag-handle":m}),b({pageSize:m?99999:10,pageIndex:0})},[m]);const T=(N,R)=>{m&&(N.dataTransfer.setData("text/plain",R.toString()),N.currentTarget.classList.add("opacity-50"))},p=(N,R)=>{if(!m)return;N.preventDefault(),N.currentTarget.classList.remove("bg-muted");const W=parseInt(N.dataTransfer.getData("text/plain"));if(W===R)return;const L=[...x],[ae]=L.splice(W,1);L.splice(R,0,ae),y(L)},_=async()=>{if(!m){w(!0);return}try{const N=x?.map(R=>R.id);await qc(N),V.success("排序保存成功"),w(!1),D()}catch{V.error("排序保存失败"),w(!1)}},z=Re({data:x||[],columns:Vm(D),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:j},enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:d,onColumnFiltersChange:l,onColumnVisibilityChange:n,getCoreRowModel:Me(),getFilteredRowModel:$e(),getPaginationRowModel:Ae(),getSortedRowModel:He(),getFacetedRowModel:es(),getFacetedUniqueValues:ss(),initialState:{columnPinning:{right:["actions"]}},pageCount:m?1:void 0});return e.jsx(Fm,{refreshData:D,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(qe,{table:z,toolbar:N=>e.jsx(Im,{table:N,refetch:D,saveOrder:_,isSortMode:m}),draggable:m,onDragStart:T,onDragEnd:N=>N.currentTarget.classList.remove("opacity-50"),onDragOver:N=>{N.preventDefault(),N.currentTarget.classList.add("bg-muted")},onDragLeave:N=>N.currentTarget.classList.remove("bg-muted"),onDrop:p,showPagination:!m}),e.jsx(zm,{})]})})}function Om(){return e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsx(Ce,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Se,{}),e.jsx(ke,{})]})]}),e.jsxs(Ne,{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:"订阅管理"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"在这里可以配置订阅计划,包括添加、删除、编辑等操作。"})]})}),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(Em,{})})]})]})}const Lm=Object.freeze(Object.defineProperty({__proto__:null,default:Om},Symbol.toStringTag,{value:"Module"})),Pr=[{value:ie.PENDING,label:ks[ie.PENDING],icon:so,color:Hs[ie.PENDING]},{value:ie.PROCESSING,label:ks[ie.PROCESSING],icon:Pn,color:Hs[ie.PROCESSING]},{value:ie.COMPLETED,label:ks[ie.COMPLETED],icon:Lt,color:Hs[ie.COMPLETED]},{value:ie.CANCELLED,label:ks[ie.CANCELLED],icon:Fn,color:Hs[ie.CANCELLED]},{value:ie.DISCOUNTED,label:ks[ie.DISCOUNTED],icon:Lt,color:Hs[ie.DISCOUNTED]}],Fr=[{value:xe.PENDING,label:at[xe.PENDING],icon:to,color:nt[xe.PENDING]},{value:xe.PROCESSING,label:at[xe.PROCESSING],icon:Pn,color:nt[xe.PROCESSING]},{value:xe.VALID,label:at[xe.VALID],icon:Lt,color:nt[xe.VALID]},{value:xe.INVALID,label:at[xe.INVALID],icon:Fn,color:nt[xe.INVALID]}];function Da({column:s,title:t,options:a}){const n=s?.getFacetedUniqueValues(),r=s?.getFilterValue(),l=Array.isArray(r)?new Set(r):r!==void 0?new Set([r]):new Set;return e.jsxs(Be,{children:[e.jsx(Ye,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Ms,{className:"mr-2 h-4 w-4"}),t,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(le,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(E,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:l.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:l.size>2?e.jsxs(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[l.size," selected"]}):a.filter(c=>l.has(c.value)).map(c=>e.jsx(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:c.label},c.value))})]})]})}),e.jsx(Ke,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ts,{children:[e.jsx(hs,{placeholder:t}),e.jsxs(as,{children:[e.jsx(js,{children:"No results found."}),e.jsx(be,{children:a.map(c=>{const d=l.has(c.value);return e.jsxs(me,{onSelect:()=>{const m=new Set(l);d?m.delete(c.value):m.add(c.value);const w=Array.from(m);s?.setFilterValue(w.length?w:void 0)},children:[e.jsx("div",{className:f("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(us,{className:f("h-4 w-4")})}),c.icon&&e.jsx(c.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${c.color}`}),e.jsx("span",{children:c.label}),n?.get(c.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:n.get(c.value)})]},c.value)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_s,{}),e.jsx(be,{children:e.jsx(me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const $m=o.object({email:o.string().min(1),plan_id:o.number(),period:o.string(),total_amount:o.number()}),Am={email:"",plan_id:0,total_amount:0,period:""};function Ir({refetch:s,trigger:t,defaultValues:a}){const[n,r]=i.useState(!1),l=Z({resolver:ee($m),defaultValues:{...Am,...a},mode:"onChange"}),[c,d]=i.useState([]);return i.useEffect(()=>{n&&zs().then(({data:m})=>{d(m)})},[n]),e.jsxs(ue,{open:n,onOpenChange:r,children:[e.jsx(Pe,{asChild:!0,children:t||e.jsxs(k,{variant:"outline",size:"sm",className:" h-8 space-x-2",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"添加订单"})]})}),e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsx(he,{children:"订单分配"}),e.jsx(ze,{})]}),e.jsxs(se,{...l,children:[e.jsx(h,{control:l.control,name:"email",render:({field:m})=>e.jsxs(u,{children:[e.jsx(g,{children:"用户邮箱"}),e.jsx(v,{children:e.jsx(C,{placeholder:"请输入用户邮箱",...m})})]})}),e.jsx(h,{control:l.control,name:"plan_id",render:({field:m})=>e.jsxs(u,{children:[e.jsx(g,{children:"订阅计划"}),e.jsx(v,{children:e.jsxs(B,{value:m.value?m.value?.toString():void 0,onValueChange:w=>m.onChange(parseInt(w)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择订阅计划"})}),e.jsx(G,{children:c.map(w=>e.jsx(A,{value:w.id.toString(),children:w.name},w.id))})]})})]})}),e.jsx(h,{control:l.control,name:"period",render:({field:m})=>e.jsxs(u,{children:[e.jsx(g,{children:"订阅时长"}),e.jsx(v,{children:e.jsxs(B,{value:m.value,onValueChange:m.onChange,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择购买时长"})}),e.jsx(G,{children:Object.keys(ht).map(w=>e.jsx(A,{value:w,children:ht[w]},w))})]})})]})}),e.jsx(h,{control:l.control,name:"total_amount",render:({field:m})=>e.jsxs(u,{children:[e.jsx(g,{children:"支付金额"}),e.jsx(v,{children:e.jsx(C,{type:"number",placeholder:"请输入需要支付的金额",value:m.value/100,onChange:w=>m.onChange(parseFloat(w.currentTarget.value)*100)})}),e.jsx(S,{})]})}),e.jsxs(Fe,{children:[e.jsx(k,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(k,{type:"submit",onClick:()=>{l.handleSubmit(m=>{Yc(m).then(({data:w})=>{w&&(s&&s(),l.reset(),r(!1),V.success("添加成功"))})})()},children:"确定"})]})]})]})]})}function Hm({table:s,refetch:t}){const a=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ir,{refetch:t}),e.jsx(C,{placeholder:"搜索订单...",value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:n=>s.getColumn("trade_no")?.setFilterValue(n.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("status")&&e.jsx(Da,{column:s.getColumn("status"),title:"订单状态",options:Pr}),s.getColumn("commission_status")&&e.jsx(Da,{column:s.getColumn("commission_status"),title:"佣金状态",options:Fr})]}),a&&e.jsxs(k,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["重置",e.jsx(Le,{className:"ml-2 h-4 w-4"})]})]})}function Ee({label:s,value:t,className:a,valueClassName:n}){return e.jsxs("div",{className:f("flex items-center py-1.5",a),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:f("text-sm",n),children:t||"-"})]})}function Km({status:s}){const t={PENDING:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",PAID:"bg-green-100 text-green-800 hover:bg-green-100",FAILED:"bg-red-100 text-red-800 hover:bg-red-100",REFUNDED:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(E,{variant:"secondary",className:f("font-medium",t[s]),children:ks[s]})}function qm({id:s,trigger:t}){const[a,n]=i.useState(!1),[r,l]=i.useState();return i.useEffect(()=>{(async()=>{if(a){const{data:d}=await Uc({id:s});l(d)}})()},[a,s]),e.jsxs(ue,{onOpenChange:n,open:a,children:[e.jsx(Pe,{asChild:!0,children:t}),e.jsxs(de,{className:"max-w-xl",children:[e.jsxs(ge,{className:"space-y-2",children:[e.jsx(he,{className:"text-lg font-medium",children:"订单信息"}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:["订单号:",r?.trade_no]}),r?.status&&e.jsx(Km,{status:r.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"基本信息"}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ee,{label:"用户邮箱",value:r?.user?.email?e.jsxs(Ns,{to:`/user/manage?email=${r.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[r.user.email,e.jsx(In,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(Ee,{label:"订单周期",value:r&&ht[r.period]}),e.jsx(Ee,{label:"订阅计划",value:r?.plan?.name,valueClassName:"font-medium"}),e.jsx(Ee,{label:"回调单号",value:r?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"金额信息"}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ee,{label:"支付金额",value:As(r?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(le,{className:"my-2"}),e.jsx(Ee,{label:"余额支付",value:As(r?.balance_amount||0)}),e.jsx(Ee,{label:"优惠金额",value:As(r?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(Ee,{label:"退回金额",value:As(r?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(Ee,{label:"折抵金额",value:As(r?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"时间信息"}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ee,{label:"创建时间",value:X(r?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(Ee,{label:"更新时间",value:X(r?.updated_at),valueClassName:"font-mono text-xs"})]})]})]})]})]})}const Um=s=>[{accessorKey:"trade_no",header:({column:t})=>e.jsx(F,{column:t,title:"订单号"}),cell:({row:t})=>{const a=t.original.trade_no,n=a.length>6?`${a.slice(0,3)}...${a.slice(-3)}`:a;return e.jsx("div",{className:"flex items-center",children:e.jsx(qm,{trigger:e.jsxs(H,{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:n}),e.jsx(In,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(F,{column:t,title:"类型"}),cell:({row:t})=>e.jsx(E,{variant:"outline",className:"bg-muted/50 transition-colors hover:bg-muted/60",children:md[t.getValue("type")]}),enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(F,{column:t,title:"订阅计划"}),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(F,{column:t,title:"周期"}),cell:({row:t})=>e.jsx(E,{variant:"outline",className:"bg-muted/50 transition-colors hover:bg-muted/60",children:ht[t.getValue("period")]}),enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx(F,{column:t,title:"支付金额"}),cell:({row:t})=>{const a=t.getValue("total_amount"),n=typeof a=="number"?(a/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",n]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:t})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(F,{column:t,title:"订单状态"}),e.jsx(ce,{delayDuration:100,children:e.jsxs(ne,{children:[e.jsx(re,{children:e.jsx(br,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(te,{side:"top",className:"max-w-[200px] text-sm",children:"标记为[已支付]后将会由系统进行开通后并完成"})]})})]}),cell:({row:t})=>{const a=Pr.find(n=>n.value===t.getValue("status"));return a?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[a.icon&&e.jsx(a.icon,{className:`h-4 w-4 text-${a.color}`}),e.jsx("span",{className:"text-sm font-medium",children:a.label})]}),a.value===ie.PENDING&&e.jsxs(vs,{modal:!0,children:[e.jsx(bs,{asChild:!0,children:e.jsxs(H,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(ut,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"打开菜单"})]})}),e.jsxs(ms,{align:"end",className:"w-[140px]",children:[e.jsx(oe,{className:"cursor-pointer",onClick:async()=>{await Gc({trade_no:t.original.trade_no}),s()},children:"标记为已支付"}),e.jsx(oe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await Bc({trade_no:t.original.trade_no}),s()},children:"取消订单"})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx(F,{column:t,title:"佣金金额"}),cell:({row:t})=>{const a=t.getValue("commission_balance"),n=a?(a/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:a?`¥${n}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx(F,{column:t,title:"佣金状态"}),cell:({row:t})=>{const a=t.original.commission_status,n=Fr.find(r=>r.value===t.getValue("commission_status"));return a==0||!n?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:[n.icon&&e.jsx(n.icon,{className:`h-4 w-4 text-${n.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n.label})]}),n.value===xe.PENDING&&e.jsxs(vs,{modal:!0,children:[e.jsx(bs,{asChild:!0,children:e.jsxs(H,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(ut,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"打开菜单"})]})}),e.jsxs(ms,{align:"end",className:"w-[120px]",children:[e.jsx(oe,{className:"cursor-pointer",onClick:async()=>{await Na({trade_no:t.original.trade_no,commission_status:xe.PROCESSING}),s()},children:"标记为有效"}),e.jsx(oe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await Na({trade_no:t.original.trade_no,commission_status:xe.INVALID}),s()},children:"标记为无效"})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(F,{column:t,title:"创建时间"}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:X(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}];function Gm(){const s=gt(),t=new URLSearchParams(s.search),a=Array.from(t.entries()).map(([R,W])=>({id:R,value:parseInt(W)||W})),[n]=i.useState(!0),r=n&&s.state?.filters?s.state.filters:[],l=[...a,...r];i.useEffect(()=>{s.state?.filters&&window.history.replaceState({...s.state,filters:void 0},"")},[]);const[c,d]=i.useState({}),[m,w]=i.useState({}),[j,b]=i.useState(l),[x,y]=i.useState([]),[D,T]=i.useState({pageIndex:0,pageSize:10}),{refetch:p,data:_,isLoading:z}=K({queryKey:["orderList",D,j,x],queryFn:()=>ar({pageSize:D.pageSize,current:D.pageIndex+1,filter:j,sort:x})}),N=Re({data:_?.data??[],columns:Um(p),state:{sorting:x,columnVisibility:m,rowSelection:c,columnFilters:j,pagination:D},rowCount:_?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:d,onSortingChange:y,onColumnFiltersChange:b,onColumnVisibilityChange:w,getCoreRowModel:Me(),getFilteredRowModel:$e(),getPaginationRowModel:Ae(),onPaginationChange:T,getSortedRowModel:He(),getFacetedRowModel:es(),getFacetedUniqueValues:ss()});return e.jsx(qe,{table:N,toolbar:e.jsx(Hm,{table:N,refetch:p}),showPagination:!0})}function Bm(){return e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsx(Ce,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Se,{}),e.jsx(ke,{})]})]}),e.jsxs(Ne,{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:" 订单管理"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"在这里可以查看用户订单,包括分配、查看、删除等操作。"})]})}),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(Gm,{})})]})]})}const Ym=Object.freeze(Object.defineProperty({__proto__:null,default:Bm},Symbol.toStringTag,{value:"Module"}));function Wm({column:s,title:t,options:a}){const n=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(Be,{children:[e.jsx(Ye,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Ms,{className:"mr-2 h-4 w-4"}),t,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(le,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(E,{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(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(l=>r.has(l.value)).map(l=>e.jsx(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(Ke,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ts,{children:[e.jsx(hs,{placeholder:t}),e.jsxs(as,{children:[e.jsx(js,{children:"No results found."}),e.jsx(be,{children:a.map(l=>{const c=r.has(l.value);return e.jsxs(me,{onSelect:()=>{c?r.delete(l.value):r.add(l.value);const d=Array.from(r);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:f("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(us,{className:f("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}),n?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:n.get(l.value)})]},l.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_s,{}),e.jsx(be,{children:e.jsx(me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Jm=o.object({id:o.coerce.number().nullable().optional(),name:o.string().min(1,"请输入优惠券名称"),code:o.string().nullable(),type:o.union([o.string(),o.nativeEnum(kt)]),value:o.coerce.number(),started_at:o.coerce.number(),ended_at:o.coerce.number(),limit_use:o.union([o.string(),o.number()]).nullable(),limit_use_with_user:o.union([o.string(),o.number()]).nullable(),generate_count:o.coerce.number().nullable().optional(),limit_plan_ids:o.array(o.number()).default([]).nullable(),limit_period:o.array(o.nativeEnum(Ds)).default([]).nullable()}).refine(s=>s.ended_at>s.started_at,{message:"结束时间必须晚于开始时间",path:["ended_at"]}),Pa={name:"",code:"",type:kt.AMOUNT,value:0,started_at:Math.floor(Date.now()/1e3),ended_at:Math.floor(Date.now()/1e3)+7*24*60*60,limit_use:"",limit_use_with_user:"",limit_plan_ids:[],limit_period:[],generate_count:""};function Vr({defaultValues:s,refetch:t,type:a="create",dialogTrigger:n=e.jsxs(k,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"添加优惠券"})]}),open:r,onOpenChange:l}){const[c,d]=i.useState(!1),m=r??c,w=l??d,[j,b]=i.useState([]),x=Z({resolver:ee(Jm),defaultValues:s||Pa});i.useEffect(()=>{s&&x.reset(s)},[s,x]),i.useEffect(()=>{zs().then(({data:p})=>b(p))},[]);const y=p=>{if(!p)return;const _=(z,N)=>{const R=new Date(N*1e3);return z.setHours(R.getHours(),R.getMinutes(),R.getSeconds()),Math.floor(z.getTime()/1e3)};p.from&&x.setValue("started_at",_(p.from,x.watch("started_at"))),p.to&&x.setValue("ended_at",_(p.to,x.watch("ended_at")))},D=async p=>{try{await Jc(p),w(!1),a==="create"&&x.reset(Pa),t()}catch(_){console.error("保存优惠券失败:",_)}},T=(p,_)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:_}),e.jsx(C,{type:"datetime-local",step:"1",value:X(x.watch(p),"YYYY-MM-DDTHH:mm:ss"),onChange:z=>{const N=new Date(z.target.value);x.setValue(p,Math.floor(N.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(ue,{open:m,onOpenChange:w,children:[n&&e.jsx(Pe,{asChild:!0,children:n}),e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsx(ge,{children:e.jsx(he,{children:a==="create"?"添加优惠券":"编辑优惠券"})}),e.jsx(se,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(D),className:"space-y-4",children:[e.jsx(h,{control:x.control,name:"name",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"优惠券名称"}),e.jsx(C,{placeholder:"请输入优惠券名称",...p}),e.jsx(S,{})]})}),e.jsxs(u,{children:[e.jsx(g,{children:"优惠券类型和值"}),e.jsxs("div",{className:"flex",children:[e.jsx(h,{control:x.control,name:"type",render:({field:p})=>e.jsxs(B,{value:p.value.toString(),onValueChange:p.onChange,children:[e.jsx(U,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Y,{placeholder:"优惠券类型"})}),e.jsx(G,{children:Object.entries(Zt).map(([_,z])=>e.jsx(A,{value:_,children:z},_))})]})}),e.jsx(h,{control:x.control,name:"value",render:({field:p})=>e.jsx(C,{type:"number",placeholder:"请输入值",...p,onChange:_=>p.onChange(_.target.value===""?"":_.target.value),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:x.watch("type")===kt.AMOUNT?"¥":"%"})})]})]}),e.jsxs(u,{children:[e.jsx(g,{children:"优惠券有效期"}),e.jsxs(Be,{children:[e.jsx(Ye,{asChild:!0,children:e.jsxs(k,{variant:"outline",className:f("w-full justify-start text-left font-normal",!x.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(yt,{className:"mr-2 h-4 w-4"}),X(x.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ","至"," ",X(x.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})}),e.jsxs(Ke,{className:"w-auto p-0",align:"start",children:[e.jsx("div",{className:"border-b border-border",children:e.jsx(et,{mode:"range",selected:{from:new Date(x.watch("started_at")*1e3),to:new Date(x.watch("ended_at")*1e3)},onSelect:y,numberOfMonths:2})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-4",children:[T("started_at","开始时间"),e.jsx("div",{className:"mt-6 text-sm text-muted-foreground",children:"至"}),T("ended_at","结束时间")]})})]})]}),e.jsx(S,{})]}),e.jsx(h,{control:x.control,name:"limit_use",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"最大使用次数"}),e.jsx(C,{type:"number",min:0,placeholder:"限制最大使用次数,留空则不限制",...p,value:p.value===void 0?"":p.value,onChange:_=>p.onChange(_.target.value===""?"":_.target.value),className:"h-9"}),e.jsx(P,{className:"text-xs",children:"设置优惠券的总使用次数限制,留空表示不限制使用次数"}),e.jsx(S,{})]})}),e.jsx(h,{control:x.control,name:"limit_use_with_user",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"每个用户可使用次数"}),e.jsx(C,{type:"number",min:0,placeholder:"限制每个用户可使用次数,留空则不限制",...p,value:p.value===void 0?"":p.value,onChange:_=>p.onChange(_.target.value===""?"":_.target.value),className:"h-9"}),e.jsx(P,{className:"text-xs",children:"限制每个用户可使用该优惠券的次数,留空表示不限制单用户使用次数"}),e.jsx(S,{})]})}),e.jsx(h,{control:x.control,name:"limit_period",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"指定周期"}),e.jsx(Qs,{options:Object.entries(Ds).filter(([_])=>isNaN(Number(_))).map(([_,z])=>({label:z,value:_})),onChange:_=>{if(_.length===0){p.onChange([]);return}const z=_.map(N=>Ds[N.value]);p.onChange(z)},value:(p.value||[]).map(_=>({label:Object.entries(Ds).find(([z,N])=>N===_)?.[1]||"",value:Object.entries(Ds).find(([z,N])=>N===_)?.[0]||""})),placeholder:"限制指定周期可以使用优惠,留空则不限制",emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:"没有找到匹配的周期"})}),e.jsx(P,{className:"text-xs",children:"选择可以使用优惠券的订阅周期,留空表示不限制使用周期"}),e.jsx(S,{})]})}),e.jsx(h,{control:x.control,name:"limit_plan_ids",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"指定订阅"}),e.jsx(Qs,{options:j?.map(_=>({label:_.name,value:_.id.toString()}))||[],onChange:_=>p.onChange(_.map(z=>Number(z.value))),value:(j||[]).filter(_=>(p.value||[]).includes(_.id)).map(_=>({label:_.name,value:_.id.toString()})),placeholder:"限制指定订阅可以使用优惠,留空则不限制",emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:"没有找到匹配的订阅"})}),e.jsx(S,{})]})}),a==="create"&&e.jsxs(e.Fragment,{children:[e.jsx(h,{control:x.control,name:"code",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"自定义优惠码"}),e.jsx(C,{placeholder:"自定义优惠码,留空则自动生成",...p,className:"h-9"}),e.jsx(P,{className:"text-xs",children:"可以自定义优惠码,留空则系统自动生成"}),e.jsx(S,{})]})}),e.jsx(h,{control:x.control,name:"generate_count",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"批量生成数量"}),e.jsx(C,{type:"number",min:0,placeholder:"批量生成优惠码数量,留空则生成单个",...p,value:p.value===void 0?"":p.value,onChange:_=>p.onChange(_.target.value===""?"":_.target.value),className:"h-9"}),e.jsx(P,{className:"text-xs",children:"批量生成多个优惠码,留空则只生成单个优惠码"}),e.jsx(S,{})]})})]}),e.jsx(Fe,{children:e.jsx(k,{type:"submit",disabled:x.formState.isSubmitting,children:x.formState.isSubmitting?"保存中...":"保存"})})]})})]})]})}function Qm({table:s,refetch:t}){const a=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Vr,{refetch:t}),e.jsx(C,{placeholder:"搜索优惠券...",value:s.getColumn("name")?.getFilterValue()??"",onChange:n=>s.getColumn("name")?.setFilterValue(n.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(Wm,{column:s.getColumn("type"),title:"类型",options:Object.entries(Zt).map(([n,r])=>({value:n,label:r}))}),a&&e.jsxs(k,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["重置",e.jsx(Le,{className:"ml-2 h-4 w-4"})]})]})}const Rr=i.createContext(void 0);function Zm({children:s,refetch:t}){const[a,n]=i.useState(!1),[r,l]=i.useState(null),c=m=>{l(m),n(!0)},d=()=>{n(!1),l(null)};return e.jsxs(Rr.Provider,{value:{isOpen:a,currentCoupon:r,openEdit:c,closeEdit:d},children:[s,r&&e.jsx(Vr,{defaultValues:r,refetch:t,type:"edit",open:a,onOpenChange:n})]})}function Xm(){const s=i.useContext(Rr);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const eu=s=>[{accessorKey:"id",header:({column:t})=>e.jsx(F,{column:t,title:"ID"}),cell:({row:t})=>e.jsx(E,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(F,{column:t,title:"启用"}),cell:({row:t})=>e.jsx(O,{defaultChecked:t.original.show,onCheckedChange:a=>{Zc({id:t.original.id,show:a}).then(({data:n})=>!n&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(F,{column:t,title:"卷名称"}),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(F,{column:t,title:"类型"}),cell:({row:t})=>e.jsx(E,{variant:"outline",children:Zt[t.original.type]}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(F,{column:t,title:"卷码"}),cell:({row:t})=>e.jsx(E,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(F,{column:t,title:"剩余次数"}),cell:({row:t})=>e.jsx(E,{variant:"outline",children:t.original.limit_use===null?"无限次":t.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:t})=>e.jsx(F,{column:t,title:"可用次数/用户"}),cell:({row:t})=>e.jsx(E,{variant:"outline",children:t.original.limit_use_with_user===null?"无限制":t.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:t})=>e.jsx(F,{column:t,title:"有效期"}),cell:({row:t})=>{const[a,n]=i.useState(!1),r=Date.now(),l=t.original.started_at*1e3,c=t.original.ended_at*1e3,d=r>c,m=re.jsx(F,{className:"justify-end",column:t,title:"操作"}),cell:({row:t})=>{const{openEdit:a}=Xm();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(k,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>a(t.original),children:[e.jsx(ws,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:"编辑"})]}),e.jsx(Ue,{title:"确认删除",description:"此操作将永久删除该优惠券,删除后无法恢复。确定要继续吗?",confirmText:"删除",variant:"destructive",onConfirm:async()=>{Qc({id:t.original.id}).then(({data:n})=>{n&&(V.success("删除成功"),s())})},children:e.jsxs(k,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(Xe,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:"删除"})]})})]})}}];function su(){const[s,t]=i.useState({}),[a,n]=i.useState({}),[r,l]=i.useState([]),[c,d]=i.useState([]),[m,w]=i.useState({pageIndex:0,pageSize:10}),{refetch:j,data:b}=K({queryKey:["couponList",m,r,c],queryFn:()=>Wc({pageSize:m.pageSize,current:m.pageIndex+1,filter:r,sort:c})}),x=Re({data:b?.data??[],columns:eu(j),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:m},pageCount:Math.ceil((b?.total??0)/m.pageSize),rowCount:b?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:d,onColumnFiltersChange:l,onColumnVisibilityChange:n,onPaginationChange:w,getCoreRowModel:Me(),getFilteredRowModel:$e(),getPaginationRowModel:Ae(),getSortedRowModel:He(),getFacetedRowModel:es(),getFacetedUniqueValues:ss(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Zm,{refetch:j,children:e.jsx("div",{className:"space-y-4",children:e.jsx(qe,{table:x,toolbar:e.jsx(Qm,{table:x,refetch:j})})})})}function tu(){return e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsx(Ce,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Se,{}),e.jsx(ke,{})]})]}),e.jsxs(Ne,{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:"优惠券管理"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"在这里可以查看优惠券,包括增加、查看、删除等操作。"})]})}),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(su,{})})]})]})}const au=Object.freeze(Object.defineProperty({__proto__:null,default:tu},Symbol.toStringTag,{value:"Module"}));function Fa({column:s,title:t,options:a}){const n=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(Be,{children:[e.jsx(Ye,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Ms,{className:"mr-2 h-4 w-4"}),t,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(le,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(E,{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(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(l=>r.has(l.value)).map(l=>e.jsx(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(Ke,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ts,{children:[e.jsx(hs,{placeholder:t}),e.jsxs(as,{children:[e.jsx(js,{children:"No results found."}),e.jsx(be,{children:a.map(l=>{const c=r.has(l.value);return e.jsxs(me,{onSelect:()=>{c?r.delete(l.value):r.add(l.value);const d=Array.from(r);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:f("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(us,{className:f("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}),n?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:n.get(l.value)})]},l.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_s,{}),e.jsx(be,{children:e.jsx(me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const nu=o.object({email_prefix:o.string().optional(),email_suffix:o.string().min(1),password:o.string().optional(),expired_at:o.number().optional().nullable(),plan_id:o.number().nullable(),generate_count:o.number().optional().nullable()}).refine(s=>s.generate_count===null?s.email_prefix!==void 0&&s.email_prefix!=="":!0,{message:"Email prefix is required when generate_count is null",path:["email_prefix"]}),ru={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0};function lu({refetch:s}){const[t,a]=i.useState(!1),n=Z({resolver:ee(nu),defaultValues:ru,mode:"onChange"}),[r,l]=i.useState([]);return i.useEffect(()=>{t&&zs().then(({data:c})=>{c&&l(c)})},[t]),e.jsxs(ue,{open:t,onOpenChange:a,children:[e.jsx(Pe,{asChild:!0,children:e.jsxs(H,{size:"sm",variant:"outline",className:"space-x-2",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"创建用户"})]})}),e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsx(he,{children:"创建用户"}),e.jsx(ze,{})]}),e.jsxs(se,{...n,children:[e.jsxs(u,{children:[e.jsx(g,{children:"邮箱"}),e.jsxs("div",{className:"flex",children:[!n.watch("generate_count")&&e.jsx(h,{control:n.control,name:"email_prefix",render:({field:c})=>e.jsx(C,{className:"flex-[5] rounded-r-none",placeholder:"帐号(批量生成请留空)",...c})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${n.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(h,{control:n.control,name:"email_suffix",render:({field:c})=>e.jsx(C,{className:"flex-[4] rounded-l-none",placeholder:"域",...c})})]})]}),e.jsx(h,{control:n.control,name:"password",render:({field:c})=>e.jsxs(u,{children:[e.jsx(g,{children:"密码"}),e.jsx(C,{placeholder:"留空则密码与邮件相同",...c}),e.jsx(S,{})]})}),e.jsx(h,{control:n.control,name:"expired_at",render:({field:c})=>e.jsxs(u,{className:"flex flex-col",children:[e.jsx(g,{children:"到期时间"}),e.jsxs(Be,{children:[e.jsx(Ye,{asChild:!0,children:e.jsx(v,{children:e.jsxs(H,{variant:"outline",className:f("w-full pl-3 text-left font-normal",!c.value&&"text-muted-foreground"),children:[c.value?X(c.value):e.jsx("span",{children:"请选择用户到期日期,留空为长期有效"}),e.jsx(yt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(Ke,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(no,{asChild:!0,children:e.jsx(H,{variant:"outline",className:"w-full",onClick:()=>{c.onChange(null)},children:"长期有效"})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(et,{mode:"single",selected:c.value?new Date(c.value*1e3):void 0,onSelect:d=>{d&&c.onChange(d?.getTime()/1e3)}})})]})]})]})}),e.jsx(h,{control:n.control,name:"plan_id",render:({field:c})=>e.jsxs(u,{children:[e.jsx(g,{children:"订阅计划"}),e.jsx(v,{children:e.jsxs(B,{value:c.value?c.value.toString():"null",onValueChange:d=>c.onChange(d==="null"?null:parseInt(d)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"无"})}),e.jsxs(G,{children:[e.jsx(A,{value:"null",children:"无"}),r.map(d=>e.jsx(A,{value:d.id.toString(),children:d.name},d.id))]})]})})]})}),!n.watch("email_prefix")&&e.jsx(h,{control:n.control,name:"generate_count",render:({field:c})=>e.jsxs(u,{children:[e.jsx(g,{children:"生成数量"}),e.jsx(C,{type:"number",placeholder:"如果为批量生产请输入生成数量",value:c.value||"",onChange:d=>c.onChange(d.target.value?parseInt(d.target.value):null)})]})})]}),e.jsxs(Fe,{children:[e.jsx(H,{variant:"outline",onClick:()=>a(!1),children:"取消"}),e.jsx(H,{onClick:()=>n.handleSubmit(c=>{td(c).then(({data:d})=>{d&&(V.success("生成成功"),n.reset(),s(),a(!1))})})(),children:"生成"})]})]})]})}function iu({table:s,refetch:t,serverGroupList:a}){const n=s.getState().columnFilters.length>0;return e.jsx("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(lu,{refetch:t}),e.jsx(C,{placeholder:"搜索用户邮箱...",value:s.getColumn("email")?.getFilterValue()??"",onChange:r=>s.getColumn("email")?.setFilterValue(r.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("banned")&&e.jsx(Fa,{column:s.getColumn("banned"),title:"用户状态",options:[{label:"正常",value:0},{label:"封禁",value:1}]}),s.getColumn("group_ids")&&e.jsx(Fa,{column:s.getColumn("group_ids"),title:"权限组",options:a.map(r=>({label:r.name,value:r.id}))}),n&&e.jsxs(k,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["重置筛选",e.jsx(Le,{className:"ml-2 h-4 w-4"})]})]})})}const ou=Ra,cu=Ma,du=za,Mr=i.forwardRef(({className:s,...t},a)=>e.jsx(ft,{className:f("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),...t,ref:a}));Mr.displayName=ft.displayName;const xu=ys("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"}}),zr=i.forwardRef(({side:s="right",className:t,children:a,...n},r)=>e.jsxs(du,{children:[e.jsx(Mr,{}),e.jsxs(pt,{ref:r,className:f(xu({side:s}),t),...n,children:[e.jsxs(Bt,{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(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),a]})]}));zr.displayName=pt.displayName;const Er=({className:s,...t})=>e.jsx("div",{className:f("flex flex-col space-y-2 text-center sm:text-left",s),...t});Er.displayName="SheetHeader";const Or=({className:s,...t})=>e.jsx("div",{className:f("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});Or.displayName="SheetFooter";const Lr=i.forwardRef(({className:s,...t},a)=>e.jsx(vt,{ref:a,className:f("text-lg font-semibold text-foreground",s),...t}));Lr.displayName=vt.displayName;const $r=i.forwardRef(({className:s,...t},a)=>e.jsx(bt,{ref:a,className:f("text-sm text-muted-foreground",s),...t}));$r.displayName=bt.displayName;const mu=o.object({id:o.number(),email:o.string().email(),invite_user_email:o.string().email().nullable().optional(),password:o.string().optional().nullable(),balance:o.coerce.number(),commission_balance:o.coerce.number(),u:o.number(),d:o.number(),transfer_enable:o.number(),expired_at:o.number().nullable(),plan_id:o.number().nullable(),banned:o.number(),commission_type:o.number(),commission_rate:o.number().nullable(),discount:o.number().nullable(),speed_limit:o.number().nullable(),is_admin:o.number(),is_staff:o.number(),remarks:o.string().nullable()});function Ar({refetch:s,defaultValues:t,dialogTrigger:a=e.jsxs(k,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(Ms,{className:"mr-2 h-4 w-4"}),"编辑用户信息"]})}){const[n,r]=i.useState(!1),[l,c]=i.useState(!1),d=Z({resolver:ee(mu),defaultValues:t,mode:"onChange"}),[m,w]=i.useState([]);return i.useEffect(()=>{n&&zs().then(({data:j})=>{w(j)})},[n]),e.jsxs(ou,{open:n,onOpenChange:r,children:[e.jsx(cu,{asChild:!0,children:a}),e.jsxs(zr,{className:"max-w-[90%] space-y-4 ",children:[e.jsxs(Er,{children:[e.jsx(Lr,{children:"用户管理"}),e.jsx($r,{})]}),e.jsxs(se,{...d,children:[e.jsx(h,{control:d.control,name:"email",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"邮箱"}),e.jsx(C,{...j,placeholder:"请输入邮箱"}),e.jsx(S,{...j})]})}),e.jsx(h,{control:d.control,name:"invite_user_email",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"邀请人邮箱"}),e.jsx(C,{value:j.value||"",onChange:b=>j.onChange(b.target.value?b.target.value:null),placeholder:"请输入邮箱"}),e.jsx(S,{...j})]})}),e.jsx(h,{control:d.control,name:"password",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"密码"}),e.jsx(C,{value:j.value||"",onChange:j.onChange,placeholder:"如需修改密码请输入"}),e.jsx(S,{...j})]})}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsx(h,{control:d.control,name:"balance",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"余额"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value||"",onChange:j.onChange,placeholder:"请输入余额",className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]}),e.jsx(S,{...j})]})}),e.jsx(h,{control:d.control,name:"commission_balance",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"佣金余额"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value||"",onChange:j.onChange,placeholder:"请输入佣金余额",className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]}),e.jsx(S,{...j})]})}),e.jsx(h,{control:d.control,name:"u",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"已用上行"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:(j.value/1024/1024/1024).toFixed(3)||"",onChange:b=>j.onChange(parseInt(b.target.value)*1024*1024*1024),placeholder:"已用上行",className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]}),e.jsx(S,{...j})]})}),e.jsx(h,{control:d.control,name:"d",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"已用下行"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:(j.value/1024/1024/1024).toFixed(3)||"",onChange:b=>j.onChange(parseInt(b.target.value)*1024*1024*1024),placeholder:"已用下行",className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]}),e.jsx(S,{...j})]})})]}),e.jsx(h,{control:d.control,name:"transfer_enable",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"流量"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value/1024/1024/1024||"",onChange:b=>j.onChange(parseInt(b.target.value)*1024*1024*1024),placeholder:"请输入流量",className:"rounded-r-none "}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]}),e.jsx(S,{})]})}),e.jsx(h,{control:d.control,name:"expired_at",render:({field:j})=>e.jsxs(u,{className:"flex flex-col",children:[e.jsx(g,{children:"到期时间"}),e.jsxs(Be,{open:l,onOpenChange:c,children:[e.jsx(Ye,{asChild:!0,children:e.jsx(v,{children:e.jsxs(k,{type:"button",variant:"outline",className:f("w-full pl-3 text-left font-normal",!j.value&&"text-muted-foreground"),onClick:()=>c(!0),children:[j.value?X(j.value):e.jsx("span",{children:"请选择用户到期日期,留空为长期有效"}),e.jsx(yt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Ke,{className:"w-auto p-0",align:"start",side:"top",sideOffset:4,onInteractOutside:b=>{b.preventDefault()},onEscapeKeyDown:b=>{b.preventDefault()},children:e.jsxs("div",{className:"flex flex-col space-y-3 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{j.onChange(null),c(!1)},children:"长期有效"}),e.jsx(k,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const b=new Date;b.setMonth(b.getMonth()+1),b.setHours(23,59,59,999),j.onChange(Math.floor(b.getTime()/1e3)),c(!1)},children:"一个月"}),e.jsx(k,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const b=new Date;b.setMonth(b.getMonth()+3),b.setHours(23,59,59,999),j.onChange(Math.floor(b.getTime()/1e3)),c(!1)},children:"三个月"})]}),e.jsx("div",{className:"rounded-md border",children:e.jsx(et,{mode:"single",selected:j.value?new Date(j.value*1e3):void 0,onSelect:b=>{if(b){const x=new Date(j.value?j.value*1e3:Date.now());b.setHours(x.getHours(),x.getMinutes(),x.getSeconds()),j.onChange(Math.floor(b.getTime()/1e3))}},disabled:b=>b{const b=new Date;b.setHours(23,59,59,999),j.onChange(Math.floor(b.getTime()/1e3))},className:"h-6 px-2 text-xs",children:"设为当天结束"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(C,{type:"datetime-local",step:"1",value:X(j.value,"YYYY-MM-DDTHH:mm:ss"),onChange:b=>{const x=new Date(b.target.value);isNaN(x.getTime())||j.onChange(Math.floor(x.getTime()/1e3))},className:"flex-1"}),e.jsx(k,{type:"button",variant:"outline",onClick:()=>c(!1),children:"确定"})]})]})]})})]}),e.jsx(S,{})]})}),e.jsx(h,{control:d.control,name:"plan_id",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"订阅计划"}),e.jsx(v,{children:e.jsxs(B,{value:j.value?j.value.toString():"null",onValueChange:b=>j.onChange(b==="null"?null:parseInt(b)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"无"})}),e.jsxs(G,{children:[e.jsx(A,{value:"null",children:"无"}),m.map(b=>e.jsx(A,{value:b.id.toString(),children:b.name},b.id))]})]})})]})}),e.jsx(h,{control:d.control,name:"banned",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"账户状态"}),e.jsx(v,{children:e.jsxs(B,{value:j.value.toString(),onValueChange:b=>j.onChange(parseInt(b)),children:[e.jsx(U,{children:e.jsx(Y,{})}),e.jsxs(G,{children:[e.jsx(A,{value:"1",children:"封禁"}),e.jsx(A,{value:"0",children:"正常"})]})]})})]})}),e.jsx(h,{control:d.control,name:"commission_type",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"佣金类型"}),e.jsx(v,{children:e.jsxs(B,{value:j.value.toString(),onValueChange:b=>j.onChange(parseInt(b)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"无"})}),e.jsxs(G,{children:[e.jsx(A,{value:"0",children:"跟随系统设置"}),e.jsx(A,{value:"1",children:"循环返利"}),e.jsx(A,{value:"2",children:"首次返利"})]})]})})]})}),e.jsx(h,{control:d.control,name:"commission_rate",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"推荐返利比例"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value||"",onChange:b=>j.onChange(parseInt(b.currentTarget.value)||null),placeholder:"请输入推荐返利比例(为空则跟随站点设置返利比例)",className:"rounded-r-none "}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]}),e.jsx(S,{})]})}),e.jsx(h,{control:d.control,name:"discount",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"专享折扣比例"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value||"",onChange:b=>j.onChange(parseInt(b.currentTarget.value)||null),placeholder:"请输入专享折扣比例(为空则不享受专享折扣)",className:"rounded-r-none "}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]}),e.jsx(S,{})]})}),e.jsx(h,{control:d.control,name:"speed_limit",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"限速"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value||"",onChange:b=>j.onChange(parseInt(b.currentTarget.value)||null),placeholder:"留空则不限速",className:"rounded-r-none "}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"Mbps"})]}),e.jsx(S,{})]})}),e.jsx(h,{control:d.control,name:"is_admin",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"是否管理员"}),e.jsx("div",{className:"py-2",children:e.jsx(v,{children:e.jsx(O,{checked:j.value===1,onCheckedChange:b=>j.onChange(b?1:0)})})})]})}),e.jsx(h,{control:d.control,name:"is_staff",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"是否员工"}),e.jsx("div",{className:"py-2",children:e.jsx(v,{children:e.jsx(O,{checked:j.value===1,onCheckedChange:b=>j.onChange(b?1:0)})})})]})}),e.jsx(h,{control:d.control,name:"remarks",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"备注"}),e.jsx(gs,{className:"h-24",value:j.value||"",onChange:b=>j.onChange(b.currentTarget.value??null),placeholder:"请在这里记录"})]})})]}),e.jsxs(Or,{children:[e.jsx(k,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(k,{type:"submit",onClick:()=>{d.handleSubmit(j=>{ed(j).then(({data:b})=>{b&&(V.success("修改成功"),r(!1),s())}).catch(b=>{V.error("修改失败")})})()},children:"提交"})]})]})]})}const Hr=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"})}),Kr=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),uu=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"})}),hu=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"})}),Rt=[{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:Oo(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Hr,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:Fs(s.original.u)})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Kr,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:Fs(s.original.d)})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const t=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(E,{variant:"outline",className:"font-mono",children:[t,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const t=(s.original.u+s.original.d)*s.original.server_rate;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:Fs(t)})}}];function qr({user_id:s,dialogTrigger:t}){const[a,n]=i.useState(!1),[r,l]=i.useState({pageIndex:0,pageSize:10}),{data:c,isLoading:d}=K({queryKey:["userStats",s,r,a],queryFn:()=>a?ad({user_id:s,pageSize:r.pageSize,page:r.pageIndex+1}):null}),m=Re({data:c?.data??[],columns:Rt,pageCount:Math.ceil((c?.total??0)/r.pageSize),state:{pagination:r},manualPagination:!0,getCoreRowModel:Me(),onPaginationChange:l});return e.jsxs(ue,{open:a,onOpenChange:n,children:[e.jsx(Pe,{asChild:!0,children:t}),e.jsxs(de,{className:"sm:max-w-[700px]",children:[e.jsx(ge,{children:e.jsx(he,{children:"流量使用记录"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Xt,{children:[e.jsx(ea,{children:m.getHeaderGroups().map(w=>e.jsx(xs,{children:w.headers.map(j=>e.jsx(ta,{className:f("h-10 px-2 text-xs",j.id==="total"&&"text-right"),children:j.isPlaceholder?null:mt(j.column.columnDef.header,j.getContext())},j.id))},w.id))}),e.jsx(sa,{children:d?Array.from({length:r.pageSize}).map((w,j)=>e.jsx(xs,{children:Array.from({length:Rt.length}).map((b,x)=>e.jsx(Is,{className:"p-2",children:e.jsx(Ve,{className:"h-6 w-full"})},x))},j)):m.getRowModel().rows?.length?m.getRowModel().rows.map(w=>e.jsx(xs,{"data-state":w.getIsSelected()&&"selected",className:"h-10",children:w.getVisibleCells().map(j=>e.jsx(Is,{className:"px-2",children:mt(j.column.columnDef.cell,j.getContext())},j.id))},w.id)):e.jsx(xs,{children:e.jsx(Is,{colSpan:Rt.length,className:"h-24 text-center",children:"暂无记录"})})})]})}),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:"每页显示"}),e.jsxs(B,{value:`${m.getState().pagination.pageSize}`,onValueChange:w=>{m.setPageSize(Number(w))},children:[e.jsx(U,{className:"h-8 w-[70px]",children:e.jsx(Y,{placeholder:m.getState().pagination.pageSize})}),e.jsx(G,{side:"top",children:[10,20,30,40,50].map(w=>e.jsx(A,{value:`${w}`,children:w},w))})]}),e.jsx("p",{className:"text-sm font-medium",children:"条记录"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("div",{className:"flex w-[100px] items-center justify-center text-sm",children:["第 ",m.getState().pagination.pageIndex+1," /"," ",m.getPageCount()," 页"]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(H,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>m.previousPage(),disabled:!m.getCanPreviousPage()||d,children:e.jsx(uu,{className:"h-4 w-4"})}),e.jsx(H,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>m.nextPage(),disabled:!m.getCanNextPage()||d,children:e.jsx(hu,{className:"h-4 w-4"})})]})]})]})]})]})]})}const ju=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M5 18h4.24a1 1 0 0 0 .71-.29l6.92-6.93L19.71 8a1 1 0 0 0 0-1.42l-4.24-4.29a1 1 0 0 0-1.42 0l-2.82 2.83l-6.94 6.93a1 1 0 0 0-.29.71V17a1 1 0 0 0 1 1m9.76-13.59l2.83 2.83l-1.42 1.42l-2.83-2.83ZM6 13.17l5.93-5.93l2.83 2.83L8.83 16H6ZM21 20H3a1 1 0 0 0 0 2h18a1 1 0 0 0 0-2"})}),gu=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"})}),fu=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"})}),pu=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"})}),vu=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"})}),bu=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"})}),yu=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"})}),Nu=(s,t)=>[{accessorKey:"id",header:({column:a})=>e.jsx(F,{column:a,title:"ID"}),cell:({row:a})=>e.jsx(E,{variant:"outline",children:a.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:a})=>e.jsx(F,{column:a,title:"邮箱"}),cell:({row:a})=>{const n=a.original.t||0,r=Date.now()/1e3-n<120,l=Math.floor(Date.now()/1e3-n);let c=r?"当前在线":n===0?"从未在线":`最后在线时间: ${X(n)}`;if(!r&&n!==0){const d=Math.floor(l/60),m=Math.floor(d/60),w=Math.floor(m/24);w>0?c+=` +- 支持随时更换套餐`)},children:"使用模板"})}),e.jsx(te,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:"点击使用预设的套餐描述模板"})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${T?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(v,{children:e.jsx(kn,{style:{height:"400px"},value:D.value||"",renderHTML:_=>m.render(_),onChange:({text:_})=>D.onChange(_),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:"在这里编写套餐描述...",className:"rounded-md border"})})}),T&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"预览"}),e.jsx("div",{className:"prose prose-sm dark:prose-invert h-[400px] max-w-none overflow-y-auto rounded-md border p-4",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:m.render(D.value||"")}})})]})]}),e.jsx(P,{className:"text-xs",children:"支持 Markdown 格式,可以使用标题、列表、粗体、斜体等样式来美化描述内容"}),e.jsx(S,{})]})}})]}),e.jsx(Fe,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:a&&e.jsx(h,{control:d.control,name:"force_update",render:({field:D})=>e.jsxs(u,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(v,{children:e.jsx(Dr,{checked:D.value,onCheckedChange:D.onChange})}),e.jsx("div",{className:"",children:e.jsx(g,{className:"text-sm",children:"强制更新到用户"})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{type:"button",variant:"outline",onClick:y,children:"取消"}),e.jsx(k,{type:"submit",disabled:l,onClick:()=>{d.handleSubmit(async D=>{c(!0),(await Hc(D)).data&&(V.success(a?"套餐更新成功":"套餐添加成功"),y(),r()),c(!1)})()},children:l?"提交中...":"提交"})]})]})})]})]})})}function Em(){const[s,t]=i.useState({}),[a,n]=i.useState({"drag-handle":!1}),[r,l]=i.useState([]),[c,d]=i.useState([]),[m,w]=i.useState(!1),[j,b]=i.useState({pageSize:10,pageIndex:0}),[x,y]=i.useState([]),{refetch:D}=K({queryKey:["planList"],queryFn:async()=>{const{data:N}=await zs();return y(N),N}});i.useEffect(()=>{n({"drag-handle":m}),b({pageSize:m?99999:10,pageIndex:0})},[m]);const T=(N,R)=>{m&&(N.dataTransfer.setData("text/plain",R.toString()),N.currentTarget.classList.add("opacity-50"))},p=(N,R)=>{if(!m)return;N.preventDefault(),N.currentTarget.classList.remove("bg-muted");const W=parseInt(N.dataTransfer.getData("text/plain"));if(W===R)return;const L=[...x],[ae]=L.splice(W,1);L.splice(R,0,ae),y(L)},_=async()=>{if(!m){w(!0);return}try{const N=x?.map(R=>R.id);await qc(N),V.success("排序保存成功"),w(!1),D()}catch{V.error("排序保存失败"),w(!1)}},z=Re({data:x||[],columns:Vm(D),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:j},enableRowSelection:!0,onPaginationChange:b,onRowSelectionChange:t,onSortingChange:d,onColumnFiltersChange:l,onColumnVisibilityChange:n,getCoreRowModel:Me(),getFilteredRowModel:$e(),getPaginationRowModel:Ae(),getSortedRowModel:He(),getFacetedRowModel:es(),getFacetedUniqueValues:ss(),initialState:{columnPinning:{right:["actions"]}},pageCount:m?1:void 0});return e.jsx(Fm,{refreshData:D,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(qe,{table:z,toolbar:N=>e.jsx(Im,{table:N,refetch:D,saveOrder:_,isSortMode:m}),draggable:m,onDragStart:T,onDragEnd:N=>N.currentTarget.classList.remove("opacity-50"),onDragOver:N=>{N.preventDefault(),N.currentTarget.classList.add("bg-muted")},onDragLeave:N=>N.currentTarget.classList.remove("bg-muted"),onDrop:p,showPagination:!m}),e.jsx(zm,{})]})})}function Om(){return e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsx(Ce,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Se,{}),e.jsx(ke,{})]})]}),e.jsxs(Ne,{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:"订阅管理"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"在这里可以配置订阅计划,包括添加、删除、编辑等操作。"})]})}),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(Em,{})})]})]})}const Lm=Object.freeze(Object.defineProperty({__proto__:null,default:Om},Symbol.toStringTag,{value:"Module"})),Pr=[{value:ie.PENDING,label:ks[ie.PENDING],icon:so,color:Hs[ie.PENDING]},{value:ie.PROCESSING,label:ks[ie.PROCESSING],icon:Pn,color:Hs[ie.PROCESSING]},{value:ie.COMPLETED,label:ks[ie.COMPLETED],icon:Lt,color:Hs[ie.COMPLETED]},{value:ie.CANCELLED,label:ks[ie.CANCELLED],icon:Fn,color:Hs[ie.CANCELLED]},{value:ie.DISCOUNTED,label:ks[ie.DISCOUNTED],icon:Lt,color:Hs[ie.DISCOUNTED]}],Fr=[{value:xe.PENDING,label:at[xe.PENDING],icon:to,color:nt[xe.PENDING]},{value:xe.PROCESSING,label:at[xe.PROCESSING],icon:Pn,color:nt[xe.PROCESSING]},{value:xe.VALID,label:at[xe.VALID],icon:Lt,color:nt[xe.VALID]},{value:xe.INVALID,label:at[xe.INVALID],icon:Fn,color:nt[xe.INVALID]}];function Da({column:s,title:t,options:a}){const n=s?.getFacetedUniqueValues(),r=s?.getFilterValue(),l=Array.isArray(r)?new Set(r):r!==void 0?new Set([r]):new Set;return e.jsxs(Be,{children:[e.jsx(Ye,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Ms,{className:"mr-2 h-4 w-4"}),t,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(le,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(E,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:l.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:l.size>2?e.jsxs(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[l.size," selected"]}):a.filter(c=>l.has(c.value)).map(c=>e.jsx(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:c.label},c.value))})]})]})}),e.jsx(Ke,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ts,{children:[e.jsx(hs,{placeholder:t}),e.jsxs(as,{children:[e.jsx(js,{children:"No results found."}),e.jsx(be,{children:a.map(c=>{const d=l.has(c.value);return e.jsxs(me,{onSelect:()=>{const m=new Set(l);d?m.delete(c.value):m.add(c.value);const w=Array.from(m);s?.setFilterValue(w.length?w:void 0)},children:[e.jsx("div",{className:f("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(us,{className:f("h-4 w-4")})}),c.icon&&e.jsx(c.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${c.color}`}),e.jsx("span",{children:c.label}),n?.get(c.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:n.get(c.value)})]},c.value)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_s,{}),e.jsx(be,{children:e.jsx(me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const $m=o.object({email:o.string().min(1),plan_id:o.number(),period:o.string(),total_amount:o.number()}),Am={email:"",plan_id:0,total_amount:0,period:""};function Ir({refetch:s,trigger:t,defaultValues:a}){const[n,r]=i.useState(!1),l=Z({resolver:ee($m),defaultValues:{...Am,...a},mode:"onChange"}),[c,d]=i.useState([]);return i.useEffect(()=>{n&&zs().then(({data:m})=>{d(m)})},[n]),e.jsxs(ue,{open:n,onOpenChange:r,children:[e.jsx(Pe,{asChild:!0,children:t||e.jsxs(k,{variant:"outline",size:"sm",className:" h-8 space-x-2",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"添加订单"})]})}),e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsx(he,{children:"订单分配"}),e.jsx(ze,{})]}),e.jsxs(se,{...l,children:[e.jsx(h,{control:l.control,name:"email",render:({field:m})=>e.jsxs(u,{children:[e.jsx(g,{children:"用户邮箱"}),e.jsx(v,{children:e.jsx(C,{placeholder:"请输入用户邮箱",...m})})]})}),e.jsx(h,{control:l.control,name:"plan_id",render:({field:m})=>e.jsxs(u,{children:[e.jsx(g,{children:"订阅计划"}),e.jsx(v,{children:e.jsxs(B,{value:m.value?m.value?.toString():void 0,onValueChange:w=>m.onChange(parseInt(w)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择订阅计划"})}),e.jsx(G,{children:c.map(w=>e.jsx(A,{value:w.id.toString(),children:w.name},w.id))})]})})]})}),e.jsx(h,{control:l.control,name:"period",render:({field:m})=>e.jsxs(u,{children:[e.jsx(g,{children:"订阅时长"}),e.jsx(v,{children:e.jsxs(B,{value:m.value,onValueChange:m.onChange,children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"请选择购买时长"})}),e.jsx(G,{children:Object.keys(ht).map(w=>e.jsx(A,{value:w,children:ht[w]},w))})]})})]})}),e.jsx(h,{control:l.control,name:"total_amount",render:({field:m})=>e.jsxs(u,{children:[e.jsx(g,{children:"支付金额"}),e.jsx(v,{children:e.jsx(C,{type:"number",placeholder:"请输入需要支付的金额",value:m.value/100,onChange:w=>m.onChange(parseFloat(w.currentTarget.value)*100)})}),e.jsx(S,{})]})}),e.jsxs(Fe,{children:[e.jsx(k,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(k,{type:"submit",onClick:()=>{l.handleSubmit(m=>{Yc(m).then(({data:w})=>{w&&(s&&s(),l.reset(),r(!1),V.success("添加成功"))})})()},children:"确定"})]})]})]})]})}function Hm({table:s,refetch:t}){const a=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ir,{refetch:t}),e.jsx(C,{placeholder:"搜索订单...",value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:n=>s.getColumn("trade_no")?.setFilterValue(n.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("status")&&e.jsx(Da,{column:s.getColumn("status"),title:"订单状态",options:Pr}),s.getColumn("commission_status")&&e.jsx(Da,{column:s.getColumn("commission_status"),title:"佣金状态",options:Fr})]}),a&&e.jsxs(k,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["重置",e.jsx(Le,{className:"ml-2 h-4 w-4"})]})]})}function Ee({label:s,value:t,className:a,valueClassName:n}){return e.jsxs("div",{className:f("flex items-center py-1.5",a),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:f("text-sm",n),children:t||"-"})]})}function Km({status:s}){const t={PENDING:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",PAID:"bg-green-100 text-green-800 hover:bg-green-100",FAILED:"bg-red-100 text-red-800 hover:bg-red-100",REFUNDED:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(E,{variant:"secondary",className:f("font-medium",t[s]),children:ks[s]})}function qm({id:s,trigger:t}){const[a,n]=i.useState(!1),[r,l]=i.useState();return i.useEffect(()=>{(async()=>{if(a){const{data:d}=await Uc({id:s});l(d)}})()},[a,s]),e.jsxs(ue,{onOpenChange:n,open:a,children:[e.jsx(Pe,{asChild:!0,children:t}),e.jsxs(de,{className:"max-w-xl",children:[e.jsxs(ge,{className:"space-y-2",children:[e.jsx(he,{className:"text-lg font-medium",children:"订单信息"}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:["订单号:",r?.trade_no]}),r?.status&&e.jsx(Km,{status:r.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"基本信息"}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ee,{label:"用户邮箱",value:r?.user?.email?e.jsxs(Ns,{to:`/user/manage?email=${r.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[r.user.email,e.jsx(In,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(Ee,{label:"订单周期",value:r&&ht[r.period]}),e.jsx(Ee,{label:"订阅计划",value:r?.plan?.name,valueClassName:"font-medium"}),e.jsx(Ee,{label:"回调单号",value:r?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"金额信息"}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ee,{label:"支付金额",value:As(r?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(le,{className:"my-2"}),e.jsx(Ee,{label:"余额支付",value:As(r?.balance_amount||0)}),e.jsx(Ee,{label:"优惠金额",value:As(r?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(Ee,{label:"退回金额",value:As(r?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(Ee,{label:"折抵金额",value:As(r?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"时间信息"}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ee,{label:"创建时间",value:X(r?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(Ee,{label:"更新时间",value:X(r?.updated_at),valueClassName:"font-mono text-xs"})]})]})]})]})]})}const Um=s=>[{accessorKey:"trade_no",header:({column:t})=>e.jsx(F,{column:t,title:"订单号"}),cell:({row:t})=>{const a=t.original.trade_no,n=a.length>6?`${a.slice(0,3)}...${a.slice(-3)}`:a;return e.jsx("div",{className:"flex items-center",children:e.jsx(qm,{trigger:e.jsxs(H,{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:n}),e.jsx(In,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(F,{column:t,title:"类型"}),cell:({row:t})=>e.jsx(E,{variant:"outline",className:"bg-muted/50 transition-colors hover:bg-muted/60",children:md[t.getValue("type")]}),enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(F,{column:t,title:"订阅计划"}),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(F,{column:t,title:"周期"}),cell:({row:t})=>e.jsx(E,{variant:"outline",className:"bg-muted/50 transition-colors hover:bg-muted/60",children:ht[t.getValue("period")]}),enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx(F,{column:t,title:"支付金额"}),cell:({row:t})=>{const a=t.getValue("total_amount"),n=typeof a=="number"?(a/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",n]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:t})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(F,{column:t,title:"订单状态"}),e.jsx(ce,{delayDuration:100,children:e.jsxs(ne,{children:[e.jsx(re,{children:e.jsx(br,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(te,{side:"top",className:"max-w-[200px] text-sm",children:"标记为[已支付]后将会由系统进行开通后并完成"})]})})]}),cell:({row:t})=>{const a=Pr.find(n=>n.value===t.getValue("status"));return a?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[a.icon&&e.jsx(a.icon,{className:`h-4 w-4 text-${a.color}`}),e.jsx("span",{className:"text-sm font-medium",children:a.label})]}),a.value===ie.PENDING&&e.jsxs(vs,{modal:!0,children:[e.jsx(bs,{asChild:!0,children:e.jsxs(H,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(ut,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"打开菜单"})]})}),e.jsxs(ms,{align:"end",className:"w-[140px]",children:[e.jsx(oe,{className:"cursor-pointer",onClick:async()=>{await Gc({trade_no:t.original.trade_no}),s()},children:"标记为已支付"}),e.jsx(oe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await Bc({trade_no:t.original.trade_no}),s()},children:"取消订单"})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx(F,{column:t,title:"佣金金额"}),cell:({row:t})=>{const a=t.getValue("commission_balance"),n=a?(a/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:a?`¥${n}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx(F,{column:t,title:"佣金状态"}),cell:({row:t})=>{const a=t.original.commission_status,n=Fr.find(r=>r.value===t.getValue("commission_status"));return a==0||!n?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:[n.icon&&e.jsx(n.icon,{className:`h-4 w-4 text-${n.color}`}),e.jsx("span",{className:"text-sm font-medium",children:n.label})]}),n.value===xe.PENDING&&e.jsxs(vs,{modal:!0,children:[e.jsx(bs,{asChild:!0,children:e.jsxs(H,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(ut,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"打开菜单"})]})}),e.jsxs(ms,{align:"end",className:"w-[120px]",children:[e.jsx(oe,{className:"cursor-pointer",onClick:async()=>{await Na({trade_no:t.original.trade_no,commission_status:xe.PROCESSING}),s()},children:"标记为有效"}),e.jsx(oe,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await Na({trade_no:t.original.trade_no,commission_status:xe.INVALID}),s()},children:"标记为无效"})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(F,{column:t,title:"创建时间"}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:X(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}];function Gm(){const s=gt(),t=new URLSearchParams(s.search),a=Array.from(t.entries()).map(([R,W])=>({id:R,value:parseInt(W)||W})),[n]=i.useState(!0),r=n&&s.state?.filters?s.state.filters:[],l=[...a,...r];i.useEffect(()=>{s.state?.filters&&window.history.replaceState({...s.state,filters:void 0},"")},[]);const[c,d]=i.useState({}),[m,w]=i.useState({}),[j,b]=i.useState(l),[x,y]=i.useState([]),[D,T]=i.useState({pageIndex:0,pageSize:10}),{refetch:p,data:_,isLoading:z}=K({queryKey:["orderList",D,j,x],queryFn:()=>ar({pageSize:D.pageSize,current:D.pageIndex+1,filter:j,sort:x})}),N=Re({data:_?.data??[],columns:Um(p),state:{sorting:x,columnVisibility:m,rowSelection:c,columnFilters:j,pagination:D},rowCount:_?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:d,onSortingChange:y,onColumnFiltersChange:b,onColumnVisibilityChange:w,getCoreRowModel:Me(),getFilteredRowModel:$e(),getPaginationRowModel:Ae(),onPaginationChange:T,getSortedRowModel:He(),getFacetedRowModel:es(),getFacetedUniqueValues:ss()});return e.jsx(qe,{table:N,toolbar:e.jsx(Hm,{table:N,refetch:p}),showPagination:!0})}function Bm(){return e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsx(Ce,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Se,{}),e.jsx(ke,{})]})]}),e.jsxs(Ne,{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:" 订单管理"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"在这里可以查看用户订单,包括分配、查看、删除等操作。"})]})}),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(Gm,{})})]})]})}const Ym=Object.freeze(Object.defineProperty({__proto__:null,default:Bm},Symbol.toStringTag,{value:"Module"}));function Wm({column:s,title:t,options:a}){const n=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(Be,{children:[e.jsx(Ye,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Ms,{className:"mr-2 h-4 w-4"}),t,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(le,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(E,{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(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(l=>r.has(l.value)).map(l=>e.jsx(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(Ke,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ts,{children:[e.jsx(hs,{placeholder:t}),e.jsxs(as,{children:[e.jsx(js,{children:"No results found."}),e.jsx(be,{children:a.map(l=>{const c=r.has(l.value);return e.jsxs(me,{onSelect:()=>{c?r.delete(l.value):r.add(l.value);const d=Array.from(r);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:f("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(us,{className:f("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}),n?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:n.get(l.value)})]},l.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_s,{}),e.jsx(be,{children:e.jsx(me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Jm=o.object({id:o.coerce.number().nullable().optional(),name:o.string().min(1,"请输入优惠券名称"),code:o.string().nullable(),type:o.union([o.string(),o.nativeEnum(kt)]),value:o.coerce.number(),started_at:o.coerce.number(),ended_at:o.coerce.number(),limit_use:o.union([o.string(),o.number()]).nullable(),limit_use_with_user:o.union([o.string(),o.number()]).nullable(),generate_count:o.coerce.number().nullable().optional(),limit_plan_ids:o.array(o.number()).default([]).nullable(),limit_period:o.array(o.nativeEnum(Ds)).default([]).nullable()}).refine(s=>s.ended_at>s.started_at,{message:"结束时间必须晚于开始时间",path:["ended_at"]}),Pa={name:"",code:"",type:kt.AMOUNT,value:0,started_at:Math.floor(Date.now()/1e3),ended_at:Math.floor(Date.now()/1e3)+7*24*60*60,limit_use:"",limit_use_with_user:"",limit_plan_ids:[],limit_period:[],generate_count:""};function Vr({defaultValues:s,refetch:t,type:a="create",dialogTrigger:n=e.jsxs(k,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"添加优惠券"})]}),open:r,onOpenChange:l}){const[c,d]=i.useState(!1),m=r??c,w=l??d,[j,b]=i.useState([]),x=Z({resolver:ee(Jm),defaultValues:s||Pa});i.useEffect(()=>{s&&x.reset(s)},[s,x]),i.useEffect(()=>{zs().then(({data:p})=>b(p))},[]);const y=p=>{if(!p)return;const _=(z,N)=>{const R=new Date(N*1e3);return z.setHours(R.getHours(),R.getMinutes(),R.getSeconds()),Math.floor(z.getTime()/1e3)};p.from&&x.setValue("started_at",_(p.from,x.watch("started_at"))),p.to&&x.setValue("ended_at",_(p.to,x.watch("ended_at")))},D=async p=>{try{await Jc(p),w(!1),a==="create"&&x.reset(Pa),t()}catch(_){console.error("保存优惠券失败:",_)}},T=(p,_)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:_}),e.jsx(C,{type:"datetime-local",step:"1",value:X(x.watch(p),"YYYY-MM-DDTHH:mm:ss"),onChange:z=>{const N=new Date(z.target.value);x.setValue(p,Math.floor(N.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(ue,{open:m,onOpenChange:w,children:[n&&e.jsx(Pe,{asChild:!0,children:n}),e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsx(ge,{children:e.jsx(he,{children:a==="create"?"添加优惠券":"编辑优惠券"})}),e.jsx(se,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(D),className:"space-y-4",children:[e.jsx(h,{control:x.control,name:"name",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"优惠券名称"}),e.jsx(C,{placeholder:"请输入优惠券名称",...p}),e.jsx(S,{})]})}),e.jsxs(u,{children:[e.jsx(g,{children:"优惠券类型和值"}),e.jsxs("div",{className:"flex",children:[e.jsx(h,{control:x.control,name:"type",render:({field:p})=>e.jsxs(B,{value:p.value.toString(),onValueChange:p.onChange,children:[e.jsx(U,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Y,{placeholder:"优惠券类型"})}),e.jsx(G,{children:Object.entries(Zt).map(([_,z])=>e.jsx(A,{value:_,children:z},_))})]})}),e.jsx(h,{control:x.control,name:"value",render:({field:p})=>e.jsx(C,{type:"number",placeholder:"请输入值",...p,onChange:_=>p.onChange(_.target.value===""?"":_.target.value),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:x.watch("type")===kt.AMOUNT?"¥":"%"})})]})]}),e.jsxs(u,{children:[e.jsx(g,{children:"优惠券有效期"}),e.jsxs(Be,{children:[e.jsx(Ye,{asChild:!0,children:e.jsxs(k,{variant:"outline",className:f("w-full justify-start text-left font-normal",!x.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(yt,{className:"mr-2 h-4 w-4"}),X(x.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ","至"," ",X(x.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})}),e.jsxs(Ke,{className:"w-auto p-0",align:"start",children:[e.jsx("div",{className:"border-b border-border",children:e.jsx(et,{mode:"range",selected:{from:new Date(x.watch("started_at")*1e3),to:new Date(x.watch("ended_at")*1e3)},onSelect:y,numberOfMonths:2})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-4",children:[T("started_at","开始时间"),e.jsx("div",{className:"mt-6 text-sm text-muted-foreground",children:"至"}),T("ended_at","结束时间")]})})]})]}),e.jsx(S,{})]}),e.jsx(h,{control:x.control,name:"limit_use",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"最大使用次数"}),e.jsx(C,{type:"number",min:0,placeholder:"限制最大使用次数,留空则不限制",...p,value:p.value===void 0?"":p.value,onChange:_=>p.onChange(_.target.value===""?"":_.target.value),className:"h-9"}),e.jsx(P,{className:"text-xs",children:"设置优惠券的总使用次数限制,留空表示不限制使用次数"}),e.jsx(S,{})]})}),e.jsx(h,{control:x.control,name:"limit_use_with_user",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"每个用户可使用次数"}),e.jsx(C,{type:"number",min:0,placeholder:"限制每个用户可使用次数,留空则不限制",...p,value:p.value===void 0?"":p.value,onChange:_=>p.onChange(_.target.value===""?"":_.target.value),className:"h-9"}),e.jsx(P,{className:"text-xs",children:"限制每个用户可使用该优惠券的次数,留空表示不限制单用户使用次数"}),e.jsx(S,{})]})}),e.jsx(h,{control:x.control,name:"limit_period",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"指定周期"}),e.jsx(Qs,{options:Object.entries(Ds).filter(([_])=>isNaN(Number(_))).map(([_,z])=>({label:z,value:_})),onChange:_=>{if(_.length===0){p.onChange([]);return}const z=_.map(N=>Ds[N.value]);p.onChange(z)},value:(p.value||[]).map(_=>({label:Object.entries(Ds).find(([z,N])=>N===_)?.[1]||"",value:Object.entries(Ds).find(([z,N])=>N===_)?.[0]||""})),placeholder:"限制指定周期可以使用优惠,留空则不限制",emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:"没有找到匹配的周期"})}),e.jsx(P,{className:"text-xs",children:"选择可以使用优惠券的订阅周期,留空表示不限制使用周期"}),e.jsx(S,{})]})}),e.jsx(h,{control:x.control,name:"limit_plan_ids",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"指定订阅"}),e.jsx(Qs,{options:j?.map(_=>({label:_.name,value:_.id.toString()}))||[],onChange:_=>p.onChange(_.map(z=>Number(z.value))),value:(j||[]).filter(_=>(p.value||[]).includes(_.id)).map(_=>({label:_.name,value:_.id.toString()})),placeholder:"限制指定订阅可以使用优惠,留空则不限制",emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:"没有找到匹配的订阅"})}),e.jsx(S,{})]})}),a==="create"&&e.jsxs(e.Fragment,{children:[e.jsx(h,{control:x.control,name:"code",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"自定义优惠码"}),e.jsx(C,{placeholder:"自定义优惠码,留空则自动生成",...p,className:"h-9"}),e.jsx(P,{className:"text-xs",children:"可以自定义优惠码,留空则系统自动生成"}),e.jsx(S,{})]})}),e.jsx(h,{control:x.control,name:"generate_count",render:({field:p})=>e.jsxs(u,{children:[e.jsx(g,{children:"批量生成数量"}),e.jsx(C,{type:"number",min:0,placeholder:"批量生成优惠码数量,留空则生成单个",...p,value:p.value===void 0?"":p.value,onChange:_=>p.onChange(_.target.value===""?"":_.target.value),className:"h-9"}),e.jsx(P,{className:"text-xs",children:"批量生成多个优惠码,留空则只生成单个优惠码"}),e.jsx(S,{})]})})]}),e.jsx(Fe,{children:e.jsx(k,{type:"submit",disabled:x.formState.isSubmitting,children:x.formState.isSubmitting?"保存中...":"保存"})})]})})]})]})}function Qm({table:s,refetch:t}){const a=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Vr,{refetch:t}),e.jsx(C,{placeholder:"搜索优惠券...",value:s.getColumn("name")?.getFilterValue()??"",onChange:n=>s.getColumn("name")?.setFilterValue(n.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(Wm,{column:s.getColumn("type"),title:"类型",options:Object.entries(Zt).map(([n,r])=>({value:n,label:r}))}),a&&e.jsxs(k,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["重置",e.jsx(Le,{className:"ml-2 h-4 w-4"})]})]})}const Rr=i.createContext(void 0);function Zm({children:s,refetch:t}){const[a,n]=i.useState(!1),[r,l]=i.useState(null),c=m=>{l(m),n(!0)},d=()=>{n(!1),l(null)};return e.jsxs(Rr.Provider,{value:{isOpen:a,currentCoupon:r,openEdit:c,closeEdit:d},children:[s,r&&e.jsx(Vr,{defaultValues:r,refetch:t,type:"edit",open:a,onOpenChange:n})]})}function Xm(){const s=i.useContext(Rr);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const eu=s=>[{accessorKey:"id",header:({column:t})=>e.jsx(F,{column:t,title:"ID"}),cell:({row:t})=>e.jsx(E,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(F,{column:t,title:"启用"}),cell:({row:t})=>e.jsx(O,{defaultChecked:t.original.show,onCheckedChange:a=>{Zc({id:t.original.id,show:a}).then(({data:n})=>!n&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(F,{column:t,title:"卷名称"}),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(F,{column:t,title:"类型"}),cell:({row:t})=>e.jsx(E,{variant:"outline",children:Zt[t.original.type]}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(F,{column:t,title:"卷码"}),cell:({row:t})=>e.jsx(E,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(F,{column:t,title:"剩余次数"}),cell:({row:t})=>e.jsx(E,{variant:"outline",children:t.original.limit_use===null?"无限次":t.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:t})=>e.jsx(F,{column:t,title:"可用次数/用户"}),cell:({row:t})=>e.jsx(E,{variant:"outline",children:t.original.limit_use_with_user===null?"无限制":t.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:t})=>e.jsx(F,{column:t,title:"有效期"}),cell:({row:t})=>{const[a,n]=i.useState(!1),r=Date.now(),l=t.original.started_at*1e3,c=t.original.ended_at*1e3,d=r>c,m=re.jsx(F,{className:"justify-end",column:t,title:"操作"}),cell:({row:t})=>{const{openEdit:a}=Xm();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(k,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>a(t.original),children:[e.jsx(ws,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:"编辑"})]}),e.jsx(Ue,{title:"确认删除",description:"此操作将永久删除该优惠券,删除后无法恢复。确定要继续吗?",confirmText:"删除",variant:"destructive",onConfirm:async()=>{Qc({id:t.original.id}).then(({data:n})=>{n&&(V.success("删除成功"),s())})},children:e.jsxs(k,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(Xe,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:"删除"})]})})]})}}];function su(){const[s,t]=i.useState({}),[a,n]=i.useState({}),[r,l]=i.useState([]),[c,d]=i.useState([]),[m,w]=i.useState({pageIndex:0,pageSize:10}),{refetch:j,data:b}=K({queryKey:["couponList",m,r,c],queryFn:()=>Wc({pageSize:m.pageSize,current:m.pageIndex+1,filter:r,sort:c})}),x=Re({data:b?.data??[],columns:eu(j),state:{sorting:c,columnVisibility:a,rowSelection:s,columnFilters:r,pagination:m},pageCount:Math.ceil((b?.total??0)/m.pageSize),rowCount:b?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:d,onColumnFiltersChange:l,onColumnVisibilityChange:n,onPaginationChange:w,getCoreRowModel:Me(),getFilteredRowModel:$e(),getPaginationRowModel:Ae(),getSortedRowModel:He(),getFacetedRowModel:es(),getFacetedUniqueValues:ss(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(Zm,{refetch:j,children:e.jsx("div",{className:"space-y-4",children:e.jsx(qe,{table:x,toolbar:e.jsx(Qm,{table:x,refetch:j})})})})}function tu(){return e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsx(Ce,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Se,{}),e.jsx(ke,{})]})]}),e.jsxs(Ne,{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:"优惠券管理"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"在这里可以查看优惠券,包括增加、查看、删除等操作。"})]})}),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(su,{})})]})]})}const au=Object.freeze(Object.defineProperty({__proto__:null,default:tu},Symbol.toStringTag,{value:"Module"}));function Fa({column:s,title:t,options:a}){const n=s?.getFacetedUniqueValues(),r=new Set(s?.getFilterValue());return e.jsxs(Be,{children:[e.jsx(Ye,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Ms,{className:"mr-2 h-4 w-4"}),t,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(le,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(E,{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(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):a.filter(l=>r.has(l.value)).map(l=>e.jsx(E,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(Ke,{className:"w-[200px] p-0",align:"start",children:e.jsxs(ts,{children:[e.jsx(hs,{placeholder:t}),e.jsxs(as,{children:[e.jsx(js,{children:"No results found."}),e.jsx(be,{children:a.map(l=>{const c=r.has(l.value);return e.jsxs(me,{onSelect:()=>{c?r.delete(l.value):r.add(l.value);const d=Array.from(r);s?.setFilterValue(d.length?d:void 0)},children:[e.jsx("div",{className:f("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",c?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(us,{className:f("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}),n?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:n.get(l.value)})]},l.value)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_s,{}),e.jsx(be,{children:e.jsx(me,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const nu=o.object({email_prefix:o.string().optional(),email_suffix:o.string().min(1),password:o.string().optional(),expired_at:o.number().optional().nullable(),plan_id:o.number().nullable(),generate_count:o.number().optional().nullable()}).refine(s=>s.generate_count===null?s.email_prefix!==void 0&&s.email_prefix!=="":!0,{message:"Email prefix is required when generate_count is null",path:["email_prefix"]}),ru={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0};function lu({refetch:s}){const[t,a]=i.useState(!1),n=Z({resolver:ee(nu),defaultValues:ru,mode:"onChange"}),[r,l]=i.useState([]);return i.useEffect(()=>{t&&zs().then(({data:c})=>{c&&l(c)})},[t]),e.jsxs(ue,{open:t,onOpenChange:a,children:[e.jsx(Pe,{asChild:!0,children:e.jsxs(H,{size:"sm",variant:"outline",className:"space-x-2",children:[e.jsx(ve,{icon:"ion:add"}),e.jsx("div",{children:"创建用户"})]})}),e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsxs(ge,{children:[e.jsx(he,{children:"创建用户"}),e.jsx(ze,{})]}),e.jsxs(se,{...n,children:[e.jsxs(u,{children:[e.jsx(g,{children:"邮箱"}),e.jsxs("div",{className:"flex",children:[!n.watch("generate_count")&&e.jsx(h,{control:n.control,name:"email_prefix",render:({field:c})=>e.jsx(C,{className:"flex-[5] rounded-r-none",placeholder:"帐号(批量生成请留空)",...c})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${n.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(h,{control:n.control,name:"email_suffix",render:({field:c})=>e.jsx(C,{className:"flex-[4] rounded-l-none",placeholder:"域",...c})})]})]}),e.jsx(h,{control:n.control,name:"password",render:({field:c})=>e.jsxs(u,{children:[e.jsx(g,{children:"密码"}),e.jsx(C,{placeholder:"留空则密码与邮件相同",...c}),e.jsx(S,{})]})}),e.jsx(h,{control:n.control,name:"expired_at",render:({field:c})=>e.jsxs(u,{className:"flex flex-col",children:[e.jsx(g,{children:"到期时间"}),e.jsxs(Be,{children:[e.jsx(Ye,{asChild:!0,children:e.jsx(v,{children:e.jsxs(H,{variant:"outline",className:f("w-full pl-3 text-left font-normal",!c.value&&"text-muted-foreground"),children:[c.value?X(c.value):e.jsx("span",{children:"请选择用户到期日期,留空为长期有效"}),e.jsx(yt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(Ke,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(no,{asChild:!0,children:e.jsx(H,{variant:"outline",className:"w-full",onClick:()=>{c.onChange(null)},children:"长期有效"})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(et,{mode:"single",selected:c.value?new Date(c.value*1e3):void 0,onSelect:d=>{d&&c.onChange(d?.getTime()/1e3)}})})]})]})]})}),e.jsx(h,{control:n.control,name:"plan_id",render:({field:c})=>e.jsxs(u,{children:[e.jsx(g,{children:"订阅计划"}),e.jsx(v,{children:e.jsxs(B,{value:c.value?c.value.toString():"null",onValueChange:d=>c.onChange(d==="null"?null:parseInt(d)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"无"})}),e.jsxs(G,{children:[e.jsx(A,{value:"null",children:"无"}),r.map(d=>e.jsx(A,{value:d.id.toString(),children:d.name},d.id))]})]})})]})}),!n.watch("email_prefix")&&e.jsx(h,{control:n.control,name:"generate_count",render:({field:c})=>e.jsxs(u,{children:[e.jsx(g,{children:"生成数量"}),e.jsx(C,{type:"number",placeholder:"如果为批量生产请输入生成数量",value:c.value||"",onChange:d=>c.onChange(d.target.value?parseInt(d.target.value):null)})]})})]}),e.jsxs(Fe,{children:[e.jsx(H,{variant:"outline",onClick:()=>a(!1),children:"取消"}),e.jsx(H,{onClick:()=>n.handleSubmit(c=>{td(c).then(({data:d})=>{d&&(V.success("生成成功"),n.reset(),s(),a(!1))})})(),children:"生成"})]})]})]})}function iu({table:s,refetch:t,serverGroupList:a}){const n=s.getState().columnFilters.length>0;return e.jsx("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(lu,{refetch:t}),e.jsx(C,{placeholder:"搜索用户邮箱...",value:s.getColumn("email")?.getFilterValue()??"",onChange:r=>s.getColumn("email")?.setFilterValue(r.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("banned")&&e.jsx(Fa,{column:s.getColumn("banned"),title:"用户状态",options:[{label:"正常",value:0},{label:"封禁",value:1}]}),s.getColumn("group_ids")&&e.jsx(Fa,{column:s.getColumn("group_ids"),title:"权限组",options:a.map(r=>({label:r.name,value:r.id}))}),n&&e.jsxs(k,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["重置筛选",e.jsx(Le,{className:"ml-2 h-4 w-4"})]})]})})}const ou=Ra,cu=Ma,du=za,Mr=i.forwardRef(({className:s,...t},a)=>e.jsx(ft,{className:f("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),...t,ref:a}));Mr.displayName=ft.displayName;const xu=ys("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"}}),zr=i.forwardRef(({side:s="right",className:t,children:a,...n},r)=>e.jsxs(du,{children:[e.jsx(Mr,{}),e.jsxs(pt,{ref:r,className:f(xu({side:s}),t),...n,children:[e.jsxs(Bt,{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(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),a]})]}));zr.displayName=pt.displayName;const Er=({className:s,...t})=>e.jsx("div",{className:f("flex flex-col space-y-2 text-center sm:text-left",s),...t});Er.displayName="SheetHeader";const Or=({className:s,...t})=>e.jsx("div",{className:f("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});Or.displayName="SheetFooter";const Lr=i.forwardRef(({className:s,...t},a)=>e.jsx(vt,{ref:a,className:f("text-lg font-semibold text-foreground",s),...t}));Lr.displayName=vt.displayName;const $r=i.forwardRef(({className:s,...t},a)=>e.jsx(bt,{ref:a,className:f("text-sm text-muted-foreground",s),...t}));$r.displayName=bt.displayName;const mu=o.object({id:o.number(),email:o.string().email(),invite_user_email:o.string().email().nullable().optional(),password:o.string().optional().nullable(),balance:o.coerce.number(),commission_balance:o.coerce.number(),u:o.number(),d:o.number(),transfer_enable:o.number(),expired_at:o.number().nullable(),plan_id:o.number().nullable(),banned:o.number(),commission_type:o.number(),commission_rate:o.number().nullable(),discount:o.number().nullable(),speed_limit:o.number().nullable(),is_admin:o.number(),is_staff:o.number(),remarks:o.string().nullable()});function Ar({refetch:s,defaultValues:t,dialogTrigger:a=e.jsxs(k,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[e.jsx(Ms,{className:"mr-2 h-4 w-4"}),"编辑用户信息"]})}){const[n,r]=i.useState(!1),[l,c]=i.useState(!1),d=Z({resolver:ee(mu),defaultValues:t,mode:"onChange"}),[m,w]=i.useState([]);return i.useEffect(()=>{n&&zs().then(({data:j})=>{w(j)})},[n]),e.jsxs(ou,{open:n,onOpenChange:r,children:[e.jsx(cu,{asChild:!0,children:a}),e.jsxs(zr,{className:"max-w-[90%] space-y-4 ",children:[e.jsxs(Er,{children:[e.jsx(Lr,{children:"用户管理"}),e.jsx($r,{})]}),e.jsxs(se,{...d,children:[e.jsx(h,{control:d.control,name:"email",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"邮箱"}),e.jsx(C,{...j,placeholder:"请输入邮箱"}),e.jsx(S,{...j})]})}),e.jsx(h,{control:d.control,name:"invite_user_email",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"邀请人邮箱"}),e.jsx(C,{value:j.value||"",onChange:b=>j.onChange(b.target.value?b.target.value:null),placeholder:"请输入邮箱"}),e.jsx(S,{...j})]})}),e.jsx(h,{control:d.control,name:"password",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"密码"}),e.jsx(C,{value:j.value||"",onChange:j.onChange,placeholder:"如需修改密码请输入"}),e.jsx(S,{...j})]})}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsx(h,{control:d.control,name:"balance",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"余额"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value||"",onChange:j.onChange,placeholder:"请输入余额",className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]}),e.jsx(S,{...j})]})}),e.jsx(h,{control:d.control,name:"commission_balance",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"佣金余额"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value||"",onChange:j.onChange,placeholder:"请输入佣金余额",className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]}),e.jsx(S,{...j})]})}),e.jsx(h,{control:d.control,name:"u",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"已用上行"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:(j.value/1024/1024/1024).toFixed(3)||"",onChange:b=>j.onChange(parseInt(b.target.value)*1024*1024*1024),placeholder:"已用上行",className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]}),e.jsx(S,{...j})]})}),e.jsx(h,{control:d.control,name:"d",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"已用下行"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:(j.value/1024/1024/1024).toFixed(3)||"",onChange:b=>j.onChange(parseInt(b.target.value)*1024*1024*1024),placeholder:"已用下行",className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]}),e.jsx(S,{...j})]})})]}),e.jsx(h,{control:d.control,name:"transfer_enable",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"流量"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value/1024/1024/1024||"",onChange:b=>j.onChange(parseInt(b.target.value)*1024*1024*1024),placeholder:"请输入流量",className:"rounded-r-none "}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]}),e.jsx(S,{})]})}),e.jsx(h,{control:d.control,name:"expired_at",render:({field:j})=>e.jsxs(u,{className:"flex flex-col",children:[e.jsx(g,{children:"到期时间"}),e.jsxs(Be,{open:l,onOpenChange:c,children:[e.jsx(Ye,{asChild:!0,children:e.jsx(v,{children:e.jsxs(k,{type:"button",variant:"outline",className:f("w-full pl-3 text-left font-normal",!j.value&&"text-muted-foreground"),onClick:()=>c(!0),children:[j.value?X(j.value):e.jsx("span",{children:"请选择用户到期日期,留空为长期有效"}),e.jsx(yt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Ke,{className:"w-auto p-0",align:"start",side:"top",sideOffset:4,onInteractOutside:b=>{b.preventDefault()},onEscapeKeyDown:b=>{b.preventDefault()},children:e.jsxs("div",{className:"flex flex-col space-y-3 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{j.onChange(null),c(!1)},children:"长期有效"}),e.jsx(k,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const b=new Date;b.setMonth(b.getMonth()+1),b.setHours(23,59,59,999),j.onChange(Math.floor(b.getTime()/1e3)),c(!1)},children:"一个月"}),e.jsx(k,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const b=new Date;b.setMonth(b.getMonth()+3),b.setHours(23,59,59,999),j.onChange(Math.floor(b.getTime()/1e3)),c(!1)},children:"三个月"})]}),e.jsx("div",{className:"rounded-md border",children:e.jsx(et,{mode:"single",selected:j.value?new Date(j.value*1e3):void 0,onSelect:b=>{if(b){const x=new Date(j.value?j.value*1e3:Date.now());b.setHours(x.getHours(),x.getMinutes(),x.getSeconds()),j.onChange(Math.floor(b.getTime()/1e3))}},disabled:b=>b{const b=new Date;b.setHours(23,59,59,999),j.onChange(Math.floor(b.getTime()/1e3))},className:"h-6 px-2 text-xs",children:"设为当天结束"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(C,{type:"datetime-local",step:"1",value:X(j.value,"YYYY-MM-DDTHH:mm:ss"),onChange:b=>{const x=new Date(b.target.value);isNaN(x.getTime())||j.onChange(Math.floor(x.getTime()/1e3))},className:"flex-1"}),e.jsx(k,{type:"button",variant:"outline",onClick:()=>c(!1),children:"确定"})]})]})]})})]}),e.jsx(S,{})]})}),e.jsx(h,{control:d.control,name:"plan_id",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"订阅计划"}),e.jsx(v,{children:e.jsxs(B,{value:j.value?j.value.toString():"null",onValueChange:b=>j.onChange(b==="null"?null:parseInt(b)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"无"})}),e.jsxs(G,{children:[e.jsx(A,{value:"null",children:"无"}),m.map(b=>e.jsx(A,{value:b.id.toString(),children:b.name},b.id))]})]})})]})}),e.jsx(h,{control:d.control,name:"banned",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"账户状态"}),e.jsx(v,{children:e.jsxs(B,{value:j.value.toString(),onValueChange:b=>j.onChange(parseInt(b)),children:[e.jsx(U,{children:e.jsx(Y,{})}),e.jsxs(G,{children:[e.jsx(A,{value:"1",children:"封禁"}),e.jsx(A,{value:"0",children:"正常"})]})]})})]})}),e.jsx(h,{control:d.control,name:"commission_type",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"佣金类型"}),e.jsx(v,{children:e.jsxs(B,{value:j.value.toString(),onValueChange:b=>j.onChange(parseInt(b)),children:[e.jsx(U,{children:e.jsx(Y,{placeholder:"无"})}),e.jsxs(G,{children:[e.jsx(A,{value:"0",children:"跟随系统设置"}),e.jsx(A,{value:"1",children:"循环返利"}),e.jsx(A,{value:"2",children:"首次返利"})]})]})})]})}),e.jsx(h,{control:d.control,name:"commission_rate",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"推荐返利比例"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value||"",onChange:b=>j.onChange(parseInt(b.currentTarget.value)||null),placeholder:"请输入推荐返利比例(为空则跟随站点设置返利比例)",className:"rounded-r-none "}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]}),e.jsx(S,{})]})}),e.jsx(h,{control:d.control,name:"discount",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"专享折扣比例"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value||"",onChange:b=>j.onChange(parseInt(b.currentTarget.value)||null),placeholder:"请输入专享折扣比例(为空则不享受专享折扣)",className:"rounded-r-none "}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]}),e.jsx(S,{})]})}),e.jsx(h,{control:d.control,name:"speed_limit",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"限速"}),e.jsxs("div",{className:"flex",children:[e.jsx(C,{type:"number",value:j.value||"",onChange:b=>j.onChange(parseInt(b.currentTarget.value)||null),placeholder:"留空则不限速",className:"rounded-r-none "}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"Mbps"})]}),e.jsx(S,{})]})}),e.jsx(h,{control:d.control,name:"is_admin",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"是否管理员"}),e.jsx("div",{className:"py-2",children:e.jsx(v,{children:e.jsx(O,{checked:j.value===1,onCheckedChange:b=>j.onChange(b?1:0)})})})]})}),e.jsx(h,{control:d.control,name:"is_staff",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"是否员工"}),e.jsx("div",{className:"py-2",children:e.jsx(v,{children:e.jsx(O,{checked:j.value===1,onCheckedChange:b=>j.onChange(b?1:0)})})})]})}),e.jsx(h,{control:d.control,name:"remarks",render:({field:j})=>e.jsxs(u,{children:[e.jsx(g,{children:"备注"}),e.jsx(gs,{className:"h-24",value:j.value||"",onChange:b=>j.onChange(b.currentTarget.value??null),placeholder:"请在这里记录"})]})})]}),e.jsxs(Or,{children:[e.jsx(k,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(k,{type:"submit",onClick:()=>{d.handleSubmit(j=>{ed(j).then(({data:b})=>{b&&(V.success("修改成功"),r(!1),s())}).catch(b=>{V.error("修改失败")})})()},children:"提交"})]})]})]})}const Hr=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"})}),Kr=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"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"})}),uu=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"})}),hu=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"})}),Rt=[{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:Oo(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Hr,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:Fs(s.original.u)})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Kr,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:Fs(s.original.d)})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const t=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(E,{variant:"outline",className:"font-mono",children:[t,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const t=(s.original.u+s.original.d)*s.original.server_rate;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:Fs(t)})}}];function qr({user_id:s,dialogTrigger:t}){const[a,n]=i.useState(!1),[r,l]=i.useState({pageIndex:0,pageSize:10}),{data:c,isLoading:d}=K({queryKey:["userStats",s,r,a],queryFn:()=>a?ad({user_id:s,pageSize:r.pageSize,page:r.pageIndex+1}):null}),m=Re({data:c?.data??[],columns:Rt,pageCount:Math.ceil((c?.total??0)/r.pageSize),state:{pagination:r},manualPagination:!0,getCoreRowModel:Me(),onPaginationChange:l});return e.jsxs(ue,{open:a,onOpenChange:n,children:[e.jsx(Pe,{asChild:!0,children:t}),e.jsxs(de,{className:"sm:max-w-[700px]",children:[e.jsx(ge,{children:e.jsx(he,{children:"流量使用记录"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Xt,{children:[e.jsx(ea,{children:m.getHeaderGroups().map(w=>e.jsx(xs,{children:w.headers.map(j=>e.jsx(ta,{className:f("h-10 px-2 text-xs",j.id==="total"&&"text-right"),children:j.isPlaceholder?null:mt(j.column.columnDef.header,j.getContext())},j.id))},w.id))}),e.jsx(sa,{children:d?Array.from({length:r.pageSize}).map((w,j)=>e.jsx(xs,{children:Array.from({length:Rt.length}).map((b,x)=>e.jsx(Is,{className:"p-2",children:e.jsx(Ve,{className:"h-6 w-full"})},x))},j)):m.getRowModel().rows?.length?m.getRowModel().rows.map(w=>e.jsx(xs,{"data-state":w.getIsSelected()&&"selected",className:"h-10",children:w.getVisibleCells().map(j=>e.jsx(Is,{className:"px-2",children:mt(j.column.columnDef.cell,j.getContext())},j.id))},w.id)):e.jsx(xs,{children:e.jsx(Is,{colSpan:Rt.length,className:"h-24 text-center",children:"暂无记录"})})})]})}),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:"每页显示"}),e.jsxs(B,{value:`${m.getState().pagination.pageSize}`,onValueChange:w=>{m.setPageSize(Number(w))},children:[e.jsx(U,{className:"h-8 w-[70px]",children:e.jsx(Y,{placeholder:m.getState().pagination.pageSize})}),e.jsx(G,{side:"top",children:[10,20,30,40,50].map(w=>e.jsx(A,{value:`${w}`,children:w},w))})]}),e.jsx("p",{className:"text-sm font-medium",children:"条记录"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("div",{className:"flex w-[100px] items-center justify-center text-sm",children:["第 ",m.getState().pagination.pageIndex+1," /"," ",m.getPageCount()," 页"]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(H,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>m.previousPage(),disabled:!m.getCanPreviousPage()||d,children:e.jsx(uu,{className:"h-4 w-4"})}),e.jsx(H,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>m.nextPage(),disabled:!m.getCanNextPage()||d,children:e.jsx(hu,{className:"h-4 w-4"})})]})]})]})]})]})]})}const ju=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M5 18h4.24a1 1 0 0 0 .71-.29l6.92-6.93L19.71 8a1 1 0 0 0 0-1.42l-4.24-4.29a1 1 0 0 0-1.42 0l-2.82 2.83l-6.94 6.93a1 1 0 0 0-.29.71V17a1 1 0 0 0 1 1m9.76-13.59l2.83 2.83l-1.42 1.42l-2.83-2.83ZM6 13.17l5.93-5.93l2.83 2.83L8.83 16H6ZM21 20H3a1 1 0 0 0 0 2h18a1 1 0 0 0 0-2"})}),gu=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"})}),fu=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"})}),pu=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"})}),vu=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"})}),bu=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"})}),yu=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"})}),Nu=(s,t)=>[{accessorKey:"id",header:({column:a})=>e.jsx(F,{column:a,title:"ID"}),cell:({row:a})=>e.jsx(E,{variant:"outline",children:a.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:a})=>e.jsx(F,{column:a,title:"邮箱"}),cell:({row:a})=>{const n=a.original.t||0,r=Date.now()/1e3-n<120,l=Math.floor(Date.now()/1e3-n);let c=r?"当前在线":n===0?"从未在线":`最后在线时间: ${X(n)}`;if(!r&&n!==0){const d=Math.floor(l/60),m=Math.floor(d/60),w=Math.floor(m/24);w>0?c+=` 离线时长: ${w}天`:m>0?c+=` 离线时长: ${m}小时`:d>0?c+=` 离线时长: ${d}分钟`:c+=`