import React, { useState, useRef, useEffect } from 'react'; import { Search, Bell, Menu, User, ChevronDown, Settings, LogOut, UserCircle, X, PanelLeftClose, PanelLeftOpen } from 'lucide-react'; import { useNavigate } from 'react-router-dom'; import NotificationPopover from '../../user/components/NotificationPopover'; import useAuthStore from '../../store/authStore'; import { Avatar, AvatarFallback, AvatarImage } from "../../components/ui/avatar"; /** * AdminHeader Component * Refined 64px header for the administrative console. * Features a solid white background, specific search placeholder, * and a functional avatar dropdown menu. */ const AdminHeader = ({ onMobileNavToggle, isSidebarCollapsed, onToggleSidebar }) => { const [isProfileOpen, setIsProfileOpen] = useState(false); const [searchQuery, setSearchQuery] = useState(''); const dropdownRef = useRef(null); const searchRef = useRef(null); const navigate = useNavigate(); const { logout, profile: adminProfile } = useAuthStore(); const initials = adminProfile?.full_name ? adminProfile.full_name.split(' ').map(n => n[0]).join('').toUpperCase() : 'AD'; const handleSearchKeyDown = (e) => { if (e.key === 'Enter' && searchQuery.trim()) { navigate(`/admin/tickets?q=${encodeURIComponent(searchQuery.trim())}`); searchRef.current?.blur(); } else if (e.key === 'Escape') { setSearchQuery(''); searchRef.current?.blur(); } }; const handleSearchClear = () => { setSearchQuery(''); searchRef.current?.focus(); }; // Handle clicks outside of dropdown to close it useEffect(() => { const handleClickOutside = (event) => { if (dropdownRef.current && !dropdownRef.current.contains(event.target)) { setIsProfileOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, []); const handleLogout = async () => { await logout(); navigate('/login'); }; return (
{/* Mobile Menu Toggle */} {/* Desktop Sidebar Toggle */} {onToggleSidebar && ( )} {/* Primary Search Terminal */}
setSearchQuery(e.target.value)} onKeyDown={handleSearchKeyDown} placeholder="Search tickets, users… (press Enter)" className="w-full bg-slate-50/50 border border-slate-200 rounded-xl pl-11 pr-9 py-2 text-sm font-medium tracking-tight focus:outline-none focus:ring-4 focus:ring-emerald-600/5 focus:border-emerald-600 focus:bg-white transition-all text-slate-600 placeholder:text-slate-400" /> {searchQuery && ( )}
{/* Header Operations */}
{/* Communications Hub */}
{/* Identity Access & Dropdown */}
{/* Dropdown Menu */} {isProfileOpen && (
)}
); }; export default AdminHeader;