import { createContext, useContext } from "react";
import { useBraidTheme } from "../../../../side-effects/lib/components/BraidProvider/BraidProvider.mjs";
import { mapColorModeValue } from "../../css/atoms/sprinkles.css.mjs";
const backgroundContext = createContext({
  lightMode: "body",
  darkMode: "bodyDark"
});
const BackgroundProvider = backgroundContext.Provider;
const useBackground = () => useContext(backgroundContext);
const useBackgroundLightness = (backgroundOverride) => {
  const backgroundFromContext = useBackground();
  const background = backgroundOverride || backgroundFromContext;
  const { backgroundLightness } = useBraidTheme();
  const lightnessMap = {
    ...backgroundLightness,
    customDark: "dark",
    customLight: "light"
  };
  return {
    lightMode: lightnessMap[background.lightMode],
    darkMode: lightnessMap[background.darkMode]
  };
};
const useColorContrast = () => {
  const background = useBackground();
  const backgroundLightness = useBackgroundLightness();
  return (map) => mapColorModeValue(
    backgroundLightness,
    (lightness, mode) => typeof map === "function" ? map(lightness, background[mode]) : map[lightness]
  );
};
export {
  BackgroundProvider,
  useBackground,
  useBackgroundLightness,
  useColorContrast
};
