'use client';
import { __rest, __assign } from '../_virtual/_tslib.js';
import classNames from '../external/classnames/index.js';
import React__default from 'react';
import AutoSizer from '../external/react-virtualized-auto-sizer/dist/react-virtualized-auto-sizer.esm.js';
import { createColorMap, ChartTooltip, ChartLegend, DEFAULT_COLORS } from './chart-components.js';
import styles from './pie-chart.module.css.js';
import { Cell } from '../external/recharts/es6/component/Cell.js';
import { PieChart as PieChart$1 } from '../external/recharts/es6/chart/PieChart.js';
import { Tooltip } from '../external/recharts/es6/component/Tooltip.js';
import { Legend } from '../external/recharts/es6/component/Legend.js';
import { Pie } from '../external/recharts/es6/polar/Pie.js';

var PieChart = React__default.forwardRef(function PieChartRoot(_a, ref) {
    var className = _a.className, category = _a.category, _b = _a.colors, colors = _b === void 0 ? DEFAULT_COLORS : _b, dark = _a.dark, data = _a.data, index = _a.index, otherProps = __rest(_a, ["className", "category", "colors", "dark", "data", "index"]);
    var colorMap = createColorMap({ categories: data.map(function (obj) { return obj[index]; }), colors: colors });
    var cells = data.map(function (_, index) {
        var color = colors[index % colors.length];
        return React__default.createElement(Cell, { key: index, fill: color });
    });
    return (React__default.createElement("div", __assign({ className: classNames(className, styles.root), ref: ref }, otherProps, { style: __assign(__assign({}, otherProps.style), { minHeight: 200, minWidth: 300 }) }),
        React__default.createElement(AutoSizer, null, function (_a) {
            var _b;
            var height = _a.height, width = _a.width;
            return (React__default.createElement(PieChart$1, { className: classNames((_b = {}, _b[styles.dark] = dark, _b)), data: data, height: height, width: width },
                React__default.createElement(Tooltip, { content: function (_a) {
                        var active = _a.active, payload = _a.payload, label = _a.label;
                        return (React__default.createElement(ChartTooltip, { active: active, colorMap: colorMap, dark: dark, label: label, payload: payload }));
                    }, isAnimationActive: false }),
                React__default.createElement(Legend, { content: function (_a) {
                        var payload = _a.payload;
                        return React__default.createElement(ChartLegend, { colorMap: colorMap, dark: dark, payload: payload });
                    }, verticalAlign: "bottom" }),
                React__default.createElement(Pie, { className: styles.pie, data: data, cx: "50%", cy: "50%", startAngle: 90, endAngle: -270, innerRadius: "75%", isAnimationActive: false, outerRadius: "100%", dataKey: category, nameKey: index }, cells)));
        })));
});

export { PieChart };
//# sourceMappingURL=pie-chart.js.map
