import parseColor from 'color-parse'

export default (rgb) => {
  const parsed = parseColor(rgb)
  if (parsed.space !== 'rgb') {
    return null
  }
  const {
    values: [r, g, b],
    alpha,
  } = parsed

  return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255 * alpha + (1 - alpha) // * white (1)
}
