/* ============================================
THEME MANAGEMENT
Dark/Light theme toggle with persistence
============================================ */
function initTheme() {
// Check saved preference or system preference
const saved = Storage.get('theme');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const theme = saved || (prefersDark ? 'dark' : 'light');
setTheme(theme);
// Listen for system theme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
if (!Storage.get('theme')) {
setTheme(e.matches ? 'dark' : 'light');
}
});
}
function setTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
updateThemeToggleIcon(theme);
}
function toggleTheme() {
const current = document.documentElement.getAttribute('data-theme') || 'dark';
const next = current === 'dark' ? 'light' : 'dark';
setTheme(next);
Storage.set('theme', next);
}
function updateThemeToggleIcon(theme) {
const toggle = DOM.themeToggle;
if (!toggle) return;
const sunIcon = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>';
const moonIcon = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>';
toggle.innerHTML = theme === 'dark' ? sunIcon : moonIcon;
toggle.setAttribute('aria-label', `Switch to ${theme === 'dark' ? 'light' : 'dark'} theme`);
toggle.setAttribute('title', `Switch to ${theme === 'dark' ? 'light' : 'dark'} theme`);
}
/* ============================================
SEQUENCE FORMAT TOGGLE
Switch between numeric (001) and named (EXHAUSTED) display
============================================ */
function toggleSequenceFormat() {
console.log('[Format] Toggle clicked, current:', AppState.sequenceFormat);
// Toggle between numeric and named
const current = AppState.sequenceFormat;
const next = current === 'numeric' ? 'named' : 'numeric';
AppState.sequenceFormat = next;
console.log('[Format] Switched to:', next);
// Update button visual state
updateFormatToggleIcon(next);
// Re-render all error cards to update sequence display
renderResults();
// Show toast notification
const message = next === 'named'
? 'Showing sequence names (e.g., EXHAUSTED)'
: 'Showing sequence numbers (e.g., 026)';
showToast('Format Changed', message, 'info');
}
function updateFormatToggleIcon(format) {
const toggle = DOM.formatToggle;
if (!toggle) return;
// Update button content based on format
if (format === 'numeric') {
toggle.textContent = '001';
toggle.setAttribute('title', 'Switch to named sequences (e.g., EXHAUSTED)');
} else {
toggle.textContent = 'ABC';
toggle.setAttribute('title', 'Switch to numeric sequences (e.g., 001)');
}
console.log('[Format] Updated button to:', format, toggle.textContent);
}