import type { GetStaticProps, InferGetStaticPropsType } from 'next'

import { getGlobalFields } from '@/lib/api/globals'
import { getMaterialsPage } from '@/lib/api/materials'

import MaterialTemplate from '@/components/templates/Material'

export default function MaterialsAndFinishes({ page, menu }: InferGetStaticPropsType<typeof getStaticProps>) {
  return <MaterialTemplate page={page} menu={menu} />
}

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

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