/*!
 * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */

import { hexToRgb, isValidHexString, rgbComponentsToString } from "./hexToRgb.js";
const LUMINANCE_THRESHOLD = 128;
const LUMINANCE_EDGE_MIN = 108;
const LUMINANCE_EDGE_MAX = 142;
const BLACK_FONT_COLOR = "#000000";
const WHITE_FONT_COLOR = "#FFFFFF";
export const generateContrastColors = ({
  backgroundColor,
  backgroundContrastColor,
  odysseyDesignTokens
}) => {
  const rgbFromHex = isValidHexString(backgroundColor) ? hexToRgb(backgroundColor) : hexToRgb(odysseyDesignTokens.HueNeutralWhite);
  const {
    red,
    green,
    blue
  } = rgbFromHex;
  const luminance = 0.2126 * red + 0.7152 * green + 0.0722 * blue;
  const luminanceValueInEdgeRange = luminance > LUMINANCE_EDGE_MIN && luminance < LUMINANCE_EDGE_MAX;
  const isLight = luminance > LUMINANCE_THRESHOLD;
  const fontColor = backgroundContrastColor || (luminanceValueInEdgeRange ? BLACK_FONT_COLOR : isLight ? odysseyDesignTokens.TypographyColorBody : WHITE_FONT_COLOR);
  const calculatedFontColorInRgb = hexToRgb(fontColor);
  const lightFontColorInRgb = hexToRgb(WHITE_FONT_COLOR);
  const darkFontColorInRgb = hexToRgb(luminanceValueInEdgeRange ? BLACK_FONT_COLOR : odysseyDesignTokens.TypographyColorBody);
  const calculatedFontRgbComponentsString = rgbComponentsToString({
    red: calculatedFontColorInRgb?.red,
    green: calculatedFontColorInRgb?.green,
    blue: calculatedFontColorInRgb?.blue
  });
  const lightFontRgbComponentsString = rgbComponentsToString({
    red: lightFontColorInRgb?.red,
    green: lightFontColorInRgb?.green,
    blue: lightFontColorInRgb?.blue
  });
  const darkFontRgbComponentsString = rgbComponentsToString({
    red: darkFontColorInRgb?.red,
    green: darkFontColorInRgb?.green,
    blue: darkFontColorInRgb?.blue
  });
  const getHighlightColor = (luminanceValueInEdgeRange, isLight) => {
    if (luminanceValueInEdgeRange) {
      return isLight ? darkFontRgbComponentsString : lightFontRgbComponentsString;
    }
    return calculatedFontRgbComponentsString;
  };
  return {
    fontColor,
    focusRingColor: `rgba(${calculatedFontRgbComponentsString}, .8)`,
    itemDisabledFontColor: `rgba(${calculatedFontRgbComponentsString}, .4)`,
    itemHoverBackgroundColor: `rgba(${getHighlightColor(luminanceValueInEdgeRange, isLight)}, .1)`,
    itemSelectedBackgroundColor: `rgba(${getHighlightColor(luminanceValueInEdgeRange, isLight)}, .15)`
  };
};
//# sourceMappingURL=createContrastColors.js.map