import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2024-2026 GoodData Corporation
import { useMemo } from "react";
import { useIntl } from "react-intl";
import { IntlWrapper } from "@gooddata/sdk-ui";
import { Bubble } from "../Bubble/Bubble.js";
import { BubbleHoverTrigger } from "../Bubble/BubbleHoverTrigger.js";
import { RichText } from "./RichText.js";
const alignPoints = [{ align: "bc tc" }, { align: "tc bc" }];
const descriptionMarkdown = (_jsxs(_Fragment, { children: [
        _jsx("br", {}),
        "# Heading 1",
        _jsx("br", {}),
        "**Bold**",
        _jsx("br", {}),
        "* List",
        _jsx("br", {}),
        "[link](http://thisisalink.com)",
        _jsx("br", {}),
        "![image](http://url/img.png)",
        _jsx("br", {}), "{metric/metric_id}", _jsx("br", {}), "{label/label_id}"] }));
function RichTextWithTooltipCore({ value, onChange, renderMode, editPlaceholder, editRows, emptyElement, className, showTooltip = true, tooltipAlignPoints = alignPoints, tooltipDescription, tooltipMarkdown = descriptionMarkdown, autoResize, referencesEnabled, filters, separators, onLoadingChanged, onError, LoadingComponent, rawContent, execConfig, }) {
    const intl = useIntl();
    const description = tooltipDescription ?? intl.formatMessage({ id: "richText.tooltip" });
    const Component = useMemo(() => {
        return (_jsx(RichText, { value: value, onChange: onChange, renderMode: renderMode, editPlaceholder: editPlaceholder, editRows: editRows, emptyElement: emptyElement, className: className, autoResize: autoResize, referencesEnabled: referencesEnabled, filters: filters, separators: separators, LoadingComponent: LoadingComponent, onLoadingChanged: onLoadingChanged, onError: onError, rawContent: rawContent, execConfig: {
                timestamp: execConfig?.timestamp,
                dataSamplingPercentage: execConfig?.dataSamplingPercentage,
            } }));
    }, [
        value,
        onChange,
        renderMode,
        editPlaceholder,
        editRows,
        emptyElement,
        className,
        autoResize,
        referencesEnabled,
        filters,
        LoadingComponent,
        onLoadingChanged,
        onError,
        rawContent,
        separators,
        execConfig?.timestamp,
        execConfig?.dataSamplingPercentage,
    ]);
    if (!showTooltip) {
        return Component;
    }
    return (_jsxs(BubbleHoverTrigger, { showDelay: 0, hideDelay: 0, openOnInit: true, children: [Component, showTooltip ? (_jsxs(Bubble, { alignPoints: tooltipAlignPoints, className: "bubble-primary bubble-small", overlayClassName: "rich-text-tooltip", children: [description, tooltipMarkdown] })) : null] }));
}
/**
 * @internal
 */
export function RichTextWithTooltip(props) {
    return (_jsx(IntlWrapper, { children: _jsx(RichTextWithTooltipCore, { ...props }) }));
}
