'use client'; import type { AutomodConfigDashboard } from '@nexumi/shared'; import { useTranslations } from '@/components/locale-provider'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Switch } from '@/components/ui/switch'; import type { SettingsSaveResult } from '@/components/settings/settings-form'; import { SettingsForm } from '@/components/settings/settings-form'; async function saveAutomod(guildId: string, value: AutomodConfigDashboard): Promise { try { const response = await fetch(`/api/guilds/${guildId}/automod`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(value) }); if (!response.ok) { const body = (await response.json().catch(() => null)) as { error?: string } | null; return { ok: false, error: body?.error ?? `Request failed with status ${response.status}` }; } return { ok: true }; } catch { return { ok: false, error: 'Network error' }; } } interface AutomodFormProps { guildId: string; initialValue: AutomodConfigDashboard; } export function AutomodForm({ guildId, initialValue }: AutomodFormProps) { const t = useTranslations(); return ( initialValue={initialValue} onSave={(value) => saveAutomod(guildId, value)}> {({ value, setValue }) => (
{t('modulePages.automod.title')} {t('modulePages.automod.description')}

{t('modulePages.automod.enabledHint')}

setValue((prev) => ({ ...prev, enabled: checked }))} />
{t('modulePages.automod.antiRaidTitle')} {t('modulePages.automod.antiRaidDescription')}
setValue((prev) => ({ ...prev, antiRaidEnabled: checked }))} />
setValue((prev) => ({ ...prev, antiRaidJoinThreshold: Number(event.target.value) || 1 })) } />
setValue((prev) => ({ ...prev, antiRaidWindowSeconds: Number(event.target.value) || 1 })) } />

{t('modulePages.automod.antiRaidActionHint')}

{t('modulePages.automod.antiNukeTitle')} {t('modulePages.automod.antiNukeDescription')}
setValue((prev) => ({ ...prev, antiNukeEnabled: checked }))} />
setValue((prev) => ({ ...prev, antiNukeBanThreshold: Number(event.target.value) || 1 })) } />
setValue((prev) => ({ ...prev, antiNukeChannelThreshold: Number(event.target.value) || 1 })) } />
setValue((prev) => ({ ...prev, antiNukeWindowSeconds: Number(event.target.value) || 1 })) } />

{t('modulePages.automod.lockdownActiveHint')}

setValue((prev) => ({ ...prev, lockdownActive: checked }))} />
)} ); }