import { MDCDialog } from '@material/dialog';
import { h } from '@stencil/core';
export class Dialog {
    constructor() {
        this.items = [];
        this.dialogTitle = '';
    }
    componentDidLoad() {
        this.mdcDialog = new MDCDialog(this.dialogEl);
        this.mdcDialog.listen('MDCDialog:closing', (event) => {
            switch (event.detail.action) {
                case 'accept':
                    this.accept.emit(true);
                    break;
                case 'close':
                    this.cancel.emit(false);
                    break;
                default:
                    this.cancel.emit(false);
                    break;
            }
        });
    }
    /**
     * @deprecated since 1.1.0 : use toggle() instead
     * Open/Close dialog.
     */
    async show() {
        this.toggle();
    }
    async toggle() {
        this.mdcDialog.isOpen ? this.close() : this.open();
    }
    async isOpen() {
        return this.mdcDialog.isOpen;
    }
    async open() {
        this.mdcDialog.open();
    }
    async close() {
        this.mdcDialog.close();
        this.cancel.emit(false);
    }
    getSectionClass() {
        return {
            'mdc-dialog__content': true
        };
    }
    render() {
        return (h("aside", { id: "my-mdc-dialog", class: "mdc-dialog", role: "alertdialog", "aria-modal": "true", "aria-labelledby": this.dialogTitle, "aria-describedby": "mdc-dialog-description", ref: el => this.dialogEl = el },
            h("div", { class: "mdc-dialog__container" },
                h("div", { style: { 'min-width': this.width + 'px', 'width': this.width + 'px' }, class: "mdc-dialog__surface" },
                    h("h2", { id: "mdc-dialog-label", class: "mdc-dialog__title" },
                        this.dialogTitle,
                        this.closeButton && h("materials-icon-button", { class: "close-btn", icon: "close", onClick: () => this.close() })),
                    h("section", { id: "mdc-dialog-content", style: { 'min-height': this.height + 'px', 'height': this.height + 'px' }, class: this.getSectionClass() },
                        h("slot", { name: "body" })),
                    h("footer", { class: "mdc-dialog__actions" },
                        h("slot", { name: "third-button" }),
                        !!this.cancelButton &&
                            h("button", { type: "button", class: "mdc-button mdc-dialog__button", "data-mdc-dialog-action": "close" }, this.cancelButton),
                        !!this.acceptButton &&
                            h("button", { type: "button", disabled: this.disableAcceptButton, class: "mdc-button mdc-dialog__button", "data-mdc-dialog-action": "accept" }, this.acceptButton)))),
            h("div", { class: "mdc-dialog__scrim" })));
    }
    static get is() { return "materials-dialog"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() { return {
        "$": ["dialog.scss"]
    }; }
    static get styleUrls() { return {
        "$": ["dialog.css"]
    }; }
    static get properties() { return {
        "scrollable": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [{
                        "text": "since 1.1.0 : dialog scroll automatically",
                        "name": "deprecated"
                    }],
                "text": ""
            },
            "attribute": "scrollable",
            "reflect": false
        },
        "items": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "string[]",
                "resolved": "string[]",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "defaultValue": "[]"
        },
        "width": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "width",
            "reflect": false
        },
        "height": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "height",
            "reflect": false
        },
        "dialogTitle": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "dialog-title",
            "reflect": false,
            "defaultValue": "''"
        },
        "acceptButton": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "accept-button",
            "reflect": false
        },
        "cancelButton": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "cancel-button",
            "reflect": false
        },
        "disableAcceptButton": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "disable-accept-button",
            "reflect": false
        },
        "closeButton": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "close-button",
            "reflect": false
        }
    }; }
    static get events() { return [{
            "method": "accept",
            "name": "accept",
            "bubbles": true,
            "cancelable": true,
            "composed": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "complexType": {
                "original": "any",
                "resolved": "any",
                "references": {}
            }
        }, {
            "method": "cancel",
            "name": "cancel",
            "bubbles": true,
            "cancelable": true,
            "composed": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "complexType": {
                "original": "any",
                "resolved": "any",
                "references": {}
            }
        }]; }
    static get methods() { return {
        "show": {
            "complexType": {
                "signature": "() => Promise<void>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": [{
                        "name": "deprecated",
                        "text": "since 1.1.0 : use toggle() instead\nOpen/Close dialog."
                    }]
            }
        },
        "toggle": {
            "complexType": {
                "signature": "() => Promise<void>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        },
        "isOpen": {
            "complexType": {
                "signature": "() => Promise<boolean>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<boolean>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        },
        "open": {
            "complexType": {
                "signature": "() => Promise<void>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        },
        "close": {
            "complexType": {
                "signature": "() => Promise<void>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        }
    }; }
    static get elementRef() { return "host"; }
}
