import {writable} from "svelte/store";
import {browser} from "$app/environment";

export const theme = writable(browser && localStorage.getItem("theme") || "light");
theme.subscribe((value: string) => {
    if (browser) {
        if (value === "dark") {
            localStorage.setItem("theme", "dark");
            document.documentElement.classList.add("dark");
        } else {
            localStorage.setItem("theme", "light");
            document.documentElement.classList.remove("dark");
        }
    }
});