'use client';
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Pie", {
    enumerable: true,
    get: function() {
        return Pie;
    }
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _d3shape = require("d3-shape");
const _index = require("../Arc/index");
const _usePieStylesstyles = require("./usePieStyles.styles");
const _index1 = require("../../../utilities/index");
const TEXT_PADDING = 5;
const Pie = /*#__PURE__*/ _react.forwardRef((props, forwardedRef)=>{
    _react.useEffect(()=>{
        (0, _index1.wrapTextInsideDonut)(classes.insideDonutString, props.innerRadius * 2 - TEXT_PADDING);
    }, []);
    let _totalValue;
    const classes = (0, _usePieStylesstyles.usePieStyles)(props);
    const pieForFocusRing = (0, _d3shape.pie)().sort(null).value((d)=>d.data).padAngle(0);
    function _focusCallback(data, id, e, targetElement) {
        props.onFocusCallback(data, id, e, targetElement);
    }
    function _hoverCallback(data, e, targetElement) {
        props.hoverOnCallback(data, e, targetElement);
    }
    function _computeTotalValue() {
        let totalValue = 0;
        props.data.forEach((arc)=>{
            totalValue += arc.data;
        });
        return totalValue;
    }
    function arcGenerator(d, i, focusData, href) {
        const color = d && d.data && d.data.color;
        return /*#__PURE__*/ _react.createElement(_index.Arc, {
            key: i,
            data: d,
            focusData: focusData,
            innerRadius: props.innerRadius,
            outerRadius: props.outerRadius,
            color: color,
            onFocusCallback: _focusCallback,
            hoverOnCallback: _hoverCallback,
            onBlurCallback: props.onBlurCallback,
            hoverLeaveCallback: props.hoverLeaveCallback,
            uniqText: props.uniqText,
            activeArc: props.activeArc,
            href: href,
            calloutId: props.calloutId,
            valueInsideDonut: props.valueInsideDonut,
            focusedArcId: props.focusedArcId,
            showLabelsInPercent: props.showLabelsInPercent,
            totalValue: _totalValue,
            hideLabels: props.hideLabels
        });
    }
    const { data } = props;
    // Filter out data points with value 0 to avoid gaps in the donut chart
    const filteredData = data.filter((d)=>d.data !== 0);
    const focusData = pieForFocusRing(filteredData.map((d)=>d.data));
    const piechart = (0, _d3shape.pie)().sort(null).value((d)=>d.data).padAngle(0.02)(filteredData);
    const translate = `translate(${props.width / 2}, ${props.height / 2})`;
    _totalValue = _computeTotalValue();
    return /*#__PURE__*/ _react.createElement("g", {
        transform: translate
    }, piechart.map((d, i)=>arcGenerator(d, i, focusData[i], props.href)), props.valueInsideDonut && /*#__PURE__*/ _react.createElement("text", {
        y: 5,
        textAnchor: "middle",
        dominantBaseline: "middle",
        className: classes.insideDonutString
    }, props.valueInsideDonut));
});
Pie.displayName = 'Pie';
