import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import * as React from "react";
import Notification from "./Notification";
import { ComponentDefaults } from "../../utils/typings";
var messageInstance = null;
var options = _object_spread_props(_object_spread({}, ComponentDefaults), {
    id: '',
    duration: 3000,
    type: 'danger',
    position: 'top',
    onClose: function() {},
    onClick: function() {}
});
function getInstance(props, callback) {
    if (messageInstance) {
        messageInstance.destroy();
        messageInstance = null;
    }
    Notification.newInstance(props, function(notification) {
        return callback && callback(notification);
    });
}
function notice(opts) {
    opts = _object_spread({}, options, opts);
    getInstance(opts, function(notification) {
        messageInstance = notification;
    });
}
var errorMsg = function(message) {
    if (!message) {
        console.warn('[NutUI Notify]: message不能为空');
    }
};
export default {
    text: function text(message) {
        var option = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
        errorMsg(message);
        return notice(_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(_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(_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(_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(_object_spread({
            message: message,
            type: 'warning'
        }, option));
    },
    hide: function hide() {
        if (messageInstance) {
            messageInstance.destroy();
            messageInstance = null;
        }
    }
};
