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 Parallax from "components/Parallax/Parallax.js";
import styles from "assets/jss/nextjs-material-kit/pages/components.js";
import Button from "components/CustomButtons/Button.js";

import GetbusinessPartners from "../api/home/businessPartner.js";
import Getservices from "../api/home/service.js";
import Getcarousels from "../api/home/carousel.js";

import DataSnackbarContent from "../pages-sections/snackbar.js";
import DataCarousel from "../pages-sections/home/carousel.js";
import DataService from "../pages-sections/home/service.js";
import DataBusinessPartner from "../pages-sections/home/business_partner.js";
import CoreValue from "../pages-sections/home/core_value.js";

const useStyles = makeStyles(styles);
const Home = function ({
  backend,
  businessPartners,
  service,
  carousel,
  ...props
}) {
  const classes = useStyles();
  const { ...rest } = props;
  <DataService service={props.service} />;

  return (
    <div>
      <Header
        rightLinks={<HeaderLinks />}
        fixed
        color="info"
        changeColorOnScroll={{
          height: 400,
          color: "white",
        }}
        {...rest}
      />
      <Parallax
        image={require("assets/img/welcome.png")}
        styles={{ marginTop: "50px" }}
      >
        <div className={classes.container}>
          <GridContainer>
            {/* <GridItem>
              <div className={classes.brand} align="center">
                <h1 className={classes.title}>Thamrin Group</h1>
                <h3 className={classes.subtitle}>
                  A Badass Material Kit based on Material-UI and NextJS.
                </h3>
              </div>
            <Button
              href="/login"
              className={classes.registerNavLink}
              color="info"
              box
            >
              Shop Now
            </Button>
            </GridItem> */}
          </GridContainer>
        </div>
      </Parallax>
      <div className={classNames(classes.main, classes.mainRaised)}>
        <DataSnackbarContent />
        <CoreValue />
        <DataCarousel carousel={carousel} backend={backend} />
        <DataService service={service} backend={backend} />
        <DataBusinessPartner
          businessPartners={businessPartners}
          backend={backend}
        />
      </div>
      <Footer />
    </div>
  );
};

export async function getServerSideProps(context) {
  var businessPartners = [];
  var service = [];
  var carousel = [];
  const backend = process.env.BACKEND_SERVER_URI;

  var res = await GetbusinessPartners.GetbusinessPartners();
  if (res["STATUS"] === 1) {
    businessPartners = res["DATA"]["businessPartners"];
  }

  var res = await Getservices.Getservices();
  if (res["STATUS"] === 1) {
    service = res["DATA"]["services"];
  }

  var res = await Getcarousels.GetCarousels();
  if (res["STATUS"] === 1) {
    carousel = res["DATA"]["carousels"];
  }

  return {
    props: { businessPartners, service, carousel, backend }, // will be passed to the page component as props
  };
}

export default Home;
