'use client' import { useState } from 'react' import { useTranslations } from 'next-intl' import { useRouter } from '@/i18n/navigation' export function ReplyForm({ topicId }: { topicId: number }) { const t = useTranslations('Forum') const router = useRouter() const [text, setText] = useState('') const [busy, setBusy] = useState(false) const [error, setError] = useState(null) async function handleSubmit(e: React.FormEvent) { e.preventDefault() if (busy || !text.trim()) return setBusy(true) setError(null) try { const res = await fetch('/api/forum/reply', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin', body: JSON.stringify({ topicId, text }), }) const data: { success?: boolean } = await res.json() if (data.success) { setText('') router.refresh() } else { setError(t('genericError')) } } catch { setError(t('genericError')) } finally { setBusy(false) } } const field = 'w-full rounded border border-amber-900/60 bg-[#2c1e14] px-3 py-2' return (