import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
import React__default, { useState, useEffect } from 'react';
import { TooltipProvider, Tooltip as Tooltip$1, TooltipTrigger, TooltipContent } from './primitives/Tooltip.js';

const SIDE_MAP = {
    top: "top",
    bottom: "bottom",
    left: "left",
    right: "right",
    "top-start": "top",
    "top-end": "top",
    "bottom-start": "bottom",
    "bottom-end": "bottom",
    "left-start": "left",
    "left-end": "left",
    "right-start": "right",
    "right-end": "right",
    auto: "top",
};
const ALIGN_MAP = {
    top: "center",
    bottom: "center",
    left: "center",
    right: "center",
    "top-start": "start",
    "top-end": "end",
    "bottom-start": "start",
    "bottom-end": "end",
    "left-start": "start",
    "left-end": "end",
    "right-start": "start",
    "right-end": "end",
    auto: "center",
};

const Tooltip = ({ content, children, disabled = false, position = "auto", interactive = false, hideAfter = -1, className, delayDuration = 0, defaultOpen, 
// Radix TooltipContent props forwarded
...contentProps }) => {
    const [open, setOpen] = useState(false);
    // Auto-hide after hideAfter ms
    useEffect(() => {
        if (!open || hideAfter <= 0)
            return;
        const timer = setTimeout(() => setOpen(false), hideAfter);
        return () => clearTimeout(timer);
    }, [open, hideAfter]);
    if (disabled || !content) {
        return jsx(Fragment, { children: children });
    }
    const side = SIDE_MAP[position] ?? "top";
    const align = ALIGN_MAP[position] ?? "center";
    // Wrap non-element children in a span so TooltipTrigger can attach
    const trigger = React__default.isValidElement(children) ? (children) : (jsx("span", { children: children }));
    return (jsx(TooltipProvider, { delayDuration: delayDuration, children: jsxs(Tooltip$1, { open: open, onOpenChange: setOpen, defaultOpen: defaultOpen, disableHoverableContent: !interactive, children: [jsx(TooltipTrigger, { asChild: true, children: trigger }), jsx(TooltipContent, { side: side, align: align, className: className, onPointerDownOutside: interactive ? e => e.preventDefault() : undefined, ...contentProps, children: content })] }) }));
};
Tooltip.displayName = "Tooltip";

export { Tooltip as T };
//# sourceMappingURL=Tooltip-3ZzQyaDV.js.map
