const points = require("../assets/data/points");
import getHex from "./getHex";

const getRandomPoint = () => {
  // Generate a point number between 0 and 13
  let meridianIndex = randomIntFromInterval(0, points.length - 1);

  let meridianObj = points[meridianIndex];
  let start = meridianObj.interval[0];
  let end = meridianObj.interval[1];

  // Generate a random point based on the interval
  const meridian = meridianObj.meridian;
  const pointNumber = randomIntFromInterval(start, end);
  const colorName =JSON.parse(`"${meridianObj.color}"`);
  const colorHex = getHex(colorName);

  const point = { meridian, pointNumber, colorName, colorHex };
  // console.log(meridian, pointNumber, colorName, colorHex );

  return point;
};

const randomIntFromInterval = (min, max) => {
  // min and max included
  return Math.floor(Math.random() * (max - min + 1) + min);
}

export default getRandomPoint;
