import { Injectable } from '@angular/core'; import { SelectionData } from '../selection.service/selection.service'; // Define mutually exclusive label groups export const LABEL_GROUPS: { [key: string]: string[] } = { groupA: ['WIN', 'SHP', 'THP', 'PLC', 'SHW'], groupB: ['FOR', 'QUI', 'TAN', 'EXA'], groupWSP: ['WSP'], groupTRE: ['TRE'], groupMJP: ['MJP'], groupJKP: ['JKP'], }; // Reverse index to map labels to their groups export const LABEL_TO_GROUP: { [label: string]: string } = {}; Object.entries(LABEL_GROUPS).forEach(([group, labels]) => { labels.forEach(label => (LABEL_TO_GROUP[label] = group)); }); @Injectable({ providedIn: 'root' }) export class LabelRestrictionService { getBlockedLabels(selections: SelectionData[]): Set { const selectedGroups = new Set(); for (const row of selections) { if (row.label && LABEL_TO_GROUP[row.label]) { selectedGroups.add(LABEL_TO_GROUP[row.label]); } } const blockLabels = new Set(); if (selectedGroups.size > 0) { // Block all labels from groups not already selected Object.entries(LABEL_GROUPS).forEach(([group, labels]) => { if (!selectedGroups.has(group)) { labels.forEach(label => blockLabels.add(label)); } }); // Special rule for WSP: if WSP is selected, only allow WIN, SHP, THP in the three rows if (selectedGroups.has('groupWSP')) { Object.keys(LABEL_TO_GROUP).forEach(label => { if (!['WIN', 'SHP', 'THP'].includes(label)) { blockLabels.add(label); } }); } } return blockLabels; } }