/**
 * This annotation allows drawing a freeform line on a chart.
 *
 * It accepts either pixel coordinates or data values for positioning.
 *
 * In case it receives pixel coordinates, it uses a line SVG element.
 * If data values are provided, it uses a ReferenceLine component with the segment prop.
 */
import React from 'react';
import { ReferenceLine } from 'recharts';
export function FreeformLine({ annotation }) {
    const { pointA, pointB, positionType, style, label } = annotation;
    const { color = '#ccc', strokeWidth = 1, strokeDasharray, opacity = 1 } = style;
    if (!pointB) {
        return null;
    }
    if (positionType === 'data') {
        // Use ReferenceLine with segment prop for data-based positioning
        if (!pointA.dataPoint || !pointB.dataPoint) {
            return null;
        }
        return (React.createElement(ReferenceLine, { segment: [
                { x: String(pointA.dataPoint.x), y: String(pointA.dataPoint.y) },
                { x: String(pointB.dataPoint.x), y: String(pointB.dataPoint.y) },
            ], stroke: color, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, strokeOpacity: opacity, label: label }));
    }
    // For pixel-based positioning, use raw SVG line
    const x1Pixel = pointA.interactionCoordinate.x;
    const y1Pixel = pointA.interactionCoordinate.y;
    const x2Pixel = pointB.interactionCoordinate.x;
    const y2Pixel = pointB.interactionCoordinate.y;
    return (React.createElement("g", null,
        React.createElement("line", { x1: x1Pixel, y1: y1Pixel, x2: x2Pixel, y2: y2Pixel, stroke: color, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, opacity: opacity, pointerEvents: "none" }),
        label && (React.createElement("text", { x: (x1Pixel + x2Pixel) / 2, y: (y1Pixel + y2Pixel) / 2 - 5, fill: label.style?.fill ?? color, fontSize: label.style?.fontSize ?? 10, fontWeight: label.style?.fontWeight ?? 'normal', textAnchor: "middle", pointerEvents: "none" }, label.value))));
}
