import { h, Host } from "@stencil/core";
import { state as headerState } from "./pn-marketweb-siteheader-store";
export class PnMarketwebSiteheaderLoginLinks {
    constructor() {
        this.loginDialog = null;
        this.idNamespace = '';
        this.loggedin = false;
        this.username = '';
        this.showUnifiedLogin = false;
    }
    hostElement;
    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 = headerState.loginManager.getLogoutUrl(link.href);
            }
            link.href = link.href.replace('window.location.href', window.location.href);
            if (i === 0 && !link.href) {
                link.href = headerState.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: headerState.loginManager.getLoginUrl(this.loginDialog.loginUrl),
                linkText: this.loginDialog.loginLinkText,
                openInNewWindow: false,
                isLogoutLink: false,
                pageLink: null,
                linkType: 'primary',
                primaryLinkApperance: true,
            },
            {
                href: headerState.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 is() { return "pn-marketweb-siteheader-login-links"; }
    static get originalStyleUrls() {
        return {
            "$": ["pn-marketweb-siteheader-login-links.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["pn-marketweb-siteheader-login-links.css"]
        };
    }
    static get properties() {
        return {
            "loginDialog": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "LoginDialog",
                    "resolved": "LoginDialog",
                    "references": {
                        "LoginDialog": {
                            "location": "import",
                            "path": "./pn-marketweb-siteheader-types",
                            "id": "src/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-types.ts::LoginDialog"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "defaultValue": "null"
            },
            "idNamespace": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "id-namespace",
                "reflect": false,
                "defaultValue": "''"
            },
            "loggedin": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "loggedin",
                "reflect": true,
                "defaultValue": "false"
            },
            "username": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "username",
                "reflect": false,
                "defaultValue": "''"
            },
            "showUnifiedLogin": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "show-unified-login",
                "reflect": false,
                "defaultValue": "false"
            }
        };
    }
    static get elementRef() { return "hostElement"; }
    static get watchers() {
        return [{
                "propName": "loginDialog",
                "methodName": "init"
            }];
    }
}
//# sourceMappingURL=pn-marketweb-siteheader-login-links.js.map
