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/Main/DetailLaporan";
import Link from "next/link";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import { Row, Col, Card, CardBody } from "reactstrap";
import Loader from "@/components/Common/Loader";
import { connect } from "react-redux";

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

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

	componentDidMount = async () => {
		const { query } = this.props;
		const pelaporan = await getOneLaporan(this.props.token, query.id);
		this.setState({ pelaporan });
	};

	render() {
		const { pelaporan } = this.state;
		return (
			<ContentWrapper unwrap>
				{/* <Header /> */}
				<div className="p-3">
					<div className="content-heading">
						<div>Detail Pelaporan</div>
						<div className="ml-auto">
							<Link href="/app/pelaporan">
								<button className="btn btn-sm btn-secondary text-sm">&lt; back</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);
