import { h } from "@stencil/core";
import getAssetPath from "../../utils/assetPath";
export class EclBreadcrumb {
    constructor() {
        this.styleClass = '';
        this.variant = 'default';
        this.theme = 'ec';
        this.eclScript = false;
        this.minItemsRight = 2;
    }
    getClass() {
        return [
            `ecl-breadcrumb`,
            `ecl-breadcrumb--${this.variant}`,
            this.styleClass
        ].join(' ');
    }
    componentDidRender() {
        const items = this.el.querySelectorAll('.ecl-breadcrumb__segment');
        const itemsCount = items.length;
        const ellipsis = this.el.querySelector('.ecl-breadcrumb__segment--ellipsis');
        const startHidingIndex = Array.from(items).indexOf(ellipsis);
        const toBeHidden = Array.from(items).slice((startHidingIndex + 1), (itemsCount - this.minItemsRight));
        toBeHidden.forEach((item) => {
            item.setAttribute('data-ecl-breadcrumb-item', 'expandable');
        });
        this.el.querySelector('.ecl-breadcrumb__container').innerHTML = '';
        this.el.querySelector('.ecl-breadcrumb__container').append(...items);
        if (this.eclScript) {
            // Load the ECL vanilla js if not already present.
            const src = getAssetPath('./build/scripts/ecl-breadcrumb-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 breadcrumb = new ECL.Breadcrumb(this.el.firstElementChild);
                breadcrumb.init();
            };
            document.body.appendChild(script);
        }
    }
    render() {
        return (h("nav", { class: this.getClass(), "data-ecl-breadcrumb": true }, h("ol", { class: "ecl-breadcrumb__container" }, h("slot", null))));
    }
    static get is() { return "ecl-breadcrumb"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "ec": ["./build/styles/ecl-breadcrumb-ec.css"],
            "eu": ["./build/styles/ecl-breadcrumb-eu.css"]
        };
    }
    static get styleUrls() {
        return {
            "ec": ["build/styles/ecl-breadcrumb-ec.css"],
            "eu": ["build/styles/ecl-breadcrumb-eu.css"]
        };
    }
    static get assetsDirs() { return ["build"]; }
    static get properties() {
        return {
            "styleClass": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "style-class",
                "reflect": false,
                "defaultValue": "''"
            },
            "variant": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "variant",
                "reflect": false,
                "defaultValue": "'default'"
            },
            "theme": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "theme",
                "reflect": false,
                "defaultValue": "'ec'"
            },
            "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"
            },
            "minItemsRight": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "min-items-right",
                "reflect": false,
                "defaultValue": "2"
            }
        };
    }
    static get elementRef() { return "el"; }
}
//# sourceMappingURL=ecl-breadcrumb.js.map
