import{j as e}from"./vendor-query-Brcc40-Y.js";import{L as u}from"./vendor-react-DP6BW_9B.js";import{T as p,S as o}from"./Skeleton-DGpeJz1z.js";import{l as h,q as m,m as d,B as j,f,n as c,i as x}from"./index-tN-ddyeb.js";import{E as g}from"./EmptyState-DBHsSu6q.js";import"./vendor-utils-ui5PHgZB.js";import"./vendor-zustand-CVDiRiMG.js";import"./vendor-form-BQNAly2Z.js";function N({group:s,balance:a}){const r=(a==null?void 0:a.net)??0,n=!a||r===0,l=r>0;return e.jsxs(u,{to:`/groups/${s.id}`,className:"card p-4 hover:bg-bg-elevated transition-all duration-150 group flex items-center gap-3.5",children:[e.jsx("div",{className:"h-12 w-12 flex-shrink-0 rounded-2xl bg-primary-subtle flex items-center justify-center text-xl font-bold text-primary ring-1 ring-primary/20 overflow-hidden",children:s.imageUrl?e.jsx("img",{src:s.imageUrl,alt:s.name,className:"h-full w-full object-cover"}):s.name[0]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold text-ink truncate",children:s.name}),s.description&&e.jsx("p",{className:"text-xs text-ink-muted mt-0.5 truncate",children:s.description}),e.jsxs("p",{className:"text-[11px] text-ink-faint mt-0.5",children:[s.memberCount," ",s.memberCount===1?"member":"members"]})]}),e.jsx("div",{className:"flex-shrink-0 text-right",children:n?e.jsx("p",{className:"text-sm font-medium text-ink-faint",children:"Settled"}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:x("text-sm font-semibold tabular-nums",l?"text-success":"text-danger"),children:[l?"+":"",c(Math.abs(r),s.currency)]}),e.jsx("p",{className:"text-[11px] text-ink-muted mt-0.5",children:l?"owed to you":"you owe"})]})}),e.jsx("svg",{className:"h-4 w-4 text-ink-faint group-hover:text-ink-muted transition-colors flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]})}function v(){return e.jsxs("div",{className:"card p-4 flex items-center gap-3.5 animate-pulse",children:[e.jsx(o,{className:"h-12 w-12 rounded-2xl flex-shrink-0"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(o,{className:"h-4 w-1/2"}),e.jsx(o,{className:"h-3 w-1/3"})]}),e.jsx(o,{className:"h-4 w-16"})]})}function k(){const{data:s,isLoading:a}=d(),{data:r}=m(),n=f(i=>i.user),l=(n==null?void 0:n.currency)??"USD";if(a)return e.jsx("div",{className:"grid grid-cols-3 gap-2.5",children:[1,2,3].map(i=>e.jsx(o,{className:"h-[72px] rounded-2xl"},i))});const t=[{value:String((r==null?void 0:r.length)??0),label:"Groups",className:"text-ink"},{value:c((s==null?void 0:s.totalYouOwe)??0,l),label:"You owe",className:"text-danger"},{value:c((s==null?void 0:s.totalOwedToYou)??0,l),label:"Owed to you",className:"text-success"}];return e.jsx("div",{className:"grid grid-cols-3 gap-2.5",children:t.map(i=>e.jsxs("div",{className:"card px-2.5 py-3.5 text-center overflow-hidden",children:[e.jsx("p",{className:x("text-sm sm:text-lg font-bold tabular-nums leading-tight break-words",i.className),title:i.value,children:i.value}),e.jsx("p",{className:"text-[11px] sm:text-xs text-ink-muted mt-1.5 leading-tight",children:i.label})]},i.label))})}function B(){const s=h(t=>t.openModal),{data:a,isLoading:r}=m(),{data:n}=d(),l=new Map(((n==null?void 0:n.groupSummaries)??[]).map(t=>[t.groupId,t]));return e.jsxs("div",{className:"flex flex-col",children:[e.jsx(p,{title:"Groups",subtitle:"Manage shared expenses",actions:e.jsxs(j,{size:"sm",onClick:()=>s("add-group"),children:[e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M12 4v16m8-8H4"})}),"New group"]})}),e.jsxs("div",{className:"mx-auto w-full max-w-3xl space-y-6 p-4 lg:p-6 animate-fade-in",children:[e.jsx(k,{}),r?e.jsx("div",{className:"space-y-3",children:[1,2,3,4].map(t=>e.jsx(v,{},t))}):!a||a.length===0?e.jsx(g,{icon:"👥",title:"No groups yet",description:"Create a group to start splitting expenses with friends, roommates, or colleagues.",action:{label:"Create your first group",onClick:()=>s("add-group")}}):e.jsx("div",{className:"space-y-3",children:a.map(t=>e.jsx(N,{group:t,balance:l.get(t.id)},t.id))})]})]})}export{B as default};
