"use strict";

class khcToastr {
    /**
     * positionClass      控制展示位置
     * closeButton        是否展示关闭按钮
     * progressBar        是否展示进度条
     * preventDuplicates  防止重复
     * newestOnTop        是否顶部最新
     */
    static getDefaultData(){
        let defaultData={positionClass:'toast-top-center',closeButton:false,progressBar:false,preventDuplicates:false,newestOnTop:true}
        return defaultData;
    }
    /**
     * @param data 可以是字符串，也可以是obj对象：{msg:'标题'}
     */
    static showSuccessMessage(data) {
        data =this.toData(data);
        data.type = 'success'
        this.showToastr(data)
    }
    static showInfoMessage(data) {
        data =this.toData(data);
        data.type = 'info'
        this.showToastr(data)
    }
    static showWarningMessage(data) {
        data =this.toData(data);
        data.type = 'warning'
        this.showToastr(data)
    }
    static showErrorMessage(data) {
        data =this.toData(data);
        data.type = 'error'
        this.showToastr(data)
    }
    static toData(data){
        if(typeof data == 'string'){
            return {msg:data}
        }else{
            return data;
        }
    }

    static showToastr(data){
        let msg = data.msg;
        let title = data.title || '';
        let type = data.type;

        let positionClass = data.positionClass || this.getDefaultData().positionClass;
        let closeButton = data.closeButton || this.getDefaultData().closeButton;
        let progressBar = data.positionClass || this.getDefaultData().progressBar;
        let preventDuplicates = data.positionClass || this.getDefaultData().preventDuplicates;
        let newestOnTop = data.positionClass || this.getDefaultData().newestOnTop;
        toastr[type](msg, title, {
            positionClass: positionClass,
            closeButton: closeButton,
            progressBar: progressBar,
            preventDuplicates: preventDuplicates,
            newestOnTop: newestOnTop,
            rtl: $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl'
        });
    }
}
export { khcToastr }