"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 _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _Notification = /*#__PURE__*/ _interop_require_default._(require("./Notification"));
var _overlay = require("../overlay/overlay");
var messageInstance = null;
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _overlay.defaultOverlayProps), {
    id: '',
    position: 'center',
    title: '',
    size: 'base',
    icon: null,
    content: '',
    contentClassName: '',
    contentStyle: {},
    wordBreak: 'break-all',
    duration: 2,
    closeOnOverlayClick: false,
    lockScroll: false,
    zIndex: 1300,
    onClose: function onClose() {}
});
function getInstance(props, callback) {
    if (messageInstance) {
        messageInstance.destroy();
        messageInstance = null;
    }
    _Notification.default.newInstance(props, function(notification) {
        return callback && callback(notification);
    });
}
function notice(opts) {
    function close() {
        if (messageInstance) {
            messageInstance.destroy();
            messageInstance = null;
            opts.onClose && opts.onClose();
        }
    }
    var opts2 = (0, _object_spread_props._)((0, _object_spread._)({}, defaultProps, opts), {
        onClose: close
    });
    getInstance(opts2, function(notification) {
        messageInstance = notification;
    });
}
var errorMsg = function errorMsg(msg) {
    if (!msg) {
        console.warn('[NutUI Toast]: msg cannot be null');
    }
};
function show(option) {
    if (typeof option === 'string') {
        errorMsg(option);
        return notice({
            content: option
        });
    }
    errorMsg(option.content);
    return notice((0, _object_spread._)({}, option));
}
function config(config) {
    defaultProps = (0, _object_spread._)({}, defaultProps, config);
}
var _default = {
    show: show,
    config: config,
    clear: function clear() {
        if (messageInstance) {
            messageInstance.destroy();
            messageInstance = null;
        }
    }
};
