import React, { Component } from "react";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import DetailPT from "@/components/Main/DetailPT";
import Header from "@/components/Main/Header";
import DetailLaporan from "@/components/Main/DetailLaporan";
import InputEvaluasi from "@/components/Pemeriksaan/InputEvaluasi";
import TableRiwayat from "@/components/Pemeriksaan/TableRiwayat";
import { getPelaporan } from "@/actions/pelaporan";
import Link from "next/link";
import { Row, Col, Card, CardBody, CardHeader, CardTitle } from "reactstrap";
import Loader from "@/components/Common/Loader";

class PemeriksaanNew extends Component {
	constructor(props) {
		super(props);
		this.state = {
			pelaporan: {},
		};
	}
	static getInitialProps = async ({ query }) => {
		return { query };
	};

	componentDidMount = async () => {
		const { query } = this.props;
		const pelaporan = await getPelaporan({ ptId: query.ptId, number: query.number });
		this.setState({ pelaporan });
	};

	render() {
		const { query } = this.props;
		const { pelaporan } = this.state;
		return (
			<ContentWrapper unwrap>
				{/* <Header /> */}
				<div className="p-3">
					<div className="content-heading">
						<div>Evaluasi Pemeriksaan</div>
						<div className="ml-auto">
							<Link href="/app/pemeriksaan">
								<button className="btn btn-sm btn-secondary text-sm">&lt; back</button>
							</Link>
						</div>
					</div>
					<Row>
						<Col xl="9">
							{pelaporan.data && pelaporan.data.length ? (
								<Card className="card-default">
									<CardBody>
										<Row>
											<Col lg={12}>
												<DetailLaporan data={pelaporan.data[0]} />
												<InputEvaluasi query={query} />
											</Col>
										</Row>
									</CardBody>
								</Card>
							) : (
								<Loader />
							)}
						</Col>
						<Col xl="3">{pelaporan.data && pelaporan.data.length ? <DetailPT data={pelaporan.data[0].pt} /> : <Loader />}</Col>
					</Row>
					{pelaporan.data && pelaporan.data.length && (
						<Row>
							<Col>
								<Card className="card-default">
									<CardHeader>
										<CardTitle>Riwayat Evaluasi</CardTitle>
									</CardHeader>
									<CardBody>
										<TableRiwayat data={pelaporan.data[0]} />
									</CardBody>
								</Card>
							</Col>
						</Row>
					)}
				</div>
			</ContentWrapper>
		);
	}
}

export default PemeriksaanNew;
