var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import ConfigProvider from '../config-provider';
import React, { Component, isValidElement } from 'react';
import cls from 'classnames';
import { Message as NextMessage } from '@alifd/next';
function isMessageQuickProps(config) {
    return typeof config === 'object' && !isValidElement(config);
}
class Message extends Component {
    constructor() {
        super(...arguments);
        this.classNameDefine = () => {
            let className_new;
            const { shape, prefix = 'next-', bgcolor = 'colorful', className, } = this.props;
            if (shape === 'toast') {
                const { bgcolor = 'white' } = this.props;
                className_new = cls(className, {
                    [`${prefix}bg-white`]: bgcolor === 'white',
                    [`${prefix}bg-colorful`]: bgcolor === 'colorful',
                });
            }
            className_new = cls(className, {
                [`${prefix}bg-white`]: bgcolor === 'white',
                [`${prefix}bg-colorful`]: bgcolor === 'colorful',
            });
            return className_new;
        };
    }
    render() {
        const _a = this.props, { shape, type, prefix = 'next-' } = _a, otherProps = __rest(_a, ["shape", "type", "prefix"]);
        return (React.createElement(NextMessage, Object.assign({ type: type === 'notice' ? 'help' : type }, otherProps, { shape: shape, prefix: prefix, className: this.classNameDefine() })));
    }
}
Message.wrapMethod = (type) => (config) => {
    if (isMessageQuickProps(config)) {
        const { prefix = 'next-', closeable, content, className } = config;
        if (type === 'show') {
            config.type = (config.type === 'notice' ? 'help' : config.type);
        }
        config.className = cls(className, {
            [`${prefix}close-add`]: closeable === true,
            [`${prefix}with-content`]: content,
        });
    }
    const ret = NextMessage[type](config);
    return ret;
};
Message.notice = Message.wrapMethod('notice');
Message.show = Message.wrapMethod('show');
Message.success = Message.wrapMethod('success');
Message.warning = Message.wrapMethod('warning');
Message.error = Message.wrapMethod('error');
Message.help = Message.wrapMethod('help');
Message.loading = Message.wrapMethod('loading');
Message.hide = Message.wrapMethod('hide');
// @ts-ignore
Message.withContext = NextMessage.withContext;
export default ConfigProvider.config(Message);
