(function () {
    const key = 'ppphp.documentation.theme';

    function apply(theme) {
        document.documentElement.dataset.theme = theme;
        localStorage.setItem(key, theme);
    }

    window.PPphpDocsTheme = {
        toggle() {
            const current = document.documentElement.dataset.theme || 'light';
            apply(current === 'dark' ? 'light' : 'dark');
        },
        apply
    };

    apply(localStorage.getItem(key) || 'light');
})();