import{r as e,j as n}from"./router.chunk.YsRm4bSN.js";import{_ as __}from"./wordpress.chunk.BVds2GcU.js";import{bD as r,c as s,aN as a,k as o,b as d,I as u,i as l,al as i,B as t,ak as f,am as g,F as c,a as w,p as m}from"./main.chunk.N-eZ2ybB.js";import{C as h}from"./campaign.chunk.BU0ryCmb.js";import{g as p}from"./campaign.chunk.DLkjF6XJ.js";import{u as x}from"./use-debounce.chunk.th480LZc.js";import{b as j,aP as b,x as v}from"./icons.chunk.BwnSC3zE.js";const N=e.createContext(null),C=()=>{const n=e.use(N);if(!n)throw new Error("useCampaignFieldContext must be used within a CampaignFieldProvider");return n},y=({children:s,field:a,fieldState:o,disabled:d=!1,...u})=>{const[l,i]=e.useState(!1),[t,f]=e.useState(""),g=x(t),c=p({page:1,search:g,per_page:r.CAMPAIGN_FIELD,status:[h.Values.published,h.Values.funded,h.Values.completed].join(",")}),w=e.useMemo(()=>c.data?.results?c.data.results:[],[c.data]),m=e.useMemo(()=>({search:t,setSearch:f,campaigns:w,open:l,onOpenChange:i,field:a,fieldState:o,disabled:d}),[t,w,l,a,o,d]);return n.jsx(N,{value:m,...u,children:s})},k=()=>{const{campaigns:e,field:r,onOpenChange:d}=C();return 0===e.length?n.jsx("div",{className:"growfund-flex growfund-items-center growfund-justify-center growfund-h-24 growfund-text-fg-secondary growfund-typo-small",children:n.jsx("p",{children:__("No campaigns found","growfund")})}):n.jsx("div",{className:"growfund-flex growfund-flex-col growfund-mt-3",children:e.map(e=>n.jsxs("div",{role:"button",tabIndex:0,onKeyDown:a,onClick:()=>{r.onChange(r.value===e.id?null:e.id),d(!1)},className:s("growfund-flex growfund-items-center growfund-cursor-pointer growfund-px-4 growfund-py-2 hover:growfund-bg-background-surface-secondary",r.value===e.id&&"growfund-text-fg-primary growfund-font-medium growfund-typo-small"),children:[n.jsxs("div",{className:"growfund-flex growfund-items-center growfund-gap-2 growfund-min-w-0",children:[n.jsx(o,{src:e.images?.[0]?.url??null,alt:e.title,className:"growfund-size-8 growfund-rounded-sm growfund-flex-shrink-0"}),n.jsx("span",{className:"growfund-truncate growfund-typo-small growfund-w-full",title:e.title,children:e.title})]}),n.jsx(j,{className:s("growfund-size-4 growfund-ml-auto growfund-shrink-0 growfund-transition-all",r.value===e.id?"growfund-opacity-100":"growfund-opacity-0")})]},e.id))})},S=()=>{const{search:e,setSearch:r}=C();return n.jsx("div",{className:"growfund-flex growfund-justify-between growfund-gap-3 growfund-px-4 growfund-pt-4",children:n.jsx(d,{children:n.jsx(u,{placeholder:__("Search for a campaign...","growfund"),type:"search",value:e,onChange:e=>{r(e.target.value)},autoFocus:!0})})})},F=({placeholder:e})=>{const{field:r,campaigns:a}=C(),o=a.find(e=>e.id===r.value),d=l(o)?o.title:e;return n.jsxs("div",{className:"growfund-flex growfund-items-center growfund-rounded-md focus-within:growfund-ring-2 focus-within:growfund-ring-ring focus-within:growfund-ring-offset-2",children:[n.jsx(i,{asChild:!0,children:n.jsxs(t,{variant:"outline",title:d,className:s("growfund-max-w-40 growfund-min-w-[12.5rem] growfund-justify-between growfund-pe-3 focus-visible:growfund-ring-0",l(o)&&"growfund-rounded-none growfund-rounded-tl-lg growfund-rounded-bl-lg"),children:[n.jsx("span",{className:"growfund-typo-small growfund-truncate",children:d}),n.jsx(b,{})]})}),l(o)&&n.jsx(t,{onClick:()=>{r.onChange(null)},variant:"outline",className:"growfund-rounded-none growfund-rounded-tr-lg growfund-rounded-br-lg growfund-border-l-0 focus-visible:growfund-ring-0",size:"icon",children:n.jsx(v,{})})]})},I=({placeholder:e})=>{const{open:r,onOpenChange:s}=C();return n.jsxs(f,{open:r,onOpenChange:s,children:[n.jsx(F,{placeholder:e}),n.jsx(g,{className:"growfund-p-0 growfund-w-96",align:"start",children:n.jsxs("div",{className:"growfund-space-y-3",children:[n.jsx(S,{}),n.jsx(k,{})]})})]})},O=({control:e,name:r,label:s,disabled:a=!1,placeholder:o=__("All Campaigns","growfund")})=>n.jsx(c,{control:e,name:r,render:({field:e,fieldState:r})=>n.jsx(y,{field:e,fieldState:r,disabled:a,children:n.jsxs(w,{className:"growfund-space-y-2",children:[l(s)&&n.jsx(m,{className:"growfund-flex-shrink-0",children:s}),n.jsx(I,{placeholder:o})]})})});export{O as C};
