import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { r as renderHeaderLogin, d as renderHeaderLanguageSelector, f as renderHeaderSiteSelector, h as renderHeaderLogo, i as renderHeaderMenuSwitcher } from './pn-marketweb-header-shared.js';
import { d as defineCustomElement$g } from './pn-language-selector2.js';
import { d as defineCustomElement$f } from './pn-language-selector-option2.js';
import { d as defineCustomElement$e } from './pn-mainnav2.js';
import { d as defineCustomElement$d } from './pn-mainnav-level2.js';
import { d as defineCustomElement$c } from './pn-mainnav-link2.js';
import { d as defineCustomElement$b } from './pn-mainnav-list2.js';
import { d as defineCustomElement$a } from './pn-marketweb-header-toggle2.js';
import { d as defineCustomElement$9 } from './pn-marketweb-siteheader-login2.js';
import { d as defineCustomElement$8 } from './pn-marketweb-siteheader-login-button2.js';
import { d as defineCustomElement$7 } from './pn-marketweb-siteheader-login-linklist2.js';
import { d as defineCustomElement$6 } from './pn-marketweb-siteheader-login-links2.js';
import { d as defineCustomElement$5 } from './pn-marketweb-siteheader-login-profileselection2.js';
import { d as defineCustomElement$4 } from './pn-marketweb-siteheader-search2.js';
import { d as defineCustomElement$3 } from './pn-marketweb-siteheader-unified-login2.js';
import { d as defineCustomElement$2 } from './pn-site-selector2.js';
import { d as defineCustomElement$1 } from './pn-site-selector-item2.js';

/**
 * Adds a Home item at the beginning of the main menu when needed.
 *
 * What it does:
 * - Returns the input untouched when hideHomeMenuItem is true
 * - Avoids adding a duplicate Home item if one already exists first in the list
 * - Otherwise prepends a synthetic Home item using the translated label
 */
function prependHomeMenuItem(items, i18n, homeUrl, hideHomeMenuItem) {
    if (hideHomeMenuItem) {
        return items;
    }
    if (items[0]?.name === i18n.menuHomeButton) {
        return items;
    }
    return [
        {
            href: homeUrl,
            name: i18n.menuHomeButton,
            id: 'homelink',
            open: false,
            selected: false,
            children: [],
        },
        ...items,
    ];
}
/**
 * Creates a stable-ish tracking id for promoted menu items.
 *
 * This mirrors the old wrapper behavior and is used when rendering promoted links.
 */
function promotedItemId(item) {
    return 'promo-' + item.linkText.replace(/[^A-Za-z0-9.\\\/]/gim, '');
}

