%PDF- %PDF-
| Direktori : /home2/rezakur1/ai.rezakurnia.com/assets/ |
| Current File : /home2/rezakur1/ai.rezakurnia.com/assets/PaketPage-YNjWEkq9.js |
import{r as l,c as y,j as e}from"./index-CnB9nKbp.js";import{B as S}from"./Button-RaC0qoA7.js";import{c as q,C as m,d as k,e as o,b as w,h as v,j as _}from"./format-B8Won_Te.js";import{B as j}from"./Badge-CXRzVGa3.js";import{u as B}from"./useWallet-CPn0Ib7E.js";function P(){const[r,s]=l.useState([]),[h,b]=l.useState(null),[u,f]=l.useState([]),[p,N]=l.useState(!0),[g,x]=l.useState(null),i=l.useCallback(async()=>{try{const a=await y("/me/packages");s(a.catalog),b(a.active),f(a.purchases),x(null)}catch(a){x(a instanceof Error?a.message:"Gagal memuat paket")}finally{N(!1)}},[]);l.useEffect(()=>{i()},[i]);const d=l.useCallback(async a=>{const t=await y(`/me/packages/${a}/buy`,{method:"POST"});return await i(),t},[i]);return{catalog:r,active:h,purchases:u,loading:p,error:g,buy:d,refresh:i}}function c(r){return r===null?"Unlimited":r.toLocaleString("id-ID")}function C(r){const s=new Date(r).getTime()-Date.now();return Math.max(0,Math.ceil(s/864e5))}function L(){const{catalog:r,active:s,purchases:h,loading:b,error:u,buy:f}=P(),{data:p,refresh:N}=B(),[g,x]=l.useState(null),[i,d]=l.useState(null),a=async t=>{x(t.id),d(null);try{const n=await f(t.id);await N(),d({type:"success",text:`Paket "${n.user_package.package_name}" aktif! Berakhir ${w(n.user_package.expires_at)}.`})}catch(n){d({type:"error",text:n instanceof Error?n.message:"Gagal membeli paket"})}finally{x(null)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold tracking-tight text-white sm:text-2xl",children:"Paket"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Beli paket untuk kuota request & token, atau lanjutkan memakai saldo wallet."})]}),e.jsxs("div",{className:"panel flex items-center gap-3 px-4 py-2.5",children:[e.jsx("span",{className:"text-xs text-slate-500",children:"Saldo wallet"}),e.jsx("span",{className:"text-base font-bold tabular-nums text-white",children:p?q(p.wallet.balance):"…"})]})]}),i&&e.jsx("div",{className:`rounded-xl border px-4 py-3 text-sm ${i.type==="success"?"border-emerald-500/25 bg-emerald-500/10 text-emerald-300":"border-red-500/25 bg-red-500/10 text-red-300"}`,children:i.text}),s&&e.jsxs(m,{children:[e.jsx(k,{title:"Paket Aktif",subtitle:s.name,action:e.jsx(j,{tone:"success",children:"Aktif"})}),e.jsx(o,{children:e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Sisa Request"}),e.jsx("p",{className:"mt-1 text-2xl font-bold tabular-nums text-white",children:c(s.request_remaining)}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-slate-500",children:["dari ",c(s.request_quota)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Sisa Token"}),e.jsx("p",{className:"mt-1 text-2xl font-bold tabular-nums text-white",children:c(s.token_remaining)}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-slate-500",children:["dari ",c(s.token_quota)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Masa Aktif"}),e.jsxs("p",{className:"mt-1 text-2xl font-bold tabular-nums text-white",children:[C(s.expires_at)," hari"]}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-slate-500",children:["berakhir ",w(s.expires_at)]})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-white",children:"Katalog Paket"}),b?e.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3",children:[...Array(3)].map((t,n)=>e.jsx("div",{className:"h-52 animate-pulse rounded-2xl border border-white/[0.04] bg-white/[0.02]"},n))}):u?e.jsx(m,{children:e.jsx(o,{children:e.jsx("p",{className:"text-sm text-red-300",children:u})})}):r.length===0?e.jsx(m,{children:e.jsx(o,{children:e.jsx("p",{className:"text-sm text-slate-500",children:"Belum ada paket tersedia."})})}):e.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3",children:r.map(t=>e.jsx(m,{className:"flex flex-col",children:e.jsxs(o,{className:"flex flex-1 flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-semibold text-white",children:t.name}),t.description&&e.jsx("p",{className:"mt-0.5 text-xs text-slate-500",children:t.description})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-lg font-bold tabular-nums text-white",children:v(Number(t.price))}),e.jsx("p",{className:"text-[11px] text-slate-500",children:_(t)})]})]}),e.jsxs("div",{className:"mt-4 space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-slate-400",children:"Request"}),e.jsx("span",{className:"font-semibold tabular-nums text-white",children:c(t.request_quota)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-slate-400",children:"Token"}),e.jsx("span",{className:"font-semibold tabular-nums text-white",children:c(t.token_quota)})]})]}),e.jsx("div",{className:"mt-5 flex-1"}),e.jsx(S,{className:"w-full",isLoading:g===t.id,disabled:!!s,onClick:()=>a(t),children:s?"Sudah ada paket aktif":"Beli Paket"})]})},t.id))})]}),e.jsxs(m,{children:[e.jsx(k,{title:"Riwayat Pembelian",subtitle:"Paket yang pernah dibeli"}),e.jsx(o,{className:"p-0",children:h.length===0?e.jsx("div",{className:"px-5 py-10 text-center text-sm text-slate-500",children:"Belum ada pembelian paket."}):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:"Paket"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Harga"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Sisa Request"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Sisa Token"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Status"}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:"Dibeli"})]})}),e.jsx("tbody",{children:h.map(t=>e.jsxs("tr",{className:"border-b border-white/[0.04] transition-colors last:border-0 hover:bg-white/[0.02]",children:[e.jsxs("td",{className:"px-5 py-3.5",children:[e.jsx("p",{className:"font-medium text-white",children:t.name}),e.jsx("p",{className:"text-[11px] text-slate-500",children:_(t)})]}),e.jsx("td",{className:"px-4 py-3.5 text-right font-medium tabular-nums text-slate-300",children:v(Number(t.package_price))}),e.jsx("td",{className:"px-4 py-3.5 text-right tabular-nums text-slate-400",children:c(t.request_remaining)}),e.jsx("td",{className:"px-4 py-3.5 text-right tabular-nums text-slate-400",children:c(t.token_remaining)}),e.jsx("td",{className:"px-4 py-3.5",children:t.status==="active"?e.jsx(j,{tone:"success",children:"Aktif"}):t.status==="exhausted"?e.jsx(j,{tone:"warning",children:"Kuota Habis"}):e.jsx(j,{tone:"default",children:"Berakhir"})}),e.jsx("td",{className:"px-5 py-3.5 text-right text-xs tabular-nums text-slate-500",children:w(t.purchased_at)})]},t.id))})]})})})]})]})}export{L as default};