import MarkdocRenderer from '@/components/Markdoc/Renderer'
import { AWQLayout } from '@/layouts/AWQLayout'
import {
  collectAWQContent,
  getContentByPath,
} from '@/lib/content/awq/collector'
import { notFound } from 'next/navigation'

export async function generateStaticParams() {
  const allContent = await collectAWQContent()

  return allContent.map((item) => ({
    slug: item.fullPath.split('/'),
  }))
}

export default async function Page({ params }: { params: { slug: string[] } }) {
  const { slug } = await params
  const breadcrumbs = ['awq', ...slug]
  const path = slug.join('/')
  const article = await getContentByPath(path)

  if (!article) {
    notFound()
  }

  return (
    <AWQLayout article={article} breadcrumbs={breadcrumbs}>
      <MarkdocRenderer content={article.content} className="awq-content" />
    </AWQLayout>
  )
}
