export const getPositionClass = (target, styles) => {
  const children = target?.parentNode?.children || [];

  // eslint-disable-next-line no-restricted-syntax
  for (const element of children) {
    if (element?.tagName === 'UL' && [...element?.classList].includes(styles.subMenuList)) {
      const { left, width } = element.getBoundingClientRect();

      // eslint-disable-next-line no-unused-expressions
      (left + width > document.body.clientWidth || left < 0) &&
        element.classList.add(styles.staticLeft, styles.hoverLeft);
      break;
    }
  }
};

export const getMenuObj = (modules, menu) =>
  modules.find(
    (module) => module.menu_short_code === menu || module.menu_short_code === 'main_menu'
  );

// eslint-disable-next-line no-prototype-builtins
export const itemHasChildren = (item) =>
  item.children.some((child) => child.hasOwnProperty('children'));
