import React from "react";
// nodejs library that concatenates classes
import classNames from "classnames";
// react components for routing our app without refresh
import Link from "next/link";
// @material-ui/core components
import { makeStyles } from "@material-ui/core/styles";
// @material-ui/icons
// core components
import Header from "components/Header/Header.js";
import HeaderLinks from "components/Header/HeaderLinks.js";
import Footer from "components/Footer/Footer.js";
import GridContainer from "components/Grid/GridContainer.js";
import GridItem from "components/Grid/GridItem.js";
import DataProduct from "pages-sections/product/product.js";
import Parallax from "components/Parallax/Parallax.js";
import styles from "assets/jss/nextjs-material-kit/pages/components.js";

import Getproduct from "../api/product/product.js";

const useStyles = makeStyles(styles);

const Product = function ({
  backend,
  yamaha,
  suzuki,
  honda,
  hino,
  mercedes,
  bpr,
  emilia,
  homes,
  ...props
}) {
  const classes = useStyles();
  const { ...rest } = props;
  return (
    <div>
      <Header
        rightLinks={<HeaderLinks />}
        fixed
        color="info"
        changeColorOnScroll={{
          height: 400,
          color: "white",
        }}
        {...rest}
      />
      <Parallax image={require("assets/img/Promotion_2-1.jpg")} width="200px">
        <div className={classes.container}>
          <GridContainer>
            <GridItem>
              {/* <div className={classes.brand}>
                <h1 className={classes.title}>NextJS Material Kit.</h1>
                <h3 className={classes.subtitle}>
                  A Badass Material Kit based on Material-UI and NextJS.
                </h3>
              </div> */}
            </GridItem>
          </GridContainer>
        </div>
      </Parallax>
      <div className={classNames(classes.main, classes.mainRaised)}>
        <DataProduct
          yamaha={yamaha}
          suzuki={suzuki}
          honda={honda}
          hino={hino}
          mercedes={mercedes}
          bpr={bpr}
          emilia={emilia}
          homes={homes}
          backend={backend}
        />
      </div>
      <Footer />
    </div>
  );
};

export default Product;

export async function getServerSideProps(context) {
  var yamaha = [];
  var suzuki = [];
  var honda = [];
  var hino = [];
  var mercedes = [];
  var bpr = [];
  var emilia = [];
  var homes = [];
  const backend = process.env.BACKEND_SERVER_URI;

  var res = await Getproduct.GetProductYamaha();
  if (res["STATUS"] === 1) {
    yamaha = res["DATA"]["products"];
  }

  var res = await Getproduct.GetProductSuzuki();
  if (res["STATUS"] === 1) {
    suzuki = res["DATA"]["products"];
  }

  var res = await Getproduct.GetProductHonda();
  if (res["STATUS"] === 1) {
    honda = res["DATA"]["products"];
  }

  var res = await Getproduct.GetProductHino();
  if (res["STATUS"] === 1) {
    hino = res["DATA"]["products"];
  }

  var res = await Getproduct.GetProductMercedes();
  if (res["STATUS"] === 1) {
    mercedes = res["DATA"]["products"];
  }

  var res = await Getproduct.GetProductBPR();
  if (res["STATUS"] === 1) {
    bpr = res["DATA"]["products"];
  }

  var res = await Getproduct.GetProductEmilia();
  if (res["STATUS"] === 1) {
    emilia = res["DATA"]["products"];
  }

  var res = await Getproduct.GetProductHomes();
  if (res["STATUS"] === 1) {
    homes = res["DATA"]["products"];
  }

  return {
    props: {
      yamaha,
      suzuki,
      honda,
      hino,
      mercedes,
      bpr,
      emilia,
      homes,
      backend,
    }, // will be passed to the page component as props
  };
}
