import{a as p,j as e}from"./vendor-query-Brcc40-Y.js";import{T as f,S as d}from"./Skeleton-DGpeJz1z.js";import{P as u,i as x,f as h,Q as j,D as g,A as N,N as o,n as m,B as y}from"./index-tN-ddyeb.js";import{B as v}from"./Badge-CnBuGwnc.js";import{E as k}from"./EmptyState-DBHsSu6q.js";import"./vendor-react-DP6BW_9B.js";import"./vendor-utils-ui5PHgZB.js";import"./vendor-zustand-CVDiRiMG.js";import"./vendor-form-BQNAly2Z.js";const C={cash:"💵 Cash",bank_transfer:"🏦 Bank transfer",upi:"📲 UPI",other:"🔄 Other"};function b({settlement:s}){const n=h(l=>l.user),a=j(),t=g(),r=s.payer.id===(n==null?void 0:n.id),c=s.payee.id===(n==null?void 0:n.id);async function i(){await t({title:"Confirm payment received?",message:`Mark ${m(s.amount,s.currency)} from ${s.payer.name} as received.`,confirmLabel:"Confirm received",variant:"primary"})&&a.mutate(s.id)}return e.jsxs("div",{className:x("card p-4 space-y-3",!s.isConfirmed&&c&&"ring-1 ring-warning/30"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(N,{name:r?s.payee.name:s.payer.name,src:r?s.payee.avatarUrl:s.payer.avatarUrl,size:"sm"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-ink",children:r?e.jsxs(e.Fragment,{children:["You → ",e.jsx("span",{className:"text-ink",children:s.payee.name})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-ink",children:s.payer.name})," → You"]})}),e.jsxs("p",{className:"text-xs text-ink-muted mt-0.5",children:[s.settledAt?o(s.settledAt):o(s.createdAt),s.groupId&&" · group"]})]})]}),e.jsxs("div",{className:"text-right flex-shrink-0",children:[e.jsxs("p",{className:`text-base font-bold ${r?"text-danger":"text-success"}`,children:[r?"-":"+",m(s.amount,s.currency)]}),e.jsx("p",{className:"text-xs text-ink-muted mt-0.5",children:C[s.method]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(v,{variant:s.isConfirmed?"success":"warning",size:"sm",children:s.isConfirmed?"✓ Confirmed":"Pending confirmation"}),!s.isConfirmed&&c&&e.jsx(y,{size:"sm",variant:"secondary",loading:a.isPending,onClick:i,children:"Confirm received"})]}),s.notes&&e.jsx("p",{className:"text-xs text-ink-muted border-t border-bg-overlay pt-2",children:s.notes})]})}function w(){return e.jsxs("div",{className:"card p-4 space-y-3 animate-pulse",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(d,{className:"h-8 w-8 rounded-full flex-shrink-0"}),e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsx(d,{className:"h-3.5 w-2/3"}),e.jsx(d,{className:"h-3 w-1/3"})]}),e.jsx(d,{className:"h-5 w-20"})]}),e.jsx(d,{className:"h-6 w-32 rounded-full"})]})}function S({active:s,onChange:n}){const a=[{key:"all",label:"All"},{key:"pending",label:"Pending"},{key:"confirmed",label:"Confirmed"}];return e.jsx("div",{className:"flex gap-1 rounded-xl bg-bg-elevated p-1 w-fit",children:a.map(({key:t,label:r})=>e.jsx("button",{onClick:()=>n(t),className:x("rounded-lg px-4 py-2 text-xs font-medium transition-all",s===t?"bg-primary text-ink shadow-soft":"text-ink-muted hover:text-ink"),children:r},t))})}function M(){const[s,n]=p.useState("all"),{data:a,isLoading:t}=u(),r=((a==null?void 0:a.data)??[]).filter(i=>s==="pending"?!i.isConfirmed:s==="confirmed"?i.isConfirmed:!0),c=(a==null?void 0:a.data.filter(i=>!i.isConfirmed).length)??0;return e.jsxs("div",{className:"flex flex-col",children:[e.jsx(f,{title:"Payments",subtitle:"Your settlement history"}),e.jsxs("div",{className:"mx-auto w-full max-w-2xl space-y-5 p-4 lg:p-6 animate-fade-in",children:[!t&&a&&e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"card p-3 text-center",children:[e.jsx("p",{className:"text-xl font-bold text-ink",children:a.total}),e.jsx("p",{className:"text-xs text-ink-muted",children:"Total"})]}),e.jsxs("div",{className:"card p-3 text-center",children:[e.jsx("p",{className:"text-xl font-bold text-warning",children:c}),e.jsx("p",{className:"text-xs text-ink-muted",children:"Pending"})]}),e.jsxs("div",{className:"card p-3 text-center",children:[e.jsx("p",{className:"text-xl font-bold text-success",children:a.total-c}),e.jsx("p",{className:"text-xs text-ink-muted",children:"Confirmed"})]})]}),e.jsx(S,{active:s,onChange:n}),t?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(i=>e.jsx(w,{},i))}):r.length===0?e.jsx(k,{icon:"💸",title:s==="pending"?"No pending payments":"No payments yet",description:s==="pending"?"All payments have been confirmed.":"Payments will appear here once you record or receive them."}):e.jsx("div",{className:"space-y-3",children:r.map(i=>e.jsx(b,{settlement:i},i.id))})]})]})}export{M as default};
