"use client";

// src/hooks/use-app-theme.ts
import { useCallback, useEffect, useState } from "react";

// src/theme/windows-contrast-theme.json
var windows_contrast_theme_default = {
  $comment: "In-app \u201CWindows (JSON)\u201D contrast mode. Edit hex or oklch() strings to match a Windows Contrast theme (Settings \u2192 Accessibility \u2192 Contrast themes) or an exported .theme file. Keys are Exxat semantic CSS variables on <html>. Light/dark follow the app\u2019s light/dark mode (next-themes).",
  windowsSettingsLabels: {
    Background: "Canvas \u2014 maps to --background, surfaces, sidebar base",
    Text: "Text \u2014 maps to --foreground and readable copy tokens",
    Hyperlink: "Hyperlinks \u2014 mapped to --primary / focus via --ring where useful",
    "Selected text": "Selected text \u2014 maps to --accent and --accent-foreground",
    "Button text": "Button text \u2014 maps to --primary / --primary-foreground pair",
    "Disabled text": "Disabled text \u2014 maps to --muted / --muted-foreground"
  },
  light: {
    "--hc-highlight": "#0000ff",
    "--hc-highlight-text": "#ffffff",
    "--background": "#ffffff",
    "--foreground": "#000000",
    "--card": "#ffffff",
    "--card-foreground": "#000000",
    "--popover": "#ffffff",
    "--popover-foreground": "#000000",
    "--primary": "#0000ff",
    "--primary-foreground": "#ffffff",
    "--secondary": "#ffffff",
    "--secondary-foreground": "#000000",
    "--muted": "#e8e8e8",
    "--muted-foreground": "#3b3b3b",
    "--accent": "#0000ff",
    "--accent-foreground": "#ffffff",
    "--destructive": "#b5200d",
    "--destructive-foreground": "#ffffff",
    "--border": "#000000",
    "--border-control": "#000000",
    "--border-control-3": "#000000",
    "--border-control-35": "#000000",
    "--control-border": "#000000",
    "--input": "#000000",
    "--input-background": "#ffffff",
    "--ring": "#0000ff",
    "--sidebar": "#ffffff",
    "--sidebar-foreground": "#000000",
    "--sidebar-primary": "#000000",
    "--sidebar-primary-foreground": "#ffffff",
    "--sidebar-accent": "#d9d9d9",
    "--sidebar-accent-foreground": "#000000",
    "--sidebar-border": "#000000",
    "--sidebar-ring": "#0000ff",
    "--sidebar-section-label-foreground": "#515151",
    "--brand-tint": "#f0f0f0",
    "--brand-tint-light": "#f7f7f7",
    "--brand-tint-subtle": "#fafafa",
    "--chart-1": "#000000",
    "--chart-2": "#3b3b3b",
    "--chart-3": "#6e6e6e",
    "--chart-4": "#a0a0a0",
    "--chart-5": "#d1d1d1",
    "--chip-1": "#000000",
    "--chip-2": "#000000",
    "--chip-3": "#000000",
    "--chip-4": "#000000",
    "--chip-5": "#000000",
    "--chip-destructive": "#b5200d",
    "--interactive-hover": "#e0e0e0",
    "--interactive-hover-foreground": "#000000",
    "--interactive-hover-subtle": "#ebebeb",
    "--interactive-hover-soft": "#ebebeb",
    "--interactive-hover-medium": "#d5d5d5",
    "--interactive-hover-strong": "#cccccc",
    "--interactive-hover-row": "#e0e0e0",
    "--overlay": "color-mix(in srgb, #000000 18%, transparent)",
    "--dt-row-bg": "#ffffff",
    "--dt-row-hover": "#ebebeb",
    "--dt-row-selected": "#0000ff",
    "--dt-row-selected-fg": "#ffffff",
    "--dt-header-bg": "#ffffff",
    "--dt-group-bg": "#ebebeb",
    "--dt-new-row-bg": "#ffffff",
    "--dt-new-row-border": "#000000",
    "--theme-color-chrome": "#ffffff"
  },
  dark: {
    "--hc-highlight": "#ffff00",
    "--hc-highlight-text": "#000000",
    "--background": "#000000",
    "--foreground": "#ffffff",
    "--card": "#000000",
    "--card-foreground": "#ffffff",
    "--popover": "#0a0a0a",
    "--popover-foreground": "#ffffff",
    "--primary": "#00ffff",
    "--primary-foreground": "#000000",
    "--secondary": "#000000",
    "--secondary-foreground": "#ffffff",
    "--muted": "#1a1a1a",
    "--muted-foreground": "#ffffff",
    "--accent": "#ffff00",
    "--accent-foreground": "#000000",
    "--destructive": "#ff8080",
    "--destructive-foreground": "#000000",
    "--border": "#ffffff",
    "--border-control": "#ffffff",
    "--border-control-3": "#ffffff",
    "--border-control-35": "#ffffff",
    "--control-border": "#ffffff",
    "--input": "#ffffff",
    "--input-background": "#000000",
    "--ring": "#ffff00",
    "--sidebar": "#000000",
    "--sidebar-foreground": "#ffffff",
    "--sidebar-primary": "#ffffff",
    "--sidebar-primary-foreground": "#000000",
    "--sidebar-accent": "#1a1a1a",
    "--sidebar-accent-foreground": "#ffffff",
    "--sidebar-border": "#ffffff",
    "--sidebar-ring": "#ffff00",
    "--sidebar-section-label-foreground": "#c8c8c8",
    "--brand-tint": "#1a1a1a",
    "--brand-tint-light": "#141414",
    "--brand-tint-subtle": "#101010",
    "--chart-1": "#ffffff",
    "--chart-2": "#c8c8c8",
    "--chart-3": "#8e8e8e",
    "--chart-4": "#5a5a5a",
    "--chart-5": "#2e2e2e",
    "--chip-1": "#ffffff",
    "--chip-2": "#ffffff",
    "--chip-3": "#ffffff",
    "--chip-4": "#ffffff",
    "--chip-5": "#ffffff",
    "--chip-destructive": "#ff8080",
    "--interactive-hover": "#262626",
    "--interactive-hover-foreground": "#ffffff",
    "--interactive-hover-subtle": "#1f1f1f",
    "--interactive-hover-soft": "#1f1f1f",
    "--interactive-hover-medium": "#2e2e2e",
    "--interactive-hover-strong": "#383838",
    "--interactive-hover-row": "#262626",
    "--overlay": "color-mix(in srgb, #ffffff 22%, transparent)",
    "--dt-row-bg": "#000000",
    "--dt-row-hover": "#1a1a1a",
    "--dt-row-selected": "#ffff00",
    "--dt-row-selected-fg": "#000000",
    "--dt-header-bg": "#000000",
    "--dt-group-bg": "#1a1a1a",
    "--dt-new-row-bg": "#000000",
    "--dt-new-row-border": "#ffffff",
    "--theme-color-chrome": "#000000"
  }
};

