'use client'; import type { CaptchaProvider, VerificationConfigDashboard } from '@nexumi/shared'; import { FieldAnchor } from '@/components/layout/field-anchor'; import { useTranslations } from '@/components/locale-provider'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { DiscordChannelSelect } from '@/components/ui/discord-channel-select'; import { DiscordRoleSelect } from '@/components/ui/discord-role-select'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Switch } from '@/components/ui/switch'; import type { SettingsSaveResult } from '@/components/settings/settings-form'; import { SettingsForm } from '@/components/settings/settings-form'; async function saveVerification(guildId: string, value: VerificationConfigDashboard): Promise { try { const response = await fetch(`/api/guilds/${guildId}/verification`, { 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 VerificationFormProps { guildId: string; initialValue: VerificationConfigDashboard; availableCaptchaProviders: CaptchaProvider[]; } export function VerificationForm({ guildId, initialValue, availableCaptchaProviders }: VerificationFormProps) { const t = useTranslations(); return ( initialValue={initialValue} onSave={(value) => saveVerification(guildId, value)} > {({ value, setValue }) => (
{t('modulePages.verification.title')} {t('modulePages.verification.description')}
setValue((prev) => ({ ...prev, enabled: checked }))} />
{value.mode === 'CAPTCHA' ? (

{t('modulePages.verification.captchaProviderHint')}

) : null}
setValue((prev) => ({ ...prev, channelId }))} />
setValue((prev) => ({ ...prev, verifiedRoleId }))} />
setValue((prev) => ({ ...prev, unverifiedRoleId })) } />
setValue((prev) => ({ ...prev, minAccountAgeDays: Number(event.target.value) || 0 })) } />
{t('modulePages.verification.altTitle')} {t('modulePages.verification.altDescription')}
setValue((prev) => ({ ...prev, altDetectionEnabled: checked })) } />

{t('modulePages.verification.altBlockOnMatchHint')}

setValue((prev) => ({ ...prev, altBlockOnMatch: checked })) } disabled={!value.altDetectionEnabled} />
setValue((prev) => ({ ...prev, altIpWindowDays: Number(event.target.value) || 1 })) } />
setValue((prev) => ({ ...prev, altInviteWindowHours: Number(event.target.value) || 1 })) } />
setValue((prev) => ({ ...prev, altMaxAccountsPerInvite: Number(event.target.value) || 1 })) } />
)} ); }