38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { ViewModel } from "../contracts/view-models/ViewModel";
|
|
import { LeagueRoleDisplay, LeagueRole } from "../display-objects/LeagueRoleDisplay";
|
|
import type { LeagueMemberViewData } from "../view-data/LeagueMemberViewData";
|
|
|
|
export class LeagueMemberViewModel extends ViewModel {
|
|
private readonly data: LeagueMemberViewData;
|
|
|
|
constructor(data: LeagueMemberViewData) {
|
|
super();
|
|
this.data = data;
|
|
}
|
|
|
|
get driverId(): string { return this.data.driverId; }
|
|
get driver(): any { return this.data.driver; }
|
|
get role(): string { return this.data.role; }
|
|
get joinedAt(): string { return this.data.joinedAt; }
|
|
|
|
/** UI-specific: Formatted join date */
|
|
get formattedJoinedAt(): string {
|
|
// Client-only formatting
|
|
return new Date(this.joinedAt).toLocaleDateString();
|
|
}
|
|
|
|
/** UI-specific: Badge classes for role */
|
|
get roleBadgeClasses(): string {
|
|
return LeagueRoleDisplay.getLeagueRoleDisplay(this.role as LeagueRole)?.badgeClasses || '';
|
|
}
|
|
|
|
/** UI-specific: Whether this member is the owner */
|
|
get isOwner(): boolean {
|
|
return this.role === 'owner';
|
|
}
|
|
|
|
/** UI-specific: Whether this is the current user */
|
|
get isCurrentUser(): boolean {
|
|
return this.driverId === this.data.currentUserId;
|
|
}
|
|
} |