import { __decorate, __metadata } from "tslib";
import { Language, loadFooterLinks, loadSocialMediaLinks } from "@baloise/web-app-utils";
import { h, Host } from "@stencil/core";
import { BEM } from "../../utils/bem";
import { defaultConfig, ListenToConfig, updateBalLanguage, } from "../../utils/config";
import { rIC } from "../../utils/helpers";
import { Logger } from "../../utils/log";
import { sanitizeSvg } from "../../utils/svg";
import { i18nBalFooter } from "./bal-footer.i18n";
export class Footer {
    constructor() {
        this.logoSvgContent = '';
        this.links = [];
        this.socialMediaLinks = [];
        this.language = defaultConfig.language;
        this.region = defaultConfig.region;
        this.allowedLanguages = defaultConfig.allowedLanguages;
        /**
         * PUBLIC PROPERTY API
         * ------------------------------------------------------
         */
        /**
         * Image address for the logo.
         */
        this.logoHref = '';
        /**
         * Svg content for the logo.
         */
        this.logoSvg = '';
        /**
         * If `true` the legal Baloise links will be hidden.
         */
        this.hideLinks = false;
        /**
         * If provided, the footer links will be overridden.
         */
        this.overrideLinks = undefined;
        /**
         * If `true` the social media links will be shown.
         */
        this.showSocialMedia = false;
        /**
         * If `true` the language selection will be hidden.
         */
        this.hideLanguageSelection = false;
    }
    createLogger(log) {
        this.log = log;
    }
    logoSvgChanged() {
        this.logoSvgContent = sanitizeSvg(this.logoSvg);
    }
    /**
     * LIFECYCLE
     * ------------------------------------------------------
     */
    connectedCallback() {
        this.updateFooterLinks();
        this.updateSocialMediaLinks();
        this.logoSvgChanged();
    }
    /**
     * LISTENERS
     * ------------------------------------------------------
     */
    /**
     * @internal define config for the component
     */
    async configChanged(state) {
        if (this.language !== state.language || this.region !== state.region) {
            this.language = state.language;
            this.region = state.region;
            this.allowedLanguages = state.allowedLanguages;
            this.updateFooterLinks();
            this.updateSocialMediaLinks();
        }
    }
    /**
     * PRIVATE METHODS
     * ------------------------------------------------------
     */
    changeLanguage(language) {
        updateBalLanguage(language);
    }
    updateFooterLinks() {
        if (this.overrideLinks) {
            this.links = this.overrideLinks;
        }
        else if (!this.hideLinks && (this.region === 'CH' || this.region === 'DE')) {
            // The following footer links only apply to swiss and german applications
            const region = this.region;
            rIC(() => {
                loadFooterLinks(new Language(this.language), region).then(links => (this.links = links));
            });
        }
    }
    updateSocialMediaLinks() {
        if (this.showSocialMedia && (this.region === 'CH' || this.region === 'DE')) {
            // The following footer links only apply to swiss and german applications
            const region = this.region;
            rIC(() => {
                loadSocialMediaLinks(new Language(this.language), region).then(links => (this.socialMediaLinks = links));
            });
        }
    }
    /**
     * RENDER
     * ------------------------------------------------------
     */
    render() {
        const block = BEM.block('footer');
        const elSlot = block.element('slot');
        const elInner = block.element('inner');
        const elInnerWrapper = elInner.element('wrapper');
        const elContainer = elInnerWrapper.element('container');
        const elLinksContainer = elInnerWrapper.element('links-container');
        const elHeaderContainer = elInnerWrapper.element('header-container');
        const elLogo = elHeaderContainer.element('logo');
        const elLanguage = elHeaderContainer.element('language');
        const elWrapper = elLanguage.element('wrapper');
        const elLegalLinks = elLinksContainer.element('legal-links');
        const elSocialMediaLinks = elLinksContainer.element('social-media-links');
        return (h(Host, { key: '04ec38780841ea9902e3f465b8fd4e3561a9092e', class: Object.assign({}, block.class()) }, h("footer", { key: 'dc1fa3c156ad78d3d05d3f5d219c81801bca5044', class: Object.assign({}, elInner.class()) }, h("div", { key: 'e8f1144c09a1b52fb956bc03438671086e801895', class: Object.assign({}, elInnerWrapper.class()) }, h("div", { key: 'b6d1e0c4deed43eec0e0889cc4011cc5465db527', class: Object.assign(Object.assign({ container: true }, elContainer.class()), elHeaderContainer.class()) }, h("div", { key: '6102cc926e8542a0a2802b1fa8914b054a9391b4', class: Object.assign({}, elLogo.class()) }, this.logoHref ? (h("img", { src: this.logoHref, alt: "Logo" })) : this.logoSvgContent ? (h("div", { innerHTML: this.logoSvgContent })) : (h("bal-logo", { color: "white" }))), h("div", { key: '5cd3a29dd8d40a4704f85635e32bcca1d0af0546', class: Object.assign({}, elLanguage.class()), style: {
                display: this.hideLanguageSelection || this.allowedLanguages.length <= 1 ? 'none' : 'flex',
            } }, h("div", { key: '023ba95e77cc80681af23b8a0ed50b49a94b81fd', class: Object.assign({}, elWrapper.class()) }, h("bal-icon", { key: '3c5ce093f139a07def8c73fdfbcf6060de8893b3', class: Object.assign({}, elWrapper.element('icon').class()), name: "web", color: "white" }), h("select", { key: '7cd8af0cb134b8b8a9733333df37a1c9f909e9fb', class: Object.assign({}, elWrapper.element('select').class()), onChange: event => this.changeLanguage(event.target.value), "data-testid": "bal-footer-language" }, this.allowedLanguages.map(language => (h("option", { key: language, value: language, selected: language === this.language }, language.toLocaleUpperCase() + ' - ' + i18nBalFooter[language].name))))))), h("div", { key: '017b017c8d5714e5b8568cf10e12a96a468b722e', class: Object.assign({}, elSlot.class()) }, h("slot", { key: 'e09a963ac71e749cecfe38751ae330759e626080' })), h("div", { key: '993161e25ae9c3fccc18fd7f2b032b74b3120106', class: Object.assign(Object.assign({ container: true }, elContainer.class()), elLinksContainer.class()) }, h("div", { key: 'eee88e5f349aebf4d16333462f7e18a029bfe82e', class: Object.assign({}, elSocialMediaLinks.class()), style: {
                display: !this.showSocialMedia ? 'none' : 'flex',
            } }, this.socialMediaLinks.map(link => (h("a", { key: link.link, href: link.link, target: "_blank", class: {
                'link': true,
                'is-inverted': true,
            } }, h("bal-icon", { name: link.label.toLowerCase() }))))), h("div", { key: 'fdd8006cd0d1ec2f6e3fa6ee418705a7d607f9c8', class: Object.assign({}, elLegalLinks.class()), style: { display: this.hideLinks ? 'none' : 'flex' } }, this.links &&
            this.links.map(link => (h("a", { key: link.link, href: link.link, target: "_blank", class: {
                    'link': true,
                    'is-light': true,
                } }, link.label)))))))));
    }
    static get is() { return "bal-footer"; }
    static get originalStyleUrls() {
        return {
            "$": ["bal-footer.sass"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bal-footer.css"]
        };
    }
    static get properties() {
        return {
            "logoHref": {
                "type": "string",
                "attribute": "logo-href",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Image address for the logo."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "''"
            },
            "logoSvg": {
                "type": "string",
                "attribute": "logo-svg",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Svg content for the logo."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "''"
            },
            "hideLinks": {
                "type": "boolean",
                "attribute": "hide-links",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` the legal Baloise links will be hidden."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "overrideLinks": {
                "type": "unknown",
                "attribute": "override-links",
                "mutable": false,
                "complexType": {
                    "original": "FooterLink[] | undefined",
                    "resolved": "FooterLink[]",
                    "references": {
                        "FooterLink": {
                            "location": "import",
                            "path": "@baloise/web-app-utils",
                            "id": "../../node_modules/@baloise/web-app-utils/dist/types/index.d.ts::FooterLink"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If provided, the footer links will be overridden."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "undefined"
            },
            "showSocialMedia": {
                "type": "boolean",
                "attribute": "show-social-media",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` the social media links will be shown."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "hideLanguageSelection": {
                "type": "boolean",
                "attribute": "hide-language-selection",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` the language selection will be hidden."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            }
        };
    }
    static get states() {
        return {
            "logoSvgContent": {},
            "links": {},
            "socialMediaLinks": {},
            "language": {},
            "region": {},
            "allowedLanguages": {}
        };
    }
    static get methods() {
        return {
            "configChanged": {
                "complexType": {
                    "signature": "(state: BalConfigState) => Promise<void>",
                    "parameters": [{
                            "name": "state",
                            "type": "BalConfigState",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "BalConfigState": {
                            "location": "import",
                            "path": "../../utils/config",
                            "id": "src/utils/config/index.ts::BalConfigState"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": [{
                            "name": "internal",
                            "text": "define config for the component"
                        }]
                }
            }
        };
    }
    static get watchers() {
        return [{
                "propName": "logoSvg",
                "methodName": "logoSvgChanged"
            }];
    }
}
__decorate([
    Logger('bal-footer'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Function]),
    __metadata("design:returntype", void 0)
], Footer.prototype, "createLogger", null);
__decorate([
    ListenToConfig(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], Footer.prototype, "configChanged", null);
