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 _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;
}
import { QuestionCircleOutlined } from "@ant-design/icons";
import { ConfigProvider, Tooltip } from "antd";
import clsx from "clsx";
import React, { useContext } from "react";
import { useAdaptiveTooltipProps } from "../../../Hooks/useAdaptiveTooltipProps";
import { useStyle } from "./style";
import { formatNumber } from "./utils";
var ChartStatistic = function ChartStatistic(param) {
    var title = param.title, subtitle = param.subtitle, 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 getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('chart-statistic');
    var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var informationalTooltip = useAdaptiveTooltipProps('informational');
    // 渲染数值
    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 && !subtitle && !extra) return null;
        var titleElement = title ? /*#__PURE__*/ React.createElement("span", {
            className: clsx("".concat(prefixCls, "-title"), hashId, classNames === null || classNames === void 0 ? void 0 : classNames.title),
            style: styles === null || styles === void 0 ? void 0 : styles.title
        }, title) : null;
        var subtitleElement = subtitle ? /*#__PURE__*/ React.createElement("span", {
            className: clsx("".concat(prefixCls, "-subtitle"), hashId, classNames === null || classNames === void 0 ? void 0 : classNames.subtitle),
            style: styles === null || styles === void 0 ? void 0 : styles.subtitle
        }, subtitle) : null;
        var questionIcon = tooltip ? /*#__PURE__*/ React.createElement(Tooltip, _object_spread({
            mouseEnterDelay: 0.3,
            title: tooltip,
            placement: "top"
        }, informationalTooltip), /*#__PURE__*/ React.createElement(QuestionCircleOutlined, {
            className: clsx("".concat(prefixCls, "-question-icon"), hashId, classNames === null || classNames === void 0 ? void 0 : classNames.questionIcon),
            style: styles === null || styles === void 0 ? void 0 : styles.questionIcon
        })) : null;
        var extraElement = extra ? /*#__PURE__*/ React.createElement("div", {
            className: classNames === null || classNames === void 0 ? void 0 : classNames.extra,
            style: styles === null || styles === void 0 ? void 0 : styles.extra
        }, extra) : null;
        var hasHeaderLeft = titleElement || subtitleElement || questionIcon;
        return /*#__PURE__*/ React.createElement("div", {
            className: clsx("".concat(prefixCls, "-header"), hashId, classNames === null || classNames === void 0 ? void 0 : classNames.header),
            style: styles === null || styles === void 0 ? void 0 : styles.header
        }, hasHeaderLeft && /*#__PURE__*/ React.createElement("div", {
            className: clsx("".concat(prefixCls, "-header-left"), hashId, classNames === null || classNames === void 0 ? void 0 : classNames.headerLeft),
            style: styles === null || styles === void 0 ? void 0 : styles.headerLeft
        }, (titleElement || questionIcon) && /*#__PURE__*/ React.createElement("div", {
            className: clsx("".concat(prefixCls, "-header-row"), hashId)
        }, titleElement, questionIcon), subtitleElement), extraElement);
    };
    var rootClassName = clsx(prefixCls, "".concat(prefixCls, "-").concat(theme), size !== 'default' && "".concat(prefixCls, "-").concat(size), block && "".concat(prefixCls, "-block"), hashId, className, classNames === null || classNames === void 0 ? void 0 : classNames.root);
    var rootStyle = _object_spread({}, style, styles === null || styles === void 0 ? void 0 : styles.root);
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: rootClassName,
        style: rootStyle
    }, renderHeader(), /*#__PURE__*/ React.createElement("div", {
        className: clsx("".concat(prefixCls, "-value"), hashId, classNames === null || classNames === void 0 ? void 0 : classNames.value),
        style: styles === null || styles === void 0 ? void 0 : styles.value
    }, prefix && /*#__PURE__*/ React.createElement("span", {
        className: clsx("".concat(prefixCls, "-value-prefix"), hashId, classNames === null || classNames === void 0 ? void 0 : classNames.valuePrefix),
        style: styles === null || styles === void 0 ? void 0 : styles.valuePrefix
    }, prefix), renderValue(), suffix && /*#__PURE__*/ React.createElement("span", {
        className: clsx("".concat(prefixCls, "-value-suffix"), hashId, classNames === null || classNames === void 0 ? void 0 : classNames.valueSuffix),
        style: styles === null || styles === void 0 ? void 0 : styles.valueSuffix
    }, suffix))));
};
export default ChartStatistic;
