115 lines
3.4 KiB
TypeScript
115 lines
3.4 KiB
TypeScript
import { ViewModel } from "../contracts/view-models/ViewModel";
|
|
import type { LeagueScoringSectionViewData } from "../view-data/LeagueScoringSectionViewData";
|
|
import type { CustomPointsConfig } from "../view-data/ScoringConfigurationViewData";
|
|
import { LeagueScoringPresetViewModel } from './LeagueScoringPresetViewModel';
|
|
|
|
export class LeagueScoringSectionViewModel extends ViewModel {
|
|
readonly presets: LeagueScoringPresetViewModel[];
|
|
readonly readOnly: boolean;
|
|
readonly patternOnly: boolean;
|
|
readonly championshipsOnly: boolean;
|
|
readonly disabled: boolean;
|
|
readonly currentPreset: LeagueScoringPresetViewModel | null;
|
|
readonly isCustom: boolean;
|
|
private readonly data: LeagueScoringSectionViewData;
|
|
|
|
constructor(data: LeagueScoringSectionViewData) {
|
|
super();
|
|
this.data = data;
|
|
this.presets = data.presets.map(p => new LeagueScoringPresetViewModel(p));
|
|
this.readOnly = data.options?.readOnly || false;
|
|
this.patternOnly = data.options?.patternOnly || false;
|
|
this.championshipsOnly = data.options?.championshipsOnly || false;
|
|
this.disabled = this.readOnly;
|
|
this.currentPreset = data.form.scoring.patternId
|
|
? this.presets.find(p => p.id === data.form.scoring.patternId) || null
|
|
: null;
|
|
this.isCustom = data.form.scoring.customScoringEnabled || false;
|
|
}
|
|
|
|
get form() { return this.data.form; }
|
|
|
|
/**
|
|
* Get default custom points configuration
|
|
*/
|
|
static getDefaultCustomPoints(): CustomPointsConfig {
|
|
return {
|
|
racePoints: [25, 18, 15, 12, 10, 8, 6, 4, 2, 1],
|
|
poleBonusPoints: 1,
|
|
fastestLapPoints: 1,
|
|
leaderLapPoints: 0,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Check if form can be modified
|
|
*/
|
|
canModify(): boolean {
|
|
return !this.readOnly;
|
|
}
|
|
|
|
/**
|
|
* Get available presets for display
|
|
*/
|
|
getAvailablePresets(): LeagueScoringPresetViewModel[] {
|
|
return this.presets;
|
|
}
|
|
|
|
/**
|
|
* Get championships configuration for display
|
|
*/
|
|
getChampionshipsConfig() {
|
|
const isTeamsMode = this.form.structure.mode === 'fixedTeams';
|
|
|
|
return [
|
|
{
|
|
key: 'enableDriverChampionship' as const,
|
|
label: 'Driver Standings',
|
|
description: 'Track individual driver points',
|
|
enabled: this.form.championships.enableDriverChampionship,
|
|
available: true,
|
|
},
|
|
{
|
|
key: 'enableTeamChampionship' as const,
|
|
label: 'Team Standings',
|
|
description: 'Combined team points',
|
|
enabled: this.form.championships.enableTeamChampionship,
|
|
available: isTeamsMode,
|
|
unavailableHint: 'Teams mode only',
|
|
},
|
|
{
|
|
key: 'enableNationsChampionship' as const,
|
|
label: 'Nations Cup',
|
|
description: 'By nationality',
|
|
enabled: this.form.championships.enableNationsChampionship,
|
|
available: true,
|
|
},
|
|
{
|
|
key: 'enableTrophyChampionship' as const,
|
|
label: 'Trophy Cup',
|
|
description: 'Special category',
|
|
enabled: this.form.championships.enableTrophyChampionship,
|
|
available: true,
|
|
},
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get panel visibility based on flags
|
|
*/
|
|
shouldShowPatternPanel(): boolean {
|
|
return !this.championshipsOnly;
|
|
}
|
|
|
|
shouldShowChampionshipsPanel(): boolean {
|
|
return !this.patternOnly;
|
|
}
|
|
|
|
/**
|
|
* Get the active custom points configuration
|
|
*/
|
|
getActiveCustomPoints(): CustomPointsConfig {
|
|
return LeagueScoringSectionViewModel.getDefaultCustomPoints();
|
|
}
|
|
}
|