'use strict';

var index = require('./index-DuCXzb-X.js');

const spwHeaderNavigationCss = () => `html{line-height:1.3;-webkit-text-size-adjust:100%;}h1,h2,h3,h4,h5,h6,p,ul,li{padding:0;margin:0}ul{list-style:none}:host{box-sizing:border-box;line-height:1.3;-webkit-text-size-adjust:100%;font-size:100%}:host *,:host *::before,:host *::after{box-sizing:inherit;font-family:var(--spw-ds-font-main)}body{margin:0}hr{box-sizing:content-box;height:0;overflow:visible;}pre{font-family:monospace, monospace;font-size:1em;}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted;}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace, monospace;font-size:1em;}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0;}button,input{overflow:visible}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button}button::-moz-focus-inner,[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal;}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0;}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px;}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit;}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}:root{--spw-ds-container-xl:1232px;--spw-ds-container-lg:1024px;--spw-ds-container-md:768px;--spw-ds-container-sm:640px}.spw-ds-container{width:100%;padding-left:16px;padding-right:16px;margin-left:auto;margin-right:auto}@media (min-width: 460px){.spw-ds-container{max-width:var(--spw-ds-container-sm)}}@media (min-width: 768px){.spw-ds-container{max-width:var(--spw-ds-container-md)}}@media (min-width: 1024px){.spw-ds-container{max-width:var(--spw-ds-container-lg)}}@media (min-width: 1350px){.spw-ds-container{max-width:var(--spw-ds-container-xl)}}:host{display:contents}.spw-header-navigation{display:none;left:0;width:100%;height:calc(100% - 80px);background:white;z-index:9999;overflow-y:auto;order:2;border-top:1px solid var(--spw-colors-support-grey-grey-300)}:host(.spw-ds-nav-open) .spw-header-navigation{display:flex;flex-direction:column}@media (min-width: 1024px){.spw-header-navigation{order:initial;display:block;height:auto;width:auto;overflow-y:initial;top:auto;left:auto;z-index:30}}@media (min-width: 1024px){:host(.spw-ds-search-open) .spw-header-navigation{display:none}}.spw-header-navigation__extra-button-parent{padding:16px;order:2;border-top:1px solid var(--spw-colors-support-grey-grey-300)}@media (min-width: 1024px){.spw-header-navigation__extra-button{padding-left:32px}}.spw-header-navigation__extra-button--desktop{display:none}@media (min-width: 1024px){.spw-header-navigation__extra-button--desktop{display:block}}.spw-header-navigation__extra-button--mobile{display:none}@media (max-width: 1023px){:host(.spw-ds-nav-open) .spw-header-navigation__extra-button--mobile{display:block}}.spw-header-navigation .spw-ds-container{position:relative}.spw-header-navigation__list{position:static;display:flex;flex:1;align-items:center;flex-direction:column;width:calc(100% + 32px);margin-left:-16px;margin-right:-16px}@media (min-width: 1024px){.spw-header-navigation__list{flex-direction:row}.spw-header-navigation--flex-start .spw-header-navigation__list{justify-content:flex-start}.spw-header-navigation--space-between .spw-header-navigation__list{justify-content:space-between}}@media (min-width: 1350px){.spw-header-navigation__list{gap:24px}}.spw-header-navigation__list-back{display:flex;justify-content:left;width:100%;padding:24px 16px;padding-bottom:0;position:relative;z-index:3}.spw-header-navigation__list-back:after{content:"";position:absolute;bottom:-1px;width:100%;left:0;height:1px;background:white}.spw-header-navigation__list-back a{gap:8px;display:flex;justify-content:left;align-items:center;font-weight:700;font-size:14px;text-decoration:none;color:var(--spw-colors-support-grey-grey-900)}.spw-header-navigation__list-back a span{text-decoration:underline}.spw-header-navigation__list-back a spw-icon{font-size:18px}@media (min-width: 1024px){.spw-header-navigation__list-back{display:none}}.spw-tw-flex{display:flex}.spw-tw-items-center{align-items:center}.spw-tw-justify-between{justify-content:space-between}`;

const SpwHeaderNavigation = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.extraButtonClick = index.createEvent(this, "extraButtonClick", 7);
        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 (index.h(index.Host, { key: 'ac2118a592683fdc6961cbe3b22f029bad7f3b71' }, index.h("nav", { key: '8064b1837ef9242953ca26ce2a317088a133a2b1', class: this.elementClass, ref: el => (this.navEl = el) }, index.h("div", { key: '5f06b742dc2e878e78d4bd455402beefafa440fa', class: "spw-ds-container spw-tw-flex spw-tw-items-center spw-tw-justify-between" }, index.h("div", { key: '72f584fb1f157ee9e43fd6e23479d35e379030db', class: "spw-header-navigation__list" }, index.h("div", { key: '9d8f4efc5ef644acc29e3f69073c9b4844fd0634', class: "spw-header-navigation__list-back" }, index.h("a", { key: 'cdbc4b85a35dead9895ebaf3ab5d0b6bb9f53afb', href: "#", onClick: event => this.redirectToHome(event) }, index.h("spw-icon", { key: '1fd793a2af89859b10ab750ff1e3571d6be06b71', icon: "fa-chevron-left" }), " ", index.h("span", { key: '772bf755b33315d869441ec14cfce3f9560cc068' }, this.homepageLabel))), index.h("slot", { key: '1ec3f7286aecb1fda952a55128cd815b0ba0bff8' })), this.extraButton && (index.h("div", { key: '411ebac53887bc68f41d75c536461409f31f0957', class: "spw-header-navigation__extra-button spw-header-navigation__extra-button--desktop" }, index.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 && (index.h("div", { key: 'bee2c3cc9ed83138c090c2be8fc95fe37b06436c', class: "spw-header-navigation__extra-button-parent spw-header-navigation__extra-button--mobile" }, index.h("div", { key: 'c547c7a11dc9dec1f7f103aefeabbd54dce406fd', class: "spw-ds-container" }, index.h("div", { key: '09bb291a662d91ade86c924999109c3c6e4a8518', class: "spw-header-navigation__extra-button spw-header-navigation__extra-button--mobile" }, index.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)))))));
    }
    get el() { return index.getElement(this); }
};
SpwHeaderNavigation.style = spwHeaderNavigationCss();

exports.spw_header_navigation = SpwHeaderNavigation;
