"use client"; import { useState, useEffect } from 'react'; import { useRouter } from '@/i18n/navigation'; import { useTranslations } from 'next-intl'; import { ArrowLeft, ChevronRight, LogOut, Settings as SettingsIcon } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { AppearanceSettings } from '@/components/settings/appearance-settings'; import { EmailSettings } from '@/components/settings/email-settings'; import { AccountSettings } from '@/components/settings/account-settings'; import { IdentitySettings } from '@/components/settings/identity-settings'; import { VacationSettings } from '@/components/settings/vacation-settings'; import { CalendarSettings } from '@/components/settings/calendar-settings'; import { FilterSettings } from '@/components/settings/filter-settings'; import { TemplateSettings } from '@/components/settings/template-settings'; import { AdvancedSettings } from '@/components/settings/advanced-settings'; import { FolderSettings } from '@/components/settings/folder-settings'; import { KeywordSettings } from '@/components/settings/keyword-settings'; import { AccountSecuritySettings } from '@/components/settings/account-security-settings'; import { useAuthStore } from '@/stores/auth-store'; import { useEmailStore } from '@/stores/email-store'; import { useIsDesktop } from '@/hooks/use-media-query'; import { NavigationRail } from '@/components/layout/navigation-rail'; import { useConfig } from '@/hooks/use-config'; import { cn } from '@/lib/utils'; type Tab = 'appearance' | 'email' | 'account' | 'security' | 'identities' | 'vacation' | 'calendar' | 'filters' | 'templates' | 'folders' | 'keywords' | 'advanced'; export default function SettingsPage() { const router = useRouter(); const t = useTranslations('settings'); const tSidebar = useTranslations('sidebar'); const { client, isAuthenticated, logout } = useAuthStore(); const { quota, isPushConnected } = useEmailStore(); const { stalwartFeaturesEnabled } = useConfig(); const [activeTab, setActiveTab] = useState('appearance'); const [mobileShowContent, setMobileShowContent] = useState(false); const isDesktop = useIsDesktop(); useEffect(() => { if (!isAuthenticated) { try { sessionStorage.setItem('redirect_after_login', window.location.pathname); } catch { /* ignore */ } router.push('/login'); } }, [isAuthenticated, router]); if (!isAuthenticated) { return null; } const supportsVacation = client?.supportsVacationResponse() ?? false; const supportsCalendar = client?.supportsCalendars() ?? false; const supportsSieve = client?.supportsSieve() ?? false; const tabs: { id: Tab; label: string }[] = [ { id: 'appearance', label: t('tabs.appearance') }, { id: 'email', label: t('tabs.email') }, { id: 'account', label: t('tabs.account') }, ...(stalwartFeaturesEnabled ? [{ id: 'security' as Tab, label: t('tabs.security') }] : []), { id: 'identities', label: t('tabs.identities') }, ...(supportsVacation ? [{ id: 'vacation' as Tab, label: t('tabs.vacation') }] : []), ...(supportsCalendar ? [{ id: 'calendar' as Tab, label: t('tabs.calendar') }] : []), ...(supportsSieve ? [{ id: 'filters' as Tab, label: t('tabs.filters') }] : []), { id: 'templates', label: t('tabs.templates') }, { id: 'folders', label: t('tabs.folders') }, { id: 'keywords', label: t('tabs.keywords') }, { id: 'advanced', label: t('tabs.advanced') }, ]; const handleTabSelect = (tabId: Tab) => { setActiveTab(tabId); if (!isDesktop) { setMobileShowContent(true); } }; const activeTabLabel = tabs.find((tab) => tab.id === activeTab)?.label ?? ''; const renderTabContent = () => ( <> {activeTab === 'appearance' && } {activeTab === 'email' && } {activeTab === 'account' && } {activeTab === 'security' && } {activeTab === 'identities' && } {activeTab === 'vacation' && } {activeTab === 'calendar' && } {activeTab === 'filters' && } {activeTab === 'templates' && } {activeTab === 'folders' && } {activeTab === 'keywords' && } {activeTab === 'advanced' && } ); // Mobile layout if (!isDesktop) { // Mobile: show content view if (mobileShowContent) { return (
{/* Mobile content header */}

{activeTabLabel}

{/* Content */}
{renderTabContent()}
{/* Bottom Navigation */}
); } // Mobile: show tab list return (
{/* Mobile header */}

{t('title')}

{/* Tab list */}
{tabs.map((tab) => ( ))}
{/* Logout */}
{/* Bottom Navigation */}
); } // Desktop layout return (
{/* Navigation Rail */}
{ logout(); router.push('/login'); }} />
{/* Settings Sidebar */}
{/* Header */}
{/* Tabs */}
{tabs.map((tab) => ( ))}
{/* Settings Content */}
{/* Page Header */}

{t('title')}

{/* Active Tab Content */}
{renderTabContent()}
); }