/*
 * Copyright (C) 2016-2020 Kano Computing Ltd.
 * License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 */
import '@polymer/paper-dialog/paper-dialog.js';
import { Base } from './base.js';
import { EventEmitter, subscribeDOM } from '@kano/common/index.js';
export class Dialog extends Base {
    constructor() {
        super(...arguments);
        this._onDidConfirm = new EventEmitter();
        this._onDidCancel = new EventEmitter();
        this._onDidClose = new EventEmitter();
    }
    get onDidConfirm() { return this._onDidConfirm.event; }
    get onDidCancel() { return this._onDidCancel.event; }
    get onDidClose() { return this._onDidClose.event; }
    createDom(opts) {
        const root = document.createElement('paper-dialog');
        root.style.background = 'transparent';
        // 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;
        const domNode = opts.createDom();
        domNode.style.margin = '0px';
        subscribeDOM(root, 'iron-overlay-closed', this._onClose, this);
        root.appendChild(domNode);
        return root;
    }
    _onClose(e) {
        if (e.detail.confirmed) {
            this._onDidConfirm.fire();
        }
        else {
            this._onDidCancel.fire();
        }
        this._onDidClose.fire();
    }
}
export default Dialog;
//# sourceMappingURL=dialog.js.map