"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    CanvasTooltip: ()=>CanvasTooltip,
    CanvasTooltipProviderMarker: ()=>CanvasTooltipProviderMarker
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const apollo_wind_namespaceObject = require("@uipath/apollo-wind");
const tooltip_namespaceObject = require("@uipath/apollo-wind/components/ui/tooltip");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const useTruncationDetection_cjs_namespaceObject = require("../../material/components/ap-tooltip/useTruncationDetection.cjs");
const HasTooltipProviderContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(false);
function CanvasTooltipProviderMarker({ children }) {
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(HasTooltipProviderContext.Provider, {
        value: true,
        children: children
    });
}
function CanvasTooltip({ content, placement = 'top', smartTooltip = false, delay = false, isOpen, hide, sideOffset, contentClassName, disableHoverableContent, disableSkipDelay, children }) {
    const childElement = (0, external_react_namespaceObject.useMemo)(()=>/*#__PURE__*/ external_react_default().isValidElement(children) ? children : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
            children: children
        }), [
        children
    ]);
    const childElementRef = (0, external_react_namespaceObject.useRef)(childElement);
    childElementRef.current = childElement;
    const childRef = (0, external_react_namespaceObject.useRef)(null);
    const truncationDetection = (0, useTruncationDetection_cjs_namespaceObject.useTruncationDetection)(childRef);
    const isTruncated = smartTooltip ? truncationDetection.isTruncated : true;
    const [hoverOpen, setHoverOpen] = (0, external_react_namespaceObject.useState)(false);
    const setChildRef = (0, external_react_namespaceObject.useCallback)((node)=>{
        childRef.current = node;
        const childRefProp = childElementRef.current.props.ref;
        if ('function' == typeof childRefProp) childRefProp(node);
        else if (childRefProp && 'object' == typeof childRefProp) childRefProp.current = node;
    }, []);
    const handleMouseEnter = (0, external_react_namespaceObject.useCallback)((e)=>{
        truncationDetection.check();
        const childProps = childElementRef.current.props;
        childProps.onMouseEnter?.(e);
    }, [
        truncationDetection.check
    ]);
    const triggerWithSmartTooltipHandlers = (0, external_react_namespaceObject.useMemo)(()=>/*#__PURE__*/ external_react_default().cloneElement(childElement, {
            ref: setChildRef,
            onMouseEnter: handleMouseEnter
        }), [
        childElement,
        setChildRef,
        handleMouseEnter
    ]);
    const triggerWithHandlers = smartTooltip ? triggerWithSmartTooltipHandlers : childElement;
    const handleOpenChange = (0, external_react_namespaceObject.useCallback)((nextOpen)=>{
        if (nextOpen && smartTooltip) truncationDetection.check();
        setHoverOpen(nextOpen);
    }, [
        smartTooltip,
        truncationDetection.check
    ]);
    const isEmptyContent = null == content || false === content || 'string' == typeof content && '' === content.trim();
    const isTooltipHidden = (0, external_react_namespaceObject.useMemo)(()=>{
        if (null != isOpen) return !isOpen;
        if (null != hide) return hide;
        if (smartTooltip && !isTruncated) return true;
        return false;
    }, [
        isOpen,
        hide,
        smartTooltip,
        isTruncated
    ]);
    const effectiveOpen = isEmptyContent || isTooltipHidden ? false : isOpen ?? hoverOpen;
    const hasProvider = (0, external_react_namespaceObject.useContext)(HasTooltipProviderContext);
    const tooltip = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(tooltip_namespaceObject.Tooltip, {
        open: effectiveOpen,
        onOpenChange: handleOpenChange,
        delayDuration: delay ? 700 : 200,
        disableHoverableContent: disableHoverableContent,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(tooltip_namespaceObject.TooltipTrigger, {
                asChild: true,
                children: triggerWithHandlers
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(tooltip_namespaceObject.TooltipPortal, {
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(tooltip_namespaceObject.TooltipContent, {
                    side: placement,
                    sideOffset: sideOffset,
                    className: (0, apollo_wind_namespaceObject.cn)('z-1200 max-w-xs wrap-break-word', contentClassName),
                    children: content
                })
            })
        ]
    });
    if (hasProvider && !disableSkipDelay) return tooltip;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(tooltip_namespaceObject.TooltipProvider, {
        delayDuration: 200,
        skipDelayDuration: disableSkipDelay ? 0 : 100,
        children: tooltip
    });
}
exports.CanvasTooltip = __webpack_exports__.CanvasTooltip;
exports.CanvasTooltipProviderMarker = __webpack_exports__.CanvasTooltipProviderMarker;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "CanvasTooltip",
    "CanvasTooltipProviderMarker"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
