import { TableCodes } from '../types/ToneTypes'; // Load the full, authoritative frequency table (parity with Swift SDK 22) // Note: We transform `tonetag` -> `tag` to match RN Pair type // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore import frequencyTablesRaw from '../frequency_tables.json'; /** * Utility class to load frequency tables * In a real React Native app, this would load from bundled assets */ export class FrequencyTableLoader { private static frequencyTable: TableCodes | null = null; /** * Load frequency tables from bundled assets * In a real implementation, this would use react-native-fs or similar */ public static async loadFrequencyTables(): Promise { if (this.frequencyTable) { return this.frequencyTable; } try { // Transform the JSON structure from Swift (tonetag -> tag) const transformed: TableCodes = { data: (frequencyTablesRaw?.data || []).map((item: any) => ({ lowkey: item.lowkey, pairs: (item.pairs || []).map((p: any) => ({ highkey: p.highkey, tag: p.tonetag })) })) }; this.frequencyTable = transformed; console.log(`🎯 FrequencyTableLoader: Loaded ${this.frequencyTable.data.length} frequency groups`); return this.frequencyTable; } catch (error) { console.error('🎯 FrequencyTableLoader: Error loading frequency tables:', error); throw error; } } /** * Get frequencies to detect from loaded table */ public static getFrequenciesToDetect(tableCodes: TableCodes | null): number[] { if (!tableCodes) return []; const frequencies: number[] = []; // Add low frequencies for (const low of tableCodes.data) { frequencies.push(low.lowkey); for (const high of low.pairs) { frequencies.push(high.highkey); } } // Add bridge frequencies (matching SDK 21 exactly) const bridgeFrequencies = [14987, 15978, 16968, 17959, 18992, 19983, 20973]; frequencies.push(...bridgeFrequencies); // Remove duplicates and sort return [...new Set(frequencies)].sort((a, b) => a - b); } /** * Clear cached frequency table */ public static clearCache(): void { this.frequencyTable = null; } }