@pitvox/partner-react 0.7.22 → 0.7.24
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/README.md +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1467 -1071
- package/dist/styles.css +466 -0
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),C=require("react"),w=require("@tanstack/react-query"),ie=C.createContext(null),hs="https://cdn.pitvox.com",ms="https://pitvox.com";let ae=null;function vs({partnerSlug:s=null,cdnUrl:t=hs,pitvoxUrl:n=ms,getSteamId:r,onRegister:a,onWithdraw:i,onFetchNotifications:o,onMarkNotificationRead:c,onMarkAllNotificationsRead:d,onFetchServerPassword:l,children:p}){const h=C.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 j=!1;try{w.useQueryClient(),j=!0}catch{j=!1}return j?e.jsx(ie.Provider,{value:h,children:p}):(ae||(ae=new w.QueryClient({defaultOptions:{queries:{staleTime:6e4}}})),e.jsx(w.QueryClientProvider,{client:ae,children:e.jsx(ie.Provider,{value:h,children:p})}))}function L(){const s=C.useContext(ie);if(!s)throw new Error("usePitVox must be used within a <PitVoxPartnerProvider>");return s}async function M(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 G(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 we(s,t,n,r){const a=r||"default";return s?`laps/partners/${s}/${t}/${n}/${a}.json`:`laps/${t}/${n}/${a}.json`}function oe(s,t){return s?`laps/partners/${s}/${t}/index.json`:`laps/${t}/index.json`}function Se(s){return s?`recent-laps/partners/${s}.json`:"recent-laps.json"}function I(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 E(s){return!s&&s!==0?"-":s>=6e4?I(s):(s/1e3).toFixed(3)}function A(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 U(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 H(s){if(!s)return"-";try{return new Date(s).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}catch{return"-"}}function z(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`:H(s)}function js(s){return s==null?"":`${s>=0?"+":"-"}${(Math.abs(s)/1e3).toFixed(3)}`}function Le(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?U(a,i,c):null,h=o?A(o):null,j=[p,h].filter(Boolean).join(" — ");return n==="RECORD_BEATEN"&&j?`${l!=null&&l.beatenBySteamId&&t?t(l.beatenBySteamId).displayName:"Someone"} beat your record on ${j}`:n==="RECORD_SET"&&j?`You set a new record on ${j}`:r||"New notification"}function le(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 ce(s){if(!s)return"-";const t=Number(s);return isNaN(t)?"-":t%1?`${t.toFixed(1)}L`:`${t}L`}function Re(s={}){var d,l,p,h,j,x;const{cdnUrl:t,partnerSlug:n}=L(),{game:r,gameVersion:a}=s,i=G(n,null,null,"index.json"),o=w.useQuery({queryKey:["pitvox","leaderboards",n,"index"],queryFn:()=>M(t,i),staleTime:3e4,refetchInterval:3e4}),c=C.useMemo(()=>{var u;if(!((u=o.data)!=null&&u.tracks))return[];let b=o.data.tracks;return r&&(b=b.filter(v=>v.game===r)),a&&(b=b.filter(v=>v.gameVersion===a)),b.map(v=>({id:v.trackId,layout:v.layout,game:v.game,gameVersion:v.gameVersion,displayName:U(v.trackId,v.layout,v.game),driverCount:v.driverCount||0,carCount:v.carCount||0,record:v.recordHolder?{visibleId:v.recordHolder.steamId||v.recordHolder.userId,carId:v.recordHolder.carId,carDisplayName:A(v.recordHolder.carId),lapTimeMs:v.recordHolder.lapTimeMs,timestamp:v.recordHolder.recordedAt}:null,recordByTag:v.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:((j=o.data)==null?void 0:j.totalUsers)||0,versions:((x=o.data)==null?void 0:x.versions)||{}}}function Te(s,t,n={}){const{cdnUrl:r,partnerSlug:a}=L(),{carId:i,game:o,gameVersion:c}=n,d=t||"default",l=G(a,o,c,`tracks/${s}/${d}.json`),{data:p,isLoading:h,error:j}=w.useQuery({queryKey:["pitvox","leaderboards",a,"track",s,d,o,c],queryFn:()=>M(r,l),enabled:!!s,staleTime:3e4,refetchInterval:3e4});return{data:C.useMemo(()=>{if(!(p!=null&&p.entries))return[];let b=p.entries;if(o&&(b=b.filter(u=>u.game===o)),!i){const u=new Map,v=new Map;for(const f of b){const m=f.steamId||f.userId;v.has(f.carId)||v.set(f.carId,new Set),v.get(f.carId).add(m),(!u.has(f.carId)||f.lapTimeMs<u.get(f.carId).lapTimeMs)&&u.set(f.carId,f)}return Array.from(u.values()).map(f=>{var m;return{...f,driverCount:((m=v.get(f.carId))==null?void 0:m.size)||0}}).sort((f,m)=>f.lapTimeMs-m.lapTimeMs)}return b.filter(u=>u.carId===i).sort((u,v)=>u.lapTimeMs-v.lapTimeMs)},[p==null?void 0:p.entries,i,o]),isLoading:h,error:j}}function Me(s,t,n,r,a={}){var u,v;const{cdnUrl:i,partnerSlug:o}=L(),{showInvalid:c=!1,game:d,gameVersion:l}=a,p=s&&t?we(o,s,t,n):null,h=n||"default",j=w.useQuery({queryKey:["pitvox","laps",o,s,t,h],queryFn:()=>M(i,p),enabled:!!s&&!!t,staleTime:3e4,refetchInterval:3e4}),x=C.useMemo(()=>{var f;return(f=j.data)!=null&&f.laps?j.data.laps.filter(m=>!(m.carId!==r||d&&m.game!==d||l&&m.gameVersion!==l||!c&&!m.isValid)).sort((m,y)=>m.lapTimeMs-y.lapTimeMs):[]},[(u=j.data)==null?void 0:u.laps,r,d,l,c]),b=C.useMemo(()=>{const f=x.filter(g=>g.isValid&&g.sector1Ms&&g.sector2Ms&&g.sector3Ms);if(f.length<2)return null;const m=Math.min(...f.map(g=>g.sector1Ms)),y=Math.min(...f.map(g=>g.sector2Ms)),k=Math.min(...f.map(g=>g.sector3Ms)),T=m+y+k,D=Math.min(...f.map(g=>g.lapTimeMs));return T>=D?null:{lapTimeMs:T,sector1Ms:m,sector2Ms:y,sector3Ms:k}},[x]);return{...j,data:x,driverName:((v=j.data)==null?void 0:v.driverName)||"Driver",theoreticalBest:b}}function de(){const{cdnUrl:s}=L(),{data:t}=w.useQuery({queryKey:["pitvox","users","index"],queryFn:()=>M(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 gs(s="evo"){const{cdnUrl:t}=L(),{data:n}=w.useQuery({queryKey:["pitvox","cars",s],queryFn:()=>M(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 fs(){var a,i;const{cdnUrl:s,partnerSlug:t}=L(),n=Se(t),r=w.useQuery({queryKey:["pitvox","recentLaps",t],queryFn:()=>M(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 Ns(s,t){return Te(s,null,{carId:t})}function bs(){const{cdnUrl:s,partnerSlug:t}=L();return w.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const n=await M(s,"competitions/index.json");return n!=null&&n.competitions?t?n.competitions.filter(r=>r.partnerSlug===t):n.competitions:[]},staleTime:6e4})}function pe(s,t={}){const n=L(),r=t.partnerSlug||n.partnerSlug;return w.useQuery({queryKey:["pitvox","competition",r,s,"config"],queryFn:()=>M(n.cdnUrl,`competitions/${r}/${s}/config.json`),enabled:!!r&&!!s,staleTime:6e4})}function xe(s,t={}){const n=L(),r=t.partnerSlug||n.partnerSlug;return w.useQuery({queryKey:["pitvox","competition",r,s,"standings"],queryFn:()=>M(n.cdnUrl,`competitions/${r}/${s}/standings.json`),enabled:!!r&&!!s,staleTime:6e4})}function $e(s,t,n={}){const r=L(),a=n.partnerSlug||r.partnerSlug;return w.useQuery({queryKey:["pitvox","competition",a,s,"round",t],queryFn:()=>M(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}.json`),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function De(s,t=[],n={}){const r=L(),a=n.partnerSlug||r.partnerSlug;return w.useQuery({queryKey:["pitvox","competition",a,s,"allRounds",t],queryFn:async()=>(await Promise.all(t.map(o=>M(r.cdnUrl,`competitions/${a}/${s}/rounds/${o}.json`).catch(()=>null)))).filter(Boolean),enabled:!!a&&!!s&&t.length>0,staleTime:6e4})}function Pe(s,t={}){const n=L(),r=t.partnerSlug||n.partnerSlug;return w.useQuery({queryKey:["pitvox","competition",r,s,"leaderboard"],queryFn:()=>M(n.cdnUrl,`competitions/${r}/${s}/leaderboard.json`).catch(()=>null),enabled:!!r&&!!s,staleTime:6e4})}function Ae(s,t,n={}){const r=L(),a=n.partnerSlug||r.partnerSlug;return w.useQuery({queryKey:["pitvox","competition",a,s,"round",t,"leaderboard"],queryFn:()=>M(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}/leaderboard.json`).catch(()=>null),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function Be(s,t,n={}){const r=L(),a=n.partnerSlug||r.partnerSlug;return w.useQuery({queryKey:["pitvox","competition",a,s,"round",t,"laps"],queryFn:()=>M(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}/laps.json`).catch(()=>null),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function Ee(s,t,n={}){const r=L(),a=n.partnerSlug||r.partnerSlug;return w.useQuery({queryKey:["pitvox","competition",a,s,"round",t,"positions"],queryFn:()=>M(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}/positions.json`).catch(()=>null),enabled:(n.enabled??!0)&&!!a&&!!s&&t!=null,staleTime:6e4})}function ue(s,t={}){const n=L(),r=t.partnerSlug||n.partnerSlug;return w.useQuery({queryKey:["pitvox","competition",r,s,"entrylist"],queryFn:()=>M(n.cdnUrl,`competitions/${r}/${s}/entrylist.json`),enabled:!!r&&!!s,staleTime:6e4})}function Y(s){const{cdnUrl:t,partnerSlug:n,getSteamId:r}=L(),a=r();return w.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 he(s){const{onRegister:t,partnerSlug:n,getSteamId:r}=L(),a=w.useQueryClient(),i=de();return w.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 h;return l?((h=l.drivers)==null?void 0:h.some(j=>j.steamId===o))?l:{...l,drivers:[...l.drivers||[],d]}:{drivers:[d]}})}}})}function me(s){const{onWithdraw:t,partnerSlug:n,getSteamId:r}=L(),a=w.useQueryClient();return w.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 Z(){const{onRegister:s,onWithdraw:t}=L(),n=!!(s&&t);return{isPowerMode:n,isBasicMode:!n}}function J(s){const{pitvoxUrl:t,partnerSlug:n}=L();return`${t}/p/${n}/competitions/${s}/register`}function ys(s,t){for(const n of t)if(n.tags.includes(s))return n.id;return"other"}function Ie(s,t,n=[]){if(t.size===0)return!0;const r={};for(const a of t){const i=ys(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 Fe(s,t){const[n,r]=C.useState(new Set),a=s!==void 0,i=a?s:n,o=C.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=C.useCallback(()=>{a&&t?t(new Set):r(new Set)},[a,t]);return{activeTags:i,toggle:o,clear:c}}function X(s){const[t,n]=C.useState(s),r=C.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 ee(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 _e(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 Cs({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 P({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(Cs,{active:n.key===t,dir:n.dir})]})})}function se({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 ve({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 Ue({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 je({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 V({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 W(){return e.jsx("div",{className:"pvx-loading",children:"Loading..."})}function ks(){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 ws(){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 Ss({tracks:s,isLoading:t,carMetadata:n,getUserDisplay:r,onTrackSelect:a,tags:i,onTagChange:o}){const[c,d]=X({key:"record.timestamp",dir:"desc"}),{activeTags:l,toggle:p,clear:h}=Fe(i,o),j=C.useMemo(()=>{var v;if(!((v=n==null?void 0:n.tags)!=null&&v.length))return[];const u=new Set;for(const f of s||[])f.recordByTag&&Object.keys(f.recordByTag).forEach(m=>u.add(m));return n.tags.filter(f=>u.has(f))},[s,n]),x=C.useMemo(()=>s?l.size===0?s:s.map(u=>{var m,y;if(!u.recordByTag)return null;let v=null;const f=new Set;for(const k of Object.values(u.recordByTag)){if(f.has(k.carId))continue;f.add(k.carId);const T=((y=(m=n==null?void 0:n.cars)==null?void 0:m[k.carId])==null?void 0:y.tags)||[];Ie(T,l,n==null?void 0:n.categories)&&(!v||k.lapTimeMs<v.lapTimeMs)&&(v=k)}return v?{...u,record:{visibleId:v.steamId||v.identifier,carId:v.carId,carDisplayName:A(v.carId),lapTimeMs:v.lapTimeMs,timestamp:v.recordedAt}}:null}).filter(Boolean):[],[s,l,n]),b=C.useMemo(()=>ee(x,c,(u,v)=>{var f,m;switch(v){case"displayName":return u.displayName;case"record.lapTimeMs":return(f=u.record)==null?void 0:f.lapTimeMs;case"driverCount":return u.driverCount||0;case"carCount":return u.carCount||0;case"record.timestamp":default:return(m=u.record)!=null&&m.timestamp?new Date(u.record.timestamp).getTime():0}}),[x,c]);return t?e.jsx(W,{}):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(Ue,{availableTags:j,activeTags:l,onToggle:p,onClear:h,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(P,{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(P,{label:"Lap Time",sortKey:"record.lapTimeMs",config:c,onSort:d}),e.jsx(P,{label:"Drivers",sortKey:"driverCount",config:c,onSort:d,className:"pvx-hidden-below-md"}),e.jsx(P,{label:"Cars",sortKey:"carCount",config:c,onSort:d,className:"pvx-hidden-below-lg"}),e.jsx(P,{label:"Date",sortKey:"record.timestamp",config:c,onSort:d,className:"pvx-hidden-below-xl"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:b.map(u=>{var v,f,m;return e.jsxs("tr",{className:"pvx-row pvx-row--clickable",onClick:()=>a(u.id,u.layout),children:[e.jsx("td",{className:"pvx-td pvx-td--primary",children:u.displayName}),e.jsx("td",{className:"pvx-td",children:(v=u.record)!=null&&v.visibleId?e.jsx(se,{userId:u.record.visibleId,getUserDisplay:r}):"-"}),e.jsx("td",{className:"pvx-td pvx-hidden-below-lg",children:((f=u.record)==null?void 0:f.carDisplayName)||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:u.record?I(u.record.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--center pvx-hidden-below-lg",children:u.carCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:(m=u.record)!=null&&m.timestamp?H(u.record.timestamp):"-"})]},`${u.id}|${u.layout||""}`)})})]})})]}):e.jsx(V,{message:"No lap times recorded yet."})}function Ls({entries:s,isLoading:t,track:n,carMetadata:r,getUserDisplay:a,onCarSelect:i,onNavigate:o,tags:c,onTagChange:d}){const[l,p]=X({key:"lapTimeMs",dir:"asc"}),{activeTags:h,toggle:j,clear:x}=Fe(c,d),b=C.useMemo(()=>{var y,k,T;if(!s||!((y=r==null?void 0:r.tags)!=null&&y.length))return[];const m=new Set;for(const D of s)(((T=(k=r.cars)==null?void 0:k[D.carId])==null?void 0:T.tags)||[]).forEach(S=>m.add(S));return r.tags.filter(D=>m.has(D))},[s,r]),u=C.useMemo(()=>s?h.size===0?s:s.filter(m=>{var k,T;const y=((T=(k=r==null?void 0:r.cars)==null?void 0:k[m.carId])==null?void 0:T.tags)||[];return Ie(y,h,r==null?void 0:r.categories)}):[],[s,h,r]),v=C.useMemo(()=>ee(u,l,(m,y)=>{switch(y){case"carId":return A(m.carId);case"driverCount":return m.driverCount||0;case"lapTimeMs":default:return m.lapTimeMs}}),[u,l]),f=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:n.displayName}];return t?e.jsx(W,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(je,{segments:f})}),e.jsx(Ue,{availableTags:b,activeTags:h,onToggle:j,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(P,{label:"Car",sortKey:"carId",config:l,onSort:p}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx(P,{label:"Lap Time",sortKey:"lapTimeMs",config:l,onSort:p}),e.jsx(P,{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:v.map((m,y)=>e.jsxs("tr",{className:"pvx-row pvx-row--clickable",onClick:()=>i(m.carId),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ve,{rank:y+1,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:A(m.carId)}),e.jsx("td",{className:"pvx-td",children:e.jsx(se,{userId:m.steamId||m.userId,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:I(m.lapTimeMs)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-md",children:m.driverCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-lg",children:m.recordedAt?H(m.recordedAt):"-"})]},m.carId))})]})}):e.jsx(V,{message:"No lap times for this track yet."})]})}function Rs({entries:s,isLoading:t,track:n,carId:r,getUserDisplay:a,onDriverSelect:i,onNavigate:o,highlightId:c}){const[d,l]=X({key:"lapTimeMs",dir:"asc"}),p=C.useMemo(()=>_e(s),[s]),h=C.useMemo(()=>ee(s||[],d,(x,b)=>{switch(b){case"userId":return a(x.steamId||x.userId).displayName;case"lapCount":return x.lapCount||0;case"lapTimeMs":default:return x.lapTimeMs}}),[s,d,a]),j=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:n.displayName,onClick:()=>o("track")},{key:"car",label:A(r)}];return t?e.jsx(W,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(je,{segments:j})}),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(P,{label:"Driver",sortKey:"userId",config:d,onSort:l}),e.jsx(P,{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(P,{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,b)=>{const u=b+1,v=x.steamId||x.userId,f=p&&x.sector1Ms===p.s1,m=p&&x.sector2Ms===p.s2,y=p&&x.sector3Ms===p.s3,k=c&&v===c;return e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${k?"pvx-row--highlight":u<=3?"pvx-row--podium":""}`,onClick:()=>i(v),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ve,{rank:u,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(se,{userId:v,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:I(x.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${f?"pvx-td--best-sector":""}`,children:E(x.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${m?"pvx-td--best-sector":""}`,children:E(x.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${y?"pvx-td--best-sector":""}`,children:E(x.sector3Ms)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:le(x.tyreCompound),children:x.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-xl",children:ce(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?H(x.recordedAt):"-"})]},v)})})]})}):e.jsx(V,{message:"No lap times for this car yet."})]})}function Ts({userId:s,track:t,carId:n,game:r,gameVersion:a,showInvalid:i,getUserDisplay:o,onToggleInvalid:c,onNavigate:d}){const{data:l,driverName:p,theoreticalBest:h,isLoading:j}=Me(s,t.id,t.layout,n,{showInvalid:i,game:r,gameVersion:a}),{displayName:x,avatarUrl:b}=o(s,p),u=C.useMemo(()=>_e(l,!0),[l]),v=C.useMemo(()=>{const m=(l==null?void 0:l.filter(y=>y.isValid))||[];return m.length?Math.min(...m.map(y=>y.lapTimeMs)):null},[l]),f=[{key:"tracks",label:"Tracks",onClick:()=>d("tracks")},{key:"track",label:t.displayName,onClick:()=>d("track")},{key:"car",label:A(n),onClick:()=>d("car")},{key:"driver",label:x}];return j?e.jsx(W,{}):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(je,{segments:f}),b?e.jsx("img",{src:b,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:I(h.lapTimeMs)}),e.jsxs("span",{className:"pvx-theoretical-best-sectors",children:["(",E(h.sector1Ms)," + ",E(h.sector2Ms)," + ",E(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((m,y)=>{const k=m.isValid&&m.lapTimeMs===v,T=u&&m.isValid&&m.sector1Ms===u.s1,D=u&&m.isValid&&m.sector2Ms===u.s2,g=u&&m.isValid&&m.sector3Ms===u.s3;let S="pvx-row";return m.isValid||(S+=" pvx-row--invalid"),k&&(S+=" pvx-row--personal-best"),e.jsxs("tr",{className:S,children:[e.jsx("td",{className:"pvx-td",children:e.jsx("span",{className:`pvx-rank ${k?"pvx-rank--gold":""}`,children:y+1})}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-md",children:m.lapNumber||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:I(m.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${T?"pvx-td--best-sector":""}`,children:E(m.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${D?"pvx-td--best-sector":""}`,children:E(m.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${g?"pvx-td--best-sector":""}`,children:E(m.sector3Ms)}),e.jsx("td",{className:"pvx-td",title:m.isValid?void 0:m.invalidReason||"Invalid",children:m.isValid?e.jsx(ks,{}):e.jsx(ws,{})}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:le(m.tyreCompound),children:m.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:ce(m.startingFuelL)}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:H(m.timestamp)})]},m.id)})})]})}):e.jsx(V,{message:i?"No laps recorded for this combination.":'No valid laps. Try enabling "Show invalid laps".'})]})}function Ms({drivers:s,isLoading:t,getUserDisplay:n,game:r,gameVersion:a,onComboSelect:i}){const[o,c]=X({key:"rank",dir:"asc"}),[d,l]=C.useState(null),p=C.useMemo(()=>s?ee(s,o,(j,x)=>{switch(x){case"rating":return j.rating;case"comboCount":return j.comboCount||0;case"distinctCars":return j.distinctCars||0;case"rank":default:return j.rank}}):[],[s,o]);if(t)return e.jsx(W,{});if(!(s!=null&&s.length))return e.jsx("div",{className:"pvx-card",children:e.jsx(V,{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(P,{label:"#",sortKey:"rank",config:o,onSort:c,className:"pvx-th--narrow"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx(P,{label:"Rating",sortKey:"rating",config:o,onSort:c}),e.jsx(P,{label:"Cars",sortKey:"distinctCars",config:o,onSort:c,className:"pvx-hidden-below-sm"}),e.jsx(P,{label:"Combos",sortKey:"comboCount",config:o,onSort:c,className:"pvx-hidden-below-sm"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:p.map(j=>{const x=d===j.identifier;return e.jsx($s,{driver:j,getUserDisplay:n,isExpanded:x,onToggle:()=>l(x?null:j.identifier),colCount:h,game:r,gameVersion:a,onComboSelect:i},j.identifier)})})]})})]})}function $s({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(ve,{rank:s.rank,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(se,{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 h=l.layout?`${l.trackId}|${l.layout}`:l.trackId,j=c?()=>c({track:h,car:l.carId,highlight:d,game:i,gameVersion:o}):void 0;return e.jsxs("div",{className:`pvx-rankings-combo ${j?"pvx-rankings-combo--clickable":""}`,onClick:j,role:j?"button":void 0,children:[e.jsxs("div",{className:"pvx-rankings-combo-info",children:[e.jsx("p",{className:"pvx-rankings-combo-track",children:U(l.trackId,l.layout,i)}),e.jsx("p",{className:"pvx-rankings-combo-car",children:A(l.carId)})]}),e.jsxs("div",{className:"pvx-rankings-combo-stats",children:[e.jsx("p",{className:"pvx-rankings-combo-time",children:I(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 Ds={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:"🇰🇷"},te=["🥇","🥈","🥉"],Ps={championship:"Championship",series:"Series",event:"Event",hotlap:"Hotlap"},As=["PRACTICE","QUALIFYING","RACE"];function be(s){const t=As.indexOf(s);if(t>=0)return t;const n=s.match(/^PRACTICE_(\d+)$/);return n?100+parseInt(n[1]):999}function K(s){const t=s.match(/^PRACTICE_(\d+)$/);return t?`P${t[1]}`:s}function ge({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 ne({nation:s}){const t=s&&Ds[s];return t?e.jsx("span",{className:"pvx-nation-flag",title:s,children:t}):null}function Bs({sessions:s,activeSession:t,onSelect:n}){if(!s||s.length<=1)return null;const r=[...s].sort((a,i)=>be(a.type)-be(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:K(a.type)},a.type))})}function qe({type:s}){return e.jsx("span",{className:`pvx-comp-badge pvx-comp-badge--${s}`,children:Ps[s]||s})}function O({children:s,variant:t="default"}){return e.jsx("span",{className:`pvx-info-pill ${t!=="default"?`pvx-info-pill--${t}`:""}`,children:s})}function Es(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 Is(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 q({message:s="Loading..."}){return e.jsx("div",{className:"pvx-loading",children:s})}function B({message:s="No data available."}){return e.jsx("div",{className:"pvx-empty",children:e.jsx("p",{children:s})})}const fe=3;function _(s){if(!s)return!1;if(s.closesAt){const t=new Date(s.closesAt).getTime();if(!Number.isNaN(t))return Date.now()>=t}return!!s.isClosed}function He(s){const t=s==null?void 0:s.rounds;return t!=null&&t.length?s.type==="hotlap"?t.every(n=>_(n)):t.every(n=>n.isFinalized):!1}function Ve(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 Ne(s,t=fe){if(!He(s))return"active";const n=Ve(s);if(!n)return"recently-completed";const r=t*24*60*60*1e3;return Date.now()-n.getTime()<=r?"recently-completed":"archived"}function Fs(s,t,n=fe){if(!(s!=null&&s.length))return[];const r=new Set(Array.isArray(t)?t:[t]);return s.filter(a=>r.has(Ne(a,n)))}function We(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 Ke({competitionId:s,topN:t=3,label:n="Completed",className:r}){const{data:a}=xe(s),i=We(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:te[c]||""}),e.jsx(ne,{nation:o.nation}),e.jsx("span",{className:"pvx-comp-completed-badge-name",children:o.driverName})]},o.driverId||c))})]})}const _s={GameModeSelectionWeatherType_CLEAR:"Clear",GameModeSelectionWeatherType_SCATTERED_CLOUDS:"Scattered Clouds",GameModeSelectionWeatherType_BROKEN_CLOUDS:"Broken Clouds",GameModeSelectionWeatherType_OVERCAST:"Overcast",GameModeSelectionWeatherType_DRIZZLE:"Drizzle",GameModeSelectionWeatherType_DAMP:"Damp",GameModeSelectionWeatherType_RAIN:"Rain",GameModeSelectionWeatherType_HEAVY_RAIN:"Heavy Rain"},Us={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"};function qs(){return e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"12",cy:"12",r:"4"}),e.jsx("path",{d:"M12 2v2"}),e.jsx("path",{d:"M12 20v2"}),e.jsx("path",{d:"m4.93 4.93 1.41 1.41"}),e.jsx("path",{d:"m17.66 17.66 1.41 1.41"}),e.jsx("path",{d:"M2 12h2"}),e.jsx("path",{d:"M20 12h2"}),e.jsx("path",{d:"m6.34 17.66-1.41 1.41"}),e.jsx("path",{d:"m19.07 4.93-1.41 1.41"})]})}function Hs(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M12 2v2"}),e.jsx("path",{d:"m4.93 4.93 1.41 1.41"}),e.jsx("path",{d:"M20 12h2"}),e.jsx("path",{d:"m19.07 4.93-1.41 1.41"}),e.jsx("path",{d:"M15.947 12.65a4 4 0 0 0-5.925-4.128"}),e.jsx("path",{d:"M13 22H7a5 5 0 1 1 4.9-6H13a3 3 0 0 1 0 6Z"})]})}function Vs(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M17.5 21H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"}),e.jsx("path",{d:"M22 10a3 3 0 0 0-3-3h-2.207a5.502 5.502 0 0 0-10.702.5"})]})}function Ws(){return e.jsx("path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"})}function Ks(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242"}),e.jsx("path",{d:"M8 19v1"}),e.jsx("path",{d:"M8 14v1"}),e.jsx("path",{d:"M16 19v1"}),e.jsx("path",{d:"M16 14v1"}),e.jsx("path",{d:"M12 21v1"}),e.jsx("path",{d:"M12 16v1"})]})}function Os(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M16 17H7"}),e.jsx("path",{d:"M17 21H9"}),e.jsx("path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242"})]})}function Qs(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242"}),e.jsx("path",{d:"M16 14v6"}),e.jsx("path",{d:"M8 14v6"}),e.jsx("path",{d:"M12 16v6"})]})}function Gs(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242"}),e.jsx("path",{d:"m9.2 22 3-7"}),e.jsx("path",{d:"m9 13-3 7"}),e.jsx("path",{d:"m17 13-3 7"})]})}const zs={GameModeSelectionWeatherType_CLEAR:qs,GameModeSelectionWeatherType_SCATTERED_CLOUDS:Hs,GameModeSelectionWeatherType_BROKEN_CLOUDS:Vs,GameModeSelectionWeatherType_OVERCAST:Ws,GameModeSelectionWeatherType_DRIZZLE:Ks,GameModeSelectionWeatherType_DAMP:Os,GameModeSelectionWeatherType_RAIN:Qs,GameModeSelectionWeatherType_HEAVY_RAIN:Gs};function Oe({weatherType:s,weatherBehaviour:t,className:n}){const r=s?zs[s]:null;if(!r)return null;const a=_s[s]||s,i=t==="GameModeSelectionWeatherBehaviour_DYNAMIC",o=i?`${a} · Dynamic`:a;return e.jsxs("span",{className:`pvx-weather-icon ${n||""}`.trim(),title:o,"aria-label":o,children:[e.jsx("svg",{className:"pvx-weather-icon-main",...Us,children:e.jsx(r,{})}),i&&e.jsx("span",{className:"pvx-weather-icon-dynamic","aria-hidden":"true",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"}),e.jsx("path",{d:"M21 3v5h-5"}),e.jsx("path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"}),e.jsx("path",{d:"M8 16H3v5"})]})})]})}function Ys({competitions:s,isLoading:t,onSelect:n,onRegister:r,className:a}){return t?e.jsx(q,{message:"Loading competitions..."}):s!=null&&s.length?e.jsx("div",{className:`pvx-comp-grid ${a||""}`,children:s.map(i=>e.jsx(Qe,{comp:i,onSelect:n,onRegister:r||n},i.id))}):e.jsx(B,{message:"No competitions available."})}function Qe({comp:s,onSelect:t,onRegister:n}){var D,g,S,N,$;const{cdnUrl:r}=L(),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,j=(D=s.rounds)==null?void 0:D.find(R=>R.startTime&&new Date(R.startTime)<=h&&!_(R)),x=j||((g=s.rounds)==null?void 0:g.find(R=>R.startTime&&new Date(R.startTime)>=h)),b=!!j,u=((S=s.rounds)==null?void 0:S.length)||0,v=s.type==="hotlap",f=v&&u>1,m=v?((N=s.rounds)==null?void 0:N.filter(_).length)||0:(($=s.rounds)==null?void 0:$.filter(R=>R.isFinalized).length)||0,y=Ne(s),k=y==="recently-completed"||y==="archived",T=s.type==="championship";return e.jsxs("div",{className:"pvx-comp-card",onClick:()=>t(s.id),role:"button",tabIndex:0,onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.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(Js,{})})}),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(qe,{type:s.type}),s.game&&e.jsx(O,{children:s.game.toUpperCase()}),s.formatDescription&&s.formatDescription.split(", ").map((R,F)=>e.jsx(O,{variant:"format",children:R},F))]}),s.carsDescription&&e.jsx("div",{className:"pvx-comp-card-pills",children:s.carsDescription.split(", ").map((R,F)=>e.jsx(O,{children:R},F))}),e.jsxs("div",{className:"pvx-comp-card-schedule",children:[x?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[e.jsx("span",{className:"pvx-comp-card-schedule-label",children:b?"Live:":"Next:"})," ",(s.type!=="hotlap"||f)&&`R${x.roundNumber} `,x.track||"TBD"," · ",Es(x.startTime),(x.weatherType||s.weatherType)&&e.jsxs(e.Fragment,{children:[" ",e.jsx(Oe,{weatherType:x.weatherType||s.weatherType,weatherBehaviour:x.weatherBehaviour||s.weatherBehaviour})]})]}):u>0?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[m,"/",u," rounds completed"]}):null,u>0&&e.jsxs("span",{className:"pvx-comp-card-round-count",children:[u," round",u!==1?"s":""]})]}),k&&(T||f)&&e.jsx(Ke,{competitionId:s.id}),i&&!k&&e.jsx(Zs,{competitionId:s.id,regOpen:p,isFull:d,deadlinePassed:l,regCount:o,regMax:c,onRegister:n})]})]})}function Zs({competitionId:s,regOpen:t,isFull:n,deadlinePassed:r,regCount:a,regMax:i,onRegister:o}){const{isPowerMode:c}=Z(),d=J(s),{data:l}=Y(s),p=(l==null?void 0:l.isRegistered)||!1,h=i?a/i*100:0,j=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--${j}`,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 Js(){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 Ge({competitionId:s,className:t}){var l,p,h;const{data:n,isLoading:r}=xe(s),{data:a,isLoading:i}=pe(s);if(r||i)return e.jsx(q,{message:"Loading standings..."});if(!((l=n==null?void 0:n.standings)!=null&&l.length))return e.jsx(B,{message:"No standings data yet. Results will appear once rounds are finalised."});const o=(a==null?void 0:a.type)==="hotlap",c=o?((p=a==null?void 0:a.rounds)==null?void 0:p.filter(_))||[]:((h=a==null?void 0:a.rounds)==null?void 0:h.filter(j=>j.isFinalized))||[],d=n.roundsClosed??n.roundsCompleted??0;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:o?"Overall Standings":"Championship Standings"}),e.jsxs("span",{className:"pvx-standings-subtitle",children:["After ",d," round",d!==1?"s":"",o?" closed":"",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"}),c.map(j=>e.jsxs("th",{className:"pvx-th pvx-th--center pvx-hidden-below-md",title:j.track||`Round ${j.roundNumber}`,children:["R",j.roundNumber]},j.roundNumber))]})}),e.jsx("tbody",{className:"pvx-tbody",children:n.standings.map(j=>e.jsx(Xs,{driver:j,columnRounds:c},j.driverId||j.driverName))})]})})]})}function Xs({driver:s,columnRounds: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(ge,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ne,{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),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)})]})}const ye=["#f59e0b","#3b82f6","#ef4444","#10b981","#8b5cf6","#ec4899","#06b6d4","#f97316","#84cc16","#6366f1","#14b8a6","#e11d48","#a855f7","#0ea5e9","#d946ef","#eab308","#22c55e","#f43f5e","#2dd4bf","#fb923c","#818cf8","#4ade80","#f87171","#38bdf8"];function et(s,t){return s.map(n=>({driverName:n.driverName,carClass:n.carClass,positions:n.positions.map((r,a)=>{const o=s.filter(c=>c.positions[a]!=null).sort((c,d)=>c.positions[a]-d.positions[a]).findIndex(c=>c.driverName===n.driverName);return o===-1?null:o+1})}))}function st({title:s,drivers:t,timingPoints:n}){const[r,a]=C.useState(()=>new Set),i=C.useCallback(g=>{a(S=>{const N=new Set(S);return N.has(g)?N.delete(g):N.add(g),N})},[]),{series:o,maxPos:c}=C.useMemo(()=>{let g=1;return{series:t.map((N,$)=>{for(const R of N.positions)R!=null&&R>g&&(g=R);return{...N,colour:ye[$%ye.length]}}),maxPos:g}},[t]);if(!o.length||n.length<2)return e.jsxs("div",{className:"pvx-positions-empty",children:["No position data for ",s||"this race","."]});const d=800,l=34,p=12,h=12,j=22,x=34,b=d-l-p,u=Math.max(j*(c-1),j),v=h+u+x,f=n.length,m=g=>l+(f===1?0:g/(f-1)*b),y=g=>h+(c===1?0:(g-1)/(c-1)*u),k=g=>{const S=[];let N=[];return g.forEach(($,R)=>{$==null?N.length&&(S.push(N),N=[]):N.push([m(R),y($)])}),N.length&&S.push(N),S},T=r.size>0,D=Math.ceil(f/24);return e.jsxs("div",{className:"pvx-positions-chart",children:[s&&e.jsx("div",{className:"pvx-positions-title",children:s}),e.jsxs("svg",{className:"pvx-positions-svg",viewBox:`0 0 ${d} ${v}`,preserveAspectRatio:"xMidYMid meet",role:"img","aria-label":`Race position progression${s?` — ${s}`:""}`,children:[Array.from({length:c},(g,S)=>S+1).map(g=>e.jsxs("g",{children:[e.jsx("line",{className:"pvx-positions-grid",x1:l,y1:y(g),x2:d-p,y2:y(g)}),e.jsxs("text",{className:"pvx-positions-axis",x:l-6,y:y(g)+3,textAnchor:"end",children:["P",g]})]},`y${g}`)),n.map((g,S)=>S%D===0&&e.jsx("text",{className:"pvx-positions-axis",x:m(S),y:v-x+16,textAnchor:"middle",children:g.label},`x${S}`)),o.map(g=>{const S=T&&!r.has(g.driverName);return e.jsxs("g",{opacity:S?.12:1,children:[k(g.positions).map((N,$)=>e.jsx("polyline",{fill:"none",stroke:g.colour,strokeWidth:S?1:2,points:N.map(([R,F])=>`${R},${F}`).join(" ")},$)),!S&&g.positions.map((N,$)=>N!=null&&e.jsx("circle",{cx:m($),cy:y(N),r:2.4,fill:g.colour,children:e.jsx("title",{children:`${g.driverName} — ${n[$].label}: P${N}`})},$))]},g.driverName)})]}),e.jsxs("div",{className:"pvx-positions-legend",children:[o.map(g=>{const S=T&&!r.has(g.driverName);return e.jsxs("button",{type:"button",className:"pvx-positions-legend-item",style:{opacity:S?.4:1},onClick:()=>i(g.driverName),children:[e.jsx("span",{className:"pvx-positions-swatch",style:{background:g.colour}}),g.driverName]},g.driverName)}),T&&e.jsx("button",{type:"button",className:"pvx-positions-legend-clear",onClick:()=>a(new Set),children:"Clear"})]})]})}function ze({positions:s}){const t=(s==null?void 0:s.timingPoints)||[],n=(s==null?void 0:s.drivers)||[],r=C.useMemo(()=>{const a=[...new Set(n.map(i=>i.carClass).filter(Boolean))];return a.length<=1?[{title:a[0]||null,drivers:n}]:a.sort().map(i=>({title:i,drivers:et(n.filter(o=>o.carClass===i),t.length)}))},[n,t.length]);return!t.length||!n.length?e.jsx("div",{className:"pvx-positions-empty",children:"No position data available for this race."}):e.jsx("div",{className:"pvx-positions",children:r.map((a,i)=>e.jsx(st,{title:r.length>1?a.title:null,drivers:a.drivers,timingPoints:t},a.title||i))})}function tt({competitionId:s,roundNumber:t,className:n}){var d;const{data:r,isLoading:a}=$e(s,t);if(a)return e.jsx(q,{message:"Loading results..."});if(!r)return e.jsx(B,{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:te[l.position-1]}),e.jsx("span",{children:l.driverName})]},l.driverId))})]}),e.jsx(re,{round:r,competitionId:s})]})}function re({round:s,competitionId:t,className:n}){var x,b,u,v,f,m;const[r,a]=C.useState(null),i=(s==null?void 0:s.sessions)||[];if(!i.length)return e.jsx(B,{message:"No session data for this round."});const{data:o}=Be(t,s==null?void 0:s.roundNumber,{}),c=i.some(y=>y.type==="RACE"),{data:d}=Ee(t,s==null?void 0:s.roundNumber,{enabled:!!t&&c}),l=r||((x=i.find(y=>y.type==="RACE"))==null?void 0:x.type)||((b=i[0])==null?void 0:b.type),p=i.find(y=>y.type===l)||i[0],h=((v=(u=o==null?void 0:o.sessions)==null?void 0:u.find(y=>y.type===l))==null?void 0:v.drivers)||null,j=(p==null?void 0:p.type)==="RACE"&&((f=d==null?void 0:d.timingPoints)==null?void 0:f.length)>0&&((m=d==null?void 0:d.drivers)==null?void 0:m.length)>0;return e.jsxs("div",{className:n||"",children:[e.jsx(Bs,{sessions:i,activeSession:l,onSelect:a}),e.jsx(nt,{session:p,sessionLaps:h}),j&&e.jsxs("div",{className:"pvx-positions-section",children:[e.jsx("div",{className:"pvx-positions-section-title",children:"Race Positions"}),e.jsx(ze,{positions:d})]})]})}function nt({session:s,sessionLaps:t}){var p;const n=s.type==="RACE",[r,a]=C.useState(null);if(!((p=s.results)!=null&&p.length))return e.jsx(B,{message:`No results for ${s.type}.`});const i=Is(s.results),o=n?7:4,c=[...new Set(s.results.map(h=>h.carClass).filter(Boolean))],d=c.length>1,l=(h,j,x)=>{var v;const b=(v=t==null?void 0:t[h.driverId])==null?void 0:v.laps,u=r===h.driverId&&!!b;return e.jsx(rt,{result:h,isRace:n,fastestSplits:i,rowIndex:j,displayPosition:x,hasLapDetail:!!b,isExpanded:u,onToggle:()=>a(u?null:h.driverId),driverLaps:u?b:null,colCount:o},h.driverId||j)};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:d?c.sort().map(h=>{const j=s.results.filter(x=>x.carClass===h).sort((x,b)=>(x.classPosition??x.position)-(b.classPosition??b.position));return[e.jsx("tr",{className:"pvx-row pvx-row--class-header",children:e.jsx("td",{colSpan:o,className:"pvx-td pvx-td--class-header",children:h})},`hdr-${h}`),...j.map((x,b)=>l(x,b,x.classPosition??x.position))]}):s.results.map((h,j)=>l(h,j))})]})})}function rt({result:s,isRace:t,fastestSplits:n,rowIndex:r,displayPosition:a,hasLapDetail:i,isExpanded:o,onToggle:c,driverLaps:d,colCount:l}){const p=a??s.position,h=p<=3;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row ${h?"pvx-row--podium":""} ${i?"pvx-row--expandable":""}`,onClick:i?c:void 0,style:i?{cursor:"pointer"}:void 0,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ge,{position:p})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ne,{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:A(s.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx(it,{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,")"]})]})]})]}),o&&d&&e.jsx("tr",{className:"pvx-row pvx-row--lap-detail",children:e.jsx("td",{colSpan:l,className:"pvx-td pvx-td--lap-detail",children:e.jsx(at,{laps:d})})})]})}function at({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 it({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 ot({competitionId:s,className:t}){const{getSteamId:n}=L(),{data:r,isLoading:a}=ue(s),i=n();if(a)return e.jsx(q,{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(B,{message:"No drivers registered yet."})}function lt({competitionId:s,driverData:t,className:n,children:r}){const{data:a,isLoading:i}=Y(s),{isPowerMode:o}=Z(),c=J(s),d=he(s),l=me(s),p=(a==null?void 0:a.isRegistered)||!1,h=i||d.isPending||l.isPending,j=d.error||l.error||null,x=()=>{o&&d.mutate(t||{})},b=()=>{o&&l.mutate()};return typeof r=="function"?r({isRegistered:p,isLoading:h,register:x,withdraw:b,error:j,isPowerMode:o,registrationUrl:c}):o?e.jsx("button",{className:`pvx-comp-register-btn ${n||""}`,onClick:p?b:x,disabled:h,children:h?"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 ct({competitionId:s,registration:t,onWithdrawSuccess:n,className:r}){const{getSteamId:a}=L(),{isPowerMode:i}=Z(),o=J(s),{data:c,isLoading:d}=Y(s),{data:l,isLoading:p}=ue(s),h=he(s),j=me(s),x=a(),b=(c==null?void 0:c.isRegistered)||!1,u=(l==null?void 0:l.drivers)||(l==null?void 0:l.entries)||[],v=t||{},f=u.length||v.currentCount||0,m=v.maxParticipants&&f>=v.maxParticipants,y=v.deadline&&new Date(v.deadline)<new Date,k=v.isOpen&&!y&&!m;return d||p?e.jsx(q,{message:"Loading registration..."}):b?e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx(pt,{competitionId:s,drivers:u,steamId:x,isPowerMode:i,registrationUrl:o,withdrawMutation:j,onWithdrawSuccess:n,registration:v})}):k?x?i?e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx(dt,{competitionId:s,registerMutation:h,registration:v})}):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:m?"Registration is full.":y?"Registration deadline has passed.":"Registration is closed."}),u.length>0&&e.jsx(Ye,{drivers:u,steamId:x})]})}function dt({competitionId:s,registerMutation:t,registration:n}){const[r,a]=C.useState(""),[i,o]=C.useState("intermediate"),[c,d]=C.useState(""),l=x=>{x.preventDefault(),t.mutate({discordUsername:r||void 0,experience:i,comments:c||void 0})},p=n||{},h=p.currentCount||0,j=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"}),j&&e.jsx(Ze,{count:h,max:j})]}),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 pt({competitionId:s,drivers:t,steamId:n,isPowerMode:r,registrationUrl:a,withdrawMutation:i,onWithdrawSuccess:o,registration:c}){const[d,l]=C.useState(!1),p=()=>{i.mutate(void 0,{onSuccess:()=>{l(!1),o&&o()}})},h=c||{},j=t.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(Ze,{count:j,max:x})]}),e.jsx(Ye,{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 Ye({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 Ze({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 xt({competitionId:s,className:t}){const{data:n,isLoading:r}=pe(s),a=(n==null?void 0:n.type)==="championship",i=(n==null?void 0:n.type)==="hotlap",o=C.useMemo(()=>(n==null?void 0:n.rounds)||[],[n]),c=i&&o.length>1,d=i&&!c,{data:l}=Pe(d?s:null),p=C.useMemo(()=>o.filter(N=>N.isFinalized),[o]),h=C.useMemo(()=>p.map(N=>N.roundNumber),[p]),{data:j=[],isLoading:x}=De(s,h),b=d&&j.length>0?j[0]:null,u=(b==null?void 0:b.sessions)||[],v=c?o.find(N=>N.startTime&&new Date(N.startTime)<=new Date&&!_(N)):null,f=c?v?`hlround-${v.roundNumber}`:"standings":d?"leaderboard":a?"standings":h.length>0?`round-${h[h.length-1]}`:null,[m,y]=C.useState(null),k=m||f;if(r||x)return e.jsx(q,{message:"Loading results..."});if(!n)return e.jsx(B,{message:"Competition not found."});if(!p.length)return e.jsx(B,{message:"No results available yet. Results will appear here once rounds are finalised."});const T=new Map(j.map(N=>[`round-${N.roundNumber}`,N])),D=new Map(j.map(N=>[N.roundNumber,N])),g=[];if(c){g.push({id:"standings",label:"Standings"});for(const N of[...o].sort(($,R)=>$.roundNumber-R.roundNumber))g.push({id:`hlround-${N.roundNumber}`,label:`R${N.roundNumber}`,track:N.track||null})}else if(d){g.push({id:"leaderboard",label:"Leaderboard"});for(const N of u)g.push({id:`session-${N.type}`,label:K(N.type)})}else if(a){g.push({id:"standings",label:"Standings"});for(const N of p)g.push({id:`round-${N.roundNumber}`,label:`R${N.roundNumber}`,track:null})}else for(const N of p)g.push({id:`round-${N.roundNumber}`,label:`R${N.roundNumber}`,track:null});let S;if(k==="standings")S=e.jsx(Ge,{competitionId:s});else if(k==="leaderboard")S=e.jsx(Je,{leaderboard:l,config:n});else if(k!=null&&k.startsWith("hlround-")){const N=parseInt(k.slice(8),10),$=o.find(R=>R.roundNumber===N);S=$?e.jsx(ht,{competitionId:s,roundMeta:$,roundData:D.get(N)}):e.jsx(B,{message:"No results for this round."})}else if(k!=null&&k.startsWith("session-"))S=e.jsx(Xe,{session:u.find(N=>`session-${N.type}`===k),round:b,competitionId:s});else{const N=T.get(k);S=N?e.jsx(ut,{round:N,competitionId:s}):e.jsx(B,{message:"No results for this round."})}return e.jsxs("div",{className:t||"",children:[e.jsx("div",{className:"pvx-results-tabs",children:g.map(N=>e.jsxs("button",{className:`pvx-results-tab ${k===N.id?"pvx-results-tab--active":""}`,onClick:()=>y(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))}),S]})}function ut({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:te[o.position-1]}),e.jsx("span",{children:o.driverName})]},o.driverId))})]}),e.jsx(re,{round:s,competitionId:t})]})}function Je({leaderboard:s,config:t,heading:n}){var r;return(r=s==null?void 0:s.drivers)!=null&&r.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:n||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(a=>{const i=a.position===1?"":`+${((a.bestLapMs-s.drivers[0].bestLapMs)/1e3).toFixed(3)}`;return e.jsxs("tr",{className:`pvx-row ${a.position<=3?"pvx-row--podium":""}`,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ge,{position:a.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ne,{nation:a.nation}),a.driverName]}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:A(a.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx("span",{className:a.position===1?"pvx-best-lap-cell--fastest":"",children:a.bestLapFormatted})}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:a.totalLaps}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:a.sessionsParticipated}),e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:i})]},a.driverId)})})]})})]}):e.jsx(B,{message:"No lap times recorded yet."})}function Xe({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:K(s.type)})}),e.jsx(re,{round:{...t,sessions:[s]},competitionId:n})]}):e.jsx(B,{message:"Session data not available."})}function ht({competitionId:s,roundMeta:t,roundData:n}){const{data:r}=Ae(s,t.roundNumber),a=(n==null?void 0:n.sessions)||[],[i,o]=C.useState("leaderboard"),c=[{id:"leaderboard",label:"Leaderboard"},...a.map(p=>({id:`session-${p.type}`,label:K(p.type)}))],d=c.some(p=>p.id===i)?i:"leaderboard",l=`Round ${t.roundNumber}${t.track?` — ${t.track}`:""}`;return e.jsxs("div",{children:[e.jsx("div",{className:"pvx-session-tabs",children:c.map(p=>e.jsx("button",{onClick:()=>o(p.id),className:`pvx-session-tab ${d===p.id?"pvx-session-tab--active":""}`,children:p.label},p.id))}),d==="leaderboard"?e.jsx(Je,{leaderboard:r,heading:l}):e.jsx(Xe,{session:a.find(p=>`session-${p.type}`===d),round:n,competitionId:s})]})}function es(s){const{cdnUrl:t}=L(),n=w.useQuery({queryKey:["pitvox","laps","global",s,"index"],queryFn:()=>M(t,oe(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 ss(s){const{cdnUrl:t,partnerSlug:n}=L(),r=w.useQuery({queryKey:["pitvox","laps",n||"global",s,"index"],queryFn:()=>M(t,oe(n,s)),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),a=C.useMemo(()=>{var i;return((i=r.data)==null?void 0:i.combos)||[]},[r.data]);return{isLoading:r.isLoading,error:r.error,data:a}}function ts(s={}){const{cdnUrl:t,partnerSlug:n}=L(),{game:r,gameVersion:a,enabled:i=!0}=s,o=G(n,r,a,"ratings.json");return w.useQuery({queryKey:["pitvox","ratings",n,r||null,a||null],queryFn:()=>M(t,o),staleTime:3e4,refetchInterval:3e4,enabled:i})}function mt(s){var r;const t=ts(),n=C.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 Q(s={}){const t=ts(s);return{data:t.data||null,isLoading:t.isLoading,error:t.error}}function ns(s){var d,l;const{versions:t}=Re(),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=Q({game:"evo",gameVersion:n,enabled:!!n}),i=Q({game:"acc"}),o=Q({game:"lmu",gameVersion:r,enabled:!!r});return{data:C.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:h,label:j})=>{var u;if(!((u=p==null?void 0:p.drivers)!=null&&u.length))return null;const x=[...p.drivers].sort((v,f)=>f.rating-v.rating),b=x.findIndex(v=>v.identifier===s);return b===-1?null:{game:h,label:j,rating:x[b].rating,rank:b+1,totalDrivers:x.length}}).filter(Boolean):[],[s,a.data,i.data,o.data]),isLoading:a.isLoading||i.isLoading||o.isLoading}}function rs(){const{cdnUrl:s,partnerSlug:t,getSteamId:n,onFetchServerPassword:r}=L(),a=n(),{data:i,isLoading:o}=w.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const x=await M(s,"competitions/index.json");return x!=null&&x.competitions?x.competitions.filter(b=>b.partnerSlug===t):[]},staleTime:6e4}),c=(i==null?void 0:i.map(x=>x.id))||[],d=w.useQueries({queries:c.map(x=>({queryKey:["pitvox","competition",t,x,"entrylist"],queryFn:()=>M(s,`competitions/${t}/${x}/entrylist.json`),enabled:!!a&&c.length>0,staleTime:6e4}))}),l=d.some(x=>x.isLoading),p=C.useMemo(()=>{var u,v;if(!i||!a||l)return[];const x=new Date,b=[];for(let f=0;f<i.length;f++){const m=i[f],y=(u=d[f])==null?void 0:u.data;if(!((v=y==null?void 0:y.drivers)==null?void 0:v.some(g=>g.steamId===a)))continue;const T=m.type==="hotlap",D=m.rounds||[];for(const g of D){if(T?_(g):g.isFinalized)continue;const N=g.dediStatus==="running"||g.dediStatus==="provisioning",$=g.dediStatus==="scheduled",R=g.startTime&&new Date(g.startTime)>x,F=N||$||g.dediServerAddress;!N&&!R&&!F||b.push({competitionId:m.id,competitionName:m.name,roundNumber:g.roundNumber,track:g.track||"TBD",startTime:g.startTime,dediStatus:g.dediStatus||null,dediServerAddress:g.dediServerAddress||null})}}return b.sort((f,m)=>{const y=f.dediStatus==="running"||f.dediStatus==="provisioning",k=m.dediStatus==="running"||m.dediStatus==="provisioning";return y&&!k?-1:!y&&k?1:new Date(f.startTime)-new Date(m.startTime)}),b.length>0&&(b[0].isNext=!0),b},[i,a,l,d]),h=w.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:C.useMemo(()=>p.length?r?p.map((x,b)=>{var v;const u=(v=h[b])==null?void 0:v.data;return u!=null&&u.success?{...x,serverAddress:u.serverAddress||null,serverPassword:u.serverPassword||null}:x}):p:[],[p,r,h]),isLoading:o||!!a&&l}}function as(){const{onFetchNotifications:s}=L();return!!s}function is(s={}){const{onFetchNotifications:t,partnerSlug:n}=L(),{limit:r=20,unreadOnly:a=!1}=s;return w.useQuery({queryKey:["pitvox","notifications",n,{limit:r,unreadOnly:a}],queryFn:()=>t({limit:r,unreadOnly:a}),enabled:!!t,staleTime:3e4,refetchInterval:3e4})}function vt(){const{onFetchNotifications:s,partnerSlug:t}=L(),{data:n,isLoading:r}=w.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 os(){const{onMarkNotificationRead:s,partnerSlug:t}=L(),n=w.useQueryClient();return w.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 ls(){const{onMarkAllNotificationsRead:s,partnerSlug:t}=L(),n=w.useQueryClient();return w.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 cs({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 jt(){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 gt(){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 Ce(){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 ke({icon:s,value:t,label:n,items:r,labelKey:a,countKey:i}){const[o,c]=C.useState(!1),d=C.useRef(null);C.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: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,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 ds({stats:s,gameRatings:t,onGameRatingSelect:n,rating:r,className:a=""}){if(!s)return null;const i=s.trackBreakdown.map(d=>({name:U(d.trackId,d.layout),lapCount:d.lapCount})),o=s.carBreakdown.map(d=>({name:A(d.carId),lapCount:d.lapCount})),c=Array.isArray(t)&&t.length>0;return e.jsxs("div",{className:`pvx-dash-stats ${a}`,children:[e.jsx(ke,{icon:e.jsx(jt,{}),value:s.lapCount.toLocaleString(),label:"Total Laps",items:i,labelKey:"name",countKey:"lapCount"}),e.jsx(ke,{icon:e.jsx(gt,{}),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(Ce,{}),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=h=>{l&&(h.key==="Enter"||h.key===" ")&&(h.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(Ce,{}),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 ps({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(ft,{combo:r,onClick:t?()=>t(r):null},`${r.trackId}|${r.trackLayout||""}|${r.carId}|${r.game||""}|${r.gameVersion||""}`))})]}):null}function ft({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:U(s.trackId,s.trackLayout,s.game)})]}),e.jsxs("div",{className:"pvx-dash-combo-meta",children:[e.jsx("span",{className:"pvx-dash-combo-car",children:A(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:z(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:I(s.personalBestMs)})]})]})}function xs({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(yt,{}),"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(Nt,{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...":bt(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 Nt({password:s,address:t}){const[n,r]=C.useState(!1),[a,i]=C.useState(!1),o=t?s?`join:${t}|${s}`:`join:${t}`:null,c=C.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(kt,{})," ",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(St,{}):e.jsx(wt,{})}),a&&e.jsxs("span",{className:"pvx-server-detail",children:[e.jsx(Ct,{})," ",s]})]})]})}function bt(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 z(s)}function yt(){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 Ct(){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 kt(){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 wt(){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 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:"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 us({notifications:s,unreadCount:t=0,onMarkRead:n,onMarkAllRead:r,isLoading:a,className:i}){const o=de();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(Tt,{}),"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(Lt,{notification:c,getUserDisplay:o,onMarkRead:n},c.id))}):e.jsx("div",{className:"pvx-notif-empty",children:"No notifications"})]})}function Lt({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(Rt,{type:s.type}),e.jsxs("div",{className:"pvx-notif-content",children:[e.jsx("span",{className:"pvx-notif-message",children:Le(s,t)}),e.jsx("span",{className:"pvx-notif-time",children:z(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 Tt(){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 Mt({steamId:s,avatarUrl:t,memberSince:n,hideProfile:r=!1,onComboSelect:a,onGameRatingSelect:i,className:o=""}){const{data:c,isLoading:d,error:l}=es(s),{data:p}=ns(s),{data:h}=ss(s),{data:j,isLoading:x}=rs(),b=as(),{data:u,isLoading:v}=is({limit:10}),f=os(),m=ls();return d?e.jsx("div",{className:"pvx-loading",children:"Loading dashboard..."}):l?e.jsx("div",{className:"pvx-empty",children:"Failed to load dashboard data."}):c?e.jsxs("div",{className:`pvx-dash ${o}`,children:[!r&&e.jsx(cs,{driverName:c.driverName,avatarUrl:t,memberSince:n}),e.jsx(ds,{stats:c,gameRatings:p,onGameRatingSelect:i}),s&&e.jsx(xs,{events:j,isLoading:x}),e.jsxs("div",{className:`pvx-dash-row ${b?"pvx-dash-row--2col":""}`,children:[e.jsx(ps,{combos:h,onComboSelect:a}),b&&e.jsx(us,{notifications:u==null?void 0:u.notifications,unreadCount:(u==null?void 0:u.unreadCount)||0,onMarkRead:y=>f.mutate(y),onMarkAllRead:()=>m.mutate(),isLoading:v})]})]}):e.jsx("div",{className:"pvx-empty",children:"No data available yet. Start driving to see your stats!"})}function $t({records:s,className:t=""}){const n=C.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:U(r.trackId,r.layout,r.game)}),e.jsx("span",{className:"pvx-dash-record-car",children:A(r.carId)})]}),e.jsxs("div",{className:"pvx-dash-record-time",children:[e.jsx("span",{className:"pvx-dash-record-lap",children:I(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=Ls;exports.CompEmptyState=B;exports.CompLoadingState=q;exports.CompetitionCard=Qe;exports.CompetitionCards=Ys;exports.CompetitionResultsTabs=xt;exports.CompletedBadge=Ke;exports.DEFAULT_COMPLETION_GRACE_DAYS=fe;exports.DriverDashboard=Mt;exports.DriverProfile=cs;exports.DriversTable=Rs;exports.EntryList=ot;exports.InfoPill=O;exports.LapHistoryTable=Ts;exports.NotificationsCard=us;exports.PODIUM_MEDALS=te;exports.PitVoxPartnerProvider=vs;exports.RacePositionsChart=ze;exports.RankingsTable=Ms;exports.RecentCombosCard=ps;exports.RecordsTable=$t;exports.RegisterButton=lt;exports.RegistrationPanel=ct;exports.RoundResults=tt;exports.RoundSessionResults=re;exports.StandingsTable=Ge;exports.StatsCards=ds;exports.TracksTable=Ss;exports.TypeBadge=qe;exports.UpcomingEvents=xs;exports.WeatherIcon=Oe;exports.buildDriverIndexPath=oe;exports.buildLapsPath=we;exports.buildLeaderboardPath=G;exports.buildRecentLapsPath=Se;exports.fetchCdnJson=M;exports.filterCompetitionsByStatus=Fs;exports.formatCarName=A;exports.formatDate=H;exports.formatDelta=js;exports.formatFuel=ce;exports.formatLapTime=I;exports.formatNotificationMessage=Le;exports.formatRelativeTime=z;exports.formatSectorTime=E;exports.formatSessionLabel=K;exports.formatTrackName=U;exports.formatTyreCompound=le;exports.getCompetitionPodium=We;exports.getCompetitionStatus=Ne;exports.getCompletionDate=Ve;exports.isCompetitionComplete=He;exports.isRoundClosed=_;exports.useCarLeaderboard=Ns;exports.useCarMetadata=gs;exports.useCompetitionAllRounds=De;exports.useCompetitionConfig=pe;exports.useCompetitionEntryList=ue;exports.useCompetitionLeaderboard=Pe;exports.useCompetitionRound=$e;exports.useCompetitionRoundLaps=Be;exports.useCompetitionRoundLeaderboard=Ae;exports.useCompetitionRoundPositions=Ee;exports.useCompetitionStandings=xe;exports.useCompetitions=bs;exports.useDriverCombos=ss;exports.useDriverLaps=Me;exports.useDriverRating=mt;exports.useDriverRatings=Q;exports.useDriverRatingsByGame=ns;exports.useDriverStats=es;exports.useLeaderboardIndex=Re;exports.useMarkAllNotificationsRead=ls;exports.useMarkNotificationRead=os;exports.useNotifications=is;exports.useNotificationsEnabled=as;exports.usePitVox=L;exports.useRecentLaps=fs;exports.useRegister=he;exports.useRegistrationMode=Z;exports.useRegistrationStatus=Y;exports.useRegistrationUrl=J;exports.useTrackLeaderboard=Te;exports.useUnreadCount=vt;exports.useUpcomingEvents=rs;exports.useUserLookup=de;exports.useWithdraw=me;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),w=require("react"),k=require("@tanstack/react-query"),As=require("react-markdown"),ce=w.createContext(null),Bs="https://cdn.pitvox.com",Us="https://pitvox.com";let le=null;function Is({partnerSlug:s=null,cdnUrl:t=Bs,pitvoxUrl:n=Us,getSteamId:r,onRegister:a,onWithdraw:o,onFetchNotifications:i,onMarkNotificationRead:c,onMarkAllNotificationsRead:d,onFetchServerPassword:l,onEnterPromotion:p,onWithdrawPromotionEntry:m,children:g}){const x=w.useMemo(()=>({partnerSlug:s,cdnUrl:t.replace(/\/$/,""),pitvoxUrl:n.replace(/\/$/,""),getSteamId:r||(()=>null),onRegister:a||null,onWithdraw:o||null,onFetchNotifications:i||null,onMarkNotificationRead:c||null,onMarkAllNotificationsRead:d||null,onFetchServerPassword:l||null,onEnterPromotion:p||null,onWithdrawPromotionEntry:m||null}),[s,t,n,r,a,o,i,c,d,l,p,m]);let f=!1;try{k.useQueryClient(),f=!0}catch{f=!1}return f?e.jsx(ce.Provider,{value:x,children:g}):(le||(le=new k.QueryClient({defaultOptions:{queries:{staleTime:6e4}}})),e.jsx(k.QueryClientProvider,{client:le,children:e.jsx(ce.Provider,{value:x,children:g})}))}function S(){const s=w.useContext(ce);if(!s)throw new Error("usePitVox must be used within a <PitVoxPartnerProvider>");return s}async function T(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 Y(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 Pe(s,t,n,r){const a=r||"default";return s?`laps/partners/${s}/${t}/${n}/${a}.json`:`laps/${t}/${n}/${a}.json`}function xe(s,t){return s?`laps/partners/${s}/${t}/index.json`:`laps/${t}/index.json`}function De(s){return s?`recent-laps/partners/${s}.json`:"recent-laps.json"}function U(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 B(s){return!s&&s!==0?"-":s>=6e4?U(s):(s/1e3).toFixed(3)}function A(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 W(s,t,n){if(!s)return"";const r=s.split("_").map(i=>i.charAt(0).toUpperCase()+i.slice(1)).join(" "),a=n==="acc"||!n&&(t==null?void 0:t.toLowerCase())==="track config";if(!t||t==="default"||a)return r;const o=t.split("_").map(i=>i.charAt(0).toUpperCase()+i.slice(1)).join(" ");return`${r} ${o}`}function V(s){if(!s)return"-";try{return new Date(s).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}catch{return"-"}}function Z(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 o=Math.floor(a/24);return o<30?`${o}d ago`:V(s)}function _s(s){return s==null?"":`${s>=0?"+":"-"}${(Math.abs(s)/1e3).toFixed(3)}`}function Ee(s,t){const{type:n,title:r,trackId:a,trackLayout:o,carId:i,game:c,data:d}=s,l=typeof d=="string"?JSON.parse(d):d,p=a?W(a,o,c):null,m=i?A(i):null,g=[p,m].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 ue(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 me(s){if(!s)return"-";const t=Number(s);return isNaN(t)?"-":t%1?`${t.toFixed(1)}L`:`${t}L`}function Ae(s={}){var d,l,p,m,g,x;const{cdnUrl:t,partnerSlug:n}=S(),{game:r,gameVersion:a}=s,o=Y(n,null,null,"index.json"),i=k.useQuery({queryKey:["pitvox","leaderboards",n,"index"],queryFn:()=>T(t,o),staleTime:3e4,refetchInterval:3e4}),c=w.useMemo(()=>{var h;if(!((h=i.data)!=null&&h.tracks))return[];let f=i.data.tracks;return r&&(f=f.filter(u=>u.game===r)),a&&(f=f.filter(u=>u.gameVersion===a)),f.map(u=>({id:u.trackId,layout:u.layout,game:u.game,gameVersion:u.gameVersion,displayName:W(u.trackId,u.layout,u.game),driverCount:u.driverCount||0,carCount:u.carCount||0,record:u.recordHolder?{visibleId:u.recordHolder.steamId||u.recordHolder.userId,carId:u.recordHolder.carId,carDisplayName:A(u.recordHolder.carId),lapTimeMs:u.recordHolder.lapTimeMs,timestamp:u.recordHolder.recordedAt}:null,recordByTag:u.recordByTag||null}))},[(d=i.data)==null?void 0:d.tracks,r,a]);return{...i,data:c,partner:((l=i.data)==null?void 0:l.partner)||null,generatedAt:(p=i.data)==null?void 0:p.generatedAt,totalLaps:((m=i.data)==null?void 0:m.totalLaps)||0,totalUsers:((g=i.data)==null?void 0:g.totalUsers)||0,versions:((x=i.data)==null?void 0:x.versions)||{}}}function Be(s,t,n={}){const{cdnUrl:r,partnerSlug:a}=S(),{carId:o,game:i,gameVersion:c}=n,d=t||"default",l=Y(a,i,c,`tracks/${s}/${d}.json`),{data:p,isLoading:m,error:g}=k.useQuery({queryKey:["pitvox","leaderboards",a,"track",s,d,i,c],queryFn:()=>T(r,l),enabled:!!s,staleTime:3e4,refetchInterval:3e4});return{data:w.useMemo(()=>{if(!(p!=null&&p.entries))return[];let f=p.entries;if(i&&(f=f.filter(h=>h.game===i)),!o){const h=new Map,u=new Map;for(const N of f){const v=N.steamId||N.userId;u.has(N.carId)||u.set(N.carId,new Set),u.get(N.carId).add(v),(!h.has(N.carId)||N.lapTimeMs<h.get(N.carId).lapTimeMs)&&h.set(N.carId,N)}return Array.from(h.values()).map(N=>{var v;return{...N,driverCount:((v=u.get(N.carId))==null?void 0:v.size)||0}}).sort((N,v)=>N.lapTimeMs-v.lapTimeMs)}return f.filter(h=>h.carId===o).sort((h,u)=>h.lapTimeMs-u.lapTimeMs)},[p==null?void 0:p.entries,o,i]),isLoading:m,error:g}}function Ue(s,t,n,r,a={}){var h,u;const{cdnUrl:o,partnerSlug:i}=S(),{showInvalid:c=!1,game:d,gameVersion:l}=a,p=s&&t?Pe(i,s,t,n):null,m=n||"default",g=k.useQuery({queryKey:["pitvox","laps",i,s,t,m],queryFn:()=>T(o,p),enabled:!!s&&!!t,staleTime:3e4,refetchInterval:3e4}),x=w.useMemo(()=>{var N;return(N=g.data)!=null&&N.laps?g.data.laps.filter(v=>!(v.carId!==r||d&&v.game!==d||l&&v.gameVersion!==l||!c&&!v.isValid)).sort((v,b)=>v.lapTimeMs-b.lapTimeMs):[]},[(h=g.data)==null?void 0:h.laps,r,d,l,c]),f=w.useMemo(()=>{const N=x.filter(j=>j.isValid&&j.sector1Ms&&j.sector2Ms&&j.sector3Ms);if(N.length<2)return null;const v=Math.min(...N.map(j=>j.sector1Ms)),b=Math.min(...N.map(j=>j.sector2Ms)),C=Math.min(...N.map(j=>j.sector3Ms)),$=v+b+C,P=Math.min(...N.map(j=>j.lapTimeMs));return $>=P?null:{lapTimeMs:$,sector1Ms:v,sector2Ms:b,sector3Ms:C}},[x]);return{...g,data:x,driverName:((u=g.data)==null?void 0:u.driverName)||"Driver",theoreticalBest:f}}function J(){const{cdnUrl:s}=S(),{data:t}=k.useQuery({queryKey:["pitvox","users","index"],queryFn:()=>T(s,"users/index.json"),staleTime:5*6e4,gcTime:30*6e4}),n=(t==null?void 0:t.users)||{};return(r,a)=>{const o=n[r];return{displayName:(o==null?void 0:o.displayName)||a||r||"Unknown",avatarUrl:(o==null?void 0:o.avatarUrl)||null,affiliations:(o==null?void 0:o.affiliations)||[]}}}function Fs(s="evo"){const{cdnUrl:t}=S(),{data:n}=k.useQuery({queryKey:["pitvox","cars",s],queryFn:()=>T(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 qs(){var a,o;const{cdnUrl:s,partnerSlug:t}=S(),n=De(t),r=k.useQuery({queryKey:["pitvox","recentLaps",t],queryFn:()=>T(s,n),staleTime:3e4,refetchInterval:3e4,gcTime:10*6e4});return{groups:((a=r.data)==null?void 0:a.groups)||[],generatedAt:((o=r.data)==null?void 0:o.generatedAt)||null,isLoading:r.isLoading}}function Ws(s,t){return Be(s,null,{carId:t})}function Vs(){const{cdnUrl:s,partnerSlug:t}=S();return k.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const n=await T(s,"competitions/index.json");return n!=null&&n.competitions?t?n.competitions.filter(r=>r.partnerSlug===t):n.competitions:[]},staleTime:6e4})}function he(s,t={}){const n=S(),r=t.partnerSlug||n.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",r,s,"config"],queryFn:()=>T(n.cdnUrl,`competitions/${r}/${s}/config.json`),enabled:!!r&&!!s,staleTime:6e4})}function ve(s,t={}){const n=S(),r=t.partnerSlug||n.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",r,s,"standings"],queryFn:()=>T(n.cdnUrl,`competitions/${r}/${s}/standings.json`),enabled:!!r&&!!s,staleTime:6e4})}function Ie(s,t,n={}){const r=S(),a=n.partnerSlug||r.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",a,s,"round",t],queryFn:()=>T(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}.json`),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function _e(s,t=[],n={}){const r=S(),a=n.partnerSlug||r.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",a,s,"allRounds",t],queryFn:async()=>(await Promise.all(t.map(i=>T(r.cdnUrl,`competitions/${a}/${s}/rounds/${i}.json`).catch(()=>null)))).filter(Boolean),enabled:!!a&&!!s&&t.length>0,staleTime:6e4})}function Fe(s,t={}){const n=S(),r=t.partnerSlug||n.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",r,s,"leaderboard"],queryFn:()=>T(n.cdnUrl,`competitions/${r}/${s}/leaderboard.json`).catch(()=>null),enabled:!!r&&!!s,staleTime:6e4})}function qe(s,t,n={}){const r=S(),a=n.partnerSlug||r.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",a,s,"round",t,"leaderboard"],queryFn:()=>T(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}/leaderboard.json`).catch(()=>null),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function We(s,t,n={}){const r=S(),a=n.partnerSlug||r.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",a,s,"round",t,"laps"],queryFn:()=>T(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}/laps.json`).catch(()=>null),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function Ve(s,t,n={}){const r=S(),a=n.partnerSlug||r.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",a,s,"round",t,"positions"],queryFn:()=>T(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}/positions.json`).catch(()=>null),enabled:(n.enabled??!0)&&!!a&&!!s&&t!=null,staleTime:6e4})}function ge(s,t={}){const n=S(),r=t.partnerSlug||n.partnerSlug;return k.useQuery({queryKey:["pitvox","competition",r,s,"entrylist"],queryFn:()=>T(n.cdnUrl,`competitions/${r}/${s}/entrylist.json`),enabled:!!r&&!!s,staleTime:6e4})}function X(s){const{cdnUrl:t,partnerSlug:n,getSteamId:r}=S(),a=r();return k.useQuery({queryKey:["pitvox","registration",n,s,a],queryFn:async()=>{var d;const o=await fetch(`${t}/competitions/${n}/${s}/entrylist.json`);if(!o.ok)return{isRegistered:!1,entryList:null};const i=await o.json();return{isRegistered:!!a&&((d=i.drivers)==null?void 0:d.some(l=>l.steamId===a)),entryList:i}},enabled:!!s,staleTime:6e4})}function je(s){const{onRegister:t,partnerSlug:n,getSteamId:r}=S(),a=k.useQueryClient(),o=J();return k.useMutation({mutationFn:i=>{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,i)},onSuccess:()=>{const i=r();if(a.setQueriesData({queryKey:["pitvox","registration",n,s]},c=>c?{...c,isRegistered:!0}:{isRegistered:!0,entryList:null}),i){const c=o(i),d={steamId:i,displayName:c.displayName,avatarUrl:c.avatarUrl};a.setQueriesData({queryKey:["pitvox","competition",n,s,"entrylist"]},l=>{var m;return l?((m=l.drivers)==null?void 0:m.some(g=>g.steamId===i))?l:{...l,drivers:[...l.drivers||[],d]}:{drivers:[d]}})}}})}function fe(s){const{onWithdraw:t,partnerSlug:n,getSteamId:r}=S(),a=k.useQueryClient();return k.useMutation({mutationFn:o=>{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 i=o||r();if(!i)throw new Error("No Steam ID available");return t(s,i)},onSuccess:()=>{const o=r();a.setQueriesData({queryKey:["pitvox","registration",n,s]},i=>i?{...i,isRegistered:!1}:{isRegistered:!1,entryList:null}),o&&a.setQueriesData({queryKey:["pitvox","competition",n,s,"entrylist"]},i=>i!=null&&i.drivers?{...i,drivers:i.drivers.filter(c=>c.steamId!==o)}:i)}})}function ee(){const{onRegister:s,onWithdraw:t}=S(),n=!!(s&&t);return{isPowerMode:n,isBasicMode:!n}}function se(s){const{pitvoxUrl:t,partnerSlug:n}=S();return`${t}/p/${n}/competitions/${s}/register`}function H(s,t=new Date){var n;return s.winnersAnnouncedAt||(n=s.winners)!=null&&n.length?"winners":s.opensAt&&t<new Date(s.opensAt)?"upcoming":s.closesAt&&t>=new Date(s.closesAt)?"closed":"open"}const He={upcoming:"Opens soon",open:"Open",closed:"Closed",winners:"Winners announced"};function Ke(){const{cdnUrl:s,partnerSlug:t}=S();return k.useQuery({queryKey:["pitvox","promotions",t],queryFn:async()=>{const n=await T(s,"promotions/index.json");return n!=null&&n.promotions?t?n.promotions.filter(r=>r.partnerSlug===t):n.promotions:[]},staleTime:6e4})}function Oe(s,t={}){const n=S(),r=t.partnerSlug||n.partnerSlug;return k.useQuery({queryKey:["pitvox","promotion",r,s,"config"],queryFn:()=>T(n.cdnUrl,`promotions/${r}/${s}/config.json`),enabled:!!r&&!!s,staleTime:6e4})}function Qe(s,t={}){const n=S(),r=t.partnerSlug||n.partnerSlug;return k.useQuery({queryKey:["pitvox","promotion",r,s,"entrylist"],queryFn:()=>T(n.cdnUrl,`promotions/${r}/${s}/entrylist.json`),enabled:!!r&&!!s,staleTime:6e4})}function Ge(s){const{cdnUrl:t,partnerSlug:n,getSteamId:r}=S(),a=r();return k.useQuery({queryKey:["pitvox","promotionEntry",n,s,a],queryFn:async()=>{var c;const o=await T(t,`promotions/${n}/${s}/entrylist.json`);return o?{isEntered:!!a&&((c=o.entrants)==null?void 0:c.some(d=>d.steamId===a)),entryList:o}:{isEntered:!1,entryList:null}},enabled:!!s,staleTime:6e4})}function ze(s){const{onEnterPromotion:t,partnerSlug:n,getSteamId:r}=S(),a=k.useQueryClient(),o=J();return k.useMutation({mutationFn:i=>{if(!t)throw new Error("No onEnterPromotion callback provided to PitVoxPartnerProvider. Provide onEnterPromotion for in-app entry, or use usePromotionUrl() to link to pitvox.com.");return t(s,i)},onSuccess:()=>{const i=r();if(a.setQueriesData({queryKey:["pitvox","promotionEntry",n,s]},c=>c?{...c,isEntered:!0}:{isEntered:!0,entryList:null}),i){const c=o(i),d={steamId:i,displayName:c.displayName,avatarUrl:c.avatarUrl};a.setQueriesData({queryKey:["pitvox","promotion",n,s,"entrylist"]},l=>{var g;if(!l)return{entrants:[d],count:1};if((g=l.entrants)==null?void 0:g.some(x=>x.steamId===i))return l;const m=[...l.entrants||[],d];return{...l,entrants:m,count:m.length}})}}})}function Ye(s){const{onWithdrawPromotionEntry:t,partnerSlug:n,getSteamId:r}=S(),a=k.useQueryClient();return k.useMutation({mutationFn:o=>{if(!t)throw new Error("No onWithdrawPromotionEntry callback provided to PitVoxPartnerProvider. Provide onWithdrawPromotionEntry for in-app withdrawal, or use usePromotionUrl() to link to pitvox.com.");const i=o||r();if(!i)throw new Error("No Steam ID available");return t(s,i)},onSuccess:()=>{const o=r();a.setQueriesData({queryKey:["pitvox","promotionEntry",n,s]},i=>i?{...i,isEntered:!1}:{isEntered:!1,entryList:null}),o&&a.setQueriesData({queryKey:["pitvox","promotion",n,s,"entrylist"]},i=>{if(!(i!=null&&i.entrants))return i;const c=i.entrants.filter(d=>d.steamId!==o);return{...i,entrants:c,count:c.length}})}})}function Ze(){const{onEnterPromotion:s,onWithdrawPromotionEntry:t}=S(),n=!!(s&&t);return{isPowerMode:n,isBasicMode:!n}}function Je(s){const{pitvoxUrl:t,partnerSlug:n}=S();return`${t}/p/${n}/promotions/${s}`}const Hs={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:"🇰🇷"},te=["🥇","🥈","🥉"],Ks={championship:"Championship",series:"Series",event:"Event",hotlap:"Hotlap"},Os=["PRACTICE","QUALIFYING","RACE"];function Le(s){const t=Os.indexOf(s);if(t>=0)return t;const n=s.match(/^PRACTICE_(\d+)$/);return n?100+parseInt(n[1]):999}function K(s){const t=s.match(/^PRACTICE_(\d+)$/);return t?`P${t[1]}`:s}function Ne({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 ne({nation:s}){const t=s&&Hs[s];return t?e.jsx("span",{className:"pvx-nation-flag",title:s,children:t}):null}function Qs({sessions:s,activeSession:t,onSelect:n}){if(!s||s.length<=1)return null;const r=[...s].sort((a,o)=>Le(a.type)-Le(o.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:K(a.type)},a.type))})}function Xe({type:s}){return e.jsx("span",{className:`pvx-comp-badge pvx-comp-badge--${s}`,children:Ks[s]||s})}function G({children:s,variant:t="default"}){return e.jsx("span",{className:`pvx-info-pill ${t!=="default"?`pvx-info-pill--${t}`:""}`,children:s})}function Gs(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 zs(s){return s.reduce((t,n)=>{var r;return(r=n.splits)!=null&&r.length?t?t.map((a,o)=>{const i=n.splits[o];return i&&i<a?i:a}):[...n.splits]:t},null)}function I({message:s="Loading..."}){return e.jsx("div",{className:"pvx-loading",children:s})}function E({message:s="No data available."}){return e.jsx("div",{className:"pvx-empty",children:e.jsx("p",{children:s})})}const ye=3;function q(s){if(!s)return!1;if(s.closesAt){const t=new Date(s.closesAt).getTime();if(!Number.isNaN(t))return Date.now()>=t}return!!s.isClosed}function es(s){const t=s==null?void 0:s.rounds;return t!=null&&t.length?s.type==="hotlap"?t.every(n=>q(n)):t.every(n=>n.isFinalized):!1}function ss(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 be(s,t=ye){if(!es(s))return"active";const n=ss(s);if(!n)return"recently-completed";const r=t*24*60*60*1e3;return Date.now()-n.getTime()<=r?"recently-completed":"archived"}function Ys(s,t,n=ye){if(!(s!=null&&s.length))return[];const r=new Set(Array.isArray(t)?t:[t]);return s.filter(a=>r.has(be(a,n)))}function ts(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):[]}const Zs={giveaway:"Giveaway"};function we({promotion:s,status:t}){const n=t||H(s);return e.jsx("span",{className:`pvx-promo-status pvx-promo-status--${n}`,children:He[n]||n})}function Ce({type:s}){return e.jsx("span",{className:`pvx-promo-type pvx-promo-type--${s||"giveaway"}`,children:Zs[s]||s})}function F(s){if(!s)return"";const t=new Date(s);if(isNaN(t))return"";const n=t.toLocaleDateString(void 0,{weekday:"short",day:"numeric",month:"short"}),r=t.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"});return`${n} ${r}`}function ns(s,t){const n=t||H(s);return n==="upcoming"?`Entries open ${F(s.opensAt)}`:n==="open"&&s.closesAt?`Entries close ${F(s.closesAt)}`:n==="open"?"Entries open now":n==="closed"?`Entries closed ${F(s.closesAt)}`:null}function de({className:s}){return e.jsxs("svg",{className:s,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"8",width:"18",height:"4",rx:"1"}),e.jsx("path",{d:"M12 8v13"}),e.jsx("path",{d:"M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7"}),e.jsx("path",{d:"M7.5 8a2.5 2.5 0 0 1 0-5A4.8 8 0 0 1 12 8a4.8 8 0 0 1 4.5-5 2.5 2.5 0 0 1 0 5"})]})}function rs({promotions:s,isLoading:t,onSelect:n,className:r}){if(t)return e.jsx(I,{message:"Loading promotions..."});if(!(s!=null&&s.length))return e.jsx(E,{message:"No promotions running right now."});const a=s.length===1?"pvx-promo-grid--single":s.length===2?"pvx-promo-grid--pair":"";return e.jsx("div",{className:`pvx-promo-grid ${a} ${r||""}`,children:s.map(o=>e.jsx(as,{promo:o,onSelect:n},o.id))})}function as({promo:s,onSelect:t}){const{cdnUrl:n}=S(),r=s.posterCdnPath?`${n}/${s.posterCdnPath}`:null,a=H(s),o=ns(s,a);return e.jsxs("div",{className:"pvx-promo-card",role:"button",tabIndex:0,onClick:()=>t==null?void 0:t(s.id),onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),t==null||t(s.id))},children:[e.jsx("div",{className:"pvx-promo-card-poster",children:r?e.jsx("img",{src:r,alt:s.title,className:"pvx-promo-card-poster-img"}):e.jsx("div",{className:"pvx-promo-card-poster-placeholder",children:e.jsx(de,{className:"pvx-promo-gift-icon"})})}),e.jsxs("div",{className:"pvx-promo-card-body",children:[e.jsxs("div",{className:"pvx-promo-card-badges",children:[e.jsx(we,{promotion:s,status:a}),e.jsx(Ce,{type:s.type}),s.game&&e.jsx("span",{className:"pvx-promo-game",children:s.game})]}),e.jsx("h3",{className:"pvx-promo-card-title",children:s.title}),s.prizeDescription&&e.jsx("p",{className:"pvx-promo-card-prize",children:s.prizeDescription}),e.jsxs("div",{className:"pvx-promo-card-meta",children:[o&&e.jsx("span",{children:o}),e.jsxs("span",{children:[s.entryCount," ",s.entryCount===1?"entry":"entries",s.maxEntrants?` / ${s.maxEntrants}`:""]})]})]})]})}function is({promotionId:s,driverData:t,className:n,children:r}){const{data:a,isLoading:o}=Ge(s),{isPowerMode:i}=Ze(),c=Je(s),d=ze(s),l=Ye(s),p=(a==null?void 0:a.isEntered)||!1,m=o||d.isPending||l.isPending,g=d.error||l.error||null,x=()=>{i&&d.mutate(t||{})},f=()=>{i&&l.mutate()};return typeof r=="function"?r({isEntered:p,isLoading:m,enter:x,withdraw:f,error:g,isPowerMode:i,promotionUrl:c}):i?e.jsx("button",{className:`pvx-promo-enter-btn ${n||""}`,onClick:p?f:x,disabled:m,children:m?"Loading...":p?"Withdraw Entry":"Enter Giveaway"}):e.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:`pvx-promo-enter-link ${n||""}`,children:p?"View Entry":"Enter on PitVox"})}function os({promotionId:s,driverData:t,onBack:n,className:r}){const{cdnUrl:a,getSteamId:o}=S(),{data:i,isLoading:c}=Oe(s),{data:d}=Qe(s);if(c)return e.jsx(I,{message:"Loading promotion..."});if(!i)return e.jsx(E,{message:"Promotion not found."});const l=H(i),p=i.winners||[],m=(d==null?void 0:d.entrants)||[],g=m.length||i.entryCount||0,x=i.maxEntrants&&g>=i.maxEntrants,f=i.posterCdnPath?`${a}/${i.posterCdnPath}`:null,h=o();return e.jsxs("div",{className:`pvx-promo-detail ${r||""}`,children:[n&&e.jsx("button",{type:"button",className:"pvx-promo-back",onClick:n,children:"← All promotions"}),f&&e.jsx("div",{className:"pvx-promo-detail-poster",children:e.jsx("img",{src:f,alt:i.title})}),e.jsxs("div",{className:"pvx-promo-detail-header",children:[e.jsxs("div",{className:"pvx-promo-card-badges",children:[e.jsx(we,{promotion:i,status:l}),e.jsx(Ce,{type:i.type}),i.game&&e.jsx("span",{className:"pvx-promo-game",children:i.game})]}),e.jsx("h2",{className:"pvx-promo-detail-title",children:i.title}),i.prizeDescription&&e.jsx("p",{className:"pvx-promo-detail-prize",children:i.prizeDescription}),e.jsxs("div",{className:"pvx-promo-detail-meta",children:[i.opensAt&&l==="upcoming"&&e.jsxs("span",{children:["Opens ",F(i.opensAt)]}),i.closesAt&&e.jsxs("span",{children:[l==="open"||l==="upcoming"?"Closes":"Closed"," ",F(i.closesAt)]}),e.jsxs("span",{children:[g," ",g===1?"entry":"entries",i.maxEntrants?` / ${i.maxEntrants}`:""]})]})]}),p.length>0&&e.jsxs("div",{className:"pvx-promo-winners",children:[e.jsx("h3",{className:"pvx-promo-section-title",children:p.length===1?"Winner":"Winners"}),e.jsx("div",{className:"pvx-promo-winners-list",children:p.map(u=>e.jsxs("div",{className:"pvx-promo-winner",children:[u.avatarUrl?e.jsx("img",{src:u.avatarUrl,alt:"",className:"pvx-promo-avatar pvx-promo-avatar--lg"}):e.jsx("div",{className:"pvx-promo-avatar pvx-promo-avatar--lg pvx-promo-avatar--placeholder",children:e.jsx(de,{className:"pvx-promo-avatar-glyph"})}),e.jsx("span",{className:"pvx-promo-winner-name",children:u.displayName})]},u.steamId))})]}),e.jsxs("div",{className:"pvx-promo-action",children:[l==="upcoming"&&e.jsxs("p",{className:"pvx-promo-action-note",children:["Entries aren't open yet — come back ",i.opensAt?F(i.opensAt):"soon","."]}),(l==="closed"||l==="winners")&&e.jsxs("p",{className:"pvx-promo-action-note",children:["Entries have closed.",l==="closed"&&" Winners will be announced here once the draw is done."]}),l==="open"&&!h&&e.jsx("p",{className:"pvx-promo-action-note",children:"Sign in with Steam to enter this giveaway."}),l==="open"&&h&&e.jsx(is,{promotionId:s,driverData:t,children:({isEntered:u,isLoading:N,enter:v,withdraw:b,error:C,isPowerMode:$,promotionUrl:P})=>e.jsxs("div",{className:"pvx-promo-action-row",children:[e.jsxs("div",{className:"pvx-promo-action-text",children:[C&&e.jsx("p",{className:"pvx-promo-error",children:C.message}),e.jsx("p",{className:"pvx-promo-action-note",children:u?"✓ You're in the draw.":x?"This giveaway is full.":"One click and you're in the draw."}),!u&&!x&&e.jsx("p",{className:"pvx-promo-disclosure",children:"Entering displays your Steam name and avatar publicly; winners are announced by name."})]}),$?e.jsx("button",{type:"button",className:u?"pvx-promo-withdraw-btn":"pvx-promo-enter-btn",onClick:u?b:v,disabled:N||!u&&x,children:N?"Loading...":u?"Withdraw Entry":"Enter Giveaway"}):e.jsx("a",{href:P,target:"_blank",rel:"noopener noreferrer",className:"pvx-promo-enter-link",children:u?"View Entry":"Enter on PitVox"})]})})]}),i.description&&e.jsx("div",{className:"pvx-promo-description",children:e.jsx(As,{children:i.description})}),m.length>0&&e.jsxs("div",{className:"pvx-promo-entrants",children:[e.jsxs("h3",{className:"pvx-promo-section-title",children:["Entrants ",e.jsxs("span",{className:"pvx-promo-section-count",children:["(",m.length,")"]})]}),e.jsx("div",{className:"pvx-promo-entrants-grid",children:m.map(u=>e.jsxs("div",{className:"pvx-promo-entrant",children:[u.avatarUrl?e.jsx("img",{src:u.avatarUrl,alt:"",className:"pvx-promo-avatar"}):e.jsx("div",{className:"pvx-promo-avatar pvx-promo-avatar--placeholder",children:e.jsx(de,{className:"pvx-promo-avatar-glyph"})}),e.jsx("span",{className:"pvx-promo-entrant-name",title:u.displayName,children:u.displayName})]},u.steamId))})]})]})}const pe="promotion";function Re(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get(pe)}function Js({title:s="Promotions",driverData:t,className:n}){const{data:r=[],isLoading:a}=Ke(),[o,i]=w.useState(Re);w.useEffect(()=>{const d=()=>i(Re());return window.addEventListener("popstate",d),()=>window.removeEventListener("popstate",d)},[]);const c=w.useCallback(d=>{if(i(d),typeof window<"u"){const l=new URL(window.location.href);d?l.searchParams.set(pe,d):l.searchParams.delete(pe),window.history.pushState({},"",l)}},[]);return e.jsxs("div",{className:`pvx-promo-explorer ${n||""}`,children:[s&&e.jsx("h1",{className:"pvx-promo-explorer-title",children:s}),o?e.jsx(os,{promotionId:o,driverData:t,onBack:()=>c(null)}):e.jsx(rs,{promotions:r,isLoading:a,onSelect:c})]})}function Xs(s,t){for(const n of t)if(n.tags.includes(s))return n.id;return"other"}function ls(s,t,n=[]){if(t.size===0)return!0;const r={};for(const a of t){const o=Xs(a,n);r[o]||(r[o]=[]),r[o].push(a)}for(const a of Object.values(r))if(!a.some(o=>s.includes(o)))return!1;return!0}function cs(s,t){const[n,r]=w.useState(new Set),a=s!==void 0,o=a?s:n,i=w.useCallback(d=>{const l=new Set(o);l.has(d)?l.delete(d):l.add(d),a&&t?t(l):r(l)},[o,a,t]),c=w.useCallback(()=>{a&&t?t(new Set):r(new Set)},[a,t]);return{activeTags:o,toggle:i,clear:c}}function re(s){const[t,n]=w.useState(s),r=w.useCallback(a=>{n(o=>o.key===a?{key:a,dir:o.dir==="asc"?"desc":"asc"}:{key:a,dir:a.includes("timestamp")||a.includes("Date")?"desc":"asc"})},[]);return[t,r]}function ae(s,t,n){return[...s].sort((r,a)=>{const o=n(r,t.key),i=n(a,t.key);if(o==null&&i==null)return 0;if(o==null)return 1;if(i==null)return-1;const c=typeof o=="string"?o.localeCompare(i):o-i;return t.dir==="desc"?-c:c})}function ds(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 et({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 D({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(et,{active:n.key===t,dir:n.dir})]})})}function ie({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 ke({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 ps({availableTags:s,activeTags:t,onToggle:n,onClear:r,categories:a=[],tagLabels:o={}}){if(!s||s.length<2)return null;const i=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"}),i.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:o[l]||l},l))]},c.id))]})}function Se({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 O({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 Q(){return e.jsx("div",{className:"pvx-loading",children:"Loading..."})}function st(){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 tt(){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 nt({tracks:s,isLoading:t,carMetadata:n,getUserDisplay:r,onTrackSelect:a,tags:o,onTagChange:i}){const[c,d]=re({key:"record.timestamp",dir:"desc"}),{activeTags:l,toggle:p,clear:m}=cs(o,i),g=w.useMemo(()=>{var u;if(!((u=n==null?void 0:n.tags)!=null&&u.length))return[];const h=new Set;for(const N of s||[])N.recordByTag&&Object.keys(N.recordByTag).forEach(v=>h.add(v));return n.tags.filter(N=>h.has(N))},[s,n]),x=w.useMemo(()=>s?l.size===0?s:s.map(h=>{var v,b;if(!h.recordByTag)return null;let u=null;const N=new Set;for(const C of Object.values(h.recordByTag)){if(N.has(C.carId))continue;N.add(C.carId);const $=((b=(v=n==null?void 0:n.cars)==null?void 0:v[C.carId])==null?void 0:b.tags)||[];ls($,l,n==null?void 0:n.categories)&&(!u||C.lapTimeMs<u.lapTimeMs)&&(u=C)}return u?{...h,record:{visibleId:u.steamId||u.identifier,carId:u.carId,carDisplayName:A(u.carId),lapTimeMs:u.lapTimeMs,timestamp:u.recordedAt}}:null}).filter(Boolean):[],[s,l,n]),f=w.useMemo(()=>ae(x,c,(h,u)=>{var N,v;switch(u){case"displayName":return h.displayName;case"record.lapTimeMs":return(N=h.record)==null?void 0:N.lapTimeMs;case"driverCount":return h.driverCount||0;case"carCount":return h.carCount||0;case"record.timestamp":default:return(v=h.record)!=null&&v.timestamp?new Date(h.record.timestamp).getTime():0}}),[x,c]);return t?e.jsx(Q,{}):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(ps,{availableTags:g,activeTags:l,onToggle:p,onClear:m,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(D,{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(D,{label:"Lap Time",sortKey:"record.lapTimeMs",config:c,onSort:d}),e.jsx(D,{label:"Drivers",sortKey:"driverCount",config:c,onSort:d,className:"pvx-hidden-below-md"}),e.jsx(D,{label:"Cars",sortKey:"carCount",config:c,onSort:d,className:"pvx-hidden-below-lg"}),e.jsx(D,{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 u,N,v;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:(u=h.record)!=null&&u.visibleId?e.jsx(ie,{userId:h.record.visibleId,getUserDisplay:r}):"-"}),e.jsx("td",{className:"pvx-td pvx-hidden-below-lg",children:((N=h.record)==null?void 0:N.carDisplayName)||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:h.record?U(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:(v=h.record)!=null&&v.timestamp?V(h.record.timestamp):"-"})]},`${h.id}|${h.layout||""}`)})})]})})]}):e.jsx(O,{message:"No lap times recorded yet."})}function rt({entries:s,isLoading:t,track:n,carMetadata:r,getUserDisplay:a,onCarSelect:o,onNavigate:i,tags:c,onTagChange:d}){const[l,p]=re({key:"lapTimeMs",dir:"asc"}),{activeTags:m,toggle:g,clear:x}=cs(c,d),f=w.useMemo(()=>{var b,C,$;if(!s||!((b=r==null?void 0:r.tags)!=null&&b.length))return[];const v=new Set;for(const P of s)((($=(C=r.cars)==null?void 0:C[P.carId])==null?void 0:$.tags)||[]).forEach(L=>v.add(L));return r.tags.filter(P=>v.has(P))},[s,r]),h=w.useMemo(()=>s?m.size===0?s:s.filter(v=>{var C,$;const b=(($=(C=r==null?void 0:r.cars)==null?void 0:C[v.carId])==null?void 0:$.tags)||[];return ls(b,m,r==null?void 0:r.categories)}):[],[s,m,r]),u=w.useMemo(()=>ae(h,l,(v,b)=>{switch(b){case"carId":return A(v.carId);case"driverCount":return v.driverCount||0;case"lapTimeMs":default:return v.lapTimeMs}}),[h,l]),N=[{key:"tracks",label:"Tracks",onClick:()=>i("tracks")},{key:"track",label:n.displayName}];return t?e.jsx(Q,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(Se,{segments:N})}),e.jsx(ps,{availableTags:f,activeTags:m,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(D,{label:"Car",sortKey:"carId",config:l,onSort:p}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx(D,{label:"Lap Time",sortKey:"lapTimeMs",config:l,onSort:p}),e.jsx(D,{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:u.map((v,b)=>e.jsxs("tr",{className:"pvx-row pvx-row--clickable",onClick:()=>o(v.carId),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ke,{rank:b+1,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:A(v.carId)}),e.jsx("td",{className:"pvx-td",children:e.jsx(ie,{userId:v.steamId||v.userId,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:U(v.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--muted pvx-hidden-below-lg",children:v.recordedAt?V(v.recordedAt):"-"})]},v.carId))})]})}):e.jsx(O,{message:"No lap times for this track yet."})]})}function at({entries:s,isLoading:t,track:n,carId:r,getUserDisplay:a,onDriverSelect:o,onNavigate:i,highlightId:c}){const[d,l]=re({key:"lapTimeMs",dir:"asc"}),p=w.useMemo(()=>ds(s),[s]),m=w.useMemo(()=>ae(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:()=>i("tracks")},{key:"track",label:n.displayName,onClick:()=>i("track")},{key:"car",label:A(r)}];return t?e.jsx(Q,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(Se,{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(D,{label:"Driver",sortKey:"userId",config:d,onSort:l}),e.jsx(D,{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(D,{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:m.map((x,f)=>{const h=f+1,u=x.steamId||x.userId,N=p&&x.sector1Ms===p.s1,v=p&&x.sector2Ms===p.s2,b=p&&x.sector3Ms===p.s3,C=c&&u===c;return e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${C?"pvx-row--highlight":h<=3?"pvx-row--podium":""}`,onClick:()=>o(u),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ke,{rank:h,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(ie,{userId:u,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:U(x.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${N?"pvx-td--best-sector":""}`,children:B(x.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${v?"pvx-td--best-sector":""}`,children:B(x.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${b?"pvx-td--best-sector":""}`,children:B(x.sector3Ms)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:ue(x.tyreCompound),children:x.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-xl",children:me(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?V(x.recordedAt):"-"})]},u)})})]})}):e.jsx(O,{message:"No lap times for this car yet."})]})}function it({userId:s,track:t,carId:n,game:r,gameVersion:a,showInvalid:o,getUserDisplay:i,onToggleInvalid:c,onNavigate:d}){const{data:l,driverName:p,theoreticalBest:m,isLoading:g}=Ue(s,t.id,t.layout,n,{showInvalid:o,game:r,gameVersion:a}),{displayName:x,avatarUrl:f}=i(s,p),h=w.useMemo(()=>ds(l,!0),[l]),u=w.useMemo(()=>{const v=(l==null?void 0:l.filter(b=>b.isValid))||[];return v.length?Math.min(...v.map(b=>b.lapTimeMs)):null},[l]),N=[{key:"tracks",label:"Tracks",onClick:()=>d("tracks")},{key:"track",label:t.displayName,onClick:()=>d("track")},{key:"car",label:A(n),onClick:()=>d("car")},{key:"driver",label:x}];return g?e.jsx(Q,{}):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(Se,{segments:N}),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:o,onChange:c,className:"pvx-checkbox"}),e.jsx("span",{children:"Show invalid laps"})]})]}),m&&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:U(m.lapTimeMs)}),e.jsxs("span",{className:"pvx-theoretical-best-sectors",children:["(",B(m.sector1Ms)," + ",B(m.sector2Ms)," + ",B(m.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((v,b)=>{const C=v.isValid&&v.lapTimeMs===u,$=h&&v.isValid&&v.sector1Ms===h.s1,P=h&&v.isValid&&v.sector2Ms===h.s2,j=h&&v.isValid&&v.sector3Ms===h.s3;let L="pvx-row";return v.isValid||(L+=" pvx-row--invalid"),C&&(L+=" pvx-row--personal-best"),e.jsxs("tr",{className:L,children:[e.jsx("td",{className:"pvx-td",children:e.jsx("span",{className:`pvx-rank ${C?"pvx-rank--gold":""}`,children:b+1})}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-md",children:v.lapNumber||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:U(v.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${$?"pvx-td--best-sector":""}`,children:B(v.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${P?"pvx-td--best-sector":""}`,children:B(v.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${j?"pvx-td--best-sector":""}`,children:B(v.sector3Ms)}),e.jsx("td",{className:"pvx-td",title:v.isValid?void 0:v.invalidReason||"Invalid",children:v.isValid?e.jsx(st,{}):e.jsx(tt,{})}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:ue(v.tyreCompound),children:v.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:me(v.startingFuelL)}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:V(v.timestamp)})]},v.id)})})]})}):e.jsx(O,{message:o?"No laps recorded for this combination.":'No valid laps. Try enabling "Show invalid laps".'})]})}function ot({drivers:s,isLoading:t,getUserDisplay:n,game:r,gameVersion:a,onComboSelect:o}){const[i,c]=re({key:"rank",dir:"asc"}),[d,l]=w.useState(null),p=w.useMemo(()=>s?ae(s,i,(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,i]);if(t)return e.jsx(Q,{});if(!(s!=null&&s.length))return e.jsx("div",{className:"pvx-card",children:e.jsx(O,{message:"Not enough data for rankings yet."})});const m=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(D,{label:"#",sortKey:"rank",config:i,onSort:c,className:"pvx-th--narrow"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx(D,{label:"Rating",sortKey:"rating",config:i,onSort:c}),e.jsx(D,{label:"Cars",sortKey:"distinctCars",config:i,onSort:c,className:"pvx-hidden-below-sm"}),e.jsx(D,{label:"Combos",sortKey:"comboCount",config:i,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(lt,{driver:g,getUserDisplay:n,isExpanded:x,onToggle:()=>l(x?null:g.identifier),colCount:m,game:r,gameVersion:a,onComboSelect:o},g.identifier)})})]})})]})}function lt({driver:s,getUserDisplay:t,isExpanded:n,onToggle:r,colCount:a,game:o,gameVersion:i,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(ke,{rank:s.rank,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(ie,{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 m=l.layout?`${l.trackId}|${l.layout}`:l.trackId,g=c?()=>c({track:m,car:l.carId,highlight:d,game:o,gameVersion:i}):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:W(l.trackId,l.layout,o)}),e.jsx("p",{className:"pvx-rankings-combo-car",children:A(l.carId)})]}),e.jsxs("div",{className:"pvx-rankings-combo-stats",children:[e.jsx("p",{className:"pvx-rankings-combo-time",children:U(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)})})})})]})}function xs({competitionId:s,topN:t=3,label:n="Completed",className:r}){const{data:a}=ve(s),o=ts(a,t);return e.jsxs("div",{className:`pvx-comp-completed-badge ${r||""}`,children:[e.jsx("span",{className:"pvx-comp-completed-badge-label",children:n}),o.length>0&&e.jsx("ol",{className:"pvx-comp-completed-badge-podium",children:o.map((i,c)=>e.jsxs("li",{className:"pvx-comp-completed-badge-driver",children:[e.jsx("span",{className:"pvx-comp-completed-badge-medal","aria-hidden":"true",children:te[c]||""}),e.jsx(ne,{nation:i.nation}),e.jsx("span",{className:"pvx-comp-completed-badge-name",children:i.driverName})]},i.driverId||c))})]})}const ct={GameModeSelectionWeatherType_CLEAR:"Clear",GameModeSelectionWeatherType_SCATTERED_CLOUDS:"Scattered Clouds",GameModeSelectionWeatherType_BROKEN_CLOUDS:"Broken Clouds",GameModeSelectionWeatherType_OVERCAST:"Overcast",GameModeSelectionWeatherType_DRIZZLE:"Drizzle",GameModeSelectionWeatherType_DAMP:"Damp",GameModeSelectionWeatherType_RAIN:"Rain",GameModeSelectionWeatherType_HEAVY_RAIN:"Heavy Rain"},dt={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"};function pt(){return e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"12",cy:"12",r:"4"}),e.jsx("path",{d:"M12 2v2"}),e.jsx("path",{d:"M12 20v2"}),e.jsx("path",{d:"m4.93 4.93 1.41 1.41"}),e.jsx("path",{d:"m17.66 17.66 1.41 1.41"}),e.jsx("path",{d:"M2 12h2"}),e.jsx("path",{d:"M20 12h2"}),e.jsx("path",{d:"m6.34 17.66-1.41 1.41"}),e.jsx("path",{d:"m19.07 4.93-1.41 1.41"})]})}function xt(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M12 2v2"}),e.jsx("path",{d:"m4.93 4.93 1.41 1.41"}),e.jsx("path",{d:"M20 12h2"}),e.jsx("path",{d:"m19.07 4.93-1.41 1.41"}),e.jsx("path",{d:"M15.947 12.65a4 4 0 0 0-5.925-4.128"}),e.jsx("path",{d:"M13 22H7a5 5 0 1 1 4.9-6H13a3 3 0 0 1 0 6Z"})]})}function ut(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M17.5 21H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"}),e.jsx("path",{d:"M22 10a3 3 0 0 0-3-3h-2.207a5.502 5.502 0 0 0-10.702.5"})]})}function mt(){return e.jsx("path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"})}function ht(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242"}),e.jsx("path",{d:"M8 19v1"}),e.jsx("path",{d:"M8 14v1"}),e.jsx("path",{d:"M16 19v1"}),e.jsx("path",{d:"M16 14v1"}),e.jsx("path",{d:"M12 21v1"}),e.jsx("path",{d:"M12 16v1"})]})}function vt(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M16 17H7"}),e.jsx("path",{d:"M17 21H9"}),e.jsx("path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242"})]})}function gt(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242"}),e.jsx("path",{d:"M16 14v6"}),e.jsx("path",{d:"M8 14v6"}),e.jsx("path",{d:"M12 16v6"})]})}function jt(){return e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242"}),e.jsx("path",{d:"m9.2 22 3-7"}),e.jsx("path",{d:"m9 13-3 7"}),e.jsx("path",{d:"m17 13-3 7"})]})}const ft={GameModeSelectionWeatherType_CLEAR:pt,GameModeSelectionWeatherType_SCATTERED_CLOUDS:xt,GameModeSelectionWeatherType_BROKEN_CLOUDS:ut,GameModeSelectionWeatherType_OVERCAST:mt,GameModeSelectionWeatherType_DRIZZLE:ht,GameModeSelectionWeatherType_DAMP:vt,GameModeSelectionWeatherType_RAIN:gt,GameModeSelectionWeatherType_HEAVY_RAIN:jt};function us({weatherType:s,weatherBehaviour:t,className:n}){const r=s?ft[s]:null;if(!r)return null;const a=ct[s]||s,o=t==="GameModeSelectionWeatherBehaviour_DYNAMIC",i=o?`${a} · Dynamic`:a;return e.jsxs("span",{className:`pvx-weather-icon ${n||""}`.trim(),title:i,"aria-label":i,children:[e.jsx("svg",{className:"pvx-weather-icon-main",...dt,children:e.jsx(r,{})}),o&&e.jsx("span",{className:"pvx-weather-icon-dynamic","aria-hidden":"true",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"}),e.jsx("path",{d:"M21 3v5h-5"}),e.jsx("path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"}),e.jsx("path",{d:"M8 16H3v5"})]})})]})}function Nt({competitions:s,isLoading:t,onSelect:n,onRegister:r,className:a}){return t?e.jsx(I,{message:"Loading competitions..."}):s!=null&&s.length?e.jsx("div",{className:`pvx-comp-grid ${a||""}`,children:s.map(o=>e.jsx(ms,{comp:o,onSelect:n,onRegister:r||n},o.id))}):e.jsx(E,{message:"No competitions available."})}function ms({comp:s,onSelect:t,onRegister:n}){var P,j,L,y,M;const{cdnUrl:r}=S(),a=s.posterCdnPath?`${r}/${s.posterCdnPath}`:null,o=s.registration,i=(o==null?void 0:o.currentCount)||0,c=o==null?void 0:o.maxParticipants,d=c&&i>=c,l=(o==null?void 0:o.deadline)&&new Date(o.deadline)<new Date,p=(o==null?void 0:o.isOpen)&&!l&&!d,m=new Date,g=(P=s.rounds)==null?void 0:P.find(R=>R.startTime&&new Date(R.startTime)<=m&&!q(R)),x=g||((j=s.rounds)==null?void 0:j.find(R=>R.startTime&&new Date(R.startTime)>=m)),f=!!g,h=((L=s.rounds)==null?void 0:L.length)||0,u=s.type==="hotlap",N=u&&h>1,v=u?((y=s.rounds)==null?void 0:y.filter(q).length)||0:((M=s.rounds)==null?void 0:M.filter(R=>R.isFinalized).length)||0,b=be(s),C=b==="recently-completed"||b==="archived",$=s.type==="championship";return e.jsxs("div",{className:"pvx-comp-card",onClick:()=>t(s.id),role:"button",tabIndex:0,onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.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(bt,{})})}),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(Xe,{type:s.type}),s.game&&e.jsx(G,{children:s.game.toUpperCase()}),s.formatDescription&&s.formatDescription.split(", ").map((R,_)=>e.jsx(G,{variant:"format",children:R},_))]}),s.carsDescription&&e.jsx("div",{className:"pvx-comp-card-pills",children:s.carsDescription.split(", ").map((R,_)=>e.jsx(G,{children:R},_))}),e.jsxs("div",{className:"pvx-comp-card-schedule",children:[x?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[e.jsx("span",{className:"pvx-comp-card-schedule-label",children:f?"Live:":"Next:"})," ",(s.type!=="hotlap"||N)&&`R${x.roundNumber} `,x.track||"TBD"," · ",Gs(x.startTime),(x.weatherType||s.weatherType)&&e.jsxs(e.Fragment,{children:[" ",e.jsx(us,{weatherType:x.weatherType||s.weatherType,weatherBehaviour:x.weatherBehaviour||s.weatherBehaviour})]})]}):h>0?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[v,"/",h," rounds completed"]}):null,h>0&&e.jsxs("span",{className:"pvx-comp-card-round-count",children:[h," round",h!==1?"s":""]})]}),C&&($||N)&&e.jsx(xs,{competitionId:s.id}),o&&!C&&e.jsx(yt,{competitionId:s.id,regOpen:p,isFull:d,deadlinePassed:l,regCount:i,regMax:c,onRegister:n})]})]})}function yt({competitionId:s,regOpen:t,isFull:n,deadlinePassed:r,regCount:a,regMax:o,onRegister:i}){const{isPowerMode:c}=ee(),d=se(s),{data:l}=X(s),p=(l==null?void 0:l.isRegistered)||!1,m=o?a/o*100:0,g=m>=100?"full":m>=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,"/",o||"∞"," 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(),i(s)},children:"✓ Registered"}):t?c?e.jsx("button",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--open",onClick:x=>{x.stopPropagation(),i(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 bt(){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 hs({competitionId:s,className:t}){var l,p,m;const{data:n,isLoading:r}=ve(s),{data:a,isLoading:o}=he(s);if(r||o)return e.jsx(I,{message:"Loading standings..."});if(!((l=n==null?void 0:n.standings)!=null&&l.length))return e.jsx(E,{message:"No standings data yet. Results will appear once rounds are finalised."});const i=(a==null?void 0:a.type)==="hotlap",c=i?((p=a==null?void 0:a.rounds)==null?void 0:p.filter(q))||[]:((m=a==null?void 0:a.rounds)==null?void 0:m.filter(g=>g.isFinalized))||[],d=n.roundsClosed??n.roundsCompleted??0;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:i?"Overall Standings":"Championship Standings"}),e.jsxs("span",{className:"pvx-standings-subtitle",children:["After ",d," round",d!==1?"s":"",i?" closed":"",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"}),c.map(g=>e.jsxs("th",{className:"pvx-th pvx-th--center pvx-hidden-below-md",title:g.track||`Round ${g.roundNumber}`,children:["R",g.roundNumber]},g.roundNumber))]})}),e.jsx("tbody",{className:"pvx-tbody",children:n.standings.map(g=>e.jsx(wt,{driver:g,columnRounds:c},g.driverId||g.driverName))})]})})]})}function wt({driver:s,columnRounds:t}){var i,c,d;const n=s.position<=3,r=new Map(((i=s.roundResults)==null?void 0:i.map(l=>[l.roundNumber,l]))||[]),a=((c=s.roundResults)==null?void 0:c.filter(l=>l.position===1).length)||0,o=((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(Ne,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ne,{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:o||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-standings-total",children:s.totalPoints}),t.map(l=>{const p=r.get(l.roundNumber),m=p==null?void 0:p.dropped;return e.jsx("td",{className:`pvx-td pvx-td--center pvx-hidden-below-md ${!m&&(p==null?void 0:p.position)===1?"pvx-standings-cell--p1":!m&&(p==null?void 0:p.position)===2?"pvx-standings-cell--p2":!m&&(p==null?void 0:p.position)===3?"pvx-standings-cell--p3":""}`,children:p?e.jsxs("div",{className:`pvx-standings-round-cell ${m?"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)})]})}const Te=["#f59e0b","#3b82f6","#ef4444","#10b981","#8b5cf6","#ec4899","#06b6d4","#f97316","#84cc16","#6366f1","#14b8a6","#e11d48","#a855f7","#0ea5e9","#d946ef","#eab308","#22c55e","#f43f5e","#2dd4bf","#fb923c","#818cf8","#4ade80","#f87171","#38bdf8"];function Ct(s,t){return s.map(n=>({driverName:n.driverName,carClass:n.carClass,positions:n.positions.map((r,a)=>{const i=s.filter(c=>c.positions[a]!=null).sort((c,d)=>c.positions[a]-d.positions[a]).findIndex(c=>c.driverName===n.driverName);return i===-1?null:i+1})}))}function kt({title:s,drivers:t,timingPoints:n}){const[r,a]=w.useState(()=>new Set),o=w.useCallback(j=>{a(L=>{const y=new Set(L);return y.has(j)?y.delete(j):y.add(j),y})},[]),{series:i,maxPos:c}=w.useMemo(()=>{let j=1;return{series:t.map((y,M)=>{for(const R of y.positions)R!=null&&R>j&&(j=R);return{...y,colour:Te[M%Te.length]}}),maxPos:j}},[t]);if(!i.length||n.length<2)return e.jsxs("div",{className:"pvx-positions-empty",children:["No position data for ",s||"this race","."]});const d=800,l=34,p=12,m=12,g=22,x=34,f=d-l-p,h=Math.max(g*(c-1),g),u=m+h+x,N=n.length,v=j=>l+(N===1?0:j/(N-1)*f),b=j=>m+(c===1?0:(j-1)/(c-1)*h),C=j=>{const L=[];let y=[];return j.forEach((M,R)=>{M==null?y.length&&(L.push(y),y=[]):y.push([v(R),b(M)])}),y.length&&L.push(y),L},$=r.size>0,P=Math.ceil(N/24);return e.jsxs("div",{className:"pvx-positions-chart",children:[s&&e.jsx("div",{className:"pvx-positions-title",children:s}),e.jsxs("svg",{className:"pvx-positions-svg",viewBox:`0 0 ${d} ${u}`,preserveAspectRatio:"xMidYMid meet",role:"img","aria-label":`Race position progression${s?` — ${s}`:""}`,children:[Array.from({length:c},(j,L)=>L+1).map(j=>e.jsxs("g",{children:[e.jsx("line",{className:"pvx-positions-grid",x1:l,y1:b(j),x2:d-p,y2:b(j)}),e.jsxs("text",{className:"pvx-positions-axis",x:l-6,y:b(j)+3,textAnchor:"end",children:["P",j]})]},`y${j}`)),n.map((j,L)=>L%P===0&&e.jsx("text",{className:"pvx-positions-axis",x:v(L),y:u-x+16,textAnchor:"middle",children:j.label},`x${L}`)),i.map(j=>{const L=$&&!r.has(j.driverName);return e.jsxs("g",{opacity:L?.12:1,children:[C(j.positions).map((y,M)=>e.jsx("polyline",{fill:"none",stroke:j.colour,strokeWidth:L?1:2,points:y.map(([R,_])=>`${R},${_}`).join(" ")},M)),!L&&j.positions.map((y,M)=>y!=null&&e.jsx("circle",{cx:v(M),cy:b(y),r:2.4,fill:j.colour,children:e.jsx("title",{children:`${j.driverName} — ${n[M].label}: P${y}`})},M))]},j.driverName)})]}),e.jsxs("div",{className:"pvx-positions-legend",children:[i.map(j=>{const L=$&&!r.has(j.driverName);return e.jsxs("button",{type:"button",className:"pvx-positions-legend-item",style:{opacity:L?.4:1},onClick:()=>o(j.driverName),children:[e.jsx("span",{className:"pvx-positions-swatch",style:{background:j.colour}}),j.driverName]},j.driverName)}),$&&e.jsx("button",{type:"button",className:"pvx-positions-legend-clear",onClick:()=>a(new Set),children:"Clear"})]})]})}function vs({positions:s}){const t=(s==null?void 0:s.timingPoints)||[],n=(s==null?void 0:s.drivers)||[],r=w.useMemo(()=>{const a=[...new Set(n.map(o=>o.carClass).filter(Boolean))];return a.length<=1?[{title:a[0]||null,drivers:n}]:a.sort().map(o=>({title:o,drivers:Ct(n.filter(i=>i.carClass===o),t.length)}))},[n,t.length]);return!t.length||!n.length?e.jsx("div",{className:"pvx-positions-empty",children:"No position data available for this race."}):e.jsx("div",{className:"pvx-positions",children:r.map((a,o)=>e.jsx(kt,{title:r.length>1?a.title:null,drivers:a.drivers,timingPoints:t},a.title||o))})}function St({competitionId:s,roundNumber:t,className:n}){var d;const{data:r,isLoading:a}=Ie(s,t);if(a)return e.jsx(I,{message:"Loading results..."});if(!r)return e.jsx(E,{message:"No results for this round."});const i=(r.sessions||[]).find(l=>l.type==="RACE"),c=(d=i==null?void 0:i.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:te[l.position-1]}),e.jsx("span",{children:l.driverName})]},l.driverId))})]}),e.jsx(oe,{round:r,competitionId:s})]})}function oe({round:s,competitionId:t,className:n}){var x,f,h,u,N,v;const[r,a]=w.useState(null),o=(s==null?void 0:s.sessions)||[];if(!o.length)return e.jsx(E,{message:"No session data for this round."});const{data:i}=We(t,s==null?void 0:s.roundNumber,{}),c=o.some(b=>b.type==="RACE"),{data:d}=Ve(t,s==null?void 0:s.roundNumber,{enabled:!!t&&c}),l=r||((x=o.find(b=>b.type==="RACE"))==null?void 0:x.type)||((f=o[0])==null?void 0:f.type),p=o.find(b=>b.type===l)||o[0],m=((u=(h=i==null?void 0:i.sessions)==null?void 0:h.find(b=>b.type===l))==null?void 0:u.drivers)||null,g=(p==null?void 0:p.type)==="RACE"&&((N=d==null?void 0:d.timingPoints)==null?void 0:N.length)>0&&((v=d==null?void 0:d.drivers)==null?void 0:v.length)>0;return e.jsxs("div",{className:n||"",children:[e.jsx(Qs,{sessions:o,activeSession:l,onSelect:a}),e.jsx(Lt,{session:p,sessionLaps:m}),g&&e.jsxs("div",{className:"pvx-positions-section",children:[e.jsx("div",{className:"pvx-positions-section-title",children:"Race Positions"}),e.jsx(vs,{positions:d})]})]})}function Lt({session:s,sessionLaps:t}){var p;const n=s.type==="RACE",[r,a]=w.useState(null);if(!((p=s.results)!=null&&p.length))return e.jsx(E,{message:`No results for ${s.type}.`});const o=zs(s.results),i=n?7:4,c=[...new Set(s.results.map(m=>m.carClass).filter(Boolean))],d=c.length>1,l=(m,g,x)=>{var u;const f=(u=t==null?void 0:t[m.driverId])==null?void 0:u.laps,h=r===m.driverId&&!!f;return e.jsx(Rt,{result:m,isRace:n,fastestSplits:o,rowIndex:g,displayPosition:x,hasLapDetail:!!f,isExpanded:h,onToggle:()=>a(h?null:m.driverId),driverLaps:h?f:null,colCount:i},m.driverId||g)};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:d?c.sort().map(m=>{const g=s.results.filter(x=>x.carClass===m).sort((x,f)=>(x.classPosition??x.position)-(f.classPosition??f.position));return[e.jsx("tr",{className:"pvx-row pvx-row--class-header",children:e.jsx("td",{colSpan:i,className:"pvx-td pvx-td--class-header",children:m})},`hdr-${m}`),...g.map((x,f)=>l(x,f,x.classPosition??x.position))]}):s.results.map((m,g)=>l(m,g))})]})})}function Rt({result:s,isRace:t,fastestSplits:n,rowIndex:r,displayPosition:a,hasLapDetail:o,isExpanded:i,onToggle:c,driverLaps:d,colCount:l}){const p=a??s.position,m=p<=3;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row ${m?"pvx-row--podium":""} ${o?"pvx-row--expandable":""}`,onClick:o?c:void 0,style:o?{cursor:"pointer"}:void 0,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(Ne,{position:p})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ne,{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:A(s.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx($t,{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&&d&&e.jsx("tr",{className:"pvx-row pvx-row--lap-detail",children:e.jsx("td",{colSpan:l,className:"pvx-td pvx-td--lap-detail",children:e.jsx(Tt,{laps:d})})})]})}function Tt({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((o,i)=>e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:o},i)),Array.from({length:Math.max(0,3-(((a=n.splits)==null?void 0:a.length)||0))}).map((o,i)=>e.jsx("td",{className:"pvx-td pvx-hidden-below-sm"},`pad-${i}`))]},n.lap)})})]})}function $t({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((o,i)=>{const c=r&&o===r[i];return e.jsxs("span",{className:"pvx-splits-tooltip-row",children:[e.jsxs("span",{className:"pvx-splits-tooltip-label",children:["S",i+1]}),e.jsx("span",{className:c?"pvx-splits-tooltip-best":"",children:o})]},i)})})})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})}function Mt({competitionId:s,className:t}){const{getSteamId:n}=S(),{data:r,isLoading:a}=ge(s),o=n();if(a)return e.jsx(I,{message:"Loading drivers..."});const i=(r==null?void 0:r.drivers)||(r==null?void 0:r.entries)||[];return i.length?e.jsx("div",{className:`pvx-entry-grid ${t||""}`,children:i.map(c=>{var l,p;const d=o&&c.steamId===o;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(E,{message:"No drivers registered yet."})}function Pt({competitionId:s,driverData:t,className:n,children:r}){const{data:a,isLoading:o}=X(s),{isPowerMode:i}=ee(),c=se(s),d=je(s),l=fe(s),p=(a==null?void 0:a.isRegistered)||!1,m=o||d.isPending||l.isPending,g=d.error||l.error||null,x=()=>{i&&d.mutate(t||{})},f=()=>{i&&l.mutate()};return typeof r=="function"?r({isRegistered:p,isLoading:m,register:x,withdraw:f,error:g,isPowerMode:i,registrationUrl:c}):i?e.jsx("button",{className:`pvx-comp-register-btn ${n||""}`,onClick:p?f:x,disabled:m,children:m?"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 Dt({competitionId:s,registration:t,onWithdrawSuccess:n,className:r}){const{getSteamId:a}=S(),{isPowerMode:o}=ee(),i=se(s),{data:c,isLoading:d}=X(s),{data:l,isLoading:p}=ge(s),m=je(s),g=fe(s),x=a(),f=(c==null?void 0:c.isRegistered)||!1,h=(l==null?void 0:l.drivers)||(l==null?void 0:l.entries)||[],u=t||{},N=h.length||u.currentCount||0,v=u.maxParticipants&&N>=u.maxParticipants,b=u.deadline&&new Date(u.deadline)<new Date,C=u.isOpen&&!b&&!v;return d||p?e.jsx(I,{message:"Loading registration..."}):f?e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx(At,{competitionId:s,drivers:h,steamId:x,isPowerMode:o,registrationUrl:i,withdrawMutation:g,onWithdrawSuccess:n,registration:u})}):C?x?o?e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx(Et,{competitionId:s,registerMutation:m,registration:u})}):e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Register on PitVox"})}):e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:o?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:i,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:v?"Registration is full.":b?"Registration deadline has passed.":"Registration is closed."}),h.length>0&&e.jsx(gs,{drivers:h,steamId:x})]})}function Et({competitionId:s,registerMutation:t,registration:n}){const[r,a]=w.useState(""),[o,i]=w.useState("intermediate"),[c,d]=w.useState(""),l=x=>{x.preventDefault(),t.mutate({discordUsername:r||void 0,experience:o,comments:c||void 0})},p=n||{},m=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(js,{count:m,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:o,onChange:x=>i(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 At({competitionId:s,drivers:t,steamId:n,isPowerMode:r,registrationUrl:a,withdrawMutation:o,onWithdrawSuccess:i,registration:c}){const[d,l]=w.useState(!1),p=()=>{o.mutate(void 0,{onSuccess:()=>{l(!1),i&&i()}})},m=c||{},g=t.length||m.currentCount||0,x=m.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(js,{count:g,max:x})]}),e.jsx(gs,{drivers:t,steamId:n}),o.error&&e.jsx("div",{className:"pvx-reg-error",children:o.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:o.isPending,children:o.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 gs({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 o=t&&r.steamId===t?-1:0,i=t&&a.steamId===t?-1:0;return o-i});return e.jsx("div",{className:"pvx-reg-driver-list",children:n.map(r=>{var o,i;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:((i=(o=r.displayName)==null?void 0:o.charAt(0))==null?void 0:i.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 js({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 Bt({competitionId:s,className:t}){const{data:n,isLoading:r}=he(s),a=(n==null?void 0:n.type)==="championship",o=(n==null?void 0:n.type)==="hotlap",i=w.useMemo(()=>(n==null?void 0:n.rounds)||[],[n]),c=o&&i.length>1,d=o&&!c,{data:l}=Fe(d?s:null),p=w.useMemo(()=>i.filter(y=>y.isFinalized),[i]),m=w.useMemo(()=>p.map(y=>y.roundNumber),[p]),{data:g=[],isLoading:x}=_e(s,m),f=d&&g.length>0?g[0]:null,h=(f==null?void 0:f.sessions)||[],u=c?i.find(y=>y.startTime&&new Date(y.startTime)<=new Date&&!q(y)):null,N=c?u?`hlround-${u.roundNumber}`:"standings":d?"leaderboard":a?"standings":m.length>0?`round-${m[m.length-1]}`:null,[v,b]=w.useState(null),C=v||N;if(r||x)return e.jsx(I,{message:"Loading results..."});if(!n)return e.jsx(E,{message:"Competition not found."});if(!p.length)return e.jsx(E,{message:"No results available yet. Results will appear here once rounds are finalised."});const $=new Map(g.map(y=>[`round-${y.roundNumber}`,y])),P=new Map(g.map(y=>[y.roundNumber,y])),j=[];if(c){j.push({id:"standings",label:"Standings"});for(const y of[...i].sort((M,R)=>M.roundNumber-R.roundNumber))j.push({id:`hlround-${y.roundNumber}`,label:`R${y.roundNumber}`,track:y.track||null})}else if(d){j.push({id:"leaderboard",label:"Leaderboard"});for(const y of h)j.push({id:`session-${y.type}`,label:K(y.type)})}else if(a){j.push({id:"standings",label:"Standings"});for(const y of p)j.push({id:`round-${y.roundNumber}`,label:`R${y.roundNumber}`,track:null})}else for(const y of p)j.push({id:`round-${y.roundNumber}`,label:`R${y.roundNumber}`,track:null});let L;if(C==="standings")L=e.jsx(hs,{competitionId:s});else if(C==="leaderboard")L=e.jsx(fs,{leaderboard:l,config:n});else if(C!=null&&C.startsWith("hlround-")){const y=parseInt(C.slice(8),10),M=i.find(R=>R.roundNumber===y);L=M?e.jsx(It,{competitionId:s,roundMeta:M,roundData:P.get(y)}):e.jsx(E,{message:"No results for this round."})}else if(C!=null&&C.startsWith("session-"))L=e.jsx(Ns,{session:h.find(y=>`session-${y.type}`===C),round:f,competitionId:s});else{const y=$.get(C);L=y?e.jsx(Ut,{round:y,competitionId:s}):e.jsx(E,{message:"No results for this round."})}return e.jsxs("div",{className:t||"",children:[e.jsx("div",{className:"pvx-results-tabs",children:j.map(y=>e.jsxs("button",{className:`pvx-results-tab ${C===y.id?"pvx-results-tab--active":""}`,onClick:()=>b(y.id),title:y.track||void 0,children:[e.jsx("span",{className:"pvx-results-tab-label",children:y.label}),y.track&&e.jsx("span",{className:"pvx-results-tab-track",children:y.track})]},y.id))}),L]})}function Ut({round:s,competitionId:t}){var o;const r=(s.sessions||[]).find(i=>i.type==="RACE"),a=(o=r==null?void 0:r.results)==null?void 0:o.filter(i=>i.position<=3).sort((i,c)=>i.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(i=>e.jsxs("span",{className:"pvx-round-podium-item",children:[e.jsx("span",{children:te[i.position-1]}),e.jsx("span",{children:i.driverName})]},i.driverId))})]}),e.jsx(oe,{round:s,competitionId:t})]})}function fs({leaderboard:s,config:t,heading:n}){var r;return(r=s==null?void 0:s.drivers)!=null&&r.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:n||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(a=>{const o=a.position===1?"":`+${((a.bestLapMs-s.drivers[0].bestLapMs)/1e3).toFixed(3)}`;return e.jsxs("tr",{className:`pvx-row ${a.position<=3?"pvx-row--podium":""}`,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(Ne,{position:a.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ne,{nation:a.nation}),a.driverName]}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:A(a.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx("span",{className:a.position===1?"pvx-best-lap-cell--fastest":"",children:a.bestLapFormatted})}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:a.totalLaps}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:a.sessionsParticipated}),e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:o})]},a.driverId)})})]})})]}):e.jsx(E,{message:"No lap times recorded yet."})}function Ns({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:K(s.type)})}),e.jsx(oe,{round:{...t,sessions:[s]},competitionId:n})]}):e.jsx(E,{message:"Session data not available."})}function It({competitionId:s,roundMeta:t,roundData:n}){const{data:r}=qe(s,t.roundNumber),a=(n==null?void 0:n.sessions)||[],[o,i]=w.useState("leaderboard"),c=[{id:"leaderboard",label:"Leaderboard"},...a.map(p=>({id:`session-${p.type}`,label:K(p.type)}))],d=c.some(p=>p.id===o)?o:"leaderboard",l=`Round ${t.roundNumber}${t.track?` — ${t.track}`:""}`;return e.jsxs("div",{children:[e.jsx("div",{className:"pvx-session-tabs",children:c.map(p=>e.jsx("button",{onClick:()=>i(p.id),className:`pvx-session-tab ${d===p.id?"pvx-session-tab--active":""}`,children:p.label},p.id))}),d==="leaderboard"?e.jsx(fs,{leaderboard:r,heading:l}):e.jsx(Ns,{session:a.find(p=>`session-${p.type}`===d),round:n,competitionId:s})]})}function ys(s){const{cdnUrl:t}=S(),n=k.useQuery({queryKey:["pitvox","laps","global",s,"index"],queryFn:()=>T(t,xe(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 bs(s){const{cdnUrl:t,partnerSlug:n}=S(),r=k.useQuery({queryKey:["pitvox","laps",n||"global",s,"index"],queryFn:()=>T(t,xe(n,s)),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),a=w.useMemo(()=>{var o;return((o=r.data)==null?void 0:o.combos)||[]},[r.data]);return{isLoading:r.isLoading,error:r.error,data:a}}function ws(s={}){const{cdnUrl:t,partnerSlug:n}=S(),{game:r,gameVersion:a,enabled:o=!0}=s,i=Y(n,r,a,"ratings.json");return k.useQuery({queryKey:["pitvox","ratings",n,r||null,a||null],queryFn:()=>T(t,i),staleTime:3e4,refetchInterval:3e4,enabled:o})}function _t(s){var r;const t=ws(),n=w.useMemo(()=>{var a;return!((a=t.data)!=null&&a.drivers)||!s?null:t.data.drivers.find(o=>o.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 z(s={}){const t=ws(s);return{data:t.data||null,isLoading:t.isLoading,error:t.error}}function Cs(s){var d,l;const{versions:t}=Ae(),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=z({game:"evo",gameVersion:n,enabled:!!n}),o=z({game:"acc"}),i=z({game:"lmu",gameVersion:r,enabled:!!r});return{data:w.useMemo(()=>s?[{data:a.data,game:"evo",label:"EVO"},{data:o.data,game:"acc",label:"ACC"},{data:i.data,game:"lmu",label:"LMU"}].map(({data:p,game:m,label:g})=>{var h;if(!((h=p==null?void 0:p.drivers)!=null&&h.length))return null;const x=[...p.drivers].sort((u,N)=>N.rating-u.rating),f=x.findIndex(u=>u.identifier===s);return f===-1?null:{game:m,label:g,rating:x[f].rating,rank:f+1,totalDrivers:x.length}}).filter(Boolean):[],[s,a.data,o.data,i.data]),isLoading:a.isLoading||o.isLoading||i.isLoading}}function ks(){const{cdnUrl:s,partnerSlug:t,getSteamId:n,onFetchServerPassword:r}=S(),a=n(),{data:o,isLoading:i}=k.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const x=await T(s,"competitions/index.json");return x!=null&&x.competitions?x.competitions.filter(f=>f.partnerSlug===t):[]},staleTime:6e4}),c=(o==null?void 0:o.map(x=>x.id))||[],d=k.useQueries({queries:c.map(x=>({queryKey:["pitvox","competition",t,x,"entrylist"],queryFn:()=>T(s,`competitions/${t}/${x}/entrylist.json`),enabled:!!a&&c.length>0,staleTime:6e4}))}),l=d.some(x=>x.isLoading),p=w.useMemo(()=>{var h,u;if(!o||!a||l)return[];const x=new Date,f=[];for(let N=0;N<o.length;N++){const v=o[N],b=(h=d[N])==null?void 0:h.data;if(!((u=b==null?void 0:b.drivers)==null?void 0:u.some(j=>j.steamId===a)))continue;const $=v.type==="hotlap",P=v.rounds||[];for(const j of P){if($?q(j):j.isFinalized)continue;const y=j.dediStatus==="running"||j.dediStatus==="provisioning",M=j.dediStatus==="scheduled",R=j.startTime&&new Date(j.startTime)>x,_=y||M||j.dediServerAddress;!y&&!R&&!_||f.push({competitionId:v.id,competitionName:v.name,roundNumber:j.roundNumber,track:j.track||"TBD",startTime:j.startTime,dediStatus:j.dediStatus||null,dediServerAddress:j.dediServerAddress||null})}}return f.sort((N,v)=>{const b=N.dediStatus==="running"||N.dediStatus==="provisioning",C=v.dediStatus==="running"||v.dediStatus==="provisioning";return b&&!C?-1:!b&&C?1:new Date(N.startTime)-new Date(v.startTime)}),f.length>0&&(f[0].isNext=!0),f},[o,a,l,d]),m=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:w.useMemo(()=>p.length?r?p.map((x,f)=>{var u;const h=(u=m[f])==null?void 0:u.data;return h!=null&&h.success?{...x,serverAddress:h.serverAddress||null,serverPassword:h.serverPassword||null}:x}):p:[],[p,r,m]),isLoading:i||!!a&&l}}function Ss(){const{onFetchNotifications:s}=S();return!!s}function Ls(s={}){const{onFetchNotifications:t,partnerSlug:n}=S(),{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 Ft(){const{onFetchNotifications:s,partnerSlug:t}=S(),{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 Rs(){const{onMarkNotificationRead:s,partnerSlug:t}=S(),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]},o=>o!=null&&o.notifications?{...o,unreadCount:Math.max(0,(o.unreadCount||0)-1),notifications:o.notifications.map(i=>i.id===a?{...i,isRead:!0,readAt:new Date().toISOString()}:i)}:o)}})}function Ts(){const{onMarkAllNotificationsRead:s,partnerSlug:t}=S(),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 $s({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 qt(){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 Wt(){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 $e(){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 Me({icon:s,value:t,label:n,items:r,labelKey:a,countKey:o}){const[i,c]=w.useState(!1),d=w.useRef(null);w.useEffect(()=>{if(!i)return;function p(m){d.current&&!d.current.contains(m.target)&&c(!1)}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[i]);const l=r!=null&&r.length?r.slice().sort((p,m)=>m[o]-p[o]):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 ${i?"pvx-dash-tooltip--open":""}`,children:l.map((p,m)=>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[o]})]},m))})]})}function Ms({stats:s,gameRatings:t,onGameRatingSelect:n,rating:r,className:a=""}){if(!s)return null;const o=s.trackBreakdown.map(d=>({name:W(d.trackId,d.layout),lapCount:d.lapCount})),i=s.carBreakdown.map(d=>({name:A(d.carId),lapCount:d.lapCount})),c=Array.isArray(t)&&t.length>0;return e.jsxs("div",{className:`pvx-dash-stats ${a}`,children:[e.jsx(Me,{icon:e.jsx(qt,{}),value:s.lapCount.toLocaleString(),label:"Total Laps",items:o,labelKey:"name",countKey:"lapCount"}),e.jsx(Me,{icon:e.jsx(Wt,{}),value:s.carBreakdown.length,label:"Cars Used",items:i,labelKey:"name",countKey:"lapCount"}),c?e.jsxs("div",{className:"pvx-dash-stat-card pvx-dash-stat-card--rating-chips",children:[e.jsx($e,{}),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=m=>{l&&(m.key==="Enter"||m.key===" ")&&(m.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($e,{}),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 Ps({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(Vt,{combo:r,onClick:t?()=>t(r):null},`${r.trackId}|${r.trackLayout||""}|${r.carId}|${r.game||""}|${r.gameVersion||""}`))})]}):null}function Vt({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,o=`pvx-dash-combo-row${t?" pvx-dash-combo-row--clickable":""}`,i=c=>{t&&(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),t())};return e.jsxs("div",{className:o,onClick:t||void 0,onKeyDown:t?i: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:W(s.trackId,s.trackLayout,s.game)})]}),e.jsxs("div",{className:"pvx-dash-combo-meta",children:[e.jsx("span",{className:"pvx-dash-combo-car",children:A(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:Z(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:U(s.personalBestMs)})]})]})}function Ds({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,o=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(Ot,{}),"Upcoming Events",e.jsxs("span",{className:"pvx-dash-records-count",children:["(",s.length,")"]})]})}),e.jsxs("div",{className:"pvx-upcoming-list",children:[a.map(i=>e.jsxs("div",{className:`pvx-upcoming-item ${i.isNext?"pvx-upcoming-item--next":""}`,children:[e.jsxs("div",{className:"pvx-upcoming-info",children:[e.jsx("span",{className:"pvx-upcoming-comp",children:i.competitionName}),e.jsxs("span",{className:"pvx-upcoming-round",children:["Round ",i.roundNumber,": ",i.track]}),i.serverPassword&&e.jsx(Ht,{password:i.serverPassword,address:i.serverAddress})]}),e.jsxs("div",{className:"pvx-upcoming-time",children:[e.jsx("span",{className:"pvx-upcoming-date",children:new Date(i.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}),e.jsx("span",{className:"pvx-upcoming-relative",children:i.dediStatus==="running"?"Live now":i.dediStatus==="provisioning"?"Starting...":Kt(i.startTime)}),i.dediStatus==="running"&&e.jsx("span",{className:"pvx-upcoming-badge pvx-upcoming-badge--live",children:"Live"}),!i.dediStatus&&i.isNext&&e.jsx("span",{className:"pvx-upcoming-badge",children:"Next"})]})]},`${i.competitionId}-${i.roundNumber}`)),o>0&&e.jsxs("div",{className:"pvx-upcoming-remaining",children:["+",o," more event",o!==1?"s":""]})]})]})}function Ht({password:s,address:t}){const[n,r]=w.useState(!1),[a,o]=w.useState(!1),i=t?s?`join:${t}|${s}`:`join:${t}`:null,c=w.useCallback(async()=>{if(i)try{await navigator.clipboard.writeText(i),r(!0),setTimeout(()=>r(!1),2e3)}catch{}},[i]);return e.jsxs("div",{className:"pvx-server-info",children:[i&&e.jsxs("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick:c,title:"Copy join string to clipboard",children:[e.jsx(Gt,{})," ",n?"Copied!":"Join"]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick:()=>o(d=>!d),title:a?"Hide password":"Reveal password",children:a?e.jsx(Yt,{}):e.jsx(zt,{})}),a&&e.jsxs("span",{className:"pvx-server-detail",children:[e.jsx(Qt,{})," ",s]})]})]})}function Kt(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 Z(s)}function Ot(){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 Qt(){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 Gt(){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 zt(){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 Yt(){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 Es({notifications:s,unreadCount:t=0,onMarkRead:n,onMarkAllRead:r,isLoading:a,className:o}){const i=J();return a?e.jsx("div",{className:"pvx-loading",children:"Loading notifications..."}):e.jsxs("div",{className:`pvx-card ${o||""}`,children:[e.jsxs("div",{className:"pvx-card-header",children:[e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(Xt,{}),"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(Zt,{notification:c,getUserDisplay:i,onMarkRead:n},c.id))}):e.jsx("div",{className:"pvx-notif-empty",children:"No notifications"})]})}function Zt({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(Jt,{type:s.type}),e.jsxs("div",{className:"pvx-notif-content",children:[e.jsx("span",{className:"pvx-notif-message",children:Ee(s,t)}),e.jsx("span",{className:"pvx-notif-time",children:Z(s.createdAt)})]}),!s.isRead&&e.jsx("span",{className:"pvx-notif-dot"})]})}function Jt({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 Xt(){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 en({steamId:s,avatarUrl:t,memberSince:n,hideProfile:r=!1,onComboSelect:a,onGameRatingSelect:o,className:i=""}){const{data:c,isLoading:d,error:l}=ys(s),{data:p}=Cs(s),{data:m}=bs(s),{data:g,isLoading:x}=ks(),f=Ss(),{data:h,isLoading:u}=Ls({limit:10}),N=Rs(),v=Ts();return d?e.jsx("div",{className:"pvx-loading",children:"Loading dashboard..."}):l?e.jsx("div",{className:"pvx-empty",children:"Failed to load dashboard data."}):c?e.jsxs("div",{className:`pvx-dash ${i}`,children:[!r&&e.jsx($s,{driverName:c.driverName,avatarUrl:t,memberSince:n}),e.jsx(Ms,{stats:c,gameRatings:p,onGameRatingSelect:o}),s&&e.jsx(Ds,{events:g,isLoading:x}),e.jsxs("div",{className:`pvx-dash-row ${f?"pvx-dash-row--2col":""}`,children:[e.jsx(Ps,{combos:m,onComboSelect:a}),f&&e.jsx(Es,{notifications:h==null?void 0:h.notifications,unreadCount:(h==null?void 0:h.unreadCount)||0,onMarkRead:b=>N.mutate(b),onMarkAllRead:()=>v.mutate(),isLoading:u})]})]}):e.jsx("div",{className:"pvx-empty",children:"No data available yet. Start driving to see your stats!"})}function sn({records:s,className:t=""}){const n=w.useMemo(()=>s!=null&&s.length?s.slice().sort((r,a)=>{const o=r.recordedAt?new Date(r.recordedAt).getTime():0;return(a.recordedAt?new Date(a.recordedAt).getTime():0)-o}):[],[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:W(r.trackId,r.layout,r.game)}),e.jsx("span",{className:"pvx-dash-record-car",children:A(r.carId)})]}),e.jsxs("div",{className:"pvx-dash-record-time",children:[e.jsx("span",{className:"pvx-dash-record-lap",children:U(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=rt;exports.CompEmptyState=E;exports.CompLoadingState=I;exports.CompetitionCard=ms;exports.CompetitionCards=Nt;exports.CompetitionResultsTabs=Bt;exports.CompletedBadge=xs;exports.DEFAULT_COMPLETION_GRACE_DAYS=ye;exports.DriverDashboard=en;exports.DriverProfile=$s;exports.DriversTable=at;exports.EnterButton=is;exports.EntryList=Mt;exports.InfoPill=G;exports.LapHistoryTable=it;exports.NotificationsCard=Es;exports.PODIUM_MEDALS=te;exports.PROMOTION_STATUS_LABELS=He;exports.PitVoxPartnerProvider=Is;exports.PromotionCard=as;exports.PromotionCards=rs;exports.PromotionDetail=os;exports.PromotionExplorer=Js;exports.PromotionStatusBadge=we;exports.PromotionTypeBadge=Ce;exports.RacePositionsChart=vs;exports.RankingsTable=ot;exports.RecentCombosCard=Ps;exports.RecordsTable=sn;exports.RegisterButton=Pt;exports.RegistrationPanel=Dt;exports.RoundResults=St;exports.RoundSessionResults=oe;exports.StandingsTable=hs;exports.StatsCards=Ms;exports.TracksTable=nt;exports.TypeBadge=Xe;exports.UpcomingEvents=Ds;exports.WeatherIcon=us;exports.buildDriverIndexPath=xe;exports.buildLapsPath=Pe;exports.buildLeaderboardPath=Y;exports.buildRecentLapsPath=De;exports.fetchCdnJson=T;exports.filterCompetitionsByStatus=Ys;exports.formatCarName=A;exports.formatDate=V;exports.formatDelta=_s;exports.formatFuel=me;exports.formatLapTime=U;exports.formatNotificationMessage=Ee;exports.formatPromotionDate=F;exports.formatRelativeTime=Z;exports.formatSectorTime=B;exports.formatSessionLabel=K;exports.formatTrackName=W;exports.formatTyreCompound=ue;exports.getCompetitionPodium=ts;exports.getCompetitionStatus=be;exports.getCompletionDate=ss;exports.getPromotionStatus=H;exports.isCompetitionComplete=es;exports.isRoundClosed=q;exports.promotionWindowSummary=ns;exports.useCarLeaderboard=Ws;exports.useCarMetadata=Fs;exports.useCompetitionAllRounds=_e;exports.useCompetitionConfig=he;exports.useCompetitionEntryList=ge;exports.useCompetitionLeaderboard=Fe;exports.useCompetitionRound=Ie;exports.useCompetitionRoundLaps=We;exports.useCompetitionRoundLeaderboard=qe;exports.useCompetitionRoundPositions=Ve;exports.useCompetitionStandings=ve;exports.useCompetitions=Vs;exports.useDriverCombos=bs;exports.useDriverLaps=Ue;exports.useDriverRating=_t;exports.useDriverRatings=z;exports.useDriverRatingsByGame=Cs;exports.useDriverStats=ys;exports.useEnterPromotion=ze;exports.useLeaderboardIndex=Ae;exports.useMarkAllNotificationsRead=Ts;exports.useMarkNotificationRead=Rs;exports.useNotifications=Ls;exports.useNotificationsEnabled=Ss;exports.usePitVox=S;exports.usePromotionConfig=Oe;exports.usePromotionEntryList=Qe;exports.usePromotionEntryStatus=Ge;exports.usePromotionMode=Ze;exports.usePromotionUrl=Je;exports.usePromotions=Ke;exports.useRecentLaps=qs;exports.useRegister=je;exports.useRegistrationMode=ee;exports.useRegistrationStatus=X;exports.useRegistrationUrl=se;exports.useTrackLeaderboard=Be;exports.useUnreadCount=Ft;exports.useUpcomingEvents=ks;exports.useUserLookup=J;exports.useWithdraw=fe;exports.useWithdrawPromotionEntry=Ye;
|