import PropTypes from 'prop-types';
import { useEffect, useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
// material-ui
import MuiBreadcrumbs from '@mui/material/Breadcrumbs';
import { useTheme } from '@mui/material/styles';
import { Divider, Grid, Typography } from '@mui/material';
// project import
import MainCard from 'components/MainCard';
// assets
import { ApartmentOutlined, HomeFilled, HomeOutlined } from '@ant-design/icons';
// ==============================|| BREADCRUMBS ||============================== //
const Breadcrumbs = ({
card,
divider = true,
icon,
icons,
maxItems,
navigation,
rightAlign,
separator,
title,
titleBottom,
sx,
...others
}) => {
const theme = useTheme();
const location = useLocation();
const [main, setMain] = useState();
const [item, setItem] = useState();
let currentPath = location.pathname;
// only used for component demo breadcrumbs
if (currentPath.includes('/components-overview/breadcrumbs')) {
currentPath = '/apps/kanban/board';
}
if (currentPath.includes('/apps/kanban/backlogs')) {
currentPath = '/apps/kanban/board';
}
useEffect(() => {
if (currentPath.includes('/apps/profiles/user/payment')) {
setItem(undefined);
}
}, [item, currentPath]);
const iconSX = {
marginRight: theme.spacing(0.75),
marginTop: `-${theme.spacing(0.25)}`,
width: '1rem',
height: '1rem',
color: theme.palette.secondary.main
};
// set active item state
const getCollapse = (menu) => {
if (menu.children) {
menu.children.filter((collapse) => {
if (collapse.type && collapse.type === 'collapse') {
getCollapse(collapse);
if (collapse.url === currentPath) {
setMain(collapse);
setItem(collapse);
}
} else if (collapse.type && collapse.type === 'item') {
if (currentPath.includes(collapse.url)) {
setMain(menu);
setItem(collapse);
}
}
return false;
});
}
};
useEffect(() => {
navigation?.items?.map((menu) => {
if (menu.type && menu.type === 'group') {
getCollapse(menu);
}
return false;
});
});
// item separator
const SeparatorIcon = separator;
const separatorIcon = separator ? : '/';
let mainContent;
let itemContent;
let breadcrumbContent = ;
let itemTitle = '';
let CollapseIcon;
let ItemIcon;
// collapse item
if (main && main.type === 'collapse' && main.breadcrumbs === true) {
CollapseIcon = main.icon ? main.icon : ApartmentOutlined;
mainContent = (
{icons && }
{main.title}
);
breadcrumbContent = (
{icons && }
{icon && !icons && }
{(!icon || icons) && 'Home'}
{mainContent}
{title && titleBottom && (
{main.title}
)}
{card === false && divider !== false && }
);
}
// items
if (item && item.type === 'item') {
itemTitle = item.title;
ItemIcon = item.icon ? item.icon : ApartmentOutlined;
itemContent = (
{icons && }
{itemTitle}
);
// main
if (item.breadcrumbs !== false) {
breadcrumbContent = (
{title && !titleBottom && (
{item.title}
)}
{icons && }
{icon && !icons && }
{(!icon || icons) && 'Home'}
{mainContent}
{itemContent}
{title && titleBottom && (
{item.title}
)}
{card === false && divider !== false && }
);
}
}
return breadcrumbContent;
};
Breadcrumbs.propTypes = {
card: PropTypes.bool,
divider: PropTypes.bool,
icon: PropTypes.bool,
icons: PropTypes.bool,
maxItems: PropTypes.number,
navigation: PropTypes.object,
rightAlign: PropTypes.bool,
separator: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
title: PropTypes.bool,
titleBottom: PropTypes.bool,
sx: PropTypes.oneOfType([PropTypes.object, PropTypes.string])
};
export default Breadcrumbs;