import React, { useState } from "react";
import { Modal } from "antd";
import { Link } from "react-router-dom";
import {
User,
LogIn,
Wallet,
Heart,
Languages,
List,
Mail,
Info,
Edit,
MapPin,
LogOut,
} from "lucide-react";
import { useTranslation } from "react-i18next";
import styles from "./ProfileMenu.module.scss";
import LoginModal from "../LogIn";
import SignUpModal from "../SignUp";
import ProfileModal from "..//MyProfileModal/index";
import tm from "../../assets/tm.png";
import ru from "../../assets/ru.png";
import en from "../../assets/en.png";
import { useAuth } from "../../context/authContext";
import { useGetProfileQuery } from "../../app/api/myProfileApi";
const ProfileMenu = () => {
const [activeModal, setActiveModal] = useState(null);
const { t, i18n } = useTranslation();
const { isAuthenticated, logout } = useAuth();
// Fetch profile data from API
const { data: profileData, isLoading } = useGetProfileQuery(undefined, {
skip: !isAuthenticated, // Skip the API call if not authenticated
});
// Extract user data from API response
const userData = profileData?.data || {
first_name: "",
last_name: "",
phone_number: "",
address: "",
};
const languages = [
{ code: "tk", img: tm, name: "Türkmen" },
{ code: "ru", img: ru, name: "Русский" },
{ code: "en", img: en, name: "English" },
];
const handleMenuClick = (item) => {
if (item.action === "logout") {
logout();
return;
}
if (item.action) {
setActiveModal(item.action);
}
};
const handleLanguageChange = async (langCode) => {
await i18n.changeLanguage(langCode);
localStorage.setItem("preferredLanguage", langCode);
setActiveModal(null);
window.location.reload();
};
// Handle edit profile click
const handleEditProfile = () => {
setActiveModal("editProfile");
};
// Close any modal
const handleCloseModal = () => {
setActiveModal(null);
};
// Render authenticated profile view
const renderAuthenticatedProfile = () => {
const menuItems = [
// { icon: ,
text: t("profile.delivery"),
path: "/delivery-and-payment",
},
{ icon: