import { DownloadOutlined } from "@ant-design/icons";
import { ConfigProvider, Tooltip } from "antd";
import classNames from "classnames";
import React, { useContext } from "react";
import { Loading } from "../../../../Components/Loading";
import { I18nContext } from "../../../../I18n";
import TimeIcon from "../icons/TimeIcon";
import { useStyle } from "./style";
/**
 * 图表工具栏组件
 *
 * 用于显示图表标题、数据时间、下载按钮等工具栏内容。
 * 支持主题切换、自定义内容、下载功能等。
 *
 * @component
 * @param {ChartToolBarProps} props - 组件属性
 * @returns {React.ReactElement | null} 图表工具栏组件，当没有标题和额外内容时返回 null
 *
 * @example
 * ```tsx
 * <ChartToolBar
 *   title="销售数据"
 *   dataTime="2024-01-01 00:00:00"
 *   theme="light"
 *   onDownload={() => console.log('下载图表')}
 *   extra={<Button>自定义按钮</Button>}
 * />
 * ```
 *
 * @since 1.0.0
 */ var ChartToolBar = function(param) {
    var title = param.title, dataTime = param.dataTime, _param_className = param.className, className = _param_className === void 0 ? '' : _param_className, _param_theme = param.theme, theme = _param_theme === void 0 ? 'light' : _param_theme, onDownload = param.onDownload, extra = param.extra, filter = param.filter, _param_loading = param.loading, loading = _param_loading === void 0 ? false : _param_loading;
    var _i18n_locale, _i18n_locale1;
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var i18n = useContext(I18nContext);
    var prefixCls = getPrefixCls('chart-toolbar');
    var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var handleDownload = function() {
        if (onDownload) {
            onDownload();
        }
    };
    if (!title && !extra) {
        return null;
    }
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: classNames(prefixCls, "".concat(prefixCls, "-").concat(theme), hashId, className)
    }, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-header-title"), hashId)
    }, title, loading && /*#__PURE__*/ React.createElement(Loading, {
        style: {
            fontSize: '14px',
            marginLeft: '8px',
            flexShrink: 0
        }
    })), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-header-actions"), hashId)
    }, dataTime ? /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(TimeIcon, {
        className: classNames("".concat(prefixCls, "-time-icon"), hashId)
    }), /*#__PURE__*/ React.createElement("span", {
        className: classNames("".concat(prefixCls, "-data-time"), hashId)
    }, (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale = i18n.locale) === null || _i18n_locale === void 0 ? void 0 : _i18n_locale.dataTime) || '数据时间', ": ", dataTime)) : null, filter, extra, handleDownload ? /*#__PURE__*/ React.createElement(Tooltip, {
        mouseEnterDelay: 0.3,
        title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale1 = i18n.locale) === null || _i18n_locale1 === void 0 ? void 0 : _i18n_locale1.download) || '下载'
    }, /*#__PURE__*/ React.createElement(DownloadOutlined, {
        className: classNames("".concat(prefixCls, "-download-btn"), hashId),
        onClick: handleDownload
    })) : null)));
};
export default ChartToolBar;
