@pitvox/partner-react 0.7.7 → 0.7.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/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"),Y=N.createContext(null),Ze="https://cdn.pitvox.com",Xe="https://pitvox.com";let z=null;function es({partnerSlug:s=null,cdnUrl:t=Ze,pitvoxUrl:r=Xe,getSteamId:n,onRegister:a,onWithdraw:i,onFetchNotifications:o,onMarkNotificationRead:l,onMarkAllNotificationsRead:p,onFetchServerPassword:c,children:d}){const g=N.useMemo(()=>({partnerSlug:s,cdnUrl:t.replace(/\/$/,""),pitvoxUrl:r.replace(/\/$/,""),getSteamId:n||(()=>null),onRegister:a||null,onWithdraw:i||null,onFetchNotifications:o||null,onMarkNotificationRead:l||null,onMarkAllNotificationsRead:p||null,onFetchServerPassword:c||null}),[s,t,r,n,a,i,o,l,p,c]);let h=!1;try{y.useQueryClient(),h=!0}catch{h=!1}return h?e.jsx(Y.Provider,{value:g,children:d}):(z||(z=new y.QueryClient({defaultOptions:{queries:{staleTime:6e4}}})),e.jsx(y.QueryClientProvider,{client:z,children:e.jsx(Y.Provider,{value:g,children:d})}))}function C(){const s=N.useContext(Y);if(!s)throw new Error("usePitVox must be used within a <PitVoxPartnerProvider>");return s}async function S(s,t){const r=await fetch(`${s}/${t}`);if(!r.ok){if(r.status===404||r.status===403)return null;throw new Error(`CDN fetch failed: ${r.status}`)}return r.json()}function q(s,t,r,...n){const a=["leaderboards"];return s&&a.push(`partners/${s}`),t&&a.push(t),r&&a.push(`v/${r}`),[...a,...n].join("/")}function me(s,t,r,n){const a=n||"default";return s?`laps/partners/${s}/${t}/${r}/${a}.json`:`laps/${t}/${r}/${a}.json`}function ve(s,t){return s?`laps/partners/${s}/${t}/index.json`:`laps/${t}/index.json`}function he(s){return s?`recent-laps/partners/${s}.json`:"recent-laps.json"}function P(s){if(!s&&s!==0)return"-";const t=Math.floor(s/1e3),r=Math.floor(t/60),n=t%60,a=s%1e3;return`${r}:${String(n).padStart(2,"0")}.${String(a).padStart(3,"0")}`}function $(s){return!s&&s!==0?"-":s>=6e4?P(s):(s/1e3).toFixed(3)}function M(s){if(!s)return"";let t=s;return t.startsWith("ks_")&&(t=t.slice(3)),t.split("_").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function B(s,t,r){if(!s)return"";const n=s.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" "),a=r==="acc"||!r&&(t==null?void 0:t.toLowerCase())==="track config";if(!t||t==="default"||a)return n;const i=t.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ");return`${n} ${i}`}function A(s){if(!s)return"-";try{return new Date(s).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}catch{return"-"}}function J(s){if(!s)return"";const t=Date.now()-new Date(s).getTime(),r=Math.floor(t/1e3);if(r<60)return"Just now";const n=Math.floor(r/60);if(n<60)return`${n}m ago`;const a=Math.floor(n/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);return i<30?`${i}d ago`:A(s)}function ss(s){return s==null?"":`${s>=0?"+":"-"}${(Math.abs(s)/1e3).toFixed(3)}`}function ge(s,t){const{type:r,title:n,trackId:a,trackLayout:i,carId:o,game:l,data:p}=s,c=typeof p=="string"?JSON.parse(p):p,d=a?B(a,i,l):null,g=o?M(o):null,h=[d,g].filter(Boolean).join(" — ");return r==="RECORD_BEATEN"&&h?`${c!=null&&c.beatenBySteamId&&t?t(c.beatenBySteamId).displayName:"Someone"} beat your record on ${h}`:r==="RECORD_SET"&&h?`You set a new record on ${h}`:n||"New notification"}function Z(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 X(s){if(!s)return"-";const t=Number(s);return isNaN(t)?"-":t%1?`${t.toFixed(1)}L`:`${t}L`}function ts(s={}){var p,c,d,g,h,x;const{cdnUrl:t,partnerSlug:r}=C(),{game:n,gameVersion:a}=s,i=q(r,null,null,"index.json"),o=y.useQuery({queryKey:["pitvox","leaderboards",r,"index"],queryFn:()=>S(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 n&&(f=f.filter(u=>u.game===n)),a&&(f=f.filter(u=>u.gameVersion===a)),f.map(u=>({id:u.trackId,layout:u.layout,game:u.game,gameVersion:u.gameVersion,displayName:B(u.trackId,u.layout,u.game),driverCount:u.driverCount||0,carCount:u.carCount||0,record:u.recordHolder?{visibleId:u.recordHolder.steamId||u.recordHolder.userId,carId:u.recordHolder.carId,carDisplayName:M(u.recordHolder.carId),lapTimeMs:u.recordHolder.lapTimeMs,timestamp:u.recordHolder.recordedAt}:null,recordByTag:u.recordByTag||null}))},[(p=o.data)==null?void 0:p.tracks,n,a]);return{...o,data:l,partner:((c=o.data)==null?void 0:c.partner)||null,generatedAt:(d=o.data)==null?void 0:d.generatedAt,totalLaps:((g=o.data)==null?void 0:g.totalLaps)||0,totalUsers:((h=o.data)==null?void 0:h.totalUsers)||0,versions:((x=o.data)==null?void 0:x.versions)||{}}}function je(s,t,r={}){const{cdnUrl:n,partnerSlug:a}=C(),{carId:i,game:o,gameVersion:l}=r,p=t||"default",c=q(a,o,l,`tracks/${s}/${p}.json`),{data:d,isLoading:g,error:h}=y.useQuery({queryKey:["pitvox","leaderboards",a,"track",s,p,o,l],queryFn:()=>S(n,c),enabled:!!s,staleTime:3e4,refetchInterval:3e4});return{data:N.useMemo(()=>{if(!(d!=null&&d.entries))return[];let f=d.entries;if(o&&(f=f.filter(v=>v.game===o)),!i){const v=new Map,u=new Map;for(const j of f){const m=j.steamId||j.userId;u.has(j.carId)||u.set(j.carId,new Set),u.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=u.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,u)=>v.lapTimeMs-u.lapTimeMs)},[d==null?void 0:d.entries,i,o]),isLoading:g,error:h}}function fe(s,t,r,n,a={}){var v,u;const{cdnUrl:i,partnerSlug:o}=C(),{showInvalid:l=!1,game:p,gameVersion:c}=a,d=s&&t?me(o,s,t,r):null,g=r||"default",h=y.useQuery({queryKey:["pitvox","laps",o,s,t,g],queryFn:()=>S(i,d),enabled:!!s&&!!t,staleTime:3e4,refetchInterval:3e4}),x=N.useMemo(()=>{var j;return(j=h.data)!=null&&j.laps?h.data.laps.filter(m=>!(m.carId!==n||p&&m.game!==p||c&&m.gameVersion!==c||!l&&!m.isValid)).sort((m,b)=>m.lapTimeMs-b.lapTimeMs):[]},[(v=h.data)==null?void 0:v.laps,n,p,c,l]),f=N.useMemo(()=>{const j=x.filter(T=>T.isValid&&T.sector1Ms&&T.sector2Ms&&T.sector3Ms);if(j.length<2)return null;const m=Math.min(...j.map(T=>T.sector1Ms)),b=Math.min(...j.map(T=>T.sector2Ms)),w=Math.min(...j.map(T=>T.sector3Ms)),k=m+b+w,L=Math.min(...j.map(T=>T.lapTimeMs));return k>=L?null:{lapTimeMs:k,sector1Ms:m,sector2Ms:b,sector3Ms:w}},[x]);return{...h,data:x,driverName:((u=h.data)==null?void 0:u.driverName)||"Driver",theoreticalBest:f}}function ee(){const{cdnUrl:s}=C(),{data:t}=y.useQuery({queryKey:["pitvox","users","index"],queryFn:()=>S(s,"users/index.json"),staleTime:5*6e4,gcTime:30*6e4}),r=(t==null?void 0:t.users)||{};return(n,a)=>{const i=r[n];return{displayName:(i==null?void 0:i.displayName)||a||n||"Unknown",avatarUrl:(i==null?void 0:i.avatarUrl)||null,affiliations:(i==null?void 0:i.affiliations)||[]}}}function rs(){const{cdnUrl:s}=C(),{data:t}=y.useQuery({queryKey:["pitvox","cars","evo"],queryFn:()=>S(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 ns(){var a,i;const{cdnUrl:s,partnerSlug:t}=C(),r=he(t),n=y.useQuery({queryKey:["pitvox","recentLaps",t],queryFn:()=>S(s,r),staleTime:3e4,refetchInterval:3e4,gcTime:10*6e4});return{groups:((a=n.data)==null?void 0:a.groups)||[],generatedAt:((i=n.data)==null?void 0:i.generatedAt)||null,isLoading:n.isLoading}}function as(s,t){return je(s,null,{carId:t})}function is(){const{cdnUrl:s,partnerSlug:t}=C();return y.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const r=await S(s,"competitions/index.json");return r!=null&&r.competitions?t?r.competitions.filter(n=>n.partnerSlug===t):r.competitions:[]},staleTime:6e4})}function se(s,t={}){const r=C(),n=t.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",n,s,"config"],queryFn:()=>S(r.cdnUrl,`competitions/${n}/${s}/config.json`),enabled:!!n&&!!s,staleTime:6e4})}function te(s,t={}){const r=C(),n=t.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",n,s,"standings"],queryFn:()=>S(r.cdnUrl,`competitions/${n}/${s}/standings.json`),enabled:!!n&&!!s,staleTime:6e4})}function Ne(s,t,r={}){const n=C(),a=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"round",t],queryFn:()=>S(n.cdnUrl,`competitions/${a}/${s}/rounds/${t}.json`),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function be(s,t=[],r={}){const n=C(),a=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"allRounds",t],queryFn:async()=>(await Promise.all(t.map(o=>S(n.cdnUrl,`competitions/${a}/${s}/rounds/${o}.json`).catch(()=>null)))).filter(Boolean),enabled:!!a&&!!s&&t.length>0,staleTime:6e4})}function os(s,t={}){const r=C(),n=t.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",n,s,"leaderboard"],queryFn:()=>S(r.cdnUrl,`competitions/${n}/${s}/leaderboard.json`).catch(()=>null),enabled:!!n&&!!s,staleTime:6e4})}function ye(s,t,r={}){const n=C(),a=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"round",t,"laps"],queryFn:()=>S(n.cdnUrl,`competitions/${a}/${s}/rounds/${t}/laps.json`).catch(()=>null),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function re(s,t={}){const r=C(),n=t.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",n,s,"entrylist"],queryFn:()=>S(r.cdnUrl,`competitions/${n}/${s}/entrylist.json`),enabled:!!n&&!!s,staleTime:6e4})}function V(s){const{cdnUrl:t,partnerSlug:r,getSteamId:n}=C(),a=n();return y.useQuery({queryKey:["pitvox","registration",r,s,a],queryFn:async()=>{var p;const i=await fetch(`${t}/competitions/${r}/${s}/entrylist.json`);if(!i.ok)return{isRegistered:!1,entryList:null};const o=await i.json();return{isRegistered:!!a&&((p=o.drivers)==null?void 0:p.some(c=>c.steamId===a)),entryList:o}},enabled:!!s,staleTime:6e4})}function ne(s){const{onRegister:t,partnerSlug:r,getSteamId:n}=C(),a=y.useQueryClient(),i=ee();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=n();if(a.setQueriesData({queryKey:["pitvox","registration",r,s]},l=>l?{...l,isRegistered:!0}:{isRegistered:!0,entryList:null}),o){const l=i(o),p={steamId:o,displayName:l.displayName,avatarUrl:l.avatarUrl};a.setQueriesData({queryKey:["pitvox","competition",r,s,"entrylist"]},c=>{var g;return c?((g=c.drivers)==null?void 0:g.some(h=>h.steamId===o))?c:{...c,drivers:[...c.drivers||[],p]}:{drivers:[p]}})}}})}function ae(s){const{onWithdraw:t,partnerSlug:r,getSteamId:n}=C(),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||n();if(!o)throw new Error("No Steam ID available");return t(s,o)},onSuccess:()=>{const i=n();a.setQueriesData({queryKey:["pitvox","registration",r,s]},o=>o?{...o,isRegistered:!1}:{isRegistered:!1,entryList:null}),i&&a.setQueriesData({queryKey:["pitvox","competition",r,s,"entrylist"]},o=>o!=null&&o.drivers?{...o,drivers:o.drivers.filter(l=>l.steamId!==i)}:o)}})}function K(){const{onRegister:s,onWithdraw:t}=C(),r=!!(s&&t);return{isPowerMode:r,isBasicMode:!r}}function Q(s){const{pitvoxUrl:t,partnerSlug:r}=C();return`${t}/p/${r}/competitions/${s}/register`}const cs={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"},Ce=[{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 ls(s){for(const t of Ce)if(t.tags.includes(s))return t.id;return"other"}function ke(s,t){if(t.size===0)return!0;const r={};for(const n of t){const a=ls(n);r[a]||(r[a]=[]),r[a].push(n)}for(const n of Object.values(r))if(!n.some(a=>s.includes(a)))return!1;return!0}function we(s,t){const[r,n]=N.useState(new Set),a=s!==void 0,i=a?s:r,o=N.useCallback(p=>{const c=new Set(i);c.has(p)?c.delete(p):c.add(p),a&&t?t(c):n(c)},[i,a,t]),l=N.useCallback(()=>{a&&t?t(new Set):n(new Set)},[a,t]);return{activeTags:i,toggle:o,clear:l}}function H(s){const[t,r]=N.useState(s),n=N.useCallback(a=>{r(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,n]}function O(s,t,r){return[...s].sort((n,a)=>{const i=r(n,t.key),o=r(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 Le(s,t=!1){const r=t?s==null?void 0:s.filter(n=>n.isValid):s;return r!=null&&r.length?{s1:Math.min(...r.map(n=>n.sector1Ms).filter(Boolean)),s2:Math.min(...r.map(n=>n.sector2Ms).filter(Boolean)),s3:Math.min(...r.map(n=>n.sector3Ms).filter(Boolean))}:null}function ds({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:r,onSort:n,className:a=""}){return e.jsx("th",{className:`pvx-th pvx-th--sortable ${a}`,onClick:()=>n(t),children:e.jsxs("span",{className:"pvx-th-inner",children:[s,e.jsx(ds,{active:r.key===t,dir:r.dir})]})})}function W({userId:s,getUserDisplay:t}){const{displayName:r,avatarUrl:n}=t(s);return e.jsxs("span",{className:"pvx-driver",children:[n?e.jsx("img",{src:n,alt:"",className:"pvx-driver-avatar"}):e.jsx("span",{className:"pvx-driver-avatar pvx-driver-avatar--placeholder"}),e.jsx("span",{className:"pvx-driver-name",children:r})]})}function ie({rank:s,podium:t=!1}){const r=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:r,children:s})}function Se({availableTags:s,activeTags:t,onToggle:r,onClear:n}){if(!s||s.length<2)return null;const a=Ce.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:n,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:()=>r(l),className:`pvx-tag ${t.has(l)?"pvx-tag--active":""}`,children:cs[l]||l},l))]},i.id))]})}function oe({segments:s}){return e.jsx("nav",{className:"pvx-breadcrumb","aria-label":"Breadcrumb",children:e.jsx("ol",{className:"pvx-breadcrumb-list",children:s.map((t,r)=>{const n=r===s.length-1;return e.jsxs("li",{className:"pvx-breadcrumb-item",children:[r>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"})}),!n&&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 F(){return e.jsx("div",{className:"pvx-loading",children:"Loading..."})}function ps(){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 xs(){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 us({tracks:s,isLoading:t,carMetadata:r,getUserDisplay:n,onTrackSelect:a,tags:i,onTagChange:o}){const[l,p]=H({key:"record.timestamp",dir:"desc"}),{activeTags:c,toggle:d,clear:g}=we(i,o),h=N.useMemo(()=>{var u;if(!((u=r==null?void 0:r.tags)!=null&&u.length))return[];const v=new Set;for(const j of s||[])j.recordByTag&&Object.keys(j.recordByTag).forEach(m=>v.add(m));return r.tags.filter(j=>v.has(j))},[s,r]),x=N.useMemo(()=>s?c.size===0?s:s.map(v=>{var m,b;if(!v.recordByTag)return null;let u=null;const j=new Set;for(const w of Object.values(v.recordByTag)){if(j.has(w.carId))continue;j.add(w.carId);const k=((b=(m=r==null?void 0:r.cars)==null?void 0:m[w.carId])==null?void 0:b.tags)||["sports_car"];ke(k,c)&&(!u||w.lapTimeMs<u.lapTimeMs)&&(u=w)}return u?{...v,record:{visibleId:u.steamId||u.identifier,carId:u.carId,carDisplayName:M(u.carId),lapTimeMs:u.lapTimeMs,timestamp:u.recordedAt}}:null}).filter(Boolean):[],[s,c,r]),f=N.useMemo(()=>O(x,l,(v,u)=>{var j,m;switch(u){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}}),[x,l]);return t?e.jsx(F,{}):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(Se,{availableTags:h,activeTags:c,onToggle:d,onClear:g}),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:p}),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:p}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:l,onSort:p,className:"pvx-hidden-below-md"}),e.jsx(R,{label:"Cars",sortKey:"carCount",config:l,onSort:p,className:"pvx-hidden-below-lg"}),e.jsx(R,{label:"Date",sortKey:"record.timestamp",config:l,onSort:p,className:"pvx-hidden-below-xl"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:f.map(v=>{var u,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:(u=v.record)!=null&&u.visibleId?e.jsx(W,{userId:v.record.visibleId,getUserDisplay:n}):"-"}),e.jsx("td",{className:"pvx-td pvx-hidden-below-lg",children:((j=v.record)==null?void 0:j.carDisplayName)||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:v.record?P(v.record.lapTimeMs):"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-md",children:v.driverCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:v.carCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:(m=v.record)!=null&&m.timestamp?A(v.record.timestamp):"-"})]},`${v.id}|${v.layout||""}`)})})]})})]}):e.jsx(U,{message:"No lap times recorded yet."})}function ms({entries:s,isLoading:t,track:r,carMetadata:n,getUserDisplay:a,onCarSelect:i,onNavigate:o,tags:l,onTagChange:p}){const[c,d]=H({key:"lapTimeMs",dir:"asc"}),{activeTags:g,toggle:h,clear:x}=we(l,p),f=N.useMemo(()=>{var b,w,k;if(!s||!((b=n==null?void 0:n.tags)!=null&&b.length))return[];const m=new Set;for(const L of s)(((k=(w=n.cars)==null?void 0:w[L.carId])==null?void 0:k.tags)||["sports_car"]).forEach(E=>m.add(E));return n.tags.filter(L=>m.has(L))},[s,n]),v=N.useMemo(()=>s?g.size===0?s:s.filter(m=>{var w,k;const b=((k=(w=n==null?void 0:n.cars)==null?void 0:w[m.carId])==null?void 0:k.tags)||["sports_car"];return ke(b,g)}):[],[s,g,n]),u=N.useMemo(()=>O(v,c,(m,b)=>{switch(b){case"carId":return M(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:r.displayName}];return t?e.jsx(F,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(oe,{segments:j})}),e.jsx(Se,{availableTags:f,activeTags:g,onToggle:h,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:d}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:c,onSort:d}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:c,onSort:d,className:"pvx-hidden-below-md"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:u.map((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(ie,{rank:b+1,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:M(m.carId)}),e.jsx("td",{className:"pvx-td",children:e.jsx(W,{userId:m.steamId||m.userId,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:P(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?A(m.recordedAt):"-"})]},m.carId))})]})}):e.jsx(U,{message:"No lap times for this track yet."})]})}function vs({entries:s,isLoading:t,track:r,carId:n,getUserDisplay:a,onDriverSelect:i,onNavigate:o,highlightId:l}){const[p,c]=H({key:"lapTimeMs",dir:"asc"}),d=N.useMemo(()=>Le(s),[s]),g=N.useMemo(()=>O(s||[],p,(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,p,a]),h=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:r.displayName,onClick:()=>o("track")},{key:"car",label:M(n)}];return t?e.jsx(F,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(oe,{segments:h})}),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:p,onSort:c}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:p,onSort:c}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Tyre"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Fuel"}),e.jsx(R,{label:"Laps",sortKey:"lapCount",config:p,onSort:c,className:"pvx-hidden-below-lg"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:g.map((x,f)=>{const v=f+1,u=x.steamId||x.userId,j=d&&x.sector1Ms===d.s1,m=d&&x.sector2Ms===d.s2,b=d&&x.sector3Ms===d.s3,w=l&&u===l;return e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${w?"pvx-row--highlight":v<=3?"pvx-row--podium":""}`,onClick:()=>i(u),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ie,{rank:v,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(W,{userId:u,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:P(x.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${j?"pvx-td--best-sector":""}`,children:$(x.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${m?"pvx-td--best-sector":""}`,children:$(x.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${b?"pvx-td--best-sector":""}`,children:$(x.sector3Ms)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:Z(x.tyreCompound),children:x.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-xl",children:X(x.startingFuelL)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:x.lapCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:x.recordedAt?A(x.recordedAt):"-"})]},u)})})]})}):e.jsx(U,{message:"No lap times for this car yet."})]})}function hs({userId:s,track:t,carId:r,game:n,gameVersion:a,showInvalid:i,getUserDisplay:o,onToggleInvalid:l,onNavigate:p}){const{data:c,driverName:d,theoreticalBest:g,isLoading:h}=fe(s,t.id,t.layout,r,{showInvalid:i,game:n,gameVersion:a}),{displayName:x,avatarUrl:f}=o(s,d),v=N.useMemo(()=>Le(c,!0),[c]),u=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:()=>p("tracks")},{key:"track",label:t.displayName,onClick:()=>p("track")},{key:"car",label:M(r),onClick:()=>p("car")},{key:"driver",label:x}];return h?e.jsx(F,{}):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(oe,{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"})]})]}),g&&e.jsxs("div",{className:"pvx-theoretical-best",children:[e.jsx("span",{className:"pvx-theoretical-best-label",children:"Theoretical Best:"}),e.jsx("span",{className:"pvx-theoretical-best-time",children:P(g.lapTimeMs)}),e.jsxs("span",{className:"pvx-theoretical-best-sectors",children:["(",$(g.sector1Ms)," + ",$(g.sector2Ms)," + ",$(g.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===u,k=v&&m.isValid&&m.sector1Ms===v.s1,L=v&&m.isValid&&m.sector2Ms===v.s2,T=v&&m.isValid&&m.sector3Ms===v.s3;let E="pvx-row";return m.isValid||(E+=" pvx-row--invalid"),w&&(E+=" pvx-row--personal-best"),e.jsxs("tr",{className:E,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:P(m.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${k?"pvx-td--best-sector":""}`,children:$(m.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${L?"pvx-td--best-sector":""}`,children:$(m.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${T?"pvx-td--best-sector":""}`,children:$(m.sector3Ms)}),e.jsx("td",{className:"pvx-td",title:m.isValid?void 0:m.invalidReason||"Invalid",children:m.isValid?e.jsx(ps,{}):e.jsx(xs,{})}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:Z(m.tyreCompound),children:m.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:X(m.startingFuelL)}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:A(m.timestamp)})]},m.id)})})]})}):e.jsx(U,{message:i?"No laps recorded for this combination.":'No valid laps. Try enabling "Show invalid laps".'})]})}function gs({drivers:s,isLoading:t,getUserDisplay:r,game:n,gameVersion:a,onComboSelect:i}){const[o,l]=H({key:"rank",dir:"asc"}),[p,c]=N.useState(null),d=N.useMemo(()=>s?O(s,o,(h,x)=>{switch(x){case"rating":return h.rating;case"comboCount":return h.comboCount||0;case"distinctCars":return h.distinctCars||0;case"rank":default:return h.rank}}):[],[s,o]);if(t)return e.jsx(F,{});if(!(s!=null&&s.length))return e.jsx("div",{className:"pvx-card",children:e.jsx(U,{message:"Not enough data for rankings yet."})});const g=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:d.map(h=>{const x=p===h.identifier;return e.jsx(js,{driver:h,getUserDisplay:r,isExpanded:x,onToggle:()=>c(x?null:h.identifier),colCount:g,game:n,gameVersion:a,onComboSelect:i},h.identifier)})})]})})]})}function js({driver:s,getUserDisplay:t,isExpanded:r,onToggle:n,colCount:a,game:i,gameVersion:o,onComboSelect:l}){const p=s.identifier;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${s.rank<=3?"pvx-row--podium":""}`,onClick:n,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ie,{rank:s.rank,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(W,{userId:p,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 ${r?"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"})})]})})]}),r&&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,d)=>{const g=c.layout?`${c.trackId}|${c.layout}`:c.trackId,h=l?()=>l({track:g,car:c.carId,highlight:p,game:i,gameVersion:o}):void 0;return e.jsxs("div",{className:`pvx-rankings-combo ${h?"pvx-rankings-combo--clickable":""}`,onClick:h,role:h?"button":void 0,children:[e.jsxs("div",{className:"pvx-rankings-combo-info",children:[e.jsx("p",{className:"pvx-rankings-combo-track",children:B(c.trackId,c.layout,i)}),e.jsx("p",{className:"pvx-rankings-combo-car",children:M(c.carId)})]}),e.jsxs("div",{className:"pvx-rankings-combo-stats",children:[e.jsx("p",{className:"pvx-rankings-combo-time",children:P(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,")"]})]})]})]},d)})})})})]})}const fs={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:"🇰🇷"},G=["🥇","🥈","🥉"],Ns={championship:"Championship",series:"Series",event:"Event"},bs=["PRACTICE","QUALIFYING","RACE"];function xe(s){const t=bs.indexOf(s);if(t>=0)return t;const r=s.match(/^PRACTICE_(\d+)$/);return r?100+parseInt(r[1]):999}function Te(s){const t=s.match(/^PRACTICE_(\d+)$/);return t?`P${t[1]}`:s}function Re({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 ce({nation:s}){const t=s&&fs[s];return t?e.jsx("span",{className:"pvx-nation-flag",title:s,children:t}):null}function ys({sessions:s,activeSession:t,onSelect:r}){if(!s||s.length<=1)return null;const n=[...s].sort((a,i)=>xe(a.type)-xe(i.type));return e.jsx("div",{className:"pvx-session-tabs",children:n.map(a=>e.jsx("button",{onClick:()=>r(a.type),className:`pvx-session-tab ${t===a.type?"pvx-session-tab--active":""}`,children:Te(a.type)},a.type))})}function Me({type:s}){return e.jsx("span",{className:`pvx-comp-badge pvx-comp-badge--${s}`,children:Ns[s]||s})}function _({children:s,variant:t="default"}){return e.jsx("span",{className:`pvx-info-pill ${t!=="default"?`pvx-info-pill--${t}`:""}`,children:s})}function Cs(s){if(!s)return"TBD";const t=new Date(s);if(isNaN(t))return"TBD";const r=t.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),n=t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return`${r} • ${n}`}function ks(s){return s.reduce((t,r)=>{var n;return(n=r.splits)!=null&&n.length?t?t.map((a,i)=>{const o=r.splits[i];return o&&o<a?o:a}):[...r.splits]:t},null)}function I({message:s="Loading..."}){return e.jsx("div",{className:"pvx-loading",children:s})}function D({message:s="No data available."}){return e.jsx("div",{className:"pvx-empty",children:e.jsx("p",{children:s})})}const le=3;function $e(s){const t=s==null?void 0:s.rounds;return t!=null&&t.length?t.every(r=>r.isFinalized):!1}function De(s){const t=s==null?void 0:s.rounds;if(!(t!=null&&t.length))return null;let r=null;for(const n of t){if(!n.startTime)continue;const a=new Date(n.startTime);isNaN(a)||(!r||a>r)&&(r=a)}return r}function de(s,t=le){if(!$e(s))return"active";const r=De(s);if(!r)return"recently-completed";const n=t*24*60*60*1e3;return Date.now()-r.getTime()<=n?"recently-completed":"archived"}function ws(s,t,r=le){if(!(s!=null&&s.length))return[];const n=new Set(Array.isArray(t)?t:[t]);return s.filter(a=>n.has(de(a,r)))}function Pe(s,t=3){const r=s==null?void 0:s.standings;return Array.isArray(r)?[...r].sort((n,a)=>(n.position??999)-(a.position??999)).slice(0,t):[]}function Ie({competitionId:s,topN:t=3,label:r="Completed",className:n}){const{data:a}=te(s),i=Pe(a,t);return e.jsxs("div",{className:`pvx-comp-completed-badge ${n||""}`,children:[e.jsx("span",{className:"pvx-comp-completed-badge-label",children:r}),i.length>0&&e.jsx("ol",{className:"pvx-comp-completed-badge-podium",children:i.map((o,l)=>e.jsxs("li",{className:"pvx-comp-completed-badge-driver",children:[e.jsx("span",{className:"pvx-comp-completed-badge-medal","aria-hidden":"true",children:G[l]||""}),e.jsx(ce,{nation:o.nation}),e.jsx("span",{className:"pvx-comp-completed-badge-name",children:o.driverName})]},o.driverId||l))})]})}function Ls({competitions:s,isLoading:t,onSelect:r,onRegister:n,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(Be,{comp:i,onSelect:r,onRegister:n||r},i.id))}):e.jsx(D,{message:"No competitions available."})}function Be({comp:s,onSelect:t,onRegister:r}){var m,b,w;const{cdnUrl:n}=C(),a=s.posterCdnPath?`${n}/${s.posterCdnPath}`:null,i=s.registration,o=(i==null?void 0:i.currentCount)||0,l=i==null?void 0:i.maxParticipants,p=l&&o>=l,c=(i==null?void 0:i.deadline)&&new Date(i.deadline)<new Date,d=(i==null?void 0:i.isOpen)&&!c&&!p,g=new Date,h=(m=s.rounds)==null?void 0:m.find(k=>k.startTime&&new Date(k.startTime)>=g),x=((b=s.rounds)==null?void 0:b.length)||0,f=((w=s.rounds)==null?void 0:w.filter(k=>k.isFinalized).length)||0,v=de(s),u=v==="recently-completed"||v==="archived",j=s.type==="championship";return e.jsxs("div",{className:"pvx-comp-card",onClick:()=>t(s.id),role:"button",tabIndex:0,onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&(k.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(Ts,{})})}),e.jsxs("div",{className:"pvx-comp-card-body",children:[e.jsx("h3",{className:"pvx-comp-card-title",children:s.name}),s.description&&e.jsx("p",{className:"pvx-comp-card-desc",children:s.description}),e.jsxs("div",{className:"pvx-comp-card-pills",children:[e.jsx(Me,{type:s.type}),s.game&&e.jsx(_,{children:s.game.toUpperCase()}),s.formatDescription&&s.formatDescription.split(", ").map((k,L)=>e.jsx(_,{variant:"format",children:k},L))]}),s.carsDescription&&e.jsx("div",{className:"pvx-comp-card-pills",children:s.carsDescription.split(", ").map((k,L)=>e.jsx(_,{children:k},L))}),e.jsxs("div",{className:"pvx-comp-card-schedule",children:[h?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[e.jsx("span",{className:"pvx-comp-card-schedule-label",children:"Next:"})," ","R",h.roundNumber," ",h.track||"TBD"," — ",Cs(h.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":""]})]}),u&&j&&e.jsx(Ie,{competitionId:s.id}),i&&!u&&e.jsx(Ss,{competitionId:s.id,regOpen:d,isFull:p,deadlinePassed:c,regCount:o,regMax:l,onRegister:r})]})]})}function Ss({competitionId:s,regOpen:t,isFull:r,deadlinePassed:n,regCount:a,regMax:i,onRegister:o}){const{isPowerMode:l}=K(),p=Q(s),{data:c}=V(s),d=(c==null?void 0:c.isRegistered)||!1,g=i?a/i*100:0,h=g>=100?"full":g>=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--${h}`,children:[a,"/",i||"∞"," drivers"]})}),e.jsx("div",{className:"pvx-comp-card-reg-action",children:d?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:p,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:r?"Full":"Closed"})})]})}function Ts(){return e.jsxs("svg",{className:"pvx-comp-trophy-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 0 1 0-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 0 0 0-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0 0 12 0V2Z"})]})}function Ae({competitionId:s,className:t}){var l,p;const{data:r,isLoading:n}=te(s),{data:a,isLoading:i}=se(s);if(n||i)return e.jsx(I,{message:"Loading standings..."});if(!((l=r==null?void 0:r.standings)!=null&&l.length))return e.jsx(D,{message:"No standings data yet. Results will appear once rounds are finalised."});const o=((p=a==null?void 0:a.rounds)==null?void 0:p.filter(c=>c.isFinalized))||[];return e.jsxs("div",{className:`pvx-card ${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 ",r.roundsCompleted," round",r.roundsCompleted!==1?"s":"",r.countingRounds>0&&` (best ${r.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:r.standings.map(c=>e.jsx(Rs,{driver:c,finalizedRounds:o},c.driverId||c.driverName))})]})})]})}function Rs({driver:s,finalizedRounds:t}){var o,l,p;const r=s.position<=3,n=new Map(((o=s.roundResults)==null?void 0:o.map(c=>[c.roundNumber,c]))||[]),a=((l=s.roundResults)==null?void 0:l.filter(c=>c.position===1).length)||0,i=((p=s.roundResults)==null?void 0:p.filter(c=>c.position<=3).length)||0;return e.jsxs("tr",{className:`pvx-row ${r?"pvx-row--podium":""}`,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(Re,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ce,{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 d=n.get(c.roundNumber),g=d==null?void 0:d.dropped;return e.jsx("td",{className:`pvx-td pvx-td--center pvx-hidden-below-md ${!g&&(d==null?void 0:d.position)===1?"pvx-standings-cell--p1":!g&&(d==null?void 0:d.position)===2?"pvx-standings-cell--p2":!g&&(d==null?void 0:d.position)===3?"pvx-standings-cell--p3":""}`,children:d?e.jsxs("div",{className:`pvx-standings-round-cell ${g?"pvx-standings-round-cell--dropped":""}`,children:[e.jsxs("span",{className:"pvx-standings-round-pos",children:["P",d.position]}),e.jsx("span",{className:"pvx-standings-round-pts",children:d.points})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})},c.roundNumber)})]})}function Ms({competitionId:s,roundNumber:t,className:r}){var p;const{data:n,isLoading:a}=Ne(s,t);if(a)return e.jsx(I,{message:"Loading results..."});if(!n)return e.jsx(D,{message:"No results for this round."});const o=(n.sessions||[]).find(c=>c.type==="RACE"),l=(p=o==null?void 0:o.results)==null?void 0:p.filter(c=>c.position<=3).sort((c,d)=>c.position-d.position);return e.jsxs("div",{className:`pvx-round-results ${r||""}`,children:[e.jsxs("div",{className:"pvx-round-results-header",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"pvx-round-results-title",children:["Round ",n.roundNumber,n.track?`: ${n.track}`:""]}),n.startTime&&e.jsx("p",{className:"pvx-round-results-date",children:new Date(n.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:G[c.position-1]}),e.jsx("span",{children:c.driverName})]},c.driverId))})]}),e.jsx(pe,{round:n,competitionId:s})]})}function pe({round:s,competitionId:t,className:r}){var d,g,h,x;const[n,a]=N.useState(null),i=(s==null?void 0:s.sessions)||[];if(!i.length)return e.jsx(D,{message:"No session data for this round."});const{data:o}=ye(t,s==null?void 0:s.roundNumber,{}),l=n||((d=i.find(f=>f.type==="RACE"))==null?void 0:d.type)||((g=i[0])==null?void 0:g.type),p=i.find(f=>f.type===l)||i[0],c=((x=(h=o==null?void 0:o.sessions)==null?void 0:h.find(f=>f.type===l))==null?void 0:x.drivers)||null;return e.jsxs("div",{className:r||"",children:[e.jsx(ys,{sessions:i,activeSession:l,onSelect:a}),e.jsx($s,{session:p,sessionLaps:c})]})}function $s({session:s,sessionLaps:t}){var l;const r=s.type==="RACE",[n,a]=N.useState(null);if(!((l=s.results)!=null&&l.length))return e.jsx(D,{message:`No results for ${s.type}.`});const i=ks(s.results),o=r?7:4;return e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Car"}),e.jsx("th",{className:"pvx-th",children:"Best Lap"}),r&&e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Laps"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Time / Gap"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"})]})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.results.map((p,c)=>{var h;const d=(h=t==null?void 0:t[p.driverId])==null?void 0:h.laps,g=n===p.driverId&&!!d;return e.jsx(Ds,{result:p,isRace:r,fastestSplits:i,rowIndex:c,hasLapDetail:!!d,isExpanded:g,onToggle:()=>a(g?null:p.driverId),driverLaps:g?d:null,colCount:o},p.driverId||c)})})]})})}function Ds({result:s,isRace:t,fastestSplits:r,rowIndex:n,hasLapDetail:a,isExpanded:i,onToggle:o,driverLaps:l,colCount:p}){const c=s.position<=3;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row ${c?"pvx-row--podium":""} ${a?"pvx-row--expandable":""}`,onClick:a?o:void 0,style:a?{cursor:"pointer"}:void 0,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(Re,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ce,{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:M(s.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx(Is,{bestLap:s.bestLapFormatted,hasBestLap:s.hasBestLap,splits:s.splits,fastestSplits:r,showAbove:n<=1})}),t&&e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:s.lapsCompleted}),e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:s.position===1?s.totalTime||"-":s.gap||"-"}),e.jsxs("td",{className:"pvx-td pvx-td--center",children:[e.jsx("span",{className:"pvx-session-points",children:s.points}),s.pointsOverride!==0&&s.pointsOverride&&e.jsxs("span",{className:"pvx-points-override",children:["(",s.pointsOverride>0?"+":"",s.pointsOverride,")"]})]})]})]}),i&&l&&e.jsx("tr",{className:"pvx-row pvx-row--lap-detail",children:e.jsx("td",{colSpan:p,className:"pvx-td pvx-td--lap-detail",children:e.jsx(Ps,{laps:l})})})]})}function Ps({laps:s}){const t=Math.min(...s.filter(r=>r.valid&&r.timeMs>0).map(r=>r.timeMs));return e.jsxs("table",{className:"pvx-table pvx-table--laps",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Lap"}),e.jsx("th",{className:"pvx-th",children:"Time"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.map(r=>{var a;const n=r.valid&&r.timeMs===t;return e.jsxs("tr",{className:`pvx-row ${r.valid?"":"pvx-row--invalid"} ${n?"pvx-row--fastest":""}`,children:[e.jsx("td",{className:"pvx-td pvx-td--muted",children:r.lap}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:r.time}),(r.splits||[]).map((i,o)=>e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:i},o)),Array.from({length:Math.max(0,3-(((a=r.splits)==null?void 0:a.length)||0))}).map((i,o)=>e.jsx("td",{className:"pvx-td pvx-hidden-below-sm"},`pad-${o}`))]},r.lap)})})]})}function Is({bestLap:s,hasBestLap:t,splits:r,fastestSplits:n,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}),(r==null?void 0:r.length)>0&&e.jsx("span",{className:"pvx-splits-tooltip-anchor",children:e.jsx("span",{className:`pvx-splits-tooltip ${a?"":"pvx-splits-tooltip--above"}`,children:r.map((i,o)=>{const l=n&&i===n[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:r}=C(),{data:n,isLoading:a}=re(s),i=r();if(a)return e.jsx(I,{message:"Loading drivers..."});const o=(n==null?void 0:n.drivers)||(n==null?void 0:n.entries)||[];return o.length?e.jsx("div",{className:`pvx-entry-grid ${t||""}`,children:o.map(l=>{var c,d;const p=i&&l.steamId===i;return e.jsxs("div",{className:`pvx-entry-card ${p?"pvx-entry-card--you":""}`,children:[l.avatarUrl?e.jsx("img",{src:l.avatarUrl,alt:"",className:"pvx-entry-avatar"}):e.jsx("div",{className:"pvx-entry-avatar pvx-entry-avatar--placeholder",children:((d=(c=l.displayName)==null?void 0:c.charAt(0))==null?void 0:d.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-entry-name",children:[l.displayName,p&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},l.steamId||l.driverId)})}):e.jsx(D,{message:"No drivers registered yet."})}function As({competitionId:s,driverData:t,className:r,children:n}){const{data:a,isLoading:i}=V(s),{isPowerMode:o}=K(),l=Q(s),p=ne(s),c=ae(s),d=(a==null?void 0:a.isRegistered)||!1,g=i||p.isPending||c.isPending,h=p.error||c.error||null,x=()=>{o&&p.mutate(t||{})},f=()=>{o&&c.mutate()};return typeof n=="function"?n({isRegistered:d,isLoading:g,register:x,withdraw:f,error:h,isPowerMode:o,registrationUrl:l}):o?e.jsx("button",{className:`pvx-comp-register-btn ${r||""}`,onClick:d?f:x,disabled:g,children:g?"Loading...":d?"Withdraw":"Register"}):e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:`pvx-comp-register-link ${r||""}`,children:d?"View Registration":"Register on PitVox"})}function Es({competitionId:s,registration:t,onWithdrawSuccess:r,className:n}){const{getSteamId:a}=C(),{isPowerMode:i}=K(),o=Q(s),{data:l,isLoading:p}=V(s),{data:c,isLoading:d}=re(s),g=ne(s),h=ae(s),x=a(),f=(l==null?void 0:l.isRegistered)||!1,v=(c==null?void 0:c.drivers)||(c==null?void 0:c.entries)||[],u=t||{},j=v.length||u.currentCount||0,m=u.maxParticipants&&j>=u.maxParticipants,b=u.deadline&&new Date(u.deadline)<new Date,w=u.isOpen&&!b&&!m;return p||d?e.jsx(I,{message:"Loading registration..."}):f?e.jsx("div",{className:`pvx-reg-panel ${n||""}`,children:e.jsx(Fs,{competitionId:s,drivers:v,steamId:x,isPowerMode:i,registrationUrl:o,withdrawMutation:h,onWithdrawSuccess:r,registration:u})}):w?x?i?e.jsx("div",{className:`pvx-reg-panel ${n||""}`,children:e.jsx(Us,{competitionId:s,registerMutation:g,registration:u})}):e.jsx("div",{className:`pvx-reg-panel ${n||""}`,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 ${n||""}`,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 ${n||""}`,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(Ee,{drivers:v,steamId:x})]})}function Us({competitionId:s,registerMutation:t,registration:r}){const[n,a]=N.useState(""),[i,o]=N.useState("intermediate"),[l,p]=N.useState(""),c=x=>{x.preventDefault(),t.mutate({discordUsername:n||void 0,experience:i,comments:l||void 0})},d=r||{},g=d.currentCount||0,h=d.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"}),h&&e.jsx(Ue,{count:g,max:h})]}),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:n,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=>p(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 Fs({competitionId:s,drivers:t,steamId:r,isPowerMode:n,registrationUrl:a,withdrawMutation:i,onWithdrawSuccess:o,registration:l}){const[p,c]=N.useState(!1),d=()=>{i.mutate(void 0,{onSuccess:()=>{c(!1),o&&o()}})},g=l||{},h=t.length||g.currentCount||0,x=g.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(Ue,{count:h,max:x})]}),e.jsx(Ee,{drivers:t,steamId:r}),i.error&&e.jsx("div",{className:"pvx-reg-error",children:i.error.message||"Withdrawal failed"}),n?e.jsx("div",{className:"pvx-reg-actions",children:p?e.jsxs("div",{className:"pvx-reg-confirm",children:[e.jsx("p",{className:"pvx-reg-confirm-text",children:"Are you sure you want to unregister?"}),e.jsxs("div",{className:"pvx-reg-confirm-actions",children:[e.jsx("button",{type:"button",className:"pvx-reg-cancel-btn",onClick:()=>c(!1),children:"Cancel"}),e.jsx("button",{type:"button",className:"pvx-reg-danger-btn",onClick:d,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 Ee({drivers:s,steamId:t}){if(!s.length)return e.jsx("div",{className:"pvx-reg-no-drivers",children:"No drivers registered yet."});const r=[...s].sort((n,a)=>{const i=t&&n.steamId===t?-1:0,o=t&&a.steamId===t?-1:0;return i-o});return e.jsx("div",{className:"pvx-reg-driver-list",children:r.map(n=>{var i,o;const a=t&&n.steamId===t;return e.jsxs("div",{className:`pvx-reg-driver-row ${a?"pvx-reg-driver-row--you":""}`,children:[n.avatarUrl?e.jsx("img",{src:n.avatarUrl,alt:"",className:"pvx-reg-driver-avatar"}):e.jsx("div",{className:"pvx-reg-driver-avatar pvx-reg-driver-avatar--placeholder",children:((o=(i=n.displayName)==null?void 0:i.charAt(0))==null?void 0:o.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-reg-driver-name",children:[n.displayName,a&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},n.steamId||n.driverId)})})}function Ue({count:s,max:t}){const r=t?s/t*100:0,n=r>=100?"full":r>=75?"warning":"ok";return e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${n}`,children:[s,"/",t," drivers"]})}function _s({competitionId:s,className:t}){const{data:r,isLoading:n}=se(s),a=(r==null?void 0:r.type)==="championship",i=N.useMemo(()=>{var u;return((u=r==null?void 0:r.rounds)==null?void 0:u.filter(j=>j.isFinalized))||[]},[r]),o=N.useMemo(()=>i.map(u=>u.roundNumber),[i]),{data:l=[],isLoading:p}=be(s,o),c=a?"standings":o.length>0?`round-${o[o.length-1]}`:null,[d,g]=N.useState(null),h=d||c;if(n||p)return e.jsx(I,{message:"Loading results..."});if(!r)return e.jsx(D,{message:"Competition not found."});if(!i.length)return e.jsx(D,{message:"No results available yet. Results will appear here once rounds are finalised."});const x=new Map(l.map(u=>[`round-${u.roundNumber}`,u])),f=[];a&&f.push({id:"standings",label:"Standings"});for(const u of i)f.push({id:`round-${u.roundNumber}`,label:`R${u.roundNumber}`,track:null});const v=x.get(h);return e.jsxs("div",{className:t||"",children:[e.jsx("div",{className:"pvx-results-tabs",children:f.map(u=>e.jsxs("button",{className:`pvx-results-tab ${h===u.id?"pvx-results-tab--active":""}`,onClick:()=>g(u.id),title:u.track||void 0,children:[e.jsx("span",{className:"pvx-results-tab-label",children:u.label}),u.track&&e.jsx("span",{className:"pvx-results-tab-track",children:u.track})]},u.id))}),h==="standings"?e.jsx(Ae,{competitionId:s}):v?e.jsx(qs,{round:v}):e.jsx(D,{message:"No results for this round."})]})}function qs({round:s}){var a;const r=(s.sessions||[]).find(i=>i.type==="RACE"),n=(a=r==null?void 0:r.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"})})]}),(n==null?void 0:n.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:n.map(i=>e.jsxs("span",{className:"pvx-round-podium-item",children:[e.jsx("span",{children:G[i.position-1]}),e.jsx("span",{children:i.driverName})]},i.driverId))})]}),e.jsx(pe,{round:s})]})}function Fe(s){const{cdnUrl:t}=C(),r=y.useQuery({queryKey:["pitvox","laps","global",s,"index"],queryFn:()=>S(t,ve(null,s)),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),n=r.data;return{isLoading:r.isLoading,error:r.error,data:n?{driverName:n.driverName||"Driver",lapCount:n.lapCount||0,trackBreakdown:n.trackBreakdown||[],carBreakdown:n.carBreakdown||[],recordsHeld:n.recordsHeld||0,currentRecords:n.currentRecords||[],bestRanking:n.bestRanking??null,bestRankingTrackId:n.bestRankingTrackId??null,bestRankingLayout:n.bestRankingLayout??null,bestRankingCarId:n.bestRankingCarId??null,generatedAt:n.generatedAt}:null}}function _e(s={}){const{cdnUrl:t,partnerSlug:r}=C(),{game:n,gameVersion:a,enabled:i=!0}=s,o=q(r,n,a,"ratings.json");return y.useQuery({queryKey:["pitvox","ratings",r,n||null,a||null],queryFn:()=>S(t,o),staleTime:3e4,refetchInterval:3e4,enabled:i})}function qe(s){var n;const t=_e(),r=N.useMemo(()=>{var a;return!((a=t.data)!=null&&a.drivers)||!s?null:t.data.drivers.find(i=>i.identifier===s)||null},[(n=t.data)==null?void 0:n.drivers,s]);return{isLoading:t.isLoading,error:t.error,data:r?{rating:r.rating,rank:r.rank,totalDrivers:t.data.driverCount||t.data.drivers.length,comboCount:r.comboCount||0,distinctCars:r.distinctCars||0,combos:r.combos||[]}:null}}function Vs(s={}){const t=_e(s);return{data:t.data||null,isLoading:t.isLoading,error:t.error}}function Ve(){const{cdnUrl:s,partnerSlug:t,getSteamId:r,onFetchServerPassword:n}=C(),a=r(),{data:i,isLoading:o}=y.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const x=await S(s,"competitions/index.json");return x!=null&&x.competitions?x.competitions.filter(f=>f.partnerSlug===t):[]},staleTime:6e4}),l=(i==null?void 0:i.map(x=>x.id))||[],p=y.useQueries({queries:l.map(x=>({queryKey:["pitvox","competition",t,x,"entrylist"],queryFn:()=>S(s,`competitions/${t}/${x}/entrylist.json`),enabled:!!a&&l.length>0,staleTime:6e4}))}),c=p.some(x=>x.isLoading),d=N.useMemo(()=>{var v,u;if(!i||!a||c)return[];const x=new Date,f=[];for(let j=0;j<i.length;j++){const m=i[j],b=(v=p[j])==null?void 0:v.data;if(!((u=b==null?void 0:b.drivers)==null?void 0:u.some(L=>L.steamId===a)))continue;const k=m.rounds||[];for(const L of k)L.isFinalized||!L.startTime||new Date(L.startTime)<=x||f.push({competitionId:m.id,competitionName:m.name,roundNumber:L.roundNumber,track:L.track||"TBD",startTime:L.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,p]),g=y.useQueries({queries:d.map(x=>({queryKey:["pitvox","serverInfo",x.competitionId,x.roundNumber],queryFn:()=>n(x.competitionId,x.roundNumber),enabled:!!n&&d.length>0,staleTime:5*6e4,retry:!1}))});return{data:N.useMemo(()=>d.length?n?d.map((x,f)=>{var u;const v=(u=g[f])==null?void 0:u.data;return v!=null&&v.success?{...x,serverAddress:v.serverAddress||null,serverPassword:v.serverPassword||null}:x}):d:[],[d,n,g]),isLoading:o||!!a&&c}}function Ke(){const{onFetchNotifications:s}=C();return!!s}function Qe(s={}){const{onFetchNotifications:t,partnerSlug:r}=C(),{limit:n=20,unreadOnly:a=!1}=s;return y.useQuery({queryKey:["pitvox","notifications",r,{limit:n,unreadOnly:a}],queryFn:()=>t({limit:n,unreadOnly:a}),enabled:!!t,staleTime:3e4,refetchInterval:3e4})}function Ks(){const{onFetchNotifications:s,partnerSlug:t}=C(),{data:r,isLoading:n}=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:r??0,isLoading:n}}function He(){const{onMarkNotificationRead:s,partnerSlug:t}=C(),r=y.useQueryClient();return y.useMutation({mutationFn:n=>{if(!s)throw new Error("No onMarkNotificationRead callback provided to PitVoxPartnerProvider.");return s(n)},onSuccess:(n,a)=>{r.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 Oe(){const{onMarkAllNotificationsRead:s,partnerSlug:t}=C(),r=y.useQueryClient();return y.useMutation({mutationFn:()=>{if(!s)throw new Error("No onMarkAllNotificationsRead callback provided to PitVoxPartnerProvider.");return s()},onSuccess:()=>{r.setQueriesData({queryKey:["pitvox","notifications",t]},n=>n!=null&&n.notifications?{...n,unreadCount:0,notifications:n.notifications.map(a=>({...a,isRead:!0,readAt:a.readAt||new Date().toISOString()}))}:n)}})}function We({driverName:s,avatarUrl:t,memberSince:r,className:n=""}){const a=r?new Date(r).toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"numeric"}):null;return e.jsxs("div",{className:`pvx-card pvx-dash-profile ${n}`,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 Qs(){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 Hs(){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 Os(){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 ue({icon:s,value:t,label:r,items:n,labelKey:a,countKey:i}){const[o,l]=N.useState(!1),p=N.useRef(null);N.useEffect(()=>{if(!o)return;function d(g){p.current&&!p.current.contains(g.target)&&l(!1)}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[o]);const c=n!=null&&n.length?n.slice().sort((d,g)=>g[i]-d[i]):null;return e.jsxs("div",{ref:p,className:`pvx-dash-stat-card ${c?"pvx-dash-stat-card--clickable":""}`,onClick:c?()=>l(d=>!d):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:r})]}),c&&e.jsx("div",{className:`pvx-dash-tooltip pvx-dash-tooltip--scrollable ${o?"pvx-dash-tooltip--open":""}`,children:c.map((d,g)=>e.jsxs("div",{className:"pvx-dash-tooltip-row",children:[e.jsx("span",{className:"pvx-dash-tooltip-label",children:d[a]}),e.jsx("span",{className:"pvx-dash-tooltip-value",children:d[i]})]},g))})]})}function Ge({stats:s,rating:t,className:r=""}){if(!s)return null;const n=s.trackBreakdown.map(i=>({name:B(i.trackId,i.layout),lapCount:i.lapCount})),a=s.carBreakdown.map(i=>({name:M(i.carId),lapCount:i.lapCount}));return e.jsxs("div",{className:`pvx-dash-stats ${r}`,children:[e.jsx(ue,{icon:e.jsx(Qs,{}),value:s.lapCount.toLocaleString(),label:"Total Laps",items:n,labelKey:"name",countKey:"lapCount"}),e.jsx(ue,{icon:e.jsx(Hs,{}),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(Os,{}),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 ze({records:s,className:t=""}){const r=N.useMemo(()=>s!=null&&s.length?s.slice().sort((n,a)=>{const i=n.recordedAt?new Date(n.recordedAt).getTime():0;return(a.recordedAt?new Date(a.recordedAt).getTime():0)-i}):[],[s]);return r.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:["(",r.length,")"]})]})}),e.jsx("div",{className:"pvx-dash-records-list",children:r.map((n,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:B(n.trackId,n.layout,n.game)}),e.jsx("span",{className:"pvx-dash-record-car",children:M(n.carId)})]}),e.jsxs("div",{className:"pvx-dash-record-time",children:[e.jsx("span",{className:"pvx-dash-record-lap",children:P(n.lapTimeMs)}),e.jsxs("span",{className:`pvx-dash-game-badge pvx-dash-game-badge--${n.game||"evo"}`,children:[(n.game||"evo").toUpperCase(),n.gameVersion?` ${n.gameVersion}`:""]})]})]},a))})]}):null}function Ye({events:s,isLoading:t,className:r,limit:n=3}){if(t)return e.jsx("div",{className:"pvx-loading",children:"Loading upcoming events..."});if(!(s!=null&&s.length))return null;const a=n?s.slice(0,n):s,i=s.length-a.length;return e.jsxs("div",{className:`pvx-card ${r||""}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(zs,{}),"Upcoming Events",e.jsxs("span",{className:"pvx-dash-records-count",children:["(",s.length,")"]})]})}),e.jsxs("div",{className:"pvx-upcoming-list",children:[a.map(o=>e.jsxs("div",{className:`pvx-upcoming-item ${o.isNext?"pvx-upcoming-item--next":""}`,children:[e.jsxs("div",{className:"pvx-upcoming-info",children:[e.jsx("span",{className:"pvx-upcoming-comp",children:o.competitionName}),e.jsxs("span",{className:"pvx-upcoming-round",children:["Round ",o.roundNumber,": ",o.track]}),o.serverPassword&&e.jsx(Ws,{password:o.serverPassword,address:o.serverAddress})]}),e.jsxs("div",{className:"pvx-upcoming-time",children:[e.jsx("span",{className:"pvx-upcoming-date",children:new Date(o.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}),e.jsx("span",{className:"pvx-upcoming-relative",children:o.dediStatus==="running"?"Live now":o.dediStatus==="provisioning"?"Starting...":Gs(o.startTime)}),o.dediStatus==="running"&&e.jsx("span",{className:"pvx-upcoming-badge pvx-upcoming-badge--live",children:"Live"}),!o.dediStatus&&o.isNext&&e.jsx("span",{className:"pvx-upcoming-badge",children:"Next"})]})]},`${o.competitionId}-${o.roundNumber}`)),i>0&&e.jsxs("div",{className:"pvx-upcoming-remaining",children:["+",i," more event",i!==1?"s":""]})]})]})}function Ws({password:s,address:t}){const[r,n]=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),n(!0),setTimeout(()=>n(!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(Js,{})," ",r?"Copied!":"Join"]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick:()=>i(p=>!p),title:a?"Hide password":"Reveal password",children:a?e.jsx(Xs,{}):e.jsx(Zs,{})}),a&&e.jsxs("span",{className:"pvx-server-detail",children:[e.jsx(Ys,{})," ",s]})]})]})}function Gs(s){const t=new Date(s).getTime()-Date.now();if(t<=0)return"Now";const r=Math.floor(t/(1e3*60*60));if(r<1)return"Less than 1 hour";if(r<24)return`in ${r}h`;const n=Math.floor(r/24);if(n===1)return"Tomorrow";if(n<7)return`in ${n} days`;if(n<30){const a=Math.floor(n/7);return`in ${a} week${a!==1?"s":""}`}return J(s)}function zs(){return e.jsxs("svg",{className:"pvx-dash-records-icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M16 2v4M8 2v4M3 10h18"})]})}function Ys(){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 Js(){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 Zs(){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 Xs(){return e.jsxs("svg",{className:"pvx-server-icon pvx-server-icon--action",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),e.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Je({notifications:s,unreadCount:t=0,onMarkRead:r,onMarkAllRead:n,isLoading:a,className:i}){const o=ee();return a?e.jsx("div",{className:"pvx-loading",children:"Loading notifications..."}):e.jsxs("div",{className:`pvx-card ${i||""}`,children:[e.jsxs("div",{className:"pvx-card-header",children:[e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(tt,{}),"Notifications",t>0&&e.jsx("span",{className:"pvx-notif-badge",children:t>99?"99+":t})]}),t>0&&n&&e.jsx("button",{className:"pvx-notif-mark-all",onClick:n,children:"Mark all read"})]}),s!=null&&s.length?e.jsx("div",{className:"pvx-notif-list",children:s.map(l=>e.jsx(et,{notification:l,getUserDisplay:o,onMarkRead:r},l.id))}):e.jsx("div",{className:"pvx-notif-empty",children:"No notifications"})]})}function et({notification:s,getUserDisplay:t,onMarkRead:r}){const n=()=>{!s.isRead&&r&&r(s.id)};return e.jsxs("button",{className:`pvx-notif-item ${s.isRead?"":"pvx-notif-item--unread"}`,onClick:n,children:[e.jsx(st,{type:s.type}),e.jsxs("div",{className:"pvx-notif-content",children:[e.jsx("span",{className:"pvx-notif-message",children:ge(s,t)}),e.jsx("span",{className:"pvx-notif-time",children:J(s.createdAt)})]}),!s.isRead&&e.jsx("span",{className:"pvx-notif-dot"})]})}function st({type:s}){return s==="RECORD_BEATEN"?e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--beaten",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m7 7 10 10M17 7v10H7"})})}):s==="ADMIN_MESSAGE"?e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--admin",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"m3 11 18-5v12L3 13v-2z"}),e.jsx("path",{d:"M11.6 16.8a3 3 0 1 1-5.8-1.6"})]})}):e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--record",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 0 1 0-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 0 0 0-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0 0 12 0V2Z"})]})})}function tt(){return e.jsxs("svg",{className:"pvx-dash-records-icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"}),e.jsx("path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0"})]})}function rt({steamId:s,avatarUrl:t,memberSince:r,className:n=""}){const{data:a,isLoading:i,error:o}=Fe(s),{data:l,isLoading:p}=qe(s),{data:c,isLoading:d}=Ve(),g=Ke(),{data:h,isLoading:x}=Qe({limit:10}),f=He(),v=Oe();return i||p?e.jsx("div",{className:"pvx-loading",children:"Loading dashboard..."}):o?e.jsx("div",{className:"pvx-empty",children:"Failed to load dashboard data."}):a?e.jsxs("div",{className:`pvx-dash ${n}`,children:[e.jsx(We,{driverName:a.driverName,avatarUrl:t,memberSince:r}),e.jsx(Ge,{stats:a,rating:l}),s&&e.jsx(Ye,{events:c,isLoading:d}),e.jsxs("div",{className:`pvx-dash-row ${g?"pvx-dash-row--2col":""}`,children:[e.jsx(ze,{records:a.currentRecords}),g&&e.jsx(Je,{notifications:h==null?void 0:h.notifications,unreadCount:(h==null?void 0:h.unreadCount)||0,onMarkRead:u=>f.mutate(u),onMarkAllRead:()=>v.mutate(),isLoading:x})]})]}):e.jsx("div",{className:"pvx-empty",children:"No data available yet. Start driving to see your stats!"})}exports.CarsTable=ms;exports.CompEmptyState=D;exports.CompLoadingState=I;exports.CompetitionCard=Be;exports.CompetitionCards=Ls;exports.CompetitionResultsTabs=_s;exports.CompletedBadge=Ie;exports.DEFAULT_COMPLETION_GRACE_DAYS=le;exports.DriverDashboard=rt;exports.DriverProfile=We;exports.DriversTable=vs;exports.EntryList=Bs;exports.InfoPill=_;exports.LapHistoryTable=hs;exports.NotificationsCard=Je;exports.PODIUM_MEDALS=G;exports.PitVoxPartnerProvider=es;exports.RankingsTable=gs;exports.RecordsTable=ze;exports.RegisterButton=As;exports.RegistrationPanel=Es;exports.RoundResults=Ms;exports.RoundSessionResults=pe;exports.StandingsTable=Ae;exports.StatsCards=Ge;exports.TracksTable=us;exports.TypeBadge=Me;exports.UpcomingEvents=Ye;exports.buildDriverIndexPath=ve;exports.buildLapsPath=me;exports.buildLeaderboardPath=q;exports.buildRecentLapsPath=he;exports.fetchCdnJson=S;exports.filterCompetitionsByStatus=ws;exports.formatCarName=M;exports.formatDate=A;exports.formatDelta=ss;exports.formatFuel=X;exports.formatLapTime=P;exports.formatNotificationMessage=ge;exports.formatRelativeTime=J;exports.formatSectorTime=$;exports.formatSessionLabel=Te;exports.formatTrackName=B;exports.formatTyreCompound=Z;exports.getCompetitionPodium=Pe;exports.getCompetitionStatus=de;exports.getCompletionDate=De;exports.isCompetitionComplete=$e;exports.useCarLeaderboard=as;exports.useCarMetadata=rs;exports.useCompetitionAllRounds=be;exports.useCompetitionConfig=se;exports.useCompetitionEntryList=re;exports.useCompetitionLeaderboard=os;exports.useCompetitionRound=Ne;exports.useCompetitionRoundLaps=ye;exports.useCompetitionStandings=te;exports.useCompetitions=is;exports.useDriverLaps=fe;exports.useDriverRating=qe;exports.useDriverRatings=Vs;exports.useDriverStats=Fe;exports.useLeaderboardIndex=ts;exports.useMarkAllNotificationsRead=Oe;exports.useMarkNotificationRead=He;exports.useNotifications=Qe;exports.useNotificationsEnabled=Ke;exports.usePitVox=C;exports.useRecentLaps=ns;exports.useRegister=ne;exports.useRegistrationMode=K;exports.useRegistrationStatus=V;exports.useRegistrationUrl=Q;exports.useTrackLeaderboard=je;exports.useUnreadCount=Ks;exports.useUpcomingEvents=Ve;exports.useUserLookup=ee;exports.useWithdraw=ae;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),N=require("react"),y=require("@tanstack/react-query"),Y=N.createContext(null),Ze="https://cdn.pitvox.com",Xe="https://pitvox.com";let z=null;function es({partnerSlug:s=null,cdnUrl:t=Ze,pitvoxUrl:r=Xe,getSteamId:n,onRegister:a,onWithdraw:i,onFetchNotifications:o,onMarkNotificationRead:l,onMarkAllNotificationsRead:p,onFetchServerPassword:c,children:d}){const g=N.useMemo(()=>({partnerSlug:s,cdnUrl:t.replace(/\/$/,""),pitvoxUrl:r.replace(/\/$/,""),getSteamId:n||(()=>null),onRegister:a||null,onWithdraw:i||null,onFetchNotifications:o||null,onMarkNotificationRead:l||null,onMarkAllNotificationsRead:p||null,onFetchServerPassword:c||null}),[s,t,r,n,a,i,o,l,p,c]);let h=!1;try{y.useQueryClient(),h=!0}catch{h=!1}return h?e.jsx(Y.Provider,{value:g,children:d}):(z||(z=new y.QueryClient({defaultOptions:{queries:{staleTime:6e4}}})),e.jsx(y.QueryClientProvider,{client:z,children:e.jsx(Y.Provider,{value:g,children:d})}))}function C(){const s=N.useContext(Y);if(!s)throw new Error("usePitVox must be used within a <PitVoxPartnerProvider>");return s}async function S(s,t){const r=await fetch(`${s}/${t}`);if(!r.ok){if(r.status===404||r.status===403)return null;throw new Error(`CDN fetch failed: ${r.status}`)}return r.json()}function q(s,t,r,...n){const a=["leaderboards"];return s&&a.push(`partners/${s}`),t&&a.push(t),r&&a.push(`v/${r}`),[...a,...n].join("/")}function me(s,t,r,n){const a=n||"default";return s?`laps/partners/${s}/${t}/${r}/${a}.json`:`laps/${t}/${r}/${a}.json`}function ve(s,t){return s?`laps/partners/${s}/${t}/index.json`:`laps/${t}/index.json`}function he(s){return s?`recent-laps/partners/${s}.json`:"recent-laps.json"}function P(s){if(!s&&s!==0)return"-";const t=Math.floor(s/1e3),r=Math.floor(t/60),n=t%60,a=s%1e3;return`${r}:${String(n).padStart(2,"0")}.${String(a).padStart(3,"0")}`}function $(s){return!s&&s!==0?"-":s>=6e4?P(s):(s/1e3).toFixed(3)}function M(s){if(!s)return"";let t=s;return t.startsWith("ks_")&&(t=t.slice(3)),t.split("_").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function B(s,t,r){if(!s)return"";const n=s.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" "),a=r==="acc"||!r&&(t==null?void 0:t.toLowerCase())==="track config";if(!t||t==="default"||a)return n;const i=t.split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ");return`${n} ${i}`}function A(s){if(!s)return"-";try{return new Date(s).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}catch{return"-"}}function J(s){if(!s)return"";const t=Date.now()-new Date(s).getTime(),r=Math.floor(t/1e3);if(r<60)return"Just now";const n=Math.floor(r/60);if(n<60)return`${n}m ago`;const a=Math.floor(n/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);return i<30?`${i}d ago`:A(s)}function ss(s){return s==null?"":`${s>=0?"+":"-"}${(Math.abs(s)/1e3).toFixed(3)}`}function ge(s,t){const{type:r,title:n,trackId:a,trackLayout:i,carId:o,game:l,data:p}=s,c=typeof p=="string"?JSON.parse(p):p,d=a?B(a,i,l):null,g=o?M(o):null,h=[d,g].filter(Boolean).join(" — ");return r==="RECORD_BEATEN"&&h?`${c!=null&&c.beatenBySteamId&&t?t(c.beatenBySteamId).displayName:"Someone"} beat your record on ${h}`:r==="RECORD_SET"&&h?`You set a new record on ${h}`:n||"New notification"}function Z(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 X(s){if(!s)return"-";const t=Number(s);return isNaN(t)?"-":t%1?`${t.toFixed(1)}L`:`${t}L`}function ts(s={}){var p,c,d,g,h,x;const{cdnUrl:t,partnerSlug:r}=C(),{game:n,gameVersion:a}=s,i=q(r,null,null,"index.json"),o=y.useQuery({queryKey:["pitvox","leaderboards",r,"index"],queryFn:()=>S(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 n&&(f=f.filter(u=>u.game===n)),a&&(f=f.filter(u=>u.gameVersion===a)),f.map(u=>({id:u.trackId,layout:u.layout,game:u.game,gameVersion:u.gameVersion,displayName:B(u.trackId,u.layout,u.game),driverCount:u.driverCount||0,carCount:u.carCount||0,record:u.recordHolder?{visibleId:u.recordHolder.steamId||u.recordHolder.userId,carId:u.recordHolder.carId,carDisplayName:M(u.recordHolder.carId),lapTimeMs:u.recordHolder.lapTimeMs,timestamp:u.recordHolder.recordedAt}:null,recordByTag:u.recordByTag||null}))},[(p=o.data)==null?void 0:p.tracks,n,a]);return{...o,data:l,partner:((c=o.data)==null?void 0:c.partner)||null,generatedAt:(d=o.data)==null?void 0:d.generatedAt,totalLaps:((g=o.data)==null?void 0:g.totalLaps)||0,totalUsers:((h=o.data)==null?void 0:h.totalUsers)||0,versions:((x=o.data)==null?void 0:x.versions)||{}}}function je(s,t,r={}){const{cdnUrl:n,partnerSlug:a}=C(),{carId:i,game:o,gameVersion:l}=r,p=t||"default",c=q(a,o,l,`tracks/${s}/${p}.json`),{data:d,isLoading:g,error:h}=y.useQuery({queryKey:["pitvox","leaderboards",a,"track",s,p,o,l],queryFn:()=>S(n,c),enabled:!!s,staleTime:3e4,refetchInterval:3e4});return{data:N.useMemo(()=>{if(!(d!=null&&d.entries))return[];let f=d.entries;if(o&&(f=f.filter(v=>v.game===o)),!i){const v=new Map,u=new Map;for(const j of f){const m=j.steamId||j.userId;u.has(j.carId)||u.set(j.carId,new Set),u.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=u.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,u)=>v.lapTimeMs-u.lapTimeMs)},[d==null?void 0:d.entries,i,o]),isLoading:g,error:h}}function fe(s,t,r,n,a={}){var v,u;const{cdnUrl:i,partnerSlug:o}=C(),{showInvalid:l=!1,game:p,gameVersion:c}=a,d=s&&t?me(o,s,t,r):null,g=r||"default",h=y.useQuery({queryKey:["pitvox","laps",o,s,t,g],queryFn:()=>S(i,d),enabled:!!s&&!!t,staleTime:3e4,refetchInterval:3e4}),x=N.useMemo(()=>{var j;return(j=h.data)!=null&&j.laps?h.data.laps.filter(m=>!(m.carId!==n||p&&m.game!==p||c&&m.gameVersion!==c||!l&&!m.isValid)).sort((m,b)=>m.lapTimeMs-b.lapTimeMs):[]},[(v=h.data)==null?void 0:v.laps,n,p,c,l]),f=N.useMemo(()=>{const j=x.filter(T=>T.isValid&&T.sector1Ms&&T.sector2Ms&&T.sector3Ms);if(j.length<2)return null;const m=Math.min(...j.map(T=>T.sector1Ms)),b=Math.min(...j.map(T=>T.sector2Ms)),w=Math.min(...j.map(T=>T.sector3Ms)),k=m+b+w,L=Math.min(...j.map(T=>T.lapTimeMs));return k>=L?null:{lapTimeMs:k,sector1Ms:m,sector2Ms:b,sector3Ms:w}},[x]);return{...h,data:x,driverName:((u=h.data)==null?void 0:u.driverName)||"Driver",theoreticalBest:f}}function ee(){const{cdnUrl:s}=C(),{data:t}=y.useQuery({queryKey:["pitvox","users","index"],queryFn:()=>S(s,"users/index.json"),staleTime:5*6e4,gcTime:30*6e4}),r=(t==null?void 0:t.users)||{};return(n,a)=>{const i=r[n];return{displayName:(i==null?void 0:i.displayName)||a||n||"Unknown",avatarUrl:(i==null?void 0:i.avatarUrl)||null,affiliations:(i==null?void 0:i.affiliations)||[]}}}function rs(){const{cdnUrl:s}=C(),{data:t}=y.useQuery({queryKey:["pitvox","cars","evo"],queryFn:()=>S(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 ns(){var a,i;const{cdnUrl:s,partnerSlug:t}=C(),r=he(t),n=y.useQuery({queryKey:["pitvox","recentLaps",t],queryFn:()=>S(s,r),staleTime:3e4,refetchInterval:3e4,gcTime:10*6e4});return{groups:((a=n.data)==null?void 0:a.groups)||[],generatedAt:((i=n.data)==null?void 0:i.generatedAt)||null,isLoading:n.isLoading}}function as(s,t){return je(s,null,{carId:t})}function is(){const{cdnUrl:s,partnerSlug:t}=C();return y.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const r=await S(s,"competitions/index.json");return r!=null&&r.competitions?t?r.competitions.filter(n=>n.partnerSlug===t):r.competitions:[]},staleTime:6e4})}function se(s,t={}){const r=C(),n=t.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",n,s,"config"],queryFn:()=>S(r.cdnUrl,`competitions/${n}/${s}/config.json`),enabled:!!n&&!!s,staleTime:6e4})}function te(s,t={}){const r=C(),n=t.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",n,s,"standings"],queryFn:()=>S(r.cdnUrl,`competitions/${n}/${s}/standings.json`),enabled:!!n&&!!s,staleTime:6e4})}function Ne(s,t,r={}){const n=C(),a=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"round",t],queryFn:()=>S(n.cdnUrl,`competitions/${a}/${s}/rounds/${t}.json`),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function be(s,t=[],r={}){const n=C(),a=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"allRounds",t],queryFn:async()=>(await Promise.all(t.map(o=>S(n.cdnUrl,`competitions/${a}/${s}/rounds/${o}.json`).catch(()=>null)))).filter(Boolean),enabled:!!a&&!!s&&t.length>0,staleTime:6e4})}function os(s,t={}){const r=C(),n=t.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",n,s,"leaderboard"],queryFn:()=>S(r.cdnUrl,`competitions/${n}/${s}/leaderboard.json`).catch(()=>null),enabled:!!n&&!!s,staleTime:6e4})}function ye(s,t,r={}){const n=C(),a=r.partnerSlug||n.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",a,s,"round",t,"laps"],queryFn:()=>S(n.cdnUrl,`competitions/${a}/${s}/rounds/${t}/laps.json`).catch(()=>null),enabled:!!a&&!!s&&t!=null,staleTime:6e4})}function re(s,t={}){const r=C(),n=t.partnerSlug||r.partnerSlug;return y.useQuery({queryKey:["pitvox","competition",n,s,"entrylist"],queryFn:()=>S(r.cdnUrl,`competitions/${n}/${s}/entrylist.json`),enabled:!!n&&!!s,staleTime:6e4})}function V(s){const{cdnUrl:t,partnerSlug:r,getSteamId:n}=C(),a=n();return y.useQuery({queryKey:["pitvox","registration",r,s,a],queryFn:async()=>{var p;const i=await fetch(`${t}/competitions/${r}/${s}/entrylist.json`);if(!i.ok)return{isRegistered:!1,entryList:null};const o=await i.json();return{isRegistered:!!a&&((p=o.drivers)==null?void 0:p.some(c=>c.steamId===a)),entryList:o}},enabled:!!s,staleTime:6e4})}function ne(s){const{onRegister:t,partnerSlug:r,getSteamId:n}=C(),a=y.useQueryClient(),i=ee();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=n();if(a.setQueriesData({queryKey:["pitvox","registration",r,s]},l=>l?{...l,isRegistered:!0}:{isRegistered:!0,entryList:null}),o){const l=i(o),p={steamId:o,displayName:l.displayName,avatarUrl:l.avatarUrl};a.setQueriesData({queryKey:["pitvox","competition",r,s,"entrylist"]},c=>{var g;return c?((g=c.drivers)==null?void 0:g.some(h=>h.steamId===o))?c:{...c,drivers:[...c.drivers||[],p]}:{drivers:[p]}})}}})}function ae(s){const{onWithdraw:t,partnerSlug:r,getSteamId:n}=C(),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||n();if(!o)throw new Error("No Steam ID available");return t(s,o)},onSuccess:()=>{const i=n();a.setQueriesData({queryKey:["pitvox","registration",r,s]},o=>o?{...o,isRegistered:!1}:{isRegistered:!1,entryList:null}),i&&a.setQueriesData({queryKey:["pitvox","competition",r,s,"entrylist"]},o=>o!=null&&o.drivers?{...o,drivers:o.drivers.filter(l=>l.steamId!==i)}:o)}})}function K(){const{onRegister:s,onWithdraw:t}=C(),r=!!(s&&t);return{isPowerMode:r,isBasicMode:!r}}function H(s){const{pitvoxUrl:t,partnerSlug:r}=C();return`${t}/p/${r}/competitions/${s}/register`}const cs={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"},Ce=[{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 ls(s){for(const t of Ce)if(t.tags.includes(s))return t.id;return"other"}function ke(s,t){if(t.size===0)return!0;const r={};for(const n of t){const a=ls(n);r[a]||(r[a]=[]),r[a].push(n)}for(const n of Object.values(r))if(!n.some(a=>s.includes(a)))return!1;return!0}function we(s,t){const[r,n]=N.useState(new Set),a=s!==void 0,i=a?s:r,o=N.useCallback(p=>{const c=new Set(i);c.has(p)?c.delete(p):c.add(p),a&&t?t(c):n(c)},[i,a,t]),l=N.useCallback(()=>{a&&t?t(new Set):n(new Set)},[a,t]);return{activeTags:i,toggle:o,clear:l}}function Q(s){const[t,r]=N.useState(s),n=N.useCallback(a=>{r(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,n]}function O(s,t,r){return[...s].sort((n,a)=>{const i=r(n,t.key),o=r(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 Le(s,t=!1){const r=t?s==null?void 0:s.filter(n=>n.isValid):s;return r!=null&&r.length?{s1:Math.min(...r.map(n=>n.sector1Ms).filter(Boolean)),s2:Math.min(...r.map(n=>n.sector2Ms).filter(Boolean)),s3:Math.min(...r.map(n=>n.sector3Ms).filter(Boolean))}:null}function ds({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:r,onSort:n,className:a=""}){return e.jsx("th",{className:`pvx-th pvx-th--sortable ${a}`,onClick:()=>n(t),children:e.jsxs("span",{className:"pvx-th-inner",children:[s,e.jsx(ds,{active:r.key===t,dir:r.dir})]})})}function W({userId:s,getUserDisplay:t}){const{displayName:r,avatarUrl:n}=t(s);return e.jsxs("span",{className:"pvx-driver",children:[n?e.jsx("img",{src:n,alt:"",className:"pvx-driver-avatar"}):e.jsx("span",{className:"pvx-driver-avatar pvx-driver-avatar--placeholder"}),e.jsx("span",{className:"pvx-driver-name",children:r})]})}function ie({rank:s,podium:t=!1}){const r=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:r,children:s})}function Se({availableTags:s,activeTags:t,onToggle:r,onClear:n}){if(!s||s.length<2)return null;const a=Ce.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:n,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:()=>r(l),className:`pvx-tag ${t.has(l)?"pvx-tag--active":""}`,children:cs[l]||l},l))]},i.id))]})}function oe({segments:s}){return e.jsx("nav",{className:"pvx-breadcrumb","aria-label":"Breadcrumb",children:e.jsx("ol",{className:"pvx-breadcrumb-list",children:s.map((t,r)=>{const n=r===s.length-1;return e.jsxs("li",{className:"pvx-breadcrumb-item",children:[r>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"})}),!n&&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 F(){return e.jsx("div",{className:"pvx-loading",children:"Loading..."})}function ps(){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 xs(){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 us({tracks:s,isLoading:t,carMetadata:r,getUserDisplay:n,onTrackSelect:a,tags:i,onTagChange:o}){const[l,p]=Q({key:"record.timestamp",dir:"desc"}),{activeTags:c,toggle:d,clear:g}=we(i,o),h=N.useMemo(()=>{var u;if(!((u=r==null?void 0:r.tags)!=null&&u.length))return[];const v=new Set;for(const j of s||[])j.recordByTag&&Object.keys(j.recordByTag).forEach(m=>v.add(m));return r.tags.filter(j=>v.has(j))},[s,r]),x=N.useMemo(()=>s?c.size===0?s:s.map(v=>{var m,b;if(!v.recordByTag)return null;let u=null;const j=new Set;for(const w of Object.values(v.recordByTag)){if(j.has(w.carId))continue;j.add(w.carId);const k=((b=(m=r==null?void 0:r.cars)==null?void 0:m[w.carId])==null?void 0:b.tags)||["sports_car"];ke(k,c)&&(!u||w.lapTimeMs<u.lapTimeMs)&&(u=w)}return u?{...v,record:{visibleId:u.steamId||u.identifier,carId:u.carId,carDisplayName:M(u.carId),lapTimeMs:u.lapTimeMs,timestamp:u.recordedAt}}:null}).filter(Boolean):[],[s,c,r]),f=N.useMemo(()=>O(x,l,(v,u)=>{var j,m;switch(u){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}}),[x,l]);return t?e.jsx(F,{}):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(Se,{availableTags:h,activeTags:c,onToggle:d,onClear:g}),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:p}),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:p}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:l,onSort:p,className:"pvx-hidden-below-md"}),e.jsx(R,{label:"Cars",sortKey:"carCount",config:l,onSort:p,className:"pvx-hidden-below-lg"}),e.jsx(R,{label:"Date",sortKey:"record.timestamp",config:l,onSort:p,className:"pvx-hidden-below-xl"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:f.map(v=>{var u,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:(u=v.record)!=null&&u.visibleId?e.jsx(W,{userId:v.record.visibleId,getUserDisplay:n}):"-"}),e.jsx("td",{className:"pvx-td pvx-hidden-below-lg",children:((j=v.record)==null?void 0:j.carDisplayName)||"-"}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:v.record?P(v.record.lapTimeMs):"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-md",children:v.driverCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:v.carCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:(m=v.record)!=null&&m.timestamp?A(v.record.timestamp):"-"})]},`${v.id}|${v.layout||""}`)})})]})})]}):e.jsx(U,{message:"No lap times recorded yet."})}function ms({entries:s,isLoading:t,track:r,carMetadata:n,getUserDisplay:a,onCarSelect:i,onNavigate:o,tags:l,onTagChange:p}){const[c,d]=Q({key:"lapTimeMs",dir:"asc"}),{activeTags:g,toggle:h,clear:x}=we(l,p),f=N.useMemo(()=>{var b,w,k;if(!s||!((b=n==null?void 0:n.tags)!=null&&b.length))return[];const m=new Set;for(const L of s)(((k=(w=n.cars)==null?void 0:w[L.carId])==null?void 0:k.tags)||["sports_car"]).forEach(E=>m.add(E));return n.tags.filter(L=>m.has(L))},[s,n]),v=N.useMemo(()=>s?g.size===0?s:s.filter(m=>{var w,k;const b=((k=(w=n==null?void 0:n.cars)==null?void 0:w[m.carId])==null?void 0:k.tags)||["sports_car"];return ke(b,g)}):[],[s,g,n]),u=N.useMemo(()=>O(v,c,(m,b)=>{switch(b){case"carId":return M(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:r.displayName}];return t?e.jsx(F,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(oe,{segments:j})}),e.jsx(Se,{availableTags:f,activeTags:g,onToggle:h,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:d}),e.jsx("th",{className:"pvx-th",children:"Record Holder"}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:c,onSort:d}),e.jsx(R,{label:"Drivers",sortKey:"driverCount",config:c,onSort:d,className:"pvx-hidden-below-md"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:u.map((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(ie,{rank:b+1,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:M(m.carId)}),e.jsx("td",{className:"pvx-td",children:e.jsx(W,{userId:m.steamId||m.userId,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:P(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?A(m.recordedAt):"-"})]},m.carId))})]})}):e.jsx(U,{message:"No lap times for this track yet."})]})}function vs({entries:s,isLoading:t,track:r,carId:n,getUserDisplay:a,onDriverSelect:i,onNavigate:o,highlightId:l}){const[p,c]=Q({key:"lapTimeMs",dir:"asc"}),d=N.useMemo(()=>Le(s),[s]),g=N.useMemo(()=>O(s||[],p,(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,p,a]),h=[{key:"tracks",label:"Tracks",onClick:()=>o("tracks")},{key:"track",label:r.displayName,onClick:()=>o("track")},{key:"car",label:M(n)}];return t?e.jsx(F,{}):e.jsxs("div",{className:"pvx-card",children:[e.jsx("div",{className:"pvx-card-header",children:e.jsx(oe,{segments:h})}),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:p,onSort:c}),e.jsx(R,{label:"Lap Time",sortKey:"lapTimeMs",config:p,onSort:c}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-lg",children:"Tyre"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Fuel"}),e.jsx(R,{label:"Laps",sortKey:"lapCount",config:p,onSort:c,className:"pvx-hidden-below-lg"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-xl",children:"Date"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:g.map((x,f)=>{const v=f+1,u=x.steamId||x.userId,j=d&&x.sector1Ms===d.s1,m=d&&x.sector2Ms===d.s2,b=d&&x.sector3Ms===d.s3,w=l&&u===l;return e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${w?"pvx-row--highlight":v<=3?"pvx-row--podium":""}`,onClick:()=>i(u),children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ie,{rank:v,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(W,{userId:u,getUserDisplay:a})}),e.jsx("td",{className:"pvx-td pvx-td--primary pvx-td--mono",children:P(x.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${j?"pvx-td--best-sector":""}`,children:$(x.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${m?"pvx-td--best-sector":""}`,children:$(x.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${b?"pvx-td--best-sector":""}`,children:$(x.sector3Ms)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:Z(x.tyreCompound),children:x.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-xl",children:X(x.startingFuelL)}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:x.lapCount||"-"}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:x.recordedAt?A(x.recordedAt):"-"})]},u)})})]})}):e.jsx(U,{message:"No lap times for this car yet."})]})}function hs({userId:s,track:t,carId:r,game:n,gameVersion:a,showInvalid:i,getUserDisplay:o,onToggleInvalid:l,onNavigate:p}){const{data:c,driverName:d,theoreticalBest:g,isLoading:h}=fe(s,t.id,t.layout,r,{showInvalid:i,game:n,gameVersion:a}),{displayName:x,avatarUrl:f}=o(s,d),v=N.useMemo(()=>Le(c,!0),[c]),u=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:()=>p("tracks")},{key:"track",label:t.displayName,onClick:()=>p("track")},{key:"car",label:M(r),onClick:()=>p("car")},{key:"driver",label:x}];return h?e.jsx(F,{}):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(oe,{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"})]})]}),g&&e.jsxs("div",{className:"pvx-theoretical-best",children:[e.jsx("span",{className:"pvx-theoretical-best-label",children:"Theoretical Best:"}),e.jsx("span",{className:"pvx-theoretical-best-time",children:P(g.lapTimeMs)}),e.jsxs("span",{className:"pvx-theoretical-best-sectors",children:["(",$(g.sector1Ms)," + ",$(g.sector2Ms)," + ",$(g.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===u,k=v&&m.isValid&&m.sector1Ms===v.s1,L=v&&m.isValid&&m.sector2Ms===v.s2,T=v&&m.isValid&&m.sector3Ms===v.s3;let E="pvx-row";return m.isValid||(E+=" pvx-row--invalid"),w&&(E+=" pvx-row--personal-best"),e.jsxs("tr",{className:E,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:P(m.lapTimeMs)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${k?"pvx-td--best-sector":""}`,children:$(m.sector1Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${L?"pvx-td--best-sector":""}`,children:$(m.sector2Ms)}),e.jsx("td",{className:`pvx-td pvx-td--mono pvx-td--sector pvx-hidden-below-sm ${T?"pvx-td--best-sector":""}`,children:$(m.sector3Ms)}),e.jsx("td",{className:"pvx-td",title:m.isValid?void 0:m.invalidReason||"Invalid",children:m.isValid?e.jsx(ps,{}):e.jsx(xs,{})}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",title:Z(m.tyreCompound),children:m.tyreCompound||"-"}),e.jsx("td",{className:"pvx-td pvx-td--center pvx-hidden-below-lg",children:X(m.startingFuelL)}),e.jsx("td",{className:"pvx-td pvx-td--muted pvx-hidden-below-xl",children:A(m.timestamp)})]},m.id)})})]})}):e.jsx(U,{message:i?"No laps recorded for this combination.":'No valid laps. Try enabling "Show invalid laps".'})]})}function gs({drivers:s,isLoading:t,getUserDisplay:r,game:n,gameVersion:a,onComboSelect:i}){const[o,l]=Q({key:"rank",dir:"asc"}),[p,c]=N.useState(null),d=N.useMemo(()=>s?O(s,o,(h,x)=>{switch(x){case"rating":return h.rating;case"comboCount":return h.comboCount||0;case"distinctCars":return h.distinctCars||0;case"rank":default:return h.rank}}):[],[s,o]);if(t)return e.jsx(F,{});if(!(s!=null&&s.length))return e.jsx("div",{className:"pvx-card",children:e.jsx(U,{message:"Not enough data for rankings yet."})});const g=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:d.map(h=>{const x=p===h.identifier;return e.jsx(js,{driver:h,getUserDisplay:r,isExpanded:x,onToggle:()=>c(x?null:h.identifier),colCount:g,game:n,gameVersion:a,onComboSelect:i},h.identifier)})})]})})]})}function js({driver:s,getUserDisplay:t,isExpanded:r,onToggle:n,colCount:a,game:i,gameVersion:o,onComboSelect:l}){const p=s.identifier;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row pvx-row--clickable ${s.rank<=3?"pvx-row--podium":""}`,onClick:n,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(ie,{rank:s.rank,podium:!0})}),e.jsx("td",{className:"pvx-td pvx-td--primary",children:e.jsx(W,{userId:p,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 ${r?"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"})})]})})]}),r&&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,d)=>{const g=c.layout?`${c.trackId}|${c.layout}`:c.trackId,h=l?()=>l({track:g,car:c.carId,highlight:p,game:i,gameVersion:o}):void 0;return e.jsxs("div",{className:`pvx-rankings-combo ${h?"pvx-rankings-combo--clickable":""}`,onClick:h,role:h?"button":void 0,children:[e.jsxs("div",{className:"pvx-rankings-combo-info",children:[e.jsx("p",{className:"pvx-rankings-combo-track",children:B(c.trackId,c.layout,i)}),e.jsx("p",{className:"pvx-rankings-combo-car",children:M(c.carId)})]}),e.jsxs("div",{className:"pvx-rankings-combo-stats",children:[e.jsx("p",{className:"pvx-rankings-combo-time",children:P(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,")"]})]})]})]},d)})})})})]})}const fs={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:"🇰🇷"},G=["🥇","🥈","🥉"],Ns={championship:"Championship",series:"Series",event:"Event",hotlap:"Hotlap"},bs=["PRACTICE","QUALIFYING","RACE"];function xe(s){const t=bs.indexOf(s);if(t>=0)return t;const r=s.match(/^PRACTICE_(\d+)$/);return r?100+parseInt(r[1]):999}function Te(s){const t=s.match(/^PRACTICE_(\d+)$/);return t?`P${t[1]}`:s}function Re({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 ce({nation:s}){const t=s&&fs[s];return t?e.jsx("span",{className:"pvx-nation-flag",title:s,children:t}):null}function ys({sessions:s,activeSession:t,onSelect:r}){if(!s||s.length<=1)return null;const n=[...s].sort((a,i)=>xe(a.type)-xe(i.type));return e.jsx("div",{className:"pvx-session-tabs",children:n.map(a=>e.jsx("button",{onClick:()=>r(a.type),className:`pvx-session-tab ${t===a.type?"pvx-session-tab--active":""}`,children:Te(a.type)},a.type))})}function Me({type:s}){return e.jsx("span",{className:`pvx-comp-badge pvx-comp-badge--${s}`,children:Ns[s]||s})}function _({children:s,variant:t="default"}){return e.jsx("span",{className:`pvx-info-pill ${t!=="default"?`pvx-info-pill--${t}`:""}`,children:s})}function Cs(s){if(!s)return"TBD";const t=new Date(s);if(isNaN(t))return"TBD";const r=t.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),n=t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return`${r} • ${n}`}function ks(s){return s.reduce((t,r)=>{var n;return(n=r.splits)!=null&&n.length?t?t.map((a,i)=>{const o=r.splits[i];return o&&o<a?o:a}):[...r.splits]:t},null)}function I({message:s="Loading..."}){return e.jsx("div",{className:"pvx-loading",children:s})}function D({message:s="No data available."}){return e.jsx("div",{className:"pvx-empty",children:e.jsx("p",{children:s})})}const le=3;function $e(s){const t=s==null?void 0:s.rounds;return t!=null&&t.length?t.every(r=>r.isFinalized):!1}function De(s){const t=s==null?void 0:s.rounds;if(!(t!=null&&t.length))return null;let r=null;for(const n of t){if(!n.startTime)continue;const a=new Date(n.startTime);isNaN(a)||(!r||a>r)&&(r=a)}return r}function de(s,t=le){if(!$e(s))return"active";const r=De(s);if(!r)return"recently-completed";const n=t*24*60*60*1e3;return Date.now()-r.getTime()<=n?"recently-completed":"archived"}function ws(s,t,r=le){if(!(s!=null&&s.length))return[];const n=new Set(Array.isArray(t)?t:[t]);return s.filter(a=>n.has(de(a,r)))}function Pe(s,t=3){const r=s==null?void 0:s.standings;return Array.isArray(r)?[...r].sort((n,a)=>(n.position??999)-(a.position??999)).slice(0,t):[]}function Ie({competitionId:s,topN:t=3,label:r="Completed",className:n}){const{data:a}=te(s),i=Pe(a,t);return e.jsxs("div",{className:`pvx-comp-completed-badge ${n||""}`,children:[e.jsx("span",{className:"pvx-comp-completed-badge-label",children:r}),i.length>0&&e.jsx("ol",{className:"pvx-comp-completed-badge-podium",children:i.map((o,l)=>e.jsxs("li",{className:"pvx-comp-completed-badge-driver",children:[e.jsx("span",{className:"pvx-comp-completed-badge-medal","aria-hidden":"true",children:G[l]||""}),e.jsx(ce,{nation:o.nation}),e.jsx("span",{className:"pvx-comp-completed-badge-name",children:o.driverName})]},o.driverId||l))})]})}function Ls({competitions:s,isLoading:t,onSelect:r,onRegister:n,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(Be,{comp:i,onSelect:r,onRegister:n||r},i.id))}):e.jsx(D,{message:"No competitions available."})}function Be({comp:s,onSelect:t,onRegister:r}){var m,b,w;const{cdnUrl:n}=C(),a=s.posterCdnPath?`${n}/${s.posterCdnPath}`:null,i=s.registration,o=(i==null?void 0:i.currentCount)||0,l=i==null?void 0:i.maxParticipants,p=l&&o>=l,c=(i==null?void 0:i.deadline)&&new Date(i.deadline)<new Date,d=(i==null?void 0:i.isOpen)&&!c&&!p,g=new Date,h=(m=s.rounds)==null?void 0:m.find(k=>k.startTime&&new Date(k.startTime)>=g),x=((b=s.rounds)==null?void 0:b.length)||0,f=((w=s.rounds)==null?void 0:w.filter(k=>k.isFinalized).length)||0,v=de(s),u=v==="recently-completed"||v==="archived",j=s.type==="championship";return e.jsxs("div",{className:"pvx-comp-card",onClick:()=>t(s.id),role:"button",tabIndex:0,onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&(k.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(Ts,{})})}),e.jsxs("div",{className:"pvx-comp-card-body",children:[e.jsx("h3",{className:"pvx-comp-card-title",children:s.name}),s.description&&e.jsx("p",{className:"pvx-comp-card-desc",children:s.description}),e.jsxs("div",{className:"pvx-comp-card-pills",children:[e.jsx(Me,{type:s.type}),s.game&&e.jsx(_,{children:s.game.toUpperCase()}),s.formatDescription&&s.formatDescription.split(", ").map((k,L)=>e.jsx(_,{variant:"format",children:k},L))]}),s.carsDescription&&e.jsx("div",{className:"pvx-comp-card-pills",children:s.carsDescription.split(", ").map((k,L)=>e.jsx(_,{children:k},L))}),e.jsxs("div",{className:"pvx-comp-card-schedule",children:[h?e.jsxs("span",{className:"pvx-comp-card-schedule-next",children:[e.jsx("span",{className:"pvx-comp-card-schedule-label",children:"Next:"})," ","R",h.roundNumber," ",h.track||"TBD"," — ",Cs(h.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":""]})]}),u&&j&&e.jsx(Ie,{competitionId:s.id}),i&&!u&&e.jsx(Ss,{competitionId:s.id,regOpen:d,isFull:p,deadlinePassed:c,regCount:o,regMax:l,onRegister:r})]})]})}function Ss({competitionId:s,regOpen:t,isFull:r,deadlinePassed:n,regCount:a,regMax:i,onRegister:o}){const{isPowerMode:l}=K(),p=H(s),{data:c}=V(s),d=(c==null?void 0:c.isRegistered)||!1,g=i?a/i*100:0,h=g>=100?"full":g>=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--${h}`,children:[a,"/",i||"∞"," drivers"]})}),e.jsx("div",{className:"pvx-comp-card-reg-action",children:d?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:p,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:r?"Full":"Closed"})})]})}function Ts(){return e.jsxs("svg",{className:"pvx-comp-trophy-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 0 1 0-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 0 0 0-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0 0 12 0V2Z"})]})}function Ae({competitionId:s,className:t}){var l,p;const{data:r,isLoading:n}=te(s),{data:a,isLoading:i}=se(s);if(n||i)return e.jsx(I,{message:"Loading standings..."});if(!((l=r==null?void 0:r.standings)!=null&&l.length))return e.jsx(D,{message:"No standings data yet. Results will appear once rounds are finalised."});const o=((p=a==null?void 0:a.rounds)==null?void 0:p.filter(c=>c.isFinalized))||[];return e.jsxs("div",{className:`pvx-card ${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 ",r.roundsCompleted," round",r.roundsCompleted!==1?"s":"",r.countingRounds>0&&` (best ${r.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:r.standings.map(c=>e.jsx(Rs,{driver:c,finalizedRounds:o},c.driverId||c.driverName))})]})})]})}function Rs({driver:s,finalizedRounds:t}){var o,l,p;const r=s.position<=3,n=new Map(((o=s.roundResults)==null?void 0:o.map(c=>[c.roundNumber,c]))||[]),a=((l=s.roundResults)==null?void 0:l.filter(c=>c.position===1).length)||0,i=((p=s.roundResults)==null?void 0:p.filter(c=>c.position<=3).length)||0;return e.jsxs("tr",{className:`pvx-row ${r?"pvx-row--podium":""}`,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(Re,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ce,{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 d=n.get(c.roundNumber),g=d==null?void 0:d.dropped;return e.jsx("td",{className:`pvx-td pvx-td--center pvx-hidden-below-md ${!g&&(d==null?void 0:d.position)===1?"pvx-standings-cell--p1":!g&&(d==null?void 0:d.position)===2?"pvx-standings-cell--p2":!g&&(d==null?void 0:d.position)===3?"pvx-standings-cell--p3":""}`,children:d?e.jsxs("div",{className:`pvx-standings-round-cell ${g?"pvx-standings-round-cell--dropped":""}`,children:[e.jsxs("span",{className:"pvx-standings-round-pos",children:["P",d.position]}),e.jsx("span",{className:"pvx-standings-round-pts",children:d.points})]}):e.jsx("span",{className:"pvx-td--muted",children:"-"})},c.roundNumber)})]})}function Ms({competitionId:s,roundNumber:t,className:r}){var p;const{data:n,isLoading:a}=Ne(s,t);if(a)return e.jsx(I,{message:"Loading results..."});if(!n)return e.jsx(D,{message:"No results for this round."});const o=(n.sessions||[]).find(c=>c.type==="RACE"),l=(p=o==null?void 0:o.results)==null?void 0:p.filter(c=>c.position<=3).sort((c,d)=>c.position-d.position);return e.jsxs("div",{className:`pvx-round-results ${r||""}`,children:[e.jsxs("div",{className:"pvx-round-results-header",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"pvx-round-results-title",children:["Round ",n.roundNumber,n.track?`: ${n.track}`:""]}),n.startTime&&e.jsx("p",{className:"pvx-round-results-date",children:new Date(n.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:G[c.position-1]}),e.jsx("span",{children:c.driverName})]},c.driverId))})]}),e.jsx(pe,{round:n,competitionId:s})]})}function pe({round:s,competitionId:t,className:r}){var d,g,h,x;const[n,a]=N.useState(null),i=(s==null?void 0:s.sessions)||[];if(!i.length)return e.jsx(D,{message:"No session data for this round."});const{data:o}=ye(t,s==null?void 0:s.roundNumber,{}),l=n||((d=i.find(f=>f.type==="RACE"))==null?void 0:d.type)||((g=i[0])==null?void 0:g.type),p=i.find(f=>f.type===l)||i[0],c=((x=(h=o==null?void 0:o.sessions)==null?void 0:h.find(f=>f.type===l))==null?void 0:x.drivers)||null;return e.jsxs("div",{className:r||"",children:[e.jsx(ys,{sessions:i,activeSession:l,onSelect:a}),e.jsx($s,{session:p,sessionLaps:c})]})}function $s({session:s,sessionLaps:t}){var l;const r=s.type==="RACE",[n,a]=N.useState(null);if(!((l=s.results)!=null&&l.length))return e.jsx(D,{message:`No results for ${s.type}.`});const i=ks(s.results),o=r?7:4;return e.jsx("div",{className:"pvx-table-scroll",children:e.jsxs("table",{className:"pvx-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Pos"}),e.jsx("th",{className:"pvx-th",children:"Driver"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Car"}),e.jsx("th",{className:"pvx-th",children:"Best Lap"}),r&&e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Laps"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"Time / Gap"}),e.jsx("th",{className:"pvx-th pvx-th--center",children:"Points"})]})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.results.map((p,c)=>{var h;const d=(h=t==null?void 0:t[p.driverId])==null?void 0:h.laps,g=n===p.driverId&&!!d;return e.jsx(Ds,{result:p,isRace:r,fastestSplits:i,rowIndex:c,hasLapDetail:!!d,isExpanded:g,onToggle:()=>a(g?null:p.driverId),driverLaps:g?d:null,colCount:o},p.driverId||c)})})]})})}function Ds({result:s,isRace:t,fastestSplits:r,rowIndex:n,hasLapDetail:a,isExpanded:i,onToggle:o,driverLaps:l,colCount:p}){const c=s.position<=3;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`pvx-row ${c?"pvx-row--podium":""} ${a?"pvx-row--expandable":""}`,onClick:a?o:void 0,style:a?{cursor:"pointer"}:void 0,children:[e.jsx("td",{className:"pvx-td",children:e.jsx(Re,{position:s.position})}),e.jsxs("td",{className:"pvx-td pvx-td--primary",children:[e.jsx(ce,{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:M(s.carId)}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:e.jsx(Is,{bestLap:s.bestLapFormatted,hasBestLap:s.hasBestLap,splits:s.splits,fastestSplits:r,showAbove:n<=1})}),t&&e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"pvx-td pvx-hidden-below-sm",children:s.lapsCompleted}),e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:s.position===1?s.totalTime||"-":s.gap||"-"}),e.jsxs("td",{className:"pvx-td pvx-td--center",children:[e.jsx("span",{className:"pvx-session-points",children:s.points}),s.pointsOverride!==0&&s.pointsOverride&&e.jsxs("span",{className:"pvx-points-override",children:["(",s.pointsOverride>0?"+":"",s.pointsOverride,")"]})]})]})]}),i&&l&&e.jsx("tr",{className:"pvx-row pvx-row--lap-detail",children:e.jsx("td",{colSpan:p,className:"pvx-td pvx-td--lap-detail",children:e.jsx(Ps,{laps:l})})})]})}function Ps({laps:s}){const t=Math.min(...s.filter(r=>r.valid&&r.timeMs>0).map(r=>r.timeMs));return e.jsxs("table",{className:"pvx-table pvx-table--laps",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"pvx-thead-row",children:[e.jsx("th",{className:"pvx-th pvx-th--narrow",children:"Lap"}),e.jsx("th",{className:"pvx-th",children:"Time"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S1"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S2"}),e.jsx("th",{className:"pvx-th pvx-hidden-below-sm",children:"S3"})]})}),e.jsx("tbody",{className:"pvx-tbody",children:s.map(r=>{var a;const n=r.valid&&r.timeMs===t;return e.jsxs("tr",{className:`pvx-row ${r.valid?"":"pvx-row--invalid"} ${n?"pvx-row--fastest":""}`,children:[e.jsx("td",{className:"pvx-td pvx-td--muted",children:r.lap}),e.jsx("td",{className:"pvx-td pvx-td--mono",children:r.time}),(r.splits||[]).map((i,o)=>e.jsx("td",{className:"pvx-td pvx-td--mono pvx-td--muted pvx-hidden-below-sm",children:i},o)),Array.from({length:Math.max(0,3-(((a=r.splits)==null?void 0:a.length)||0))}).map((i,o)=>e.jsx("td",{className:"pvx-td pvx-hidden-below-sm"},`pad-${o}`))]},r.lap)})})]})}function Is({bestLap:s,hasBestLap:t,splits:r,fastestSplits:n,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}),(r==null?void 0:r.length)>0&&e.jsx("span",{className:"pvx-splits-tooltip-anchor",children:e.jsx("span",{className:`pvx-splits-tooltip ${a?"":"pvx-splits-tooltip--above"}`,children:r.map((i,o)=>{const l=n&&i===n[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:r}=C(),{data:n,isLoading:a}=re(s),i=r();if(a)return e.jsx(I,{message:"Loading drivers..."});const o=(n==null?void 0:n.drivers)||(n==null?void 0:n.entries)||[];return o.length?e.jsx("div",{className:`pvx-entry-grid ${t||""}`,children:o.map(l=>{var c,d;const p=i&&l.steamId===i;return e.jsxs("div",{className:`pvx-entry-card ${p?"pvx-entry-card--you":""}`,children:[l.avatarUrl?e.jsx("img",{src:l.avatarUrl,alt:"",className:"pvx-entry-avatar"}):e.jsx("div",{className:"pvx-entry-avatar pvx-entry-avatar--placeholder",children:((d=(c=l.displayName)==null?void 0:c.charAt(0))==null?void 0:d.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-entry-name",children:[l.displayName,p&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},l.steamId||l.driverId)})}):e.jsx(D,{message:"No drivers registered yet."})}function As({competitionId:s,driverData:t,className:r,children:n}){const{data:a,isLoading:i}=V(s),{isPowerMode:o}=K(),l=H(s),p=ne(s),c=ae(s),d=(a==null?void 0:a.isRegistered)||!1,g=i||p.isPending||c.isPending,h=p.error||c.error||null,x=()=>{o&&p.mutate(t||{})},f=()=>{o&&c.mutate()};return typeof n=="function"?n({isRegistered:d,isLoading:g,register:x,withdraw:f,error:h,isPowerMode:o,registrationUrl:l}):o?e.jsx("button",{className:`pvx-comp-register-btn ${r||""}`,onClick:d?f:x,disabled:g,children:g?"Loading...":d?"Withdraw":"Register"}):e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:`pvx-comp-register-link ${r||""}`,children:d?"View Registration":"Register on PitVox"})}function Es({competitionId:s,registration:t,onWithdrawSuccess:r,className:n}){const{getSteamId:a}=C(),{isPowerMode:i}=K(),o=H(s),{data:l,isLoading:p}=V(s),{data:c,isLoading:d}=re(s),g=ne(s),h=ae(s),x=a(),f=(l==null?void 0:l.isRegistered)||!1,v=(c==null?void 0:c.drivers)||(c==null?void 0:c.entries)||[],u=t||{},j=v.length||u.currentCount||0,m=u.maxParticipants&&j>=u.maxParticipants,b=u.deadline&&new Date(u.deadline)<new Date,w=u.isOpen&&!b&&!m;return p||d?e.jsx(I,{message:"Loading registration..."}):f?e.jsx("div",{className:`pvx-reg-panel ${n||""}`,children:e.jsx(Fs,{competitionId:s,drivers:v,steamId:x,isPowerMode:i,registrationUrl:o,withdrawMutation:h,onWithdrawSuccess:r,registration:u})}):w?x?i?e.jsx("div",{className:`pvx-reg-panel ${n||""}`,children:e.jsx(Us,{competitionId:s,registerMutation:g,registration:u})}):e.jsx("div",{className:`pvx-reg-panel ${n||""}`,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 ${n||""}`,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 ${n||""}`,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(Ee,{drivers:v,steamId:x})]})}function Us({competitionId:s,registerMutation:t,registration:r}){const[n,a]=N.useState(""),[i,o]=N.useState("intermediate"),[l,p]=N.useState(""),c=x=>{x.preventDefault(),t.mutate({discordUsername:n||void 0,experience:i,comments:l||void 0})},d=r||{},g=d.currentCount||0,h=d.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"}),h&&e.jsx(Ue,{count:g,max:h})]}),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:n,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=>p(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 Fs({competitionId:s,drivers:t,steamId:r,isPowerMode:n,registrationUrl:a,withdrawMutation:i,onWithdrawSuccess:o,registration:l}){const[p,c]=N.useState(!1),d=()=>{i.mutate(void 0,{onSuccess:()=>{c(!1),o&&o()}})},g=l||{},h=t.length||g.currentCount||0,x=g.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(Ue,{count:h,max:x})]}),e.jsx(Ee,{drivers:t,steamId:r}),i.error&&e.jsx("div",{className:"pvx-reg-error",children:i.error.message||"Withdrawal failed"}),n?e.jsx("div",{className:"pvx-reg-actions",children:p?e.jsxs("div",{className:"pvx-reg-confirm",children:[e.jsx("p",{className:"pvx-reg-confirm-text",children:"Are you sure you want to unregister?"}),e.jsxs("div",{className:"pvx-reg-confirm-actions",children:[e.jsx("button",{type:"button",className:"pvx-reg-cancel-btn",onClick:()=>c(!1),children:"Cancel"}),e.jsx("button",{type:"button",className:"pvx-reg-danger-btn",onClick:d,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 Ee({drivers:s,steamId:t}){if(!s.length)return e.jsx("div",{className:"pvx-reg-no-drivers",children:"No drivers registered yet."});const r=[...s].sort((n,a)=>{const i=t&&n.steamId===t?-1:0,o=t&&a.steamId===t?-1:0;return i-o});return e.jsx("div",{className:"pvx-reg-driver-list",children:r.map(n=>{var i,o;const a=t&&n.steamId===t;return e.jsxs("div",{className:`pvx-reg-driver-row ${a?"pvx-reg-driver-row--you":""}`,children:[n.avatarUrl?e.jsx("img",{src:n.avatarUrl,alt:"",className:"pvx-reg-driver-avatar"}):e.jsx("div",{className:"pvx-reg-driver-avatar pvx-reg-driver-avatar--placeholder",children:((o=(i=n.displayName)==null?void 0:i.charAt(0))==null?void 0:o.toUpperCase())||"?"}),e.jsxs("span",{className:"pvx-reg-driver-name",children:[n.displayName,a&&e.jsx("span",{className:"pvx-entry-you",children:" (you)"})]})]},n.steamId||n.driverId)})})}function Ue({count:s,max:t}){const r=t?s/t*100:0,n=r>=100?"full":r>=75?"warning":"ok";return e.jsxs("span",{className:`pvx-reg-capacity pvx-reg-capacity--${n}`,children:[s,"/",t," drivers"]})}function _s({competitionId:s,className:t}){const{data:r,isLoading:n}=se(s),a=(r==null?void 0:r.type)==="championship",i=N.useMemo(()=>{var u;return((u=r==null?void 0:r.rounds)==null?void 0:u.filter(j=>j.isFinalized))||[]},[r]),o=N.useMemo(()=>i.map(u=>u.roundNumber),[i]),{data:l=[],isLoading:p}=be(s,o),c=a?"standings":o.length>0?`round-${o[o.length-1]}`:null,[d,g]=N.useState(null),h=d||c;if(n||p)return e.jsx(I,{message:"Loading results..."});if(!r)return e.jsx(D,{message:"Competition not found."});if(!i.length)return e.jsx(D,{message:"No results available yet. Results will appear here once rounds are finalised."});const x=new Map(l.map(u=>[`round-${u.roundNumber}`,u])),f=[];a&&f.push({id:"standings",label:"Standings"});for(const u of i)f.push({id:`round-${u.roundNumber}`,label:`R${u.roundNumber}`,track:null});const v=x.get(h);return e.jsxs("div",{className:t||"",children:[e.jsx("div",{className:"pvx-results-tabs",children:f.map(u=>e.jsxs("button",{className:`pvx-results-tab ${h===u.id?"pvx-results-tab--active":""}`,onClick:()=>g(u.id),title:u.track||void 0,children:[e.jsx("span",{className:"pvx-results-tab-label",children:u.label}),u.track&&e.jsx("span",{className:"pvx-results-tab-track",children:u.track})]},u.id))}),h==="standings"?e.jsx(Ae,{competitionId:s}):v?e.jsx(qs,{round:v}):e.jsx(D,{message:"No results for this round."})]})}function qs({round:s}){var a;const r=(s.sessions||[]).find(i=>i.type==="RACE"),n=(a=r==null?void 0:r.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"})})]}),(n==null?void 0:n.length)>0&&e.jsx("div",{className:"pvx-round-podium-summary",children:n.map(i=>e.jsxs("span",{className:"pvx-round-podium-item",children:[e.jsx("span",{children:G[i.position-1]}),e.jsx("span",{children:i.driverName})]},i.driverId))})]}),e.jsx(pe,{round:s})]})}function Fe(s){const{cdnUrl:t}=C(),r=y.useQuery({queryKey:["pitvox","laps","global",s,"index"],queryFn:()=>S(t,ve(null,s)),enabled:!!s,staleTime:3e4,refetchInterval:3e4}),n=r.data;return{isLoading:r.isLoading,error:r.error,data:n?{driverName:n.driverName||"Driver",lapCount:n.lapCount||0,trackBreakdown:n.trackBreakdown||[],carBreakdown:n.carBreakdown||[],recordsHeld:n.recordsHeld||0,currentRecords:n.currentRecords||[],bestRanking:n.bestRanking??null,bestRankingTrackId:n.bestRankingTrackId??null,bestRankingLayout:n.bestRankingLayout??null,bestRankingCarId:n.bestRankingCarId??null,generatedAt:n.generatedAt}:null}}function _e(s={}){const{cdnUrl:t,partnerSlug:r}=C(),{game:n,gameVersion:a,enabled:i=!0}=s,o=q(r,n,a,"ratings.json");return y.useQuery({queryKey:["pitvox","ratings",r,n||null,a||null],queryFn:()=>S(t,o),staleTime:3e4,refetchInterval:3e4,enabled:i})}function qe(s){var n;const t=_e(),r=N.useMemo(()=>{var a;return!((a=t.data)!=null&&a.drivers)||!s?null:t.data.drivers.find(i=>i.identifier===s)||null},[(n=t.data)==null?void 0:n.drivers,s]);return{isLoading:t.isLoading,error:t.error,data:r?{rating:r.rating,rank:r.rank,totalDrivers:t.data.driverCount||t.data.drivers.length,comboCount:r.comboCount||0,distinctCars:r.distinctCars||0,combos:r.combos||[]}:null}}function Vs(s={}){const t=_e(s);return{data:t.data||null,isLoading:t.isLoading,error:t.error}}function Ve(){const{cdnUrl:s,partnerSlug:t,getSteamId:r,onFetchServerPassword:n}=C(),a=r(),{data:i,isLoading:o}=y.useQuery({queryKey:["pitvox","competitions",t],queryFn:async()=>{const x=await S(s,"competitions/index.json");return x!=null&&x.competitions?x.competitions.filter(f=>f.partnerSlug===t):[]},staleTime:6e4}),l=(i==null?void 0:i.map(x=>x.id))||[],p=y.useQueries({queries:l.map(x=>({queryKey:["pitvox","competition",t,x,"entrylist"],queryFn:()=>S(s,`competitions/${t}/${x}/entrylist.json`),enabled:!!a&&l.length>0,staleTime:6e4}))}),c=p.some(x=>x.isLoading),d=N.useMemo(()=>{var v,u;if(!i||!a||c)return[];const x=new Date,f=[];for(let j=0;j<i.length;j++){const m=i[j],b=(v=p[j])==null?void 0:v.data;if(!((u=b==null?void 0:b.drivers)==null?void 0:u.some(L=>L.steamId===a)))continue;const k=m.rounds||[];for(const L of k)L.isFinalized||!L.startTime||new Date(L.startTime)<=x||f.push({competitionId:m.id,competitionName:m.name,roundNumber:L.roundNumber,track:L.track||"TBD",startTime:L.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,p]),g=y.useQueries({queries:d.map(x=>({queryKey:["pitvox","serverInfo",x.competitionId,x.roundNumber],queryFn:()=>n(x.competitionId,x.roundNumber),enabled:!!n&&d.length>0,staleTime:5*6e4,retry:!1}))});return{data:N.useMemo(()=>d.length?n?d.map((x,f)=>{var u;const v=(u=g[f])==null?void 0:u.data;return v!=null&&v.success?{...x,serverAddress:v.serverAddress||null,serverPassword:v.serverPassword||null}:x}):d:[],[d,n,g]),isLoading:o||!!a&&c}}function Ke(){const{onFetchNotifications:s}=C();return!!s}function He(s={}){const{onFetchNotifications:t,partnerSlug:r}=C(),{limit:n=20,unreadOnly:a=!1}=s;return y.useQuery({queryKey:["pitvox","notifications",r,{limit:n,unreadOnly:a}],queryFn:()=>t({limit:n,unreadOnly:a}),enabled:!!t,staleTime:3e4,refetchInterval:3e4})}function Ks(){const{onFetchNotifications:s,partnerSlug:t}=C(),{data:r,isLoading:n}=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:r??0,isLoading:n}}function Qe(){const{onMarkNotificationRead:s,partnerSlug:t}=C(),r=y.useQueryClient();return y.useMutation({mutationFn:n=>{if(!s)throw new Error("No onMarkNotificationRead callback provided to PitVoxPartnerProvider.");return s(n)},onSuccess:(n,a)=>{r.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 Oe(){const{onMarkAllNotificationsRead:s,partnerSlug:t}=C(),r=y.useQueryClient();return y.useMutation({mutationFn:()=>{if(!s)throw new Error("No onMarkAllNotificationsRead callback provided to PitVoxPartnerProvider.");return s()},onSuccess:()=>{r.setQueriesData({queryKey:["pitvox","notifications",t]},n=>n!=null&&n.notifications?{...n,unreadCount:0,notifications:n.notifications.map(a=>({...a,isRead:!0,readAt:a.readAt||new Date().toISOString()}))}:n)}})}function We({driverName:s,avatarUrl:t,memberSince:r,className:n=""}){const a=r?new Date(r).toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"numeric"}):null;return e.jsxs("div",{className:`pvx-card pvx-dash-profile ${n}`,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 Hs(){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 Qs(){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 Os(){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 ue({icon:s,value:t,label:r,items:n,labelKey:a,countKey:i}){const[o,l]=N.useState(!1),p=N.useRef(null);N.useEffect(()=>{if(!o)return;function d(g){p.current&&!p.current.contains(g.target)&&l(!1)}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[o]);const c=n!=null&&n.length?n.slice().sort((d,g)=>g[i]-d[i]):null;return e.jsxs("div",{ref:p,className:`pvx-dash-stat-card ${c?"pvx-dash-stat-card--clickable":""}`,onClick:c?()=>l(d=>!d):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:r})]}),c&&e.jsx("div",{className:`pvx-dash-tooltip pvx-dash-tooltip--scrollable ${o?"pvx-dash-tooltip--open":""}`,children:c.map((d,g)=>e.jsxs("div",{className:"pvx-dash-tooltip-row",children:[e.jsx("span",{className:"pvx-dash-tooltip-label",children:d[a]}),e.jsx("span",{className:"pvx-dash-tooltip-value",children:d[i]})]},g))})]})}function Ge({stats:s,rating:t,className:r=""}){if(!s)return null;const n=s.trackBreakdown.map(i=>({name:B(i.trackId,i.layout),lapCount:i.lapCount})),a=s.carBreakdown.map(i=>({name:M(i.carId),lapCount:i.lapCount}));return e.jsxs("div",{className:`pvx-dash-stats ${r}`,children:[e.jsx(ue,{icon:e.jsx(Hs,{}),value:s.lapCount.toLocaleString(),label:"Total Laps",items:n,labelKey:"name",countKey:"lapCount"}),e.jsx(ue,{icon:e.jsx(Qs,{}),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(Os,{}),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 ze({records:s,className:t=""}){const r=N.useMemo(()=>s!=null&&s.length?s.slice().sort((n,a)=>{const i=n.recordedAt?new Date(n.recordedAt).getTime():0;return(a.recordedAt?new Date(a.recordedAt).getTime():0)-i}):[],[s]);return r.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:["(",r.length,")"]})]})}),e.jsx("div",{className:"pvx-dash-records-list",children:r.map((n,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:B(n.trackId,n.layout,n.game)}),e.jsx("span",{className:"pvx-dash-record-car",children:M(n.carId)})]}),e.jsxs("div",{className:"pvx-dash-record-time",children:[e.jsx("span",{className:"pvx-dash-record-lap",children:P(n.lapTimeMs)}),e.jsxs("span",{className:`pvx-dash-game-badge pvx-dash-game-badge--${n.game||"evo"}`,children:[(n.game||"evo").toUpperCase(),n.gameVersion?` ${n.gameVersion}`:""]})]})]},a))})]}):null}function Ye({events:s,isLoading:t,className:r,limit:n=3}){if(t)return e.jsx("div",{className:"pvx-loading",children:"Loading upcoming events..."});if(!(s!=null&&s.length))return null;const a=n?s.slice(0,n):s,i=s.length-a.length;return e.jsxs("div",{className:`pvx-card ${r||""}`,children:[e.jsx("div",{className:"pvx-card-header",children:e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(zs,{}),"Upcoming Events",e.jsxs("span",{className:"pvx-dash-records-count",children:["(",s.length,")"]})]})}),e.jsxs("div",{className:"pvx-upcoming-list",children:[a.map(o=>e.jsxs("div",{className:`pvx-upcoming-item ${o.isNext?"pvx-upcoming-item--next":""}`,children:[e.jsxs("div",{className:"pvx-upcoming-info",children:[e.jsx("span",{className:"pvx-upcoming-comp",children:o.competitionName}),e.jsxs("span",{className:"pvx-upcoming-round",children:["Round ",o.roundNumber,": ",o.track]}),o.serverPassword&&e.jsx(Ws,{password:o.serverPassword,address:o.serverAddress})]}),e.jsxs("div",{className:"pvx-upcoming-time",children:[e.jsx("span",{className:"pvx-upcoming-date",children:new Date(o.startTime).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}),e.jsx("span",{className:"pvx-upcoming-relative",children:o.dediStatus==="running"?"Live now":o.dediStatus==="provisioning"?"Starting...":Gs(o.startTime)}),o.dediStatus==="running"&&e.jsx("span",{className:"pvx-upcoming-badge pvx-upcoming-badge--live",children:"Live"}),!o.dediStatus&&o.isNext&&e.jsx("span",{className:"pvx-upcoming-badge",children:"Next"})]})]},`${o.competitionId}-${o.roundNumber}`)),i>0&&e.jsxs("div",{className:"pvx-upcoming-remaining",children:["+",i," more event",i!==1?"s":""]})]})]})}function Ws({password:s,address:t}){const[r,n]=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),n(!0),setTimeout(()=>n(!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(Js,{})," ",r?"Copied!":"Join"]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"pvx-server-detail pvx-server-detail--clickable",onClick:()=>i(p=>!p),title:a?"Hide password":"Reveal password",children:a?e.jsx(Xs,{}):e.jsx(Zs,{})}),a&&e.jsxs("span",{className:"pvx-server-detail",children:[e.jsx(Ys,{})," ",s]})]})]})}function Gs(s){const t=new Date(s).getTime()-Date.now();if(t<=0)return"Now";const r=Math.floor(t/(1e3*60*60));if(r<1)return"Less than 1 hour";if(r<24)return`in ${r}h`;const n=Math.floor(r/24);if(n===1)return"Tomorrow";if(n<7)return`in ${n} days`;if(n<30){const a=Math.floor(n/7);return`in ${a} week${a!==1?"s":""}`}return J(s)}function zs(){return e.jsxs("svg",{className:"pvx-dash-records-icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M16 2v4M8 2v4M3 10h18"})]})}function Ys(){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 Js(){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 Zs(){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 Xs(){return e.jsxs("svg",{className:"pvx-server-icon pvx-server-icon--action",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),e.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Je({notifications:s,unreadCount:t=0,onMarkRead:r,onMarkAllRead:n,isLoading:a,className:i}){const o=ee();return a?e.jsx("div",{className:"pvx-loading",children:"Loading notifications..."}):e.jsxs("div",{className:`pvx-card ${i||""}`,children:[e.jsxs("div",{className:"pvx-card-header",children:[e.jsxs("h3",{className:"pvx-card-title",children:[e.jsx(tt,{}),"Notifications",t>0&&e.jsx("span",{className:"pvx-notif-badge",children:t>99?"99+":t})]}),t>0&&n&&e.jsx("button",{className:"pvx-notif-mark-all",onClick:n,children:"Mark all read"})]}),s!=null&&s.length?e.jsx("div",{className:"pvx-notif-list",children:s.map(l=>e.jsx(et,{notification:l,getUserDisplay:o,onMarkRead:r},l.id))}):e.jsx("div",{className:"pvx-notif-empty",children:"No notifications"})]})}function et({notification:s,getUserDisplay:t,onMarkRead:r}){const n=()=>{!s.isRead&&r&&r(s.id)};return e.jsxs("button",{className:`pvx-notif-item ${s.isRead?"":"pvx-notif-item--unread"}`,onClick:n,children:[e.jsx(st,{type:s.type}),e.jsxs("div",{className:"pvx-notif-content",children:[e.jsx("span",{className:"pvx-notif-message",children:ge(s,t)}),e.jsx("span",{className:"pvx-notif-time",children:J(s.createdAt)})]}),!s.isRead&&e.jsx("span",{className:"pvx-notif-dot"})]})}function st({type:s}){return s==="RECORD_BEATEN"?e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--beaten",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m7 7 10 10M17 7v10H7"})})}):s==="ADMIN_MESSAGE"?e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--admin",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"m3 11 18-5v12L3 13v-2z"}),e.jsx("path",{d:"M11.6 16.8a3 3 0 1 1-5.8-1.6"})]})}):e.jsx("span",{className:"pvx-notif-icon pvx-notif-icon--record",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 9H4.5a2.5 2.5 0 0 1 0-5H6"}),e.jsx("path",{d:"M18 9h1.5a2.5 2.5 0 0 0 0-5H18"}),e.jsx("path",{d:"M4 22h16"}),e.jsx("path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"}),e.jsx("path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"}),e.jsx("path",{d:"M18 2H6v7a6 6 0 0 0 12 0V2Z"})]})})}function tt(){return e.jsxs("svg",{className:"pvx-dash-records-icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"}),e.jsx("path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0"})]})}function rt({steamId:s,avatarUrl:t,memberSince:r,className:n=""}){const{data:a,isLoading:i,error:o}=Fe(s),{data:l,isLoading:p}=qe(s),{data:c,isLoading:d}=Ve(),g=Ke(),{data:h,isLoading:x}=He({limit:10}),f=Qe(),v=Oe();return i||p?e.jsx("div",{className:"pvx-loading",children:"Loading dashboard..."}):o?e.jsx("div",{className:"pvx-empty",children:"Failed to load dashboard data."}):a?e.jsxs("div",{className:`pvx-dash ${n}`,children:[e.jsx(We,{driverName:a.driverName,avatarUrl:t,memberSince:r}),e.jsx(Ge,{stats:a,rating:l}),s&&e.jsx(Ye,{events:c,isLoading:d}),e.jsxs("div",{className:`pvx-dash-row ${g?"pvx-dash-row--2col":""}`,children:[e.jsx(ze,{records:a.currentRecords}),g&&e.jsx(Je,{notifications:h==null?void 0:h.notifications,unreadCount:(h==null?void 0:h.unreadCount)||0,onMarkRead:u=>f.mutate(u),onMarkAllRead:()=>v.mutate(),isLoading:x})]})]}):e.jsx("div",{className:"pvx-empty",children:"No data available yet. Start driving to see your stats!"})}exports.CarsTable=ms;exports.CompEmptyState=D;exports.CompLoadingState=I;exports.CompetitionCard=Be;exports.CompetitionCards=Ls;exports.CompetitionResultsTabs=_s;exports.CompletedBadge=Ie;exports.DEFAULT_COMPLETION_GRACE_DAYS=le;exports.DriverDashboard=rt;exports.DriverProfile=We;exports.DriversTable=vs;exports.EntryList=Bs;exports.InfoPill=_;exports.LapHistoryTable=hs;exports.NotificationsCard=Je;exports.PODIUM_MEDALS=G;exports.PitVoxPartnerProvider=es;exports.RankingsTable=gs;exports.RecordsTable=ze;exports.RegisterButton=As;exports.RegistrationPanel=Es;exports.RoundResults=Ms;exports.RoundSessionResults=pe;exports.StandingsTable=Ae;exports.StatsCards=Ge;exports.TracksTable=us;exports.TypeBadge=Me;exports.UpcomingEvents=Ye;exports.buildDriverIndexPath=ve;exports.buildLapsPath=me;exports.buildLeaderboardPath=q;exports.buildRecentLapsPath=he;exports.fetchCdnJson=S;exports.filterCompetitionsByStatus=ws;exports.formatCarName=M;exports.formatDate=A;exports.formatDelta=ss;exports.formatFuel=X;exports.formatLapTime=P;exports.formatNotificationMessage=ge;exports.formatRelativeTime=J;exports.formatSectorTime=$;exports.formatSessionLabel=Te;exports.formatTrackName=B;exports.formatTyreCompound=Z;exports.getCompetitionPodium=Pe;exports.getCompetitionStatus=de;exports.getCompletionDate=De;exports.isCompetitionComplete=$e;exports.useCarLeaderboard=as;exports.useCarMetadata=rs;exports.useCompetitionAllRounds=be;exports.useCompetitionConfig=se;exports.useCompetitionEntryList=re;exports.useCompetitionLeaderboard=os;exports.useCompetitionRound=Ne;exports.useCompetitionRoundLaps=ye;exports.useCompetitionStandings=te;exports.useCompetitions=is;exports.useDriverLaps=fe;exports.useDriverRating=qe;exports.useDriverRatings=Vs;exports.useDriverStats=Fe;exports.useLeaderboardIndex=ts;exports.useMarkAllNotificationsRead=Oe;exports.useMarkNotificationRead=Qe;exports.useNotifications=He;exports.useNotificationsEnabled=Ke;exports.usePitVox=C;exports.useRecentLaps=ns;exports.useRegister=ne;exports.useRegistrationMode=K;exports.useRegistrationStatus=V;exports.useRegistrationUrl=H;exports.useTrackLeaderboard=je;exports.useUnreadCount=Ks;exports.useUpcomingEvents=Ve;exports.useUserLookup=ee;exports.useWithdraw=ae;
package/dist/index.js CHANGED
@@ -999,7 +999,8 @@ const Xe = {
999
999
  }, se = ["🥇", "🥈", "🥉"], en = {
1000
1000
  championship: "Championship",
1001
1001
  series: "Series",
1002
- event: "Event"
1002
+ event: "Event",
1003
+ hotlap: "Hotlap"
1003
1004
  }, nn = ["PRACTICE", "QUALIFYING", "RACE"];
1004
1005
  function oe(e) {
1005
1006
  const t = nn.indexOf(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pitvox/partner-react",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "React hooks and styled components for PitVox partner websites — leaderboards, competitions, driver dashboards",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",