"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    useTruncationDetection: ()=>useTruncationDetection
});
const external_react_namespaceObject = require("react");
const TOOLTIP_TARGET_ELEMENT = 'tooltip-target-element';
function useTruncationDetection(elementRef) {
    const [isTruncated, setIsTruncated] = (0, external_react_namespaceObject.useState)(false);
    const hasCheckedRef = (0, external_react_namespaceObject.useRef)(false);
    const resizeObserverRef = (0, external_react_namespaceObject.useRef)(null);
    const checkTruncation = (0, external_react_namespaceObject.useCallback)(()=>{
        const element = elementRef.current;
        if (!element || !(element instanceof HTMLElement)) return void setIsTruncated(false);
        let targetElement = element;
        if (element.id === TOOLTIP_TARGET_ELEMENT) {
            const slot = element.querySelector('slot');
            if (slot) {
                const assignedNodes = slot.assignedNodes();
                for (const node of assignedNodes)if (node.nodeType === Node.ELEMENT_NODE) {
                    targetElement = node;
                    break;
                }
            } else if (element.firstElementChild) targetElement = element.firstElementChild;
            if (targetElement.id === TOOLTIP_TARGET_ELEMENT) {
                const rootNode = element.getRootNode();
                if (rootNode instanceof ShadowRoot) {
                    const hostElement = rootNode.host;
                    const slottedElement = hostElement.querySelector('div[data-slot-name="children"]') || Array.from(hostElement.children).find((child)=>child instanceof HTMLElement && 'ellipsis' === window.getComputedStyle(child).textOverflow);
                    if (slottedElement instanceof HTMLElement) targetElement = slottedElement;
                }
            }
        }
        const computedStyle = window.getComputedStyle(targetElement);
        const hasEllipsis = 'ellipsis' === computedStyle.textOverflow;
        const hasOverflowHidden = 'hidden' === computedStyle.overflow || 'hidden' === computedStyle.overflowX;
        const hasWhiteSpaceNowrap = 'nowrap' === computedStyle.whiteSpace;
        if (!hasEllipsis || !hasOverflowHidden || !hasWhiteSpaceNowrap) return void setIsTruncated(false);
        const isElementTruncated = targetElement.scrollWidth > targetElement.clientWidth;
        setIsTruncated(isElementTruncated);
    }, [
        elementRef
    ]);
    const setupObservers = (0, external_react_namespaceObject.useCallback)(()=>{
        if (hasCheckedRef.current) return;
        const element = elementRef.current;
        if (!element) return;
        hasCheckedRef.current = true;
        if (!resizeObserverRef.current) {
            resizeObserverRef.current = new ResizeObserver(checkTruncation);
            resizeObserverRef.current.observe(element);
            if (element.id === TOOLTIP_TARGET_ELEMENT && element.firstElementChild) resizeObserverRef.current.observe(element.firstElementChild);
        }
        window.addEventListener('resize', checkTruncation);
    }, [
        checkTruncation,
        elementRef
    ]);
    const check = (0, external_react_namespaceObject.useCallback)(()=>{
        checkTruncation();
        setupObservers();
    }, [
        checkTruncation,
        setupObservers
    ]);
    (0, external_react_namespaceObject.useEffect)(()=>()=>{
            if (resizeObserverRef.current) {
                resizeObserverRef.current.disconnect();
                resizeObserverRef.current = null;
            }
            window.removeEventListener('resize', checkTruncation);
        }, [
        checkTruncation
    ]);
    return {
        isTruncated,
        check
    };
}
exports.useTruncationDetection = __webpack_exports__.useTruncationDetection;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "useTruncationDetection"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
