export class ThemeToggler {
    constructor() {
    }
    static toggle() {
        const newTheme = ThemeToggler.getCurrentTheme() === ThemeToggler.DARK_THEME
            ? ThemeToggler.LIGHT_THEME
            : ThemeToggler.DARK_THEME;
        ThemeToggler.setTheme(newTheme);
    }
    static setTheme(theme) {
        ThemeToggler.htmlElement.dataset[ThemeToggler.THEME_ATTRIBUTE] = theme;
        localStorage.setItem(ThemeToggler.STORAGE_KEY, theme);
    }
    static getCurrentTheme() {
        return (ThemeToggler.htmlElement.dataset[ThemeToggler.THEME_ATTRIBUTE] ||
            localStorage.getItem(ThemeToggler.STORAGE_KEY) ||
            ThemeToggler.LIGHT_THEME);
    }
    static syncToggleState(toggle) {
        const currentTheme = ThemeToggler.getCurrentTheme();
        toggle.checked = currentTheme === ThemeToggler.DARK_THEME;
    }
    static initializeToggleSwitch(toggleId = "themeToggle") {
        let toggle = document.getElementById(toggleId);
        if (!toggle) {
            toggle = document.querySelector("[data-theme-toggle]");
        }
        if (!toggle) {
            return;
        }
        ThemeToggler.syncToggleState(toggle);
        toggle.addEventListener("change", () => {
            ThemeToggler.toggle();
        });
    }
    static registerOnLoad(toggleId = "themeToggle") {
        window.addEventListener("load", () => {
            ThemeToggler.initializeToggleSwitch(toggleId);
        });
    }
}
ThemeToggler.THEME_ATTRIBUTE = "theme";
ThemeToggler.DARK_THEME = "dark";
ThemeToggler.LIGHT_THEME = "light";
ThemeToggler.STORAGE_KEY = "preferredTheme";
ThemeToggler.htmlElement = document.documentElement;
//# sourceMappingURL=ThemeToggler.js.map