import { message } from 'antd';
import bannerMessage from './BannerMessage';
import alertMessage from './AlertMessage';
import confirm from '../modal/Confirm';

export default {
    confirm(options) {
        return confirm(options);
    },
    show(options) {
        if (options.alert) {
            return alertMessage.show(options);
        }
        if (options.banner) {
            bannerMessage.show(options);
            return;
        }
        const { type = 'info', content = '', duration = 3, onClose, banner = false, modal = false } = options;
        switch (type.toUpperCase()) {
            case 'INFO': message.info(content, duration, onClose); break;
            case 'SUCCESS': message.success(content, duration, onClose); break;
            case 'ERROR': message.error(content, duration, onClose); break;
            case 'WARN': message.warning(content, duration, onClose); break;
            case 'LOADING': message.loading(content, duration, onClose); break;
        }
    },
    info(options) {
        return this.show({ ...options, type: 'info' });
    },
    success(options) {
        return this.show({ ...options, type: 'success' });
    },
    error(options) {
        return this.show({ ...options, type: 'error' });
    },
    warn(options) {
        return this.show({ ...options, type: 'warn' });
    },
    loading(options) {
        return this.show({ ...options, type: 'loading' });
    }
}