import { useAuth, useSignInUp } from '@hooks/useAuth'
import { Avatar, Badge, Box, Divider, Flex, Menu, NavLink } from '@mantine/core'
import { notifications } from '@mantine/notifications'
import { NAV_ITEM } from '@routes/nav-route'
import { PathConstants } from '@routes/routes'
import {
IconAt,
IconCircleXFilled,
IconLogout,
IconUserCircle,
} from '@tabler/icons-react'
import { useTranslation } from 'react-i18next'
import { NavLink as Link } from 'react-router-dom'
function NavLinkWithChildren(item) {
const Icon = item.icon
return (
}>
{item.children.map((child) => {
if (!child.show) return
if (child.children) {
return
} else {
return (
}
label={child.text}
component={Link}
to={child.pathName}
/>
)
}
})}
)
}
export default function Navbar() {
const { auth, setAuth } = useAuth()
const { t } = useTranslation()
const { onLogout } = useSignInUp(setAuth)
const logOut = async () => {
try {
await onLogout()
} catch (error) {
notifications.show({
color: 'red.5',
icon: ,
withCloseButton: true,
title: t('message_logout_fail'),
})
}
}
return (
<>
{NAV_ITEM(t, auth?.userInfo?.isAdmin).map((item) => {
if (!item.show) return null
const Icon = item.icon
if (item.children) {
return
} else {
return (
}
label={item.text}
component={Link}
to={item.pathName}
className={({ isActive, isPending }) =>
isPending ? 'pending' : isActive ? 'active' : ''
}
color="red.8"
/>
)
}
})}
>
)
}