const pnMarketwebHeaderMainRowCss = "pn-button-dropdown .pn-button-dropdown>pn-button>.pn-button{min-height:initial}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);white-space:nowrap;border-width:0}@media screen and (max-width: 767px){.sr-only-mobile{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);white-space:nowrap;border-width:0}}pn-marketweb-header-main-row{display:contents}pn-marketweb-header-main-row .siteheader-row-main{background-color:var(--siteheader-main-row-bg-mobile, transparent)}pn-marketweb-header-main-row .siteheader-mobile-left{display:flex;align-items:center;flex:1 1 auto;min-width:0;order:1}pn-marketweb-header-main-row .siteheader-mobile-logo{display:flex;align-items:center;justify-content:flex-start;min-width:0;order:1}pn-marketweb-header-main-row .siteheader-mobile-logo .siteheader-logocontainer{min-height:5.6rem;background:transparent;position:static;left:auto;transform:none}pn-marketweb-header-main-row .siteheader-mobile-logo .siteheader-logolink{max-height:5.6rem}pn-marketweb-header-main-row .siteheader-mobile-logo .siteheader-logo{display:block;width:auto;max-width:12.7rem;height:2.4rem}pn-marketweb-header-main-row .siteheader-mobile-menu-toggle{display:none;align-items:center}pn-marketweb-header-main-row .siteheader-mainnav-middle{display:none;align-items:center;justify-content:flex-end;order:3}pn-marketweb-header-main-row .siteheader-mainnav-middle>pn-marketweb-siteheader-search{display:flex;align-items:center;justify-content:flex-end}pn-marketweb-header-main-row .siteheader-mainnav-middle>[slot=header-bottom-button]{display:contents}pn-marketweb-header-main-row .siteheader-mainnav-menu{display:flex;align-items:center;justify-content:flex-end;flex:0 0 auto;order:2}pn-marketweb-header-main-row .siteheader-mainnav-menu>[slot=mobile-toprightend]{display:flex;align-items:center;align-self:center;padding:1rem 0;margin-right:1.2rem;color:var(--siteheader-cart-link-color, var(--siteheader-top-link-color, inherit));text-decoration:none}pn-marketweb-header-main-row .siteheader-mainnav-menu>[slot=mobile-toprightend]>:not(pn-icon):not([data-cart-countindicator]){display:none}pn-marketweb-header-main-row .siteheader-mainnav-menu>[slot=mobile-toprightend] pn-icon svg>path{fill:var(--siteheader-cart-icon-color, var(--siteheader-top-icon-fill, currentColor))}pn-marketweb-header-main-row .siteheader-menu{max-width:100%;overflow:visible}pn-marketweb-header-main-row .siteheader-menu pn-mainnav-link a[target]::after{content:none}pn-marketweb-header-main-row .siteheader-menu pn-marketweb-siteheader-search{width:100%;padding:0.3rem 1.6rem}pn-marketweb-header-main-row .siteheader-menu [slot=top] pn-search-field{width:100%}pn-marketweb-header-main-row .siteheader-menu nav.mainnav[data-menu-open=true]>pn-mainnav-level[data-level=\"1\"]{display:block;margin-top:0;height:calc(100dvh - 0);overflow-y:auto;-webkit-overflow-scrolling:touch}pn-marketweb-header-main-row .siteheader-mainnav-groups{display:flex;flex-direction:column}pn-marketweb-header-main-row .siteheader-mainnav-list{overflow:visible}pn-marketweb-header-main-row .siteheader-mainnav-divider{display:none}pn-marketweb-header-main-row .siteheader-menu-footer{display:flex;flex-direction:column;align-items:center}pn-marketweb-header-main-row .siteheader-menu-footer>*{margin:1.6rem}body[data-siteheader-menuopen=false] pn-marketweb-header-main-row .siteheader-mobile-logo,body:not([data-siteheader-menuopen]) pn-marketweb-header-main-row .siteheader-mobile-logo{display:flex}body[data-siteheader-menuopen=false] pn-marketweb-header-main-row .siteheader-mobile-menu-toggle,body:not([data-siteheader-menuopen]) pn-marketweb-header-main-row .siteheader-mobile-menu-toggle{display:none}body[data-siteheader-menuopen=true] pn-marketweb-header-main-row .siteheader-mobile-logo{display:none}body[data-siteheader-menuopen=true] pn-marketweb-header-main-row .siteheader-mobile-menu-toggle{display:flex}@media screen and (min-width: 769px){pn-marketweb-header-main-row .siteheader-row-main{background-color:var(--siteheader-main-row-bg-tablet, transparent)}pn-marketweb-header-main-row .siteheader-mobile-left{display:none}pn-marketweb-header-main-row .siteheader-mainnav-middle{display:flex;margin-left:auto}pn-marketweb-header-main-row .siteheader-mainnav-menu{justify-content:flex-start}pn-marketweb-header-main-row .siteheader-mainnav-menu>[slot=mobile-toprightend]{display:none}pn-marketweb-header-main-row .siteheader-menu-footer{display:none}body[data-siteheader-menuopen=false] pn-marketweb-header-main-row .siteheader-mobile-logo,body:not([data-siteheader-menuopen]) pn-marketweb-header-main-row .siteheader-mobile-logo,body[data-siteheader-menuopen=true] pn-marketweb-header-main-row .siteheader-mobile-logo{display:flex}body[data-siteheader-menuopen=false] pn-marketweb-header-main-row .siteheader-mobile-menu-toggle,body:not([data-siteheader-menuopen]) pn-marketweb-header-main-row .siteheader-mobile-menu-toggle,body[data-siteheader-menuopen=true] pn-marketweb-header-main-row .siteheader-mobile-menu-toggle{display:none}}@media screen and (min-width: 1024px){pn-marketweb-header-main-row .siteheader-mainnav-groups{display:inline-flex;flex-direction:row;align-items:stretch;vertical-align:top}pn-marketweb-header-main-row .siteheader-mainnav-middle{order:3;margin-left:1.6rem}pn-marketweb-header-main-row .siteheader-mainnav-menu{order:2}pn-marketweb-header-main-row .siteheader-menu{margin-top:auto;overflow:visible}pn-marketweb-header-main-row .siteheader-menu nav.mainnav[data-menu-open=true]>pn-mainnav-level[data-level=\"1\"]{margin-top:0;height:auto;overflow-y:visible}pn-marketweb-header-main-row .siteheader-mainnav-list{display:inline-flex;align-items:stretch;vertical-align:top}pn-marketweb-header-main-row .siteheader-mainnav-divider{display:inline-flex;align-self:center;width:1px;min-height:4rem;margin:0 0.8rem;background:var(--siteheader-mainnav-divider-color, #d3cecb)}}";
const PnMarketwebHeaderMainRowStyle0 = pnMarketwebHeaderMainRowCss;

