65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { ViewModel } from "../contracts/view-models/ViewModel";
|
|
import type { LeaderboardDriverItem } from '../view-data/LeaderboardDriverItem';
|
|
import { SkillLevelDisplay } from "../display-objects/SkillLevelDisplay";
|
|
import { SkillLevelIconDisplay } from "../display-objects/SkillLevelIconDisplay";
|
|
import { WinRateDisplay } from "../display-objects/WinRateDisplay";
|
|
import { RatingTrendDisplay } from "../display-objects/RatingTrendDisplay";
|
|
|
|
export class DriverLeaderboardItemViewModel extends ViewModel {
|
|
private readonly data: LeaderboardDriverItem;
|
|
private readonly previousRating: number | undefined;
|
|
|
|
constructor(data: LeaderboardDriverItem, previousRating?: number) {
|
|
super();
|
|
this.data = data;
|
|
this.previousRating = previousRating;
|
|
}
|
|
|
|
get id(): string { return this.data.id; }
|
|
get name(): string { return this.data.name; }
|
|
get rating(): number { return this.data.rating; }
|
|
get skillLevel(): string { return this.data.skillLevel; }
|
|
get nationality(): string { return this.data.nationality; }
|
|
get racesCompleted(): number { return this.data.racesCompleted; }
|
|
get wins(): number { return this.data.wins; }
|
|
get podiums(): number { return this.data.podiums; }
|
|
get rank(): number { return this.data.rank; }
|
|
get avatarUrl(): string { return this.data.avatarUrl; }
|
|
get position(): number { return this.data.position; }
|
|
|
|
/** UI-specific: Skill level color */
|
|
get skillLevelColor(): string {
|
|
return SkillLevelDisplay.getColor(this.skillLevel);
|
|
}
|
|
|
|
/** UI-specific: Skill level icon */
|
|
get skillLevelIcon(): string {
|
|
return SkillLevelIconDisplay.getIcon(this.skillLevel);
|
|
}
|
|
|
|
/** UI-specific: Win rate */
|
|
get winRate(): number {
|
|
return this.racesCompleted > 0 ? (this.wins / this.racesCompleted) * 100 : 0;
|
|
}
|
|
|
|
/** UI-specific: Formatted win rate */
|
|
get winRateFormatted(): string {
|
|
return WinRateDisplay.format(this.winRate);
|
|
}
|
|
|
|
/** UI-specific: Rating trend */
|
|
get ratingTrend(): 'up' | 'down' | 'same' {
|
|
return RatingTrendDisplay.getTrend(this.rating, this.previousRating);
|
|
}
|
|
|
|
/** UI-specific: Rating change indicator */
|
|
get ratingChangeIndicator(): string {
|
|
return RatingTrendDisplay.getChangeIndicator(this.rating, this.previousRating);
|
|
}
|
|
|
|
/** UI-specific: Position badge */
|
|
get positionBadge(): string {
|
|
return this.position.toString();
|
|
}
|
|
}
|