1import{r as i,t as O,j as e}from"./index-DSugmHUS.js";import{supabase as P}from"./client-ChDlC2U2.js";import{B as E,L as C}from"./button-m1DExL1R.js";import{C as V,d as H}from"./card-Di9E2Ks8.js";import{B as Y}from"./badge-B8atV_Tq.js";import{I}from"./input-D9uL_PFp.js";import{d as K,K as q,k as f,C as z,m as G,o as U,p as N,q as Q,r as J,s as W}from"./Index-BPe71JiC.js";import{S as j}from"./use-forms-ul9uhWcB.js";import{E as X}from"./empty-state-CmeKY_o4.js";import{u as Z,T as $}from"./TablePager-D54m2sq4.js";import{f as ee}from"./alert-dialog-B3LhExJT.js";import{R as te}from"./refresh-cw-CJgTW5sq.js";import{B as _}from"./badge-dollar-sign-CwqfhmDU.js";import{a3 as v,a6 as ae,d as se}from"./use-roles-D4XvQNKE.js";import{S as ne}from"./use-states-CkirmXom.js";import"./UIPreferencesProvider-z_xzDbof.js";import"./auth-identity-DzeYk6GR.js";import"./auth-signout-intent-Cwv85joy.js";import"./AppFooter-5aU6EpQT.js";import"./SniperLogo-CIrxtFra.js";import"./app-settings-store-xfeo64yl.js";import"./use-permissions-DY9JGyl_.js";import"./index-PNcq8FZ2.js";import"./index-Be40SeTS.js";import"./orders-data-BfL7ogtZ.js";import"./forms-data-C22rYxwX.js";import"./conversion-api-DgR-Bv2N.js";import"./use-theme-3WYHr7HG.js";import"./minus-CS-1NInk.js";import"./dialog-CIarVAiX.js";import"./use-countries-3rmBWzkp.js";import"./products-data-Cr26dmrZ.js";import"./format-date-OQ-J4T8_.js";import"./schemas-dF-40InO.js";import"./label-vTM0e4c2.js";import"./textarea-l-vHJGTB.js";import"./forms-sync-AQymZ2vX.js";import"./duplicate-block-message-3iGWS-XC.js";import"./chevron-left-CC9fasRI.js";import"./circle-check-VuDJsLoV.js";const h=n=>ee(n,"â¦"),oe=n=>n?new Date(n).toLocaleString("en-GB",{dateStyle:"medium",timeStyle:"short"}):"â",re=[{key:"date",label:"Date",disableHide:!0},{key:"store",label:"Store",disableHide:!0},{key:"email",label:"Owner email"},{key:"amount",label:"Amount"},{key:"method",label:"Payment method"},{key:"source",label:"Source"},{key:"fundedBy",label:"Funded by"},{key:"reference",label:"Reference"},{key:"status",label:"Status",defaultVisible:!1},{key:"balanceAfter",label:"Balance after",defaultVisible:!1},{key:"description",label:"Description",defaultVisible:!1}],le=[{value:"all",label:"All time"},{value:"today",label:"Today"},{value:"7d",label:"Last 7 days"},{value:"30d",label:"Last 30 days"},{value:"month",label:"This month"},{value:"lastMonth",label:"Last month"}];function ie(n){const t=new Date,r=new Date(t.getFullYear(),t.getMonth(),t.getDate());switch(n){case"today":return{from:r};case"7d":return{from:new Date(r.getTime()-6*864e5)};case"30d":return{from:new Date(r.getTime()-29*864e5)};case"month":return{from:new Date(t.getFullYear(),t.getMonth(),1)};case"lastMonth":return{from:new Date(t.getFullYear(),t.getMonth()-1,1),to:new Date(t.getFullYear(),t.getMonth(),1)};default:return{}}}const A=n=>n==="admin_topup"?"Admin top-up":n==="credit_funding"?"Self-funded":n,me={date:"whitespace-nowrap text-sm",store:"font-medium",email:"text-sm text-muted-foreground",amount:"text-right font-mono",method:"",source:"text-sm",fundedBy:"text-sm",reference:"text-xs font-mono text-muted-foreground",status:"text-sm",balanceAfter:"text-right font-mono text-sm",description:"text-sm text-muted-foreground"};function ue(n,t){switch(n){case"date":return oe(t.created_at);case"store":return t.store_name||"â";case"email":return t.owner_email||"â";case"amount":return h(t.amount);case"method":return e.jsx(Y,{variant:"outline",children:t.payment_method||"Other"});case"source":return A(t.type);case"fundedBy":return t.funded_by||"â";case"reference":return t.reference||"â";case"status":return t.status||"â";case"balanceAfter":return t.balance_after==null?"â":h(Number(t.balance_after));case"description":return t.description||"â";default:return null}}function Xe(){const[n,t]=i.useState([]),[r,S]=i.useState(!0),[g,k]=i.useState(""),[y,T]=i.useState("all"),[x,M]=i.useState("all"),[b,D]=i.useState("all"),u=K("superAdminTransactionsColumns",re),w=i.useCallback(async()=>{S(!0);const{data:a,error:s}=await P.rpc("admin_list_all_wallet_funding",{_from:null,_to:null});s&&O({title:"Failed to load transactions",description:s.message,variant:"destructive"}),t((a??[]).map(c=>({...c,amount:Number(c.amount)}))),S(!1)},[]);i.useEffect(()=>{w()},[w]);const L=i.useMemo(()=>{const a=new Set(n.map(s=>s.payment_method||"Other"));return[{value:"all",label:"All payment methods"},...Array.from(a).sort().map(s=>({value:s,label:s}))]},[n]),R=i.useMemo(()=>{const a=new Set(n.map(s=>s.type));return[{value:"all",label:"All sources"},...Array.from(a).sort().map(s=>({value:s,label:A(s)}))]},[n]),m=i.useMemo(()=>{const{from:a,to:s}=ie(y),c=g.trim().toLowerCase();return n.filter(l=>{const o=new Date(l.created_at);return a&&o<a||s&&o>=s||x!=="all"&&(l.payment_method||"Other")!==x||b!=="all"&&l.type!==b?!1:c?[l.store_name,l.owner_email,l.payment_method,l.funded_by,l.reference,l.description,String(l.amount)].some(d=>(d||"").toLowerCase().includes(c)):!0})},[n,y,x,b,g]),p=i.useMemo(()=>{const a=m.reduce((o,d)=>o+d.amount,0),s=m.filter(o=>o.type==="credit_funding"),c=m.filter(o=>o.type==="admin_topup"),l=new Set(m.map(o=>o.owner_id)).size;return{total:a,count:m.length,stores:l,avg:m.length?a/m.length:0,selfAmount:s.reduce((o,d)=>o+d.amount,0),adminAmount:c.reduce((o,d)=>o+d.amount,0)}},[m]),{pageRows:B,pagerProps:F}=Z(m,50);return e.jsxs("div",{className:"flex-1 overflow-auto p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Transactions"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Every wallet funding across all stores â payment method, date and store."})]}),e.jsxs(E,{variant:"outline",size:"sm",onClick:w,disabled:r,children:[r?e.jsx(C,{className:"w-4 h-4 animate-spin"}):e.jsx(te,{className:"w-4 h-4"})," Refresh"]})]}),e.jsxs(q,{children:[e.jsx(f,{label:"Total Funded",value:r?"â¦":h(p.total),icon:e.jsx(_,{className:"w-4 h-4"}),tone:"primary",hint:"Sum of matching fundings."}),e.jsx(f,{label:"Transactions",value:r?"â¦":p.count,icon:e.jsx(v,{className:"w-4 h-4"}),tone:"info",hint:"Number of funding records."}),e.jsx(f,{label:"Funding Stores",value:r?"â¦":p.stores,icon:e.jsx(ae,{className:"w-4 h-4"}),tone:"success",hint:"Distinct stores that funded."}),e.jsx(f,{label:"Average Funding",value:r?"â¦":h(p.avg),icon:e.jsx(se,{className:"w-4 h-4"}),tone:"warning",hint:"Average amount per transaction."}
1),e.jsx(f,{label:"Self-Funded (Paystack)",value:r?"â¦":h(p.selfAmount),icon:e.jsx(v,{className:"w-4 h-4"}),tone:"info",hint:"Paid by subscribers online."}),e.jsx(f,{label:"Admin Top-ups",value:r?"â¦":h(p.adminAmount),icon:e.jsx(_,{className:"w-4 h-4"}),tone:"warning",hint:"Credited manually by Super Admin."})]}),e.jsx(V,{children:e.jsxs(H,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 min-w-[220px]",children:[e.jsx(ne,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(I,{value:g,onChange:a=>k(a.target.value),placeholder:"Search store, email, reference, method, amountâ¦",className:"pl-9"})]}),e.jsx(j,{options:le,value:y,onChange:T,className:"w-[170px]",placeholder:"All time"}),e.jsx(j,{options:L,value:x,onChange:M,className:"w-[200px]",placeholder:"All payment methods"}),e.jsx(j,{options:R,value:b,onChange:D,className:"w-[170px]",placeholder:"All sources"}),e.jsx(z,{columns:u.orderedColumns,visibleMap:u.visibleColumnsMap,onToggle:u.setColumnVisible,onReset:u.resetColumns,onMove:u.moveColumn,onReorder:u.reorderColumn})]}),r?e.jsxs("div",{className:"py-12 flex items-center justify-center text-muted-foreground",children:[e.jsx(C,{className:"w-5 h-5 animate-spin mr-2"})," Loading transactionsâ¦"]}):m.length===0?e.jsx(X,{icon:v,title:"No transactions found",description:"No wallet fundings match your current search and filters."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(G,{children:[e.jsx(U,{children:e.jsx(N,{children:u.visibleColumns.map(a=>e.jsx(Q,{className:a.key==="amount"||a.key==="balanceAfter"?"text-right":void 0,children:a.label},a.key))})}),e.jsx(J,{children:B.map(a=>e.jsx(N,{children:u.visibleColumns.map(s=>e.jsx(W,{className:me[s.key],children:ue(s.key,a)},s.key))},a.id))})]})}),e.jsx($,{...F,label:"transaction"})]})]})})]})}export{Xe as SuperAdminTransactionsPage};
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.