import React, { useState, useRef, useEffect, useContext } from "react"; import { useNavigate, Link } from "react-router-dom"; import profile from "../../assets/person_icon.png"; import styles from "./Profile.module.css"; import { useAppContext } from "../AppContext/AppContext.jsx"; function Profile({ position = "fixed" }) { const { username, isAuthenticated } = useAppContext(); const [open, setOpen] = useState(false); const menuRef = useRef(null); const imgRef = useRef(null); const navigate = useNavigate(); const menus = isAuthenticated ? ["My Maps", "Logout"] : ["Login"]; useEffect(() => { const handleClickOutside = (e) => { if (menuRef.current && imgRef.current) { if (!menuRef.current.contains(e.target) && !imgRef.current.contains(e.target)) { setOpen(false); } } }; document.addEventListener("click", handleClickOutside); return () => { document.removeEventListener("click", handleClickOutside); }; }, []); const handleMenuClick = (menu) => { if (menu === "My Maps") { navigate("/MyMaps"); } else if (menu === "Logout") { localStorage.removeItem("token"); window.location.reload(); } setOpen(false); }; return (