"use client";
import { jsx, jsxs } from 'react/jsx-runtime';
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 { useTooltipProvider, TooltipProvider } from './tooltip-provider.js';
import styles from './tooltip.module.css.js';
import { getTransformForPlacement } from './utils.js';
import { 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@19.1.7_@types_react@19.1.9__@types_react@19.1._dc3knlq5xr3bsp42ltsj4iesx4/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 TooltipBase = ({ children, message, disabled, side = 'top', classNames, triggerStyle, contentStyle, 'aria-label': ariaLabel, asChild = true, showArrow = true, id, followCursor = false, sideOffset = 4, alignOffset = 0, open, defaultOpen, delayDuration = 200, onOpenChange, disableHoverableContent, ...props }) => {
    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 (jsxs(Root3, { open: open, defaultOpen: defaultOpen, onOpenChange: onOpenChange, delayDuration: delayDuration, disableHoverableContent: disableHoverableContent, children: [jsx(Trigger, { "aria-describedby": tooltipId, asChild: asChild, onFocus: followCursor ? reset : undefined, children: jsx("div", { ref: ref, className: cx(styles.trigger, classNames?.trigger), style: triggerStyle, children: children }) }), jsx(Portal, { children: 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
                    }, ...props, children: [typeof message === 'string' ? jsx(Text, { children: message }) : message, showArrow && (jsx(Arrow2, { className: cx(styles.arrow, classNames?.arrow), width: 7, height: 7 }))] }) })] }));
};
const TooltipRoot = (props) => {
    const provider = useTooltipProvider();
    // If already inside a provider, just return the tooltip
    if (provider)
        return jsx(TooltipBase, { ...props });
    // If not inside a provider, wrap with our own provider
    return (jsx(TooltipProvider, { children: jsx(TooltipBase, { ...props }) }));
};
TooltipRoot.displayName = 'TooltipRoot';

export { TooltipBase, TooltipRoot };
//# sourceMappingURL=tooltip-root.js.map
