1import{i as e}from"./rolldown-runtime-B1_YRrcp.js";import{d as a,m as t}from"./vendor-react-DA-w_tJi.js";import{Pn as s,gi as r,qt as n}from"./vendor-ui-C-SSe3t9.js";import{t as o}from"./button-CRUaFOpN.js";import{n as i}from"./client-DVp9qcvq.js";import{$ as c,F as l,I as m,M as d,N as h,R as u,_ as p,a as _,b as f,g as x,h as j,m as y,p as v,z as g}from"./index-Bvj_e81I.js";import{a as N,i as w,n as C,o as b,r as S,t as q}from"./table-DI35AT7t.js";import{t as $}from"./AdminLayout-DdU9AzmR.js";import{n as L,t as E}from"./toggle-group-CQa_K3mR.js";import{i as M}from"./csvExport-Bf9ynf_q.js";var I=e(t(),1),P=a(),R={coach:"Current Coach",previous_coach:"Previous Coach",referee:"Referee",volunteer:"Volunteer",board:"Board Member",coach_inquiry:"Coach Inquiry",referee_inquiry:"Referee Inquiry",contact_inquiry:"Contact Inquiry",registration_interest:"Registration (wants to help)"},k=/^(no|none|not at this time|n\/?a|no thanks?|nope)$/i;function D(){const[e,a]=(0,I.useState)(""),[t,D]=(0,I.useState)([]),[V,A]=(0,I.useState)(null),F=g(),{toast:H}=c(),{data:K=[],isLoading:O}=u({queryKey:["helper-master-list"],queryFn:async()=>{const[e,a,t,s,r,n]=await Promise.all([i.from("coaches").select("id,first_name,last_name,email,phone,role,status,notes,created_at"),i.from("officials").select("first_name,last_name,email,phone,certification,created_at"),i.from("volunteers").select("first_name,last_name,email,phone,interest,status,created_at"),i.from("board_members").select("name,title,created_at,board_member_contacts(email)"),i.from("form_submissions").select("form_type,name,email,phone,message,status,created_at").in("form_type",["coach","official","contact"]),i.from("registrations").select("parent_name,parent_email,parent_phone,interest_in_helping,created_at,player:player_id(season)")]),o=[];return(e.data||[]).forEach(e=>{const a=e.status&&"active"!==e.status;o.push({id:e.id,name:`${e.first_name} ${e.last_name}`.trim(),email:e.email||"",phone:e.phone||"",source:a?"previous_coach":"coach",role_or_interest:e.role||"",status:e.status||"",season:"",created_at:e.created_at,notes:e.notes||""})}),(a.data||[]).forEach(e=>o.push({name:`${e.first_name} ${e.last_name}`.trim(),email:e.email||"",phone:e.phone||"",source:"referee",role_or_interest:e.certification||"",status:"",season:"",created_at:e.created_at,notes:""})),(t.data||[]).forEach(e=>o.push({name:`${e.first_name} ${e.last_name}`.trim(),email:e.email||"",phone:e.phone||"",source:"volunteer",role_or_interest:e.interest||"",status:e.status||"",season:"",created_at:e.created_at,notes:""})),(s.data||[]).forEach(e=>o.push({name:e.name||"",email:e.board_member_contacts?.email||"",phone:"",source:"board",role_or_interest:e.title||"",status:"",season:"",created_at:e.created_at,notes:""})),(r.data||[]).forEach(e=>{const a="coach"===e.form_type?"coach_inquiry":"official"===e.form_type?"referee_inquiry":"contact_inquiry";o.push({name:e.name||"",email:e.email||"",phone:e.phone||"",source:a,role_or_interest:e.form_type,status:e.status||"",season:"",created_at:e.created_at,notes:e.message||""})}),(n.data||[]).forEach(e=>{const a=(e.interest_in_helping||"").trim();a&&!k.test(a)&&o.push({name:e.parent_name||"",email:e.parent_email||"",phone:e.parent_phone||"",source:"registration_interest",role_or_interest:a,status:"",season:e.player?.season||"",created_at:e.created_at,notes:""})}),function(e){const a=new Map;for(const t of e){const e=`${(t.email||"").toLowerCase().trim()}|${t.source}`,s=`${t.name.toLowerCase().trim()}|${t.phone}|${t.source}`,r=t.email?e:s;a.has(r)||a.set(r,t)}return Array.from(a.values())}(o).sort((e,a)=>(e.name||"").localeCompare(a.name||""))}}),z=(0,I.useMemo)(()=>{const a=e.toLowerCase().trim();return K.filter(e=>!(t.length&&!t.includes(e.source))&&(!a||e.name.toLowerCase().includes(a)||e.email.toLowerCase().includes(a)||e.phone.toLowerCase().includes(a)||e.role_or_interest.toLowerCase().includes(a)))},[K,e,t]),B=(0,I.useMemo)(()=>{const e={};return K.forEach(a=>e[a.source]=(e[a.source]||0)+1),e},[K]);return(0,P.jsx)($,{title:"Helper Master List",children:(0,P.jsxs)("div",{className:"space-y-6",children:[(0,P.jsxs)("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[(0,P.jsxs)("div",{children:[(0,P.jsxs)("h1",{className:"text-3xl font-bold flex items-center gap-2",children:[(0,P.jsx)(n,{className:"h-8 w-8"})," Helper Master List"]}),(0,P.jsx)("p",{className:"text-muted-foreground mt-1",children:"Every coach, previous coach, referee, volunteer, and inquiry â in one place."})]}),(0,P.jsxs)(o,{onClick:()=>{M(z.map(e=>({Name:e.name,Email:e.email,Phone:e.phone,Source:R[e.source],"Role / Interest":e.role_or_interest,Status:e.status,Season:e.season,Notes:e.notes,"Created At":e.created_at?new Date(e.created_at).toLocaleDateString():""}
1)),`helper-master-list-${(new Date).toISOString().slice(0,10)}`)},className:"gap-2",disabled:!z.length,children:[(0,P.jsx)(r,{className:"h-4 w-4"}),"Download CSV (",z.length,")"]})]}),(0,P.jsxs)(d,{children:[(0,P.jsx)(l,{children:(0,P.jsx)(m,{className:"text-lg",children:"Filter"})}),(0,P.jsxs)(h,{className:"space-y-4",children:[(0,P.jsxs)("div",{className:"relative",children:[(0,P.jsx)(s,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,P.jsx)(f,{placeholder:"Search name, email, phone, interest...",value:e,onChange:e=>a(e.target.value),className:"pl-9"})]}),(0,P.jsx)(E,{type:"multiple",value:t,onValueChange:e=>D(e),className:"flex-wrap justify-start",children:Object.keys(R).map(e=>(0,P.jsxs)(L,{value:e,className:"gap-2",children:[R[e],(0,P.jsx)(_,{variant:"secondary",children:B[e]||0})]},e))})]})]}),(0,P.jsx)(d,{children:(0,P.jsx)(h,{className:"p-0",children:(0,P.jsxs)(q,{children:[(0,P.jsx)(N,{children:(0,P.jsxs)(b,{children:[(0,P.jsx)(w,{children:"Name"}),(0,P.jsx)(w,{children:"Email"}),(0,P.jsx)(w,{children:"Phone"}),(0,P.jsx)(w,{children:"Source"}),(0,P.jsx)(w,{children:"Role / Interest"}),(0,P.jsx)(w,{children:"Season"}),(0,P.jsx)(w,{children:"Change Status"})]})}),(0,P.jsx)(C,{children:O?(0,P.jsx)(b,{children:(0,P.jsx)(S,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"Loading..."})}):0===z.length?(0,P.jsx)(b,{children:(0,P.jsx)(S,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"No matching entries"})}):z.map((e,a)=>(0,P.jsxs)(b,{children:[(0,P.jsx)(S,{className:"font-medium",children:e.name}),(0,P.jsx)(S,{children:e.email}),(0,P.jsx)(S,{children:e.phone}),(0,P.jsx)(S,{children:(0,P.jsx)(_,{variant:"outline",children:R[e.source]})}),(0,P.jsx)(S,{className:"max-w-xs truncate",title:e.role_or_interest,children:e.role_or_interest}),(0,P.jsx)(S,{children:e.season}),(0,P.jsx)(S,{children:!e.id||"coach"!==e.source&&"previous_coach"!==e.source?(0,P.jsx)("span",{className:"text-muted-foreground text-xs",children:"â"}):(0,P.jsxs)(v,{value:"coach"===e.source?"active":"previous",disabled:V===e.id,onValueChange:a=>(async(e,a)=>{A(e);try{const{error:t}=await i.from("coaches").update({status:a}).eq("id",e);if(t)throw t;H({title:"Status updated",description:"active"===a?"Marked as a current coach.":"Marked as a previous coach."}),await F.invalidateQueries({queryKey:["helper-master-list"]})}catch(t){H({title:"Could not update",description:t.message||"Please try again.",variant:"destructive"})}finally{A(null)}})(e.id,a),children:[(0,P.jsx)(x,{className:"w-[170px]",children:(0,P.jsx)(p,{})}),(0,P.jsxs)(y,{children:[(0,P.jsx)(j,{value:"active",children:"Current Coach"}),(0,P.jsx)(j,{value:"previous",children:"Previous Coach"})]})]})})]},a))})]})})})]})})}export{D as default}; 2//# sourceMappingURL=HelperMasterList-BI8NSZCE.js.map
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.