import { h } from "@stencil/core";
import { currencyString } from "@boldpenguin/sdk-utility";
export class BpSdkQuoteRequestPremiumContainer {
    constructor() {
        this.quoteInfo = undefined;
        this.annualPrice = undefined;
        this.downpayment = undefined;
        this.installments = undefined;
        this.monthlyPrice = undefined;
        this.price = undefined;
        this.showTotalPremium = undefined;
        this.termLength = undefined;
        this.totalPremium = undefined;
        this.useExternal = false;
    }
    resetState() { }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-quote-request-premium-container');
        customElements.whenDefined('bp-sdk-external-quote-request-premium-container').then(() => {
            this.useExternal = true;
        });
        this.onQuoteInfoChange(this.quoteInfo);
    }
    onQuoteInfoChange(quoteInfo) {
        var _a;
        this.annualPrice = quoteInfo === null || quoteInfo === void 0 ? void 0 : quoteInfo.annual_price;
        this.monthlyPrice = quoteInfo === null || quoteInfo === void 0 ? void 0 : quoteInfo.monthly_price;
        this.downpayment = quoteInfo === null || quoteInfo === void 0 ? void 0 : quoteInfo.downpayment;
        this.installments = quoteInfo === null || quoteInfo === void 0 ? void 0 : quoteInfo.number_of_installments;
        this.showTotalPremium = !!((_a = quoteInfo === null || quoteInfo === void 0 ? void 0 : quoteInfo.price_details) === null || _a === void 0 ? void 0 : _a.new_total_premium);
        if (!!(quoteInfo === null || quoteInfo === void 0 ? void 0 : quoteInfo.annual_price)) {
            this.setAnnual(quoteInfo);
        }
        else if (!!(quoteInfo === null || quoteInfo === void 0 ? void 0 : quoteInfo.semiannual_price)) {
            this.setSemiAnnual(quoteInfo);
        }
        this.updateTotalPremium(quoteInfo);
    }
    setAnnual(quoteInfo) {
        this.price = quoteInfo.annual_price;
        this.termLength = 'year';
    }
    setSemiAnnual(quoteInfo) {
        this.price = quoteInfo.semiannual_price;
        this.termLength = '6-month policy term';
    }
    updateTotalPremium(quoteInfo) {
        var _a;
        if (!!((_a = quoteInfo === null || quoteInfo === void 0 ? void 0 : quoteInfo.price_details) === null || _a === void 0 ? void 0 : _a.new_total_premium)) {
            this.totalPremium =
                typeof quoteInfo.price_details.new_total_premium === 'number'
                    ? currencyString(quoteInfo.price_details.new_total_premium)
                    : quoteInfo.price_details.new_total_premium.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
        }
        else {
            this.totalPremium = this.price;
        }
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return h("bp-sdk-external-quote-request-premium-container", { quoteInfo: this.quoteInfo });
    }
    renderInternal() {
        return (h("bp-sdk-quote-request-premium", { annualPrice: this.annualPrice, downpayment: this.downpayment, installments: this.installments, monthlyPrice: this.monthlyPrice, price: this.price, showTotalPremium: this.showTotalPremium, termLength: this.termLength, totalPremium: this.totalPremium }));
    }
    static get is() { return "bp-sdk-quote-request-premium-container"; }
    static get originalStyleUrls() {
        return {
            "$": ["./bp-sdk-quote-request-premium-container.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-quote-request-premium-container.css"]
        };
    }
    static get properties() {
        return {
            "quoteInfo": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "IQuoteInfo",
                    "resolved": "IQuoteInfo",
                    "references": {
                        "IQuoteInfo": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::IQuoteInfo"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Quote info"
                }
            }
        };
    }
    static get states() {
        return {
            "annualPrice": {},
            "downpayment": {},
            "installments": {},
            "monthlyPrice": {},
            "price": {},
            "showTotalPremium": {},
            "termLength": {},
            "totalPremium": {},
            "useExternal": {}
        };
    }
    static get watchers() {
        return [{
                "propName": "quoteInfo",
                "methodName": "onQuoteInfoChange"
            }];
    }
}
