function applyTheme(theme) {
    document.documentElement.setAttribute('data-theme', theme);
    document.documentElement.setAttribute('data-bs-theme', theme);
}

function setSiteTheme(theme) {
    localStorage.setItem('theme', theme);
    applyTheme(theme);
    document.querySelectorAll('[data-theme-option]').forEach((btn) => {
        btn.classList.toggle('active', btn.getAttribute('data-theme-option') === theme);
    });
}

document.addEventListener('DOMContentLoaded', () => {
    const currentTheme = localStorage.getItem('theme') || 'dark';
    document.querySelectorAll('[data-theme-option]').forEach((btn) => {
        btn.classList.toggle('active', btn.getAttribute('data-theme-option') === currentTheme);
        btn.addEventListener('click', () => setSiteTheme(btn.getAttribute('data-theme-option')));
    });
});
