"use client"; import { useState } from 'react'; import { useTranslations } from 'next-intl'; import { useSettingsStore } from '@/stores/settings-store'; import type { ReplyIdentityMatch, SendDelaySeconds } from '@/stores/settings-store'; import { useAuthStore } from '@/stores/auth-store'; import { SettingsSection, SettingItem, Select, ToggleSwitch } from './settings-section'; import { X } from '@/components/icons'; import { SUPPORTED_SUB_ADDRESS_DELIMITERS, isSupportedSubAddressDelimiter, isValidSubAddressDelimiter, } from '@/lib/sub-addressing'; const CUSTOM_DELIMITER_SENTINEL = '__custom__'; const DEFAULT_CUSTOM_DELIMITER = '~'; export function ComposingSettings() { const t = useTranslations('settings.email_behavior'); const [newKeyword, setNewKeyword] = useState(''); const { autoSelectReplyIdentity, replyIdentityMatch, plainTextMode, rtlEditingSupport, attachmentReminderEnabled, attachmentReminderKeywords, emptySubjectWarningEnabled, recipientMentionsEnabled, sendDelaySeconds, subAddressDelimiter, signaturePosition, signatureSeparatorEnabled, requestReadReceiptDefault, readReceiptResponse, updateSetting, } = useSettingsStore(); const { client } = useAuthStore(); const delayedSendSupported = client?.hasDelayedSend() ?? false; return ( updateSetting('autoSelectReplyIdentity', checked)} /> {autoSelectReplyIdentity && ( updateSetting('sendDelaySeconds', Number(value) as SendDelaySeconds)} options={[ { value: '0', label: t('send_delay.off') }, { value: '10', label: t('send_delay.seconds', { seconds: 10 }) }, { value: '30', label: t('send_delay.seconds', { seconds: 30 }) }, { value: '60', label: t('send_delay.seconds', { seconds: 60 }) }, ]} /> {sendDelaySeconds > 0 && !delayedSendSupported && (

{t('send_delay.unsupported')}

)}
updateSetting('readReceiptResponse', value as 'ask' | 'always' | 'never')} options={[ { value: 'ask', label: t('read_receipt_response.ask') }, { value: 'always', label: t('read_receipt_response.always') }, { value: 'never', label: t('read_receipt_response.never') }, ]} />
{ const next = e.target.value.slice(0, 1); if (next && isValidSubAddressDelimiter(next)) { updateSetting('subAddressDelimiter', next); } }} aria-label={t('sub_address_delimiter.custom_input_label')} placeholder={DEFAULT_CUSTOM_DELIMITER} className="w-16 px-2 py-1 text-sm font-mono text-center bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-ring" /> )}
updateSetting('emptySubjectWarningEnabled', checked)} /> updateSetting('recipientMentionsEnabled', checked)} /> updateSetting('attachmentReminderEnabled', checked)} /> {attachmentReminderEnabled && (

{t('attachment_reminder.keywords_description')}

{attachmentReminderKeywords.map((kw) => ( {kw} ))}
{ e.preventDefault(); const trimmed = newKeyword.trim().toLowerCase(); if (trimmed && !attachmentReminderKeywords.includes(trimmed)) { updateSetting('attachmentReminderKeywords', [...attachmentReminderKeywords, trimmed]); } setNewKeyword(''); }} > setNewKeyword(e.target.value)} placeholder={t('attachment_reminder.add_placeholder')} className="flex-1 min-w-0 px-2 py-1 text-sm bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-ring" />
)}
); }