"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractMaybeLineOptions = exports.renderScatterPolarCategoryLabels = void 0;
var React = require("react");
/**
 * Helper to render categorical labels for scatterpolar charts with improved overlap logic across all series
 * Now places labels at equal angles for all unique texts, regardless of data positions.
 */
function renderScatterPolarCategoryLabels(_a) {
    var _b, _c;
    var xAxisScale = _a.xAxisScale, yAxisScale = _a.yAxisScale, className = _a.className, lineOptions = _a.lineOptions, _d = _a.minPixelGap, minPixelGap = _d === void 0 ? 40 : _d;
    var maybeLineOptions = extractMaybeLineOptions(lineOptions);
    // Always use axisLabel from lineOptions to display the labels
    var uniqueTexts = (_b = maybeLineOptions === null || maybeLineOptions === void 0 ? void 0 : maybeLineOptions.axisLabel) !== null && _b !== void 0 ? _b : [];
    // Place labels at equal angles
    var renderedLabels = [];
    var placedPositions = [];
    var labelRadius = 0.7; // You can adjust this value for more/less offset
    var numLabels = uniqueTexts.length;
    // Respect schema or prop rotation and direction (default ccw, 0°)
    var dirMultiplier = (maybeLineOptions === null || maybeLineOptions === void 0 ? void 0 : maybeLineOptions.direction) === 'clockwise' ? -1 : 1;
    var rotationRad = (((_c = maybeLineOptions === null || maybeLineOptions === void 0 ? void 0 : maybeLineOptions.rotation) !== null && _c !== void 0 ? _c : 0) * Math.PI) / 180;
    uniqueTexts.forEach(function (text, i) {
        var angle = rotationRad + dirMultiplier * ((2 * Math.PI) / numLabels) * i;
        var originXOffset = (maybeLineOptions === null || maybeLineOptions === void 0 ? void 0 : maybeLineOptions.originXOffset) || 0;
        var x = xAxisScale(labelRadius * Math.cos(angle) - originXOffset / 2);
        var y = yAxisScale(labelRadius * Math.sin(angle));
        // Check distance from all previously placed labels
        var isFarEnough = placedPositions.every(function (pos) { return Math.sqrt(Math.pow((x - pos.x), 2) + Math.pow((y - pos.y), 2)) >= minPixelGap; });
        if (renderedLabels.length === 0 || isFarEnough) {
            renderedLabels.push(React.createElement("text", { key: "scatterpolar-label-".concat(text), x: x, y: y, className: className, textAnchor: "middle", alignmentBaseline: "middle", opacity: 1 }, text));
            placedPositions.push({ x: x, y: y });
        }
    });
    return renderedLabels;
}
exports.renderScatterPolarCategoryLabels = renderScatterPolarCategoryLabels;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function extractMaybeLineOptions(lineOptions) {
    return lineOptions
        ? {
            originXOffset: lineOptions.originXOffset,
            direction: lineOptions.direction === 'clockwise' || lineOptions.direction === 'counterclockwise'
                ? lineOptions.direction
                : undefined,
            rotation: lineOptions.rotation,
            axisLabel: Array.isArray(lineOptions.axisLabel) ? lineOptions.axisLabel : undefined,
        }
        : undefined;
}
exports.extractMaybeLineOptions = extractMaybeLineOptions;
//# sourceMappingURL=scatterpolar-utils.js.map