"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "ChartTitle", {
    enumerable: true,
    get: function() {
        return ChartTitle;
    }
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _SVGTooltipText = require("./SVGTooltipText");
const _Commonstyles = require("./Common.styles");
const _utilities = require("./utilities");
const AXIS_TITLE_PADDING = 8;
const ChartTitle = (props)=>{
    const { title, x, y, maxWidth, className, titleStyles, tooltipProps, tooltipClassName } = props;
    const { titleFont, titleXAnchor, titleYAnchor, titlePad } = titleStyles !== null && titleStyles !== void 0 ? titleStyles : {};
    const computedTextAnchor = titleXAnchor === 'left' ? 'start' : titleXAnchor === 'right' ? 'end' : 'middle';
    // Calculate dominantBaseline from titleYAnchor for vertical alignment
    // 'top' means text hangs below the y position (text-before-edge/hanging)
    // 'bottom' means text sits above the y position (text-after-edge/alphabetic)
    // 'middle' means text is centered on the y position (central)
    const computedDominantBaseline = titleYAnchor === 'top' ? 'hanging' : titleYAnchor === 'bottom' ? 'alphabetic' : titleYAnchor === 'middle' ? 'central' : 'auto';
    var _titlePad_l, _titlePad_r;
    // Calculate x position with padding adjustments
    const computedX = x + ((_titlePad_l = titlePad === null || titlePad === void 0 ? void 0 : titlePad.l) !== null && _titlePad_l !== void 0 ? _titlePad_l : 0) - ((_titlePad_r = titlePad === null || titlePad === void 0 ? void 0 : titlePad.r) !== null && _titlePad_r !== void 0 ? _titlePad_r : 0);
    var _titlePad_t, _titlePad_b;
    // Calculate y position with padding adjustments
    const calculatedY = (y !== null && y !== void 0 ? y : Math.max((typeof (titleFont === null || titleFont === void 0 ? void 0 : titleFont.size) === 'number' ? titleFont.size : 13) + AXIS_TITLE_PADDING, _Commonstyles.CHART_TITLE_PADDING - AXIS_TITLE_PADDING)) + ((_titlePad_t = titlePad === null || titlePad === void 0 ? void 0 : titlePad.t) !== null && _titlePad_t !== void 0 ? _titlePad_t : 0) - ((_titlePad_b = titlePad === null || titlePad === void 0 ? void 0 : titlePad.b) !== null && _titlePad_b !== void 0 ? _titlePad_b : 0);
    const commonSvgToolTipProps = {
        wrapContent: _utilities.wrapContent,
        showBackground: true,
        className: tooltipClassName,
        ...tooltipProps
    };
    return /*#__PURE__*/ _react.createElement(_SVGTooltipText.SVGTooltipText, {
        ...commonSvgToolTipProps,
        content: title,
        textProps: {
            x: computedX,
            y: calculatedY,
            textAnchor: computedTextAnchor,
            dominantBaseline: computedDominantBaseline,
            className,
            'aria-hidden': true,
            style: (0, _Commonstyles.getChartTitleInlineStyles)(titleFont)
        },
        maxWidth: maxWidth
    });
};
ChartTitle.displayName = 'ChartTitle';
