/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-2800b6c
 * Released under the MIT license.
 */

import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { isValidElement, useEffect, useState, } from 'react';
import { Tooltip } from './Tooltip.js';
import { TooltipTrigger, } from './TooltipTrigger.js';
export function TooltipProvider(props) {
    const [rendered, setRendered] = useState(false);
    const { title, children, tooltipStyles, width, isDisabled, ...otherProps } = props;
    useEffect(() => {
        setRendered(true);
    }, []);
    const isFunction = typeof children === 'function';
    // SSR: render without tooltip
    if (!rendered) {
        return (_jsx(_Fragment, { children: isFunction
                ? children({}, { current: null })
                : children }));
    }
    // Both patterns pass through to TooltipTrigger
    // The difference is whether we pass function or element as first child
    return (_jsxs(TooltipTrigger, { ...otherProps, isDisabled: isDisabled, disableFocusableProvider: isFunction, children: [isFunction ||
                isValidElement(children) ||
                typeof children === 'string' ? (children) : (_jsx(_Fragment, { children: children })), isDisabled ? (_jsx("div", {})) : (_jsx(Tooltip, { styles: tooltipStyles, ...(width ? { width } : null), children: title }))] }));
}

        