diff --git a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts index c434e3f..470e56c 100755 --- a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts +++ b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts @@ -1149,94 +1149,136 @@ const winLabels = allRows.map(row => { displayLabel = this.currentPool; // Use trb1 or trb2 } - // --- Multi-leg pools: Expand 'F' for each leg --- - if (['TBP', 'MJP', 'JPP'].includes(row.label)) { - // Split by '/' for legs - let legs: (number | string)[][] = []; - let currentLeg: (number | string)[] = []; - for (const n of displayNumbers) { - if (n === '/') { - legs.push(currentLeg); - currentLeg = []; - } else { - currentLeg.push(n); - } +// // --- Multi-leg pools: Expand 'F' for each leg --- +// if (['TBP', 'MJP', 'JPP'].includes(row.label)) { +// // Split by '/' for legs +// let legs: (number | string)[][] = []; +// let currentLeg: (number | string)[] = []; +// for (const n of displayNumbers) { +// if (n === '/') { +// legs.push(currentLeg); +// currentLeg = []; +// } else { +// currentLeg.push(n); +// } +// } +// if (currentLeg.length) legs.push(currentLeg); + +// // For each leg, expand 'F' to correct horse numbers for that leg +// const poolName = row.label === 'MJP' ? 'mjp1' : row.label === 'JPP' ? 'jkp1' : this.currentPool || 'trb1'; +// const raceCardData = JSON.parse(localStorage.getItem('raceCardData') || '{}'); +// const poolRaces = raceCardData?.raceVenueRaces?.pools?.[poolName] || []; +// // Fallback to hardcoded mapping if needed +// const raceMap: { [key: string]: number[] } = { +// 'mjp1': [1, 2, 3, 4], +// 'jkp1': [3, 4, 5, 6, 7], +// 'trb1': [2, 3, 4], +// 'trb2': [5, 6, 7] +// }; +// const raceIndices: number[] = poolRaces.length > 0 ? poolRaces : (raceMap[poolName] || []); +// // If no mapping, fallback to consecutive races from 1 +// const baseRaceIdx = raceIndices.length > 0 ? raceIndices[0] : 1; + +// let expandedLegs: string[] = legs.map((leg, i) => { +// // Find race index for this leg +// let raceIdx = raceIndices.length > i ? raceIndices[i] - 1 : (baseRaceIdx - 1 + i); + +// let expanded = leg.flatMap((n) => { +// if (n === 'F') { +// // Expand F → horse numbers, no extra dashes +// return this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString()); +// } +// return [n]; // Keep original (including '-') if user entered +// }); + +// // Remove '-' and '#' for display +// return expanded.filter(n => n !== '-' && n !== '#').join(','); +// }); + +// // Join legs with '/' +// let numbersStr = expandedLegs.join(' / '); + +// const label = displayLabel.padEnd(10); +// const numbers = numbersStr.padEnd(15); +// const value = (`*${row.value || 0}`).padEnd(8); +// return `${label}${numbers} ${value}`; +// } + +// Helper to pad ticket count to 3 digits (if you don't already have it elsewhere) +function padTicketCountToThree(n: number) { + const num = Number.isFinite(n) && n >= 0 ? Math.floor(n) : 0; + return String(num).padStart(3, '0'); +} + +// Replace the existing TBP / MJP / JPP block with this: +if (['TBP', 'MJP', 'JPP'].includes(row.label)) { + // Split by '/' for legs + let legs: (number | string)[][] = []; + let currentLeg: (number | string)[] = []; + for (const n of displayNumbers) { + if (n === '/') { + legs.push(currentLeg); + currentLeg = []; + } else { + currentLeg.push(n); } - if (currentLeg.length) legs.push(currentLeg); - - // For each leg, expand 'F' to correct horse numbers for that leg - const poolName = row.label === 'MJP' ? 'mjp1' : row.label === 'JPP' ? 'jkp1' : this.currentPool || 'trb1'; - const raceCardData = JSON.parse(localStorage.getItem('raceCardData') || '{}'); - const poolRaces = raceCardData?.raceVenueRaces?.pools?.[poolName] || []; - // Fallback to hardcoded mapping if needed - const raceMap: { [key: string]: number[] } = { - 'mjp1': [1, 2, 3, 4], - 'jkp1': [3, 4, 5, 6, 7], - 'trb1': [2, 3, 4], - 'trb2': [5, 6, 7] - }; - const raceIndices: number[] = poolRaces.length > 0 ? poolRaces : (raceMap[poolName] || []); - // If no mapping, fallback to consecutive races from 1 - const baseRaceIdx = raceIndices.length > 0 ? raceIndices[0] : 1; - - let expandedLegs: string[] = legs.map((leg, i) => { - // Find race index for this leg - let raceIdx = raceIndices.length > i ? raceIndices[i] - 1 : (baseRaceIdx - 1 + i); - // let expanded = leg.flatMap(n => - // n === 'F' - // ? this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString()) - // : [n] - // ); - // let expanded = leg.flatMap((n, idx) => { - // if (n === 'F') { - // const horses = this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString()).join(','); - // const isFirst = idx === 0; - // const isLast = idx === leg.length - 1; - // if (isFirst && !isLast) return [`${horses}-`]; - // if (!isFirst && isLast) return [`-${horses}`]; - // if (isFirst && isLast) return [horses]; // only F in the leg - // return [`-${horses}-`]; - // } - // return [n]; - // }); - let expanded = leg.flatMap((n) => { - if (n === 'F') { - // Expand F → horse numbers, no extra dashes - return this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString()); } - return [n]; // Keep original (including '-') if user entered -}); + if (currentLeg.length) legs.push(currentLeg); - // Remove '-' and '#' for display - return expanded.filter(n => n !== '-' && n !== '#').join(','); + // Choose pool name (used only for race->horses lookup) + const poolName = row.label === 'MJP' ? 'mjp1' : row.label === 'JPP' ? 'jkp1' : (this.currentPool || 'trb1'); + + // Get pool races from cached raceCardData; fallback to hard-coded map + const raceCardData = JSON.parse(localStorage.getItem('raceCardData') || '{}'); + const poolRaces = raceCardData?.raceVenueRaces?.pools?.[poolName] || []; + const raceMap: { [key: string]: number[] } = { + 'mjp1': [1, 2, 3, 4], + 'jkp1': [3, 4, 5, 6, 7], + 'trb1': [2, 3, 4], + 'trb2': [5, 6, 7] + }; + const raceIndices: number[] = poolRaces.length > 0 ? poolRaces : (raceMap[poolName] || []); + const baseRaceIdx = raceIndices.length > 0 ? raceIndices[0] : 1; + + // Expand each leg: expand 'F' to actual horse numbers for that leg, normalize numeric tokens to two digits + const normalizeToken = (tok: string | number) => { + const s = String(tok); + return /^\d+$/.test(s) ? s.padStart(2, '0') : s; + }; + + const expandedLegs: string[] = legs.map((leg, i) => { + const raceIdx = raceIndices.length > i ? raceIndices[i] - 1 : (baseRaceIdx - 1 + i); + const expanded = leg.flatMap((n) => { + if (n === 'F') { + // expand to horse numbers for that race index + return this.getHorseNumbersForRaceIdx(raceIdx).map(num => String(num)); + } + return [n]; }); + // remove any stray '-' and '#', normalize numeric tokens to two digits, then join by ',' + return expanded + .filter(n => n !== '-' && n !== '#') + .map(normalizeToken) + .join(','); + }); - // Join legs with '/' - let numbersStr = expandedLegs.join(' / '); + // Join legs with '/' (no extra spaces to match your desired output) + const numbersStr = expandedLegs.join('/'); + + // Label: always show TBP (uppercase) for TBP rows; for MJP/JPP leave as-is + const labelForDisplay = row.label === 'TBP' ? 'TBP' : displayLabel; + + // Value: zero-pad tickets to 3 digits like *007 + const valueStr = `*${padTicketCountToThree(row.value || 0)}`; + + // Build line: e.g. "TBP 01,02/02,03/02,03*007" + return `${labelForDisplay} ${numbersStr}${valueStr}`; +} - const label = displayLabel.padEnd(10); - const numbers = numbersStr.padEnd(15); - const value = (`*${row.value || 0}`).padEnd(8); - return `${label}${numbers} ${value}`; - } // 🐎 Expand 'F' to full horse numbers for other pools if (displayNumbers.includes('F')) { - // displayNumbers = displayNumbers.flatMap(n => - // n === 'F' ? this.getHorseNumbersForSelectedRace().map(num => num.toString()) : [n] - // ); -// displayNumbers = displayNumbers.flatMap((n, idx, arr) => { -// if (n === 'F') { - // const horses = this.getHorseNumbersForSelectedRace().map(num => num.toString()).join(','); - // const isFirst = idx === 0; - // const isLast = idx === arr.length - 1; - // if (isFirst && !isLast) return [`${horses}-`]; - // if (!isFirst && isLast) return [`-${horses}`]; - // if (isFirst && isLast) return [horses]; // only F - // return [`-${horses}-`]; - // } - // return [n]; -// }); + displayNumbers = displayNumbers.flatMap((n) => { if (n === 'F') { // Expand F → horse numbers, no extra dashes