import React, { memo } from 'react';
import "./style.css";

var CountDownTimer = function CountDownTimer(_ref) {
  var timeLimit = _ref.timeLimit;
  var TIME_LIMIT = timeLimit;
  var timePassed = 0;
  var timeLeft = TIME_LIMIT;
  var timerInterval = null;

  var onTimesUp = function onTimesUp() {
    clearInterval(timerInterval);
  };

  var circleProgress = 0;

  var startTimer = function startTimer() {
    timerInterval = setInterval(function () {
      timePassed = timePassed += 1;
      timeLeft = TIME_LIMIT - timePassed;
      document.getElementById('base-timer-label').innerHTML = formatTime(timeLeft);
      var circle = document.getElementById('circle-progress');
      var rCircle = 377;
      circleProgress = timeLeft * rCircle / TIME_LIMIT;
      circle.style.strokeDashoffset = circleProgress;

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

  startTimer();

  var formatTime = function formatTime(time) {
    // const minutes = Math.floor(time / 60);
    var seconds = time; // if (seconds < 10) {
    //   seconds = `0${seconds}`;
    // }

    return "" + seconds;
  };

  return /*#__PURE__*/React.createElement("div", {
    className: "countdown-timer"
  }, /*#__PURE__*/React.createElement("div", {
    className: "box-circle"
  }, /*#__PURE__*/React.createElement("svg", null, /*#__PURE__*/React.createElement("circle", {
    id: "circle-progress",
    cx: "60",
    cy: "60"
  }), /*#__PURE__*/React.createElement("circle", {
    cx: "60",
    cy: "60"
  }))), /*#__PURE__*/React.createElement("div", {
    className: "number"
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    id: "base-timer-label"
  }, formatTime(timeLeft)), /*#__PURE__*/React.createElement("div", null, "sec"))));
};

export default memo(CountDownTimer);