import { h } from "@stencil/core";
import getAssetPath from "../../utils/assetPath";
export class EclPopover {
    constructor() {
        this.theme = 'ec';
        this.styleClass = undefined;
        this.eclScript = false;
        this.itemId = undefined;
        this.toggleLabel = undefined;
        this.list = false;
        this.icon = undefined;
        this.iconSize = 'fluid';
        this.iconSprite = '';
    }
    getClass() {
        const styleClasses = [
            `ecl-popover`,
            this.styleClass
        ];
        return styleClasses.join(' ');
    }
    getAttrs() {
        return {
            'aria-controls': this.itemId,
            'data-ecl-popover-toggle': 'data-ecl-popover-toggle',
            'aria-expanded': 'false',
        };
    }
    componentDidLoad() {
        if (this.el.querySelector('.ecl-popover__list')) {
            // Clean the html so that the script finds what it expects.
            const items = this.el.querySelectorAll('.ecl-popover__item');
            this.el.querySelector('.ecl-popover__list').innerHTML = '';
            this.el.querySelector('.ecl-popover__list').append(...items);
        }
        if (this.eclScript) {
            // Load the ECL vanilla js if not already present.
            const src = getAssetPath('./build/scripts/ecl-popover-vanilla.js');
            if (document.querySelector(`script[src="${src}"]`)) {
                document.querySelector(`script[src="${src}"]`).remove();
            }
            const script = document.createElement('script');
            script.src = src;
            script.onload = () => {
                const popover = new ECL.Popover(this.el.firstElementChild);
                popover.init();
            };
            document.body.appendChild(script);
        }
    }
    render() {
        return (h("div", { class: this.getClass() }, h("a", Object.assign({ class: `ecl-link sc-ecl-link-${this.theme} ecl-link--standalone ecl-popover__toggle` }, this.getAttrs()), this.icon ?
            h("ecl-icon", { theme: this.theme, icon: this.icon, size: this.iconSize, "style-class": "ecl-link__icon--before", sprite: this.iconSprite }) : '', this.toggleLabel), h("div", { class: "ecl-popover__container", id: this.itemId, hidden: true }, h("div", { class: "ecl-popover__content" }, this.list ?
            h("ul", { class: "ecl-popover__list" }, h("slot", null)) : '', !this.list ?
            h("slot", null) : ''))));
    }
    static get is() { return "ecl-popover"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "ec": ["./build/styles/ecl-popover-ec.css"],
            "eu": ["./build/styles/ecl-popover-eu.css"]
        };
    }
    static get styleUrls() {
        return {
            "ec": ["build/styles/ecl-popover-ec.css"],
            "eu": ["build/styles/ecl-popover-eu.css"]
        };
    }
    static get assetsDirs() { return ["build"]; }
    static get properties() {
        return {
            "theme": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "theme",
                "reflect": false,
                "defaultValue": "'ec'"
            },
            "styleClass": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "style-class",
                "reflect": false
            },
            "eclScript": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "ecl-script",
                "reflect": false,
                "defaultValue": "false"
            },
            "itemId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "item-id",
                "reflect": false
            },
            "toggleLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "toggle-label",
                "reflect": false
            },
            "list": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "list",
                "reflect": false,
                "defaultValue": "false"
            },
            "icon": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "icon",
                "reflect": false
            },
            "iconSize": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "icon-size",
                "reflect": false,
                "defaultValue": "'fluid'"
            },
            "iconSprite": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "icon-sprite",
                "reflect": false,
                "defaultValue": "''"
            }
        };
    }
    static get elementRef() { return "el"; }
}
//# sourceMappingURL=ecl-popover.js.map
