1import{r as l,j as e,E as o,W as L,f as z,d as M,h as $,G as b,H as q,N as G,B as h,U as J,n as O,C as N,s as g,ac as V,ad as W}from"./index-C6FwMg2j.js";import{A as K}from"./arrow-left-CUfUbOqF.js";import{R as w}from"./receipt-BlX_0aSJ.js";import{C as U}from"./credit-card-BAzHlJ5w.js";import{C as T}from"./circle-check-big-B2pYiWZS.js";import{f as X}from"./format-NVB74tPW.js";import{F as Q}from"./file-text-tSvgRH_A.js";import{C as y}from"./circle-x-545ANrvP.js";const C=l.forwardRef(({className:a,...s},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:o("w-full caption-bottom text-sm",a),...s})}));C.displayName="Table";const R=l.forwardRef(({className:a,...s},t)=>e.jsx("thead",{ref:t,className:o("[&_tr]:border-b",a),...s}));R.displayName="TableHeader";const S=l.forwardRef(({className:a,...s},t)=>e.jsx("tbody",{ref:t,className:o("[&_tr:last-child]:border-0",a),...s}));S.displayName="TableBody";const Y=l.forwardRef(({className:a,...s},t)=>e.jsx("tfoot",{ref:t,className:o("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",a),...s}));Y.displayName="TableFooter";const f=l.forwardRef(({className:a,...s},t)=>e.jsx("tr",{ref:t,className:o("border-b transition-colors data-[state=selected]:bg-muted hover:bg-muted/50",a),...s}));f.displayName="TableRow";const c=l.forwardRef(({className:a,...s},t)=>e.jsx("th",{ref:t,className:o("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",a),...s}));c.displayName="TableHead";const d=l.forwardRef(({className:a,...s},t)=>e.jsx("td",{ref:t,className:o("p-4 align-middle [&:has([role=checkbox])]:pr-0",a),...s}));d.displayName="TableCell";const Z=l.forwardRef(({className:a,...s},t)=>e.jsx("caption",{ref:t,className:o("mt-4 text-sm text-muted-foreground",a),...s}));Z.displayName="TableCaption";const v=a=>new Intl.NumberFormat("id-ID",{style:"currency",currency:"IDR",minimumFractionDigits:0,maximumFractionDigits:0}).format(a),k={active:{icon:e.jsx(T,{className:"h-3 w-3"}),color:"text-green-400",label:"Aktif"},expired:{icon:e.jsx(N,{className:"h-3 w-3"}),color:"text-muted-foreground",label:"Kedaluwarsa"},pending:{icon:e.jsx(N,{className:"h-3 w-3"}),color:"text-accent",label:"Menunggu"},failed:{icon:e.jsx(y,{className:"h-3 w-3"}),color:"text-destructive",label:"Gagal"},cancelled:{icon:e.jsx(y,{className:"h-3 w-3"}),color:"text-muted-foreground",label:"Batal"}},oe=()=>{const a=L(),{user:s,isLoading:t}=z(),{settings:_}=M(),[u,D]=l.useState([]),[H,P]=l.useState(!0),[B,F]=l.useState(0),[p,j]=l.useState(null),{ref:A,isVisible:I}=$();l.useEffect(()=>{!t&&!s&&a("/auth",{replace:!0})},[s,t,a]),l.useEffect(()=>{s&&(async()=>{if(s)try{const{data:i,error:n}=await g.from("subscription_history").select("*, subscription_plans (name, tier)").eq("user_id",s.id).order("started_at",{ascending:!1});if(n)throw n;D(i||[]),F((i||[]).filter(m=>m.status==="active").reduce((m,x)=>m+Number(x.amount_paid),0))}catch{}finally{P(!1)}})()},[s]);const E=async r=>{try{j(r);const{data:{session:i}}=await g.auth.getSession();if(!i)return;const n=await fetch("https://jegpmqwykmbygrkrnvqm.supabase.co/functions/v1/generate-invoice-pdf",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i.access_token}`},body:JSON.stringify({subscriptionHistoryId:r})});if(!n.ok)throw new Error;const m=await n.text(),x=window.open();x&&(x.document.write(m),x.document.close())}catch{V.error("Gagal mengunduh invoice")}finally{j(null)}};return t||!s?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(b,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsxs("div",{className:"min-h-screen bg-background flex flex-col",children:[e.jsx(q,{children:e.jsxs("title",{children:["Riwayat Pembayaran - ",_.site_name]})}),e.jsx(G,{}),e.jsxs("main",{className:"flex-1 container mx-auto px-4 pt-20 pb-8 max-w-4xl",children:[e.jsxs("div",{className:"relative rounded-2xl overflow-hidden bg-gradient-to-br from-primary/10 via-accent/5 to-transparent border border-border/30 p-6 mb-6",children:[e.jsx("div",{className:"absolute inset-0 bg-card/40 backdrop-blur-sm"}),e.jsxs("div",{className:"relative flex items-center gap-3",children:[e.jsx(h,{variant:"ghost",size:"icon",onClick:()=>a(-1),className:"w-8 h-8 shrink-0 rounded-xl",children:e.jsx(K,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold",children:"Riwayat Pembayaran"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Histori transaksi & invoice"})]})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2 mb-6",children:[{label:"Transaksi",value:u.length,icon:e.jsx(w,{className:"h-4 w-4"})},{label:"Pengeluaran",value:v(B),icon:e.jsx(U,{className:"h-4 w-4"})},{label:"Aktif",value:u.filter(r=>r.status==="active").length,icon:e.jsx(T,{className:"h-4 w-4 text-green-400"})}].map((r,i)=>e.jsxs("div",{className:"rounded-2xl border border-border/30 bg-card/60 backdrop-blur-sm p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground uppercase",children:r.label}),r.icon]}),e.jsx("p",{className:"text-lg font-bold",children:r.value})]},i))}),e.jsx("div",{ref:A,className:`transition-all duration-700 ${I?"opacity-100 translate-y-0":"opacity-0 translate-y-6"}`,children:H?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(b,{className:"h-6 w-6 animate-spin text-primary"})}):u.length===0?e.jsxs("div",{className:"rounded-2xl border border-border/30 bg-card/50 backdrop-blur-sm flex flex-col items-center py-12",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-secondary/60 flex items-center justify-center mb-4",children:e.jsx(w,{className:"h-7 w-7 text-muted-foreground
1/40"})}),e.jsx("h3",{className:"font-semibold mb-1",children:"Belum Ada Transaksi"}),e.jsxs(h,{onClick:()=>a("/subscription"),size:"sm",className:"rounded-xl gap-1 text-xs mt-3",children:[e.jsx(J,{className:"h-3 w-3"}),"Lihat Paket"]})]}):e.jsx("div",{className:"rounded-2xl border border-border/30 bg-card/60 backdrop-blur-sm overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(C,{children:[e.jsx(R,{children:e.jsxs(f,{className:"border-border/30",children:[e.jsx(c,{className:"text-[10px] uppercase",children:"Tanggal"}),e.jsx(c,{className:"text-[10px] uppercase",children:"Paket"}),e.jsx(c,{className:"text-[10px] uppercase",children:"Jumlah"}),e.jsx(c,{className:"text-[10px] uppercase",children:"Status"}),e.jsx(c,{className:"text-[10px] uppercase text-right",children:"Invoice"})]})}),e.jsx(S,{children:u.map(r=>{var n;const i=k[r.status]||k.pending;return e.jsxs(f,{className:"border-border/30 hover:bg-secondary/30 transition-colors",children:[e.jsx(d,{className:"text-sm",children:X(new Date(r.started_at),"dd MMM yyyy",{locale:W})}),e.jsx(d,{className:"text-sm",children:((n=r.subscription_plans)==null?void 0:n.name)||"â"}),e.jsx(d,{className:"text-sm font-medium",children:v(Number(r.amount_paid))}),e.jsx(d,{children:e.jsxs("span",{className:`inline-flex items-center gap-1 text-xs ${i.color}`,children:[i.icon,i.label]})}),e.jsx(d,{className:"text-right",children:e.jsx(h,{variant:"ghost",size:"sm",onClick:()=>E(r.id),disabled:p===r.id,className:"h-7 text-xs rounded-lg gap-1",children:p===r.id?e.jsx(b,{className:"h-3 w-3 animate-spin"}):e.jsx(Q,{className:"h-3 w-3"})})})]},r.id)})})]})})})})]}),e.jsx(O,{})]})};export{oe as default};
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.