var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
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 (e) {
        return childrenCount < 1 ? null : React.createElement("span", { ref: ref }, props.children);
    }
});
export default function Tooltip(props) {
    const { content, placement = "auto", children } = props, rest = __rest(props, ["content", "placement", "children"]);
    return (React.createElement(Tippy, Object.assign({}, rest, { placement: placement, content: React.createElement(Text, { fontWeight: "medium", variant: "paragraph", color: "neutral.c00" }, content) }),
        React.createElement(Wrapper, { children: children })));
}
//# sourceMappingURL=index.js.map