import { j as jsxRuntimeExports } from '../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js';
import { cx, cva } from '../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js';
import { useId, useMemo } from 'react';
import { useMouse } from '../../hooks/useMouse.js';
import { Text } from '../text/text.js';
import styles from './tooltip.module.css.js';
import { getTransformForPlacement } from './utils.js';
import { Provider, Root as Root3, Trigger, Portal, Content as Content2, Arrow as Arrow2 } from '../../node_modules/.pnpm/@radix-ui_react-tooltip@1.2.7_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18.3.1_react@18.2.0__react@18.2.0/node_modules/@radix-ui/react-tooltip/dist/index.js';

const tooltip = cva(styles.content, {
    variants: {
        side: {
            top: styles['side-top'],
            right: styles['side-right'],
            bottom: styles['side-bottom'],
            left: styles['side-left'],
            'top-left': styles['side-top-left'],
            'top-right': styles['side-top-right'],
            'bottom-left': styles['side-bottom-left'],
            'bottom-right': styles['side-bottom-right']
        }
    },
    defaultVariants: {
        side: 'top'
    }
});
const Tooltip = ({ children, message, disabled, side = 'top', classNames, triggerStyle, contentStyle, delayDuration = 200, skipDelayDuration = 200, 'aria-label': ariaLabel, asChild = true, showArrow = true, id, followCursor = false, sideOffset = 4, alignOffset = 0 }) => {
    const generatedId = useId();
    const tooltipId = id ?? generatedId;
    const { ref, value: mouseValue, reset } = useMouse({
        resetOnExit: false,
        enabled: followCursor
    });
    const computedSide = useMemo(() => (side?.split('-')[0] || 'top'), [side]);
    const computedAlign = useMemo(() => (side?.includes('-')
        ? side.split('-')[1] === 'left'
            ? 'start'
            : 'end'
        : 'center'), [side]);
    if (disabled)
        return children;
    return (jsxRuntimeExports.jsx(Provider, { delayDuration: delayDuration, skipDelayDuration: skipDelayDuration, children: jsxRuntimeExports.jsxs(Root3, { children: [jsxRuntimeExports.jsx(Trigger, { "aria-describedby": tooltipId, asChild: asChild, onFocus: followCursor ? reset : undefined, children: jsxRuntimeExports.jsx("div", { ref: ref, className: cx(styles.trigger, classNames?.trigger), style: triggerStyle, children: children }) }), jsxRuntimeExports.jsx(Portal, { children: jsxRuntimeExports.jsxs(Content2, { id: tooltipId, role: 'tooltip', "aria-label": ariaLabel || (typeof message === 'string' ? message : undefined), side: computedSide, align: computedAlign, alignOffset: alignOffset, sideOffset: sideOffset, className: tooltip({ side, className: classNames?.content }), "data-follow-cursor": followCursor, style: {
                            ...contentStyle,
                            pointerEvents: followCursor ? 'none' : undefined,
                            transform: followCursor && mouseValue
                                ? getTransformForPlacement(computedSide, computedAlign, mouseValue)
                                : undefined
                        }, children: [typeof message === 'string' ? jsxRuntimeExports.jsx(Text, { children: message }) : message, showArrow && (jsxRuntimeExports.jsx(Arrow2, { className: cx(styles.arrow, classNames?.arrow), width: 7, height: 7 }))] }) })] }) }));
};
Tooltip.displayName = 'Tooltip';
const TooltipProvider = Provider;

export { Tooltip, TooltipProvider };
//# sourceMappingURL=tooltip.js.map
