"use client";
import { useMemo } from 'react';
import { useTranslations } from 'next-intl';
import { Check, Folder } from '@/components/icons';
import { useSettingsStore, type ToolbarPosition, type MailLayout, type InterfaceLayout } from '@/stores/settings-store';
import { SettingsSection, SettingItem, RadioGroup, ToggleSwitch } from './settings-section';
import { cn } from '@/lib/utils';
import { usePolicyStore } from '@/stores/policy-store';
import { useAccountStore } from '@/stores/account-store';
import { useEmailStore } from '@/stores/email-store';
import { hiddenSharedMailIds, setSharedMailAccountHidden } from '@/lib/shared-mail-visibility';
const MAIL_LAYOUT_PREVIEW_ROWS = [
{ sender: 'Alice', subject: 'Quarterly roadmap', preview: 'The draft is ready for review.', selected: false },
{ sender: 'Nadia', subject: 'Design sync', preview: 'Pushed updated mocks and notes.', selected: true },
{ sender: 'Billing', subject: 'Invoice 1042', preview: 'Your receipt is attached.', selected: false },
];
const MAIL_LAYOUT_PREVIEW_ROWS_FOCUS = [
...MAIL_LAYOUT_PREVIEW_ROWS,
{ sender: 'Sam', subject: 'Lunch?', preview: '', selected: false },
{ sender: 'Newsletter', subject: 'Weekly digest', preview: '', selected: false },
];
function MailLayoutPreview({
value,
t,
}: {
value: MailLayout;
t: (key: string) => string;
}) {
return (
{t(`mail_layout.${value}`)}
{t(`mail_layout.${value}_description`)}
{value === 'split' && (
<>
{MAIL_LAYOUT_PREVIEW_ROWS.map((row) => (
{row.sender}
{row.subject}
))}
>
)}
{value === 'focus' && (
{MAIL_LAYOUT_PREVIEW_ROWS_FOCUS.map((row) => (
{row.sender}{row.subject}
))}
)}
{value === 'horizontal' && (
{MAIL_LAYOUT_PREVIEW_ROWS.map((row) => (
{row.sender}{row.subject}
))}
)}
);
}
/**
* The Appearance page's Layout section: where the interface, the reading
* pane and the toolbars sit.
*/
export function LayoutSection() {
const t = useTranslations('settings.appearance');
const tEmail = useTranslations('settings.email_behavior');
const { toolbarPosition, showToolbarLabels, mailLayout, interfaceLayout, updateSetting } = useSettingsStore();
const { isSettingLocked, isSettingHidden } = usePolicyStore();
const mountainView = interfaceLayout === 'mountain-view';
return (
{/* The interface layout decides where search, navigation and toolbars
go - a layout choice, so it leads the section. */}
{!isSettingHidden('interfaceLayout') && (
updateSetting('interfaceLayout', value as InterfaceLayout)}
options={[
{ value: 'default', label: t('interface_layout.default') },
{ value: 'mountain-view', label: t('interface_layout.mountain_view') },
]}
/>
)}
{/* Mountain View always shows the list and then the conversation, and
its toolbars are icon-only, so these two would change nothing there.
Their saved values stay and apply again under the default layout. */}
{!isSettingHidden('mailLayout') && !mountainView && (