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

100 lines
2.9 KiB
TypeScript

import { ViewModel } from "../contracts/view-models/ViewModel";
import { CurrencyDisplay } from '../display-objects/CurrencyDisplay';
import { DateDisplay } from '../display-objects/DateDisplay';
import { NumberDisplay } from '../display-objects/NumberDisplay';
import type { SponsorshipViewData } from "../view-data/SponsorshipViewData";
/**
* Sponsorship View Model
*
* View model for individual sponsorship data.
*/
export class SponsorshipViewModel extends ViewModel {
id: string;
type: 'leagues' | 'teams' | 'drivers' | 'races' | 'platform';
entityId: string;
entityName: string;
tier?: 'main' | 'secondary';
status: 'active' | 'pending_approval' | 'approved' | 'rejected' | 'expired';
applicationDate?: Date;
approvalDate?: Date;
rejectionReason?: string;
startDate: Date;
endDate: Date;
price: number;
impressions: number;
impressionsChange?: number;
engagement?: number;
details?: string;
entityOwner?: string;
applicationMessage?: string;
constructor(data: SponsorshipViewData) {
super();
this.id = data.id;
this.type = data.type;
this.entityId = data.entityId;
this.entityName = data.entityName;
this.tier = data.tier;
this.status = data.status;
this.applicationDate = data.applicationDate ? new Date(data.applicationDate) : undefined;
this.approvalDate = data.approvalDate ? new Date(data.approvalDate) : undefined;
this.rejectionReason = data.rejectionReason;
this.startDate = new Date(data.startDate);
this.endDate = new Date(data.endDate);
this.price = data.price;
this.impressions = data.impressions;
this.impressionsChange = data.impressionsChange;
this.engagement = data.engagement;
this.details = data.details;
this.entityOwner = data.entityOwner;
this.applicationMessage = data.applicationMessage;
}
get formattedImpressions(): string {
return NumberDisplay.format(this.impressions);
}
get formattedPrice(): string {
return CurrencyDisplay.format(this.price);
}
get daysRemaining(): number {
const now = new Date();
const diffTime = this.endDate.getTime() - now.getTime();
return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
}
get isExpiringSoon(): boolean {
return this.daysRemaining > 0 && this.daysRemaining <= 30;
}
get statusLabel(): string {
const labels = {
active: 'Active',
pending_approval: 'Awaiting Approval',
approved: 'Approved',
rejected: 'Declined',
expired: 'Expired',
};
return labels[this.status] || this.status;
}
get typeLabel(): string {
const labels = {
leagues: 'League',
teams: 'Team',
drivers: 'Driver',
races: 'Race',
platform: 'Platform',
};
return labels[this.type] || this.type;
}
get periodDisplay(): string {
const start = DateDisplay.formatMonthYear(this.startDate);
const end = DateDisplay.formatMonthYear(this.endDate);
return `${start} - ${end}`;
}
}