import lastOpenedGroupFunc from "./getLastOpenedGroup";
import isDescendant from "./descendant";
import { getData } from "../Popper.manage";
export default function handleGetNeedPrevent(e) {
  let data = lastOpenedGroupFunc() || [];
  let popups = getData();
  let needPrevent = false;

  if (data.length > 1) {
    const {
      target
    } = e;
    const groupPopups = data.length ? popups[data[0]] : [];
    let openedPopup = null; // eslint-disable-next-line guard-for-in

    for (const i in groupPopups) {
      const {
        isPopupOpen
      } = groupPopups[i];

      if (isPopupOpen) {
        openedPopup = groupPopups[i];
        break;
      }
    }

    if (openedPopup) {
      const {
        dropElement,
        placeHolderElement
      } = openedPopup;
      const isDropBoxChild = isDescendant(dropElement.current, target);
      const isTargetChild = isDescendant(placeHolderElement.current, target);

      if (!isDropBoxChild && !isTargetChild // && isPopupMassUpdateChild
      ) {
        needPrevent = true;
      }
    }
  }

  return needPrevent;
}