import PropTypes from 'prop-types';
import { Activity, useEffect, useRef, useState } from 'react';
import { Link, matchPath, useLocation } from 'react-router-dom';
// material-ui
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import Avatar from '@mui/material/Avatar';
import ButtonBase from '@mui/material/ButtonBase';
import Chip from '@mui/material/Chip';
import ListItemButton from '@mui/material/ListItemButton';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
import Tooltip from '@mui/material/Tooltip';
import Typography from '@mui/material/Typography';
// project imports
import { handlerDrawerOpen, useGetMenuMaster } from 'api/menu';
import useConfig from 'hooks/useConfig';
// assets
import FiberManualRecordIcon from '@mui/icons-material/FiberManualRecord';
export default function NavItem({ item, level, isParents = false, setSelectedID }) {
const theme = useTheme();
const downMD = useMediaQuery(theme.breakpoints.down('md'));
const ref = useRef(null);
const { pathname } = useLocation();
const {
state: { borderRadius }
} = useConfig();
const { menuMaster } = useGetMenuMaster();
const drawerOpen = menuMaster.isDashboardDrawerOpened;
const isSelected = !!matchPath({ path: item?.link ? item.link : item.url, end: false }, pathname);
const [hoverStatus, setHover] = useState(false);
const compareSize = () => {
const compare = ref.current && ref.current.scrollWidth > ref.current.clientWidth;
setHover(compare);
};
useEffect(() => {
compareSize();
window.addEventListener('resize', compareSize);
window.removeEventListener('resize', compareSize);
}, []);
const Icon = item?.icon;
const itemIcon = item?.icon ? (
) : (
0 ? 'inherit' : 'medium'} />
);
let itemTarget = '_self';
if (item.target) {
itemTarget = '_blank';
}
const itemHandler = () => {
if (downMD) handlerDrawerOpen(false);
if (isParents && setSelectedID) {
setSelectedID();
}
};
return (
<>
itemHandler()}
>
{itemIcon}
{(drawerOpen || (!drawerOpen && level !== 1)) && (
{item.title}
}
secondary={
item.caption && (
{item.caption}
)
}
/>
)}
{item.chip?.avatar}
}
/>
>
);
}
NavItem.propTypes = { item: PropTypes.any, level: PropTypes.number, isParents: PropTypes.bool, setSelectedID: PropTypes.func };