Files
gridpilot.gg/apps/website/lib/view-models/LeagueScoringSectionViewModel.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

127 lines
3.6 KiB
TypeScript

import type { LeagueConfigFormModel } from '@/lib/types/LeagueConfigFormModel';
import type { LeagueScoringPresetViewModel } from '@/lib/view-models/LeagueScoringPresetViewModel';
import type { CustomPointsConfig } from '@/lib/view-models/ScoringConfigurationViewModel';
/**
* LeagueScoringSectionViewModel
*
* View model for the league scoring section UI state and operations
*/
import { ViewModel } from "../contracts/view-models/ViewModel";
export class LeagueScoringSectionViewModel extends ViewModel {
readonly form: LeagueConfigFormModel;
readonly presets: LeagueScoringPresetViewModel[];
readonly readOnly: boolean;
readonly patternOnly: boolean;
readonly championshipsOnly: boolean;
readonly disabled: boolean;
readonly currentPreset: LeagueScoringPresetViewModel | null;
readonly isCustom: boolean;
constructor(
form: LeagueConfigFormModel,
presets: LeagueScoringPresetViewModel[],
options: {
readOnly?: boolean;
patternOnly?: boolean;
championshipsOnly?: boolean;
} = {}
) {
this.form = form;
this.presets = presets;
this.readOnly = options.readOnly || false;
this.patternOnly = options.patternOnly || false;
this.championshipsOnly = options.championshipsOnly || false;
this.disabled = this.readOnly;
this.currentPreset = form.scoring.patternId
? presets.find(p => p.id === form.scoring.patternId) || null
: null;
this.isCustom = form.scoring.customScoringEnabled || false;
}
/**
* 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 {
// This would be stored separately in the form model
// For now, return defaults
return LeagueScoringSectionViewModel.getDefaultCustomPoints();
}
}