import { LINK_VIEWER_DATA_HOOK } from "./../wix-rich-content-common/index.js";
function addLinkPreviewPopoverListener(container, callback) {
  const onLinkHover = (linkNode) => {
    const url = linkNode.href;
    const linkNodeRect = linkNode.getBoundingClientRect();
    const position = { top: linkNodeRect.top + linkNodeRect.height + 4, left: linkNodeRect.left };
    callback(url, position);
  };
  const onStopLinkHover = () => callback(void 0);
  const handleMouseOver = (event) => {
    const isLink = event.target?.parentNode?.dataset?.hook === LINK_VIEWER_DATA_HOOK;
    return isLink ? onLinkHover(event.target.closest("a")) : onStopLinkHover();
  };
  container.addEventListener("mouseover", handleMouseOver);
  return () => {
    container.removeEventListener("mouseover", handleMouseOver);
  };
}
export {
  addLinkPreviewPopoverListener
};
//# sourceMappingURL=link-preview-popover-listener.js.map
