import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
/**
 * global popup notification
 */
import React from 'react';
import ReactDOM from 'react-dom';
import { useTranslation } from 'react-i18next';
import iconWarning from "../../../styles/assets/icon/redError.svg";
import iconInfo from "../../../styles/assets/icon/blackInfo.svg";
import iconCheck from "../../../styles/assets/icon/greenCheck.svg";
import MessageBar from "./MessageBar";
import { jsx as _jsx } from "react/jsx-runtime";
export var MessageTypes;
(function (MessageTypes) {
  MessageTypes["Success"] = "Success";
  MessageTypes["Info"] = "Info";
  MessageTypes["Error"] = "Error";
})(MessageTypes || (MessageTypes = {}));
var MessageBottomComp = function MessageBottomComp(_ref) {
  var content = _ref.content,
    type = _ref.type,
    i18 = _ref.i18,
    isRichText = _ref.isRichText,
    actions = _ref.actions;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var getImgSrc = function getImgSrc(type) {
    var src = '';
    switch (type) {
      case MessageTypes.Error:
        src = iconWarning;
        break;
      case MessageTypes.Info:
        src = iconInfo;
        break;
      case MessageTypes.Success:
        src = iconCheck;
        break;
      default:
        src = iconInfo;
        break;
    }
    return src;
  };
  return /*#__PURE__*/_jsx(MessageBar, {
    icon: getImgSrc(type),
    tips: /*#__PURE__*/_jsx("div", {
      className: "tipsContainer",
      children: /*#__PURE__*/_jsx("div", {
        // eslint-disable-next-line react/no-danger
        dangerouslySetInnerHTML: {
          __html: !isRichText && i18 ? t(content) : content
        }
      })
    }),
    actions: actions
  });
};
var message = function message(props) {
  var holder = document.createElement('div');
  holder.setAttribute('id', 'dataverseMessageBox');
  document.body.append(holder);
  var destroy = function destroy() {
    holder.remove();
  };
  setTimeout(function () {
    destroy();
  }, props.duration || 3000);
  holder.addEventListener('click', function () {
    holder.remove();
  });
  ReactDOM.render( /*#__PURE__*/_jsx(MessageBottomComp, _objectSpread({}, props)), holder);
};
export default message;