/*
 * Copyright (C) 2016-2020 Kano Computing Ltd.
 * License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 */
import { EventEmitter } from '@kano/common/index.js';
import { button } from '@kano/styles/button.js';
import { KanoAlert } from '../../../elements/kano-alert/kano-alert.js';
import { Alert } from './alert.js';
import { _ } from '../../i18n/index.js';
const DEFAULT_OPTS = {
    confirmLabel: _('CONFIRM', 'Confirm'),
    dismissLabel: _('CANCEL', 'Cancel'),
};
export class Confirm extends Alert {
    constructor() {
        super(...arguments);
        this._onDidConfirm = new EventEmitter();
        this._onDidCancel = new EventEmitter();
    }
    get onDidConfirm() { return this._onDidConfirm.event; }
    get onDidCancel() { return this._onDidCancel.event; }
    createDom(opts) {
        const options = Object.assign({}, DEFAULT_OPTS, 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 = options.heading;
        root.text = options.text;
        const confirm = this.createButton(options.confirmLabel);
        confirm.className = 'btn l kano-alert-primary';
        confirm.setAttribute('dialog-confirm', '');
        const dismiss = this.createButton(options.dismissLabel);
        dismiss.className = 'btn l secondary kano-alert-secondary';
        dismiss.setAttribute('dialog-dismiss', '');
        root.appendChild(confirm);
        root.appendChild(dismiss);
        return root;
    }
    _onClose(e) {
        if (e.detail.confirmed) {
            this._onDidConfirm.fire();
        }
        else {
            this._onDidCancel.fire();
        }
        super._onClose(e);
    }
}
export default Confirm;
//# sourceMappingURL=confirm.js.map