%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home2/rezakur1/ai.rezakurnia.com/assets/
Upload File :
Create Path :
Current File : //home2/rezakur1/ai.rezakurnia.com/assets/PaketPage-DeVDbc0q.js

import{r as i,c as k,j as e}from"./index-_MR6QBUm.js";import{B as P}from"./Button-BRUb7BtQ.js";import{c as C,C as o,d as v,e as h,b as y,h as _,j as S}from"./format-DuRu6B7q.js";import{B as b}from"./Badge-MEsxA8Zk.js";import{u as D}from"./useWallet-DGUzjYAl.js";function T(){const[r,s]=i.useState([]),[u,f]=i.useState(null),[p,N]=i.useState([]),[j,g]=i.useState(!0),[w,d]=i.useState(null),c=i.useCallback(async()=>{try{const a=await k("/me/packages");s(a.catalog);const t=Date.now(),l=x=>new Date(x.expires_at).getTime()<=t,q=a.active&&!l(a.active)?a.active:null,B=a.purchases.map(x=>x.status==="active"&&l(x)?{...x,status:"expired"}:x);f(q),N(B),d(null)}catch(a){d(a instanceof Error?a.message:"Gagal memuat paket")}finally{g(!1)}},[]);i.useEffect(()=>{c()},[c]);const m=i.useCallback(async a=>{const t=await k(`/me/packages/${a}/buy`,{method:"POST"});return await c(),t},[c]);return{catalog:r,active:u,purchases:p,loading:j,error:w,buy:m,refresh:c}}function n(r){return r===null?"Unlimited":r.toLocaleString("id-ID")}function E(r){const s=new Date(r).getTime()-Date.now();return Math.max(0,Math.ceil(s/864e5))}function M(){const{catalog:r,active:s,purchases:u,loading:f,error:p,buy:N}=T(),{data:j,refresh:g}=D(),[w,d]=i.useState(null),[c,m]=i.useState(null),a=async t=>{d(t.id),m(null);try{const l=await N(t.id);await g(),m({type:"success",text:`Paket "${l.user_package.package_name}" aktif! Berakhir ${y(l.user_package.expires_at)}.`})}catch(l){m({type:"error",text:l instanceof Error?l.message:"Gagal membeli paket"})}finally{d(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:j?C(j.wallet.balance):"…"})]})]}),c&&e.jsx("div",{className:`rounded-xl border px-4 py-3 text-sm ${c.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:c.text}),s&&e.jsxs(o,{children:[e.jsx(v,{title:"Paket Aktif",subtitle:s.name,action:e.jsx(b,{tone:"success",children:"Aktif"})}),e.jsx(h,{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:n(s.request_remaining)}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-slate-500",children:["dari ",n(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:n(s.token_remaining)}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-slate-500",children:["dari ",n(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:[E(s.expires_at)," hari"]}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-slate-500",children:["berakhir ",y(s.expires_at)]})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-white",children:"Katalog Paket"}),f?e.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3",children:[...Array(3)].map((t,l)=>e.jsx("div",{className:"h-52 animate-pulse rounded-2xl border border-white/[0.04] bg-white/[0.02]"},l))}):p?e.jsx(o,{children:e.jsx(h,{children:e.jsx("p",{className:"text-sm text-red-300",children:p})})}):r.length===0?e.jsx(o,{children:e.jsx(h,{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(o,{className:"flex flex-col",children:e.jsxs(h,{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:_(Number(t.price))}),e.jsx("p",{className:"text-[11px] text-slate-500",children:S(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:n(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:n(t.token_quota)})]})]}),e.jsx("div",{className:"mt-5 flex-1"}),e.jsx(P,{className:"w-full",isLoading:w===t.id,disabled:!!s,onClick:()=>a(t),children:s?"Sudah ada paket aktif":"Beli Paket"})]})},t.id))})]}),e.jsxs(o,{children:[e.jsx(v,{title:"Riwayat Pembelian",subtitle:"Paket yang pernah dibeli"}),e.jsx(h,{className:"p-0",children:u.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:u.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:S(t)})]}),e.jsx("td",{className:"px-4 py-3.5 text-right font-medium tabular-nums text-slate-300",children:_(Number(t.package_price))}),e.jsx("td",{className:"px-4 py-3.5 text-right tabular-nums text-slate-400",children:n(t.request_remaining)}),e.jsx("td",{className:"px-4 py-3.5 text-right tabular-nums text-slate-400",children:n(t.token_remaining)}),e.jsx("td",{className:"px-4 py-3.5",children:t.status==="active"?e.jsx(b,{tone:"success",children:"Aktif"}):t.status==="exhausted"?e.jsx(b,{tone:"warning",children:"Kuota Habis"}):e.jsx(b,{tone:"default",children:"Berakhir"})}),e.jsx("td",{className:"px-5 py-3.5 text-right text-xs tabular-nums text-slate-500",children:y(t.purchased_at)})]},t.id))})]})})})]})]})}export{M as default};

Zerion Mini Shell 1.0