import Color from 'color';
var RGBA_PATTERN = /^rgba/i;
var RGBA_TRANSPARENT = 'rgba(0,0,0,0)';
var ColorMaping = {
  transparent: RGBA_TRANSPARENT,
  inherit: ''
};
export function isTransparent(source) {
  if (!source) {
    return true;
  }
  var hex = toCSSColor(source);
  return !hex || hex === RGBA_TRANSPARENT;
}
export function toCSSColor(source) {
  if (!source) {
    return '';
  }
  if (source in ColorMaping) {
    return ColorMaping[source];
  }
  if (source && RGBA_PATTERN.test(source)) {
    var color = Color(source);
    if (color.valpha === 0) {
      ColorMaping[source] = RGBA_TRANSPARENT;
      return RGBA_TRANSPARENT;
    }
    var rgba = color.toString();
    ColorMaping[source] = rgba.toString();
    return rgba;
  }
  var hex = '';
  try {
    hex = Color(source).hex().toLowerCase();
    ColorMaping[source] = hex;
  } catch (ex) {
    console.warn('unable to convert to hex', source, ex);
    ColorMaping[source] = '';
  }
  return hex;
}
export default toCSSColor;