import { useRef, useState } from 'react' import { useRouter } from 'next/router' import { Popover } from '@headlessui/react' import Link from 'next/link' import { AaveMonoIcon, BtcMonoIcon, CopeMonoIcon, DogeMonoIcon, EthMonoIcon, FidaMonoIcon, FttMonoIcon, MediaMonoIcon, MerMonoIcon, MngoMonoIcon, RayMonoIcon, SolMonoIcon, SrmMonoIcon, StepMonoIcon, SushiMonoIcon, UniMonoIcon, UsdtMonoIcon, } from './icons' const symbolIcons = { AaveMonoIcon, BtcMonoIcon, CopeMonoIcon, DogeMonoIcon, EthMonoIcon, FidaMonoIcon, FttMonoIcon, MediaMonoIcon, MerMonoIcon, MngoMonoIcon, RayMonoIcon, SolMonoIcon, SrmMonoIcon, StepMonoIcon, SushiMonoIcon, UniMonoIcon, UsdtMonoIcon, } export default function MarketMenuItem({ menuTitle = '', linksArray = [] }) { const { asPath } = useRouter() const buttonRef = useRef(null) const [openState, setOpenState] = useState(false) const iconName = `${menuTitle.substr(0, 1)}${menuTitle .substr(1, 4) .toLowerCase()}MonoIcon` const SymbolIcon = symbolIcons[iconName] const toggleMenu = () => { setOpenState((openState) => !openState) buttonRef?.current?.click() } const onHover = (open, action) => { if ( (!open && !openState && action === 'onMouseEnter') || (open && openState && action === 'onMouseLeave') ) { toggleMenu() } } const handleClick = (open) => { setOpenState(!open) } return (
{({ open }) => (
onHover(open, 'onMouseEnter')} onMouseLeave={() => onHover(open, 'onMouseLeave')} className="flex flex-col h-10" > handleClick(open)} > {menuTitle}
{linksArray.map((m) => ( {m.name} ))}
)}
) }