import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
const StablePopover = (props)=>{
    const target = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
    const avoidClose = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e)=>{
        target.current = e.target;
    }, []);
    const onOpenChange = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((open)=>{
        setTimeout(()=>{
            var _props_onOpenChange;
            if (!open && null !== target.current && !isTargetInPopover(target.current)) {
                target.current = null;
                return;
            }
            null === (_props_onOpenChange = props.onOpenChange) || void 0 === _props_onOpenChange || _props_onOpenChange.call(props, open);
        });
    }, [
        props
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        className: "popover-with-stop-propagation",
        onClick: avoidClose,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Popover, {
            ...props,
            onOpenChange: onOpenChange
        })
    });
};
function isTargetInPopover(target) {
    if (!target) return false;
    while(target){
        var _target_classList;
        if (null === (_target_classList = target.classList) || void 0 === _target_classList ? void 0 : _target_classList.contains('popover-with-stop-propagation')) return true;
        target = target.parentNode;
    }
    return false;
}
export { StablePopover };