const PnMarketwebHeaderMainRow = /*@__PURE__*/ proxyCustomElement(class PnMarketwebHeaderMainRow extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.vm = undefined;
        this.i18n = undefined;
        this.market = undefined;
        this.language = undefined;
        this.siteid = undefined;
        this.hideSearch = undefined;
        this.hideLogin = undefined;
        this.hideLanguageSelector = undefined;
        this.hideSiteSelector = undefined;
        this.minimizeSearch = undefined;
        this.activeMenuMode = undefined;
        this.navigateOnMenuToggle = undefined;
        this.primaryItems = undefined;
        this.sharedItems = undefined;
        this.showMenuDivider = undefined;
        this.userToken = undefined;
        this.userFullname = undefined;
        this.userLoggedin = undefined;
        this.endpoint = undefined;
        this.environment = undefined;
        this.showProfileSelection = undefined;
        this.showUnifiedLogin = undefined;
        this.checkUserLoggedInStateInterval = undefined;
        this.useMarketwebLogin = undefined;
        this.spaMode = undefined;
        this.theme = undefined;
        this.logoUrl = undefined;
        this.menuToggleChangeHandler = undefined;
        this.mainNavRefHandler = undefined;
        this.adjustSiteSelectorUrl = undefined;
    }
    renderMenuLink(item) {
        return (h("pn-mainnav-link", { name: item.name, href: item.href, itemid: item.id, target: item.linkTarget ?? '_self', linkid: item.trackingId }, ((item.promotedMenuItems && item.promotedMenuItems.length > 0) || (item.children && item.children.length > 0)) && (h("pn-mainnav-level", { label: item.name }, !!item.children?.length && (h("pn-mainnav-list", { heading: item.navigationHeading ?? '' }, item.children.map(childitem => (h("pn-mainnav-link", { name: childitem.name, href: childitem.href, target: childitem.linkTarget ?? '_self', linkid: childitem.trackingId }))))), !!item.promotedMenuItems?.length && (h("pn-mainnav-list", { heading: item.promotedMenuItemsHeader }, item.promotedMenuItems.map((childitem) => (h("pn-mainnav-link", { href: childitem.href, name: childitem.linkText, target: childitem.openInNewWindow ? '_blank' : '_self', linkid: promotedItemId(childitem) + item.id })))))))));
    }
    renderMenuLinks(items) {
        return items.map(item => this.renderMenuLink(item));
    }
    renderGroupedMenuLists(primaryItems, sharedItems) {
        const hasPrimaryItems = primaryItems.length > 0;
        const hasSharedItems = sharedItems.length > 0;
        const hasDivider = hasPrimaryItems && hasSharedItems;
        return h("div", { class: "siteheader-mainnav-groups" }, hasPrimaryItems ? (h("pn-mainnav-list", { class: "siteheader-mainnav-list siteheader-mainnav-list-primary" }, this.renderMenuLinks(primaryItems))) : null, hasDivider ? (h("div", { class: "siteheader-mainnav-divider", "aria-hidden": "true" })) : null, hasSharedItems ? (h("pn-mainnav-list", { class: "siteheader-mainnav-list siteheader-mainnav-list-shared" }, this.renderMenuLinks(sharedItems))) : null);
    }
    renderMenuFooter(appearance) {
        return (h("div", { slot: "footer", class: "siteheader-menu-footer" }, h("slot", { name: "menu-footer-cta" }), renderHeaderLogin({
            vm: this.vm,
            hideLogin: this.hideLogin,
            userToken: this.userToken,
            userFullname: this.userFullname,
            userLoggedin: this.userLoggedin,
            endpoint: this.endpoint,
            environment: this.environment,
            i18n: this.i18n,
            showProfileSelection: this.showProfileSelection,
            showUnifiedLogin: this.showUnifiedLogin,
            checkUserLoggedInStateInterval: this.checkUserLoggedInStateInterval,
            useMarketwebLogin: this.useMarketwebLogin,
            appearance
        }), renderHeaderLanguageSelector({
            vm: this.vm,
            hideLanguageSelector: this.hideLanguageSelector,
            language: this.language,
            spaMode: this.spaMode,
            appearance
        }), renderHeaderSiteSelector({
            vm: this.vm,
            hideSiteSelector: this.hideSiteSelector,
            language: this.language,
            appearance,
            adjustSiteSelectorUrl: this.adjustSiteSelectorUrl,
        })));
    }
    render() {
        // main row's subcomponent have light appearance even if business theme, since white bg
        const appearance = 'light';
        return (h("div", { key: '6569068aa71f831c64d80ae49841c52c422aafee', class: "siteheader-row siteheader-row-main" }, h("div", { key: 'd80d94ad7d42ad0e6dd4f17793470e3b99e1259b', class: "siteheader-mobile-left" }, h("div", { key: '8f15ec3f0912eff80b9b2b1b5110f9d8d5be340b', class: "siteheader-mobile-logo" }, renderHeaderLogo({
            homePageLink: this.logoUrl, //this.vm.homePageLink,
            homeLabel: this.i18n.home,
        })), this.vm.hasMenuSwitching && (h("div", { key: 'cd7e5b59db027518655aa6b64ca7d41c50439df8', class: "siteheader-mobile-menu-toggle" }, renderHeaderMenuSwitcher({
            vm: this.vm,
            activeMenuMode: this.activeMenuMode,
            navigateOnMenuToggle: this.navigateOnMenuToggle,
            onMenuToggleChange: this.menuToggleChangeHandler,
        })))), h("div", { key: '1e1602ae9fa7a24e67c4210c349fa11c647cbc61', class: "siteheader-mainnav-middle" }, h("pn-marketweb-siteheader-search", { key: '56b70f0de0d1eb0818f9be8b29f6aab4a33436ce', language: this.language, siteid: this.siteid, primary: true, search: this.vm.search, "hide-search": this.hideSearch, "show-only-link": this.minimizeSearch, i18n: this.i18n }), h("slot", { key: '3a2a912c7578588245a306e0a69b19ba4fe6f07b', name: "header-bottom-button" })), h("div", { key: '950031e00ce843cb258fe41a019d2d291484355e', class: "siteheader-mainnav-menu" }, h("slot", { key: '5d162a549fa86c35ae1df1a70d8fa891676115c9', name: "mobile-toprightend" }), h("div", { key: '590c867a2b6c21b32677583050455464ec3d7256', class: "siteheader-menu" }, h("pn-mainnav", { key: '22e04f8724b186aa428ec79f1779b79c9c4fdaa0', ref: el => {
                this.mainNavRefHandler(el);
            }, market: this.market, language: this.language, onMenuOpenChange: e => {
                document.body.setAttribute('data-siteheader-menuopen', String(e.detail));
            } }, h("pn-mainnav-level", { key: '67a41d3f1fda939b23f8115fa8a0358f75f44422' }, this.showMenuDivider ? (this.renderGroupedMenuLists(this.primaryItems, this.sharedItems)) : (h("pn-mainnav-list", null, this.renderMenuLinks(this.primaryItems))), this.renderMenuFooter(appearance), h("div", { key: 'f4c378b80d938530e5fe28bbedb48c080f4edb35', slot: "top", class: "siteheader-menu-top" }, h("pn-marketweb-siteheader-search", { key: '7dd680e6a0e3286e988b86d27e2d916e29171e98', language: this.language, siteid: this.siteid, search: this.vm.search, "hide-search": this.hideSearch, i18n: this.i18n }))))))));
    }
    static get style() { return PnMarketwebHeaderMainRowStyle0; }
}, [4, "pn-marketweb-header-main-row", {
        "vm": [16],
        "i18n": [16],
        "market": [1],
        "language": [1],
        "siteid": [1],
        "hideSearch": [4, "hide-search"],
        "hideLogin": [4, "hide-login"],
        "hideLanguageSelector": [4, "hide-language-selector"],
        "hideSiteSelector": [4, "hide-site-selector"],
        "minimizeSearch": [4, "minimize-search"],
        "activeMenuMode": [2, "active-menu-mode"],
        "navigateOnMenuToggle": [4, "navigate-on-menu-toggle"],
        "primaryItems": [16],
        "sharedItems": [16],
        "showMenuDivider": [4, "show-menu-divider"],
        "userToken": [1, "user-token"],
        "userFullname": [1, "user-fullname"],
        "userLoggedin": [4, "user-loggedin"],
        "endpoint": [1],
        "environment": [1],
        "showProfileSelection": [4, "show-profile-selection"],
        "showUnifiedLogin": [4, "show-unified-login"],
        "checkUserLoggedInStateInterval": [2, "check-user-logged-in-state-interval"],
        "useMarketwebLogin": [4, "use-marketweb-login"],
        "spaMode": [4, "spa-mode"],
        "theme": [1],
        "logoUrl": [1, "logo-url"],
        "menuToggleChangeHandler": [16],
        "mainNavRefHandler": [16],
        "adjustSiteSelectorUrl": [16]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["pn-marketweb-header-main-row", "pn-language-selector", "pn-language-selector-option", "pn-mainnav", "pn-mainnav-level", "pn-mainnav-link", "pn-mainnav-list", "pn-marketweb-header-toggle", "pn-marketweb-siteheader-login", "pn-marketweb-siteheader-login-button", "pn-marketweb-siteheader-login-linklist", "pn-marketweb-siteheader-login-links", "pn-marketweb-siteheader-login-profileselection", "pn-marketweb-siteheader-search", "pn-marketweb-siteheader-unified-login", "pn-site-selector", "pn-site-selector-item"];
    components.forEach(tagName => { switch (tagName) {
        case "pn-marketweb-header-main-row":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, PnMarketwebHeaderMainRow);
            }
            break;
        case "pn-language-selector":
            if (!customElements.get(tagName)) {
                defineCustomElement$g();
            }
            break;
        case "pn-language-selector-option":
            if (!customElements.get(tagName)) {
                defineCustomElement$f();
            }
            break;
        case "pn-mainnav":
            if (!customElements.get(tagName)) {
                defineCustomElement$e();
            }
            break;
        case "pn-mainnav-level":
            if (!customElements.get(tagName)) {
                defineCustomElement$d();
            }
            break;
        case "pn-mainnav-link":
            if (!customElements.get(tagName)) {
                defineCustomElement$c();
            }
            break;
        case "pn-mainnav-list":
            if (!customElements.get(tagName)) {
                defineCustomElement$b();
            }
            break;
        case "pn-marketweb-header-toggle":
            if (!customElements.get(tagName)) {
                defineCustomElement$a();
            }
            break;
        case "pn-marketweb-siteheader-login":
            if (!customElements.get(tagName)) {
                defineCustomElement$9();
            }
            break;
        case "pn-marketweb-siteheader-login-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$8();
            }
            break;
        case "pn-marketweb-siteheader-login-linklist":
            if (!customElements.get(tagName)) {
                defineCustomElement$7();
            }
            break;
        case "pn-marketweb-siteheader-login-links":
            if (!customElements.get(tagName)) {
                defineCustomElement$6();
            }
            break;
        case "pn-marketweb-siteheader-login-profileselection":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "pn-marketweb-siteheader-search":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "pn-marketweb-siteheader-unified-login":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "pn-site-selector":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "pn-site-selector-item":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { PnMarketwebHeaderMainRow as P, defineCustomElement as d, prependHomeMenuItem as p };

//# sourceMappingURL=pn-marketweb-header-main-row2.js.map