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/HeaderHino.js";
import Parallax from "components/Parallax/Parallax.js";
import styles from "assets/jss/nextjs-material-kit/pages/components.js";
import Footer from "components/Footer/FooterHino.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/yamaha/snackbar.js";
import DataCarousel from "pages-sections/honda/home/carousel.js";
import DataService from "pages-sections/honda/home/service.js";
import DataFeature from "pages-sections/honda/home/feature.js";
import stylecss from "pages/home.css";
import Cookies from "cookies";

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

    return (
        <div>
        <Header
            rightLinks={<HeaderLinks username={user} />}
            fixed
            color="dark"
            changeColorOnScroll={{
            height: 400,
            color: "white",
            }}
            {...rest}
        />
        <Parallax
            image={require("assets/img/hino.jpg")}
            styles={{ marginTop: "50px" }}
        />
        <div className={classNames(classes.main, classes.mainRaised)}>
            <DataSnackbarContent />
            {/* <CoreValue /> */}
            <DataCarousel carousel={carousel} backend={backend} />
            <DataService service={service} backend={backend} />
            <DataFeature />
            {/* <DataBusinessPartner
            businessPartners={businessPartners}
            backend={backend}
            /> */}
            {/* <DataSosmed /> */}
            <a href="https://wa.me/087797315685" target="_blank" class="float">
                <i class="fa fa-phone my-float"></i>
            </a>
        </div>
        <Footer />
        </div>
    );
};

export async function getServerSideProps(context) {
    var businessPartners = [];
    var service = [];
    var carousel = [];
    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() == "HINO"
        );
        });
        if (sessionId.length != 0) user = userObj["username"];
    }

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

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

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

    console.log(carousel);
    return {
        props: { businessPartners, service, carousel, backend, user }, // will be passed to the page component as props
    };
}

export default Home;
