import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2023-2026 GoodData Corporation
import { forwardRef } from "react";
import { useIntl } from "react-intl";
import { Bubble } from "./Bubble.js";
import { BubbleHoverTrigger } from "./BubbleHoverTrigger.js";
/**
 * @internal
 */
export function withBubble(WrappedComponent) {
    const ResultComponent = forwardRef((props, ref) => {
        const { showBubble = true, alignPoints = [{ align: "cr cl" }], bubbleTextId, triggerClassName, ...wrappedComponentProps } = props;
        const intl = useIntl();
        if (!showBubble || !bubbleTextId) {
            return _jsx(WrappedComponent, { ...props, ref: ref });
        }
        const bubbleText = intl.formatMessage({ id: bubbleTextId }, { strong: (chunks) => _jsx("strong", { children: chunks }) });
        return (_jsxs(BubbleHoverTrigger, { className: triggerClassName, children: [
                _jsx(WrappedComponent, { ...wrappedComponentProps, ref: ref }), _jsx(Bubble, { alignPoints: alignPoints, children: _jsx("div", { children: bubbleText }) })
            ] }));
    });
    ResultComponent.displayName = `withBubble(${WrappedComponent.displayName || WrappedComponent.name || "Component"})`;
    return ResultComponent;
}
