1import{c as F,a as N,u as w,j as e}from"./vendor-query-cXsdqGcv.js";import{r as y,L as K}from"./vendor-router-DH4wqzhc.js";import{L as M,B as f,I as A}from"./index-kR8qAHhZ.js";import{e as L,ai as q,B as U,n as J,aj as B,a as _,J as W,L as v,o as T,ak as R,a9 as D,al as V,k as O,N as z,F as H,v as G,W as I,y as Y,E as X,am as Z,i as ee,V as se,an as te,ao as ae,C as re,l as le}from"./vendor-icons-Df2JX92Y.js";import"./vendor-react-Dl9vZzi4.js";function S(r){return new Date(r).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})}function ie(r){return r<1024?`${r} B`:r<1024*1024?`${(r/1024).toFixed(1)} KB`:`${(r/(1024*1024)).toFixed(1)} MB`}function ne(r){return r.split("_").map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" ")}function oe({password:r}){const[a,n]=y.useState(!1);return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-mono",style:{color:"hsl(var(--text-secondary))"},children:a?r:"â¢â¢â¢â¢â¢â¢â¢â¢"}),e.jsx("button",{onClick:()=>n(!a),className:"w-6 h-6 rounded flex items-center justify-center transition-colors hover:bg-[hsl(var(--accent))]",style:{color:"hsl(var(--text-tertiary))"},"data-testid":"button-toggle-user-password",children:a?e.jsx(Y,{className:"w-3.5 h-3.5"}):e.jsx(X,{className:"w-3.5 h-3.5"})})]})}function ce({status:r}){const a={pending:{bg:"hsla(45, 93%, 47%, 0.1)",text:"hsl(45, 93%, 37%)"},submitted:{bg:"hsla(217, 91%, 60%, 0.1)",text:"hsl(217, 91%, 50%)"},approved:{bg:"hsla(160, 84%, 39%, 0.1)",text:"hsl(160, 84%, 29%)"}},n=a[r]||a.pending;return e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-[11px] font-semibold",style:{background:n.bg,color:n.text},"data-testid":`badge-kyc-${r}`,children:r.charAt(0).toUpperCase()+r.slice(1)})}function de({status:r}){const a={pending:{bg:"hsla(45, 93%, 47%, 0.1)",text:"hsl(45, 93%, 37%)"},approved:{bg:"hsla(160, 84%, 39%, 0.1)",text:"hsl(160, 84%, 29%)"},rejected:{bg:"hsla(0, 0%, 50%, 0.1)",text:"hsl(0, 0%, 40%)"}},n=a[r]||a.pending;return e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-[11px] font-semibold",style:{background:n.bg,color:n.text},"data-testid":`badge-status-${r}`,children:r.charAt(0).toUpperCase()+r.slice(1)})}const me=[{id:"users",label:"Users",icon:e.jsx(L,{className:"w-4 h-4"})},{id:"waitlist",label:"Waitlist",icon:e.jsx(q,{className:"w-4 h-4"})},{id:"applications",label:"Business Applications",icon:e.jsx(U,{className:"w-4 h-4"})},{id:"support",label:"Support Tickets",icon:e.jsx(B,{className:"w-4 h-4"})},{id:"balances",label:"Balance Management",icon:e.jsx(I,{className:"w-4 h-4"})}];function xe({onLogin:r}){const[a,n]=y.useState(""),[i,p]=y.useState(""),[d,c]=y.useState(""),[m,o]=y.useState(!1),x=async j=>{j.preventDefault(),c(""),o(!0);try{const u=await fetch("/api/admin/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:a,password:i})}),l=await u.json();if(!u.ok){c(l.message||"Invalid credentials."),o(!1);return}sessionStorage.setItem("adminToken",l.token),r(l.token)}catch{c("Something went wrong. Please try again."),o(!1)}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center px-6",style:{background:"hsl(var(--background))"},children:e.jsxs("div",{className:"w-full max-w-sm",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(M,{theme:"light",size:"default"})}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mb-2",children:[e.jsx(G,{className:"w-4 h-4",style:{color:"hsl(var(--text-tertiary))"}}),e.jsx("h1",{className:"text-xl font-semibold",style:{color:"hsl(var(--text-primary))"},children:"Admin Portal"})]}),e.jsx("p",{className:"text-sm",style:{color:"hsl(var(--text-secondary))"},children:"Sign in to access the admin dashboard"})]}),e.jsxs("form",{onSubmit:x,className:"space-y-4",children:[e.jsx("div",{children:e.jsx(A,{type:"email",placeholder:"Email address",value:a,onChange:j=>n(j.target.value),required:!0,"data-testid":"input-admin-email",className:"h-11"})}),e.jsx("div",{children:e.jsx(A,{type:"password",placeholder:"Password",value:i,onChange:j=>p(j.target.value),required:!0,"data-testid":"input-admin-password",className:"h-11"})}),d&&e.jsx("p",{className:"text-sm font-medium",style:{color:"hsl(25, 95%, 53%)"},"data-testid":"text-admin-error",children:d}),e.jsx(f,{type:"submit",className:"w-full h-11 font-semibold",style:{background:"linear-gradient(135deg, hsl(220, 90%, 40%), hsl(235, 70%, 45%))",color:"white"},disabled:m,"data-testid":"button-admin-login",children:m?e.jsx(v,{className:"w-4 h-4 animate-spin"}):"Sign in"})]}),e.jsx("div",{className:"mt-6 text-center",children:e.jsx(K,{href:"/",className:"text-sm font-medium",style:{color:"hsl(var(--text-tertiary))"},children:"â Back to site"})})]})})}function fe(){const r=F(),[a,n]=y.useState(()=>sessionStorage.getItem("adminToken")),[i,p]=y.useState("users"),[d,c]=y.useState(null),m={headers:{Authorization:`Bearer ${a}`}},{data:o,isLoading:x}=N({queryKey:["/api/admin/stats"],queryFn:()=>fetch("/api/admin/stats",m).then(s=>{if(!s.ok)throw new Error;return s.json()}),enabled:!!a}),{data:j,isLoading:u}=N({queryKey:["/api/admin/users"],queryFn:()=>fetch("/api/admin/users",m).then(s=>{if(!s.ok)throw new Error;return s.json()}),enabled:!!a}),{data:l,isLoading:t}=N({queryKey:["/api/admin/waitlist"],queryFn:()=>fetch("/api/admin/waitlist",m).then(s=>{if(!s.ok)throw new Error;return s.json()}),enabled:!!a}),h=w({mutationFn:s=>fetch(`/api/admin/waitlist/${s}`,{method:"DELETE",headers:{Authorization:`Bearer ${a}`}}).then(b=>{if(!b.ok)throw new Error;return b.json()}),onSuccess:()=>{r.invalidateQueries({queryKey:["/api/admin/waitlist"]}),r.invalidateQueries({queryKey:["/api/admin/stats"]})}}),{data:g,isLoading:k}=N({queryKey:["/api/admin/business-applications"],queryFn:()=>fetch("/api/admin/business-applications",m).then(s=>{if(!s.ok)throw new Error;return s.json()}),enabled:!!a});if(!a)return e.jsx(xe,{onLogin:s=>n(s)});const Q=[{label:"Total Users",value:o?.users??0,icon:e.jsx(L,{className:"w-5 h-5"}),color:"hsla(217, 91%, 60%, 0.1)",iconColor:"hsl(217, 91%, 50%)"},{label:"Waitlist Entries",value:o?.waitlist??0,icon:e.jsx(q,{className:"w-5 h-5"}),color:"hsla(160, 84%, 39%, 0.1)",iconColor:"hsl(160, 84%, 29%)"},{label:"Business Applications",value:o?.applications??0,icon:e.jsx(U,{className:"w-5 h-5"}
1),color:"hsla(270, 76%, 53%, 0.1)",iconColor:"hsl(270, 76%, 43%)"},{label:"KYC Submitted",value:o?.kycSubmitted??0,icon:e.jsx(J,{className:"w-5 h-5"}),color:"hsla(45, 93%, 47%, 0.1)",iconColor:"hsl(45, 93%, 37%)"},{label:"Support Tickets",value:o?.supportTickets??0,icon:e.jsx(B,{className:"w-5 h-5"}),color:"hsla(200, 80%, 50%, 0.1)",iconColor:"hsl(200, 80%, 40%)"}];return e.jsxs("div",{className:"min-h-screen overflow-x-hidden",style:{background:"hsl(var(--background))"},children:[e.jsx("header",{className:"sticky top-0 z-30 border-b",style:{background:"hsl(var(--surface-elevated))",borderColor:"hsl(var(--border-subtle))"},children:e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 h-16 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(M,{theme:"light"}),e.jsx("div",{className:"hidden sm:block h-6 w-px shrink-0",style:{background:"hsl(var(--border-subtle))"}}),e.jsx("h1",{className:"hidden sm:block text-sm font-semibold truncate",style:{color:"hsl(var(--text-primary))"},"data-testid":"text-admin-title",children:"Admin Panel"})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(K,{href:"/","data-testid":"link-back-to-site",children:e.jsxs(f,{variant:"ghost",className:"gap-2 text-sm font-medium rounded-xl",style:{color:"hsl(var(--text-secondary))"},children:[e.jsx(_,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Back to site"})]})}),e.jsxs(f,{variant:"ghost",className:"gap-2 text-sm font-medium rounded-xl",style:{color:"hsl(var(--text-secondary))"},"data-testid":"button-admin-logout",onClick:()=>{sessionStorage.removeItem("adminToken"),n(null)},children:[e.jsx(W,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Log out"})]})]})]})}),e.jsxs("main",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[x?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(v,{className:"w-6 h-6 animate-spin",style:{color:"hsl(var(--text-tertiary))"}})}):e.jsx("div",{className:"grid grid-cols-1 min-[400px]:grid-cols-2 lg:grid-cols-5 gap-3 sm:gap-4 mb-8","data-testid":"stats-grid",children:Q.map(s=>e.jsxs("div",{className:"rounded-2xl border p-4 sm:p-5 transition-shadow hover:shadow-sm",style:{background:"hsl(var(--card-bg))",borderColor:"hsl(var(--card-border))"},"data-testid":`stat-card-${s.label.toLowerCase().replace(/\s+/g,"-")}`,children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center shrink-0",style:{background:s.color,color:s.iconColor},children:s.icon})}),e.jsx("p",{className:"text-xl sm:text-2xl font-semibold tracking-tight",style:{color:"hsl(var(--text-primary))"},children:s.value}),e.jsx("p",{className:"text-[11px] sm:text-xs mt-1 leading-tight",style:{color:"hsl(var(--text-tertiary))"},children:s.label})]},s.label))}),e.jsx("div",{className:"flex gap-2 mb-6 overflow-x-auto pb-1 -mx-4 px-4 sm:mx-0 sm:px-0 no-scrollbar","data-testid":"tab-navigation",children:me.map(s=>e.jsxs("button",{onClick:()=>p(s.id),className:"flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-medium transition-all shrink-0",style:i===s.id?{background:"hsl(var(--primary))",color:"white"}:{background:"hsl(var(--accent))",color:"hsl(var(--text-secondary))"},"data-testid":`tab-${s.id}`,children:[s.icon,s.label]},s.id))}),e.jsxs("div",{className:"rounded-2xl border overflow-hidden",style:{background:"hsl(var(--card-bg))",borderColor:"hsl(var(--card-border))"},children:[i==="users"&&e.jsx(e.Fragment,{children:u?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(v,{className:"w-5 h-5 animate-spin",style:{color:"hsl(var(--text-tertiary))"}})}):j?.length?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full","data-testid":"table-users",children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"hsl(var(--section-alt))"},children:["Email","Password","Name","Account Type","Phone","Company","KYC Status","Step","Joined"].map(s=>e.jsx("th",{className:"text-left text-[11px] font-semibold uppercase tracking-wider px-5 py-3",style:{color:"hsl(var(--text-tertiary))"},children:s},s))})}),e.jsx("tbody",{children:j.map((s,b)=>e.jsxs("tr",{className:"border-t transition-colors hover:bg-[hsl(var(--accent))]",style:{borderColor:"hsl(var(--border-subtle))"},"data-testid":`row-user-${b}`,children:[e.jsx("td",{className:"px-5 py-3.5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"w-3.5 h-3.5 shrink-0",style:{color:"hsl(var(--text-tertiary))"}}),e.jsx("span",{className:"text-sm font-medium",style:{color:"hsl(var(--text-primary))"},children:s.email})]})}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsx(oe,{password:s.password})}),e.jsx("td",{className:"px-5 py-3.5 text-sm",style:{color:"hsl(var(--text-secondary))"},children:s.firstName&&s.lastName?`${s.firstName} ${s.lastName}`:"â"}),e.jsx("td",{className:"px-5 py-3.5 text-sm font-medium",style:{color:"hsl(var(--text-secondary))"},children:s.accountType?s.accountType.charAt(0).toUpperCase()+s.accountType.slice(1):"â"}),e.jsx("td",{className:"px-5 py-3.5 text-sm",style:{color:"hsl(var(--text-secondary))"},children:s.phone||"â"}),e.jsx("td",{className:"px-5 py-3.5 text-sm",style:{color:"hsl(var(--text-secondary))"},children:s.companyName||"â"}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsx(ce,{status:s.kycStatus})}),e.jsx("td",{className:"px-5 py-3.5 text-sm font-mono",style:{color:"hsl(var(--text-tertiary))"},children:s.onboardingStep}),e.jsx("td",{className:"px-5 py-3.5 text-sm whitespace-nowrap",style:{color:"hsl(var(--text-tertiary))"},children:S(s.createdAt)})]},s.id))})]})}):e.jsx($,{icon:e.jsx(L,{className:"w-6 h-6"}),message:"No users registered yet"})}),i==="waitlist"&&e.jsx(e.Fragment,{children:t?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(v,{className:"w-5 h-5 animate-spin",style:{color:"hsl(var(--text-tertiary))"}})}):l?.length?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full","data-testid":"table-waitlist",children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"hsl(var(--section-alt))"},children:["#","Name","Email","Phone","Joined","Actions"].map(s=>e.jsx("th",{className:"text-left text-[11px] font-semibold uppercase tracking-wider px-5 py-3",style:{color:"hsl(var(--text-tertiary))"},children:s},s))})}),e.jsx("tbody",{children:l.map((s,b)=>e.jsxs("tr",{className:"border-t transition-colors hover:bg-[hsl(var(--accent))]",style:{borderColor:"hsl(var(--border-subtle))"},"data-testid":`row-waitlist-${b}`,children:[e.jsx("td",{className:"px-5 py-3.5 text-sm font-mono",style:{color:"hsl(var(--text-tertiary))"},children:b+1}),e.jsxs("td",{className:"px-5 py-3.5 text-sm font-medium",style:{color:"hsl(var(--text-primary))"},children:[s.firstName," ",s.lastName]}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"w-3.5 h-3.5 shrink-0",style:{color:"hsl(var(--text-tertiary))"}}),e.jsx("span",{className:"text-sm",style:{color:"hsl(var(--text-secondary))"},children:s.email})]})}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{className:"w-3.5 h-3.5 shrink-0",style:{color:"hsl(var(--text-tertiary))"}}),e.jsx("span",{className:"text-sm",style:{color:"hsl(var(--text-secondary))"},children:s.phone})]})}),e.jsx("td",{className:"px-5 py-3.5 text-sm whitespace-nowrap",style:{color:"hsl(var(--text-tertiary))"},children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"w-3.5 h-3.5 shrink-0"}),S(s.createdAt)]})}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsx("button",{"data-testid":`button-delete-waitlist-${b}`,onClick:()=>{window.confirm(`Remove ${s.email} from the waitlist?`)&&h.mutate(s.id)},disabled:h.isPending,className:"p-2 rounded-lg text-slate-400 hover:text-slate-700 hover:bg-slate-100 transition-colors disabled:opacity-50",title:"Remove from waitlist",children:e.jsx(V,{className:"w-4 h-4"})})})]},s.id))})]})}):e.jsx($,{icon:e.jsx(q,{className:"w-6 h-6"}
1),message:"No waitlist entries yet"})}),i==="balances"&&e.jsx(pe,{adminToken:a}),i==="support"&&e.jsx(ye,{adminToken:a}),i==="applications"&&e.jsx(e.Fragment,{children:k?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(v,{className:"w-5 h-5 animate-spin",style:{color:"hsl(var(--text-tertiary))"}})}):g?.length?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full","data-testid":"table-applications",children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"hsl(var(--section-alt))"},children:["Company","Sector","UBO","Purpose","Monthly Volume","Status","Applied",""].map(s=>e.jsx("th",{className:"text-left text-[11px] font-semibold uppercase tracking-wider px-5 py-3",style:{color:"hsl(var(--text-tertiary))"},children:s},s))})}),e.jsx("tbody",{children:g.map((s,b)=>e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:"border-t transition-colors hover:bg-[hsl(var(--accent))] cursor-pointer",style:{borderColor:"hsl(var(--border-subtle))"},onClick:()=>c(d===s.id?null:s.id),"data-testid":`row-application-${b}`,children:[e.jsx("td",{className:"px-5 py-3.5",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"hsl(var(--text-primary))"},children:s.companyName}),e.jsx("p",{className:"text-[11px]",style:{color:"hsl(var(--text-tertiary))"},children:s.companyNumber})]})}),e.jsx("td",{className:"px-5 py-3.5 text-sm",style:{color:"hsl(var(--text-secondary))"},children:s.sector}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"hsl(var(--text-primary))"},children:s.uboFullName}),e.jsx("p",{className:"text-[11px]",style:{color:"hsl(var(--text-tertiary))"},children:s.uboEmail})]})}),e.jsx("td",{className:"px-5 py-3.5 text-sm max-w-[200px] truncate",style:{color:"hsl(var(--text-secondary))"},children:s.accountPurpose}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"hsl(var(--text-primary))"},children:s.estimatedMonthlyValue}),e.jsxs("p",{className:"text-[11px]",style:{color:"hsl(var(--text-tertiary))"},children:[s.estimatedMonthlyPayments," payments"]})]})}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsx(de,{status:s.status})}),e.jsx("td",{className:"px-5 py-3.5 text-sm whitespace-nowrap",style:{color:"hsl(var(--text-tertiary))"},children:S(s.createdAt)}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsx("button",{className:"w-7 h-7 rounded-lg flex items-center justify-center transition-colors hover:bg-[hsl(var(--accent))]",style:{color:"hsl(var(--text-tertiary))"},"data-testid":`button-expand-${b}`,children:d===s.id?e.jsx(O,{className:"w-4 h-4"}):e.jsx(z,{className:"w-4 h-4"})})})]},s.id),d===s.id&&e.jsx("tr",{style:{borderColor:"hsl(var(--border-subtle))"},className:"border-t",children:e.jsxs("td",{colSpan:8,className:"px-5 py-5",style:{background:"hsl(var(--section-alt))"},children:[e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-3 gap-4 mb-5",children:[e.jsx(P,{label:"Website",value:s.website||"â"}),e.jsx(P,{label:"Expected Payment Types",value:s.expectedPaymentTypes}),e.jsx(P,{label:"Company Number",value:s.companyNumber})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-wider mb-3",style:{color:"hsl(var(--text-tertiary))"},children:["Uploaded Documents (",s.documents.length,")"]}),s.documents.length>0?e.jsx("div",{className:"grid sm:grid-cols-2 lg:grid-cols-3 gap-2",children:s.documents.map(C=>e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl border",style:{background:"hsl(var(--card-bg))",borderColor:"hsl(var(--card-border))"},"data-testid":`doc-${C.id}`,children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center shrink-0",style:{background:"hsla(217, 91%, 60%, 0.1)",color:"hsl(217, 91%, 50%)"},children:e.jsx(H,{className:"w-4 h-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold truncate",style:{color:"hsl(var(--text-primary))"},children:ne(C.documentType)}),e.jsxs("p",{className:"text-[11px] truncate",style:{color:"hsl(var(--text-tertiary))"},children:[C.originalFilename," · ",ie(C.fileSize)]})]})]},C.id))}):e.jsx("p",{className:"text-sm",style:{color:"hsl(var(--text-tertiary))"},children:"No documents uploaded"})]})]})},`${s.id}-details`)]}))})]})}):e.jsx($,{icon:e.jsx(U,{className:"w-6 h-6"}),message:"No business applications yet"})})]})]})]})}function E({label:r,variant:a,onSubmit:n,isPending:i}){const[p,d]=y.useState(!1),[c,m]=y.useState(""),[o,x]=y.useState(""),j=()=>{n(c,o),m(""),x(""),d(!1)};return p?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(A,{type:"number",step:"0.01",min:"0.01",placeholder:"Amount (£)",value:c,onChange:u=>m(u.target.value),className:"h-8 w-28 text-xs rounded-lg","data-testid":`input-${a}-amount`}),e.jsx(A,{type:"text",placeholder:"Note",value:o,onChange:u=>x(u.target.value),className:"h-8 w-40 text-xs rounded-lg","data-testid":`input-${a}-note`}),e.jsx(f,{onClick:j,disabled:!c||parseFloat(c)<=0||i,className:"h-8 px-3 text-xs font-semibold rounded-lg",style:{background:"linear-gradient(135deg, hsl(220, 90%, 40%), hsl(235, 70%, 45%))",color:"white"},"data-testid":`button-${a}-confirm`,children:i?e.jsx(v,{className:"w-3 h-3 animate-spin"}):"Confirm"}),e.jsx(f,{onClick:()=>{d(!1),m(""),x("")},variant:"ghost",className:"h-8 px-2 text-xs rounded-lg",style:{color:"hsl(var(--text-tertiary))"},"data-testid":`button-${a}-cancel`,children:"Cancel"})]}):e.jsxs(f,{onClick:()=>d(!0),className:"gap-1.5 text-xs font-semibold rounded-xl h-8 px-3",style:a==="credit"?{background:"hsla(160, 84%, 39%, 0.1)",color:"hsl(160, 84%, 29%)"}:{background:"hsla(0, 72%, 51%, 0.1)",color:"hsl(0, 72%, 41%)"},"data-testid":`button-${a}-balance`,children:[a==="credit"?e.jsx(se,{className:"w-3.5 h-3.5"}):e.jsx(te,{className:"w-3.5 h-3.5"}),r]})}function he({cardId:r,adminToken:a}){const n=F(),i=w({mutationFn:async({amount:d,note:c})=>{const m=await fetch(`/api/admin/card-balance/${r}/load`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({amount:d,note:c})});if(!m.ok){const o=await m.json();throw new Error(o.message)}return m.json()},onSuccess:()=>{n.invalidateQueries({queryKey:["/api/admin/user-balance"]})}}),p=w({mutationFn:async({amount:d,note:c})=>{const m=await fetch(`/api/admin/card-balance/${r}/unload`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({amount:d,note:c})});if(!m.ok){const o=await m.json();throw new Error(o.message)}return m.json()},onSuccess:()=>{n.invalidateQueries({queryKey:["/api/admin/user-balance"]})}});return e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(E,{label:"Credit",variant:"credit",onSubmit:(d,c)=>i.mutate({amount:d,note:c}),isPending:i.isPending}),e.jsx(E,{label:"Debit",variant:"debit",onSubmit:(d,c)=>p.mutate({amount:d,note:c}),isPending:p.isPending}),(i.isError||p.isError)&&e.jsx("p",{className:"text-xs font-medium",style:{color:"hsl(0, 72%, 51%)"},"data-testid":"text-card-action-error",children:(i.error||p.error)?.message})]})}function pe({adminToken:r}){const[a,n]=y.useState(""),[i,p]=y.useState(null),d=F(),c={headers:{Authorization:`Bearer ${r}`}},{data:m}=N({queryKey:["/api/admin/users"],queryFn:()=>fetch("/api/admin/users",c).then(t=>{if(!t.ok)throw new Error;return t.json()})}),o=a.length>=1?(m||[]).filter(t=>t.email.toLowerCase().includes(a.toLowerCase())):m||[],{data:x,isLoading:j}=N({queryKey:["/api/admin/user-balance",i],queryFn:()=>fetch(`/api/admin/user-balance/${i}`,c).then(t=>{if(!t.ok)throw new Error;return t.json()}),enabled:!!i}),u=w({mutationFn:async({amount:t,note:h})=>{const g=await fetch(`/api/admin/user-balance/${i}/load`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({amount:t,note:h})});if(!g.ok){const k=await g.json();throw new Error(k.message)}return g.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["/api/admin/user-balance",i]})}}),l=w({mutationFn:async({amount:t,note:h})=>{const g=await fetch(`/api/admin/user-balance/${i}/unload`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({amount:t,note:h})});if(!g.ok){const k=await g.json();throw new Error(k.message)}return g.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["/api/admin/user-balance",i]})}});return e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Z,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4",style:{color:"hsl(var(--text-tertiary))"}}),e.jsx(A,{type:"text",placeholder:"Search users by email...",value:a,onChange:t=>{n(t.target.value),t.target.value||p(null)},className:"h-11 pl-10 rounded-xl","data-testid":"input-balance-search"})]}),o.length>0&&!i&&e.jsxs("div",{className:"mt-2 rounded-xl border overflow-hidden max-h-64 overflow-y-auto",style:{borderColor:"hsl(var(--card-border))",background:"hsl(var(--card-bg))"},"data-testid":"balance-search-results",children:[e.jsxs("p",{className:"px-4 py-2 text-[11px] font-semibold uppercase tracking-wider",style:{color:"hsl(var(--text-tertiary))",background:"hsl(var(--section-alt))"},children:["Select a user (",o.length,")"]}),o.slice(0,20).map(t=>e.jsxs("button",{onClick:()=>
1{p(t.id),n(t.email)},className:"w-full text-left px-4 py-3 border-b last:border-b-0 transition-colors hover:bg-[hsl(var(--accent))]",style:{borderColor:"hsl(var(--border-subtle))"},"data-testid":`balance-user-option-${t.id}`,children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"hsl(var(--text-primary))"},children:t.email}),e.jsxs("p",{className:"text-xs",style:{color:"hsl(var(--text-tertiary))"},children:[t.firstName&&t.lastName?`${t.firstName} ${t.lastName}`:"No name"," · ",t.accountType||"personal"]})]},t.id))]}),a.length>=1&&o.length===0&&!i&&e.jsxs("p",{className:"mt-3 text-sm",style:{color:"hsl(var(--text-tertiary))"},"data-testid":"text-no-users-found",children:['No users found matching "',a,'"']})]}),i&&j&&e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(v,{className:"w-5 h-5 animate-spin",style:{color:"hsl(var(--text-tertiary))"}})}),i&&x&&e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"rounded-2xl border p-5",style:{background:"hsl(var(--card-bg))",borderColor:"hsl(var(--card-border))"},"data-testid":"panel-user-info",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold",style:{color:"hsl(var(--text-primary))"},"data-testid":"text-user-name",children:x.user.firstName&&x.user.lastName?`${x.user.firstName} ${x.user.lastName}`:"Unnamed User"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(T,{className:"w-3.5 h-3.5",style:{color:"hsl(var(--text-tertiary))"}}),e.jsx("span",{className:"text-sm",style:{color:"hsl(var(--text-secondary))"},"data-testid":"text-user-email",children:x.user.email})]}),e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-[11px] font-semibold mt-2",style:{background:"hsla(217, 91%, 60%, 0.1)",color:"hsl(217, 91%, 50%)"},"data-testid":"text-user-account-type",children:x.user.accountType?x.user.accountType.charAt(0).toUpperCase()+x.user.accountType.slice(1):"Personal"})]}),e.jsx(f,{variant:"ghost",className:"text-xs rounded-lg",style:{color:"hsl(var(--text-tertiary))"},onClick:()=>{p(null),n("")},"data-testid":"button-clear-selection",children:"Clear"})]}),e.jsxs("div",{className:"rounded-xl border p-4 mb-4",style:{background:"hsl(var(--section-alt))",borderColor:"hsl(var(--border-subtle))"},children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider mb-1",style:{color:"hsl(var(--text-tertiary))"},children:"Exchange Balance"}),e.jsxs("p",{className:"text-3xl font-bold tracking-tight",style:{color:"hsl(var(--text-primary))"},"data-testid":"text-exchange-balance",children:["£",parseFloat(x.simulatedBalance).toLocaleString("en-GB",{minimumFractionDigits:2,maximumFractionDigits:2})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-3",children:[e.jsx(E,{label:"Credit Balance",variant:"credit",onSubmit:(t,h)=>u.mutate({amount:t,note:h}),isPending:u.isPending}),e.jsx(E,{label:"Debit Balance",variant:"debit",onSubmit:(t,h)=>l.mutate({amount:t,note:h}),isPending:l.isPending})]}),(u.isError||l.isError)&&e.jsx("p",{className:"text-xs font-medium mt-2",style:{color:"hsl(0, 72%, 51%)"},"data-testid":"text-balance-action-error",children:(u.error||l.error)?.message})]}),x.virtualCards.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider mb-3",style:{color:"hsl(var(--text-tertiary))"},children:"Virtual Cards"}),e.jsx("div",{className:"space-y-3",children:x.virtualCards.map(t=>e.jsxs("div",{className:"rounded-xl border p-4",style:{background:"hsl(var(--section-alt))",borderColor:"hsl(var(--border-subtle))"},"data-testid":`card-panel-${t.id}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"w-4 h-4",style:{color:"hsl(217, 91%, 50%)"}}),e.jsxs("span",{className:"text-sm font-medium",style:{color:"hsl(var(--text-primary))"},"data-testid":`text-card-number-${t.id}`,children:["â¢â¢â¢â¢ â¢â¢â¢â¢ â¢â¢â¢â¢ ",t.cardNumberLast4]})]}),e.jsxs("span",{className:"text-lg font-semibold",style:{color:"hsl(var(--text-primary))"},"data-testid":`text-card-balance-${t.id}
1`,children:["£",parseFloat(t.balance||"0").toLocaleString("en-GB",{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),e.jsx(he,{cardId:t.id,adminToken:r})]},t.id))})]}),x.recentTransactions.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider mb-3",style:{color:"hsl(var(--text-tertiary))"},children:"Recent Transactions"}),e.jsx("div",{className:"space-y-1",children:x.recentTransactions.slice(0,10).map(t=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2.5 rounded-lg transition-colors hover:bg-[hsl(var(--accent))]","data-testid":`transaction-row-${t.id}`,children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"hsl(var(--text-primary))"},children:t.title}),e.jsxs("p",{className:"text-[11px]",style:{color:"hsl(var(--text-tertiary))"},children:[t.description?`${t.description} · `:"",S(t.createdAt)]})]}),e.jsxs("span",{className:"text-sm font-semibold",style:{color:t.type.includes("load")&&!t.type.includes("unload")?"hsl(160, 84%, 29%)":"hsl(0, 72%, 41%)"},"data-testid":`text-tx-amount-${t.id}`,children:[t.type.includes("load")&&!t.type.includes("unload")?"+":"-","£",parseFloat(t.amount).toFixed(2)]})]},t.id))})]})]})}),!i&&!a&&e.jsx($,{icon:e.jsx(I,{className:"w-6 h-6"}),message:"Search for a user by email to manage their balance"})]})}function ue({status:r}){const a={open:{bg:"hsla(217, 91%, 60%, 0.1)",text:"hsl(217, 91%, 50%)",icon:e.jsx(B,{className:"w-3 h-3"})},in_progress:{bg:"hsla(45, 93%, 47%, 0.1)",text:"hsl(45, 93%, 37%)",icon:e.jsx(le,{className:"w-3 h-3"})},resolved:{bg:"hsla(160, 84%, 39%, 0.1)",text:"hsl(160, 84%, 29%)",icon:e.jsx(re,{className:"w-3 h-3"})},closed:{bg:"hsla(0, 0%, 50%, 0.1)",text:"hsl(0, 0%, 40%)",icon:e.jsx(ae,{className:"w-3 h-3"})}},n=a[r]||a.open,i=r==="in_progress"?"In Progress":r.charAt(0).toUpperCase()+r.slice(1);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-[11px] font-semibold",style:{background:n.bg,color:n.text},"data-testid":`badge-ticket-${r}`,children:[n.icon," ",i]})}function ye({adminToken:r}){const a=F(),n={headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}},{data:i,isLoading:p}=N({queryKey:["/api/admin/support-tickets"],queryFn:()=>fetch("/api/admin/support-tickets",{headers:{Authorization:`Bearer ${r}`}}).then(l=>{if(!l.ok)throw new Error;return l.json()})}),d=w({mutationFn:async({id:l,status:t})=>{const h=await fetch(`/api/admin/support-tickets/${l}/status`,{method:"PATCH",...n,body:JSON.stringify({status:t})});if(!h.ok)throw new Error("Failed to update status");return h.json()},onSuccess:()=>{a.invalidateQueries({queryKey:["/api/admin/support-tickets"]}),a.invalidateQueries({queryKey:["/api/admin/stats"]})}}),[c,m]=y.useState(null),[o,x]=y.useState("all");if(p)return e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(v,{className:"w-5 h-5 animate-spin",style:{color:"hsl(var(--text-tertiary))"}})});if(!i?.length)return e.jsx($,{icon:e.jsx(B,{className:"w-6 h-6"}),message:"No support tickets yet"});const j=o==="all"?i:i.filter(l=>l.status===o),u=["all","open","in_progress","resolved","closed"];return e.jsxs("div",{children:[e.jsx("div",{className:"flex flex-wrap gap-2 mb-4","data-testid":"ticket-filter-bar",children:u.map(l=>e.jsxs("button",{onClick:()=>x(l),className:"px-3 py-1.5 rounded-full text-[12px] font-semibold transition-all",style:{background:o===l?"hsl(220, 90%, 40%)":"hsl(var(--accent))",color:o===l?"white":"hsl(var(--text-secondary))"},"data-testid":`filter-${l}`,children:[l==="all"?"All":l==="in_progress"?"In Progress":l.charAt(0).toUpperCase()+l.slice(1),l==="all"?` (${i.length})`:` (${i.filter(t=>t.status===l).length})`]},l))}),e.jsx("div",{className:"rounded-2xl border overflow-hidden",style:{borderColor:"hsl(var(--card-border))",background:"hsl(var(--card-bg))"},"data-testid":"support-tickets-list",children:j.map((l,t)=>e.jsxs("div",{className:t>0?"border-t":"",style:{borderColor:"hsl(var(--border-subtle))"},children:[e.jsx("div",{className:"px-5 py-4 cursor-pointer transition-colors hover:bg-[hsl(var(--accent))]",onClick:()=>m(c===l.id?null:l.id),"data-testid":`ticket-row-${l.id}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1.5",children:[e.jsx("p",{className:"text-sm font-semibold truncate",style:{color:"hsl(var(--text-primary))"},children:l.name}),e.jsx(ue,{status:l.status})]}),e.jsx("p",{className:"text-[13px] truncate",style:{color:"hsl(var(--text-secondary))"},children:l.message}),e.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[e.jsxs("span",{className:"flex items-center gap-1 text-[11px]",style:{color:"hsl(var(--text-tertiary))"},children:[e.jsx(T,{className:"w-3 h-3"})," ",l.email]}),e.jsxs("span",{className:"flex items-center gap-1 text-[11px]",style:{color:"hsl(var(--text-tertiary))"},children:[e.jsx(D,{className:"w-3 h-3"})," ",S(l.createdAt)]})]})]}),e.jsx("button",{className:"w-7 h-7 rounded-lg flex items-center justify-center shrink-0 transition-colors hover:bg-[hsl(var(--accent))]",style:{color:"hsl(var(--text-tertiary))"},children:c===l.id?e.jsx(O,{className:"w-4 h-4"}):e.jsx(z,{className:"w-4 h-4"})})]})}),c===l.id&&e.jsxs("div",{className:"px-5 pb-5 pt-1",style:{background:"hsl(var(--section-alt))"},children:[e.jsxs("div",{className:"rounded-xl border p-4 mb-4",style:{background:"hsl(var(--card-bg))",borderColor:"hsl(var(--border-subtle))"},children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider mb-2",style:{color:"hsl(var(--text-tertiary))"},children:"Full Message"}),e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",style:{color:"hsl(var(--text-primary))"},children:l.message})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider mr-2",style:{color:"hsl(var(--text-tertiary))"},children:"Update Status:"}),["open","in_progress","resolved","closed"].map(h=>e.jsx("button",{onClick:()=>d.mutate({id:l.id,status:h}),disabled:l.status===h||d.isPending,className:"px-3 py-1.5 rounded-lg text-[12px] font-medium transition-all disabled:opacity-40",style:{background:l.status===h?"hsl(220, 90%, 40%)":"hsl(var(--accent))",color:l.status===h?"white":"hsl(var(--text-secondary))",borderColor:"hsl(var(--border-subtle))"},"data-testid":`ticket-status-${h}-${l.id}`,children:h==="in_progress"?"In Progress":h.charAt(0).toUpperCase()+h.slice(1)},h))]})]})]},l.id))})]})}function $({icon:r,message:a}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 px-6","data-testid":"empty-state",children:[e.jsx("div",{className:"w-14 h-14 roun
1ded-2xl flex items-center justify-center mb-4",style:{background:"hsl(var(--accent))",color:"hsl(var(--text-tertiary))"},children:r}),e.jsx("p",{className:"text-sm font-medium",style:{color:"hsl(var(--text-secondary))"},children:a})]})}function P({label:r,value:a}){return e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider mb-1",style:{color:"hsl(var(--text-tertiary))"},children:r}),e.jsx("p",{className:"text-sm",style:{color:"hsl(var(--text-primary))"},children:a})]})}export{fe 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.