import { h } from "@stencil/core";
import { currencyString } from "@boldpenguin/sdk-utility";
export class BpSdkQuoteRequestPremiumPayment {
    constructor() {
        this.period = undefined;
        this.price = undefined;
        this.showObelus = false;
        this.useExternal = false;
    }
    resetState() { }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-quote-request-premium-payment');
        customElements.whenDefined('bp-sdk-external-quote-request-premium-payment').then(() => {
            this.useExternal = true;
        });
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return h("bp-sdk-external-quote-request-premium-payment", { period: this.period, price: this.price, showObelus: this.showObelus });
    }
    renderInternal() {
        return (h("div", { class: "bp-sdk-quote-request-premium-payment__container" }, h("div", { class: "bp-sdk-online-quote__price bp-sdk-quote__price" }, h("div", { class: "bp-sdk-online-quote__pride-usd bp-sdk-quote__price-usd" }, "$"), h("div", { class: "bp-sdk-online-quote__price-value bp-sdk-quote__price-value" }, this.priceDisplay(this.price)), h("div", { class: "bp-sdk-online-quote__price-period bp-sdk-quote__price-period" }, "/", this.period, this.showObelus && h("sup", null, "\u2020")))));
    }
    priceDisplay(price) {
        if (typeof price === 'number') {
            return currencyString(price);
        }
        else if (!!price && price.includes('.')) {
            const convertedPrice = price.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
            return convertedPrice.split('.')[1].length === 2 ? convertedPrice : `${convertedPrice}0`;
        }
        return '0';
    }
    static get is() { return "bp-sdk-quote-request-premium-payment"; }
    static get originalStyleUrls() {
        return {
            "$": ["./bp-sdk-quote-request-premium-payment.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-quote-request-premium-payment.css"]
        };
    }
    static get properties() {
        return {
            "period": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Price"
                },
                "attribute": "period",
                "reflect": false
            },
            "price": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Price"
                },
                "attribute": "price",
                "reflect": false
            },
            "showObelus": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Show obelus"
                },
                "attribute": "show-obelus",
                "reflect": false,
                "defaultValue": "false"
            }
        };
    }
    static get states() {
        return {
            "useExternal": {}
        };
    }
}
