export interface AppSettings { theme: 'light' | 'dark' | 'system'; audioBufferSize: number; sampleRate: number; autoSave: boolean; autoSaveInterval: number; // in seconds snapToGrid: boolean; gridResolution: number; // in ms waveformColor: string; showSpectrogram: boolean; maxHistorySize: number; } const DEFAULT_SETTINGS: AppSettings = { theme: 'system', audioBufferSize: 4096, sampleRate: 44100, autoSave: true, autoSaveInterval: 60, snapToGrid: false, gridResolution: 100, waveformColor: '#3b82f6', showSpectrogram: false, maxHistorySize: 50, }; const SETTINGS_KEY = 'audio-ui-settings'; export function getSettings(): AppSettings { if (typeof window === 'undefined') return DEFAULT_SETTINGS; try { const stored = localStorage.getItem(SETTINGS_KEY); if (!stored) return DEFAULT_SETTINGS; const parsed = JSON.parse(stored); return { ...DEFAULT_SETTINGS, ...parsed }; } catch (error) { console.error('Failed to load settings:', error); return DEFAULT_SETTINGS; } } export function saveSettings(settings: Partial): void { if (typeof window === 'undefined') return; try { const current = getSettings(); const updated = { ...current, ...settings }; localStorage.setItem(SETTINGS_KEY, JSON.stringify(updated)); // Dispatch custom event for settings updates window.dispatchEvent( new CustomEvent('settingsUpdated', { detail: updated }) ); } catch (error) { console.error('Failed to save settings:', error); } } export function resetSettings(): void { if (typeof window === 'undefined') return; try { localStorage.removeItem(SETTINGS_KEY); window.dispatchEvent( new CustomEvent('settingsUpdated', { detail: DEFAULT_SETTINGS }) ); } catch (error) { console.error('Failed to reset settings:', error); } }