import { BgColorsOutlined, HomeOutlined, LoginOutlined, LogoutOutlined, MenuOutlined, TranslationOutlined, } from "@ant-design/icons"; import { logoutThunk } from "features/auth/authSlice"; import { setLocale, setLocalesThunk } from "features/locale/localeSlice"; 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: "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()); }, }] : []), ]; return { menuItems }; }