import { Fragment, h } from "@stencil/core";
export class DgaMenuV2 {
    constructor() {
        this.anchorEl = null;
        this.open = false;
        this.onClose = () => { };
        this.anchorOrigin = {
            vertical: 'bottom',
            horizontal: 'left',
        };
        this.transformOrigin = { vertical: 0, horizontal: 0 };
        this.menuStyle = {};
        this.handleClickOutside = (event) => {
            if (this.anchorEl &&
                !this.anchorEl.contains(event.target) &&
                !event.composedPath().includes(this.anchorEl)) {
                this.onClose();
            }
        };
    }
    handleOpenChange(newValue) {
        if (newValue) {
            this.calculateMenuStyle();
            document.addEventListener('click', this.handleClickOutside);
        }
        else {
            document.removeEventListener('click', this.handleClickOutside);
        }
    }
    calculateMenuStyle() {
        if (!this.anchorEl)
            return;
        const rect = this.anchorEl.getBoundingClientRect();
        // Calculate position using anchorOrigin and transformOrigin
        const top = this.anchorOrigin.vertical === 'bottom' ? rect.bottom : rect.top;
        const left = this.anchorOrigin.horizontal === 'right' ? rect.right : rect.left;
        this.menuStyle = {
            // position: 'absolute',
            position: 'fixed',
            top: `${top + this.transformOrigin.vertical + window.scrollY}px`,
            left: `${left + this.transformOrigin.horizontal + window.scrollX}px`,
            zIndex: '1000',
        };
    }
    render() {
        return (h(Fragment, { key: '59258cbbd5dbe51c1e10eef0b6b7406a1ca2f91b' }, this.open && (h("ul", { key: '3b9bc6217f7c494ba83184634595f93440122041', class: "menu", style: this.menuStyle, role: "menu", "aria-hidden": !this.open }, h("slot", { key: 'dd84c9e5e733ec59318c40c1761f7e5b1aa9b619' })))));
    }
    static get is() { return "dga-menu-v2"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["dga-menu.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["dga-menu.css"]
        };
    }
    static get properties() {
        return {
            "anchorEl": {
                "type": "unknown",
                "attribute": "anchor-el",
                "mutable": false,
                "complexType": {
                    "original": "HTMLElement | null",
                    "resolved": "HTMLElement",
                    "references": {
                        "HTMLElement": {
                            "location": "global",
                            "id": "global::HTMLElement"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "null"
            },
            "open": {
                "type": "boolean",
                "attribute": "open",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "onClose": {
                "type": "unknown",
                "attribute": "on-close",
                "mutable": false,
                "complexType": {
                    "original": "() => void",
                    "resolved": "() => void",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "() => {}"
            },
            "anchorOrigin": {
                "type": "unknown",
                "attribute": "anchor-origin",
                "mutable": false,
                "complexType": {
                    "original": "{ vertical: 'top' | 'bottom'; horizontal: 'left' | 'right' }",
                    "resolved": "{ vertical: \"top\" | \"bottom\"; horizontal: \"left\" | \"right\"; }",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "{\n    vertical: 'bottom',\n    horizontal: 'left',\n  }"
            },
            "transformOrigin": {
                "type": "unknown",
                "attribute": "transform-origin",
                "mutable": false,
                "complexType": {
                    "original": "{ vertical: number; horizontal: number }",
                    "resolved": "{ vertical: number; horizontal: number; }",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "{ vertical: 0, horizontal: 0 }"
            }
        };
    }
    static get states() {
        return {
            "menuStyle": {}
        };
    }
    static get watchers() {
        return [{
                "propName": "open",
                "methodName": "handleOpenChange"
            }];
    }
}
