1import{k as I,aZ as q,r as p,Q as D,l as E,s as y,j as e,S as F,n as T,o as A,q as Q,t as B,I as O,B as P,X as V}from"./index-BCH4IFx8.js";import{B as z}from"./BpSpinner-Bqvfph1h.js";import{u as K}from"./useSelectedTimingEvent-3RcC6Kj0.js";import{B as X}from"./BikeMakeBadge-ogaJPLaU.js";import{u as Z}from"./MyRidersFilterContext-DhyaPTl1.js";import{R as G}from"./RiderProfileDialog-BR7psrTC.js";import{S as H}from"./search-GvbQAZxx.js";import{F as J}from"./flag-CvB2R2ls.js";import"./TimingSelectionContext-Daw75Td3.js";import"./useTimingEvents-C-M7e7gJ.js";import"./useOrganizationSlug-DcRVJD25.js";import"./useBikeMakeLogos-B-qqkSzN.js";import"./bikeMakeStyle-RND07Se0.js";import"./useRiderFamily-14KWoc-T.js";import"./useUserEmails-64UGJRED.js";import"./nicknameVariants-CT_QG-k6.js";import"./useRiderResults-tE427sBj.js";import"./map-pin-Eqsqtagn.js";import"./trophy-vILI8AG3.js";import"./timer-C6AhmeTR.js";import"./history-Bo2cYU1t.js";function ge(){const c=I(),x=q().bikeMakeColumn,{orgSlug:f,event:t}=K(),{matches:v,active:w}=Z(),[u,L]=p.useState("ALL"),[j,k]=p.useState(""),[S,g]=p.useState(null),C=D(),N=["timing-event-results",f,(t==null?void 0:t.id)??(t==null?void 0:t.event_name),u],{data:i,isLoading:R}=E({queryKey:N,queryFn:async()=>{if(!f||!(t!=null&&t.id))return{event_name:"",moto_format:"",classes:[],motos_per_class:{},rows:[]};const{data:r,error:l}=await y.functions.invoke("fetch-public-lab-event-results",{body:{org_slug:f,event_name:t.event_name,lab_event_id:t.id,event_date:t.event_date,class_name:u}});if(l)throw l;return r??{event_name:t.event_name,moto_format:"",classes:[],motos_per_class:{},rows:[]}},enabled:!!f&&!!(t!=null&&t.id),refetchInterval:5e3});p.useEffect(()=>{if(!(t!=null&&t.id))return;const r=y.channel(`race-results-${t.id}-${u}`).on("postgres_changes",{event:"*",schema:"public",table:"timing_lab_session_entries"},()=>C.invalidateQueries({queryKey:N})).on("postgres_changes",{event:"*",schema:"public",table:"timing_lab_sessions",filter:`event_id=eq.${t.id}`},()=>C.invalidateQueries({queryKey:N})).subscribe();return()=>{y.removeChannel(r)}},[t==null?void 0:t.id,u]);const _=p.useMemo(()=>{const r=(i==null?void 0:i.rows)??[],l=j.trim().toLowerCase();let n=w?r.filter(a=>v(a.rider_name)):r;return l&&(n=n.filter(a=>a.rider_name.toLowerCase().includes(l))),n},[i,w,v,j]),$=(i==null?void 0:i.motos_per_class)??{},M=p.useMemo(()=>{const r=new Map;for(const n of _){const a=r.get(n.class_name)??[];a.push(n),r.set(n.class_name,a)}const l=n=>{const a=Number(n);return Number.isFinite(a)&&a>0?a:1/0};for(const[,n]of r)n.sort((a,s)=>{const m=l(a.position),d=l(s.position);return m!==d?m-d:s.points!==a.points?s.points-a.points:Number(a.rider_number??0)-Number(s.rider_number??0)});return[...r.entries()]},[_]);return R?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(z,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsxs("div",{className:"space-y-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-semibold",children:[c.class,":"]}),e.jsxs(F,{value:u,onValueChange:L,children:[e.jsx(T,{className:"w-56",children:e.jsx(A,{})}),e.jsxs(Q,{children:[e.jsxs(B,{value:"ALL",children:["All ",c.classes]}),((i==null?void 0:i.classes)??[]).map(r=>e.jsx(B,{value:r,children:r},r))]})]}),e.jsxs("div",{className:"relative ml-auto w-full sm:w-64",children:[e.jsx(H,{className:"absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(O,{value:j,onChange:r=>k(r.target.value),placeholder:"Search rider by nameâ¦",className:"h-9 pl-7 pr-7"}),j&&e.jsx(P,{type:"button",variant:"ghost",size:"icon",onClick:()=>k(""),className:"absolute right-0 top-0 h-9 w-9","aria-label":"Clear search",children:e.jsx(V,{className:"h-3.5 w-3.5"})})]})]}),!_.length&&e.jsxs("p",{className:"rounded-md border bg-card p-6 text-center text-sm text-muted-foreground",children:[e.jsx(J,{className:"mx-auto mb-2 h-6 w-6"})," No results published yet."]}),(i==null?void 0:i.is_endurance)&&M.map(([r,l])=>e.jsxs("div",{className:"overflow-hidden rounded-md border bg-card",children:[e.jsx("div",{className:"bg-foreground px-3 py-1.5 text-xs font-bold uppercase tracking-wide text-background",children:r}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-muted/50 text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-1.5 py-1.5 text-center",children:c.position}),e.jsx("th",{className:"px-1.5 py-1.5 text-center",children:"#"}),e.jsx("th",{className:"px-2 py-1.5 text-left",children:"Team"}),e.jsx("th",{className:"px-2 py-1.5 text-right",children:"Laps"})]})}),e.jsx("tbody",{children:l.map((n,a)=>{var s;return e.jsxs("tr",{className:"border-t align-top",children:[e.jsx("td",{className:"px-1.5 py-1.5 text-center font-semibold",children:n.position}),e.jsx("td",{className:"px-1.5 py-1.5 text-center font-mono",children:n.rider_number??"â"}),e.jsxs("td",{className:"px-2 py-1.5",children:[e.jsx("div",{className:"font-medium leading-tight",children:n.rider_name}),!!((s=n.team_members)!=null&&s.length)&&e.jsx("div",{className:"text-[10px] text-muted-foreground",children:n.team_members.join(" · ")})]}),e.jsx("td",{className:"px-2 py-1.5 text-right font-mono tabular-nums",children:n.laps??0})]}
1,`${n.rider_name}-${a}`)})})]})})]},r)),!(i!=null&&i.is_endurance)&&M.map(([r,l])=>{const n=$[r]??(()=>{let s=0;for(const m of l)for(const d of Object.keys(m.moto_finishes??{})){const h=Number(d);Number.isFinite(h)&&h>s&&(s=h)}return Math.max(s,1)})(),a=Array.from({length:n},(s,m)=>m+1);return e.jsxs("div",{className:"overflow-hidden rounded-md border bg-card",children:[e.jsx("div",{className:"bg-foreground px-3 py-1.5 text-xs font-bold uppercase tracking-wide text-background",children:r}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-muted/50 text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-10 bg-muted/50 px-1.5 py-1.5 text-center",children:c.position}),!x&&e.jsx("th",{className:"px-1.5 py-1.5 text-center",children:c.bib}),e.jsx("th",{className:"px-2 py-1.5 text-left",children:c.racer}),x&&e.jsx("th",{className:"px-2 py-1.5 text-center",children:c.bikeMake||"Make"}),e.jsx("th",{className:"hidden px-2 py-1.5 text-left sm:table-cell",children:"City"}),e.jsx("th",{className:"hidden px-2 py-1.5 text-center sm:table-cell",children:"ST"}),a.map(s=>e.jsxs("th",{className:"px-2 py-1.5 text-center",children:[c.race.charAt(0),s]},s)),e.jsx("th",{className:"px-2 py-1.5 text-right",children:"Pts"})]})}),e.jsx("tbody",{children:l.map((s,m)=>{[s.city,s.state].filter(Boolean).join(", ");const d=a.map(o=>{var b;return((b=s.moto_finishes)==null?void 0:b[String(o)])||""}),h=d.length>0&&d.every(o=>o==="DNS"||o==="");return e.jsxs("tr",{className:"cursor-pointer border-t align-top transition-colors hover:bg-muted/50 focus:bg-muted/50 focus:outline-none",tabIndex:0,role:"button","aria-label":`View ${s.rider_name}'s profile`,onClick:()=>g({rider_id:s.rider_id??null,member_number:s.member_number??null,rider_name:s.rider_name}),onKeyDown:o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),g({rider_id:s.rider_id??null,member_number:s.member_number??null,rider_name:s.rider_name}))},children:[e.jsx("td",{className:"sticky left-0 z-10 bg-card px-1.5 py-1.5 text-center font-semibold",children:h?e.jsx("span",{className:"text-destructive",children:"DNS"}):s.position}),!x&&e.jsx("td",{className:"px-1.5 py-1.5 text-center font-mono",children:s.rider_number??"â"}),e.jsxs("td",{className:"px-2 py-1.5",children:[e.jsx("div",{className:"break-words leading-tight",children:s.rider_name}),e.jsx("div",{className:"text-[10px] text-muted-foreground sm:hidden",children:[s.city,s.state].filter(Boolean).join(", ")||"â"})]}),x&&e.jsx("td",{className:"px-1 py-1.5 text-center",children:e.jsx(X,{make:s.make,bikeNumber:s.rider_number??void 0})}),e.jsx("td",{className:"hidden px-2 py-1.5 sm:table-cell",children:s.city}),e.jsx("td",{className:"hidden px-2 py-1.5 text-center sm:table-cell",children:s.state}),a.map(o=>{var b;return e.jsx("td",{className:"px-2 py-1.5 text-center",children:((b=s.moto_finishes)==null?void 0:b[String(o)])||"â"},o)}),e.jsx("td",{className:"px-2 py-1.5 text-right font-semibold",children:s.points})]},`${s.rider_number}-${m}`)})})]})})]},r)}),e.jsx(G,{identity:S,labEventId:(t==null?void 0:t.id)??null,open:!!S,onOpenChange:r=>{r||g(null)},showMake:x})]})}export{ge 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.