export type ThemeType = "light" | "dark" | "system";

export function getThemeType(): ThemeType {
  let mode = localStorage.getItem("theme")
  const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
  if (mode === "system") {
    if (prefersDark) return "dark"
    if (!prefersDark) return "light"
  }
  return mode !== "light" ? "dark" : "light"
}

export function setThemeType(theme: ThemeType) {
  localStorage.setItem("theme", theme);
}

export function getThemeMode(): ThemeType {
  let mode = localStorage.getItem("theme")
  const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
  if (mode === "system") {
    if (prefersDark) return "dark"
    if (!prefersDark) return "light"
  }
  return mode !== "light" ? "dark" : "light"
}