import React from "react";
import classNames from "classnames";
import { makeStyles } from "@material-ui/core/styles";

import Header from "components/Header/Header.js";
import HeaderLinks from "components/Header/HeaderLinks.js";
import Footer from "components/Footer/Footer.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,
  maxi,
  matic,
  naked,
  sport,
  offroad,
  moped,
  monsterenergy,
  cbu,
  ...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={classNames(classes.main, classes.mainRaised)}>
        <DataProduct
          maxi={maxi}
          matic={matic}
          naked={naked}
          sport={sport}
          offroad={offroad}
          moped={moped}
          monsterenergy={monsterenergy}
          cbu={cbu}
          backend={backend}
        />
      </div>
      <Footer />
    </div>
  );
};

export default Product;

export async function getServerSideProps(context) {
  var maxi = [];
  var matic = [];
  var naked = [];
  var sport = [];
  var offroad = [];
  var moped = [];
  var monsterenergy = [];
  var cbu = [];
  const backend = process.env.BACKEND_SERVER_URI;

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

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

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

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

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

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

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

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

  console.log(cbu);

  return {
    props: {
      maxi,
      matic,
      naked,
      sport,
      offroad,
      moped,
      monsterenergy,
      cbu,
      backend,
    }, // will be passed to the page component as props
  };
}
