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/PerpanjanganSanksi/DetailSanksi";
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";
import InputTanggal from "../../../components/PerpanjanganSanksi/InputTanggal";


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

	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;
		this.setState({ sanksi, pt });

	};


	render() {
		const { files, sanksi, pt } = this.state;
		const { query, token } = this.props;
		return (
			<ContentWrapper unwrap>
				{/* <Header /> */}
				<div className="p-3">
					<div className="content-heading">
						<span className="font-color-white">
							Perpanjangan Sanksi
						</span>
						<div className="ml-auto">
							<Link href="/app/perpanjangan-sanksi">
								<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} />
								<InputTanggal 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);
