import React, { Component } from "react";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import { getOneSanksi } from "@/actions/sanksi";
import Header from "@/components/Main/Header";
import DetailPT from "@/components/Main/DetailPT";
import DetailSanksi from "@/components/Main/DetailSanksi";
import DetailJawaban from "@/components/PT/JawabanBanding/DetailJawaban";
import Link from "next/link";
import { Row, Col, Card, CardBody, Button } from "reactstrap";
import { connect } from "react-redux";
import { withRouter } from "next/router";
import Loader from "@/components/Common/Loader";

class JawabanBanding extends Component {
	constructor(props) {
		super(props);
		this.state = {
			modal: false,
			sanksi: {},
			pt: null,
		};
	}

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

	componentDidMount = async () => {
		const { token, query } = this.props;
		const sanksi = await getOneSanksi(token, query.id);
		this.setState({ sanksi, pt: sanksi.data.laporan.pt });
	};

	render() {
		const { sanksi, pt } = this.state;
		return (
			<ContentWrapper unwrap>
				{pt && <Header data={pt} />}
				<div className="p-3">
					<div className="content-heading">
						<span className="font-color-white">
							Jawaban Atas Permohonan Banding
						</span>
						<div className="ml-auto">
							<Link href="/pt/jawaban-banding">
								<Button className="color-3e3a8e" color>
									<span className="font-color-white">
										&lt; Kembali
									</span>
								</Button>
							</Link>
						</div>
					</div>
					<Row>
						{sanksi.data ? (
							<Col xl="9">
								<Card className="card-default">
									<CardBody>
										<Row>
											<Col lg={12}>
												<DetailSanksi data={sanksi.data} />
												<DetailJawaban data={sanksi.data.jawaban.banding} sanksiId={sanksi.data._id} />
											</Col>
										</Row>
									</CardBody>
								</Card>
							</Col>
						) : (
							<Loader />
						)}
						<Col xl="3">{pt && <DetailPT data={pt} />}</Col>
					</Row>
				</div>
			</ContentWrapper>
		);
	}
}

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