import { BgColorsOutlined, GlobalOutlined, LogoutOutlined, } from "@ant-design/icons"; import BranchesIcon from "components/Icons/BranchesIcon"; import LoginIcon from "components/Icons/LoginIcon"; import LoyaltyAndRewardIcon from "components/Icons/LoyaltyAndRewardIcon"; import MyOrderIcon from "components/Icons/MyOrderIcon"; import { logoutThunk } from "features/auth/authSlice"; import { setLocale, setLocalesThunk } from "features/locale/localeSlice"; import { clearCart } from "features/order/orderSlice"; import { toggleTheme } from "features/theme/themeSlice"; import i18n from "i18n/i18n"; import { useTranslation } from "react-i18next"; import { Link, useNavigate, useParams } from "react-router-dom"; import { useAppDispatch, useAppSelector } from "redux/hooks"; import { ACCESS_TOKEN } from "utils/constants"; export default function useHeaderMenu() { const { subdomain } = useParams(); const dispatch = useAppDispatch(); const { t } = useTranslation(); const { isRTL } = useAppSelector((state) => state.locale); const { themeName } = useAppSelector((state) => state.theme); const navigate = useNavigate(); const token = localStorage.getItem(ACCESS_TOKEN); const menuItems = [ { key: "language", icon: ( ), label:
{isRTL ? t("common.arabic") : t("common.english")}
, onClick: () => { const key = isRTL ? "en" : "ar"; dispatch(setLocale(key)); dispatch(setLocalesThunk(key)); i18n.changeLanguage(key); }, }, { key: "theme", icon: ( ), label: (
{themeName === "light" ? t("common.dark") : t("common.light")}
), onClick: () => { dispatch(toggleTheme()); }, }, { key: "orders", icon: , label: {t("common.myOrder")}, onClick: () => { navigate(`/${subdomain}/orders`); }, }, { key: "rewardsAndLoyalty", icon: , label: ( {t("common.rewardsAndLoyalty")} ), onClick: () => { navigate(`/${subdomain}/rewards-and-loyalty`); }, }, { key: "branches", icon: , label: {t("common.branches")}, }, ...(!token ? [ { key: "login", icon: , label: {t("common.login")}, onClick: () => { navigate(`/${subdomain}/login`); }, }, ] : []), ...(token ? [ { key: "logout", icon: ( ), label:
{t("common.logout")}
, onClick: () => { dispatch(logoutThunk()); dispatch(clearCart()); }, }, ] : []), ]; return { menuItems }; }