import { jsx } from 'react/jsx-runtime';
import React__default from 'react';
import { cn } from '../../../../utils/cn.js';
import { chartTextTheme } from './ChartText.theme.js';

/**
 * ChartText component for consistent typography in charts
 * Uses fixed Tailwind styling for consistency
 */
const ChartText = ({ children, textAnchor = "start", dominantBaseline = "auto", maxWidth, truncate = false, rotation = 0, className, ...props }) => {
    const theme = chartTextTheme;
    // Truncate text if needed
    const truncateText = (text, maxWidth) => {
        // Rough estimate: 6px per character for text-base
        if (!maxWidth || text.length <= maxWidth / 6) {
            return text;
        }
        const maxChars = Math.floor(maxWidth / 6) - 3;
        return text.substring(0, maxChars) + "...";
    };
    // Process children to handle truncation
    const processedChildren = React__default.useMemo(() => {
        if (!truncate || !maxWidth || typeof children !== "string") {
            return children;
        }
        return truncateText(children, maxWidth);
    }, [children, truncate, maxWidth]);
    const { x, y } = props;
    return (jsx("text", { textAnchor: textAnchor, dominantBaseline: dominantBaseline, className: cn(theme.baseStyle, className), transform: rotation !== 0 && x !== undefined && y !== undefined ? `rotate(${rotation}, ${x}, ${y})` : undefined, ...props, children: processedChildren }));
};

export { ChartText };
