/* eslint-disable no-prototype-builtins */ import React, { useEffect, useState } from "react"; import { MenuItemProps, SubMenuItemProps } from "../DynamicMenu"; import { Link } from "vtex.render-runtime"; import styles from "./MenuItem.css"; import { SubMenuBanner } from "../SubMenuBanner"; export const MenuItem: React.FC = ({ href, title, content, internal, items, banner, bannerUrl, }: MenuItemProps) => { const [subMenuItems, setSubMenuItems] = useState([]); const [showSubMenu, setShowSubMenu] = useState(false); const standardizeSubItems = () => { const newItems = items?.map((item) => { if (item.hasOwnProperty("SubMenuItemProps")) { return item.SubMenuItemProps; } return item; }); setSubMenuItems(newItems as []); }; useEffect(() => { if (items) { standardizeSubItems(); } }, [items]); const isEmpty = (obj: SubMenuItemProps[]) => { for (const prop in obj) { if (obj.hasOwnProperty(prop)) return true; } return false; }; return ( <>
  • { setShowSubMenu(!showSubMenu); }} onMouseLeave={() => { setShowSubMenu(!showSubMenu); }} > {title} {isEmpty(subMenuItems) && showSubMenu && (
      {subMenuItems.map((item, i) => { let isNextItemHighlight = false; if (i > 0 || i !== subMenuItems.length) { isNextItemHighlight = subMenuItems[ i + 1 ]?.highlight ? true : false; } return ( <>
    • {item.title}
    • {/* {isNextItemHighlight && (
    •  
    • )} */} ); })}
    {banner && ( )}
    )}
  • ); };