48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { ViewModel } from "../contracts/view-models/ViewModel";
|
|
import type { SponsorSponsorshipsViewData } from "../view-data/SponsorSponsorshipsViewData";
|
|
import { SponsorshipDetailViewModel } from './SponsorshipDetailViewModel';
|
|
|
|
export class SponsorSponsorshipsViewModel extends ViewModel {
|
|
sponsorId: string;
|
|
sponsorName: string;
|
|
sponsorships: SponsorshipDetailViewModel[];
|
|
|
|
constructor(data: SponsorSponsorshipsViewData) {
|
|
super();
|
|
this.sponsorId = data.sponsorId;
|
|
this.sponsorName = data.sponsorName;
|
|
this.sponsorships = (data.sponsorships || []).map(s => new SponsorshipDetailViewModel(s));
|
|
}
|
|
|
|
/** UI-specific: Total sponsorships count */
|
|
get totalCount(): number {
|
|
return this.sponsorships.length;
|
|
}
|
|
|
|
/** UI-specific: Active sponsorships */
|
|
get activeSponsorships(): SponsorshipDetailViewModel[] {
|
|
return this.sponsorships.filter(s => s.status === 'active');
|
|
}
|
|
|
|
/** UI-specific: Active count */
|
|
get activeCount(): number {
|
|
return this.activeSponsorships.length;
|
|
}
|
|
|
|
/** UI-specific: Has sponsorships */
|
|
get hasSponsorships(): boolean {
|
|
return this.sponsorships.length > 0;
|
|
}
|
|
|
|
/** UI-specific: Total investment */
|
|
get totalInvestment(): number {
|
|
return this.sponsorships.reduce((sum, s) => sum + s.amount, 0);
|
|
}
|
|
|
|
/** UI-specific: Formatted total investment */
|
|
get formattedTotalInvestment(): string {
|
|
const firstCurrency = this.sponsorships[0]?.currency || 'USD';
|
|
return `${firstCurrency} ${this.totalInvestment.toLocaleString()}`;
|
|
}
|
|
}
|