import React, { useState } from 'react'; import { usePluginLogs } from '../../../application/state/usePluginLogs'; import { useI18n } from '../../../application/i18n/I18nProvider'; import { Button } from '../../ui/button'; import { ConfirmDialog } from '../../ui/confirm-dialog'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '../../ui/dialog'; import { SettingRow, Toggle } from '../settings-ui'; /** Host settings row; detailed controls stay inside the standard host dialog. */ export function PluginLogSettings() { const { t, resolvedLocale } = useI18n(); const zh = resolvedLocale.startsWith('zh'); const { status, error, busy, run } = usePluginLogs(); const [open, setOpen] = useState(false); const [confirmVerbose, setConfirmVerbose] = useState(false); const title = zh ? '本地插件日志' : 'Local plugin logs'; const saveLabel = zh ? '将宿主审计日志保存到本地' : 'Save host audit logs locally'; const verboseLabel = zh ? '包含插件详细诊断文字' : 'Include verbose plugin text'; const disclosure = zh ? '插件编写的日志文字可能包含敏感数据。截断和字段过滤不能保证任意文字安全。只为排查问题临时开启,导出前请检查。重启应用后自动关闭详细日志。' : 'Plugin-authored text may contain sensitive data. Truncation and field filtering cannot make arbitrary text safe. Enable temporarily for troubleshooting and review files before sharing. Verbose diagnostics turn off after app restart.'; return
{status ? (status.saveToDisk ? t('common.enabled') : t('common.disabled')) : error ? (zh ? '不可用' : 'Unavailable') : (zh ? '载入中' : 'Loading')}
{title} {zh ? '默认不保存。仅保存在此设备,不上传或同步。权限面板中的有限安全历史独立保留。' : 'Saving is off by default. Files stay on this device with no upload or sync. The bounded security history in plugin permissions is separate.'} {error &&

{error}

}
void run('configure', { saveToDisk, verbose: false })} /> verbose ? setConfirmVerbose(true) : void run('configure', { saveToDisk: true, verbose: false })} />
{status &&

{zh ? `最多 ${status.maxBytes / 1048576} MiB,最长保留 ${status.retentionDays} 天。丢弃 ${status.droppedRecords} 条,写入错误 ${status.writeErrors} 次。` : `Up to ${status.maxBytes / 1048576} MiB, up to ${status.retentionDays} days. Dropped: ${status.droppedRecords}. Write errors: ${status.writeErrors}.`}

}
{ setConfirmVerbose(false); void run('configure', { saveToDisk: true, verbose: true }); }} />
; }