import React, { useState, useEffect, useRef } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { Menu, X, Sun, Moon, LogOut, User as UserIcon } from 'lucide-react'; import { auth } from '../firebase'; import { onAuthStateChanged, User as FirebaseUser, signOut } from 'firebase/auth'; const Header: React.FC = () => { const [isMenuOpen, setIsMenuOpen] = useState(false); const [darkMode, setDarkMode] = useState(false); const [user, setUser] = useState(null); const [profilePic, setProfilePic] = useState(null); const [isProfileOpen, setIsProfileOpen] = useState(false); const [showSignOutConfirm, setShowSignOutConfirm] = useState(false); // NEW const profileRef = useRef(null); const location = useLocation(); const navLinks = [ { path: '/', label: 'Humanizer X' }, { path: '/gpt-checker', label: 'GPT Checker' }, { path: '/word-counter', label: 'Word Counter' }, // <-- added { path: '/about', label: 'About' }, { path: '/contact', label: 'Contact' }, { path: '/blogs', label: 'Blog' }, ]; // Theme handling useEffect(() => { const savedTheme = localStorage.getItem('theme'); const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; if (savedTheme === 'dark' || (!savedTheme && prefersDark)) { setDarkMode(true); document.documentElement.classList.add('dark'); } else { setDarkMode(false); document.documentElement.classList.remove('dark'); } }, []); const toggleDarkMode = () => { const newDark = !darkMode; setDarkMode(newDark); if (newDark) { document.documentElement.classList.add('dark'); localStorage.setItem('theme', 'dark'); } else { document.documentElement.classList.remove('dark'); localStorage.setItem('theme', 'light'); } }; // Auth listener useEffect(() => { const unsubscribe = onAuthStateChanged(auth, (currentUser) => { setUser(currentUser); setProfilePic(currentUser?.photoURL || null); }); return () => unsubscribe(); }, []); // Close profile dropdown when clicking outside useEffect(() => { const handleClickOutside = (e: MouseEvent) => { if (profileRef.current && !profileRef.current.contains(e.target as Node)) { setIsProfileOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, []); const isActive = (path: string) => location.pathname === path || location.pathname.startsWith(path + "/"); // Sign out function const handleSignOut = async () => { try { await signOut(auth); setIsProfileOpen(false); setIsMenuOpen(false); setShowSignOutConfirm(false); // Close modal } catch (err) { console.error('Sign out error:', err); } }; return (
{/* Logo */} Humanizer X - AI Text Humanization Platform Logo Humanizer X {/* Desktop Navigation */} {/* Right side controls */}
{/* Profile/Auth Section */} {!user ? (
Sign In Get Started
) : (
{isProfileOpen && (
{profilePic ? ( Profile ) : ( )}

{user.displayName || 'User'}

{user.email}


My Profile
)}
)} {/* Mobile menu button */}
{/* Mobile Navigation */} {isMenuOpen && (
)}
{/* Sign Out Confirmation Modal */} {showSignOutConfirm && (

Confirm Sign Out

Are you sure you want to sign out?

)}
); }; export default Header;