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>
										{sanksi.data.jawaban?.banding ? (
											<Row>
												<Col lg={12}>
													<DetailSanksi data={sanksi.data} />
													<DetailJawaban data={sanksi.data.jawaban.banding} sanksiId={sanksi.data._id} />
												</Col>
											</Row>)
											: (
												<Col lg={12}>
													<h3 className=" font-weight-bold">Menunggu Jawaban Atas Permohonan Banding</h3>
													<div className=" tengah"><img className=" tengah" src="/static/img/Wait-Jawaban.png" alt="gambar" /></div>
												</Col>
											)}

									</CardBody>
								</Card>
							</Col>
						) : (
							<Loader />
						)}
						<Col xl="3">{pt && <DetailPT data={pt} />}</Col>
					</Row>
					{sanksi.data ? (

						<Col xl="9">
							<p className="pb-5">
								<Link href={{ pathname: "/pt/jawaban-keberatan/detail", query: { id: sanksi.data._id } }}>
									<span className="btn-radius float-left">
										<Button color="" className="btn-labeled-3-notHover" >
											<h4 className=" mt-1 mb-md-2 text-center">Previous</h4>
										</Button>
									</span>
								</Link>

							</p>
						</Col>
					) : ("")}
				</div>
			</ContentWrapper>
		);
	}
}

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