import { h, Host } from "@stencil/core";
import { SidePanelSideEnum } from "./side-panel.types";
export class SidePanel {
    constructor() {
        this.isOpen = false;
        this.side = SidePanelSideEnum.RIGHT;
        this.isVisible = false;
        this.shouldAnimate = false;
        this.closeTimeout = null;
        this.ANIMATION_DURATION_MS = 300;
        this.handleOverlayClick = (event) => {
            if (event.target === event.currentTarget) {
                this.close.emit();
            }
        };
    }
    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);
    }
    render() {
        if (!this.isVisible) {
            return null;
        }
        return (h(Host, null, h("div", { class: {
                'overlay': true,
                'visible': this.shouldAnimate,
                'hidden': !this.shouldAnimate,
                'side-left': this.side === 'left',
                'side-right': this.side === 'right',
            }, onClick: this.handleOverlayClick }, h("div", { class: {
                panel: true,
                [this.panelClassName]: Boolean(this.panelClassName),
            } }, h("slot", null)))));
    }
    static get is() { return "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",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "is-open",
                "reflect": false,
                "defaultValue": "false"
            },
            "side": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "SidePanelSideEnum",
                    "resolved": "SidePanelSideEnum.LEFT | SidePanelSideEnum.RIGHT",
                    "references": {
                        "SidePanelSideEnum": {
                            "location": "import",
                            "path": "./side-panel.types",
                            "id": "src/components/visual/side-panel/side-panel.types.ts::SidePanelSideEnum"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "side",
                "reflect": false,
                "defaultValue": "SidePanelSideEnum.RIGHT"
            },
            "panelClassName": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "panel-class-name",
                "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": {}
                }
            }];
    }
    static get watchers() {
        return [{
                "propName": "isOpen",
                "methodName": "handleOpenChange"
            }];
    }
}
//# sourceMappingURL=side-panel.js.map
