import Modal from "./modal";
import {alertTpl} from "./modalTpl";
import classNames from 'classnames';
const Alert = (($)=>{
    const DefaultConfig = {
        label:"确定",
        iconClass:"cd-question"
    }
    class Alert extends Modal {
        constructor(config) {
            super(config);
        }
        _getConfig(config){
            config = $.extend(true, {}, DefaultConfig, config);
            return super._getConfig(config);
        }
        initUI(){
            const {iconClass} = this._config;
            if(this._config.footer){
                this._config.footer.show = false;
            }
            let _iconCls = "";
            let _contentCls = "cd-content-box";
            if(iconClass){
                _iconCls = classNames("cd-modal-icon", iconClass);
                _contentCls = "cd-content-box cd-icon-md";
            }
            this._config.content = alertTpl.replace("{{@text}}", this._config.content || "");
            this._config.content = template.render(this._config.content, {iconClass:_iconCls, contentClass:_contentCls});
            super.initUI();
            if(this._$dialog){
                const {label} = this._config;
                this._$dialog.find(".J_btnOK").html(label);
            }
        }
        _addEvent(){
            super._addEvent();
            if(this._$dialog){
                this._$dialog.on("click", ".J_btnOK", (event)=>{
                    this.beforeClose(Modal.CloseType.TYPE_OK);
                });
            }
        }
        dispose(){
            if(this._$dialog){
                this._$dialog.off();
            }
            super.dispose();
        }
    }
    return Alert;
})($);
export default Alert;