import { useState } from "react"; import { Dialog } from "@headlessui/react"; import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/outline"; import { NavLink, Link, useNavigate } from "react-router-dom"; import { Button } from "../UI"; import { useAuth } from "../../hooks/useAuth"; const publicNavigation = [ { name: "Дома", href: "/" }, { name: "За нас", href: "/about" }, { name: "Галерија", href: "/gallery" }, { name: "Контакт", href: "/contact" }, { name: "Логин", href: "/login" }, ]; const basePrivateNavigation = [ { name: "Дома", href: "/" }, { name: "За нас", href: "/about" }, { name: "Галерија", href: "/gallery" }, { name: "Контакт", href: "/contact" }, ]; export default function Navbar() { const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const { user, logout } = useAuth(); const navigate = useNavigate(); const getNavigation = () => { if (!user) return publicNavigation; // Add appropriate dashboard link based on user role const privateNavigation = [...basePrivateNavigation]; if (user.isAdmin) { privateNavigation.push({ name: "Админ Панел", href: "/admin" }); } else { privateNavigation.push({ name: "Клиент Зона", href: "/dashboard" }); } return privateNavigation; }; const navigation = getNavigation(); const handleLogout = async () => { try { await logout(); navigate("/"); } catch (error) { console.error("Logout failed:", error); } }; return (
{/* Mobile Menu */}
IMK logo
{/* User Info in Mobile Menu */} {user && (
{user.name || user.email} {user.isAdmin ? "Администратор" : "Корисник"}
)} {/* Navigation Items */} {navigation.map((item) => ( `block px-3 py-2 text-base font-medium rounded-lg transition-colors ${ isActive ? "bg-primary-700 text-white" : "text-neutral-200 hover:bg-primary-700/50 hover:text-white" }` } onClick={() => setMobileMenuOpen(false)} > {item.name} ))} {/* Logout in Mobile Menu */} {user && ( )}
); }