import { h } from "@stencil/core";
import BigNumber from "bignumber.js";
import { formatAmount } from "@multiversx/sdk-dapp-utils/out/helpers";
import { DECIMALS, DIGITS, ZERO } from "@multiversx/sdk-dapp-utils/out/constants";
export class FormatAmount {
    constructor() {
        this.class = undefined;
        this.decimals = DECIMALS;
        this.digits = DIGITS;
        this.egldLabel = undefined;
        this.showLabel = true;
        this.showLastNonZeroDecimal = false;
        this.token = undefined;
        this.value = undefined;
    }
    renderInvalid() {
        return (h("span", { "data-testid": 'formatAmountComponent', class: this.class }, h("span", { class: 'int-amount', "data-testid": 'formatAmountInt' }, "...")));
    }
    renderValid() {
        var _a;
        const formattedValue = formatAmount({
            input: this.value,
            decimals: this.decimals,
            digits: this.digits,
            showLastNonZeroDecimal: this.showLastNonZeroDecimal,
            addCommas: true
        });
        const valueParts = formattedValue.split('.');
        const hasNoDecimals = valueParts.length === 1;
        const isNotZero = formattedValue !== ZERO;
        if (this.digits > 0 && hasNoDecimals && isNotZero) {
            valueParts.push(ZERO.repeat(this.digits));
        }
        return (h("span", { "data-testid": 'formatAmountComponent', class: this.class }, h("span", { class: 'int-amount', "data-testid": 'formatAmountInt' }, valueParts[0]), valueParts.length > 1 && (h("span", { class: 'decimals', "data-testid": 'formatAmountDecimals' }, ".", valueParts[1])), this.showLabel && (h("span", { class: {
                'symbol': true,
                [this.token]: !!this.token
            }, "data-testid": 'formatAmountSymbol' }, ` ${(_a = this.token) !== null && _a !== void 0 ? _a : this.egldLabel}`))));
    }
    render() {
        const isInteger = new BigNumber(this.value).isInteger();
        return !isInteger ? this.renderInvalid() : this.renderValid();
    }
    static get is() { return "format-amount"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["format-amount.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["format-amount.css"]
        };
    }
    static get properties() {
        return {
            "class": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "class",
                "reflect": false
            },
            "decimals": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "decimals",
                "reflect": false,
                "defaultValue": "DECIMALS"
            },
            "digits": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "digits",
                "reflect": false,
                "defaultValue": "DIGITS"
            },
            "egldLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "egld-label",
                "reflect": false
            },
            "showLabel": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "show-label",
                "reflect": false,
                "defaultValue": "true"
            },
            "showLastNonZeroDecimal": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "show-last-non-zero-decimal",
                "reflect": false,
                "defaultValue": "false"
            },
            "token": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "token",
                "reflect": false
            },
            "value": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "value",
                "reflect": false
            }
        };
    }
}
//# sourceMappingURL=format-amount.js.map
