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 React from "react";
var Legend = function(param) {
    var chartData = param.chartData, backgroundColors = param.backgroundColors, hiddenDataIndicesByChart = param.hiddenDataIndicesByChart, chartIndex = param.chartIndex, onLegendItemClick = param.onLegendItemClick, total = param.total, baseClassName = param.baseClassName, hashId = param.hashId, isMobile = param.isMobile;
    var hiddenDataIndices = React.useMemo(function() {
        return hiddenDataIndicesByChart[chartIndex] || new Set();
    }, [
        hiddenDataIndicesByChart,
        chartIndex
    ]);
    return /*#__PURE__*/ React.createElement("div", {
        className: [
            "".concat(baseClassName, "-legend"),
            hashId
        ].filter(Boolean).join(' '),
        style: _object_spread({
            marginLeft: isMobile ? 0 : 12,
            maxHeight: isMobile ? '120px' : 'none',
            overflowY: isMobile ? 'auto' : 'visible'
        }, isMobile ? {
            alignSelf: 'center'
        } : {})
    }, chartData.map(function(d, i) {
        var isHidden = hiddenDataIndices.has(i);
        var _obj;
        return /*#__PURE__*/ React.createElement("div", {
            key: i,
            className: [
                "".concat(baseClassName, "-legend-item"),
                hashId
            ].filter(Boolean).join(' '),
            style: {
                cursor: 'pointer',
                padding: isMobile ? '4px 0' : '6px 0',
                fontSize: isMobile ? 11 : 12,
                minHeight: isMobile ? '24px' : '28px',
                textDecoration: isHidden ? 'line-through' : 'none'
            },
            onClick: function() {
                return onLegendItemClick(i);
            },
            onKeyDown: function(e) {
                if (e.key === 'Enter' || e.key === ' ') {
                    e.preventDefault();
                    onLegendItemClick(i);
                }
            },
            tabIndex: 0,
            role: "button",
            "aria-label": "".concat(isHidden ? '显示' : '隐藏', " ").concat(d.label)
        }, /*#__PURE__*/ React.createElement("span", {
            className: [
                "".concat(baseClassName, "-legend-color"),
                hashId
            ].filter(Boolean).join(' '),
            style: (_obj = {}, _define_property(_obj, '--donut-legend-color', backgroundColors[i] || '#ccc'), _define_property(_obj, "width", isMobile ? 10 : 12), _define_property(_obj, "height", isMobile ? 10 : 12), _define_property(_obj, "borderRadius", 4), _define_property(_obj, "marginRight", isMobile ? 4 : 6), _obj)
        }), /*#__PURE__*/ React.createElement("span", {
            className: [
                "".concat(baseClassName, "-legend-label"),
                hashId
            ].filter(Boolean).join(' '),
            style: {
                fontSize: isMobile ? 11 : 13,
                flex: isMobile ? '0 1 auto' : 1,
                minWidth: isMobile ? '60px' : 'auto'
            }
        }, d.label), /*#__PURE__*/ React.createElement("span", {
            className: [
                "".concat(baseClassName, "-legend-value"),
                hashId
            ].filter(Boolean).join(' '),
            style: {
                fontSize: isMobile ? 11 : 13,
                fontWeight: isMobile ? 400 : 500,
                marginLeft: isMobile ? 8 : 15,
                display: 'flex',
                flexDirection: 'row',
                alignItems: 'center'
            }
        }, /*#__PURE__*/ React.createElement("span", null, d.value), /*#__PURE__*/ React.createElement("span", {
            className: [
                "".concat(baseClassName, "-legend-percent"),
                hashId
            ].filter(Boolean).join(' '),
            style: {
                fontSize: isMobile ? 10 : 12,
                marginLeft: isMobile ? 6 : 8,
                marginTop: 0
            }
        }, function() {
            var v = typeof d.value === 'number' ? d.value : Number(d.value);
            return total > 0 && Number.isFinite(v) ? (v / total * 100).toFixed(0) : '0';
        }(), "%")));
    }));
};
export default Legend;
