package com.example.js;

public final class CommonJS {

    private CommonJS() {}

    /** Sets color-scheme on <html> from the saved choice, falling back to the OS
     *  preference (prefers-color-scheme) when no choice was saved, and
     *  returns "light"/"dark" so the button's initial icon can match. */
    public static final String INIT_THEME_JS = """
            const saved = localStorage.getItem('dialect-theme');
            const theme = saved
                || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
            document.documentElement.style.colorScheme = theme;
            return theme;
            """;

    public static final String TOGGLE_THEME_JS = """
            const next = document.documentElement.style.colorScheme === 'dark' ? 'light' : 'dark';
            document.documentElement.style.colorScheme = next;
            localStorage.setItem('dialect-theme', next);
            window.dispatchEvent(new CustomEvent('dialect-theme-change'));
            return next;
            """;
}
