@pitvox/partner-react 0.7.14 → 0.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("react"),C=require("@tanstack/react-query"),X=b.createContext(null),ss="https://cdn.pitvox.com",ts="https://pitvox.com";let Z=null;function ns({partnerSlug:s=null,cdnUrl:n=ss,pitvoxUrl:t=ts,getSteamId:r,onRegister:a,onWithdraw:i,onFetchNotifications:o,onMarkNotificationRead:c,onMarkAllNotificationsRead:d,onFetchServerPassword:l,children:p}){const h=b.useMemo(()=>({partnerSlug:s,cdnUrl:n.replace(/\/$/,""),pitvoxUrl:t.replace(/\/$/,""),getSteamId:r||(()=>null),onRegister:a||null,onWithdraw:i||null,onFetchNotifications:o||null,onMarkNotificationRead:c||null,onMarkAllNotificationsRead:d||null,onFetchServerPassword:l||null}),[s,n,t,r,a,i,o,c,d,l]);let g=!1;try{C.useQueryClient(),g=!0}catch{g=!1}return g?e.jsx(X.Provider,{value:h,children:p}):(Z||(Z=new C.QueryClient({defaultOptions:{queries:{staleTime:6e4}}})),e.jsx(C.QueryClientProvider,{client:Z,children:e.jsx(X.Provider,{value:h,children:p})}))}function w(){const s=b.useContext(X);if(!s)throw new Error("usePitVox must be used within a <PitVoxPartnerProvider>");return s}async function S(s,n){const t=await fetch(`${s}/${n}`);if(!t.ok){if(t.status===404||t.status===403)return null;throw new Error(`CDN fetch failed: ${t.status}`)}return t.json()}function _(s,n,t,...r){const a=["leaderboards"];return s&&a.push(`partners/${s}`),n&&a.push(n),t&&a.push(`v/${t}`),[...a,...r].join("/")}function he(s,n,t,r){const a=r||"default";return s?`laps/partners/${s}/${n}/${t}/${a}.json`:`laps/${n}/${t}/${a}.json`}function ge(s,n){return s?`laps/partners/${s}/${n}/index.json`:`laps/${n}/index.json`}function je(s){return s?`recent-laps/partners/${s}.json`:"recent-laps.json"}function P(s){if(!s&&s!==0)return"-";const n=Math.floor(s/1e3),t=Math.floor(n/60),r=n%60,a=s%1e3;return`${t}:${String(r).padStart(2,"0")}.${String(a).padStart(3,"0")}`}function D(s){return!s&&s!==0?"-":s>=6e4?P(s):(s/1e3).toFixed(3)}function $(s){if(!s)return"";let n=s;return n.startsWith("ks_")&&(n=n.slice(3)),n.split("_").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function A(s,n,t){if(!s)return"";const r=s.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" "),a=t==="acc"||!t&&(n==null?void 0:n.toLowerCase())==="track config";if(!n||n==="default"||a)return r;const i=n.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ");return`${r} ${i}`}function U(s){if(!s)return"-";try{return new Date(s).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}catch{return"-"}}function ee(s){if(!s)return"";const n=Date.now()-new Date(s).getTime(),t=Math.floor(n/1e3);if(t<60)return"Just now";const r=Math.floor(t/60);if(r<60)return`${r}m ago`;const a=Math.floor(r/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);return i<30?`${i}d ago`:U(s)}function rs(s){return s==null?"":`${s>=0?"+":"-"}${(Math.abs(s)/1e3).toFixed(3)}`}function fe(s,n){const{type:t,title:r,trackId:a,trackLayout:i,carId:o,game:c,data:d}=s,l=typeof d=="string"?JSON.parse(d):d,p=a?A(a,i,c):null,h=o?$(o):null,g=[p,h].filter(Boolean).join(" — ");return t==="RECORD_BEATEN"&&g?`${l!=null&&l.beatenBySteamId&&n?n(l.beatenBySteamId).displayName:"Someone"} beat your record on ${g}`:t==="RECORD_SET"&&g?`You set a new record on ${g}`:r||"New notification"}function se(s){return s?{E:"Eco",RD:"Road",SC:"SuperCar",RV:"Race Vintage",SM:"Semislick",ST:"Street",HR:"Hard Race",MR:"Medium Race",SR:"Soft Race",S:"Soft"}[s]||s:"Unknown"}function te(s){if(!s)return"-";const n=Number(s);return isNaN(n)?"-":n%1?`${n.toFixed(1)}L`:`${n}L`}function as(s={}){var d,l,p,h,g,x;const{cdnUrl:n,partnerSlug:t}=w(),{game:r,gameVersion:a}=s,i=_(t,null,null,"index.json"),o=C.useQuery({queryKey:["pitvox","leaderboards",t,"index"],queryFn:()=>S(n,i),staleTime:3e4,refetchInterval:3e4}),c=b.useMemo(()=>{var v;if(!((v=o.data)!=null&&v.tracks))return[];let N=o.data.tracks;return r&&(N=N.filter(m=>m.game===r)),a&&(N=N.filter(m=>m.gameVersion===a)),N.map(m=>({id:m.trackId,layout:m.layout,game:m.game,gameVersion:m.gameVersion,displayName:A(m.trackId,m.layout,m.game),driverCount:m.driverCount||0,carCount:m.carCount||0,record:m.recordHolder?{visibleId:m.recordHolder.steamId||m.recordHolder.userId,carId:m.recordHolder.carId,carDisplayName:$(m.recordHolder.carId),lapTimeMs:m.recordHolder.lapTimeMs,timestamp:m.recordHolder.recordedAt}:null,recordByTag:m.recordByTag||null}))},[(d=o.data)==null?void 0:d.tracks,r,a]);return{...o,data:c,partner:((l=o.data)==null?void 0:l.partner)||null,generatedAt:(p=o.data)==null?void 0:p.generatedAt,totalLaps:((h=o.data)==null?void 0:h.totalLaps)||0,totalUsers:((g=o.data)==null?void 0:g.totalUsers)||0,versions:((x=o.data)==null?void 0:x.versions)||{}}}function Ne(s,n,t={}){const{cdnUrl:r,partnerSlug:a}=w(),{carId:i,game:o,gameVersion:c}=t,d=n||"default",l=_(a,o,c,`tracks/${s}/${d}.json`),{data:p,isLoading:h,error:g}=C.useQuery({queryKey:["pitvox","leaderboards",a,"track",s,d,o,c],queryFn:()=>S(r,l),enabled:!!s,staleTime:3e4,refetchInterval:3e4});return{data:b.useMemo(()=>{if(!(p!=null&&p.entries))return[];let N=p.entries;if(o&&(N=N.filter(v=>v.game===o)),!i){const v=new Map,m=new Map;for(const j of N){const u=j.steamId||j.userId;m.has(j.carId)||m.set(j.carId,new Set),m.get(j.carId).add(u),(!v.has(j.carId)||j.lapTimeMs<v.get(j.carId).lapTimeMs)&&v.set(j.carId,j)}return Array.from(v.values()).map(j=>{var u;return{...j,driverCount:((u=m.get(j.carId))==null?void 0:u.size)||0}}).sort((j,u)=>j.lapTimeMs-u.lapTimeMs)}return N.filter(v=>v.carId===i).sort((v,m)=>v.lapTimeMs-m.lapTimeMs)},[p==null?void 0:p.entries,i,o]),isLoading:h,error:g}}function be(s,n,t,r,a={}){var v,m;const{cdnUrl:i,partnerSlug:o}=w(),{showInvalid:c=!1,game:d,gameVersion:l}=a,p=s&&n?he(o,s,n,t):null,h=t||"default",g=C.useQuery({queryKey:["pitvox","laps",o,s,n,h],queryFn:()=>S(i,p),enabled:!!s&&!!n,staleTime:3e4,refetchInterval:3e4}),x=b.useMemo(()=>{var j;return(j=g.data)!=null&&j.laps?g.data.laps.filter(u=>!(u.carId!==r||d&&u.game!==d||l&&u.gameVersion!==l||!c&&!u.isValid)).sort((u,y)=>u.lapTimeMs-y.lapTimeMs):[]},[(v=g.data)==null?void 0:v.laps,r,d,l,c]),N=b.useMemo(()=>{const j=x.filter(k=>k.isValid&&k.sector1Ms&&k.sector2Ms&&k.sector3Ms);if(j.length<2)return null;const u=Math.min(...j.map(k=>k.sector1Ms)),y=Math.min(...j.map(k=>k.sector2Ms)),f=Math.min(...j.map(k=>k.sector3Ms)),L=u+y+f,T=Math.min(...j.map(k=>k.lapTimeMs));return L>=T?null:{lapTimeMs:L,sector1Ms:u,sector2Ms:y,sector3Ms:f}},[x]);return{...g,data:x,driverName:((m=g.data)==null?void 0:m.driverName)||"Driver",theoreticalBest:N}}function ne(){const{cdnUrl:s}=w(),{data:n}=C.useQuery({queryKey:["pitvox","users","index"],queryFn:()=>S(s,"users/index.json"),staleTime:5*6e4,gcTime:30*6e4}),t=(n==null?void 0:n.users)||{};return(r,a)=>{const i=t[r];return{displayName:(i==null?void 0:i.displayName)||a||r||"Unknown",avatarUrl:(i==null?void 0:i.avatarUrl)||null,affiliations:(i==null?void 0:i.affiliations)||[]}}}function is(s="evo"){const{cdnUrl:n}=w(),{data:t}=C.useQuery({queryKey:["pitvox","cars",s],queryFn:()=>S(n,`cars/${s}.json`),staleTime:5*6e4,gcTime:30*6e4});return{tags:(t==null?void 0:t.tags)||[],cars:(t==null?void 0:t.cars)||{},categories:(t==null?void 0:t.categories)||[],tagLabels:(t==null?void 0:t.tagLabels)||{}}}function os(){var a,i;const{cdnUrl:s,partnerSlug:n}=w(),t=je(n),r=C.useQuery({queryKey:["pitvox","recentLaps",n],queryFn:()=>S(s,t),staleTime:3e4,refetchInterval:3e4,gcTime:10*6e4});return{groups:((a=r.data)==null?void 0:a.groups)||[],generatedAt:((i=r.data)==null?void 0:i.generatedAt)||null,isLoading:r.isLoading}}function ls(s,n){return Ne(s,null,{carId:n})}function cs(){const{cdnUrl:s,partnerSlug:n}=w();return C.useQuery({queryKey:["pitvox","competitions",n],queryFn:async()=>{const t=await S(s,"competitions/index.json");return t!=null&&t.competitions?n?t.competitions.filter(r=>r.partnerSlug===n):t.competitions:[]},staleTime:6e4})}function re(s,n={}){const t=w(),r=n.partnerSlug||t.partnerSlug;return C.useQuery({queryKey:["pitvox","competition",r,s,"config"],queryFn:()=>S(t.cdnUrl,`competitions/${r}/${s}/config.json`),enabled:!!r&&!!s,staleTime:6e4})}function ae(s,n={}){const t=w(),r=n.partnerSlug||t.partnerSlug;return C.useQuery({queryKey:["pitvox","competition",r,s,"standings"],queryFn:()=>S(t.cdnUrl,`competitions/${r}/${s}/standings.json`),enabled:!!r&&!!s,staleTime:6e4})}function ye(s,n,t={}){const r=w(),a=t.partnerSlug||r.partnerSlug;return C.useQuery({queryKey:["pitvox","competition",a,s,"round",n],queryFn:()=>S(r.cdnUrl,`competitions/${a}/${s}/rounds/${n}.json`),enabled:!!a&&!!s&&n!=null,staleTime:6e4})}function Ce(s,n=[],t={}){const r=w(),a=t.partnerSlug||r.partnerSlug;return C.useQuery({queryKey:["pitvox","competition",a,s,"allRounds",n],queryFn:async()=>(await Promise.all(n.map(o=>S(r.cdnUrl,`competitions/${a}/${s}/rounds/${o}.json`).catch(()=>null)))).filter(Boolean),enabled:!!a&&!!s&&n.length>0,staleTime:6e4})}function ke(s,n={}){const t=w(),r=n.partnerSlug||t.partnerSlug;return C.useQuery({queryKey:["pitvox","competition",r,s,"leaderboard"],queryFn:()=>S(t.cdnUrl,`competitions/${r}/${s}/leaderboard.json`).catch(()=>null),enabled:!!r&&!!s,staleTime:6e4})}function we(s,n,t={}){const r=w(),a=t.partnerSlug||r.partnerSlug;return C.useQuery({queryKey:["pitvox","competition",a,s,"round",n,"laps"],queryFn:()=>S(r.cdnUrl,`competitions/${a}/${s}/rounds/${n}/laps.json`).catch(()=>null),enabled:!!a&&!!s&&n!=null,staleTime:6e4})}function ie(s,n={}){const t=w(),r=n.partnerSlug||t.partnerSlug;return C.useQuery({queryKey:["pitvox","competition",r,s,"entrylist"],queryFn:()=>S(t.cdnUrl,`competitions/${r}/${s}/entrylist.json`),enabled:!!r&&!!s,staleTime:6e4})}function V(s){const{cdnUrl:n,partnerSlug:t,getSteamId:r}=w(),a=r();return C.useQuery({queryKey:["pitvox","registration",t,s,a],queryFn:async()=>{var d;const i=await fetch(`${n}/competitions/${t}/${s}/entrylist.json`);if(!i.ok)return{isRegistered:!1,entryList:null};const o=await i.json();return{isRegistered:!!a&&((d=o.drivers)==null?void 0:d.some(l=>l.steamId===a)),entryList:o}},enabled:!!s,staleTime:6e4})}function oe(s){const{onRegister:n,partnerSlug:t,getSteamId:r}=w(),a=C.useQueryClient(),i=ne();return C.useMutation({mutationFn:o=>{if(!n)throw new Error("No onRegister callback provided to PitVoxPartnerProvider. Provide onRegister for in-app registration, or use useRegistrationUrl() to link to pitvox.com.");return n(s,o)},onSuccess:()=>{const o=r();if(a.setQueriesData({queryKey:["pitvox","registration",t,s]},c=>c?{...c,isRegistered:!0}:{isRegistered:!0,entryList:null}),o){const c=i(o),d={steamId:o,displayName:c.displayName,avatarUrl:c.avatarUrl};a.setQueriesData({queryKey:["pitvox","competition",t,s,"entrylist"]},l=>{var h;return l?((h=l.drivers)==null?void 0:h.some(g=>g.steamId===o))?l:{...l,drivers:[...l.drivers||[],d]}:{drivers:[d]}})}}})}function le(s){const{onWithdraw:n,partnerSlug:t,getSteamId:r}=w(),a=C.useQueryClient();return C.useMutation({mutationFn:i=>{if(!n)throw new Error("No onWithdraw callback provided to PitVoxPartnerProvider. Provide onWithdraw for in-app withdrawal, or use useRegistrationUrl() to link to pitvox.com.");const o=i||r();if(!o)throw new Error("No Steam ID available");return n(s,o)},onSuccess:()=>{const i=r();a.setQueriesData({queryKey:["pitvox","registration",t,s]},o=>o?{...o,isRegistered:!1}:{isRegistered:!1,entryList:null}),i&&a.setQueriesData({queryKey:["pitvox","competition",t,s,"entrylist"]},o=>o!=null&&o.drivers?{...o,drivers:o.drivers.filter(c=>c.steamId!==i)}:o)}})}function K(){const{onRegister:s,onWithdraw:n}=w(),t=!!(s&&n);return{isPowerMode:t,isBasicMode:!t}}function H(s){const{pitvoxUrl:n,partnerSlug:t}=w();return`${n}/p/${t}/competitions/${s}/register`}function ds(s,n){for(const t of n)if(t.tags.includes(s))return t.id;return"other"}function Le(s,n,t=[]){if(n.size===0)return!0;const r={};for(const a of n){const i=ds(a,t);r[i]||(r[i]=[]),r[i].push(a)}for(const a of Object.values(r))if(!a.some(i=>s.includes(i)))return!1;return!0}function Se(s,n){const[t,r]=b.useState(new Set),a=s!==void 0,i=a?s:t,o=b.useCallback(d=>{const l=new Set(i);l.has(d)?l.delete(d):l.add(d),a&&n?n(l):r(l)},[i,a,n]),c=b.useCallback(()=>{a&&n?n(new Set):r(new Set)},[a,n]);return{activeTags:i,toggle:o,clear:c}}function Q(s){const[n,t]=b.useState(s),r=b.useCallback(a=>{t(i=>i.key===a?{key:a,dir:i.dir==="asc"?"desc":"asc"}:{key:a,dir:a.includes("timestamp")||a.includes("Date")?"desc":"asc"})},[]);return[n,r]}function O(s,n,t){return[...s].sort((r,a)=>{const i=t(r,n.key),o=t(a,n.key);if(i==null&&o==null)return 0;if(i==null)return 1;if(o==null)return-1;const c=typeof i=="string"?i.localeCompare(o):i-o;return n.dir==="desc"?-c:c})}function Re(s,n=!1){const t=n?s==null?void 0:s.filter(r=>r.isValid):s;return t!=null&&t.length?{s1:Math.min(...t.map(r=>r.sector1Ms).filter(Boolean)),s2:Math.min(...t.map(r=>r.sector2Ms).filter(Boolean)),s3:Math.min(...t.map(r=>r.sector3Ms).filter(Boolean))}:null}function ps({active:s,dir:n}){return s?n==="asc"?e.jsx("svg",{className:"pvx-sort-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 15.75l7.5-7.5 7.5 7.5"})}):e.jsx("svg",{className:"pvx-sort-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 8.25l-7.5 7.5-7.5-7.5"})}):e.jsx("svg",{className:"pvx-sort-icon pvx-sort-icon--inactive",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 9l4-4 4 4M16 15l-4 4-4-4"})})}function R({label:s,sortKey:n,config:t,onSort:r,className:a=""}){return e.jsx("th",{className:`pvx-th pvx-th--sortable ${a}`,onClick:()=>r(n),children:e.jsxs("span",{className:"pvx-th-inner",children:[s,e.jsx(ps,{active:t.key===n,dir:t.dir})]})})}function W({userId:s,getUserDisplay:n}){const{displayName:t,avatarUrl:r}=n(s);return e.jsxs("span",{className:"pvx-driver",children:[r?e.jsx("img",{src:r,alt:"",className:"pvx-driver-avatar"}):e.jsx("span",{className:"pvx-driver-avatar pvx-driver-avatar--placeholder"}),e.jsx("span",{className:"pvx-driver-name",children:t})]})}function ce({rank:s,podium:n=!1}){const t=n?s===1?"pvx-rank pvx-rank--gold":s===2?"pvx-rank pvx-rank--silver":s===3?"pvx-rank pvx-rank--bronze":"pvx-rank":"pvx-rank";return e.jsx("span",{className:t,children:s})}function Te({availableTags:s,activeTags:n,onToggle:t,onClear:r,categories:a=[],tagLabels:i={}}){if(!s||s.length<2)return null;const o=a.map(c=>({id:c.id,tags:c.tags.filter(d=>s.includes(d))})).filter(c=>c.tags.length>0);return e.jsxs("div",{className:"pvx-tag-bar",children:[e.jsx("button",{onClick:r,className:`pvx-tag ${n.size===0?"pvx-tag--active":""}`,children:"All"}),o.map((c,d)=>e.jsxs("span",{className:"contents",children:[d>0&&e.jsx("span",{className:"pvx-tag-separator"}),c.tags.map(l=>e.jsx("button",{onClick:()=>t(l),className:`pvx-tag ${n.has(l)?"pvx-tag--active":""}`,children:i[l]||l},l))]},c.id))]})}function de({segments:s}){return e.jsx("nav",{className:"pvx-breadcrumb","aria-label":"Breadcrumb",children:e.jsx("ol",{className:"pvx-breadcrumb-list",children:s.map((n,t)=>{const r=t===s.length-1;return e.jsxs("li",{className:"pvx-breadcrumb-item",children:[t>0&&e.jsx("svg",{className:"pvx-breadcrumb-chevron",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.25 4.5l7.5 7.5-7.5 7.5"})}),!r&&n.onClick?e.jsx("button",{onClick:n.onClick,className:"pvx-breadcrumb-link",children:n.label}):e.jsx("span",{className:"pvx-breadcrumb-current",children:n.label})]},n.key)})})})}function F({message:s}){return e.jsxs("div",{className:"pvx-empty",children:[e.jsx("svg",{className:"pvx-empty-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.5 18.75h-9m9 0a3 3 0 013 3h-15a3 3 0 013-3m9 0v-4.5A3.375 3.375 0 0013.125 10.875h-2.25A3.375 3.375 0 007.5 14.25v4.5"})}),e.jsx("p",{children:s})]})}function E(){return e.jsx("div",{className:"pvx-loading",children:"Loading..."})}function xs(){return e.jsx("svg",{className:"pvx-icon pvx-icon--valid",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 12.75l6 6 9-13.5"})})}function us(){return e.jsx("svg",{className:"pvx-icon pvx-icon--invalid",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})}function ms({tracks:s,isLoading:n,carMetadata:t,getUserDisplay:r,onTrackSelect:a,tags:i,onTagChange:o}){const[c,d]=Q({key:"record.timestamp",dir:"desc"}),{activeTags:l,toggle:p,clear:h}=Se(i,o),g=b.useMemo(()=>{var m;if(!((m=t==null?void 0:t.tags)!=null&&m.length))return[];const v=new Set;for(const j of s||[])j.recordByTag&&Object.keys(j.recordByTag).forEach(u=>v.add(u));return t.tags.filter(j=>v.has(j))},[s,t]),x=b.useMemo(()=>s?l.size===0?s:s.map(v=>{var u,y;if(!v.recordByTag)return null;let m=null;const j=new Set;for(const f of Object.values(v.recordByTag)){if(j.has(f.carId))continue;j.add(f.carId);const L=((y=(u=t==null?void 0:t.cars)==null?void 0:u[f.carId])==null?void 0:y.tags)||[];Le(L,l,t==null?void 0:t.categories)&&(!m||f.lapTimeMs<m.lapTimeMs)&&(m=f)}return m?{...v,record:{visibleId:m.steamId||m.identifier,carId:m.carId,carDisplayName:$(m.carId),lapTimeMs:m.lapTimeMs,timestamp:m.recordedAt}}:null}).filter(Boolean):[],[s,l,t]),N=b.useMemo(()=>O(x,c,(v,m)=>{var j,u;switch(m){case"displayName":return v.displayName;case"record.lapTimeMs":return(j=v.record)==null?void 0:j.lapTimeMs;case"driverCount":return v.driverCount||0;case"carCount":return v.carCount||0;case"record.timestamp":default:return(u=v.record)!=null&&u.timestamp?new Date(v.record.timestamp).getTime():0}}),[x,c]);return n?e.jsx(E,{}):s!=null&&s.length?e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx("h2",{className:"pvx-card-title",children:"Track Records"})}),e.jsx(Te,{availableTags:g,activeTags:l,onToggle:p,onClear:h,categories:t==null?void 0:t.categories,tagLabels:t==null?void 0:t.tagLabels}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx(R,{label:"Track",sortKey:"displayName",config:c,onSort:d}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Car"}),e.jsx(R,{label:"Lap Time",sortKey:"record.lapTimeMs",config:c,onSort:d}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:c,onSort:d,className:"pvx-hidden-below-md"}),e.jsx(R,{label:"Cars",sortKey:"carCount",config:c,onSort:d,className:"pvx-hidden-below-lg"}),e.jsx(R,{label:"Date",sortKey:"record.timestamp",config:c,onSort:d,className:"pvx-hidden-below-xl"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:N.map(v=>{var m,j,u;return e.jsxs("tr",{className:"pvx-row pvx-row--clickable",onClick:()=>a(v.id,v.layout),children:[e.jsx("td",{className:"pvx-td pvx-td--primary",children:v.displayName}),e.jsx("td",{className:"pvx-td",children:(m=v.record)!=null&&m.visibleId?e.jsx(W,{userId:v.record.visibleId,getUserDisplay:r}):"-"}),e.jsx("td",{className:"pvx-td pvx-hidden-below-lg",children:((j=v.record)==null?void 0:j.carDisplayName)||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:v.record?P(v.record.lapTimeMs):"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-md",children:v.driverCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:v.carCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:(u=v.record)!=null&&u.timestamp?U(v.record.timestamp):"-"})]},`${v.id}|${v.layout||""}`)})})]})})]}):e.jsx(F,{message:"No lap times recorded yet."})}function vs({entries:s,isLoading:n,track:t,carMetadata:r,getUserDisplay:a,onCarSelect:i,onNavigate:o,tags:c,onTagChange:d}){const[l,p]=Q({key:"lapTimeMs",dir:"asc"}),{activeTags:h,toggle:g,clear:x}=Se(c,d),N=b.useMemo(()=>{var y,f,L;if(!s||!((y=r==null?void 0:r.tags)!=null&&y.length))return[];const u=new Set;for(const T of s)(((L=(f=r.cars)==null?void 0:f[T.carId])==null?void 0:L.tags)||[]).forEach(I=>u.add(I));return r.tags.filter(T=>u.has(T))},[s,r]),v=b.useMemo(()=>s?h.size===0?s:s.filter(u=>{var f,L;const y=((L=(f=r==null?void 0:r.cars)==null?void 0:f[u.carId])==null?void 0:L.tags)||[];return Le(y,h,r==null?void 0:r.categories)}):[],[s,h,r]),m=b.useMemo(()=>O(v,l,(u,y)=>{switch(y){case"carId":return $(u.carId);case"driverCount":return u.driverCount||0;case"lapTimeMs":default:return u.lapTimeMs}}),[v,l]),j=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:t.displayName}];return n?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(de,{segments:j})}),e.jsx(Te,{availableTags:N,activeTags:h,onToggle:g,onClear:x,categories:r==null?void 0:r.categories,tagLabels:r==null?void 0:r.tagLabels}),s!=null&&s.length?e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"#"}),e.jsx(R,{label:"Car",sortKey:"carId",config:l,onSort:p}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:l,onSort:p}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:l,onSort:p,className:"pvx-hidden-below-md"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:m.map((u,y)=>e.jsxs("tr",{className:"pvx-row pvx-row--clickable",onClick:()=>i(u.carId),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ce,{rank:y+1,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:$(u.carId)}),e.jsx("td",{className:"pvx-td",children:e.jsx(W,{userId:u.steamId||u.userId,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:P(u.lapTimeMs)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-md",children:u.driverCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-lg",children:u.recordedAt?U(u.recordedAt):"-"})]},u.carId))})]})}):e.jsx(F,{message:"No lap times for this track yet."})]})}function hs({entries:s,isLoading:n,track:t,carId:r,getUserDisplay:a,onDriverSelect:i,onNavigate:o,highlightId:c}){const[d,l]=Q({key:"lapTimeMs",dir:"asc"}),p=b.useMemo(()=>Re(s),[s]),h=b.useMemo(()=>O(s||[],d,(x,N)=>{switch(N){case"userId":return a(x.steamId||x.userId).displayName;case"lapCount":return x.lapCount||0;case"lapTimeMs":default:return x.lapTimeMs}}),[s,d,a]),g=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:t.displayName,onClick:()=>o("track")},{key:"car",label:$(r)}];return n?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(de,{segments:g})}),s!=null&&s.length?e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"#"}),e.jsx(R,{label:"Driver",sortKey:"userId",config:d,onSort:l}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:d,onSort:l}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Tyre"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Fuel"}),e.jsx(R,{label:"Laps",sortKey:"lapCount",config:d,onSort:l,className:"pvx-hidden-below-lg"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:h.map((x,N)=>{const v=N+1,m=x.steamId||x.userId,j=p&&x.sector1Ms===p.s1,u=p&&x.sector2Ms===p.s2,y=p&&x.sector3Ms===p.s3,f=c&&m===c;return e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${f?"pvx-row--highlight":v<=3?"pvx-row--podium":""}`,onClick:()=>i(m),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ce,{rank:v,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(W,{userId:m,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:P(x.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${j?"pvx-td--best-sector":""}`,children:D(x.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${u?"pvx-td--best-sector":""}`,children:D(x.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${y?"pvx-td--best-sector":""}`,children:D(x.sector3Ms)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:se(x.tyreCompound),children:x.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-xl",children:te(x.startingFuelL)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:x.lapCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:x.recordedAt?U(x.recordedAt):"-"})]},m)})})]})}):e.jsx(F,{message:"No lap times for this car yet."})]})}function gs({userId:s,track:n,carId:t,game:r,gameVersion:a,showInvalid:i,getUserDisplay:o,onToggleInvalid:c,onNavigate:d}){const{data:l,driverName:p,theoreticalBest:h,isLoading:g}=be(s,n.id,n.layout,t,{showInvalid:i,game:r,gameVersion:a}),{displayName:x,avatarUrl:N}=o(s,p),v=b.useMemo(()=>Re(l,!0),[l]),m=b.useMemo(()=>{const u=(l==null?void 0:l.filter(y=>y.isValid))||[];return u.length?Math.min(...u.map(y=>y.lapTimeMs)):null},[l]),j=[{key:"tracks",label:"Tracks",onClick:()=>d("tracks")},{key:"track",label:n.displayName,onClick:()=>d("track")},{key:"car",label:$(t),onClick:()=>d("car")},{key:"driver",label:x}];return g?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header pvx-card-header--split",children:[e.jsxs("div",{className:"pvx-card-header-left",children:[e.jsx(de,{segments:j}),N?e.jsx("img",{src:N,alt:"",className:"pvx-driver-avatar pvx-driver-avatar--lg"}):e.jsx("span",{className:"pvx-driver-avatar pvx-driver-avatar--lg pvx-driver-avatar--placeholder"})]}),e.jsxs("label",{className:"pvx-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:c,className:"pvx-checkbox"}),e.jsx("span",{children:"Show invalid laps"})]})]}),h&&e.jsxs("div",{className:"pvx-theoretical-best",children:[e.jsx("span",{className:"pvx-theoretical-best-label",children:"Theoretical Best:"}),e.jsx("span",{className:"pvx-theoretical-best-time",children:P(h.lapTimeMs)}),e.jsxs("span",{className:"pvx-theoretical-best-sectors",children:["(",D(h.sector1Ms)," + ",D(h.sector2Ms)," + ",D(h.sector3Ms),")"]})]}),l!=null&&l.length?e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"#"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-md",children:"Lap"}),e.jsx("th",{className:"pvx-th",children:"Lap Time"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"}),e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Valid"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Tyre"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Fuel"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:l.map((u,y)=>{const f=u.isValid&&u.lapTimeMs===m,L=v&&u.isValid&&u.sector1Ms===v.s1,T=v&&u.isValid&&u.sector2Ms===v.s2,k=v&&u.isValid&&u.sector3Ms===v.s3;let I="pvx-row";return u.isValid||(I+=" pvx-row--invalid"),f&&(I+=" pvx-row--personal-best"),e.jsxs("tr",{className:I,children:[e.jsx("td",{className:"pvx-td",children:e.jsx("span",{className:`pvx-rank ${f?"pvx-rank--gold":""}`,children:y+1})}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-md",children:u.lapNumber||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:P(u.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${L?"pvx-td--best-sector":""}`,children:D(u.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${T?"pvx-td--best-sector":""}`,children:D(u.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${k?"pvx-td--best-sector":""}`,children:D(u.sector3Ms)}),e.jsx("td",{className:"pvx-td",title:u.isValid?void 0:u.invalidReason||"Invalid",children:u.isValid?e.jsx(xs,{}):e.jsx(us,{})}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:se(u.tyreCompound),children:u.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:te(u.startingFuelL)}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:U(u.timestamp)})]},u.id)})})]})}):e.jsx(F,{message:i?"No laps recorded for this combination.":'No valid laps. Try enabling "Show invalid laps".'})]})}function js({drivers:s,isLoading:n,getUserDisplay:t,game:r,gameVersion:a,onComboSelect:i}){const[o,c]=Q({key:"rank",dir:"asc"}),[d,l]=b.useState(null),p=b.useMemo(()=>s?O(s,o,(g,x)=>{switch(x){case"rating":return g.rating;case"comboCount":return g.comboCount||0;case"distinctCars":return g.distinctCars||0;case"rank":default:return g.rank}}):[],[s,o]);if(n)return e.jsx(E,{});if(!(s!=null&&s.length))return e.jsx("div",{className:"pvx-card",children:e.jsx(F,{message:"Not enough data for rankings yet."})});const h=5;return e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header pvx-rankings-header",children:[e.jsx("h2",{className:"pvx-card-title",children:"Driver Rankings"}),e.jsxs("div",{className:"pvx-rankings-info-trigger",children:[e.jsx("svg",{className:"pvx-rankings-info-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"})}),e.jsxs("div",{className:"pvx-rankings-info-tooltip",children:[e.jsx("p",{className:"pvx-rankings-info-title",children:"How ratings work"}),e.jsxs("ul",{className:"pvx-rankings-info-list",children:[e.jsx("li",{children:"For each car/track combo with 3+ drivers, you're ranked by lap time and given a percentile (100 = fastest, 0 = slowest)"}),e.jsx("li",{children:"Your rating is a weighted average across all your combos — bigger fields count more"}),e.jsx("li",{children:"A confidence adjustment rewards car diversity: the more different cars you drive competitively, the closer your rating reflects your true score"}),e.jsx("li",{children:"Minimum 2 qualifying combos required"})]})]})]})]}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx(R,{label:"#",sortKey:"rank",config:o,onSort:c,className:"pvx-th--narrow"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx(R,{label:"Rating",sortKey:"rating",config:o,onSort:c}),e.jsx(R,{label:"Cars",sortKey:"distinctCars",config:o,onSort:c,className:"pvx-hidden-below-sm"}),e.jsx(R,{label:"Combos",sortKey:"comboCount",config:o,onSort:c,className:"pvx-hidden-below-sm"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:p.map(g=>{const x=d===g.identifier;return e.jsx(fs,{driver:g,getUserDisplay:t,isExpanded:x,onToggle:()=>l(x?null:g.identifier),colCount:h,game:r,gameVersion:a,onComboSelect:i},g.identifier)})})]})})]})}function fs({driver:s,getUserDisplay:n,isExpanded:t,onToggle:r,colCount:a,game:i,gameVersion:o,onComboSelect:c}){const d=s.identifier;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${s.rank<=3?"pvx-row--podium":""}`,onClick:r,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ce,{rank:s.rank,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(W,{userId:d,getUserDisplay:n})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:s.rating.toFixed(1)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:s.distinctCars||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:e.jsxs("span",{className:"pvx-rankings-combo-count",children:[s.comboCount,e.jsx("svg",{className:`pvx-rankings-chevron ${t?"pvx-rankings-chevron--open":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})})]}),t&&s.combos&&e.jsx("tr",{children:e.jsx("td",{colSpan:a,className:"pvx-rankings-combos-cell",children:e.jsx("div",{className:"pvx-rankings-combos",children:s.combos.map((l,p)=>{const h=l.layout?`${l.trackId}|${l.layout}`:l.trackId,g=c?()=>c({track:h,car:l.carId,highlight:d,game:i,gameVersion:o}):void 0;return e.jsxs("div",{className:`pvx-rankings-combo ${g?"pvx-rankings-combo--clickable":""}`,onClick:g,role:g?"button":void 0,children:[e.jsxs("div",{className:"pvx-rankings-combo-info",children:[e.jsx("p",{className:"pvx-rankings-combo-track",children:A(l.trackId,l.layout,i)}),e.jsx("p",{className:"pvx-rankings-combo-car",children:$(l.carId)})]}),e.jsxs("div",{className:"pvx-rankings-combo-stats",children:[e.jsx("p",{className:"pvx-rankings-combo-time",children:P(l.lapTimeMs)}),e.jsxs("p",{className:`pvx-rankings-combo-pct ${l.percentile>=75?"pvx-rankings-combo-pct--high":l.percentile>=50?"pvx-rankings-combo-pct--mid":l.percentile>=25?"pvx-rankings-combo-pct--low":"pvx-rankings-combo-pct--bottom"}`,children:[l.percentile.toFixed(0),"%",e.jsxs("span",{className:"pvx-rankings-combo-rank",children:["(",l.rank,"/",l.totalDrivers,")"]})]})]})]},p)})})})})]})}const Ns={GBR:"🇬🇧",DEU:"🇩🇪",NLD:"🇳🇱",SWE:"🇸🇪",ESP:"🇪🇸",ZAF:"🇿🇦",FRA:"🇫🇷",ITA:"🇮🇹",USA:"🇺🇸",AUS:"🇦🇺",BRA:"🇧🇷",JPN:"🇯🇵",CAN:"🇨🇦",POL:"🇵🇱",AUT:"🇦🇹",BEL:"🇧🇪",PRT:"🇵🇹",NOR:"🇳🇴",DNK:"🇩🇰",FIN:"🇫🇮",IRL:"🇮🇪",CHE:"🇨🇭",NZL:"🇳🇿",MEX:"🇲🇽",ARG:"🇦🇷",CZE:"🇨🇿",HUN:"🇭🇺",RUS:"🇷🇺",TUR:"🇹🇷",KOR:"🇰🇷"},z=["🥇","🥈","🥉"],bs={championship:"Championship",series:"Series",event:"Event",hotlap:"Hotlap"},ys=["PRACTICE","QUALIFYING","RACE"];function me(s){const n=ys.indexOf(s);if(n>=0)return n;const t=s.match(/^PRACTICE_(\d+)$/);return t?100+parseInt(t[1]):999}function G(s){const n=s.match(/^PRACTICE_(\d+)$/);return n?`P${n[1]}`:s}function pe({position:s}){const n=s===1?"pvx-rank pvx-rank--gold":s===2?"pvx-rank pvx-rank--silver":s===3?"pvx-rank pvx-rank--bronze":"pvx-rank";return e.jsx("span",{className:n,children:s})}function Y({nation:s}){const n=s&&Ns[s];return n?e.jsx("span",{className:"pvx-nation-flag",title:s,children:n}):null}function Cs({sessions:s,activeSession:n,onSelect:t}){if(!s||s.length<=1)return null;const r=[...s].sort((a,i)=>me(a.type)-me(i.type));return e.jsx("div",{className:"pvx-session-tabs",children:r.map(a=>e.jsx("button",{onClick:()=>t(a.type),className:`pvx-session-tab ${n===a.type?"pvx-session-tab--active":""}`,children:G(a.type)},a.type))})}function $e({type:s}){return e.jsx("span",{className:`pvx-comp-badge pvx-comp-badge--${s}`,children:bs[s]||s})}function q({children:s,variant:n="default"}){return e.jsx("span",{className:`pvx-info-pill ${n!=="default"?`pvx-info-pill--${n}`:""}`,children:s})}function ks(s){if(!s)return"TBD";const n=new Date(s);if(isNaN(n))return"TBD";const t=n.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),r=n.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return`${t} • ${r}`}function ws(s){return s.reduce((n,t)=>{var r;return(r=t.splits)!=null&&r.length?n?n.map((a,i)=>{const o=t.splits[i];return o&&o<a?o:a}):[...t.splits]:n},null)}function B({message:s="Loading..."}){return e.jsx("div",{className:"pvx-loading",children:s})}function M({message:s="No data available."}){return e.jsx("div",{className:"pvx-empty",children:e.jsx("p",{children:s})})}const xe=3;function Me(s){const n=s==null?void 0:s.rounds;return n!=null&&n.length?s.type==="hotlap"?n.every(t=>t.isFinalized&&t.dediStatus==="completed"):n.every(t=>t.isFinalized):!1}function De(s){const n=s==null?void 0:s.rounds;if(!(n!=null&&n.length))return null;let t=null;for(const r of n){if(!r.startTime)continue;const a=new Date(r.startTime);isNaN(a)||(!t||a>t)&&(t=a)}return t}function ue(s,n=xe){if(!Me(s))return"active";const t=De(s);if(!t)return"recently-completed";const r=n*24*60*60*1e3;return Date.now()-t.getTime()<=r?"recently-completed":"archived"}function Ls(s,n,t=xe){if(!(s!=null&&s.length))return[];const r=new Set(Array.isArray(n)?n:[n]);return s.filter(a=>r.has(ue(a,t)))}function Pe(s,n=3){const t=s==null?void 0:s.standings;return Array.isArray(t)?[...t].sort((r,a)=>(r.position??999)-(a.position??999)).slice(0,n):[]}function Ie({competitionId:s,topN:n=3,label:t="Completed",className:r}){const{data:a}=ae(s),i=Pe(a,n);return e.jsxs("div",{className:`pvx-comp-completed-badge ${r||""}`,children:[e.jsx("span",{className:"pvx-comp-completed-badge-label",children:t}),i.length>0&&e.jsx("ol",{className:"pvx-comp-completed-badge-podium",children:i.map((o,c)=>e.jsxs("li",{className:"pvx-comp-completed-badge-driver",children:[e.jsx("span",{className:"pvx-comp-completed-badge-medal","aria-hidden":"true",children:z[c]||""}),e.jsx(Y,{nation:o.nation}),e.jsx("span",{className:"pvx-comp-completed-badge-name",children:o.driverName})]},o.driverId||c))})]})}function Ss({competitions:s,isLoading:n,onSelect:t,onRegister:r,className:a}){return n?e.jsx(B,{message:"Loading competitions..."}):s!=null&&s.length?e.jsx("div",{className:`pvx-comp-grid ${a||""}`,children:s.map(i=>e.jsx(Be,{comp:i,onSelect:t,onRegister:r||t},i.id))}):e.jsx(M,{message:"No competitions available."})}function Be({comp:s,onSelect:n,onRegister:t}){var u,y,f;const{cdnUrl:r}=w(),a=s.posterCdnPath?`${r}/${s.posterCdnPath}`:null,i=s.registration,o=(i==null?void 0:i.currentCount)||0,c=i==null?void 0:i.maxParticipants,d=c&&o>=c,l=(i==null?void 0:i.deadline)&&new Date(i.deadline)<new Date,p=(i==null?void 0:i.isOpen)&&!l&&!d,h=new Date,g=(u=s.rounds)==null?void 0:u.find(L=>L.startTime&&new Date(L.startTime)>=h),x=((y=s.rounds)==null?void 0:y.length)||0,N=((f=s.rounds)==null?void 0:f.filter(L=>L.isFinalized).length)||0,v=ue(s),m=v==="recently-completed"||v==="archived",j=s.type==="championship";return e.jsxs("div",{className:"pvx-comp-card",onClick:()=>n(s.id),role:"button",tabIndex:0,onKeyDown:L=>{(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),n(s.id))},children:[e.jsx("div",{className:"pvx-comp-card-poster",children:a?e.jsx("img",{src:a,alt:s.name,className:"pvx-comp-card-poster-img"}):e.jsx("div",{className:"pvx-comp-card-poster-placeholder",children:e.jsx(Ts,{})})}),e.jsxs("div",{className:"pvx-comp-card-body",children:[e.jsx("h3",{className:"pvx-comp-card-title",children:s.name}),s.description&&e.jsx("p",{className:"pvx-comp-card-desc",children:s.description}),e.jsxs("div",{className:"pvx-comp-card-pills",children:[e.jsx($e,{type:s.type}),s.game&&e.jsx(q,{children:s.game.toUpperCase()}),s.formatDescription&&s.formatDescription.split(", ").map((L,T)=>e.jsx(q,{variant:"format",children:L},T))]}),s.carsDescription&&e.jsx("div",{className:"pvx-comp-card-pills",children:s.carsDescription.split(", ").map((L,T)=>e.jsx(q,{children:L},T))}),e.jsxs("div",{className:"pvx-comp-card-schedule",children:[g?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[e.jsx("span",{className:"pvx-comp-card-schedule-label",children:"Next:"})," ",s.type!=="hotlap"&&`R${g.roundNumber} `,g.track||"TBD"," · ",ks(g.startTime)]}):x>0?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[N,"/",x," rounds completed"]}):null,x>0&&e.jsxs("span",{className:"pvx-comp-card-round-count",children:[x," round",x!==1?"s":""]})]}),m&&j&&e.jsx(Ie,{competitionId:s.id}),i&&!m&&e.jsx(Rs,{competitionId:s.id,regOpen:p,isFull:d,deadlinePassed:l,regCount:o,regMax:c,onRegister:t})]})]})}function Rs({competitionId:s,regOpen:n,isFull:t,deadlinePassed:r,regCount:a,regMax:i,onRegister:o}){const{isPowerMode:c}=K(),d=H(s),{data:l}=V(s),p=(l==null?void 0:l.isRegistered)||!1,h=i?a/i*100:0,g=h>=100?"full":h>=75?"warning":"ok";return e.jsxs("div",{className:"pvx-comp-card-reg",children:[e.jsx("div",{className:"pvx-comp-card-reg-info",children:e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${g}`,children:[a,"/",i||"∞"," drivers"]})}),e.jsx("div",{className:"pvx-comp-card-reg-action",children:p?e.jsx("button",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--registered",onClick:x=>{x.stopPropagation(),o(s)},children:"✓ Registered"}):n?c?e.jsx("button",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--open",onClick:x=>{x.stopPropagation(),o(s)},children:"Register"}):e.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--open",onClick:x=>x.stopPropagation(),children:"Register"}):e.jsx("span",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--closed",children:t?"Full":"Closed"})})]})}function Ts(){return e.jsxs("svg",{className:"pvx-comp-trophy-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 0 1 0-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 0 0 0-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0 0 12 0V2Z"})]})}function Ae({competitionId:s,className:n}){var c,d;const{data:t,isLoading:r}=ae(s),{data:a,isLoading:i}=re(s);if(r||i)return e.jsx(B,{message:"Loading standings..."});if(!((c=t==null?void 0:t.standings)!=null&&c.length))return e.jsx(M,{message:"No standings data yet. Results will appear once rounds are finalised."});const o=((d=a==null?void 0:a.rounds)==null?void 0:d.filter(l=>l.isFinalized))||[];return e.jsxs("div",{className:`pvx-card ${n||""}`,children:[e.jsx("div",{className:"pvx-card-header--split",children:e.jsxs("div",{className:"pvx-card-header-left",children:[e.jsx("h3",{className:"pvx-card-title",children:"Championship Standings"}),e.jsxs("span",{className:"pvx-standings-subtitle",children:["After ",t.roundsCompleted," round",t.roundsCompleted!==1?"s":"",t.countingRounds>0&&` (best ${t.countingRounds} count)`]})]})}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"W"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"Pod"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"}),o.map(l=>e.jsxs("th",{className:"pvx-th pvx-th--center pvx-hidden-below-md",title:l.track||`Round ${l.roundNumber}`,children:["R",l.roundNumber]},l.roundNumber))]})}),e.jsx("tbody",{className:"pvx-tbody",children:t.standings.map(l=>e.jsx($s,{driver:l,finalizedRounds:o},l.driverId||l.driverName))})]})})]})}function $s({driver:s,finalizedRounds:n}){var o,c,d;const t=s.position<=3,r=new Map(((o=s.roundResults)==null?void 0:o.map(l=>[l.roundNumber,l]))||[]),a=((c=s.roundResults)==null?void 0:c.filter(l=>l.position===1).length)||0,i=((d=s.roundResults)==null?void 0:d.filter(l=>l.position<=3).length)||0;return e.jsxs("tr",{className:`pvx-row ${t?"pvx-row--podium":""}`,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(pe,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(Y,{nation:s.nation}),s.driverName]}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:a||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:i||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-standings-total",children:s.totalPoints}),n.map(l=>{const p=r.get(l.roundNumber),h=p==null?void 0:p.dropped;return e.jsx("td",{className:`pvx-td pvx-td--center pvx-hidden-below-md ${!h&&(p==null?void 0:p.position)===1?"pvx-standings-cell--p1":!h&&(p==null?void 0:p.position)===2?"pvx-standings-cell--p2":!h&&(p==null?void 0:p.position)===3?"pvx-standings-cell--p3":""}`,children:p?e.jsxs("div",{className:`pvx-standings-round-cell ${h?"pvx-standings-round-cell--dropped":""}`,children:[e.jsxs("span",{className:"pvx-standings-round-pos",children:["P",p.position]}),e.jsx("span",{className:"pvx-standings-round-pts",children:p.points})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})},l.roundNumber)})]})}function Ms({competitionId:s,roundNumber:n,className:t}){var d;const{data:r,isLoading:a}=ye(s,n);if(a)return e.jsx(B,{message:"Loading results..."});if(!r)return e.jsx(M,{message:"No results for this round."});const o=(r.sessions||[]).find(l=>l.type==="RACE"),c=(d=o==null?void 0:o.results)==null?void 0:d.filter(l=>l.position<=3).sort((l,p)=>l.position-p.position);return e.jsxs("div",{className:`pvx-round-results ${t||""}`,children:[e.jsxs("div",{className:"pvx-round-results-header",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"pvx-round-results-title",children:["Round ",r.roundNumber,r.track?`: ${r.track}`:""]}),r.startTime&&e.jsx("p",{className:"pvx-round-results-date",children:new Date(r.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(c==null?void 0:c.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:c.map(l=>e.jsxs("span",{className:"pvx-round-podium-item",children:[e.jsx("span",{children:z[l.position-1]}),e.jsx("span",{children:l.driverName})]},l.driverId))})]}),e.jsx(J,{round:r,competitionId:s})]})}function J({round:s,competitionId:n,className:t}){var p,h,g,x;const[r,a]=b.useState(null),i=(s==null?void 0:s.sessions)||[];if(!i.length)return e.jsx(M,{message:"No session data for this round."});const{data:o}=we(n,s==null?void 0:s.roundNumber,{}),c=r||((p=i.find(N=>N.type==="RACE"))==null?void 0:p.type)||((h=i[0])==null?void 0:h.type),d=i.find(N=>N.type===c)||i[0],l=((x=(g=o==null?void 0:o.sessions)==null?void 0:g.find(N=>N.type===c))==null?void 0:x.drivers)||null;return e.jsxs("div",{className:t||"",children:[e.jsx(Cs,{sessions:i,activeSession:c,onSelect:a}),e.jsx(Ds,{session:d,sessionLaps:l})]})}function Ds({session:s,sessionLaps:n}){var c;const t=s.type==="RACE",[r,a]=b.useState(null);if(!((c=s.results)!=null&&c.length))return e.jsx(M,{message:`No results for ${s.type}.`});const i=ws(s.results),o=t?7:4;return e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Car"}),e.jsx("th",{className:"pvx-th",children:"Best Lap"}),t&&e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Laps"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Time / Gap"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"})]})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.results.map((d,l)=>{var g;const p=(g=n==null?void 0:n[d.driverId])==null?void 0:g.laps,h=r===d.driverId&&!!p;return e.jsx(Ps,{result:d,isRace:t,fastestSplits:i,rowIndex:l,hasLapDetail:!!p,isExpanded:h,onToggle:()=>a(h?null:d.driverId),driverLaps:h?p:null,colCount:o},d.driverId||l)})})]})})}function Ps({result:s,isRace:n,fastestSplits:t,rowIndex:r,hasLapDetail:a,isExpanded:i,onToggle:o,driverLaps:c,colCount:d}){const l=s.position<=3;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row ${l?"pvx-row--podium":""} ${a?"pvx-row--expandable":""}`,onClick:a?o:void 0,style:a?{cursor:"pointer"}:void 0,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(pe,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(Y,{nation:s.nation}),s.driverName,s.carNumber!=null&&e.jsxs("span",{className:"pvx-car-number",children:["#",s.carNumber]}),s.penalty&&e.jsx("span",{className:"pvx-penalty",children:s.penalty})]}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:$(s.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx(Bs,{bestLap:s.bestLapFormatted,hasBestLap:s.hasBestLap,splits:s.splits,fastestSplits:t,showAbove:r<=1})}),n&&e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:s.lapsCompleted}),e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:s.position===1?s.totalTime||"-":s.gap||"-"}),e.jsxs("td",{className:"pvx-td pvx-td--center",children:[e.jsx("span",{className:"pvx-session-points",children:s.points}),s.pointsOverride!==0&&s.pointsOverride&&e.jsxs("span",{className:"pvx-points-override",children:["(",s.pointsOverride>0?"+":"",s.pointsOverride,")"]})]})]})]}),i&&c&&e.jsx("tr",{className:"pvx-row pvx-row--lap-detail",children:e.jsx("td",{colSpan:d,className:"pvx-td pvx-td--lap-detail",children:e.jsx(Is,{laps:c})})})]})}function Is({laps:s}){const n=Math.min(...s.filter(t=>t.valid&&t.timeMs>0).map(t=>t.timeMs));return e.jsxs("table",{className:"pvx-table pvx-table--laps",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Lap"}),e.jsx("th",{className:"pvx-th",children:"Time"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.map(t=>{var a;const r=t.valid&&t.timeMs===n;return e.jsxs("tr",{className:`pvx-row ${t.valid?"":"pvx-row--invalid"} ${r?"pvx-row--fastest":""}`,children:[e.jsx("td",{className:"pvx-td pvx-td--muted",children:t.lap}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:t.time}),(t.splits||[]).map((i,o)=>e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:i},o)),Array.from({length:Math.max(0,3-(((a=t.splits)==null?void 0:a.length)||0))}).map((i,o)=>e.jsx("td",{className:"pvx-td pvx-hidden-below-sm"},`pad-${o}`))]},t.lap)})})]})}function Bs({bestLap:s,hasBestLap:n,splits:t,fastestSplits:r,showAbove:a}){return s?e.jsxs("span",{className:`pvx-best-lap-cell ${n?"pvx-best-lap-cell--fastest":""}`,children:[e.jsx("span",{className:"pvx-best-lap-time",children:s}),(t==null?void 0:t.length)>0&&e.jsx("span",{className:"pvx-splits-tooltip-anchor",children:e.jsx("span",{className:`pvx-splits-tooltip ${a?"":"pvx-splits-tooltip--above"}`,children:t.map((i,o)=>{const c=r&&i===r[o];return e.jsxs("span",{className:"pvx-splits-tooltip-row",children:[e.jsxs("span",{className:"pvx-splits-tooltip-label",children:["S",o+1]}),e.jsx("span",{className:c?"pvx-splits-tooltip-best":"",children:i})]},o)})})})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})}function As({competitionId:s,className:n}){const{getSteamId:t}=w(),{data:r,isLoading:a}=ie(s),i=t();if(a)return e.jsx(B,{message:"Loading drivers..."});const o=(r==null?void 0:r.drivers)||(r==null?void 0:r.entries)||[];return o.length?e.jsx("div",{className:`pvx-entry-grid ${n||""}`,children:o.map(c=>{var l,p;const d=i&&c.steamId===i;return e.jsxs("div",{className:`pvx-entry-card ${d?"pvx-entry-card--you":""}`,children:[c.avatarUrl?e.jsx("img",{src:c.avatarUrl,alt:"",className:"pvx-entry-avatar"}):e.jsx("div",{className:"pvx-entry-avatar pvx-entry-avatar--placeholder",children:((p=(l=c.displayName)==null?void 0:l.charAt(0))==null?void 0:p.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-entry-name",children:[c.displayName,d&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},c.steamId||c.driverId)})}):e.jsx(M,{message:"No drivers registered yet."})}function Us({competitionId:s,driverData:n,className:t,children:r}){const{data:a,isLoading:i}=V(s),{isPowerMode:o}=K(),c=H(s),d=oe(s),l=le(s),p=(a==null?void 0:a.isRegistered)||!1,h=i||d.isPending||l.isPending,g=d.error||l.error||null,x=()=>{o&&d.mutate(n||{})},N=()=>{o&&l.mutate()};return typeof r=="function"?r({isRegistered:p,isLoading:h,register:x,withdraw:N,error:g,isPowerMode:o,registrationUrl:c}):o?e.jsx("button",{className:`pvx-comp-register-btn ${t||""}`,onClick:p?N:x,disabled:h,children:h?"Loading...":p?"Withdraw":"Register"}):e.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:`pvx-comp-register-link ${t||""}`,children:p?"View Registration":"Register on PitVox"})}function Fs({competitionId:s,registration:n,onWithdrawSuccess:t,className:r}){const{getSteamId:a}=w(),{isPowerMode:i}=K(),o=H(s),{data:c,isLoading:d}=V(s),{data:l,isLoading:p}=ie(s),h=oe(s),g=le(s),x=a(),N=(c==null?void 0:c.isRegistered)||!1,v=(l==null?void 0:l.drivers)||(l==null?void 0:l.entries)||[],m=n||{},j=v.length||m.currentCount||0,u=m.maxParticipants&&j>=m.maxParticipants,y=m.deadline&&new Date(m.deadline)<new Date,f=m.isOpen&&!y&&!u;return d||p?e.jsx(B,{message:"Loading registration..."}):N?e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx(qs,{competitionId:s,drivers:v,steamId:x,isPowerMode:i,registrationUrl:o,withdrawMutation:g,onWithdrawSuccess:t,registration:m})}):f?x?i?e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx(Es,{competitionId:s,registerMutation:h,registration:m})}):e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Register on PitVox"})}):e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:i?e.jsx("div",{className:"pvx-reg-status-msg",children:"Sign in to register for this competition."}):e.jsx("div",{className:"pvx-reg-status-msg",children:e.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Register on PitVox"})})}):e.jsxs("div",{className:`pvx-reg-panel ${r||""}`,children:[e.jsx("div",{className:"pvx-reg-status-msg",children:u?"Registration is full.":y?"Registration deadline has passed.":"Registration is closed."}),v.length>0&&e.jsx(Ue,{drivers:v,steamId:x})]})}function Es({competitionId:s,registerMutation:n,registration:t}){const[r,a]=b.useState(""),[i,o]=b.useState("intermediate"),[c,d]=b.useState(""),l=x=>{x.preventDefault(),n.mutate({discordUsername:r||void 0,experience:i,comments:c||void 0})},p=t||{},h=p.currentCount||0,g=p.maxParticipants;return e.jsxs("form",{className:"pvx-reg-form",onSubmit:l,children:[e.jsxs("div",{className:"pvx-reg-form-header",children:[e.jsx("h3",{className:"pvx-reg-form-title",children:"Register"}),g&&e.jsx(Fe,{count:h,max:g})]}),n.error&&e.jsx("div",{className:"pvx-reg-error",children:n.error.message||"Registration failed"}),e.jsxs("div",{className:"pvx-reg-field",children:[e.jsxs("label",{className:"pvx-reg-label",htmlFor:`pvx-discord-${s}`,children:["Discord Username ",e.jsx("span",{className:"pvx-reg-optional",children:"(optional)"})]}),e.jsx("input",{id:`pvx-discord-${s}`,type:"text",className:"pvx-reg-input",placeholder:"e.g. username",value:r,onChange:x=>a(x.target.value)})]}),e.jsxs("div",{className:"pvx-reg-field",children:[e.jsx("label",{className:"pvx-reg-label",htmlFor:`pvx-exp-${s}`,children:"Experience Level"}),e.jsxs("select",{id:`pvx-exp-${s}`,className:"pvx-reg-select",value:i,onChange:x=>o(x.target.value),children:[e.jsx("option",{value:"beginner",children:"Beginner"}),e.jsx("option",{value:"intermediate",children:"Intermediate"}),e.jsx("option",{value:"advanced",children:"Advanced"})]})]}),e.jsxs("div",{className:"pvx-reg-field",children:[e.jsxs("label",{className:"pvx-reg-label",htmlFor:`pvx-comments-${s}`,children:["Comments ",e.jsx("span",{className:"pvx-reg-optional",children:"(optional)"})]}),e.jsx("textarea",{id:`pvx-comments-${s}`,className:"pvx-reg-textarea",rows:3,placeholder:"Anything the organisers should know?",value:c,onChange:x=>d(x.target.value)})]}),e.jsx("div",{className:"pvx-reg-actions",children:e.jsx("button",{type:"submit",className:"pvx-comp-register-btn",disabled:n.isPending,children:n.isPending?"Registering...":"Register"})})]})}function qs({competitionId:s,drivers:n,steamId:t,isPowerMode:r,registrationUrl:a,withdrawMutation:i,onWithdrawSuccess:o,registration:c}){const[d,l]=b.useState(!1),p=()=>{i.mutate(void 0,{onSuccess:()=>{l(!1),o&&o()}})},h=c||{},g=n.length||h.currentCount||0,x=h.maxParticipants;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pvx-reg-form-header",children:[e.jsx("h3",{className:"pvx-reg-form-title",children:"Registered Drivers"}),x&&e.jsx(Fe,{count:g,max:x})]}),e.jsx(Ue,{drivers:n,steamId:t}),i.error&&e.jsx("div",{className:"pvx-reg-error",children:i.error.message||"Withdrawal failed"}),r?e.jsx("div",{className:"pvx-reg-actions",children:d?e.jsxs("div",{className:"pvx-reg-confirm",children:[e.jsx("p",{className:"pvx-reg-confirm-text",children:"Are you sure you want to unregister?"}),e.jsxs("div",{className:"pvx-reg-confirm-actions",children:[e.jsx("button",{type:"button",className:"pvx-reg-cancel-btn",onClick:()=>l(!1),children:"Cancel"}),e.jsx("button",{type:"button",className:"pvx-reg-danger-btn",onClick:p,disabled:i.isPending,children:i.isPending?"Unregistering...":"Yes, Unregister"})]})]}):e.jsx("button",{type:"button",className:"pvx-reg-unregister-btn",onClick:()=>l(!0),children:"Unregister"})}):e.jsx("div",{className:"pvx-reg-actions",children:e.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Manage on PitVox"})})]})}function Ue({drivers:s,steamId:n}){if(!s.length)return e.jsx("div",{className:"pvx-reg-no-drivers",children:"No drivers registered yet."});const t=[...s].sort((r,a)=>{const i=n&&r.steamId===n?-1:0,o=n&&a.steamId===n?-1:0;return i-o});return e.jsx("div",{className:"pvx-reg-driver-list",children:t.map(r=>{var i,o;const a=n&&r.steamId===n;return e.jsxs("div",{className:`pvx-reg-driver-row ${a?"pvx-reg-driver-row--you":""}`,children:[r.avatarUrl?e.jsx("img",{src:r.avatarUrl,alt:"",className:"pvx-reg-driver-avatar"}):e.jsx("div",{className:"pvx-reg-driver-avatar pvx-reg-driver-avatar--placeholder",children:((o=(i=r.displayName)==null?void 0:i.charAt(0))==null?void 0:o.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-reg-driver-name",children:[r.displayName,a&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},r.steamId||r.driverId)})})}function Fe({count:s,max:n}){const t=n?s/n*100:0,r=t>=100?"full":t>=75?"warning":"ok";return e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${r}`,children:[s,"/",n," drivers"]})}function _s({competitionId:s,className:n}){const{data:t,isLoading:r}=re(s),a=(t==null?void 0:t.type)==="championship",i=(t==null?void 0:t.type)==="hotlap",{data:o}=ke(i?s:null),c=b.useMemo(()=>{var f;return((f=t==null?void 0:t.rounds)==null?void 0:f.filter(L=>L.isFinalized))||[]},[t]),d=b.useMemo(()=>c.map(f=>f.roundNumber),[c]),{data:l=[],isLoading:p}=Ce(s,d),h=i&&l.length>0?l[0]:null,g=(h==null?void 0:h.sessions)||[],x=i?"leaderboard":a?"standings":d.length>0?`round-${d[d.length-1]}`:null,[N,v]=b.useState(null),m=N||x;if(r||p)return e.jsx(B,{message:"Loading results..."});if(!t)return e.jsx(M,{message:"Competition not found."});if(!c.length)return e.jsx(M,{message:"No results available yet. Results will appear here once rounds are finalised."});const j=new Map(l.map(f=>[`round-${f.roundNumber}`,f])),u=[];if(a&&u.push({id:"standings",label:"Standings"}),i){u.push({id:"leaderboard",label:"Leaderboard"});for(const f of g)u.push({id:`session-${f.type}`,label:G(f.type)})}else for(const f of c)u.push({id:`round-${f.roundNumber}`,label:`R${f.roundNumber}`,track:null});const y=j.get(m);return e.jsxs("div",{className:n||"",children:[e.jsx("div",{className:"pvx-results-tabs",children:u.map(f=>e.jsxs("button",{className:`pvx-results-tab ${m===f.id?"pvx-results-tab--active":""}`,onClick:()=>v(f.id),title:f.track||void 0,children:[e.jsx("span",{className:"pvx-results-tab-label",children:f.label}),f.track&&e.jsx("span",{className:"pvx-results-tab-track",children:f.track})]},f.id))}),m==="standings"?e.jsx(Ae,{competitionId:s}):m==="leaderboard"?e.jsx(Ks,{leaderboard:o,config:t}):m!=null&&m.startsWith("session-")?e.jsx(Hs,{session:g.find(f=>`session-${f.type}`===m),round:h,competitionId:s}):y?e.jsx(Vs,{round:y,competitionId:s}):e.jsx(M,{message:"No results for this round."})]})}function Vs({round:s,competitionId:n}){var i;const r=(s.sessions||[]).find(o=>o.type==="RACE"),a=(i=r==null?void 0:r.results)==null?void 0:i.filter(o=>o.position<=3).sort((o,c)=>o.position-c.position);return e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header--split",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"pvx-card-title",children:["Round ",s.roundNumber,s.track?`: ${s.track}`:""]}),s.startTime&&e.jsx("span",{className:"pvx-standings-subtitle",children:new Date(s.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(a==null?void 0:a.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:a.map(o=>e.jsxs("span",{className:"pvx-round-podium-item",children:[e.jsx("span",{children:z[o.position-1]}),e.jsx("span",{children:o.driverName})]},o.driverId))})]}),e.jsx(J,{round:s,competitionId:n})]})}function Ks({leaderboard:s,config:n}){var t;return(t=s==null?void 0:s.drivers)!=null&&t.length?e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header--split",children:e.jsxs("div",{children:[e.jsx("h4",{className:"pvx-card-title",children:s.track||(n==null?void 0:n.name)||"Hotlap Leaderboard"}),e.jsxs("span",{className:"pvx-standings-subtitle",children:[s.sessionsCompleted," session",s.sessionsCompleted!==1?"s":""," completed"]})]})}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Car"}),e.jsx("th",{className:"pvx-th",children:"Best Lap"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Laps"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Sessions"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Gap"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.drivers.map(r=>{const a=r.position===1?"":`+${((r.bestLapMs-s.drivers[0].bestLapMs)/1e3).toFixed(3)}`;return e.jsxs("tr",{className:`pvx-row ${r.position<=3?"pvx-row--podium":""}`,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(pe,{position:r.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(Y,{nation:r.nation}),r.driverName]}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:$(r.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx("span",{className:r.position===1?"pvx-best-lap-cell--fastest":"",children:r.bestLapFormatted})}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:r.totalLaps}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:r.sessionsParticipated}),e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:a})]},r.driverId)})})]})})]}):e.jsx(M,{message:"No lap times recorded yet."})}function Hs({session:s,round:n,competitionId:t}){return s?e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx("h4",{className:"pvx-card-title",children:G(s.type)})}),e.jsx(J,{round:{...n,sessions:[s]},competitionId:t})]}):e.jsx(M,{message:"Session data not available."})}function Ee(s){const{cdnUrl:n}=w(),t=C.useQuery({queryKey:["pitvox","laps","global",s,"index"],queryFn:()=>S(n,ge(null,s)),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),r=t.data;return{isLoading:t.isLoading,error:t.error,data:r?{driverName:r.driverName||"Driver",lapCount:r.lapCount||0,trackBreakdown:r.trackBreakdown||[],carBreakdown:r.carBreakdown||[],recordsHeld:r.recordsHeld||0,currentRecords:r.currentRecords||[],bestRanking:r.bestRanking??null,bestRankingTrackId:r.bestRankingTrackId??null,bestRankingLayout:r.bestRankingLayout??null,bestRankingCarId:r.bestRankingCarId??null,generatedAt:r.generatedAt}:null}}function qe(s={}){const{cdnUrl:n,partnerSlug:t}=w(),{game:r,gameVersion:a,enabled:i=!0}=s,o=_(t,r,a,"ratings.json");return C.useQuery({queryKey:["pitvox","ratings",t,r||null,a||null],queryFn:()=>S(n,o),staleTime:3e4,refetchInterval:3e4,enabled:i})}function _e(s){var r;const n=qe(),t=b.useMemo(()=>{var a;return!((a=n.data)!=null&&a.drivers)||!s?null:n.data.drivers.find(i=>i.identifier===s)||null},[(r=n.data)==null?void 0:r.drivers,s]);return{isLoading:n.isLoading,error:n.error,data:t?{rating:t.rating,rank:t.rank,totalDrivers:n.data.driverCount||n.data.drivers.length,comboCount:t.comboCount||0,distinctCars:t.distinctCars||0,combos:t.combos||[]}:null}}function Qs(s={}){const n=qe(s);return{data:n.data||null,isLoading:n.isLoading,error:n.error}}function Ve(){const{cdnUrl:s,partnerSlug:n,getSteamId:t,onFetchServerPassword:r}=w(),a=t(),{data:i,isLoading:o}=C.useQuery({queryKey:["pitvox","competitions",n],queryFn:async()=>{const x=await S(s,"competitions/index.json");return x!=null&&x.competitions?x.competitions.filter(N=>N.partnerSlug===n):[]},staleTime:6e4}),c=(i==null?void 0:i.map(x=>x.id))||[],d=C.useQueries({queries:c.map(x=>({queryKey:["pitvox","competition",n,x,"entrylist"],queryFn:()=>S(s,`competitions/${n}/${x}/entrylist.json`),enabled:!!a&&c.length>0,staleTime:6e4}))}),l=d.some(x=>x.isLoading),p=b.useMemo(()=>{var v,m;if(!i||!a||l)return[];const x=new Date,N=[];for(let j=0;j<i.length;j++){const u=i[j],y=(v=d[j])==null?void 0:v.data;if(!((m=y==null?void 0:y.drivers)==null?void 0:m.some(k=>k.steamId===a)))continue;const L=u.type==="hotlap",T=u.rounds||[];for(const k of T){if(k.isFinalized&&(!L||k.dediStatus==="completed"))continue;const I=k.dediStatus==="running"||k.dediStatus==="provisioning",Ze=k.dediStatus==="scheduled",Xe=k.startTime&&new Date(k.startTime)>x,es=I||Ze||k.dediServerAddress;!I&&!Xe&&!es||N.push({competitionId:u.id,competitionName:u.name,roundNumber:k.roundNumber,track:k.track||"TBD",startTime:k.startTime,dediStatus:k.dediStatus||null,dediServerAddress:k.dediServerAddress||null})}}return N.sort((j,u)=>{const y=j.dediStatus==="running"||j.dediStatus==="provisioning",f=u.dediStatus==="running"||u.dediStatus==="provisioning";return y&&!f?-1:!y&&f?1:new Date(j.startTime)-new Date(u.startTime)}),N.length>0&&(N[0].isNext=!0),N},[i,a,l,d]),h=C.useQueries({queries:p.map(x=>({queryKey:["pitvox","serverInfo",x.competitionId,x.roundNumber],queryFn:()=>r(x.competitionId,x.roundNumber),enabled:!!r&&p.length>0,staleTime:5*6e4,retry:!1}))});return{data:b.useMemo(()=>p.length?r?p.map((x,N)=>{var m;const v=(m=h[N])==null?void 0:m.data;return v!=null&&v.success?{...x,serverAddress:v.serverAddress||null,serverPassword:v.serverPassword||null}:x}):p:[],[p,r,h]),isLoading:o||!!a&&l}}function Ke(){const{onFetchNotifications:s}=w();return!!s}function He(s={}){const{onFetchNotifications:n,partnerSlug:t}=w(),{limit:r=20,unreadOnly:a=!1}=s;return C.useQuery({queryKey:["pitvox","notifications",t,{limit:r,unreadOnly:a}],queryFn:()=>n({limit:r,unreadOnly:a}),enabled:!!n,staleTime:3e4,refetchInterval:3e4})}function Os(){const{onFetchNotifications:s,partnerSlug:n}=w(),{data:t,isLoading:r}=C.useQuery({queryKey:["pitvox","notifications",n,{limit:1,unreadOnly:!1}],queryFn:()=>s({limit:1}),enabled:!!s,staleTime:3e4,refetchInterval:3e4,select:a=>(a==null?void 0:a.unreadCount)??0});return{count:t??0,isLoading:r}}function Qe(){const{onMarkNotificationRead:s,partnerSlug:n}=w(),t=C.useQueryClient();return C.useMutation({mutationFn:r=>{if(!s)throw new Error("No onMarkNotificationRead callback provided to PitVoxPartnerProvider.");return s(r)},onSuccess:(r,a)=>{t.setQueriesData({queryKey:["pitvox","notifications",n]},i=>i!=null&&i.notifications?{...i,unreadCount:Math.max(0,(i.unreadCount||0)-1),notifications:i.notifications.map(o=>o.id===a?{...o,isRead:!0,readAt:new Date().toISOString()}:o)}:i)}})}function Oe(){const{onMarkAllNotificationsRead:s,partnerSlug:n}=w(),t=C.useQueryClient();return C.useMutation({mutationFn:()=>{if(!s)throw new Error("No onMarkAllNotificationsRead callback provided to PitVoxPartnerProvider.");return s()},onSuccess:()=>{t.setQueriesData({queryKey:["pitvox","notifications",n]},r=>r!=null&&r.notifications?{...r,unreadCount:0,notifications:r.notifications.map(a=>({...a,isRead:!0,readAt:a.readAt||new Date().toISOString()}))}:r)}})}function We({driverName:s,avatarUrl:n,memberSince:t,className:r=""}){const a=t?new Date(t).toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"numeric"}):null;return e.jsxs("div",{className:`pvx-card pvx-dash-profile ${r}`,children:[n?e.jsx("img",{src:n,alt:"",className:"pvx-dash-profile-avatar"}):e.jsx("div",{className:"pvx-dash-profile-avatar pvx-dash-profile-avatar--placeholder",children:(s||"?")[0].toUpperCase()}),e.jsxs("div",{className:"pvx-dash-profile-info",children:[e.jsx("h2",{className:"pvx-dash-profile-name",children:s}),a&&e.jsxs("p",{className:"pvx-dash-profile-since",children:["Racing since ",a]})]})]})}function Ws(){return e.jsxs("svg",{className:"pvx-dash-stat-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"4",y1:"9",x2:"20",y2:"9"}),e.jsx("line",{x1:"4",y1:"15",x2:"20",y2:"15"}),e.jsx("line",{x1:"10",y1:"3",x2:"8",y2:"21"}),e.jsx("line",{x1:"16",y1:"3",x2:"14",y2:"21"})]})}function zs(){return e.jsxs("svg",{className:"pvx-dash-stat-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"}),e.jsx("path",{d:"M12 14v4"}),e.jsx("path",{d:"M10.5 12.5l-4 2.5"}),e.jsx("path",{d:"M13.5 12.5l4 2.5"})]})}function Gs(){return e.jsx("svg",{className:"pvx-dash-stat-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})})}function ve({icon:s,value:n,label:t,items:r,labelKey:a,countKey:i}){const[o,c]=b.useState(!1),d=b.useRef(null);b.useEffect(()=>{if(!o)return;function p(h){d.current&&!d.current.contains(h.target)&&c(!1)}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[o]);const l=r!=null&&r.length?r.slice().sort((p,h)=>h[i]-p[i]):null;return e.jsxs("div",{ref:d,className:`pvx-dash-stat-card ${l?"pvx-dash-stat-card--clickable":""}`,onClick:l?()=>c(p=>!p):void 0,children:[s,e.jsxs("div",{className:"pvx-dash-stat-content",children:[e.jsx("span",{className:"pvx-dash-stat-value",children:n}),e.jsx("span",{className:"pvx-dash-stat-label",children:t})]}),l&&e.jsx("div",{className:`pvx-dash-tooltip pvx-dash-tooltip--scrollable ${o?"pvx-dash-tooltip--open":""}`,children:l.map((p,h)=>e.jsxs("div",{className:"pvx-dash-tooltip-row",children:[e.jsx("span",{className:"pvx-dash-tooltip-label",children:p[a]}),e.jsx("span",{className:"pvx-dash-tooltip-value",children:p[i]})]},h))})]})}function ze({stats:s,rating:n,className:t=""}){if(!s)return null;const r=s.trackBreakdown.map(i=>({name:A(i.trackId,i.layout),lapCount:i.lapCount})),a=s.carBreakdown.map(i=>({name:$(i.carId),lapCount:i.lapCount}));return e.jsxs("div",{className:`pvx-dash-stats ${t}`,children:[e.jsx(ve,{icon:e.jsx(Ws,{}),value:s.lapCount.toLocaleString(),label:"Total Laps",items:r,labelKey:"name",countKey:"lapCount"}),e.jsx(ve,{icon:e.jsx(zs,{}),value:s.carBreakdown.length,label:"Cars Used",items:a,labelKey:"name",countKey:"lapCount"}),n&&e.jsxs("div",{className:"pvx-dash-stat-card pvx-dash-stat-card--rating",children:[e.jsx(Gs,{}),e.jsxs("div",{className:"pvx-dash-stat-content",children:[e.jsx("span",{className:"pvx-dash-stat-value",children:n.rating.toFixed(1)}),e.jsx("span",{className:"pvx-dash-stat-label",children:"Driver Rating"}),e.jsxs("span",{className:"pvx-dash-stat-sub",children:["#",n.rank," of ",n.totalDrivers]})]})]})]})}function Ge({records:s,className:n=""}){const t=b.useMemo(()=>s!=null&&s.length?s.slice().sort((r,a)=>{const i=r.recordedAt?new Date(r.recordedAt).getTime():0;return(a.recordedAt?new Date(a.recordedAt).getTime():0)-i}):[],[s]);return t.length?e.jsxs("div",{className:`pvx-card ${n}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx("span",{className:"pvx-dash-records-icon",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 010-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 000-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0012 0V2z"})]})}),"Current Records",e.jsxs("span",{className:"pvx-dash-records-count",children:["(",t.length,")"]})]})}),e.jsx("div",{className:"pvx-dash-records-list",children:t.map((r,a)=>e.jsxs("div",{className:"pvx-dash-record-row",children:[e.jsxs("div",{className:"pvx-dash-record-info",children:[e.jsx("span",{className:"pvx-dash-record-track",children:A(r.trackId,r.layout,r.game)}),e.jsx("span",{className:"pvx-dash-record-car",children:$(r.carId)})]}),e.jsxs("div",{className:"pvx-dash-record-time",children:[e.jsx("span",{className:"pvx-dash-record-lap",children:P(r.lapTimeMs)}),e.jsxs("span",{className:`pvx-dash-game-badge pvx-dash-game-badge--${r.game||"evo"}`,children:[(r.game||"evo").toUpperCase(),r.gameVersion?` ${r.gameVersion}`:""]})]})]},a))})]}):null}function Ye({events:s,isLoading:n,className:t,limit:r=3}){if(n)return e.jsx("div",{className:"pvx-loading",children:"Loading upcoming events..."});if(!(s!=null&&s.length))return null;const a=r?s.slice(0,r):s,i=s.length-a.length;return e.jsxs("div",{className:`pvx-card ${t||""}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(Zs,{}),"Upcoming Events",e.jsxs("span",{className:"pvx-dash-records-count",children:["(",s.length,")"]})]})}),e.jsxs("div",{className:"pvx-upcoming-list",children:[a.map(o=>e.jsxs("div",{className:`pvx-upcoming-item ${o.isNext?"pvx-upcoming-item--next":""}`,children:[e.jsxs("div",{className:"pvx-upcoming-info",children:[e.jsx("span",{className:"pvx-upcoming-comp",children:o.competitionName}),e.jsxs("span",{className:"pvx-upcoming-round",children:["Round ",o.roundNumber,": ",o.track]}),o.serverPassword&&e.jsx(Ys,{password:o.serverPassword,address:o.serverAddress})]}),e.jsxs("div",{className:"pvx-upcoming-time",children:[e.jsx("span",{className:"pvx-upcoming-date",children:new Date(o.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}),e.jsx("span",{className:"pvx-upcoming-relative",children:o.dediStatus==="running"?"Live now":o.dediStatus==="provisioning"?"Starting...":Js(o.startTime)}),o.dediStatus==="running"&&e.jsx("span",{className:"pvx-upcoming-badge pvx-upcoming-badge--live",children:"Live"}),!o.dediStatus&&o.isNext&&e.jsx("span",{className:"pvx-upcoming-badge",children:"Next"})]})]},`${o.competitionId}-${o.roundNumber}`)),i>0&&e.jsxs("div",{className:"pvx-upcoming-remaining",children:["+",i," more event",i!==1?"s":""]})]})]})}function Ys({password:s,address:n}){const[t,r]=b.useState(!1),[a,i]=b.useState(!1),o=n?s?`join:${n}|${s}`:`join:${n}`:null,c=b.useCallback(async()=>{if(o)try{await navigator.clipboard.writeText(o),r(!0),setTimeout(()=>r(!1),2e3)}catch{}},[o]);return e.jsxs("div",{className:"pvx-server-info",children:[o&&e.jsxs("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick:c,title:"Copy join string to clipboard",children:[e.jsx(et,{})," ",t?"Copied!":"Join"]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick:()=>i(d=>!d),title:a?"Hide password":"Reveal password",children:a?e.jsx(tt,{}):e.jsx(st,{})}),a&&e.jsxs("span",{className:"pvx-server-detail",children:[e.jsx(Xs,{})," ",s]})]})]})}function Js(s){const n=new Date(s).getTime()-Date.now();if(n<=0)return"Now";const t=Math.floor(n/(1e3*60*60));if(t<1)return"Less than 1 hour";if(t<24)return`in ${t}h`;const r=Math.floor(t/24);if(r===1)return"Tomorrow";if(r<7)return`in ${r} days`;if(r<30){const a=Math.floor(r/7);return`in ${a} week${a!==1?"s":""}`}return ee(s)}function Zs(){return e.jsxs("svg",{className:"pvx-dash-records-icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M16 2v4M8 2v4M3 10h18"})]})}function Xs(){return e.jsxs("svg",{className:"pvx-server-icon",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function et(){return e.jsxs("svg",{className:"pvx-server-icon pvx-server-icon--action",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function st(){return e.jsxs("svg",{className:"pvx-server-icon pvx-server-icon--action",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function tt(){return e.jsxs("svg",{className:"pvx-server-icon pvx-server-icon--action",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),e.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Je({notifications:s,unreadCount:n=0,onMarkRead:t,onMarkAllRead:r,isLoading:a,className:i}){const o=ne();return a?e.jsx("div",{className:"pvx-loading",children:"Loading notifications..."}):e.jsxs("div",{className:`pvx-card ${i||""}`,children:[e.jsxs("div",{className:"pvx-card-header",children:[e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(at,{}),"Notifications",n>0&&e.jsx("span",{className:"pvx-notif-badge",children:n>99?"99+":n})]}),n>0&&r&&e.jsx("button",{className:"pvx-notif-mark-all",onClick:r,children:"Mark all read"})]}),s!=null&&s.length?e.jsx("div",{className:"pvx-notif-list",children:s.map(c=>e.jsx(nt,{notification:c,getUserDisplay:o,onMarkRead:t},c.id))}):e.jsx("div",{className:"pvx-notif-empty",children:"No notifications"})]})}function nt({notification:s,getUserDisplay:n,onMarkRead:t}){const r=()=>{!s.isRead&&t&&t(s.id)};return e.jsxs("button",{className:`pvx-notif-item ${s.isRead?"":"pvx-notif-item--unread"}`,onClick:r,children:[e.jsx(rt,{type:s.type}),e.jsxs("div",{className:"pvx-notif-content",children:[e.jsx("span",{className:"pvx-notif-message",children:fe(s,n)}),e.jsx("span",{className:"pvx-notif-time",children:ee(s.createdAt)})]}),!s.isRead&&e.jsx("span",{className:"pvx-notif-dot"})]})}function rt({type:s}){return s==="RECORD_BEATEN"?e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--beaten",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m7 7 10 10M17 7v10H7"})})}):s==="ADMIN_MESSAGE"?e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--admin",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"m3 11 18-5v12L3 13v-2z"}),e.jsx("path",{d:"M11.6 16.8a3 3 0 1 1-5.8-1.6"})]})}):e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--record",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 0 1 0-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 0 0 0-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0 0 12 0V2Z"})]})})}function at(){return e.jsxs("svg",{className:"pvx-dash-records-icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"}),e.jsx("path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0"})]})}function it({steamId:s,avatarUrl:n,memberSince:t,className:r=""}){const{data:a,isLoading:i,error:o}=Ee(s),{data:c,isLoading:d}=_e(s),{data:l,isLoading:p}=Ve(),h=Ke(),{data:g,isLoading:x}=He({limit:10}),N=Qe(),v=Oe();return i||d?e.jsx("div",{className:"pvx-loading",children:"Loading dashboard..."}):o?e.jsx("div",{className:"pvx-empty",children:"Failed to load dashboard data."}):a?e.jsxs("div",{className:`pvx-dash ${r}`,children:[e.jsx(We,{driverName:a.driverName,avatarUrl:n,memberSince:t}),e.jsx(ze,{stats:a,rating:c}),s&&e.jsx(Ye,{events:l,isLoading:p}),e.jsxs("div",{className:`pvx-dash-row ${h?"pvx-dash-row--2col":""}`,children:[e.jsx(Ge,{records:a.currentRecords}),h&&e.jsx(Je,{notifications:g==null?void 0:g.notifications,unreadCount:(g==null?void 0:g.unreadCount)||0,onMarkRead:m=>N.mutate(m),onMarkAllRead:()=>v.mutate(),isLoading:x})]})]}):e.jsx("div",{className:"pvx-empty",children:"No data available yet. Start driving to see your stats!"})}exports.CarsTable=vs;exports.CompEmptyState=M;exports.CompLoadingState=B;exports.CompetitionCard=Be;exports.CompetitionCards=Ss;exports.CompetitionResultsTabs=_s;exports.CompletedBadge=Ie;exports.DEFAULT_COMPLETION_GRACE_DAYS=xe;exports.DriverDashboard=it;exports.DriverProfile=We;exports.DriversTable=hs;exports.EntryList=As;exports.InfoPill=q;exports.LapHistoryTable=gs;exports.NotificationsCard=Je;exports.PODIUM_MEDALS=z;exports.PitVoxPartnerProvider=ns;exports.RankingsTable=js;exports.RecordsTable=Ge;exports.RegisterButton=Us;exports.RegistrationPanel=Fs;exports.RoundResults=Ms;exports.RoundSessionResults=J;exports.StandingsTable=Ae;exports.StatsCards=ze;exports.TracksTable=ms;exports.TypeBadge=$e;exports.UpcomingEvents=Ye;exports.buildDriverIndexPath=ge;exports.buildLapsPath=he;exports.buildLeaderboardPath=_;exports.buildRecentLapsPath=je;exports.fetchCdnJson=S;exports.filterCompetitionsByStatus=Ls;exports.formatCarName=$;exports.formatDate=U;exports.formatDelta=rs;exports.formatFuel=te;exports.formatLapTime=P;exports.formatNotificationMessage=fe;exports.formatRelativeTime=ee;exports.formatSectorTime=D;exports.formatSessionLabel=G;exports.formatTrackName=A;exports.formatTyreCompound=se;exports.getCompetitionPodium=Pe;exports.getCompetitionStatus=ue;exports.getCompletionDate=De;exports.isCompetitionComplete=Me;exports.useCarLeaderboard=ls;exports.useCarMetadata=is;exports.useCompetitionAllRounds=Ce;exports.useCompetitionConfig=re;exports.useCompetitionEntryList=ie;exports.useCompetitionLeaderboard=ke;exports.useCompetitionRound=ye;exports.useCompetitionRoundLaps=we;exports.useCompetitionStandings=ae;exports.useCompetitions=cs;exports.useDriverLaps=be;exports.useDriverRating=_e;exports.useDriverRatings=Qs;exports.useDriverStats=Ee;exports.useLeaderboardIndex=as;exports.useMarkAllNotificationsRead=Oe;exports.useMarkNotificationRead=Qe;exports.useNotifications=He;exports.useNotificationsEnabled=Ke;exports.usePitVox=w;exports.useRecentLaps=os;exports.useRegister=oe;exports.useRegistrationMode=K;exports.useRegistrationStatus=V;exports.useRegistrationUrl=H;exports.useTrackLeaderboard=Ne;exports.useUnreadCount=Os;exports.useUpcomingEvents=Ve;exports.useUserLookup=ne;exports.useWithdraw=le;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("react"),k=require("@tanstack/react-query"),se=b.createContext(null),as="https://cdn.pitvox.com",is="https://pitvox.com";let ee=null;function os({partnerSlug:s=null,cdnUrl:t=as,pitvoxUrl:n=is,getSteamId:r,onRegister:a,onWithdraw:i,onFetchNotifications:o,onMarkNotificationRead:c,onMarkAllNotificationsRead:d,onFetchServerPassword:l,children:p}){const v=b.useMemo(()=>({partnerSlug:s,cdnUrl:t.replace(/\/$/,""),pitvoxUrl:n.replace(/\/$/,""),getSteamId:r||(()=>null),onRegister:a||null,onWithdraw:i||null,onFetchNotifications:o||null,onMarkNotificationRead:c||null,onMarkAllNotificationsRead:d||null,onFetchServerPassword:l||null}),[s,t,n,r,a,i,o,c,d,l]);let g=!1;try{k.useQueryClient(),g=!0}catch{g=!1}return g?e.jsx(se.Provider,{value:v,children:p}):(ee||(ee=new k.QueryClient({defaultOptions:{queries:{staleTime:6e4}}})),e.jsx(k.QueryClientProvider,{client:ee,children:e.jsx(se.Provider,{value:v,children:p})}))}function C(){const s=b.useContext(se);if(!s)throw new Error("usePitVox must be used within a <PitVoxPartnerProvider>");return s}async function S(s,t){const n=await fetch(`${s}/${t}`);if(!n.ok){if(n.status===404||n.status===403)return null;throw new Error(`CDN fetch failed: ${n.status}`)}return n.json()}function V(s,t,n,...r){const a=["leaderboards"];return s&&a.push(`partners/${s}`),t&&a.push(t),n&&a.push(`v/${n}`),[...a,...r].join("/")}function fe(s,t,n,r){const a=r||"default";return s?`laps/partners/${s}/${t}/${n}/${a}.json`:`laps/${t}/${n}/${a}.json`}function te(s,t){return s?`laps/partners/${s}/${t}/index.json`:`laps/${t}/index.json`}function Ne(s){return s?`recent-laps/partners/${s}.json`:"recent-laps.json"}function P(s){if(!s&&s!==0)return"-";const t=Math.floor(s/1e3),n=Math.floor(t/60),r=t%60,a=s%1e3;return`${n}:${String(r).padStart(2,"0")}.${String(a).padStart(3,"0")}`}function D(s){return!s&&s!==0?"-":s>=6e4?P(s):(s/1e3).toFixed(3)}function T(s){if(!s)return"";let t=s;return t.startsWith("ks_")&&(t=t.slice(3)),t.split("_").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function I(s,t,n){if(!s)return"";const r=s.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" "),a=n==="acc"||!n&&(t==null?void 0:t.toLowerCase())==="track config";if(!t||t==="default"||a)return r;const i=t.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ");return`${r} ${i}`}function F(s){if(!s)return"-";try{return new Date(s).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}catch{return"-"}}function K(s){if(!s)return"";const t=Date.now()-new Date(s).getTime(),n=Math.floor(t/1e3);if(n<60)return"Just now";const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const a=Math.floor(r/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);return i<30?`${i}d ago`:F(s)}function ls(s){return s==null?"":`${s>=0?"+":"-"}${(Math.abs(s)/1e3).toFixed(3)}`}function be(s,t){const{type:n,title:r,trackId:a,trackLayout:i,carId:o,game:c,data:d}=s,l=typeof d=="string"?JSON.parse(d):d,p=a?I(a,i,c):null,v=o?T(o):null,g=[p,v].filter(Boolean).join(" — ");return n==="RECORD_BEATEN"&&g?`${l!=null&&l.beatenBySteamId&&t?t(l.beatenBySteamId).displayName:"Someone"} beat your record on ${g}`:n==="RECORD_SET"&&g?`You set a new record on ${g}`:r||"New notification"}function ne(s){return s?{E:"Eco",RD:"Road",SC:"SuperCar",RV:"Race Vintage",SM:"Semislick",ST:"Street",HR:"Hard Race",MR:"Medium Race",SR:"Soft Race",S:"Soft"}[s]||s:"Unknown"}function re(s){if(!s)return"-";const t=Number(s);return isNaN(t)?"-":t%1?`${t.toFixed(1)}L`:`${t}L`}function ye(s={}){var d,l,p,v,g,x;const{cdnUrl:t,partnerSlug:n}=C(),{game:r,gameVersion:a}=s,i=V(n,null,null,"index.json"),o=k.useQuery({queryKey:["pitvox","leaderboards",n,"index"],queryFn:()=>S(t,i),staleTime:3e4,refetchInterval:3e4}),c=b.useMemo(()=>{var h;if(!((h=o.data)!=null&&h.tracks))return[];let f=o.data.tracks;return r&&(f=f.filter(m=>m.game===r)),a&&(f=f.filter(m=>m.gameVersion===a)),f.map(m=>({id:m.trackId,layout:m.layout,game:m.game,gameVersion:m.gameVersion,displayName:I(m.trackId,m.layout,m.game),driverCount:m.driverCount||0,carCount:m.carCount||0,record:m.recordHolder?{visibleId:m.recordHolder.steamId||m.recordHolder.userId,carId:m.recordHolder.carId,carDisplayName:T(m.recordHolder.carId),lapTimeMs:m.recordHolder.lapTimeMs,timestamp:m.recordHolder.recordedAt}:null,recordByTag:m.recordByTag||null}))},[(d=o.data)==null?void 0:d.tracks,r,a]);return{...o,data:c,partner:((l=o.data)==null?void 0:l.partner)||null,generatedAt:(p=o.data)==null?void 0:p.generatedAt,totalLaps:((v=o.data)==null?void 0:v.totalLaps)||0,totalUsers:((g=o.data)==null?void 0:g.totalUsers)||0,versions:((x=o.data)==null?void 0:x.versions)||{}}}function ke(s,t,n={}){const{cdnUrl:r,partnerSlug:a}=C(),{carId:i,game:o,gameVersion:c}=n,d=t||"default",l=V(a,o,c,`tracks/${s}/${d}.json`),{data:p,isLoading:v,error:g}=k.useQuery({queryKey:["pitvox","leaderboards",a,"track",s,d,o,c],queryFn:()=>S(r,l),enabled:!!s,staleTime:3e4,refetchInterval:3e4});return{data:b.useMemo(()=>{if(!(p!=null&&p.entries))return[];let f=p.entries;if(o&&(f=f.filter(h=>h.game===o)),!i){const h=new Map,m=new Map;for(const j of f){const u=j.steamId||j.userId;m.has(j.carId)||m.set(j.carId,new Set),m.get(j.carId).add(u),(!h.has(j.carId)||j.lapTimeMs<h.get(j.carId).lapTimeMs)&&h.set(j.carId,j)}return Array.from(h.values()).map(j=>{var u;return{...j,driverCount:((u=m.get(j.carId))==null?void 0:u.size)||0}}).sort((j,u)=>j.lapTimeMs-u.lapTimeMs)}return f.filter(h=>h.carId===i).sort((h,m)=>h.lapTimeMs-m.lapTimeMs)},[p==null?void 0:p.entries,i,o]),isLoading:v,error:g}}function Ce(s,t,n,r,a={}){var h,m;const{cdnUrl:i,partnerSlug:o}=C(),{showInvalid:c=!1,game:d,gameVersion:l}=a,p=s&&t?fe(o,s,t,n):null,v=n||"default",g=k.useQuery({queryKey:["pitvox","laps",o,s,t,v],queryFn:()=>S(i,p),enabled:!!s&&!!t,staleTime:3e4,refetchInterval:3e4}),x=b.useMemo(()=>{var j;return(j=g.data)!=null&&j.laps?g.data.laps.filter(u=>!(u.carId!==r||d&&u.game!==d||l&&u.gameVersion!==l||!c&&!u.isValid)).sort((u,y)=>u.lapTimeMs-y.lapTimeMs):[]},[(h=g.data)==null?void 0:h.laps,r,d,l,c]),f=b.useMemo(()=>{const j=x.filter(w=>w.isValid&&w.sector1Ms&&w.sector2Ms&&w.sector3Ms);if(j.length<2)return null;const u=Math.min(...j.map(w=>w.sector1Ms)),y=Math.min(...j.map(w=>w.sector2Ms)),N=Math.min(...j.map(w=>w.sector3Ms)),L=u+y+N,$=Math.min(...j.map(w=>w.lapTimeMs));return L>=$?null:{lapTimeMs:L,sector1Ms:u,sector2Ms:y,sector3Ms:N}},[x]);return{...g,data:x,driverName:((m=g.data)==null?void 0:m.driverName)||"Driver",theoreticalBest:f}}function ae(){const{cdnUrl:s}=C(),{data:t}=k.useQuery({queryKey:["pitvox","users","index"],queryFn:()=>S(s,"users/index.json"),staleTime:5*6e4,gcTime:30*6e4}),n=(t==null?void 0:t.users)||{};return(r,a)=>{const i=n[r];return{displayName:(i==null?void 0:i.displayName)||a||r||"Unknown",avatarUrl:(i==null?void 0:i.avatarUrl)||null,affiliations:(i==null?void 0:i.affiliations)||[]}}}function cs(s="evo"){const{cdnUrl:t}=C(),{data:n}=k.useQuery({queryKey:["pitvox","cars",s],queryFn:()=>S(t,`cars/${s}.json`),staleTime:5*6e4,gcTime:30*6e4});return{tags:(n==null?void 0:n.tags)||[],cars:(n==null?void 0:n.cars)||{},categories:(n==null?void 0:n.categories)||[],tagLabels:(n==null?void 0:n.tagLabels)||{}}}function ds(){var a,i;const{cdnUrl:s,partnerSlug:t}=C(),n=Ne(t),r=k.useQuery({queryKey:["pitvox","recentLaps",t],queryFn:()=>S(s,n),staleTime:3e4,refetchInterval:3e4,gcTime:10*6e4});return{groups:((a=r.data)==null?void 0:a.groups)||[],generatedAt:((i=r.data)==null?void 0:i.generatedAt)||null,isLoading:r.isLoading}}function ps(s,t){return ke(s,null,{carId:t})}function xs(){const{cdnUrl:s,partnerSlug:t}=C();return k.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const n=await S(s,"competitions/index.json");return n!=null&&n.competitions?t?n.competitions.filter(r=>r.partnerSlug===t):n.competitions:[]},staleTime:6e4})}function ie(s,t={}){const n=C(),r=t.partnerSlug||n.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",r,s,"config"],queryFn:()=>S(n.cdnUrl,`competitions/${r}/${s}/config.json`),enabled:!!r&&!!s,staleTime:6e4})}function oe(s,t={}){const n=C(),r=t.partnerSlug||n.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",r,s,"standings"],queryFn:()=>S(n.cdnUrl,`competitions/${r}/${s}/standings.json`),enabled:!!r&&!!s,staleTime:6e4})}function we(s,t,n={}){const r=C(),a=n.partnerSlug||r.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",a,s,"round",t],queryFn:()=>S(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}.json`),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function Le(s,t=[],n={}){const r=C(),a=n.partnerSlug||r.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",a,s,"allRounds",t],queryFn:async()=>(await Promise.all(t.map(o=>S(r.cdnUrl,`competitions/${a}/${s}/rounds/${o}.json`).catch(()=>null)))).filter(Boolean),enabled:!!a&&!!s&&t.length>0,staleTime:6e4})}function Se(s,t={}){const n=C(),r=t.partnerSlug||n.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",r,s,"leaderboard"],queryFn:()=>S(n.cdnUrl,`competitions/${r}/${s}/leaderboard.json`).catch(()=>null),enabled:!!r&&!!s,staleTime:6e4})}function Re(s,t,n={}){const r=C(),a=n.partnerSlug||r.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",a,s,"round",t,"laps"],queryFn:()=>S(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}/laps.json`).catch(()=>null),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function le(s,t={}){const n=C(),r=t.partnerSlug||n.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",r,s,"entrylist"],queryFn:()=>S(n.cdnUrl,`competitions/${r}/${s}/entrylist.json`),enabled:!!r&&!!s,staleTime:6e4})}function H(s){const{cdnUrl:t,partnerSlug:n,getSteamId:r}=C(),a=r();return k.useQuery({queryKey:["pitvox","registration",n,s,a],queryFn:async()=>{var d;const i=await fetch(`${t}/competitions/${n}/${s}/entrylist.json`);if(!i.ok)return{isRegistered:!1,entryList:null};const o=await i.json();return{isRegistered:!!a&&((d=o.drivers)==null?void 0:d.some(l=>l.steamId===a)),entryList:o}},enabled:!!s,staleTime:6e4})}function ce(s){const{onRegister:t,partnerSlug:n,getSteamId:r}=C(),a=k.useQueryClient(),i=ae();return k.useMutation({mutationFn:o=>{if(!t)throw new Error("No onRegister callback provided to PitVoxPartnerProvider. Provide onRegister for in-app registration, or use useRegistrationUrl() to link to pitvox.com.");return t(s,o)},onSuccess:()=>{const o=r();if(a.setQueriesData({queryKey:["pitvox","registration",n,s]},c=>c?{...c,isRegistered:!0}:{isRegistered:!0,entryList:null}),o){const c=i(o),d={steamId:o,displayName:c.displayName,avatarUrl:c.avatarUrl};a.setQueriesData({queryKey:["pitvox","competition",n,s,"entrylist"]},l=>{var v;return l?((v=l.drivers)==null?void 0:v.some(g=>g.steamId===o))?l:{...l,drivers:[...l.drivers||[],d]}:{drivers:[d]}})}}})}function de(s){const{onWithdraw:t,partnerSlug:n,getSteamId:r}=C(),a=k.useQueryClient();return k.useMutation({mutationFn:i=>{if(!t)throw new Error("No onWithdraw callback provided to PitVoxPartnerProvider. Provide onWithdraw for in-app withdrawal, or use useRegistrationUrl() to link to pitvox.com.");const o=i||r();if(!o)throw new Error("No Steam ID available");return t(s,o)},onSuccess:()=>{const i=r();a.setQueriesData({queryKey:["pitvox","registration",n,s]},o=>o?{...o,isRegistered:!1}:{isRegistered:!1,entryList:null}),i&&a.setQueriesData({queryKey:["pitvox","competition",n,s,"entrylist"]},o=>o!=null&&o.drivers?{...o,drivers:o.drivers.filter(c=>c.steamId!==i)}:o)}})}function Q(){const{onRegister:s,onWithdraw:t}=C(),n=!!(s&&t);return{isPowerMode:n,isBasicMode:!n}}function O(s){const{pitvoxUrl:t,partnerSlug:n}=C();return`${t}/p/${n}/competitions/${s}/register`}function us(s,t){for(const n of t)if(n.tags.includes(s))return n.id;return"other"}function Te(s,t,n=[]){if(t.size===0)return!0;const r={};for(const a of t){const i=us(a,n);r[i]||(r[i]=[]),r[i].push(a)}for(const a of Object.values(r))if(!a.some(i=>s.includes(i)))return!1;return!0}function $e(s,t){const[n,r]=b.useState(new Set),a=s!==void 0,i=a?s:n,o=b.useCallback(d=>{const l=new Set(i);l.has(d)?l.delete(d):l.add(d),a&&t?t(l):r(l)},[i,a,t]),c=b.useCallback(()=>{a&&t?t(new Set):r(new Set)},[a,t]);return{activeTags:i,toggle:o,clear:c}}function W(s){const[t,n]=b.useState(s),r=b.useCallback(a=>{n(i=>i.key===a?{key:a,dir:i.dir==="asc"?"desc":"asc"}:{key:a,dir:a.includes("timestamp")||a.includes("Date")?"desc":"asc"})},[]);return[t,r]}function z(s,t,n){return[...s].sort((r,a)=>{const i=n(r,t.key),o=n(a,t.key);if(i==null&&o==null)return 0;if(i==null)return 1;if(o==null)return-1;const c=typeof i=="string"?i.localeCompare(o):i-o;return t.dir==="desc"?-c:c})}function Me(s,t=!1){const n=t?s==null?void 0:s.filter(r=>r.isValid):s;return n!=null&&n.length?{s1:Math.min(...n.map(r=>r.sector1Ms).filter(Boolean)),s2:Math.min(...n.map(r=>r.sector2Ms).filter(Boolean)),s3:Math.min(...n.map(r=>r.sector3Ms).filter(Boolean))}:null}function ms({active:s,dir:t}){return s?t==="asc"?e.jsx("svg",{className:"pvx-sort-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 15.75l7.5-7.5 7.5 7.5"})}):e.jsx("svg",{className:"pvx-sort-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 8.25l-7.5 7.5-7.5-7.5"})}):e.jsx("svg",{className:"pvx-sort-icon pvx-sort-icon--inactive",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 9l4-4 4 4M16 15l-4 4-4-4"})})}function R({label:s,sortKey:t,config:n,onSort:r,className:a=""}){return e.jsx("th",{className:`pvx-th pvx-th--sortable ${a}`,onClick:()=>r(t),children:e.jsxs("span",{className:"pvx-th-inner",children:[s,e.jsx(ms,{active:n.key===t,dir:n.dir})]})})}function G({userId:s,getUserDisplay:t}){const{displayName:n,avatarUrl:r}=t(s);return e.jsxs("span",{className:"pvx-driver",children:[r?e.jsx("img",{src:r,alt:"",className:"pvx-driver-avatar"}):e.jsx("span",{className:"pvx-driver-avatar pvx-driver-avatar--placeholder"}),e.jsx("span",{className:"pvx-driver-name",children:n})]})}function pe({rank:s,podium:t=!1}){const n=t?s===1?"pvx-rank pvx-rank--gold":s===2?"pvx-rank pvx-rank--silver":s===3?"pvx-rank pvx-rank--bronze":"pvx-rank":"pvx-rank";return e.jsx("span",{className:n,children:s})}function De({availableTags:s,activeTags:t,onToggle:n,onClear:r,categories:a=[],tagLabels:i={}}){if(!s||s.length<2)return null;const o=a.map(c=>({id:c.id,tags:c.tags.filter(d=>s.includes(d))})).filter(c=>c.tags.length>0);return e.jsxs("div",{className:"pvx-tag-bar",children:[e.jsx("button",{onClick:r,className:`pvx-tag ${t.size===0?"pvx-tag--active":""}`,children:"All"}),o.map((c,d)=>e.jsxs("span",{className:"contents",children:[d>0&&e.jsx("span",{className:"pvx-tag-separator"}),c.tags.map(l=>e.jsx("button",{onClick:()=>n(l),className:`pvx-tag ${t.has(l)?"pvx-tag--active":""}`,children:i[l]||l},l))]},c.id))]})}function xe({segments:s}){return e.jsx("nav",{className:"pvx-breadcrumb","aria-label":"Breadcrumb",children:e.jsx("ol",{className:"pvx-breadcrumb-list",children:s.map((t,n)=>{const r=n===s.length-1;return e.jsxs("li",{className:"pvx-breadcrumb-item",children:[n>0&&e.jsx("svg",{className:"pvx-breadcrumb-chevron",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.25 4.5l7.5 7.5-7.5 7.5"})}),!r&&t.onClick?e.jsx("button",{onClick:t.onClick,className:"pvx-breadcrumb-link",children:t.label}):e.jsx("span",{className:"pvx-breadcrumb-current",children:t.label})]},t.key)})})})}function U({message:s}){return e.jsxs("div",{className:"pvx-empty",children:[e.jsx("svg",{className:"pvx-empty-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.5 18.75h-9m9 0a3 3 0 013 3h-15a3 3 0 013-3m9 0v-4.5A3.375 3.375 0 0013.125 10.875h-2.25A3.375 3.375 0 007.5 14.25v4.5"})}),e.jsx("p",{children:s})]})}function E(){return e.jsx("div",{className:"pvx-loading",children:"Loading..."})}function vs(){return e.jsx("svg",{className:"pvx-icon pvx-icon--valid",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 12.75l6 6 9-13.5"})})}function hs(){return e.jsx("svg",{className:"pvx-icon pvx-icon--invalid",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})}function gs({tracks:s,isLoading:t,carMetadata:n,getUserDisplay:r,onTrackSelect:a,tags:i,onTagChange:o}){const[c,d]=W({key:"record.timestamp",dir:"desc"}),{activeTags:l,toggle:p,clear:v}=$e(i,o),g=b.useMemo(()=>{var m;if(!((m=n==null?void 0:n.tags)!=null&&m.length))return[];const h=new Set;for(const j of s||[])j.recordByTag&&Object.keys(j.recordByTag).forEach(u=>h.add(u));return n.tags.filter(j=>h.has(j))},[s,n]),x=b.useMemo(()=>s?l.size===0?s:s.map(h=>{var u,y;if(!h.recordByTag)return null;let m=null;const j=new Set;for(const N of Object.values(h.recordByTag)){if(j.has(N.carId))continue;j.add(N.carId);const L=((y=(u=n==null?void 0:n.cars)==null?void 0:u[N.carId])==null?void 0:y.tags)||[];Te(L,l,n==null?void 0:n.categories)&&(!m||N.lapTimeMs<m.lapTimeMs)&&(m=N)}return m?{...h,record:{visibleId:m.steamId||m.identifier,carId:m.carId,carDisplayName:T(m.carId),lapTimeMs:m.lapTimeMs,timestamp:m.recordedAt}}:null}).filter(Boolean):[],[s,l,n]),f=b.useMemo(()=>z(x,c,(h,m)=>{var j,u;switch(m){case"displayName":return h.displayName;case"record.lapTimeMs":return(j=h.record)==null?void 0:j.lapTimeMs;case"driverCount":return h.driverCount||0;case"carCount":return h.carCount||0;case"record.timestamp":default:return(u=h.record)!=null&&u.timestamp?new Date(h.record.timestamp).getTime():0}}),[x,c]);return t?e.jsx(E,{}):s!=null&&s.length?e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx("h2",{className:"pvx-card-title",children:"Track Records"})}),e.jsx(De,{availableTags:g,activeTags:l,onToggle:p,onClear:v,categories:n==null?void 0:n.categories,tagLabels:n==null?void 0:n.tagLabels}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx(R,{label:"Track",sortKey:"displayName",config:c,onSort:d}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Car"}),e.jsx(R,{label:"Lap Time",sortKey:"record.lapTimeMs",config:c,onSort:d}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:c,onSort:d,className:"pvx-hidden-below-md"}),e.jsx(R,{label:"Cars",sortKey:"carCount",config:c,onSort:d,className:"pvx-hidden-below-lg"}),e.jsx(R,{label:"Date",sortKey:"record.timestamp",config:c,onSort:d,className:"pvx-hidden-below-xl"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:f.map(h=>{var m,j,u;return e.jsxs("tr",{className:"pvx-row pvx-row--clickable",onClick:()=>a(h.id,h.layout),children:[e.jsx("td",{className:"pvx-td pvx-td--primary",children:h.displayName}),e.jsx("td",{className:"pvx-td",children:(m=h.record)!=null&&m.visibleId?e.jsx(G,{userId:h.record.visibleId,getUserDisplay:r}):"-"}),e.jsx("td",{className:"pvx-td pvx-hidden-below-lg",children:((j=h.record)==null?void 0:j.carDisplayName)||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:h.record?P(h.record.lapTimeMs):"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-md",children:h.driverCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:h.carCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:(u=h.record)!=null&&u.timestamp?F(h.record.timestamp):"-"})]},`${h.id}|${h.layout||""}`)})})]})})]}):e.jsx(U,{message:"No lap times recorded yet."})}function js({entries:s,isLoading:t,track:n,carMetadata:r,getUserDisplay:a,onCarSelect:i,onNavigate:o,tags:c,onTagChange:d}){const[l,p]=W({key:"lapTimeMs",dir:"asc"}),{activeTags:v,toggle:g,clear:x}=$e(c,d),f=b.useMemo(()=>{var y,N,L;if(!s||!((y=r==null?void 0:r.tags)!=null&&y.length))return[];const u=new Set;for(const $ of s)(((L=(N=r.cars)==null?void 0:N[$.carId])==null?void 0:L.tags)||[]).forEach(B=>u.add(B));return r.tags.filter($=>u.has($))},[s,r]),h=b.useMemo(()=>s?v.size===0?s:s.filter(u=>{var N,L;const y=((L=(N=r==null?void 0:r.cars)==null?void 0:N[u.carId])==null?void 0:L.tags)||[];return Te(y,v,r==null?void 0:r.categories)}):[],[s,v,r]),m=b.useMemo(()=>z(h,l,(u,y)=>{switch(y){case"carId":return T(u.carId);case"driverCount":return u.driverCount||0;case"lapTimeMs":default:return u.lapTimeMs}}),[h,l]),j=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:n.displayName}];return t?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(xe,{segments:j})}),e.jsx(De,{availableTags:f,activeTags:v,onToggle:g,onClear:x,categories:r==null?void 0:r.categories,tagLabels:r==null?void 0:r.tagLabels}),s!=null&&s.length?e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"#"}),e.jsx(R,{label:"Car",sortKey:"carId",config:l,onSort:p}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:l,onSort:p}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:l,onSort:p,className:"pvx-hidden-below-md"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:m.map((u,y)=>e.jsxs("tr",{className:"pvx-row pvx-row--clickable",onClick:()=>i(u.carId),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(pe,{rank:y+1,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:T(u.carId)}),e.jsx("td",{className:"pvx-td",children:e.jsx(G,{userId:u.steamId||u.userId,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:P(u.lapTimeMs)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-md",children:u.driverCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-lg",children:u.recordedAt?F(u.recordedAt):"-"})]},u.carId))})]})}):e.jsx(U,{message:"No lap times for this track yet."})]})}function fs({entries:s,isLoading:t,track:n,carId:r,getUserDisplay:a,onDriverSelect:i,onNavigate:o,highlightId:c}){const[d,l]=W({key:"lapTimeMs",dir:"asc"}),p=b.useMemo(()=>Me(s),[s]),v=b.useMemo(()=>z(s||[],d,(x,f)=>{switch(f){case"userId":return a(x.steamId||x.userId).displayName;case"lapCount":return x.lapCount||0;case"lapTimeMs":default:return x.lapTimeMs}}),[s,d,a]),g=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:n.displayName,onClick:()=>o("track")},{key:"car",label:T(r)}];return t?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(xe,{segments:g})}),s!=null&&s.length?e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"#"}),e.jsx(R,{label:"Driver",sortKey:"userId",config:d,onSort:l}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:d,onSort:l}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Tyre"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Fuel"}),e.jsx(R,{label:"Laps",sortKey:"lapCount",config:d,onSort:l,className:"pvx-hidden-below-lg"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:v.map((x,f)=>{const h=f+1,m=x.steamId||x.userId,j=p&&x.sector1Ms===p.s1,u=p&&x.sector2Ms===p.s2,y=p&&x.sector3Ms===p.s3,N=c&&m===c;return e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${N?"pvx-row--highlight":h<=3?"pvx-row--podium":""}`,onClick:()=>i(m),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(pe,{rank:h,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(G,{userId:m,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:P(x.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${j?"pvx-td--best-sector":""}`,children:D(x.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${u?"pvx-td--best-sector":""}`,children:D(x.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${y?"pvx-td--best-sector":""}`,children:D(x.sector3Ms)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:ne(x.tyreCompound),children:x.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-xl",children:re(x.startingFuelL)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:x.lapCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:x.recordedAt?F(x.recordedAt):"-"})]},m)})})]})}):e.jsx(U,{message:"No lap times for this car yet."})]})}function Ns({userId:s,track:t,carId:n,game:r,gameVersion:a,showInvalid:i,getUserDisplay:o,onToggleInvalid:c,onNavigate:d}){const{data:l,driverName:p,theoreticalBest:v,isLoading:g}=Ce(s,t.id,t.layout,n,{showInvalid:i,game:r,gameVersion:a}),{displayName:x,avatarUrl:f}=o(s,p),h=b.useMemo(()=>Me(l,!0),[l]),m=b.useMemo(()=>{const u=(l==null?void 0:l.filter(y=>y.isValid))||[];return u.length?Math.min(...u.map(y=>y.lapTimeMs)):null},[l]),j=[{key:"tracks",label:"Tracks",onClick:()=>d("tracks")},{key:"track",label:t.displayName,onClick:()=>d("track")},{key:"car",label:T(n),onClick:()=>d("car")},{key:"driver",label:x}];return g?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header pvx-card-header--split",children:[e.jsxs("div",{className:"pvx-card-header-left",children:[e.jsx(xe,{segments:j}),f?e.jsx("img",{src:f,alt:"",className:"pvx-driver-avatar pvx-driver-avatar--lg"}):e.jsx("span",{className:"pvx-driver-avatar pvx-driver-avatar--lg pvx-driver-avatar--placeholder"})]}),e.jsxs("label",{className:"pvx-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:c,className:"pvx-checkbox"}),e.jsx("span",{children:"Show invalid laps"})]})]}),v&&e.jsxs("div",{className:"pvx-theoretical-best",children:[e.jsx("span",{className:"pvx-theoretical-best-label",children:"Theoretical Best:"}),e.jsx("span",{className:"pvx-theoretical-best-time",children:P(v.lapTimeMs)}),e.jsxs("span",{className:"pvx-theoretical-best-sectors",children:["(",D(v.sector1Ms)," + ",D(v.sector2Ms)," + ",D(v.sector3Ms),")"]})]}),l!=null&&l.length?e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"#"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-md",children:"Lap"}),e.jsx("th",{className:"pvx-th",children:"Lap Time"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"}),e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Valid"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Tyre"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Fuel"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:l.map((u,y)=>{const N=u.isValid&&u.lapTimeMs===m,L=h&&u.isValid&&u.sector1Ms===h.s1,$=h&&u.isValid&&u.sector2Ms===h.s2,w=h&&u.isValid&&u.sector3Ms===h.s3;let B="pvx-row";return u.isValid||(B+=" pvx-row--invalid"),N&&(B+=" pvx-row--personal-best"),e.jsxs("tr",{className:B,children:[e.jsx("td",{className:"pvx-td",children:e.jsx("span",{className:`pvx-rank ${N?"pvx-rank--gold":""}`,children:y+1})}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-md",children:u.lapNumber||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:P(u.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${L?"pvx-td--best-sector":""}`,children:D(u.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${$?"pvx-td--best-sector":""}`,children:D(u.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${w?"pvx-td--best-sector":""}`,children:D(u.sector3Ms)}),e.jsx("td",{className:"pvx-td",title:u.isValid?void 0:u.invalidReason||"Invalid",children:u.isValid?e.jsx(vs,{}):e.jsx(hs,{})}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:ne(u.tyreCompound),children:u.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:re(u.startingFuelL)}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:F(u.timestamp)})]},u.id)})})]})}):e.jsx(U,{message:i?"No laps recorded for this combination.":'No valid laps. Try enabling "Show invalid laps".'})]})}function bs({drivers:s,isLoading:t,getUserDisplay:n,game:r,gameVersion:a,onComboSelect:i}){const[o,c]=W({key:"rank",dir:"asc"}),[d,l]=b.useState(null),p=b.useMemo(()=>s?z(s,o,(g,x)=>{switch(x){case"rating":return g.rating;case"comboCount":return g.comboCount||0;case"distinctCars":return g.distinctCars||0;case"rank":default:return g.rank}}):[],[s,o]);if(t)return e.jsx(E,{});if(!(s!=null&&s.length))return e.jsx("div",{className:"pvx-card",children:e.jsx(U,{message:"Not enough data for rankings yet."})});const v=5;return e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header pvx-rankings-header",children:[e.jsx("h2",{className:"pvx-card-title",children:"Driver Rankings"}),e.jsxs("div",{className:"pvx-rankings-info-trigger",children:[e.jsx("svg",{className:"pvx-rankings-info-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"})}),e.jsxs("div",{className:"pvx-rankings-info-tooltip",children:[e.jsx("p",{className:"pvx-rankings-info-title",children:"How ratings work"}),e.jsxs("ul",{className:"pvx-rankings-info-list",children:[e.jsx("li",{children:"For each car/track combo with 3+ drivers, you're ranked by lap time and given a percentile (100 = fastest, 0 = slowest)"}),e.jsx("li",{children:"Your rating is a weighted average across all your combos — bigger fields count more"}),e.jsx("li",{children:"A confidence adjustment rewards car diversity: the more different cars you drive competitively, the closer your rating reflects your true score"}),e.jsx("li",{children:"Minimum 2 qualifying combos required"})]})]})]})]}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx(R,{label:"#",sortKey:"rank",config:o,onSort:c,className:"pvx-th--narrow"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx(R,{label:"Rating",sortKey:"rating",config:o,onSort:c}),e.jsx(R,{label:"Cars",sortKey:"distinctCars",config:o,onSort:c,className:"pvx-hidden-below-sm"}),e.jsx(R,{label:"Combos",sortKey:"comboCount",config:o,onSort:c,className:"pvx-hidden-below-sm"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:p.map(g=>{const x=d===g.identifier;return e.jsx(ys,{driver:g,getUserDisplay:n,isExpanded:x,onToggle:()=>l(x?null:g.identifier),colCount:v,game:r,gameVersion:a,onComboSelect:i},g.identifier)})})]})})]})}function ys({driver:s,getUserDisplay:t,isExpanded:n,onToggle:r,colCount:a,game:i,gameVersion:o,onComboSelect:c}){const d=s.identifier;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${s.rank<=3?"pvx-row--podium":""}`,onClick:r,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(pe,{rank:s.rank,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(G,{userId:d,getUserDisplay:t})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:s.rating.toFixed(1)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:s.distinctCars||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:e.jsxs("span",{className:"pvx-rankings-combo-count",children:[s.comboCount,e.jsx("svg",{className:`pvx-rankings-chevron ${n?"pvx-rankings-chevron--open":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})})]}),n&&s.combos&&e.jsx("tr",{children:e.jsx("td",{colSpan:a,className:"pvx-rankings-combos-cell",children:e.jsx("div",{className:"pvx-rankings-combos",children:s.combos.map((l,p)=>{const v=l.layout?`${l.trackId}|${l.layout}`:l.trackId,g=c?()=>c({track:v,car:l.carId,highlight:d,game:i,gameVersion:o}):void 0;return e.jsxs("div",{className:`pvx-rankings-combo ${g?"pvx-rankings-combo--clickable":""}`,onClick:g,role:g?"button":void 0,children:[e.jsxs("div",{className:"pvx-rankings-combo-info",children:[e.jsx("p",{className:"pvx-rankings-combo-track",children:I(l.trackId,l.layout,i)}),e.jsx("p",{className:"pvx-rankings-combo-car",children:T(l.carId)})]}),e.jsxs("div",{className:"pvx-rankings-combo-stats",children:[e.jsx("p",{className:"pvx-rankings-combo-time",children:P(l.lapTimeMs)}),e.jsxs("p",{className:`pvx-rankings-combo-pct ${l.percentile>=75?"pvx-rankings-combo-pct--high":l.percentile>=50?"pvx-rankings-combo-pct--mid":l.percentile>=25?"pvx-rankings-combo-pct--low":"pvx-rankings-combo-pct--bottom"}`,children:[l.percentile.toFixed(0),"%",e.jsxs("span",{className:"pvx-rankings-combo-rank",children:["(",l.rank,"/",l.totalDrivers,")"]})]})]})]},p)})})})})]})}const ks={GBR:"🇬🇧",DEU:"🇩🇪",NLD:"🇳🇱",SWE:"🇸🇪",ESP:"🇪🇸",ZAF:"🇿🇦",FRA:"🇫🇷",ITA:"🇮🇹",USA:"🇺🇸",AUS:"🇦🇺",BRA:"🇧🇷",JPN:"🇯🇵",CAN:"🇨🇦",POL:"🇵🇱",AUT:"🇦🇹",BEL:"🇧🇪",PRT:"🇵🇹",NOR:"🇳🇴",DNK:"🇩🇰",FIN:"🇫🇮",IRL:"🇮🇪",CHE:"🇨🇭",NZL:"🇳🇿",MEX:"🇲🇽",ARG:"🇦🇷",CZE:"🇨🇿",HUN:"🇭🇺",RUS:"🇷🇺",TUR:"🇹🇷",KOR:"🇰🇷"},Y=["🥇","🥈","🥉"],Cs={championship:"Championship",series:"Series",event:"Event",hotlap:"Hotlap"},ws=["PRACTICE","QUALIFYING","RACE"];function he(s){const t=ws.indexOf(s);if(t>=0)return t;const n=s.match(/^PRACTICE_(\d+)$/);return n?100+parseInt(n[1]):999}function J(s){const t=s.match(/^PRACTICE_(\d+)$/);return t?`P${t[1]}`:s}function ue({position:s}){const t=s===1?"pvx-rank pvx-rank--gold":s===2?"pvx-rank pvx-rank--silver":s===3?"pvx-rank pvx-rank--bronze":"pvx-rank";return e.jsx("span",{className:t,children:s})}function Z({nation:s}){const t=s&&ks[s];return t?e.jsx("span",{className:"pvx-nation-flag",title:s,children:t}):null}function Ls({sessions:s,activeSession:t,onSelect:n}){if(!s||s.length<=1)return null;const r=[...s].sort((a,i)=>he(a.type)-he(i.type));return e.jsx("div",{className:"pvx-session-tabs",children:r.map(a=>e.jsx("button",{onClick:()=>n(a.type),className:`pvx-session-tab ${t===a.type?"pvx-session-tab--active":""}`,children:J(a.type)},a.type))})}function Pe({type:s}){return e.jsx("span",{className:`pvx-comp-badge pvx-comp-badge--${s}`,children:Cs[s]||s})}function q({children:s,variant:t="default"}){return e.jsx("span",{className:`pvx-info-pill ${t!=="default"?`pvx-info-pill--${t}`:""}`,children:s})}function Ss(s){if(!s)return"TBD";const t=new Date(s);if(isNaN(t))return"TBD";const n=t.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),r=t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return`${n} • ${r}`}function Rs(s){return s.reduce((t,n)=>{var r;return(r=n.splits)!=null&&r.length?t?t.map((a,i)=>{const o=n.splits[i];return o&&o<a?o:a}):[...n.splits]:t},null)}function A({message:s="Loading..."}){return e.jsx("div",{className:"pvx-loading",children:s})}function M({message:s="No data available."}){return e.jsx("div",{className:"pvx-empty",children:e.jsx("p",{children:s})})}const me=3;function Be(s){const t=s==null?void 0:s.rounds;return t!=null&&t.length?s.type==="hotlap"?t.every(n=>n.isFinalized&&n.dediStatus==="completed"):t.every(n=>n.isFinalized):!1}function Ie(s){const t=s==null?void 0:s.rounds;if(!(t!=null&&t.length))return null;let n=null;for(const r of t){if(!r.startTime)continue;const a=new Date(r.startTime);isNaN(a)||(!n||a>n)&&(n=a)}return n}function ve(s,t=me){if(!Be(s))return"active";const n=Ie(s);if(!n)return"recently-completed";const r=t*24*60*60*1e3;return Date.now()-n.getTime()<=r?"recently-completed":"archived"}function Ts(s,t,n=me){if(!(s!=null&&s.length))return[];const r=new Set(Array.isArray(t)?t:[t]);return s.filter(a=>r.has(ve(a,n)))}function Ae(s,t=3){const n=s==null?void 0:s.standings;return Array.isArray(n)?[...n].sort((r,a)=>(r.position??999)-(a.position??999)).slice(0,t):[]}function Fe({competitionId:s,topN:t=3,label:n="Completed",className:r}){const{data:a}=oe(s),i=Ae(a,t);return e.jsxs("div",{className:`pvx-comp-completed-badge ${r||""}`,children:[e.jsx("span",{className:"pvx-comp-completed-badge-label",children:n}),i.length>0&&e.jsx("ol",{className:"pvx-comp-completed-badge-podium",children:i.map((o,c)=>e.jsxs("li",{className:"pvx-comp-completed-badge-driver",children:[e.jsx("span",{className:"pvx-comp-completed-badge-medal","aria-hidden":"true",children:Y[c]||""}),e.jsx(Z,{nation:o.nation}),e.jsx("span",{className:"pvx-comp-completed-badge-name",children:o.driverName})]},o.driverId||c))})]})}function $s({competitions:s,isLoading:t,onSelect:n,onRegister:r,className:a}){return t?e.jsx(A,{message:"Loading competitions..."}):s!=null&&s.length?e.jsx("div",{className:`pvx-comp-grid ${a||""}`,children:s.map(i=>e.jsx(Ue,{comp:i,onSelect:n,onRegister:r||n},i.id))}):e.jsx(M,{message:"No competitions available."})}function Ue({comp:s,onSelect:t,onRegister:n}){var u,y,N;const{cdnUrl:r}=C(),a=s.posterCdnPath?`${r}/${s.posterCdnPath}`:null,i=s.registration,o=(i==null?void 0:i.currentCount)||0,c=i==null?void 0:i.maxParticipants,d=c&&o>=c,l=(i==null?void 0:i.deadline)&&new Date(i.deadline)<new Date,p=(i==null?void 0:i.isOpen)&&!l&&!d,v=new Date,g=(u=s.rounds)==null?void 0:u.find(L=>L.startTime&&new Date(L.startTime)>=v),x=((y=s.rounds)==null?void 0:y.length)||0,f=((N=s.rounds)==null?void 0:N.filter(L=>L.isFinalized).length)||0,h=ve(s),m=h==="recently-completed"||h==="archived",j=s.type==="championship";return e.jsxs("div",{className:"pvx-comp-card",onClick:()=>t(s.id),role:"button",tabIndex:0,onKeyDown:L=>{(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),t(s.id))},children:[e.jsx("div",{className:"pvx-comp-card-poster",children:a?e.jsx("img",{src:a,alt:s.name,className:"pvx-comp-card-poster-img"}):e.jsx("div",{className:"pvx-comp-card-poster-placeholder",children:e.jsx(Ds,{})})}),e.jsxs("div",{className:"pvx-comp-card-body",children:[e.jsx("h3",{className:"pvx-comp-card-title",children:s.name}),s.description&&e.jsx("p",{className:"pvx-comp-card-desc",children:s.description}),e.jsxs("div",{className:"pvx-comp-card-pills",children:[e.jsx(Pe,{type:s.type}),s.game&&e.jsx(q,{children:s.game.toUpperCase()}),s.formatDescription&&s.formatDescription.split(", ").map((L,$)=>e.jsx(q,{variant:"format",children:L},$))]}),s.carsDescription&&e.jsx("div",{className:"pvx-comp-card-pills",children:s.carsDescription.split(", ").map((L,$)=>e.jsx(q,{children:L},$))}),e.jsxs("div",{className:"pvx-comp-card-schedule",children:[g?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[e.jsx("span",{className:"pvx-comp-card-schedule-label",children:"Next:"})," ",s.type!=="hotlap"&&`R${g.roundNumber} `,g.track||"TBD"," · ",Ss(g.startTime)]}):x>0?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[f,"/",x," rounds completed"]}):null,x>0&&e.jsxs("span",{className:"pvx-comp-card-round-count",children:[x," round",x!==1?"s":""]})]}),m&&j&&e.jsx(Fe,{competitionId:s.id}),i&&!m&&e.jsx(Ms,{competitionId:s.id,regOpen:p,isFull:d,deadlinePassed:l,regCount:o,regMax:c,onRegister:n})]})]})}function Ms({competitionId:s,regOpen:t,isFull:n,deadlinePassed:r,regCount:a,regMax:i,onRegister:o}){const{isPowerMode:c}=Q(),d=O(s),{data:l}=H(s),p=(l==null?void 0:l.isRegistered)||!1,v=i?a/i*100:0,g=v>=100?"full":v>=75?"warning":"ok";return e.jsxs("div",{className:"pvx-comp-card-reg",children:[e.jsx("div",{className:"pvx-comp-card-reg-info",children:e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${g}`,children:[a,"/",i||"∞"," drivers"]})}),e.jsx("div",{className:"pvx-comp-card-reg-action",children:p?e.jsx("button",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--registered",onClick:x=>{x.stopPropagation(),o(s)},children:"✓ Registered"}):t?c?e.jsx("button",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--open",onClick:x=>{x.stopPropagation(),o(s)},children:"Register"}):e.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--open",onClick:x=>x.stopPropagation(),children:"Register"}):e.jsx("span",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--closed",children:n?"Full":"Closed"})})]})}function Ds(){return e.jsxs("svg",{className:"pvx-comp-trophy-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 0 1 0-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 0 0 0-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0 0 12 0V2Z"})]})}function Ee({competitionId:s,className:t}){var c,d;const{data:n,isLoading:r}=oe(s),{data:a,isLoading:i}=ie(s);if(r||i)return e.jsx(A,{message:"Loading standings..."});if(!((c=n==null?void 0:n.standings)!=null&&c.length))return e.jsx(M,{message:"No standings data yet. Results will appear once rounds are finalised."});const o=((d=a==null?void 0:a.rounds)==null?void 0:d.filter(l=>l.isFinalized))||[];return e.jsxs("div",{className:`pvx-card ${t||""}`,children:[e.jsx("div",{className:"pvx-card-header--split",children:e.jsxs("div",{className:"pvx-card-header-left",children:[e.jsx("h3",{className:"pvx-card-title",children:"Championship Standings"}),e.jsxs("span",{className:"pvx-standings-subtitle",children:["After ",n.roundsCompleted," round",n.roundsCompleted!==1?"s":"",n.countingRounds>0&&` (best ${n.countingRounds} count)`]})]})}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"W"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"Pod"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"}),o.map(l=>e.jsxs("th",{className:"pvx-th pvx-th--center pvx-hidden-below-md",title:l.track||`Round ${l.roundNumber}`,children:["R",l.roundNumber]},l.roundNumber))]})}),e.jsx("tbody",{className:"pvx-tbody",children:n.standings.map(l=>e.jsx(Ps,{driver:l,finalizedRounds:o},l.driverId||l.driverName))})]})})]})}function Ps({driver:s,finalizedRounds:t}){var o,c,d;const n=s.position<=3,r=new Map(((o=s.roundResults)==null?void 0:o.map(l=>[l.roundNumber,l]))||[]),a=((c=s.roundResults)==null?void 0:c.filter(l=>l.position===1).length)||0,i=((d=s.roundResults)==null?void 0:d.filter(l=>l.position<=3).length)||0;return e.jsxs("tr",{className:`pvx-row ${n?"pvx-row--podium":""}`,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ue,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(Z,{nation:s.nation}),s.driverName]}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:a||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:i||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-standings-total",children:s.totalPoints}),t.map(l=>{const p=r.get(l.roundNumber),v=p==null?void 0:p.dropped;return e.jsx("td",{className:`pvx-td pvx-td--center pvx-hidden-below-md ${!v&&(p==null?void 0:p.position)===1?"pvx-standings-cell--p1":!v&&(p==null?void 0:p.position)===2?"pvx-standings-cell--p2":!v&&(p==null?void 0:p.position)===3?"pvx-standings-cell--p3":""}`,children:p?e.jsxs("div",{className:`pvx-standings-round-cell ${v?"pvx-standings-round-cell--dropped":""}`,children:[e.jsxs("span",{className:"pvx-standings-round-pos",children:["P",p.position]}),e.jsx("span",{className:"pvx-standings-round-pts",children:p.points})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})},l.roundNumber)})]})}function Bs({competitionId:s,roundNumber:t,className:n}){var d;const{data:r,isLoading:a}=we(s,t);if(a)return e.jsx(A,{message:"Loading results..."});if(!r)return e.jsx(M,{message:"No results for this round."});const o=(r.sessions||[]).find(l=>l.type==="RACE"),c=(d=o==null?void 0:o.results)==null?void 0:d.filter(l=>l.position<=3).sort((l,p)=>l.position-p.position);return e.jsxs("div",{className:`pvx-round-results ${n||""}`,children:[e.jsxs("div",{className:"pvx-round-results-header",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"pvx-round-results-title",children:["Round ",r.roundNumber,r.track?`: ${r.track}`:""]}),r.startTime&&e.jsx("p",{className:"pvx-round-results-date",children:new Date(r.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(c==null?void 0:c.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:c.map(l=>e.jsxs("span",{className:"pvx-round-podium-item",children:[e.jsx("span",{children:Y[l.position-1]}),e.jsx("span",{children:l.driverName})]},l.driverId))})]}),e.jsx(X,{round:r,competitionId:s})]})}function X({round:s,competitionId:t,className:n}){var p,v,g,x;const[r,a]=b.useState(null),i=(s==null?void 0:s.sessions)||[];if(!i.length)return e.jsx(M,{message:"No session data for this round."});const{data:o}=Re(t,s==null?void 0:s.roundNumber,{}),c=r||((p=i.find(f=>f.type==="RACE"))==null?void 0:p.type)||((v=i[0])==null?void 0:v.type),d=i.find(f=>f.type===c)||i[0],l=((x=(g=o==null?void 0:o.sessions)==null?void 0:g.find(f=>f.type===c))==null?void 0:x.drivers)||null;return e.jsxs("div",{className:n||"",children:[e.jsx(Ls,{sessions:i,activeSession:c,onSelect:a}),e.jsx(Is,{session:d,sessionLaps:l})]})}function Is({session:s,sessionLaps:t}){var c;const n=s.type==="RACE",[r,a]=b.useState(null);if(!((c=s.results)!=null&&c.length))return e.jsx(M,{message:`No results for ${s.type}.`});const i=Rs(s.results),o=n?7:4;return e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Car"}),e.jsx("th",{className:"pvx-th",children:"Best Lap"}),n&&e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Laps"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Time / Gap"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"})]})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.results.map((d,l)=>{var g;const p=(g=t==null?void 0:t[d.driverId])==null?void 0:g.laps,v=r===d.driverId&&!!p;return e.jsx(As,{result:d,isRace:n,fastestSplits:i,rowIndex:l,hasLapDetail:!!p,isExpanded:v,onToggle:()=>a(v?null:d.driverId),driverLaps:v?p:null,colCount:o},d.driverId||l)})})]})})}function As({result:s,isRace:t,fastestSplits:n,rowIndex:r,hasLapDetail:a,isExpanded:i,onToggle:o,driverLaps:c,colCount:d}){const l=s.position<=3;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row ${l?"pvx-row--podium":""} ${a?"pvx-row--expandable":""}`,onClick:a?o:void 0,style:a?{cursor:"pointer"}:void 0,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ue,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(Z,{nation:s.nation}),s.driverName,s.carNumber!=null&&e.jsxs("span",{className:"pvx-car-number",children:["#",s.carNumber]}),s.penalty&&e.jsx("span",{className:"pvx-penalty",children:s.penalty})]}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:T(s.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx(Us,{bestLap:s.bestLapFormatted,hasBestLap:s.hasBestLap,splits:s.splits,fastestSplits:n,showAbove:r<=1})}),t&&e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:s.lapsCompleted}),e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:s.position===1?s.totalTime||"-":s.gap||"-"}),e.jsxs("td",{className:"pvx-td pvx-td--center",children:[e.jsx("span",{className:"pvx-session-points",children:s.points}),s.pointsOverride!==0&&s.pointsOverride&&e.jsxs("span",{className:"pvx-points-override",children:["(",s.pointsOverride>0?"+":"",s.pointsOverride,")"]})]})]})]}),i&&c&&e.jsx("tr",{className:"pvx-row pvx-row--lap-detail",children:e.jsx("td",{colSpan:d,className:"pvx-td pvx-td--lap-detail",children:e.jsx(Fs,{laps:c})})})]})}function Fs({laps:s}){const t=Math.min(...s.filter(n=>n.valid&&n.timeMs>0).map(n=>n.timeMs));return e.jsxs("table",{className:"pvx-table pvx-table--laps",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Lap"}),e.jsx("th",{className:"pvx-th",children:"Time"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.map(n=>{var a;const r=n.valid&&n.timeMs===t;return e.jsxs("tr",{className:`pvx-row ${n.valid?"":"pvx-row--invalid"} ${r?"pvx-row--fastest":""}`,children:[e.jsx("td",{className:"pvx-td pvx-td--muted",children:n.lap}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:n.time}),(n.splits||[]).map((i,o)=>e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:i},o)),Array.from({length:Math.max(0,3-(((a=n.splits)==null?void 0:a.length)||0))}).map((i,o)=>e.jsx("td",{className:"pvx-td pvx-hidden-below-sm"},`pad-${o}`))]},n.lap)})})]})}function Us({bestLap:s,hasBestLap:t,splits:n,fastestSplits:r,showAbove:a}){return s?e.jsxs("span",{className:`pvx-best-lap-cell ${t?"pvx-best-lap-cell--fastest":""}`,children:[e.jsx("span",{className:"pvx-best-lap-time",children:s}),(n==null?void 0:n.length)>0&&e.jsx("span",{className:"pvx-splits-tooltip-anchor",children:e.jsx("span",{className:`pvx-splits-tooltip ${a?"":"pvx-splits-tooltip--above"}`,children:n.map((i,o)=>{const c=r&&i===r[o];return e.jsxs("span",{className:"pvx-splits-tooltip-row",children:[e.jsxs("span",{className:"pvx-splits-tooltip-label",children:["S",o+1]}),e.jsx("span",{className:c?"pvx-splits-tooltip-best":"",children:i})]},o)})})})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})}function Es({competitionId:s,className:t}){const{getSteamId:n}=C(),{data:r,isLoading:a}=le(s),i=n();if(a)return e.jsx(A,{message:"Loading drivers..."});const o=(r==null?void 0:r.drivers)||(r==null?void 0:r.entries)||[];return o.length?e.jsx("div",{className:`pvx-entry-grid ${t||""}`,children:o.map(c=>{var l,p;const d=i&&c.steamId===i;return e.jsxs("div",{className:`pvx-entry-card ${d?"pvx-entry-card--you":""}`,children:[c.avatarUrl?e.jsx("img",{src:c.avatarUrl,alt:"",className:"pvx-entry-avatar"}):e.jsx("div",{className:"pvx-entry-avatar pvx-entry-avatar--placeholder",children:((p=(l=c.displayName)==null?void 0:l.charAt(0))==null?void 0:p.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-entry-name",children:[c.displayName,d&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},c.steamId||c.driverId)})}):e.jsx(M,{message:"No drivers registered yet."})}function qs({competitionId:s,driverData:t,className:n,children:r}){const{data:a,isLoading:i}=H(s),{isPowerMode:o}=Q(),c=O(s),d=ce(s),l=de(s),p=(a==null?void 0:a.isRegistered)||!1,v=i||d.isPending||l.isPending,g=d.error||l.error||null,x=()=>{o&&d.mutate(t||{})},f=()=>{o&&l.mutate()};return typeof r=="function"?r({isRegistered:p,isLoading:v,register:x,withdraw:f,error:g,isPowerMode:o,registrationUrl:c}):o?e.jsx("button",{className:`pvx-comp-register-btn ${n||""}`,onClick:p?f:x,disabled:v,children:v?"Loading...":p?"Withdraw":"Register"}):e.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:`pvx-comp-register-link ${n||""}`,children:p?"View Registration":"Register on PitVox"})}function _s({competitionId:s,registration:t,onWithdrawSuccess:n,className:r}){const{getSteamId:a}=C(),{isPowerMode:i}=Q(),o=O(s),{data:c,isLoading:d}=H(s),{data:l,isLoading:p}=le(s),v=ce(s),g=de(s),x=a(),f=(c==null?void 0:c.isRegistered)||!1,h=(l==null?void 0:l.drivers)||(l==null?void 0:l.entries)||[],m=t||{},j=h.length||m.currentCount||0,u=m.maxParticipants&&j>=m.maxParticipants,y=m.deadline&&new Date(m.deadline)<new Date,N=m.isOpen&&!y&&!u;return d||p?e.jsx(A,{message:"Loading registration..."}):f?e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx(Ks,{competitionId:s,drivers:h,steamId:x,isPowerMode:i,registrationUrl:o,withdrawMutation:g,onWithdrawSuccess:n,registration:m})}):N?x?i?e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx(Vs,{competitionId:s,registerMutation:v,registration:m})}):e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Register on PitVox"})}):e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:i?e.jsx("div",{className:"pvx-reg-status-msg",children:"Sign in to register for this competition."}):e.jsx("div",{className:"pvx-reg-status-msg",children:e.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Register on PitVox"})})}):e.jsxs("div",{className:`pvx-reg-panel ${r||""}`,children:[e.jsx("div",{className:"pvx-reg-status-msg",children:u?"Registration is full.":y?"Registration deadline has passed.":"Registration is closed."}),h.length>0&&e.jsx(qe,{drivers:h,steamId:x})]})}function Vs({competitionId:s,registerMutation:t,registration:n}){const[r,a]=b.useState(""),[i,o]=b.useState("intermediate"),[c,d]=b.useState(""),l=x=>{x.preventDefault(),t.mutate({discordUsername:r||void 0,experience:i,comments:c||void 0})},p=n||{},v=p.currentCount||0,g=p.maxParticipants;return e.jsxs("form",{className:"pvx-reg-form",onSubmit:l,children:[e.jsxs("div",{className:"pvx-reg-form-header",children:[e.jsx("h3",{className:"pvx-reg-form-title",children:"Register"}),g&&e.jsx(_e,{count:v,max:g})]}),t.error&&e.jsx("div",{className:"pvx-reg-error",children:t.error.message||"Registration failed"}),e.jsxs("div",{className:"pvx-reg-field",children:[e.jsxs("label",{className:"pvx-reg-label",htmlFor:`pvx-discord-${s}`,children:["Discord Username ",e.jsx("span",{className:"pvx-reg-optional",children:"(optional)"})]}),e.jsx("input",{id:`pvx-discord-${s}`,type:"text",className:"pvx-reg-input",placeholder:"e.g. username",value:r,onChange:x=>a(x.target.value)})]}),e.jsxs("div",{className:"pvx-reg-field",children:[e.jsx("label",{className:"pvx-reg-label",htmlFor:`pvx-exp-${s}`,children:"Experience Level"}),e.jsxs("select",{id:`pvx-exp-${s}`,className:"pvx-reg-select",value:i,onChange:x=>o(x.target.value),children:[e.jsx("option",{value:"beginner",children:"Beginner"}),e.jsx("option",{value:"intermediate",children:"Intermediate"}),e.jsx("option",{value:"advanced",children:"Advanced"})]})]}),e.jsxs("div",{className:"pvx-reg-field",children:[e.jsxs("label",{className:"pvx-reg-label",htmlFor:`pvx-comments-${s}`,children:["Comments ",e.jsx("span",{className:"pvx-reg-optional",children:"(optional)"})]}),e.jsx("textarea",{id:`pvx-comments-${s}`,className:"pvx-reg-textarea",rows:3,placeholder:"Anything the organisers should know?",value:c,onChange:x=>d(x.target.value)})]}),e.jsx("div",{className:"pvx-reg-actions",children:e.jsx("button",{type:"submit",className:"pvx-comp-register-btn",disabled:t.isPending,children:t.isPending?"Registering...":"Register"})})]})}function Ks({competitionId:s,drivers:t,steamId:n,isPowerMode:r,registrationUrl:a,withdrawMutation:i,onWithdrawSuccess:o,registration:c}){const[d,l]=b.useState(!1),p=()=>{i.mutate(void 0,{onSuccess:()=>{l(!1),o&&o()}})},v=c||{},g=t.length||v.currentCount||0,x=v.maxParticipants;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pvx-reg-form-header",children:[e.jsx("h3",{className:"pvx-reg-form-title",children:"Registered Drivers"}),x&&e.jsx(_e,{count:g,max:x})]}),e.jsx(qe,{drivers:t,steamId:n}),i.error&&e.jsx("div",{className:"pvx-reg-error",children:i.error.message||"Withdrawal failed"}),r?e.jsx("div",{className:"pvx-reg-actions",children:d?e.jsxs("div",{className:"pvx-reg-confirm",children:[e.jsx("p",{className:"pvx-reg-confirm-text",children:"Are you sure you want to unregister?"}),e.jsxs("div",{className:"pvx-reg-confirm-actions",children:[e.jsx("button",{type:"button",className:"pvx-reg-cancel-btn",onClick:()=>l(!1),children:"Cancel"}),e.jsx("button",{type:"button",className:"pvx-reg-danger-btn",onClick:p,disabled:i.isPending,children:i.isPending?"Unregistering...":"Yes, Unregister"})]})]}):e.jsx("button",{type:"button",className:"pvx-reg-unregister-btn",onClick:()=>l(!0),children:"Unregister"})}):e.jsx("div",{className:"pvx-reg-actions",children:e.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Manage on PitVox"})})]})}function qe({drivers:s,steamId:t}){if(!s.length)return e.jsx("div",{className:"pvx-reg-no-drivers",children:"No drivers registered yet."});const n=[...s].sort((r,a)=>{const i=t&&r.steamId===t?-1:0,o=t&&a.steamId===t?-1:0;return i-o});return e.jsx("div",{className:"pvx-reg-driver-list",children:n.map(r=>{var i,o;const a=t&&r.steamId===t;return e.jsxs("div",{className:`pvx-reg-driver-row ${a?"pvx-reg-driver-row--you":""}`,children:[r.avatarUrl?e.jsx("img",{src:r.avatarUrl,alt:"",className:"pvx-reg-driver-avatar"}):e.jsx("div",{className:"pvx-reg-driver-avatar pvx-reg-driver-avatar--placeholder",children:((o=(i=r.displayName)==null?void 0:i.charAt(0))==null?void 0:o.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-reg-driver-name",children:[r.displayName,a&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},r.steamId||r.driverId)})})}function _e({count:s,max:t}){const n=t?s/t*100:0,r=n>=100?"full":n>=75?"warning":"ok";return e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${r}`,children:[s,"/",t," drivers"]})}function Hs({competitionId:s,className:t}){const{data:n,isLoading:r}=ie(s),a=(n==null?void 0:n.type)==="championship",i=(n==null?void 0:n.type)==="hotlap",{data:o}=Se(i?s:null),c=b.useMemo(()=>{var N;return((N=n==null?void 0:n.rounds)==null?void 0:N.filter(L=>L.isFinalized))||[]},[n]),d=b.useMemo(()=>c.map(N=>N.roundNumber),[c]),{data:l=[],isLoading:p}=Le(s,d),v=i&&l.length>0?l[0]:null,g=(v==null?void 0:v.sessions)||[],x=i?"leaderboard":a?"standings":d.length>0?`round-${d[d.length-1]}`:null,[f,h]=b.useState(null),m=f||x;if(r||p)return e.jsx(A,{message:"Loading results..."});if(!n)return e.jsx(M,{message:"Competition not found."});if(!c.length)return e.jsx(M,{message:"No results available yet. Results will appear here once rounds are finalised."});const j=new Map(l.map(N=>[`round-${N.roundNumber}`,N])),u=[];if(a&&u.push({id:"standings",label:"Standings"}),i){u.push({id:"leaderboard",label:"Leaderboard"});for(const N of g)u.push({id:`session-${N.type}`,label:J(N.type)})}else for(const N of c)u.push({id:`round-${N.roundNumber}`,label:`R${N.roundNumber}`,track:null});const y=j.get(m);return e.jsxs("div",{className:t||"",children:[e.jsx("div",{className:"pvx-results-tabs",children:u.map(N=>e.jsxs("button",{className:`pvx-results-tab ${m===N.id?"pvx-results-tab--active":""}`,onClick:()=>h(N.id),title:N.track||void 0,children:[e.jsx("span",{className:"pvx-results-tab-label",children:N.label}),N.track&&e.jsx("span",{className:"pvx-results-tab-track",children:N.track})]},N.id))}),m==="standings"?e.jsx(Ee,{competitionId:s}):m==="leaderboard"?e.jsx(Os,{leaderboard:o,config:n}):m!=null&&m.startsWith("session-")?e.jsx(Ws,{session:g.find(N=>`session-${N.type}`===m),round:v,competitionId:s}):y?e.jsx(Qs,{round:y,competitionId:s}):e.jsx(M,{message:"No results for this round."})]})}function Qs({round:s,competitionId:t}){var i;const r=(s.sessions||[]).find(o=>o.type==="RACE"),a=(i=r==null?void 0:r.results)==null?void 0:i.filter(o=>o.position<=3).sort((o,c)=>o.position-c.position);return e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header--split",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"pvx-card-title",children:["Round ",s.roundNumber,s.track?`: ${s.track}`:""]}),s.startTime&&e.jsx("span",{className:"pvx-standings-subtitle",children:new Date(s.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(a==null?void 0:a.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:a.map(o=>e.jsxs("span",{className:"pvx-round-podium-item",children:[e.jsx("span",{children:Y[o.position-1]}),e.jsx("span",{children:o.driverName})]},o.driverId))})]}),e.jsx(X,{round:s,competitionId:t})]})}function Os({leaderboard:s,config:t}){var n;return(n=s==null?void 0:s.drivers)!=null&&n.length?e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header--split",children:e.jsxs("div",{children:[e.jsx("h4",{className:"pvx-card-title",children:s.track||(t==null?void 0:t.name)||"Hotlap Leaderboard"}),e.jsxs("span",{className:"pvx-standings-subtitle",children:[s.sessionsCompleted," session",s.sessionsCompleted!==1?"s":""," completed"]})]})}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Car"}),e.jsx("th",{className:"pvx-th",children:"Best Lap"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Laps"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Sessions"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Gap"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.drivers.map(r=>{const a=r.position===1?"":`+${((r.bestLapMs-s.drivers[0].bestLapMs)/1e3).toFixed(3)}`;return e.jsxs("tr",{className:`pvx-row ${r.position<=3?"pvx-row--podium":""}`,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ue,{position:r.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(Z,{nation:r.nation}),r.driverName]}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:T(r.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx("span",{className:r.position===1?"pvx-best-lap-cell--fastest":"",children:r.bestLapFormatted})}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:r.totalLaps}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:r.sessionsParticipated}),e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:a})]},r.driverId)})})]})})]}):e.jsx(M,{message:"No lap times recorded yet."})}function Ws({session:s,round:t,competitionId:n}){return s?e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx("h4",{className:"pvx-card-title",children:J(s.type)})}),e.jsx(X,{round:{...t,sessions:[s]},competitionId:n})]}):e.jsx(M,{message:"Session data not available."})}function Ve(s){const{cdnUrl:t}=C(),n=k.useQuery({queryKey:["pitvox","laps","global",s,"index"],queryFn:()=>S(t,te(null,s)),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),r=n.data;return{isLoading:n.isLoading,error:n.error,data:r?{driverName:r.driverName||"Driver",lapCount:r.lapCount||0,trackBreakdown:r.trackBreakdown||[],carBreakdown:r.carBreakdown||[],recordsHeld:r.recordsHeld||0,currentRecords:r.currentRecords||[],bestRanking:r.bestRanking??null,bestRankingTrackId:r.bestRankingTrackId??null,bestRankingLayout:r.bestRankingLayout??null,bestRankingCarId:r.bestRankingCarId??null,generatedAt:r.generatedAt}:null}}function Ke(s){const{cdnUrl:t,partnerSlug:n}=C(),r=k.useQuery({queryKey:["pitvox","laps",n||"global",s,"index"],queryFn:()=>S(t,te(n,s)),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),a=b.useMemo(()=>{var i;return((i=r.data)==null?void 0:i.combos)||[]},[r.data]);return{isLoading:r.isLoading,error:r.error,data:a}}function He(s={}){const{cdnUrl:t,partnerSlug:n}=C(),{game:r,gameVersion:a,enabled:i=!0}=s,o=V(n,r,a,"ratings.json");return k.useQuery({queryKey:["pitvox","ratings",n,r||null,a||null],queryFn:()=>S(t,o),staleTime:3e4,refetchInterval:3e4,enabled:i})}function zs(s){var r;const t=He(),n=b.useMemo(()=>{var a;return!((a=t.data)!=null&&a.drivers)||!s?null:t.data.drivers.find(i=>i.identifier===s)||null},[(r=t.data)==null?void 0:r.drivers,s]);return{isLoading:t.isLoading,error:t.error,data:n?{rating:n.rating,rank:n.rank,totalDrivers:t.data.driverCount||t.data.drivers.length,comboCount:n.comboCount||0,distinctCars:n.distinctCars||0,combos:n.combos||[]}:null}}function _(s={}){const t=He(s);return{data:t.data||null,isLoading:t.isLoading,error:t.error}}function Qe(s){var d,l;const{versions:t}=ye(),n=(d=t==null?void 0:t.evo)==null?void 0:d.default,r=(l=t==null?void 0:t.lmu)==null?void 0:l.default,a=_({game:"evo",gameVersion:n,enabled:!!n}),i=_({game:"acc"}),o=_({game:"lmu",gameVersion:r,enabled:!!r});return{data:b.useMemo(()=>s?[{data:a.data,game:"evo",label:"EVO"},{data:i.data,game:"acc",label:"ACC"},{data:o.data,game:"lmu",label:"LMU"}].map(({data:p,game:v,label:g})=>{var h;if(!((h=p==null?void 0:p.drivers)!=null&&h.length))return null;const x=[...p.drivers].sort((m,j)=>j.rating-m.rating),f=x.findIndex(m=>m.identifier===s);return f===-1?null:{game:v,label:g,rating:x[f].rating,rank:f+1,totalDrivers:x.length}}).filter(Boolean):[],[s,a.data,i.data,o.data]),isLoading:a.isLoading||i.isLoading||o.isLoading}}function Oe(){const{cdnUrl:s,partnerSlug:t,getSteamId:n,onFetchServerPassword:r}=C(),a=n(),{data:i,isLoading:o}=k.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const x=await S(s,"competitions/index.json");return x!=null&&x.competitions?x.competitions.filter(f=>f.partnerSlug===t):[]},staleTime:6e4}),c=(i==null?void 0:i.map(x=>x.id))||[],d=k.useQueries({queries:c.map(x=>({queryKey:["pitvox","competition",t,x,"entrylist"],queryFn:()=>S(s,`competitions/${t}/${x}/entrylist.json`),enabled:!!a&&c.length>0,staleTime:6e4}))}),l=d.some(x=>x.isLoading),p=b.useMemo(()=>{var h,m;if(!i||!a||l)return[];const x=new Date,f=[];for(let j=0;j<i.length;j++){const u=i[j],y=(h=d[j])==null?void 0:h.data;if(!((m=y==null?void 0:y.drivers)==null?void 0:m.some(w=>w.steamId===a)))continue;const L=u.type==="hotlap",$=u.rounds||[];for(const w of $){if(w.isFinalized&&(!L||w.dediStatus==="completed"))continue;const B=w.dediStatus==="running"||w.dediStatus==="provisioning",ts=w.dediStatus==="scheduled",ns=w.startTime&&new Date(w.startTime)>x,rs=B||ts||w.dediServerAddress;!B&&!ns&&!rs||f.push({competitionId:u.id,competitionName:u.name,roundNumber:w.roundNumber,track:w.track||"TBD",startTime:w.startTime,dediStatus:w.dediStatus||null,dediServerAddress:w.dediServerAddress||null})}}return f.sort((j,u)=>{const y=j.dediStatus==="running"||j.dediStatus==="provisioning",N=u.dediStatus==="running"||u.dediStatus==="provisioning";return y&&!N?-1:!y&&N?1:new Date(j.startTime)-new Date(u.startTime)}),f.length>0&&(f[0].isNext=!0),f},[i,a,l,d]),v=k.useQueries({queries:p.map(x=>({queryKey:["pitvox","serverInfo",x.competitionId,x.roundNumber],queryFn:()=>r(x.competitionId,x.roundNumber),enabled:!!r&&p.length>0,staleTime:5*6e4,retry:!1}))});return{data:b.useMemo(()=>p.length?r?p.map((x,f)=>{var m;const h=(m=v[f])==null?void 0:m.data;return h!=null&&h.success?{...x,serverAddress:h.serverAddress||null,serverPassword:h.serverPassword||null}:x}):p:[],[p,r,v]),isLoading:o||!!a&&l}}function We(){const{onFetchNotifications:s}=C();return!!s}function ze(s={}){const{onFetchNotifications:t,partnerSlug:n}=C(),{limit:r=20,unreadOnly:a=!1}=s;return k.useQuery({queryKey:["pitvox","notifications",n,{limit:r,unreadOnly:a}],queryFn:()=>t({limit:r,unreadOnly:a}),enabled:!!t,staleTime:3e4,refetchInterval:3e4})}function Gs(){const{onFetchNotifications:s,partnerSlug:t}=C(),{data:n,isLoading:r}=k.useQuery({queryKey:["pitvox","notifications",t,{limit:1,unreadOnly:!1}],queryFn:()=>s({limit:1}),enabled:!!s,staleTime:3e4,refetchInterval:3e4,select:a=>(a==null?void 0:a.unreadCount)??0});return{count:n??0,isLoading:r}}function Ge(){const{onMarkNotificationRead:s,partnerSlug:t}=C(),n=k.useQueryClient();return k.useMutation({mutationFn:r=>{if(!s)throw new Error("No onMarkNotificationRead callback provided to PitVoxPartnerProvider.");return s(r)},onSuccess:(r,a)=>{n.setQueriesData({queryKey:["pitvox","notifications",t]},i=>i!=null&&i.notifications?{...i,unreadCount:Math.max(0,(i.unreadCount||0)-1),notifications:i.notifications.map(o=>o.id===a?{...o,isRead:!0,readAt:new Date().toISOString()}:o)}:i)}})}function Ye(){const{onMarkAllNotificationsRead:s,partnerSlug:t}=C(),n=k.useQueryClient();return k.useMutation({mutationFn:()=>{if(!s)throw new Error("No onMarkAllNotificationsRead callback provided to PitVoxPartnerProvider.");return s()},onSuccess:()=>{n.setQueriesData({queryKey:["pitvox","notifications",t]},r=>r!=null&&r.notifications?{...r,unreadCount:0,notifications:r.notifications.map(a=>({...a,isRead:!0,readAt:a.readAt||new Date().toISOString()}))}:r)}})}function Je({driverName:s,avatarUrl:t,memberSince:n,className:r=""}){const a=n?new Date(n).toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"numeric"}):null;return e.jsxs("div",{className:`pvx-card pvx-dash-profile ${r}`,children:[t?e.jsx("img",{src:t,alt:"",className:"pvx-dash-profile-avatar"}):e.jsx("div",{className:"pvx-dash-profile-avatar pvx-dash-profile-avatar--placeholder",children:(s||"?")[0].toUpperCase()}),e.jsxs("div",{className:"pvx-dash-profile-info",children:[e.jsx("h2",{className:"pvx-dash-profile-name",children:s}),a&&e.jsxs("p",{className:"pvx-dash-profile-since",children:["Racing since ",a]})]})]})}function Ys(){return e.jsxs("svg",{className:"pvx-dash-stat-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"4",y1:"9",x2:"20",y2:"9"}),e.jsx("line",{x1:"4",y1:"15",x2:"20",y2:"15"}),e.jsx("line",{x1:"10",y1:"3",x2:"8",y2:"21"}),e.jsx("line",{x1:"16",y1:"3",x2:"14",y2:"21"})]})}function Js(){return e.jsxs("svg",{className:"pvx-dash-stat-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"}),e.jsx("path",{d:"M12 14v4"}),e.jsx("path",{d:"M10.5 12.5l-4 2.5"}),e.jsx("path",{d:"M13.5 12.5l4 2.5"})]})}function ge(){return e.jsx("svg",{className:"pvx-dash-stat-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})})}function je({icon:s,value:t,label:n,items:r,labelKey:a,countKey:i}){const[o,c]=b.useState(!1),d=b.useRef(null);b.useEffect(()=>{if(!o)return;function p(v){d.current&&!d.current.contains(v.target)&&c(!1)}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[o]);const l=r!=null&&r.length?r.slice().sort((p,v)=>v[i]-p[i]):null;return e.jsxs("div",{ref:d,className:`pvx-dash-stat-card ${l?"pvx-dash-stat-card--clickable":""}`,onClick:l?()=>c(p=>!p):void 0,children:[s,e.jsxs("div",{className:"pvx-dash-stat-content",children:[e.jsx("span",{className:"pvx-dash-stat-value",children:t}),e.jsx("span",{className:"pvx-dash-stat-label",children:n})]}),l&&e.jsx("div",{className:`pvx-dash-tooltip pvx-dash-tooltip--scrollable ${o?"pvx-dash-tooltip--open":""}`,children:l.map((p,v)=>e.jsxs("div",{className:"pvx-dash-tooltip-row",children:[e.jsx("span",{className:"pvx-dash-tooltip-label",children:p[a]}),e.jsx("span",{className:"pvx-dash-tooltip-value",children:p[i]})]},v))})]})}function Ze({stats:s,gameRatings:t,onGameRatingSelect:n,rating:r,className:a=""}){if(!s)return null;const i=s.trackBreakdown.map(d=>({name:I(d.trackId,d.layout),lapCount:d.lapCount})),o=s.carBreakdown.map(d=>({name:T(d.carId),lapCount:d.lapCount})),c=Array.isArray(t)&&t.length>0;return e.jsxs("div",{className:`pvx-dash-stats ${a}`,children:[e.jsx(je,{icon:e.jsx(Ys,{}),value:s.lapCount.toLocaleString(),label:"Total Laps",items:i,labelKey:"name",countKey:"lapCount"}),e.jsx(je,{icon:e.jsx(Js,{}),value:s.carBreakdown.length,label:"Cars Used",items:o,labelKey:"name",countKey:"lapCount"}),c?e.jsxs("div",{className:"pvx-dash-stat-card pvx-dash-stat-card--rating-chips",children:[e.jsx(ge,{}),e.jsxs("div",{className:"pvx-dash-stat-content",children:[e.jsx("span",{className:"pvx-dash-stat-label",children:"Driver Rating"}),e.jsx("div",{className:"pvx-dash-rating-chips",children:t.map(d=>{const l=!!n,p=v=>{l&&(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),n(d))};return e.jsxs("span",{className:`pvx-dash-rating-chip${l?" pvx-dash-rating-chip--clickable":""}`,onClick:l?()=>n(d):void 0,onKeyDown:l?p:void 0,role:l?"button":void 0,tabIndex:l?0:void 0,title:`${d.label} rating: ${d.rating.toFixed(1)} (#${d.rank} of ${d.totalDrivers})`,children:[e.jsx("span",{className:"pvx-dash-rating-chip-label",children:d.label}),e.jsx("span",{className:"pvx-dash-rating-chip-value",children:d.rating.toFixed(1)}),e.jsxs("span",{className:"pvx-dash-rating-chip-rank",children:["#",d.rank,"/",d.totalDrivers]})]},d.game)})})]})]}):r?e.jsxs("div",{className:"pvx-dash-stat-card pvx-dash-stat-card--rating",children:[e.jsx(ge,{}),e.jsxs("div",{className:"pvx-dash-stat-content",children:[e.jsx("span",{className:"pvx-dash-stat-value",children:r.rating.toFixed(1)}),e.jsx("span",{className:"pvx-dash-stat-label",children:"Driver Rating"}),e.jsxs("span",{className:"pvx-dash-stat-sub",children:["#",r.rank," of ",r.totalDrivers]})]})]}):null]})}function Xe({combos:s,onComboSelect:t,className:n=""}){return s!=null&&s.length?e.jsxs("div",{className:`pvx-card ${n}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx("span",{className:"pvx-dash-combos-icon",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]})}),"Recent Combos",e.jsxs("span",{className:"pvx-dash-combos-count",children:["(",s.length,")"]})]})}),e.jsx("div",{className:"pvx-dash-combos-list",children:s.map(r=>e.jsx(Zs,{combo:r,onClick:t?()=>t(r):null},`${r.trackId}|${r.trackLayout||""}|${r.carId}|${r.game||""}|${r.gameVersion||""}`))})]}):null}function Zs({combo:s,onClick:t}){const n=s.game||"evo",r=s.gapToLeaderMs&&s.gapToLeaderMs>0?(s.gapToLeaderMs/1e3).toFixed(3):null,a=s.rank===1&&s.totalDrivers>1,i=`pvx-dash-combo-row${t?" pvx-dash-combo-row--clickable":""}`,o=c=>{t&&(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),t())};return e.jsxs("div",{className:i,onClick:t||void 0,onKeyDown:t?o:void 0,role:t?"button":void 0,tabIndex:t?0:void 0,children:[e.jsxs("div",{className:"pvx-dash-combo-info",children:[e.jsxs("div",{className:"pvx-dash-combo-title",children:[s.game&&e.jsx("span",{className:`pvx-dash-game-badge pvx-dash-game-badge--${n}`,children:n.toUpperCase()}),e.jsx("span",{className:"pvx-dash-combo-track",children:I(s.trackId,s.trackLayout,s.game)})]}),e.jsxs("div",{className:"pvx-dash-combo-meta",children:[e.jsx("span",{className:"pvx-dash-combo-car",children:T(s.carId)}),s.lapCount>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"pvx-dash-combo-meta-sep",children:"·"}),e.jsxs("span",{children:[s.lapCount," ",s.lapCount===1?"lap":"laps"]})]}),s.lastDrivenAt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"pvx-dash-combo-meta-sep",children:"·"}),e.jsx("span",{children:K(s.lastDrivenAt)})]})]})]}),e.jsxs("div",{className:"pvx-dash-combo-stats",children:[s.rank?e.jsxs("span",{className:"pvx-dash-combo-rank",children:[a&&e.jsx("span",{className:"pvx-dash-combo-trophy","aria-label":"Leader",title:"Leader",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 010-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 000-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0012 0V2z"})]})}),e.jsxs("span",{className:"pvx-dash-combo-rank-text",children:["P",s.rank,s.totalDrivers?e.jsxs("span",{className:"pvx-dash-combo-rank-total",children:["/",s.totalDrivers]}):null]})]}):s.totalDrivers?e.jsxs("span",{className:"pvx-dash-combo-rank-text pvx-dash-combo-rank-text--muted",children:[s.totalDrivers," on leaderboard"]}):null,r&&e.jsxs("span",{className:"pvx-dash-combo-gap",children:["+",r]}),s.personalBestMs&&e.jsx("span",{className:"pvx-dash-combo-pb",children:P(s.personalBestMs)})]})]})}function es({events:s,isLoading:t,className:n,limit:r=3}){if(t)return e.jsx("div",{className:"pvx-loading",children:"Loading upcoming events..."});if(!(s!=null&&s.length))return null;const a=r?s.slice(0,r):s,i=s.length-a.length;return e.jsxs("div",{className:`pvx-card ${n||""}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(st,{}),"Upcoming Events",e.jsxs("span",{className:"pvx-dash-records-count",children:["(",s.length,")"]})]})}),e.jsxs("div",{className:"pvx-upcoming-list",children:[a.map(o=>e.jsxs("div",{className:`pvx-upcoming-item ${o.isNext?"pvx-upcoming-item--next":""}`,children:[e.jsxs("div",{className:"pvx-upcoming-info",children:[e.jsx("span",{className:"pvx-upcoming-comp",children:o.competitionName}),e.jsxs("span",{className:"pvx-upcoming-round",children:["Round ",o.roundNumber,": ",o.track]}),o.serverPassword&&e.jsx(Xs,{password:o.serverPassword,address:o.serverAddress})]}),e.jsxs("div",{className:"pvx-upcoming-time",children:[e.jsx("span",{className:"pvx-upcoming-date",children:new Date(o.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}),e.jsx("span",{className:"pvx-upcoming-relative",children:o.dediStatus==="running"?"Live now":o.dediStatus==="provisioning"?"Starting...":et(o.startTime)}),o.dediStatus==="running"&&e.jsx("span",{className:"pvx-upcoming-badge pvx-upcoming-badge--live",children:"Live"}),!o.dediStatus&&o.isNext&&e.jsx("span",{className:"pvx-upcoming-badge",children:"Next"})]})]},`${o.competitionId}-${o.roundNumber}`)),i>0&&e.jsxs("div",{className:"pvx-upcoming-remaining",children:["+",i," more event",i!==1?"s":""]})]})]})}function Xs({password:s,address:t}){const[n,r]=b.useState(!1),[a,i]=b.useState(!1),o=t?s?`join:${t}|${s}`:`join:${t}`:null,c=b.useCallback(async()=>{if(o)try{await navigator.clipboard.writeText(o),r(!0),setTimeout(()=>r(!1),2e3)}catch{}},[o]);return e.jsxs("div",{className:"pvx-server-info",children:[o&&e.jsxs("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick:c,title:"Copy join string to clipboard",children:[e.jsx(nt,{})," ",n?"Copied!":"Join"]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick:()=>i(d=>!d),title:a?"Hide password":"Reveal password",children:a?e.jsx(at,{}):e.jsx(rt,{})}),a&&e.jsxs("span",{className:"pvx-server-detail",children:[e.jsx(tt,{})," ",s]})]})]})}function et(s){const t=new Date(s).getTime()-Date.now();if(t<=0)return"Now";const n=Math.floor(t/(1e3*60*60));if(n<1)return"Less than 1 hour";if(n<24)return`in ${n}h`;const r=Math.floor(n/24);if(r===1)return"Tomorrow";if(r<7)return`in ${r} days`;if(r<30){const a=Math.floor(r/7);return`in ${a} week${a!==1?"s":""}`}return K(s)}function st(){return e.jsxs("svg",{className:"pvx-dash-records-icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M16 2v4M8 2v4M3 10h18"})]})}function tt(){return e.jsxs("svg",{className:"pvx-server-icon",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function nt(){return e.jsxs("svg",{className:"pvx-server-icon pvx-server-icon--action",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function rt(){return e.jsxs("svg",{className:"pvx-server-icon pvx-server-icon--action",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function at(){return e.jsxs("svg",{className:"pvx-server-icon pvx-server-icon--action",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),e.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function ss({notifications:s,unreadCount:t=0,onMarkRead:n,onMarkAllRead:r,isLoading:a,className:i}){const o=ae();return a?e.jsx("div",{className:"pvx-loading",children:"Loading notifications..."}):e.jsxs("div",{className:`pvx-card ${i||""}`,children:[e.jsxs("div",{className:"pvx-card-header",children:[e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(lt,{}),"Notifications",t>0&&e.jsx("span",{className:"pvx-notif-badge",children:t>99?"99+":t})]}),t>0&&r&&e.jsx("button",{className:"pvx-notif-mark-all",onClick:r,children:"Mark all read"})]}),s!=null&&s.length?e.jsx("div",{className:"pvx-notif-list",children:s.map(c=>e.jsx(it,{notification:c,getUserDisplay:o,onMarkRead:n},c.id))}):e.jsx("div",{className:"pvx-notif-empty",children:"No notifications"})]})}function it({notification:s,getUserDisplay:t,onMarkRead:n}){const r=()=>{!s.isRead&&n&&n(s.id)};return e.jsxs("button",{className:`pvx-notif-item ${s.isRead?"":"pvx-notif-item--unread"}`,onClick:r,children:[e.jsx(ot,{type:s.type}),e.jsxs("div",{className:"pvx-notif-content",children:[e.jsx("span",{className:"pvx-notif-message",children:be(s,t)}),e.jsx("span",{className:"pvx-notif-time",children:K(s.createdAt)})]}),!s.isRead&&e.jsx("span",{className:"pvx-notif-dot"})]})}function ot({type:s}){return s==="RECORD_BEATEN"?e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--beaten",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m7 7 10 10M17 7v10H7"})})}):s==="ADMIN_MESSAGE"?e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--admin",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"m3 11 18-5v12L3 13v-2z"}),e.jsx("path",{d:"M11.6 16.8a3 3 0 1 1-5.8-1.6"})]})}):e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--record",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 0 1 0-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 0 0 0-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0 0 12 0V2Z"})]})})}function lt(){return e.jsxs("svg",{className:"pvx-dash-records-icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"}),e.jsx("path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0"})]})}function ct({steamId:s,avatarUrl:t,memberSince:n,onComboSelect:r,onGameRatingSelect:a,className:i=""}){const{data:o,isLoading:c,error:d}=Ve(s),{data:l}=Qe(s),{data:p}=Ke(s),{data:v,isLoading:g}=Oe(),x=We(),{data:f,isLoading:h}=ze({limit:10}),m=Ge(),j=Ye();return c?e.jsx("div",{className:"pvx-loading",children:"Loading dashboard..."}):d?e.jsx("div",{className:"pvx-empty",children:"Failed to load dashboard data."}):o?e.jsxs("div",{className:`pvx-dash ${i}`,children:[e.jsx(Je,{driverName:o.driverName,avatarUrl:t,memberSince:n}),e.jsx(Ze,{stats:o,gameRatings:l,onGameRatingSelect:a}),s&&e.jsx(es,{events:v,isLoading:g}),e.jsxs("div",{className:`pvx-dash-row ${x?"pvx-dash-row--2col":""}`,children:[e.jsx(Xe,{combos:p,onComboSelect:r}),x&&e.jsx(ss,{notifications:f==null?void 0:f.notifications,unreadCount:(f==null?void 0:f.unreadCount)||0,onMarkRead:u=>m.mutate(u),onMarkAllRead:()=>j.mutate(),isLoading:h})]})]}):e.jsx("div",{className:"pvx-empty",children:"No data available yet. Start driving to see your stats!"})}function dt({records:s,className:t=""}){const n=b.useMemo(()=>s!=null&&s.length?s.slice().sort((r,a)=>{const i=r.recordedAt?new Date(r.recordedAt).getTime():0;return(a.recordedAt?new Date(a.recordedAt).getTime():0)-i}):[],[s]);return n.length?e.jsxs("div",{className:`pvx-card ${t}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx("span",{className:"pvx-dash-records-icon",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 010-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 000-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0012 0V2z"})]})}),"Current Records",e.jsxs("span",{className:"pvx-dash-records-count",children:["(",n.length,")"]})]})}),e.jsx("div",{className:"pvx-dash-records-list",children:n.map((r,a)=>e.jsxs("div",{className:"pvx-dash-record-row",children:[e.jsxs("div",{className:"pvx-dash-record-info",children:[e.jsx("span",{className:"pvx-dash-record-track",children:I(r.trackId,r.layout,r.game)}),e.jsx("span",{className:"pvx-dash-record-car",children:T(r.carId)})]}),e.jsxs("div",{className:"pvx-dash-record-time",children:[e.jsx("span",{className:"pvx-dash-record-lap",children:P(r.lapTimeMs)}),e.jsxs("span",{className:`pvx-dash-game-badge pvx-dash-game-badge--${r.game||"evo"}`,children:[(r.game||"evo").toUpperCase(),r.gameVersion?` ${r.gameVersion}`:""]})]})]},a))})]}):null}exports.CarsTable=js;exports.CompEmptyState=M;exports.CompLoadingState=A;exports.CompetitionCard=Ue;exports.CompetitionCards=$s;exports.CompetitionResultsTabs=Hs;exports.CompletedBadge=Fe;exports.DEFAULT_COMPLETION_GRACE_DAYS=me;exports.DriverDashboard=ct;exports.DriverProfile=Je;exports.DriversTable=fs;exports.EntryList=Es;exports.InfoPill=q;exports.LapHistoryTable=Ns;exports.NotificationsCard=ss;exports.PODIUM_MEDALS=Y;exports.PitVoxPartnerProvider=os;exports.RankingsTable=bs;exports.RecentCombosCard=Xe;exports.RecordsTable=dt;exports.RegisterButton=qs;exports.RegistrationPanel=_s;exports.RoundResults=Bs;exports.RoundSessionResults=X;exports.StandingsTable=Ee;exports.StatsCards=Ze;exports.TracksTable=gs;exports.TypeBadge=Pe;exports.UpcomingEvents=es;exports.buildDriverIndexPath=te;exports.buildLapsPath=fe;exports.buildLeaderboardPath=V;exports.buildRecentLapsPath=Ne;exports.fetchCdnJson=S;exports.filterCompetitionsByStatus=Ts;exports.formatCarName=T;exports.formatDate=F;exports.formatDelta=ls;exports.formatFuel=re;exports.formatLapTime=P;exports.formatNotificationMessage=be;exports.formatRelativeTime=K;exports.formatSectorTime=D;exports.formatSessionLabel=J;exports.formatTrackName=I;exports.formatTyreCompound=ne;exports.getCompetitionPodium=Ae;exports.getCompetitionStatus=ve;exports.getCompletionDate=Ie;exports.isCompetitionComplete=Be;exports.useCarLeaderboard=ps;exports.useCarMetadata=cs;exports.useCompetitionAllRounds=Le;exports.useCompetitionConfig=ie;exports.useCompetitionEntryList=le;exports.useCompetitionLeaderboard=Se;exports.useCompetitionRound=we;exports.useCompetitionRoundLaps=Re;exports.useCompetitionStandings=oe;exports.useCompetitions=xs;exports.useDriverCombos=Ke;exports.useDriverLaps=Ce;exports.useDriverRating=zs;exports.useDriverRatings=_;exports.useDriverRatingsByGame=Qe;exports.useDriverStats=Ve;exports.useLeaderboardIndex=ye;exports.useMarkAllNotificationsRead=Ye;exports.useMarkNotificationRead=Ge;exports.useNotifications=ze;exports.useNotificationsEnabled=We;exports.usePitVox=C;exports.useRecentLaps=ds;exports.useRegister=ce;exports.useRegistrationMode=Q;exports.useRegistrationStatus=H;exports.useRegistrationUrl=O;exports.useTrackLeaderboard=ke;exports.useUnreadCount=Gs;exports.useUpcomingEvents=Oe;exports.useUserLookup=ae;exports.useWithdraw=de;