1import{r,u as S,w as _,s as d,j as e,L as k,A as C,M as J,I as q,B as g,C as E,f as B,U as I}from"./index-CZOkqSXl.js";import{u as L}from"./use-auth-jGP3eZah.js";import{B as c}from"./badge-aja6yD2P.js";import{S as j}from"./search-DBDJAcUI.js";const F=()=>{const{user:t,loading:o}=L("volunteer"),[n,N]=r.useState(""),[m,v]=r.useState([]),[i,u]=r.useState(!1),[b,x]=r.useState(new Set),[h,f]=r.useState(null);S();const{toast:p}=_();r.useEffect(()=>{t&&d.from("campaign_volunteers").select("campaign_id").eq("volunteer_id",t.id).eq("status","active").then(({data:s})=>{x(new Set((s??[]).map(a=>a.campaign_id)))})},[t]);const l=async()=>{u(!0);let s=d.from("campaigns").select("id, name, party, district, location_name").eq("is_public",!0).limit(20);n.trim()&&(s=s.ilike("name",`%${n.trim()}%`));const{data:a}=await s.order("created_at",{ascending:!1});v(a??[]),u(!1)};r.useEffect(()=>{t&&l()},[t]);const y=async s=>{if(!t)return;f(s);const{error:a}=await d.from("campaign_volunteers").insert({campaign_id:s,volunteer_id:t.id});f(null),a?p({variant:"destructive",title:"Failed to join",description:a.message}):(x(w=>new Set([...w,s])),p({title:"Joined campaign!"}))};return o&&o?null:e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"sticky top-0 z-40 border-b border-border/50 bg-background/80 backdrop-blur-lg",children:e.jsxs("div",{className:"container flex h-14 items-center gap-3",children:[e.jsx(k,{to:"/dashboard/volunteer",className:"text-muted-foreground hover:text-foreground",children:e.jsx(C,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-primary",children:e.jsx(J,{className:"h-4 w-4 text-primary-foreground"})}),e.jsx("span",{className:"font-display text-lg font-bold",children:"Find Campaigns"})]})}),e.jsxs("main",{className:"container max-w-2xl py-8",children:[e.jsxs("div",{className:"mb-6 flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(j,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(q,{placeholder:"Search by campaign name...",value:n,onChange:s=>N(s.target.value),onKeyDown:s=>s.key==="Enter"&&l(),className:"pl-9"})]}),e.jsx(g,{onClick:l,disabled:i,children:i?"Searching...":"Search"})]}),m.length===0&&!i?e.jsxs("div",{className:"flex flex-col items-center py-16 text-center",children:[e.jsx(j,{className:"mb-4 h-10 w-10 text-muted-foreground/40"}),e.jsx("p",{className:"text-muted-foreground",children:"No campaigns found. Try a different search."})]}):e.jsx("div",{className:"space-y-3",children:m.map(s=>{const a=b.has(s.id);return e.jsx(E,{className:"border-border/50",children:e.jsxs(B,{className:"flex items-center gap-4 p-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10",children:e.jsx(I,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate font-display font-semibold",children:s.name}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[s.party&&e.jsx(c,{variant:"secondary",className:"text-[10px]",children:s.party}),s.district&&e.jsx(c,{variant:"outline",className:"text-[10px]",children:s.district}),s.location_name&&e.jsx("span",{children:s.location_name})]})]}),a?e.jsx(c,{variant:"secondary",children:"Joined"}):e.jsx(g,{size:"sm",onClick:()=>y(s.id),disabled:h===s.id,children:h===s.id?"Joining...":"Join"})]})},s.id)})})]})]})};export{F as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.