const { useState, useRef, useEffect } = React; function Navbar({ currentPath }) { const { useAuth } = window.AuthComponents || {}; // Fallback if useAuth is not loaded for some reason const auth = useAuth ? useAuth() : { user: null, loading: false }; const { user, loading, logout, checkLogin } = auth; const [showMoreMenu, setShowMoreMenu] = useState(false); const [showUserMenu, setShowUserMenu] = useState(false); const [showLoginModal, setShowLoginModal] = useState(false); const [showProfileModal, setShowProfileModal] = useState(false); const menuRef = useRef(null); const userMenuRef = useRef(null); // Close menus when clicking outside useEffect(() => { const handleClickOutside = (event) => { if (menuRef.current && !menuRef.current.contains(event.target)) { setShowMoreMenu(false); } if (userMenuRef.current && !userMenuRef.current.contains(event.target)) { setShowUserMenu(false); } }; document.addEventListener("mousedown", handleClickOutside); return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, [menuRef, userMenuRef]); const pathMap = { '缘分测试': 'compatibility.html', '星座运势': 'horoscope.html', '塔罗占卜': 'index.html', '八字命理': 'bazi.html', '寻找宿命': 'destiny.html', '依恋测试': 'attachment.html' }; const handleNavigation = (target) => { if (target) { window.location.href = window.location.protocol === 'file:' ? target : '/' + target; } else { alert('该功能正在开发中,敬请期待!'); } }; const handleDeleteHistory = async () => { if (!confirm('确认删除你的全部测算历史吗?此操作不可恢复。')) return; const token = localStorage.getItem('mystic_token'); try { await fetch('/api/auth/history', { method: 'DELETE', headers: { 'Authorization': `Bearer ${token}` } }); alert('历史记录已删除'); } catch (err) { alert('操作失败'); } }; const handleDeleteAccount = async () => { if (!confirm('确认注销账户并删除全部个人资料与测算历史吗?此操作不可恢复。')) return; const token = localStorage.getItem('mystic_token'); try { await fetch('/api/auth/account', { method: 'DELETE', headers: { 'Authorization': `Bearer ${token}` } }); localStorage.removeItem('mystic_token'); localStorage.removeItem('mystic_profile'); window.location.href = '/'; } catch (err) { alert('操作失败'); } }; return (