import { Host, h } from "@stencil/core";
export class SpwHeaderNavigation {
    constructor() {
        this.level = 0;
        this.element = null;
        /** Alignement des éléments de navigation sur desktop */
        this.alignment = 'flex-start';
        /** Présence ou non d'un bouton à droite de la navigation */
        this.extraButton = false;
        /** Attribut target de l'extra button */
        this.extraButtonTarget = '_self';
        /** Variant de l'extra button */
        this.extraButtonVariant = 'primary';
        /** Position de l'icône de l'extra button */
        this.extraButtonIconPosition = 'left';
        /** Activer l'émission d'événement au clic de l'extra button au lieu de la navigation classique */
        this.emitExtraButtonClick = false;
        /** Texte du lien "Page d'accueil" dans la navigation mobile */
        this.homepageLabel = "Page d'accueil";
    }
    componentDidLoad() {
        this.updateHeightVar();
        this.resizeObserver = new ResizeObserver(() => this.updateHeightVar());
        this.resizeObserver.observe(this.navEl);
    }
    disconnectedCallback() {
        var _a;
        (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
    }
    updateHeightVar() {
        document.documentElement.style.setProperty('--spw-header-navigation-height', `${this.navEl.offsetHeight}px`);
    }
    redirectToHome(event) {
        event.preventDefault();
        window.location.href = '/';
    }
    handleExtraButtonClick(event) {
        if (this.emitExtraButtonClick) {
            event.preventDefault();
            this.extraButtonClick.emit();
        }
    }
    handleNavigation(event) {
        event.stopPropagation();
        this.element = event.detail.element;
        this.level = event.detail.level;
        setTimeout(() => {
            this.updateNavigationItems();
        }, 0);
    }
    updateNavigationItems() {
        const allItems = this.getAllNavigationItems();
        allItems.forEach((item, index) => {
            item.setAttribute('data-id', `${index + 1}`);
            item.setAttribute('data-level-visible', `${this.level}`);
        });
    }
    getAllNavigationItems() {
        const allItems = [];
        const navItems = this.el.querySelectorAll('spw-header-navigation-item');
        navItems.forEach(item => {
            allItems.push(item);
            const shadowRoot = item.shadowRoot;
            if (shadowRoot) {
                const subItems = shadowRoot.querySelectorAll('spw-header-navigation-item');
                subItems.forEach(subItem => allItems.push(subItem));
            }
        });
        return allItems;
    }
    get elementClass() {
        return {
            'spw-header-navigation': true,
            [`spw-header-navigation--${this.alignment}`]: true,
        };
    }
    render() {
        return (h(Host, { key: 'ac2118a592683fdc6961cbe3b22f029bad7f3b71' }, h("nav", { key: '8064b1837ef9242953ca26ce2a317088a133a2b1', class: this.elementClass, ref: el => (this.navEl = el) }, h("div", { key: '5f06b742dc2e878e78d4bd455402beefafa440fa', class: "spw-ds-container spw-tw-flex spw-tw-items-center spw-tw-justify-between" }, h("div", { key: '72f584fb1f157ee9e43fd6e23479d35e379030db', class: "spw-header-navigation__list" }, h("div", { key: '9d8f4efc5ef644acc29e3f69073c9b4844fd0634', class: "spw-header-navigation__list-back" }, h("a", { key: 'cdbc4b85a35dead9895ebaf3ab5d0b6bb9f53afb', href: "#", onClick: event => this.redirectToHome(event) }, h("spw-icon", { key: '1fd793a2af89859b10ab750ff1e3571d6be06b71', icon: "fa-chevron-left" }), " ", h("span", { key: '772bf755b33315d869441ec14cfce3f9560cc068' }, this.homepageLabel))), h("slot", { key: '1ec3f7286aecb1fda952a55128cd815b0ba0bff8' })), this.extraButton && (h("div", { key: '411ebac53887bc68f41d75c536461409f31f0957', class: "spw-header-navigation__extra-button spw-header-navigation__extra-button--desktop" }, h("spw-button", { key: '7cf70b535c90dd3394e8568a9a0966ce5cb430a5', variant: this.extraButtonVariant, icon: this.extraButtonIcon, "icon-position": this.extraButtonIconPosition, href: this.extraButtonHref, target: this.extraButtonTarget, size: "small", onClick: e => this.handleExtraButtonClick(e) }, this.extraButtonText))))), this.extraButton && (h("div", { key: 'bee2c3cc9ed83138c090c2be8fc95fe37b06436c', class: "spw-header-navigation__extra-button-parent spw-header-navigation__extra-button--mobile" }, h("div", { key: 'c547c7a11dc9dec1f7f103aefeabbd54dce406fd', class: "spw-ds-container" }, h("div", { key: '09bb291a662d91ade86c924999109c3c6e4a8518', class: "spw-header-navigation__extra-button spw-header-navigation__extra-button--mobile" }, h("spw-button", { key: '67dace8d9228b9a006767fb837e1ca8fe0e00519', "is-full-width": "true", variant: this.extraButtonVariant, icon: this.extraButtonIcon, href: this.extraButtonHref, target: this.extraButtonTarget, size: "small", onClick: e => this.handleExtraButtonClick(e) }, this.extraButtonText)))))));
    }
    static get is() { return "spw-header-navigation"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["spw-header-navigation.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["spw-header-navigation.css"]
        };
    }
    static get properties() {
        return {
            "alignment": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "'flex-start' | 'space-between'",
                    "resolved": "\"flex-start\" | \"space-between\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Alignement des \u00E9l\u00E9ments de navigation sur desktop"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "alignment",
                "defaultValue": "'flex-start'"
            },
            "extraButton": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Pr\u00E9sence ou non d'un bouton \u00E0 droite de la navigation"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "extra-button",
                "defaultValue": "false"
            },
            "extraButtonHref": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Sp\u00E9cifie le lien de l'extra button"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "extra-button-href"
            },
            "extraButtonTarget": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Attribut target de l'extra button"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "extra-button-target",
                "defaultValue": "'_self'"
            },
            "extraButtonText": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Texte de l'extra button"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "extra-button-text"
            },
            "extraButtonVariant": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "'primary' | 'secondary'",
                    "resolved": "\"primary\" | \"secondary\"",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Variant de l'extra button"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "extra-button-variant",
                "defaultValue": "'primary'"
            },
            "extraButtonIcon": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Ic\u00F4ne de l'extra button (r\u00E9f\u00E9rence font-awesome)"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "extra-button-icon"
            },
            "extraButtonIconPosition": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "'left' | 'right'",
                    "resolved": "\"left\" | \"right\"",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Position de l'ic\u00F4ne de l'extra button"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "extra-button-icon-position",
                "defaultValue": "'left'"
            },
            "emitExtraButtonClick": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Activer l'\u00E9mission d'\u00E9v\u00E9nement au clic de l'extra button au lieu de la navigation classique"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "emit-extra-button-click",
                "defaultValue": "false"
            },
            "homepageLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Texte du lien \"Page d'accueil\" dans la navigation mobile"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "homepage-label",
                "defaultValue": "\"Page d'accueil\""
            }
        };
    }
    static get states() {
        return {
            "level": {},
            "element": {}
        };
    }
    static get events() {
        return [{
                "method": "extraButtonClick",
                "name": "extraButtonClick",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "\u00C9v\u00E9nement \u00E9mis lors du clic sur l'extra button (si emitExtraButtonClick est activ\u00E9)"
                },
                "complexType": {
                    "original": "void",
                    "resolved": "void",
                    "references": {}
                }
            }];
    }
    static get elementRef() { return "el"; }
    static get listeners() {
        return [{
                "name": "spwHeaderNavigationNavigate",
                "method": "handleNavigation",
                "target": undefined,
                "capture": true,
                "passive": false
            }];
    }
}
