"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.MessageTypes = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactDom = _interopRequireDefault(require("react-dom"));
var _reactI18next = require("react-i18next");
var _redError = _interopRequireDefault(require("../../../styles/assets/icon/redError.svg"));
var _blackInfo = _interopRequireDefault(require("../../../styles/assets/icon/blackInfo.svg"));
var _greenCheck = _interopRequireDefault(require("../../../styles/assets/icon/greenCheck.svg"));
var _MessageBar = _interopRequireDefault(require("./MessageBar"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
let MessageTypes;
exports.MessageTypes = MessageTypes;
(function (MessageTypes) {
  MessageTypes["Success"] = "Success";
  MessageTypes["Info"] = "Info";
  MessageTypes["Error"] = "Error";
})(MessageTypes || (exports.MessageTypes = MessageTypes = {}));
const MessageBottomComp = ({
  content,
  type,
  i18,
  isRichText,
  actions
}) => {
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  const getImgSrc = type => {
    let src = '';
    switch (type) {
      case MessageTypes.Error:
        src = _redError.default;
        break;
      case MessageTypes.Info:
        src = _blackInfo.default;
        break;
      case MessageTypes.Success:
        src = _greenCheck.default;
        break;
      default:
        src = _blackInfo.default;
        break;
    }
    return src;
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_MessageBar.default, {
    icon: getImgSrc(type),
    tips: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: "tipsContainer",
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        // eslint-disable-next-line react/no-danger
        dangerouslySetInnerHTML: {
          __html: !isRichText && i18 ? t(content) : content
        }
      })
    }),
    actions: actions
  });
};
const message = props => {
  const holder = document.createElement('div');
  holder.setAttribute('id', 'dataverseMessageBox');
  document.body.append(holder);
  const destroy = () => {
    holder.remove();
  };
  setTimeout(() => {
    destroy();
  }, props.duration || 3000);
  holder.addEventListener('click', () => {
    holder.remove();
  });
  _reactDom.default.render( /*#__PURE__*/(0, _jsxRuntime.jsx)(MessageBottomComp, _objectSpread({}, props)), holder);
};
var _default = message;
exports.default = _default;