function hasParentOfType(node, type) {
  if (!node) return false;
  if (type === node.nodeName) return true;
  return hasParentOfType(node.parentNode, type);
}

/**
 * 适用于 header/footer/dashboard "preview mode", 阻止内部组件中所有 link 的默认点击行为
 */
function LinkBlocker({ ...rest }) {
  const handleOnClick = (e) => {
    const isInsideLink = hasParentOfType(e.target, 'A');
    if (isInsideLink) {
      e.preventDefault();
    }
  };
  return <div onClick={handleOnClick} {...rest} />;
}

export default LinkBlocker;
