import { r as registerInstance, h, H as Host, a as getElement } from './index-Co4V4Zk-.js';

const spwHeaderPersonaCss = () => `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:block}.spw-header-persona{position:relative}@media (max-width: 1023px){.spw-header-persona{border-bottom:1px solid var(--spw-colors-support-grey-grey-300);padding-top:16px;padding-bottom:16px}}@media (min-width: 1024px){.spw-header-persona{display:flex;flex-wrap:wrap;align-items:center;gap:6px;padding-left:24px;margin-left:24px;margin-right:12px;border-left:1px solid var(--spw-colors-support-grey-grey-300)}}.spw-header-persona__label{font-size:14px;display:block;color:var(--spw-colors-support-grey-grey-700)}@media (max-width: 1023px){.spw-header-persona__label{display:none}}.spw-header-persona__active-persona{position:relative;display:flex;gap:6px;justify-content:space-between;cursor:pointer;font-weight:bold;text-decoration:none;color:var(--spw-colors-support-grey-grey-900)}@media (min-width: 1024px){.spw-header-persona__active-persona{transition:all ease 0.15s;border-radius:var(--spw-ds-border-radius-full);background:var(--spw-colors-support-grey-grey-100);padding:8px 12px;font-size:14px}}@media (min-width: 1024px){.spw-header-persona__active-persona:has(~.spw-header-persona__select:hover),.spw-header-persona__active-persona:hover{background:var(--spw-colors-support-grey-grey-300)}}.spw-header-persona__active-persona:focus-visible{outline:2px solid var(--spw-ds-focus);outline-offset:2px;border-radius:var(--spw-ds-border-radius-full)}.spw-header-persona__trigger{display:block}.spw-header-persona--opened .spw-header-persona__trigger{transform:rotate(180deg)}.spw-header-persona__select{display:block;position:absolute;top:0;left:0;width:100%;height:100%;opacity:0;cursor:pointer;z-index:2}.spw-header-persona__dropdown{display:none;overflow:hidden}.spw-header-persona--opened .spw-header-persona__dropdown{display:block}@media (min-width: 1024px){.spw-header-persona--opened .spw-header-persona__dropdown{position:absolute;width:max-content;z-index:99999;background:white;border-radius:4px;box-shadow:var(--spw-effect-elevation-8)}}`;

const SpwHeaderPersona = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        /** Label pour le choix du persona (à appliquer sur spw-header-persona) */
        this.personaLabel = 'Je suis :';
        this.activePersona = '';
        this.options = [];
        this.handleButtonClick = () => {
            var _a;
            (_a = this.selectEl) === null || _a === void 0 ? void 0 : _a.click();
        };
        this.handleButtonKeyDown = (event) => {
            var _a;
            if (event.key === ' ' || event.key === 'Enter') {
                event.preventDefault();
                (_a = this.selectEl) === null || _a === void 0 ? void 0 : _a.click();
            }
        };
    }
    componentWillLoad() {
        this.setInitialPersona();
    }
    componentDidLoad() {
        this.moveOptionsToSelect();
    }
    setInitialPersona() {
        var _a;
        const selected = this.el.querySelector('option[selected]');
        this.activePersona = ((_a = selected === null || selected === void 0 ? void 0 : selected.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
    }
    moveOptionsToSelect() {
        const lightDomOptions = Array.from(this.el.querySelectorAll('option'));
        this.options = lightDomOptions;
        lightDomOptions.forEach(option => {
            this.selectEl.appendChild(option);
        });
    }
    handleChange(event) {
        var _a;
        const select = event.target;
        const selectedOption = select.selectedOptions[0];
        this.activePersona = ((_a = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
        const link = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.getAttribute('data-link');
        if (link) {
            window.location.href = link;
        }
    }
    render() {
        return (h(Host, { key: 'e4b59a2e369219aaa37bd9feda07a8ea744b2237' }, h("div", { key: '1052b05e702b3a5ac280aaece9943960f40aece8', class: "spw-header-persona", onClick: this.handleButtonClick, onKeyDown: this.handleButtonKeyDown }, h("span", { key: 'a49eda95727e18bbde6a8b5da032d1232e31ac1b', class: "spw-header-persona__label" }, this.personaLabel), h("div", { key: '4193bf378aaf026f5b6f3fc645e8b780d947e854', class: "spw-header-persona__active-persona" }, this.activePersona, " ", h("spw-icon", { key: 'd78a9e006c8c84126d219c229235247efbd513e7', icon: "fa-chevron-down" })), h("select", { key: '3d8af10298b497fcd10f9428b3bdef0277d4b11c', "aria-label": this.accAriaLabel || this.personaLabel, class: "spw-header-persona__select", ref: el => (this.selectEl = el), onChange: e => this.handleChange(e), tabIndex: -1 }))));
    }
    get el() { return getElement(this); }
};
SpwHeaderPersona.style = spwHeaderPersonaCss();

export { SpwHeaderPersona as spw_header_persona };
