import { getQuoteById, selectShouldQuoteCardRenderSupplierLogos } from "@boldpenguin/sdk-redux";
import { h } from "@stencil/core";
import store from "../../services/redux-store.service";
export class BpSdkQuoteRequestLogoContainer {
    constructor() {
        this.mapStateToProps = (state) => {
            return {
                shouldRenderSupplierLogo: selectShouldQuoteCardRenderSupplierLogos(state),
                quote: getQuoteById(state, this.quoteId),
            };
        };
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            this.storeUnsubscribe = store.mapStateToProps(this, this.mapStateToProps);
        };
        this.carrier = undefined;
        this.customLogoBaseUrl = undefined;
        this.showLogo = undefined;
        this.showCustomLogo = undefined;
        this.quoteId = undefined;
        this.shouldRenderSupplierLogo = undefined;
        this.configOptions = undefined;
        this.quote = undefined;
        this.useExternal = false;
        this.name = undefined;
        this.logoUrl = undefined;
    }
    resetState() {
        this.quote = undefined;
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-quote-request-logo-container');
        customElements.whenDefined('bp-sdk-external-quote-request-logo-container').then(() => {
            this.useExternal = true;
        });
        this.onCarrierChange(this.carrier);
        this.onCustomLogoBaseUrlChange(this.customLogoBaseUrl);
        this.onShowCustomLogoChange(this.showCustomLogo);
    }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    onCarrierChange(carrier) {
        this.name = carrier === null || carrier === void 0 ? void 0 : carrier.name;
        this.updateLogoUrl(carrier, this.customLogoBaseUrl, this.showCustomLogo);
    }
    onCustomLogoBaseUrlChange(customLogoBaseUrl) {
        this.updateLogoUrl(this.carrier, customLogoBaseUrl, this.showCustomLogo);
    }
    onShowCustomLogoChange(showCustomLogo) {
        this.updateLogoUrl(this.carrier, this.customLogoBaseUrl, showCustomLogo);
    }
    onShouldRenderSupplierLogoChange(shouldRenderSupplierLogo) {
        this.updateLogoUrl(this.carrier, this.customLogoBaseUrl, this.showCustomLogo, shouldRenderSupplierLogo);
    }
    updateLogoUrl(carrier, baseUrl, showCustomLogo, renderSupplierLogo = false) {
        var _a, _b, _c;
        if (showCustomLogo) {
            if (this.shouldRenderSupplierLogo && ((_a = this.quote) === null || _a === void 0 ? void 0 : _a.supplier_name)) {
                this.logoUrl = `${baseUrl}${this.quote.supplier_name.toLowerCase()}.png`;
            }
            else {
                this.logoUrl = `${baseUrl}${(_b = carrier === null || carrier === void 0 ? void 0 : carrier.name) === null || _b === void 0 ? void 0 : _b.toLowerCase()}.png`;
            }
        }
        else {
            if (this.shouldRenderSupplierLogo && ((_c = this.quote) === null || _c === void 0 ? void 0 : _c.supplier_logo_url)) {
                this.logoUrl = this.quote.supplier_logo_url;
            }
            else {
                this.logoUrl = carrier === null || carrier === void 0 ? void 0 : carrier.logo_url;
            }
        }
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (h("bp-sdk-external-quote-request-logo-container", { carrier: this.carrier, customLogoBaseUrl: this.customLogoBaseUrl, showLogo: this.showLogo, showCustomLogo: this.showCustomLogo, shouldRenderSupplierLogo: this.shouldRenderSupplierLogo }));
    }
    renderInternal() {
        return h("bp-sdk-quote-request-logo", { logoUrl: this.logoUrl, name: this.name, showLogo: this.showLogo });
    }
    static get is() { return "bp-sdk-quote-request-logo-container"; }
    static get originalStyleUrls() {
        return {
            "$": ["./bp-sdk-quote-request-logo-container.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-quote-request-logo-container.css"]
        };
    }
    static get properties() {
        return {
            "carrier": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "ICarrier",
                    "resolved": "ICarrier",
                    "references": {
                        "ICarrier": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::ICarrier"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Carrier information"
                }
            },
            "customLogoBaseUrl": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Custom logo base url"
                },
                "attribute": "custom-logo-base-url",
                "reflect": false
            },
            "showLogo": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Show logo"
                },
                "attribute": "show-logo",
                "reflect": false
            },
            "showCustomLogo": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Show custom logo"
                },
                "attribute": "show-custom-logo",
                "reflect": false
            },
            "quoteId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Quote ID"
                },
                "attribute": "quote-id",
                "reflect": false
            },
            "shouldRenderSupplierLogo": {
                "type": "boolean",
                "mutable": true,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Render supplier logo instead of carrier logo, injected from redux"
                },
                "attribute": "should-render-supplier-logo",
                "reflect": false
            },
            "configOptions": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "IConfigOptions",
                    "resolved": "IConfigOptions",
                    "references": {
                        "IConfigOptions": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::IConfigOptions"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Web component config options injected from redux"
                }
            },
            "quote": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "IQuotesState",
                    "resolved": "IQuotesState",
                    "references": {
                        "IQuotesState": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::IQuotesState"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Quote, injected from redux"
                }
            }
        };
    }
    static get states() {
        return {
            "useExternal": {},
            "name": {},
            "logoUrl": {}
        };
    }
    static get watchers() {
        return [{
                "propName": "carrier",
                "methodName": "onCarrierChange"
            }, {
                "propName": "customLogoBaseUrl",
                "methodName": "onCustomLogoBaseUrlChange"
            }, {
                "propName": "showCustomLogo",
                "methodName": "onShowCustomLogoChange"
            }, {
                "propName": "shouldRenderSupplierLogo",
                "methodName": "onShouldRenderSupplierLogoChange"
            }];
    }
}
