import React, { Component } from "react";
import { Row, Col, Card, CardBody, FormGroup, Input, Button, Modal, ModalHeader, ModalBody, ModalFooter, CardHeader, CardTitle } from "reactstrap";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import DetailSanksi from "@/components/PerpanjanganSanksi/DetailSanksi";
import Link from "next/link";
import DetailPT from "@/components/Main/DetailPT";
import { getOneSanksi, addRekomendasiDelegasi } from "@/actions/sanksi";
import Loader from "@/components/Common/Loader";
import { connect } from "react-redux";
import TableRiwayat from "@/components/NaikSanksi/TableRiwayat"
import InputTanggal from "../../../components/NaikSanksi/InputTanggal";
import { getPelanggaran, getPelanggaranSanksi } from "@/actions/pelanggaran";



class Detail extends Component {
	constructor(props) {
		super(props);
		this.state = {
			sanksi: {},
			files: [],
			pt: {},
			data: {},
			listSanksi: {},
		};
	}

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

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

	};


	render() {
		const { files, sanksi, pt, listSanksi } = this.state;
		const { query, token } = this.props;
		return (
			<ContentWrapper unwrap>
				{/* <Header /> */}
				<div className="p-3">
					<div className="content-heading">
						<span className="font-color-white">
							Detail Perubahan Naik Sanksi
						</span>
						<div className="ml-auto">
							<Link href="/app/naik-sanksi">
								<Button className="color-3e3a8e" color>
									<span className="font-color-white">
										&lt; Kembali
									</span>
								</Button>
							</Link>
						</div>
					</div>
					{sanksi.data && (
						<Row>

							<Col xl="9">
								<DetailSanksi data={sanksi.data} />
								<InputTanggal query={query} token={token} data={sanksi.data} listSanksi={this.state.listSanksi} />
								<Card className="card-default">
									<CardHeader>
										<CardTitle>Riwayat</CardTitle>
									</CardHeader>
									<CardBody>
										<TableRiwayat data={sanksi.data.riwayat_sanksi} perbaikan={sanksi.data.perbaikan} />
									</CardBody>
								</Card>
							</Col>
							<Col lg="3">{pt ? <DetailPT data={pt} /> : <Loader />}</Col>
						</Row>
					)}
				</div>
			</ContentWrapper>
		);
	}
}

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