import{c as K,r as s,j as e,F as oe,g as G,k as ce,m as de,e as xe}from"./index-HUEYA8gO.js";import{T as me}from"./TransactionDetailsModal-CbgOhFvM.js";import{X as ue}from"./x-CRpu2A8N.js";import{D as Q}from"./dollar-sign-B5KhycjN.js";import{C as he}from"./calendar-96DrS3w3.js";import{C as Y}from"./clock-DgYiYlPW.js";import{T as pe,a as be}from"./trending-up-CKoyN7JV.js";import"./hash-DL6bgNCn.js";/**
 * @license lucide-react v0.545.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const fe=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],ge=K("download",fe);/**
 * @license lucide-react v0.545.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const je=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],Ne=K("funnel",je);function ve({open:d,onClose:y,transaction:a,loading:k=!1,onSave:D}){if(!d||!a)return null;let j={};try{j=typeof a.details=="string"?JSON.parse(a.details):a.details||{}}catch{j={}}const _=a.amount!=null?String(a.amount):"",x=j.admin_notes||j.user_description||a.admin_note||"";let S="",m="";if(a.created_at){const l=new Date(a.created_at);if(!isNaN(l.getTime())){const p=l.toISOString();S=p.slice(0,10),m=p.slice(11,16)}}const[i,c]=s.useState(_),[u,M]=s.useState(x),[N,E]=s.useState(S),[h,A]=s.useState(m),[v,w]=s.useState("");s.useEffect(()=>{c(_),M(x),E(S),A(m),w("")},[a==null?void 0:a.id]);const C=l=>{l.preventDefault(),w("");const p=parseFloat(i);if(!i||isNaN(p)||p<=0){w("Please enter a valid amount greater than zero.");return}if(!N){w("Please select a date.");return}if(!h){w("Please select a time.");return}D&&D({amount:p,description:u.trim(),date:N,time:h})},o=k;return e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-slate-800 border border-slate-700 rounded-xl max-w-lg w-full shadow-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-slate-700",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-amber-500/10 rounded-lg",children:e.jsx(oe,{className:"w-5 h-5 text-amber-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-white",children:"Edit Transaction"}),e.jsx("p",{className:"text-sm text-slate-400",children:"Update amount, date/time and description"})]})]}),e.jsx("button",{type:"button",onClick:()=>!o&&y&&y(),className:"text-slate-400 hover:text-white transition-colors p-1 disabled:opacity-50",disabled:o,children:e.jsx(ue,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:C,className:"p-6 space-y-5",children:[e.jsxs("div",{className:"space-y-1 text-sm text-slate-400",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Transaction ID:"}),e.jsxs("span",{className:"text-white font-mono",children:["#",a.id]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"User ID:"}),e.jsx("span",{className:"text-white font-mono",children:a.user_id})]}),a.type&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Type:"}),e.jsx("span",{className:"text-white capitalize",children:a.type})]}),a.status&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Status:"}),e.jsx("span",{className:"text-white capitalize",children:a.status})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"block text-sm font-medium text-slate-200 mb-1",children:"Amount"}),e.jsxs("div",{className:"relative",children:[e.jsx(Q,{className:"w-4 h-4 text-slate-400 absolute left-3 top-1/2 -translate-y-1/2"}),e.jsx("input",{type:"number",step:"0.01",min:"0",className:"w-full bg-slate-900 border border-slate-700 rounded-lg pl-9 pr-3 py-2 text-white focus:outline-none focus:ring-2 focus:ring-amber-500",value:i,onChange:l=>c(l.target.value),disabled:o})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-200 mb-1",children:"Date"}),e.jsxs("div",{className:"relative",children:[e.jsx(he,{className:"w-4 h-4 text-slate-400 absolute left-3 top-1/2 -translate-y-1/2"}),e.jsx("input",{type:"date",className:"w-full bg-slate-900 border border-slate-700 rounded-lg pl-9 pr-3 py-2 text-white focus:outline-none focus:ring-2 focus:ring-amber-500",value:N,onChange:l=>E(l.target.value),disabled:o})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-200 mb-1",children:"Time"}),e.jsxs("div",{className:"relative",children:[e.jsx(Y,{className:"w-4 h-4 text-slate-400 absolute left-3 top-1/2 -translate-y-1/2"}),e.jsx("input",{type:"time",className:"w-full bg-slate-900 border border-slate-700 rounded-lg pl-9 pr-3 py-2 text-white focus:outline-none focus:ring-2 focus:ring-amber-500",value:h,onChange:l=>A(l.target.value),disabled:o})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-200 mb-1",children:"Description / Admin Notes"}),e.jsx("textarea",{className:"w-full bg-slate-900 border border-slate-700 rounded-lg px-3 py-2 text-white focus:outline-none focus:ring-2 focus:ring-amber-500 min-h-[80px]",value:u,onChange:l=>M(l.target.value),disabled:o}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"This will be stored in the transaction details as admin_notes."})]}),v&&e.jsx("div",{className:"bg-red-500/10 border border-red-500/30 rounded-lg px-3 py-2 text-sm text-red-400",children:v})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 p-6 border-t border-slate-700",children:[e.jsx("button",{type:"button",onClick:()=>!o&&y&&y(),className:"px-4 py-2 bg-slate-700 hover:bg-slate-600 text-white rounded-lg text-sm font-medium transition-colors disabled:opacity-50",disabled:o,children:"Cancel"}),e.jsx("button",{type:"button",onClick:C,className:"px-5 py-2 bg-amber-500 hover:bg-amber-600 text-slate-900 rounded-lg text-sm font-semibold transition-colors disabled:opacity-50 disabled:cursor-not-allowed",disabled:o,children:k?"Saving...":"Save changes"})]})]})})}function Ee(){const[d,y]=s.useState([]),[a,k]=s.useState(!0),[D,j]=s.useState(""),[_,x]=s.useState(""),[S,m]=s.useState(""),[i,c]=s.useState(1),[u,M]=s.useState(20),[N,E]=s.useState(0),[h,A]=s.useState(""),[v,w]=s.useState(""),[C,o]=s.useState(""),[l,p]=s.useState(""),[F,Z]=s.useState(""),[L,ee]=s.useState(""),[H,J]=s.useState(!1),[te,W]=s.useState(null),[q,R]=s.useState(!1),[I,V]=s.useState(null),[B,X]=s.useState(!1);s.useEffect(()=>{const t=setTimeout(()=>p(C.trim()),400);return()=>clearTimeout(t)},[C]);const P=s.useCallback(async()=>{var t;k(!0),j("");try{const n=new URLSearchParams;h&&n.set("type",h),v&&n.set("status",v),l&&n.set("search",l),F&&n.set("date_from",F),L&&n.set("date_to",L),n.set("page",String(i)),n.set("per_page",String(u));const T=await fetch(G(`/admin_list_transactions.php?${n.toString()}`),{credentials:"include"}),b=await T.json();if(!T.ok||b.success===!1)throw new Error(b.message||"Failed to load transactions");y(b.transactions||[]),E(((t=b.pagination)==null?void 0:t.total)||0)}catch(n){console.error("Transactions load error:",n),j(n.message||"Failed to load transactions")}finally{k(!1)}},[h,v,l,i,u,F,L]);s.useEffect(()=>{P()},[P]);const O=Math.max(1,Math.ceil(N/u)),se=t=>{W(t),J(!0)},ae=t=>{V(t),R(!0),x(""),m("")},le=async({amount:t,description:n,date:T,time:b})=>{if(I){X(!0),x("");try{const f=await fetch(G("/admin_edit_transaction.php"),{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({transaction_id:I.id,amount:t,description:n,date:T,time:b})}),g=await f.json();if(!f.ok||g.success===!1)throw new Error(g.message||"Failed to update transaction");m("Transaction updated successfully"),R(!1),V(null),await P()}catch(f){console.error("Transaction edit failed:",f),x(f.message||"Failed to update transaction")}finally{X(!1)}}},ne=()=>{try{const t=["ID","User","Email","Type","Amount","Status","Reference","Date"],n=d.map(r=>{const z=r.created_at?new Date(r.created_at).toISOString():"";return[r.id,r.username||r.user_id||"",r.email||"",r.type||"",Number(r.amount||0).toFixed(2),r.status||"",r.reference||"",z]}),T=[t,...n].map(r=>r.map(z=>{const $=String(z??"");return/[",\n]/.test($)?'"'+$.replace(/"/g,'""')+'"':$}).join(",")).join(`
`),b=new Blob([T],{type:"text/csv;charset=utf-8;"}),f=URL.createObjectURL(b),g=document.createElement("a");g.href=f,g.download=`transactions_${Date.now()}.csv`,document.body.appendChild(g),g.click(),document.body.removeChild(g),URL.revokeObjectURL(f),m("CSV exported successfully")}catch(t){console.error("CSV export failed:",t),x("Failed to export CSV")}},re=t=>{switch(t==null?void 0:t.toLowerCase()){case"completed":return"bg-green-500/10 border-green-500/30 text-green-400";case"pending":return"bg-yellow-500/10 border-yellow-500/30 text-yellow-400";case"rejected":case"failed":return"bg-red-500/10 border-red-500/30 text-red-400";default:return"bg-slate-500/10 border-slate-500/30 text-slate-400"}},ie=t=>{switch(t==null?void 0:t.toLowerCase()){case"deposit":return"text-green-400";case"withdrawal":return"text-red-400";case"investment":return"text-blue-400";case"roi":return"text-purple-400";default:return"text-slate-400"}},U={total:d.length,deposits:d.filter(t=>t.type==="deposit").length,withdrawals:d.filter(t=>t.type==="withdrawal").length,pending:d.filter(t=>t.status==="pending").length};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-white",children:"Transactions"}),e.jsx("p",{className:"text-slate-400 mt-1",children:"Manage all platform transactions"})]}),e.jsxs("button",{onClick:ne,className:"flex items-center gap-2 px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg transition-colors",children:[e.jsx(ge,{className:"w-4 h-4"}),"Export CSV"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx("div",{className:"bg-slate-800 border border-slate-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-400 text-sm",children:"Total"}),e.jsx("p",{className:"text-2xl font-bold text-white mt-1",children:U.total})]}),e.jsx(Q,{className:"w-10 h-10 text-blue-400"})]})}),e.jsx("div",{className:"bg-slate-800 border border-slate-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-400 text-sm",children:"Deposits"}),e.jsx("p",{className:"text-2xl font-bold text-green-400 mt-1",children:U.deposits})]}),e.jsx(pe,{className:"w-10 h-10 text-green-400"})]})}),e.jsx("div",{className:"bg-slate-800 border border-slate-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-400 text-sm",children:"Withdrawals"}),e.jsx("p",{className:"text-2xl font-bold text-red-400 mt-1",children:U.withdrawals})]}),e.jsx(be,{className:"w-10 h-10 text-red-400"})]})}),e.jsx("div",{className:"bg-slate-800 border border-slate-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-400 text-sm",children:"Pending"}),e.jsx("p",{className:"text-2xl font-bold text-yellow-400 mt-1",children:U.pending})]}),e.jsx(Y,{className:"w-10 h-10 text-yellow-400"})]})})]}),_&&e.jsxs("div",{className:"bg-red-500/10 border border-red-500/30 rounded-lg p-4",children:[e.jsx("p",{className:"text-red-400",children:_}),e.jsx("button",{onClick:()=>x(""),className:"text-red-300 hover:text-red-200 text-sm mt-2",children:"Dismiss"})]}),S&&e.jsxs("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:[e.jsx("p",{className:"text-green-400",children:S}),e.jsx("button",{onClick:()=>m(""),className:"text-green-300 hover:text-green-200 text-sm mt-2",children:"Dismiss"})]}),e.jsxs("div",{className:"bg-slate-800 border border-slate-700 rounded-lg p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Ne,{className:"w-5 h-5 text-slate-400"}),e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Filters"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-6 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Type"}),e.jsxs("select",{className:"w-full bg-slate-900 border border-slate-600 rounded-lg px-3 py-2 text-white focus:outline-none focus:ring-2 focus:ring-blue-500",value:h,onChange:t=>{c(1),A(t.target.value)},children:[e.jsx("option",{value:"",children:"All"}),e.jsx("option",{value:"deposit",children:"Deposit"}),e.jsx("option",{value:"withdrawal",children:"Withdrawal"}),e.jsx("option",{value:"investment",children:"Investment"}),e.jsx("option",{value:"roi",children:"ROI"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Status"}),e.jsxs("select",{className:"w-full bg-slate-900 border border-slate-600 rounded-lg px-3 py-2 text-white focus:outline-none focus:ring-2 focus:ring-blue-500",value:v,onChange:t=>{c(1),w(t.target.value)},children:[e.jsx("option",{value:"",children:"All"}),e.jsx("option",{value:"pending",children:"Pending"}),e.jsx("option",{value:"completed",children:"Completed"}),e.jsx("option",{value:"rejected",children:"Rejected"}),e.jsx("option",{value:"failed",children:"Failed"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Date From"}),e.jsx("input",{type:"date",className:"w-full bg-slate-900 border border-slate-600 rounded-lg px-3 py-2 text-white focus:outline-none focus:ring-2 focus:ring-blue-500",value:F,onChange:t=>{c(1),Z(t.target.value)}})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Date To"}),e.jsx("input",{type:"date",className:"w-full bg-slate-900 border border-slate-600 rounded-lg px-3 py-2 text-white focus:outline-none focus:ring-2 focus:ring-blue-500",value:L,onChange:t=>{c(1),ee(t.target.value)}})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Search"}),e.jsxs("div",{className:"relative",children:[e.jsx(ce,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-slate-400"}),e.jsx("input",{type:"text",placeholder:"User, email, reference...",className:"w-full bg-slate-900 border border-slate-600 rounded-lg pl-10 pr-3 py-2 text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-blue-500",value:C,onChange:t=>{c(1),o(t.target.value)}})]})]})]})]}),e.jsx("div",{className:"bg-slate-800 border border-slate-700 rounded-lg overflow-hidden",children:a?e.jsxs("div",{className:"p-12 text-center",children:[e.jsx("div",{className:"inline-block animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500"}),e.jsx("p",{className:"text-slate-400 mt-4",children:"Loading transactions..."})]}):D?e.jsxs("div",{className:"p-8 text-center",children:[e.jsx("p",{className:"text-red-400 text-lg",children:D}),e.jsx("button",{onClick:P,className:"mt-4 px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg transition-colors",children:"Retry"})]}):d.length===0?e.jsx("div",{className:"p-12 text-center",children:e.jsx("p",{className:"text-slate-400 text-lg",children:"No transactions found"})}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-900 border-b border-slate-700",children:[e.jsx("th",{className:"text-left px-6 py-4 text-sm font-semibold text-slate-300",children:"ID"}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-semibold text-slate-300",children:"User"}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-semibold text-slate-300",children:"Type"}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-semibold text-slate-300",children:"Amount"}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-semibold text-slate-300",children:"Status"}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-semibold text-slate-300",children:"Date"}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-semibold text-slate-300",children:"Actions"})]})}),e.jsx("tbody",{children:d.map(t=>e.jsxs("tr",{className:"border-b border-slate-700 hover:bg-slate-700/50 transition-colors",children:[e.jsxs("td",{className:"px-6 py-4 text-white font-mono text-sm",children:["#",t.id]}),e.jsxs("td",{className:"px-6 py-4",children:[e.jsx("div",{className:"text-white font-medium",children:t.username||"N/A"}),e.jsx("div",{className:"text-slate-400 text-sm",children:t.email||""})]}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("span",{className:`font-medium capitalize ${ie(t.type)}`,children:t.type||"N/A"})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("span",{className:"text-white font-semibold",children:["$",Number(t.amount||0).toFixed(2)]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("span",{className:`inline-flex items-center px-3 py-1 rounded-full text-xs font-medium border capitalize ${re(t.status)}`,children:t.status||"N/A"})}),e.jsx("td",{className:"px-6 py-4 text-slate-300 text-sm",children:t.created_at?new Date(t.created_at).toLocaleDateString():"N/A"}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:()=>se(t),className:"px-3 py-1 bg-blue-500 hover:bg-blue-600 text-white text-sm rounded-lg transition-colors",children:"View"}),e.jsx("button",{onClick:()=>ae(t),className:"px-3 py-1 bg-amber-500 hover:bg-amber-600 text-slate-900 text-sm rounded-lg font-medium transition-colors",children:"Edit"})]})})]},t.id))})]})})}),O>1&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-slate-400",children:["Showing ",e.jsx("span",{className:"text-white font-medium",children:(i-1)*u+1})," to"," ",e.jsx("span",{className:"text-white font-medium",children:Math.min(i*u,N)})," of"," ",e.jsx("span",{className:"text-white font-medium",children:N})," transactions"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>c(t=>Math.max(1,t-1)),disabled:i===1,className:"px-3 py-2 bg-slate-800 border border-slate-700 text-white rounded-lg hover:bg-slate-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:e.jsx(de,{className:"w-5 h-5"})}),e.jsxs("span",{className:"text-slate-300",children:["Page ",i," of ",O]}),e.jsx("button",{onClick:()=>c(t=>Math.min(O,t+1)),disabled:i===O,className:"px-3 py-2 bg-slate-800 border border-slate-700 text-white rounded-lg hover:bg-slate-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:e.jsx(xe,{className:"w-5 h-5"})})]})]}),H&&e.jsx(me,{open:H,onClose:()=>{J(!1),W(null)},transaction:te}),q&&e.jsx(ve,{open:q,onClose:()=>{B||(R(!1),V(null))},transaction:I,loading:B,onSave:le})]})}export{Ee as default};
