"use strict";

require("core-js/modules/es.object.define-property.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
require("core-js/modules/web.timers.js");
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
require("./index.css");
var _jsxRuntime = require("react/jsx-runtime");
var NotificationToast = function NotificationToast(_ref) {
  var onClose = _ref.onClose,
    data = _ref.data;
  var _useState = (0, _react.useState)(6),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    time = _useState2[0],
    setTime = _useState2[1];
  var timer = (0, _react.useRef)();
  (0, _react.useEffect)(function () {
    timer.current = setInterval(function () {
      setTime(function (prevState) {
        if (prevState === 1) {
          onClose && onClose();
          clearInterval(timer.current);
        }
        return prevState - 1;
      });
    }, 1000);
    return function () {
      clearInterval(timer.current);
    };
  }, []);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: "frc-notification-toast",
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      children: data
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: "frc-notification-toast-countdown",
      children: "(".concat(time, "s)")
    })]
  });
};
var _default = exports["default"] = NotificationToast;