{"size": 4241, "ext": "js", "max_stars_repo_path": "assets/s3/js/index.js", "max_stars_repo_name": "SealBuzz/sealbuzz", "max_stars_repo_stars_event_min_datetime": "2021-05-13T16:42:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-20T02:16:07.000Z", "max_issues_repo_path": "assets/s3/js/index.js", "max_issues_repo_name": "SealBuzz/sealbuzz", "max_issues_repo_issues_event_min_datetime": "2021-05-04T23:48:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T11:18:15.000Z", "max_forks_repo_path": "assets/s3/js/index.js", "max_forks_repo_name": "beekeeper-cli/beekeeper", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 8, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 25.703030303, "max_line_length": 185, "alphanum_fraction": 0.6599858524}
import polling from '../polling.js';
const FULL_DASH_ARRAY = 283;
const WARNING_THRESHOLD = 10;
const ALERT_THRESHOLD = 5;
const RATE = polling.rate;

(() => {
  document.querySelector("#display-name").innerText = polling.displayName;
})();

const COLOR_CODES = {
  info: {
    color: "green"
  },
  warning: {
    color: "orange",
    threshold: WARNING_THRESHOLD
  },
  alert: {
    color: "red",
    threshold: ALERT_THRESHOLD
  }
};

const waitLine = parseInt(window.location.search.split('=')[1], 10) || 1;
const numOfMinutes = Math.ceil(waitLine / RATE);
let currentDate = new Date();
let waitDisplay = document.querySelector('#wait-display');
let displayTime = window.localStorage.getItem('displayTime');

currentDate.setMinutes(currentDate.getMinutes() + numOfMinutes);

if (!displayTime) {
  displayTime = currentDate;

  window.localStorage.setItem('displayTime', displayTime);

} else if (new Date() > new Date(displayTime)) {
  window.localStorage.removeItem('displayTime');
  currentDate = new Date();
  currentDate.setMinutes(currentDate.getMinutes() + 1);
  window.localStorage.setItem('displayTime', currentDate);
}


waitDisplay.textContent = `You will be redirected by approximately: ${new Date(window.localStorage.getItem('displayTime')).toLocaleTimeString([], {hour: 'numeric', minute:'numeric'})}`;

const TIME_LIMIT = 20;
let timePassed;
let timeLeft;
let timerInterval;
let remainingPathColor;

const timer = document.getElementById("timer");

const initializeTimer = () => {
  timePassed = 0;
  timeLeft = TIME_LIMIT;
  timerInterval = null;
  remainingPathColor = COLOR_CODES.info.color;

  timer.innerHTML = `
  <div class="base-timer">
    <svg class="base-timer__svg" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
      <g class="base-timer__circle">
        <circle class="base-timer__path-elapsed" cx="50" cy="50" r="45"></circle>
        <path
          id="base-timer-path-remaining"
          stroke-dasharray="283"
          class="base-timer__path-remaining ${remainingPathColor}"
          d="
            M 50, 50
            m -45, 0
            a 45,45 0 1,0 90,0
            a 45,45 0 1,0 -90,0
          "
        ></path>
      </g>
    </svg>
    <span id="base-timer-label" class="base-timer__label">${formatTime(
      timeLeft
    )}</span>
  </div>
  `;
}

initializeTimer();
startTimer();

const onTimesUp = async () => {
  const waitMessage = document.querySelector("#wait-message");
  let forward = await polling.poll();


  if (!forward) {
    waitMessage.style.display = "block";
  }

  clearInterval(timerInterval);
  setTimeout(() => {
    waitMessage.style.display = "none";
    initializeTimer();
    startTimer();
  }, 3000);
}   

function startTimer() {
  timerInterval = setInterval(() => {
    timePassed = timePassed += 1;
    timeLeft = TIME_LIMIT - timePassed;
    document.getElementById("base-timer-label").innerHTML = formatTime(
      timeLeft
    );
    setCircleDasharray();
    setRemainingPathColor(timeLeft);

    if (timeLeft === 0) {
      onTimesUp();
    }
  }, 1000);
}

function formatTime(time) {
  const minutes = Math.floor(time / 60);
  let seconds = time % 60;

  if (seconds < 10) {
    seconds = `0${seconds}`;
  }

  return `${minutes}:${seconds}`;
}

function setRemainingPathColor(timeLeft) {
  const { alert, warning, info } = COLOR_CODES;
  if (timeLeft <= alert.threshold) {
    document
      .getElementById("base-timer-path-remaining")
      .classList.remove(warning.color);
    document
      .getElementById("base-timer-path-remaining")
      .classList.add(alert.color);
  } else if (timeLeft <= warning.threshold) {
    document
      .getElementById("base-timer-path-remaining")
      .classList.remove(info.color);
    document
      .getElementById("base-timer-path-remaining")
      .classList.add(warning.color);
  }
}

function calculateTimeFraction() {
  const rawTimeFraction = timeLeft / TIME_LIMIT;
  return rawTimeFraction - (1 / TIME_LIMIT) * (1 - rawTimeFraction);
}

function setCircleDasharray() {
  const circleDasharray = `${(
    calculateTimeFraction() * FULL_DASH_ARRAY
  ).toFixed(0)} 283`;
  document
    .getElementById("base-timer-path-remaining")
    .setAttribute("stroke-dasharray", circleDasharray);
}