"use client"; import { memo, useEffect, useRef, useState } from "react"; import { Link, usePathname, useTranslation } from "@/i18n/navigation"; import { getStoredUserEmail, pbLogout } from "@/app/lib/pocketbase"; interface MenuItem { labelKey: string; href: string; icon: string; new?: boolean; ad?: boolean; } interface MenuSection { titleKey: string; items: MenuItem[]; } export default memo(function SiteMenu({ isOpen, onClose, onLoginClick, }: { isOpen: boolean; onClose: () => void; onLoginClick: () => void; }) { const { t } = useTranslation("menu"); const pathname = usePathname(); const ref = useRef(null); const [userEmail, setUserEmail] = useState(null); useEffect(() => { setUserEmail(getStoredUserEmail()); }, []); useEffect(() => { const handleClickOutside = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) onClose(); }; const handleEscape = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; if (isOpen) { document.addEventListener("mousedown", handleClickOutside); document.addEventListener("keydown", handleEscape); } return () => { document.removeEventListener("mousedown", handleClickOutside); document.removeEventListener("keydown", handleEscape); }; }, [isOpen, onClose]); const sections: MenuSection[] = [ { titleKey: "community", items: [ { labelKey: "messages", href: "/messages", icon: "🔔", new: true }, { labelKey: "chat", href: "/join", icon: "💬" }, { labelKey: "hostMeetup", href: "/meetups/host", icon: "🎤", new: true }, { labelKey: "membersMap", href: "/map", icon: "🌐" }, ], }, { titleKey: "tools", items: [ { labelKey: "climateFinder", href: "/tools", icon: "🌤️" }, { labelKey: "fireCalculator", href: "/tools", icon: "🌱" }, { labelKey: "costCalculator", href: "/tools", icon: "💱" }, { labelKey: "aiAssistant", href: "/ai", icon: "🤖", new: true }, { labelKey: "yearInReview", href: "/report", icon: "🥂" }, { labelKey: "nomadStats", href: "/report/data", icon: "📊", new: true }, { labelKey: "gigBoard", href: "/gigs", icon: "💰" }, ], }, { titleKey: "help", items: [ { labelKey: "ideasBugs", href: "/feedback", icon: "💡" }, { labelKey: "faq", href: "#", icon: "🆘" }, { labelKey: "terms", href: "#", icon: "📄" }, { labelKey: "changelog", href: "#", icon: "🚀" }, ], }, { titleKey: "other", items: [ { labelKey: "digitalNomadGuide", href: process.env.NEXT_PUBLIC_DIGITAL_URL || "https://digital.hackrobot.cn/", icon: "📖" }, { labelKey: "remoteJobs", href: "#", icon: "💼" }, { labelKey: "coworking", href: "#", icon: "🏢" }, ], }, ]; const profileItems: MenuItem[] = [ { labelKey: "yourProfile", href: "/join", icon: "👤" }, { labelKey: "settings", href: "/join", icon: "⚙️" }, { labelKey: "favorites", href: "/", icon: "❤️" }, { labelKey: "pricing", href: "/pricing", icon: "👑" }, { labelKey: "nomadInsurance", href: "#", icon: "🛡️", ad: true }, ]; const filteredSections = sections; if (!isOpen) return null; return ( <>
{/* Profile links */}
{profileItems.map((item) => ( {item.icon} {t(item.labelKey)} ))}
{/* Sections */}
{filteredSections.map((section) => (

{t(section.titleKey)}

    {section.items.map((item) => { const isExternal = item.href.startsWith("http"); const linkClass = `flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${ item.href !== "#" && !isExternal && (pathname === item.href || (item.href !== "/" && pathname.startsWith(item.href))) ? "bg-[#ff4d4f]/10 text-[#ff4d4f]" : "text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800" }`; return (
  • {isExternal ? ( {item.icon} {t(item.labelKey)} {item.new && ( NEW )} {item.ad && ( Ad )} ) : ( {item.icon} {t(item.labelKey)} {item.new && ( NEW )} {item.ad && ( Ad )} )}
  • ); })}
))}
{/* Footer */} {userEmail && (
)}
); });