/* eslint-env node */

const COLORS = ["#ff1f5a","#ffd615","#f9ff21","#1e2a78", "#43ab92", "#f75f00", "#c93838", "#512c62", "#f6f078", "#01d28e", "#434982", "#730068"];

var currentColor = 0;

function createRandomColorChannel() {
  let value = Math.floor(Math.random() * 256);
  value = Math.floor((value + 255) / 2);
  return value;
}

function componentToHex(c) {
  var hex = Number(c).toString(16);
  if (hex.length < 2) {
    hex = "0" + hex;
  }
  return hex;
}

function rgbToHex(r, g, b) {
  return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}

class Colors {

  static getNextColor() {
    if(currentColor === COLORS.length) {
      currentColor = 0;
    }
    return COLORS[currentColor++];
  }

  static createRandomColor() {
    let r = createRandomColorChannel(),
      g = createRandomColorChannel(),
      b = createRandomColorChannel();
    return rgbToHex(r, g, b);
  }

}

module.exports = Colors;