"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "default", {
    enumerable: true,
    get: function() {
        return _default;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _Notification = /*#__PURE__*/ _interop_require_default._(require("./Notification"));
var _typings = require("../../utils/typings");
var messageInstance = null;
var options = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    id: '',
    duration: 3000,
    type: 'danger',
    position: 'top',
    onClose: function onClose() {},
    onClick: function onClick() {}
});
function getInstance(props, callback) {
    if (messageInstance) {
        messageInstance.destroy();
        messageInstance = null;
    }
    _Notification.default.newInstance(props, function(notification) {
        return callback && callback(notification);
    });
}
function notice(opts) {
    opts = (0, _object_spread._)({}, options, opts);
    getInstance(opts, function(notification) {
        messageInstance = notification;
    });
}
var errorMsg = function errorMsg(message) {
    if (!message) {
        console.warn('[NutUI Notify]: message不能为空');
    }
};
var _default = {
    text: function text(message) {
        var option = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
        errorMsg(message);
        return notice((0, _object_spread._)({
            message: message,
            type: 'base'
        }, option));
    },
    success: function success(message) {
        var option = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
        errorMsg(message);
        return notice((0, _object_spread._)({
            message: message,
            type: 'success'
        }, option));
    },
    primary: function primary(message) {
        var option = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
        errorMsg(message);
        return notice((0, _object_spread._)({
            message: message,
            type: 'primary'
        }, option));
    },
    danger: function danger(message) {
        var option = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
        errorMsg(message);
        return notice((0, _object_spread._)({
            message: message,
            type: 'danger'
        }, option));
    },
    warn: function warn(message) {
        var option = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
        errorMsg(message);
        return notice((0, _object_spread._)({
            message: message,
            type: 'warning'
        }, option));
    },
    hide: function hide() {
        if (messageInstance) {
            messageInstance.destroy();
            messageInstance = null;
        }
    }
};
