"use strict";

exports.__esModule = true;
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

require("./style.css");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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["default"].createElement("div", {
    className: "countdown-timer"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "box-circle"
  }, /*#__PURE__*/_react["default"].createElement("svg", null, /*#__PURE__*/_react["default"].createElement("circle", {
    id: "circle-progress",
    cx: "60",
    cy: "60"
  }), /*#__PURE__*/_react["default"].createElement("circle", {
    cx: "60",
    cy: "60"
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "number"
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
    id: "base-timer-label"
  }, formatTime(timeLeft)), /*#__PURE__*/_react["default"].createElement("div", null, "sec"))));
};

var _default = (0, _react.memo)(CountDownTimer);

exports["default"] = _default;
module.exports = exports.default;