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

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

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

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

	render() {
		const { sanksi, pt } = this.state;
		return (
			<ContentWrapper unwrap>
				{/* <Header /> */}
				<div className="p-3">
					<div className="content-heading">
						<div>Detail Pemantauan Perbaikan</div>
						<div className="ml-auto">
							<Link href="/app/pemantauan-perbaikan">
								<button className="btn btn-sm btn-secondary text-sm">&lt; back</button>
							</Link>
						</div>
					</div>
					<Row>
						{sanksi.data ? (
							<Col xl="9">
								<Card className="card-default">
									<CardBody>
										<Row>
											<Col lg={12}>
												<DetailSanksi data={sanksi.data} />
											</Col>
										</Row>
									</CardBody>
								</Card>
							</Col>
						) : (
							<Loader />
						)}
						<Col xl="3">{pt ? <DetailPT data={pt} /> : <Loader />}</Col>
					</Row>
					<Row>
						<Col>{sanksi.data && <Riwayat data={sanksi.data.perbaikan} />}</Col>
					</Row>
				</div>
			</ContentWrapper>
		);
	}
}

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