import React, { forwardRef } from "react";
import { isForwardRef } from "react-is";
import Tippy from "@tippyjs/react";
import Text from "../../asorted/Text";
// Tippyjs need the ref to be forwarded to the DOM element wrapping the children.
// This component has been created to add a wrapping span and use its ref when needed.
// See: https://github.com/atomiks/tippyjs-react#component-children
const Wrapper = forwardRef((props, ref) => {
    const childrenCount = React.Children.count(props.children);
    try {
        const child = React.Children.only(props.children);
        const isValidElement = React.isValidElement(child);
        const isForwardingRef = isForwardRef(child);
        const isDomElement = isValidElement && typeof child.type === "string";
        if (isForwardingRef || isDomElement) {
            return React.cloneElement(child, { ref });
        }
        else {
            return React.createElement("span", { ref: ref }, props.children);
        }
    }
    catch {
        return childrenCount < 1 ? null : React.createElement("span", { ref: ref }, props.children);
    }
});
export default function Tooltip(props) {
    const { content, placement = "auto", children, ...rest } = props;
    return (React.createElement(Tippy, { ...rest, placement: placement, content: React.createElement(Text, { fontWeight: "medium", variant: "paragraph", color: "neutral.c00" }, content) },
        React.createElement(Wrapper, { children: children })));
}
//# sourceMappingURL=index.js.map