import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { s as state, d as defineCustomElement$1 } from './pn-marketweb-siteheader-login-linklist2.js';

const pnMarketwebSiteheaderLoginLinksCss = "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}}";
const PnMarketwebSiteheaderLoginLinksStyle0 = pnMarketwebSiteheaderLoginLinksCss;

const PnMarketwebSiteheaderLoginLinks = /*@__PURE__*/ proxyCustomElement(class PnMarketwebSiteheaderLoginLinks extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.loginDialog = null;
        this.idNamespace = '';
        this.loggedin = false;
        this.username = '';
        this.showUnifiedLogin = false;
    }
    get hostElement() { return this; }
    componentWillLoad() {
        this.init();
    }
    async init() {
        this.adjustLoginLinks();
    }
    adjustLoginLinks() {
        if (!this.loginDialog) {
            return;
        }
        const adjustLink = (link, i) => {
            if (!link.isLogoutLink) {
                link.isLogoutLink = link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1;
            }
            if (link.isLogoutLink) {
                link.href = state.loginManager.getLogoutUrl(link.href);
            }
            link.href = link.href.replace('window.location.href', window.location.href);
            if (i === 0 && !link.href) {
                link.href = state.loginManager.getLoginUrl();
                link.linkType = 'primary';
            }
            if (link.primaryLinkApperance && !link.linkType) {
                link.linkType = 'primary';
            }
        };
        if (this.loginDialog?.loginMenuLinks) {
            this.loginDialog?.loginMenuLinks.forEach(adjustLink);
        }
        if (this.loginDialog?.loggedInLinks) {
            this.loginDialog?.loggedInLinks.forEach(adjustLink);
        }
        this.loginDialog.legacyLoginLinks = [
            {
                href: state.loginManager.getLoginUrl(this.loginDialog.loginUrl),
                linkText: this.loginDialog.loginLinkText,
                openInNewWindow: false,
                isLogoutLink: false,
                pageLink: null,
                linkType: 'primary',
                primaryLinkApperance: true,
            },
            {
                href: state.loginManager.getLoginUrl(this.loginDialog.registerUrl),
                linkText: this.loginDialog.createLoginLinkText,
                openInNewWindow: false,
                isLogoutLink: false,
                pageLink: null,
                primaryLinkApperance: false,
            },
        ];
    }
    render() {
        if (!this.loginDialog) {
            return;
        }
        let hostElementAttribute = {
            username: null,
            loggedin: false,
        };
        if (this.username) {
            hostElementAttribute.username = this.username;
            hostElementAttribute.loggedin = this.loggedin;
        }
        return (h(Host, { ...hostElementAttribute }, !this.loginDialog.overrideLoginMenu ? (h("div", { "data-loggedin": this.loggedin + '' }, this.loggedin ? (h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.loggedInLinks, idNamespace: this.idNamespace })) : (h("div", null, this.loginDialog.loginMenuLinks?.length > 0 ? (h("pn-marketweb-siteheader-login-linklist", { heading: this.loginDialog.loginTitle, links: this.loginDialog.loginMenuLinks, idNamespace: this.idNamespace, showUnifiedLogin: this.showUnifiedLogin })) : (h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.legacyLoginLinks, idNamespace: this.idNamespace })))))) : null, this.loginDialog.overrideLoginMenu ? (h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.loginMenuLinks, idNamespace: this.idNamespace })) : null));
    }
    static get watchers() { return {
        "loginDialog": ["init"]
    }; }
    static get style() { return PnMarketwebSiteheaderLoginLinksStyle0; }
}, [0, "pn-marketweb-siteheader-login-links", {
        "loginDialog": [1040],
        "idNamespace": [1, "id-namespace"],
        "loggedin": [516],
        "username": [1],
        "showUnifiedLogin": [4, "show-unified-login"]
    }, undefined, {
        "loginDialog": ["init"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["pn-marketweb-siteheader-login-links", "pn-marketweb-siteheader-login-linklist"];
    components.forEach(tagName => { switch (tagName) {
        case "pn-marketweb-siteheader-login-links":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, PnMarketwebSiteheaderLoginLinks);
            }
            break;
        case "pn-marketweb-siteheader-login-linklist":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { PnMarketwebSiteheaderLoginLinks as P, defineCustomElement as d };

//# sourceMappingURL=pn-marketweb-siteheader-login-links2.js.map