import { getPayload } from 'payload'
import configPromise from '@payload-config'
import { Media, News } from '@/payload-types'
import { ContactSectionForm } from '@/globals/ContactForm/Component'
import { BlogContent } from '@/components/pages/Blog/BlogContent'
import { getCurrentLocale } from '@/locales/server'

export default async function BlogPage() {
  const payload = await getPayload({ config: configPromise })
  const locale = await getCurrentLocale()

  const { bg, title } = await payload.findGlobal({
    slug: 'blog',
    depth: 1,
    locale,
  })

  const result = await payload.find({
    collection: 'news',
    limit: 1000,
    pagination: false,
    depth: 2,
  })

  const docs = result.docs as News[]

  return (
    <>
      <BlogContent bg={bg as Media} title={title} news={docs} />
      <ContactSectionForm />
    </>
  )
}
