'use strict';

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

const spwHeaderLangCss = () => `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-lang{position:relative}@media (max-width: 1023px){.spw-header-lang{margin-bottom:0}}@media (min-width: 1024px){.spw-header-lang:hover .spw-header-lang__dropdown{display:block}}.spw-header-lang spw-button{--spw-button-text-decoration-tertiary:none}.spw-header-lang__select{display:none}@media (min-width: 1024px){.spw-header-lang__select{display:block;position:absolute;top:0;left:0;width:100%;height:100%;opacity:0;cursor:pointer;z-index:2}}.spw-header-lang__active-lang{display:none}@media (min-width: 1024px){.spw-header-lang__active-lang{display:block}}.spw-header-lang__options{display:flex;gap:24px;text-transform:uppercase}@media (min-width: 1024px){.spw-header-lang__options{display:none}}.spw-header-lang__option{padding:16px 0;font-weight:bold;text-decoration:underline}.spw-header-lang__option--selected{color:var(--spw-ds-primary);text-decoration:none}@media (min-width: 1024px){.spw-header-lang__option{padding:24px 0}}.spw-header-lang__dropdown{display:flex}@media (min-width: 1024px){.spw-header-lang__dropdown{display:none;z-index:99999;position:absolute;overflow:hidden;top:100%;width:max-content;right:0;background:white;border-radius:4px;box-shadow:var(--spw-effect-elevation-8)}}`;

const SpwHeaderLang = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.langChange = index.createEvent(this, "langChange", 7);
        this.activeLang = '';
        this.options = [];
        this.handleButtonKeyDown = (event) => {
            var _a;
            if (event.key === ' ' || event.key === 'Enter') {
                event.preventDefault();
                (_a = this.selectEl) === null || _a === void 0 ? void 0 : _a.click();
            }
        };
        this.handleButtonClick = () => {
            var _a;
            (_a = this.selectEl) === null || _a === void 0 ? void 0 : _a.click();
        };
        this.handleOptionClick = (option) => {
            this.setActiveLangAndRedirect(option);
        };
    }
    componentDidLoad() {
        this.moveOptionsToSelect();
    }
    moveOptionsToSelect() {
        var _a;
        const lightDomOptions = Array.from(this.el.querySelectorAll('option'));
        this.options = lightDomOptions;
        const selectedOption = lightDomOptions.find(opt => opt.hasAttribute('selected') || opt.selected);
        lightDomOptions.forEach(option => {
            this.selectEl.appendChild(option);
        });
        if (selectedOption) {
            this.activeLang = ((_a = selectedOption.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
        }
    }
    handleChange(event) {
        const target = event.target;
        const selectedOption = target.selectedOptions[0];
        this.setActiveLangAndRedirect(selectedOption);
    }
    setActiveLangAndRedirect(option) {
        var _a;
        this.activeLang = ((_a = option === null || option === void 0 ? void 0 : option.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
        const value = (option === null || option === void 0 ? void 0 : option.getAttribute('value')) || '';
        this.langChange.emit(value);
        const link = option === null || option === void 0 ? void 0 : option.getAttribute('data-link');
        if (link && link !== '#') {
            window.location.href = link;
        }
    }
    render() {
        return (index.h(index.Host, { key: '06242ab720bf430b9fc2b2f3dee6792465511ab9' }, index.h("div", { key: 'bb3a9606231b8bf69b6e19346223b52044bfb280', class: "spw-header-lang" }, index.h("spw-button", { key: '02c5b7db54c98c34a5a67c2ed50a42b43bb43861', variant: "tertiary", surface: "light", icon: "fa-chevron-down", class: "spw-header-lang__active-lang", onKeyDown: this.handleButtonKeyDown, onClick: this.handleButtonClick }, this.activeLang), index.h("select", { key: '247fe0ac8ac870da425f52e41f239921529fdf70', "aria-label": this.accAriaLabel || 'Lang', class: "spw-header-lang__select", onChange: e => this.handleChange(e), ref: el => (this.selectEl = el), tabIndex: -1 }), index.h("ul", { key: 'a5b041a4630a55593243ff102ee0738eb8efb2ea', class: "spw-header-lang__options" }, this.options.map(option => {
            var _a;
            const label = ((_a = option.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
            const value = option.getAttribute('value') || '';
            const isSelected = label === this.activeLang;
            return (index.h("li", { class: { 'spw-header-lang__option': true, 'spw-header-lang__option--selected': isSelected }, "data-value": value, onClick: () => this.handleOptionClick(option) }, label));
        })))));
    }
    get el() { return index.getElement(this); }
};
SpwHeaderLang.style = spwHeaderLangCss();

exports.spw_header_lang = SpwHeaderLang;