// src/theme/apply-windows-contrast-theme.ts
var file = windows_contrast_theme_default;
var WINDOWS_VAR_KEYS = /* @__PURE__ */ new Set([
  ...Object.keys(file.light),
  ...Object.keys(file.dark)
]);
function applyWindowsContrastTheme() {
  const el = document.documentElement;
  const isDark = el.classList.contains("dark");
  const map = isDark ? file.dark : file.light;
  for (const [prop, val] of Object.entries(map)) {
    el.style.setProperty(prop, val);
  }
}
function clearWindowsContrastTheme() {
  const el = document.documentElement;
  for (const key of WINDOWS_VAR_KEYS) {
    el.style.removeProperty(key);
  }
}

// src/hooks/use-app-theme.ts
var CONTRAST_PREFS = ["system", "normal", "high", "windows"];
var LEGACY_BRAND_KEY = "exxat-brand";
var CONTRAST_KEY = "exxat-contrast";
var TEXT_SIZE_KEY = "exxat-text-size";
var MQ = "(prefers-contrast: more)";
function getOsContrast() {
  if (typeof window === "undefined") return "normal";
  return window.matchMedia(MQ).matches ? "high" : "normal";
}
function resolveContrast(pref) {
  if (pref === "system") return getOsContrast();
  return pref;
}
function normalizeContrastPref(raw) {
  if (raw && CONTRAST_PREFS.includes(raw)) {
    return raw;
  }
  return "system";
}
function applyContrast(mode) {
  if (mode === "windows") {
    document.documentElement.setAttribute("data-contrast", "windows");
    applyWindowsContrastTheme();
    return;
  }
  clearWindowsContrastTheme();
  document.documentElement.setAttribute(
    "data-contrast",
    mode === "high" ? "high" : "off"
  );
}
function applyTextSize(pref) {
  const html = document.documentElement;
  if (pref === "default") {
    html.removeAttribute("data-text-size");
  } else {
    html.setAttribute("data-text-size", pref);
  }
}
function useAppTheme() {
  const [contrastPref, setContrastPrefState] = useState("system");
  const [resolvedContrast, setResolvedContrast] = useState("normal");
  const [textSizePref, setTextSizePrefState] = useState("default");
  const [mounted, setMounted] = useState(false);
  useEffect(() => {
    setMounted(true);
    try {
      localStorage.removeItem(LEGACY_BRAND_KEY);
    } catch {
    }
    const storedPref = normalizeContrastPref(localStorage.getItem(CONTRAST_KEY));
    const storedText = localStorage.getItem(TEXT_SIZE_KEY) ?? "default";
    setContrastPrefState(storedPref);
    setTextSizePrefState(storedText);
    const resolved = resolveContrast(storedPref);
    setResolvedContrast(resolved);
    applyContrast(resolved);
    applyTextSize(storedText);
  }, []);
  useEffect(() => {
    if (contrastPref !== "system") return;
    const mql = window.matchMedia(MQ);
    function onChange() {
      const resolved = getOsContrast();
      setResolvedContrast(resolved);
      applyContrast(resolved);
    }
    mql.addEventListener("change", onChange);
    return () => mql.removeEventListener("change", onChange);
  }, [contrastPref]);
  useEffect(() => {
    if (resolvedContrast !== "windows") return;
    applyWindowsContrastTheme();
    const html = document.documentElement;
    const obs = new MutationObserver(() => {
      applyWindowsContrastTheme();
    });
    obs.observe(html, { attributes: true, attributeFilter: ["class"] });
    return () => obs.disconnect();
  }, [resolvedContrast]);
  const setContrast = useCallback((pref) => {
    setContrastPrefState(pref);
    localStorage.setItem(CONTRAST_KEY, pref);
    const resolved = resolveContrast(pref);
    setResolvedContrast(resolved);
    applyContrast(resolved);
  }, []);
  const setTextSize = useCallback((pref) => {
    setTextSizePrefState(pref);
    localStorage.setItem(TEXT_SIZE_KEY, pref);
    applyTextSize(pref);
  }, []);
  return {
    /** The user's preference: "system" | "normal" | "high" | "windows" */
    contrastPref,
    /** The resolved contrast mode actually applied to the DOM. */
    contrast: resolvedContrast,
    /** Set the contrast preference. */
    setContrast,
    /** Text scale: "compact" | "default" | "large" */
    textSizePref,
    setTextSize,
    mounted
  };
}
export {
  useAppTheme
};
//# sourceMappingURL=use-app-theme.js.map