@pitvox/partner-react 0.6.1 → 0.6.3
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 +25 -8
- package/dist/index.cjs +1 -1
- package/dist/index.js +857 -766
- package/dist/styles.css +84 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,16 @@ function App() {
|
|
|
37
37
|
|
|
38
38
|
> The provider auto-creates a `QueryClient` if your app doesn't already have one. If you use React Query elsewhere, wrap with your own `QueryClientProvider` first and the SDK will share it.
|
|
39
39
|
|
|
40
|
+
### Global mode
|
|
41
|
+
|
|
42
|
+
`partnerSlug` is optional. Omit it (or pass `null`) to use global CDN paths instead of partner-scoped ones. This is useful for sites like pitvox.com that display leaderboards and competitions across all partners.
|
|
43
|
+
|
|
44
|
+
```jsx
|
|
45
|
+
<PitVoxPartnerProvider cdnUrl="https://cdn.pitvox.com">
|
|
46
|
+
{/* hooks return global data */}
|
|
47
|
+
</PitVoxPartnerProvider>
|
|
48
|
+
```
|
|
49
|
+
|
|
40
50
|
## Leaderboards
|
|
41
51
|
|
|
42
52
|
### Hooks
|
|
@@ -46,6 +56,7 @@ import {
|
|
|
46
56
|
useLeaderboardIndex,
|
|
47
57
|
useTrackLeaderboard,
|
|
48
58
|
useDriverLaps,
|
|
59
|
+
useRecentLaps,
|
|
49
60
|
useUserLookup,
|
|
50
61
|
useCarMetadata,
|
|
51
62
|
} from '@pitvox/partner-react'
|
|
@@ -62,7 +73,11 @@ import {
|
|
|
62
73
|
|
|
63
74
|
**`useDriverLaps(userId, trackId, layout, carId, options?)`** — Fetch a driver's lap history.
|
|
64
75
|
- `options.showInvalid` — Include invalid laps (default `false`)
|
|
65
|
-
- Returns `{ data: Lap[], isLoading, driverName }`
|
|
76
|
+
- Returns `{ data: Lap[], isLoading, driverName, theoreticalBest }`
|
|
77
|
+
- `theoreticalBest` — `{ lapTimeMs, sector1Ms, sector2Ms, sector3Ms }` or `null`. Computed from the best individual sectors across all valid laps. Only returned when it's faster than the actual best lap and there are at least 2 valid laps.
|
|
78
|
+
|
|
79
|
+
**`useRecentLaps()`** — Fetch recent lap activity.
|
|
80
|
+
- Returns `{ groups: Activity[], generatedAt, isLoading }`
|
|
66
81
|
|
|
67
82
|
**`useUserLookup()`** — Returns a lookup function: `(userId, fallback?) => { displayName, avatarUrl, affiliations }`
|
|
68
83
|
|
|
@@ -100,17 +115,19 @@ import {
|
|
|
100
115
|
} from '@pitvox/partner-react'
|
|
101
116
|
```
|
|
102
117
|
|
|
103
|
-
**`useCompetitions()`** — All competitions for this partner.
|
|
118
|
+
**`useCompetitions()`** — All competitions for this partner (or all competitions in global mode).
|
|
119
|
+
|
|
120
|
+
**`useCompetitionConfig(competitionId, options?)`** — Single competition config (name, rounds, countingRounds, etc.).
|
|
104
121
|
|
|
105
|
-
**`
|
|
122
|
+
**`useCompetitionStandings(competitionId, options?)`** — Championship standings with per-round breakdowns.
|
|
106
123
|
|
|
107
|
-
**`
|
|
124
|
+
**`useCompetitionRound(competitionId, roundNumber, options?)`** — Single round results with session data.
|
|
108
125
|
|
|
109
|
-
**`
|
|
126
|
+
**`useCompetitionAllRounds(competitionId, roundNumbers, options?)`** — Fetch multiple round results in parallel.
|
|
110
127
|
|
|
111
|
-
**`
|
|
128
|
+
**`useCompetitionEntryList(competitionId, options?)`** — Registered drivers.
|
|
112
129
|
|
|
113
|
-
|
|
130
|
+
All competition detail hooks accept `options.partnerSlug` to override the provider's slug. This is useful in global mode where the partner slug comes from the competition data rather than from context.
|
|
114
131
|
|
|
115
132
|
### Styled components
|
|
116
133
|
|
|
@@ -308,7 +325,7 @@ import { useRegistrationStatus, useRegister, useWithdraw, useRegistrationMode, u
|
|
|
308
325
|
```jsx
|
|
309
326
|
import {
|
|
310
327
|
formatLapTime, // 92365 → "1:32.365"
|
|
311
|
-
formatSectorTime, // 34567 → "34.567"
|
|
328
|
+
formatSectorTime, // 34567 → "34.567", 197487 → "3:17.487"
|
|
312
329
|
formatCarName, // "ks_ferrari_296_gt3" → "Ferrari 296 Gt3"
|
|
313
330
|
formatTrackName, // "donington_park", "national" → "Donington Park National"
|
|
314
331
|
formatDate, // ISO string → "27 Feb 2024"
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),N=require("react"),y=require("@tanstack/react-query"),G=N.createContext(null),qe="https://cdn.pitvox.com",_e="https://pitvox.com";let W=null;function Ve({partnerSlug:s=null,cdnUrl:r=qe,pitvoxUrl:n=_e,getSteamId:t,onRegister:a,onWithdraw:i,onFetchNotifications:o,onMarkNotificationRead:l,onMarkAllNotificationsRead:p,onFetchServerPassword:c,children:u}){const v=N.useMemo(()=>({partnerSlug:s,cdnUrl:r.replace(/\/$/,""),pitvoxUrl:n.replace(/\/$/,""),getSteamId:t||(()=>null),onRegister:a||null,onWithdraw:i||null,onFetchNotifications:o||null,onMarkNotificationRead:l||null,onMarkAllNotificationsRead:p||null,onFetchServerPassword:c||null}),[s,r,n,t,a,i,o,l,p,c]);let j=!1;try{y.useQueryClient(),j=!0}catch{j=!1}return j?e.jsx(G.Provider,{value:v,children:u}):(W||(W=new y.QueryClient({defaultOptions:{queries:{staleTime:6e4}}})),e.jsx(y.QueryClientProvider,{client:W,children:e.jsx(G.Provider,{value:v,children:u})}))}function k(){const s=N.useContext(G);if(!s)throw new Error("usePitVox must be used within a <PitVoxPartnerProvider>");return s}async function w(s,r){const n=await fetch(`${s}/${r}`);if(!n.ok){if(n.status===404||n.status===403)return null;throw new Error(`CDN fetch failed: ${n.status}`)}return n.json()}function q(s,...r){return[s?`leaderboards/partners/${s}`:"leaderboards",...r].join("/")}function ae(s,r){return s?`laps/partners/${s}/${r}.json`:`laps/${r}.json`}function ie(s){return s?`recent-laps/partners/${s}.json`:"recent-laps.json"}function $(s){if(!s&&s!==0)return"-";const r=Math.floor(s/1e3),n=Math.floor(r/60),t=r%60,a=s%1e3;return`${n}:${String(t).padStart(2,"0")}.${String(a).padStart(3,"0")}`}function M(s){return!s&&s!==0?"-":(s/1e3).toFixed(3)}function S(s){if(!s)return"";let r=s;return r.startsWith("ks_")&&(r=r.slice(3)),r.split("_").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function I(s,r,n){if(!s)return"";const t=s.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" "),a=n==="acc"||!n&&(r==null?void 0:r.toLowerCase())==="track config";if(!r||r==="default"||a)return t;const i=r.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ");return`${t} ${i}`}function P(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 r=Date.now()-new Date(s).getTime(),n=Math.floor(r/1e3);if(n<60)return"Just now";const t=Math.floor(n/60);if(t<60)return`${t}m ago`;const a=Math.floor(t/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);return i<30?`${i}d ago`:P(s)}function Ke(s){return s==null?"":`${s>=0?"+":"-"}${(Math.abs(s)/1e3).toFixed(3)}`}function oe(s,r){const{type:n,title:t,trackId:a,trackLayout:i,carId:o,game:l,data:p}=s,c=typeof p=="string"?JSON.parse(p):p,u=a?I(a,i,l):null,v=o?S(o):null,j=[u,v].filter(Boolean).join(" — ");return n==="RECORD_BEATEN"&&j?`${c!=null&&c.beatenBySteamId&&r?r(c.beatenBySteamId).displayName:"Someone"} beat your record on ${j}`:n==="RECORD_SET"&&j?`You set a new record on ${j}`:t||"New notification"}function J(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 He(s={}){var p,c,u,v,j,d;const{cdnUrl:r,partnerSlug:n}=k(),{game:t,gameVersion:a}=s,i=q(n,"index.json"),o=y.useQuery({queryKey:["pitvox","leaderboards",n,"index"],queryFn:()=>w(r,i),staleTime:3e4,refetchInterval:3e4}),l=N.useMemo(()=>{var h;if(!((h=o.data)!=null&&h.tracks))return[];let f=o.data.tracks;return t&&(f=f.filter(x=>x.game===t)),a&&(f=f.filter(x=>x.gameVersion===a)),f.map(x=>({id:x.trackId,layout:x.layout,game:x.game,gameVersion:x.gameVersion,displayName:I(x.trackId,x.layout,x.game),driverCount:x.driverCount||0,carCount:x.carCount||0,record:x.recordHolder?{visibleId:x.recordHolder.steamId||x.recordHolder.userId,carId:x.recordHolder.carId,carDisplayName:S(x.recordHolder.carId),lapTimeMs:x.recordHolder.lapTimeMs,timestamp:x.recordHolder.recordedAt}:null,recordByTag:x.recordByTag||null}))},[(p=o.data)==null?void 0:p.tracks,t,a]);return{...o,data:l,partner:((c=o.data)==null?void 0:c.partner)||null,generatedAt:(u=o.data)==null?void 0:u.generatedAt,totalLaps:((v=o.data)==null?void 0:v.totalLaps)||0,totalUsers:((j=o.data)==null?void 0:j.totalUsers)||0,versions:((d=o.data)==null?void 0:d.versions)||{}}}function ce(s,r,n={}){const{cdnUrl:t,partnerSlug:a}=k(),{carId:i,game:o,gameVersion:l}=n,p=r||"default",c=l?`v/${l}/`:"",u=q(a,`${c}tracks/${s}/${p}.json`),{data:v,isLoading:j,error:d}=y.useQuery({queryKey:["pitvox","leaderboards",a,"track",s,p,l],queryFn:()=>w(t,u),enabled:!!s,staleTime:3e4,refetchInterval:3e4});return{data:N.useMemo(()=>{if(!(v!=null&&v.entries))return[];let h=v.entries;if(o&&(h=h.filter(x=>x.game===o)),!i){const x=new Map,g=new Map;for(const m of h){const b=m.steamId||m.userId;g.has(m.carId)||g.set(m.carId,new Set),g.get(m.carId).add(b),(!x.has(m.carId)||m.lapTimeMs<x.get(m.carId).lapTimeMs)&&x.set(m.carId,m)}return Array.from(x.values()).map(m=>{var b;return{...m,driverCount:((b=g.get(m.carId))==null?void 0:b.size)||0}}).sort((m,b)=>m.lapTimeMs-b.lapTimeMs)}return h.filter(x=>x.carId===i).sort((x,g)=>x.lapTimeMs-g.lapTimeMs)},[v==null?void 0:v.entries,i,o]),isLoading:j,error:d}}function le(s,r,n,t,a={}){var d,f;const{cdnUrl:i,partnerSlug:o}=k(),{showInvalid:l=!1,game:p,gameVersion:c}=a,u=ae(o,s),v=y.useQuery({queryKey:["pitvox","laps",o,s],queryFn:()=>w(i,u),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),j=N.useMemo(()=>{var h;return(h=v.data)!=null&&h.laps?v.data.laps.filter(x=>{if(x.trackId!==r)return!1;if(n){if(x.trackLayout!==n)return!1}else if(x.trackLayout&&x.trackLayout!=="default")return!1;return!(x.carId!==t||p&&x.game!==p||c&&x.gameVersion!==c||!l&&!x.isValid)}).sort((x,g)=>x.lapTimeMs-g.lapTimeMs):[]},[(d=v.data)==null?void 0:d.laps,r,n,t,p,c,l]);return{...v,data:j,driverName:((f=v.data)==null?void 0:f.driverName)||"Driver"}}function Y(){const{cdnUrl:s}=k(),{data:r}=y.useQuery({queryKey:["pitvox","users","index"],queryFn:()=>w(s,"users/index.json"),staleTime:5*6e4,gcTime:30*6e4}),n=(r==null?void 0:r.users)||{};return(t,a)=>{const i=n[t];return{displayName:(i==null?void 0:i.displayName)||a||t||"Unknown",avatarUrl:(i==null?void 0:i.avatarUrl)||null,affiliations:(i==null?void 0:i.affiliations)||[]}}}function Qe(){const{cdnUrl:s}=k(),{data:r}=y.useQuery({queryKey:["pitvox","cars","index"],queryFn:()=>w(s,"cars/index.json"),staleTime:5*6e4,gcTime:30*6e4});return{tags:(r==null?void 0:r.tags)||[],cars:(r==null?void 0:r.cars)||{}}}function Oe(){var a,i;const{cdnUrl:s,partnerSlug:r}=k(),n=ie(r),t=y.useQuery({queryKey:["pitvox","recentLaps",r],queryFn:()=>w(s,n),staleTime:3e4,refetchInterval:3e4,gcTime:10*6e4});return{groups:((a=t.data)==null?void 0:a.groups)||[],generatedAt:((i=t.data)==null?void 0:i.generatedAt)||null,isLoading:t.isLoading}}function We(s,r){return ce(s,null,{carId:r})}function Ge(){const{cdnUrl:s,partnerSlug:r}=k();return y.useQuery({queryKey:["pitvox","competitions",r],queryFn:async()=>{const n=await w(s,"competitions/index.json");return n!=null&&n.competitions?r?n.competitions.filter(t=>t.partnerSlug===r):n.competitions:[]},staleTime:6e4})}function de(s,r={}){const n=k(),t=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",t,s,"config"],queryFn:()=>w(n.cdnUrl,`competitions/${t}/${s}/config.json`),enabled:!!t&&!!s,staleTime:6e4})}function pe(s,r={}){const n=k(),t=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",t,s,"standings"],queryFn:()=>w(n.cdnUrl,`competitions/${t}/${s}/standings.json`),enabled:!!t&&!!s,staleTime:6e4})}function xe(s,r,n={}){const t=k(),a=n.partnerSlug||t.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"round",r],queryFn:()=>w(t.cdnUrl,`competitions/${a}/${s}/rounds/${r}.json`),enabled:!!a&&!!s&&r!=null,staleTime:6e4})}function ze(s,r=[],n={}){const t=k(),a=n.partnerSlug||t.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"allRounds",r],queryFn:async()=>(await Promise.all(r.map(o=>w(t.cdnUrl,`competitions/${a}/${s}/rounds/${o}.json`).catch(()=>null)))).filter(Boolean),enabled:!!a&&!!s&&r.length>0,staleTime:6e4})}function Z(s,r={}){const n=k(),t=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",t,s,"entrylist"],queryFn:()=>w(n.cdnUrl,`competitions/${t}/${s}/entrylist.json`),enabled:!!t&&!!s,staleTime:6e4})}function _(s){const{cdnUrl:r,partnerSlug:n,getSteamId:t}=k(),a=t();return y.useQuery({queryKey:["pitvox","registration",n,s,a],queryFn:async()=>{var p;const i=await fetch(`${r}/competitions/${n}/${s}/entrylist.json`);if(!i.ok)return{isRegistered:!1,entryList:null};const o=await i.json();return{isRegistered:!!a&&((p=o.drivers)==null?void 0:p.some(c=>c.steamId===a)),entryList:o}},enabled:!!s,staleTime:6e4})}function X(s){const{onRegister:r,partnerSlug:n,getSteamId:t}=k(),a=y.useQueryClient(),i=Y();return y.useMutation({mutationFn:o=>{if(!r)throw new Error("No onRegister callback provided to PitVoxPartnerProvider. Provide onRegister for in-app registration, or use useRegistrationUrl() to link to pitvox.com.");return r(s,o)},onSuccess:()=>{const o=t();if(a.setQueriesData({queryKey:["pitvox","registration",n,s]},l=>l?{...l,isRegistered:!0}:{isRegistered:!0,entryList:null}),o){const l=i(o),p={steamId:o,displayName:l.displayName,avatarUrl:l.avatarUrl};a.setQueriesData({queryKey:["pitvox","competition",n,s,"entrylist"]},c=>{var v;return c?((v=c.drivers)==null?void 0:v.some(j=>j.steamId===o))?c:{...c,drivers:[...c.drivers||[],p]}:{drivers:[p]}})}}})}function ee(s){const{onWithdraw:r,partnerSlug:n,getSteamId:t}=k(),a=y.useQueryClient();return y.useMutation({mutationFn:i=>{if(!r)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||t();if(!o)throw new Error("No Steam ID available");return r(s,o)},onSuccess:()=>{const i=t();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(l=>l.steamId!==i)}:o)}})}function V(){const{onRegister:s,onWithdraw:r}=k(),n=!!(s&&r);return{isPowerMode:n,isBasicMode:!n}}function K(s){const{pitvoxUrl:r,partnerSlug:n}=k();return`${r}/p/${n}/competitions/${s}/register`}const Je={formula:"Formula",gt3:"GT3",gt2:"GT2",gt4:"GT4",cup:"Cup",prototype:"Prototype",rally:"Rally",hypercar:"Hypercar",supercar:"Supercar",sports_car:"Sports Car",hot_hatch:"Hot Hatch",lightweight:"Lightweight","1960s":"1960s","1970s":"1970s","1980s":"1980s","1990s":"1990s","2000s":"2000s","2010s":"2010s","2020s":"2020s"},ue=[{id:"class",tags:["formula","gt3","gt2","gt4","cup","prototype","rally"]},{id:"tier",tags:["hypercar","supercar","sports_car","hot_hatch","lightweight"]},{id:"era",tags:["1960s","1970s","1980s","1990s","2000s","2010s","2020s"]}];function Ye(s){for(const r of ue)if(r.tags.includes(s))return r.id;return"other"}function me(s,r){if(r.size===0)return!0;const n={};for(const t of r){const a=Ye(t);n[a]||(n[a]=[]),n[a].push(t)}for(const t of Object.values(n))if(!t.some(a=>s.includes(a)))return!1;return!0}function ve(s,r){const[n,t]=N.useState(new Set),a=s!==void 0,i=a?s:n,o=N.useCallback(p=>{const c=new Set(i);c.has(p)?c.delete(p):c.add(p),a&&r?r(c):t(c)},[i,a,r]),l=N.useCallback(()=>{a&&r?r(new Set):t(new Set)},[a,r]);return{activeTags:i,toggle:o,clear:l}}function H(s){const[r,n]=N.useState(s),t=N.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[r,t]}function Q(s,r,n){return[...s].sort((t,a)=>{const i=n(t,r.key),o=n(a,r.key);if(i==null&&o==null)return 0;if(i==null)return 1;if(o==null)return-1;const l=typeof i=="string"?i.localeCompare(o):i-o;return r.dir==="desc"?-l:l})}function he(s,r=!1){const n=r?s==null?void 0:s.filter(t=>t.isValid):s;return n!=null&&n.length?{s1:Math.min(...n.map(t=>t.sector1Ms).filter(Boolean)),s2:Math.min(...n.map(t=>t.sector2Ms).filter(Boolean)),s3:Math.min(...n.map(t=>t.sector3Ms).filter(Boolean))}:null}function Ze({active:s,dir:r}){return s?r==="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 L({label:s,sortKey:r,config:n,onSort:t,className:a=""}){return e.jsx("th",{className:`pvx-th pvx-th--sortable ${a}`,onClick:()=>t(r),children:e.jsxs("span",{className:"pvx-th-inner",children:[s,e.jsx(Ze,{active:n.key===r,dir:n.dir})]})})}function O({userId:s,getUserDisplay:r}){const{displayName:n,avatarUrl:t}=r(s);return e.jsxs("span",{className:"pvx-driver",children:[t?e.jsx("img",{src:t,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 se({rank:s,podium:r=!1}){const n=r?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 ge({availableTags:s,activeTags:r,onToggle:n,onClear:t}){if(!s||s.length<2)return null;const a=ue.map(i=>({id:i.id,tags:i.tags.filter(o=>s.includes(o))})).filter(i=>i.tags.length>0);return e.jsxs("div",{className:"pvx-tag-bar",children:[e.jsx("button",{onClick:t,className:`pvx-tag ${r.size===0?"pvx-tag--active":""}`,children:"All"}),a.map((i,o)=>e.jsxs("span",{className:"contents",children:[o>0&&e.jsx("span",{className:"pvx-tag-separator"}),i.tags.map(l=>e.jsx("button",{onClick:()=>n(l),className:`pvx-tag ${r.has(l)?"pvx-tag--active":""}`,children:Je[l]||l},l))]},i.id))]})}function re({segments:s}){return e.jsx("nav",{className:"pvx-breadcrumb","aria-label":"Breadcrumb",children:e.jsx("ol",{className:"pvx-breadcrumb-list",children:s.map((r,n)=>{const t=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"})}),!t&&r.onClick?e.jsx("button",{onClick:r.onClick,className:"pvx-breadcrumb-link",children:r.label}):e.jsx("span",{className:"pvx-breadcrumb-current",children:r.label})]},r.key)})})})}function U({message:s}){return e.jsxs("div",{className:"pvx-empty",children:[e.jsx("svg",{className:"pvx-empty-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.5 18.75h-9m9 0a3 3 0 013 3h-15a3 3 0 013-3m9 0v-4.5A3.375 3.375 0 0013.125 10.875h-2.25A3.375 3.375 0 007.5 14.25v4.5"})}),e.jsx("p",{children:s})]})}function A(){return e.jsx("div",{className:"pvx-loading",children:"Loading..."})}function Xe(){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 es(){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:r,carMetadata:n,getUserDisplay:t,onTrackSelect:a,tags:i,onTagChange:o}){const[l,p]=H({key:"record.timestamp",dir:"desc"}),{activeTags:c,toggle:u,clear:v}=ve(i,o),j=N.useMemo(()=>{var x;if(!((x=n==null?void 0:n.tags)!=null&&x.length))return[];const h=new Set;for(const g of s||[])g.recordByTag&&Object.keys(g.recordByTag).forEach(m=>h.add(m));return n.tags.filter(g=>h.has(g))},[s,n]),d=N.useMemo(()=>s?c.size===0?s:s.map(h=>{var m,b;if(!h.recordByTag)return null;let x=null;const g=new Set;for(const C of Object.values(h.recordByTag)){if(g.has(C.carId))continue;g.add(C.carId);const T=((b=(m=n==null?void 0:n.cars)==null?void 0:m[C.carId])==null?void 0:b.tags)||["sports_car"];me(T,c)&&(!x||C.lapTimeMs<x.lapTimeMs)&&(x=C)}return x?{...h,record:{visibleId:x.steamId||x.identifier,carId:x.carId,carDisplayName:S(x.carId),lapTimeMs:x.lapTimeMs,timestamp:x.recordedAt}}:null}).filter(Boolean):[],[s,c,n]),f=N.useMemo(()=>Q(d,l,(h,x)=>{var g,m;switch(x){case"displayName":return h.displayName;case"record.lapTimeMs":return(g=h.record)==null?void 0:g.lapTimeMs;case"driverCount":return h.driverCount||0;case"carCount":return h.carCount||0;case"record.timestamp":default:return(m=h.record)!=null&&m.timestamp?new Date(h.record.timestamp).getTime():0}}),[d,l]);return r?e.jsx(A,{}):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(ge,{availableTags:j,activeTags:c,onToggle:u,onClear:v}),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(L,{label:"Track",sortKey:"displayName",config:l,onSort:p}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Car"}),e.jsx(L,{label:"Lap Time",sortKey:"record.lapTimeMs",config:l,onSort:p}),e.jsx(L,{label:"Drivers",sortKey:"driverCount",config:l,onSort:p,className:"pvx-hidden-below-md"}),e.jsx(L,{label:"Cars",sortKey:"carCount",config:l,onSort:p,className:"pvx-hidden-below-lg"}),e.jsx(L,{label:"Date",sortKey:"record.timestamp",config:l,onSort:p,className:"pvx-hidden-below-xl"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:f.map(h=>{var x,g,m;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:(x=h.record)!=null&&x.visibleId?e.jsx(O,{userId:h.record.visibleId,getUserDisplay:t}):"-"}),e.jsx("td",{className:"pvx-td pvx-hidden-below-lg",children:((g=h.record)==null?void 0:g.carDisplayName)||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:h.record?$(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:(m=h.record)!=null&&m.timestamp?P(h.record.timestamp):"-"})]},`${h.id}|${h.layout||""}`)})})]})})]}):e.jsx(U,{message:"No lap times recorded yet."})}function rs({entries:s,isLoading:r,track:n,carMetadata:t,getUserDisplay:a,onCarSelect:i,onNavigate:o,tags:l,onTagChange:p}){const[c,u]=H({key:"lapTimeMs",dir:"asc"}),{activeTags:v,toggle:j,clear:d}=ve(l,p),f=N.useMemo(()=>{var b,C,T;if(!s||!((b=t==null?void 0:t.tags)!=null&&b.length))return[];const m=new Set;for(const R of s)(((T=(C=t.cars)==null?void 0:C[R.carId])==null?void 0:T.tags)||["sports_car"]).forEach(Fe=>m.add(Fe));return t.tags.filter(R=>m.has(R))},[s,t]),h=N.useMemo(()=>s?v.size===0?s:s.filter(m=>{var C,T;const b=((T=(C=t==null?void 0:t.cars)==null?void 0:C[m.carId])==null?void 0:T.tags)||["sports_car"];return me(b,v)}):[],[s,v,t]),x=N.useMemo(()=>Q(h,c,(m,b)=>{switch(b){case"carId":return S(m.carId);case"driverCount":return m.driverCount||0;case"lapTimeMs":default:return m.lapTimeMs}}),[h,c]),g=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:n.displayName}];return r?e.jsx(A,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(re,{segments:g})}),e.jsx(ge,{availableTags:f,activeTags:v,onToggle:j,onClear:d}),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(L,{label:"Car",sortKey:"carId",config:c,onSort:u}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx(L,{label:"Lap Time",sortKey:"lapTimeMs",config:c,onSort:u}),e.jsx(L,{label:"Drivers",sortKey:"driverCount",config:c,onSort:u,className:"pvx-hidden-below-md"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:x.map((m,b)=>e.jsxs("tr",{className:"pvx-row pvx-row--clickable",onClick:()=>i(m.carId),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(se,{rank:b+1,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:S(m.carId)}),e.jsx("td",{className:"pvx-td",children:e.jsx(O,{userId:m.steamId||m.userId,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:$(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?P(m.recordedAt):"-"})]},m.carId))})]})}):e.jsx(U,{message:"No lap times for this track yet."})]})}function ts({entries:s,isLoading:r,track:n,carId:t,getUserDisplay:a,onDriverSelect:i,onNavigate:o,highlightId:l}){const[p,c]=H({key:"lapTimeMs",dir:"asc"}),u=N.useMemo(()=>he(s),[s]),v=N.useMemo(()=>Q(s||[],p,(d,f)=>{switch(f){case"userId":return a(d.steamId||d.userId).displayName;case"lapCount":return d.lapCount||0;case"lapTimeMs":default:return d.lapTimeMs}}),[s,p,a]),j=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:n.displayName,onClick:()=>o("track")},{key:"car",label:S(t)}];return r?e.jsx(A,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(re,{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(L,{label:"Driver",sortKey:"userId",config:p,onSort:c}),e.jsx(L,{label:"Lap Time",sortKey:"lapTimeMs",config:p,onSort:c}),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(L,{label:"Laps",sortKey:"lapCount",config:p,onSort:c,className:"pvx-hidden-below-lg"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:v.map((d,f)=>{const h=f+1,x=d.steamId||d.userId,g=u&&d.sector1Ms===u.s1,m=u&&d.sector2Ms===u.s2,b=u&&d.sector3Ms===u.s3,C=l&&x===l;return e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${C?"pvx-row--highlight":h<=3?"pvx-row--podium":""}`,onClick:()=>i(x),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(se,{rank:h,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(O,{userId:x,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:$(d.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${g?"pvx-td--best-sector":""}`,children:M(d.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${m?"pvx-td--best-sector":""}`,children:M(d.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${b?"pvx-td--best-sector":""}`,children:M(d.sector3Ms)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:J(d.tyreCompound),children:d.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-xl",children:d.startingFuelL?`${d.startingFuelL}L`:"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:d.lapCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:d.recordedAt?P(d.recordedAt):"-"})]},x)})})]})}):e.jsx(U,{message:"No lap times for this car yet."})]})}function ns({userId:s,track:r,carId:n,game:t,gameVersion:a,showInvalid:i,getUserDisplay:o,onToggleInvalid:l,onNavigate:p}){const{data:c,driverName:u,isLoading:v}=le(s,r.id,r.layout,n,{showInvalid:i,game:t,gameVersion:a}),{displayName:j,avatarUrl:d}=o(s,u),f=N.useMemo(()=>he(c,!0),[c]),h=N.useMemo(()=>{const g=(c==null?void 0:c.filter(m=>m.isValid))||[];return g.length?Math.min(...g.map(m=>m.lapTimeMs)):null},[c]),x=[{key:"tracks",label:"Tracks",onClick:()=>p("tracks")},{key:"track",label:r.displayName,onClick:()=>p("track")},{key:"car",label:S(n),onClick:()=>p("car")},{key:"driver",label:j}];return v?e.jsx(A,{}):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(re,{segments:x}),d?e.jsx("img",{src:d,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:l,className:"pvx-checkbox"}),e.jsx("span",{children:"Show invalid laps"})]})]}),c!=null&&c.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:c.map((g,m)=>{const b=g.isValid&&g.lapTimeMs===h,C=f&&g.isValid&&g.sector1Ms===f.s1,T=f&&g.isValid&&g.sector2Ms===f.s2,R=f&&g.isValid&&g.sector3Ms===f.s3;let E="pvx-row";return g.isValid||(E+=" pvx-row--invalid"),b&&(E+=" pvx-row--personal-best"),e.jsxs("tr",{className:E,children:[e.jsx("td",{className:"pvx-td",children:e.jsx("span",{className:`pvx-rank ${b?"pvx-rank--gold":""}`,children:m+1})}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-md",children:g.lapNumber||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:$(g.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${C?"pvx-td--best-sector":""}`,children:M(g.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${T?"pvx-td--best-sector":""}`,children:M(g.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${R?"pvx-td--best-sector":""}`,children:M(g.sector3Ms)}),e.jsx("td",{className:"pvx-td",title:g.isValid?void 0:g.invalidReason||"Invalid",children:g.isValid?e.jsx(Xe,{}):e.jsx(es,{})}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:J(g.tyreCompound),children:g.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:g.startingFuelL?`${g.startingFuelL}L`:"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:P(g.timestamp)})]},g.id)})})]})}):e.jsx(U,{message:i?"No laps recorded for this combination.":'No valid laps. Try enabling "Show invalid laps".'})]})}function as({drivers:s,isLoading:r,getUserDisplay:n,game:t,gameVersion:a,onComboSelect:i}){const[o,l]=H({key:"rank",dir:"asc"}),[p,c]=N.useState(null),u=N.useMemo(()=>s?Q(s,o,(j,d)=>{switch(d){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(r)return e.jsx(A,{});if(!(s!=null&&s.length))return e.jsx("div",{className:"pvx-card",children:e.jsx(U,{message:"Not enough data for rankings yet."})});const v=5;return e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header pvx-rankings-header",children:[e.jsx("h2",{className:"pvx-card-title",children:"Driver Rankings"}),e.jsxs("div",{className:"pvx-rankings-info-trigger",children:[e.jsx("svg",{className:"pvx-rankings-info-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"})}),e.jsxs("div",{className:"pvx-rankings-info-tooltip",children:[e.jsx("p",{className:"pvx-rankings-info-title",children:"How ratings work"}),e.jsxs("ul",{className:"pvx-rankings-info-list",children:[e.jsx("li",{children:"For each car/track combo with 3+ drivers, you're ranked by lap time and given a percentile (100 = fastest, 0 = slowest)"}),e.jsx("li",{children:"Your rating is a weighted average across all your combos — bigger fields count more"}),e.jsx("li",{children:"A confidence adjustment rewards car diversity: the more different cars you drive competitively, the closer your rating reflects your true score"}),e.jsx("li",{children:"Minimum 2 qualifying combos required"})]})]})]})]}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx(L,{label:"#",sortKey:"rank",config:o,onSort:l,className:"pvx-th--narrow"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx(L,{label:"Rating",sortKey:"rating",config:o,onSort:l}),e.jsx(L,{label:"Cars",sortKey:"distinctCars",config:o,onSort:l,className:"pvx-hidden-below-sm"}),e.jsx(L,{label:"Combos",sortKey:"comboCount",config:o,onSort:l,className:"pvx-hidden-below-sm"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:u.map(j=>{const d=p===j.identifier;return e.jsx(is,{driver:j,getUserDisplay:n,isExpanded:d,onToggle:()=>c(d?null:j.identifier),colCount:v,game:t,gameVersion:a,onComboSelect:i},j.identifier)})})]})})]})}function is({driver:s,getUserDisplay:r,isExpanded:n,onToggle:t,colCount:a,game:i,gameVersion:o,onComboSelect:l}){const p=s.identifier;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${s.rank<=3?"pvx-row--podium":""}`,onClick:t,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(se,{rank:s.rank,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(O,{userId:p,getUserDisplay:r})}),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((c,u)=>{const v=c.layout?`${c.trackId}|${c.layout}`:c.trackId,j=l?()=>l({track:v,car:c.carId,highlight:p,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:I(c.trackId,c.layout,i)}),e.jsx("p",{className:"pvx-rankings-combo-car",children:S(c.carId)})]}),e.jsxs("div",{className:"pvx-rankings-combo-stats",children:[e.jsx("p",{className:"pvx-rankings-combo-time",children:$(c.lapTimeMs)}),e.jsxs("p",{className:`pvx-rankings-combo-pct ${c.percentile>=75?"pvx-rankings-combo-pct--high":c.percentile>=50?"pvx-rankings-combo-pct--mid":c.percentile>=25?"pvx-rankings-combo-pct--low":"pvx-rankings-combo-pct--bottom"}`,children:[c.percentile.toFixed(0),"%",e.jsxs("span",{className:"pvx-rankings-combo-rank",children:["(",c.rank,"/",c.totalDrivers,")"]})]})]})]},u)})})})})]})}const os={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:"🇰🇷"},je=["🥇","🥈","🥉"],cs={championship:"Championship",series:"Series",event:"Event"},te=["PRACTICE","QUALIFYING","RACE"];function fe({position:s}){const r=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:r,children:s})}function Ne({nation:s}){const r=s&&os[s];return r?e.jsx("span",{className:"pvx-nation-flag",title:s,children:r}):null}function ls({sessions:s,activeSession:r,onSelect:n}){if(!s||s.length<=1)return null;const t=[...s].sort((a,i)=>te.indexOf(a.type)-te.indexOf(i.type));return e.jsx("div",{className:"pvx-session-tabs",children:t.map(a=>e.jsx("button",{onClick:()=>n(a.type),className:`pvx-session-tab ${r===a.type?"pvx-session-tab--active":""}`,children:a.type},a.type))})}function be({type:s}){return e.jsx("span",{className:`pvx-comp-badge pvx-comp-badge--${s}`,children:cs[s]||s})}function F({children:s,variant:r="default"}){return e.jsx("span",{className:`pvx-info-pill ${r!=="default"?`pvx-info-pill--${r}`:""}`,children:s})}function ds(s){if(!s)return"TBD";const r=new Date(s);if(isNaN(r))return"TBD";const n=r.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),t=r.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return`${n} • ${t}`}function ps(s){return s.reduce((r,n)=>{var t;return(t=n.splits)!=null&&t.length?r?r.map((a,i)=>{const o=n.splits[i];return o&&o<a?o:a}):[...n.splits]:r},null)}function B({message:s="Loading..."}){return e.jsx("div",{className:"pvx-loading",children:s})}function D({message:s="No data available."}){return e.jsx("div",{className:"pvx-empty",children:e.jsx("p",{children:s})})}function xs({competitions:s,isLoading:r,onSelect:n,onRegister:t,className:a}){return r?e.jsx(B,{message:"Loading competitions..."}):s!=null&&s.length?e.jsx("div",{className:`pvx-comp-grid ${a||""}`,children:s.map(i=>e.jsx(ye,{comp:i,onSelect:n,onRegister:t||n},i.id))}):e.jsx(D,{message:"No competitions available."})}function ye({comp:s,onSelect:r,onRegister:n}){var h,x,g;const{cdnUrl:t}=k(),a=s.posterCdnPath?`${t}/${s.posterCdnPath}`:null,i=s.registration,o=(i==null?void 0:i.currentCount)||0,l=i==null?void 0:i.maxParticipants,p=l&&o>=l,c=(i==null?void 0:i.deadline)&&new Date(i.deadline)<new Date,u=(i==null?void 0:i.isOpen)&&!c&&!p,v=new Date,j=(h=s.rounds)==null?void 0:h.find(m=>m.startTime&&new Date(m.startTime)>=v),d=((x=s.rounds)==null?void 0:x.length)||0,f=((g=s.rounds)==null?void 0:g.filter(m=>m.isFinalized).length)||0;return e.jsxs("div",{className:"pvx-comp-card",onClick:()=>r(s.id),role:"button",tabIndex:0,onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),r(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(ms,{})})}),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(be,{type:s.type}),s.game&&e.jsx(F,{children:s.game.toUpperCase()}),s.formatDescription&&s.formatDescription.split(", ").map((m,b)=>e.jsx(F,{variant:"format",children:m},b))]}),s.carsDescription&&e.jsx("div",{className:"pvx-comp-card-pills",children:s.carsDescription.split(", ").map((m,b)=>e.jsx(F,{children:m},b))}),e.jsxs("div",{className:"pvx-comp-card-schedule",children:[j?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[e.jsx("span",{className:"pvx-comp-card-schedule-label",children:"Next:"})," ","R",j.roundNumber," ",j.track||"TBD"," — ",ds(j.startTime)]}):d>0?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[f,"/",d," rounds completed"]}):null,d>0&&e.jsxs("span",{className:"pvx-comp-card-round-count",children:[d," round",d!==1?"s":""]})]}),i&&e.jsx(us,{competitionId:s.id,regOpen:u,isFull:p,deadlinePassed:c,regCount:o,regMax:l,onRegister:n})]})]})}function us({competitionId:s,regOpen:r,isFull:n,deadlinePassed:t,regCount:a,regMax:i,onRegister:o}){const{isPowerMode:l}=V(),p=K(s),{data:c}=_(s),u=(c==null?void 0:c.isRegistered)||!1,v=i?a/i*100:0,j=v>=100?"full":v>=75?"warning":"ok";return e.jsxs("div",{className:"pvx-comp-card-reg",children:[e.jsx("div",{className:"pvx-comp-card-reg-info",children:e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${j}`,children:[a,"/",i||"∞"," drivers"]})}),e.jsx("div",{className:"pvx-comp-card-reg-action",children:u?e.jsx("button",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--registered",onClick:d=>{d.stopPropagation(),o(s)},children:"✓ Registered"}):r?l?e.jsx("button",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--open",onClick:d=>{d.stopPropagation(),o(s)},children:"Register"}):e.jsx("a",{href:p,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--open",onClick:d=>d.stopPropagation(),children:"Register"}):e.jsx("span",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--closed",children:n?"Full":"Closed"})})]})}function ms(){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 vs({competitionId:s,className:r}){var l,p;const{data:n,isLoading:t}=pe(s),{data:a,isLoading:i}=de(s);if(t||i)return e.jsx(B,{message:"Loading standings..."});if(!((l=n==null?void 0:n.standings)!=null&&l.length))return e.jsx(D,{message:"No standings data yet. Results will appear once rounds are finalised."});const o=((p=a==null?void 0:a.rounds)==null?void 0:p.filter(c=>c.isFinalized))||[];return e.jsxs("div",{className:`pvx-card ${r||""}`,children:[e.jsx("div",{className:"pvx-card-header--split",children:e.jsxs("div",{className:"pvx-card-header-left",children:[e.jsx("h3",{className:"pvx-card-title",children:"Championship Standings"}),e.jsxs("span",{className:"pvx-standings-subtitle",children:["After ",n.roundsCompleted," round",n.roundsCompleted!==1?"s":"",n.countingRounds>0&&` (best ${n.countingRounds} count)`]})]})}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"W"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"Pod"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"}),o.map(c=>e.jsxs("th",{className:"pvx-th pvx-th--center pvx-hidden-below-md",title:c.track||`Round ${c.roundNumber}`,children:["R",c.roundNumber]},c.roundNumber))]})}),e.jsx("tbody",{className:"pvx-tbody",children:n.standings.map(c=>e.jsx(hs,{driver:c,finalizedRounds:o},c.driverId||c.driverName))})]})})]})}function hs({driver:s,finalizedRounds:r}){var o,l,p;const n=s.position<=3,t=new Map(((o=s.roundResults)==null?void 0:o.map(c=>[c.roundNumber,c]))||[]),a=((l=s.roundResults)==null?void 0:l.filter(c=>c.position===1).length)||0,i=((p=s.roundResults)==null?void 0:p.filter(c=>c.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(fe,{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}),r.map(c=>{const u=t.get(c.roundNumber),v=u==null?void 0:u.dropped;return e.jsx("td",{className:`pvx-td pvx-td--center pvx-hidden-below-md ${!v&&(u==null?void 0:u.position)<=3?"pvx-standings-cell--podium":""}`,children:u?e.jsxs("div",{className:`pvx-standings-round-cell ${v?"pvx-standings-round-cell--dropped":""}`,children:[e.jsxs("span",{className:"pvx-standings-round-pos",children:["P",u.position]}),e.jsx("span",{className:"pvx-standings-round-pts",children:u.points})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})},c.roundNumber)})]})}function gs({competitionId:s,roundNumber:r,className:n}){var p;const{data:t,isLoading:a}=xe(s,r);if(a)return e.jsx(B,{message:"Loading results..."});if(!t)return e.jsx(D,{message:"No results for this round."});const o=(t.sessions||[]).find(c=>c.type==="RACE"),l=(p=o==null?void 0:o.results)==null?void 0:p.filter(c=>c.position<=3).sort((c,u)=>c.position-u.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 ",t.roundNumber,t.track?`: ${t.track}`:""]}),t.startTime&&e.jsx("p",{className:"pvx-round-results-date",children:new Date(t.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(l==null?void 0:l.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:l.map(c=>e.jsxs("span",{className:"pvx-round-podium-item",children:[e.jsx("span",{children:je[c.position-1]}),e.jsx("span",{children:c.driverName})]},c.driverId))})]}),e.jsx(ke,{round:t})]})}function ke({round:s,className:r}){var l,p;const[n,t]=N.useState(null),a=(s==null?void 0:s.sessions)||[];if(!a.length)return e.jsx(D,{message:"No session data for this round."});const i=n||((l=a.find(c=>c.type==="RACE"))==null?void 0:l.type)||((p=a[0])==null?void 0:p.type),o=a.find(c=>c.type===i)||a[0];return e.jsxs("div",{className:r||"",children:[e.jsx(ls,{sessions:a,activeSession:i,onSelect:t}),e.jsx(js,{session:o})]})}function js({session:s}){var t;const r=s.type==="RACE";if(!((t=s.results)!=null&&t.length))return e.jsx(D,{message:`No results for ${s.type}.`});const n=ps(s.results);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"}),r&&e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Laps"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Time / Gap"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"})]})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.results.map((a,i)=>e.jsx(fs,{result:a,isRace:r,fastestSplits:n,rowIndex:i},a.driverId||i))})]})})}function fs({result:s,isRace:r,fastestSplits:n,rowIndex:t}){const a=s.position<=3;return e.jsxs("tr",{className:`pvx-row ${a?"pvx-row--podium":""}`,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(fe,{position:s.position})}),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:S(s.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx(Ns,{bestLap:s.bestLapFormatted,hasBestLap:s.hasBestLap,splits:s.splits,fastestSplits:n,showAbove:t<=1})}),r&&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,")"]})]})]})]})}function Ns({bestLap:s,hasBestLap:r,splits:n,fastestSplits:t,showAbove:a}){return s?e.jsxs("span",{className:`pvx-best-lap-cell ${r?"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 l=t&&i===t[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:l?"pvx-splits-tooltip-best":"",children:i})]},o)})})})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})}function bs({competitionId:s,className:r}){const{getSteamId:n}=k(),{data:t,isLoading:a}=Z(s),i=n();if(a)return e.jsx(B,{message:"Loading drivers..."});const o=(t==null?void 0:t.drivers)||(t==null?void 0:t.entries)||[];return o.length?e.jsx("div",{className:`pvx-entry-grid ${r||""}`,children:o.map(l=>{var c,u;const p=i&&l.steamId===i;return e.jsxs("div",{className:`pvx-entry-card ${p?"pvx-entry-card--you":""}`,children:[l.avatarUrl?e.jsx("img",{src:l.avatarUrl,alt:"",className:"pvx-entry-avatar"}):e.jsx("div",{className:"pvx-entry-avatar pvx-entry-avatar--placeholder",children:((u=(c=l.displayName)==null?void 0:c.charAt(0))==null?void 0:u.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-entry-name",children:[l.displayName,p&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},l.steamId||l.driverId)})}):e.jsx(D,{message:"No drivers registered yet."})}function ys({competitionId:s,driverData:r,className:n,children:t}){const{data:a,isLoading:i}=_(s),{isPowerMode:o}=V(),l=K(s),p=X(s),c=ee(s),u=(a==null?void 0:a.isRegistered)||!1,v=i||p.isPending||c.isPending,j=p.error||c.error||null,d=()=>{o&&p.mutate(r||{})},f=()=>{o&&c.mutate()};return typeof t=="function"?t({isRegistered:u,isLoading:v,register:d,withdraw:f,error:j,isPowerMode:o,registrationUrl:l}):o?e.jsx("button",{className:`pvx-comp-register-btn ${n||""}`,onClick:u?f:d,disabled:v,children:v?"Loading...":u?"Withdraw":"Register"}):e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:`pvx-comp-register-link ${n||""}`,children:u?"View Registration":"Register on PitVox"})}function ks({competitionId:s,registration:r,onWithdrawSuccess:n,className:t}){const{getSteamId:a}=k(),{isPowerMode:i}=V(),o=K(s),{data:l,isLoading:p}=_(s),{data:c,isLoading:u}=Z(s),v=X(s),j=ee(s),d=a(),f=(l==null?void 0:l.isRegistered)||!1,h=(c==null?void 0:c.drivers)||(c==null?void 0:c.entries)||[],x=r||{},g=h.length||x.currentCount||0,m=x.maxParticipants&&g>=x.maxParticipants,b=x.deadline&&new Date(x.deadline)<new Date,C=x.isOpen&&!b&&!m;return p||u?e.jsx(B,{message:"Loading registration..."}):f?e.jsx("div",{className:`pvx-reg-panel ${t||""}`,children:e.jsx(ws,{competitionId:s,drivers:h,steamId:d,isPowerMode:i,registrationUrl:o,withdrawMutation:j,onWithdrawSuccess:n,registration:x})}):C?d?i?e.jsx("div",{className:`pvx-reg-panel ${t||""}`,children:e.jsx(Cs,{competitionId:s,registerMutation:v,registration:x})}):e.jsx("div",{className:`pvx-reg-panel ${t||""}`,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 ${t||""}`,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 ${t||""}`,children:[e.jsx("div",{className:"pvx-reg-status-msg",children:m?"Registration is full.":b?"Registration deadline has passed.":"Registration is closed."}),h.length>0&&e.jsx(Ce,{drivers:h,steamId:d})]})}function Cs({competitionId:s,registerMutation:r,registration:n}){const[t,a]=N.useState(""),[i,o]=N.useState("intermediate"),[l,p]=N.useState(""),c=d=>{d.preventDefault(),r.mutate({discordUsername:t||void 0,experience:i,comments:l||void 0})},u=n||{},v=u.currentCount||0,j=u.maxParticipants;return e.jsxs("form",{className:"pvx-reg-form",onSubmit:c,children:[e.jsxs("div",{className:"pvx-reg-form-header",children:[e.jsx("h3",{className:"pvx-reg-form-title",children:"Register"}),j&&e.jsx(we,{count:v,max:j})]}),r.error&&e.jsx("div",{className:"pvx-reg-error",children:r.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:t,onChange:d=>a(d.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:d=>o(d.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:l,onChange:d=>p(d.target.value)})]}),e.jsx("div",{className:"pvx-reg-actions",children:e.jsx("button",{type:"submit",className:"pvx-comp-register-btn",disabled:r.isPending,children:r.isPending?"Registering...":"Register"})})]})}function ws({competitionId:s,drivers:r,steamId:n,isPowerMode:t,registrationUrl:a,withdrawMutation:i,onWithdrawSuccess:o,registration:l}){const[p,c]=N.useState(!1),u=()=>{i.mutate(void 0,{onSuccess:()=>{c(!1),o&&o()}})},v=l||{},j=r.length||v.currentCount||0,d=v.maxParticipants;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pvx-reg-form-header",children:[e.jsx("h3",{className:"pvx-reg-form-title",children:"Registered Drivers"}),d&&e.jsx(we,{count:j,max:d})]}),e.jsx(Ce,{drivers:r,steamId:n}),i.error&&e.jsx("div",{className:"pvx-reg-error",children:i.error.message||"Withdrawal failed"}),t?e.jsx("div",{className:"pvx-reg-actions",children:p?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:()=>c(!1),children:"Cancel"}),e.jsx("button",{type:"button",className:"pvx-reg-danger-btn",onClick:u,disabled:i.isPending,children:i.isPending?"Unregistering...":"Yes, Unregister"})]})]}):e.jsx("button",{type:"button",className:"pvx-reg-unregister-btn",onClick:()=>c(!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 Ce({drivers:s,steamId:r}){if(!s.length)return e.jsx("div",{className:"pvx-reg-no-drivers",children:"No drivers registered yet."});const n=[...s].sort((t,a)=>{const i=r&&t.steamId===r?-1:0,o=r&&a.steamId===r?-1:0;return i-o});return e.jsx("div",{className:"pvx-reg-driver-list",children:n.map(t=>{var i,o;const a=r&&t.steamId===r;return e.jsxs("div",{className:`pvx-reg-driver-row ${a?"pvx-reg-driver-row--you":""}`,children:[t.avatarUrl?e.jsx("img",{src:t.avatarUrl,alt:"",className:"pvx-reg-driver-avatar"}):e.jsx("div",{className:"pvx-reg-driver-avatar pvx-reg-driver-avatar--placeholder",children:((o=(i=t.displayName)==null?void 0:i.charAt(0))==null?void 0:o.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-reg-driver-name",children:[t.displayName,a&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},t.steamId||t.driverId)})})}function we({count:s,max:r}){const n=r?s/r*100:0,t=n>=100?"full":n>=75?"warning":"ok";return e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${t}`,children:[s,"/",r," drivers"]})}function Le(s){const{cdnUrl:r}=k(),n=y.useQuery({queryKey:["pitvox","laps","global",s],queryFn:()=>w(r,`laps/${s}.json`),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),t=n.data;return{isLoading:n.isLoading,error:n.error,data:t?{driverName:t.driverName||"Driver",lapCount:t.lapCount||0,trackBreakdown:t.trackBreakdown||[],carBreakdown:t.carBreakdown||[],recordsHeld:t.recordsHeld||0,currentRecords:t.currentRecords||[],bestRanking:t.bestRanking??null,bestRankingTrackId:t.bestRankingTrackId??null,bestRankingLayout:t.bestRankingLayout??null,bestRankingCarId:t.bestRankingCarId??null,generatedAt:t.generatedAt}:null}}function Re(s={}){const{cdnUrl:r,partnerSlug:n}=k(),{gameVersion:t,enabled:a=!0}=s,i=t?`v/${t}/`:"",o=q(n,`${i}ratings.json`);return y.useQuery({queryKey:["pitvox","ratings",n,t||null],queryFn:()=>w(r,o),staleTime:3e4,refetchInterval:3e4,enabled:a})}function Se(s){var t;const r=Re(),n=N.useMemo(()=>{var a;return!((a=r.data)!=null&&a.drivers)||!s?null:r.data.drivers.find(i=>i.identifier===s)||null},[(t=r.data)==null?void 0:t.drivers,s]);return{isLoading:r.isLoading,error:r.error,data:n?{rating:n.rating,rank:n.rank,totalDrivers:r.data.driverCount||r.data.drivers.length,comboCount:n.comboCount||0,distinctCars:n.distinctCars||0,combos:n.combos||[]}:null}}function Ls(s={}){const r=Re(s);return{data:r.data||null,isLoading:r.isLoading,error:r.error}}function Te(){const{cdnUrl:s,partnerSlug:r,getSteamId:n,onFetchServerPassword:t}=k(),a=n(),{data:i,isLoading:o}=y.useQuery({queryKey:["pitvox","competitions",r],queryFn:async()=>{const d=await w(s,"competitions/index.json");return d!=null&&d.competitions?d.competitions.filter(f=>f.partnerSlug===r):[]},staleTime:6e4}),l=(i==null?void 0:i.map(d=>d.id))||[],p=y.useQueries({queries:l.map(d=>({queryKey:["pitvox","competition",r,d,"entrylist"],queryFn:()=>w(s,`competitions/${r}/${d}/entrylist.json`),enabled:!!a&&l.length>0,staleTime:6e4}))}),c=p.some(d=>d.isLoading),u=N.useMemo(()=>{var h,x;if(!i||!a||c)return[];const d=new Date,f=[];for(let g=0;g<i.length;g++){const m=i[g],b=(h=p[g])==null?void 0:h.data;if(!((x=b==null?void 0:b.drivers)==null?void 0:x.some(R=>R.steamId===a)))continue;const T=m.rounds||[];for(const R of T)R.isFinalized||!R.startTime||new Date(R.startTime)<=d||f.push({competitionId:m.id,competitionName:m.name,roundNumber:R.roundNumber,track:R.track||"TBD",startTime:R.startTime})}return f.sort((g,m)=>new Date(g.startTime)-new Date(m.startTime)),f.length>0&&(f[0].isNext=!0),f},[i,a,c,p]),v=y.useQueries({queries:u.map(d=>({queryKey:["pitvox","serverInfo",d.competitionId,d.roundNumber],queryFn:()=>t(d.competitionId,d.roundNumber),enabled:!!t&&u.length>0,staleTime:5*6e4,retry:!1}))});return{data:N.useMemo(()=>u.length?t?u.map((d,f)=>{var x;const h=(x=v[f])==null?void 0:x.data;return h!=null&&h.success?{...d,serverAddress:h.serverAddress||null,serverPassword:h.serverPassword||null}:d}):u:[],[u,t,v]),isLoading:o||!!a&&c}}function Me(){const{onFetchNotifications:s}=k();return!!s}function $e(s={}){const{onFetchNotifications:r,partnerSlug:n}=k(),{limit:t=20,unreadOnly:a=!1}=s;return y.useQuery({queryKey:["pitvox","notifications",n,{limit:t,unreadOnly:a}],queryFn:()=>r({limit:t,unreadOnly:a}),enabled:!!r,staleTime:3e4,refetchInterval:3e4})}function Rs(){const{onFetchNotifications:s,partnerSlug:r}=k(),{data:n,isLoading:t}=y.useQuery({queryKey:["pitvox","notifications",r,{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:t}}function De(){const{onMarkNotificationRead:s,partnerSlug:r}=k(),n=y.useQueryClient();return y.useMutation({mutationFn:t=>{if(!s)throw new Error("No onMarkNotificationRead callback provided to PitVoxPartnerProvider.");return s(t)},onSuccess:(t,a)=>{n.setQueriesData({queryKey:["pitvox","notifications",r]},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 Ie(){const{onMarkAllNotificationsRead:s,partnerSlug:r}=k(),n=y.useQueryClient();return y.useMutation({mutationFn:()=>{if(!s)throw new Error("No onMarkAllNotificationsRead callback provided to PitVoxPartnerProvider.");return s()},onSuccess:()=>{n.setQueriesData({queryKey:["pitvox","notifications",r]},t=>t!=null&&t.notifications?{...t,unreadCount:0,notifications:t.notifications.map(a=>({...a,isRead:!0,readAt:a.readAt||new Date().toISOString()}))}:t)}})}function Pe({driverName:s,avatarUrl:r,memberSince:n,className:t=""}){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 ${t}`,children:[r?e.jsx("img",{src:r,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 Ss(){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 Ts(){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 Ms(){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 ne({icon:s,value:r,label:n,items:t,labelKey:a,countKey:i}){const[o,l]=N.useState(!1),p=N.useRef(null);N.useEffect(()=>{if(!o)return;function u(v){p.current&&!p.current.contains(v.target)&&l(!1)}return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[o]);const c=t!=null&&t.length?t.slice().sort((u,v)=>v[i]-u[i]):null;return e.jsxs("div",{ref:p,className:`pvx-dash-stat-card ${c?"pvx-dash-stat-card--clickable":""}`,onClick:c?()=>l(u=>!u):void 0,children:[s,e.jsxs("div",{className:"pvx-dash-stat-content",children:[e.jsx("span",{className:"pvx-dash-stat-value",children:r}),e.jsx("span",{className:"pvx-dash-stat-label",children:n})]}),c&&e.jsx("div",{className:`pvx-dash-tooltip pvx-dash-tooltip--scrollable ${o?"pvx-dash-tooltip--open":""}`,children:c.map((u,v)=>e.jsxs("div",{className:"pvx-dash-tooltip-row",children:[e.jsx("span",{className:"pvx-dash-tooltip-label",children:u[a]}),e.jsx("span",{className:"pvx-dash-tooltip-value",children:u[i]})]},v))})]})}function Be({stats:s,rating:r,className:n=""}){if(!s)return null;const t=s.trackBreakdown.map(i=>({name:I(i.trackId,i.layout),lapCount:i.lapCount})),a=s.carBreakdown.map(i=>({name:S(i.carId),lapCount:i.lapCount}));return e.jsxs("div",{className:`pvx-dash-stats ${n}`,children:[e.jsx(ne,{icon:e.jsx(Ss,{}),value:s.lapCount.toLocaleString(),label:"Total Laps",items:t,labelKey:"name",countKey:"lapCount"}),e.jsx(ne,{icon:e.jsx(Ts,{}),value:s.carBreakdown.length,label:"Cars Used",items:a,labelKey:"name",countKey:"lapCount"}),r&&e.jsxs("div",{className:"pvx-dash-stat-card pvx-dash-stat-card--rating",children:[e.jsx(Ms,{}),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]})]})]})]})}function Ue({records:s,className:r=""}){const n=N.useMemo(()=>s!=null&&s.length?s.slice().sort((t,a)=>{const i=t.recordedAt?new Date(t.recordedAt).getTime():0;return(a.recordedAt?new Date(a.recordedAt).getTime():0)-i}):[],[s]);return n.length?e.jsxs("div",{className:`pvx-card ${r}`,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((t,a)=>e.jsxs("div",{className:"pvx-dash-record-row",children:[e.jsxs("div",{className:"pvx-dash-record-info",children:[e.jsx("span",{className:"pvx-dash-record-track",children:I(t.trackId,t.layout,t.game)}),e.jsx("span",{className:"pvx-dash-record-car",children:S(t.carId)})]}),e.jsxs("div",{className:"pvx-dash-record-time",children:[e.jsx("span",{className:"pvx-dash-record-lap",children:$(t.lapTimeMs)}),e.jsxs("span",{className:`pvx-dash-game-badge pvx-dash-game-badge--${t.game||"evo"}`,children:[(t.game||"evo").toUpperCase(),t.gameVersion?` ${t.gameVersion}`:""]})]})]},a))})]}):null}function Ae({events:s,isLoading:r,className:n,limit:t=3}){if(r)return e.jsx("div",{className:"pvx-loading",children:"Loading upcoming events..."});if(!(s!=null&&s.length))return null;const a=t?s.slice(0,t):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(Is,{}),"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($s,{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:Ds(o.startTime)}),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 $s({password:s,address:r}){const[n,t]=N.useState(!1),[a,i]=N.useState(!1),o=r?s?`join:${r}|${s}`:`join:${r}`:null,l=N.useCallback(async()=>{if(o)try{await navigator.clipboard.writeText(o),t(!0),setTimeout(()=>t(!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:l,title:"Copy join string to clipboard",children:[e.jsx(Bs,{})," ",n?"Copied!":"Join"]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick:()=>i(p=>!p),title:a?"Hide password":"Reveal password",children:a?e.jsx(As,{}):e.jsx(Us,{})}),a&&e.jsxs("span",{className:"pvx-server-detail",children:[e.jsx(Ps,{})," ",s]})]})]})}function Ds(s){const r=new Date(s).getTime()-Date.now();if(r<=0)return"Now";const n=Math.floor(r/(1e3*60*60));if(n<1)return"Less than 1 hour";if(n<24)return`in ${n}h`;const t=Math.floor(n/24);if(t===1)return"Tomorrow";if(t<7)return`in ${t} days`;if(t<30){const a=Math.floor(t/7);return`in ${a} week${a!==1?"s":""}`}return z(s)}function Is(){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 Ps(){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 Bs(){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 Us(){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 As(){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 Ee({notifications:s,unreadCount:r=0,onMarkRead:n,onMarkAllRead:t,isLoading:a,className:i}){const o=Y();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(qs,{}),"Notifications",r>0&&e.jsx("span",{className:"pvx-notif-badge",children:r>99?"99+":r})]}),r>0&&t&&e.jsx("button",{className:"pvx-notif-mark-all",onClick:t,children:"Mark all read"})]}),s!=null&&s.length?e.jsx("div",{className:"pvx-notif-list",children:s.map(l=>e.jsx(Es,{notification:l,getUserDisplay:o,onMarkRead:n},l.id))}):e.jsx("div",{className:"pvx-notif-empty",children:"No notifications"})]})}function Es({notification:s,getUserDisplay:r,onMarkRead:n}){const t=()=>{!s.isRead&&n&&n(s.id)};return e.jsxs("button",{className:`pvx-notif-item ${s.isRead?"":"pvx-notif-item--unread"}`,onClick:t,children:[e.jsx(Fs,{type:s.type}),e.jsxs("div",{className:"pvx-notif-content",children:[e.jsx("span",{className:"pvx-notif-message",children:oe(s,r)}),e.jsx("span",{className:"pvx-notif-time",children:z(s.createdAt)})]}),!s.isRead&&e.jsx("span",{className:"pvx-notif-dot"})]})}function Fs({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 qs(){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 _s({steamId:s,avatarUrl:r,memberSince:n,className:t=""}){const{data:a,isLoading:i,error:o}=Le(s),{data:l,isLoading:p}=Se(s),{data:c,isLoading:u}=Te(),v=Me(),{data:j,isLoading:d}=$e({limit:10}),f=De(),h=Ie();return i||p?e.jsx("div",{className:"pvx-loading",children:"Loading dashboard..."}):o?e.jsx("div",{className:"pvx-empty",children:"Failed to load dashboard data."}):a?e.jsxs("div",{className:`pvx-dash ${t}`,children:[e.jsx(Pe,{driverName:a.driverName,avatarUrl:r,memberSince:n}),e.jsx(Be,{stats:a,rating:l}),s&&e.jsx(Ae,{events:c,isLoading:u}),e.jsxs("div",{className:`pvx-dash-row ${v?"pvx-dash-row--2col":""}`,children:[e.jsx(Ue,{records:a.currentRecords}),v&&e.jsx(Ee,{notifications:j==null?void 0:j.notifications,unreadCount:(j==null?void 0:j.unreadCount)||0,onMarkRead:x=>f.mutate(x),onMarkAllRead:()=>h.mutate(),isLoading:d})]})]}):e.jsx("div",{className:"pvx-empty",children:"No data available yet. Start driving to see your stats!"})}exports.CarsTable=rs;exports.CompEmptyState=D;exports.CompLoadingState=B;exports.CompetitionCard=ye;exports.CompetitionCards=xs;exports.DriverDashboard=_s;exports.DriverProfile=Pe;exports.DriversTable=ts;exports.EntryList=bs;exports.InfoPill=F;exports.LapHistoryTable=ns;exports.NotificationsCard=Ee;exports.PODIUM_MEDALS=je;exports.PitVoxPartnerProvider=Ve;exports.RankingsTable=as;exports.RecordsTable=Ue;exports.RegisterButton=ys;exports.RegistrationPanel=ks;exports.RoundResults=gs;exports.RoundSessionResults=ke;exports.StandingsTable=vs;exports.StatsCards=Be;exports.TracksTable=ss;exports.TypeBadge=be;exports.UpcomingEvents=Ae;exports.buildLapsPath=ae;exports.buildLeaderboardPath=q;exports.buildRecentLapsPath=ie;exports.fetchCdnJson=w;exports.formatCarName=S;exports.formatDate=P;exports.formatDelta=Ke;exports.formatLapTime=$;exports.formatNotificationMessage=oe;exports.formatRelativeTime=z;exports.formatSectorTime=M;exports.formatTrackName=I;exports.formatTyreCompound=J;exports.useCarLeaderboard=We;exports.useCarMetadata=Qe;exports.useCompetitionAllRounds=ze;exports.useCompetitionConfig=de;exports.useCompetitionEntryList=Z;exports.useCompetitionRound=xe;exports.useCompetitionStandings=pe;exports.useCompetitions=Ge;exports.useDriverLaps=le;exports.useDriverRating=Se;exports.useDriverRatings=Ls;exports.useDriverStats=Le;exports.useLeaderboardIndex=He;exports.useMarkAllNotificationsRead=Ie;exports.useMarkNotificationRead=De;exports.useNotifications=$e;exports.useNotificationsEnabled=Me;exports.usePitVox=k;exports.useRecentLaps=Oe;exports.useRegister=X;exports.useRegistrationMode=V;exports.useRegistrationStatus=_;exports.useRegistrationUrl=K;exports.useTrackLeaderboard=ce;exports.useUnreadCount=Rs;exports.useUpcomingEvents=Te;exports.useUserLookup=Y;exports.useWithdraw=ee;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),N=require("react"),y=require("@tanstack/react-query"),z=N.createContext(null),Ve="https://cdn.pitvox.com",Ke="https://pitvox.com";let W=null;function He({partnerSlug:s=null,cdnUrl:r=Ve,pitvoxUrl:n=Ke,getSteamId:t,onRegister:a,onWithdraw:i,onFetchNotifications:o,onMarkNotificationRead:l,onMarkAllNotificationsRead:u,onFetchServerPassword:c,children:m}){const v=N.useMemo(()=>({partnerSlug:s,cdnUrl:r.replace(/\/$/,""),pitvoxUrl:n.replace(/\/$/,""),getSteamId:t||(()=>null),onRegister:a||null,onWithdraw:i||null,onFetchNotifications:o||null,onMarkNotificationRead:l||null,onMarkAllNotificationsRead:u||null,onFetchServerPassword:c||null}),[s,r,n,t,a,i,o,l,u,c]);let g=!1;try{y.useQueryClient(),g=!0}catch{g=!1}return g?e.jsx(z.Provider,{value:v,children:m}):(W||(W=new y.QueryClient({defaultOptions:{queries:{staleTime:6e4}}})),e.jsx(y.QueryClientProvider,{client:W,children:e.jsx(z.Provider,{value:v,children:m})}))}function k(){const s=N.useContext(z);if(!s)throw new Error("usePitVox must be used within a <PitVoxPartnerProvider>");return s}async function L(s,r){const n=await fetch(`${s}/${r}`);if(!n.ok){if(n.status===404||n.status===403)return null;throw new Error(`CDN fetch failed: ${n.status}`)}return n.json()}function q(s,...r){return[s?`leaderboards/partners/${s}`:"leaderboards",...r].join("/")}function le(s,r){return s?`laps/partners/${s}/${r}.json`:`laps/${r}.json`}function de(s){return s?`recent-laps/partners/${s}.json`:"recent-laps.json"}function D(s){if(!s&&s!==0)return"-";const r=Math.floor(s/1e3),n=Math.floor(r/60),t=r%60,a=s%1e3;return`${n}:${String(t).padStart(2,"0")}.${String(a).padStart(3,"0")}`}function M(s){return!s&&s!==0?"-":s>=6e4?D(s):(s/1e3).toFixed(3)}function S(s){if(!s)return"";let r=s;return r.startsWith("ks_")&&(r=r.slice(3)),r.split("_").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function P(s,r,n){if(!s)return"";const t=s.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" "),a=n==="acc"||!n&&(r==null?void 0:r.toLowerCase())==="track config";if(!r||r==="default"||a)return t;const i=r.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ");return`${t} ${i}`}function B(s){if(!s)return"-";try{return new Date(s).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}catch{return"-"}}function G(s){if(!s)return"";const r=Date.now()-new Date(s).getTime(),n=Math.floor(r/1e3);if(n<60)return"Just now";const t=Math.floor(n/60);if(t<60)return`${t}m ago`;const a=Math.floor(t/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);return i<30?`${i}d ago`:B(s)}function Qe(s){return s==null?"":`${s>=0?"+":"-"}${(Math.abs(s)/1e3).toFixed(3)}`}function pe(s,r){const{type:n,title:t,trackId:a,trackLayout:i,carId:o,game:l,data:u}=s,c=typeof u=="string"?JSON.parse(u):u,m=a?P(a,i,l):null,v=o?S(o):null,g=[m,v].filter(Boolean).join(" — ");return n==="RECORD_BEATEN"&&g?`${c!=null&&c.beatenBySteamId&&r?r(c.beatenBySteamId).displayName:"Someone"} beat your record on ${g}`:n==="RECORD_SET"&&g?`You set a new record on ${g}`:t||"New notification"}function J(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 Oe(s={}){var u,c,m,v,g,x;const{cdnUrl:r,partnerSlug:n}=k(),{game:t,gameVersion:a}=s,i=q(n,"index.json"),o=y.useQuery({queryKey:["pitvox","leaderboards",n,"index"],queryFn:()=>L(r,i),staleTime:3e4,refetchInterval:3e4}),l=N.useMemo(()=>{var h;if(!((h=o.data)!=null&&h.tracks))return[];let f=o.data.tracks;return t&&(f=f.filter(d=>d.game===t)),a&&(f=f.filter(d=>d.gameVersion===a)),f.map(d=>({id:d.trackId,layout:d.layout,game:d.game,gameVersion:d.gameVersion,displayName:P(d.trackId,d.layout,d.game),driverCount:d.driverCount||0,carCount:d.carCount||0,record:d.recordHolder?{visibleId:d.recordHolder.steamId||d.recordHolder.userId,carId:d.recordHolder.carId,carDisplayName:S(d.recordHolder.carId),lapTimeMs:d.recordHolder.lapTimeMs,timestamp:d.recordHolder.recordedAt}:null,recordByTag:d.recordByTag||null}))},[(u=o.data)==null?void 0:u.tracks,t,a]);return{...o,data:l,partner:((c=o.data)==null?void 0:c.partner)||null,generatedAt:(m=o.data)==null?void 0:m.generatedAt,totalLaps:((v=o.data)==null?void 0:v.totalLaps)||0,totalUsers:((g=o.data)==null?void 0:g.totalUsers)||0,versions:((x=o.data)==null?void 0:x.versions)||{}}}function xe(s,r,n={}){const{cdnUrl:t,partnerSlug:a}=k(),{carId:i,game:o,gameVersion:l}=n,u=r||"default",c=l?`v/${l}/`:"",m=q(a,`${c}tracks/${s}/${u}.json`),{data:v,isLoading:g,error:x}=y.useQuery({queryKey:["pitvox","leaderboards",a,"track",s,u,l],queryFn:()=>L(t,m),enabled:!!s,staleTime:3e4,refetchInterval:3e4});return{data:N.useMemo(()=>{if(!(v!=null&&v.entries))return[];let h=v.entries;if(o&&(h=h.filter(d=>d.game===o)),!i){const d=new Map,j=new Map;for(const p of h){const b=p.steamId||p.userId;j.has(p.carId)||j.set(p.carId,new Set),j.get(p.carId).add(b),(!d.has(p.carId)||p.lapTimeMs<d.get(p.carId).lapTimeMs)&&d.set(p.carId,p)}return Array.from(d.values()).map(p=>{var b;return{...p,driverCount:((b=j.get(p.carId))==null?void 0:b.size)||0}}).sort((p,b)=>p.lapTimeMs-b.lapTimeMs)}return h.filter(d=>d.carId===i).sort((d,j)=>d.lapTimeMs-j.lapTimeMs)},[v==null?void 0:v.entries,i,o]),isLoading:g,error:x}}function ue(s,r,n,t,a={}){var f,h;const{cdnUrl:i,partnerSlug:o}=k(),{showInvalid:l=!1,game:u,gameVersion:c}=a,m=le(o,s),v=y.useQuery({queryKey:["pitvox","laps",o,s],queryFn:()=>L(i,m),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),g=N.useMemo(()=>{var d;return(d=v.data)!=null&&d.laps?v.data.laps.filter(j=>{if(j.trackId!==r)return!1;if(n){if(j.trackLayout!==n)return!1}else if(j.trackLayout&&j.trackLayout!=="default")return!1;return!(j.carId!==t||u&&j.game!==u||c&&j.gameVersion!==c||!l&&!j.isValid)}).sort((j,p)=>j.lapTimeMs-p.lapTimeMs):[]},[(f=v.data)==null?void 0:f.laps,r,n,t,u,c,l]),x=N.useMemo(()=>{const d=g.filter(C=>C.isValid&&C.sector1Ms&&C.sector2Ms&&C.sector3Ms);if(d.length<2)return null;const j=Math.min(...d.map(C=>C.sector1Ms)),p=Math.min(...d.map(C=>C.sector2Ms)),b=Math.min(...d.map(C=>C.sector3Ms)),w=j+p+b,T=Math.min(...d.map(C=>C.lapTimeMs));return w>=T?null:{lapTimeMs:w,sector1Ms:j,sector2Ms:p,sector3Ms:b}},[g]);return{...v,data:g,driverName:((h=v.data)==null?void 0:h.driverName)||"Driver",theoreticalBest:x}}function Y(){const{cdnUrl:s}=k(),{data:r}=y.useQuery({queryKey:["pitvox","users","index"],queryFn:()=>L(s,"users/index.json"),staleTime:5*6e4,gcTime:30*6e4}),n=(r==null?void 0:r.users)||{};return(t,a)=>{const i=n[t];return{displayName:(i==null?void 0:i.displayName)||a||t||"Unknown",avatarUrl:(i==null?void 0:i.avatarUrl)||null,affiliations:(i==null?void 0:i.affiliations)||[]}}}function We(){const{cdnUrl:s}=k(),{data:r}=y.useQuery({queryKey:["pitvox","cars","index"],queryFn:()=>L(s,"cars/index.json"),staleTime:5*6e4,gcTime:30*6e4});return{tags:(r==null?void 0:r.tags)||[],cars:(r==null?void 0:r.cars)||{}}}function ze(){var a,i;const{cdnUrl:s,partnerSlug:r}=k(),n=de(r),t=y.useQuery({queryKey:["pitvox","recentLaps",r],queryFn:()=>L(s,n),staleTime:3e4,refetchInterval:3e4,gcTime:10*6e4});return{groups:((a=t.data)==null?void 0:a.groups)||[],generatedAt:((i=t.data)==null?void 0:i.generatedAt)||null,isLoading:t.isLoading}}function Ge(s,r){return xe(s,null,{carId:r})}function Je(){const{cdnUrl:s,partnerSlug:r}=k();return y.useQuery({queryKey:["pitvox","competitions",r],queryFn:async()=>{const n=await L(s,"competitions/index.json");return n!=null&&n.competitions?r?n.competitions.filter(t=>t.partnerSlug===r):n.competitions:[]},staleTime:6e4})}function Z(s,r={}){const n=k(),t=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",t,s,"config"],queryFn:()=>L(n.cdnUrl,`competitions/${t}/${s}/config.json`),enabled:!!t&&!!s,staleTime:6e4})}function me(s,r={}){const n=k(),t=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",t,s,"standings"],queryFn:()=>L(n.cdnUrl,`competitions/${t}/${s}/standings.json`),enabled:!!t&&!!s,staleTime:6e4})}function ve(s,r,n={}){const t=k(),a=n.partnerSlug||t.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"round",r],queryFn:()=>L(t.cdnUrl,`competitions/${a}/${s}/rounds/${r}.json`),enabled:!!a&&!!s&&r!=null,staleTime:6e4})}function he(s,r=[],n={}){const t=k(),a=n.partnerSlug||t.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"allRounds",r],queryFn:async()=>(await Promise.all(r.map(o=>L(t.cdnUrl,`competitions/${a}/${s}/rounds/${o}.json`).catch(()=>null)))).filter(Boolean),enabled:!!a&&!!s&&r.length>0,staleTime:6e4})}function X(s,r={}){const n=k(),t=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",t,s,"entrylist"],queryFn:()=>L(n.cdnUrl,`competitions/${t}/${s}/entrylist.json`),enabled:!!t&&!!s,staleTime:6e4})}function _(s){const{cdnUrl:r,partnerSlug:n,getSteamId:t}=k(),a=t();return y.useQuery({queryKey:["pitvox","registration",n,s,a],queryFn:async()=>{var u;const i=await fetch(`${r}/competitions/${n}/${s}/entrylist.json`);if(!i.ok)return{isRegistered:!1,entryList:null};const o=await i.json();return{isRegistered:!!a&&((u=o.drivers)==null?void 0:u.some(c=>c.steamId===a)),entryList:o}},enabled:!!s,staleTime:6e4})}function ee(s){const{onRegister:r,partnerSlug:n,getSteamId:t}=k(),a=y.useQueryClient(),i=Y();return y.useMutation({mutationFn:o=>{if(!r)throw new Error("No onRegister callback provided to PitVoxPartnerProvider. Provide onRegister for in-app registration, or use useRegistrationUrl() to link to pitvox.com.");return r(s,o)},onSuccess:()=>{const o=t();if(a.setQueriesData({queryKey:["pitvox","registration",n,s]},l=>l?{...l,isRegistered:!0}:{isRegistered:!0,entryList:null}),o){const l=i(o),u={steamId:o,displayName:l.displayName,avatarUrl:l.avatarUrl};a.setQueriesData({queryKey:["pitvox","competition",n,s,"entrylist"]},c=>{var v;return c?((v=c.drivers)==null?void 0:v.some(g=>g.steamId===o))?c:{...c,drivers:[...c.drivers||[],u]}:{drivers:[u]}})}}})}function se(s){const{onWithdraw:r,partnerSlug:n,getSteamId:t}=k(),a=y.useQueryClient();return y.useMutation({mutationFn:i=>{if(!r)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||t();if(!o)throw new Error("No Steam ID available");return r(s,o)},onSuccess:()=>{const i=t();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(l=>l.steamId!==i)}:o)}})}function V(){const{onRegister:s,onWithdraw:r}=k(),n=!!(s&&r);return{isPowerMode:n,isBasicMode:!n}}function K(s){const{pitvoxUrl:r,partnerSlug:n}=k();return`${r}/p/${n}/competitions/${s}/register`}const Ye={formula:"Formula",gt3:"GT3",gt2:"GT2",gt4:"GT4",cup:"Cup",prototype:"Prototype",rally:"Rally",hypercar:"Hypercar",supercar:"Supercar",sports_car:"Sports Car",hot_hatch:"Hot Hatch",lightweight:"Lightweight","1960s":"1960s","1970s":"1970s","1980s":"1980s","1990s":"1990s","2000s":"2000s","2010s":"2010s","2020s":"2020s"},ge=[{id:"class",tags:["formula","gt3","gt2","gt4","cup","prototype","rally"]},{id:"tier",tags:["hypercar","supercar","sports_car","hot_hatch","lightweight"]},{id:"era",tags:["1960s","1970s","1980s","1990s","2000s","2010s","2020s"]}];function Ze(s){for(const r of ge)if(r.tags.includes(s))return r.id;return"other"}function je(s,r){if(r.size===0)return!0;const n={};for(const t of r){const a=Ze(t);n[a]||(n[a]=[]),n[a].push(t)}for(const t of Object.values(n))if(!t.some(a=>s.includes(a)))return!1;return!0}function fe(s,r){const[n,t]=N.useState(new Set),a=s!==void 0,i=a?s:n,o=N.useCallback(u=>{const c=new Set(i);c.has(u)?c.delete(u):c.add(u),a&&r?r(c):t(c)},[i,a,r]),l=N.useCallback(()=>{a&&r?r(new Set):t(new Set)},[a,r]);return{activeTags:i,toggle:o,clear:l}}function H(s){const[r,n]=N.useState(s),t=N.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[r,t]}function Q(s,r,n){return[...s].sort((t,a)=>{const i=n(t,r.key),o=n(a,r.key);if(i==null&&o==null)return 0;if(i==null)return 1;if(o==null)return-1;const l=typeof i=="string"?i.localeCompare(o):i-o;return r.dir==="desc"?-l:l})}function Ne(s,r=!1){const n=r?s==null?void 0:s.filter(t=>t.isValid):s;return n!=null&&n.length?{s1:Math.min(...n.map(t=>t.sector1Ms).filter(Boolean)),s2:Math.min(...n.map(t=>t.sector2Ms).filter(Boolean)),s3:Math.min(...n.map(t=>t.sector3Ms).filter(Boolean))}:null}function Xe({active:s,dir:r}){return s?r==="asc"?e.jsx("svg",{className:"pvx-sort-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 15.75l7.5-7.5 7.5 7.5"})}):e.jsx("svg",{className:"pvx-sort-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 8.25l-7.5 7.5-7.5-7.5"})}):e.jsx("svg",{className:"pvx-sort-icon pvx-sort-icon--inactive",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 9l4-4 4 4M16 15l-4 4-4-4"})})}function R({label:s,sortKey:r,config:n,onSort:t,className:a=""}){return e.jsx("th",{className:`pvx-th pvx-th--sortable ${a}`,onClick:()=>t(r),children:e.jsxs("span",{className:"pvx-th-inner",children:[s,e.jsx(Xe,{active:n.key===r,dir:n.dir})]})})}function O({userId:s,getUserDisplay:r}){const{displayName:n,avatarUrl:t}=r(s);return e.jsxs("span",{className:"pvx-driver",children:[t?e.jsx("img",{src:t,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 re({rank:s,podium:r=!1}){const n=r?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 be({availableTags:s,activeTags:r,onToggle:n,onClear:t}){if(!s||s.length<2)return null;const a=ge.map(i=>({id:i.id,tags:i.tags.filter(o=>s.includes(o))})).filter(i=>i.tags.length>0);return e.jsxs("div",{className:"pvx-tag-bar",children:[e.jsx("button",{onClick:t,className:`pvx-tag ${r.size===0?"pvx-tag--active":""}`,children:"All"}),a.map((i,o)=>e.jsxs("span",{className:"contents",children:[o>0&&e.jsx("span",{className:"pvx-tag-separator"}),i.tags.map(l=>e.jsx("button",{onClick:()=>n(l),className:`pvx-tag ${r.has(l)?"pvx-tag--active":""}`,children:Ye[l]||l},l))]},i.id))]})}function te({segments:s}){return e.jsx("nav",{className:"pvx-breadcrumb","aria-label":"Breadcrumb",children:e.jsx("ol",{className:"pvx-breadcrumb-list",children:s.map((r,n)=>{const t=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"})}),!t&&r.onClick?e.jsx("button",{onClick:r.onClick,className:"pvx-breadcrumb-link",children:r.label}):e.jsx("span",{className:"pvx-breadcrumb-current",children:r.label})]},r.key)})})})}function U({message:s}){return e.jsxs("div",{className:"pvx-empty",children:[e.jsx("svg",{className:"pvx-empty-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.5 18.75h-9m9 0a3 3 0 013 3h-15a3 3 0 013-3m9 0v-4.5A3.375 3.375 0 0013.125 10.875h-2.25A3.375 3.375 0 007.5 14.25v4.5"})}),e.jsx("p",{children:s})]})}function E(){return e.jsx("div",{className:"pvx-loading",children:"Loading..."})}function es(){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 ss(){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 rs({tracks:s,isLoading:r,carMetadata:n,getUserDisplay:t,onTrackSelect:a,tags:i,onTagChange:o}){const[l,u]=H({key:"record.timestamp",dir:"desc"}),{activeTags:c,toggle:m,clear:v}=fe(i,o),g=N.useMemo(()=>{var d;if(!((d=n==null?void 0:n.tags)!=null&&d.length))return[];const h=new Set;for(const j of s||[])j.recordByTag&&Object.keys(j.recordByTag).forEach(p=>h.add(p));return n.tags.filter(j=>h.has(j))},[s,n]),x=N.useMemo(()=>s?c.size===0?s:s.map(h=>{var p,b;if(!h.recordByTag)return null;let d=null;const j=new Set;for(const w of Object.values(h.recordByTag)){if(j.has(w.carId))continue;j.add(w.carId);const T=((b=(p=n==null?void 0:n.cars)==null?void 0:p[w.carId])==null?void 0:b.tags)||["sports_car"];je(T,c)&&(!d||w.lapTimeMs<d.lapTimeMs)&&(d=w)}return d?{...h,record:{visibleId:d.steamId||d.identifier,carId:d.carId,carDisplayName:S(d.carId),lapTimeMs:d.lapTimeMs,timestamp:d.recordedAt}}:null}).filter(Boolean):[],[s,c,n]),f=N.useMemo(()=>Q(x,l,(h,d)=>{var j,p;switch(d){case"displayName":return h.displayName;case"record.lapTimeMs":return(j=h.record)==null?void 0:j.lapTimeMs;case"driverCount":return h.driverCount||0;case"carCount":return h.carCount||0;case"record.timestamp":default:return(p=h.record)!=null&&p.timestamp?new Date(h.record.timestamp).getTime():0}}),[x,l]);return r?e.jsx(E,{}):s!=null&&s.length?e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx("h2",{className:"pvx-card-title",children:"Track Records"})}),e.jsx(be,{availableTags:g,activeTags:c,onToggle:m,onClear:v}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx(R,{label:"Track",sortKey:"displayName",config:l,onSort:u}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Car"}),e.jsx(R,{label:"Lap Time",sortKey:"record.lapTimeMs",config:l,onSort:u}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:l,onSort:u,className:"pvx-hidden-below-md"}),e.jsx(R,{label:"Cars",sortKey:"carCount",config:l,onSort:u,className:"pvx-hidden-below-lg"}),e.jsx(R,{label:"Date",sortKey:"record.timestamp",config:l,onSort:u,className:"pvx-hidden-below-xl"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:f.map(h=>{var d,j,p;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:(d=h.record)!=null&&d.visibleId?e.jsx(O,{userId:h.record.visibleId,getUserDisplay:t}):"-"}),e.jsx("td",{className:"pvx-td pvx-hidden-below-lg",children:((j=h.record)==null?void 0:j.carDisplayName)||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:h.record?D(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:(p=h.record)!=null&&p.timestamp?B(h.record.timestamp):"-"})]},`${h.id}|${h.layout||""}`)})})]})})]}):e.jsx(U,{message:"No lap times recorded yet."})}function ts({entries:s,isLoading:r,track:n,carMetadata:t,getUserDisplay:a,onCarSelect:i,onNavigate:o,tags:l,onTagChange:u}){const[c,m]=H({key:"lapTimeMs",dir:"asc"}),{activeTags:v,toggle:g,clear:x}=fe(l,u),f=N.useMemo(()=>{var b,w,T;if(!s||!((b=t==null?void 0:t.tags)!=null&&b.length))return[];const p=new Set;for(const C of s)(((T=(w=t.cars)==null?void 0:w[C.carId])==null?void 0:T.tags)||["sports_car"]).forEach(A=>p.add(A));return t.tags.filter(C=>p.has(C))},[s,t]),h=N.useMemo(()=>s?v.size===0?s:s.filter(p=>{var w,T;const b=((T=(w=t==null?void 0:t.cars)==null?void 0:w[p.carId])==null?void 0:T.tags)||["sports_car"];return je(b,v)}):[],[s,v,t]),d=N.useMemo(()=>Q(h,c,(p,b)=>{switch(b){case"carId":return S(p.carId);case"driverCount":return p.driverCount||0;case"lapTimeMs":default:return p.lapTimeMs}}),[h,c]),j=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:n.displayName}];return r?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(te,{segments:j})}),e.jsx(be,{availableTags:f,activeTags:v,onToggle:g,onClear:x}),s!=null&&s.length?e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"#"}),e.jsx(R,{label:"Car",sortKey:"carId",config:c,onSort:m}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:c,onSort:m}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:c,onSort:m,className:"pvx-hidden-below-md"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:d.map((p,b)=>e.jsxs("tr",{className:"pvx-row pvx-row--clickable",onClick:()=>i(p.carId),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(re,{rank:b+1,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:S(p.carId)}),e.jsx("td",{className:"pvx-td",children:e.jsx(O,{userId:p.steamId||p.userId,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:D(p.lapTimeMs)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-md",children:p.driverCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-lg",children:p.recordedAt?B(p.recordedAt):"-"})]},p.carId))})]})}):e.jsx(U,{message:"No lap times for this track yet."})]})}function ns({entries:s,isLoading:r,track:n,carId:t,getUserDisplay:a,onDriverSelect:i,onNavigate:o,highlightId:l}){const[u,c]=H({key:"lapTimeMs",dir:"asc"}),m=N.useMemo(()=>Ne(s),[s]),v=N.useMemo(()=>Q(s||[],u,(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,u,a]),g=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:n.displayName,onClick:()=>o("track")},{key:"car",label:S(t)}];return r?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(te,{segments:g})}),s!=null&&s.length?e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"#"}),e.jsx(R,{label:"Driver",sortKey:"userId",config:u,onSort:c}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:u,onSort:c}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Tyre"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Fuel"}),e.jsx(R,{label:"Laps",sortKey:"lapCount",config:u,onSort:c,className:"pvx-hidden-below-lg"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:v.map((x,f)=>{const h=f+1,d=x.steamId||x.userId,j=m&&x.sector1Ms===m.s1,p=m&&x.sector2Ms===m.s2,b=m&&x.sector3Ms===m.s3,w=l&&d===l;return e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${w?"pvx-row--highlight":h<=3?"pvx-row--podium":""}`,onClick:()=>i(d),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(re,{rank:h,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(O,{userId:d,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:D(x.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${j?"pvx-td--best-sector":""}`,children:M(x.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${p?"pvx-td--best-sector":""}`,children:M(x.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${b?"pvx-td--best-sector":""}`,children:M(x.sector3Ms)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:J(x.tyreCompound),children:x.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-xl",children:x.startingFuelL?`${x.startingFuelL}L`:"-"}),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?B(x.recordedAt):"-"})]},d)})})]})}):e.jsx(U,{message:"No lap times for this car yet."})]})}function as({userId:s,track:r,carId:n,game:t,gameVersion:a,showInvalid:i,getUserDisplay:o,onToggleInvalid:l,onNavigate:u}){const{data:c,driverName:m,theoreticalBest:v,isLoading:g}=ue(s,r.id,r.layout,n,{showInvalid:i,game:t,gameVersion:a}),{displayName:x,avatarUrl:f}=o(s,m),h=N.useMemo(()=>Ne(c,!0),[c]),d=N.useMemo(()=>{const p=(c==null?void 0:c.filter(b=>b.isValid))||[];return p.length?Math.min(...p.map(b=>b.lapTimeMs)):null},[c]),j=[{key:"tracks",label:"Tracks",onClick:()=>u("tracks")},{key:"track",label:r.displayName,onClick:()=>u("track")},{key:"car",label:S(n),onClick:()=>u("car")},{key:"driver",label:x}];return g?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header pvx-card-header--split",children:[e.jsxs("div",{className:"pvx-card-header-left",children:[e.jsx(te,{segments:j}),f?e.jsx("img",{src:f,alt:"",className:"pvx-driver-avatar pvx-driver-avatar--lg"}):e.jsx("span",{className:"pvx-driver-avatar pvx-driver-avatar--lg pvx-driver-avatar--placeholder"})]}),e.jsxs("label",{className:"pvx-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:l,className:"pvx-checkbox"}),e.jsx("span",{children:"Show invalid laps"})]})]}),v&&e.jsxs("div",{className:"pvx-theoretical-best",children:[e.jsx("span",{className:"pvx-theoretical-best-label",children:"Theoretical Best:"}),e.jsx("span",{className:"pvx-theoretical-best-time",children:D(v.lapTimeMs)}),e.jsxs("span",{className:"pvx-theoretical-best-sectors",children:["(",M(v.sector1Ms)," + ",M(v.sector2Ms)," + ",M(v.sector3Ms),")"]})]}),c!=null&&c.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:c.map((p,b)=>{const w=p.isValid&&p.lapTimeMs===d,T=h&&p.isValid&&p.sector1Ms===h.s1,C=h&&p.isValid&&p.sector2Ms===h.s2,ie=h&&p.isValid&&p.sector3Ms===h.s3;let A="pvx-row";return p.isValid||(A+=" pvx-row--invalid"),w&&(A+=" pvx-row--personal-best"),e.jsxs("tr",{className:A,children:[e.jsx("td",{className:"pvx-td",children:e.jsx("span",{className:`pvx-rank ${w?"pvx-rank--gold":""}`,children:b+1})}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-md",children:p.lapNumber||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:D(p.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${T?"pvx-td--best-sector":""}`,children:M(p.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${C?"pvx-td--best-sector":""}`,children:M(p.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${ie?"pvx-td--best-sector":""}`,children:M(p.sector3Ms)}),e.jsx("td",{className:"pvx-td",title:p.isValid?void 0:p.invalidReason||"Invalid",children:p.isValid?e.jsx(es,{}):e.jsx(ss,{})}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:J(p.tyreCompound),children:p.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:p.startingFuelL?`${p.startingFuelL}L`:"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:B(p.timestamp)})]},p.id)})})]})}):e.jsx(U,{message:i?"No laps recorded for this combination.":'No valid laps. Try enabling "Show invalid laps".'})]})}function is({drivers:s,isLoading:r,getUserDisplay:n,game:t,gameVersion:a,onComboSelect:i}){const[o,l]=H({key:"rank",dir:"asc"}),[u,c]=N.useState(null),m=N.useMemo(()=>s?Q(s,o,(g,x)=>{switch(x){case"rating":return g.rating;case"comboCount":return g.comboCount||0;case"distinctCars":return g.distinctCars||0;case"rank":default:return g.rank}}):[],[s,o]);if(r)return e.jsx(E,{});if(!(s!=null&&s.length))return e.jsx("div",{className:"pvx-card",children:e.jsx(U,{message:"Not enough data for rankings yet."})});const v=5;return e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header pvx-rankings-header",children:[e.jsx("h2",{className:"pvx-card-title",children:"Driver Rankings"}),e.jsxs("div",{className:"pvx-rankings-info-trigger",children:[e.jsx("svg",{className:"pvx-rankings-info-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"})}),e.jsxs("div",{className:"pvx-rankings-info-tooltip",children:[e.jsx("p",{className:"pvx-rankings-info-title",children:"How ratings work"}),e.jsxs("ul",{className:"pvx-rankings-info-list",children:[e.jsx("li",{children:"For each car/track combo with 3+ drivers, you're ranked by lap time and given a percentile (100 = fastest, 0 = slowest)"}),e.jsx("li",{children:"Your rating is a weighted average across all your combos — bigger fields count more"}),e.jsx("li",{children:"A confidence adjustment rewards car diversity: the more different cars you drive competitively, the closer your rating reflects your true score"}),e.jsx("li",{children:"Minimum 2 qualifying combos required"})]})]})]})]}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx(R,{label:"#",sortKey:"rank",config:o,onSort:l,className:"pvx-th--narrow"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx(R,{label:"Rating",sortKey:"rating",config:o,onSort:l}),e.jsx(R,{label:"Cars",sortKey:"distinctCars",config:o,onSort:l,className:"pvx-hidden-below-sm"}),e.jsx(R,{label:"Combos",sortKey:"comboCount",config:o,onSort:l,className:"pvx-hidden-below-sm"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:m.map(g=>{const x=u===g.identifier;return e.jsx(os,{driver:g,getUserDisplay:n,isExpanded:x,onToggle:()=>c(x?null:g.identifier),colCount:v,game:t,gameVersion:a,onComboSelect:i},g.identifier)})})]})})]})}function os({driver:s,getUserDisplay:r,isExpanded:n,onToggle:t,colCount:a,game:i,gameVersion:o,onComboSelect:l}){const u=s.identifier;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${s.rank<=3?"pvx-row--podium":""}`,onClick:t,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(re,{rank:s.rank,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(O,{userId:u,getUserDisplay:r})}),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((c,m)=>{const v=c.layout?`${c.trackId}|${c.layout}`:c.trackId,g=l?()=>l({track:v,car:c.carId,highlight:u,game:i,gameVersion:o}):void 0;return e.jsxs("div",{className:`pvx-rankings-combo ${g?"pvx-rankings-combo--clickable":""}`,onClick:g,role:g?"button":void 0,children:[e.jsxs("div",{className:"pvx-rankings-combo-info",children:[e.jsx("p",{className:"pvx-rankings-combo-track",children:P(c.trackId,c.layout,i)}),e.jsx("p",{className:"pvx-rankings-combo-car",children:S(c.carId)})]}),e.jsxs("div",{className:"pvx-rankings-combo-stats",children:[e.jsx("p",{className:"pvx-rankings-combo-time",children:D(c.lapTimeMs)}),e.jsxs("p",{className:`pvx-rankings-combo-pct ${c.percentile>=75?"pvx-rankings-combo-pct--high":c.percentile>=50?"pvx-rankings-combo-pct--mid":c.percentile>=25?"pvx-rankings-combo-pct--low":"pvx-rankings-combo-pct--bottom"}`,children:[c.percentile.toFixed(0),"%",e.jsxs("span",{className:"pvx-rankings-combo-rank",children:["(",c.rank,"/",c.totalDrivers,")"]})]})]})]},m)})})})})]})}const cs={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:"🇰🇷"},ne=["🥇","🥈","🥉"],ls={championship:"Championship",series:"Series",event:"Event"},oe=["PRACTICE","QUALIFYING","RACE"];function ye({position:s}){const r=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:r,children:s})}function ke({nation:s}){const r=s&&cs[s];return r?e.jsx("span",{className:"pvx-nation-flag",title:s,children:r}):null}function ds({sessions:s,activeSession:r,onSelect:n}){if(!s||s.length<=1)return null;const t=[...s].sort((a,i)=>oe.indexOf(a.type)-oe.indexOf(i.type));return e.jsx("div",{className:"pvx-session-tabs",children:t.map(a=>e.jsx("button",{onClick:()=>n(a.type),className:`pvx-session-tab ${r===a.type?"pvx-session-tab--active":""}`,children:a.type},a.type))})}function Ce({type:s}){return e.jsx("span",{className:`pvx-comp-badge pvx-comp-badge--${s}`,children:ls[s]||s})}function F({children:s,variant:r="default"}){return e.jsx("span",{className:`pvx-info-pill ${r!=="default"?`pvx-info-pill--${r}`:""}`,children:s})}function ps(s){if(!s)return"TBD";const r=new Date(s);if(isNaN(r))return"TBD";const n=r.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),t=r.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return`${n} • ${t}`}function xs(s){return s.reduce((r,n)=>{var t;return(t=n.splits)!=null&&t.length?r?r.map((a,i)=>{const o=n.splits[i];return o&&o<a?o:a}):[...n.splits]:r},null)}function I({message:s="Loading..."}){return e.jsx("div",{className:"pvx-loading",children:s})}function $({message:s="No data available."}){return e.jsx("div",{className:"pvx-empty",children:e.jsx("p",{children:s})})}function us({competitions:s,isLoading:r,onSelect:n,onRegister:t,className:a}){return r?e.jsx(I,{message:"Loading competitions..."}):s!=null&&s.length?e.jsx("div",{className:`pvx-comp-grid ${a||""}`,children:s.map(i=>e.jsx(we,{comp:i,onSelect:n,onRegister:t||n},i.id))}):e.jsx($,{message:"No competitions available."})}function we({comp:s,onSelect:r,onRegister:n}){var h,d,j;const{cdnUrl:t}=k(),a=s.posterCdnPath?`${t}/${s.posterCdnPath}`:null,i=s.registration,o=(i==null?void 0:i.currentCount)||0,l=i==null?void 0:i.maxParticipants,u=l&&o>=l,c=(i==null?void 0:i.deadline)&&new Date(i.deadline)<new Date,m=(i==null?void 0:i.isOpen)&&!c&&!u,v=new Date,g=(h=s.rounds)==null?void 0:h.find(p=>p.startTime&&new Date(p.startTime)>=v),x=((d=s.rounds)==null?void 0:d.length)||0,f=((j=s.rounds)==null?void 0:j.filter(p=>p.isFinalized).length)||0;return e.jsxs("div",{className:"pvx-comp-card",onClick:()=>r(s.id),role:"button",tabIndex:0,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),r(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(vs,{})})}),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(Ce,{type:s.type}),s.game&&e.jsx(F,{children:s.game.toUpperCase()}),s.formatDescription&&s.formatDescription.split(", ").map((p,b)=>e.jsx(F,{variant:"format",children:p},b))]}),s.carsDescription&&e.jsx("div",{className:"pvx-comp-card-pills",children:s.carsDescription.split(", ").map((p,b)=>e.jsx(F,{children:p},b))}),e.jsxs("div",{className:"pvx-comp-card-schedule",children:[g?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[e.jsx("span",{className:"pvx-comp-card-schedule-label",children:"Next:"})," ","R",g.roundNumber," ",g.track||"TBD"," — ",ps(g.startTime)]}):x>0?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[f,"/",x," rounds completed"]}):null,x>0&&e.jsxs("span",{className:"pvx-comp-card-round-count",children:[x," round",x!==1?"s":""]})]}),i&&e.jsx(ms,{competitionId:s.id,regOpen:m,isFull:u,deadlinePassed:c,regCount:o,regMax:l,onRegister:n})]})]})}function ms({competitionId:s,regOpen:r,isFull:n,deadlinePassed:t,regCount:a,regMax:i,onRegister:o}){const{isPowerMode:l}=V(),u=K(s),{data:c}=_(s),m=(c==null?void 0:c.isRegistered)||!1,v=i?a/i*100:0,g=v>=100?"full":v>=75?"warning":"ok";return e.jsxs("div",{className:"pvx-comp-card-reg",children:[e.jsx("div",{className:"pvx-comp-card-reg-info",children:e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${g}`,children:[a,"/",i||"∞"," drivers"]})}),e.jsx("div",{className:"pvx-comp-card-reg-action",children:m?e.jsx("button",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--registered",onClick:x=>{x.stopPropagation(),o(s)},children:"✓ Registered"}):r?l?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:u,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 vs(){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 Le({competitionId:s,className:r}){var l,u;const{data:n,isLoading:t}=me(s),{data:a,isLoading:i}=Z(s);if(t||i)return e.jsx(I,{message:"Loading standings..."});if(!((l=n==null?void 0:n.standings)!=null&&l.length))return e.jsx($,{message:"No standings data yet. Results will appear once rounds are finalised."});const o=((u=a==null?void 0:a.rounds)==null?void 0:u.filter(c=>c.isFinalized))||[];return e.jsxs("div",{className:`pvx-card ${r||""}`,children:[e.jsx("div",{className:"pvx-card-header--split",children:e.jsxs("div",{className:"pvx-card-header-left",children:[e.jsx("h3",{className:"pvx-card-title",children:"Championship Standings"}),e.jsxs("span",{className:"pvx-standings-subtitle",children:["After ",n.roundsCompleted," round",n.roundsCompleted!==1?"s":"",n.countingRounds>0&&` (best ${n.countingRounds} count)`]})]})}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"W"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"Pod"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"}),o.map(c=>e.jsxs("th",{className:"pvx-th pvx-th--center pvx-hidden-below-md",title:c.track||`Round ${c.roundNumber}`,children:["R",c.roundNumber]},c.roundNumber))]})}),e.jsx("tbody",{className:"pvx-tbody",children:n.standings.map(c=>e.jsx(hs,{driver:c,finalizedRounds:o},c.driverId||c.driverName))})]})})]})}function hs({driver:s,finalizedRounds:r}){var o,l,u;const n=s.position<=3,t=new Map(((o=s.roundResults)==null?void 0:o.map(c=>[c.roundNumber,c]))||[]),a=((l=s.roundResults)==null?void 0:l.filter(c=>c.position===1).length)||0,i=((u=s.roundResults)==null?void 0:u.filter(c=>c.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(ye,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ke,{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}),r.map(c=>{const m=t.get(c.roundNumber),v=m==null?void 0:m.dropped;return e.jsx("td",{className:`pvx-td pvx-td--center pvx-hidden-below-md ${!v&&(m==null?void 0:m.position)<=3?"pvx-standings-cell--podium":""}`,children:m?e.jsxs("div",{className:`pvx-standings-round-cell ${v?"pvx-standings-round-cell--dropped":""}`,children:[e.jsxs("span",{className:"pvx-standings-round-pos",children:["P",m.position]}),e.jsx("span",{className:"pvx-standings-round-pts",children:m.points})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})},c.roundNumber)})]})}function gs({competitionId:s,roundNumber:r,className:n}){var u;const{data:t,isLoading:a}=ve(s,r);if(a)return e.jsx(I,{message:"Loading results..."});if(!t)return e.jsx($,{message:"No results for this round."});const o=(t.sessions||[]).find(c=>c.type==="RACE"),l=(u=o==null?void 0:o.results)==null?void 0:u.filter(c=>c.position<=3).sort((c,m)=>c.position-m.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 ",t.roundNumber,t.track?`: ${t.track}`:""]}),t.startTime&&e.jsx("p",{className:"pvx-round-results-date",children:new Date(t.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(l==null?void 0:l.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:l.map(c=>e.jsxs("span",{className:"pvx-round-podium-item",children:[e.jsx("span",{children:ne[c.position-1]}),e.jsx("span",{children:c.driverName})]},c.driverId))})]}),e.jsx(ae,{round:t})]})}function ae({round:s,className:r}){var l,u;const[n,t]=N.useState(null),a=(s==null?void 0:s.sessions)||[];if(!a.length)return e.jsx($,{message:"No session data for this round."});const i=n||((l=a.find(c=>c.type==="RACE"))==null?void 0:l.type)||((u=a[0])==null?void 0:u.type),o=a.find(c=>c.type===i)||a[0];return e.jsxs("div",{className:r||"",children:[e.jsx(ds,{sessions:a,activeSession:i,onSelect:t}),e.jsx(js,{session:o})]})}function js({session:s}){var t;const r=s.type==="RACE";if(!((t=s.results)!=null&&t.length))return e.jsx($,{message:`No results for ${s.type}.`});const n=xs(s.results);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"}),r&&e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Laps"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Time / Gap"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"})]})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.results.map((a,i)=>e.jsx(fs,{result:a,isRace:r,fastestSplits:n,rowIndex:i},a.driverId||i))})]})})}function fs({result:s,isRace:r,fastestSplits:n,rowIndex:t}){const a=s.position<=3;return e.jsxs("tr",{className:`pvx-row ${a?"pvx-row--podium":""}`,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ye,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ke,{nation:s.nation}),s.driverName,s.carNumber!=null&&e.jsxs("span",{className:"pvx-car-number",children:["#",s.carNumber]}),s.penalty&&e.jsx("span",{className:"pvx-penalty",children:s.penalty})]}),e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:S(s.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx(Ns,{bestLap:s.bestLapFormatted,hasBestLap:s.hasBestLap,splits:s.splits,fastestSplits:n,showAbove:t<=1})}),r&&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,")"]})]})]})]})}function Ns({bestLap:s,hasBestLap:r,splits:n,fastestSplits:t,showAbove:a}){return s?e.jsxs("span",{className:`pvx-best-lap-cell ${r?"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 l=t&&i===t[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:l?"pvx-splits-tooltip-best":"",children:i})]},o)})})})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})}function bs({competitionId:s,className:r}){const{getSteamId:n}=k(),{data:t,isLoading:a}=X(s),i=n();if(a)return e.jsx(I,{message:"Loading drivers..."});const o=(t==null?void 0:t.drivers)||(t==null?void 0:t.entries)||[];return o.length?e.jsx("div",{className:`pvx-entry-grid ${r||""}`,children:o.map(l=>{var c,m;const u=i&&l.steamId===i;return e.jsxs("div",{className:`pvx-entry-card ${u?"pvx-entry-card--you":""}`,children:[l.avatarUrl?e.jsx("img",{src:l.avatarUrl,alt:"",className:"pvx-entry-avatar"}):e.jsx("div",{className:"pvx-entry-avatar pvx-entry-avatar--placeholder",children:((m=(c=l.displayName)==null?void 0:c.charAt(0))==null?void 0:m.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-entry-name",children:[l.displayName,u&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},l.steamId||l.driverId)})}):e.jsx($,{message:"No drivers registered yet."})}function ys({competitionId:s,driverData:r,className:n,children:t}){const{data:a,isLoading:i}=_(s),{isPowerMode:o}=V(),l=K(s),u=ee(s),c=se(s),m=(a==null?void 0:a.isRegistered)||!1,v=i||u.isPending||c.isPending,g=u.error||c.error||null,x=()=>{o&&u.mutate(r||{})},f=()=>{o&&c.mutate()};return typeof t=="function"?t({isRegistered:m,isLoading:v,register:x,withdraw:f,error:g,isPowerMode:o,registrationUrl:l}):o?e.jsx("button",{className:`pvx-comp-register-btn ${n||""}`,onClick:m?f:x,disabled:v,children:v?"Loading...":m?"Withdraw":"Register"}):e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:`pvx-comp-register-link ${n||""}`,children:m?"View Registration":"Register on PitVox"})}function ks({competitionId:s,registration:r,onWithdrawSuccess:n,className:t}){const{getSteamId:a}=k(),{isPowerMode:i}=V(),o=K(s),{data:l,isLoading:u}=_(s),{data:c,isLoading:m}=X(s),v=ee(s),g=se(s),x=a(),f=(l==null?void 0:l.isRegistered)||!1,h=(c==null?void 0:c.drivers)||(c==null?void 0:c.entries)||[],d=r||{},j=h.length||d.currentCount||0,p=d.maxParticipants&&j>=d.maxParticipants,b=d.deadline&&new Date(d.deadline)<new Date,w=d.isOpen&&!b&&!p;return u||m?e.jsx(I,{message:"Loading registration..."}):f?e.jsx("div",{className:`pvx-reg-panel ${t||""}`,children:e.jsx(ws,{competitionId:s,drivers:h,steamId:x,isPowerMode:i,registrationUrl:o,withdrawMutation:g,onWithdrawSuccess:n,registration:d})}):w?x?i?e.jsx("div",{className:`pvx-reg-panel ${t||""}`,children:e.jsx(Cs,{competitionId:s,registerMutation:v,registration:d})}):e.jsx("div",{className:`pvx-reg-panel ${t||""}`,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 ${t||""}`,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 ${t||""}`,children:[e.jsx("div",{className:"pvx-reg-status-msg",children:p?"Registration is full.":b?"Registration deadline has passed.":"Registration is closed."}),h.length>0&&e.jsx(Re,{drivers:h,steamId:x})]})}function Cs({competitionId:s,registerMutation:r,registration:n}){const[t,a]=N.useState(""),[i,o]=N.useState("intermediate"),[l,u]=N.useState(""),c=x=>{x.preventDefault(),r.mutate({discordUsername:t||void 0,experience:i,comments:l||void 0})},m=n||{},v=m.currentCount||0,g=m.maxParticipants;return e.jsxs("form",{className:"pvx-reg-form",onSubmit:c,children:[e.jsxs("div",{className:"pvx-reg-form-header",children:[e.jsx("h3",{className:"pvx-reg-form-title",children:"Register"}),g&&e.jsx(Te,{count:v,max:g})]}),r.error&&e.jsx("div",{className:"pvx-reg-error",children:r.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:t,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:l,onChange:x=>u(x.target.value)})]}),e.jsx("div",{className:"pvx-reg-actions",children:e.jsx("button",{type:"submit",className:"pvx-comp-register-btn",disabled:r.isPending,children:r.isPending?"Registering...":"Register"})})]})}function ws({competitionId:s,drivers:r,steamId:n,isPowerMode:t,registrationUrl:a,withdrawMutation:i,onWithdrawSuccess:o,registration:l}){const[u,c]=N.useState(!1),m=()=>{i.mutate(void 0,{onSuccess:()=>{c(!1),o&&o()}})},v=l||{},g=r.length||v.currentCount||0,x=v.maxParticipants;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pvx-reg-form-header",children:[e.jsx("h3",{className:"pvx-reg-form-title",children:"Registered Drivers"}),x&&e.jsx(Te,{count:g,max:x})]}),e.jsx(Re,{drivers:r,steamId:n}),i.error&&e.jsx("div",{className:"pvx-reg-error",children:i.error.message||"Withdrawal failed"}),t?e.jsx("div",{className:"pvx-reg-actions",children:u?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:()=>c(!1),children:"Cancel"}),e.jsx("button",{type:"button",className:"pvx-reg-danger-btn",onClick:m,disabled:i.isPending,children:i.isPending?"Unregistering...":"Yes, Unregister"})]})]}):e.jsx("button",{type:"button",className:"pvx-reg-unregister-btn",onClick:()=>c(!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 Re({drivers:s,steamId:r}){if(!s.length)return e.jsx("div",{className:"pvx-reg-no-drivers",children:"No drivers registered yet."});const n=[...s].sort((t,a)=>{const i=r&&t.steamId===r?-1:0,o=r&&a.steamId===r?-1:0;return i-o});return e.jsx("div",{className:"pvx-reg-driver-list",children:n.map(t=>{var i,o;const a=r&&t.steamId===r;return e.jsxs("div",{className:`pvx-reg-driver-row ${a?"pvx-reg-driver-row--you":""}`,children:[t.avatarUrl?e.jsx("img",{src:t.avatarUrl,alt:"",className:"pvx-reg-driver-avatar"}):e.jsx("div",{className:"pvx-reg-driver-avatar pvx-reg-driver-avatar--placeholder",children:((o=(i=t.displayName)==null?void 0:i.charAt(0))==null?void 0:o.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-reg-driver-name",children:[t.displayName,a&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},t.steamId||t.driverId)})})}function Te({count:s,max:r}){const n=r?s/r*100:0,t=n>=100?"full":n>=75?"warning":"ok";return e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${t}`,children:[s,"/",r," drivers"]})}function Ls({competitionId:s,className:r}){const{data:n,isLoading:t}=Z(s),a=(n==null?void 0:n.type)==="championship",i=N.useMemo(()=>{var d;return((d=n==null?void 0:n.rounds)==null?void 0:d.filter(j=>j.isFinalized))||[]},[n]),o=N.useMemo(()=>i.map(d=>d.roundNumber),[i]),{data:l=[],isLoading:u}=he(s,o),c=a?"standings":o.length>0?`round-${o[o.length-1]}`:null,[m,v]=N.useState(null),g=m||c;if(t||u)return e.jsx(I,{message:"Loading results..."});if(!n)return e.jsx($,{message:"Competition not found."});if(!i.length)return e.jsx($,{message:"No results available yet. Results will appear here once rounds are finalised."});const x=new Map(l.map(d=>[`round-${d.roundNumber}`,d])),f=[];a&&f.push({id:"standings",label:"Standings"});for(const d of i)f.push({id:`round-${d.roundNumber}`,label:`R${d.roundNumber}`,track:d.track||null});const h=x.get(g);return e.jsxs("div",{className:r||"",children:[e.jsx("div",{className:"pvx-results-tabs",children:f.map(d=>e.jsxs("button",{className:`pvx-results-tab ${g===d.id?"pvx-results-tab--active":""}`,onClick:()=>v(d.id),title:d.track||void 0,children:[e.jsx("span",{className:"pvx-results-tab-label",children:d.label}),d.track&&e.jsx("span",{className:"pvx-results-tab-track",children:d.track})]},d.id))}),g==="standings"?e.jsx(Le,{competitionId:s}):h?e.jsx(Rs,{round:h}):e.jsx($,{message:"No results for this round."})]})}function Rs({round:s}){var a;const n=(s.sessions||[]).find(i=>i.type==="RACE"),t=(a=n==null?void 0:n.results)==null?void 0:a.filter(i=>i.position<=3).sort((i,o)=>i.position-o.position);return e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-round-results-header",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"pvx-round-results-title",children:["Round ",s.roundNumber,s.track?`: ${s.track}`:""]}),s.startTime&&e.jsx("p",{className:"pvx-round-results-date",children:new Date(s.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(t==null?void 0:t.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:t.map(i=>e.jsxs("span",{className:"pvx-round-podium-item",children:[e.jsx("span",{children:ne[i.position-1]}),e.jsx("span",{children:i.driverName})]},i.driverId))})]}),e.jsx(ae,{round:s})]})}function Se(s){const{cdnUrl:r}=k(),n=y.useQuery({queryKey:["pitvox","laps","global",s],queryFn:()=>L(r,`laps/${s}.json`),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),t=n.data;return{isLoading:n.isLoading,error:n.error,data:t?{driverName:t.driverName||"Driver",lapCount:t.lapCount||0,trackBreakdown:t.trackBreakdown||[],carBreakdown:t.carBreakdown||[],recordsHeld:t.recordsHeld||0,currentRecords:t.currentRecords||[],bestRanking:t.bestRanking??null,bestRankingTrackId:t.bestRankingTrackId??null,bestRankingLayout:t.bestRankingLayout??null,bestRankingCarId:t.bestRankingCarId??null,generatedAt:t.generatedAt}:null}}function Me(s={}){const{cdnUrl:r,partnerSlug:n}=k(),{gameVersion:t,enabled:a=!0}=s,i=t?`v/${t}/`:"",o=q(n,`${i}ratings.json`);return y.useQuery({queryKey:["pitvox","ratings",n,t||null],queryFn:()=>L(r,o),staleTime:3e4,refetchInterval:3e4,enabled:a})}function $e(s){var t;const r=Me(),n=N.useMemo(()=>{var a;return!((a=r.data)!=null&&a.drivers)||!s?null:r.data.drivers.find(i=>i.identifier===s)||null},[(t=r.data)==null?void 0:t.drivers,s]);return{isLoading:r.isLoading,error:r.error,data:n?{rating:n.rating,rank:n.rank,totalDrivers:r.data.driverCount||r.data.drivers.length,comboCount:n.comboCount||0,distinctCars:n.distinctCars||0,combos:n.combos||[]}:null}}function Ts(s={}){const r=Me(s);return{data:r.data||null,isLoading:r.isLoading,error:r.error}}function De(){const{cdnUrl:s,partnerSlug:r,getSteamId:n,onFetchServerPassword:t}=k(),a=n(),{data:i,isLoading:o}=y.useQuery({queryKey:["pitvox","competitions",r],queryFn:async()=>{const x=await L(s,"competitions/index.json");return x!=null&&x.competitions?x.competitions.filter(f=>f.partnerSlug===r):[]},staleTime:6e4}),l=(i==null?void 0:i.map(x=>x.id))||[],u=y.useQueries({queries:l.map(x=>({queryKey:["pitvox","competition",r,x,"entrylist"],queryFn:()=>L(s,`competitions/${r}/${x}/entrylist.json`),enabled:!!a&&l.length>0,staleTime:6e4}))}),c=u.some(x=>x.isLoading),m=N.useMemo(()=>{var h,d;if(!i||!a||c)return[];const x=new Date,f=[];for(let j=0;j<i.length;j++){const p=i[j],b=(h=u[j])==null?void 0:h.data;if(!((d=b==null?void 0:b.drivers)==null?void 0:d.some(C=>C.steamId===a)))continue;const T=p.rounds||[];for(const C of T)C.isFinalized||!C.startTime||new Date(C.startTime)<=x||f.push({competitionId:p.id,competitionName:p.name,roundNumber:C.roundNumber,track:C.track||"TBD",startTime:C.startTime})}return f.sort((j,p)=>new Date(j.startTime)-new Date(p.startTime)),f.length>0&&(f[0].isNext=!0),f},[i,a,c,u]),v=y.useQueries({queries:m.map(x=>({queryKey:["pitvox","serverInfo",x.competitionId,x.roundNumber],queryFn:()=>t(x.competitionId,x.roundNumber),enabled:!!t&&m.length>0,staleTime:5*6e4,retry:!1}))});return{data:N.useMemo(()=>m.length?t?m.map((x,f)=>{var d;const h=(d=v[f])==null?void 0:d.data;return h!=null&&h.success?{...x,serverAddress:h.serverAddress||null,serverPassword:h.serverPassword||null}:x}):m:[],[m,t,v]),isLoading:o||!!a&&c}}function Ie(){const{onFetchNotifications:s}=k();return!!s}function Pe(s={}){const{onFetchNotifications:r,partnerSlug:n}=k(),{limit:t=20,unreadOnly:a=!1}=s;return y.useQuery({queryKey:["pitvox","notifications",n,{limit:t,unreadOnly:a}],queryFn:()=>r({limit:t,unreadOnly:a}),enabled:!!r,staleTime:3e4,refetchInterval:3e4})}function Ss(){const{onFetchNotifications:s,partnerSlug:r}=k(),{data:n,isLoading:t}=y.useQuery({queryKey:["pitvox","notifications",r,{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:t}}function Be(){const{onMarkNotificationRead:s,partnerSlug:r}=k(),n=y.useQueryClient();return y.useMutation({mutationFn:t=>{if(!s)throw new Error("No onMarkNotificationRead callback provided to PitVoxPartnerProvider.");return s(t)},onSuccess:(t,a)=>{n.setQueriesData({queryKey:["pitvox","notifications",r]},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 Ae(){const{onMarkAllNotificationsRead:s,partnerSlug:r}=k(),n=y.useQueryClient();return y.useMutation({mutationFn:()=>{if(!s)throw new Error("No onMarkAllNotificationsRead callback provided to PitVoxPartnerProvider.");return s()},onSuccess:()=>{n.setQueriesData({queryKey:["pitvox","notifications",r]},t=>t!=null&&t.notifications?{...t,unreadCount:0,notifications:t.notifications.map(a=>({...a,isRead:!0,readAt:a.readAt||new Date().toISOString()}))}:t)}})}function Ue({driverName:s,avatarUrl:r,memberSince:n,className:t=""}){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 ${t}`,children:[r?e.jsx("img",{src:r,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 Ms(){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 $s(){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 Ds(){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 ce({icon:s,value:r,label:n,items:t,labelKey:a,countKey:i}){const[o,l]=N.useState(!1),u=N.useRef(null);N.useEffect(()=>{if(!o)return;function m(v){u.current&&!u.current.contains(v.target)&&l(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[o]);const c=t!=null&&t.length?t.slice().sort((m,v)=>v[i]-m[i]):null;return e.jsxs("div",{ref:u,className:`pvx-dash-stat-card ${c?"pvx-dash-stat-card--clickable":""}`,onClick:c?()=>l(m=>!m):void 0,children:[s,e.jsxs("div",{className:"pvx-dash-stat-content",children:[e.jsx("span",{className:"pvx-dash-stat-value",children:r}),e.jsx("span",{className:"pvx-dash-stat-label",children:n})]}),c&&e.jsx("div",{className:`pvx-dash-tooltip pvx-dash-tooltip--scrollable ${o?"pvx-dash-tooltip--open":""}`,children:c.map((m,v)=>e.jsxs("div",{className:"pvx-dash-tooltip-row",children:[e.jsx("span",{className:"pvx-dash-tooltip-label",children:m[a]}),e.jsx("span",{className:"pvx-dash-tooltip-value",children:m[i]})]},v))})]})}function Ee({stats:s,rating:r,className:n=""}){if(!s)return null;const t=s.trackBreakdown.map(i=>({name:P(i.trackId,i.layout),lapCount:i.lapCount})),a=s.carBreakdown.map(i=>({name:S(i.carId),lapCount:i.lapCount}));return e.jsxs("div",{className:`pvx-dash-stats ${n}`,children:[e.jsx(ce,{icon:e.jsx(Ms,{}),value:s.lapCount.toLocaleString(),label:"Total Laps",items:t,labelKey:"name",countKey:"lapCount"}),e.jsx(ce,{icon:e.jsx($s,{}),value:s.carBreakdown.length,label:"Cars Used",items:a,labelKey:"name",countKey:"lapCount"}),r&&e.jsxs("div",{className:"pvx-dash-stat-card pvx-dash-stat-card--rating",children:[e.jsx(Ds,{}),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]})]})]})]})}function Fe({records:s,className:r=""}){const n=N.useMemo(()=>s!=null&&s.length?s.slice().sort((t,a)=>{const i=t.recordedAt?new Date(t.recordedAt).getTime():0;return(a.recordedAt?new Date(a.recordedAt).getTime():0)-i}):[],[s]);return n.length?e.jsxs("div",{className:`pvx-card ${r}`,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((t,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:P(t.trackId,t.layout,t.game)}),e.jsx("span",{className:"pvx-dash-record-car",children:S(t.carId)})]}),e.jsxs("div",{className:"pvx-dash-record-time",children:[e.jsx("span",{className:"pvx-dash-record-lap",children:D(t.lapTimeMs)}),e.jsxs("span",{className:`pvx-dash-game-badge pvx-dash-game-badge--${t.game||"evo"}`,children:[(t.game||"evo").toUpperCase(),t.gameVersion?` ${t.gameVersion}`:""]})]})]},a))})]}):null}function qe({events:s,isLoading:r,className:n,limit:t=3}){if(r)return e.jsx("div",{className:"pvx-loading",children:"Loading upcoming events..."});if(!(s!=null&&s.length))return null;const a=t?s.slice(0,t):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(Bs,{}),"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(Is,{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:Ps(o.startTime)}),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 Is({password:s,address:r}){const[n,t]=N.useState(!1),[a,i]=N.useState(!1),o=r?s?`join:${r}|${s}`:`join:${r}`:null,l=N.useCallback(async()=>{if(o)try{await navigator.clipboard.writeText(o),t(!0),setTimeout(()=>t(!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:l,title:"Copy join string to clipboard",children:[e.jsx(Us,{})," ",n?"Copied!":"Join"]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick:()=>i(u=>!u),title:a?"Hide password":"Reveal password",children:a?e.jsx(Fs,{}):e.jsx(Es,{})}),a&&e.jsxs("span",{className:"pvx-server-detail",children:[e.jsx(As,{})," ",s]})]})]})}function Ps(s){const r=new Date(s).getTime()-Date.now();if(r<=0)return"Now";const n=Math.floor(r/(1e3*60*60));if(n<1)return"Less than 1 hour";if(n<24)return`in ${n}h`;const t=Math.floor(n/24);if(t===1)return"Tomorrow";if(t<7)return`in ${t} days`;if(t<30){const a=Math.floor(t/7);return`in ${a} week${a!==1?"s":""}`}return G(s)}function Bs(){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 As(){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 Us(){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 Es(){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 Fs(){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 _e({notifications:s,unreadCount:r=0,onMarkRead:n,onMarkAllRead:t,isLoading:a,className:i}){const o=Y();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(Vs,{}),"Notifications",r>0&&e.jsx("span",{className:"pvx-notif-badge",children:r>99?"99+":r})]}),r>0&&t&&e.jsx("button",{className:"pvx-notif-mark-all",onClick:t,children:"Mark all read"})]}),s!=null&&s.length?e.jsx("div",{className:"pvx-notif-list",children:s.map(l=>e.jsx(qs,{notification:l,getUserDisplay:o,onMarkRead:n},l.id))}):e.jsx("div",{className:"pvx-notif-empty",children:"No notifications"})]})}function qs({notification:s,getUserDisplay:r,onMarkRead:n}){const t=()=>{!s.isRead&&n&&n(s.id)};return e.jsxs("button",{className:`pvx-notif-item ${s.isRead?"":"pvx-notif-item--unread"}`,onClick:t,children:[e.jsx(_s,{type:s.type}),e.jsxs("div",{className:"pvx-notif-content",children:[e.jsx("span",{className:"pvx-notif-message",children:pe(s,r)}),e.jsx("span",{className:"pvx-notif-time",children:G(s.createdAt)})]}),!s.isRead&&e.jsx("span",{className:"pvx-notif-dot"})]})}function _s({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 Vs(){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 Ks({steamId:s,avatarUrl:r,memberSince:n,className:t=""}){const{data:a,isLoading:i,error:o}=Se(s),{data:l,isLoading:u}=$e(s),{data:c,isLoading:m}=De(),v=Ie(),{data:g,isLoading:x}=Pe({limit:10}),f=Be(),h=Ae();return i||u?e.jsx("div",{className:"pvx-loading",children:"Loading dashboard..."}):o?e.jsx("div",{className:"pvx-empty",children:"Failed to load dashboard data."}):a?e.jsxs("div",{className:`pvx-dash ${t}`,children:[e.jsx(Ue,{driverName:a.driverName,avatarUrl:r,memberSince:n}),e.jsx(Ee,{stats:a,rating:l}),s&&e.jsx(qe,{events:c,isLoading:m}),e.jsxs("div",{className:`pvx-dash-row ${v?"pvx-dash-row--2col":""}`,children:[e.jsx(Fe,{records:a.currentRecords}),v&&e.jsx(_e,{notifications:g==null?void 0:g.notifications,unreadCount:(g==null?void 0:g.unreadCount)||0,onMarkRead:d=>f.mutate(d),onMarkAllRead:()=>h.mutate(),isLoading:x})]})]}):e.jsx("div",{className:"pvx-empty",children:"No data available yet. Start driving to see your stats!"})}exports.CarsTable=ts;exports.CompEmptyState=$;exports.CompLoadingState=I;exports.CompetitionCard=we;exports.CompetitionCards=us;exports.CompetitionResultsTabs=Ls;exports.DriverDashboard=Ks;exports.DriverProfile=Ue;exports.DriversTable=ns;exports.EntryList=bs;exports.InfoPill=F;exports.LapHistoryTable=as;exports.NotificationsCard=_e;exports.PODIUM_MEDALS=ne;exports.PitVoxPartnerProvider=He;exports.RankingsTable=is;exports.RecordsTable=Fe;exports.RegisterButton=ys;exports.RegistrationPanel=ks;exports.RoundResults=gs;exports.RoundSessionResults=ae;exports.StandingsTable=Le;exports.StatsCards=Ee;exports.TracksTable=rs;exports.TypeBadge=Ce;exports.UpcomingEvents=qe;exports.buildLapsPath=le;exports.buildLeaderboardPath=q;exports.buildRecentLapsPath=de;exports.fetchCdnJson=L;exports.formatCarName=S;exports.formatDate=B;exports.formatDelta=Qe;exports.formatLapTime=D;exports.formatNotificationMessage=pe;exports.formatRelativeTime=G;exports.formatSectorTime=M;exports.formatTrackName=P;exports.formatTyreCompound=J;exports.useCarLeaderboard=Ge;exports.useCarMetadata=We;exports.useCompetitionAllRounds=he;exports.useCompetitionConfig=Z;exports.useCompetitionEntryList=X;exports.useCompetitionRound=ve;exports.useCompetitionStandings=me;exports.useCompetitions=Je;exports.useDriverLaps=ue;exports.useDriverRating=$e;exports.useDriverRatings=Ts;exports.useDriverStats=Se;exports.useLeaderboardIndex=Oe;exports.useMarkAllNotificationsRead=Ae;exports.useMarkNotificationRead=Be;exports.useNotifications=Pe;exports.useNotificationsEnabled=Ie;exports.usePitVox=k;exports.useRecentLaps=ze;exports.useRegister=ee;exports.useRegistrationMode=V;exports.useRegistrationStatus=_;exports.useRegistrationUrl=K;exports.useTrackLeaderboard=xe;exports.useUnreadCount=Ss;exports.useUpcomingEvents=De;exports.useUserLookup=Y;exports.useWithdraw=se;
|