import { h } from "@stencil/core";
/**
 * Statistic 统计数值组件
 * 展示某个统计数据，常用于展示一个指标的当前值
 */
export class Statistic {
    /** 数值标题（使用默认值使其成为 required string，避免与 HTMLElement.title 类型冲突） */
    title = '';
    /** 数值内容（数字或字符串） */
    value = 0;
    /** 数值小数位数 */
    precision;
    /** 数值前缀（如货币符号 ¥）（改名 valuePrefix 避免与 Element.prefix 类型冲突） */
    valuePrefix = '';
    /** 数值后缀（如单位） */
    suffix;
    /** 数值容器的内联样式 */
    valueStyle;
    /**
     * 将 value 按 precision 格式化为千分位字符串
     * - 纯数字字符串（含小数）会被当作数值进行格式化（便于 attribute 传入）
     * - 含非数字字符的字符串原样返回（如 "1.2K"、"N/A"）
     */
    getFormattedValue() {
        // 将 value 归一为数值：number 直接用；纯数字字符串转为 number；否则原样返回
        let numericValue;
        if (typeof this.value === 'number') {
            numericValue = this.value;
        }
        else {
            const trimmed = this.value.trim();
            if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
                numericValue = Number(trimmed);
            }
            else {
                return this.value;
            }
        }
        let str;
        if (typeof this.precision === 'number' && this.precision >= 0) {
            str = numericValue.toFixed(this.precision);
        }
        else {
            str = String(numericValue);
        }
        // 拆分整数/小数部分，仅对整数部分加千分位
        const [intPart, decPart] = str.split('.');
        const grouped = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
        return decPart !== undefined ? `${grouped}.${decPart}` : grouped;
    }
    render() {
        return (h("div", { key: 'e38db3c8ae83480a933a7a9fd03d4ecb8e3cb07d', class: "hb-statistic" }, this.title && h("div", { key: '2d4af905f79558e98b6db498db1d251d10b64151', class: "hb-statistic__title" }, this.title), h("div", { key: 'f60f0263f6f22ca95d863c1fcd7f94556b351cea', class: "hb-statistic__content", style: this.valueStyle ? { cssText: this.valueStyle } : undefined }, this.valuePrefix && h("span", { key: '4dd5f92066507ad0abf5c5bbeca64001d425b83a', class: "hb-statistic__prefix" }, this.valuePrefix), h("span", { key: '746806287e5f0752263ce913a4b81fa221b0fb3b', class: "hb-statistic__value" }, this.getFormattedValue()), this.suffix !== undefined && h("span", { key: 'a93c66aeb111922903214884e664b425279cc5ac', class: "hb-statistic__suffix" }, this.suffix))));
    }
    static get is() { return "hb-statistic"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["statistic.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["statistic.css"]
        };
    }
    static get properties() {
        return {
            "title": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u6570\u503C\u6807\u9898\uFF08\u4F7F\u7528\u9ED8\u8BA4\u503C\u4F7F\u5176\u6210\u4E3A required string\uFF0C\u907F\u514D\u4E0E HTMLElement.title \u7C7B\u578B\u51B2\u7A81\uFF09"
                },
                "getter": false,
                "setter": false,
                "attribute": "title",
                "reflect": false,
                "defaultValue": "''"
            },
            "value": {
                "type": "any",
                "mutable": false,
                "complexType": {
                    "original": "number | string",
                    "resolved": "number | string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u6570\u503C\u5185\u5BB9\uFF08\u6570\u5B57\u6216\u5B57\u7B26\u4E32\uFF09"
                },
                "getter": false,
                "setter": false,
                "attribute": "value",
                "reflect": false,
                "defaultValue": "0"
            },
            "precision": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "\u6570\u503C\u5C0F\u6570\u4F4D\u6570"
                },
                "getter": false,
                "setter": false,
                "attribute": "precision",
                "reflect": false
            },
            "valuePrefix": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u6570\u503C\u524D\u7F00\uFF08\u5982\u8D27\u5E01\u7B26\u53F7 \u00A5\uFF09\uFF08\u6539\u540D valuePrefix \u907F\u514D\u4E0E Element.prefix \u7C7B\u578B\u51B2\u7A81\uFF09"
                },
                "getter": false,
                "setter": false,
                "attribute": "value-prefix",
                "reflect": false,
                "defaultValue": "''"
            },
            "suffix": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "\u6570\u503C\u540E\u7F00\uFF08\u5982\u5355\u4F4D\uFF09"
                },
                "getter": false,
                "setter": false,
                "attribute": "suffix",
                "reflect": false
            },
            "valueStyle": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "\u6570\u503C\u5BB9\u5668\u7684\u5185\u8054\u6837\u5F0F"
                },
                "getter": false,
                "setter": false,
                "attribute": "value-style",
                "reflect": false
            }
        };
    }
}
//# sourceMappingURL=Statistic.js.map
