import React, { Component } from "react";
import Header from "@/components/Main/Header";
import DetailPT from "@/components/Main/DetailPT";
import InputData from "@/components/Pelaporan/InputData";
import Link from "next/link";
import { getOnePT } from "@/actions/PT";
import { connect } from "react-redux";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import { Row, Col, Card, CardHeader, CardBody } from "reactstrap";
import Loader from "@/components/Common/Loader";

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

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

	componentDidMount = async () => {
		const { query, token } = this.props;
		const pt = await getOnePT(token, query.ptId);
		this.setState({ pt });
	};

	render() {
		const { pt } = this.state;
		return (
			<ContentWrapper unwrap>
				{/* <Header /> */}
				<div className="p-3">
					<div className="content-heading">
						<div>
							Pelaporan Baru
							{/* <small>Form pembuatan laporan baru v.0.1</small> */}
						</div>
						<div className="ml-auto">
							<Link href="/app/pelaporan/search">
								<button className="btn btn-sm btn-secondary text-sm">&lt; back</button>
							</Link>
						</div>
					</div>
					<Row>
						<Col xl="9">
							<Card className="card-default">
								<CardBody>
									<Row>
										<Col lg={12}>
											<p className="lead bb">Informasi Laporan<span className="font-20">(wajib diisi)</span></p>
											<InputData query={this.props.query} />
										</Col>
									</Row>
								</CardBody>
							</Card>
						</Col>
						<Col xl="3">{pt?.data ? <DetailPT data={pt.data} /> : <Loader />}</Col>
					</Row>
				</div>
			</ContentWrapper>
		);
	}
}

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