'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var primitives_Tooltip = require('./primitives/Tooltip.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

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] = React.useState(false);
    // Auto-hide after hideAfter ms
    React.useEffect(() => {
        if (!open || hideAfter <= 0)
            return;
        const timer = setTimeout(() => setOpen(false), hideAfter);
        return () => clearTimeout(timer);
    }, [open, hideAfter]);
    if (disabled || !content) {
        return jsxRuntime.jsx(jsxRuntime.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.default.isValidElement(children) ? (children) : (jsxRuntime.jsx("span", { children: children }));
    return (jsxRuntime.jsx(primitives_Tooltip.TooltipProvider, { delayDuration: delayDuration, children: jsxRuntime.jsxs(primitives_Tooltip.Tooltip, { open: open, onOpenChange: setOpen, defaultOpen: defaultOpen, disableHoverableContent: !interactive, children: [jsxRuntime.jsx(primitives_Tooltip.TooltipTrigger, { asChild: true, children: trigger }), jsxRuntime.jsx(primitives_Tooltip.TooltipContent, { side: side, align: align, className: className, onPointerDownOutside: interactive ? e => e.preventDefault() : undefined, ...contentProps, children: content })] }) }));
};
Tooltip.displayName = "Tooltip";

exports.Tooltip = Tooltip;
//# sourceMappingURL=Tooltip-criVUtIg.js.map
