Files
gridpilot.gg/apps/website/lib/view-models/DriverSummaryViewModel.ts
2026-01-26 17:47:37 +01:00

55 lines
1.3 KiB
TypeScript

import { ViewModel } from "../contracts/view-models/ViewModel";
import { NumberFormatter } from "../formatters/NumberFormatter";
import { RatingFormatter } from "../formatters/RatingFormatter";
import type { DriverSummaryData } from "../view-data/DriverSummaryData";
/**
* View Model for driver summary with rating and rank
*
* Client-only UI helper built from ViewData.
*/
export class DriverSummaryViewModel extends ViewModel {
constructor(private readonly viewData: any) {
super();
}
get id(): string {
return this.viewData.driverId || this.viewData.id;
}
get name(): string {
return this.viewData.driverName || this.viewData.name;
}
get avatarUrl(): string | null {
return this.viewData.avatarUrl;
}
get rating(): number | null {
return this.viewData.rating;
}
get ratingLabel(): string {
return RatingFormatter.format(this.rating);
}
get rank(): number | null {
return this.viewData.rank;
}
get rankLabel(): string {
return this.rank === null ? '—' : NumberFormatter.format(this.rank);
}
get roleBadgeText(): string {
return this.viewData.roleBadgeText;
}
get roleBadgeClasses(): string {
return this.viewData.roleBadgeClasses;
}
get profileUrl(): string {
return this.viewData.profileUrl;
}
}