%PDF- %PDF-
| Direktori : /home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/dist/assets/ |
| Current File : //home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/dist/assets/BillingPage-rhDoE3tP.js |
import{r as o,a as q,j as e}from"./index-BDMoG-ch.js";import{C as N,b as _,a as B}from"./Card-DCk8Plvl.js";import{B as g}from"./Badge-BO45Wp4q.js";import{a as f,f as T}from"./format-CjhWL3Ta.js";const S=3e4;function C(t=0,{autoRefresh:l=!0}={}){const[d,u]=o.useState(null),[m,b]=o.useState(!0),[j,k]=o.useState(null),a=o.useRef(0),n=o.useCallback(async()=>{const r=++a.current;try{const x=await q(`/me/billing?days=${t}`);if(a.current!==r)return;u(x),k(null)}catch(x){if(a.current!==r)return;k(x instanceof Error?x.message:"Gagal memuat billing")}finally{a.current===r&&b(!1)}},[t]);return o.useEffect(()=>{if(b(!0),n(),!l)return;const r=setInterval(n,S);return()=>clearInterval(r)},[n,l]),{data:d,loading:m,error:j,refresh:n}}const L=[{id:"all",label:"Semua"},{id:"topup",label:"Top Up"},{id:"usage",label:"Pemakaian"},{id:"adjustment",label:"Paket"}];function i(t){const l=Number(t);return Number.isFinite(l)?l.toLocaleString("id-ID",{style:"currency",currency:"IDR",maximumFractionDigits:2}):"Rp 0"}function M(t){switch(t.type){case"topup":return t.description||"Top up saldo";case"usage":return t.description||"Pemakaian model";case"adjustment":return t.description||"Pembelian paket";default:return t.description||"Transaksi"}}function F({type:t}){return t==="topup"?e.jsx(g,{tone:"success",children:"Top Up"}):t==="usage"?e.jsx(g,{tone:"danger",children:"Pemakaian"}):t==="adjustment"?e.jsx(g,{tone:"warning",children:"Paket"}):e.jsx(g,{tone:"default",children:t})}function h({label:t,value:l,hint:d,accent:u}){return e.jsxs(N,{className:"p-5",children:[e.jsx("p",{className:"text-xs font-medium text-slate-400",children:t}),e.jsx("p",{className:`mt-2 text-xl font-bold tracking-tight tabular-nums sm:text-2xl ${u}`,children:l}),d&&e.jsx("div",{className:"mt-1 text-[11px] text-slate-500",children:d})]})}function I(){const{data:t,loading:l,error:d,refresh:u}=C(),[m,b]=o.useState("all"),[j,k]=o.useState(!1),a=t==null?void 0:t.summary,n=t==null?void 0:t.active_package,r=t==null?void 0:t.breakdown,x=((t==null?void 0:t.transactions)??[]).filter(s=>m==="all"||s.type===m),v=Number((a==null?void 0:a.covered_by_package)??0),p=Number((a==null?void 0:a.total_usage_gross)??0),P=[{key:"billed_wallet",label:"Dipotong dari wallet",hint:"Request yang langsung mengurangi saldo",tone:"text-red-300",bar:"bg-red-400"},{key:"covered_package",label:"Ditanggung paket aktif",hint:"Request saat paket aktif (kuota paket)",tone:"text-brand-300",bar:"bg-brand-400"},{key:"untracked",label:"Tidak tertagih",hint:"Harga 0 / sebelum harga diset / model kosong",tone:"text-slate-400",bar:"bg-slate-500"}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-6 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight text-white",children:"Billing"}),e.jsx("p",{className:"mt-0.5 text-sm text-slate-400",children:"Saldo wallet, ringkasan, dan log transaksi finansial Anda."})]}),e.jsx("button",{onClick:u,disabled:l,className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3.5 py-2 text-xs font-medium text-slate-300 transition-colors hover:bg-white/[0.06] disabled:opacity-50",children:l?"Memuat…":"Muat Ulang"})]}),n&&e.jsxs("div",{className:"mb-6 flex flex-wrap items-center gap-3 rounded-2xl border border-brand-400/20 bg-brand-500/[0.07] px-5 py-4",children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border border-brand-400/25 bg-brand-500/10 text-brand-300",children:e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.7,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M20.25 7.5l-.625 10.632a2.25 2.25 0 01-2.247 2.118H6.622a2.25 2.25 0 01-2.247-2.118L3.75 7.5M10 11.25h4M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125z"})})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-sm font-semibold text-white",children:["Paket aktif: ",n.package_name]}),e.jsxs("p",{className:"mt-0.5 text-xs text-slate-400",children:["Pemakaian model selama paket aktif ditanggung paket (tidak memotong wallet)."," ",n.request_remaining!==null&&e.jsxs(e.Fragment,{children:["Sisa kuota:"," ",e.jsxs("span",{className:"font-medium text-slate-200",children:[f(n.request_remaining)," request"]}),n.token_remaining!==null&&e.jsxs(e.Fragment,{children:[" · ",e.jsxs("span",{className:"font-medium text-slate-200",children:[f(n.token_remaining)," token"]})]})]})," · ","Berlaku s.d."," ",e.jsx("span",{className:"font-medium text-slate-200",children:T(n.expires_at)})]})]}),e.jsx(g,{tone:"success",children:"Aktif"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-5",children:[e.jsx(h,{label:"Saldo Wallet",value:i((a==null?void 0:a.balance)??0),accent:"text-white",hint:"Saldo tersedia saat ini"}),e.jsx(h,{label:"Total Top Up",value:i((a==null?void 0:a.total_topup)??0),accent:"text-emerald-300",hint:"Akumulasi pengisian saldo"}),e.jsx(h,{label:"Total Pemakaian",value:i((a==null?void 0:a.total_usage)??0),accent:"text-red-300",hint:v>0?e.jsxs(e.Fragment,{children:[i(v)," ditanggung paket aktif",p>0&&e.jsxs(e.Fragment,{children:[" · nilai semua request ",e.jsx("span",{className:"text-slate-400",children:i(p)})]})]}):"Biaya pemakaian yang dipotong dari wallet"}),e.jsx(h,{label:"Total Beli Paket",value:i((a==null?void 0:a.total_package_orders)??0),accent:"text-amber-300",hint:"Pembelian paket kuota"}),e.jsx(h,{label:"Jumlah Request",value:f((a==null?void 0:a.requests)??0),accent:"text-sky-300",hint:"Total permintaan API (auto-refresh)"})]}),e.jsx(N,{className:"mt-6",children:e.jsxs(_,{className:"p-5",children:[e.jsxs("button",{type:"button",onClick:()=>k(s=>!s),className:"flex w-full items-center justify-between text-left",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-white",children:"Darimana angka pemakaian?"}),e.jsx("p",{className:"mt-0.5 text-xs text-slate-400",children:"Penjelasan mengapa Total Pemakaian (wallet) bisa jauh lebih kecil dari nilai semua request."})]}),e.jsx("svg",{className:`h-4 w-4 shrink-0 text-slate-500 transition-transform ${j?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 8.25l-7.5 7.5-7.5-7.5"})})]}),j&&e.jsxs("div",{className:"mt-5 space-y-4",children:[e.jsx("div",{className:"flex items-end gap-1 rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 pt-3",children:P.map(s=>{const c=r==null?void 0:r[s.key],R=c&&typeof c=="object"?c.requests:0,w=c&&typeof c=="object"?c.nominal_cost:0,y=p>0?Math.round(w/p*100):0;return e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:`h-2.5 rounded-t-md ${s.bar}`,style:{opacity:y>0?.9:.25}}),e.jsx("p",{className:`mt-2 text-[11px] font-medium ${s.tone}`,children:s.label}),e.jsx("p",{className:"text-sm font-semibold tabular-nums text-white",children:i(w)}),e.jsxs("p",{className:"text-[11px] text-slate-500",children:[R," request · ",y,"%"]}),e.jsx("p",{className:"mb-3 mt-0.5 text-[10px] text-slate-600",children:s.hint})]},s.key)})}),e.jsxs("p",{className:"text-xs leading-relaxed text-slate-400",children:["Total Pemakaian (Rp"," ",i((a==null?void 0:a.total_usage)??0).replace("Rp ",""),") hanya menghitung request yang benar-benar memotong wallet. Nilai semua request (Rp ",i(p).replace("Rp ",""),") sebagian ditanggung paket aktif, sebagian terjadi sebelum harga model diset (biaya 0), sehingga tidak tercatat sebagai potongan."]})]})]})}),e.jsxs(N,{className:"mt-6",children:[e.jsx(B,{title:"Log Transaksi",subtitle:"Riwayat finansial: top-up, pemakaian model, dan pembelian paket",action:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:L.map(s=>e.jsx("button",{onClick:()=>b(s.id),className:`rounded-full px-3 py-1.5 text-xs font-medium transition-colors ${m===s.id?"bg-brand-500/20 text-brand-200 ring-1 ring-brand-400/30":"text-slate-400 hover:bg-white/[0.04] hover:text-slate-200"}`,children:s.label},s.id))})}),e.jsxs(_,{className:"p-0",children:[d&&e.jsxs("div",{className:"p-5 text-sm text-red-300",children:["Gagal memuat: ",d]}),l?e.jsx("div",{className:"space-y-3 p-5",children:[...Array(6)].map((s,c)=>e.jsx("div",{className:"h-12 animate-pulse rounded-xl bg-white/[0.02]"},c))}):x.length===0?e.jsxs("div",{className:"px-5 py-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-2xl border border-white/[0.06] bg-white/[0.03] text-slate-500",children:e.jsx("svg",{className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.7,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.25 18.75a60.07 60.07 0 0115.797 2.101c.727.198 1.453-.342 1.453-1.096V18.75M3.75 4.5v.75A.75.75 0 013 6h-.75m0 0v-.375c0-.621.504-1.125 1.125-1.125H20.25M2.25 6v9m18-10.5v.75c0 .414.336.75.75.75h.75m-1.5-1.5h.375c.621 0 1.125.504 1.125 1.125v9.75c0 .621-.504 1.125-1.125 1.125h-.375m1.5-1.5H21a.75.75 0 00-.75.75v.75m0 0H3.75m0 0h-.375a1.125 1.125 0 01-1.125-1.125V15m1.5 1.5v-.75A.75.75 0 003 15h-.75M15 10.5a3 3 0 11-6 0 3 3 0 016 0zm3 0h.008v.008H18V10.5zm-12 0h.008v.008H6V10.5z"})})}),e.jsx("p",{className:"mt-4 text-sm font-medium text-slate-200",children:"Belum ada transaksi"}),e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:m==="all"?"Transaksi finansial Anda akan muncul di sini.":"Tidak ada transaksi untuk kategori ini."})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[640px] text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/[0.06] bg-white/[0.02] text-[11px] uppercase tracking-wider text-slate-500",children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:"Jenis"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Detail"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Nominal"}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:"Tanggal"})]})}),e.jsx("tbody",{children:x.map(s=>e.jsxs("tr",{className:"border-b border-white/[0.04] transition-colors last:border-0 hover:bg-white/[0.02]",children:[e.jsx("td",{className:"px-5 py-3.5",children:e.jsx(F,{type:s.type})}),e.jsxs("td",{className:"max-w-[260px] truncate px-4 py-3.5 text-slate-300",children:[M(s),s.reference&&e.jsxs("span",{className:"ml-1.5 font-mono text-[11px] text-slate-500",children:["#",s.reference]})]}),e.jsxs("td",{className:`px-4 py-3.5 text-right font-medium tabular-nums ${s.type==="topup"?"text-emerald-300":"text-slate-200"}`,children:[s.type==="topup"?"+":"−",i(Math.abs(Number(s.amount)))]}),e.jsx("td",{className:"px-5 py-3.5 text-right text-slate-500",children:T(s.created_at)})]},s.id))})]})})]})]})]})}export{I as default};