import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import "core-js/modules/web.timers.js";
import { useEffect, useRef, useState } from 'react';
import './index.css';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var NotificationToast = function NotificationToast(_ref) {
  var onClose = _ref.onClose,
    data = _ref.data;
  var _useState = useState(6),
    _useState2 = _slicedToArray(_useState, 2),
    time = _useState2[0],
    setTime = _useState2[1];
  var timer = useRef();
  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__*/_jsxs("div", {
    className: "frc-notification-toast",
    children: [/*#__PURE__*/_jsx("span", {
      children: data
    }), /*#__PURE__*/_jsx("span", {
      className: "frc-notification-toast-countdown",
      children: "(".concat(time, "s)")
    })]
  });
};
export default NotificationToast;