import { hoverTooltip } from '../../../../../../@codemirror_view@6.28.6/node_modules/@codemirror/view/dist/index.js';
import { tsFacet } from '../facet/tsFacet.js';
import { getHover } from './getHover.js';
import { defaultRenderer } from './renderTooltip.js';

/**
 * This binds the CodeMirror `hoverTooltip` method
 * with a code that pulls types and documentation
 * from the TypeScript environment.
 */
function tsHover({ renderTooltip = defaultRenderer, } = {}) {
    return hoverTooltip(async (view, pos) => {
        const config = view.state.facet(tsFacet);
        if (!config?.env)
            return null;
        const hoverData = getHover({
            ...config,
            pos,
        });
        if (!hoverData)
            return null;
        return {
            pos: hoverData.start,
            end: hoverData.end,
            create: () => renderTooltip(hoverData, view),
        };
    });
}

export { tsHover };
