import React, { Component } from "react";
import Header from "@/components/Main/Header";
import DetailPT from "@/components/Main/DetailPT";
import { getOneLaporan } from "@/actions/pelaporan";
import DetailLaporan from "@/components/PelaporanTuntas/DetailLaporan";
import Link from "next/link";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import { Row, Col, Card, Button, CardBody } from "reactstrap";
import Loader from "@/components/Common/Loader";
import { connect } from "react-redux";
import { createLog } from "@/actions/log";

class DetailPelaporan extends Component {
	constructor(props) {
		super(props);
		this.state = {
			pelaporan: {},
		};
	}

	static getInitialProps = async ({ query }) => {
		return { query };
	};

	componentDidMount = async () => {
		const { token, query } = this.props;
		const pelaporan = await getOneLaporan(this.props.token, query.id + "?aktif=false");
		await createLog(token, { aktivitas: `Mengakses halaman detail Pelaporan Tuntas dengan No. Laporan ${pelaporan.data.no_laporan}`, menu: "Pelaporan" });
		this.setState({ pelaporan });
	};

	render() {
		const { pelaporan } = this.state;
		return (
			<ContentWrapper unwrap>
				{/* <Header /> */}
				<div className="p-3">
					<div className="content-heading">
						<span className="font-color-white">Detail Pelaporan</span>
						<div className="ml-auto">
							<Link href="/app/tuntas">
								<Button className="btn-login" color>
									<span className="font-color-white">&lt; Kembali</span>
								</Button>
							</Link>
						</div>
					</div>
					<Row>
						<Col xl="9">
							{pelaporan.data ? (
								<Card className="card-default">
									<CardBody>
										<Row>
											<Col lg={12}>{<DetailLaporan data={pelaporan.data} />}</Col>
										</Row>
									</CardBody>
								</Card>
							) : (
								<Loader />
							)}
						</Col>
						<Col xl="3">{pelaporan.data ? <DetailPT data={pelaporan.data.pt} /> : <Loader />}</Col>
					</Row>
				</div>
			</ContentWrapper>
		);
	}
}

const mapStateToProps = (state) => ({ user: state.user, token: state.token });
export default connect(mapStateToProps)(DetailPelaporan);
