"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useAccessibleColor = void 0;
var _useTheme = require("./useTheme");
var _tinycolor = require("@ctrl/tinycolor");
var _typeHelpers = require("../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
 */
const useAccessibleColor = (backgroundColor, foregroundChoices = {
  light: "white",
  dark: "black"
}) => {
  // Get the current theme
  const {
    theme
  } = (0, _useTheme.useTheme)();

  // Get the final background color value
  let finalBackgroundColor;
  if (backgroundColor.includes("#")) {
    finalBackgroundColor = backgroundColor;
  } else if (backgroundColor.includes(".")) {
    finalBackgroundColor = (0, _typeHelpers.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.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;
  }
};
exports.useAccessibleColor = useAccessibleColor;
//# sourceMappingURL=useAccessibleColor.js.map