function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_without_holes(arr) {
    if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _non_iterable_spread() {
    throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function _to_consumable_array(arr) {
    return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { QuestionCircleOutlined } from "@ant-design/icons";
import { ConfigProvider, Tooltip } from "antd";
import React, { useContext } from "react";
import { useStyle } from "./style";
import { formatNumber } from "./utils";
var ChartStatistic = function ChartStatistic(param) {
    var title = param.title, tooltip = param.tooltip, value = param.value, precision = param.precision, _param_groupSeparator = param.groupSeparator, groupSeparator = _param_groupSeparator === void 0 ? ',' : _param_groupSeparator, _param_prefix = param.prefix, prefix = _param_prefix === void 0 ? '' : _param_prefix, _param_suffix = param.suffix, suffix = _param_suffix === void 0 ? '' : _param_suffix, formatter = param.formatter, _param_className = param.className, className = _param_className === void 0 ? '' : _param_className, classNames = param.classNames, style = param.style, styles = param.styles, _param_theme = param.theme, theme = _param_theme === void 0 ? 'light' : _param_theme, _param_size = param.size, size = _param_size === void 0 ? 'default' : _param_size, _param_block = param.block, block = _param_block === void 0 ? false : _param_block, extra = param.extra;
    var _Object;
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('chart-statistic');
    var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    // 渲染数值
    var renderValue = function renderValue() {
        // 如果提供了自定义格式化函数，优先使用
        if (formatter) {
            return formatter(value);
        }
        // 使用内置格式化逻辑
        var formatOptions = {
            precision: precision,
            groupSeparator: groupSeparator
        };
        return formatNumber(value, formatOptions);
    };
    // 渲染标题和问号图标
    var renderHeader = function renderHeader() {
        if (!title && !extra) return null;
        var titleElement = title ? /*#__PURE__*/ React.createElement("span", {
            className: [
                "".concat(prefixCls, "-title"),
                hashId
            ].filter(Boolean).join(' ')
        }, title) : null;
        var questionIcon = tooltip ? /*#__PURE__*/ React.createElement(Tooltip, {
            mouseEnterDelay: 0.3,
            title: tooltip,
            placement: "top"
        }, /*#__PURE__*/ React.createElement(QuestionCircleOutlined, {
            className: [
                "".concat(prefixCls, "-question-icon"),
                hashId
            ].filter(Boolean).join(' ')
        })) : null;
        var extraElement = extra ? /*#__PURE__*/ React.createElement("div", null, extra) : null;
        return /*#__PURE__*/ React.createElement("div", {
            className: [
                "".concat(prefixCls, "-header"),
                hashId
            ].filter(Boolean).join(' ')
        }, /*#__PURE__*/ React.createElement("div", {
            className: [
                "".concat(prefixCls, "-header-left"),
                hashId
            ].filter(Boolean).join(' ')
        }, titleElement, questionIcon), extraElement);
    };
    var mergedClassName = [
        prefixCls,
        "".concat(prefixCls, "-").concat(theme),
        size !== 'default' && "".concat(prefixCls, "-").concat(size),
        block && "".concat(prefixCls, "-block"),
        hashId,
        className,
        classNames
    ].filter(Boolean).join(' ');
    var mergedStyle = _object_spread({}, style, Array.isArray(styles) ? (_Object = Object).assign.apply(_Object, [
        {}
    ].concat(_to_consumable_array(styles))) : styles || {});
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: mergedClassName,
        style: mergedStyle
    }, renderHeader(), /*#__PURE__*/ React.createElement("div", {
        className: [
            "".concat(prefixCls, "-value"),
            hashId
        ].filter(Boolean).join(' ')
    }, prefix && /*#__PURE__*/ React.createElement("span", {
        className: [
            "".concat(prefixCls, "-value-prefix"),
            hashId
        ].filter(Boolean).join(' ')
    }, prefix), renderValue(), suffix && /*#__PURE__*/ React.createElement("span", {
        className: [
            "".concat(prefixCls, "-value-suffix"),
            hashId
        ].filter(Boolean).join(' ')
    }, suffix))));
};
export default ChartStatistic;
