PageSourceSearch

https://xyc.ai/static/js/async/6728.fcf61aa822.js

js xyc.ai collected 2026-10-05 14:40:15 UTC 105,171 bytes, 1 lines download raw bytes

1"use strict";(self.rspackChunknewapi_web=self.rspackChunknewapi_web||[]).push([[6728],{71067(e,t,s){s.r(t),s.d(t,{component:()=>tx});var a=s(72361),r=s(68413),n=s(6702),i=s(20598),l=s(20032),o=s(64577),d=s(3642),c=s(61631),m=s(29760),u=s(81204),x=s(99170),p=s(38610),h=s(67267),f=s(10601),g=s(96962),b=s(53540),y=s(55667),j=s(63742),N=s(46775),v=s(54023),w=s(32999);function k(){let{t:e}=(0,n.Bd)(),t=(0,g.jE)(),[s,l]=(0,r.useState)(""),[m,u]=(0,r.useState)(""),{data:x,isLoading:p}=(0,b.I)({queryKey:["cache-refund-candidates",m],queryFn:async()=>(await o.FH.get("/api/admin/cache-refund/candidates",{params:{days:7,username:m||void 0}})).data.data??[],staleTime:6e4}),h=(0,y.n)({mutationFn:async e=>(await o.FH.post("/api/admin/cache-refund/approve",{user_id:e.user_id,day:e.day})).data,onSuccess:s=>{s.success?(i.oR.success(e("Refund approved and credited")),t.invalidateQueries({queryKey:["cache-refund-candidates"]})):i.oR.error(s.message||e("Approval failed"))},onError:()=>i.oR.error(e("Approval failed"))}),f=x??[];return(0,a.jsxs)("section",{className:"border-border/70 bg-card rounded-lg border p-4 sm:p-5",children:[(0,a.jsxs)("div",{className:"mb-3 flex flex-wrap items-end justify-between gap-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-base font-semibold",children:e("Cache refund review")}),(0,a.jsx)("p",{className:"text-muted-foreground mt-1 text-xs",children:e("Daily aggregated 1h-cache creation charges with zero cache hits (last 7 days). Approving recalculates server-side and credits the user.")})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(c.vji,{className:"text-muted-foreground absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2"}),(0,a.jsx)(v.p,{className:"h-8 w-52 pl-8 text-sm",placeholder:e("Search by username"),value:s,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&u(s.trim())}})]}),(0,a.jsx)(N.$,{variant:"outline",size:"sm",className:"h-8",onClick:()=>u(s.trim()),children:e("Search")})]})]}),p?(0,a.jsx)("div",{className:"text-muted-foreground py-8 text-center text-sm",children:e("Loading...")}):0===f.length?(0,a.jsx)("div",{className:"text-muted-foreground py-8 text-center text-sm",children:e("No cache anomalies detected")}):(0,a.jsxs)(w.XI,{children:[(0,a.jsx)(w.A0,{children:(0,a.jsxs)(w.Hj,{children:[(0,a.jsx)(w.nd,{children:e("Date")}),(0,a.jsx)(w.nd,{children:e("Username")}),(0,a.jsx)(w.nd,{className:"text-right",children:e("Requests")}),(0,a.jsx)(w.nd,{className:"text-right",children:e("Creation tokens")}),(0,a.jsx)(w.nd,{className:"text-right",children:e("Refund amount")}),(0,a.jsx)(w.nd,{className:"text-right",children:e("Actions")})]})}),(0,a.jsx)(w.BF,{children:f.map(t=>(0,a.jsxs)(w.Hj,{children:[(0,a.jsx)(w.nA,{className:"font-mono text-xs",children:t.day}),(0,a.jsx)(w.nA,{className:"max-w-[16rem] truncate font-mono text-xs",children:t.username}),(0,a.jsx)(w.nA,{className:"text-right tabular-nums",children:t.error_count}),(0,a.jsx)(w.nA,{className:"text-right tabular-nums",children:t.creation_tokens.toLocaleString()}),(0,a.jsx)(w.nA,{className:"text-right font-semibold tabular-nums",children:(0,d.eN)(t.refund_quota)}),(0,a.jsx)(w.nA,{className:"text-right",children:t.approved?(0,a.jsx)(j.E,{variant:"secondary",children:e("Refunded")}):(0,a.jsx)(N.$,{size:"sm",className:"h-7 px-3 text-xs",disabled:h.isPending,onClick:()=>h.mutate(t),children:e("Approve")})})]},`${t.user_id}-${t.day}`))})]})]})}var _=s(47888),S=s(1755);function C(e){let{t}=(0,n.Bd)(),[s,l]=(0,r.useState)(!1),d=(0,r.useRef)(e.onPaid);return(0,r.useEffect)(()=>{d.current=e.onPaid},[e.onPaid]),(0,r.useEffect)(()=>{if(!e.open||!e.tradeNo||s)return;let a=setInterval(async()=>{try{let s=await o.FH.get("/api/user/topup/self",{params:{keyword:e.tradeNo,p:1,page_size:1}}),a=(s.data?.data?.items??[]).find(t=>t.trade_no===e.tradeNo);a&&"success"===a.status&&(l(!0),i.oR.success(t("Payment successful, balance credited")),d.current?.())}catch{}},3e3);return()=>clearInterval(a)},[e.open,e.tradeNo,s,t]),(0,r.useEffect)(()=>{if(!s)return;let t=setTimeout(()=>e.onOpenChange(!1),1600);return()=>clearTimeout(t)},[s]),(0,r.useEffect)(()=>{e.open&&l(!1)},[e.open,e.tradeNo]),(0,a.jsx)(S.lG,{open:e.open,onOpenChange:e.onOpenChange,children:(0,a.jsxs)(S.Cf,{className:"sm:max-w-sm",children:[(0,a.jsxs)(S.c7,{children:[(0,a.jsx)(S.L3,{children:t("Alipay QR Code Payment")}),(0,a.jsx)(S.rr,{children:t("Corporate Alipay account, supports business transfers")})]}),(0,a.jsx)("div",{className:"flex justify-center py-2",children:s?(0,a.jsxs)("div",{className:"flex h-[256px] w-[256px] flex-col items-center justify-center gap-3",children:[(0,a.jsx)(c.rW7,{className:"text-success size-14",strokeWidth:1.5}),(0,a.jsx)("p",{className:"text-base font-medium",children:t("Payment Successful")}),(0,a.jsx)("p",{className:"text-text-tertiary text-xs",children:t("Balance credited. This window will close shortly.")})]}):(0,a.jsx)("div",{className:"border-border rounded-md border bg-white p-4",children:e.qr?(0,a.jsx)(_.h,{value:e.qr,size:224,marginSize:0}):null})}),!s&&(0,a.jsx)("p",{className:"text-text-tertiary text-center text-xs leading-relaxed",children:t("Scan the QR code with Alipay to complete payment. This window will close automatically after payment.")})]})})}var q=s(33120),F=s(3676);function A(e){let{open:t,onOpenChange:s,topups:i,topupsLoading:l,title:o,submitting:d,onRefreshTopups:m,onSubmit:x,onSubmitMonthly:p,monthlyBill:h=null,mode:f="detail",amountTarget:g=""}=e,{t:b}=(0,n.Bd)(),[y,j]=(0,r.useState)(new Set),[v,w]=(0,r.useState)("normal"),[k,_]=(0,r.useState)(!1),C="month"===f&&!!h;(0,r.useEffect)(()=>{t&&m()},[t,m]),(0,r.useEffect)(()=>
1{if(t)if("amount"===f&&Number(g)>0){let e=new Set,t=0;for(let s of i)if(e.add(s.id),(t+=s.money)>=Number(g))break;j(e)}else j(new Set(i.map(e=>e.id)))},[g,f,t,i]);let A=(0,r.useMemo)(()=>C?h?.amount_yuan??0:i.filter(e=>y.has(e.id)).reduce((e,t)=>e+t.money,0),[C,h,i,y]),z=(0,r.useMemo)(()=>{let e="special"===v?.06:.01;return C?(h?.amount_usd??0)*e:i.filter(e=>y.has(e.id)).reduce((e,t)=>e+(t.amount||0),0)*e},[v,C,h,i,y]),R=e=>{j(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},I=!!o&&!!o.company_name,M=A>=490&&I&&!d&&(C||y.size>0),T=async()=>{(C&&p&&h?await p({month:h.month,use_title:!0,invoice_type:v,need_xml:k}):await x({topup_ids:Array.from(y),use_title:!0,invoice_type:v,need_xml:k}))&&s(!1)};return(0,a.jsx)(S.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(S.Cf,{className:"max-sm:w-[calc(100vw-1.5rem)] sm:max-w-lg",children:[(0,a.jsxs)(S.c7,{children:[(0,a.jsx)(S.L3,{className:"text-xl font-semibold",children:b("Apply for Invoice")}),(0,a.jsx)(S.rr,{children:"amount"===f&&Number(g)>0?`Orders totaling \xa5${Number(g).toFixed(2)} were preselected; you can adjust them before submitting.`:"month"===f?"Eligible orders for the selected month were loaded; you can adjust them before submitting.":b("Select paid topup orders to merge into one invoice")})]}),(0,a.jsxs)("div",{className:"space-y-3 py-2",children:[(0,a.jsx)("p",{className:"rounded-md bg-amber-50/60 px-3 py-2 text-xs font-medium text-amber-700 dark:bg-amber-950/20 dark:text-amber-400",children:b("All prices exclude tax")}),(0,a.jsx)(F.F,{className:C?"rounded-md border":"h-64 rounded-md border",children:C?(0,a.jsxs)("div",{className:"space-y-1.5 px-4 py-4 text-sm",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:b("Billing month")}),(0,a.jsx)("span",{className:"font-medium",children:h?.month})]}),(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:b("Monthly consumption")}),(0,a.jsxs)("span",{className:"font-mono",children:["$",h?.amount_usd.toFixed(2)," ≈ ¥",h?.amount_yuan.toFixed(2)]})]}),(0,a.jsx)("p",{className:"text-muted-foreground pt-1 text-xs",children:b("Consumption bill for the full month (through the last hour of the month)")})]}):l?(0,a.jsxs)("div",{className:"text-muted-foreground flex h-64 items-center justify-center text-sm",children:[(0,a.jsx)(c.krw,{className:"mr-2 h-4 w-4 animate-spin"}),b("Loading...")]}):0===i.length?(0,a.jsx)("div",{className:"text-muted-foreground flex h-64 items-center justify-center px-4 text-center text-sm",children:b("No invoiceable topup orders available")}):(0,a.jsx)("ul",{className:"divide-border divide-y",children:i.map(e=>(0,a.jsx)("li",{children:(0,a.jsxs)("div",{role:"button",tabIndex:0,onClick:()=>R(e.id),onKeyDown:t=>{(" "===t.key||"Enter"===t.key)&&(t.preventDefault(),R(e.id))},className:"hover:bg-muted/40 flex cursor-pointer items-center gap-3 px-3 py-2.5",children:[(0,a.jsx)(q.S,{checked:y.has(e.id),className:"pointer-events-none",tabIndex:-1}),(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsx)("p",{className:"truncate font-mono text-xs",children:e.trade_no}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:new Date(1e3*e.create_time).toLocaleString()})]}),(0,a.jsxs)("span",{className:"font-mono text-sm font-medium",children:["¥",e.money.toFixed(2)]})]})},e.id))})}),(0,a.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:b("Total")}),(0,a.jsxs)("span",{className:"font-mono text-lg font-semibold",children:["¥",A.toFixed(2)]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("div",{className:"flex items-center justify-between gap-2",children:(0,a.jsx)("span",{className:"text-sm font-medium",children:b("Invoice type")})}),(0,a.jsxs)("p",{className:"bg-muted/60 text-muted-foreground rounded-md px-3 py-2 text-xs",children:[b("Default invoice item name"),":"," ",(0,a.jsx)("span",{className:"text-foreground font-medium",children:"*生产生活服务*技术服务费"})," · ",b("For special requirements, please contact support")]}),(0,a.jsxs)("div",{className:"grid gap-2 sm:grid-cols-2",children:[(0,a.jsxs)("button",{type:"button","aria-pressed":"special"===v,onClick:()=>w("special"),className:(0,u.cn)("rounded-md border px-3 py-2 text-left transition-colors","special"===v?"border-primary bg-primary/5 ring-primary/20 ring-2":"border-border hover:bg-muted/50"),children:[(0,a.jsx)("span",{className:"block text-sm font-medium",children:b("Special invoice")}),(0,a.jsx)("span",{className:"text-muted-foreground mt-0.5 block text-xs",children:b("Tax and handling, 6% total")})]}),(0,a.jsxs)("button",{type:"button","aria-pressed":"normal"===v,onClick:()=>w("normal"),className:(0,u.cn)("rounded-md border px-3 py-2 text-left transition-colors","normal"===v?"border-primary bg-primary/5 ring-primary/20 ring-2":"border-border hover:bg-muted/50"),children:[(0,a.jsx)("span",{className:"block text-sm font-medium",children:b("Standard invoice")}),(0,a.jsx)("span",{className:"text-muted-foreground mt-0.5 block text-xs",children:"1% tax"})]})]})]}),z>0&&(0,a.jsxs)("div",{className:"flex items-center justify-between text-xs",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:"special"===v?"Tax and handling (special invoice 6%, deducted on submit)":"Tax (standard invoice 1%, deducted on submit)"}),(0,a.jsxs)("span",{className:"font-mono",children:["$",z.toFixed(2)]})]}),(0,a.jsxs)("div",{role:"checkbox","aria-checked":k,tabIndex:0,onClick:()=>_(e=>!e),onKeyDown:e=>
1{(" "===e.key||"Enter"===e.key)&&(e.preventDefault(),_(e=>!e))},className:"flex cursor-pointer items-center gap-2 text-sm select-none",children:[(0,a.jsx)(q.S,{checked:k,className:"pointer-events-none",tabIndex:-1}),(0,a.jsx)("span",{children:b("I need the invoice in XML format")})]}),!I&&(0,a.jsx)("p",{className:"text-destructive text-xs",children:b("Please save your invoice information first")}),I&&A>0&&A<490&&(0,a.jsx)("p",{className:"text-destructive text-xs",children:b("Minimum invoice amount is 500 CNY")})]}),(0,a.jsxs)(S.Es,{className:"grid grid-cols-2 gap-2 sm:flex",children:[(0,a.jsx)(N.$,{variant:"outline",onClick:()=>s(!1),disabled:d,children:b("Cancel")}),(0,a.jsxs)(N.$,{onClick:T,disabled:!M,children:[d&&(0,a.jsx)(c.krw,{className:"mr-2 h-4 w-4 animate-spin"}),b("Submit")]})]})]})})}var z=s(61309);let R={company_name:"",tax_number:"",bank_name:"",bank_account:"",address:"",phone:"",email:""};function I(e){let{open:t,onOpenChange:s,title:i,saving:l,onSave:o}=e,{t:d}=(0,n.Bd)(),[m,u]=(0,r.useState)(R);(0,r.useEffect)(()=>{t&&u(i??R)},[t,i]);let x=""!==m.company_name.trim()&&""!==m.tax_number.trim()&&""!==m.email.trim()&&!l,p=async()=>{await o({company_name:m.company_name.trim(),tax_number:m.tax_number.trim(),bank_name:m.bank_name.trim(),bank_account:m.bank_account.trim(),address:m.address.trim(),phone:m.phone.trim(),email:m.email.trim()})&&s(!1)},h=[{key:"company_name",label:d("Company Name"),required:!0},{key:"tax_number",label:d("Tax Number"),required:!0},{key:"email",label:d("Email"),required:!0}];return(0,a.jsx)(S.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(S.Cf,{className:"max-sm:w-[calc(100vw-1.5rem)] sm:max-w-md",children:[(0,a.jsxs)(S.c7,{children:[(0,a.jsx)(S.L3,{className:"text-xl font-semibold",children:d("Invoice Information")}),(0,a.jsx)(S.rr,{children:d("Enterprise invoice header used for invoice requests")})]}),(0,a.jsx)("div",{className:"grid gap-3 py-2",children:h.map(e=>(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsxs)(z.J,{htmlFor:`invoice-${e.key}`,className:"text-xs",children:[e.label,e.required&&(0,a.jsx)("span",{className:"text-destructive ml-0.5",children:"*"})]}),(0,a.jsx)(v.p,{id:`invoice-${e.key}`,type:"email"===e.key?"email":"text",value:m[e.key],onChange:t=>{var s,a;return s=e.key,a=t.target.value,void u(e=>({...e,[s]:a}))}})]},e.key))}),(0,a.jsxs)(S.Es,{className:"grid grid-cols-2 gap-2 sm:flex",children:[(0,a.jsx)(N.$,{variant:"outline",onClick:()=>s(!1),disabled:l,children:d("Cancel")}),(0,a.jsxs)(N.$,{onClick:p,disabled:!x,children:[l&&(0,a.jsx)(c.krw,{className:"mr-2 h-4 w-4 animate-spin"}),d("Save")]})]})]})})}var M=s(52946),T=s(18692),$=s(18434),E=s(99198),P=s(42324);function D(e){return e===E.J1.STRIPE}function L(e){return e===E.J1.WAFFO_PANCAKE}function O(e){return e?e.pay_methods?.length>0?e.pay_methods[0].type:e.enable_stripe_topup?E.J1.STRIPE:e.enable_waffo_topup?E.J1.WAFFO:e.enable_waffo_pancake_topup?E.J1.WAFFO_PANCAKE:E.Ar:E.Ar}function H(e){let t=Number(e);return!Number.isFinite(t)||t<=0?10:Math.max(t,10)}function B(e){return e?e.enable_online_topup?H(e.min_topup):e.enable_stripe_topup?H(e.stripe_min_topup):e.enable_waffo_topup?H(e.waffo_min_topup):e.enable_waffo_pancake_topup?H(e.waffo_pancake_min_topup):10:10}var U=s(19376);let W="u">typeof globalThis&&"location"in globalThis;function G(e){let{open:t,onOpenChange:s,onConfirm:r,topupAmount:i,paymentAmount:l,paymentMethod:o,calculating:d,processing:m,discountRate:x=1,usdExchangeRate:p=1}=e,{t:h}=(0,n.Bd)(),f=x>0&&x<1&&l>0,g=f?l/x:0,b=f?g-l:0;return(0,a.jsx)(T.Lt,{open:t,onOpenChange:s,children:(0,a.jsxs)(T.EO,{className:"max-sm:w-[calc(100vw-1.5rem)] sm:max-w-md",children:[(0,a.jsxs)(T.wd,{children:[(0,a.jsx)(T.r7,{className:"text-xl font-semibold",children:h("Confirm Payment")}),(0,a.jsx)(T.$v,{children:h("Review your payment details")})]}),(0,a.jsxs)("div",{className:"space-y-3 py-3 sm:space-y-4 sm:py-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-muted-foreground text-sm",children:h("Topup Amount")}),(0,a.jsx)("span",{className:"text-lg font-semibold",children:(0,M.QO)(i*p,{digitsLarge:2,digitsSmall:2,abbreviate:!1})})]}),(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-muted-foreground text-sm",children:h("You Pay")}),d?(0,a.jsx)($.E,{className:"h-6 w-24"}):(0,a.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,a.jsx)("span",{className:"text-2xl font-semibold",children:(0,P.vv)(l)}),f&&(0,a.jsx)("span",{className:"text-muted-foreground text-sm line-through",children:(0,P.vv)(g)})]})]}),f&&!d&&(0,a.jsx)("div",{className:"bg-muted/50 rounded-lg p-3",children:(0,a.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:h("You save")}),(0,a.jsx)("span",{className:"font-semibold text-green-600",children:(0,P.vv)(b)})]})}),(0,a.jsx)("div",{className:"border-t pt-4",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-muted-foreground text-sm",children:h("Payment Method")}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"h-4 w-4",s=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,n=(0,u.cn)("shrink-0",t),i=function(e){let t;if(!e)return null;let s=e.trim();if(!s)return null;try{t=W?new URL(s,globalThis.location.href):new URL(s)}catch{return null}return"http:"!==t.protocol&&"https:"!==t.protocol||t.username||t.password?null:t.toString()}(s);if(i)return(0,a.jsx)("span",{className:(0,u.cn)("inline-flex items-center justify-center overflow-hidden rounded-[4px] bg-white/90 ring-1 ring-black/10",n),children:(0,a.jsx)("img",{src:i,alt:r||e||"payment",className:"block size-[82%] object-contain",loading:"lazy",decoding:"async",referrerPolicy:"no-referrer"})});if(!e)return(0,a.jsx)(c.y5g,{className:n});switch(e){case E.J1.ALIPAY:return(0,a.jsx)(c.HD8,{className:n});case E.J1.WECHAT:return(0,a.jsx)(c.oFn,{className:n});case E.J1.STRIPE:return(0,a.jsx)(c.y5g,{className:n});case E.J1.CREEM:return(0,a.jsx)(c.lTC,{className:n});case E.J1.WAFFO:return(0,a.jsx)(c.y5g,{className:n});case E.J1.WAFFO_PANCAKE:return(0,a.jsxs)("span",{className:(0,u.cn)("inline-flex items-center justify-center overflow-hidden rounded-[4px] bg-white/90 ring-1 ring-black/10",n),children:[(0,a.jsx)("img",{src:"/waffo-logo-light.svg",alt:U.Ay.t("Waffo"),className:"block size-[82%] object-contain dark:hidden"}),(0,a.jsx)("img",{src:"/waffo-logo-dark.svg",alt:U.Ay.t("Waffo"),className:"hidden size-[82%] object-contain dark:block"})]});default:return(0,a.jsx)(c.y5g,{className:n})}}(o?.type,"h-4 w-4",o?.icon,o?.name),(0,a.jsx)("span",{className:"font-medium",children:o?.name})]})]})})]}),(0,a.jsxs)(T.ck,{className:"grid grid-cols-2 gap-2 sm:flex",children:[(0,a.jsx)(T.Zr,{disabled:m,children:h("Cancel")}),(0,a.jsxs)(T.Rx,{onClick:r,disabled:m,children:[m&&(0,a.jsx)(c.krw,{className:"mr-2 h-4 w-4 animate-spin"}),h("Confirm Payment")]})]})]})})}function J(e){return!0===e.success||"success"===e.message}async function K(){return(await o.FH.get("/api/user/topup/info")).data}async function Y(e){return(await o.FH.post("/api/user/amount",e,{skipBusinessError:!0})).data}async function V(e){return(await o.FH.post("/api/user/stripe/amount",e,{skipBusinessError:!0})).data}async function Q(e){let t=await o.FH.post("/api/user/pay",e,{skipBusinessError:!0});return{...t.data,url:t.data.url||t.url}}async function X(e){return(await o.FH.post("/api/user/stripe/pay",e,{skipBusinessError:!0})).data}async function Z(e){return(await o.FH.post("/api/user/creem/pay",e,{skipBusinessError:!0})).data}async function ee(e){return(await o.FH.post("/api/user/plisio/pay",e,{skipBusinessError:!0})).data}async function et(){return(await o.FH.get("/api/user/plisio/currencies")).data}async function es(e){return(await o.FH.post("/api/user/waffo-pancake/amount",e,{skipBusinessError:!0})).data}async function ea(e){return(await o.FH.post("/api/user/waffo-pancake/
1pay",e,{skipBusinessError:!0})).data}async function er(e,t,s){let a=new URLSearchParams({p:e.toString(),page_size:t.toString()});return s&&a.append("keyword",s),(await o.FH.get(`/api/user/topup/self?${a.toString()}`)).data}async function en(e,t,s){let a=new URLSearchParams({p:e.toString(),page_size:t.toString()});return s&&a.append("keyword",s),(await o.FH.get(`/api/user/topup?${a.toString()}`)).data}async function ei(e){return(await o.FH.post("/api/user/topup/complete",e)).data}async function el(){return(await o.FH.get("/api/invoice/title")).data}async function eo(e){return(await o.FH.post("/api/invoice/title",e)).data}async function ed(){return(await o.FH.get("/api/invoice/topups")).data}async function ec(e){return(await o.FH.post("/api/invoice/request",e)).data}async function em(e,t){let s=new URLSearchParams({p:e.toString(),page_size:t.toString()});return(await o.FH.get(`/api/invoice/request/self?${s.toString()}`)).data}async function eu(){return(await o.FH.get("/api/invoice/monthly-bills")).data}async function ex(e){return(await o.FH.get("/api/invoice/monthly-bills/detail",{params:{month:e}})).data}async function ep(e){return(await o.FH.post("/api/invoice/request/monthly",e)).data}async function eh(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{let s=(await o.FH.get(e,{responseType:"blob"})).data;if(s.type.includes("application/json")){let e=await s.text();try{let t=JSON.parse(e);if(t&&!1===t.success)return i.oR.error(t.message||"Failed to load file"),!1}catch{}}let a=URL.createObjectURL(s);if(t.download){let e=document.createElement("a");e.href=a,e.download=t.filename||"download",document.body.appendChild(e),e.click(),e.remove()}else window.open(a,"_blank");return setTimeout(()=>URL.revokeObjectURL(a),6e4),!0}catch{return i.oR.error("Failed to load file"),!1}}function ef(e){return e.includes(".")?e.replace(/0+$/,"").replace(/\.$/,""):e}function eg(e){let{label:t,value:s}=e,{t:l}=(0,n.Bd)(),[o,d]=(0,r.useState)(!1);return(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("p",{className:"text-text-secondary text-xs",children:t}),(0,a.jsxs)("div",{className:"border-border flex items-center gap-2 rounded-md border px-3 py-2",children:[(0,a.jsx)("code",{className:"min-w-0 flex-1 truncate font-mono text-sm",children:s}),(0,a.jsx)("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(s),d(!0),i.oR.success(l("Copied to clipboard")),window.setTimeout(()=>d(!1),1500)},className:"text-icon hover:text-foreground shrink-0","aria-label":`${l("Copy")} ${t}`,children:o?(0,a.jsx)(c.Jlk,{className:"size-4 text-emerald-600"}):(0,a.jsx)(c.QRo,{className:"size-4"})})]})]})}function eb(e){let{expireUtc:t}=e,[s,n]=(0,r.useState)(()=>Math.max(0,t-Math.floor(Date.now()/1e3)));if((0,r.useEffect)(()=>{let e=setInterval(()=>{n(Math.max(0,t-Math.floor(Date.now()/1e3)))},1e3);return()=>clearInterval(e)},[t]),!t)return null;let i=Math.floor(s/60),l=s%60;return(0,a.jsxs)("span",{className:"font-mono tabular-nums",children:[i,":",l<10?`0${l}`:l]})}function ey(e){let{t}=(0,n.Bd)(),{createPlisioInvoice:s,processing:l}=function(){let[e,t]=(0,r.useState)(!1);return{processing:e,createPlisioInvoice:(0,r.useCallback)(async(e,s)=>{t(!0);try{let t=await ee({amount:e,currency:s}),a="object"==typeof t.data&&t.data?t.data:null;if(J(t)&&a&&a.wallet_hash)return{orderId:a.order_id??"",walletHash:a.wallet_hash,amount:a.amount??"",currency:a.currency??s,qrCode:a.qr_code??"",expireUtc:a.expire_utc??0};let r="string"==typeof t.data&&t.data?t.data:t.message;return i.oR.error(r||U.Ay.t("Failed to create order")),null}catch(e){return i.oR.error(U.Ay.t("Failed to create order")),null}finally{t(!1)}},[])}}(),[d,m]=(0,r.useState)(null),[u,x]=(0,r.useState)(!1),p=(0,r.useRef)(e.onPaid);(0,r.useEffect)(()=>{p.current=e.onPaid},[e.onPaid]),(0,r.useEffect)(()=>{e.open&&(m(null),x(!1))},[e.open]);let{data:h,isLoading:f}=(0,b.I)({queryKey:["plisio-currencies"],queryFn:et,enabled:e.open,staleTime:3e5}),g=h?.data??[],y=async t=>{let a=await s(e.amount,t);a&&m(a)};return(0,r.useEffect)(()=>{if(!e.open||!d?.orderId||u)return;let s=setInterval(async()=>{try{let e=await o.FH.get("/api/user/topup/self",{params:{keyword:d.orderId,p:1,page_size:1}}),s=(e.data?.data?.items??[]).find(e=>e.trade_no===d.orderId);s&&"success"===s.status&&(x(!0),i.oR.success(t("Payment successful, balance credited")),p.current?.())}catch{}},3e3);return()=>clearInterval(s)},[e.open,d?.orderId,u,t]),(0,r.useEffect)(()=>
1{if(!u)return;let t=setTimeout(()=>e.onOpenChange(!1),1800);return()=>clearTimeout(t)},[u]),(0,a.jsx)(S.lG,{open:e.open,onOpenChange:e.onOpenChange,children:(0,a.jsxs)(S.Cf,{className:"sm:max-w-md",children:[(0,a.jsxs)(S.c7,{children:[(0,a.jsx)(S.L3,{children:t("Cryptocurrency Payment")}),(0,a.jsx)(S.rr,{children:d?t("Send the specified amount to the address below (top-up ${{amount}})",{amount:e.amount}):t("Select a cryptocurrency to pay with")})]}),u?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center gap-3 py-10",children:[(0,a.jsx)(c.rW7,{className:"text-success size-14",strokeWidth:1.5}),(0,a.jsx)("p",{className:"text-base font-medium",children:t("Payment Successful")}),(0,a.jsx)("p",{className:"text-text-tertiary text-xs",children:t("Balance credited. This window will close shortly.")})]}):d?(0,a.jsxs)("div",{className:"space-y-4 py-2",children:[(0,a.jsx)("div",{className:"flex justify-center",children:(0,a.jsx)("div",{className:"border-border rounded-md border bg-white p-3",children:d.qrCode?(0,a.jsx)("img",{src:d.qrCode,alt:t("Payment QR code"),className:"size-48"}):null})}),(0,a.jsxs)("div",{className:"bg-surface-hover flex items-center justify-between rounded-md px-3 py-2",children:[(0,a.jsx)("span",{className:"text-text-secondary text-xs",children:t("Amount Due")}),(0,a.jsxs)("span",{className:"font-mono text-sm font-semibold",children:[ef(d.amount)," ",d.currency]})]}),(0,a.jsx)(eg,{label:t("Wallet Address"),value:d.walletHash}),(0,a.jsx)(eg,{label:`${t("Amount Due")} (${d.currency})`,value:d.amount}),(0,a.jsxs)("p",{className:"text-text-tertiary text-center text-xs leading-relaxed",children:[t("Send the payment within")," ",(0,a.jsx)(eb,{expireUtc:d.expireUtc})," ",t("to the address above:"),(0,a.jsxs)("span",{className:"text-foreground font-medium",children:[" ",ef(d.amount)," ",d.currency]}),t(". This window will close automatically after payment. The amount must match exactly or crediting may be delayed.")]})]}):(0,a.jsx)("div",{className:"py-2",children:f||l?(0,a.jsxs)("div",{className:"text-muted-foreground flex h-40 items-center justify-center text-sm",children:[(0,a.jsx)(c.krw,{className:"mr-2 size-4 animate-spin"}),l?t("Creating order..."):t("Loading currencies...")]}):0===g.length?(0,a.jsx)("p",{className:"text-text-secondary py-10 text-center text-sm",children:t("No currencies available")}):(0,a.jsx)("div",{className:"grid grid-cols-2 gap-2",children:g.map(e=>(0,a.jsxs)("button",{type:"button",disabled:l,onClick:()=>y(e.cid),className:"border-border hover:border-primary/50 hover:bg-surface-hover flex items-center gap-2 rounded-md border px-3 py-2.5 text-left transition-colors disabled:opacity-50",children:[e.icon?(0,a.jsx)("img",{src:e.icon,alt:"",className:"size-5 shrink-0"}):null,(0,a.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,a.jsx)("span",{className:"block truncate text-sm font-medium",children:e.currency}),(0,a.jsx)("span",{className:"text-text-tertiary block truncate text-xs",children:e.name})]}),e.recommended?(0,a.jsx)("span",{className:"bg-primary/10 text-primary shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium",children:t("Recommended")}):null]},e.cid))})})]})})}var ej=s(26423),eN=s(52606),ev=s(47627),ew=s(69502);let ek={stripe:"Stripe",alipay:"Alipay",wxpay:"WeChat Pay",waffo:"Waffo"};function e_(e,t){let s=ek[e]||e;return t?t(s):s}let eS=[{value:"7d",label:"Last 7 days"},{value:"30d",label:"Last 30 days"},{value:"90d",label:"Last 90 days"},{value:"all",label:"All time"}],eC=[{value:"all",label:"All transactions"},{value:"usage",label:"Model charges"},{value:"income",label:"Top-ups and refunds"},{value:"adjustment",label:"Admin adjustments"}];function eq(e){return"topup"===e.kind?e.topup.create_time:e.log.created_at}function eF(e){var t;return"topup"===e.kind?e.topup.trade_no:(t=e.log).request_id||t.upstream_request_id||""}function eA(e){return"topup"===e.kind?"Order ID":"Conversation ID"}function ez(e){return"success"===e?"Paid":"pending"===e?"Pending":"Expired"}function eR(e){if(!e)return null;let t=e.match(/($|\$|¥|¥|€|£|¤)\s*[\d,]+(?:\.\d+)?\s*额度|[\d,]+\s*点额度/gi);if(t?.length)return t[t.length-1].replace(/\s+/g,"");let s=e.match(/(¥|¥|$|\$|€|£)\s*[\d,]+(?:\.\d+)?/g);return s?.at(-1)?.replace(/\s+/g,"")??null}function eI(e){if("topup"===e.kind)return"success"===e.topup.status?{value:`+${(0,M.J5)(e.topup.amount,{digitsLarge:2,digitsSmall:2,abbreviate:!1})}`,direction:"in"}:{value:ez(e.topup.status),direction:"neutral"};var t=e.log;if(t.type===ew.G7.CONSUME&&t.quota>0)return{value:`-${(0,d.qW)(Math.abs(t.quota))}`,direction:"out"};if((t.type===ew.G7.TOPUP||t.type===ew.G7.REFUND)&&t.quota>0)return{value:`+${(0,d.qW)(Math.abs(t.quota))}`,direction:"in"};if(t.type===ew.G7.MANAGE){if(/增加|返还|退回|补发|转入|increase|credit|credited|refund|return|restore/i.test(t.content))return{value:`+${eR(t.content)??"quota"}`,direction:"in"};if(/减少|扣除|扣费|转出|decrease|deduct|charge|debit|transfer out/i.test(t.content))return{value:`-${eR(t.content)??"quota"}`,direction:"out"};if(/覆盖|overwrite|replace/i.test(t.content))return{value:"Overwritten",direction:"neutral"}}if(t.type===ew.G7.SYSTEM&&/获得|赠送|返还|退还|补偿|赔付|refund|payout|
1credited/i.test(t.content)){let e=t.quota>0?(0,d.qW)(Math.abs(t.quota)):null;return{value:`+${e??eR(t.content)??"quota"}`,direction:"in"}}if(t.type===ew.G7.SYSTEM&&/补扣费|扣费|扣除|charge|debit/i.test(t.content)){let e=t.quota>0?(0,d.qW)(Math.abs(t.quota)):null;return{value:`-${e??eR(t.content)??"quota"}`,direction:"out"}}return{value:eR(t.content)??"—",direction:"neutral"}}function eM(e){var t;return"topup"===e.kind?`Top-up order \xb7 ${e.topup.trade_no}`:(t=e.log).type===ew.G7.CONSUME?t.model_name||t.content||"Model call":t.content||"System balance entry"}function eT(e){return"topup"===e.kind?e.topup.user_id?`User ID: ${e.topup.user_id}`:null:e.log.username||(e.log.user_id?`User ID: ${e.log.user_id}`:null)}function e$(e){let{entry:t}=e,{t:s}=(0,n.Bd)(),r=function(e,t){if("topup"===e.kind)return{label:t("Top-up"),tone:"income"};switch(e.log.type){case ew.G7.TOPUP:return{label:t("Top-up"),tone:"income"};case ew.G7.CONSUME:return{label:t("Consume"),tone:"usage"};case ew.G7.MANAGE:return{label:t("Admin adjustment"),tone:"adjustment"};case ew.G7.SYSTEM:return{label:t("System"),tone:"system"};case ew.G7.REFUND:return{label:t("Refund"),tone:"refund"};default:return{label:t("System entry"),tone:"system"}}}(t,s);return(0,a.jsx)("span",{className:(0,u.cn)("inline-flex w-fit items-center rounded-md border px-2 py-1 text-[11px] font-medium whitespace-nowrap",{income:"border-emerald-200/70 bg-emerald-50 text-emerald-700 dark:border-emerald-900/70 dark:bg-emerald-950/30 dark:text-emerald-300",usage:"border-rose-200/70 bg-rose-50 text-rose-700 dark:border-rose-900/70 dark:bg-rose-950/30 dark:text-rose-300",adjustment:"border-amber-200/70 bg-amber-50 text-amber-700 dark:border-amber-900/70 dark:bg-amber-950/30 dark:text-amber-300",refund:"border-sky-200/70 bg-sky-50 text-sky-700 dark:border-sky-900/70 dark:bg-sky-950/30 dark:text-sky-300",system:"border-slate-200/70 bg-slate-50 text-slate-600 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300"}[r.tone]),children:r.label})}function eE(e){let{entry:t,isAdmin:s,onRequestComplete:r,completingTradeNo:i}=e,{t:l}=(0,n.Bd)(),{copiedText:o,copyToClipboard:m}=(0,eN.C)({notify:!1}),x=eF(t),p=eI(t),h=eM(t),f=s?eT(t):null;return(0,a.jsxs)("tr",{className:"border-border/60 hover:bg-surface-hover border-b align-top transition-colors last:border-b-0",children:[(0,a.jsx)("td",{className:"px-4 py-3.5",children:(0,a.jsx)(e$,{entry:t})}),(0,a.jsxs)("td",{className:"max-w-[420px] min-w-[260px] px-4 py-3.5",children:[(0,a.jsx)("p",{className:"text-foreground truncate text-sm font-medium",title:h,children:h}),f?(0,a.jsx)("span",{className:"text-muted-foreground mt-1 block truncate text-[11px]",children:f}):null,x?(0,a.jsxs)("button",{type:"button",className:"text-muted-foreground hover:text-foreground mt-1 inline-flex max-w-full items-center gap-1 text-[11px] transition-colors",title:`Copy ${eA(t)}`,onClick:()=>m(x),children:[(0,a.jsxs)("span",{className:"truncate font-mono",children:[eA(t),": ",x]}),o===x?(0,a.jsx)("span",{className:"shrink-0",children:l("Copied")}):(0,a.jsx)(c.QRo,{className:"size-3 shrink-0"})]}):(0,a.jsx)("span",{className:"text-muted-foreground mt-1 block text-[11px]",children:"No related conversation"})]}),(0,a.jsx)("td",{className:"px-4 py-3.5",children:"topup"===t.kind?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-muted-foreground block max-w-40 truncate text-xs",children:e_(t.topup.payment_method,l)}),(0,a.jsxs)("span",{className:"text-muted-foreground/70 mt-1 block text-[10px]",children:["Paid"," ",t.topup.money.toLocaleString(void 0,{maximumFractionDigits:2})," ","· ",ez(t.topup.status)]}),s&&"pending"===t.topup.status?(0,a.jsxs)(N.$,{type:"button",size:"sm",variant:"outline",className:"mt-2 h-7 px-2 text-[11px]",onClick:()=>r?.(t.topup.trade_no),disabled:!!i,children:[i===t.topup.trade_no?(0,a.jsx)(c.e9t,{className:"mr-1 size-3 animate-spin"}):(0,a.jsx)(c.Jlk,{className:"mr-1 size-3"}),l("Complete order")]}):null,"success"===t.topup.status?(0,a.jsxs)(N.$,{type:"button",size:"sm",variant:"outline",className:"mt-2 h-7 px-2 text-[11px]",onClick:()=>void eh(`/api/user/topup/${t.topup.id}/invoice`),children:[(0,a.jsx)(c.iUU,{className:"mr-1 size-3"}),l("Download Invoice")]}):null]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-muted-foreground block max-w-40 truncate text-xs",children:t.log.model_name||"—"}),t.log.prompt_tokens||t.log.completion_tokens?(0,a.jsxs)("span",{className:"text-muted-foreground
1/70 mt-1 block font-mono text-[10px] tabular-nums",children:[(t.log.prompt_tokens+t.log.completion_tokens).toLocaleString()," ","tokens"]}):null]})}),(0,a.jsx)("td",{className:"px-4 py-3.5 text-right",children:(0,a.jsxs)("span",{className:(0,u.cn)("inline-flex items-center gap-1 font-mono text-sm font-semibold tabular-nums","in"===p.direction&&"text-emerald-600 dark:text-emerald-400","out"===p.direction&&"text-rose-600 dark:text-rose-400","neutral"===p.direction&&"text-muted-foreground"),children:["in"===p.direction?(0,a.jsx)(c.PS$,{className:"size-3.5"}):"out"===p.direction?(0,a.jsx)(c.F1e,{className:"size-3.5"}):null,p.value]})}),(0,a.jsx)("td",{className:"px-4 py-3.5 whitespace-nowrap",children:(0,a.jsx)("span",{className:"text-muted-foreground font-mono text-xs tabular-nums",children:(0,d.fk)(eq(t))})})]})}function eP(e){let{entry:t,isAdmin:s,onRequestComplete:r,completingTradeNo:i}=e,{t:l}=(0,n.Bd)(),o=eF(t),m=eI(t),x=eM(t),p=s?eT(t):null;return(0,a.jsxs)("article",{className:"border-border/70 bg-background rounded-lg border p-3.5",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsx)(e$,{entry:t}),(0,a.jsx)("p",{className:"text-foreground mt-2 truncate text-sm font-medium",title:x,children:x}),p?(0,a.jsx)("span",{className:"text-muted-foreground mt-1 block truncate text-[11px]",children:p}):null]}),(0,a.jsx)("span",{className:(0,u.cn)("shrink-0 font-mono text-sm font-semibold tabular-nums","in"===m.direction&&"text-emerald-600 dark:text-emerald-400","out"===m.direction&&"text-rose-600 dar
1k:text-rose-400","neutral"===m.direction&&"text-muted-foreground"),children:m.value})]}),(0,a.jsxs)("div",{className:"text-muted-foreground mt-3 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]",children:[(0,a.jsx)("span",{children:"topup"===t.kind?e_(t.topup.payment_method,l):t.log.model_name||"System entry"}),(0,a.jsx)("span",{children:(0,d.fk)(eq(t))}),o?(0,a.jsxs)("span",{className:"font-mono",children:[eA(t),": ",o]}):null]}),s&&"topup"===t.kind&&"pending"===t.topup.status?(0,a.jsxs)(N.$,{type:"button",size:"sm",variant:"outline",className:"mt-3 h-8 w-full text-xs",onClick:()=>r?.(t.topup.trade_no),disabled:!!i,children:[i===t.topup.trade_no?(0,a.jsx)(c.e9t,{className:"mr-1.5 size-3.5 animate-spin"}):(0,a.jsx)(c.Jlk,{className:"mr-1.5 size-3.5"}),l("Complete order")]}):null]})}function eD(e){let{title:t="Transaction ledger",description:s="Track model charges, top-ups, refunds and account adjustments by conversation or order ID.",defaultFilter:l="all",compact:o=!1}=e,{t:d}=(0,n.Bd)(),[m,x]=(0,r.useState)(l),[p,h]=(0,r.useState)("30d"),[f,g]=(0,r.useState)(""),[y,j]=(0,r.useState)(1),[w,k]=(0,r.useState)(""),[_,S]=(0,r.useState)(null),[C,q]=(0,r.useState)(null),F=(0,ej.h)(),A=(0,r.useMemo)(()=>{if("all"===p)return{};let e=Number(p.replace("d","")),t=new Date,s=new Date(Date.now()-24*e*36e5);return s.setHours(0,0,0,0),{start_timestamp:Math.floor(s.getTime()/1e3),end_timestamp:Math.floor(t.getTime()/1e3)}},[p]),{data:z,isLoading:R,isFetching:I,refetch:M}=(0,b.I)({queryKey:["finance-ledger",F,p,A,f.trim(),w.trim()],queryFn:async()=>{let[e,t]=await Promise.all([(F?ev.jp:ev.ni)({p:1,page_size:100,...A,...f.trim()?{request_id:f.trim()}:{},...F&&w.trim()?{username:w.trim()}:{}}),F?en(1,100,f.trim()):er(1,100,f.trim())]);if(!e.success)throw Error(e.message||"Failed to load transaction logs");if(!J(t))throw Error(t.message||"Failed to load top-up records");return{logs:e.data?.items??[],topups:t.data?.items??[]}},placeholderData:e=>e}),E=(0,r.useMemo)(()=>{let e=A.start_timestamp,t=z?.topups??[];return[...(z?.logs??[]).filter(e=>!(e.type===ew.G7.ERROR||e.type===ew.G7.SYSTEM&&!(e.quota>0||/(额度|返还|退还|赔付|充值|赠送|获得|补偿|扣费|扣除|退回|补扣费|quota|credit|credited|refund|payout|top.?up|charge|debit|compensation)/i.test(e.content))||e.type===ew.G7.TOPUP&&/(在线充值|Creem充值|Waffo充值|Pancake充值|加密货币充值|online top.?up|Creem top.?up|Waffo top.?up|Pancake top.?up|crypto(?:currency)? top.?up)/i.test(e.content)&&t.some(t=>"success"===t.status&&t.user_id===e.user_id&&172800>=Math.abs(t.create_time-e.created_at)))).map(e=>({kind:"log",log:e})),...t.filter(t=>!e||t.create_time>=e&&t.create_time<=(A.end_timestamp??1/0)).map(e=>({kind:"topup",topup:e}))].filter(e=>{var t;return"all"===m||("topup"===e.kind?"income":(t=e.log).type===ew.G7.CONSUME?"usage":t.type===ew.G7.TOPUP||t.type===ew.G7.REFUND||t.type===ew.G7.SYSTEM?"income":t.type===ew.G7.MANAGE?"adjustment":"all")===m}).sort((e,t)=>eq(t)-eq(e))},[z?.logs,z?.topups,m,A]),P=E.length,D=Math.max(1,Math.ceil(P/20)),L=E.slice((y-1)*20,20*y),O=e=>{F&&S(e)},H=async()=>{if(_&&F&&!C){q(_);try{let e=await ei({trade_no:_});if(!J(e))return void i.oR.error(e.message||"Failed to complete the order");i.oR.success("Order completed and the balance has been credited"),S(null),await M()}catch{i.oR.error("Failed to complete the order. Please try again later.")}finally{q(null)}}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("section",{className:(0,u.cn)("border-border/70 bg-card rounded-lg border",o&&"shadow-none"),children:[(0,a.jsxs)("div",{className:"border-border/70 flex flex-col gap-3 border-b px-4 py-4 sm:px-5 sm:py-5",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1 sm:flex-row sm:items-start sm:justify-between sm:gap-4",children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-start gap-3",children:[(0,a.jsx)("span",{className:"bg-primary/10 text-primary mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md",children:(0,a.jsx)(c.VzH,{className:"size-4"})}),(0,a.jsx)("div",{className:"min-w-0",children:(0,a.jsx)("h2",{className:"text-foreground text-base font-semibold",children:d(t)})})]}),(0,a.jsxs)(N.$,{variant:"ghost",size:"sm",className:"text-muted-foreground hover:text-foreground h-8 shrink-0 gap-1.5 self-start px-2 text-xs",onClick:()=>void M(),disabled:I,children:[(0,a.jsx)(c.e9t,{className:(0,u.cn)("size-3.5",I&&"animate-spin")}),"Refresh"]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 lg:flex-row lg:items-center lg:justify-between",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[F?(0,a.jsx)("div",{className:"relative min-w-0 flex-1 sm:max-w-[220px]",children:(0,a.jsx)(v.p,{value:w,onChange:e=>{k(e.target.value),j(1)},placeholder:d("Filter by username"),className:"h-8 text-xs"})}):null,(0,a.jsxs)("div",{className:"relative min-w-0 flex-1 sm:max-w-[360px]",children:[(0,a.jsx)(c.vji,{className:"text-muted-foreground absolute top-1/2 left-3 size-3.5 -translate-y-1/2"}),(0,a.jsx)(v.p,{value:f,onChange:e=>{g(e.target.value),j(1)},placeholder:d("Search conversation ID / order ID"),className:"h-8 pl-9 text-xs"})]}),(0,a.jsxs)("span",{className:"text-muted-foreground hidden items-center gap-1 text-[11px] sm:inline-flex",children:[(0,a.jsx)(c.YCF,{className:"size-3.5"}),d("Conversation ID is the API request ID; order IDs are searchable")]})]}),(0,a.jsx)("div",{className:"flex flex-wrap items-center gap-1.5",children:eS.map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>{h(e.value),j(1)},className:(0,u.cn)("rounded-md px-2.5 py-1.5 text-[11px] font-medium transition-colors",p===e.value?"bg-foreground text-background":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:d(e.label)},e.value))})]}),(0,a.jsx)("div",{className:"flex flex-wrap items-center gap-1.5",children:eC.map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>{x(e.value),j(1)},className:(0,u.cn)("rounded-full border px-3 py-1 text-[11px] font-medium transition-colors",m===e.value?"border-primary/30 bg-primary/10 text-primary":"border-border/70 text-muted-foreground hover:border-border-strong hover:text-foreground"),children:d(e.label)},e.value))})]}),R?(0,a.jsx)("div",{className:"space-y-3 p-4 sm:p-5",children:Array.from({length:o?4:7}).map((e,t)=>(0,a.jsx)($.E,{className:"h-12 w-full rounded-md"},t))}):0===E.length?(0,a.jsxs)("div",{className:"text-muted-foreground flex min-h-56 flex-col items-center justify-center gap-2 px-5 text-center",children:[(0,a.jsx)(c.VzH,{className:"text-muted-foreground
1/50 size-7"}),(0,a.jsx)("p",{className:"text-sm font-medium",children:d("No transactions yet")}),(0,a.jsx)("p",{className:"text-xs",children:d("Top-ups, model calls and balance adjustments will appear here.")})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"hidden overflow-x-auto md:block",children:(0,a.jsxs)("table",{className:"w-full min-w-[820px] border-collapse",children:[(0,a.jsx)("thead",{className:"bg-muted/30 border-border/70 border-b",children:(0,a.jsxs)("tr",{className:"text-muted-foreground text-left text-[11px] font-medium tracking-wide",children:[(0,a.jsx)("th",{className:"w-28 px-4 py-3",children:d("Type")}),(0,a.jsx)("th",{className:"px-4 py-3",children:d("Description / reference")}),(0,a.jsx)("th",{className:"w-44 px-4 py-3",children:d("Model / payment")}),(0,a.jsx)("th",{className:"w-40 px-4 py-3 text-right",children:d("Balance change")}),(0,a.jsx)("th",{className:"w-44 px-4 py-3",children:d("Time")})]})}),(0,a.jsx)("tbody",{children:L.map(e=>(0,a.jsx)(eE,{entry:e,isAdmin:F,onRequestComplete:O,completingTradeNo:C},`${e.kind}-${"topup"===e.kind?e.topup.id:e.log.id}-${eq(e)}`))})]})}),(0,a.jsx)("div",{className:"space-y-2 p-3 md:hidden",children:L.map(e=>(0,a.jsx)(eP,{entry:e,isAdmin:F,onRequestComplete:O,completingTradeNo:C},`${e.kind}-${"topup"===e.kind?e.topup.id:e.log.id}-${eq(e)}`))}),(0,a.jsxs)("div",{className:"border-border/70 flex flex-col gap-2 border-t px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("span",{className:"text-muted-foreground text-xs",children:[P.toLocaleString()," records · Page ",y," of ",D]}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)(N.$,{variant:"outline",size:"icon-sm","aria-label":"Previous page",disabled:y<=1||I,onClick:()=>j(e=>Math.max(1,e-1)),children:(0,a.jsx)(c.JGc,{className:"size-3.5"})}),(0,a.jsxs)("span",{className:"text-muted-foreground min-w-12 text-center text-xs tabular-nums",children:[y," / ",D]}),(0,a.jsx)(N.$,{variant:"outline",size:"icon-sm","aria-label":"Next page",disabled:y>=D||I,onClick:()=>j(e=>Math.min(D,e+1)),children:(0,a.jsx)(c.c_$,{className:"size-3.5"})})]})]})]})]}),(0,a.jsx)(T.Lt,{open:!!_,onOpenChange:e=>{e||C||S(null)},children:(0,a.jsxs)(T.EO,{children:[(0,a.jsxs)(T.wd,{children:[(0,a.jsx)(T.r7,{children:d("Complete pending order?")}),(0,a.jsx)(T.$v,{children:d("Mark order {{order}} as paid and credit its top-up amount to the user?",{order:_||""})})]}),(0,a.jsxs)(T.ck,{children:[(0,a.jsx)(T.Zr,{disabled:!!C,children:d("Cancel")}),(0,a.jsx)(T.Rx,{onClick:()=>void H(),disabled:!!C,children:C?d("Processing..."):d("Complete order")})]})]})})]})}var eL=s(82243);let eO=[{value:"detail",label:"Invoice by order details",description:"Select paid orders to invoice",icon:c.B8B},{value:"amount",label:"Invoice by amount",description:"Combine orders up to a target amount",icon:c.OJX},{value:"month",label:"Invoice by monthly bill",description:"Summarize eligible orders by month",icon:c.ADG}];function eH(e){let[t,s]=e.split("-");return`${t}-${String(Number(s)).padStart(2,"0")}`}function eB(e){let{title:t,topups:s,topupsLoading:i,mode:l,amountTarget:o,month:d,monthlyBills:m,monthlyBillsLoading:x,monthlyBillDetail:p,monthlyBillDetailLoading:h,onModeChange:f,onAmountTargetChange:g,onMonthChange:b,onEditTitle:y,onApply:j,requests:w,requestsLoading:k,onRefreshRequests:_}=e,{t:S}=(0,n.Bd)(),C=!!t&&!!t.company_name,[q,F]=(0,r.useState)("apply"),[A,z]=(0,r.useState)(!1),R=(0,r.useMemo)(()=>s.reduce((e,t)=>e+t.money,0),[s]),I=(0,r.useMemo)(()=>m.map(e=>e.month),[m]),M=(0,r.useMemo)(()=>m.find(e=>e.month===d)??null,[m,d]),T=(0,r.useMemo)(()=>"month"===l&&p?.month===d?p.rows:[],[l,d,p]),$=async()=>{if(d&&!A){z(!0);try{await eh(`/api/invoice/monthly-bills/pdf?month=${encodeURIComponent(d)}`,{download:!0,filename:`月度模型账单-${d}.pdf`})}finally{z(!1)}}};return(0,a.jsxs)("div",{className:"mx-auto w-full max-w-[1440px] space-y-4",children:[(0,a.jsxs)("div",{className:"border-border/70 bg-card overflow-hidden rounded-lg border",children:[(0,a.jsxs)("div",{className:"bg-muted/35 border-border/60 flex flex-wrap items-center justify-between gap-3 border-b px-4 py-3 sm:px-5",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-semibold",children:S("Invoice notice")}),(0,a.jsx)("p",{className:"text-muted-foreground mt-1 text-xs",children:"month"===l?S("Monthly bills cover consumption in a finished calendar month (Beijing time). Minimum invoice amount: 500 CNY."):S("Only paid, uninvoiced top-up orders are eligible. Minimum invoice amount: 500 CNY.")})]}),"month"!==l&&(0,a.jsxs)("span",{className:"text-primary text-xs font-medium",children:[S("Eligible balance")," ¥",R.toFixed(2)]})]}),(0,a.jsxs)("div",{className:"p-4 sm:p-5",children:[(0,a.jsxs)("div",{className:"mb-4 flex flex-wrap gap-1 rounded-md border p-1",children:[eO.map(e=>{let t=e.icon,s=l===e.value;return(0,a.jsxs)("button",{type:"button",onClick:()=>{F("apply"),f(e.value)},className:(0,u.cn)("flex min-w-[150px] flex-1 items-center gap-2 rounded-sm px-3 py-2 text-left transition-colors",s?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[(0,a.jsx)(t,{className:"size-4 shrink-0"}),(0,a.jsxs)("span",{className:"min-w-0",children:[(0,a.jsx)("span",{className:"block text-sm font-medium",children:S(e.label)}),(0,a.jsx)("span",{className:(0,u.cn)("mt-0.5 block truncate text-[11px]",s?"text-primary-foreground
1/75":"text-muted-foreground/75"),children:S(e.description)})]})]},e.value)}),(0,a.jsxs)("button",{type:"button",onClick:()=>F("records"),className:(0,u.cn)("flex min-w-[150px] flex-1 items-center gap-2 rounded-sm px-3 py-2 text-left transition-colors","records"===q?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[(0,a.jsx)(c.iUU,{className:"size-4 shrink-0"}),(0,a.jsxs)("span",{className:"min-w-0",children:[(0,a.jsx)("span",{className:"block text-sm font-medium",children:S("Invoice records")}),(0,a.jsx)("span",{className:(0,u.cn)("mt-0.5 block truncate text-[11px]","records"===q?"text-primary-foreground/75":"text-muted-foreground/75"),children:S("View submitted invoice requests")})]})]})]}),"apply"===q&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"border-border/70 bg-background-secondary/45 mb-4 grid gap-3 rounded-md border p-3 sm:grid-cols-2",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[(0,a.jsx)("p",{className:"text-muted-foreground text-xs font-medium",children:S("Invoice entity")}),(0,a.jsxs)(N.$,{variant:"ghost",size:"xs",onClick:y,children:[(0,a.jsx)(c.gHP,{className:"size-3"}),C?S("Edit"):S("Set details")]})]}),(0,a.jsxs)("div",{className:"border-border bg-background rounded-md border px-3 py-2",children:[(0,a.jsx)("p",{className:"truncate text-sm font-medium",children:C?t.company_name:S("Invoice details not set")}),(0,a.jsx)("p",{className:"text-muted-foreground mt-0.5 truncate text-xs",children:C?`Tax ID ${t.tax_number}`:S("Add company invoice details first")})]})]}),"amount"===l?(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-muted-foreground mb-1.5 text-xs font-medium",children:S("Target invoice amount")}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("span",{className:"text-muted-foreground pointer-events-none absolute inset-y-0 left-3 flex items-center text-sm",children:"¥"}),(0,a.jsx)(v.p,{value:o,onChange:e=>g(e.target.value),inputMode:"decimal",placeholder:S("Enter an amount; orders will be combined"),className:"pl-7"})]})]}):"month"===l?(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-muted-foreground mb-1.5 text-xs font-medium",children:S("Billing month")}),(0,a.jsxs)(eL.l6,{value:d,onValueChange:e=>{e&&b(e)},children:[(0,a.jsx)(eL.bq,{className:"bg-background w-full",children:(0,a.jsx)(eL.yv,{placeholder:x?S("Loading monthly bills..."):0===I.length?S("No finished monthly bills yet"):S("Select a month")})}),(0,a.jsx)(eL.gC,{children:m.map(e=>(0,a.jsxs)(eL.eb,{value:e.month,disabled:e.invoiced||!e.cny_eligible,children:[eH(e.month),e.cny_eligible?` \xb7 \xa5${e.amount_yuan.toFixed(2)}`:` \xb7 $${e.amount_usd.toFixed(2)} \xb7 ${S("No CNY top-up record")}`,e.invoiced?` \xb7 ${S("Invoiced")}`:""]},e.month))})]}),M&&(0,a.jsxs)("p",{className:"text-muted-foreground mt-1.5 text-xs",children:[S("Consumption bill for the full month (through the last hour of the month)")," · $",M.amount_usd.toFixed(2)," ≈ ¥",M.amount_yuan.toFixed(2)," · ",S("Rate {{rate}} (weighted by your CNY top-ups)",{rate:M.rate.toFixed(4)})]})]}):(0,a.jsxs)("div",{className:"flex items-end justify-between gap-3 sm:justify-end",children:[(0,a.jsxs)("div",{className:"text-right",children:[(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:S("Eligible orders")}),(0,a.jsx)("p",{className:"mt-1 text-lg font-semibold tabular-nums",children:s.length})]}),(0,a.jsxs)("div",{className:"text-right",children:[(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:S("Eligible amount")}),(0,a.jsxs)("p",{className:"text-primary mt-1 text-lg font-semibold tabular-nums",children:["¥",R.toFixed(2)]})]})]})]}),"month"===l?(0,a.jsxs)("div",{className:"border-border/70 overflow-hidden rounded-md border",children:[(0,a.jsxs)("div",{className:"border-border/60 bg-muted/35 flex items-center justify-between border-b px-3 py-2.5 sm:px-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-semibold",children:S("Bill details")}),(0,a.jsx)("p",{className:"text-muted-foreground mt-0.5 text-xs",children:d&&M?S("{{month}} · {{models}} models · {{count}} requests",{month:eH(d),models:T.length,count:p?.count??0}):S("Select a month to view the consumption breakdown")})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)(N.$,{variant:"outline",size:"sm",onClick:()=>void $(),disabled:!d||h||0===T.length||A,children:[A?(0,a.jsx)(c.krw,{className:"size-3.5 animate-spin"}):(0,a.jsx)(c.f5X,{className:"size-3.5"}),A?S("Exporting..."):S("Export monthly statement PDF")]}),(0,a.jsxs)(N.$,{size:"sm",onClick:j,disabled:!C||!M||M.invoiced,children:[S("Apply for invoice"),(0,a.jsx)(c.c_$,{className:"size-3.5"})]})]})]}),d?h?(0,a.jsx)("div",{className:"text-muted-foreground px-4 py-10 text-center text-sm",children:S("Loading bill details...")}):0===T.length?(0,a.jsx)("div",{className:"text-muted-foreground px-4 py-10 text-center text-sm",children:S("No consumption in this month")}):(0,a.jsx)("div",{className:"overflow-x-auto",children:(0,a.jsxs)("table",{className:"w-full min-w-[620px] text-sm",children:[(0,a.jsx)("thead",{className:"bg-muted/20 text-muted-foreground text-xs",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{className:"px-4 py-2.5 text-left font-medium",children:S("Model")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-right font-medium",children:S("Requests")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-right font-medium",children:S("Input tokens")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-right font-medium",children:S("Output tokens")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-right font-medium",children:S("Consumption")})]})}),(0,a.jsx)("tbody",{className:"divide-border/60 divide-y",children:T.map(e=>(0,a.jsxs)("tr",{className:"hover:bg-muted/20 transition-colors",children:[(0,a.jsx)("td",{className:"max-w-[300px] truncate px-4 py-3 font-mono text-xs",children:e.model_name||"-"}),(0,a.jsx)("td",{className:"text-muted-foreground px-4 py-3 text-right text-xs tabular-nums",children:e.count.toLocaleStr
1ing()}),(0,a.jsx)("td",{className:"text-muted-foreground px-4 py-3 text-right text-xs tabular-nums",children:e.prompt_tokens.toLocaleString()}),(0,a.jsx)("td",{className:"text-muted-foreground px-4 py-3 text-right text-xs tabular-nums",children:e.completion_tokens.toLocaleString()}),(0,a.jsxs)("td",{className:"px-4 py-3 text-right font-medium tabular-nums",children:["Â¥",e.amount_yuan.toFixed(2),(0,a.jsxs)("span",{className:"text-muted-foreground ml-1.5 text-xs font-normal",children:["$",e.amount_usd.toFixed(2)]})]})]},e.model_name))}),(0,a.jsx)("tfoot",{className:"bg-muted/20 border-border/60 border-t text-xs",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("td",{className:"px-4 py-2.5 font-medium",children:S("Total")}),(0,a.jsx)("td",{className:"text-muted-foreground px-4 py-2.5 text-right tabular-nums",children:(p?.count??0).toLocaleString()}),(0,a.jsx)("td",{className:"text-muted-foreground px-4 py-2.5 text-right tabular-nums",children:T.reduce((e,t)=>e+t.prompt_tokens,0).toLocaleString()}),(0,a.jsx)("td",{className:"text-muted-foreground px-4 py-2.5 text-right tabular-nums",children:T.reduce((e,t)=>e+t.completion_tokens,0).toLocaleString()}),(0,a.jsxs)("td",{className:"text-primary px-4 py-2.5 text-right text-sm font-semibold tabular-nums",children:["Â¥",(p?.amount_yuan??0).toFixed(2),(0,a.jsxs)("span",{className:"text-muted-foreground ml-1.5 text-xs font-normal",children:["$",(p?.amount_usd??0).toFixed(2)]})]})]})})]})}):(0,a.jsx)("div",{className:"text-muted-foreground px-4 py-10 text-center text-sm",children:S("No month selected")})]}):(0,a.jsxs)("div",{className:"border-border/70 overflow-hidden rounded-md border",children:[(0,a.jsxs)("div",{className:"border-border/60 bg-muted/35 flex items-center justify-between border-b px-3 py-2.5 sm:px-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-semibold",children:S("Eligible orders")}),(0,a.jsx)("p",{className:"text-muted-foreground mt-0.5 text-xs",children:S("Select orders and submit one invoice")})]}),(0,a.jsxs)(N.$,{size:"sm",onClick:j,disabled:!C||i||0===s.length,children:[S("Apply for invoice"),(0,a.jsx)(c.c_$,{className:"size-3.5"})]})]}),i?(0,a.jsx)("div",{className:"text-muted-foreground px-4 py-10 text-center text-sm",children:S("Loading eligible orders...")}):0===s.length?(0,a.jsx)("div",{className:"text-muted-foreground px-4 py-10 text-center text-sm",children:S("No eligible orders")}):(0,a.jsxs)("div",{className:"overflow-x-auto",children:[(0,a.jsxs)("table",{className:"w-full min-w-[620px] text-sm",children:[(0,a.jsx)("thead",{className:"bg-muted/20 text-muted-foreground text-xs",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{className:"px-4 py-2.5 text-left font-medium",children:S("Order date")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-left font-medium",children:S("Order ID")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-right font-medium",children:S("Order amount")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-right font-medium",children:S("Status")})]})}),(0,a.jsx)("tbody",{className:"divide-border/60 divide-y",children:s.slice(0,8).map(e=>(0,a.jsxs)("tr",{className:"hover:bg-muted/20 transition-colors",children:[(0,a.jsx)("td",{className:"text-muted-foreground px-4 py-3 text-xs",children:new Date(1e3*e.create_time).toLocaleString("zh-CN",{dateStyle:"medium"})}),(0,a.jsx)("td",{className:"max-w-[260px] truncate px-4 py-3 font-mono text-xs",children:e.trade_no}),(0,a.jsxs)("td",{className:"px-4 py-3 text-right font-medium tabular-nums",children:["Â¥",e.money.toFixed(2)]}),(0,a.jsx)("td",{className:"px-4 py-3 text-right",children:(0,a.jsx)("span",{className:"text-xs font-medium text-emerald-600 dark:text-emerald-400",children:S("Eligible")})})]},e.id))})]}),s.length>8&&(0,a.jsx)("p",{className:"text-muted-foreground border-border/60 border-t px-4 py-2.5 text-center text-xs",children:S("{{count}} more orders are available in the application dialog",{count:s.length-8})})]})]})]})]})]}),"records"===q&&(0,a.jsxs)("section",{className:"border-border/70 bg-card rounded-lg border",children:[(0,a.jsxs)("div",{className:"border-border/60 flex flex-wrap items-center justify-between gap-2 border-b px-4 py-3 sm:px-5",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-semibold",children:S("Invoice records")}),(0,a.jsx)("p",{className:"text-muted-foreground mt-0.5 text-xs",children:S("Review submitted requests and processing status")})]}),(0,a.jsxs)(N.$,{variant:"ghost",size:"sm",onClick:_,disabled:k,children:[(0,a.jsx)(c.e9t,{className:(0,u.cn)("size-3.5",k&&"animate-spin")}),S("Refresh")]})]}),k?(0,a.jsxs)("div",{className:"text-muted-foreground flex items-center justify-center gap-2 px-4 py-10 text-sm",children:[(0,a.jsx)(c.krw,{className:"size-4 animate-spin"}),S("Loading invoice records...")]}):0===w.length?(0,a.jsx)("div",{className:"text-muted-foreground px-4 py-10 text-center text-sm",children:S("No invoice records yet")}):(0,a.jsx)("div",{className:"overflow-x-auto",children:(0,a.jsxs)("table",{className:"w-full min-w-[760px] text-sm",children:[(0,a.jsx)("thead",{className:"bg-muted/20 text-muted-foreground text-xs",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{className:"px-4 py-2.5 text-left font-medium",children:S("Applied at")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-left font-medium",children:S("Invoice entity")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-right font-medium",children:S("Invoice amount")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-center font-medium",children:S("Status")}),(0,a.jsx)("th",{className:"px-4 py-2.5 text-right font-medium",children:S("Actions")})]})}),(0,a.jsx)("tbody",{className:"divide-border/60 divide-y",children:w.map(e=>{let t="issued"===e.status?{label:S("Issued"),className:"text-emerald-600 dark:text-emerald-400"}:"rejected"===e.status?{label:S("Rejected"),className:"text-destructive"}
1:{label:S("Processing"),className:"text-amber-600 dark:text-amber-400"};return(0,a.jsxs)("tr",{className:"hover:bg-muted/20 transition-colors",children:[(0,a.jsx)("td",{className:"text-muted-foreground px-4 py-3 text-xs",children:new Date(1e3*e.create_time).toLocaleString("zh-CN",{dateStyle:"medium"})}),(0,a.jsx)("td",{className:"max-w-[260px] truncate px-4 py-3 font-medium",children:e.company_name}),(0,a.jsxs)("td",{className:"px-4 py-3 text-right font-medium tabular-nums",children:["Â¥",e.amount_yuan.toFixed(2)]}),(0,a.jsx)("td",{className:"px-4 py-3 text-center",children:(0,a.jsx)("span",{className:(0,u.cn)("text-xs font-medium",t.className),children:t.label})}),(0,a.jsx)("td",{className:"px-4 py-3 text-right",children:(0,a.jsxs)("div",{className:"flex justify-end gap-1.5",children:[(0,a.jsxs)(N.$,{variant:"outline",size:"xs",disabled:!e.has_file,title:e.has_file?S("View invoice"):S("Invoice file not uploaded yet"),onClick:()=>{var t;eh((t=e.id,`/api/invoice/request/${t}/file`))},children:[(0,a.jsx)(c.kU3,{className:"size-3"}),S("View invoice")]}),(0,a.jsxs)(N.$,{variant:"outline",size:"xs",disabled:!e.has_file,title:e.has_file?S("Download invoice"):S("Invoice file not uploaded yet"),onClick:()=>{var t;eh((t=e.id,`/api/invoice/request/${t}/file?download=1`),{download:!0,filename:e.file_name||`invoice_${e.id}`})},children:[(0,a.jsx)(c.f5X,{className:"size-3"}),S("Download invoice")]})]})})]},e.id)})})]})})]})]})}var eU=s(77405);function eW(e){let{name:t,className:s="size-6"}=e;return(0,a.jsx)("img",{src:`/payment-icons/${t}.svg`,alt:"","aria-hidden":"true",className:s})}function eG(e){let{className:t="size-6"}=e;return(0,a.jsx)(eW,{name:"alipay",className:t})}function eJ(e){let{className:t="h-5"}=e;return(0,a.jsx)(eW,{name:"visa",className:t})}function eK(e){let{className:t="size-6"}=e;return(0,a.jsx)(eW,{name:"mastercard",className:t})}function eY(e){let{className:t="size-6"}=e;return(0,a.jsx)(eW,{name:"wechatpay",className:t})}function eV(e){let{className:t="size-6"}=e;return(0,a.jsx)(eW,{name:"bitcoin",className:t})}function eQ(e){let{className:t="size-6"}=e;return(0,a.jsx)(eW,{name:"ethereum",className:t})}function eX(e){let{className:t="size-6"}=e;return(0,a.jsx)(eW,{name:"tether",className:t})}function eZ(e){let{topupInfo:t,topupAmount:s,onTopupAmountChange:i,paymentAmount:l,calculating:o,onPaymentMethodSelect:d,paymentLoading:m,loading:x,onStripeAmountPay:p,stripeProcessing:h,enablePlisioTopup:f,onPlisioAmountPay:g,plisioProcessing:b}=e,{t:y}=(0,n.Bd)(),[j,w]=(0,r.useState)(s>0?s.toString():""),[k,_]=(0,r.useState)("alipay");(0,r.useEffect)(()=>{s>0&&w(s.toString())},[s]);let S=e=>{w(e);let t=parseInt(e)||0;t>=0&&i(t)},C=t?.pay_methods?.find(e=>"alipay"===e.type),q=!!(t?.enable_online_topup&&C),F=!!t?.enable_stripe_topup,A=q||F||f,z=s<10,R=!!m||!!h||!!b,I=(0,r.useMemo)(()=>{let e=t?.amount_options?.filter(e=>e>0);return(e?.length?e:[10,20,50,100]).slice(0,4)},[t?.amount_options]),M="alipay"===k&&l>0?l:s;return((0,r.useEffect)(()=>{"stripe"!==k||F?"alipay"!==k||q||_(F?"stripe":"plisio"):_(q?"alipay":"plisio")},[k,q,F,f]),x)?(0,a.jsxs)("div",{className:"mx-auto w-full max-w-[1440px] space-y-5",children:[(0,a.jsx)($.E,{className:"h-9 w-36"}),(0,a.jsx)($.E,{className:"h-4 w-80"}),(0,a.jsxs)("div",{className:"rounded-lg border p-6",children:[(0,a.jsx)($.E,{className:"h-14 w-full rounded-lg"}),(0,a.jsxs)("div",{className:"mt-8 grid grid-cols-2 gap-3 md:grid-cols-4",children:[(0,a.jsx)($.E,{className:"h-14 rounded-lg"}),(0,a.jsx)($.E,{className:"h-14 rounded-lg"}),(0,a.jsx)($.E,{className:"h-14 rounded-lg"}),(0,a.jsx)($.E,{className:"h-14 rounded-lg"})]}),(0,a.jsx)($.E,{className:"mt-8 h-36 rounded-lg"}),(0,a.jsx)($.E,{className:"mt-6 h-14 rounded-full"})]})]}):(0,a.jsxs)("div",{className:"mx-auto w-full max-w-[1440px]",children:[(0,a.jsx)("div",{className:"border-primary/15 bg-primary/5 text-text-secondary mb-5 rounded-md border px-4 py-3 text-sm",children:(0,a.jsxs)("div",{className:"flex gap-2.5",children:[(0,a.jsx)(c.hcu,{className:"text-icon-muted mt-0.5 size-4 shrink-0"}),(0,a.jsxs)("div",{className:"min-w-0 flex-1 space-y-1.5 text-xs leading-relaxed",children:[(0,a.jsx)("p",{className:"text-foreground text-sm font-semibold",children:y("Your payment is protected with bank-level encryption. We do not store any credit card information.")}),(0,a.jsxs)("p",{className:"text-foreground text-sm font-semibold",children:[y("Invoices and cross-border service receipts"),":"," ",y("All prices exclude tax")]}),(0,a.jsxs)("p",{children:[y("Mainland China company invoice header: minimum 500 CNY or 100 USD (cumulative). Additional tax applies (standard invoice 1%, special invoice 6%)."),(0,a.jsx)("span",{className:"ml-1 rounded bg-amber-100 px-1 py-0.5 text-amber-900 dark:bg-amber-500/20 dark:text-amber-200",children:y("Model plaza prices exclude tax.")})]}),(0,a.jsx)("p",{children:y("We also support corporate payments to our overseas entities:")}),(0,a.jsx)("p",{children:y("Hong Kong subsidiary invoice header or corporate account: minimum 10,000 HKD per payment; taxes and fees are charged at cost.")}),(0,a.jsx)("p",{children:y("Australian subsidiary invoice header or corporate account: minimum 2,000 USD/AUD per payment; taxes and fees are charged at cost.")})]})]})}),A?(0,a.jsxs)("div",{className:"border-border/70 bg-card overflow-hidden rounded-lg rounded-tr-[14px] border [corner-shape:rou
1nd_bevel_round_round]",children:[(0,a.jsxs)("div",{className:"space-y-8 p-5 sm:p-7",children:[(0,a.jsxs)("section",{className:"space-y-3",children:[(0,a.jsx)("h2",{className:"text-base font-semibold",children:y("Top-up methods")}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-[repeat(auto-fill,290px)]",children:[q?(0,a.jsxs)("button",{type:"button",onClick:()=>_("alipay"),"aria-pressed":"alipay"===k,className:(0,u.cn)("group focus-visible:ring-ring/30 flex h-auto min-h-36 w-full items-start justify-between gap-4 overflow-hidden rounded-md border p-5 text-left transition-all focus-visible:ring-2 focus-visible:outline-none md:min-h-[103px] md:w-[290px] md:gap-3 md:p-3","alipay"===k?"border-primary bg-primary/5 shadow-sm":"border-border hover:border-border-strong hover:bg-surface-hover"),children:[(0,a.jsx)("span",{className:"flex min-w-0 gap-3",children:(0,a.jsxs)("span",{className:"min-w-0",children:[(0,a.jsx)("span",{className:"text-foreground block text-sm font-semibold",children:y("Alipay top-up")}),(0,a.jsx)("span",{className:"text-text-secondary mt-1 block text-xs leading-relaxed",children:y("Supports Alipay, corporate Alipay, credit cards, and Huabei")}),(0,a.jsx)("span",{className:"text-text-tertiary mt-1 block text-xs leading-relaxed",children:y("Supports Chinese tax invoices")})]})}),(0,a.jsx)("span",{className:"flex h-11 w-14 shrink-0 items-center justify-center md:h-[75px] md:w-[90px] md:min-w-[90px]",children:C?.icon?(0,a.jsx)("img",{src:C.icon,alt:y("Alipay"),className:"size-8 md:size-14"}):(0,a.jsx)(eG,{className:"size-8 md:size-14"})})]}):null,F?(0,a.jsx)("button",{type:"button",onClick:()=>_("stripe"),"aria-pressed":"stripe"===k,className:(0,u.cn)("group focus-visible:ring-ring/30 flex h-auto min-h-36 w-full items-start justify-between gap-4 overflow-hidden rounded-md border p-5 text-left transition-all focus-visible:ring-2 focus-visible:outline-none md:min-h-[103px] md:w-[290px] md:gap-3 md:p-3","stripe"===k?"border-primary bg-primary/5 shadow-sm":"border-border hover:border-border-strong hover:bg-surface-hover"),children:(0,a.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,a.jsxs)("span",{className:"flex items-center justify-between gap-2",children:[(0,a.jsx)("span",{className:"text-foreground text-sm font-semibold",children:y("Bank Card")}),(0,a.jsxs)("span",{className:"flex shrink-0 items-center gap-1",children:[(0,a.jsx)(eJ,{className:"h-3 md:h-3.5"}),(0,a.jsx)(eK,{className:"size-4 md:size-5"}),(0,a.jsx)(eY,{className:"size-4 md:size-5"})]})]}),(0,a.jsx)("span",{className:"text-text-secondary mt-1 block text-xs leading-relaxed",children:y("Visa · Mastercard · AmEx · JCB · Apple/Google Pay · WeChat Pay · Link")}),(0,a.jsx)("span",{className:"text-text-tertiary mt-1 block text-[10px] leading-tight",children:y("Chinese tax invoices are unavailable")})]})}):null,f?(0,a.jsxs)("button",{type:"button",onClick:()=>_("plisio"),"aria-pressed":"plisio"===k,className:(0,u.cn)("group focus-visible:ring-ring/30 flex h-auto min-h-36 w-full items-start justify-between gap-4 overflow-hidden rounded-md border p-5 text-left transition-all focus-visible:ring-2 focus-visible:outline-none md:min-h-[103px] md:w-[290px] md:gap-3 md:p-3","plisio"===k?"border-primary bg-primary/5 shadow-sm":"border-border hover:border-border-strong hover:bg-surface-hover"),children:[(0,a.jsx)("span",{className:"flex min-w-0 gap-3",children:(0,a.jsxs)("span",{className:"min-w-0",children:[(0,a.jsx)("span",{className:"text-foreground block text-sm font-semibold",children:y("Cryptocurrency")}),(0,a.jsx)("span",{className:"text-text-secondary mt-1 block text-xs leading-relaxed",children:y("USDT · BTC · ETH")}),(0,a.jsx)("span",{className:"text-text-tertiary mt-1 block text-[10px] leading-tight",children:y("Chinese tax invoices are unavailable")})]})}),(0,a.jsxs)("span",{className:"flex h-11 shrink-0 items-center justify-center gap-1 md:h-[75px] md:w-[110px] md:min-w-[110px]",children:[(0,a.jsx)(eX,{className:"size-7 md:size-8"}),(0,a.jsx)(eV,{className:"size-7 md:size-8"}),(0,a.jsx)(eQ,{className:"size-7 md:size-8"})]})]}):null,(0,a.jsxs)("a",{href:"https://xycai.cn/",target:"_blank",rel:"noreferrer",className:"group border-border hover:border-border-strong hover:bg-surface-hover focus-visible:ring-ring/30 flex h-auto min-h-36 w-full items-start justify-between gap-4 overflow-hidden rounded-md border p-5 text-left transition-all focus-visible:ring-2 focus-visible:outline-none md:min-h-[103px] md:w-[290px] md:gap-3 md:p-3",children:[(0,a.jsx)("span",{className:"flex min-w-0 gap-3",children:(0,a.jsxs)("span",{className:"min-w-0",children:[(0,a.jsx)("span",{className:"text-foreground block text-sm font-semibold",children:y("Corporate remittance")}),(0,a.jsx)("span",{className:"text-text-secondary mt-1 block text-xs leading-relaxed",children:y("Go to the China site to top up")}),(0,a.jsx)("span",{className:"text-text-tertiary mt-1 block text-xs leading-relaxed",children:y("Data, billing, and API endpoints are fully synchronized")})]})}),(0,a.jsx)(c.HD8,{className:"text-primary size-10 shrink-0 self-center stroke-[1.5]"})]})]})]}),(0,a.jsxs)("section",{className:"space-y-3",children:[(0,a.jsx)("h2",{className:"text-base font-semibold",children:y("Recharge Amount")}),(0,a.jsx)("div",{className:"border-border/70 w-full overflow-hidden rounded-md border md:w-3/5",children:(0,a.jsxs)("div",{className:"grid sm:grid-cols-[minmax(0,1fr)_240px]",children:[(0,a.jsxs)("div",{className:"space-y-5 p-5",children:[(0,a.jsx)("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:I.map(e=>(0,a.jsxs)("button",{type:"button",onClick:()=>S(String(e)),"aria-pressed":s===e,className:(0,u.cn)("h-12 rounded-md border font-sans text-base font-semibold tabular-nums transition-colors",s===e?"border-foreground bg-surface-active":"border-border hover:border-border-strong hover:bg-surface-hover"),children:["$",e]},e))}),(0,a.jsxs)("div",{className:"relative max-w-44",children:[(0,a.jsx)("span",{className:"text-muted-foreground pointer-events-none absolute top-1/2 left-4 -translate-y-1/2 text-base",children:"$"}),(0,a.jsx)(v.p,{id:"topup-amount",type:"number",value:j,onChange:e=>S(e.target.value),min:10,placeholder:"10",className:"h-10 rounded-md pl-8 text-base","aria-label":y("Custom Amount")})]}),z?(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:y("Minimum topup amount: {{amount}}",{amount:"$10"})}):null]}),(0,a.jsxs)("div",{className:"border-border/70 bg-background-secondary flex flex-col justify-center gap-1.5 border-t p-5 sm:border-t-0 sm:border-l",children:[(0,a.jsx)("p",{className:"text-text-secondary text-sm",children:y("Payment total (live exchange rate)")}),(0,a.jsx)("div",{className:"font-sans text-3xl font-semibold tracking-tight tabular-nums",children:"alipay"===k?`\xa5${M.toFixed(2)}`:`$${M.toFixed(2)}`})]})]})})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-3 border-t pt-5 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsx)(N.$,{size:"lg",className:"h-11 w-full px-8 sm:w-auto",disabled:z||R,onClick:()=>{z||R||("alipay"===k&&C?d(C):"stripe"===k?p?.():"plisio"===k&&g?.())},children:y(R?"Processing":"Confirm top-up")}),(0,a.jsx)("p",{className:"text-text-tertiary flex-1 text-xs sm:pl-2",children:y("Final checkout amount may include dynamic processing fees charged by the payment gateway")})]})]}),(0,a.jsx)("div",{className:"border-border/70 bg-background-secondary text-text-secondary flex h-12 w-full items-center justify-center border-t text-xs font-medium",children:y("Supported payment methods")})]}):(0,a.jsx)(eU.Fc,{children:(0,a.jsx)(eU.TN,{children:y("Online topup is not enabled. Please use redemption code or contact administrator.")})})]})}var e0=s(48196),e1=s(64335);function e2(e,t){return new Intl.NumberFormat(t,{maximumFractionDigits:0}).format(e)}function e5(e){let{label:t,options:s,selected:r,onToggle:n,onClear:i,allLabel:l}=e,o=0===r.size?l:r.size<=2?Array.from(r).join(", "):`${r.size}`;return(0,a.jsxs)(e0.AM,{children:[(0,a.jsxs)(e0.Wv,{render:(0,a.jsx)(N.$,{type:"button",variant:"outline",size:"sm",className:"h-8 gap-1.5 px-2.5 text-xs font-normal"}),children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:t}),(0,a.jsx)("span",{className:"max-w-40 truncate font-medium",children:o}),(0,a.jsx)(c.yQN,{className:"size-3.5 opacity-60"})]}),(0,a.jsxs)(e0.hl,{align:"start",className:"w-56 p-1",children:[(0,a.jsxs)("button",{type:"button",onClick:i,className:(0,u.cn)("hover:bg-muted flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs",0===r.size&&"font-medium"),children:[(0,a.jsx)(c.Jlk,{className:(0,u.cn)("size-3.5",0===r.size?"opacity-100":"opacity-0")}),l]}),(0,a.jsx)("div",{className:"max-h-64 overflow-y-auto",children:s.map(e=>(0,a.jsxs)("button",{type:"button",onClick:()=>n(e),className:"hover:bg-muted flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs",children:[(0,a.jsx)(c.Jlk,{className:(0,u.cn)("size-3.5",r.has(e)?"opacity-100":"opacity-0")}),(0,a.jsx)("span",{className:"truncate",children:e})]},e))})]})]})}function e3(){let{t:e,i18n:t}=(0,n.Bd)(),s=t.resolvedLanguage?.startsWith("zh")?"zh-CN":"en-US",[i,l]=(0,r.useState)("today"),[m,x]=(0,r.useState)({}),[p,h]=(0,r.useState)(new Set),[f,g]=(0,r.useState)(new Set),y=(0,r.useMemo)(()=>
1{if("custom"===i&&m.start&&m.end)return{start:m.start,end:m.end};let e=new Date,t=new Date(e.getFullYear(),e.getMonth(),e.getDate());switch(i){case"yesterday":return{start:new Date(t.getTime()-864e5),end:t};case"7d":return{start:new Date(t.getTime()-5184e5),end:e};case"30d":return{start:new Date(t.getTime()-25056e5),end:e};default:return{start:t,end:e}}},[i,m]),j=Math.floor(y.start.getTime()/1e3),v=Math.floor(y.end.getTime()/1e3),w=(0,b.I)({queryKey:["wallet-token-usage",j,v],queryFn:async()=>{let e=await o.FH.get("/api/log/self/token-usage",{params:{start_timestamp:j,end_timestamp:v}});return e.data?.data??[]},staleTime:6e4}),k=w.data??[],_=(0,r.useMemo)(()=>Array.from(new Set(k.map(e=>e.model_name))).sort(),[k]),S=(0,r.useMemo)(()=>Array.from(new Set(k.map(e=>e.group))).sort(),[k]),C=k.filter(e=>(0===p.size||p.has(e.model_name))&&(0===f.size||f.has(e.group))),q=C.reduce((e,t)=>(e.prompt+=t.prompt_tokens,e.completion+=t.completion_tokens,e.quota+=t.quota,e.count+=t.count,e),{prompt:0,completion:0,quota:0,count:0}),F=(0,r.useMemo)(()=>{let e=new Map;
1return C.forEach(t=>{let s=e.get(t.model_name)??{prompt:0,completion:0,quota:0,count:0};e.set(t.model_name,{prompt:s.prompt+t.prompt_tokens,completion:s.completion+t.completion_tokens,quota:s.quota+t.quota,count:s.count+t.count})}),Array.from(e,e=>{let[t,s]=e;return{name:t,...s}}).sort((e,t)=>t.prompt+t.completion-(e.prompt+e.completion))},[C]),A=e=>t=>e(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s}),z=[{key:"today",label:e("Today")},{key:"yesterday",label:e("Yesterday")},{key:"7d",label:e("Last 7 days")},{key:"30d",label:e("Last 30 days")}];return(0,a.jsxs)("section",{className:"border-border/70 bg-card rounded-md border",children:[(0,a.jsxs)("div",{className:"border-border/60 flex flex-wrap items-center justify-between gap-3 border-b px-5 py-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-base font-semibold",children:e("Token usage stats")}),(0,a.jsx)("p",{className:"text-muted-foreground mt-1 text-xs",children:e("Token consumption by model and group for the selected period.")})]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("div",{className:"bg-muted/60 inline-flex items-center gap-0.5 rounded-md p-0.5",children:z.map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>l(e.key),className:(0,u.cn)("rounded px-2.5 py-1 text-xs transition-colors",i===e.key?"bg-background text-foreground font-medium shadow-sm":"text-muted-foreground hover:text-foreground"),children:e.label},e.key))}),(0,a.jsx)(e1.A,{start:"custom"===i?m.start:y.start,end:"custom"===i?m.end:y.end,onChange:e=>{x(e),l("custom")}}),(0,a.jsx)(e5,{label:e("Model"),options:_,selected:p,onToggle:A(h),onClear:()=>h(new Set),allLabel:e("All models")}),(0,a.jsx)(e5,{label:e("Group"),options:S,selected:f,onToggle:A(g),onClear:()=>g(new Set),allLabel:e("All groups")}),(0,a.jsx)(N.$,{type:"button",variant:"ghost",size:"icon",className:"size-8",onClick:()=>w.refetch(),children:(0,a.jsx)(c.e9t,{className:(0,u.cn)("size-3.5",w.isFetching&&"animate-spin")})})]})]}),(0,a.jsx)("div",{className:"grid grid-cols-2 gap-px sm:grid-cols-5",children:[{label:e("Total tokens"),value:e2(q.prompt+q.completion,s)},{label:e("Input tokens"),value:e2(q.prompt,s)},{label:e("Output tokens"),value:e2(q.completion,s)},{label:e("Requests"),value:e2(q.count,s)},{label:e("Spend"),value:(0,d.qW)(q.quota)}].map(e=>(0,a.jsxs)("div",{className:"px-5 py-4",children:[(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:e.label}),(0,a.jsx)("p",{className:"mt-1 text-lg font-semibold tabular-nums",children:w.isLoading?"—":e.value})]},e.label))}),F.length>0&&(0,a.jsxs)("div",{className:"border-border/60 border-t px-5 py-3",children:[(0,a.jsxs)("div",{className:"text-text-tertiary grid grid-cols-[minmax(0,2fr)_repeat(4,minmax(0,1fr))] gap-2 py-2 text-[11px]",children:[(0,a.jsx)("span",{children:e("Model")}),(0,a.jsx)("span",{className:"text-right",children:e("Input tokens")}),(0,a.jsx)("span",{className:"text-right",children:e("Output tokens")}),(0,a.jsx)("span",{className:"text-right",children:e("Requests")}),(0,a.jsx)("span",{className:"text-right",children:e("Spend")})]}),(0,a.jsx)("div",{className:"divide-border/50 divide-y",children:F.map(e=>(0,a.jsxs)("div",{className:"grid grid-cols-[minmax(0,2fr)_repeat(4,minmax(0,1fr))] gap-2 py-2 text-xs",children:[(0,a.jsx)("span",{className:"truncate font-medium",children:e.name}),(0,a.jsx)("span",{className:"text-right tabular-nums",children:e2(e.prompt,s)}),(0,a.jsx)("span",{className:"text-right tabular-nums",children:e2(e.completion,s)}),(0,a.jsx)("span",{className:"text-right tabular-nums",children:e2(e.count,s)}),(0,a.jsx)("span",{className:"text-right tabular-nums",children:(0,d.qW)(e.quota)})]},e.name))})]})]})}var e4=s(55581),e7=s(3521),e6=s(78202),e8=s(58254),e9=s(95846),te=s(67839),tt=s(29119);function ts(){let e=new Date,t=new Date(Date.now()-25056e5);return t.setHours(0,0,0,0),{start:t,end:e}}function ta(e){let{label:t,value:s,accent:r}=e;return(0,a.jsxs)("span",{className:"border-border/70 bg-muted/20 inline-flex h-7 items-center gap-2 rounded-md border px-2.5 text-[11px]",children:[(0,a.jsx)("span",{className:(0,u.cn)("h-3.5 w-0.5 rounded-full",r)}),(0,a.jsx)("span",{className:"text-muted-foreground",children:t}),(0,a.jsx)("span",{className:"text-foreground font-mono font-semibold tabular-nums",children:s})]})}function tr(e){let{range:t,onRangeChange:s,type:i,onTypeChange:l,model:d,token:m,group:x,username:p,requestId:h,upstreamRequestId:f,isAdmin:g,onChange:y,onReset:j,onDownload:w,downloading:k}=e,{t:_}=(0,n.Bd)(),S=(e,t,s)=>(0,a.jsx)(v.p,{value:t,onChange:t=>y(e,t.target.value),placeholder:s,className:"h-8 text-xs"}),C="__all__",{data:q}=(0,b.I)({queryKey:["finance-filter-keys"],queryFn:()=>(0,e6.PX)({p:1,size:100}),staleTime:6e4}),F=(0,r.useMemo)(()=>(q?.data?.items??[]).map(e=>e.name).filter(e=>!!e),[q]),{data:A}=(0,b.I)({queryKey:["finance-filter-groups"],queryFn:o.K4,staleTime:3e5}),z=(0,r.useMemo)(()=>Object.keys(A?.data??{}).sort(),[A]),R=(e,t,s,r)=>(0,a.jsxs)(eL.l6,{value:t||C,onValueChange:t=>y(e,null===t||t===C?"":t),children:[(0,a.jsx)(eL.bq,{size:"sm",className:"w-full",children:(0,a.jsx)(eL.yv,{children:t||r})}),(0,a.jsx)(eL.gC,{alignItemWithTrigger:!1,children:(0,a.jsxs)(eL.s3,{children:[(0,a.jsx)(eL.eb,{value:C,children:r}),s.map(e=>(0,a.jsx)(eL.eb,{value:e,children:e},e))]})})]}),I=_(ew.yt.find(e=>e.value===i)?.label??"All Types");return(0,a.jsxs)("div",{className:"border-border/70 bg-card space-y-3 rounded-lg border p-3.5 sm:p-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 lg:flex-row lg:items-center lg:justify-between",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)(e1.A,{start:t.start,end:t.end,onChange:e=>{e.start&&e.end&&s({start:e.start,end:e.end})},className:"w-auto"}),(0,a.jsxs)(eL.l6,{value:i,onValueChange:e=>e&&l(e),children:[(0,a.jsx)(eL.bq,{size:"sm",className:"w-32",children:(0,a.jsx)(eL.yv,{children:I})}),(0,a.jsx)(eL.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(eL.s3,{children:ew.yt.map(e=>(0,a.jsx)(eL.eb,{value:e.value,children:_(e.label)},e.value))})})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)(N.$,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:w,disabled:k,children:[(0,a.jsx)(c.f5X,{className:(0,u.cn)("size-3.5",k&&"animate-bounce")}),k?_("Preparing..."):_("Download details")]}),(0,a.jsx)(N.$,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:j,children:_("Reset filters")})]})]}),(0,a.jsxs)("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-5",children:[g?S("username",p,_("Username")):null,S("model",d,_("Model name")),R("token",m,F,_("All Keys")),R("group",x,z,_("All groups")),S("requestId",h,_("Conversation ID / request ID")),S("upstreamRequestId",f,_("Upstream request ID"))]}),(0,a.jsx)("p",{className:"text-muted-foreground text-[11px]",children:_("Every field comes from the actual usage log, including model, endpoint, key, token, cache, web search, billing mode, plan usage percentage, latency and streaming status.")})]})}function tn(){let{t:e}=(0,n.Bd)(),t=(0,ej.h)(),i=(0,r.useMemo)(ts,[]),[l,o]=(0,r.useState)(i),[m,x]=(0,r.useState)("0"),[p,h]=(0,r.useState)({username:"",model:"",token:"",group:"",requestId:"",upstreamRequestId:""}),[f,g]=(0,r.useState)({pageIndex:0,pageSize:50}),y=(0,r.useMemo)(()=>{let e="0"===m?void 0:Number(m);return{p:f.pageIndex+1,page_size:f.pageSize,type:e,username:t&&p.username.trim()||void 0,model_name:p.model.trim()||void 0,token_name:p.token.trim()||void 0,group:p.group.trim()||void 0,request_id:p.requestId.trim()||void 0,upstream_request_id:p.upstreamRequestId.trim()||void 0,start_timestamp:Math.floor(l.start.getTime()/1e3),end_timestamp:Math.floor(l.end.getTime()/1e3)}},[p,t,f.pageIndex,f.pageSize,l,m]),{data:j,isLoading:v,isFetching:k,refetch:_}=(0,b.I)({queryKey:["finance-usage-detail",t,y],queryFn:async()=>{let e=t?await (0,ev.jp)(y):await (0,ev.ni)(y);if(!e.success)throw Error(e.message||"Failed to load usage details");return e.data??{items:[],total:0,page:1,page_size:50}},placeholderData:e=>e}),S=(0,r.useMemo)(()=>{let{p:e,page_size:t,...s}=y;return s},[y]),{data:C}=(0,b.I)({queryKey:["finance-usage-stats",t,S],queryFn:async()=>{let e=t?await (0,ev.Q_)(S):await (0,ev.DV)(S);return e.success?e.data??{quota:0,rpm:0,tpm:0}:{quota:0,rpm:0,tpm:0}},placeholderData:e=>e}),q=j?.items??[],F=(0,e9.L)(t),A=(0,e4.N4)({data:q,columns:F,state:{pagination:f},onPaginationChange:g,getCoreRowModel:(0,e7.HT)(),getFilteredRowModel:(0,e7.hM)(),getPaginationRowModel:(0,e7.kW)(),manualPagination:!0,manualFiltering:!0,pageCount:Math.ceil((j?.total??0)/f.pageSize)}),[z,R]=(0,r.useState)(!1),I=async()=>
1{if(!z){R(!0);try{let a=[];for(let e=1;e<=10;e++){let s={...y,p:e,page_size:1e3},r=t?await (0,ev.jp)(s):await (0,ev.ni)(s);if(!r.success)break;let n=r.data?.items??[];if(a.push(...n),n.length<1e3)break}let r=await s.e(477).then(s.bind(s,29388)),{parseLogOther:n}=await Promise.resolve().then(s.bind(s,6996)),i=[e("Created At"),...t?[e("Username")]:[],"KEY",e("Endpoint"),e("Model"),e("Group"),e("Input tokens"),e("Output tokens"),e("Total tokens"),e("Web Search"),e("Cache Hit Rate"),e("Mode"),`${e("Latency")} (s)`,"TPS (t/s)",e("Billing Mode"),`${e("Input")} ($/M)`,`${e("Output")} ($/M)`,e("Discount Ratio"),`${e("Spend")} (USD)`,e("Request ID"),e("Upstream Request ID")],l=a.map(s=>{let a=n(s.other),r=a?.public_usage?.prompt_tokens??s.prompt_tokens??0,i=a?.public_usage?.completion_tokens??s.completion_tokens??0,l=a?.public_usage?.total_tokens??r+i,o=a?.cache_tokens||0,c=r>0&&o>0?`${Math.min(100,o/r*100).toFixed(1)}%`:"-",m=s.use_time>0&&i>0?Number((i/s.use_time).toFixed(1)):"",u=a?.model_ratio!=null?2*a.model_ratio:null,x=a?.billing_mode==="tiered_expr"?e("Dynamic Pricing"):a?.model_price!=null&&a.model_price>0?e("Per-call"):a?.model_ratio!=null?e("Per-token"):"-",p=null!=u?Number(u.toFixed(4)):"",h=null!=u&&a?.completion_ratio!=null?Number((u*a.completion_ratio).toFixed(4)):"",f=a?.group_ratio,g=null!=f&&Number.isFinite(f)&&f>0&&f<1?`\xd7${f%1==0?f:f.toFixed(4).replace(/\.?0+$/,"")}`:"";return[new Date(1e3*s.created_at).toLocaleString(),...t?[s.username]:[],s.token_name,s.request_path,s.model_name,s.group,r,i,l,a?.web_search_call_count||0,c,s.is_stream?e("Stream"):e("Non-stream"),s.use_time,m,x,p,h,g,Number((0,d.Sh)(s.quota).toFixed(6)),s.request_id,s.upstream_request_id]}),o=r.utils.aoa_to_sheet([i,...l]),c=r.utils.book_new();r.utils.book_append_sheet(c,o,e("Usage details"));let m=new Date().toISOString().slice(0,16).replace(/[-:T]/g,"");r.writeFile(c,`usage-details-${m}.xlsx`)}finally{R(!1)}}};return(0,a.jsxs)("section",{className:"border-border/70 bg-card rounded-lg border",children:[(0,a.jsx)("div",{className:"border-border/70 flex flex-col gap-3 border-b px-4 py-4 sm:px-5 sm:py-5",children:(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[(0,a.jsx)("div",{children:(0,a.jsx)("h2",{className:"text-base font-semibold",children:e("Complete usage details")})}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("div",{className:"flex flex-wrap gap-1.5",children:[(0,a.jsx)(ta,{label:e("Usage"),value:(0,d.qW)(C?.quota??0),accent:"bg-chart-1/70"}),(0,a.jsx)(ta,{label:e("RPM"),value:C?.rpm??0,accent:"bg-chart-2/70"}),(0,a.jsx)(ta,{label:e("TPM"),value:C?.tpm??0,accent:"bg-chart-5/70"})]}),(0,a.jsx)(N.$,{variant:"ghost",size:"icon-sm","aria-label":e("Refresh usage details"),onClick:()=>void _(),disabled:k,children:(0,a.jsx)(c.e9t,{className:(0,u.cn)("size-3.5",k&&"animate-spin")})})]})]})}),(0,a.jsx)("div",{className:"p-3.5 sm:p-4",children:(0,a.jsx)(tr,{range:l,onRangeChange:o,type:m,onTypeChange:e=>{x(e),g(e=>({...e,pageIndex:0}))},...p,isAdmin:t,onChange:(e,t)=>
1{h(s=>({...s,[e]:t})),g(e=>({...e,pageIndex:0}))},onReset:()=>{o(ts()),x("0"),h({username:"",model:"",token:"",group:"",requestId:"",upstreamRequestId:""}),g(e=>({...e,pageIndex:0}))},onDownload:I,downloading:z})}),(0,a.jsx)(e8.cx,{table:A,columns:F,isLoading:v,isFetching:k,emptyTitle:e("No Logs Found"),emptyDescription:e("No usage logs match the current filters."),skeletonKeyPrefix:"finance-usage-detail",paginationInFooter:!1,applyHeaderSize:"percentage",tableClassName:"rounded-none border-x-0 border-b-0",tableHeaderClassName:"sticky top-0 z-10 bg-muted/30",mobile:(0,a.jsx)(te.L,{table:A,isLoading:v,logCategory:"common"}),renderRow:e=>(0,a.jsx)(w.Hj,{className:(0,u.cn)("hover:bg-surface-hover transition-colors",6===e.original.type&&"bg-primary/5 dark:bg-primary/10",5===e.original.type&&"bg-red-50/40 dark:bg-red-950/20"),children:e.getVisibleCells().map(e=>(0,a.jsx)(w.nA,{className:"px-3 py-2.5 text-[13px]",children:(0,e4.Kv)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)}),(0,a.jsx)("div",{className:"text-muted-foreground flex items-center border-t px-4 py-3 text-xs",children:(0,a.jsxs)("span",{children:[(j?.total??0).toLocaleString()," records · Page"," ",f.pageIndex+1]})})]})}function ti(){return(0,a.jsx)(tt.m,{children:(0,a.jsx)(tn,{})})}function tl(e){if(Array.isArray(e))return e;if("string"==typeof e)try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{}return[]}let to={company_name:"",tax_number:"",bank_name:"",bank_account:"",address:"",phone:"",email:""};function td(){let{t:e}=(0,n.Bd)(),t=(0,l.n)(e=>e.auth.user),s=[{label:"Available quota",value:(0,d.eN)(t?.quota??0),description:"Balance available for model calls",icon:c.lTC,iconClass:"bg-primary/10 text-primary",valueClass:"text-primary"},{label:"Cumulative usage",value:(0,d.eN)(t?.used_quota??0),description:"Total model charges on this account",icon:c.VH9,iconClass:"bg-amber-500/10 text-amber-600 dark:text-amber-400",valueClass:"text-foreground"},{label:"API requests",value:(t?.request_count??0).toLocaleString(),description:"Total completed API requests",icon:c.Ilq,iconClass:"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",valueClass:"text-foreground"}];return(0,a.jsx)("div",{className:"grid gap-3 md:grid-cols-3",children:s.map(t=>{let s=t.icon;return(0,a.jsxs)("div",{className:"border-border/70 bg-card rounded-lg border p-4 sm:p-5",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,a.jsx)("span",{className:(0,u.cn)("flex size-8 shrink-0 items-center justify-center rounded-md",t.iconClass),children:(0,a.jsx)(s,{className:"size-4"})}),(0,a.jsx)("span",{className:"text-muted-foreground text-xs font-medium tracking-wide",children:e(t.label)})]}),(0,a.jsx)("p",{className:(0,u.cn)("mt-3 font-mono text-2xl font-semibold tracking-tight tabular-nums",t.valueClass),children:t.value}),(0,a.jsx)("p",{className:"text-muted-foreground mt-1 text-xs",children:e(t.description)})]},t.label)})})}function tc(e){let{activeTab:t,onChange:s,isAdmin:r}=e,{t:i}=(0,n.Bd)(),l=[{value:"overview",label:"Finance overview",description:"Balance and top-ups"},{value:"usage",label:"Usage analytics",description:"Model usage and charges"},{value:"ledger",label:"Transaction ledger",description:"All balance movements"},{value:"invoice",label:"Invoice management",description:"Details, requests and records"},...r?[{value:"cacheRefund",label:"Cache refund review",description:"Approve auto-detected cache anomalies"}]:[]];return(0,a.jsx)("div",{className:"border-border/70 bg-card mt-3 flex flex-wrap gap-1 rounded-lg border p-1.5",children:l.map(e=>(0,a.jsxs)("button",{type:"button",onClick:()=>s(e.value),className:(0,u.cn)("relative flex min-w-[132px] flex-1 flex-col items-start rounded-md px-3 py-2 text-left transition-colors sm:flex-none",t===e.value?"bg-foreground text-background shadow-sm":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:["invoice"===e.value&&(0,a.jsxs)("span",{className:"bg-primary text-primary-foreground pointer-events-none absolute -top-2 left-3 -translate-y-full rounded-md px-2 py-0.5 text-[11px] font-medium whitespace-nowrap shadow-sm",children:[i("Finance-grade statement export now available"),(0,a.jsx)("span",{className:"bg-primary absolute -bottom-1 left-4 size-2 rotate-45"})]}),(0,a.jsx)("span",{className:"text-sm font-semibold",children:i(e.label)}),(0,a.jsx)("span",{className:(0,u.cn)("mt-0.5 text-[11px]",t===e.value?"text-background/70":"text-muted-foreground
1/80"),children:i(e.description)})]},e.value))})}function tm(e){let{t}=(0,n.Bd)();(0,x.H)(t("Finance center"));let[s,d]=(0,r.useState)(0),[c,u]=(0,r.useState)(),[g,b]=(0,r.useState)(null),[y,j]=(0,r.useState)(!1),[N,v]=(0,r.useState)(!1),[w,_]=(0,r.useState)(""),[S,q]=(0,r.useState)(),[F,z]=(0,r.useState)(e.initialShowHistory?"ledger":"overview"),R=(0,l.n)(e=>e.auth.user?.role),M=!!(R&&R>=m.z7.ADMIN),[T,$]=(0,r.useState)(!1),[P,H]=(0,r.useState)(!1),[W,ee]=(0,r.useState)("detail"),[et,er]=(0,r.useState)(""),[en,ei]=(0,r.useState)(""),{title:eh,savingTitle:ef,handleSaveTitle:eg,topups:eb,topupsLoading:ej,fetchTopups:eN,monthlyBills:ev,monthlyBillsLoading:ew,fetchMonthlyBills:ek,monthlyBillDetail:e_,monthlyBillDetailLoading:eS,fetchMonthlyBillDetail:eC,handleSubmitMonthlyRequest:eq,requests:eF,requestsLoading:eA,fetchRequests:ez,submitting:eR,handleSubmitRequest:eI}=function(){let[e,t]=(0,r.useState)(null),[s,a]=(0,r.useState)(!1),[n,l]=(0,r.useState)(!1),[o,d]=(0,r.useState)([]),[c,m]=(0,r.useState)(!1),[u,x]=(0,r.useState)([]),[p,h]=(0,r.useState)(!1),[f,g]=(0,r.useState)(null),[b,y]=(0,r.useState)(!1),[j,N]=(0,r.useState)([]),[v,w]=(0,r.useState)(0),[k,_]=(0,r.useState)(1),[S,C]=(0,r.useState)(!1),[q,F]=(0,r.useState)(!1),A=(0,r.useCallback)(async()=>{a(!0);try{let e=await el();J(e)&&t(e.data??null)}catch(e){console.error("Failed to fetch invoice title:",e)}finally{a(!1)}},[]),z=(0,r.useCallback)(async e=>{l(!0);try{let s=await eo(e);if(J(s))return i.oR.success(U.Ay.t("Invoice information saved")),t(e),!0;return i.oR.error(s.message||U.Ay.t("Failed to save invoice information")),!1}catch(e){return console.error("Failed to save invoice title:",e),i.oR.error(U.Ay.t("Failed to save invoice information")),!1}finally{l(!1)}},[]),R=(0,r.useCallback)(async()=>{m(!0);try{let e=await ed();J(e)?d(e.data??[]):d([])}catch(e){console.error("Failed to fetch invoiceable topups:",e),d([])}finally{m(!1)}},[]),I=(0,r.useCallback)(async()=>{C(!0);try{let e=await em(k,10);J(e)&&e.data?(N(e.data.items||[]),w(e.data.total||0)):(N([]),w(0))}catch(e){console.error("Failed to fetch invoice requests:",e),N([]),w(0)}finally{C(!1)}},[k]),M=(0,r.useCallback)(async e=>{F(!0);try{let t=await ec(e);if(J(t))return i.oR.success(U.Ay.t("Invoice request submitted")),await Promise.all([R(),I()]),!0;return i.oR.error(t.message||U.Ay.t("Failed to submit invoice request")),!1}catch(e){return console.error("Failed to submit invoice request:",e),i.oR.error(U.Ay.t("Failed to submit invoice request")),!1}finally{F(!1)}},[R,I]),T=(0,r.useCallback)(async()=>{h(!0);try{let e=await eu();J(e)?x(e.data??[]):x([])}catch(e){console.error("Failed to fetch monthly bills:",e),x([])}finally{h(!1)}},[]),$=(0,r.useCallback)(async e=>{if(!e)return void g(null);y(!0);try{let t=await ex(e);J(t)&&t.data?.month===e?g(t.data):g(null)}catch(e){console.error("Failed to fetch monthly bill detail:",e),g(null)}finally{y(!1)}},[]),E=(0,r.useCallback)(async e=>{F(!0);try{let t=await ep(e);if(J(t))return i.oR.success(U.Ay.t("Invoice request submitted")),await Promise.all([T(),I()]),!0;return i.oR.error(t.message||U.Ay.t("Failed to submit invoice request")),!1}catch(e){return console.error("Failed to submit monthly invoice request:",e),i.oR.error(U.Ay.t("Failed to submit invoice request")),!1}finally{F(!1)}},[T,I]);return(0,r.useEffect)(()=>{A()},[A]),(0,r.useEffect)(()=>{I()},[I]),{emptyTitle:to,title:e,titleLoading:s,savingTitle:n,fetchTitle:A,handleSaveTitle:z,topups:o,topupsLoading:c,fetchTopups:R,monthlyBills:u,monthlyBillsLoading:p,fetchMonthlyBills:T,monthlyBillDetail:f,monthlyBillDetailLoading:b,fetchMonthlyBillDetail:$,handleSubmitMonthlyRequest:E,requests:j,requestsTotal:v,requestsPage:k,setRequestsPage:_,requestsLoading:S,fetchRequests:I,submitting:q,handleSubmitRequest:M,pageSize:10}}();(0,r.useEffect)(()=>{"month"===W&&ek()},[W,ek]),(0,r.useEffect)(()=>{"month"===W&&eC(en)},[W,en,eC]);let eM=(0,r.useMemo)(()=>ev.find(e=>e.month===en)??null,[ev,en]),eT=(0,r.useMemo)(()=>"month"===W&&en?eb.filter(e=>{let t=new Date(1e3*e.create_time);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}`===en}):eb,[W,en,eb]),{currency:e$}=(0,p.R)(),{topupInfo:eE,loading:eP}=function(){let[e,t]=(0,r.useState)(null),[s,a]=(0,r.useState)([]),[n,i]=(0,r.useState)(!0),l=async()=>{try{var e,s,r,n,l,o,d,c;i(!0);let m=await K();if(!m.success||!m.data)return void console.error("Failed to fetch topup info:",m.message);let u={...m.data,pay_methods:(e=m.data.pay_methods,s=m.data.stripe_min_topup,tl(e).filter(e=>!!e&&"object"==typeof e).map(e=>{let t=Number(e.min_topup),a=Number.isFinite(t)?t:0,r="string"==typeof e.type?e.type:"";return{name:"string"==typeof e.name?e.name:"",type:r,color:"string"==typeof e.color?e.color:void 0,min_topup:"stripe"===r&&a<=0?s:a}}).filter(e=>e.name&&e.type&&"waffo"!==e.type)),amount_options:(r=m.data.amount_options,tl(r).map(e=>Number(e)).filter(e=>Number.isFinite(e)&&e>0)),discount:function(e){if(!e)return{};let t=e;if("string"==typeof e)try{t=JSON.parse(e)}catch{return{}}return!t||"object"!=typeof t||Array.isArray(t)?{}:Object.entries(t).reduce((e,t)=>
1{let[s,a]=t,r=Number(s),n=Number(a);return Number.isFinite(r)&&Number.isFinite(n)&&(e[r]=n),e},{})}(m.data.discount),creem_products:(n=m.data.creem_products,tl(n).filter(e=>!!e&&"object"==typeof e).map(e=>{let t="EUR"===e.currency?"EUR":"USD";return{name:"string"==typeof e.name?e.name:"",productId:"string"==typeof e.productId?e.productId:"",price:Number(e.price)||0,quota:Number(e.quota)||0,currency:t}}).filter(e=>e.name&&e.productId)),waffo_pay_methods:(l=m.data.waffo_pay_methods,tl(l).filter(e=>!!e&&"object"==typeof e).map(e=>({name:"string"==typeof e.name?e.name:"",icon:"string"==typeof e.icon?e.icon:void 0,payMethodType:"string"==typeof e.payMethodType?e.payMethodType:void 0,payMethodName:"string"==typeof e.payMethodName?e.payMethodName:void 0})).filter(e=>e.name))};if(t(u),u.amount_options.length>0){let e=(o=u.amount_options,d=u.discount||{},o&&0!==o.length?o.map(e=>({value:e,discount:d[e]||1})):[]);a(e)}else{let e=(c=B(u),E.r0.map(e=>({value:c*e})));a(e)}}catch(e){console.error("Failed to fetch topup info:",e)}finally{i(!1)}};return(0,r.useEffect)(()=>
1{l()},[]),{topupInfo:e,presetAmounts:s,loading:n,refetch:l}}(),eL=(0,r.useMemo)(()=>e$?.quotaDisplayType==="USD"?1:e$?.usdExchangeRate||1,[e$?.quotaDisplayType,e$?.usdExchangeRate]),{amount:eO,calculating:eH,processing:eU,calculatePaymentAmount:eW,processPayment:eG}=function(){let[e,t]=(0,r.useState)(0),[s,a]=(0,r.useState)(!1),[n,l]=(0,r.useState)(!1);return{amount:e,calculating:s,processing:n,calculatePaymentAmount:(0,r.useCallback)(async(e,s)=>{try{a(!0);let r=D(s),n=L(s),i=r?await V({amount:e}):n?await es({amount:e}):await Y({amount:e});if(J(i)&&i.data){let e=parseFloat(i.data);return t(e),e}return t(0),0}catch(e){return t(0),0}finally{a(!1)}},[]),processPayment:(0,r.useCallback)(async(e,t)=>{try{l(!0);let r=D(t),n=Math.floor(e),o=r?await X({amount:n,payment_method:"stripe"}):await Q({amount:n,payment_method:t});if(!J(o))return i.oR.error(o.message||U.Ay.t("Payment request failed")),{ok:!1};if(r&&o.data?.pay_link)return window.open(o.data.pay_link,"_blank"),i.oR.success(U.Ay.t("Redirecting to payment page...")),{ok:!0};if(!r&&o.data){let e=o.qr||o.pay_url;if(e)return{ok:!0,qr:e,tradeNo:o.trade_no};if(o.url){var s,a;let e;return s=o.url,a=o.data,(e=document.createElement("form")).action=s,e.method="POST",navigator.userAgent.indexOf("Safari")>-1&&1>navigator.userAgent.indexOf("Chrome")||(e.target="_blank"),Object.entries(a).forEach(t=>{let[s,a]=t,r=document.createElement("input");r.type="hidden",r.name=s,r.value=String(a),e.appendChild(r)}),document.body.appendChild(e),e.submit(),document.body.removeChild(e),i.oR.success(U.Ay.t("Redirecting to payment page...")),{ok:!0}}}return{ok:!1}}catch(e){return i.oR.error(U.Ay.t("Payment request failed")),{ok:!1}}finally{l(!1)}},[]),setAmount:t}}(),{processing:eJ,processCreemPayment:eK}=function(){let[e,t]=(0,r.useState)(!1);return{processing:e,processCreemPayment:(0,r.useCallback)(async e=>{t(!0);try{let t=await Z({product_id:e.productId,amount:e.amount,payment_method:"creem"}),s="object"==typeof t.data&&t.data?t.data.checkout_url:void 0;if(J(t)&&s)return window.open(s,"_blank"),i.oR.success(U.Ay.t("Redirecting to Creem checkout...")),!0;let a="string"==typeof t.data&&t.data?t.data:t.message;return i.oR.error(a||U.Ay.t("Payment request failed")),!1}catch(e){return i.oR.error(U.Ay.t("Payment request failed")),!1}finally{t(!1)}},[])}}(),{processing:eY,processStripePayment:eV}=function(){let[e,t]=(0,r.useState)(!1);return{processing:e,processStripePayment:(0,r.useCallback)(async e=>{t(!0);try{let t=await X({amount:e,payment_method:"stripe"}),s=t.data?.pay_link;if(J(t)&&s)return window.open(s,"_blank"),i.oR.success(U.Ay.t("Redirecting to Stripe checkout...")),!0;return i.oR.error(t.message||U.Ay.t("Payment request failed")),!1}catch(e){return i.oR.error(U.Ay.t("Payment request failed")),!1}finally{t(!1)}},[])}}(),[eQ,eX]=(0,r.useState)(!1),{processing:e0,processWaffoPancakePayment:e1}=function(){let[e,t]=(0,r.useState)(!1);return{processing:e,processWaffoPancakePayment:(0,r.useCallback)(async e=>{t(!0);try{var s,a,r;let t=await ea({amount:Math.floor(e)});if(J(t)){let e=(s=t.data)&&"object"==typeof s&&"checkout_url"in s&&"string"==typeof s.checkout_url?s.checkout_url:null;if(e){if(!function(e){let t=e.trim();if(!t)return!1;try{let e=new URL(t);return"http:"===e.protocol||"https:"===e.protocol}catch{return!1}}(e))return i.oR.error(U.Ay.t("Invalid payment redirect URL")),!1;return i.oR.success(U.Ay.t("Redirecting to payment page...")),window.location.href=e,!0}}return i.oR.error((a=t.message,r=t.data,"string"==typeof r&&r.trim()?r:a||U.Ay.t("Payment request failed"))),!1}catch(e){return i.oR.error(U.Ay.t("Payment request failed")),!1}finally{t(!1)}},[])}}();(0,r.useEffect)(()=>{e.initialShowHistory&&(z("ledger"),window.history.replaceState({},"",window.location.pathname))},[e.initialShowHistory]),(0,r.useEffect)(()=>{"invoice"===F&&eN()},[F,eN]);let e2=(0,r.useRef)(!1);(0,r.useEffect)(()=>{if(!eE||e2.current)return;e2.current=!0;let e=B(eE);s<e&&(d(e),eW(e,O(eE)))},[eE,s,eW]);let e5=(0,r.useCallback)(()=>c?.type||O(eE),[c,eE]),e4=async e=>{u(e),b(e.type);try{let t=B(eE);if(s<t)return;await eW(s,e.type),j(!0)}finally{b(null)}},e7=async()=>
1{if(!c)return;if(L(c.type)){await e1(s)&&j(!1);return}let e=await eG(s,c.type);e.ok&&(j(!1),e.qr&&(_(e.qr),q(e.tradeNo),v(!0)))},e6=(0,r.useCallback)(async()=>{try{let e=await (0,o.Ng)();e?.success&&e.data&&l.n.getState().auth.setUser(e.data)}catch{}},[]),e8=async()=>{let e=eE?.stripe_min_topup??1;s<e?i.oR.error(t("Minimum topup amount: {{amount}}",{amount:`$${e}`})):await eV(s)},e9=(0,r.useCallback)(()=>eE?.discount?.[s]||1,[eE,s]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(h.Ni,{children:(0,a.jsx)(h.Ni.Content,{children:(0,a.jsxs)("div",{className:"mx-auto flex w-full max-w-[1440px] flex-col gap-4 sm:gap-5",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1.5 text-sm leading-5",children:[(0,a.jsx)("span",{className:"text-text-tertiary",children:t("Finance center")}),(0,a.jsx)("span",{className:"text-text-tertiary","aria-hidden":"true",children:"/"}),(0,a.jsx)("span",{className:"text-foreground font-semibold",children:"overview"===F?t("Finance overview"):"usage"===F?t("Usage analytics"):"ledger"===F?t("Transaction ledger"):"c
1acheRefund"===F?t("Cache refund review"):t("Invoice management")})]}),(0,a.jsx)(td,{}),(0,a.jsx)(tc,{activeTab:F,onChange:z,isAdmin:M}),"overview"===F?(0,a.jsx)(a.Fragment,{children:(0,a.jsx)("div",{id:"wallet-add-funds",className:"scroll-mt-4",children:(0,a.jsx)(eZ,{topupInfo:eE,topupAmount:s,onTopupAmountChange:e=>{d(e),eW(e,e5())},paymentAmount:eO,calculating:eH,onPaymentMethodSelect:e4,paymentLoading:g,loading:eP,activeTab:"recharge",onTabChange:e=>z("billing"===e?"ledger":"overview"),onStripeAmountPay:e8,stripeProcessing:eY,enablePlisioTopup:eE?.enable_plisio_topup,onPlisioAmountPay:()=>{let e=eE?.plisio_min_topup??10;s<e?i.oR.error(t("Minimum topup amount: {{amount}}",{amount:`$${e}`})):eX(!0)}})})}):"usage"===F?(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("section",{className:"border-border/70 bg-card rounded-lg border p-4 sm:p-5",children:[(0,a.jsxs)("div",{className:"mb-3",children:[(0,a.jsx)("h2",{className:"text-base font-semibold",children:t("Usage analytics")}),(0,a.jsx)("p",{className:"text-muted-foreground mt-1 text-xs",children:t("Review model usage and quota consumption over the last 30 days.")})]}),(0,a.jsx)(f.c,{})]}),(0,a.jsx)(e3,{}),(0,a.jsx)(ti,{})]}):"ledger"===F?(0,a.jsx)(eD,{defaultFilter:e.initialShowHistory?"income":"all"}):"cacheRefund"===F?(0,a.jsx)(k,{}):(0,a.jsx)(eB,{topups:eb,topupsLoading:ej,mode:W,amountTarget:et,month:en,monthlyBills:ev,monthlyBillsLoading:ew,monthlyBillDetail:e_,monthlyBillDetailLoading:eS,onModeChange:ee,onAmountTargetChange:er,onMonthChange:ei,title:eh,onEditTitle:()=>$(!0),onApply:()=>H(!0),requests:eF,requestsLoading:eA,onRefreshRequests:ez})]})})}),(0,a.jsx)(C,{open:N,onOpenChange:v,qr:w,tradeNo:S,onPaid:e6}),(0,a.jsx)(ey,{open:eQ,onOpenChange:eX,amount:s,onPaid:e6}),(0,a.jsx)(G,{open:y,onOpenChange:j,onConfirm:e7,topupAmount:s,paymentAmount:eO,paymentMethod:c,calculating:eH,processing:eU||e0,discountRate:e9(),usdExchangeRate:eL}),(0,a.jsx)(I,{open:T,onOpenChange:$,title:eh,saving:ef,onSave:eg}),(0,a.jsx)(A,{open:P,onOpenChange:H,topups:eT,topupsLoading:ej,title:eh,mode:W,amountTarget:et,monthlyBill:eM,submitting:eR,onRefreshTopups:eN,onSubmit:eI,onSubmitMonthly:eq})]})}var tu=s(83653);function tx(){let{show_history:e}=tu.q.useSearch();return(0,a.jsx)(tm,{initialShowHistory:e})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.