const LIGHT = "latte";
const DARK = "macchiato";

export function getSystemTheme(): string {
    return window.matchMedia("(prefers-color-scheme: dark)").matches
        ? DARK
        : LIGHT;
}

export function getStoredTheme(): string | null {
    return localStorage.getItem("theme");
}

export function getInitialTheme(): string {
    return getStoredTheme() || getSystemTheme();
}

export function applyTheme(theme: string): void {
    const root = document.documentElement;

    root.classList.remove(LIGHT, DARK);

    root.classList.add(theme);

    localStorage.setItem("theme", theme);
}

export function toggleTheme(current: string): string {
    return current === DARK ? LIGHT : DARK;
}
