Files
gridpilot.gg/apps/website/lib/view-models/PrizeViewModel.ts
2026-01-23 15:30:23 +01:00

69 lines
2.3 KiB
TypeScript

import { ViewModel } from "../contracts/view-models/ViewModel";
import { CurrencyDisplay } from "../display-objects/CurrencyDisplay";
import { FinishDisplay } from "../display-objects/FinishDisplay";
import { DateDisplay } from "../display-objects/DateDisplay";
import { PrizeTypeDisplay } from "../display-objects/PrizeTypeDisplay";
import type { PrizeViewData } from "../view-data/PrizeViewData";
export class PrizeViewModel extends ViewModel {
private readonly data: PrizeViewData;
constructor(data: PrizeViewData) {
super();
this.data = data;
}
get id(): string { return this.data.id; }
get leagueId(): string { return this.data.leagueId; }
get seasonId(): string { return this.data.seasonId; }
get position(): number { return this.data.position; }
get name(): string { return this.data.name; }
get amount(): number { return this.data.amount; }
get type(): string { return this.data.type; }
get description(): string | undefined { return this.data.description; }
get awarded(): boolean { return this.data.awarded; }
get awardedTo(): string | undefined { return this.data.awardedTo; }
get awardedAt(): string | undefined { return this.data.awardedAt; }
get createdAt(): string { return this.data.createdAt; }
/** UI-specific: Formatted amount */
get formattedAmount(): string {
return CurrencyDisplay.format(this.amount, 'EUR');
}
/** UI-specific: Position display */
get positionDisplay(): string {
return FinishDisplay.format(this.position);
}
/** UI-specific: Type display */
get typeDisplay(): string {
return PrizeTypeDisplay.format(this.type);
}
/** UI-specific: Status display */
get statusDisplay(): string {
return this.awarded ? 'Awarded' : 'Available';
}
/** UI-specific: Status color */
get statusColor(): string {
return this.awarded ? 'green' : 'blue';
}
/** UI-specific: Prize description */
get prizeDescription(): string {
return `${this.name} - ${this.formattedAmount}`;
}
/** UI-specific: Formatted awarded date */
get formattedAwardedAt(): string {
return this.awardedAt ? DateDisplay.formatShort(this.awardedAt) : 'Not awarded';
}
/** UI-specific: Formatted created date */
get formattedCreatedAt(): string {
return DateDisplay.formatShort(this.createdAt);
}
}