import "core-js/modules/es.symbol.js";
import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.array.for-each.js";
import "core-js/modules/es.array.push.js";
import "core-js/modules/es.object.define-properties.js";
import "core-js/modules/es.object.define-property.js";
import "core-js/modules/es.object.get-own-property-descriptor.js";
import "core-js/modules/es.object.get-own-property-descriptors.js";
import "core-js/modules/es.object.keys.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.filter.js";
import "core-js/modules/esnext.iterator.for-each.js";
import "core-js/modules/web.dom-collections.for-each.js";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
var _excluded = ["icon", "iconStyle", "content", "oneline"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { useNotification } from 'rc-notification';
import { useEffect, useMemo } from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import { PurePanel } from './pure-panel';
import { FcrIcon } from '../icon';
import { FcrIconType } from '../icon/type';
import { jsx as _jsx } from "react/jsx-runtime";
var ContextHolder = function ContextHolder(_ref) {
  var contextHolder = _ref.contextHolder;
  return contextHolder;
};
var prefixCls = 'fcr-notification';
export var NOTIFICATION_ROOT_CLASS_NAME = "".concat(prefixCls, "-root");
function getRoot() {
  return document.querySelector(".".concat(NOTIFICATION_ROOT_CLASS_NAME));
}
var useFcrNotification = function useFcrNotification(rootConfig) {
  var _useNotification = useNotification(_objectSpread({
      stack: {
        gap: 8
      },
      prefixCls: prefixCls,
      closeIcon: /*#__PURE__*/_jsx("div", {
        className: "".concat(prefixCls, "-notice-close-icon"),
        children: /*#__PURE__*/_jsx(FcrIcon, {
          size: 14,
          type: FcrIconType.FCR_CLOSE,
          colors: {
            iconPrimary: 'var(--fcr_ui_scene_icontext1)'
          }
        })
      })
    }, rootConfig)),
    _useNotification2 = _slicedToArray(_useNotification, 2),
    notification = _useNotification2[0],
    contextHolder = _useNotification2[1];
  useEffect(function () {
    var dom = getRoot();
    var div = document.createElement('div');
    dom === null || dom === void 0 || dom.appendChild(div);
    ReactDOM.render(/*#__PURE__*/_jsx(ContextHolder, {
      contextHolder: contextHolder
    }), div);
  }, []);
  var warpApi = useMemo(function () {
    return _objectSpread(_objectSpread({}, notification), {}, {
      open: function open(config) {
        var icon = config.icon,
          iconStyle = config.iconStyle,
          content = config.content,
          oneline = config.oneline,
          restConfig = _objectWithoutProperties(config, _excluded);
        notification.open(_objectSpread(_objectSpread({}, restConfig), {}, {
          content: content || /*#__PURE__*/_jsx(PurePanel, {
            prefixCls: "".concat(prefixCls, "-notice"),
            icon: icon,
            iconStyle: iconStyle,
            title: config.title,
            message: config.message,
            actions: config.actions,
            oneline: oneline
          })
        }));
      }
    });
  }, []);
  return [warpApi, contextHolder];
};
export default useFcrNotification;