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/theming/useTheme.tsx
var useTheme_exports = {};
__export(useTheme_exports, {
  ThemeContext: () => ThemeContext,
  ThemeProvider: () => ThemeProvider,
  ThemeUtil: () => ThemeUtil,
  useTheme: () => useTheme
});
module.exports = __toCommonJS(useTheme_exports);
var import_react2 = require("react");
var import_react3 = require("react");

// src/util/noop.ts
var noop = () => void 0;

// src/hooks/useLocalStorage.ts
var import_react = require("react");

// src/util/storage.ts
var StorageService = class {
  // this seems to be a bug in eslint as 'paramter-properties' is a special syntax of typescript
  constructor(storage) {
    this.storage = storage;
  }
  get(key) {
    const value = this.storage.getItem(key);
    if (value === null) {
      return null;
    }
    return JSON.parse(value);
  }
  set(key, value) {
    this.storage.setItem(key, JSON.stringify(value));
  }
  delete(key) {
    this.storage.removeItem(key);
  }
  deleteAll() {
    this.storage.clear();
  }
};
var LocalStorageService = class extends StorageService {
  constructor() {
    super(window.localStorage);
  }
};

// src/util/resolveSetState.ts
function resolveSetState(action, prev) {
  return typeof action === "function" ? action(prev) : action;
}

// src/hooks/useLocalStorage.ts
var useLocalStorage = (key, initValue) => {
  const get = (0, import_react.useCallback)(() => {
    if (typeof window === "undefined") {
      return initValue;
    }
    const storageService = new LocalStorageService();
    const value = storageService.get(key);
    return value || initValue;
  }, [initValue, key]);
  const [storedValue, setStoredValue] = (0, import_react.useState)(get);
  const setValue = (0, import_react.useCallback)((action) => {
    const newValue = resolveSetState(action, storedValue);
    const storageService = new LocalStorageService();
    storageService.set(key, newValue);
    setStoredValue(newValue);
  }, [storedValue, setStoredValue, key]);
  (0, import_react.useEffect)(() => {
    setStoredValue(get());
  }, []);
  return [storedValue, setValue];
};

// src/theming/useTheme.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var themes = ["light", "dark", "system"];
var defaultThemeTypeTranslation = {
  en: {
    dark: "Dark",
    light: "Light",
    system: "System",
    theme: {
      one: "Theme",
      other: "Themes"
    }
  },
  de: {
    dark: "Dunkel",
    light: "Hell",
    system: "System",
    theme: {
      one: "Farbschema",
      other: "Farbschemas"
    }
  }
};
var ThemeUtil = {
  themes,
  translation: defaultThemeTypeTranslation
};
var ThemeContext = (0, import_react3.createContext)({
  theme: "light",
  setTheme: noop
});
var ThemeProvider = ({ children, initialTheme = "system" }) => {
  const [storedTheme, setStoredTheme] = useLocalStorage("theme", initialTheme);
  const [userTheme, setUserTheme] = (0, import_react3.useState)();
  (0, import_react3.useEffect)(() => {
    if (storedTheme !== initialTheme) {
      console.warn("ThemeProvider initial state changed: Prefer using useTheme's setTheme instead");
      setStoredTheme(initialTheme);
    }
  }, [initialTheme]);
  const usedTheme = (0, import_react2.useMemo)(() => storedTheme !== "system" ? storedTheme : userTheme, [storedTheme, userTheme]);
  (0, import_react3.useEffect)(() => {
    document.documentElement.setAttribute("data-theme", usedTheme);
  }, [usedTheme]);
  (0, import_react3.useEffect)(() => {
    const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
    setUserTheme(prefersDark ? "dark" : "light");
  }, []);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThemeContext.Provider, { value: { theme: storedTheme, setTheme: setStoredTheme }, children });
};
var useTheme = () => (0, import_react3.useContext)(ThemeContext);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ThemeContext,
  ThemeProvider,
  ThemeUtil,
  useTheme
});
//# sourceMappingURL=useTheme.js.map