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; }
/**
 * 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 let MessageTypes;
(function (MessageTypes) {
  MessageTypes["Success"] = "Success";
  MessageTypes["Info"] = "Info";
  MessageTypes["Error"] = "Error";
})(MessageTypes || (MessageTypes = {}));
const MessageBottomComp = ({
  content,
  type,
  i18,
  isRichText,
  actions
}) => {
  const {
    t
  } = useTranslation();
  const getImgSrc = type => {
    let 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
  });
};
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.render( /*#__PURE__*/_jsx(MessageBottomComp, _objectSpread({}, props)), holder);
};
export default message;