"use client"; import { memo, useState, useEffect, useRef } from "react"; import { Link, usePathname, useTranslation } from "@/i18n/navigation"; import { getStoredUserEmail, pbLogout } from "@/app/lib/pocketbase"; import ThemeToggle from "./ThemeToggle"; 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 [search, setSearch] = useState(""); 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: "dating", href: "/dating", icon: "❀️" }, { labelKey: "chat", href: "/join", icon: "πŸ’¬" }, { labelKey: "hostMeetup", href: "/meetups", icon: "🎀", new: true }, { labelKey: "friendFinder", href: "/dating", icon: "πŸ’›" }, { labelKey: "membersMap", href: "#", icon: "🌐" }, { labelKey: "attendMeetup", href: "/meetups", icon: "🍹" }, ], }, { titleKey: "tools", items: [ { labelKey: "explore", href: "/", icon: "πŸ“" }, { labelKey: "nextStop", href: "/dashboard", icon: "πŸ—ΊοΈ" }, { labelKey: "climateFinder", href: "/tools", icon: "🌀️" }, { labelKey: "fireCalculator", href: "/tools", icon: "🌱" }, { labelKey: "aiAssistant", href: "/ai", icon: "πŸ€–", new: true }, { labelKey: "yearInReview", href: "/report", icon: "πŸ₯‚" }, { labelKey: "nomadStats", href: "/report", icon: "πŸ“Š", new: true }, { labelKey: "gigBoard", href: "/gigs", icon: "πŸ’°" }, { labelKey: "costCalculator", href: "/tools", icon: "πŸ’±" }, ], }, { titleKey: "help", items: [ { labelKey: "ideasBugs", href: "#", icon: "πŸ’‘" }, { labelKey: "faq", href: "#", icon: "πŸ†˜" }, { labelKey: "terms", href: "#", icon: "πŸ“„" }, { labelKey: "changelog", href: "#", icon: "πŸš€" }, ], }, { titleKey: "other", items: [ { 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.map((sec) => ({ ...sec, items: search ? sec.items.filter((i) => t(i.labelKey).toLowerCase().includes(search.toLowerCase()) ) : sec.items, })).filter((sec) => sec.items.length > 0); if (!isOpen) return null; return ( <>
{/* Header */}
{userEmail ? (
{userEmail[0].toUpperCase()}
{userEmail}
) : ( )} {t("filters")}
setSearch(e.target.value)} placeholder={t("searchPlaceholder")} className="w-full pl-10 pr-4 py-2.5 rounded-xl border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 text-sm focus:outline-none focus:ring-2 focus:ring-[#ff4d4f]/20 focus:border-[#ff4d4f]" />
{/* Profile + Dark mode */}
{profileItems.map((item) => ( {item.icon} {t(item.labelKey)} ))}
{t("darkMode")}
{/* Sections */}
{filteredSections.map((section) => (

{t(section.titleKey)}

    {section.items.map((item) => (
  • {item.icon} {t(item.labelKey)} {item.new && ( NEW )} {item.ad && ( Ad )}
  • ))}
))}
{/* Footer */} {userEmail && (
)}
); });