"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__, {
    ApTooltip: ()=>ApTooltip
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const material_namespaceObject = require("@mui/material");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const external_useTruncationDetection_cjs_namespaceObject = require("./useTruncationDetection.cjs");
const makeTooltipRenderInSameDOMTree = {
    PopperProps: {
        disablePortal: true,
        popperOptions: {
            strategy: 'fixed'
        }
    }
};
function ApTooltip({ content, placement = 'bottom', disabled = false, hide, isOpen, delay = false, children, formattedContent, dontUseInternalOnlyDebugForceOpen = false, smartTooltip = false, onTooltipOpen, onTooltipClose, closeOnInteraction = false, ...muiProps }) {
    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, external_useTruncationDetection_cjs_namespaceObject.useTruncationDetection)(childRef);
    const isTruncated = smartTooltip ? truncationDetection.isTruncated : true;
    const [isTemporarilyClosed, setIsTemporarilyClosed] = external_react_default().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 handleInteractionStart = (0, external_react_namespaceObject.useCallback)(()=>{
        if (closeOnInteraction) setIsTemporarilyClosed(true);
    }, [
        closeOnInteraction
    ]);
    const handleMouseLeave = (0, external_react_namespaceObject.useCallback)((e)=>{
        if (closeOnInteraction) setIsTemporarilyClosed(false);
        const childProps = childElementRef.current.props;
        childProps.onMouseLeave?.(e);
    }, [
        closeOnInteraction
    ]);
    const handleInputCapture = (0, external_react_namespaceObject.useCallback)((e)=>{
        handleInteractionStart();
        const childProps = childElementRef.current.props;
        childProps.onInputCapture?.(e);
    }, [
        handleInteractionStart
    ]);
    const handleMouseDown = (0, external_react_namespaceObject.useCallback)((e)=>{
        handleInteractionStart();
        const childProps = childElementRef.current.props;
        childProps.onMouseDown?.(e);
    }, [
        handleInteractionStart
    ]);
    const handleMouseEnter = (0, external_react_namespaceObject.useCallback)((e)=>{
        truncationDetection.check();
        const childProps = childElementRef.current.props;
        childProps.onMouseEnter?.(e);
    }, [
        truncationDetection.check
    ]);
    const closeOnInteractionHandlers = (0, external_react_namespaceObject.useMemo)(()=>{
        if (!closeOnInteraction) return {};
        return {
            onMouseLeave: handleMouseLeave,
            onInputCapture: handleInputCapture,
            onMouseDown: handleMouseDown
        };
    }, [
        closeOnInteraction,
        handleMouseLeave,
        handleInputCapture,
        handleMouseDown
    ]);
    const childrenWithRefSmartTooltip = (0, external_react_namespaceObject.useMemo)(()=>/*#__PURE__*/ external_react_default().cloneElement(childElement, {
            ref: setChildRef,
            onMouseEnter: handleMouseEnter,
            ...closeOnInteractionHandlers
        }), [
        childElement,
        setChildRef,
        handleMouseEnter,
        closeOnInteractionHandlers
    ]);
    const childrenWithRefRegular = (0, external_react_namespaceObject.useMemo)(()=>/*#__PURE__*/ external_react_default().cloneElement(childElement, closeOnInteractionHandlers), [
        childElement,
        closeOnInteractionHandlers
    ]);
    const childrenWithRef = smartTooltip ? childrenWithRefSmartTooltip : childrenWithRefRegular;
    const debugPopperInstanceRef = external_react_default().useRef(null);
    external_react_default().useLayoutEffect(()=>{
        let forceUpdateInterval;
        if (dontUseInternalOnlyDebugForceOpen) forceUpdateInterval = window.setInterval(()=>{
            debugPopperInstanceRef.current?.forceUpdate();
        }, 100);
        return ()=>{
            window.clearInterval(forceUpdateInterval);
        };
    }, [
        dontUseInternalOnlyDebugForceOpen
    ]);
    const hasCustomContent = Boolean(formattedContent);
    const tooltipProps = hasCustomContent ? makeTooltipRenderInSameDOMTree : {};
    const isTooltipTitleHidden = (0, external_react_namespaceObject.useMemo)(()=>{
        if (null != isOpen) return !isOpen;
        if (null != hide) return hide;
        if (closeOnInteraction && isTemporarilyClosed) return true;
        if (smartTooltip && !isTruncated) return true;
        return false;
    }, [
        isOpen,
        hide,
        closeOnInteraction,
        isTemporarilyClosed,
        smartTooltip,
        isTruncated
    ]);
    const handleTooltipOpen = (0, external_react_namespaceObject.useCallback)((event)=>{
        if (smartTooltip) truncationDetection.check();
        onTooltipOpen?.(event);
    }, [
        smartTooltip,
        truncationDetection.check,
        onTooltipOpen
    ]);
    const tooltipTitle = isTooltipTitleHidden || disabled ? '' : formattedContent ?? content;
    const { content: _unusedContent, ...safeToSpreadMuiProps } = muiProps;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(material_namespaceObject.Tooltip, {
        title: tooltipTitle,
        placement: placement,
        enterDelay: delay ? 700 : 0,
        enterNextDelay: delay ? 700 : 0,
        onOpen: handleTooltipOpen,
        onClose: onTooltipClose,
        ...safeToSpreadMuiProps,
        ...tooltipProps,
        ...dontUseInternalOnlyDebugForceOpen && {
            open: true,
            PopperProps: {
                ...'PopperProps' in tooltipProps ? tooltipProps.PopperProps : {},
                popperRef: debugPopperInstanceRef
            }
        },
        ...null != isOpen && {
            open: dontUseInternalOnlyDebugForceOpen ? true : isOpen
        },
        children: childrenWithRef
    });
}
exports.ApTooltip = __webpack_exports__.ApTooltip;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "ApTooltip"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
