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 { getSanksi } 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";

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

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

	componentDidMount = async () => {
		const { query } = this.props;
		const sanksi = await getSanksi(query);
		const pt = await getPT({ id: query.ptId });
		this.setState({ pt, sanksi });
	};

	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 && sanksi.data.length ? (
							<Col xl="9">
								<Card className="card-default">
									<CardBody>
										<Row>
											<Col lg={12}>
												<DetailSanksi data={sanksi.data[0]} />
											</Col>
										</Row>
									</CardBody>
								</Card>
							</Col>
						) : (
							<Loader />
						)}
						<Col xl="3">{pt?.data ? <DetailPT data={pt.data[0]} /> : <Loader />}</Col>
					</Row>
					<Row>
						<Col>{sanksi.data && sanksi.data.length && <Riwayat data={sanksi.data[0].sanksi.doc_perbaikan} />}</Col>
					</Row>
				</div>
			</ContentWrapper>
		);
	}
}

export default PemantauanDokumen;
