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 { CopyOutlined, DownloadOutlined } from "@ant-design/icons";
import { ConfigProvider, Tooltip } from "antd";
import clsx from "clsx";
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 ChartToolBar(param) {
    var title = param.title, dataTime = param.dataTime, _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, onDownload = param.onDownload, onCopyMarkdown = param.onCopyMarkdown, extra = param.extra, filter = param.filter, _param_loading = param.loading, loading = _param_loading === void 0 ? false : _param_loading;
    var _Object;
    var _i18n_locale, _i18n_locale1, _i18n_locale2;
    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 handleDownload() {
        if (onDownload) {
            onDownload();
        }
    };
    var handleCopyMarkdown = function handleCopyMarkdown() {
        if (onCopyMarkdown) {
            onCopyMarkdown();
        }
    };
    if (!title && !extra) {
        return null;
    }
    var mergedClassName = clsx(prefixCls, "".concat(prefixCls, "-").concat(theme), hashId, className, classNames);
    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
    }, /*#__PURE__*/ React.createElement("div", {
        className: clsx("".concat(prefixCls, "-header-title"), hashId)
    }, title, loading && /*#__PURE__*/ React.createElement(Loading, {
        style: {
            fontSize: '14px',
            marginLeft: '8px',
            flexShrink: 0
        }
    })), /*#__PURE__*/ React.createElement("div", {
        className: clsx("".concat(prefixCls, "-header-actions"), hashId)
    }, dataTime ? /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(TimeIcon, {
        className: clsx("".concat(prefixCls, "-time-icon"), hashId)
    }), /*#__PURE__*/ React.createElement("span", {
        className: clsx("".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, onCopyMarkdown ? /*#__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.copyMarkdown) || '复制表格'
    }, /*#__PURE__*/ React.createElement(CopyOutlined, {
        className: clsx("".concat(prefixCls, "-copy-btn"), hashId),
        onClick: handleCopyMarkdown
    })) : null, onDownload ? /*#__PURE__*/ React.createElement(Tooltip, {
        mouseEnterDelay: 0.3,
        title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale2 = i18n.locale) === null || _i18n_locale2 === void 0 ? void 0 : _i18n_locale2.download) || '下载'
    }, /*#__PURE__*/ React.createElement(DownloadOutlined, {
        className: clsx("".concat(prefixCls, "-download-btn"), hashId),
        onClick: handleDownload
    })) : null)));
};
export default ChartToolBar;
