"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/hooks/useTheme.ts
var useTheme_exports = {};
__export(useTheme_exports, {
  useTheme: () => useTheme
});
module.exports = __toCommonJS(useTheme_exports);
var import_react = require("react");

// src/store/themeStore.ts
var import_zustand = require("zustand");
var import_middleware = require("zustand/middleware");
var DARK_THEME_MAP = {
  "base-light": "base-dark",
  "enem-parana-light": "enem-parana-dark",
  "enem-paraiba-light": "enem-paraiba-dark",
  "analytica-light": "analytica-dark"
};
var resolveDarkTheme = (originalTheme) => {
  if (!originalTheme) return "base-dark";
  return DARK_THEME_MAP[originalTheme] ?? "base-dark";
};
var applyThemeToDOM = (mode) => {
  const htmlElement = document.documentElement;
  const originalTheme = htmlElement.dataset.originalTheme;
  if (mode === "dark") {
    htmlElement.dataset.theme = resolveDarkTheme(originalTheme);
    return true;
  } else if (mode === "light") {
    if (originalTheme) {
      htmlElement.dataset.theme = originalTheme;
    }
    return false;
  } else if (mode === "system") {
    const isSystemDark = window.matchMedia(
      "(prefers-color-scheme: dark)"
    ).matches;
    if (isSystemDark) {
      htmlElement.dataset.theme = resolveDarkTheme(originalTheme);
      return true;
    } else if (originalTheme) {
      htmlElement.dataset.theme = originalTheme;
      return false;
    }
  }
  return false;
};
var saveOriginalTheme = () => {
  const htmlElement = document.documentElement;
  const currentTheme = htmlElement.dataset.theme || document.querySelector('meta[name="theme"]')?.getAttribute("content");
  if (currentTheme && !htmlElement.dataset.originalTheme) {
    htmlElement.dataset.originalTheme = currentTheme;
  }
};
var useThemeStore = (0, import_zustand.create)()(
  (0, import_middleware.devtools)(
    (0, import_middleware.persist)(
      (set, get) => ({
        // Initial state
        themeMode: "system",
        isDark: false,
        // Actions
        applyTheme: (mode) => {
          const isDark = applyThemeToDOM(mode);
          set({ isDark });
        },
        toggleTheme: () => {
          const { themeMode, applyTheme } = get();
          let newMode;
          if (themeMode === "light") {
            newMode = "dark";
          } else if (themeMode === "dark") {
            newMode = "light";
          } else {
            newMode = "dark";
          }
          set({ themeMode: newMode });
          applyTheme(newMode);
        },
        setTheme: (mode) => {
          const { applyTheme } = get();
          set({ themeMode: mode });
          applyTheme(mode);
        },
        setWhiteLabelTheme: (theme) => {
          const htmlElement = document.documentElement;
          if (theme) {
            htmlElement.dataset.originalTheme = theme;
            const { themeMode, applyTheme } = get();
            if (themeMode === "light" || themeMode === "system") {
              htmlElement.dataset.theme = theme;
            }
            applyTheme(themeMode);
          }
        },
        clearWhiteLabelTheme: () => {
          const htmlElement = document.documentElement;
          delete htmlElement.dataset.originalTheme;
          delete htmlElement.dataset.theme;
          saveOriginalTheme();
          const { themeMode, applyTheme } = get();
          applyTheme(themeMode);
        },
        initializeTheme: () => {
          const { themeMode, applyTheme } = get();
          saveOriginalTheme();
          applyTheme(themeMode);
        },
        handleSystemThemeChange: () => {
          const { themeMode, applyTheme } = get();
          if (themeMode === "system") {
            applyTheme("system");
          }
        }
      }),
      {
        name: "theme-store",
        // Nome da chave no localStorage
        partialize: (state) => ({
          themeMode: state.themeMode
        })
        // Só persiste o themeMode, não o isDark
      }
    ),
    {
      name: "theme-store"
    }
  )
);

// src/hooks/useTheme.ts
var useTheme = () => {
  const {
    themeMode,
    isDark,
    toggleTheme,
    setTheme,
    initializeTheme,
    handleSystemThemeChange
  } = useThemeStore();
  const branding = (0, import_react.useMemo)(() => {
    if (typeof document === "undefined") {
      return {
        theme: null,
        favicon: null,
        icon: null,
        mainLogo: null,
        internalLogo: null,
        loginImage: null
      };
    }
    return {
      theme: document.querySelector('meta[name="theme"]')?.getAttribute("content") ?? null,
      favicon: document.querySelector('link[rel="icon"]')?.getAttribute("href") ?? null,
      icon: document.querySelector('link[rel="apple-touch-icon"]')?.getAttribute("href") ?? null,
      mainLogo: document.querySelector('meta[name="main-logo"]')?.getAttribute("content") ?? null,
      internalLogo: document.querySelector('meta[name="internal-logo"]')?.getAttribute("content") ?? null,
      loginImage: document.querySelector('meta[name="login-image"]')?.getAttribute("content") ?? null
    };
  }, []);
  (0, import_react.useEffect)(() => {
    initializeTheme();
    const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
    mediaQuery.addEventListener("change", handleSystemThemeChange);
    return () => {
      mediaQuery.removeEventListener("change", handleSystemThemeChange);
    };
  }, [initializeTheme, handleSystemThemeChange]);
  return {
    themeMode,
    isDark,
    toggleTheme,
    setTheme,
    branding
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useTheme
});
//# sourceMappingURL=index.js.map