// script.js
const checkbox = document.getElementById('dark_mode');
const documentElement = document.documentElement;
let switchDisabled = false;

document.addEventListener('DOMContentLoaded', () => {
    const savedTheme = localStorage.getItem('theme');
    if (savedTheme === 'dark-mode') {
        document.documentElement.classList.add('dark-mode');
        localStorage.setItem('theme', 'dark-mode');
        checkbox.checked = true;
    } else {
        document.documentElement.classList.remove('dark-mode');
        localStorage.setItem('theme', 'light');
        checkbox.checked = false;
    }
});


document.addEventListener('change', () => {
    if (switchDisabled) {
        // If switch is disabled, revert the checkbox state
        checkbox.checked = !checkbox.checked;
        return;
    }

    if (checkbox.checked) {
        document.documentElement.classList.add('dark-mode');
        localStorage.setItem('theme', 'dark-mode');
    } else {
        document.documentElement.classList.remove('dark-mode');
        localStorage.setItem('theme', 'light');
    }

    // Disable toggle for 1 second
            switchDisabled = false;
            checkbox.disabled = true; // Visually disable the button

            setTimeout(() => {
                switchDisabled = false;
                checkbox.disabled = false; // Re-enable the button
            }, 500); // 1000 milliseconds = 1 second
});
    


