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_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _array_without_holes(arr) {
    if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
    try {
        var info = gen[key](arg);
        var value = info.value;
    } catch (error) {
        reject(error);
        return;
    }
    if (info.done) {
        resolve(value);
    } else {
        Promise.resolve(value).then(_next, _throw);
    }
}
function _async_to_generator(fn) {
    return function() {
        var self = this, args = arguments;
        return new Promise(function(resolve, reject) {
            var gen = fn.apply(self, args);
            function _next(value) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
            }
            function _throw(err) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
            }
            _next(undefined);
        });
    };
}
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 _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
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 ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
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);
}
function _ts_generator(thisArg, body) {
    var f, y, t, _ = {
        label: 0,
        sent: function() {
            if (t[0] & 1) throw t[1];
            return t[1];
        },
        trys: [],
        ops: []
    }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
    return d(g, "next", {
        value: verb(0)
    }), d(g, "throw", {
        value: verb(1)
    }), d(g, "return", {
        value: verb(2)
    }), typeof Symbol === "function" && d(g, Symbol.iterator, {
        value: function() {
            return this;
        }
    }), g;
    function verb(n) {
        return function(v) {
            return step([
                n,
                v
            ]);
        };
    }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while(g && (g = 0, op[0] && (_ = 0)), _)try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [
                op[0] & 2,
                t.value
            ];
            switch(op[0]){
                case 0:
                case 1:
                    t = op;
                    break;
                case 4:
                    _.label++;
                    return {
                        value: op[1],
                        done: false
                    };
                case 5:
                    _.label++;
                    y = op[1];
                    op = [
                        0
                    ];
                    continue;
                case 7:
                    op = _.ops.pop();
                    _.trys.pop();
                    continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                        _ = 0;
                        continue;
                    }
                    if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
                        _.label = op[1];
                        break;
                    }
                    if (op[0] === 6 && _.label < t[1]) {
                        _.label = t[1];
                        t = op;
                        break;
                    }
                    if (t && _.label < t[2]) {
                        _.label = t[2];
                        _.ops.push(op);
                        break;
                    }
                    if (t[2]) _.ops.pop();
                    _.trys.pop();
                    continue;
            }
            op = body.call(thisArg, _);
        } catch (e) {
            op = [
                6,
                e
            ];
            y = 0;
        } finally{
            f = t = 0;
        }
        if (op[0] & 5) throw op[1];
        return {
            value: op[0] ? op[1] : void 0,
            done: true
        };
    }
}
import { CopyOutlined, DownOutlined, SettingOutlined } from "@ant-design/icons";
import { ProForm, ProFormSelect } from "@ant-design/pro-components";
import { ConfigProvider, Descriptions, Dropdown, message, Popover, Table } from "antd";
import copy from "copy-to-clipboard";
import React, { lazy, Suspense, useContext, useMemo, useState } from "react";
import { ActionIconBox } from "../../Components/ActionIconBox";
import { Loading } from "../../Components/Loading";
import { I18nContext } from "../../I18n";
import { loadChartRuntime } from "./loadChartRuntime";
import { debounce, getDataHash, isConfigEqual, isNotEmpty, toNumber } from "./utils";
/**
 * @fileoverview 图表渲染组件文件
 *
 * 该文件提供了统一的图表渲染组件，支持多种图表类型的渲染和配置。
 * 包括图表类型切换、配置管理、数据处理等功能。
 *
 * @author md-editor
 * @version 1.0.0
 * @since 2024
 */ /**
 * 获取图表类型映射配置
 *
 * 根据国际化上下文返回图表类型的配置映射，包括图表标题和可切换的图表类型。
 * 支持多种图表类型：饼图、环形图、条形图、折线图、柱状图、面积图、雷达图、散点图、漏斗图、表格、定义列表。
 *
 * @param {object} i18n - 国际化上下文对象
 * @returns {Object} 图表类型映射对象，包含每种图表类型的配置信息
 *
 * @example
 * ```typescript
 * const chartMap = getChartMap(i18n);
 * console.log(chartMap.pie.title); // '饼图'
 * console.log(chartMap.pie.changeData); // ['donut']
 * ```
 *
 * @since 1.0.0
 */ var getChartMap = function getChartMap(i18n) {
    var _i18n_locale, _i18n_locale1, _i18n_locale2, _i18n_locale3, _i18n_locale4, _i18n_locale5, _i18n_locale6, _i18n_locale7, _i18n_locale8, _i18n_locale9, _i18n_locale10, _i18n_locale11, _i18n_locale12;
    return {
        pie: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale = i18n.locale) === null || _i18n_locale === void 0 ? void 0 : _i18n_locale.pieChart) || '饼图',
            changeData: [
                'donut',
                'table'
            ]
        },
        donut: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale1 = i18n.locale) === null || _i18n_locale1 === void 0 ? void 0 : _i18n_locale1.donutChart) || '环形图',
            changeData: [
                'pie',
                'table'
            ]
        },
        bar: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale2 = i18n.locale) === null || _i18n_locale2 === void 0 ? void 0 : _i18n_locale2.barChart) || '条形图',
            changeData: [
                'column',
                'line',
                'area',
                'histogram',
                'boxplot',
                'table'
            ]
        },
        line: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale3 = i18n.locale) === null || _i18n_locale3 === void 0 ? void 0 : _i18n_locale3.lineChart) || '折线图',
            changeData: [
                'column',
                'bar',
                'area',
                'histogram',
                'boxplot',
                'table'
            ]
        },
        column: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale4 = i18n.locale) === null || _i18n_locale4 === void 0 ? void 0 : _i18n_locale4.columnChart) || '柱状图',
            changeData: [
                'bar',
                'line',
                'area',
                'histogram',
                'boxplot',
                'table'
            ]
        },
        area: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale5 = i18n.locale) === null || _i18n_locale5 === void 0 ? void 0 : _i18n_locale5.areaChart) || '面积图',
            changeData: [
                'column',
                'bar',
                'line',
                'histogram',
                'boxplot',
                'table'
            ]
        },
        radar: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale6 = i18n.locale) === null || _i18n_locale6 === void 0 ? void 0 : _i18n_locale6.radarChart) || '雷达图',
            changeData: [
                'table'
            ]
        },
        scatter: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale7 = i18n.locale) === null || _i18n_locale7 === void 0 ? void 0 : _i18n_locale7.scatterChart) || '散点图',
            changeData: [
                'histogram',
                'boxplot',
                'table'
            ]
        },
        funnel: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale8 = i18n.locale) === null || _i18n_locale8 === void 0 ? void 0 : _i18n_locale8.funnelChart) || '漏斗图',
            changeData: [
                'table'
            ]
        },
        boxplot: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale9 = i18n.locale) === null || _i18n_locale9 === void 0 ? void 0 : _i18n_locale9.boxplotChart) || '箱线图',
            changeData: [
                'histogram',
                'column',
                'bar',
                'table'
            ]
        },
        histogram: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale10 = i18n.locale) === null || _i18n_locale10 === void 0 ? void 0 : _i18n_locale10.histogramChart) || '直方图',
            changeData: [
                'boxplot',
                'column',
                'bar',
                'table'
            ]
        },
        table: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale11 = i18n.locale) === null || _i18n_locale11 === void 0 ? void 0 : _i18n_locale11.table) || '表格',
            changeData: [
                'column',
                'line',
                'area',
                'pie',
                'donut',
                'bar',
                'radar',
                'scatter',
                'funnel',
                'boxplot',
                'histogram'
            ]
        },
        descriptions: {
            title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale12 = i18n.locale) === null || _i18n_locale12 === void 0 ? void 0 : _i18n_locale12.descriptions) || '定义列表',
            changeData: [
                'column',
                'line',
                'area',
                'pie',
                'donut',
                'table'
            ]
        }
    };
};
/**
 * 图表运行时渲染器组件实现
 * 负责使用已加载的 runtime 渲染图表
 */ var ChartRuntimeRendererImpl = function ChartRuntimeRendererImpl(param) {
    var chartType = param.chartType, runtime = param.runtime, convertDonutData = param.convertDonutData, convertFlatData = param.convertFlatData, config = param.config, title = param.title, dataTime = param.dataTime, toolBar = param.toolBar, filterBy = param.filterBy, groupBy = param.groupBy, colorLegend = param.colorLegend, chartData = param.chartData, getFieldValue = param.getFieldValue, getFieldValueSafely = param.getFieldValueSafely, _param_loading = param.loading, loading = _param_loading === void 0 ? false : _param_loading;
    var i18n = useContext(I18nContext);
    var DonutChart = runtime.DonutChart, FunnelChart = runtime.FunnelChart, AreaChart = runtime.AreaChart, BarChart = runtime.BarChart, BoxPlotChart = runtime.BoxPlotChart, HistogramChart = runtime.HistogramChart, LineChart = runtime.LineChart, RadarChart = runtime.RadarChart, ScatterChart = runtime.ScatterChart;
    if (chartType === 'pie') {
        var pieSize = (config === null || config === void 0 ? void 0 : config.height) || 400;
        return /*#__PURE__*/ React.createElement(DonutChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-pie"),
            data: convertDonutData,
            configs: [
                {
                    chartStyle: 'pie',
                    showLegend: true
                }
            ],
            width: pieSize,
            height: pieSize,
            title: title,
            showToolbar: true,
            dataTime: dataTime,
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    if (chartType === 'donut') {
        return /*#__PURE__*/ React.createElement(DonutChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-donut"),
            data: convertDonutData,
            configs: [
                {
                    chartStyle: 'donut',
                    showLegend: true
                }
            ],
            height: (config === null || config === void 0 ? void 0 : config.height) || 400,
            title: title,
            showToolbar: true,
            dataTime: dataTime,
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    if (chartType === 'bar') {
        var _ref, _ref1;
        var _config_rest, _config_rest1, _config_rest2;
        return /*#__PURE__*/ React.createElement(BarChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-bar"),
            data: convertFlatData,
            height: (config === null || config === void 0 ? void 0 : config.height) || 400,
            title: title || '',
            indexAxis: 'y',
            stacked: config === null || config === void 0 ? void 0 : (_config_rest = config.rest) === null || _config_rest === void 0 ? void 0 : _config_rest.stacked,
            showLegend: (_ref = config === null || config === void 0 ? void 0 : (_config_rest1 = config.rest) === null || _config_rest1 === void 0 ? void 0 : _config_rest1.showLegend) !== null && _ref !== void 0 ? _ref : true,
            showGrid: (_ref1 = config === null || config === void 0 ? void 0 : (_config_rest2 = config.rest) === null || _config_rest2 === void 0 ? void 0 : _config_rest2.showGrid) !== null && _ref1 !== void 0 ? _ref1 : true,
            dataTime: dataTime,
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    if (chartType === 'line') {
        var _ref2, _ref3;
        var _config_rest3, _config_rest4;
        return /*#__PURE__*/ React.createElement(LineChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-line"),
            data: convertFlatData,
            height: (config === null || config === void 0 ? void 0 : config.height) || 400,
            title: title || '',
            showLegend: (_ref2 = config === null || config === void 0 ? void 0 : (_config_rest3 = config.rest) === null || _config_rest3 === void 0 ? void 0 : _config_rest3.showLegend) !== null && _ref2 !== void 0 ? _ref2 : true,
            showGrid: (_ref3 = config === null || config === void 0 ? void 0 : (_config_rest4 = config.rest) === null || _config_rest4 === void 0 ? void 0 : _config_rest4.showGrid) !== null && _ref3 !== void 0 ? _ref3 : true,
            dataTime: dataTime,
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    if (chartType === 'column') {
        var _ref4, _ref5;
        var _config_rest5, _config_rest6, _config_rest7;
        return /*#__PURE__*/ React.createElement(BarChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-column"),
            data: convertFlatData,
            height: (config === null || config === void 0 ? void 0 : config.height) || 400,
            title: title || '',
            indexAxis: 'x',
            stacked: config === null || config === void 0 ? void 0 : (_config_rest5 = config.rest) === null || _config_rest5 === void 0 ? void 0 : _config_rest5.stacked,
            showLegend: (_ref4 = config === null || config === void 0 ? void 0 : (_config_rest6 = config.rest) === null || _config_rest6 === void 0 ? void 0 : _config_rest6.showLegend) !== null && _ref4 !== void 0 ? _ref4 : true,
            showGrid: (_ref5 = config === null || config === void 0 ? void 0 : (_config_rest7 = config.rest) === null || _config_rest7 === void 0 ? void 0 : _config_rest7.showGrid) !== null && _ref5 !== void 0 ? _ref5 : true,
            dataTime: dataTime,
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    if (chartType === 'area') {
        var _ref6, _ref7;
        var _config_rest8, _config_rest9;
        return /*#__PURE__*/ React.createElement(AreaChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-area"),
            data: convertFlatData,
            height: (config === null || config === void 0 ? void 0 : config.height) || 400,
            title: title || '',
            showLegend: (_ref6 = config === null || config === void 0 ? void 0 : (_config_rest8 = config.rest) === null || _config_rest8 === void 0 ? void 0 : _config_rest8.showLegend) !== null && _ref6 !== void 0 ? _ref6 : true,
            showGrid: (_ref7 = config === null || config === void 0 ? void 0 : (_config_rest9 = config.rest) === null || _config_rest9 === void 0 ? void 0 : _config_rest9.showGrid) !== null && _ref7 !== void 0 ? _ref7 : true,
            dataTime: dataTime,
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    if (chartType === 'radar') {
        var radarData = (chartData || []).map(function(row, i) {
            var filterLabel = getFieldValue(row, filterBy);
            var category = getFieldValue(row, groupBy);
            var type = getFieldValue(row, colorLegend);
            // 使用 getFieldValue 获取 x 和 y 值，支持字段名规范化
            var xValue = getFieldValue(row, config === null || config === void 0 ? void 0 : config.x);
            var yValue = getFieldValue(row, config === null || config === void 0 ? void 0 : config.y);
            return _object_spread({
                label: xValue ? String(xValue) : String(i + 1),
                score: yValue ? Number(yValue) : undefined
            }, category ? {
                category: category
            } : {}, type ? {
                type: type
            } : {}, filterLabel ? {
                filterLabel: filterLabel
            } : {});
        });
        return /*#__PURE__*/ React.createElement(RadarChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-radar"),
            data: radarData,
            height: (config === null || config === void 0 ? void 0 : config.height) || 400,
            title: title || '',
            dataTime: dataTime,
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    if (chartType === 'scatter') {
        var scatterData = (chartData || []).map(function(row) {
            var filterLabel = getFieldValue(row, filterBy);
            var category = getFieldValue(row, groupBy);
            var type = getFieldValue(row, colorLegend);
            // 使用 getFieldValue 获取 x 和 y 值，支持字段名规范化
            var xValue = getFieldValue(row, config === null || config === void 0 ? void 0 : config.x);
            var yValue = getFieldValue(row, config === null || config === void 0 ? void 0 : config.y);
            return _object_spread({
                x: xValue ? Number(xValue) : 0,
                y: yValue ? Number(yValue) : 0
            }, category ? {
                category: category
            } : {}, type ? {
                type: type
            } : {}, filterLabel ? {
                filterLabel: filterLabel
            } : {});
        });
        return /*#__PURE__*/ React.createElement(ScatterChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-scatter"),
            data: scatterData,
            height: (config === null || config === void 0 ? void 0 : config.height) || 400,
            title: title || '',
            dataTime: dataTime,
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    if (chartType === 'funnel') {
        var _i18n_locale, _i18n_locale1;
        var funnelData = (chartData || []).map(function(row, i) {
            var filterLabel = getFieldValue(row, filterBy);
            var category = getFieldValue(row, groupBy);
            var type = getFieldValue(row, colorLegend);
            // 使用 getFieldValue 获取 x 和 y 值，支持字段名规范化
            var xValue = getFieldValue(row, config === null || config === void 0 ? void 0 : config.x);
            var yValue = getFieldValue(row, config === null || config === void 0 ? void 0 : config.y);
            return _object_spread({
                x: xValue ? String(xValue) : String(i + 1),
                y: yValue ? toNumber(yValue, 0) : 0
            }, (row === null || row === void 0 ? void 0 : row.ratio) !== undefined ? {
                ratio: row.ratio
            } : {}, category ? {
                category: category
            } : {}, type ? {
                type: type
            } : {}, filterLabel ? {
                filterLabel: filterLabel
            } : {});
        });
        return /*#__PURE__*/ React.createElement(FunnelChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-funnel"),
            data: funnelData,
            height: (config === null || config === void 0 ? void 0 : config.height) || 400,
            title: title || '',
            dataTime: dataTime,
            typeNames: {
                rate: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale = i18n.locale) === null || _i18n_locale === void 0 ? void 0 : _i18n_locale['common.conversionRate']) || '转化率',
                name: colorLegend || (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale1 = i18n.locale) === null || _i18n_locale1 === void 0 ? void 0 : _i18n_locale1['common.conversion']) || '转化'
            },
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    if (chartType === 'boxplot') {
        // 箱线图数据转换：将原始数据按标签分组
        var boxplotData = [];
        var groupedByLabel = {};
        (chartData || []).forEach(function(row) {
            var label = getFieldValue(row, config === null || config === void 0 ? void 0 : config.x) || '默认';
            var value = getFieldValueSafely(row, config === null || config === void 0 ? void 0 : config.y);
            var type = getFieldValue(row, colorLegend);
            var category = getFieldValue(row, groupBy);
            // filterLabel 用于未来扩展，暂不使用
            var key = "".concat(label, "_").concat(type || 'default');
            if (!groupedByLabel[key]) {
                groupedByLabel[key] = {
                    values: [],
                    type: type || undefined,
                    category: category || undefined
                };
            }
            var numValue = typeof value === 'number' ? value : toNumber(value, Number.NaN);
            if (Number.isFinite(numValue)) {
                groupedByLabel[key].values.push(numValue);
            }
        });
        Object.entries(groupedByLabel).forEach(function(param) {
            var _param = _sliced_to_array(param, 2), key = _param[0], data = _param[1];
            var label = key.split('_')[0];
            if (data.values.length > 0) {
                boxplotData.push(_object_spread({
                    label: label,
                    values: data.values
                }, data.type ? {
                    type: data.type
                } : {}, data.category ? {
                    category: data.category
                } : {}));
            }
        });
        return /*#__PURE__*/ React.createElement(BoxPlotChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-boxplot"),
            data: boxplotData,
            height: (config === null || config === void 0 ? void 0 : config.height) || 400,
            title: title || '',
            dataTime: dataTime,
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    if (chartType === 'histogram') {
        var _ref8;
        var _config_rest10;
        // 直方图数据转换：提取原始值
        // 同时支持预分箱格式：groupKey.DIM_LEFT / groupKey.DIM_RIGHT + MEASURE_PROB[0].actualValue
        var histogramData = (chartData || []).map(function(row) {
            var _row_groupKey, _row_groupKey1, _row_MEASURE_PROB_;
            var dimLeft = row === null || row === void 0 ? void 0 : (_row_groupKey = row.groupKey) === null || _row_groupKey === void 0 ? void 0 : _row_groupKey.DIM_LEFT;
            var dimRight = row === null || row === void 0 ? void 0 : (_row_groupKey1 = row.groupKey) === null || _row_groupKey1 === void 0 ? void 0 : _row_groupKey1.DIM_RIGHT;
            var measureProb = Array.isArray(row === null || row === void 0 ? void 0 : row.MEASURE_PROB) ? (_row_MEASURE_PROB_ = row.MEASURE_PROB[0]) === null || _row_MEASURE_PROB_ === void 0 ? void 0 : _row_MEASURE_PROB_.actualValue : undefined;
            if (typeof dimLeft === 'number' && typeof dimRight === 'number' && typeof measureProb === 'number') {
                var type = getFieldValue(row, colorLegend);
                var category = getFieldValue(row, groupBy);
                var filterLabel = getFieldValue(row, filterBy);
                return _object_spread({
                    value: measureProb,
                    left: dimLeft,
                    right: dimRight
                }, type ? {
                    type: type
                } : {}, category ? {
                    category: category
                } : {}, filterLabel ? {
                    filterLabel: filterLabel
                } : {});
            }
            var value = getFieldValueSafely(row, config === null || config === void 0 ? void 0 : config.y);
            var type1 = getFieldValue(row, colorLegend);
            var category1 = getFieldValue(row, groupBy);
            var filterLabel1 = getFieldValue(row, filterBy);
            var numValue = typeof value === 'number' ? value : toNumber(value, Number.NaN);
            return _object_spread({
                value: Number.isFinite(numValue) ? numValue : 0
            }, type1 ? {
                type: type1
            } : {}, category1 ? {
                category: category1
            } : {}, filterLabel1 ? {
                filterLabel: filterLabel1
            } : {});
        });
        return /*#__PURE__*/ React.createElement(HistogramChart, {
            key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-histogram"),
            data: histogramData,
            height: (config === null || config === void 0 ? void 0 : config.height) || 400,
            title: title || '',
            stacked: (_ref8 = config === null || config === void 0 ? void 0 : (_config_rest10 = config.rest) === null || _config_rest10 === void 0 ? void 0 : _config_rest10.stacked) !== null && _ref8 !== void 0 ? _ref8 : true,
            dataTime: dataTime,
            toolbarExtra: toolBar,
            loading: loading
        });
    }
    return null;
};
/**
 * 图表运行时渲染器组件
 * 使用 React.lazy 延迟加载，仅在需要时加载图表运行时
 */ var ChartRuntimeRenderer = /*#__PURE__*/ lazy(function() {
    return _async_to_generator(function() {
        var runtime;
        return _ts_generator(this, function(_state) {
            switch(_state.label){
                case 0:
                    return [
                        4,
                        loadChartRuntime()
                    ];
                case 1:
                    runtime = _state.sent();
                    return [
                        2,
                        {
                            default: function _default(props) {
                                return /*#__PURE__*/ React.createElement(ChartRuntimeRendererImpl, _object_spread_props(_object_spread({}, props), {
                                    runtime: runtime
                                }));
                            }
                        }
                    ];
            }
        });
    })();
});
/**
 * 加载中的占位组件
 */ var ChartRuntimeFallback = function ChartRuntimeFallback(param) {
    var _param_height = param.height, height = _param_height === void 0 ? 240 : _param_height;
    return /*#__PURE__*/ React.createElement("div", {
        style: {
            minHeight: height,
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center',
            width: '100%',
            color: '#6B7280'
        },
        role: "status",
        "aria-live": "polite"
    }, /*#__PURE__*/ React.createElement(Loading, null));
};
/**
 * ChartRender 组件 - 图表渲染组件
 *
 * 该组件用于渲染各种类型的图表，支持饼图、柱状图、折线图、面积图、表格等。
 * 提供图表类型切换、全屏显示、下载、配置等功能。
 * 使用 React.lazy 和 Suspense 实现代码分割和延迟加载，优化性能。
 *
 * @component
 * @description 图表渲染组件，支持多种图表类型的渲染和交互
 * @param {Object} props - 组件属性
 * @param {'pie'|'bar'|'line'|'column'|'area'|'descriptions'|'table'} props.chartType - 图表类型
 * @param {Record<string, any>[]} props.chartData - 图表数据
 * @param {Object} props.config - 图表配置
 * @param {any} props.config.height - 图表高度
 * @param {any} props.config.x - X轴字段
 * @param {any} props.config.y - Y轴字段
 * @param {any} props.config.rest - 其他配置
 * @param {any} [props.config.index] - 图表索引
 * @param {any} [props.config.chartData] - 图表数据
 * @param {any} [props.config.columns] - 列配置
 * @param {any} [props.node] - 节点数据
 * @param {any} [props.title] - 图表标题
 * @param {boolean} [props.isChartList] - 是否为图表列表
 * @param {number} [props.columnLength] - 列长度
 * @param {(value: number) => void} [props.onColumnLengthChange] - 列长度变化回调
 * @param {string} [props.dataTime] - 数据时间
 * @param {string} [props.groupBy] - 业务分组维度
 * @param {string} [props.filterBy] - 主筛选维度
 * @param {string} [props.colorLegend] - 数据系列维度
 *
 * @example
 * ```tsx
 * <ChartRender
 *   chartType="pie"
 *   chartData={[{ name: "A", value: 10 }, { name: "B", value: 20 }]}
 *   config={{
 *     height: 300,
 *     x: "name",
 *     y: "value"
 *   }}
 *   title="销售数据"
 *   dataTime="2025-06-30 00:00:00"
 * />
 * ```
 *
 * @returns {React.ReactElement} 渲染的图表组件
 *
 * @remarks
 * - 支持多种图表类型（饼图、柱状图、折线图、面积图、表格等）
 * - 提供图表类型切换功能
 * - 支持全屏显示
 * - 提供图表下载功能
 * - 支持图表配置和自定义
 * - 提供响应式布局
 * - 集成国际化支持
 * - 提供图表属性工具栏
 * - 使用 React.lazy 和 Suspense 实现代码分割
 */ export var ChartRender = function ChartRender(props) {
    var _getPrefixCls;
    var // 对于 rest 对象，使用浅比较
    _config_rest, _config_rest1, _config_rest2, _config_rest3, _config_rest4, _config_rest5;
    var _useState = _sliced_to_array(useState(function() {
        return props.chartType;
    }), 2), chartType = _useState[0], setChartType = _useState[1];
    var chartData = props.chartData, isChartList = props.isChartList, onColumnLengthChange = props.onColumnLengthChange, columnLength = props.columnLength, title = props.title, dataTime = props.dataTime, groupBy = props.groupBy, filterBy = props.filterBy, colorLegend = props.colorLegend, _props_loading = props.loading, loading = _props_loading === void 0 ? false : _props_loading;
    var i18n = useContext(I18nContext);
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('agentic-plugin-chart');
    var _useState1 = _sliced_to_array(useState(function() {
        return props.config;
    }), 2), config = _useState1[0], setConfig = _useState1[1];
    var _useState2 = _sliced_to_array(useState(0), 2), renderKey = _useState2[0], setRenderKey = _useState2[1];
    var containerRef = React.useRef(null);
    // 用于缓存上一次的数据和配置，避免不必要的重新计算
    var prevDataRef = React.useRef({
        dataHash: '',
        config: null
    });
    // 计算数据哈希值，用于依赖项比较
    var dataHash = React.useMemo(function() {
        return getDataHash(chartData || []);
    }, [
        chartData
    ]);
    // 防抖更新 renderKey，避免流式数据频繁更新导致的性能问题
    // 增加延迟时间以减少抖动
    var debouncedUpdateRenderKeyRef = React.useRef(debounce(function() {
        setRenderKey(function(k) {
            return k + 1;
        });
    }, 800));
    // 卸载时取消未执行的防抖，避免在测试或 SSR 环境下 teardown 后回调触发 setState
    React.useEffect(function() {
        return function() {
            var _debouncedUpdateRenderKeyRef_current_cancel, _debouncedUpdateRenderKeyRef_current;
            (_debouncedUpdateRenderKeyRef_current = debouncedUpdateRenderKeyRef.current) === null || _debouncedUpdateRenderKeyRef_current === void 0 ? void 0 : (_debouncedUpdateRenderKeyRef_current_cancel = _debouncedUpdateRenderKeyRef_current.cancel) === null || _debouncedUpdateRenderKeyRef_current_cancel === void 0 ? void 0 : _debouncedUpdateRenderKeyRef_current_cancel.call(_debouncedUpdateRenderKeyRef_current);
        };
    }, []);
    var renderDescriptionsFallback = React.useMemo(function() {
        var _config_columns;
        var columnCount = (config === null || config === void 0 ? void 0 : (_config_columns = config.columns) === null || _config_columns === void 0 ? void 0 : _config_columns.length) || 0;
        return chartData.length < 2 && columnCount > 8;
    }, [
        chartData,
        config === null || config === void 0 ? void 0 : config.columns
    ]);
    var shouldLoadRuntime = chartType !== 'table' && chartType !== 'descriptions' && !renderDescriptionsFallback;
    // 获取国际化的图表类型映射
    var ChartMap = useMemo(function() {
        return getChartMap(i18n);
    }, [
        i18n
    ]);
    var getAxisTitles = function getAxisTitles() {
        var _config_columns_find, _config_columns, _config_columns_find1, _config_columns1;
        var xCol = config === null || config === void 0 ? void 0 : (_config_columns = config.columns) === null || _config_columns === void 0 ? void 0 : (_config_columns_find = _config_columns.find) === null || _config_columns_find === void 0 ? void 0 : _config_columns_find.call(_config_columns, function(c) {
            return (c === null || c === void 0 ? void 0 : c.dataIndex) === (config === null || config === void 0 ? void 0 : config.x);
        });
        var yCol = config === null || config === void 0 ? void 0 : (_config_columns1 = config.columns) === null || _config_columns1 === void 0 ? void 0 : (_config_columns_find1 = _config_columns1.find) === null || _config_columns_find1 === void 0 ? void 0 : _config_columns_find1.call(_config_columns1, function(c) {
            return (c === null || c === void 0 ? void 0 : c.dataIndex) === (config === null || config === void 0 ? void 0 : config.y);
        });
        return {
            xTitle: (xCol === null || xCol === void 0 ? void 0 : xCol.title) || String((config === null || config === void 0 ? void 0 : config.x) || ''),
            yTitle: (yCol === null || yCol === void 0 ? void 0 : yCol.title) || String((config === null || config === void 0 ? void 0 : config.y) || '')
        };
    };
    var buildXIndexer = function buildXIndexer() {
        var map = new Map();
        var idx = 1;
        (chartData || []).forEach(function(row) {
            var key = row === null || row === void 0 ? void 0 : row[config === null || config === void 0 ? void 0 : config.x];
            if (isNotEmpty(key) && !map.has(key)) {
                map.set(key, idx++);
            }
        });
        return map;
    };
    /**
   * 规范化字段名，统一处理转义字符
   * 将 `index\_value` 转换为 `index_value`，确保字段名一致
   */ var normalizeFieldName = function normalizeFieldName(fieldName) {
        if (!fieldName) return fieldName;
        // 移除转义字符：将 `\_` 转换为 `_`，`\\` 转换为 `\`
        return fieldName.replace(/\\_/g, '_').replace(/\\\\/g, '\\').replace(/\\(?=")/g, '') // 移除转义的双引号
        .trim();
    };
    /**
   * 安全地获取字段值，如果字段名不匹配，也尝试规范化后的字段名
   */ var getFieldValueSafely = function getFieldValueSafely(row, field) {
        if (!field) return undefined;
        // 先尝试直接访问
        if (row[field] !== undefined) {
            return row[field];
        }
        // 如果直接访问失败，尝试规范化后的字段名
        var normalizedField = normalizeFieldName(field);
        if (normalizedField !== field && row[normalizedField] !== undefined) {
            return row[normalizedField];
        }
        // 也尝试反向：如果字段名已经是规范化的，尝试带转义字符的版本
        var escapedField = field.replace(/_/g, '\\_');
        if (escapedField !== field && row[escapedField] !== undefined) {
            return row[escapedField];
        }
        return undefined;
    };
    var getFieldValue = function getFieldValue(row, field) {
        var value = getFieldValueSafely(row, field);
        if (field && isNotEmpty(value)) {
            return String(value);
        }
        return undefined;
    };
    var convertFlatData = useMemo(function() {
        var _getAxisTitles = getAxisTitles(), xTitle = _getAxisTitles.xTitle, yTitle = _getAxisTitles.yTitle;
        var xIndexer = buildXIndexer();
        return (chartData || []).map(function(row, i) {
            var _xIndexer_get;
            var rawX = getFieldValueSafely(row, config === null || config === void 0 ? void 0 : config.x);
            var rawY = getFieldValueSafely(row, config === null || config === void 0 ? void 0 : config.y);
            var category = getFieldValue(row, groupBy);
            var type = getFieldValue(row, colorLegend);
            var filterLabel = getFieldValue(row, filterBy);
            var x = typeof rawX === 'number' ? rawX : isNotEmpty(rawX) ? String(rawX) : String((_xIndexer_get = xIndexer.get(rawX)) !== null && _xIndexer_get !== void 0 ? _xIndexer_get : i + 1);
            var y = typeof rawY === 'number' ? rawY : isNotEmpty(rawY) ? String(rawY) : '';
            return _object_spread({
                x: x,
                y: y,
                xtitle: xTitle,
                ytitle: yTitle
            }, type ? {
                type: type
            } : {}, category ? {
                category: category
            } : {}, filterLabel ? {
                filterLabel: filterLabel
            } : {});
        });
    }, [
        // 使用更高效的依赖项比较
        dataHash,
        config === null || config === void 0 ? void 0 : config.x,
        config === null || config === void 0 ? void 0 : config.y,
        config === null || config === void 0 ? void 0 : config.height,
        config === null || config === void 0 ? void 0 : config.index,
        config === null || config === void 0 ? void 0 : (_config_rest = config.rest) === null || _config_rest === void 0 ? void 0 : _config_rest.stacked,
        config === null || config === void 0 ? void 0 : (_config_rest1 = config.rest) === null || _config_rest1 === void 0 ? void 0 : _config_rest1.showLegend,
        config === null || config === void 0 ? void 0 : (_config_rest2 = config.rest) === null || _config_rest2 === void 0 ? void 0 : _config_rest2.showGrid,
        title,
        groupBy,
        colorLegend,
        filterBy
    ]);
    var convertDonutData = useMemo(function() {
        return (chartData || []).map(function(row) {
            var _getFieldValueSafely;
            var category = getFieldValue(row, groupBy);
            var label = String((_getFieldValueSafely = getFieldValueSafely(row, config === null || config === void 0 ? void 0 : config.x)) !== null && _getFieldValueSafely !== void 0 ? _getFieldValueSafely : '');
            var value = toNumber(getFieldValueSafely(row, config === null || config === void 0 ? void 0 : config.y), 0);
            var filterLabel = getFieldValue(row, filterBy);
            return _object_spread({
                label: label,
                value: value
            }, category ? {
                category: category
            } : {}, filterLabel ? {
                filterLabel: filterLabel
            } : {});
        });
    }, [
        // 使用更高效的依赖项比较
        dataHash,
        config === null || config === void 0 ? void 0 : config.x,
        config === null || config === void 0 ? void 0 : config.y,
        config === null || config === void 0 ? void 0 : config.height,
        config === null || config === void 0 ? void 0 : config.index,
        title,
        groupBy,
        filterBy
    ]);
    React.useEffect(function() {
        setChartType(props.chartType);
    }, [
        props.chartType
    ]);
    // 监听数据变化，使用防抖更新渲染键
    React.useEffect(function() {
        var configChanged = !isConfigEqual(prevDataRef.current.config, config);
        var groupByChanged = prevDataRef.current.groupBy !== groupBy;
        var colorLegendChanged = prevDataRef.current.colorLegend !== colorLegend;
        var filterByChanged = prevDataRef.current.filterBy !== filterBy;
        var hasChanged = prevDataRef.current.dataHash !== dataHash || configChanged || groupByChanged || colorLegendChanged || filterByChanged;
        if (hasChanged) {
            var dataHashChanged = prevDataRef.current.dataHash !== dataHash;
            // 更新缓存
            prevDataRef.current = {
                dataHash: dataHash,
                config: config,
                groupBy: groupBy,
                colorLegend: colorLegend,
                filterBy: filterBy
            };
            // 对于流式数据，使用防抖更新，避免频繁渲染
            if (dataHashChanged) {
                debouncedUpdateRenderKeyRef.current();
            } else {
                // 配置变化时立即更新
                setRenderKey(function(k) {
                    return k + 1;
                });
            }
        }
    }, [
        dataHash,
        config,
        groupBy,
        colorLegend,
        filterBy
    ]);
    var chartConfigFormPrefixCls = (_getPrefixCls = getPrefixCls('agentic-chart-config-form')) !== null && _getPrefixCls !== void 0 ? _getPrefixCls : 'ant-agentic-chart-config-form';
    /**
   * 将表格数据转换为 Markdown 格式
   */ var generateMarkdownTable = function generateMarkdownTable() {
        var columns = (config === null || config === void 0 ? void 0 : config.columns) || [];
        var data = chartData || [];
        if (columns.length === 0 || data.length === 0) {
            return '';
        }
        // 表头
        var headerRow = columns.filter(function(col) {
            return col === null || col === void 0 ? void 0 : col.title;
        }).map(function(col) {
            return col.title;
        }).join(' | ');
        // 分隔行
        var separatorRow = columns.filter(function(col) {
            return col === null || col === void 0 ? void 0 : col.title;
        }).map(function() {
            return '---';
        }).join(' | ');
        // 数据行
        var dataRows = data.map(function(row) {
            return columns.filter(function(col) {
                return col === null || col === void 0 ? void 0 : col.title;
            }).map(function(col) {
                var value = row[col.dataIndex];
                return value !== undefined && value !== null ? String(value) : '';
            }).join(' | ');
        });
        return [
            headerRow,
            separatorRow
        ].concat(_to_consumable_array(dataRows)).join('\n');
    };
    /**
   * 复制表格 Markdown
   */ var handleCopyMarkdown = function handleCopyMarkdown() {
        var markdown = generateMarkdownTable();
        if (markdown) {
            var _i18n_locale;
            copy(markdown);
            message.success((i18n === null || i18n === void 0 ? void 0 : (_i18n_locale = i18n.locale) === null || _i18n_locale === void 0 ? void 0 : _i18n_locale.copySuccess) || '复制成功');
        }
    };
    /**
   * 图表配置
   */ var toolBar = useMemo(function() {
        var _ChartMap_chartType_changeData, _ChartMap_chartType, _ChartMap_chartType1, _i18n_locale, _i18n_locale1, _i18n_locale2, _config_columns_filter, _config_columns, _config_columns_filter1, _config_columns1, _i18n_locale3, _i18n_locale4;
        return [
            /*#__PURE__*/ React.createElement(Dropdown, {
                key: "dropdown",
                menu: {
                    items: ((_ChartMap_chartType = ChartMap[chartType]) === null || _ChartMap_chartType === void 0 ? void 0 : (_ChartMap_chartType_changeData = _ChartMap_chartType.changeData) === null || _ChartMap_chartType_changeData === void 0 ? void 0 : _ChartMap_chartType_changeData.map(function(key) {
                        var _i18n_locale, _ChartMap_key;
                        return {
                            key: key,
                            label: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale = i18n.locale) === null || _i18n_locale === void 0 ? void 0 : _i18n_locale[key + 'eChart']) || ((_ChartMap_key = ChartMap[key]) === null || _ChartMap_key === void 0 ? void 0 : _ChartMap_key.title),
                            onClick: function onClick() {
                                setChartType(key);
                            }
                        };
                    })) || []
                },
                getPopupContainer: function getPopupContainer() {
                    return document.body;
                }
            }, /*#__PURE__*/ React.createElement("span", {
                style: {
                    fontSize: 12,
                    display: 'flex',
                    alignItems: 'center',
                    gap: 4,
                    border: '1px solid #f0f0f0',
                    padding: '4px 12px',
                    borderRadius: '1em'
                }
            }, (_ChartMap_chartType1 = ChartMap[chartType]) === null || _ChartMap_chartType1 === void 0 ? void 0 : _ChartMap_chartType1.title, /*#__PURE__*/ React.createElement(DownOutlined, {
                style: {
                    fontSize: 8
                }
            }))),
            isChartList ? /*#__PURE__*/ React.createElement(Dropdown, {
                key: "dropdown-column",
                menu: {
                    items: new Array(4).fill(0).map(function(_, i) {
                        return {
                            key: i + 1,
                            label: i + 1,
                            onClick: function onClick() {
                                onColumnLengthChange === null || onColumnLengthChange === void 0 ? void 0 : onColumnLengthChange(i + 1);
                            }
                        };
                    })
                },
                getPopupContainer: function getPopupContainer() {
                    return document.body;
                }
            }, /*#__PURE__*/ React.createElement("span", {
                style: {
                    fontSize: 12,
                    display: 'flex',
                    alignItems: 'center',
                    gap: 4,
                    border: '1px solid #f0f0f0',
                    padding: '4px 12px',
                    borderRadius: '1em'
                }
            }, columnLength, " ", (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale = i18n.locale) === null || _i18n_locale === void 0 ? void 0 : _i18n_locale.columns) || '列', /*#__PURE__*/ React.createElement(DownOutlined, {
                style: {
                    fontSize: 8
                }
            }))) : null,
            /*#__PURE__*/ React.createElement(Popover, {
                arrow: false,
                styles: {
                    body: {
                        padding: 8
                    }
                },
                key: "config",
                title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale1 = i18n.locale) === null || _i18n_locale1 === void 0 ? void 0 : _i18n_locale1.configChart) || '配置图表',
                trigger: 'click',
                getPopupContainer: function getPopupContainer() {
                    return document.body;
                },
                content: /*#__PURE__*/ React.createElement(ConfigProvider, {
                    componentSize: "small"
                }, /*#__PURE__*/ React.createElement(ProForm, {
                    prefixCls: chartConfigFormPrefixCls,
                    submitter: {
                        searchConfig: {
                            submitText: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale2 = i18n.locale) === null || _i18n_locale2 === void 0 ? void 0 : _i18n_locale2.updateChart) || '更新'
                        }
                    },
                    style: {
                        width: 300
                    },
                    initialValues: config,
                    onFinish: function onFinish(values) {
                        setConfig(_object_spread({}, props.config, values));
                        setRenderKey(function(k) {
                            return k + 1;
                        });
                    }
                }, /*#__PURE__*/ React.createElement("div", {
                    className: "".concat(chartConfigFormPrefixCls, "__content"),
                    style: {
                        maxHeight: '70vh',
                        overflow: 'auto'
                    }
                }, /*#__PURE__*/ React.createElement("div", {
                    className: "".concat(chartConfigFormPrefixCls, "__fields"),
                    style: {
                        display: 'flex',
                        gap: 8
                    }
                }, /*#__PURE__*/ React.createElement(ProFormSelect, {
                    label: "X",
                    name: "x",
                    fieldProps: {
                        onClick: function onClick(e) {
                            e.stopPropagation();
                        }
                    },
                    options: (_config_columns = config.columns) === null || _config_columns === void 0 ? void 0 : (_config_columns_filter = _config_columns.filter(function(item) {
                        return item.title;
                    })) === null || _config_columns_filter === void 0 ? void 0 : _config_columns_filter.map(function(item) {
                        return {
                            label: item.title,
                            value: item.dataIndex
                        };
                    })
                }), /*#__PURE__*/ React.createElement(ProFormSelect, {
                    name: "y",
                    label: "Y",
                    fieldProps: {
                        onClick: function onClick(e) {
                            e.stopPropagation();
                        }
                    },
                    options: (_config_columns1 = config.columns) === null || _config_columns1 === void 0 ? void 0 : (_config_columns_filter1 = _config_columns1.filter(function(item) {
                        return item.title;
                    })) === null || _config_columns_filter1 === void 0 ? void 0 : _config_columns_filter1.map(function(item) {
                        return {
                            label: item.title,
                            value: item.dataIndex
                        };
                    })
                })))))
            }, /*#__PURE__*/ React.createElement(ActionIconBox, {
                title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale3 = i18n.locale) === null || _i18n_locale3 === void 0 ? void 0 : _i18n_locale3.configChart) || '配置图表'
            }, /*#__PURE__*/ React.createElement(SettingOutlined, {
                style: {
                    color: 'rgba(0, 25, 61, 0.3255)'
                }
            }))),
            /*#__PURE__*/ React.createElement(ActionIconBox, {
                key: "copy-markdown",
                title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale4 = i18n.locale) === null || _i18n_locale4 === void 0 ? void 0 : _i18n_locale4.copyMarkdown) || '复制表格'
            }, /*#__PURE__*/ React.createElement(CopyOutlined, {
                style: {
                    color: 'rgba(0, 25, 61, 0.3255)'
                },
                onClick: handleCopyMarkdown
            }))
        ].filter(function(item) {
            return !!item;
        });
    }, [
        chartType,
        ChartMap,
        i18n === null || i18n === void 0 ? void 0 : i18n.locale,
        isChartList,
        columnLength,
        onColumnLengthChange,
        config,
        props.config,
        chartConfigFormPrefixCls,
        chartData
    ]);
    var chartDom = useMemo(function() {
        var _window;
        if (typeof window === 'undefined') return null;
        if (process.env.NODE_ENV === 'test') return null;
        //@ts-ignore
        if ((_window = window) === null || _window === void 0 ? void 0 : _window.notRenderChart) return null;
        if (chartType === 'table') {
            return /*#__PURE__*/ React.createElement("div", {
                key: config === null || config === void 0 ? void 0 : config.index,
                className: "".concat(prefixCls, "__table"),
                contentEditable: false,
                style: {
                    margin: 12,
                    overflow: 'auto',
                    border: '1px solid #eee',
                    borderRadius: '0.5em',
                    flex: 1,
                    maxWidth: 'calc(100% - 32px)',
                    maxHeight: 400,
                    userSelect: 'none',
                    display: 'flex',
                    flexDirection: 'column'
                }
            }, /*#__PURE__*/ React.createElement("div", {
                style: {
                    display: 'flex',
                    alignItems: 'center',
                    gap: 8,
                    padding: '8px 12px',
                    borderBottom: '1px solid #eee',
                    flexShrink: 0
                }
            }, title && /*#__PURE__*/ React.createElement("span", {
                style: {
                    fontSize: 14,
                    fontWeight: 500
                }
            }, title), /*#__PURE__*/ React.createElement("div", {
                style: {
                    marginLeft: 'auto',
                    display: 'flex',
                    gap: 8
                }
            }, toolBar)), /*#__PURE__*/ React.createElement("div", {
                style: {
                    flex: 1,
                    overflow: 'auto'
                }
            }, /*#__PURE__*/ React.createElement(Table, {
                size: "small",
                dataSource: chartData,
                columns: config === null || config === void 0 ? void 0 : config.columns,
                pagination: false,
                rowKey: function rowKey(record) {
                    return record.key;
                }
            })));
        }
        if (chartType === 'descriptions' || renderDescriptionsFallback) {
            return /*#__PURE__*/ React.createElement("div", {
                key: config === null || config === void 0 ? void 0 : config.index,
                className: "".concat(prefixCls, "__descriptions"),
                style: {
                    display: 'flex',
                    flexDirection: 'column',
                    gap: 8,
                    margin: 12
                }
            }, /*#__PURE__*/ React.createElement("div", {
                style: {
                    display: 'flex',
                    alignItems: 'center',
                    gap: 8,
                    padding: '8px 0',
                    flexShrink: 0
                }
            }, title && /*#__PURE__*/ React.createElement("span", {
                style: {
                    fontSize: 14,
                    fontWeight: 500
                }
            }, title), /*#__PURE__*/ React.createElement("div", {
                style: {
                    marginLeft: 'auto',
                    display: 'flex',
                    gap: 8
                }
            }, toolBar)), chartData.map(function(row, rowIndex) {
                var _config_columns;
                return /*#__PURE__*/ React.createElement(Descriptions, {
                    bordered: true,
                    key: "".concat(config === null || config === void 0 ? void 0 : config.index, "-").concat(rowIndex),
                    column: {
                        xxl: 2,
                        xl: 2,
                        lg: 2,
                        md: 2,
                        sm: 1,
                        xs: 1
                    },
                    items: config === null || config === void 0 ? void 0 : (_config_columns = config.columns) === null || _config_columns === void 0 ? void 0 : _config_columns.map(function(column) {
                        if (!column.title || !column.dataIndex) return null;
                        return {
                            label: column.title || '',
                            children: row[column.dataIndex]
                        };
                    }).filter(function(item) {
                        return !!item;
                    })
                });
            }));
        }
        if (shouldLoadRuntime) {
            return /*#__PURE__*/ React.createElement(Suspense, {
                fallback: /*#__PURE__*/ React.createElement(ChartRuntimeFallback, {
                    height: (config === null || config === void 0 ? void 0 : config.height) || 240
                })
            }, /*#__PURE__*/ React.createElement(ChartRuntimeRenderer, {
                loading: loading,
                chartType: chartType,
                convertDonutData: convertDonutData,
                convertFlatData: convertFlatData,
                config: config,
                renderKey: renderKey,
                title: title,
                dataTime: dataTime,
                toolBar: toolBar,
                filterBy: filterBy,
                groupBy: groupBy,
                colorLegend: colorLegend,
                chartData: chartData,
                getFieldValue: getFieldValue,
                getFieldValueSafely: getFieldValueSafely
            }));
        }
        return null;
    }, [
        chartType,
        // 使用更高效的依赖项
        dataHash,
        config === null || config === void 0 ? void 0 : config.x,
        config === null || config === void 0 ? void 0 : config.y,
        config === null || config === void 0 ? void 0 : config.height,
        config === null || config === void 0 ? void 0 : config.index,
        renderKey,
        toolBar,
        convertDonutData,
        convertFlatData,
        title,
        dataTime,
        filterBy,
        groupBy,
        colorLegend,
        shouldLoadRuntime,
        renderDescriptionsFallback,
        chartData,
        config === null || config === void 0 ? void 0 : config.columns,
        config === null || config === void 0 ? void 0 : (_config_rest3 = config.rest) === null || _config_rest3 === void 0 ? void 0 : _config_rest3.stacked,
        config === null || config === void 0 ? void 0 : (_config_rest4 = config.rest) === null || _config_rest4 === void 0 ? void 0 : _config_rest4.showLegend,
        config === null || config === void 0 ? void 0 : (_config_rest5 = config.rest) === null || _config_rest5 === void 0 ? void 0 : _config_rest5.showGrid,
        loading
    ]);
    return /*#__PURE__*/ React.createElement("div", {
        ref: containerRef,
        className: prefixCls,
        style: {
            width: '100%'
        },
        contentEditable: false
    }, chartDom);
};
