"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 _icon = require("../icon");
var _type = require("../icon/type");
var _jsxRuntime = require("react/jsx-runtime");
var NotificationToast = function NotificationToast(_ref) {
  var onClose = _ref.onClose,
    data = _ref.data,
    icon = _ref.icon,
    _ref$autoClose = _ref.autoClose,
    autoClose = _ref$autoClose === void 0 ? true : _ref$autoClose,
    iconColors = _ref.iconColors;
  var _useState = (0, _react.useState)(6),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    time = _useState2[0],
    setTime = _useState2[1];
  var timer = (0, _react.useRef)();
  var handleClose = function handleClose() {
    onClose && onClose();
  };
  (0, _react.useEffect)(function () {
    if (!autoClose) {
      return;
    }
    timer.current = setInterval(function () {
      setTime(function (prevState) {
        if (prevState === 1) {
          handleClose();
          clearInterval(timer.current);
        }
        return prevState - 1;
      });
    }, 1000);
    return function () {
      clearInterval(timer.current);
    };
  }, [autoClose]);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: "frc-notification-toast",
    children: [icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
      type: icon,
      size: 28,
      colors: iconColors,
      style: {
        marginRight: '8px'
      }
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      children: data
    }), autoClose && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: "frc-notification-toast-countdown",
      children: "(".concat(time, "s)")
    }), !autoClose && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: "fcr-notification-toast-close-icon",
      onClick: handleClose,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
        type: _type.FcrIconType.FCR_CLOSE,
        colors: {
          iconPrimary: 'var(--fcr_ui_scene_icontext1)'
        },
        size: 20
      })
    })]
  });
};
var _default = exports["default"] = NotificationToast;