2 lines
9.0 KiB
JavaScript
2 lines
9.0 KiB
JavaScript
import{u as M,d as $,a as B,r,g as O,e as G,j as e,Q as x,L as l,f as H,z as p,h as J,t as V}from"./index-CpYyIBrK.js";import{C as b}from"./CountUp-Dbx9PbbK.js";import{u as W}from"./useTranslation-3oSnFigB.js";function ee(){const{t:s}=W(),{user:a,refreshUser:j}=M(),{symbol:d,rate:c}=$(),{site:h}=B(),[o,L]=r.useState(null),[f,N]=r.useState(""),[v,y]=r.useState(!1),[m,D]=r.useState(""),[w,T]=r.useState([]),[u,U]=r.useState(!1),[P,k]=r.useState(!1),[S,q]=r.useState(""),[C,_]=r.useState(!1),g=r.useCallback(async()=>{var t;try{const[n,i]=await Promise.all([O(),G().catch(()=>null)]);n.data.success&&L(n.data.data),(t=i==null?void 0:i.data)!=null&&t.success&&i.data.data&&D(`${window.location.origin}/register?aff=${i.data.data}`)}catch{}},[]);r.useEffect(()=>{g()},[g]);const R=async t=>{if(t.preventDefault(),!!f.trim()){y(!0);try{(await H(f.trim())).data.success&&(p.success(s("dashboard.redeemSuccess")),N(""),await Promise.all([g(),j()]))}catch{}y(!1)}},F=async()=>{k(!0);try{const t=await J({page:1,page_size:20});t.data.success&&t.data.data&&T(t.data.data)}catch{}k(!1)},z=()=>{m&&navigator.clipboard.writeText(m).then(()=>{p.success(s("topup.copied"))}).catch(()=>{p.error("Copy failed")})},I=async()=>{const t=parseInt(S);if(!t||t<=0){p.error(s("topup.enterAmount"));return}_(!0);try{const n=await V({quota:t});n.data.success&&(p.success(n.data.message||s("topup.transferSuccess")),q(""),await Promise.all([g(),j()]))}catch{}_(!1)},A=(o==null?void 0:o.quota)??(a==null?void 0:a.quota)??0,E=(o==null?void 0:o.used_quota)??(a==null?void 0:a.used_quota)??0,Q=(o==null?void 0:o.request_count)??(a==null?void 0:a.request_count)??0,K=A/x*c;return e.jsxs("div",{className:"max-w-7xl mx-auto px-6 py-10",children:[e.jsxs("div",{className:"mb-8",children:[e.jsxs("h1",{className:"text-2xl font-heading font-bold text-page mb-1",children:[s("dashboard.welcome")," ",(a==null?void 0:a.display_name)||(a==null?void 0:a.username)||"User"]}),e.jsx("p",{className:"text-sm text-page-secondary",children:s("dashboard.manageDesc")})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-10",children:[e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("p",{className:"text-sm text-page-secondary mb-2",children:s("dashboard.balance")}),e.jsxs("div",{className:"text-3xl font-bold text-page",children:[d,e.jsx(b,{from:0,to:Math.round(K*100)/100,duration:1.5})]}),e.jsx("p",{className:"text-xs text-page-muted mt-1",children:s("dashboard.quotaUnits",{count:A.toLocaleString()})})]}),e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("p",{className:"text-sm text-page-secondary mb-2",children:s("dashboard.used")}),e.jsxs("div",{className:"text-3xl font-bold text-page",children:[d,e.jsx(b,{from:0,to:Math.round(E/x*c*100)/100,duration:1.5})]}),e.jsx("p",{className:"text-xs text-page-muted mt-1",children:s("dashboard.quotaUnits",{count:E.toLocaleString()})})]}),e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("p",{className:"text-sm text-page-secondary mb-2",children:s("dashboard.totalRequests")}),e.jsx("div",{className:"text-3xl font-bold text-page",children:e.jsx(b,{from:0,to:Q,duration:1.5})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("dashboard.redeemCode")}),e.jsxs("form",{onSubmit:R,className:"flex gap-3",children:[e.jsx("input",{type:"text",value:f,onChange:t=>N(t.target.value),className:"input flex-1",placeholder:s("dashboard.enterCode")}),e.jsx("button",{type:"submit",disabled:v,className:"btn-primary whitespace-nowrap",children:s(v?"dashboard.redeeming":"dashboard.redeem")})]})]}),e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("dashboard.quickLinks")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(l,{to:"/tokens",className:"glass-sm !rounded-xl px-4 py-3 hover:bg-page-surface-hover transition-colors group",children:[e.jsx("p",{className:"text-sm font-medium text-page group-hover:text-page-link transition-colors",children:s("dashboard.apiKeys")}),e.jsx("p",{className:"text-xs text-page-muted",children:s("dashboard.manageKeys")})]}),e.jsxs(l,{to:"/topup",className:"glass-sm !rounded-xl px-4 py-3 hover:bg-page-surface-hover transition-colors group",children:[e.jsx("p",{className:"text-sm font-medium text-page group-hover:text-page-link transition-colors",children:s("nav.topup")}),e.jsx("p",{className:"text-xs text-page-muted",children:s("dashboard.topupDesc")})]}),e.jsxs(l,{to:"/packages",className:"glass-sm !rounded-xl px-4 py-3 hover:bg-page-surface-hover transition-colors group",children:[e.jsx("p",{className:"text-sm font-medium text-page group-hover:text-page-link transition-colors",children:s("dashboard.packages")}),e.jsx("p",{className:"text-xs text-page-muted",children:s("dashboard.viewPlans")})]}),e.jsxs(l,{to:"/pricing",className:"glass-sm !rounded-xl px-4 py-3 hover:bg-page-surface-hover transition-colors group",children:[e.jsx("p",{className:"text-sm font-medium text-page group-hover:text-page-link transition-colors",children:s("dashboard.pricing")}),e.jsx("p",{className:"text-xs text-page-muted",children:s("dashboard.modelPrices")})]}),e.jsxs(l,{to:"/logs",className:"glass-sm !rounded-xl px-4 py-3 hover:bg-page-surface-hover transition-colors group",children:[e.jsx("p",{className:"text-sm font-medium text-page group-hover:text-page-link transition-colors",children:s("dashboard.logs")}),e.jsx("p",{className:"text-xs text-page-muted",children:s("dashboard.viewLogs")})]}),(h==null?void 0:h.allow_sub_dist)&&e.jsxs(l,{to:"/sub-site",className:"glass-sm !rounded-xl px-4 py-3 hover:bg-page-surface-hover transition-colors group",children:[e.jsx("p",{className:"text-sm font-medium text-page group-hover:text-page-link transition-colors",children:s("subDist.nav")}),e.jsx("p",{className:"text-xs text-page-muted",children:s("subDist.dashboardEntry")})]})]})]})]}),m&&e.jsxs("div",{className:"glass rounded-2xl p-6 mt-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-1",children:s("topup.inviteTitle")}),e.jsx("p",{className:"text-sm text-page-secondary mb-5",children:s("topup.inviteSubtitle")}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-6",children:[e.jsxs("div",{className:"glass-sm rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-xs text-page-secondary mb-1",children:s("topup.affAvailable")}),e.jsxs("p",{className:"text-xl font-bold text-page",children:[d,(((a==null?void 0:a.aff_quota)||0)/x*c).toFixed(2)]})]}),e.jsxs("div",{className:"glass-sm rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-xs text-page-secondary mb-1",children:s("topup.affTotal")}),e.jsxs("p",{className:"text-xl font-bold text-page",children:[d,(((a==null?void 0:a.aff_history_quota)||0)/x*c).toFixed(2)]})]}),e.jsxs("div",{className:"glass-sm rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-xs text-page-secondary mb-1",children:s("topup.affCount")}),e.jsx("p",{className:"text-xl font-bold text-page",children:(a==null?void 0:a.aff_count)||0})]})]}),e.jsxs("div",{className:"mb-5",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-2",children:s("topup.inviteLink")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",readOnly:!0,value:m,className:"input flex-1 text-sm"}),e.jsx("button",{onClick:z,className:"btn-primary whitespace-nowrap text-sm px-4",children:s("topup.copy")})]})]}),((a==null?void 0:a.aff_quota)||0)>0&&e.jsxs("div",{className:"mb-5",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-2",children:s("topup.transferToBalance")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"number",value:S,onChange:t=>q(t.target.value),placeholder:s("topup.transferPlaceholder"),className:"input flex-1 text-sm",min:1}),e.jsx("button",{onClick:I,disabled:C,className:"btn-primary whitespace-nowrap text-sm px-4",children:s(C?"topup.processing":"topup.transfer")})]})]}),e.jsxs("div",{children:[e.jsx("button",{onClick:()=>{U(!u),u||F()},className:"text-sm text-page-secondary hover:text-page transition-colors",children:s(u?"topup.hideEarnings":"topup.viewEarnings")}),u&&e.jsx("div",{className:"mt-3",children:P?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx("div",{className:"w-6 h-6 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin"})}):w.length===0?e.jsx("p",{className:"text-sm text-page-muted text-center py-6",children:s("topup.noEarnings")}):e.jsx("div",{className:"space-y-2",children:w.map((t,n)=>e.jsxs("div",{className:"flex items-center justify-between glass-sm rounded-xl px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-page",children:t.model_name}),e.jsxs("p",{className:"text-xs text-page-muted",children:[new Date(t.created_time*1e3).toLocaleString()," · ",(t.commission_rate*100).toFixed(1),"%"]})]}),e.jsxs("span",{className:"text-sm font-medium text-page-success",children:["+",d,(t.commission_quota/x*c).toFixed(4)]})]},n))})})]})]})]})}export{ee as default};
|