1import{c5 as Me,u as H,r,d as fe,e as O,j as e,H as Z,B as u,bm as de,S as he,x as F,aT as xe,a8 as ee,bN as Re,U as je,ag as Ne,T as ye,E as $e,F as Fe,G as ge,K as pe,f as q,g as Ce,h as be,i as z,P as Se,Q as D,O as V,ai as Oe,ap as De,aR as Ge,aS as Ve,aj as He,D as U,m as Y,n as K,o as B,aw as se,L as f,p as ae,q as ne,s as ie,t as le,v as T,I as A,c6 as Ae,a4 as oe,ax as Q,ae as Ie,C as we}from"./index-DKbmQBBZ.js";import{T as qe,a as ze,b as Ee,c as J,d as Ue,e as W}from"./table-Bz1kUzaw.js";import{S as Ye}from"./SectionErrorState-ay2GnsX_.js";import{U as ve}from"./upload-BiPYremC.js";import{L as Pe}from"./link-2-gy3d13pb.js";import{P as Ke}from"./pencil-DJDSTDvd.js";function ds(){const[,i]=Me("/my-team/:roleId"),l=i?.roleId?parseInt(i.roleId):null;H();const[c,x]=r.useState("roster"),[t,a]=r.useState(!1),[p,s]=r.useState(!1),[m,j]=r.useState(!1),[S,L]=r.useState(!1),[R,o]=r.useState(!1),[v,g]=r.useState(!1),[y,N]=r.useState([]),[P,I]=r.useState(null),[w,k]=r.useState(!1),{data:C,isLoading:n,error:E,refetch:ce,isFetching:h}=fe({queryKey:["/api/volleyball-roles",l,"team-dashboard"],queryFn:()=>fetch(`/api/volleyball-roles/${l}/team-dashboard`,{credentials:"include"}).then(d=>{if(!d.ok)throw new Error("Failed to load team dashboard");return d.json()}),enabled:!!l}),$=O({mutationFn:()=>D("POST",`/api/volleyball-roles/${l}/find-matches`),onSuccess:async d=>{const te=await d.json();if(te.suggestions.length===0){if(w)return}else N(te.suggestions),g(!0);k(!0)}});if(r.useEffect(()=>
1{C&&!w&&C.members.length>0&&(C.members.filter(te=>!te.connectedPersonId&&te.email).length>0?$.mutate():k(!0))},[C,w]),!l)return e.jsxs("div",{className:"p-6",children:[e.jsx("p",{children:"Invalid team."}),e.jsx(Z,{href:"/coach-portal",children:e.jsxs(u,{variant:"ghost","data-testid":"link-back-coach-portal",children:[e.jsx(de,{className:"h-4 w-4 mr-2"})," Back to Coach Portal"]})})]});if(n)return e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsx(he,{className:"h-8 w-64"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[1,2,3,4].map(d=>e.jsx(he,{className:"h-24"},d))}),e.jsx(he,{className:"h-96"})]});if(E)return e.jsxs("div",{className:"p-6 max-w-2xl mx-auto space-y-4",children:[e.jsx(Ye,{testId:"my-team-error",title:"Couldn't load this team",onRetry:()=>ce(),isRetrying:h}),e.jsx(Z,{href:"/coach-portal",children:e.jsxs(u,{variant:"ghost","data-testid":"link-back-coach-portal",children:[e.jsx(de,{className:"h-4 w-4 mr-2"})," Back to Coach Portal"]})})]});if(!C)return e.jsxs("div",{className:"p-6",children:[e.jsx("p",{children:"Team not found or access denied."}),e.jsx(Z,{href:"/coach-portal",children:e.jsxs(u,{variant:"ghost","data-testid":"link-back-coach-portal",children:[e.jsx(de,{className:"h-4 w-4 mr-2"})," Back to Coach Portal"]})})]});const{role:b,stats:M,members:G,recentEvents:_}=C,Le=b.teamOrProgram||b.organizationName||"My Team",ke=b.category==="SCHOOL_COACH"?b.schoolName||b.organizationName:b.clubName||b.organizationName,me=G.filter(d=>d.memberType==="PLAYER"),ue=G.filter(d=>d.memberType==="COACH"),re=G.filter(d=>d.connectionStatus==="CONNECTED"&&d.connectedPersonId);return e.jsxs("div",{className:"p-4 md:p-6 max-w-6xl mx-auto space-y-6",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(Z,{href:"/coach-portal",children:e.jsxs(u,{variant:"ghost",size:"sm","data-testid":"link-back-coach-portal",children:[e.jsx(de,{className:"h-4 w-4 mr-1"})," Coach Portal"]})})}),e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold","data-testid":"text-team-name",children:Le}),e.jsxs("p",{className:"text-muted-foreground","data-testid":"text-team-org",children:[ke,b.schoolLevel&&` · ${b.schoolLevel}`,b.clubAgeClass&&` · ${b.clubAgeClass}`,b.season&&` · ${b.season}`,b.roleStatus==="CURRENT"&&e.jsx(F,{variant:"secondary",className:"ml-2",children:"Active"})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(u,{size:"sm",onClick:()=>a(!0),"data-testid":"button-add-member",children:[e.jsx(xe,{className:"h-4 w-4 mr-1"})," Add Member"]}),e.jsxs(u,{size:"sm",variant:"outline",onClick:()=>s(!0),"data-testid":"button-import-csv",children:[e.jsx(ve,{className:"h-4 w-4 mr-1"})," Import CSV"]}),e.jsxs(u,{size:"sm",variant:"outline",onClick:()=>$.mutate(),disabled:$.isPending,"data-testid":"button-find-connections",children:[$.isPending?e.jsx(ee,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Pe,{className:"h-4 w-4 mr-1"}),"Find Connections"]}),e.jsxs(u,{size:"sm",variant:"outline",onClick:()=>o(!0),"data-testid":"button-team-announcement",children:[e.jsx(Re,{className:"h-4 w-4 mr-1"})," Announce"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(X,{icon:e.jsx(je,{className:"h-5 w-5"}),label:"Players",value:M.playerCount,testId:"stat-players"}),e.jsx(X,{icon:e.jsx(xe,{className:"h-5 w-5"}),label:"Connected Members",value:M.connectedCount,testId:"stat-connected"}),e.jsx(X,{icon:e.jsx(je,{className:"h-5 w-5"}),label:"Unconnected Members",value:M.totalMembers-M.connectedCount,testId:"stat-unconnected"}),e.jsx(X,{icon:e.jsx(Ne,{className:"h-5 w-5"}),label:"Events",value:M.eventCount,testId:"stat-events"}),e.jsx(X,{icon:e.jsx(ye,{className:"h-5 w-5"}),label:"Tournaments",value:M.tournamentsPlayed,testId:"stat-tournaments"}),e.jsx(X,{icon:e.jsx(ye,{className:"h-5 w-5"}),label:"Record",value:`${M.record.wins}W-${M.record.losses}L`,testId:"stat-record"})]}),e.jsxs($e,{value:c,onValueChange:x,children:[e.jsxs(Fe,{children:[e.jsxs(ge,{value:"roster","data-testid":"tab-roster",children:["Roster (",M.totalMembers,")"]}),e.jsx(ge,{value:"events","data-testid":"tab-events",children:"Event Log"}),re.length>0&&e.jsxs(ge,{value:"profiles","data-testid":"tab-profiles",children:["Connected (",re.length,")"]})]}),e.jsxs(pe,{value:"roster",className:"space-y-4",children:[me.length>0&&e.jsxs(q,{children:[e.jsx(Ce,{children:e.jsxs(be,{className:"text-lg",children:["Players (",me.length,")"]})}),e.jsx(z,{children:e.jsx(Te,{members:me,roleId:l,type:"player",onEdit:I})})]}),ue.length>0&&e.jsxs(q,{children:[e.jsx(Ce,{children:e.jsxs(be,{className:"text-lg",children:["Coaching Staff (",ue.length,")"]})}),e.jsx(z,{children:e.jsx(Te,{members:ue,roleId:l,type:"coach",onEdit:I})})]}),G.length===0&&e.jsx(q,{children:e.jsxs(z,{className:"py-12 text-center",children:[e.jsx(je,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"No roster members yet"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Add players and coaches to build your team roster."}),e.jsxs("div",{className:"flex gap-2 justify-center",children:[e.jsxs(u,{onClick:()=>a(!0),"data-testid":"button-add-first-member",children:[e.jsx(xe,{className:"h-4 w-4 mr-1"})," Add Member"]}),e.jsxs(u,{variant:"outline",onClick:()=>s(!0),"data-testid":"button-import-first-csv",children:[e.jsx(ve,{className:"h-4 w-4 mr-1"})," Import from CSV"]})]})]})})]}),e.jsxs(pe,{value:"events",className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-medium",children:"Team Events"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{size:"sm",variant:"outline",onClick:()=>L(!0),"data-testid":"button-tag-event",children:[e.jsx(Pe,{className:"h-4 w-4 mr-1"})," Tag Existing"]}),e.jsxs(u,{size:"sm",onClick:()=>j(!0),"data-testid":"button-add-event",children:[e.jsx(Se,{className:"h-4 w-4 mr-1"})," Add Event"]})]})]}),_.length>0?e.jsx("div",{className:"space-y-3",children:_.map(d=>e.jsx(q,{children:e.jsx(z,{className:"py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium","data-testid":`text-event-name-${d.id}`,children:d.eventName}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[new Date(d.startDate).toLocaleDateString(),d.opponentName&&` vs ${d.opponentName}`,d.venue&&` · ${d.venue}`]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{variant:"outline",className:"text-xs","data-testid":`badge-type-${d.id}`,children:{TOURNAMENT:"Tournament",PRACTICE:"Practice",LEAGUE_GAME:"League Game",SCRIMMAGE:"Scrimmage",GAME:"Game",FRIENDLY:"Friendly",CAMP:"Camp",TRYOUT:"Tryout",SCHOOL_GAME:"School Game",OTHER:"Other",EXHIBITION:"Exhibition",PLAYOFF:"Playoff",TRAINING:"Training"}[d.eventType]||d.eventType.charAt(0)+d.eventType.slice(1).toLowerCase().replace(/_/g," ")}),d.isCompleted&&d.result&&e.jsx(F,{variant:d.result.toLowerCase().includes("won")||d.result.toLowerCase().includes("win")?"default":"secondary","data-testid":`badge-result-${d.id}`,children:d.result}),d.score&&e.jsx("span",{className:"text-sm font-mono","data-testid":`text-score-${d.id}`,children:d.score}),!d.isCompleted&&e.jsx(F,{variant:"outline",children:"Upcoming"})]})]})})},d.id))}):e.jsx(q,{children:e.jsxs(z,{className:"py-12 text-center",children:[e.jsx(Ne,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"No team events yet"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Log games, tournaments, and practices for your team."}),e.jsxs(u,{onClick:()=>j(!0),"data-testid":"button-add-first-event",children:[e.jsx(Se,{className:"h-4 w-4 mr-1"})," Add Event"]})]})})]}),re.length>0&&e.jsxs(pe,{value:"profiles",className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-medium",children:"Connected Academy Profiles"}),e.jsx(ss,{members:re,roleId:l})]})]}),e.jsx(Je,{open:t,onOpenChange:a,roleId:l}),e.jsx(We,{member:P,onClose:()=>I(null),roleId:l}),e.jsx(Xe,{open:p,onOpenChange:s,roleId:l}),e.jsx(Ze,{open:m,onOpenChange:j,roleId:l}),e.jsx(es,{open:S,onOpenChange:L,roleId:l}),e.jsx(_e,{open:R,onOpenChange:o,roleId:l}),e.jsx(Qe,{open:v,onOpenChange:g,suggestions:y,roleId:l})]})}function X({icon:i,label:l,value:c,testId:x}){return e.jsx(q,{children:e.jsxs(z,{className:"py-4 flex items-center gap-3",children:[e.jsx("div",{className:"text-muted-foreground",children:i}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold","data-testid":x,children:c}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l})]})]})})}function Te({members:i,roleId:l,type:c,onEdit:x}){const{toast:t}=H(),a=O({mutationFn:s=>D("DELETE",`/api/team-roster-members/${s}`),onSuccess:()=>{t({title:"Member removed"}),V.invalidateQueries({queryKey:["/api/volleyball-roles",l,"team-dashboard"]})}}),p=O({mutationFn:s=>D("POST",`/api/team-roster-members/${s}/invite`),onSuccess:()=>{t({title:"Invitation sent"}),V.invalidateQueries({queryKey:["/api/volleyball-roles",l,"team-dashboard"]})},onError:s=>{t({title:"Failed to send invite",description:s.message,variant:"destructive"})}});return e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(qe,{children:[e.jsx(ze,{children:e.jsxs(Ee,{children:[c==="player"&&e.jsx(J,{className:"w-16",children:"#"}),e.jsx(J,{children:"Name"}),e.jsx(J,{children:c==="player"?"Position":"Role"}),e.jsx(J,{children:"Email"}),e.jsx(J,{children:"Status"}),e.jsx(J,{className:"w-24",children:"Actions"})]})}),e.jsx(Ue,{children:i.map(s=>e.jsxs(Ee,{"data-testid":`row-member-${s.id}`,children:[c==="player"&&e.jsx(W,{className:"font-mono text-sm","data-testid":`text-jersey-${s.id}`,children:s.jerseyNumber||"â"}),e.jsx(W,{className:"font-medium","data-testid":`text-name-${s.id}`,children:s.connectedPersonId?e.jsx(Z,{href:`/community/profile/${s.connectedPersonId}`,children:e.jsxs("span",{className:"text-primary hover:underline cursor-pointer",children:[s.firstName," ",s.lastName]})}):e.jsxs(e.Fragment,{children:[s.firstName," ",s.lastName]})}),e.jsx(W,{"data-testid":`text-position-${s.id}`,children:c==="player"?s.position||"â":s.coachRole||"â"}),e.jsx(W,{className:"text-sm text-muted-foreground",children:s.email||"â"}),e.jsx(W,{children:e.jsx(Be,{member:s}
1)}),e.jsx(W,{children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>x(s),"data-testid":`button-edit-${s.id}`,children:e.jsx(Ke,{className:"h-3 w-3"})}),s.email&&s.connectionStatus!=="CONNECTED"&&e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>p.mutate(s.id),disabled:p.isPending,"data-testid":`button-invite-${s.id}`,title:"Send academy invite",children:e.jsx(Oe,{className:"h-3 w-3"})}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>{confirm("Remove this member from the roster?")&&a.mutate(s.id)},"data-testid":`button-delete-${s.id}`,children:e.jsx(De,{className:"h-3 w-3 text-destructive"})})]})})]},s.id))})]})})}function Be({member:i}){return i.connectionStatus==="CONNECTED"?e.jsxs(F,{className:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200","data-testid":`badge-connected-${i.id}`,children:[e.jsx(Ie,{className:"h-3 w-3 mr-1"})," Connected"]}):i.connectionStatus==="PENDING"&&i.connectedPersonId?e.jsxs(F,{variant:"outline",className:"text-amber-600 border-amber-300","data-testid":`badge-pending-${i.id}`,children:[e.jsx(we,{className:"h-3 w-3 mr-1"})," Pending Acceptance"]}):i.invitedAt?e.jsxs(F,{variant:"outline",className:"text-amber-600 border-amber-300","data-testid":`badge-invited-${i.id}`,children:[e.jsx(we,{className:"h-3 w-3 mr-1"})," Invited"]}):i.email?e.jsx(F,{variant:"outline",className:"text-muted-foreground","data-testid":`badge-not-invited-${i.id}`,children:"Not Invited"}):e.jsx(F,{variant:"outline",className:"text-muted-foreground","data-testid":`badge-no-email-${i.id}`,children:"No Email"})}function Qe({open:i,onOpenChange:l,suggestions:c,roleId:x}){const{toast:t}=H(),[a,p]=r.useState(new Set),s=O({mutationFn:m=>D("POST",`/api/volleyball-roles/${x}/confirm-connection`,m),onSuccess:(m,j)=>{p(S=>new Set(S).add(j.memberId)),t({title:"Connection confirmed"}),V.invalidateQueries({queryKey:["/api/volleyball-roles",x,"team-dashboard"]})},onError:m=>{t({title:"Failed to confirm",description:m.message,variant:"destructive"})}});return e.jsx(U,{open:i,onOpenChange:l,children:e.jsxs(Y,{className:"max-w-md",children:[e.jsxs(K,{children:[e.jsx(B,{children:"Connection Suggestions"}),e.jsx(se,{children:"These roster members match existing academy profiles by email. Confirm to link them."})]}),e.jsx("div",{className:"space-y-3 max-h-64 overflow-y-auto",children:c.map(m=>e.jsxs("div",{className:"flex items-center justify-between p-3 border rounded-lg","data-testid":`suggestion-${m.memberId}`,children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:m.memberName}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Matches: ",m.matchedPersonName]})]}),a.has(m.memberId)?e.jsxs(F,{className:"bg-green-100 text-green-800",children:[e.jsx(Ie,{className:"h-3 w-3 mr-1"})," Linked"]}):e.jsx(u,{size:"sm",onClick:()=>s.mutate({memberId:m.memberId,matchedPersonId:m.matchedPersonId}),disabled:s.isPending,"data-testid":`button-confirm-${m.memberId}`,children:"Confirm"})]},m.memberId))}),e.jsx(Q,{children:e.jsx(u,{variant:"outline",onClick:()=>l(!1),children:"Done"})})]})})}function _e({open:i,onOpenChange:l,roleId:c}){const{toast:x}=H(),[t,a]=r.useState(""),[p,s]=r.useState(""),m=O({mutationFn:j=>D("POST",`/api/volleyball-roles/${c}/team-announcement`,j),onSuccess:async j=>{const S=await j.json();x({title:"Announcement sent",description:`Delivered to ${S.sent} of ${S.total} members`}),a(""),s(""),l(!1)},onError:j=>{x({title:"Failed to send",description:j.message,variant:"destructive"})}});return e.jsx(U,{open:i,onOpenChange:l,children:e.jsxs(Y,{children:[e.jsxs(K,{children:[e.jsx(B,{children:"Team Announcement"}),e.jsx(se,{children:"Send an email to all team members with an email address."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(f,{children:"Subject *"}),e.jsx(A,{value:t,onChange:j=>a(j.target.value),placeholder:"e.g. Practice Schedule Update","data-testid":"input-announcement-subject"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Message *"}),e.jsx(oe,{value:p,onChange:j=>s(j.target.value),rows:5,placeholder:"Write your message to the team...","data-testid":"input-announcement-message"})]})]}),e.jsxs(Q,{children:[e.jsx(u,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsxs(u,{onClick:()=>
1{if(!t.trim()||!p.trim()){x({title:"Subject and message are required",variant:"destructive"});return}m.mutate({subject:t.trim(),message:p.trim()})},disabled:m.isPending,"data-testid":"button-send-announcement",children:[m.isPending&&e.jsx(ee,{className:"h-4 w-4 mr-1 animate-spin"}),"Send to Team"]})]})]})})}function Je({open:i,onOpenChange:l,roleId:c}){const{toast:x}=H(),[t,a]=r.useState("PLAYER"),[p,s]=r.useState(""),[m,j]=r.useState(""),[S,L]=r.useState(""),[R,o]=r.useState(""),[v,g]=r.useState(""),[y,N]=r.useState(""),[P,I]=r.useState(""),w=O({mutationFn:n=>D("POST",`/api/volleyball-roles/${c}/roster-members`,n),onSuccess:()=>{x({title:"Member added"}),V.invalidateQueries({queryKey:["/api/volleyball-roles",c,"team-dashboard"]}),k(),l(!1)},onError:n=>{x({title:"Failed to add member",description:n.message,variant:"destructive"})}});function k(){s(""),j(""),L(""),o(""),g(""),N(""),I(""),a("PLAYER")}function C(){if(!p.trim()||!m.trim()){x({title:"First and last name are required",variant:"destructive"});return}w.mutate({memberType:t,firstName:p.trim(),lastName:m.trim(),email:S.trim()||null,position:t==="PLAYER"&&R||null,jerseyNumber:t==="PLAYER"&&v.trim()||null,coachRole:t==="COACH"&&y.trim()||null,notes:P.trim()||null})}return e.jsx(U,{open:i,onOpenChange:l,children:e.jsxs(Y,{children:[e.jsxs(K,{children:[e.jsx(B,{children:"Add Team Member"}),e.jsx(se,{children:"Add a player or coach to your team roster."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(f,{children:"Type"}),e.jsxs(ae,{value:t,onValueChange:a,children:[e.jsx(ne,{"data-testid":"select-member-type",children:e.jsx(ie,{})}),e.jsxs(le,{children:[e.jsx(T,{value:"PLAYER",children:"Player"}),e.jsx(T,{value:"COACH",children:"Coach"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(f,{children:"First Name *"}),e.jsx(A,{value:p,onChange:n=>s(n.target.value),"data-testid":"input-first-name"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Last Name *"}),e.jsx(A,{value:m,onChange:n=>j(n.target.value),"data-testid":"input-last-name"})]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Email"}),e.jsx(A,{type:"email",value:S,onChange:n=>L(n.target.value),placeholder:"For connection matching & invites","data-testid":"input-email"})]}),t==="PLAYER"&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(f,{children:"Position"}),e.jsxs(ae,{value:R,onValueChange:o,children:[e.jsx(ne,{"data-testid":"select-position",children:e.jsx(ie,{placeholder:"Select position"})}),e.jsx(le,{children:Ae.map(n=>e.jsx(T,{value:n,children:n},n))})]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Jersey #"}),e.jsx(A,{value:v,onChange:n=>g(n.target.value),placeholder:"e.g. 7","data-testid":"input-jersey"})]})]}),t==="COACH"&&e.jsxs("div",{children:[e.jsx(f,{children:"Coach Role"}),e.jsx(A,{value:y,onChange:n=>N(n.target.value),placeholder:"e.g. Assistant Coach","data-testid":"input-coach-role"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Notes"}),e.jsx(oe,{value:P,onChange:n=>I(n.target.value),rows:2,"data-testid":"input-notes"})]})]}),e.jsxs(Q,{children:[e.jsx(u,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsxs(u,{onClick:C,disabled:w.isPending,"data-testid":"button-save-member",children:[w.isPending&&e.jsx(ee,{className:"h-4 w-4 mr-1 animate-spin"})," Add Member"]})]})]})})}function We({member:i,onClose:l,roleId:c}){const{toast:x}=H(),[t,a]=r.useState(""),[p,s]=r.useState(""),[m,j]=r.useState(""),[S,L]=r.useState(""),[R,o]=r.useState(""),[v,g]=r.useState(""),[y,N]=r.useState(""),[P,I]=r.useState(!1),w=!!i;r.useEffect(()=>{i&&!P&&(a(i.firstName),s(i.lastName),j(i.email||""),L(i.position||""),o(i.jerseyNumber||""),g(i.coachRole||""),N(i.notes||""),I(!0)),i||I(!1)},[i,P]);const k=O({mutationFn:n=>D("PATCH",`/api/team-roster-members/${i?.id}`,n),onSuccess:()=>{x({title:"Member updated"}),V.invalidateQueries({queryKey:["/api/volleyball-roles",c,"team-dashboard"]}),C()}});function C(){a(""),s(""),j(""),L(""),o(""),g(""),N(""),I(!1),l()}return e.jsx(U,{open:w,onOpenChange:n=>{n||C()},children:e.jsxs(Y,{children:[e.jsx(K,{children:e.jsx(B,{children:"Edit Member"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(f,{children:"First Name"}),e.jsx(A,{value:t,onChange:n=>a(n.target.value),"data-testid":"input-edit-first-name"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Last Name"}),e.jsx(A,{value:p,onChange:n=>s(n.target.value),"data-testid":"input-edit-last-name"})]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Email"}),e.jsx(A,{type:"email",value:m,onChange:n=>j(n.target.value),"data-testid":"input-edit-email"})]}),i?.memberType==="PLAYER"&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(f,{children:"Position"}),e.jsxs(ae,{value:S,onValueChange:L,children:[e.jsx(ne,{"data-testid":"select-edit-position",children:e.jsx(ie,{placeholder:"Select position"})}),e.jsx(le,{children:Ae.map(n=>e.jsx(T,{value:n,children:n},n))})]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Jersey #"}),e.jsx(A,{value:R,onChange:n=>o(n.target.value),"data-testid":"input-edit-jersey"})]})]}),i?.memberType==="COACH"&&e.jsxs("div",{children:[e.jsx(f,{children:"Coach Role"}
1),e.jsx(A,{value:v,onChange:n=>g(n.target.value),"data-testid":"input-edit-coach-role"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Notes"}),e.jsx(oe,{value:y,onChange:n=>N(n.target.value),rows:2,"data-testid":"input-edit-notes"})]})]}),e.jsxs(Q,{children:[e.jsx(u,{variant:"outline",onClick:C,children:"Cancel"}),e.jsxs(u,{onClick:()=>{const n={firstName:t.trim(),lastName:p.trim(),email:m.trim()||null,notes:y.trim()||null};i?.memberType==="PLAYER"&&(n.position=S||null,n.jerseyNumber=R.trim()||null),i?.memberType==="COACH"&&(n.coachRole=v.trim()||null),k.mutate(n)},disabled:k.isPending,"data-testid":"button-update-member",children:[k.isPending&&e.jsx(ee,{className:"h-4 w-4 mr-1 animate-spin"})," Save Changes"]})]})]})})}function Xe({open:i,onOpenChange:l,roleId:c}){const{toast:x}=H(),t=r.useRef(null),[a,p]=r.useState(""),[s,m]=r.useState([]),j=O({mutationFn:o=>D("POST",`/api/volleyball-roles/${c}/roster-members/bulk-import`,o),onSuccess:async o=>{const v=await o.json();x({title:"Import complete",description:`${v.created} members added${v.errors.length>0?`, ${v.errors.length} errors`:""}`}),V.invalidateQueries({queryKey:["/api/volleyball-roles",c,"team-dashboard"]}),p(""),m([]),l(!1)}});function S(o){const v=o.target.files?.[0];if(!v)return;const g=new FileReader;g.onload=y=>{const N=y.target?.result;p(N),R(N)},g.readAsText(v)}function L(o){const v=[];let g="",y=!1;for(let N=0;N<o.length;N++){const P=o[N];P==='"'?y&&N+1<o.length&&o[N+1]==='"'?(g+='"',N++):y=!y:P===","&&!y?(v.push(g.trim()),g=""):g+=P}return v.push(g.trim()),v}function R(o){const v=o.trim().split(` 2`).map(h=>h.trim()).filter(Boolean);if(v.length<2){x({title:"CSV must have a header row and at least one data row",variant:"destructive"});return}const g=L(v[0]).map(h=>h.toLowerCase()),y=g.findIndex(h=>h.includes("first")),N=g.findIndex(h=>h.includes("last")),P=g.findIndex(h=>h==="name"||h==="full name"||h==="player name"||h==="athlete name"),I=g.findIndex(h=>h.includes("email")),w=g.findIndex(h=>h.includes("position")||h.includes("pos")),k=g.findIndex(h=>h.includes("jersey")||h.includes("number")||h==="#"),C=g.findIndex(h=>h.includes("type")||h.includes("role")),n=y!==-1&&N!==-1;if(!n&&!(P!==-1)){x({title:"CSV must have 'First Name'/'Last Name' columns or a single 'Name' column",variant:"destructive"});return}const ce=v.slice(1).map(h=>{const $=L(h);let b="",M="";if(n)b=$[y]||"",M=$[N]||"";else{const G=$[P]||"",_=G.indexOf(" ");_>0?(b=G.substring(0,_),M=G.substring(_+1)):(b=G,M="")}return{firstName:b,lastName:M,email:I>=0&&$[I]||null,position:w>=0&&$[w]||null,jerseyNumber:k>=0&&$[k]||null,memberType:C>=0&&$[C]?.toUpperCase()==="COACH"?"COACH":"PLAYER",coachRole:null,notes:null}}).filter(h=>h.firstName);m(ce)}return e.jsx(U,{open:i,onOpenChange:l,children:e.jsxs(Y,{className:"max-w-lg",children:[e.jsxs(K,{children:[e.jsx(B,{children:"Import Roster from CSV"}),e.jsx(se,{children:"Upload a CSV file with columns: First Name + Last Name (or a single Name column), Email, Position, Jersey #, Type (PLAYER/COACH)."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("input",{ref:t,type:"file",accept:".csv",onChange:S,className:"hidden"}),e.jsxs(u,{variant:"outline",onClick:()=>t.current?.click(),"data-testid":"button-upload-csv",children:[e.jsx(ve,{className:"h-4 w-4 mr-1"})," Choose CSV File"]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Or paste CSV text:"}),e.jsx(oe,{value:a,onChange:o=>{p(o.target.value),o.target.value.trim()&&R(o.target.value)},rows:6,placeholder:`First Name,Last Name,Email,Position,Jersey # 3Jane,Doe,[email protected],Setter,7`,"data-testid":"textarea-csv"})]}),s.length>0&&e.jsxs("div",{className:"text-sm",children:[e.jsxs("p",{className:"font-medium",children:[s.length," members ready to import:"]}),e.jsx("div",{className:"max-h-32 overflow-y-auto mt-1 border rounded p-2 text-muted-foreground",children:s.map((o,v)=>e.jsxs("p",{children:[o.firstName," ",o.lastName,o.position?` (${o.position})`:"",o.jerseyNumber?` #${o.jerseyNumber}`:""]},v))})]})]}),e.jsxs(Q,{children:[e.jsx(u,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsxs(u,{onClick:()=>j.mutate({members:s}),disabled:s.length===0||j.isPending,"data-testid":"button-confirm-import",children:[j.isPending&&e.jsx(ee,{className:"h-4 w-4 mr-1 animate-spin"}),"Import ",s.length," Members"]})]})]})})}function Ze({open:i,onOpenChange:l,roleId:c}){const{toast:x}=H(),[t,a]=r.useState(""),[p,s]=r.useState("GAME"),[m,j]=r.useState(""),[S,L]=r.useState(""),[R,o]=r.useState(""),[v,g]=r.useState(""),[y,N]=r.useState(""),[P,I]=r.useState(""),[w,k]=r.useState(!1),C=O({mutationFn:E=>D("POST",`/api/volleyball-roles/${c}/team-events`,E),onSuccess:()=>{x({title:"Event added"}),V.invalidateQueries({queryKey:["/api/volleyball-roles",c,"team-dashboard"]}),l(!1),n()}});function n(){a(""),s("GAME"),j(""),L(""),o(""),g(""),N(""),I(""),k(!1)}return e.jsx(U,{open:i,onOpenChange:l,children:e.jsxs(Y,{children:[e.jsxs(K,{children:[e.jsx(B,{children:"Add Team Event"}),e.jsx(se,{children:"Log a game, tournament, or practice for your team."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(f,{children:"Event Name *"}),e.jsx(A,{value:t,onChange:E=>a(E.target.value),placeholder:"e.g. League Game vs Thunder","data-testid":"input-event-name"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Type"}),e.jsxs(ae,{value:p,onValueChange:s,children:[e.jsx(ne,{"data-testid":"select-event-type",children:e.jsx(ie,{})}),e.jsxs(le,{children:[e.jsx(T,{value:"GAME",children:"Game"}
3),e.jsx(T,{value:"TOURNAMENT",children:"Tournament"}),e.jsx(T,{value:"LEAGUE_GAME",children:"League Game"}),e.jsx(T,{value:"SCHOOL_GAME",children:"School Game"}),e.jsx(T,{value:"PRACTICE",children:"Practice"}),e.jsx(T,{value:"SCRIMMAGE",children:"Scrimmage"}),e.jsx(T,{value:"OTHER",children:"Other"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(f,{children:"Opponent"}),e.jsx(A,{value:m,onChange:E=>j(E.target.value),placeholder:"e.g. Central Thunder","data-testid":"input-opponent"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Date *"}),e.jsx(A,{type:"date",value:S,onChange:E=>L(E.target.value),"data-testid":"input-event-date"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(f,{children:"Venue"}),e.jsx(A,{value:R,onChange:E=>o(E.target.value),"data-testid":"input-venue"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"City"}),e.jsx(A,{value:v,onChange:E=>g(E.target.value),"data-testid":"input-city"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"is-completed",checked:w,onChange:E=>k(E.target.checked),"data-testid":"checkbox-completed"}),e.jsx(f,{htmlFor:"is-completed",children:"Event completed (enter result)"})]}),w&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(f,{children:"Result"}),e.jsxs(ae,{value:y,onValueChange:N,children:[e.jsx(ne,{"data-testid":"select-result",children:e.jsx(ie,{placeholder:"Select result"})}),e.jsxs(le,{children:[e.jsx(T,{value:"Won",children:"Won"}),e.jsx(T,{value:"Lost",children:"Lost"}),e.jsx(T,{value:"Draw",children:"Draw"}),e.jsx(T,{value:"1st Place",children:"1st Place"}),e.jsx(T,{value:"2nd Place",children:"2nd Place"}),e.jsx(T,{value:"3rd Place",children:"3rd Place"})]})]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Score"}),e.jsx(A,{value:P,onChange:E=>I(E.target.value),placeholder:"e.g. 25-23, 25-21","data-testid":"input-score"})]})]})]}),e.jsxs(Q,{children:[e.jsx(u,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsxs(u,{onClick:()=>{if(!t.trim()||!S){x({title:"Event name and date are required",variant:"destructive"});return}C.mutate({eventName:t.trim(),eventType:p,opponentName:m.trim()||null,startDate:S,venue:R.trim()||null,city:v.trim()||null,result:w&&y||null,score:w&&P.trim()||null,isCompleted:w})},disabled:C.isPending,"data-testid":"button-save-event",children:[C.isPending&&e.jsx(ee,{className:"h-4 w-4 mr-1 animate-spin"})," Add Event"]})]})]})})}function es({open:i,onOpenChange:l,roleId:c}){const{toast:x}=H(),{data:t=[],isLoading:a}=fe({queryKey:["/api/volleyball-roles",c,"untagged-events"],queryFn:()=>fetch(`/api/volleyball-roles/${c}/untagged-events`,{credentials:"include"}).then(s=>{if(!s.ok)throw new Error("Failed to load events");return s.json()}),enabled:i&&!!c}),p=O({mutationFn:s=>D("PATCH",`/api/athlete-external-events/${s}/tag-team`,{volleyballRoleId:c}),onSuccess:()=>{x({title:"Event tagged to team"}),V.invalidateQueries({queryKey:["/api/volleyball-roles",c,"team-dashboard"]}),V.invalidateQueries({queryKey:["/api/volleyball-roles",c,"untagged-events"]})}});return e.jsx(U,{open:i,onOpenChange:l,children:e.jsxs(Y,{className:"max-w-md",children:[e.jsxs(K,{children:[e.jsx(B,{children:"Tag Existing Events"}),e.jsx(se,{children:"Select events from your log to associate with this team."})]}),e.jsx("div",{className:"space-y-2 max-h-64 overflow-y-auto",children:a?e.jsx("div",{className:"py-4 text-center text-muted-foreground",children:"Loading events..."}):t.length===0?e.jsx("div",{className:"py-4 text-center text-muted-foreground",children:"No untagged events available."}):t.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-3 border rounded-lg","data-testid":`untagged-event-${s.id}`,children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s.eventName}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[new Date(s.startDate).toLocaleDateString(),s.opponentName&&` vs ${s.opponentName}`]})]}),e.jsx(u,{size:"sm",variant:"outline",onClick:()=>p.mutate(s.id),disabled:p.isPending,"data-testid":`button-tag-${s.id}`,children:"Tag"})]},s.id))}),e.jsx(Q,{children:e.jsx(u,{variant:"outline",onClick:()=>l(!1),children:"Done"})})]})})}function ss({members:i,roleId:l}){const{data:c=[]}=fe({queryKey:["/api/volleyball-roles",l,"connected-athlete-summaries"],queryFn:()=>fetch(`/api/volleyball-roles/${l}/connected-athlete-summaries`,{credentials:"include"}).then(t=>{if(!t.ok)throw new Error("Failed to load summaries");return t.json()}),enabled:i.length>0}),x=new Map(c.map(t=>[t.memberId,t]));return e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:i.map(t=>{const a=x.get(t.id);return e.jsx(q,{children:e.jsxs(z,{className:"py-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(Ge,{className:"h-10 w-10",children:e.jsxs(Ve,{children:[t.firstName[0],t.lastName[0]]})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"font-medium truncate","data-testid":`text-connected-name-${t.id}`,children:[a?.firstName||t.firstName," ",a?.lastName||t.lastName]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.position||t.coachRole||t.memberType,t.jerseyNumber&&` · #${t.jerseyNumber}`]})]}),t.connectedPersonId&&e.jsx(Z,{href:`/community/profile/${t.connectedPersonId}`,children:e.jsx(u,{variant:"ghost",size:"sm","data-testid":`button-view-profile-${t.id}`,title:"View academy profile",children:e.jsx(He,{className:"h-4 w-4"})})})]}),a?.connectionPending&&e.jsx("div",{className:"text-xs text-amber-600 pl-13 mt-1","data-testid":`text-pending-${t.id}`,children:"Connection pending athlete acceptance"}),a&&!a.connectionPending&&e.jsxs("div",{className:"text-xs text-muted-foreground space-y-0.5 pl-13","data-testid":`profile-summary-${t.id}`,children:[a.preferredPositions&&e.jsxs("p",{children:["Positions: ",a.preferredPositions]}),a.skillLevel&&e.jsxs("p",{children:["Skill Level: ",a.skillLevel]}),a.currentSchool&&e.jsxs("p",{children:["School: ",a.currentSchool]}),a.currentGrade&&e.jsxs("p",{children:["Grade: ",a.currentGrade]}),a.currentPrograms.length>0&&e.jsxs("p",{children:["Current Programs: ",a.currentPrograms.join(", ")
3]}),a.memberSince&&e.jsxs("p",{children:["Member since: ",new Date(a.memberSince).toLocaleDateString()]})]}),a&&!a.connectionPending&&a.latestEvaluation&&e.jsxs("div",{className:"mt-2 p-2 bg-muted/50 rounded text-xs","data-testid":`eval-summary-${t.id}`,children:[e.jsxs("p",{className:"font-medium text-foreground mb-1",children:["Latest Evaluation",a.latestEvaluation.overallRating&&` · ${a.latestEvaluation.overallRating}/5`,a.evaluationCount>1&&` (${a.evaluationCount} total)`]}),a.latestEvaluation.strengths&&e.jsxs("p",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Strengths:"})," ",a.latestEvaluation.strengths]}),a.latestEvaluation.areasForImprovement&&e.jsxs("p",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Areas to improve:"})," ",a.latestEvaluation.areasForImprovement]})]})]})},t.id)})})}export{ds 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.