import{r as e,j as r}from"./router.chunk.YsRm4bSN.js";import{_ as __,s as sprintf}from"./wordpress.chunk.BVds2GcU.js";import{f as s,D as a,bD as t,L as o,N as n,aC as d,aB as c,aD as i,i as m,K as u,T as p,c3 as h,b4 as l,C as f}from"./main.chunk.N-eZ2ybB.js";import{u as g,k as j}from"./forms.chunk.Bz8aaTWe.js";import{D as k}from"./date-picker-field.chunk.ipSHuuNj.js";import{p as w,a as x}from"./index.chunk.CJx-PkC0.js";import{S as _}from"./empty-search.chunk.LcW09zII.js";import{S as y}from"./pledge.chunk.B0oa2IzN.js";import{P as v}from"./paginator.chunk.r-wRTa3n.js";import{a as D,P}from"./pledge-item.chunk.CMZBxnL9.js";import{u as N}from"./pledges.chunk.yVsVXHqt.js";import{u as b}from"./use-form-query-sync.chunk.DqmzEVyi.js";import{m as E}from"./match-paginated-query-status.chunk.78H-Yncx.js";import{f as S}from"./date-utils.chunk.DWRtWTmT.js";import{f as L}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"./dot-separator.chunk.CtyhSI2x.js";import"./separator.chunk.3HcpyIlz.js";import"./gift-pack.chunk.Bu6GqqlM.js";import"./payment-status-badge.chunk.ef6EtFKR.js";import"./pdf-pledge-without-reward-content.chunk.BqaTTSZo.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"./reward-item.chunk.DG317vVb.js";import"./use-currency.chunk.QE--bLc6.js";const T=({onLoadData:u})=>{const{currentUser:p,isFundraiser:h}=s(),l=g(),{syncQueryParams:f,params:j}=b({keyMap:{pg:x.withDefault(1),search:w,start_date:w,end_date:w},form:l,paramsToForm:e=>({search:e.search??"",date_range:{from:e.start_date?new Date(e.start_date):void 0,to:e.end_date?new Date(e.end_date):void 0}}),formToParams:e=>({search:e.search,start_date:e.date_range?.from?S(e.date_range.from,a.DATE):void 0,end_date:e.date_range?.to?S(e.date_range.to,a.DATE):void 0}),watchFields:["search","date_range"]}),k=N({page:j.pg,search:j.search??void 0,start_date:j.start_date??void 0,end_date:j.end_date??void 0,user_id:h?p.id:void 0,per_page:t.BACKER_PLEDGES});return e.useEffect(()=>{u(k.data?.total??0)},[k.data?.total,u]),E(k,{Loading:r.jsx("div",{className:"growfund-space-y-4",children:Array.from({length:5}).map((e,s)=>r.jsx(D,{},s))}),Error:r.jsxs(d,{children:[r.jsx(c,{}),r.jsx(i,{children:__("Error loading pledges","growfund")})]}),Empty:r.jsxs(o,{children:[r.jsx(y,{}),r.jsx(n,{children:__("No pledges made yet","growfund")})]}),EmptyResult:r.jsxs(o,{children:[r.jsx(_,{}),r.jsx(n,{children:__("No matching results found.","growfund")})]}),Success:({data:e},s)=>m(s)?s:r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"growfund-space-y-3",children:e.results.map(e=>r.jsx(P,{pledge:e},e.id))}),r.jsx("div",{className:"growfund-mt-3",children:r.jsx(v,{totalItems:e.total,currentPage:e.current_page,itemsPerPage:e.per_page,onPageChange:e=>{f({pg:e})}})})]})})},A=()=>{const[s,a]=e.useState(0),t=j();return r.jsxs(u,{...t,children:[r.jsxs("div",{className:"growfund-flex growfund-items-center growfund-justify-between growfund-mb-3",children:[r.jsxs("div",{className:"growfund-flex growfund-items-center growfund-gap-1",children:[r.jsx("h5",{className:"growfund-typo-h5 growfund-font-bold",children:__("All Pledges","growfund")}),r.jsx("h6",{className:"growfund-typo-h6 growfund-font-bold",children:sprintf("(%s)",s)})]}),r.jsxs("div",{className:"growfund-max-w-[25rem] growfund-flex growfund-items-center growfund-gap-2",children:[r.jsx(p,{control:t.control,name:"search",type:"search",placeholder:__("Search...","growfund")}),r.jsx(k,{control:t.control,name:"date_range",type:"range",placeholder:__("Select Date","growfund"),showRangePresets:!0,clearable:!0})]})]}),r.jsx(T,{onLoadData:a})]})},C=()=>{const{setTopbar:s}=h();return e.useEffect(()=>{s({title:__("Pledges","growfund"),icon:L})},[s]),l.isBacker()?r.jsx(f,{className:"growfund-mt-10",size:"sm",children:r.jsx(A,{})}):r.jsx("div",{children:__("You are not allowed to access this page.","growfund")})};export{C as default};
