import { assert, warn } from '@ember/debug';
import { hexToRgb } from '../../helpers/hex-to-rgb.js';
import { isColorDark } from '../../helpers/is-color-dark.js';
import { isValidHex } from '../../helpers/is-valid-hex.js';
import { euiPaletteColorBlindBehindText } from '../color/eui_palettes.js';

const baseClass = 'euiAvatar';
const VIS_COLORS = euiPaletteColorBlindBehindText();
const sizeMapping = {
  s: `${baseClass}--s`,
  m: `${baseClass}--m`,
  l: `${baseClass}--l`,
  xl: `${baseClass}--xl`
};
const typeMapping = {
  space: `${baseClass}--space`,
  user: `${baseClass}--user`
};
function inlineStyles({
  name,
  color,
  imageUrl,
  initials
}) {
  let assignedColor = color;
  // let iconCustomColor = iconColor;
  let avatarStyle = {};
  checkValidInitials(initials);
  const isNamedColor = color === 'plain' || color === null;
  if (imageUrl) {
    avatarStyle.backgroundImage = `url(${imageUrl})`;
  } else {
    avatarStyle.backgroundImage = 'none';
  }
  if (!isNamedColor) {
    checkValidColor(color);
    name = name ? name : '';
    assignedColor = color || VIS_COLORS[Math.floor(name.length % VIS_COLORS.length)];
    const textColor = isColorDark(...hexToRgb(assignedColor || 'base')) ? '#FFFFFF' : '#000000';
    avatarStyle.backgroundColor = assignedColor;
    avatarStyle.color = textColor;
    return avatarStyle;
  }
  return avatarStyle;
}
const checkValidColor = color => {
  const validHex = color && isValidHex(color) || color === 'plain';
  if (color && !validHex) {
    assert('EuiAvatar needs to pass a valid color. This can either be a three or six character hex value', true);
  }
};
function checkValidInitials(initials) {
  // Must be a string of 1 or 2 characters
  if (initials && initials.length > 2) {
    warn('EuiAvatar only accepts a max of 2 characters for the initials as a string. It is displaying only the first 2 characters.', {
      id: 'EuiAvatar-initials-excedeed'
    });
  }
}
const mapping = {
  base: baseClass,
  properties: {
    size: sizeMapping,
    type: typeMapping
  },
  inlineStyles: inlineStyles
};

export { VIS_COLORS, baseClass, checkValidColor, mapping as default, inlineStyles, sizeMapping, typeMapping };
//# sourceMappingURL=eui-avatar.js.map
