"use strict";

require("core-js/modules/es.symbol.js");
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.array.for-each.js");
require("core-js/modules/es.array.push.js");
require("core-js/modules/es.object.define-properties.js");
require("core-js/modules/es.object.define-property.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/es.object.get-own-property-descriptors.js");
require("core-js/modules/es.object.keys.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/esnext.iterator.constructor.js");
require("core-js/modules/esnext.iterator.filter.js");
require("core-js/modules/esnext.iterator.for-each.js");
require("core-js/modules/web.dom-collections.for-each.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.NOTIFICATION_ROOT_CLASS_NAME = void 0;
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _rcNotification = require("rc-notification");
var _react = require("react");
var _reactDom = _interopRequireDefault(require("react-dom"));
require("./index.css");
var _purePanel = require("./pure-panel");
var _icon = require("../icon");
var _type = require("../icon/type");
var _jsxRuntime = require("react/jsx-runtime");
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) { (0, _defineProperty2["default"])(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; }
var ContextHolder = function ContextHolder(_ref) {
  var contextHolder = _ref.contextHolder;
  return contextHolder;
};
var prefixCls = 'fcr-notification';
var NOTIFICATION_ROOT_CLASS_NAME = exports.NOTIFICATION_ROOT_CLASS_NAME = "".concat(prefixCls, "-root");
function getRoot() {
  return document.querySelector(".".concat(NOTIFICATION_ROOT_CLASS_NAME));
}
var useFcrNotification = function useFcrNotification(rootConfig) {
  var _useNotification = (0, _rcNotification.useNotification)(_objectSpread({
      stack: {
        gap: 8
      },
      prefixCls: prefixCls,
      closeIcon: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "".concat(prefixCls, "-notice-close-icon"),
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
          size: 14,
          type: _type.FcrIconType.FCR_CLOSE,
          colors: {
            iconPrimary: 'var(--fcr_ui_scene_icontext1)'
          }
        })
      })
    }, rootConfig)),
    _useNotification2 = (0, _slicedToArray2["default"])(_useNotification, 2),
    notification = _useNotification2[0],
    contextHolder = _useNotification2[1];
  (0, _react.useEffect)(function () {
    var dom = getRoot();
    var div = document.createElement('div');
    dom === null || dom === void 0 || dom.appendChild(div);
    _reactDom["default"].render(/*#__PURE__*/(0, _jsxRuntime.jsx)(ContextHolder, {
      contextHolder: contextHolder
    }), div);
  }, []);
  var warpApi = (0, _react.useMemo)(function () {
    return _objectSpread(_objectSpread({}, notification), {}, {
      open: function open(config) {
        var icon = config.icon,
          iconStyle = config.iconStyle,
          content = config.content,
          oneline = config.oneline,
          restConfig = (0, _objectWithoutProperties2["default"])(config, _excluded);
        notification.open(_objectSpread(_objectSpread({}, restConfig), {}, {
          content: content || /*#__PURE__*/(0, _jsxRuntime.jsx)(_purePanel.PurePanel, {
            prefixCls: "".concat(prefixCls, "-notice"),
            icon: icon,
            iconStyle: iconStyle,
            title: config.title,
            message: config.message,
            actions: config.actions,
            oneline: oneline
          })
        }));
      }
    });
  }, []);
  return [warpApi, contextHolder];
};
var _default = exports["default"] = useFcrNotification;