import React, { useState, useCallback } from 'react'
import Breadcrumbs from '../../components/forum/Breadcrumbs'
import PostCard from '../../components/forum/PostCard'
import ReplyForm from '../../components/forum/ReplyForm'
import Pagination from '../../components/forum/Pagination'
import SeoHead from '../../components/seo/SeoHead'
export default function ForumThread({
thread,
category,
forumCategory,
author,
opPost,
posts = [],
pagination = {},
replyCount = 0,
sort = 'asc',
quotedPost = null,
replyPrefill = '',
isAuthenticated = false,
canModerate = false,
csrfToken = '',
status = null,
captcha = {},
seo = {},
}) {
const [currentSort, setCurrentSort] = useState(sort)
const breadcrumbs = [
{ label: 'Home', href: '/' },
{ label: 'Forum', href: '/forum' },
...(forumCategory?.name ? [{ label: forumCategory.name }] : []),
{ label: category?.name ?? 'Board', href: category?.slug ? `/forum/${category.slug}` : '/forum' },
{ label: thread?.title ?? 'Thread' },
]
const handleSortToggle = useCallback(() => {
const newSort = currentSort === 'asc' ? 'desc' : 'asc'
setCurrentSort(newSort)
const url = new URL(window.location.href)
url.searchParams.set('sort', newSort)
window.location.href = url.toString()
}, [currentSort])
return (
<>
{thread.description}
) : null}{number(replyCount)} {replyCount === 1 ? 'reply' : 'replies'}