(function () {
    window.PPUI = {
        version: '1.0.0',
        theme: {
            key: 'ppphp.ppui.theme',
            apply(theme) {
                document.documentElement.dataset.theme = theme;
                localStorage.setItem(this.key, theme);
            },
            toggle() {
                const current = document.documentElement.dataset.theme || 'light';
                this.apply(current === 'dark' ? 'light' : 'dark');
            },
            init() {
                this.apply(localStorage.getItem(this.key) || 'light');
            }
        }
    };

    window.PPUI.theme.init();

    document.addEventListener('click', function (event) {
        const toggle = event.target.closest('[data-ppui-theme-toggle]');
        if (toggle) {
            event.preventDefault();
            window.PPUI.theme.toggle();
        }
    });
})();