import{r as a,j as s}from"./router.chunk.YsRm4bSN.js";import{_ as __,s as sprintf}from"./wordpress.chunk.BVds2GcU.js";import{f as e,D as r,bD as t,L as o,N as n,aC as d,aB as c,aD as u,az as i,i as l,K as m,T as p,c3 as f,C as g}from"./main.chunk.N-eZ2ybB.js";import{u as h,k as j}from"./forms.chunk.Bz8aaTWe.js";import{D as k}from"./date-picker-field.chunk.ipSHuuNj.js";import{S as w}from"./select-field.chunk.BsBigbOV.js";import{p as x,a as v}from"./index.chunk.CJx-PkC0.js";import{S as _}from"./empty-search.chunk.LcW09zII.js";import{S as y}from"./donation.chunk.D76CvJSa.js";import{P as D}from"./paginator.chunk.r-wRTa3n.js";import{D as N}from"./donation-card.chunk.DTR4BsYX.js";import{a as b}from"./donation.chunk.DRbTglja.js";import{c as P}from"./donations.chunk.DoAX5D3m.js";import{u as E}from"./use-form-query-sync.chunk.DqmzEVyi.js";import{m as S}from"./match-paginated-query-status.chunk.78H-Yncx.js";import{f as T}from"./date-utils.chunk.DWRtWTmT.js";import{f as C}from"./icons.chunk.BwnSC3zE.js";import"./react-jsx-runtime.chunk.ATkk6v2S.js";import"./react.js";import"./react-dom-client.chunk.BMQ1litG.js";import"./react-dom.js";import"./pdf-core.chunk.D33I_Wdh.js";import"./ui-radix.chunk.Xzokq_Gv.js";import"./utils.chunk.C1IATKsN.js";import"./select.chunk.BdL8rppi.js";import"./payment-status-badge.chunk.ef6EtFKR.js";import"./pdf-donation-content.chunk.CK5AzyNy.js";import"./pdf-context.chunk.DXMR6h2w.js";import"./pdf-receipt-document.chunk.BnWw5Zlc.js";import"./pdf-signature.chunk.IQZSL9sf.js";import"./pdf-html.chunk.CXZoRVhj.js";import"./option-keys.chunk.CTqS8AT8.js";import"./use-currency.chunk.QE--bLc6.js";import"./campaign.chunk.BU0ryCmb.js";import"./user.chunk.pqINMGd0.js";import"./settings.chunk.D9nMP-Um.js";import"./pledge.chunk.Dci8K-_V.js";import"./reward.chunk.BtCj3Ub4.js";const A=({onLoadData:m})=>{const{currentUser:p,isFundraiser:f}=e(),g=h(),{syncQueryParams:j,params:k}=E({keyMap:{pg:v.withDefault(1),search:x,status:x,start_date:x,end_date:x},form:g,paramsToForm:a=>({page:a.pg,search:a.search??void 0,status:a.status??void 0,date_range:{from:a.start_date?new Date(a.start_date):void 0,to:a.end_date?new Date(a.end_date):void 0}}),formToParams:a=>({search:a.search||null,status:a.status||null,start_date:a.date_range?.from?T(a.date_range.from,r.DATE):void 0,end_date:a.date_range?.to?T(a.date_range.to,r.DATE):void 0}),watchFields:["search","date_range","status"]}),w=P({page:k.pg,per_page:t.DONOR_DONATIONS,search:k.search??void 0,status:b.safeParse(k.status).data??void 0,start_date:k.start_date??void 0,end_date:k.end_date??void 0,user_id:f?p.id:void 0});return a.useEffect(()=>{m({total:w.data?.total??0,overall:w.data?.overall??0})},[w.data?.total,w.data?.overall,m]),S(w,{Loading:s.jsx(i,{}),Error:s.jsxs(d,{className:"growfund-px-0",children:[s.jsx(c,{}),s.jsx(u,{children:__("Error loading donations","growfund")})]}),Empty:s.jsxs(o,{className:"growfund-px-0",children:[s.jsx(y,{}),s.jsx(n,{children:__("No donations made yet.","growfund")})]}),EmptyResult:s.jsxs(o,{className:"growfund-px-0",children:[s.jsx(_,{}),s.jsx(n,{children:__("No matching results found.","growfund")})]}),Success:({data:a},e)=>l(e)?e:s.jsxs("div",{className:"growfund-mt-4 growfund-space-y-3",children:[s.jsx("div",{className:"growfund-space-y-4",children:a.results.map(a=>s.jsx(N,{donation:a},a.id))}),s.jsx(D,{totalItems:a.total,onPageChange:a=>{j({pg:a})},currentPage:a.current_page,itemsPerPage:a.per_page})]})})},F=()=>{const[e,r]=a.useState({total:0,overall:0}),t=j();return s.jsxs(m,{...t,children:[e.overall>0&&s.jsxs("div",{className:"growfund-flex growfund-items-center growfund-justify-between",children:[s.jsx("h4",{className:"growfund-typo-h5 growfund-font-semibold growfund-text-primary",children:sprintf(__("Donations (%d)","growfund"),e.total)}),s.jsxs("div",{className:"growfund-flex growfund-items-center growfund-gap-2",children:[s.jsx(p,{className:"growfund-bg-background-surface",control:t.control,type:"search",name:"search",placeholder:__("Search...","growfund")}),s.jsx(w,{control:t.control,className:"growfund-bg-background-fill growfund-rounded-md",name:"status",placeholder:__("All Donations","growfund"),options:[{value:"all",label:__("All Donations","growfund")},{value:"pending",label:__("Pending","growfund")},{value:"completed",label:__("Completed","growfund")},{value:"cancelled",label:__("Cancelled","growfund")},{value:"failed",label:__("Failed","growfund")}]}),s.jsx(k,{control:t.control,name:"date_range",placeholder:__("Pick a Date","growfund"),type:"range",showRangePresets:!0,clearable:!0})]})]}),s.jsx(A,{onLoadData:r})]})},L=()=>{const{setTopbar:e}=f();return a.useEffect(()=>{e({title:__("Donations","growfund"),icon:C})},[e]),s.jsx(g,{className:"growfund-mt-10 growfund-space-y-3",size:"sm",children:s.jsx(F,{})})};export{L as default};
