import "./modal.scss";
import Modal from "./modal";
import {confirmTpl} from "./modalTpl";
import classNames from 'classnames';
const Confirm = (($)=>{
    const DefaultConfig = {
        okLabel:"确定",
        cancelLabel:"取消",
        iconClass:"cd-question",
        smallTitle: '',
        isFooterTip: false,   
        footerTipText: ''   
    }
    class Confirm extends Modal{
        constructor(config) {
            super(config);
        }
        _getConfig(config){
            config = $.extend(true, {}, DefaultConfig, config);
            return super._getConfig(config);
        }
        initUI(){
            const {iconClass, smallTitle, isFooterTip, footerTipText} = 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";
            }
            smallTitle && (_contentCls += ' cd-small-title-md');
            this._config.content = confirmTpl.replace("{{@text}}", this._config.content || "");
            this._config.content = template.render(this._config.content, {iconClass:_iconCls, contentClass:_contentCls, smallTitle, isFooterTip, footerTipText});
            super.initUI();
            if(this._$dialog){
                const {okLabel, cancelLabel} = this._config;
                this._$dialog.find(".J_btnOK").html(okLabel);
                this._$dialog.find(".J_btnCancel").html(cancelLabel);
            }
        }
        _addEvent(){
            super._addEvent();
            if(this._$dialog){
                this._$dialog.on("click", ".J_btnOK", (event)=>{
                    this.beforeClose(Modal.CloseType.TYPE_OK);
                });
                this._$dialog.on("click", ".J_btnCancel", (event)=>{
                    this.beforeClose(Modal.CloseType.TYPE_CANCEL);
                });
            }
        }
        dispose(){
            if(this._$dialog){
                this._$dialog.off();
            }
            super.dispose();
        }
    }
    return Confirm;
})($);
export default Confirm;