import { button } from '@kano/styles/button.js';
import { KanoAlert } from '../../../elements/kano-alert/kano-alert.js';
import { Base } from './base.js';
import { EventEmitter } from '@kano/common/index.js';
export class Alert extends Base {
    constructor(opts = { heading: '', text: '' }) {
        super(opts);
        this._onDidClose = new EventEmitter();
        this._onClose = this._onClose.bind(this);
        this.root.addEventListener('iron-overlay-closed', this._onClose);
    }
    get onDidClose() { return this._onDidClose.event; }
    createDom(opts) {
        const root = new KanoAlert();
        root.appendChild(button.content.cloneNode(true));
        // OverlayInto is defined, Do not use modal nor backdrop
        root.modal = typeof this.overlayInto === 'undefined';
        root.withBackdrop = typeof this.overlayInto !== 'undefined';
        root.fitInto = this.fitInto;
        root.heading = opts.heading;
        root.text = opts.text;
        const buttonEl = this.createButton(opts.buttonLabel || 'Ok');
        buttonEl.className = 'btn l tertiary kano-alert-primary';
        buttonEl.setAttribute('dialog-dismiss', '');
        root.appendChild(buttonEl);
        return root;
    }
    _onClose(e) {
        this._onDidClose.fire();
    }
    dispose() {
        super.dispose();
        this.root.removeEventListener('iron-overlay-closed', (e) => this._onClose(e));
    }
}
export default Alert;
//# sourceMappingURL=alert.js.map