// DashboardNavigation.js
import React, { useContext, useEffect, useState } from 'react'
import {
Menu,
Flex,
Tag,
Space,
Dropdown,
Button,
Tooltip,
Typography,
Divider,
Badge
} from 'antd'
import {
LogoutOutlined,
MailOutlined,
MenuOutlined,
LoadingOutlined
} from '@ant-design/icons'
import { AuthContext } from '../context/AuthContext'
import { SocketContext } from '../context/SocketContext'
import { SpotlightContext } from '../context/SpotlightContext'
import { NotificationContext } from '../context/NotificationContext'
import { useNavigate, useLocation } from 'react-router-dom'
import { Header } from 'antd/es/layout/layout'
import { useMediaQuery } from 'react-responsive'
import FarmControlLogo from '../../Logos/FarmControlLogo'
import FarmControlLogoSmall from '../../Logos/FarmControlLogoSmall'
import ProductionIcon from '../../Icons/ProductionIcon'
import InventoryIcon from '../../Icons/InventoryIcon'
import PersonIcon from '../../Icons/PersonIcon'
import CloudIcon from '../../Icons/CloudIcon'
import BellIcon from '../../Icons/BellIcon'
import SearchIcon from '../../Icons/SearchIcon'
import SettingsIcon from '../../Icons/SettingsIcon'
import DeveloperIcon from '../../Icons/DeveloperIcon'
const { Text } = Typography
const DashboardNavigation = () => {
const { logout, userProfile } = useContext(AuthContext)
const { showSpotlight } = useContext(SpotlightContext)
const { toggleNotificationCenter, unreadCount } =
useContext(NotificationContext)
const { socket } = useContext(SocketContext)
const [socketState, setSocketState] = useState('disconnected')
const navigate = useNavigate()
const location = useLocation()
const [selectedKey, setSelectedKey] = useState('production')
const isMobile = useMediaQuery({ maxWidth: 768 })
useEffect(() => {
const pathParts = location.pathname.split('/').filter(Boolean)
if (pathParts.length > 2) {
setSelectedKey(pathParts[1]) // Return the section (production/management)
}
}, [location.pathname])
useEffect(() => {
if (socket?.connecting) {
setSocketState('connecting')
} else if (socket?.connected) {
setSocketState('connected')
} else {
setSocketState('disconnected')
}
}, [socket?.connecting, socket?.connected])
const mainMenuItems = [
{
key: 'production',
label: 'Production',
icon:
},
{
key: 'inventory',
label: 'Inventory',
icon:
},
{
key: 'management',
label: 'Management',
icon:
}
]
const userMenuItems = {
items: [
{
key: 'username',
label: userProfile?.username,
icon: ,
disabled: true
},
{
key: 'email',
label: userProfile?.email,
icon: ,
disabled: true
},
{
key: 'logout',
label: 'Logout',
icon:
}
],
onClick: (key) => {
if (key === 'profile') {
navigate('/profile')
} else if (key === 'logout') {
logout()
}
}
}
const handleMainMenuClick = ({ key }) => {
if (key === 'production') {
navigate('/dashboard/production/overview')
} else if (key === 'inventory') {
navigate('/dashboard/inventory/filamentstocks')
} else if (key === 'management') {
navigate('/dashboard/management/filaments')
}
}
return (
{!isMobile ? (
) : (
)}
} />}
/>
⌘ ⇧ P} arrow={false}>
}
type='text'
style={{ marginTop: '2px' }}
onClick={() => showSpotlight()}
>
}
type='text'
style={{ marginTop: '2px' }}
onClick={toggleNotificationCenter}
>
{socketState === 'connected' ? (
}
/>
) : null}
{socketState === 'connecting' ? (
}
/>
) : null}
{socketState === 'disconnected' ? (
}
/>
) : null}
{process.env.NODE_ENV === 'development' && (
}
onClick={() => {
navigate('/dashboard/developer/sessionstorage')
}}
/>
)}
{userProfile ? (
}>
{!isMobile && (userProfile?.name || userProfile.username)}
) : null}
)
}
export default DashboardNavigation