import PreviewBlocks from '@/components/PreviewBlocks'
import { getCurrentUser } from '@/lib/payload'
import { COLLECTION_SLUG_POST } from '@payload/collections/config'
import { getDocument } from '@/utils/getDocument'
import { unstable_noStore as noStore } from 'next/cache'
import { notFound } from 'next/navigation'
import PreviewPostPage from '@/components/PreviewPostPage'

const PreviewCatchAllPage = async ({ params }: { params: { path: string[] } }) => {
  noStore()
  const [page] = await Promise.all([
    getDocument({
      collection: COLLECTION_SLUG_POST,
      path: params.path,
      depth: 3,
      cache: false,
    }),
  ])
  if (!page) notFound()

  return <PreviewPostPage initialData={page} locale="" url={process.env.BASE_URL || ''} />
}

export default PreviewCatchAllPage
