import { Box } from '@mui/system';
import Head from 'next/head';
import CompanyInfo from '../components/company-info/CompanyInfo';
import Features from '../components/features/Features';
import Hero from '../components/hero/Hero';
import FeaturedProductsList from '../components/products/featured-products-list/FeaturedPorductsList';
import { getFeaturedProducts } from '../requests/products/featuredProductsRequest';

const Home = (props) => {
  return (
    <>
      <Box sx={{ width: '100%', height: '100%' }}>
        <Head>
          <title>NextJS template</title>
          <meta name="description" content="Random data with pagination..." />
        </Head>
        <Hero></Hero>
        <FeaturedProductsList
          featuredProducts={props.featuredProducts}
        ></FeaturedProductsList>
        <Features></Features>
        <CompanyInfo></CompanyInfo>
      </Box>
    </>
  );
};

export async function getStaticProps() {
  try {
    const { message, featuredProducts } = await getFeaturedProducts();
    return {
      props: {
        message,
        featuredProducts,
      },
    };
  } catch (error) {
    return {
      props: {
        errorMessage: error,
        featuredProducts: [],
      },
    };
  }
}

export default Home;
