1import{l as q,k as G,b2 as K,r as p,s as Q,j as e,_ as D,S as H,w as P,x as W,y as ee,z as X,X as I,O as te}from"./index-Ct8eLu1I.js";import{u as se}from"./useSelectedTimingEvent-IKCMbW8S.js";import{B as ne}from"./BikeMakeBadge-CLPRnHpn.js";import{u as re}from"./MyRidersFilterContext-B5HDUcVn.js";import{u as ae}from"./useOrganizationSlug-Im1jCHRI.js";import{a as ie}from"./lapOutliers-CZi5QlI6.js";import{T as le}from"./timer-BmWXyNuG.js";import"./TimingSelectionContext-0R53bEzZ.js";import"./useTimingEvents-a-TBF05g.js";import"./useBikeMakeLogos-BM39csav.js";import"./bikeMakeStyle-RND07Se0.js";import"./useRiderFamily-BWVYDRiJ.js";import"./useUserEmails-DmVLOekm.js";import"./nicknameVariants-CT_QG-k6.js";function E(n){const s=String(n??"").trim();return!(!s||s==="0"||s==="--:--"||s==="--:--.--"||s==="00:00:00"||s==="00:00.000")}function N(n){const s=String(n??"").trim();return E(s)?s:"â"}function ce(n){const s=(n??"").trim().replace(",",".");if(!s||s==="â"||s==="--:--"||s==="--:--.--")return null;const a=s.split(":");if(a.length===3){const[c,l,r]=a;return!isFinite(+c)||!isFinite(+l)||!isFinite(+r)?null:(+c*3600+ +l*60+ +r)/3600}if(a.length===2){const[c,l]=a;return!isFinite(+c)||!isFinite(+l)?null:(+c*60+ +l)/3600}return a.length===1&&isFinite(+a[0])?+a[0]/3600:null}function oe(n,s){if(!s||s<=0||!n)return null;const a=ce(n);return a===null||a<=0?null:s/a}function me(n){return q({queryKey:["public-timing-settings",n],queryFn:async()=>{var r;if(!n)return{excludeFirstLap:!1};const s="https://hhkjvpdlkhxblpqzugic.supabase.co",a="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imhoa2p2cGRsa2h4YmxwcXp1Z2ljIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjU0Njk0NjAsImV4cCI6MjA4MTA0NTQ2MH0.lmlLUKecJ7qKzZXJm_BIRvXJm7eizBY-cS543YAeD6Y",c=await fetch(`${s}/functions/v1/get-timing-settings?org_id=${encodeURIComponent(n)}`,{headers:{apikey:a,Authorization:`Bearer ${a}`}});if(!c.ok)return{excludeFirstLap:!1};const l=await c.json();return{excludeFirstLap:!!((r=l==null?void 0:l.results)!=null&&r.exclude_first_lap)}},enabled:!!n,staleTime:6e4})}function M(n){if(!n)return 0;const s=String(n).trim();if(!s)return 0;const a=s.split(":");if(a.length===2){const l=Number(a[0]),r=Number(a[1]);return!Number.isFinite(l)||!Number.isFinite(r)?0:Math.round(l*6e4+r*1e3)}const c=Number(s);return Number.isFinite(c)?Math.round(c*1e3):0}function ve(){const n=G(),s=K(),a=s.bikeMakeColumn,c=s.multiLap,{orgSlug:l,event:r}=se(),{matches:T,active:C}=re(),{data:y}=ae(l),{data:w}=me(y==null?void 0:y.id),B=!!(w!=null&&w.excludeFirstLap),[k,R]=p.useState("ALL"),[Y,V]=p.useState(new Set),Z=i=>{V(o=>{const t=new Set(o);return t.has(i)?t.delete(i):t.add(i),t})},{data:u,isLoading:U}=q({queryKey:["timing-event-lap-times",l,(r==null?void 0:r.id)??(r==null?void 0:r.event_name),k],queryFn:async()=>{if(!l||!(r!=null&&r.id))return{classes:[],groups:{}};const{data:i,error:o}=await Q.functions.invoke("fetch-public-lab-event-lap-times",{body:{org_slug:l,event_name:r.event_name,lab_event_id:r.id,event_date:r.event_date,class_name:k}});if(o)throw o;return i},enabled:!!l&&!!(r!=null&&r.id),refetchInterval:15e3}),_=p.useCallback(i=>ie(i.map(M),B),[B]),v=p.useCallback(i=>{const o=_(i);return o>=0?M(i[o]):0},[_]),F=p.useMemo(()=>{const i=(u==null?void 0:u.groups)??{},o={};for(const[t,x]of Object.entries(i)){const h=C?x.rows.filter(f=>T(f.rider)):x.rows;if(!h.length)continue;const g=[...h].sort((f,m)=>{const b=v(f.laps_arr),d=v(m.laps_arr);return b>0&&d>0?b-d:b>0?-1:d>0?1:0});o[t]={...x,rows:g}}return o},[u,C,T,v]),J=p.useMemo(()=>Object.keys(F),[F]);return U?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(D,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsxs("div",{className:"space-y-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-semibold",children:[n.class,":"]}),e.jsxs(H,{value:k,onValueChange:R,children:[e.jsx(P,{className:"w-56",children:e.jsx(W,{})}),e.jsxs(ee,{children:[e.jsxs(X,{value:"ALL",children:["All ",n.classes]}),((u==null?void 0:u.classes)??[]).map(i=>e.jsx(X,{value:i,children:i},i))]})]})]}),!J.length&&e.jsxs("p",{className:"rounded-md border bg-card p-6 text-center text-sm text-muted-foreground",children:[e.jsx(le,{className:"mx-auto mb-2 h-6 w-6"})," No ",c?"lap":"split"," times yet."]}),J.map(i=>{const o=F[i];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:i.trim()||n.race}),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-2 py-1.5 text-center hidden sm:table-cell",children:n.bib}),a&&e.jsx("th",{className:"px-2 py-1.5 text-center",children:n.bikeMake||"Make"}),e.jsx("th",{className:"px-2 py-1.5 text-left",children:n.racer}),e.jsx("th",{className:"px-2 py-1.5 text-center",children:n.laps}),e.jsx("th",{className:"px-2 py-1.5 text-right whitespace-nowrap",children:"Fast lap"}),e.jsx("th",{className:"px-2 py-1.5 text-right",children:"Time"})]})}),e.jsx("tbody",{children:o.rows.map((t,x)=>{var O;const h=`${i}::${x}::${t.number}::${t.rider}`,g=Y.has(h),f=t.laps_arr.map(M),m=_(t.laps_arr),b=m>=0?f[m]:0,d=t.laps_arr.length>0;return e.jsxs(p.Fragment,{children:[e.jsxs("tr",{className:I("border-t",x%2?"bg-muted/20":"",d&&"cursor-pointer hover:bg-muted/40",g&&"bg-muted/30"),onClick:d?()=>Z(h):void 0,children:[e.jsx("td",{className:"px-2 py-1.5 text-center font-mono hidden sm:table-cell",children:t.number}),a&&e.jsx("td",{className:"px-1 py-1.5 text-center",children:e.jsx(ne,{make:t.make,bikeNumber:t.number?Number(t.
1number):void 0})}),e.jsxs("td",{className:"px-2 py-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.rider,d&&e.jsx(te,{className:I("h-3 w-3 text-muted-foreground transition-transform",g&&"rotate-180")})]}),!!((O=t.team_members)!=null&&O.length)&&e.jsx("div",{className:"text-[10px] text-muted-foreground",children:t.team_members.join(" · ")})]}),e.jsx("td",{className:"px-2 py-1.5 text-center",children:t.laps}),e.jsx("td",{className:"px-2 py-1.5 text-right font-mono font-semibold",children:m>=0?N(t.laps_arr[m]):"â"}),e.jsx("td",{className:"px-2 py-1.5 text-right font-mono",children:N(t.elapsed_time)})]}),g&&d&&e.jsx("tr",{className:"border-t bg-muted/20",children:e.jsxs("td",{colSpan:a?6:5,className:"px-2 py-2 sm:px-4 sm:py-3",children:[e.jsxs("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:[t.class_name," â ",t.motoSelected," · ",t.laps," ",t.laps===1?"lap":"laps",m>=0&&` · best ${N(t.laps_arr[m])}`," · finish ",t.position||"â"]}),e.jsx("div",{className:"overflow-hidden rounded border bg-background",children:e.jsxs("table",{className:"w-full text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-muted/40 text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-2 py-1 text-left",children:n.lap}),e.jsx("th",{className:"px-2 py-1 text-right",children:"Time"}),t.track_length>0&&e.jsx("th",{className:"px-2 py-1 text-right",children:"mph"}),e.jsx("th",{className:"px-2 py-1 text-right",children:"+/-"})]})}),e.jsx("tbody",{children:t.laps_arr.map((S,j)=>{const $=f[j],L=j===m,z=b>0&&$>0?$-b:0,A=E(S)?oe(S,t.track_length):null;return e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"px-2 py-1 font-mono tabular-nums",children:j+1}),e.jsx("td",{className:"px-2 py-1 text-right font-mono tabular-nums",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[N(S),L&&e.jsx("span",{className:"rounded-sm bg-primary/15 px-1 py-px text-[9px] font-bold uppercase tracking-wide text-primary",children:"Best"})]})}),t.track_length>0&&e.jsx("td",{className:"px-2 py-1 text-right font-mono tabular-nums",children:A!==null?A.toFixed(1):"â"}),e.jsx("td",{className:I("px-2 py-1 text-right font-mono tabular-nums",L?"text-muted-foreground":"text-amber-700"),children:L||z<=0?"â":`+${(z/1e3).toFixed(3)}s`})]},j)})})]})})]})})]},h)})})]})})]},i)})]})}export{ve 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.