import { h, Host } from "@stencil/core";
export class SpwHeaderPersona {
    constructor() {
        /** 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 }))));
    }
    static get is() { return "spw-header-persona"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["spw-header-persona.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["spw-header-persona.css"]
        };
    }
    static get properties() {
        return {
            "personaLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Label pour le choix du persona (\u00E0 appliquer sur spw-header-persona)"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "persona-label",
                "defaultValue": "'Je suis :'"
            },
            "accAriaLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Remplit l'attribut aria-label, utilis\u00E9 \u00E0 des fins d'accessibilit\u00E9"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "acc-aria-label"
            }
        };
    }
    static get states() {
        return {
            "activePersona": {},
            "options": {}
        };
    }
    static get elementRef() { return "el"; }
}
