import React, { useState, useEffect } from 'react'; import axios from 'axios'; import { Link, useNavigate, useLocation } from 'react-router-dom'; import { motion } from 'framer-motion'; import { Cpu, LogOut, User, MessageCircle } from 'lucide-react'; import LightDark from './lightdark'; import UserAvatar from './UserAvatar'; import SupportChat from './SupportChat'; const navLinks = [ { path: '/', label: 'ГЛАВНАЯ' }, { path: '/about', label: 'О НАС' }, { path: '/contact', label: 'КОНТАКТЫ' }, ]; const catalogLink = [ { path: '/dashboard', label: 'КАТАЛОГ' } ]; const NavBar = ({ user, onLogin, onLogout }) => { const [theme, setTheme] = useState(localStorage.getItem('theme') || 'dark'); const [hoveredPath, setHoveredPath] = useState(null); const [unreadCount, setUnreadCount] = useState(0); const [isChatOpen, setIsChatOpen] = useState(false); const navigate = useNavigate(); const location = useLocation(); const isAdmin = user?.role === 'admin'; const roleLabel = isAdmin ? 'ADMIN' : 'OPERATOR'; const roleColorClass = isAdmin ? 'text-red-500' : 'text-[var(--accent-color)]'; const adminColorClass = 'text-red-500'; // --- 1. ТАБЛИЦЫ ОБОРУДОВАНИЯ (ЧИСТЫЕ ПУТИ ДЛЯ ВСЕХ) --- const equipmentLinks = [ { path: '/hubs', label: 'ХАБЫ' }, { path: '/cameras', label: 'КАМЕРЫ' }, { path: '/lighting', label: 'СВЕТ' }, { path: '/sensors', label: 'ДАТЧИКИ' }, ]; // --- 2. ТАБЛИЦЫ УПРАВЛЕНИЯ (ТОЛЬКО АДМИНУ) --- const adminManagementLinks = [ { path: '/users', label: 'ПОЛЬЗОВАТЕЛИ' }, { path: '/orders', label: 'ЗАКАЗЫ' }, { path: '/messages', label: 'ЧАТЫ' }, { path: '/admin/logs', label: 'ЛОГИ' }, ]; useEffect(() => { document.body.className = theme; localStorage.setItem('theme', theme); }, [theme]); useEffect(() => { if (user) { const checkUnread = async () => { try { const token = localStorage.getItem('token'); const res = await axios.get(`https://diplomnexus.aptcloud.ru/messages/unread?email=${user.email}`, { headers: { Authorization: `Bearer ${token}` } }); setUnreadCount(res.data.count); } catch (e) {} }; checkUnread(); const interval = setInterval(checkUnread, 5000); return () => clearInterval(interval); } }, [user]); const toggleTheme = () => setTheme(theme === 'dark' ? 'light' : 'dark'); const renderMenu = (links) => (