1import{E as ne,bh as re,Q as le,r as o,s as J,l as de,a0 as me,j as e,bj as R,d as ce,B as l,L as oe,m as j,M as L,I as f,u as _}from"./index-BCH4IFx8.js";import{C as P,b as E,c as U,a as z}from"./card-DaE3Hwfn.js";import{S as W}from"./separator-BJTOU-8g.js";import{e as xe,d as ue,t as u}from"./teams-Dc2EtOTA.js";import{f as he}from"./selectedRoundsFromResponses-CREygxYZ.js";import{S as pe}from"./shield-alert-BMOy4B7c.js";import{U as je}from"./users-Cp35uMGZ.js";import{C as fe}from"./calendar-BcfRHKCP.js";import{C as I}from"./crown-CjpfTJ_4.js";import{C as B}from"./copy-CIGjrFWu.js";import{S as ge}from"./send-CJD-Z0Nl.js";import{R as V}from"./refresh-cw-Bp2bbqxH.js";import{U as Ne}from"./user-minus-p5ZywIrz.js";const X=d=>{var h,N;return[(h=d.registration)==null?void 0:h.first_name,(N=d.registration)==null?void 0:N.last_name].filter(Boolean).join(" ")||"Pending rider"};function Ue(){var Y,Z,G;const{orgSlug:d,joinCode:h}=ne(),{setOrganizationFromSlug:N}=re(),ee=le(),[k,D]=o.useState(null),[y,M]=o.useState(""),[S,O]=o.useState(null),[m,w]=o.useState({name:"",email:"",phone:""}),[C,q]=o.useState("");o.useEffect(()=>{d&&N(d)},[d,N]),o.useEffect(()=>{let s=!1;return(async()=>{const{data:{session:t}}=await J.auth.getSession();if(s)return;if(!(t!=null&&t.user)){O([]);return}const c=new Set;t.user.email&&c.add(t.user.email.toLowerCase());const{data:p}=await J.from("linked_emails").select("email").eq("user_id",t.user.id);for(const v of p??[])v.email&&c.add(String(v.email).toLowerCase());O([...c])})(),()=>{s=!0}},[]);const{data:a,isLoading:se,error:ae}=de({queryKey:["event-team",h],queryFn:()=>u.lookup(h),enabled:!!h,refetchInterval:3e4});o.useEffect(()=>{var s,t;(s=a==null?void 0:a.team)!=null&&s.team_name&&M(a.team.team_name),q(((t=a==null?void 0:a.team)==null?void 0:t.bike_number)??"")},[(Y=a==null?void 0:a.team)==null?void 0:Y.team_name,(Z=a==null?void 0:a.team)==null?void 0:Z.bike_number]);const A=o.useMemo(()=>{var t,c;const s=a==null?void 0:a.roster.find(p=>p.registration_id&&p.registration_id===a.team.captain_registration_id);return((c=(t=s==null?void 0:s.registration)==null?void 0:t.email)==null?void 0:c.toLowerCase())??null},[a]),g=!!A&&!!(S!=null&&S.includes(A)),te=()=>ee.invalidateQueries({queryKey:["event-team",h]}),n=me({mutationFn:async s=>s(),onSuccess:()=>te(),onError:s=>_.error(s.message)}),T=async(s,t)=>{await navigator.clipboard.writeText(t),D(s),_.success("Copied"),setTimeout(()=>D(null),1500)};if(se)return e.jsx(R,{children:e.jsx("div",{className:"flex items-center justify-center py-24",children:e.jsx(ce,{className:"h-6 w-6 animate-spin text-muted-foreground"})})});if(ae||!a)return e.jsx(R,{children:e.jsxs("div",{className:"max-w-lg mx-auto px-4 py-16 text-center space-y-4",children:[e.jsx(pe,{className:"h-8 w-8 mx-auto text-muted-foreground"}),e.jsx("h1",{className:"text-xl font-semibold",children:"Team not found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Double-check the team code in your confirmation email or ask your captain for a fresh link."}),d&&e.jsx(l,{asChild:!0,variant:"outline",children:e.jsx(oe,{to:`/org/${d}/events`,children:"Back to events"})})]})});const{team:i,klass:r,event:x,roster:b,spotsRemaining:ie,isComplete:F,locked:Q}=a,$=xe(d,i.event_id,i.join_code),K=ue(d,i.join_code);return e.jsx(R,{children:e.jsxs("div",{className:"max-w-3xl mx-auto px-4 py-8 space-y-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(je,{className:"h-4 w-4"}),e.jsx("span",{children:(r==null?void 0:r.class_name)??"Team"}),(x==null?void 0:x.event_date)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx(fe,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:he(x.event_date)})]})]}),e.jsx("h1",{className:"text-2xl font-bold",children:i.team_name}),(x==null?void 0:x.name)&&e.jsx("p",{className:"text-muted-foreground",children:x.name})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(j,{variant:F?"default":"secondary",children:[b.length,r!=null&&r.max_team_riders?` / ${r.max_team_riders}`:""," riders"]}),(r==null?void 0:r.min_team_riders)!=null&&!F&&e.jsxs(j,{variant:"outline",children:["Needs ",r.min_team_riders-b.length," more to be race-ready"]}),Q&&e.jsx(j,{variant:"outline",children:"Roster locked"}),g&&e.jsxs(j,{variant:"outline",className:"gap-1",children:[e.jsx(I,{className:"h-3 w-3"})," You're the captain"]})]}),e.jsxs(P,{children:[e.jsx(E,{className:"pb-3",children:e.jsx(U,{className:"text-base",children:"Invite your riders"})}),e.jsxs(z,{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Team code"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"px-3 py-2 rounded-md bg-muted font-mono text-lg tracking-widest",children:i.join_code}),e.jsx(l,{size:"sm",variant:"outline",onClick:()=>T("code",i.join_code),children:k==="code"?e.jsx(L,{className:"h-4 w-4"}):e.jsx(B,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Signup link (riders pay their own share)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{readOnly:!0,value:$,className:"text-xs"}),e.jsx(l,{size:"sm",variant:"outline",onClick:()=>T("share",$),children:k==="share"?e.jsx(L,{className:"h-4 w-4"}):e.jsx(B,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"This team page (bookmark it)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{readOnly:!0,value:K,className:"text-xs"}),e.jsx(l,{size:"sm",variant:"outline",onClick:()=>T("manage",K),children:k==="manage"?e.jsx(L,{className:"h-4 w-4"}):e.jsx(B,{className:"h-4 w-4"})})]})]}),ie===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"This team is full â no more riders can join."}),g&&e.jsxs("div",{className:"pt-2 border-t space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Send the link for me"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Add a rider's name with their cell phone or email and we'll send them their own sign-up link."}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(f,{placeholder:"Rider name",value:m.name,onChange:s=>w({...m,name:s.target.value})}),e.jsx(f,{placeholder:"Cell phone",type:"tel",value:m.phone,onChange:s=>w({...m,phone:s.target.value})}),e.jsx(f,{placeholder:"Email",type:"email",value:m.email,onChange:s=>w({...m,email:s.target.value})})]}),e.jsxs(l,{size:"sm",disabled:n.isPending||!m.phone.trim()&&!m.email.trim(),onClick:()=>n.mutate(async()=>
1{await u.invite(i.id,[m]),w({name:"",email:"",phone:""}),_.success("Invite sent")}),children:[e.jsx(ge,{className:"h-4 w-4 mr-1"})," Send invite"]})]}),!!((G=a.invites)!=null&&G.length)&&e.jsxs("div",{className:"pt-2 border-t space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Invited riders"}),a.invites.map(s=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border p-2 text-sm",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"font-medium",children:s.invitee_name||"Rider"})," ",e.jsx("span",{className:"text-xs text-muted-foreground",children:[s.phone_masked,s.email_masked].filter(Boolean).join(" · ")})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(j,{variant:s.status==="sent"?"secondary":"outline",className:"text-[10px]",children:s.status==="sent"?"Link sent":s.status==="failed"?"Not delivered":"Pending"}),g&&e.jsx(l,{size:"sm",variant:"ghost",title:"Send again",disabled:n.isPending,onClick:()=>n.mutate(async()=>{await u.resendInvite(i.id,s.id),_.success("Invite sent again")}),children:e.jsx(V,{className:"h-4 w-4"})})]})]},s.id))]})]})]}),e.jsxs(P,{children:[e.jsx(E,{className:"pb-3",children:e.jsx(U,{className:"text-base",children:"Roster"})}),e.jsxs(z,{className:"space-y-2",children:[b.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No riders on this team yet."}),b.map(s=>{var p,v,H;const t=s.registration_id===i.captain_registration_id,c=((p=s.registration)==null?void 0:p.payment_status)==="paid";return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate",children:X(s)}),t&&e.jsx(I,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-1",children:[e.jsx(j,{variant:c?"default":"secondary",className:"text-[10px]",children:c?"Paid":((v=s.registration)==null?void 0:v.payment_status)||"Pending"}),((H=s.registration)==null?void 0:H.waiver_signed)===!1&&e.jsx(j,{variant:"outline",className:"text-[10px]",children:"Waiver needed"})]})]}),g&&!t&&!Q&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(l,{size:"sm",variant:"ghost",title:"Make captain",onClick:()=>n.mutate(()=>u.transferCaptain(i.id,s.id)),children:e.jsx(I,{className:"h-4 w-4"})}),e.jsx(l,{size:"sm",variant:"ghost",title:"Remove rider",onClick:()=>{confirm(`Remove ${X(s)} from the team? This does not refund their entry.`)&&n.mutate(()=>u.removeMember(i.id,s.id))},children:e.jsx(Ne,{className:"h-4 w-4"})})]})]},s.id)})]})]}),g&&e.jsxs(P,{children:[e.jsx(E,{className:"pb-3",children:e.jsx(U,{className:"text-base",children:"Captain tools"})}),e.jsxs(z,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Team name"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{value:y,onChange:s=>M(s.target.value),maxLength:80}),e.jsx(l,{disabled:!y.trim()||y===i.team_name||n.isPending,onClick:()=>n.mutate(()=>u.rename(i.id,y.trim())),children:"Save"})]})]}),e.jsx(W,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Team race number"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{value:C,placeholder:"#",className:"w-28",onChange:s=>q(s.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,6))}),e.jsx(l,{disabled:!C||C===(i.bike_number??"")||n.isPending,onClick:()=>n.mutate(()=>u.updateTeamNumber(i.id,C)),children:"Save"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your whole team races this number. Letters AâZ and digits only."})]}),e.jsx(W,{}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Reset team code"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Old links stop working. Use this if the code got shared too widely."})]}),e.jsxs(l,{variant:"outline",size:"sm",disabled:n.isPending,onClick:()=>{confirm("Generate a new team code? Existing invite links will stop working.")&&n.mutate(()=>u.regenerateCode(i.id))},children:[e.jsx(V,{className:"h-4 w-4 mr-1"})," Reset"]})]})]})]}),!g&&e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Only the team captain can change the roster. Sign in with the email you registered with to see captain tools."})]})})}export{Ue 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.