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

import Header from "components/Header/Header.js";
import HeaderSuzuki from "components/Header/HeaderSuzuki.js";
import FooterSuzuki from "components/Footer/FooterSuzuki.js";
import Parallax from "components/Parallax/Parallax.js";
import styles from "assets/jss/nextjs-material-kit/pages/components.js";

import SectionCarrer from "pages-sections/suzuki/carrer/carrer.js";
import Getcarrer from "../../../api/carrer/carrer.js"
import Cookies from "cookies";

const useStyles = makeStyles(styles);

const Carrer = function ({ backend, s1, d3, sma, user, ...props }) {
  const classes = useStyles();
  const { ...rest } = props;
  return (
    <div>
      <Header
        rightLinks={<HeaderSuzuki username={user} />}
        fixed
        color="info"
        changeColorOnScroll={{
          height: 400,
          color: "white"
        }}
        {...rest}
      />
      <Parallax image={require("assets/img/carrer.png")} height="50px"/>
      <div className={classNames(classes.main, classes.mainRaised)}>
        <SectionCarrer s1={s1} d3={d3} sma={sma} backend={backend}/>  
      </div>
      <FooterSuzuki />
    </div>
  );
}

export default Carrer;

export async function getServerSideProps(context) {
  var s1 = [];
  var d3 = [];
  var sma = [];
  const backend = process.env.BACKEND_SERVER_URI;

  var { req, resp } = context;
  const cookies = new Cookies(req, resp);
  var user = "";
  var userObj = (await cookies.get("user"))
    ? JSON.parse(await cookies.get("user"))
    : null;
  if (userObj) {
    let sessionId = userObj["partners_login_states"].filter(function (i) {
      return (
        i.business_partner && i.business_partner.name.toUpperCase() == "SUZUKI"
      );
    });
    if (sessionId.length != 0) user = userObj["username"];
  }

  var res = await Getcarrer.GetCarrerS1Suzuki();
	if (res["STATUS"] === 1) {
		s1 = res["DATA"]["carrers"];
	}

  var res = await Getcarrer.GetCarrerD3Suzuki();
	if (res["STATUS"] === 1) {
		d3 = res["DATA"]["carrers"];
	}

  var res = await Getcarrer.GetCarrerSMASuzuki();
	if (res["STATUS"] === 1) {
		sma = res["DATA"]["carrers"];
	}
  
	return {
		props: { s1, d3, sma, user, backend }, // will be passed to the page component as props
	};
}