import{f as s,d as r,c as a,k as e,r as o,j as n}from"./router.chunk.YsRm4bSN.js";import{_ as __,s as sprintf}from"./wordpress.chunk.BVds2GcU.js";import{p as t,a as c}from"./index.chunk.CJx-PkC0.js";import{u as m,k as u}from"./forms.chunk.Bz8aaTWe.js";import{w as i,bj as d,aw as p,ax as l,L as h,N as f,aC as g,aB as j,aD as k,bD as w,i as x,c3 as y,f as v,C as _,K as N,T as b}from"./main.chunk.N-eZ2ybB.js";import{S as B}from"./empty-search.chunk.LcW09zII.js";import{S}from"./campaign.chunk.Bl3EV_wc.js";import{C as K}from"./campaign-card.chunk._yjiAIk3.js";import{P as E}from"./paginator.chunk.r-wRTa3n.js";import{C as P}from"./campaign-card-skeleton.chunk.DVSpHftA.js";import{u as q}from"./use-form-query-sync.chunk.DqmzEVyi.js";import{m as O}from"./match-paginated-query-status.chunk.78H-Yncx.js";import{u as D}from"./use-query-params-states.chunk.Cr14Tyhz.js";import{h as R}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"./date-utils.chunk.DWRtWTmT.js";import"./dot-separator.chunk.CtyhSI2x.js";import"./progress.chunk.Bl335FuN.js";import"./goal-info.chunk.5sJIIQ8N.js";import"./use-currency.chunk.QE--bLc6.js";import"./select.chunk.BdL8rppi.js";const C=s=>a({queryKey:["Bookmarks",s],enabled:!!s.user_id,queryFn:()=>(d(s.user_id,"user_id is required"),(s=>p.get(l.BOOKMARKS,{params:s}).then(s=>s.data))(s)),placeholderData:e}),F=({user_id:s,campaign_id:r})=>p.post(l.BOOKMARKS,{user_id:s,campaign_id:r}),A=({onLoadData:a,userId:e})=>{const u=m(),{syncQueryParams:d,params:p}=q({keyMap:{pg:c.withDefault(1),search:t},form:u,paramsToForm:s=>({page:s.pg,search:s.search??void 0}),formToParams:s=>({search:s.search??null}),watchFields:["search"]}),l=(()=>{const a=s();return r({mutationFn:F,onSuccess:()=>{i.success("Bookmark removed successfully"),a.invalidateQueries({queryKey:["Bookmarks"]})},onError:s=>{i.error(s.message)}})})(),y=C({user_id:e,page:p.pg,search:p.search??void 0,per_page:w.USER_BOOKMARKS});return o.useEffect(()=>{a({total:y.data?.total??0,overall:y.data?.overall??0})},[y.data?.total,y.data?.overall,a]),O(y,{Loading:n.jsx("div",{className:"growfund-space-y-3",children:Array.from({length:5}).map((s,r)=>n.jsx(P,{},r))}),Error:n.jsxs(g,{children:[n.jsx(j,{}),n.jsx(k,{children:__("Error loading campaigns","growfund")})]}),Empty:n.jsxs(h,{children:[n.jsx(S,{}),n.jsx(f,{children:__("No campaigns bookmarked yet","growfund")})]}),EmptyResult:n.jsxs(h,{children:[n.jsx(B,{}),n.jsx(f,{children:__("No matching results found.","growfund")})]}),Success:({data:s},r)=>x(r)?r:n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"growfund-space-y-3",children:s.results.map(s=>n.jsx(K,{campaign:s,className:"growfund-border-none growfund-shadow-none",mode:"bookmark",onRemoveBookmark:()=>{e&&s.id&&l.mutate({user_id:e,campaign_id:s.id})}},s.id))}),n.jsx(E,{currentPage:s.current_page,totalItems:s.total,itemsPerPage:s.per_page,onPageChange:s=>{d({pg:s})}})]})})},I=()=>{const{setTopbar:s}=y(),{currentUser:r}=v(),[a,e]=o.useState({overall:0,total:0}),{params:c}=D({search:t}),m=u({defaultValues:{search:c.search??void 0}});return o.useEffect(()=>{s({title:__("Bookmarks","growfund"),icon:R})},[s]),n.jsx(_,{className:"growfund-mt-10 growfund-space-y-3",size:"sm",children:n.jsxs(N,{...m,children:[a.overall>0&&n.jsxs("div",{className:"growfund-flex growfund-items-center growfund-justify-between",children:[n.jsxs("div",{className:"growfund-flex growfund-items-center growfund-gap-2 growfund-text-fg-primary",children:[n.jsx("h5",{className:"growfund-typo-h5 growfund-font-semibold",children:__("Bookmarks","growfund")}),n.jsx("h6",{className:"growfund-typo-h6 growfund-font-regular",children:sprintf("(%s)",a.total)})]}),n.jsx("div",{className:"growfund-max-w-[25rem] growfund-flex growfund-items-center growfund-gap-2",children:n.jsx(b,{control:m.control,name:"search",type:"search",placeholder:__("Search...","growfund")})})]}),n.jsx(A,{onLoadData:e,userId:r.id})]})})};export{I as default};
