import { h, Host } from "@stencil/core";
import { FetchHelper } from "../../../globals/FetchHelper";
import { MarketWebContextService } from "../../../globals/MarketWebContextService";
import { state as headerState } from "./pn-marketweb-siteheader-store";
import { translations } from "./translations";
/**
 * @slot topleft - Text
 * @slot logo - Text
 * @slot toprightstart - Text
 * @slot toprightend - Text
 * @slot siteheader-menu-top-button - Text
 * @slot menu-footer-cta - Text
 * @slot header-bottom-button - Text
 */
export class PnMarketwebSiteheader {
    constructor() {
        this.market = null;
        this.language = null;
        this.siteid = null;
        this.environment = null;
        this.userToken = '';
        this.userFullname = '';
        this.userLoggedin = false;
        this.endpoint = null;
        this.hideSiteSelector = false;
        this.hideHomeMenuItem = false;
        this.hideLanguageSelector = false;
        this.hideSearch = false;
        this.hideLogin = false;
        this.showProfileSelection = false;
        this.showUnifiedLogin = false;
        this.siteDomainInUrls = false;
        this.AutocompleteEndpoint = '';
        this.sessionForward = false;
        this.cache = false;
        this.searchPlaceholder = '';
        this.spaMode = false;
        this.checkUserLoggedInStateInterval = 0;
        this.useMarketwebLogin = false;
        this.pageId = '';
        this.i18n = {
            searchlabel: '',
            searchplaceholder: '',
            searchbuttontext: '',
            menuHomeButton: '',
            menuGoBackButton: '',
            mainMenuButton: '',
            menuStartButton: '',
            profileSelectionFlyoutHeading: '',
            unifiedLoginButton: '',
            unifiedMyPagesButton: '',
            home: 'Home'
        };
        this.gotData = false;
        this.fetchingData = false;
        this.homePageLink = '/';
        this.menuItems = [];
        this.siteDefinition = undefined;
        this.search = { AutocompleteEndpoint: this.AutocompleteEndpoint };
        this.siteSelector = null;
        this.languageSelector = null;
        this.languageOptions = [];
        this.loginDialog = null;
        this.minimizeSearch = false;
        this.loggedIn = false;
    }
    hostElement;
    endpointPath = '/api/navigation/header';
    // FetchHelper
    fetchHelper = new FetchHelper('siteheader');
    // // Login manager
    // @State() loginManager: MarketWebLoginManager = null;
    // Events
    changeLanguage;
    // Events
    changeMarket;
    componentWillLoad() {
        this.setInitialValues().then(() => {
            this.init();
        });
    }
    async setInitialValues(href = window.location.href) {
        const marketWebContextService = new MarketWebContextService(href);
        if (!this.market) {
            const resolvedMarket = await marketWebContextService.getMarket();
            this.market = resolvedMarket;
        }
        if (!this.language) {
            const resolvedMarket = await marketWebContextService.getLanguage();
            this.language = resolvedMarket;
        }
        if (!this.environment) {
            this.environment = await marketWebContextService.getEnvironmentName();
        }
        if (!this.endpoint && this.environment?.indexOf('local') === -1) {
            this.endpoint = await marketWebContextService.getEndpoint(this.environment, this.market);
        }
        if (!this.endpoint) {
            this.endpoint = '';
        }
    }
    async init() {
        this.setTranslations();
        await this.fetchData();
        window.setTimeout(() => {
            this.checkMenuOverflow();
        }, 50);
    }
    setTranslations() {
        if (this.language && translations[this.language]) {
            this.i18n = translations[this.language];
        }
        if (this.searchPlaceholder) {
            this.i18n.searchplaceholder = this.searchPlaceholder;
        }
    }
    onLanguageSelectorChange(e) {
        this.language = e.detail;
        window.dispatchEvent(new CustomEvent('marketweb-languagechange', { detail: this.language }));
    }
    onLanguageChange() {
        this.setTranslations();
        this.changeLanguage.emit(this.language);
        this.fetchData();
    }
    onMarketChange() {
        this.changeMarket.emit(this.market);
        this.fetchData();
    }
    async fetchData() {
        if (this.endpoint === null || !this.market || !this.language) {
            // console.warn(`One or more values where not specified.\nEndpoint: ${this.endpoint}\nMarket: ${this.market}\nLanguage: ${this.language}`)
            return;
        }
        this.fetchingData = true;
        const endpointBase = this.endpoint.lastIndexOf('/') === this.endpoint.length - 1 ? this.endpoint.substring(0, this.endpoint.length - 1) : this.endpoint;
        const fetchUrl = `${endpointBase}${this.endpointPath}?market=${this.market}&language=${this.language}&currentPage=${this.pageId}`;
        const data = (await this.fetchHelper.fetchJson(fetchUrl, {
            mode: 'cors',
        }, this.cache));
        // const data2 = JSON.parse('{"query":{"market":"se","language":"sv","currentPage":""},"sitedefinition":{"name":"Postnord Sweden","url":"https://localhost:51547/"},"search":{"formActionUrl":"https://localhost:51547/sok/","useAutocompleteInHeaderSearch":true,"hideSearchFromHeader":false,"preferredSiteId":"06bb4e57-cf10-4374-9e4d-34ae987eff2e"},"languageSelectorViewModel":{"currentLanguageNativeName ":"Svenska","languages":[{"twoLetterISOLanguageName":"en","nativeName":"English","isCurrent":false},{"twoLetterISOLanguageName":"sv","nativeName":"Svenska","isCurrent":true},{"twoLetterISOLanguageName":"da","nativeName":"Dansk","isCurrent":false},{"twoLetterISOLanguageName":"tr","nativeName":"Türkçe","isCurrent":false}],"hideLanguageSelectorFromHeader":false},"siteSelectorViewModel":{"siteSelectorButtonText":"postnord.se","siteSelectorTitle":"PostNord","currentSiteTitle":"postnord.se","currentSiteDescription":"Tjänster och verktyg för att skicka och ta emot din post","siteSelections":[{"linkText":"Portal","linkDescription":"Hantera dina försändelser","pageLink":"https://portal.postnord.com/","openInNewWindow":false,"href":"https://portal.postnord.com/"},{"linkText":"postnord.com","linkDescription":"Information om PostNord Koncernen","pageLink":"/link/7d10839b295946bbb54bebcb289f3aff.aspx","openInNewWindow":false,"href":"https://com-inte.postnord.com/sv/"}],"hideSiteSelectorFromHeader":false},"loginViewModel":{"loginMenuLinks":[{"linkText":"Handla online","pageLink":"/login?language=sv&returnUrl=https://se-inte.postnord.com/handla-online","openInNewWindow":false,"primaryLinkApperance":false,"linkType":"regularlink","href":"/login?language=sv&returnUrl=https://se-inte.postnord.com/handla-online"},{"linkText":"Business portal","pageLink":"https://atportal.postnord.com/api/unified-login/backend/authorization?redirectionUrl=https://se-inte.postnord.com","openInNewWindow":false,"primaryLinkApperance":false,"linkType":"regularlink","href":"https://atportal.postnord.com/api/unified-login/backend/authorization?redirectionUrl=https://se-inte.postnord.com"},{"linkText":"Ombudsbutiken","pageLink":"https://se-inte.postnord.com/login?returnUrl=https://se-inte.postnord.com/handla-online&type=agent","openInNewWindow":false,"primaryLinkApperance":false,"linkType":"regularlink","href":"https://se-inte.postnord.com/login?returnUrl=https://se-inte.postnord.com/handla-online&type=agent"}],"loggedInLinks":[{"linkText":"Logga ut","pageLink":"http://window.location.href/?logout","openInNewWindow":false,"primaryLinkApperance":false,"linkType":null,"href":"http://window.location.href/?logout"}],"overrideLoginMenu":false,"loginMenuLinkText":"Logga in","countryCode":"SE","locale":"sv","loginUrl":"https://portal.postnord.com/login?language=sv","registerUrl":"https://portal.postnord.com/createaccount?market=SE","loggedInButtonText":"My PostNord","loginTitle":"Logga in direkt på:","loginLinkText":"Logga in","createLoginLinkText":"Skapa nytt konto","hideLoginFromHeader":false,"showProfileSelection":true,"checkUserLoginStateInterval":20000,"showUnifiedLogin":true,"loginInfo":"","eshopStartPageUrl":"/handla-online/"},"mainMenu":{"menuItems":[{"name":"Privat","href":"/privat2/","id":"102118","selected":false,"open":false,"children":[{"name":"Skicka","href":"/privat2/skicka/","id":"102119","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"skicka102119","level":2},{"name":"Ta emot","href":"/privat2/ta-emot/","id":"102135","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"taemot102135","level":2},{"name":"Priser och villkor","href":"/privat2/priser-och-villkor/","id":"102162","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"priserochvillkor102162","level":2},{"name":"Förberedelser","href":"/privat2/forberedelser/","id":"102173","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"frberedelser102173","level":2}],"navigationHeading":"","promotedMenuItemsHeader":"Populärt","promotedMenuItems":[{"linkText":"PostNord App","pageLink":"/link/05dcebb0c20b4b56806f4736d83b773d.aspx","href":"https://localhost:51547/vara-verktyg/postnord-app/","openInNewWindow":false},{"linkText":"Digitalt frimärke","pageLink":"https://portal.postnord.com/skickadirekt/m/?productId=800","href":"https://portal.postnord.com/skickadirekt/m/?productId=800","openInNewWindow":false},{"linkText":"Köp frakt","pageLink":"https://portal.postnord.com/skickadirekt/m/","href":"https://portal.postnord.com/skickadirekt/m/","openInNewWindow":false},{"linkText":"Sök utdelningsdag","pageLink":"/link/701d85d2a8924b7a8da0dd86f049debe.aspx","href":"https://localhost:51547/vara-verktyg/sok-utdelningsdag/","openInNewWindow":false},{"linkText":"Paketbox","pageLink":"/link/aca5b66a6f6c45ae97ecd7d5f176d512.aspx","href":"https://localhost:51547/privat/ta-emot/hamta/hamta-paket-i-paketbox/","openInNewWindow":false},{"linkText":"Skicka brev och paket","pageLink":"/link/8b60c612e9824ccb905fc260c50f69f5.aspx","href":"https://localhost:51547/privat/skicka/brev-och-paket/","openInNewWindow":false}],"hasChildren":true,"linkTarget":"","trackingId":"privat102118","level":1},{"name":"Företag","href":"/foretag2/","id":"102743","selected":false,"open":false,"children":[{"name":"Skicka","href":"/foretag2/skicka/","id":"102744","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"skicka102744","level":2},{"name":"Ta emot","href":"/foretag2/ta-emot/","id":"102826","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"taemot102826","level":2},{"name":"Priser och villkor","href":"/foretag2/priser-och-villkor/","id":"102845","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"priserochvillkor102845","level":2},{"name":"Förberedelser","href":"/foretag2/forberedelser/","id":"102855","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"frberedelser102855","level":2},{"name":"Företagslösningar","href":"/foretag2/foretagslosningar/","id":"102883","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"fretagslsningar102883","level":2}],"navigationHeading":"","promotedMenuItemsHeader":"Populärt","promotedMenuItems":[{"linkText":"Bli avtalskund","pageLink":"/link/1fb879eb737747f2afc442df11ff99b5.aspx","href":"https://localhost:51547/kundservice/bli-avtalskund/","openInNewWindow":false},{"linkText":"PEX Bud","pageLink":"/link/b1209ba46788420a8e9b5c7f06e570ad.aspx?productId=800","href":"https://localhost:51547/foretag/skicka-forsandelser/pex-bud/?productId=800","openInNewWindow":false},{"linkText":"Köp frakt","pageLink":"https://portal.postnord.com/shippingtoolpro","href":"https://portal.postnord.com/shippingtoolpro","openInNewWindow":true},{"linkText":"Portal Business","pageLink":"/link/c97df117dc9c427f90b1e95c1fa8caae.aspx","href":"https://localhost:51547/vara-verktyg/postnord-portal/","openInNewWindow":false},{"linkText":"Skicka brev och paket","pageLink":"/link/a65c6b42681f4230b927f776bfc8662a.aspx","href":"https://localhost:51547/foretag/skicka-forsandelser/brev-och-vykort/","openInNewWindow":false}],"hasChildren":true,"linkTarget":"","trackingId":"fretag102743","level":1},{"name":"Handla online","href":"/handla-online/","id":"57674","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"handlaonline57674","level":1},{"name":"Kundservice","href":"/kundservice-faq/","id":"167","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"kundservice167","level":1},{"name":"Handla online temp redirect","href":"/handla-online-new/","id":"74849","selected":false,"open":false,"children":[],"navigationHeading":"","promotedMenuItemsHeader":"","promotedMenuItems":[],"hasChildren":false,"linkTarget":"","trackingId":"handlaonlinetempredirect74849","level":1}]}}');
        // console.log(data2);
        await this.setStateFromData(data);
    }
    getLanguageVersionUrl(item) {
        if (this.spaMode) {
            return null;
        }
        const alternativeTag = document.querySelector(`link[rel="alternate"][hreflang="${item.twoLetterISOLanguageName}"]`);
        if (alternativeTag) {
            return alternativeTag.getAttribute('href');
        }
        const siteUrl = this.siteDefinition.url;
        // Add trailing slash to domain if it's missing
        return siteUrl + (siteUrl.lastIndexOf('/') !== siteUrl.length - 1 ? '/' : '') + item.twoLetterISOLanguageName;
    }
    async setStateFromData(data) {
        if (typeof data !== 'object') {
            console.warn('Data was not valid', data);
        }
        // Set site definition
        this.siteDefinition = data.sitedefinition;
        if (headerState.loginManager) {
            headerState.loginManager.setSiteUrl(this.siteDefinition.url);
        }
        let updatedMenuItems = [];
        // Set navigation information
        if (this.siteDomainInUrls) {
            updatedMenuItems = data.mainMenu.menuItems.map(item => {
                return this.adjustMenuItemUrls(item);
            });
        }
        else {
            updatedMenuItems = data.mainMenu.menuItems;
        }
        // Create the "Home" link
        if ((!updatedMenuItems[0] || updatedMenuItems[0]?.name !== this.i18n.menuHomeButton) && !this.hideHomeMenuItem) {
            updatedMenuItems.unshift({
                href: this.siteDefinition.url,
                name: this.i18n.menuHomeButton,
                id: 'homelink',
                open: false,
                selected: false,
                children: [],
            });
        }
        this.menuItems = updatedMenuItems;
        // Set search
        this.search = { ...data.search, ...{ AutocompleteEndpoint: this.AutocompleteEndpoint } };
        // Set site selector
        this.siteSelector = data.siteSelectorViewModel;
        // Set language selector
        this.languageSelector = data.languageSelectorViewModel;
        this.setLanguageOptions();
        let loginDialog = data.loginViewModel;
        if (loginDialog && this.siteDomainInUrls) {
            loginDialog.loggedInLinks = loginDialog.loggedInLinks.map(item => {
                item.href = this.adjustHref(item.href);
                return item;
            });
            loginDialog.loginMenuLinks = loginDialog.loginMenuLinks.map(item => {
                item.href = this.adjustHref(item.href);
                return item;
            });
        }
        this.loginDialog = loginDialog;
        await this.spaModeAdjustments();
        this.gotData = true;
        this.fetchingData = true;
        this.homePageLink = this.siteDefinition?.url ?? document.location.hostname;
        window.setTimeout(() => {
            this.checkMenuOverflow();
        }, 100);
    }
    adjustMenuItemUrls(item) {
        item.href = this.adjustHref(item.href);
        if (item.children && item.children.length > 0) {
            let adjustedItems = item.children.map(item => {
                return this.adjustMenuItemUrls(item);
            });
            item.children = adjustedItems;
        }
        return item;
    }
    adjustHref(href) {
        if (href.indexOf('http') === 0) {
            return href;
        }
        const domainUrl = this.siteDefinition.url.lastIndexOf('/') === this.siteDefinition.url.length - 1
            ? this.siteDefinition.url.substring(0, this.siteDefinition.url.length - 1)
            : this.siteDefinition.url;
        return this.removeDoubleLanguage(domainUrl + href);
    }
    removeDoubleLanguage(url) {
        let languageSegment = this.language.toLocaleLowerCase() + "/";
        let doubleLanguageSegment = "/" + languageSegment + languageSegment;
        if (url.includes(doubleLanguageSegment)) {
            return url.replace(doubleLanguageSegment, "/" + languageSegment);
        }
        return url;
    }
    setLanguageOptions() {
        if (!this.languageSelector || !this.languageSelector.languages) {
            return;
        }
        const hrefLangsTags = Array.prototype.slice.call(document.querySelectorAll('link[rel="alternate"][hreflang]')) ?? [];
        const hrefLangs = hrefLangsTags.map(tag => {
            let hrefLangValue = tag.getAttribute('hreflang');
            if (hrefLangValue.indexOf('en-') !== -1 || hrefLangValue.indexOf('en_') !== -1) {
                hrefLangValue = hrefLangValue.substring(0, 2);
            }
            return hrefLangValue;
        });
        let languageOptions = []; // Reset language options
        this.languageSelector.languages.map((languageOption) => {
            // In case there are language links present on the page we only show languages that have those tags
            if (hrefLangs && hrefLangs.length > 0) {
                if (hrefLangs.includes(languageOption.twoLetterISOLanguageName)) {
                    languageOptions.push(languageOption);
                }
            }
            else {
                languageOptions.push(languageOption);
            }
        });
        this.languageOptions = languageOptions; // Replace existing language options so we don't trigger a event change on every push.
    }
    async spaModeAdjustments() {
        if (!this.spaMode) {
            return;
        }
        return;
    }
    onLoginStateChange(e) {
        if (e.detail?.loggedIn && e.detail?.token) {
            this.loggedIn = e.detail?.loggedIn === true;
            if (this.sessionForward) {
                try {
                    //fetch('/api/userprofile/sync?token=' + e.detail.token);
                }
                catch (e) { }
            }
        }
    }
    promotedItemId(item) {
        return 'promo-' + item.linkText.replace(/[^A-Za-z0-9.\\\/]/gim, '');
    }
    handleResize() {
        requestAnimationFrame(() => {
            this.checkMenuOverflow();
        });
    }
    checkMenuOverflow() {
        const row = this.hostElement.querySelectorAll('.siteheader-row')[1];
        if (!row) {
            return;
        }
        const firstMenuLevel = row.querySelector('pn-mainnav-level');
        if (!firstMenuLevel) {
            return;
        }
        const parent = firstMenuLevel.parentElement;
        if (parent.tagName.toLocaleLowerCase() !== 'nav') {
            return;
        }
        const parentWidth = parent.scrollWidth;
        const elmWidth = firstMenuLevel.clientWidth;
        const isOverFlowed = parentWidth < elmWidth;
        if (isOverFlowed && this.minimizeSearch === false) {
            this.minimizeSearch = true;
        }
    }
    adjustSiteSelectorUrl(href) {
        if (!this.loggedIn) {
            return href;
        }
        const loginDomains = ['portal.postnord.com'];
        const matchedHref = loginDomains.filter(domain => {
            return href.indexOf(domain) !== -1;
        });
        if (matchedHref.length === 0) {
            return href;
        }
        if (headerState.loginManager) {
            return headerState.loginManager.getLoginUrl(href);
        }
        return href;
    }
    getFallbackValue(value, fallback) {
        return value && value.trim() !== '' ? value : fallback;
    }
    render() {
        const i18n = {
            ...this.i18n,
            home: this.getFallbackValue(this.i18n.home, 'Home')
        };
        return (h(Host, { key: '4dbc8b4f6ebc9b88d32a13ea049634102db18aa9', language: this.language, market: this.market, environment: this.environment }, h("header", { key: '54ff0d3ec7ba8cf53be40bd618c52f0afbcd14af' }, h("div", { key: '6e94c37ea02cd37b6e22aa3aad75f491db15a0b1', class: "siteheader-row" }, h("div", { key: '37e15b37ee1ba498ef461dee9a98eb2c1d7083c8', class: "siteheader-topleft" }, h("slot", { key: 'a7bff14d795adeda2bffedcbe3079bf829f83636', name: "topleft" }), this.gotData && this.siteSelector && !this.hideSiteSelector && (h("pn-site-selector", { key: '1ceb79e1cbd0879d42e62b51a9c4093420428c2e', language: this.language, buttontext: this.siteSelector?.currentSiteTitle ?? 'postnord' }, this.gotData && this.siteSelector?.currentSiteTitle && (h("pn-site-selector-item", { key: '029d93ca69e47f30f0925535ae6dd160ac5d1efb', heading: this.siteSelector.currentSiteTitle + ' ', description: this.siteSelector.currentSiteDescription })), this.gotData &&
            this.siteSelector?.siteSelections &&
            this.siteSelector.siteSelections.map(site => (h("pn-site-selector-item", { heading: site.linkText + ' ', description: site.linkDescription, url: this.adjustSiteSelectorUrl(site.href), newwindow: site.openInNewWindow })))))), h("div", { key: 'af65a947739e929885aa8e4d11ed354fdb8aa686', class: "siteheader-logocontainer" }, h("a", { key: '0afed48d2b7a7cb5118576626b56423c6d060b62', href: this.homePageLink, title: i18n.home, "aria-label": i18n.home, class: "siteheader-logolink" }, h("slot", { key: 'b74a01e3a624c170b3ebc68e1e3feeede5e8a886', name: "logo" }, h("svg", { key: 'dac6467faf89d4d78108d8b04f495219bec3773d', class: "siteheader-logo", xmlns: "http://www.w3.org/2000/svg", width: "12.7rem", height: "2.4rem", viewBox: "0 0 141.73 26.65", role: "img", "aria-label": "PostNord" }, h("path", { key: 'eabc5a6f31e85cd5fa112dca7052739af8edd495', d: "M108.84,13.35c0,6.34-5.17,9-10,9S89,19.76,89,13.63c0-6.28,5.08-9,10-9S108.84,7.25,108.84,13.35Zm-6.56.18a3.4,3.4,0,1,0-6.8,0,3.29,3.29,0,0,0,3.42,3.41A3.24,3.24,0,0,0,102.28,13.54Zm-83,0c0,4.83-3.32,8.82-8.49,8.82a6.54,6.54,0,0,1-4.65-1.57v5.86H0V5.16H6.17V6.8a6.43,6.43,0,0,1,5.11-2.18C16.41,4.62,19.31,8.58,19.31,13.54Zm-6.53,0A3.27,3.27,0,0,0,9.4,10,3.28,3.28,0,0,0,6,13.54,3.29,3.29,0,0,0,9.4,16.95,3.24,3.24,0,0,0,12.78,13.54Zm103.69,0.27c0-2.54,1.54-3.32,3.6-3.32a6.56,6.56,0,0,1,2.08.3L122.3,5.1a3.92,3.92,0,0,0-1.45-.18c-3.45,0-4.38,2.18-4.38,2.18V5.16H110.3V21.84h6.17v-8ZM141.73,0V21.84h-6.16V20.21a6.43,6.43,0,0,1-5.11,2.18c-5.14,0-8-4-8-8.91s3.32-8.82,8.49-8.82a6.54,6.54,0,0,1,4.65,1.57v-5Zm-6,13.48a3.28,3.28,0,0,0-3.41-3.41A3.24,3.24,0,0,0,129,13.47,3.4,3.4,0,1,0,135.75,13.47ZM81.35,4.62c-3.6,0-4.9,2.18-4.9,2.18V5.16H70.29V21.84h6.16V13.29c0-2.11.79-3.08,2.69-3.08s2.18,1.57,2.18,3.57v8.07h6.22V11.6C87.55,7,85.34,4.62,81.35,4.62ZM64.07,1.42H57.9V21.84h6.16V10.36H67l2.81-5.2H64.07V1.42ZM50.26,11.21c-2-.3-2.87-0.3-2.87-1.09s0.81-.94,2.42-0.94a16.15,16.15,0,0,1,5.11.91L56,5.41a24.56,24.56,0,0,0-6.13-.75c-5.89,0-9,2.27-9,5.89,0,2.81,1.66,4.47,6.53,5.11,2.06,0.27,2.81.39,2.81,1.15s-0.82,1-2.24,1a16.67,16.67,0,0,1-6-1.3L40.77,21.3a22.14,22.14,0,0,0,6.68,1c6.35,0,9.28-2.24,9.28-5.89C56.72,13.54,55.15,12,50.26,11.21ZM40.19,13.35c0,6.34-5.17,9-10,9s-9.82-2.6-9.82-8.73c0-6.28,5.08-9,10-9S40.19,7.25,40.19,13.35Zm-6.56.18a3.4,3.4,0,1,0-6.8,0,3.28,3.28,0,0,0,3.41,3.41A3.24,3.24,0,0,0,33.63,13.54Z", fill: "#00A0D6", transform: "translate(0 0)" }))))), h("div", { key: '5a1797b2d053f57533720a86260bf6753459820a', class: "siteheader-topright" }, h("slot", { key: '32c6e37f5f7a053f6006a0d7ee800dd75d56af7e', name: "toprightstart" }), this.gotData && this.loginDialog && !this.hideLogin && (h("pn-marketweb-siteheader-login", { key: '2ba7f32275f005e6093e68ce509b46fe626e5270', token: this.userToken, siteUrl: this.siteDefinition.url, fullname: this.userFullname, loggedin: this.userLoggedin, loginDialog: this.loginDialog, endpoint: this.endpoint, i18n: this.i18n, showProfileSelection: this.showProfileSelection, showUnifiedLogin: this.showUnifiedLogin, "check-user-logged-in-state-interval": this.checkUserLoggedInStateInterval, useMarketwebLogin: this.useMarketwebLogin, environment: this.environment })), this.gotData && this.languageOptions && this.languageOptions.length && !this.hideLanguageSelector && (h("pn-language-selector", { key: '6b78edccaa3b588f10f34369faffccbe76e6a447', value: this.language }, this.languageOptions.map(language => (h("pn-language-selector-option", { name: language.nativeName, code: language.twoLetterISOLanguageName, selected: language.isCurrent, url: this.getLanguageVersionUrl(language) }))))), h("slot", { key: '6cf88ca335d133dc6b1b1d154af1e21a94f858c6', name: "toprightend" }), h("div", { key: '44a1201e8286c5fe9005a12bf1d0ddf5c403853d', class: "siteheader-menu-top-search" }, h("pn-marketweb-siteheader-search", { key: '4253cba910de7490b57b2979d52415a62f297046', language: this.language, siteid: this.siteid, search: this.search, "hide-search": this.hideSearch, i18n: this.i18n, icononly: true })))), h("slot", { key: 'ed811eff451199a26337d21522c1cc551219ba9f', name: "siteheader-menu-top-button" }), h("div", { key: '9bbbfd43251c6a7204ccd7ecc0a964cd1e7e56ee', class: "siteheader-row" }, h("div", { key: 'bea362557ce1eba32baeb084dccb803ebde28753', class: "siteheader-menu" }, this.gotData && this.menuItems && (h("pn-mainnav", { key: 'ec2cc997ddf61a3e00878788e0e74d9205136e29', market: this.market, language: this.language, onMenuOpenChange: e => {
                document.body.setAttribute('data-siteheader-menuopen', e.detail + '');
            } }, h("pn-mainnav-level", { key: '8fe758a817428e24a9d71aae6e461d720e26186f' }, h("pn-mainnav-list", { key: '1e9709adbe2a8dfb585516ded4639ed280ccab32' }, this.menuItems.map(item => (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 > 0 && (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 && item.promotedMenuItems.length > 0 && (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: this.promotedItemId(childitem) + item.id }))))))))))), h("div", { key: '11717d2fa356f9592d6d3b71e2bbbc20b6a7d904', slot: "footer", class: "siteheader-menu-footer" }, h("slot", { key: '71b2a52803a8e0789e1a3df1bc4fb1ee8eebdf50', name: "menu-footer-cta" }), this.gotData && this.loginDialog && !this.hideLogin && (h("pn-marketweb-siteheader-login", { key: '6c7d438166d192447e43c4bd36dfc851115c0a03', token: this.userToken, siteUrl: this.siteDefinition.url, loginDialog: this.loginDialog, endpoint: this.endpoint, fullname: this.userFullname, loggedin: this.userLoggedin, i18n: this.i18n, showProfileSelection: this.showProfileSelection, showUnifiedLogin: this.showUnifiedLogin, environment: this.environment, "check-user-logged-in-state-interval": this.checkUserLoggedInStateInterval, useMarketwebLogin: this.useMarketwebLogin })), this.gotData && this.languageOptions && this.languageOptions.length && !this.hideLanguageSelector && (h("pn-language-selector", { key: '11a1a7d881541ecbab6fedbfe1f4ba7fa833538e', value: this.language }, this.languageOptions.map(language => (h("pn-language-selector-option", { name: language.nativeName, code: language.twoLetterISOLanguageName, selected: language.isCurrent, url: this.getLanguageVersionUrl(language) }))))), !this.hideSiteSelector && (h("pn-site-selector", { key: 'ffc1aafc17a626e459bd5c02b432af60e5d4bde5', language: this.language }, this.gotData && this.siteSelector?.currentSiteTitle && (h("pn-site-selector-item", { key: '6bbf6bee34ed07db3e89a6f8f8bb72ef189d3227', heading: this.siteSelector.currentSiteTitle, description: this.siteSelector.currentSiteDescription })), this.gotData &&
            this.siteSelector?.siteSelections &&
            this.siteSelector.siteSelections.map(site => (h("pn-site-selector-item", { heading: site.linkText, description: site.linkDescription, url: site.pageLink, newwindow: site.openInNewWindow })))))), h("div", { key: '1e4836bdc8ae8ad1e1b5d014ee6ac078ac4b1bdf', slot: "top", class: "siteheader-menu-top" }, h("pn-marketweb-siteheader-search", { key: 'a423b1dfe80b2baa2875abd764b2aa3c43866f3c', language: this.language, siteid: this.siteid, search: this.search, "hide-search": this.hideSearch, i18n: this.i18n })))))), h("pn-marketweb-siteheader-search", { key: '82e455c1c11b476cad6c13a69bddccc6051be51e', language: this.language, siteid: this.siteid, primary: true, search: this.search, "hide-search": this.hideSearch, "show-only-link": this.minimizeSearch, i18n: this.i18n }), h("slot", { key: '06eac1b150538bf75079ed50d7dd0a1aeabe5e88', name: "header-bottom-button" })))));
    }
    static get is() { return "pn-marketweb-siteheader"; }
    static get originalStyleUrls() {
        return {
            "$": ["pn-marketweb-siteheader.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["pn-marketweb-siteheader.css"]
        };
    }
    static get properties() {
        return {
            "market": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Specifies which market we want to show (se,dk,fi,no,com)"
                },
                "attribute": "market",
                "reflect": true,
                "defaultValue": "null"
            },
            "language": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Specifies which language we want to show (sv,da,fi,no,en)"
                },
                "attribute": "language",
                "reflect": true,
                "defaultValue": "null"
            },
            "siteid": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Specifies the current site id (guid)"
                },
                "attribute": "siteid",
                "reflect": false,
                "defaultValue": "null"
            },
            "environment": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Specifies which environment we're fetching data from. (production, preproduction, integration, localhost)"
                },
                "attribute": "environment",
                "reflect": true,
                "defaultValue": "null"
            },
            "userToken": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Access token passed from backend"
                },
                "attribute": "user-token",
                "reflect": false,
                "defaultValue": "''"
            },
            "userFullname": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "User Fullname"
                },
                "attribute": "user-fullname",
                "reflect": false,
                "defaultValue": "''"
            },
            "userLoggedin": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "User Logged in state from the backend"
                },
                "attribute": "user-loggedin",
                "reflect": true,
                "defaultValue": "false"
            },
            "endpoint": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Specifies which endpoint domain we should load from"
                },
                "attribute": "endpoint",
                "reflect": false,
                "defaultValue": "null"
            },
            "hideSiteSelector": {
                "type": "boolean",
                "mutable": true,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Hides the site selector if set to true"
                },
                "attribute": "hide-site-selector",
                "reflect": true,
                "defaultValue": "false"
            },
            "hideHomeMenuItem": {
                "type": "boolean",
                "mutable": true,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Hides the \"home\" menu item in the navigation if set to true"
                },
                "attribute": "hide-home-menu-item",
                "reflect": true,
                "defaultValue": "false"
            },
            "hideLanguageSelector": {
                "type": "boolean",
                "mutable": true,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Hides the language selector if set to true"
                },
                "attribute": "hide-language-selector",
                "reflect": true,
                "defaultValue": "false"
            },
            "hideSearch": {
                "type": "boolean",
                "mutable": true,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Hides the search form if set to true"
                },
                "attribute": "hide-search",
                "reflect": true,
                "defaultValue": "false"
            },
            "hideLogin": {
                "type": "boolean",
                "mutable": true,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Hides the login if set to true"
                },
                "attribute": "hide-login",
                "reflect": true,
                "defaultValue": "false"
            },
            "showProfileSelection": {
                "type": "boolean",
                "mutable": true,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If this is selected we will show the new profile selection dropdown instead of the login version"
                },
                "attribute": "show-profile-selection",
                "reflect": true,
                "defaultValue": "false"
            },
            "showUnifiedLogin": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "if this is selected we will show the unified-login button aswell as a new look for dropdown menu"
                },
                "attribute": "show-unified-login",
                "reflect": false,
                "defaultValue": "false"
            },
            "siteDomainInUrls": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Adjusts the menus URLs"
                },
                "attribute": "site-domain-in-urls",
                "reflect": false,
                "defaultValue": "false"
            },
            "AutocompleteEndpoint": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Autocomplete endpoint"
                },
                "attribute": "autocomplete-endpoint",
                "reflect": false,
                "defaultValue": "''"
            },
            "sessionForward": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Forward session to backend"
                },
                "attribute": "session-forward",
                "reflect": false,
                "defaultValue": "false"
            },
            "cache": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If the component should use cached requests"
                },
                "attribute": "cache",
                "reflect": false,
                "defaultValue": "false"
            },
            "searchPlaceholder": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Header search placeholder"
                },
                "attribute": "search-placeholder",
                "reflect": false,
                "defaultValue": "''"
            },
            "spaMode": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Event based only language switch"
                },
                "attribute": "spa-mode",
                "reflect": false,
                "defaultValue": "false"
            },
            "checkUserLoggedInStateInterval": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Continiously check if a user is logged in *"
                },
                "attribute": "check-user-logged-in-state-interval",
                "reflect": false,
                "defaultValue": "0"
            },
            "useMarketwebLogin": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "use-marketweb-login",
                "reflect": false,
                "defaultValue": "false"
            },
            "pageId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "page-id",
                "reflect": false,
                "defaultValue": "''"
            }
        };
    }
    static get states() {
        return {
            "i18n": {},
            "gotData": {},
            "fetchingData": {},
            "homePageLink": {},
            "menuItems": {},
            "siteDefinition": {},
            "search": {},
            "siteSelector": {},
            "languageSelector": {},
            "languageOptions": {},
            "loginDialog": {},
            "minimizeSearch": {},
            "loggedIn": {}
        };
    }
    static get events() {
        return [{
                "method": "changeLanguage",
                "name": "changeLanguage",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }, {
                "method": "changeMarket",
                "name": "changeMarket",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }];
    }
    static get elementRef() { return "hostElement"; }
    static get watchers() {
        return [{
                "propName": "language",
                "methodName": "onLanguageChange"
            }, {
                "propName": "market",
                "methodName": "onMarketChange"
            }];
    }
    static get listeners() {
        return [{
                "name": "setLanguage",
                "method": "onLanguageSelectorChange",
                "target": undefined,
                "capture": false,
                "passive": false
            }, {
                "name": "loginStateChange",
                "method": "onLoginStateChange",
                "target": undefined,
                "capture": false,
                "passive": false
            }, {
                "name": "resize",
                "method": "handleResize",
                "target": "window",
                "capture": false,
                "passive": true
            }];
    }
}
//# sourceMappingURL=pn-marketweb-siteheader.js.map
