import type { LeaderboardDriverItem } from '@/lib/view-data/LeaderboardDriverItem'; import { ViewModel } from "../contracts/view-models/ViewModel"; 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 { id: string; name: string; rating: number; skillLevel: string; nationality: string; racesCompleted: number; wins: number; podiums: number; rank: number; avatarUrl: string; position: number; private previousRating: number | undefined; constructor(viewData: LeaderboardDriverItem, previousRating?: number) { super(); this.id = viewData.id; this.name = viewData.name; this.rating = viewData.rating; this.skillLevel = viewData.skillLevel; this.nationality = viewData.nationality; this.racesCompleted = viewData.racesCompleted; this.wins = viewData.wins; this.podiums = viewData.podiums; this.rank = viewData.rank; this.avatarUrl = viewData.avatarUrl; this.position = viewData.position; this.previousRating = previousRating; } /** 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(); } }