1import{u as K,at as q,r as i,k as Q,a as A,H as c,t as b,au as D,av as _,aw as k,j as e,P as w,K as C,L as P,ax as L,ay as M,X as F,n as N,y as E}from"./index-BUCFbuLp.js";import{u as v}from"./useMutation-CJdcrmxg.js";import{L as S}from"./loader-circle-DDgcSI5K.js";import{S as T}from"./star-CI4T08o3.js";import{T as R}from"./trash-2-_FXoXQvX.js";import{C as O}from"./chevron-down-CTbniI12.js";import{C as U}from"./check-CQuVRh8U.js";function B(o){return o?`â¢â¢â¢â¢ â¢â¢â¢â¢ ${o.slice(-4)}`:""}function J(){const{isAuthenticated:o}=K(),u=q();i.useEffect(()=>{o||u.navigate({to:"/login"})},[o,u]);const a=Q(),l=A({...c,enabled:o,staleTime:6e4}),n=l.data??[],[f,d]=i.useState(!1),[x,p]=i.useState(null),y=v({mutationFn:t=>D(t),onMutate:async t=>{await a.cancelQueries({queryKey:c.queryKey});const m=a.getQueryData(c.queryKey);return a.setQueryData(c.queryKey,r=>(r??[]).map(s=>({...s,is_default:s.id===t}))),{prev:m}},onError:(t,m,r)=>{r?.prev&&a.setQueryData(c.queryKey,r.prev),b.error(t.message)},onSuccess:()=>{b.success("Default account updated"),a.invalidateQueries({queryKey:c.queryKey})}}),h=v({mutationFn:t=>_(t),onMutate:async t=>{await a.cancelQueries({queryKey:c.queryKey});const m=a.getQueryData(c.queryKey);return a.setQueryData(c.queryKey,r=>(r??[]).filter(s=>s.id!==t)),{prev:m}},onError:(t,m,r)=>{r?.prev&&a.setQueryData(c.queryKey,r.prev),b.error(t.message)},onSuccess:()=>{b.success("Bank account removed"),a.invalidateQueries({queryKey:c.queryKey})}}),g=n.length>=k;return e.jsxs("div",{className:"mx-auto max-w-2xl px-4 py-8 md:px-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Payout accounts"}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Add up to ",k," bank accounts to receive your earnings."]})]}),e.jsxs("button",{onClick:()=>d(!0),disabled:g,className:"inline-flex shrink-0 items-center gap-2 rounded-full brand-gradient px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-soft hover:opacity-95 transition disabled:opacity-50",children:[e.jsx(w,{className:"h-4 w-4"})," Add account"]})]}),e.jsxs("div",{className:"mt-6",children:[l.isLoading?e.jsx("div",{className:"grid place-items-center rounded-3xl border border-border bg-muted/40 p-12 text-sm text-muted-foreground",children:e.jsx(S,{className:"h-5 w-5 animate-spin"})}):n.length===0?e.jsxs("div",{className:"rounded-3xl border border-dashed border-border bg-muted/30 p-10 text-center",children:[e.jsx("div",{className:"mx-auto grid h-14 w-14 place-items-center rounded-full bg-background shadow-soft",children:e.jsx(C,{className:"h-6 w-6 text-primary"})}),e.jsx("h2",{className:"mt-4 font-semibold",children:"No bank accounts yet"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Add a Nigerian bank account so we can send your sales earnings."}),e.jsxs("button",{onClick:()=>d(!0),className:"mt-5 inline-flex items-center gap-2 rounded-full brand-gradient px-5 py-2.5 text-sm font-semibold text-primary-foreground shadow-soft hover:opacity-95 transition",children:[e.jsx(w,{className:"h-4 w-4"})," Add bank account"]})]}):e.jsx("ul",{className:"space-y-3",children:n.map(t=>e.jsxs("li",{className:"flex items-center gap-3 rounded-2xl border border-border bg-background p-4",children:[e.jsx("div",{className:"grid h-11 w-11 place-items-center rounded-xl bg-primary/10 text-primary",children:e.jsx(C,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"truncate font-semibold",children:t.bank_name}),t.is_default&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-primary",children:[e.jsx(T,{className:"h-3 w-3 fill-primary"})," Default"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:B(t.bank_account)})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[!t.is_default&&e.jsx("button",{onClick:()=>y.mutate(t.id),disabled:y.isPending,className:"rounded-full border border-border px-3 py-1.5 text-xs font-medium hover:bg-muted transition disabled:opacity-60",children:"Set default"}),e.jsx("button",{onClick:()=>p(t),"aria-label":"Remove account",className:"grid h-9 w-9 place-items-center rounded-full text-muted-foreground hover:bg-muted hover:text-destructive transition",children:e.jsx(R,{className:"h-4 w-4"})})]})]},t.id))}),g&&e.jsxs("p",{className:"mt-3 text-xs text-muted-foreground",children:["You've reached the ",k,"-account limit. Remove one to add another."]}),e.jsxs("p",{className:"mt-6 text-xs text-muted-foreground",children:["Need to view past payouts?"," ",e.jsx(P,{to:"/orders",className:"underline hover:text-foreground",children:"See your orders"}),"."]})]}),f&&e.jsx(H,{onClose:()=>d(!1),onAdded:()=>{d(!1),a.invalidateQueries({queryKey:c.queryKey})}}),x&&e.jsx(z,{title:"Remove bank account?",description:`${x.bank_name} ${B(x.bank_account)} will no longer receive payouts.`,confirmLabel:"Remove",destructive:!0,onCancel:()=>p(null),onConfirm:()=>{const t=x.id;p(null),h.mutate(t)}})]})}
1const $=[{code:"044",name:"Access Bank"},{code:"050",name:"Ecobank"},{code:"011",name:"First Bank"},{code:"214",name:"FCMB"},{code:"070",name:"Fidelity Bank"},{code:"058",name:"GTBank"},{code:"082",name:"Keystone Bank"},{code:"076",name:"Polaris Bank"},{code:"101",name:"Providus Bank"},{code:"221",name:"Stanbic IBTC"},{code:"232",name:"Sterling Bank"},{code:"032",name:"Union Bank"},{code:"033",name:"UBA"},{code:"035",name:"Wema Bank"},{code:"057",name:"Zenith Bank"}];function H({onClose:o,onAdded:u}){const a=A(L),l=i.useMemo(()=>a.data&&a.data.length>0?a.data:$,[a.data]),[n,f]=i.useState(null),[d,x]=i.useState(""),[p,y]=i.useState(!1),[h,g]=i.useState(""),t=i.useMemo(()=>{const s=h.trim().toLowerCase();return s?l.filter(j=>j.name.toLowerCase().includes(s)):l},[l,h]),m=!!n&&/^\d{10}$/.test(d),r=v({mutationFn:()=>M({bank_code:n.code,bank_account:d,bank_name:n.name}),onSuccess:()=>{b.success("Bank account added"),u()},onError:s=>{const j=/400/.test(s.message)?"Account could not be verified. Check the number or try another bank.":s.message;b.error(j)}});return e.jsx("div",{className:"fixed inset-0 z-50 grid place-items-center bg-black/50 p-4",onClick:o,children:e.jsxs("div",{className:"w-full max-w-md rounded-3xl bg-background p-6 shadow-xl",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-bold",children:"Add bank account"}),e.jsx("button",{onClick:o,"aria-label":"Close",className:"rounded-full p-1 hover:bg-muted",children:e.jsx(F,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"mt-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Bank"}),e.jsxs("button",{type:"button",onClick:()=>y(s=>!s),className:"mt-1 flex w-full items-center justify-between rounded-xl border border-border bg-background px-3 py-2.5 text-left text-sm hover:bg-muted/40 transition",children:[e.jsx("span",{className:N(!n&&"text-muted-foreground"),children:n?n.name:"Select your bank"}),e.jsx(O,{className:N("h-4 w-4 transition",p&&"rotate-180")})]}),p&&e.jsxs("div",{className:"mt-2 rounded-2xl border border-border bg-background shadow-soft",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2",children:[e.jsx(E,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:h,onChange:s=>g(s.target.value),placeholder:"Search banks",className:"w-full bg-transparent text-sm outline-none"})]}),e.jsx("ul",{className:"max-h-64 overflow-y-auto py-1",children:t.length===0?e.jsxs("li",{className:"px-3 py-4 text-center text-sm text-muted-foreground",children:['No banks match "',h,'"']}):t.map(s=>{const j=n?.code===s.code;return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>{f(s),y(!1),g("")},className:"flex w-full items-center justify-between px-3 py-2 text-left text-sm hover:bg-muted transition",children:[e.jsx("span",{children:s.name}),j&&e.jsx(U,{className:"h-4 w-4 text-primary"})]})},s.code)})})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium",children:"Account number"}),e.jsx("input",{inputMode:"numeric",maxLength:10,value:d,onChange:s=>x(s.target.value.replace(/\D/g,"").slice(0,10)),placeholder:"10-digit NUBAN",className:"mt-1 w-full rounded-xl border border-border bg-background px-3 py-2.5 text-sm tracking-wider"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"We'll verify the account with your bank before saving it. The account name must match the name on your Havyn profile."})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx("button",{onClick:o,className:"rounded-full border-2 border-border px-5 py-2 text-sm font-semibold hover:bg-muted transition",children:"Cancel"}),e.jsxs("button",{onClick:()=>r.mutate(),disabled:!m||r.isPending,className:"inline-flex items-center gap-2 rounded-full brand-gradient px-5 py-2 text-sm font-semibold text-primary-foreground shadow-soft hover:opacity-95 transition disabled:opacity-60",children:[r.isPending&&e.jsx(S,{className:"h-4 w-4 animate-spin"}),r.isPending?"Verifying...":"Save account"]})]})]})})}function z({title:o,description:u,confirmLabel:a,destructive:l,onCancel:n,onConfirm:f}){return e.jsx("div",{className:"fixed inset-0 z-50 grid place-items-center bg-black/50 p-4",onClick:n,children:e.jsxs("div",{className:"w-full max-w-sm rounded-3xl bg-background p-6 shadow-xl",onClick:d=>d.stopPropagation(),children:[e.jsx("h3",{className:"text-lg font-bold",children:o}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:u}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{onClick:n,className:"rounded-full border-2 border-border px-4 py-2 text-sm font-semibold hover:bg-muted transition",children:"Cancel"}
1),e.jsx("button",{onClick:f,className:N("rounded-full px-4 py-2 text-sm font-semibold text-primary-foreground shadow-soft transition",l?"bg-destructive hover:opacity-95":"brand-gradient hover:opacity-95"),children:a})]})]})})}export{J as component};
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.