import type { GetStaticProps, InferGetStaticPropsType } from 'next'

import { getGlobalFields } from '@/lib/api/globals'
import { getContactPage } from '@/lib/api/contact'
import { getGeneralInquiryForm } from '@/lib/api/general-inquiry-form'

import ContactTemplate from '@/components/templates/Contact'

export default function Contact({ page, menu, form }: InferGetStaticPropsType<typeof getStaticProps>) {
  return <ContactTemplate page={page} menu={menu} form={form} />
}

export const getStaticProps: GetStaticProps = async ({ preview = false }) => {
  const { globals } = await getGlobalFields(preview)
  const { page, menu } = await getContactPage('contact')

  const {
    contactPageContent: { associatedFormId },
  } = page

  const form = await getGeneralInquiryForm(associatedFormId)

  return {
    props: {
      globals,
      page,
      menu,
      form,
    },
    revalidate: 10, // In seconds
  }
}
