import { useTranslation } from 'react-i18next';
import type { HeaderExportState, Page } from './Header';
import { PAGE_PATHS } from './Header';
import type { AuthUser } from '../../hooks/useAuth';
import { changeLanguage as changeAppLanguage, SUPPORTED_LANGUAGES } from '../../i18n';
import { DownloadIcon } from './icons/DownloadIcon';
import { BookmarkIcon } from './icons/BookmarkIcon';
import { CheckIcon } from './icons/CheckIcon';
import { ClipboardIcon } from './icons/ClipboardIcon';
import { CloseIcon } from './icons/CloseIcon';
import { SunIcon } from './icons/SunIcon';
import { MoonIcon } from './icons/MoonIcon';
import { SpinnerIcon } from './icons/SpinnerIcon';
interface MobileMenuProps {
activePage: Page;
activeHash: string;
onPageChange: (page: Page, hash?: string) => void;
theme: 'light' | 'dark';
onToggleTheme: () => void;
exportState: HeaderExportState | null;
onSaveSearch: (() => void) | null;
savingSearch: boolean;
isEditingSearch: boolean;
user: AuthUser | null;
onLoginClick: () => void;
onRegisterClick: () => void;
onLogout: () => void;
onClose: () => void;
onShare: () => void;
copied: boolean;
sharing: boolean;
}
export default function MobileMenu({
activePage,
activeHash,
onPageChange,
theme,
onToggleTheme,
exportState,
onSaveSearch,
savingSearch,
isEditingSearch,
user,
onLoginClick,
onRegisterClick,
onLogout,
onClose,
onShare,
copied,
sharing,
}: MobileMenuProps) {
const { t, i18n } = useTranslation();
const emailParts = user?.email.split('@');
const emailLocal = emailParts?.[0] ?? '';
const emailDomain = emailParts && emailParts.length > 1 ? emailParts.slice(1).join('@') : '';
const mobileNavItem = (page: Page, label: string, hash?: string) => {
const isActive =
activePage === page &&
(hash ? activeHash === hash : page !== 'account' || activeHash !== 'invites');
const href = hash ? `${PAGE_PATHS[page]}#${hash}` : PAGE_PATHS[page];
return (
{
if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;
e.preventDefault();
onPageChange(page, hash);
onClose();
}}
>
{label}
);
};
const dashboardActionClass =
'w-full flex cursor-pointer items-center justify-center gap-2 px-3 py-2 rounded bg-navy-800 text-sm font-semibold text-white border border-navy-700 shadow-sm hover:bg-navy-700 disabled:opacity-50 transition-colors';
const dashboardSavedItem = user && (
{
if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;
e.preventDefault();
onPageChange('saved');
onClose();
}}
>
{t('header.saved')}
);
const dashboardActions = activePage === 'dashboard' && (
{exportState && (
)}
{onSaveSearch && (
)}
{dashboardSavedItem}
);
return (
<>
{/* Backdrop */}
{/* Menu panel */}
{t('mobileMenu.menu')}
{dashboardActions}
{/* Theme toggle + Auth section at bottom */}
{/* Theme toggle */}
{/* Language selector */}
{SUPPORTED_LANGUAGES.map((lang) => (
))}
{/* Auth buttons */}
{user ? (
{emailDomain ? (
<>
{emailLocal}
{emailDomain}
>
) : (
user.email
)}
) : (
)}
>
);
}