import { useTheme } from "./useTheme";
import { TinyColor } from "@ctrl/tinycolor";
import { getNestedObject } from "../theme/utils/type-helpers";

/**
 * Hook to get the most accessible foreground color value based on a provided background color
 * @param backgroundColor The color value of the background color
 * @param foregroundChoices The foreground color values to choose from. It expects an object which a 'light' key (for the lighter color) and a 'dark' key (for the darker color)
 * @returns The most accessible foreground color value
 */
export const useAccessibleColor = (backgroundColor, foregroundChoices = {
  light: "white",
  dark: "black"
}) => {
  // Get the current theme
  const {
    theme
  } = useTheme();

  // Get the final background color value
  let finalBackgroundColor;
  if (backgroundColor.includes("#")) {
    finalBackgroundColor = backgroundColor;
  } else if (backgroundColor.includes(".")) {
    finalBackgroundColor = getNestedObject(theme, ["palette", backgroundColor.split(".")[0], backgroundColor.split(".")[1]]);
  } else {
    finalBackgroundColor = theme.palette[backgroundColor];
  }

  // Determine if the background color is light or dark
  const isColorLight = new TinyColor(finalBackgroundColor).getBrightness() > 150;

  // Return the most accessible foreground color value
  if (isColorLight) {
    // If the background color is light, return the dark foreground color
    return foregroundChoices.dark;
  } else {
    // If the background color is dark, return the light foreground color
    return foregroundChoices.light;
  }
};
//# sourceMappingURL=useAccessibleColor.js.map