import React, { Component } from "react";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import { getSanksi } 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: {},
		};
	}

	componentDidMount = async () => {
		const { user } = this.props;
		const { noSanksi } = this.props.router.query;
		const sanksi = await getSanksi({ noSanksi, ptId: user.peran[0].organisasi.id });
		this.setState({ sanksi });
	};

	render() {
		const { sanksi } = this.state;
		return (
			<ContentWrapper unwrap>
				<Header data={this.props.pt[0]} />
				<div className="p-3">
					<div className="content-heading">
						<div>Jawaban Atas Permohonan Banding</div>
						<div className="ml-auto">
							<Link href="/app/pt/jawaban-banding">
								<button className="btn btn-sm btn-secondary text-sm">&lt; kembali</button>
							</Link>
						</div>
					</div>
					<Row>
						{sanksi?.data ? (
							<Col xl="9">
								<Card className="card-default">
									<CardBody>
										<Row>
											<Col lg={12}>
												<DetailSanksi data={sanksi.data[0]} />
												<DetailJawaban data={sanksi.data[0]} />
											</Col>
										</Row>
									</CardBody>
								</Card>
							</Col>
						) : (
							<Loader />
						)}
						<Col xl="3">{this.props.pt && <DetailPT data={this.props.pt[0]} />}</Col>
					</Row>
				</div>
			</ContentWrapper>
		);
	}
}

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