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/RekomendasiDelegasi/DetailSanksi";
import TableRiwayat from "@/components/RekomendasiDelegasi/TableRiwayat"
import InputRekomendasi from "@/components/RekomendasiDelegasi/InputRekomendasi";
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";

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

	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 pt = sanksi.data.laporan.pt;
		const perbaikan = sanksi.data.perbaikan.map((e) => e.dokumen)
		this.setState({ sanksi, pt, perbaikan });

	};


	render() {
		const { files, sanksi, pt, perbaikan } = this.state;
		const { query, token } = this.props;
		return (
			<ContentWrapper unwrap>
				{/* <Header /> */}
				<div className="p-3">
					<div className="content-heading">
						<span className="font-color-white">
							Rekomendasi Delegasi
						</span>
						<div className="ml-auto">
							<Link href="/app/rekomendasi-delegasi">
								<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} />
								<Card className="card-default">
									<CardHeader>
										<CardTitle>Riwayat</CardTitle>
									</CardHeader>
									<CardBody>
										<TableRiwayat data={sanksi.data} perbaikan={sanksi.data.perbaikan} />
									</CardBody>
								</Card>
								<InputRekomendasi query={query} token={token} data={sanksi.data} />
							</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);
