import { h, Host } from "@stencil/core";
import { state as headerState } from "./pn-marketweb-siteheader-store";
import { arrow_right, transfer } from "pn-design-assets/pn-assets/icons.js";
export class PnMarketwebSiteheaderLoginLinklist {
    constructor() {
        this.heading = null;
        this.links = [];
        this.idNamespace = '';
        this.showUnifiedLogin = false;
    }
    hostElement;
    componentWillLoad() { }
    uniqueId(text) {
        return 'loginlink-' + text.replace(/[^A-Za-z0-9.\\\/]/gim, '') + '-' + this.idNamespace;
    }
    linkAppearanceAttributes(link) {
        let attributes = {};
        if (link.linkType) {
            switch (link.linkType) {
                case 'primary':
                    attributes = {
                        appearance: '',
                        variant: '',
                    };
                    break;
                case 'secondary':
                    attributes = {
                        appearance: 'light',
                        variant: 'outlined',
                    };
                    break;
                case 'regularlink':
                default:
                    attributes = {
                        appearance: 'light',
                        variant: 'borderless',
                        icon: arrow_right,
                    };
                    break;
            }
            return attributes;
        }
        if (!link.linkType) {
            attributes = {
                appearance: link.primaryLinkApperance ? 'dark' : 'light',
            };
        }
        return attributes;
    }
    renderListAsButtons(link) {
        return (h("li", null, h("pn-button", { href: link.href, id: this.uniqueId(link.linkText), ...(link.openInNewWindow && { target: '_blank' }), ...this.linkAppearanceAttributes(link), onClick: () => {
                if (link.isLogoutLink) {
                    headerState.loginManager.clearUserData();
                }
            } }, link.linkText)));
    }
    renderListAsLinks(link) {
        return (h("li", null, h("a", { href: link.href, id: this.uniqueId(link.linkText), ...(link.openInNewWindow && { target: '_blank' }), onClick: () => {
                if (link.isLogoutLink) {
                    headerState.loginManager.clearUserData();
                }
            } }, link.linkText, link.isLogoutLink ? h("pn-icon", { icon: transfer }) : h("pn-icon", { icon: arrow_right }))));
    }
    render() {
        if (!this.links || this.links.length === 0) {
            return;
        }
        return (h(Host, null, this.heading ? h("p", { class: "pn-marketweb-siteheader-login-linklist-heading" }, this.heading) : null, h("ul", null, this.links.map(link => {
            {
                return this.showUnifiedLogin ? this.renderListAsLinks(link) : this.renderListAsButtons(link);
            }
        }))));
    }
    static get is() { return "pn-marketweb-siteheader-login-linklist"; }
    static get originalStyleUrls() {
        return {
            "$": ["pn-marketweb-siteheader-login-linklist.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["pn-marketweb-siteheader-login-linklist.css"]
        };
    }
    static get properties() {
        return {
            "heading": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "heading",
                "reflect": false,
                "defaultValue": "null"
            },
            "links": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "LoginDialogLink[]",
                    "resolved": "LoginDialogLink[]",
                    "references": {
                        "LoginDialogLink": {
                            "location": "import",
                            "path": "./pn-marketweb-siteheader-types",
                            "id": "src/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-types.ts::LoginDialogLink"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "defaultValue": "[]"
            },
            "idNamespace": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "id-namespace",
                "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"; }
}
//# sourceMappingURL=pn-marketweb-siteheader-login-linklist.js.map
