'use client' import { useState } from 'react' import { useTranslations } from 'next-intl' import { useRouter } from '@/i18n/navigation' export function TopicModBar({ topicId, locked, sticky, deleted = false, moveForums = [], }: { topicId: number locked: boolean sticky: boolean deleted?: boolean moveForums?: { id: number; name: string }[] }) { const t = useTranslations('Forum') const router = useRouter() const [busy, setBusy] = useState(false) async function act(action: string, extra?: Record, confirmMsg?: string) { if (busy) return if (confirmMsg && !confirm(confirmMsg)) return setBusy(true) try { const res = await fetch('/api/forum/moderate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin', body: JSON.stringify({ topicId, action, ...extra }), }) const data: { success?: boolean; forumId?: number } = await res.json() if (data.success && action === 'delete' && data.forumId) { router.push(`/forum/${data.forumId}`) } else if (data.success && action === 'move') { router.push(`/forum/${extra?.forumId}`) } else { router.refresh() } } finally { setBusy(false) } } if (deleted) { return (
{t('deletedMark')}{' '}
) } return (
{t('moderation')}:{' '} {' '} {' '} {moveForums.length > 0 && ( )}{' '}
) }