import { h } from "@stencil/core";
import classNames from "classnames";
export class SidePanel {
    constructor() {
        this.isOpen = false;
        this.isVisible = false;
        this.shouldAnimate = false;
        this.closeTimeout = null;
        this.ANIMATION_DURATION_MS = 300;
    }
    handleOpenChange(newValue) {
        if (newValue) {
            clearTimeout(this.closeTimeout);
            this.isVisible = true;
            requestAnimationFrame(() => {
                this.shouldAnimate = true;
            });
            return;
        }
        this.shouldAnimate = false;
        this.closeTimeout = setTimeout(() => {
            this.isVisible = false;
        }, this.ANIMATION_DURATION_MS);
    }
    disconnectedCallback() {
        clearTimeout(this.closeTimeout);
        this.isVisible = false;
        this.shouldAnimate = false;
        this.closeTimeout = null;
    }
    handleOverlayClick(event) {
        if (event.target === event.currentTarget) {
            this.close.emit();
        }
    }
    handleCloseClick(event) {
        event.preventDefault();
        this.close.emit();
    }
    handleBackClick(event) {
        event.preventDefault();
        this.back.emit();
    }
    render() {
        if (!this.isVisible) {
            return null;
        }
        return (h("div", { onClick: this.handleOverlayClick.bind(this), class: classNames('side-panel-wrapper', {
                visible: this.shouldAnimate,
            }) }, h("div", { class: classNames('side-panel', { visible: this.shouldAnimate }, this.panelClassName) }, h("div", { class: "side-panel-heading" }, this.withBackButton && h("mvx-back-arrow-icon", { onClick: this.handleBackClick.bind(this), class: "side-panel-heading-back" }), h("div", { class: "side-panel-heading-title" }, this.panelTitle), h("mvx-close-icon", { class: "side-panel-heading-close", onClick: this.handleCloseClick.bind(this) })), h("div", { class: "side-panel-content" }, h("slot", null)))));
    }
    static get is() { return "mvx-side-panel"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["side-panel.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["side-panel.css"]
        };
    }
    static get properties() {
        return {
            "isOpen": {
                "type": "boolean",
                "attribute": "is-open",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "panelClassName": {
                "type": "string",
                "attribute": "panel-class-name",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "panelTitle": {
                "type": "string",
                "attribute": "panel-title",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "withBackButton": {
                "type": "boolean",
                "attribute": "with-back-button",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "isVisible": {},
            "shouldAnimate": {}
        };
    }
    static get events() {
        return [{
                "method": "close",
                "name": "close",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }, {
                "method": "back",
                "name": "back",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }];
    }
    static get watchers() {
        return [{
                "propName": "isOpen",
                "methodName": "handleOpenChange"
            }];
    }
}
//# sourceMappingURL=side-panel.js.map
