@pitvox/partner-react 0.6.6 → 0.6.8
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 +5 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +252 -251
- package/dist/styles.css +22 -2
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -133,15 +133,17 @@ All competition detail hooks accept `options.partnerSlug` to override the provid
|
|
|
133
133
|
|
|
134
134
|
```jsx
|
|
135
135
|
import {
|
|
136
|
-
CompetitionCards, CompetitionCard,
|
|
137
|
-
|
|
136
|
+
CompetitionCards, CompetitionCard, CompetitionResultsTabs,
|
|
137
|
+
StandingsTable, RoundResults, RoundSessionResults,
|
|
138
|
+
EntryList, RegisterButton, RegistrationPanel,
|
|
138
139
|
} from '@pitvox/partner-react'
|
|
139
140
|
import '@pitvox/partner-react/styles.css'
|
|
140
141
|
```
|
|
141
142
|
|
|
143
|
+
- **`<CompetitionResultsTabs>`** — Tabbed results view for a competition. Championships show a "Standings" tab (default) plus one tab per finalized round. Series/Events show round tabs only, defaulting to the most recent. Self-contained — fetches all data via hooks. Props: `competitionId`, `className`.
|
|
142
144
|
- **`<CompetitionCards>`** — Card grid with posters, type badges, schedule, registration status. Bundles its own CSS grid layout.
|
|
143
145
|
- **`<CompetitionCard>`** — Individual competition card. Use this when you want to control the grid layout yourself (e.g. with Tailwind). Props: `comp`, `onSelect`, `onRegister`.
|
|
144
|
-
- **`<StandingsTable>`** — Championship standings with per-round breakdowns
|
|
146
|
+
- **`<StandingsTable>`** — Championship standings with per-round breakdowns and per-position podium cell highlighting
|
|
145
147
|
- **`<RoundResults>`** — Standalone round results (fetches data, renders header + sessions)
|
|
146
148
|
- **`<RoundSessionResults>`** — Session tabs + results table (data-prop driven, no fetch)
|
|
147
149
|
- **`<EntryList>`** — Registered drivers grid with avatars
|
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"),z=N.createContext(null),Ve="https://cdn.pitvox.com",Ke="https://pitvox.com";let W=null;function He({partnerSlug:s=null,cdnUrl:t=Ve,pitvoxUrl:n=Ke,getSteamId:r,onRegister:a,onWithdraw:i,onFetchNotifications:o,onMarkNotificationRead:l,onMarkAllNotificationsRead:u,onFetchServerPassword:c,children:m}){const v=N.useMemo(()=>({partnerSlug:s,cdnUrl:t.replace(/\/$/,""),pitvoxUrl:n.replace(/\/$/,""),getSteamId:r||(()=>null),onRegister:a||null,onWithdraw:i||null,onFetchNotifications:o||null,onMarkNotificationRead:l||null,onMarkAllNotificationsRead:u||null,onFetchServerPassword:c||null}),[s,t,n,r,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,t){const n=await fetch(`${s}/${t}`);if(!n.ok){if(n.status===404||n.status===403)return null;throw new Error(`CDN fetch failed: ${n.status}`)}return n.json()}function q(s,...t){return[s?`leaderboards/partners/${s}`:"leaderboards",...t].join("/")}function le(s,t){return s?`laps/partners/${s}/${t}.json`:`laps/${t}.json`}function de(s){return s?`recent-laps/partners/${s}.json`:"recent-laps.json"}function D(s){if(!s&&s!==0)return"-";const t=Math.floor(s/1e3),n=Math.floor(t/60),r=t%60,a=s%1e3;return`${n}:${String(r).padStart(2,"0")}.${String(a).padStart(3,"0")}`}function M(s){return!s&&s!==0?"-":s>=6e4?D(s):(s/1e3).toFixed(3)}function S(s){if(!s)return"";let t=s;return t.startsWith("ks_")&&(t=t.slice(3)),t.split("_").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function P(s,t,n){if(!s)return"";const r=s.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" "),a=n==="acc"||!n&&(t==null?void 0:t.toLowerCase())==="track config";if(!t||t==="default"||a)return r;const i=t.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ");return`${r} ${i}`}function 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 t=Date.now()-new Date(s).getTime(),n=Math.floor(t/1e3);if(n<60)return"Just now";const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const a=Math.floor(r/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);return i<30?`${i}d ago`:B(s)}function Qe(s){return s==null?"":`${s>=0?"+":"-"}${(Math.abs(s)/1e3).toFixed(3)}`}function pe(s,t){const{type:n,title:r,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&&t?t(c.beatenBySteamId).displayName:"Someone"} beat your record on ${g}`:n==="RECORD_SET"&&g?`You set a new record on ${g}`:r||"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:t,partnerSlug:n}=k(),{game:r,gameVersion:a}=s,i=q(n,"index.json"),o=y.useQuery({queryKey:["pitvox","leaderboards",n,"index"],queryFn:()=>L(t,i),staleTime:3e4,refetchInterval:3e4}),l=N.useMemo(()=>{var h;if(!((h=o.data)!=null&&h.tracks))return[];let f=o.data.tracks;return r&&(f=f.filter(d=>d.game===r)),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,r,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,t,n={}){const{cdnUrl:r,partnerSlug:a}=k(),{carId:i,game:o,gameVersion:l}=n,u=t||"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(r,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,t,n,r,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!==t)return!1;if(n){if(j.trackLayout!==n)return!1}else if(j.trackLayout&&j.trackLayout!=="default")return!1;return!(j.carId!==r||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,t,n,r,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:t}=y.useQuery({queryKey:["pitvox","users","index"],queryFn:()=>L(s,"users/index.json"),staleTime:5*6e4,gcTime:30*6e4}),n=(t==null?void 0:t.users)||{};return(r,a)=>{const i=n[r];return{displayName:(i==null?void 0:i.displayName)||a||r||"Unknown",avatarUrl:(i==null?void 0:i.avatarUrl)||null,affiliations:(i==null?void 0:i.affiliations)||[]}}}function We(){const{cdnUrl:s}=k(),{data:t}=y.useQuery({queryKey:["pitvox","cars","index"],queryFn:()=>L(s,"cars/index.json"),staleTime:5*6e4,gcTime:30*6e4});return{tags:(t==null?void 0:t.tags)||[],cars:(t==null?void 0:t.cars)||{}}}function ze(){var a,i;const{cdnUrl:s,partnerSlug:t}=k(),n=de(t),r=y.useQuery({queryKey:["pitvox","recentLaps",t],queryFn:()=>L(s,n),staleTime:3e4,refetchInterval:3e4,gcTime:10*6e4});return{groups:((a=r.data)==null?void 0:a.groups)||[],generatedAt:((i=r.data)==null?void 0:i.generatedAt)||null,isLoading:r.isLoading}}function Ge(s,t){return xe(s,null,{carId:t})}function Je(){const{cdnUrl:s,partnerSlug:t}=k();return y.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const n=await L(s,"competitions/index.json");return n!=null&&n.competitions?t?n.competitions.filter(r=>r.partnerSlug===t):n.competitions:[]},staleTime:6e4})}function Z(s,t={}){const n=k(),r=t.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",r,s,"config"],queryFn:()=>L(n.cdnUrl,`competitions/${r}/${s}/config.json`),enabled:!!r&&!!s,staleTime:6e4})}function me(s,t={}){const n=k(),r=t.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",r,s,"standings"],queryFn:()=>L(n.cdnUrl,`competitions/${r}/${s}/standings.json`),enabled:!!r&&!!s,staleTime:6e4})}function ve(s,t,n={}){const r=k(),a=n.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"round",t],queryFn:()=>L(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}.json`),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function he(s,t=[],n={}){const r=k(),a=n.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"allRounds",t],queryFn:async()=>(await Promise.all(t.map(o=>L(r.cdnUrl,`competitions/${a}/${s}/rounds/${o}.json`).catch(()=>null)))).filter(Boolean),enabled:!!a&&!!s&&t.length>0,staleTime:6e4})}function X(s,t={}){const n=k(),r=t.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",r,s,"entrylist"],queryFn:()=>L(n.cdnUrl,`competitions/${r}/${s}/entrylist.json`),enabled:!!r&&!!s,staleTime:6e4})}function _(s){const{cdnUrl:t,partnerSlug:n,getSteamId:r}=k(),a=r();return y.useQuery({queryKey:["pitvox","registration",n,s,a],queryFn:async()=>{var u;const i=await fetch(`${t}/competitions/${n}/${s}/entrylist.json`);if(!i.ok)return{isRegistered:!1,entryList:null};const o=await i.json();return{isRegistered:!!a&&((u=o.drivers)==null?void 0:u.some(c=>c.steamId===a)),entryList:o}},enabled:!!s,staleTime:6e4})}function ee(s){const{onRegister:t,partnerSlug:n,getSteamId:r}=k(),a=y.useQueryClient(),i=Y();return y.useMutation({mutationFn:o=>{if(!t)throw new Error("No onRegister callback provided to PitVoxPartnerProvider. Provide onRegister for in-app registration, or use useRegistrationUrl() to link to pitvox.com.");return t(s,o)},onSuccess:()=>{const o=r();if(a.setQueriesData({queryKey:["pitvox","registration",n,s]},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:t,partnerSlug:n,getSteamId:r}=k(),a=y.useQueryClient();return y.useMutation({mutationFn:i=>{if(!t)throw new Error("No onWithdraw callback provided to PitVoxPartnerProvider. Provide onWithdraw for in-app withdrawal, or use useRegistrationUrl() to link to pitvox.com.");const o=i||r();if(!o)throw new Error("No Steam ID available");return t(s,o)},onSuccess:()=>{const i=r();a.setQueriesData({queryKey:["pitvox","registration",n,s]},o=>o?{...o,isRegistered:!1}:{isRegistered:!1,entryList:null}),i&&a.setQueriesData({queryKey:["pitvox","competition",n,s,"entrylist"]},o=>o!=null&&o.drivers?{...o,drivers:o.drivers.filter(l=>l.steamId!==i)}:o)}})}function V(){const{onRegister:s,onWithdraw:t}=k(),n=!!(s&&t);return{isPowerMode:n,isBasicMode:!n}}function K(s){const{pitvoxUrl:t,partnerSlug:n}=k();return`${t}/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 t of ge)if(t.tags.includes(s))return t.id;return"other"}function je(s,t){if(t.size===0)return!0;const n={};for(const r of t){const a=Ze(r);n[a]||(n[a]=[]),n[a].push(r)}for(const r of Object.values(n))if(!r.some(a=>s.includes(a)))return!1;return!0}function fe(s,t){const[n,r]=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&&t?t(c):r(c)},[i,a,t]),l=N.useCallback(()=>{a&&t?t(new Set):r(new Set)},[a,t]);return{activeTags:i,toggle:o,clear:l}}function H(s){const[t,n]=N.useState(s),r=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[t,r]}function Q(s,t,n){return[...s].sort((r,a)=>{const i=n(r,t.key),o=n(a,t.key);if(i==null&&o==null)return 0;if(i==null)return 1;if(o==null)return-1;const l=typeof i=="string"?i.localeCompare(o):i-o;return t.dir==="desc"?-l:l})}function Ne(s,t=!1){const n=t?s==null?void 0:s.filter(r=>r.isValid):s;return n!=null&&n.length?{s1:Math.min(...n.map(r=>r.sector1Ms).filter(Boolean)),s2:Math.min(...n.map(r=>r.sector2Ms).filter(Boolean)),s3:Math.min(...n.map(r=>r.sector3Ms).filter(Boolean))}:null}function Xe({active:s,dir:t}){return s?t==="asc"?e.jsx("svg",{className:"pvx-sort-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 15.75l7.5-7.5 7.5 7.5"})}):e.jsx("svg",{className:"pvx-sort-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 8.25l-7.5 7.5-7.5-7.5"})}):e.jsx("svg",{className:"pvx-sort-icon pvx-sort-icon--inactive",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 9l4-4 4 4M16 15l-4 4-4-4"})})}function R({label:s,sortKey:t,config:n,onSort:r,className:a=""}){return e.jsx("th",{className:`pvx-th pvx-th--sortable ${a}`,onClick:()=>r(t),children:e.jsxs("span",{className:"pvx-th-inner",children:[s,e.jsx(Xe,{active:n.key===t,dir:n.dir})]})})}function O({userId:s,getUserDisplay:t}){const{displayName:n,avatarUrl:r}=t(s);return e.jsxs("span",{className:"pvx-driver",children:[r?e.jsx("img",{src:r,alt:"",className:"pvx-driver-avatar"}):e.jsx("span",{className:"pvx-driver-avatar pvx-driver-avatar--placeholder"}),e.jsx("span",{className:"pvx-driver-name",children:n})]})}function te({rank:s,podium:t=!1}){const n=t?s===1?"pvx-rank pvx-rank--gold":s===2?"pvx-rank pvx-rank--silver":s===3?"pvx-rank pvx-rank--bronze":"pvx-rank":"pvx-rank";return e.jsx("span",{className:n,children:s})}function be({availableTags:s,activeTags:t,onToggle:n,onClear:r}){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:r,className:`pvx-tag ${t.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 ${t.has(l)?"pvx-tag--active":""}`,children:Ye[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((t,n)=>{const r=n===s.length-1;return e.jsxs("li",{className:"pvx-breadcrumb-item",children:[n>0&&e.jsx("svg",{className:"pvx-breadcrumb-chevron",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.25 4.5l7.5 7.5-7.5 7.5"})}),!r&&t.onClick?e.jsx("button",{onClick:t.onClick,className:"pvx-breadcrumb-link",children:t.label}):e.jsx("span",{className:"pvx-breadcrumb-current",children:t.label})]},t.key)})})})}function U({message:s}){return e.jsxs("div",{className:"pvx-empty",children:[e.jsx("svg",{className:"pvx-empty-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.5 18.75h-9m9 0a3 3 0 013 3h-15a3 3 0 013-3m9 0v-4.5A3.375 3.375 0 0013.125 10.875h-2.25A3.375 3.375 0 007.5 14.25v4.5"})}),e.jsx("p",{children:s})]})}function E(){return e.jsx("div",{className:"pvx-loading",children:"Loading..."})}function 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 ts({tracks:s,isLoading:t,carMetadata:n,getUserDisplay:r,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 t?e.jsx(E,{}):s!=null&&s.length?e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx("h2",{className:"pvx-card-title",children:"Track Records"})}),e.jsx(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:r}):"-"}),e.jsx("td",{className:"pvx-td pvx-hidden-below-lg",children:((j=h.record)==null?void 0:j.carDisplayName)||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:h.record?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 rs({entries:s,isLoading:t,track:n,carMetadata:r,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=r==null?void 0:r.tags)!=null&&b.length))return[];const p=new Set;for(const C of s)(((T=(w=r.cars)==null?void 0:w[C.carId])==null?void 0:T.tags)||["sports_car"]).forEach(A=>p.add(A));return r.tags.filter(C=>p.has(C))},[s,r]),h=N.useMemo(()=>s?v.size===0?s:s.filter(p=>{var w,T;const b=((T=(w=r==null?void 0:r.cars)==null?void 0:w[p.carId])==null?void 0:T.tags)||["sports_car"];return je(b,v)}):[],[s,v,r]),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 t?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(re,{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(te,{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:t,track:n,carId:r,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(r)}];return t?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(re,{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(te,{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:t,carId:n,game:r,gameVersion:a,showInvalid:i,getUserDisplay:o,onToggleInvalid:l,onNavigate:u}){const{data:c,driverName:m,theoreticalBest:v,isLoading:g}=ue(s,t.id,t.layout,n,{showInvalid:i,game:r,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:t.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(re,{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:t,getUserDisplay:n,game:r,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(t)return e.jsx(E,{});if(!(s!=null&&s.length))return e.jsx("div",{className:"pvx-card",children:e.jsx(U,{message:"Not enough data for rankings yet."})});const v=5;return e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header pvx-rankings-header",children:[e.jsx("h2",{className:"pvx-card-title",children:"Driver Rankings"}),e.jsxs("div",{className:"pvx-rankings-info-trigger",children:[e.jsx("svg",{className:"pvx-rankings-info-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"})}),e.jsxs("div",{className:"pvx-rankings-info-tooltip",children:[e.jsx("p",{className:"pvx-rankings-info-title",children:"How ratings work"}),e.jsxs("ul",{className:"pvx-rankings-info-list",children:[e.jsx("li",{children:"For each car/track combo with 3+ drivers, you're ranked by lap time and given a percentile (100 = fastest, 0 = slowest)"}),e.jsx("li",{children:"Your rating is a weighted average across all your combos — bigger fields count more"}),e.jsx("li",{children:"A confidence adjustment rewards car diversity: the more different cars you drive competitively, the closer your rating reflects your true score"}),e.jsx("li",{children:"Minimum 2 qualifying combos required"})]})]})]})]}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx(R,{label:"#",sortKey:"rank",config:o,onSort: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:r,gameVersion:a,onComboSelect:i},g.identifier)})})]})})]})}function os({driver:s,getUserDisplay:t,isExpanded:n,onToggle:r,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:r,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(te,{rank:s.rank,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(O,{userId:u,getUserDisplay:t})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:s.rating.toFixed(1)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:s.distinctCars||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:e.jsxs("span",{className:"pvx-rankings-combo-count",children:[s.comboCount,e.jsx("svg",{className:`pvx-rankings-chevron ${n?"pvx-rankings-chevron--open":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})})]}),n&&s.combos&&e.jsx("tr",{children:e.jsx("td",{colSpan:a,className:"pvx-rankings-combos-cell",children:e.jsx("div",{className:"pvx-rankings-combos",children:s.combos.map((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 t=s===1?"pvx-rank pvx-rank--gold":s===2?"pvx-rank pvx-rank--silver":s===3?"pvx-rank pvx-rank--bronze":"pvx-rank";return e.jsx("span",{className:t,children:s})}function ke({nation:s}){const t=s&&cs[s];return t?e.jsx("span",{className:"pvx-nation-flag",title:s,children:t}):null}function ds({sessions:s,activeSession:t,onSelect:n}){if(!s||s.length<=1)return null;const r=[...s].sort((a,i)=>oe.indexOf(a.type)-oe.indexOf(i.type));return e.jsx("div",{className:"pvx-session-tabs",children:r.map(a=>e.jsx("button",{onClick:()=>n(a.type),className:`pvx-session-tab ${t===a.type?"pvx-session-tab--active":""}`,children: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:t="default"}){return e.jsx("span",{className:`pvx-info-pill ${t!=="default"?`pvx-info-pill--${t}`:""}`,children:s})}function ps(s){if(!s)return"TBD";const t=new Date(s);if(isNaN(t))return"TBD";const n=t.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),r=t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return`${n} • ${r}`}function xs(s){return s.reduce((t,n)=>{var r;return(r=n.splits)!=null&&r.length?t?t.map((a,i)=>{const o=n.splits[i];return o&&o<a?o:a}):[...n.splits]:t},null)}function 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:t,onSelect:n,onRegister:r,className:a}){return t?e.jsx(I,{message:"Loading competitions..."}):s!=null&&s.length?e.jsx("div",{className:`pvx-comp-grid ${a||""}`,children:s.map(i=>e.jsx(we,{comp:i,onSelect:n,onRegister:r||n},i.id))}):e.jsx($,{message:"No competitions available."})}function we({comp:s,onSelect:t,onRegister:n}){var h,d,j;const{cdnUrl:r}=k(),a=s.posterCdnPath?`${r}/${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:()=>t(s.id),role:"button",tabIndex:0,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),t(s.id))},children:[e.jsx("div",{className:"pvx-comp-card-poster",children:a?e.jsx("img",{src:a,alt:s.name,className:"pvx-comp-card-poster-img"}):e.jsx("div",{className:"pvx-comp-card-poster-placeholder",children:e.jsx(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:t,isFull:n,deadlinePassed:r,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"}):t?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:t}){var l,u;const{data:n,isLoading:r}=me(s),{data:a,isLoading:i}=Z(s);if(r||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 ${t||""}`,children:[e.jsx("div",{className:"pvx-card-header--split",children:e.jsxs("div",{className:"pvx-card-header-left",children:[e.jsx("h3",{className:"pvx-card-title",children:"Championship Standings"}),e.jsxs("span",{className:"pvx-standings-subtitle",children:["After ",n.roundsCompleted," round",n.roundsCompleted!==1?"s":"",n.countingRounds>0&&` (best ${n.countingRounds} count)`]})]})}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"W"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"Pod"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"}),o.map(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:t}){var o,l,u;const n=s.position<=3,r=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}),t.map(c=>{const m=r.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:t,className:n}){var u;const{data:r,isLoading:a}=ve(s,t);if(a)return e.jsx(I,{message:"Loading results..."});if(!r)return e.jsx($,{message:"No results for this round."});const o=(r.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 ",r.roundNumber,r.track?`: ${r.track}`:""]}),r.startTime&&e.jsx("p",{className:"pvx-round-results-date",children:new Date(r.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(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:r})]})}function ae({round:s,className:t}){var l,u;const[n,r]=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:t||"",children:[e.jsx(ds,{sessions:a,activeSession:i,onSelect:r}),e.jsx(js,{session:o})]})}function js({session:s}){var r;const t=s.type==="RACE";if(!((r=s.results)!=null&&r.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"}),t&&e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Laps"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Time / Gap"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"})]})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.results.map((a,i)=>e.jsx(fs,{result:a,isRace:t,fastestSplits:n,rowIndex:i},a.driverId||i))})]})})}function fs({result:s,isRace:t,fastestSplits:n,rowIndex:r}){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:r<=1})}),t&&e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:s.lapsCompleted}),e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:s.position===1?s.totalTime||"-":s.gap||"-"}),e.jsxs("td",{className:"pvx-td pvx-td--center",children:[e.jsx("span",{className:"pvx-session-points",children:s.points}),s.pointsOverride!==0&&s.pointsOverride&&e.jsxs("span",{className:"pvx-points-override",children:["(",s.pointsOverride>0?"+":"",s.pointsOverride,")"]})]})]})]})}function Ns({bestLap:s,hasBestLap:t,splits:n,fastestSplits:r,showAbove:a}){return s?e.jsxs("span",{className:`pvx-best-lap-cell ${t?"pvx-best-lap-cell--fastest":""}`,children:[e.jsx("span",{className:"pvx-best-lap-time",children:s}),(n==null?void 0:n.length)>0&&e.jsx("span",{className:"pvx-splits-tooltip-anchor",children:e.jsx("span",{className:`pvx-splits-tooltip ${a?"":"pvx-splits-tooltip--above"}`,children:n.map((i,o)=>{const l=r&&i===r[o];return e.jsxs("span",{className:"pvx-splits-tooltip-row",children:[e.jsxs("span",{className:"pvx-splits-tooltip-label",children:["S",o+1]}),e.jsx("span",{className:l?"pvx-splits-tooltip-best":"",children:i})]},o)})})})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})}function bs({competitionId:s,className:t}){const{getSteamId:n}=k(),{data:r,isLoading:a}=X(s),i=n();if(a)return e.jsx(I,{message:"Loading drivers..."});const o=(r==null?void 0:r.drivers)||(r==null?void 0:r.entries)||[];return o.length?e.jsx("div",{className:`pvx-entry-grid ${t||""}`,children:o.map(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:t,className:n,children:r}){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(t||{})},f=()=>{o&&c.mutate()};return typeof r=="function"?r({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:t,onWithdrawSuccess:n,className:r}){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=t||{},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 ${r||""}`,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 ${r||""}`,children:e.jsx(Cs,{competitionId:s,registerMutation:v,registration:d})}):e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Register on PitVox"})}):e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:i?e.jsx("div",{className:"pvx-reg-status-msg",children:"Sign in to register for this competition."}):e.jsx("div",{className:"pvx-reg-status-msg",children:e.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Register on PitVox"})})}):e.jsxs("div",{className:`pvx-reg-panel ${r||""}`,children:[e.jsx("div",{className:"pvx-reg-status-msg",children: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:t,registration:n}){const[r,a]=N.useState(""),[i,o]=N.useState("intermediate"),[l,u]=N.useState(""),c=x=>{x.preventDefault(),t.mutate({discordUsername:r||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})]}),t.error&&e.jsx("div",{className:"pvx-reg-error",children:t.error.message||"Registration failed"}),e.jsxs("div",{className:"pvx-reg-field",children:[e.jsxs("label",{className:"pvx-reg-label",htmlFor:`pvx-discord-${s}`,children:["Discord Username ",e.jsx("span",{className:"pvx-reg-optional",children:"(optional)"})]}),e.jsx("input",{id:`pvx-discord-${s}`,type:"text",className:"pvx-reg-input",placeholder:"e.g. username",value:r,onChange:x=>a(x.target.value)})]}),e.jsxs("div",{className:"pvx-reg-field",children:[e.jsx("label",{className:"pvx-reg-label",htmlFor:`pvx-exp-${s}`,children:"Experience Level"}),e.jsxs("select",{id:`pvx-exp-${s}`,className:"pvx-reg-select",value:i,onChange:x=>o(x.target.value),children:[e.jsx("option",{value:"beginner",children:"Beginner"}),e.jsx("option",{value:"intermediate",children:"Intermediate"}),e.jsx("option",{value:"advanced",children:"Advanced"})]})]}),e.jsxs("div",{className:"pvx-reg-field",children:[e.jsxs("label",{className:"pvx-reg-label",htmlFor:`pvx-comments-${s}`,children:["Comments ",e.jsx("span",{className:"pvx-reg-optional",children:"(optional)"})]}),e.jsx("textarea",{id:`pvx-comments-${s}`,className:"pvx-reg-textarea",rows:3,placeholder:"Anything the organisers should know?",value: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:t.isPending,children:t.isPending?"Registering...":"Register"})})]})}function ws({competitionId:s,drivers:t,steamId:n,isPowerMode:r,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=t.length||v.currentCount||0,x=v.maxParticipants;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pvx-reg-form-header",children:[e.jsx("h3",{className:"pvx-reg-form-title",children:"Registered Drivers"}),x&&e.jsx(Te,{count:g,max:x})]}),e.jsx(Re,{drivers:t,steamId:n}),i.error&&e.jsx("div",{className:"pvx-reg-error",children:i.error.message||"Withdrawal failed"}),r?e.jsx("div",{className:"pvx-reg-actions",children: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:t}){if(!s.length)return e.jsx("div",{className:"pvx-reg-no-drivers",children:"No drivers registered yet."});const n=[...s].sort((r,a)=>{const i=t&&r.steamId===t?-1:0,o=t&&a.steamId===t?-1:0;return i-o});return e.jsx("div",{className:"pvx-reg-driver-list",children:n.map(r=>{var i,o;const a=t&&r.steamId===t;return e.jsxs("div",{className:`pvx-reg-driver-row ${a?"pvx-reg-driver-row--you":""}`,children:[r.avatarUrl?e.jsx("img",{src:r.avatarUrl,alt:"",className:"pvx-reg-driver-avatar"}):e.jsx("div",{className:"pvx-reg-driver-avatar pvx-reg-driver-avatar--placeholder",children:((o=(i=r.displayName)==null?void 0:i.charAt(0))==null?void 0:o.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-reg-driver-name",children:[r.displayName,a&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},r.steamId||r.driverId)})})}function Te({count:s,max:t}){const n=t?s/t*100:0,r=n>=100?"full":n>=75?"warning":"ok";return e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${r}`,children:[s,"/",t," drivers"]})}function Ls({competitionId:s,className:t}){const{data:n,isLoading:r}=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(r||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:null});const h=x.get(g);return e.jsxs("div",{className:t||"",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"),r=(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-card-header--split",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"pvx-card-title",children:["Round ",s.roundNumber,s.track?`: ${s.track}`:""]}),s.startTime&&e.jsx("span",{className:"pvx-standings-subtitle",children:new Date(s.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(r==null?void 0:r.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:r.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:t}=k(),n=y.useQuery({queryKey:["pitvox","laps","global",s],queryFn:()=>L(t,`laps/${s}.json`),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),r=n.data;return{isLoading:n.isLoading,error:n.error,data:r?{driverName:r.driverName||"Driver",lapCount:r.lapCount||0,trackBreakdown:r.trackBreakdown||[],carBreakdown:r.carBreakdown||[],recordsHeld:r.recordsHeld||0,currentRecords:r.currentRecords||[],bestRanking:r.bestRanking??null,bestRankingTrackId:r.bestRankingTrackId??null,bestRankingLayout:r.bestRankingLayout??null,bestRankingCarId:r.bestRankingCarId??null,generatedAt:r.generatedAt}:null}}function Me(s={}){const{cdnUrl:t,partnerSlug:n}=k(),{gameVersion:r,enabled:a=!0}=s,i=r?`v/${r}/`:"",o=q(n,`${i}ratings.json`);return y.useQuery({queryKey:["pitvox","ratings",n,r||null],queryFn:()=>L(t,o),staleTime:3e4,refetchInterval:3e4,enabled:a})}function $e(s){var r;const t=Me(),n=N.useMemo(()=>{var a;return!((a=t.data)!=null&&a.drivers)||!s?null:t.data.drivers.find(i=>i.identifier===s)||null},[(r=t.data)==null?void 0:r.drivers,s]);return{isLoading:t.isLoading,error:t.error,data:n?{rating:n.rating,rank:n.rank,totalDrivers:t.data.driverCount||t.data.drivers.length,comboCount:n.comboCount||0,distinctCars:n.distinctCars||0,combos:n.combos||[]}:null}}function Ts(s={}){const t=Me(s);return{data:t.data||null,isLoading:t.isLoading,error:t.error}}function De(){const{cdnUrl:s,partnerSlug:t,getSteamId:n,onFetchServerPassword:r}=k(),a=n(),{data:i,isLoading:o}=y.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const x=await L(s,"competitions/index.json");return x!=null&&x.competitions?x.competitions.filter(f=>f.partnerSlug===t):[]},staleTime:6e4}),l=(i==null?void 0:i.map(x=>x.id))||[],u=y.useQueries({queries:l.map(x=>({queryKey:["pitvox","competition",t,x,"entrylist"],queryFn:()=>L(s,`competitions/${t}/${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:()=>r(x.competitionId,x.roundNumber),enabled:!!r&&m.length>0,staleTime:5*6e4,retry:!1}))});return{data:N.useMemo(()=>m.length?r?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,r,v]),isLoading:o||!!a&&c}}function Ie(){const{onFetchNotifications:s}=k();return!!s}function Pe(s={}){const{onFetchNotifications:t,partnerSlug:n}=k(),{limit:r=20,unreadOnly:a=!1}=s;return y.useQuery({queryKey:["pitvox","notifications",n,{limit:r,unreadOnly:a}],queryFn:()=>t({limit:r,unreadOnly:a}),enabled:!!t,staleTime:3e4,refetchInterval:3e4})}function Ss(){const{onFetchNotifications:s,partnerSlug:t}=k(),{data:n,isLoading:r}=y.useQuery({queryKey:["pitvox","notifications",t,{limit:1,unreadOnly:!1}],queryFn:()=>s({limit:1}),enabled:!!s,staleTime:3e4,refetchInterval:3e4,select:a=>(a==null?void 0:a.unreadCount)??0});return{count:n??0,isLoading:r}}function Be(){const{onMarkNotificationRead:s,partnerSlug:t}=k(),n=y.useQueryClient();return y.useMutation({mutationFn:r=>{if(!s)throw new Error("No onMarkNotificationRead callback provided to PitVoxPartnerProvider.");return s(r)},onSuccess:(r,a)=>{n.setQueriesData({queryKey:["pitvox","notifications",t]},i=>i!=null&&i.notifications?{...i,unreadCount:Math.max(0,(i.unreadCount||0)-1),notifications:i.notifications.map(o=>o.id===a?{...o,isRead:!0,readAt:new Date().toISOString()}:o)}:i)}})}function Ae(){const{onMarkAllNotificationsRead:s,partnerSlug:t}=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",t]},r=>r!=null&&r.notifications?{...r,unreadCount:0,notifications:r.notifications.map(a=>({...a,isRead:!0,readAt:a.readAt||new Date().toISOString()}))}:r)}})}function Ue({driverName:s,avatarUrl:t,memberSince:n,className:r=""}){const a=n?new Date(n).toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"numeric"}):null;return e.jsxs("div",{className:`pvx-card pvx-dash-profile ${r}`,children:[t?e.jsx("img",{src:t,alt:"",className:"pvx-dash-profile-avatar"}):e.jsx("div",{className:"pvx-dash-profile-avatar pvx-dash-profile-avatar--placeholder",children:(s||"?")[0].toUpperCase()}),e.jsxs("div",{className:"pvx-dash-profile-info",children:[e.jsx("h2",{className:"pvx-dash-profile-name",children:s}),a&&e.jsxs("p",{className:"pvx-dash-profile-since",children:["Racing since ",a]})]})]})}function 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:t,label:n,items:r,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=r!=null&&r.length?r.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:t}),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:t,className:n=""}){if(!s)return null;const r=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:r,labelKey:"name",countKey:"lapCount"}),e.jsx(ce,{icon:e.jsx($s,{}),value:s.carBreakdown.length,label:"Cars Used",items:a,labelKey:"name",countKey:"lapCount"}),t&&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:t.rating.toFixed(1)}),e.jsx("span",{className:"pvx-dash-stat-label",children:"Driver Rating"}),e.jsxs("span",{className:"pvx-dash-stat-sub",children:["#",t.rank," of ",t.totalDrivers]})]})]})]})}function Fe({records:s,className:t=""}){const n=N.useMemo(()=>s!=null&&s.length?s.slice().sort((r,a)=>{const i=r.recordedAt?new Date(r.recordedAt).getTime():0;return(a.recordedAt?new Date(a.recordedAt).getTime():0)-i}):[],[s]);return n.length?e.jsxs("div",{className:`pvx-card ${t}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx("span",{className:"pvx-dash-records-icon",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 010-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 000-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0012 0V2z"})]})}),"Current Records",e.jsxs("span",{className:"pvx-dash-records-count",children:["(",n.length,")"]})]})}),e.jsx("div",{className:"pvx-dash-records-list",children:n.map((r,a)=>e.jsxs("div",{className:"pvx-dash-record-row",children:[e.jsxs("div",{className:"pvx-dash-record-info",children:[e.jsx("span",{className:"pvx-dash-record-track",children:P(r.trackId,r.layout,r.game)}),e.jsx("span",{className:"pvx-dash-record-car",children:S(r.carId)})]}),e.jsxs("div",{className:"pvx-dash-record-time",children:[e.jsx("span",{className:"pvx-dash-record-lap",children:D(r.lapTimeMs)}),e.jsxs("span",{className:`pvx-dash-game-badge pvx-dash-game-badge--${r.game||"evo"}`,children:[(r.game||"evo").toUpperCase(),r.gameVersion?` ${r.gameVersion}`:""]})]})]},a))})]}):null}function qe({events:s,isLoading:t,className:n,limit:r=3}){if(t)return e.jsx("div",{className:"pvx-loading",children:"Loading upcoming events..."});if(!(s!=null&&s.length))return null;const a=r?s.slice(0,r):s,i=s.length-a.length;return e.jsxs("div",{className:`pvx-card ${n||""}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(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:t}){const[n,r]=N.useState(!1),[a,i]=N.useState(!1),o=t?s?`join:${t}|${s}`:`join:${t}`:null,l=N.useCallback(async()=>{if(o)try{await navigator.clipboard.writeText(o),r(!0),setTimeout(()=>r(!1),2e3)}catch{}},[o]);return e.jsxs("div",{className:"pvx-server-info",children:[o&&e.jsxs("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick: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 t=new Date(s).getTime()-Date.now();if(t<=0)return"Now";const n=Math.floor(t/(1e3*60*60));if(n<1)return"Less than 1 hour";if(n<24)return`in ${n}h`;const r=Math.floor(n/24);if(r===1)return"Tomorrow";if(r<7)return`in ${r} days`;if(r<30){const a=Math.floor(r/7);return`in ${a} week${a!==1?"s":""}`}return 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:t=0,onMarkRead:n,onMarkAllRead:r,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",t>0&&e.jsx("span",{className:"pvx-notif-badge",children:t>99?"99+":t})]}),t>0&&r&&e.jsx("button",{className:"pvx-notif-mark-all",onClick:r,children:"Mark all read"})]}),s!=null&&s.length?e.jsx("div",{className:"pvx-notif-list",children:s.map(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:t,onMarkRead:n}){const r=()=>{!s.isRead&&n&&n(s.id)};return e.jsxs("button",{className:`pvx-notif-item ${s.isRead?"":"pvx-notif-item--unread"}`,onClick:r,children:[e.jsx(_s,{type:s.type}),e.jsxs("div",{className:"pvx-notif-content",children:[e.jsx("span",{className:"pvx-notif-message",children:pe(s,t)}),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:t,memberSince:n,className:r=""}){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 ${r}`,children:[e.jsx(Ue,{driverName:a.driverName,avatarUrl:t,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=rs;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=ts;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;
|
|
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:t=Ve,pitvoxUrl:n=Ke,getSteamId:r,onRegister:a,onWithdraw:i,onFetchNotifications:o,onMarkNotificationRead:l,onMarkAllNotificationsRead:u,onFetchServerPassword:c,children:x}){const h=N.useMemo(()=>({partnerSlug:s,cdnUrl:t.replace(/\/$/,""),pitvoxUrl:n.replace(/\/$/,""),getSteamId:r||(()=>null),onRegister:a||null,onWithdraw:i||null,onFetchNotifications:o||null,onMarkNotificationRead:l||null,onMarkAllNotificationsRead:u||null,onFetchServerPassword:c||null}),[s,t,n,r,a,i,o,l,u,c]);let g=!1;try{y.useQueryClient(),g=!0}catch{g=!1}return g?e.jsx(z.Provider,{value:h,children:x}):(W||(W=new y.QueryClient({defaultOptions:{queries:{staleTime:6e4}}})),e.jsx(y.QueryClientProvider,{client:W,children:e.jsx(z.Provider,{value:h,children:x})}))}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,t){const n=await fetch(`${s}/${t}`);if(!n.ok){if(n.status===404||n.status===403)return null;throw new Error(`CDN fetch failed: ${n.status}`)}return n.json()}function q(s,t,n,...r){const a=["leaderboards"];return s&&a.push(`partners/${s}`),t&&a.push(t),n&&a.push(`v/${n}`),[...a,...r].join("/")}function le(s,t){return s?`laps/partners/${s}/${t}.json`:`laps/${t}.json`}function de(s){return s?`recent-laps/partners/${s}.json`:"recent-laps.json"}function D(s){if(!s&&s!==0)return"-";const t=Math.floor(s/1e3),n=Math.floor(t/60),r=t%60,a=s%1e3;return`${n}:${String(r).padStart(2,"0")}.${String(a).padStart(3,"0")}`}function M(s){return!s&&s!==0?"-":s>=6e4?D(s):(s/1e3).toFixed(3)}function S(s){if(!s)return"";let t=s;return t.startsWith("ks_")&&(t=t.slice(3)),t.split("_").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function P(s,t,n){if(!s)return"";const r=s.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" "),a=n==="acc"||!n&&(t==null?void 0:t.toLowerCase())==="track config";if(!t||t==="default"||a)return r;const i=t.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ");return`${r} ${i}`}function 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 t=Date.now()-new Date(s).getTime(),n=Math.floor(t/1e3);if(n<60)return"Just now";const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const a=Math.floor(r/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);return i<30?`${i}d ago`:B(s)}function Qe(s){return s==null?"":`${s>=0?"+":"-"}${(Math.abs(s)/1e3).toFixed(3)}`}function pe(s,t){const{type:n,title:r,trackId:a,trackLayout:i,carId:o,game:l,data:u}=s,c=typeof u=="string"?JSON.parse(u):u,x=a?P(a,i,l):null,h=o?S(o):null,g=[x,h].filter(Boolean).join(" — ");return n==="RECORD_BEATEN"&&g?`${c!=null&&c.beatenBySteamId&&t?t(c.beatenBySteamId).displayName:"Someone"} beat your record on ${g}`:n==="RECORD_SET"&&g?`You set a new record on ${g}`:r||"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,x,h,g,p;const{cdnUrl:t,partnerSlug:n}=k(),{game:r,gameVersion:a}=s,i=q(n,null,null,"index.json"),o=y.useQuery({queryKey:["pitvox","leaderboards",n,"index"],queryFn:()=>L(t,i),staleTime:3e4,refetchInterval:3e4}),l=N.useMemo(()=>{var v;if(!((v=o.data)!=null&&v.tracks))return[];let f=o.data.tracks;return r&&(f=f.filter(d=>d.game===r)),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,r,a]);return{...o,data:l,partner:((c=o.data)==null?void 0:c.partner)||null,generatedAt:(x=o.data)==null?void 0:x.generatedAt,totalLaps:((h=o.data)==null?void 0:h.totalLaps)||0,totalUsers:((g=o.data)==null?void 0:g.totalUsers)||0,versions:((p=o.data)==null?void 0:p.versions)||{}}}function xe(s,t,n={}){const{cdnUrl:r,partnerSlug:a}=k(),{carId:i,game:o,gameVersion:l}=n,u=t||"default",c=q(a,o,l,`tracks/${s}/${u}.json`),{data:x,isLoading:h,error:g}=y.useQuery({queryKey:["pitvox","leaderboards",a,"track",s,u,o,l],queryFn:()=>L(r,c),enabled:!!s,staleTime:3e4,refetchInterval:3e4});return{data:N.useMemo(()=>{if(!(x!=null&&x.entries))return[];let f=x.entries;if(o&&(f=f.filter(v=>v.game===o)),!i){const v=new Map,d=new Map;for(const j of f){const m=j.steamId||j.userId;d.has(j.carId)||d.set(j.carId,new Set),d.get(j.carId).add(m),(!v.has(j.carId)||j.lapTimeMs<v.get(j.carId).lapTimeMs)&&v.set(j.carId,j)}return Array.from(v.values()).map(j=>{var m;return{...j,driverCount:((m=d.get(j.carId))==null?void 0:m.size)||0}}).sort((j,m)=>j.lapTimeMs-m.lapTimeMs)}return f.filter(v=>v.carId===i).sort((v,d)=>v.lapTimeMs-d.lapTimeMs)},[x==null?void 0:x.entries,i,o]),isLoading:h,error:g}}function ue(s,t,n,r,a={}){var f,v;const{cdnUrl:i,partnerSlug:o}=k(),{showInvalid:l=!1,game:u,gameVersion:c}=a,x=le(o,s),h=y.useQuery({queryKey:["pitvox","laps",o,s],queryFn:()=>L(i,x),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),g=N.useMemo(()=>{var d;return(d=h.data)!=null&&d.laps?h.data.laps.filter(j=>{if(j.trackId!==t)return!1;if(n){if(j.trackLayout!==n)return!1}else if(j.trackLayout&&j.trackLayout!=="default")return!1;return!(j.carId!==r||u&&j.game!==u||c&&j.gameVersion!==c||!l&&!j.isValid)}).sort((j,m)=>j.lapTimeMs-m.lapTimeMs):[]},[(f=h.data)==null?void 0:f.laps,t,n,r,u,c,l]),p=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)),m=Math.min(...d.map(C=>C.sector2Ms)),b=Math.min(...d.map(C=>C.sector3Ms)),w=j+m+b,T=Math.min(...d.map(C=>C.lapTimeMs));return w>=T?null:{lapTimeMs:w,sector1Ms:j,sector2Ms:m,sector3Ms:b}},[g]);return{...h,data:g,driverName:((v=h.data)==null?void 0:v.driverName)||"Driver",theoreticalBest:p}}function Y(){const{cdnUrl:s}=k(),{data:t}=y.useQuery({queryKey:["pitvox","users","index"],queryFn:()=>L(s,"users/index.json"),staleTime:5*6e4,gcTime:30*6e4}),n=(t==null?void 0:t.users)||{};return(r,a)=>{const i=n[r];return{displayName:(i==null?void 0:i.displayName)||a||r||"Unknown",avatarUrl:(i==null?void 0:i.avatarUrl)||null,affiliations:(i==null?void 0:i.affiliations)||[]}}}function We(){const{cdnUrl:s}=k(),{data:t}=y.useQuery({queryKey:["pitvox","cars","evo"],queryFn:()=>L(s,"cars/evo.json"),staleTime:5*6e4,gcTime:30*6e4});return{tags:(t==null?void 0:t.tags)||[],cars:(t==null?void 0:t.cars)||{}}}function ze(){var a,i;const{cdnUrl:s,partnerSlug:t}=k(),n=de(t),r=y.useQuery({queryKey:["pitvox","recentLaps",t],queryFn:()=>L(s,n),staleTime:3e4,refetchInterval:3e4,gcTime:10*6e4});return{groups:((a=r.data)==null?void 0:a.groups)||[],generatedAt:((i=r.data)==null?void 0:i.generatedAt)||null,isLoading:r.isLoading}}function Ge(s,t){return xe(s,null,{carId:t})}function Je(){const{cdnUrl:s,partnerSlug:t}=k();return y.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const n=await L(s,"competitions/index.json");return n!=null&&n.competitions?t?n.competitions.filter(r=>r.partnerSlug===t):n.competitions:[]},staleTime:6e4})}function Z(s,t={}){const n=k(),r=t.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",r,s,"config"],queryFn:()=>L(n.cdnUrl,`competitions/${r}/${s}/config.json`),enabled:!!r&&!!s,staleTime:6e4})}function me(s,t={}){const n=k(),r=t.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",r,s,"standings"],queryFn:()=>L(n.cdnUrl,`competitions/${r}/${s}/standings.json`),enabled:!!r&&!!s,staleTime:6e4})}function ve(s,t,n={}){const r=k(),a=n.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"round",t],queryFn:()=>L(r.cdnUrl,`competitions/${a}/${s}/rounds/${t}.json`),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function he(s,t=[],n={}){const r=k(),a=n.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"allRounds",t],queryFn:async()=>(await Promise.all(t.map(o=>L(r.cdnUrl,`competitions/${a}/${s}/rounds/${o}.json`).catch(()=>null)))).filter(Boolean),enabled:!!a&&!!s&&t.length>0,staleTime:6e4})}function X(s,t={}){const n=k(),r=t.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",r,s,"entrylist"],queryFn:()=>L(n.cdnUrl,`competitions/${r}/${s}/entrylist.json`),enabled:!!r&&!!s,staleTime:6e4})}function _(s){const{cdnUrl:t,partnerSlug:n,getSteamId:r}=k(),a=r();return y.useQuery({queryKey:["pitvox","registration",n,s,a],queryFn:async()=>{var u;const i=await fetch(`${t}/competitions/${n}/${s}/entrylist.json`);if(!i.ok)return{isRegistered:!1,entryList:null};const o=await i.json();return{isRegistered:!!a&&((u=o.drivers)==null?void 0:u.some(c=>c.steamId===a)),entryList:o}},enabled:!!s,staleTime:6e4})}function ee(s){const{onRegister:t,partnerSlug:n,getSteamId:r}=k(),a=y.useQueryClient(),i=Y();return y.useMutation({mutationFn:o=>{if(!t)throw new Error("No onRegister callback provided to PitVoxPartnerProvider. Provide onRegister for in-app registration, or use useRegistrationUrl() to link to pitvox.com.");return t(s,o)},onSuccess:()=>{const o=r();if(a.setQueriesData({queryKey:["pitvox","registration",n,s]},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 h;return c?((h=c.drivers)==null?void 0:h.some(g=>g.steamId===o))?c:{...c,drivers:[...c.drivers||[],u]}:{drivers:[u]}})}}})}function se(s){const{onWithdraw:t,partnerSlug:n,getSteamId:r}=k(),a=y.useQueryClient();return y.useMutation({mutationFn:i=>{if(!t)throw new Error("No onWithdraw callback provided to PitVoxPartnerProvider. Provide onWithdraw for in-app withdrawal, or use useRegistrationUrl() to link to pitvox.com.");const o=i||r();if(!o)throw new Error("No Steam ID available");return t(s,o)},onSuccess:()=>{const i=r();a.setQueriesData({queryKey:["pitvox","registration",n,s]},o=>o?{...o,isRegistered:!1}:{isRegistered:!1,entryList:null}),i&&a.setQueriesData({queryKey:["pitvox","competition",n,s,"entrylist"]},o=>o!=null&&o.drivers?{...o,drivers:o.drivers.filter(l=>l.steamId!==i)}:o)}})}function V(){const{onRegister:s,onWithdraw:t}=k(),n=!!(s&&t);return{isPowerMode:n,isBasicMode:!n}}function K(s){const{pitvoxUrl:t,partnerSlug:n}=k();return`${t}/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 t of ge)if(t.tags.includes(s))return t.id;return"other"}function je(s,t){if(t.size===0)return!0;const n={};for(const r of t){const a=Ze(r);n[a]||(n[a]=[]),n[a].push(r)}for(const r of Object.values(n))if(!r.some(a=>s.includes(a)))return!1;return!0}function fe(s,t){const[n,r]=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&&t?t(c):r(c)},[i,a,t]),l=N.useCallback(()=>{a&&t?t(new Set):r(new Set)},[a,t]);return{activeTags:i,toggle:o,clear:l}}function H(s){const[t,n]=N.useState(s),r=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[t,r]}function Q(s,t,n){return[...s].sort((r,a)=>{const i=n(r,t.key),o=n(a,t.key);if(i==null&&o==null)return 0;if(i==null)return 1;if(o==null)return-1;const l=typeof i=="string"?i.localeCompare(o):i-o;return t.dir==="desc"?-l:l})}function Ne(s,t=!1){const n=t?s==null?void 0:s.filter(r=>r.isValid):s;return n!=null&&n.length?{s1:Math.min(...n.map(r=>r.sector1Ms).filter(Boolean)),s2:Math.min(...n.map(r=>r.sector2Ms).filter(Boolean)),s3:Math.min(...n.map(r=>r.sector3Ms).filter(Boolean))}:null}function Xe({active:s,dir:t}){return s?t==="asc"?e.jsx("svg",{className:"pvx-sort-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 15.75l7.5-7.5 7.5 7.5"})}):e.jsx("svg",{className:"pvx-sort-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 8.25l-7.5 7.5-7.5-7.5"})}):e.jsx("svg",{className:"pvx-sort-icon pvx-sort-icon--inactive",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 9l4-4 4 4M16 15l-4 4-4-4"})})}function R({label:s,sortKey:t,config:n,onSort:r,className:a=""}){return e.jsx("th",{className:`pvx-th pvx-th--sortable ${a}`,onClick:()=>r(t),children:e.jsxs("span",{className:"pvx-th-inner",children:[s,e.jsx(Xe,{active:n.key===t,dir:n.dir})]})})}function O({userId:s,getUserDisplay:t}){const{displayName:n,avatarUrl:r}=t(s);return e.jsxs("span",{className:"pvx-driver",children:[r?e.jsx("img",{src:r,alt:"",className:"pvx-driver-avatar"}):e.jsx("span",{className:"pvx-driver-avatar pvx-driver-avatar--placeholder"}),e.jsx("span",{className:"pvx-driver-name",children:n})]})}function te({rank:s,podium:t=!1}){const n=t?s===1?"pvx-rank pvx-rank--gold":s===2?"pvx-rank pvx-rank--silver":s===3?"pvx-rank pvx-rank--bronze":"pvx-rank":"pvx-rank";return e.jsx("span",{className:n,children:s})}function be({availableTags:s,activeTags:t,onToggle:n,onClear:r}){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:r,className:`pvx-tag ${t.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 ${t.has(l)?"pvx-tag--active":""}`,children:Ye[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((t,n)=>{const r=n===s.length-1;return e.jsxs("li",{className:"pvx-breadcrumb-item",children:[n>0&&e.jsx("svg",{className:"pvx-breadcrumb-chevron",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.25 4.5l7.5 7.5-7.5 7.5"})}),!r&&t.onClick?e.jsx("button",{onClick:t.onClick,className:"pvx-breadcrumb-link",children:t.label}):e.jsx("span",{className:"pvx-breadcrumb-current",children:t.label})]},t.key)})})})}function U({message:s}){return e.jsxs("div",{className:"pvx-empty",children:[e.jsx("svg",{className:"pvx-empty-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.5 18.75h-9m9 0a3 3 0 013 3h-15a3 3 0 013-3m9 0v-4.5A3.375 3.375 0 0013.125 10.875h-2.25A3.375 3.375 0 007.5 14.25v4.5"})}),e.jsx("p",{children:s})]})}function E(){return e.jsx("div",{className:"pvx-loading",children:"Loading..."})}function 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 ts({tracks:s,isLoading:t,carMetadata:n,getUserDisplay:r,onTrackSelect:a,tags:i,onTagChange:o}){const[l,u]=H({key:"record.timestamp",dir:"desc"}),{activeTags:c,toggle:x,clear:h}=fe(i,o),g=N.useMemo(()=>{var d;if(!((d=n==null?void 0:n.tags)!=null&&d.length))return[];const v=new Set;for(const j of s||[])j.recordByTag&&Object.keys(j.recordByTag).forEach(m=>v.add(m));return n.tags.filter(j=>v.has(j))},[s,n]),p=N.useMemo(()=>s?c.size===0?s:s.map(v=>{var m,b;if(!v.recordByTag)return null;let d=null;const j=new Set;for(const w of Object.values(v.recordByTag)){if(j.has(w.carId))continue;j.add(w.carId);const T=((b=(m=n==null?void 0:n.cars)==null?void 0:m[w.carId])==null?void 0:b.tags)||["sports_car"];je(T,c)&&(!d||w.lapTimeMs<d.lapTimeMs)&&(d=w)}return d?{...v,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(p,l,(v,d)=>{var j,m;switch(d){case"displayName":return v.displayName;case"record.lapTimeMs":return(j=v.record)==null?void 0:j.lapTimeMs;case"driverCount":return v.driverCount||0;case"carCount":return v.carCount||0;case"record.timestamp":default:return(m=v.record)!=null&&m.timestamp?new Date(v.record.timestamp).getTime():0}}),[p,l]);return t?e.jsx(E,{}):s!=null&&s.length?e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx("h2",{className:"pvx-card-title",children:"Track Records"})}),e.jsx(be,{availableTags:g,activeTags:c,onToggle:x,onClear:h}),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(v=>{var d,j,m;return e.jsxs("tr",{className:"pvx-row pvx-row--clickable",onClick:()=>a(v.id,v.layout),children:[e.jsx("td",{className:"pvx-td pvx-td--primary",children:v.displayName}),e.jsx("td",{className:"pvx-td",children:(d=v.record)!=null&&d.visibleId?e.jsx(O,{userId:v.record.visibleId,getUserDisplay:r}):"-"}),e.jsx("td",{className:"pvx-td pvx-hidden-below-lg",children:((j=v.record)==null?void 0:j.carDisplayName)||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:v.record?D(v.record.lapTimeMs):"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-md",children:v.driverCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:v.carCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:(m=v.record)!=null&&m.timestamp?B(v.record.timestamp):"-"})]},`${v.id}|${v.layout||""}`)})})]})})]}):e.jsx(U,{message:"No lap times recorded yet."})}function rs({entries:s,isLoading:t,track:n,carMetadata:r,getUserDisplay:a,onCarSelect:i,onNavigate:o,tags:l,onTagChange:u}){const[c,x]=H({key:"lapTimeMs",dir:"asc"}),{activeTags:h,toggle:g,clear:p}=fe(l,u),f=N.useMemo(()=>{var b,w,T;if(!s||!((b=r==null?void 0:r.tags)!=null&&b.length))return[];const m=new Set;for(const C of s)(((T=(w=r.cars)==null?void 0:w[C.carId])==null?void 0:T.tags)||["sports_car"]).forEach(A=>m.add(A));return r.tags.filter(C=>m.has(C))},[s,r]),v=N.useMemo(()=>s?h.size===0?s:s.filter(m=>{var w,T;const b=((T=(w=r==null?void 0:r.cars)==null?void 0:w[m.carId])==null?void 0:T.tags)||["sports_car"];return je(b,h)}):[],[s,h,r]),d=N.useMemo(()=>Q(v,c,(m,b)=>{switch(b){case"carId":return S(m.carId);case"driverCount":return m.driverCount||0;case"lapTimeMs":default:return m.lapTimeMs}}),[v,c]),j=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:n.displayName}];return t?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(re,{segments:j})}),e.jsx(be,{availableTags:f,activeTags:h,onToggle:g,onClear:p}),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:x}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:c,onSort:x}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:c,onSort:x,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((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(te,{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:D(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?B(m.recordedAt):"-"})]},m.carId))})]})}):e.jsx(U,{message:"No lap times for this track yet."})]})}function ns({entries:s,isLoading:t,track:n,carId:r,getUserDisplay:a,onDriverSelect:i,onNavigate:o,highlightId:l}){const[u,c]=H({key:"lapTimeMs",dir:"asc"}),x=N.useMemo(()=>Ne(s),[s]),h=N.useMemo(()=>Q(s||[],u,(p,f)=>{switch(f){case"userId":return a(p.steamId||p.userId).displayName;case"lapCount":return p.lapCount||0;case"lapTimeMs":default:return p.lapTimeMs}}),[s,u,a]),g=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:n.displayName,onClick:()=>o("track")},{key:"car",label:S(r)}];return t?e.jsx(E,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(re,{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:h.map((p,f)=>{const v=f+1,d=p.steamId||p.userId,j=x&&p.sector1Ms===x.s1,m=x&&p.sector2Ms===x.s2,b=x&&p.sector3Ms===x.s3,w=l&&d===l;return e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${w?"pvx-row--highlight":v<=3?"pvx-row--podium":""}`,onClick:()=>i(d),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(te,{rank:v,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(p.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${j?"pvx-td--best-sector":""}`,children:M(p.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${m?"pvx-td--best-sector":""}`,children:M(p.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${b?"pvx-td--best-sector":""}`,children:M(p.sector3Ms)}),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-xl",children:p.startingFuelL?`${p.startingFuelL}L`:"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:p.lapCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:p.recordedAt?B(p.recordedAt):"-"})]},d)})})]})}):e.jsx(U,{message:"No lap times for this car yet."})]})}function as({userId:s,track:t,carId:n,game:r,gameVersion:a,showInvalid:i,getUserDisplay:o,onToggleInvalid:l,onNavigate:u}){const{data:c,driverName:x,theoreticalBest:h,isLoading:g}=ue(s,t.id,t.layout,n,{showInvalid:i,game:r,gameVersion:a}),{displayName:p,avatarUrl:f}=o(s,x),v=N.useMemo(()=>Ne(c,!0),[c]),d=N.useMemo(()=>{const m=(c==null?void 0:c.filter(b=>b.isValid))||[];return m.length?Math.min(...m.map(b=>b.lapTimeMs)):null},[c]),j=[{key:"tracks",label:"Tracks",onClick:()=>u("tracks")},{key:"track",label:t.displayName,onClick:()=>u("track")},{key:"car",label:S(n),onClick:()=>u("car")},{key:"driver",label:p}];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(re,{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"})]})]}),h&&e.jsxs("div",{className:"pvx-theoretical-best",children:[e.jsx("span",{className:"pvx-theoretical-best-label",children:"Theoretical Best:"}),e.jsx("span",{className:"pvx-theoretical-best-time",children:D(h.lapTimeMs)}),e.jsxs("span",{className:"pvx-theoretical-best-sectors",children:["(",M(h.sector1Ms)," + ",M(h.sector2Ms)," + ",M(h.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((m,b)=>{const w=m.isValid&&m.lapTimeMs===d,T=v&&m.isValid&&m.sector1Ms===v.s1,C=v&&m.isValid&&m.sector2Ms===v.s2,ie=v&&m.isValid&&m.sector3Ms===v.s3;let A="pvx-row";return m.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:m.lapNumber||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:D(m.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${T?"pvx-td--best-sector":""}`,children:M(m.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${C?"pvx-td--best-sector":""}`,children:M(m.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${ie?"pvx-td--best-sector":""}`,children:M(m.sector3Ms)}),e.jsx("td",{className:"pvx-td",title:m.isValid?void 0:m.invalidReason||"Invalid",children:m.isValid?e.jsx(es,{}):e.jsx(ss,{})}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:J(m.tyreCompound),children:m.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:m.startingFuelL?`${m.startingFuelL}L`:"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:B(m.timestamp)})]},m.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:t,getUserDisplay:n,game:r,gameVersion:a,onComboSelect:i}){const[o,l]=H({key:"rank",dir:"asc"}),[u,c]=N.useState(null),x=N.useMemo(()=>s?Q(s,o,(g,p)=>{switch(p){case"rating":return g.rating;case"comboCount":return g.comboCount||0;case"distinctCars":return g.distinctCars||0;case"rank":default:return g.rank}}):[],[s,o]);if(t)return e.jsx(E,{});if(!(s!=null&&s.length))return e.jsx("div",{className:"pvx-card",children:e.jsx(U,{message:"Not enough data for rankings yet."})});const h=5;return e.jsxs("div",{className:"pvx-card",children:[e.jsxs("div",{className:"pvx-card-header pvx-rankings-header",children:[e.jsx("h2",{className:"pvx-card-title",children:"Driver Rankings"}),e.jsxs("div",{className:"pvx-rankings-info-trigger",children:[e.jsx("svg",{className:"pvx-rankings-info-icon",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"})}),e.jsxs("div",{className:"pvx-rankings-info-tooltip",children:[e.jsx("p",{className:"pvx-rankings-info-title",children:"How ratings work"}),e.jsxs("ul",{className:"pvx-rankings-info-list",children:[e.jsx("li",{children:"For each car/track combo with 3+ drivers, you're ranked by lap time and given a percentile (100 = fastest, 0 = slowest)"}),e.jsx("li",{children:"Your rating is a weighted average across all your combos — bigger fields count more"}),e.jsx("li",{children:"A confidence adjustment rewards car diversity: the more different cars you drive competitively, the closer your rating reflects your true score"}),e.jsx("li",{children:"Minimum 2 qualifying combos required"})]})]})]})]}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx(R,{label:"#",sortKey:"rank",config:o,onSort: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:x.map(g=>{const p=u===g.identifier;return e.jsx(os,{driver:g,getUserDisplay:n,isExpanded:p,onToggle:()=>c(p?null:g.identifier),colCount:h,game:r,gameVersion:a,onComboSelect:i},g.identifier)})})]})})]})}function os({driver:s,getUserDisplay:t,isExpanded:n,onToggle:r,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:r,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(te,{rank:s.rank,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(O,{userId:u,getUserDisplay:t})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:s.rating.toFixed(1)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:s.distinctCars||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-sm",children:e.jsxs("span",{className:"pvx-rankings-combo-count",children:[s.comboCount,e.jsx("svg",{className:`pvx-rankings-chevron ${n?"pvx-rankings-chevron--open":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})})]}),n&&s.combos&&e.jsx("tr",{children:e.jsx("td",{colSpan:a,className:"pvx-rankings-combos-cell",children:e.jsx("div",{className:"pvx-rankings-combos",children:s.combos.map((c,x)=>{const h=c.layout?`${c.trackId}|${c.layout}`:c.trackId,g=l?()=>l({track:h,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,")"]})]})]})]},x)})})})})]})}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 t=s===1?"pvx-rank pvx-rank--gold":s===2?"pvx-rank pvx-rank--silver":s===3?"pvx-rank pvx-rank--bronze":"pvx-rank";return e.jsx("span",{className:t,children:s})}function ke({nation:s}){const t=s&&cs[s];return t?e.jsx("span",{className:"pvx-nation-flag",title:s,children:t}):null}function ds({sessions:s,activeSession:t,onSelect:n}){if(!s||s.length<=1)return null;const r=[...s].sort((a,i)=>oe.indexOf(a.type)-oe.indexOf(i.type));return e.jsx("div",{className:"pvx-session-tabs",children:r.map(a=>e.jsx("button",{onClick:()=>n(a.type),className:`pvx-session-tab ${t===a.type?"pvx-session-tab--active":""}`,children: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:t="default"}){return e.jsx("span",{className:`pvx-info-pill ${t!=="default"?`pvx-info-pill--${t}`:""}`,children:s})}function ps(s){if(!s)return"TBD";const t=new Date(s);if(isNaN(t))return"TBD";const n=t.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),r=t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return`${n} • ${r}`}function xs(s){return s.reduce((t,n)=>{var r;return(r=n.splits)!=null&&r.length?t?t.map((a,i)=>{const o=n.splits[i];return o&&o<a?o:a}):[...n.splits]:t},null)}function 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:t,onSelect:n,onRegister:r,className:a}){return t?e.jsx(I,{message:"Loading competitions..."}):s!=null&&s.length?e.jsx("div",{className:`pvx-comp-grid ${a||""}`,children:s.map(i=>e.jsx(we,{comp:i,onSelect:n,onRegister:r||n},i.id))}):e.jsx($,{message:"No competitions available."})}function we({comp:s,onSelect:t,onRegister:n}){var v,d,j;const{cdnUrl:r}=k(),a=s.posterCdnPath?`${r}/${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,x=(i==null?void 0:i.isOpen)&&!c&&!u,h=new Date,g=(v=s.rounds)==null?void 0:v.find(m=>m.startTime&&new Date(m.startTime)>=h),p=((d=s.rounds)==null?void 0:d.length)||0,f=((j=s.rounds)==null?void 0:j.filter(m=>m.isFinalized).length)||0;return e.jsxs("div",{className:"pvx-comp-card",onClick:()=>t(s.id),role:"button",tabIndex:0,onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),t(s.id))},children:[e.jsx("div",{className:"pvx-comp-card-poster",children:a?e.jsx("img",{src:a,alt:s.name,className:"pvx-comp-card-poster-img"}):e.jsx("div",{className:"pvx-comp-card-poster-placeholder",children:e.jsx(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((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:[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)]}):p>0?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[f,"/",p," rounds completed"]}):null,p>0&&e.jsxs("span",{className:"pvx-comp-card-round-count",children:[p," round",p!==1?"s":""]})]}),i&&e.jsx(ms,{competitionId:s.id,regOpen:x,isFull:u,deadlinePassed:c,regCount:o,regMax:l,onRegister:n})]})]})}function ms({competitionId:s,regOpen:t,isFull:n,deadlinePassed:r,regCount:a,regMax:i,onRegister:o}){const{isPowerMode:l}=V(),u=K(s),{data:c}=_(s),x=(c==null?void 0:c.isRegistered)||!1,h=i?a/i*100:0,g=h>=100?"full":h>=75?"warning":"ok";return e.jsxs("div",{className:"pvx-comp-card-reg",children:[e.jsx("div",{className:"pvx-comp-card-reg-info",children:e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${g}`,children:[a,"/",i||"∞"," drivers"]})}),e.jsx("div",{className:"pvx-comp-card-reg-action",children:x?e.jsx("button",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--registered",onClick:p=>{p.stopPropagation(),o(s)},children:"✓ Registered"}):t?l?e.jsx("button",{className:"pvx-comp-card-reg-btn pvx-comp-card-reg-btn--open",onClick:p=>{p.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:p=>p.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:t}){var l,u;const{data:n,isLoading:r}=me(s),{data:a,isLoading:i}=Z(s);if(r||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 ${t||""}`,children:[e.jsx("div",{className:"pvx-card-header--split",children:e.jsxs("div",{className:"pvx-card-header-left",children:[e.jsx("h3",{className:"pvx-card-title",children:"Championship Standings"}),e.jsxs("span",{className:"pvx-standings-subtitle",children:["After ",n.roundsCompleted," round",n.roundsCompleted!==1?"s":"",n.countingRounds>0&&` (best ${n.countingRounds} count)`]})]})}),e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"W"}),e.jsx("th",{className:"pvx-th pvx-th--center pvx-hidden-below-sm",children:"Pod"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"}),o.map(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:t}){var o,l,u;const n=s.position<=3,r=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}),t.map(c=>{const x=r.get(c.roundNumber),h=x==null?void 0:x.dropped;return e.jsx("td",{className:`pvx-td pvx-td--center pvx-hidden-below-md ${!h&&(x==null?void 0:x.position)===1?"pvx-standings-cell--p1":!h&&(x==null?void 0:x.position)===2?"pvx-standings-cell--p2":!h&&(x==null?void 0:x.position)===3?"pvx-standings-cell--p3":""}`,children:x?e.jsxs("div",{className:`pvx-standings-round-cell ${h?"pvx-standings-round-cell--dropped":""}`,children:[e.jsxs("span",{className:"pvx-standings-round-pos",children:["P",x.position]}),e.jsx("span",{className:"pvx-standings-round-pts",children:x.points})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})},c.roundNumber)})]})}function gs({competitionId:s,roundNumber:t,className:n}){var u;const{data:r,isLoading:a}=ve(s,t);if(a)return e.jsx(I,{message:"Loading results..."});if(!r)return e.jsx($,{message:"No results for this round."});const o=(r.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,x)=>c.position-x.position);return e.jsxs("div",{className:`pvx-round-results ${n||""}`,children:[e.jsxs("div",{className:"pvx-round-results-header",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"pvx-round-results-title",children:["Round ",r.roundNumber,r.track?`: ${r.track}`:""]}),r.startTime&&e.jsx("p",{className:"pvx-round-results-date",children:new Date(r.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(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:r})]})}function ae({round:s,className:t}){var l,u;const[n,r]=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:t||"",children:[e.jsx(ds,{sessions:a,activeSession:i,onSelect:r}),e.jsx(js,{session:o})]})}function js({session:s}){var r;const t=s.type==="RACE";if(!((r=s.results)!=null&&r.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"}),t&&e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Laps"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Time / Gap"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"})]})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.results.map((a,i)=>e.jsx(fs,{result:a,isRace:t,fastestSplits:n,rowIndex:i},a.driverId||i))})]})})}function fs({result:s,isRace:t,fastestSplits:n,rowIndex:r}){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:r<=1})}),t&&e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:s.lapsCompleted}),e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:s.position===1?s.totalTime||"-":s.gap||"-"}),e.jsxs("td",{className:"pvx-td pvx-td--center",children:[e.jsx("span",{className:"pvx-session-points",children:s.points}),s.pointsOverride!==0&&s.pointsOverride&&e.jsxs("span",{className:"pvx-points-override",children:["(",s.pointsOverride>0?"+":"",s.pointsOverride,")"]})]})]})]})}function Ns({bestLap:s,hasBestLap:t,splits:n,fastestSplits:r,showAbove:a}){return s?e.jsxs("span",{className:`pvx-best-lap-cell ${t?"pvx-best-lap-cell--fastest":""}`,children:[e.jsx("span",{className:"pvx-best-lap-time",children:s}),(n==null?void 0:n.length)>0&&e.jsx("span",{className:"pvx-splits-tooltip-anchor",children:e.jsx("span",{className:`pvx-splits-tooltip ${a?"":"pvx-splits-tooltip--above"}`,children:n.map((i,o)=>{const l=r&&i===r[o];return e.jsxs("span",{className:"pvx-splits-tooltip-row",children:[e.jsxs("span",{className:"pvx-splits-tooltip-label",children:["S",o+1]}),e.jsx("span",{className:l?"pvx-splits-tooltip-best":"",children:i})]},o)})})})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})}function bs({competitionId:s,className:t}){const{getSteamId:n}=k(),{data:r,isLoading:a}=X(s),i=n();if(a)return e.jsx(I,{message:"Loading drivers..."});const o=(r==null?void 0:r.drivers)||(r==null?void 0:r.entries)||[];return o.length?e.jsx("div",{className:`pvx-entry-grid ${t||""}`,children:o.map(l=>{var c,x;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:((x=(c=l.displayName)==null?void 0:c.charAt(0))==null?void 0:x.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:t,className:n,children:r}){const{data:a,isLoading:i}=_(s),{isPowerMode:o}=V(),l=K(s),u=ee(s),c=se(s),x=(a==null?void 0:a.isRegistered)||!1,h=i||u.isPending||c.isPending,g=u.error||c.error||null,p=()=>{o&&u.mutate(t||{})},f=()=>{o&&c.mutate()};return typeof r=="function"?r({isRegistered:x,isLoading:h,register:p,withdraw:f,error:g,isPowerMode:o,registrationUrl:l}):o?e.jsx("button",{className:`pvx-comp-register-btn ${n||""}`,onClick:x?f:p,disabled:h,children:h?"Loading...":x?"Withdraw":"Register"}):e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:`pvx-comp-register-link ${n||""}`,children:x?"View Registration":"Register on PitVox"})}function ks({competitionId:s,registration:t,onWithdrawSuccess:n,className:r}){const{getSteamId:a}=k(),{isPowerMode:i}=V(),o=K(s),{data:l,isLoading:u}=_(s),{data:c,isLoading:x}=X(s),h=ee(s),g=se(s),p=a(),f=(l==null?void 0:l.isRegistered)||!1,v=(c==null?void 0:c.drivers)||(c==null?void 0:c.entries)||[],d=t||{},j=v.length||d.currentCount||0,m=d.maxParticipants&&j>=d.maxParticipants,b=d.deadline&&new Date(d.deadline)<new Date,w=d.isOpen&&!b&&!m;return u||x?e.jsx(I,{message:"Loading registration..."}):f?e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx(ws,{competitionId:s,drivers:v,steamId:p,isPowerMode:i,registrationUrl:o,withdrawMutation:g,onWithdrawSuccess:n,registration:d})}):w?p?i?e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx(Cs,{competitionId:s,registerMutation:h,registration:d})}):e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:e.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Register on PitVox"})}):e.jsx("div",{className:`pvx-reg-panel ${r||""}`,children:i?e.jsx("div",{className:"pvx-reg-status-msg",children:"Sign in to register for this competition."}):e.jsx("div",{className:"pvx-reg-status-msg",children:e.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"pvx-comp-register-link",children:"Register on PitVox"})})}):e.jsxs("div",{className:`pvx-reg-panel ${r||""}`,children:[e.jsx("div",{className:"pvx-reg-status-msg",children:m?"Registration is full.":b?"Registration deadline has passed.":"Registration is closed."}),v.length>0&&e.jsx(Re,{drivers:v,steamId:p})]})}function Cs({competitionId:s,registerMutation:t,registration:n}){const[r,a]=N.useState(""),[i,o]=N.useState("intermediate"),[l,u]=N.useState(""),c=p=>{p.preventDefault(),t.mutate({discordUsername:r||void 0,experience:i,comments:l||void 0})},x=n||{},h=x.currentCount||0,g=x.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:h,max:g})]}),t.error&&e.jsx("div",{className:"pvx-reg-error",children:t.error.message||"Registration failed"}),e.jsxs("div",{className:"pvx-reg-field",children:[e.jsxs("label",{className:"pvx-reg-label",htmlFor:`pvx-discord-${s}`,children:["Discord Username ",e.jsx("span",{className:"pvx-reg-optional",children:"(optional)"})]}),e.jsx("input",{id:`pvx-discord-${s}`,type:"text",className:"pvx-reg-input",placeholder:"e.g. username",value:r,onChange:p=>a(p.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:p=>o(p.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:p=>u(p.target.value)})]}),e.jsx("div",{className:"pvx-reg-actions",children:e.jsx("button",{type:"submit",className:"pvx-comp-register-btn",disabled:t.isPending,children:t.isPending?"Registering...":"Register"})})]})}function ws({competitionId:s,drivers:t,steamId:n,isPowerMode:r,registrationUrl:a,withdrawMutation:i,onWithdrawSuccess:o,registration:l}){const[u,c]=N.useState(!1),x=()=>{i.mutate(void 0,{onSuccess:()=>{c(!1),o&&o()}})},h=l||{},g=t.length||h.currentCount||0,p=h.maxParticipants;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pvx-reg-form-header",children:[e.jsx("h3",{className:"pvx-reg-form-title",children:"Registered Drivers"}),p&&e.jsx(Te,{count:g,max:p})]}),e.jsx(Re,{drivers:t,steamId:n}),i.error&&e.jsx("div",{className:"pvx-reg-error",children:i.error.message||"Withdrawal failed"}),r?e.jsx("div",{className:"pvx-reg-actions",children: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:x,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:t}){if(!s.length)return e.jsx("div",{className:"pvx-reg-no-drivers",children:"No drivers registered yet."});const n=[...s].sort((r,a)=>{const i=t&&r.steamId===t?-1:0,o=t&&a.steamId===t?-1:0;return i-o});return e.jsx("div",{className:"pvx-reg-driver-list",children:n.map(r=>{var i,o;const a=t&&r.steamId===t;return e.jsxs("div",{className:`pvx-reg-driver-row ${a?"pvx-reg-driver-row--you":""}`,children:[r.avatarUrl?e.jsx("img",{src:r.avatarUrl,alt:"",className:"pvx-reg-driver-avatar"}):e.jsx("div",{className:"pvx-reg-driver-avatar pvx-reg-driver-avatar--placeholder",children:((o=(i=r.displayName)==null?void 0:i.charAt(0))==null?void 0:o.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-reg-driver-name",children:[r.displayName,a&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},r.steamId||r.driverId)})})}function Te({count:s,max:t}){const n=t?s/t*100:0,r=n>=100?"full":n>=75?"warning":"ok";return e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${r}`,children:[s,"/",t," drivers"]})}function Ls({competitionId:s,className:t}){const{data:n,isLoading:r}=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,[x,h]=N.useState(null),g=x||c;if(r||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 p=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:null});const v=p.get(g);return e.jsxs("div",{className:t||"",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:()=>h(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}):v?e.jsx(Rs,{round:v}):e.jsx($,{message:"No results for this round."})]})}function Rs({round:s}){var a;const n=(s.sessions||[]).find(i=>i.type==="RACE"),r=(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-card-header--split",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"pvx-card-title",children:["Round ",s.roundNumber,s.track?`: ${s.track}`:""]}),s.startTime&&e.jsx("span",{className:"pvx-standings-subtitle",children:new Date(s.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})})]}),(r==null?void 0:r.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:r.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:t}=k(),n=y.useQuery({queryKey:["pitvox","laps","global",s],queryFn:()=>L(t,`laps/${s}.json`),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),r=n.data;return{isLoading:n.isLoading,error:n.error,data:r?{driverName:r.driverName||"Driver",lapCount:r.lapCount||0,trackBreakdown:r.trackBreakdown||[],carBreakdown:r.carBreakdown||[],recordsHeld:r.recordsHeld||0,currentRecords:r.currentRecords||[],bestRanking:r.bestRanking??null,bestRankingTrackId:r.bestRankingTrackId??null,bestRankingLayout:r.bestRankingLayout??null,bestRankingCarId:r.bestRankingCarId??null,generatedAt:r.generatedAt}:null}}function Me(s={}){const{cdnUrl:t,partnerSlug:n}=k(),{game:r,gameVersion:a,enabled:i=!0}=s,o=q(n,r,a,"ratings.json");return y.useQuery({queryKey:["pitvox","ratings",n,r||null,a||null],queryFn:()=>L(t,o),staleTime:3e4,refetchInterval:3e4,enabled:i})}function $e(s){var r;const t=Me(),n=N.useMemo(()=>{var a;return!((a=t.data)!=null&&a.drivers)||!s?null:t.data.drivers.find(i=>i.identifier===s)||null},[(r=t.data)==null?void 0:r.drivers,s]);return{isLoading:t.isLoading,error:t.error,data:n?{rating:n.rating,rank:n.rank,totalDrivers:t.data.driverCount||t.data.drivers.length,comboCount:n.comboCount||0,distinctCars:n.distinctCars||0,combos:n.combos||[]}:null}}function Ts(s={}){const t=Me(s);return{data:t.data||null,isLoading:t.isLoading,error:t.error}}function De(){const{cdnUrl:s,partnerSlug:t,getSteamId:n,onFetchServerPassword:r}=k(),a=n(),{data:i,isLoading:o}=y.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const p=await L(s,"competitions/index.json");return p!=null&&p.competitions?p.competitions.filter(f=>f.partnerSlug===t):[]},staleTime:6e4}),l=(i==null?void 0:i.map(p=>p.id))||[],u=y.useQueries({queries:l.map(p=>({queryKey:["pitvox","competition",t,p,"entrylist"],queryFn:()=>L(s,`competitions/${t}/${p}/entrylist.json`),enabled:!!a&&l.length>0,staleTime:6e4}))}),c=u.some(p=>p.isLoading),x=N.useMemo(()=>{var v,d;if(!i||!a||c)return[];const p=new Date,f=[];for(let j=0;j<i.length;j++){const m=i[j],b=(v=u[j])==null?void 0:v.data;if(!((d=b==null?void 0:b.drivers)==null?void 0:d.some(C=>C.steamId===a)))continue;const T=m.rounds||[];for(const C of T)C.isFinalized||!C.startTime||new Date(C.startTime)<=p||f.push({competitionId:m.id,competitionName:m.name,roundNumber:C.roundNumber,track:C.track||"TBD",startTime:C.startTime})}return f.sort((j,m)=>new Date(j.startTime)-new Date(m.startTime)),f.length>0&&(f[0].isNext=!0),f},[i,a,c,u]),h=y.useQueries({queries:x.map(p=>({queryKey:["pitvox","serverInfo",p.competitionId,p.roundNumber],queryFn:()=>r(p.competitionId,p.roundNumber),enabled:!!r&&x.length>0,staleTime:5*6e4,retry:!1}))});return{data:N.useMemo(()=>x.length?r?x.map((p,f)=>{var d;const v=(d=h[f])==null?void 0:d.data;return v!=null&&v.success?{...p,serverAddress:v.serverAddress||null,serverPassword:v.serverPassword||null}:p}):x:[],[x,r,h]),isLoading:o||!!a&&c}}function Ie(){const{onFetchNotifications:s}=k();return!!s}function Pe(s={}){const{onFetchNotifications:t,partnerSlug:n}=k(),{limit:r=20,unreadOnly:a=!1}=s;return y.useQuery({queryKey:["pitvox","notifications",n,{limit:r,unreadOnly:a}],queryFn:()=>t({limit:r,unreadOnly:a}),enabled:!!t,staleTime:3e4,refetchInterval:3e4})}function Ss(){const{onFetchNotifications:s,partnerSlug:t}=k(),{data:n,isLoading:r}=y.useQuery({queryKey:["pitvox","notifications",t,{limit:1,unreadOnly:!1}],queryFn:()=>s({limit:1}),enabled:!!s,staleTime:3e4,refetchInterval:3e4,select:a=>(a==null?void 0:a.unreadCount)??0});return{count:n??0,isLoading:r}}function Be(){const{onMarkNotificationRead:s,partnerSlug:t}=k(),n=y.useQueryClient();return y.useMutation({mutationFn:r=>{if(!s)throw new Error("No onMarkNotificationRead callback provided to PitVoxPartnerProvider.");return s(r)},onSuccess:(r,a)=>{n.setQueriesData({queryKey:["pitvox","notifications",t]},i=>i!=null&&i.notifications?{...i,unreadCount:Math.max(0,(i.unreadCount||0)-1),notifications:i.notifications.map(o=>o.id===a?{...o,isRead:!0,readAt:new Date().toISOString()}:o)}:i)}})}function Ae(){const{onMarkAllNotificationsRead:s,partnerSlug:t}=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",t]},r=>r!=null&&r.notifications?{...r,unreadCount:0,notifications:r.notifications.map(a=>({...a,isRead:!0,readAt:a.readAt||new Date().toISOString()}))}:r)}})}function Ue({driverName:s,avatarUrl:t,memberSince:n,className:r=""}){const a=n?new Date(n).toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"numeric"}):null;return e.jsxs("div",{className:`pvx-card pvx-dash-profile ${r}`,children:[t?e.jsx("img",{src:t,alt:"",className:"pvx-dash-profile-avatar"}):e.jsx("div",{className:"pvx-dash-profile-avatar pvx-dash-profile-avatar--placeholder",children:(s||"?")[0].toUpperCase()}),e.jsxs("div",{className:"pvx-dash-profile-info",children:[e.jsx("h2",{className:"pvx-dash-profile-name",children:s}),a&&e.jsxs("p",{className:"pvx-dash-profile-since",children:["Racing since ",a]})]})]})}function 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:t,label:n,items:r,labelKey:a,countKey:i}){const[o,l]=N.useState(!1),u=N.useRef(null);N.useEffect(()=>{if(!o)return;function x(h){u.current&&!u.current.contains(h.target)&&l(!1)}return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[o]);const c=r!=null&&r.length?r.slice().sort((x,h)=>h[i]-x[i]):null;return e.jsxs("div",{ref:u,className:`pvx-dash-stat-card ${c?"pvx-dash-stat-card--clickable":""}`,onClick:c?()=>l(x=>!x):void 0,children:[s,e.jsxs("div",{className:"pvx-dash-stat-content",children:[e.jsx("span",{className:"pvx-dash-stat-value",children:t}),e.jsx("span",{className:"pvx-dash-stat-label",children:n})]}),c&&e.jsx("div",{className:`pvx-dash-tooltip pvx-dash-tooltip--scrollable ${o?"pvx-dash-tooltip--open":""}`,children:c.map((x,h)=>e.jsxs("div",{className:"pvx-dash-tooltip-row",children:[e.jsx("span",{className:"pvx-dash-tooltip-label",children:x[a]}),e.jsx("span",{className:"pvx-dash-tooltip-value",children:x[i]})]},h))})]})}function Ee({stats:s,rating:t,className:n=""}){if(!s)return null;const r=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:r,labelKey:"name",countKey:"lapCount"}),e.jsx(ce,{icon:e.jsx($s,{}),value:s.carBreakdown.length,label:"Cars Used",items:a,labelKey:"name",countKey:"lapCount"}),t&&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:t.rating.toFixed(1)}),e.jsx("span",{className:"pvx-dash-stat-label",children:"Driver Rating"}),e.jsxs("span",{className:"pvx-dash-stat-sub",children:["#",t.rank," of ",t.totalDrivers]})]})]})]})}function Fe({records:s,className:t=""}){const n=N.useMemo(()=>s!=null&&s.length?s.slice().sort((r,a)=>{const i=r.recordedAt?new Date(r.recordedAt).getTime():0;return(a.recordedAt?new Date(a.recordedAt).getTime():0)-i}):[],[s]);return n.length?e.jsxs("div",{className:`pvx-card ${t}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx("span",{className:"pvx-dash-records-icon",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 010-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 000-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0012 0V2z"})]})}),"Current Records",e.jsxs("span",{className:"pvx-dash-records-count",children:["(",n.length,")"]})]})}),e.jsx("div",{className:"pvx-dash-records-list",children:n.map((r,a)=>e.jsxs("div",{className:"pvx-dash-record-row",children:[e.jsxs("div",{className:"pvx-dash-record-info",children:[e.jsx("span",{className:"pvx-dash-record-track",children:P(r.trackId,r.layout,r.game)}),e.jsx("span",{className:"pvx-dash-record-car",children:S(r.carId)})]}),e.jsxs("div",{className:"pvx-dash-record-time",children:[e.jsx("span",{className:"pvx-dash-record-lap",children:D(r.lapTimeMs)}),e.jsxs("span",{className:`pvx-dash-game-badge pvx-dash-game-badge--${r.game||"evo"}`,children:[(r.game||"evo").toUpperCase(),r.gameVersion?` ${r.gameVersion}`:""]})]})]},a))})]}):null}function qe({events:s,isLoading:t,className:n,limit:r=3}){if(t)return e.jsx("div",{className:"pvx-loading",children:"Loading upcoming events..."});if(!(s!=null&&s.length))return null;const a=r?s.slice(0,r):s,i=s.length-a.length;return e.jsxs("div",{className:`pvx-card ${n||""}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(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:t}){const[n,r]=N.useState(!1),[a,i]=N.useState(!1),o=t?s?`join:${t}|${s}`:`join:${t}`:null,l=N.useCallback(async()=>{if(o)try{await navigator.clipboard.writeText(o),r(!0),setTimeout(()=>r(!1),2e3)}catch{}},[o]);return e.jsxs("div",{className:"pvx-server-info",children:[o&&e.jsxs("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick: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 t=new Date(s).getTime()-Date.now();if(t<=0)return"Now";const n=Math.floor(t/(1e3*60*60));if(n<1)return"Less than 1 hour";if(n<24)return`in ${n}h`;const r=Math.floor(n/24);if(r===1)return"Tomorrow";if(r<7)return`in ${r} days`;if(r<30){const a=Math.floor(r/7);return`in ${a} week${a!==1?"s":""}`}return 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:t=0,onMarkRead:n,onMarkAllRead:r,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",t>0&&e.jsx("span",{className:"pvx-notif-badge",children:t>99?"99+":t})]}),t>0&&r&&e.jsx("button",{className:"pvx-notif-mark-all",onClick:r,children:"Mark all read"})]}),s!=null&&s.length?e.jsx("div",{className:"pvx-notif-list",children:s.map(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:t,onMarkRead:n}){const r=()=>{!s.isRead&&n&&n(s.id)};return e.jsxs("button",{className:`pvx-notif-item ${s.isRead?"":"pvx-notif-item--unread"}`,onClick:r,children:[e.jsx(_s,{type:s.type}),e.jsxs("div",{className:"pvx-notif-content",children:[e.jsx("span",{className:"pvx-notif-message",children:pe(s,t)}),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:t,memberSince:n,className:r=""}){const{data:a,isLoading:i,error:o}=Se(s),{data:l,isLoading:u}=$e(s),{data:c,isLoading:x}=De(),h=Ie(),{data:g,isLoading:p}=Pe({limit:10}),f=Be(),v=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 ${r}`,children:[e.jsx(Ue,{driverName:a.driverName,avatarUrl:t,memberSince:n}),e.jsx(Ee,{stats:a,rating:l}),s&&e.jsx(qe,{events:c,isLoading:x}),e.jsxs("div",{className:`pvx-dash-row ${h?"pvx-dash-row--2col":""}`,children:[e.jsx(Fe,{records:a.currentRecords}),h&&e.jsx(_e,{notifications:g==null?void 0:g.notifications,unreadCount:(g==null?void 0:g.unreadCount)||0,onMarkRead:d=>f.mutate(d),onMarkAllRead:()=>v.mutate(),isLoading:p})]})]}):e.jsx("div",{className:"pvx-empty",children:"No data available yet. Start driving to see your stats!"})}exports.CarsTable=rs;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=ts;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;
|