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

import GetLatestNews from "../api/latest_news/news.js"
import DataSnackbarContent from "../pages-sections/snackbar.js";
import DetailLatestNews from "../pages-sections/latest_news/news_details.js";

const useStyles = makeStyles(styles);

const detailLatestNews = function ({ backend, news, ...props }) {
    const classes = useStyles();
    const { ...rest } = props;
    <DetailLatestNews news={props.news}/>
    return (
        <div>
        <Header
            rightLinks={<HeaderLinks />}
            fixed
            color="info"
            changeColorOnScroll={{
            height: 400,
            color: "white"
            }}
            {...rest}
        />
        <Parallax image={require("assets/img/simulasicicilan.jpg")} width="200px"/>
        <div className={classNames(classes.main, classes.mainRaised)}>
            <DataSnackbarContent/>
            <DetailLatestNews news={news} backend={backend}/> 
        </div>
        <Footer />
        </div>
    );
}

export default detailLatestNews;

export async function getServerSideProps(context) {
    var {query} = context;
	var news = [];
    const backend = process.env.BACKEND_SERVER_URI;
	var res = await GetLatestNews.GetDetailNews(query.s||0);
	if (res["STATUS"] === 1) {
		news = res["DATA"]["latestNews"];
	}
	return {
		props: { news, backend }, // will be passed to the page component as props
	};
}