text: "use strict";
  
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
  
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports["default"] = createUseMessage;
  
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
  
  var React = _interopRequireWildcard(require("react"));
  
  var _useNotification = _interopRequireDefault(require("rc-notification/lib/useNotification"));
  
  var _configProvider = require("../../config-provider");
  
  var _ = require("..");
  
  function createUseMessage(getRcNotificationInstance, getRCNoticeProps) {
    var useMessage = function useMessage() {
      // We can only get content by render
      var getPrefixCls; // We create a proxy to handle delay created instance
  
      var innerInstance = null;
      var proxy = {
        add: function add(noticeProps, holderCallback) {
          innerInstance === null || innerInstance === void 0 ? void 0 : innerInstance.component.add(noticeProps, holderCallback);
        }
      };
  
      var _useRCNotification = (0, _useNotification["default"])(proxy),
          _useRCNotification2 = (0, _slicedToArray2["default"])(_useRCNotification, 2),
          hookNotify = _useRCNotification2[0],
          holder = _useRCNotification2[1];
  
      function notify(args) {
        var customizePrefixCls = args.prefixCls;
        var mergedPrefixCls = getPrefixCls('message', customizePrefixCls);
        var rootPrefixCls = getPrefixCls();
        var target = args.key || (0, _.getKeyThenIncreaseKey)();
        var closePromise = new Promise(function (resolve) {
          var callback = function callback() {
            if (typeof args.onClose === 'function') {
              args.onClose();
            }
  
            return resolve(true);
          };
  
          getRcNotificationInstance((0, _extends2["default"])((0, _extends2["default"])({}, args), {
            prefixCls: mergedPrefixCls,
            rootPrefixCls: rootPrefixCls
          }), function (_ref) {
            var prefixCls = _ref.prefixCls,
                instance = _ref.instance;
            innerInstance = instance;
            hookNotify(getRCNoticeProps((0, _extends2["default"])((0, _extends2["default"])({}, args), {
              key: target,
              onClose: callback
            }), prefixCls));
          });
        });
  
        var result = function result() {
          if (innerInstance) {
            innerInstance.removeNotice(target);
          }
        };
  
        result.then = function (filled, rejected) {
          return closePromise.then(filled, rejected);
        };
  
        result.promise = closePromise;
        return result;
      } // Fill functions
  
  
      var hookApiRef = React.useRef({});
      hookApiRef.current.open = notify;
      ['success', 'info', 'warning', 'error', 'loading'].forEach(function (type) {
        return (0, _.attachTypeApi)(hookApiRef.current, type);
      });
      return [hookApiRef.current, /*#__PURE__*/React.createElement(_configProvider.ConfigConsumer, {
        key: "holder"
      }, function (context) {
        getPrefixCls = context.getPrefixCls;
        return holder;
      })];
    };
  
    return useMessage;
  }