import{f as u,a as x,j as e}from"./vendor-query-Brcc40-Y.js";import{T as f,S as m}from"./Skeleton-DGpeJz1z.js";import{T as p,B as h,U as b,A as y,p as j}from"./index-tN-ddyeb.js";import{E as v}from"./EmptyState-DBHsSu6q.js";import{p as N,i as A,d as k,f as E}from"./vendor-utils-ui5PHgZB.js";import"./vendor-react-DP6BW_9B.js";import"./vendor-zustand-CVDiRiMG.js";import"./vendor-form-BQNAly2Z.js";const w={getGlobal:t=>p.get("/activity",{params:t}).then(s=>s.data),getByGroup:(t,s)=>p.get(`/groups/${t}/activity`,{params:s}).then(n=>n.data)},P=20;function S(){return u({queryKey:["activity","global"],queryFn:({pageParam:t=1})=>w.getGlobal({page:t,limit:P}),getNextPageParam:t=>t.hasNextPage?t.page+1:void 0,initialPageParam:1,staleTime:3e4})}const T={expense_added:{icon:"🧾",bg:"bg-primary-subtle"},expense_updated:{icon:"✏️",bg:"bg-bg-overlay"},expense_deleted:{icon:"🗑️",bg:"bg-danger-subtle"},settlement_recorded:{icon:"💸",bg:"bg-success-subtle"},member_joined:{icon:"👋",bg:"bg-primary-subtle"},member_left:{icon:"👈",bg:"bg-bg-overlay"}};function I({log:t}){const s=T[t.action]??{icon:"📌",bg:"bg-bg-overlay"},n=b[t.action]??t.action,i=t.metadata,r=(i==null?void 0:i.description)??(i==null?void 0:i.amount)??null;return e.jsxs("div",{className:"flex items-start gap-3 py-3",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx(y,{name:t.actor.name,src:t.actor.avatarUrl,size:"sm"}),e.jsx("span",{className:`absolute -bottom-1 -right-1 flex h-5 w-5 items-center justify-center rounded-full text-[10px] ${s.bg} ring-2 ring-bg-surface`,children:s.icon})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-sm text-ink leading-snug",children:[e.jsx("span",{className:"font-semibold text-ink",children:t.actor.name})," ",n,t.groupName&&e.jsxs(e.Fragment,{children:[" in ",e.jsx("span",{className:"font-medium text-ink",children:t.groupName})]})]}),r&&e.jsx("p",{className:"text-xs text-ink-muted mt-0.5 truncate",children:typeof r=="number"?String(r):r}),e.jsx("p",{className:"text-xs text-ink-faint mt-1",children:j(t.createdAt)})]})]})}function _(t){const s=N(t);return A(s)?"Today":k(s)?"Yesterday":E(s,"EEEE, MMM d")}function L(){return e.jsx("div",{className:"space-y-4",children:[1,2,3,4,5].map(t=>e.jsxs("div",{className:"flex items-start gap-3 animate-pulse",children:[e.jsx(m,{className:"h-8 w-8 rounded-full flex-shrink-0"}),e.jsxs("div",{className:"flex-1 space-y-1.5 pt-0.5",children:[e.jsx(m,{className:"h-3.5 w-3/4"}),e.jsx(m,{className:"h-3 w-1/2"}),e.jsx(m,{className:"h-3 w-20"})]})]},t))})}function z(){const{data:t,isLoading:s,hasNextPage:n,fetchNextPage:i,isFetchingNextPage:r}=S(),l=x.useMemo(()=>(t==null?void 0:t.pages.flatMap(a=>a.data))??[],[t]),g=x.useMemo(()=>{const a=[];let o="";for(const c of l){const d=c.createdAt.substring(0,10);d!==o&&(a.push({label:_(c.createdAt),items:[]}),o=d),a[a.length-1].items.push(c)}return a},[l]);return e.jsxs("div",{className:"flex flex-col",children:[e.jsx(f,{title:"Activity",subtitle:"Everything happening across your groups"}),e.jsx("div",{className:"mx-auto w-full max-w-2xl space-y-6 p-4 lg:p-6 animate-fade-in",children:s?e.jsx(L,{}):l.length===0?e.jsx(v,{icon:"⚡",title:"No activity yet",description:"Expenses, settlements, and member events will appear here."}):e.jsxs(e.Fragment,{children:[g.map(({label:a,items:o})=>e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"text-xs font-semibold text-ink-muted uppercase tracking-wider",children:a}),e.jsx("div",{className:"flex-1 h-px bg-bg-elevated"})]}),e.jsx("div",{className:"card px-4 divide-y divide-bg-overlay",children:o.map(c=>e.jsx(I,{log:c},c.id))})]},a)),n&&e.jsx("div",{className:"flex justify-center",children:e.jsx(h,{variant:"secondary",size:"sm",loading:r,onClick:()=>i(),children:"Load more"})}),!n&&l.length>0&&e.jsx("p",{className:"text-center text-xs text-ink-faint pb-2",children:"You've reached the beginning"})]})})]})}export{z as default};
