import { ConfigProvider } from "antd";
import classNames from "clsx";
import React, { memo, useContext, useMemo } from "react";
import { I18nContext } from "../../../I18n";
import { useStyle } from "./style";
import { parseQuadrantsFromRows } from "./utils";
var QUADRANT_MODIFIERS = [
    'q0',
    'q1',
    'q2',
    'q3'
];
var QuadrantChartComponent = function QuadrantChartComponent(param) {
    var title = param.title, columns = param.columns, data = param.data, toolbar = param.toolbar, className = param.className, style = param.style;
    var _i18n_locale;
    var i18n = useContext(I18nContext);
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('agentic-quadrant-chart');
    var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var quadrants = useMemo(function() {
        return parseQuadrantsFromRows(data, columns);
    }, [
        data,
        columns
    ]);
    var headerNode = useMemo(function() {
        if (!title && !toolbar) return null;
        return /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-header"), hashId),
            "data-testid": "quadrant-chart-header"
        }, title ? /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-title"), hashId),
            "data-testid": "quadrant-chart-title"
        }, title) : null, toolbar ? /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-toolbar"), hashId),
            "data-testid": "quadrant-chart-toolbar"
        }, toolbar) : null);
    }, [
        title,
        toolbar,
        prefixCls,
        hashId
    ]);
    if (!data.length || !columns.length) {
        var _i18n_locale1;
        return wrapSSR(/*#__PURE__*/ React.createElement("div", {
            className: classNames(prefixCls, hashId, className),
            style: style,
            contentEditable: false,
            "data-testid": "quadrant-chart"
        }, headerNode, /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-empty"), hashId),
            "data-testid": "quadrant-chart-empty"
        }, (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale1 = i18n.locale) === null || _i18n_locale1 === void 0 ? void 0 : _i18n_locale1.quadrantChart) || '四象限图')));
    }
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: classNames(prefixCls, hashId, className),
        style: style,
        contentEditable: false,
        "data-testid": "quadrant-chart"
    }, headerNode, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-grid"), hashId),
        role: "grid",
        "aria-label": (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale = i18n.locale) === null || _i18n_locale === void 0 ? void 0 : _i18n_locale.quadrantChart) || '四象限图',
        "data-testid": "quadrant-chart-grid"
    }, quadrants.map(function(group, qi) {
        return /*#__PURE__*/ React.createElement("div", {
            key: qi,
            className: classNames("".concat(prefixCls, "-quadrant"), "".concat(prefixCls, "-quadrant--").concat(QUADRANT_MODIFIERS[qi]), hashId),
            role: "gridcell",
            "aria-label": group.label,
            "data-testid": "quadrant-chart-".concat(QUADRANT_MODIFIERS[qi])
        }, /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-quadrant-label"), hashId),
            "data-testid": "quadrant-chart-".concat(QUADRANT_MODIFIERS[qi], "-label")
        }, group.label), group.items.length > 0 ? /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-quadrant-items"), hashId),
            role: "list",
            "data-testid": "quadrant-chart-".concat(QUADRANT_MODIFIERS[qi], "-items")
        }, group.items.map(function(item, idx) {
            return /*#__PURE__*/ React.createElement("span", {
                key: "".concat(idx, "-").concat(item),
                className: classNames("".concat(prefixCls, "-item"), hashId),
                role: "listitem",
                title: item
            }, item);
        })) : null);
    }))));
};
QuadrantChartComponent.displayName = 'QuadrantChart';
export var QuadrantChart = /*#__PURE__*/ memo(QuadrantChartComponent);
