"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__, {
    useElementsOverlap: ()=>useElementsOverlap
});
const external_react_namespaceObject = require("react");
function useElementsOverlap(obstacleRefs, triggerRefs = []) {
    const [overlaps, setOverlaps] = (0, external_react_namespaceObject.useState)(false);
    const [target, setTarget] = (0, external_react_namespaceObject.useState)(null);
    const obstaclesRef = (0, external_react_namespaceObject.useRef)(obstacleRefs);
    const triggersRef = (0, external_react_namespaceObject.useRef)(triggerRefs);
    const targetRef = (0, external_react_namespaceObject.useCallback)((el)=>{
        setTarget(el);
    }, []);
    (0, external_react_namespaceObject.useLayoutEffect)(()=>{
        obstaclesRef.current = obstacleRefs;
        triggersRef.current = triggerRefs;
    });
    (0, external_react_namespaceObject.useLayoutEffect)(()=>{
        if (!target) return;
        let baselineWidth = 0;
        let baselineHeight = 0;
        let lastOverlap = false;
        const measure = ()=>{
            const tRect = target.getBoundingClientRect();
            if (!lastOverlap) {
                baselineWidth = tRect.width;
                baselineHeight = tRect.height;
            }
            const left = tRect.right - baselineWidth;
            const top = tRect.bottom - baselineHeight;
            let isOverlapping = false;
            for (const ref of obstaclesRef.current){
                const el = ref.current;
                if (!el) continue;
                const oRect = el.getBoundingClientRect();
                if (!(oRect.right <= left || oRect.left >= tRect.right || oRect.bottom <= top || oRect.top >= tRect.bottom)) {
                    isOverlapping = true;
                    break;
                }
            }
            lastOverlap = isOverlapping;
            setOverlaps(isOverlapping);
        };
        const ro = new ResizeObserver(measure);
        ro.observe(target);
        for (const ref of obstaclesRef.current)if (ref.current) ro.observe(ref.current);
        for (const ref of triggersRef.current)if (ref.current) ro.observe(ref.current);
        measure();
        return ()=>ro.disconnect();
    }, [
        target
    ]);
    return {
        overlaps,
        targetRef
    };
}
exports.useElementsOverlap = __webpack_exports__.useElementsOverlap;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "useElementsOverlap"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
