import * as Utils from '../lib/utils' ; type BtnClickHandler = ( btnEl : HTMLElement , dialog : Dialog ) => boolean | void ; /**
 * 对话框
 */ export default class Dialog { public $el : HTMLElement ; public $content : HTMLElement ; public $actions : HTMLElement ; constructor ( contentEl ) { this . $el = Utils . createElement ( `<div class="atk-layer-dialog-wrap">
        <div class="atk-layer-dialog">
          <div class="atk-layer-dialog-content"></div>
          <div class="atk-layer-dialog-actions"></div>
        </div>
      </div>` ) ; this . $actions = this . $el . querySelector < HTMLElement > ( '.atk-layer-dialog-actions' ) ! ; this . $content = this . $el . querySelector ( '.atk-layer-dialog-content' ) ! ; this . $content . appendChild ( contentEl ) ; return this ; } /** 按钮 · 确定 */ public setYes ( handler ) { const btn = Utils . createElement < HTMLButtonElement > ( '<button data-action="confirm">确定</button>' ) ; btn . onclick = this . onBtnClick ( handler ) ; this . $actions . appendChild ( btn ) ; return this ; } /** 按钮 · 取消 */ public setNo ( handler ) { const btn = Utils . createElement < HTMLButtonElement > ( '<button data-action="cancel">取消</button>' ) ; btn . onclick = this . onBtnClick ( handler ) ; this . $actions . appendChild ( btn ) ; return this ; } private onBtnClick ( handler ) { return ( evt ) => { const re = handler ( evt . currentTarget as HTMLElement , this ) ; if ( re === undefined || re === true ) { this . $el . remove ( ) ; } } ; } }