import AppBar from "@mui/material/AppBar";
import Box from "@mui/material/Box";
import Toolbar from "@mui/material/Toolbar";
import IconButton from "@mui/material/IconButton";
import Typography from "@mui/material/Typography";
import SwipeableDrawer from "@mui/material/SwipeableDrawer";
import List from "@mui/material/List";
import ListItem from "@mui/material/ListItem";
import ListItemButton from "@mui/material/ListItemButton";
import ListItemText from "@mui/material/ListItemText";
import Avatar from "@mui/material/Avatar";
import Container from "@mui/material/Container";
import Tooltip from "@mui/material/Tooltip";
import MenuIcon from "@mui/icons-material/Menu";
import CloseIcon from "@mui/icons-material/Close";
import Divider from "@mui/material/Divider";
import Modal from "@mui/material/Modal";
import Button from "@mui/material/Button";
import LazyImage from "./LazyImage";
import Logo from "../../assets/images/logo.png";
import { useLocation, useNavigate } from "react-router-dom";
import { useState, useRef, useEffect } from "react";
import { useTheme, useMediaQuery, ListItemIcon } from "@mui/material";
import { Home, Users, Heart, MessageCircle, Search, Bell } from "lucide-react";
import { isAuthenticated } from "../../utills/auth";
import userimg from "../../assets/images/bride1.jpg"
import axiosInstance, { logoutAPI } from "../../api/axiosInstance";
import toast from "react-hot-toast";
import { API_ENDPOINTS } from "../../api/apiEndpoints";
import { useMutation, useQuery } from "@tanstack/react-query";
const NAV_LINKS = [
// { label: "Home", path: "/" },
{ label: "Matches", path: "/matches" },
// { label: "ProfileCard", path: "/profile-card" },
{ label: "Interest", path: "/interest" },
{ label: "Horoscope", path: "/horoscoper-generate" },
{ label: "Messages", path: "/chat" },
{ label: "Search", path: "/matches" },
{ label: "Notifications", path: "/notifications" }
];
const PROFILE_MENU = [
{ label: "Dashboard", path: "/dashboard-home" },
{ label: "Profile", path: "/profile" },
{ label: "Subscription", path: "/subscription-plan" },
{ label: "Subscription History", path: "/subscription-history" },
{ label: "Change Password", path: "/change-password" },
{ label: "View Reports", path: "/block-report-profilelist" },
{ label: "Blocked Users", path: "/block-report-profilelist" }
];
const ACCOUNT_SETTINGS = [
{ label: "Privacy Settings", path: "/account-settings" },
{ label: "Privacy Policy", path: "/privacy-policy" },
{ label: "Terms & Conditions", path: "/terms" },
{ label: "Contact Us", path: "/contact" },
{ label: "Be Safe Online", path: "/safe-online" },
{ label: "Delete Account", action: "delete" },
{ label: "Logout", action: "logout" }
];
const SparkleNavbar = ({ items, color = "#0fec1eff", onItemClick, activeItem, badges = {} }) => {
const [activeIndex, setActiveIndex] = useState(0);
const [indicatorStyle, setIndicatorStyle] = useState({});
const [isAnimating, setIsAnimating] = useState(false);
const navRef = useRef(null);
const buttonRefs = useRef([]);
const updateIndicator = (index) => {
const button = buttonRefs.current[index];
if (button && navRef.current) {
const navRect = navRef.current.getBoundingClientRect();
const btnRect = button.getBoundingClientRect();
setIndicatorStyle({
left: btnRect.left - navRect.left + btnRect.width / 2 - 18,
opacity: 1
});
}
};
// sync with activeItem from router
useEffect(() => {
if (!activeItem) return;
const newIndex = items.indexOf(activeItem);
if (newIndex !== -1 && newIndex !== activeIndex) {
setActiveIndex(newIndex);
updateIndicator(newIndex);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activeItem, items]);
// initial indicator
useEffect(() => {
updateIndicator(activeIndex);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const handleClick = (index) => {
if (index === activeIndex || isAnimating) return;
setIsAnimating(true);
const newButton = buttonRefs.current[index];
if (newButton && navRef.current) {
const navRect = navRef.current.getBoundingClientRect();
const newRect = newButton.getBoundingClientRect();
setIndicatorStyle((prev) => ({
...prev,
left: newRect.left - navRect.left + newRect.width / 2 - 18
}));
setTimeout(() => {
setActiveIndex(index);
setIsAnimating(false);
if (onItemClick) onItemClick(items[index], index);
}, 300);
}
};
return (
);
};
const ProfileHeader = () => {
const auth = isAuthenticated();
const navigate = useNavigate();
const location = useLocation();
const [mobileDrawerOpen, setMobileDrawerOpen] = useState(false);
const [profileDrawerOpen, setProfileDrawerOpen] = useState(false);
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
const [logoutModalOpen, setLogoutModalOpen] = useState(false);
const theme = useTheme();
const isDesktop = useMediaQuery(theme.breakpoints.up("md"));
const toggleMobileDrawer = (open) => () => setMobileDrawerOpen(open);
const toggleProfileDrawer = (open) => () => setProfileDrawerOpen(open);
const [selectedItem, setSelectedItem] = useState("Home");
const currentNav = NAV_LINKS.find(link =>
location.pathname.startsWith(link.path)
);
const currentLabel = currentNav?.label ?? NAV_LINKS[0].label;
const { data: notificationData } = useQuery({
queryKey: ["notificationCount"],
queryFn: async () => {
const res = await axiosInstance.get(API_ENDPOINTS.NOTIFICATION_COUNT);
return res.data;
},
enabled: !!auth,
});
const notificationCount = notificationData?.count || 0;
const handleMenuClick = (item) => {
if (item.action === "delete") {
setDeleteModalOpen(true);
setProfileDrawerOpen(false);
} else if (item.action === "logout") {
setLogoutModalOpen(true);
setProfileDrawerOpen(false);
} else if (item.path) {
navigate(item.path);
setProfileDrawerOpen(false);
}
};
const deleteAccountMutation = useMutation({
mutationFn: async () => {
return await axiosInstance.delete(API_ENDPOINTS.DELETE_ACCOUNT);
},
onSuccess: (response) => {
toast.success(response?.data?.message || "Account deleted successfully");
setDeleteModalOpen(false);
logoutAPI();
navigate("/");
},
onError: (error) => {
toast.error(error?.response?.data?.message || "Failed to delete account");
},
});
const handleDeleteAccount = () => {
deleteAccountMutation.mutate();
};
const handleLogout = () => {
setLogoutModalOpen(false);
logoutAPI();
};
const modalStyle = {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: isDesktop ? 400 : '90%',
bgcolor: 'background.paper',
borderRadius: 2,
boxShadow: 24,
p: 4,
};
const getNavIcon = (index) => {
const icons = [Home, Users, Heart, MessageCircle, Search, Bell];
const IconComponent = icons[index % icons.length];
return ;
};
const ProfileDrawerContent = (
Account
{!isDesktop && (
)}
{PROFILE_MENU.map((item) => (
handleMenuClick(item)}>
))}
Account Settings
{ACCOUNT_SETTINGS.map((item) => (
handleMenuClick(item)}>
))}
);
const MobileDrawerMenu = (
Menu
{NAV_LINKS.map(({ label, path }, index) => (
{
navigate(path);
toggleMobileDrawer(false)();
}}
>
{getNavIcon(index)}
{label}
{label === "Notifications" && notificationCount > 0 && (
{notificationCount}
)}
} />
))}
);
return (
<>
navigate("/")} sx={{ display: { xs: "none", md: "flex" }, mr: 1 }}>
navigate("/")}
>
link.label)}
color="#034E08"
activeItem={currentLabel}
badges={{ "Notifications": notificationCount }}
onItemClick={(item) => {
setSelectedItem(item);
const link = NAV_LINKS.find(l => l.label === item);
if (link) navigate(link.path);
}}
/>
{(auth ? (
):( ))}
{MobileDrawerMenu}
{ProfileDrawerContent}
{/* Delete Account Modal */}
setDeleteModalOpen(false)}
aria-labelledby="delete-modal-title"
>
Delete Account
setDeleteModalOpen(false)} size="small">
Are you sure you want to delete your account? This action cannot be undone.
{/* Logout Modal */}
setLogoutModalOpen(false)}
aria-labelledby="logout-modal-title"
>
Logout
setLogoutModalOpen(false)} size="small">
Are you sure you want to logout?
>
);
};
export default ProfileHeader;