import React, { useState, useRef, useEffect } from 'react' import { Link, useNavigate, useLocation } from 'react-router-dom' import { Bell, Menu, X, ChevronDown, BookOpen, PenLine, Shield, List } from 'lucide-react' import logo from '../../assets/chapterX-removebg-preview.png' import { useAuthStore } from '../../store/authStore' import { useNotificationStore } from '../../store/notificationStore' import { Avatar } from '../ui/Avatar' import { RoleBadge } from '../ui/Badge' import { Button } from '../ui/Button' import { NotificationDropdown } from '../notifications/NotificationDropdown' export const Navbar: React.FC = () => { const navigate = useNavigate() const location = useLocation() const { currentUser, logout } = useAuthStore() const { notifications, fetchUserNotifications } = useNotificationStore() const unread = notifications.filter(n => !n.is_read).length useEffect(() => { if (currentUser) fetchUserNotifications(currentUser.user_id) }, [currentUser?.user_id]) const [mobileOpen, setMobileOpen] = useState(false) const [userMenuOpen, setUserMenuOpen] = useState(false) const [notifOpen, setNotifOpen] = useState(false) const userMenuRef = useRef(null) const notifRef = useRef(null) useEffect(() => { const handler = (e: MouseEvent) => { if (userMenuRef.current && !userMenuRef.current.contains(e.target as Node)) setUserMenuOpen(false) if (notifRef.current && !notifRef.current.contains(e.target as Node)) setNotifOpen(false) } document.addEventListener('mousedown', handler) return () => document.removeEventListener('mousedown', handler) }, []) const navLinks = [ { to: '/browse', label: 'Browse', icon: }, { to: '/genres', label: 'Genres', icon: null }, { to: '/community-lists', label: 'Reading Lists', icon: }, ] const isActive = (path: string) => location.pathname.startsWith(path) return ( ) }