import React, { Component } from "react";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import { getSanksi } from "@/actions/sanksi";
import Header from "@/components/Main/Header";
import DetailPT from "@/components/Main/DetailPT";
import DetailSanksi from "@/components/Main/DetailSanksi";
import Riwayat from "@/components/PT/Keberatan/Riwayat";
import ModalPermohonan from "@/components/PT/Keberatan/ModalPermohonan";
import Link from "next/link";
import { Row, Col, Card, CardBody, Button } from "reactstrap";

class Keberatan extends Component {
	state = {
		modal: false,
	};

	static async getInitialProps({ query }) {
		const { noSanksi } = query;
		const sanksi = await getSanksi({ noSanksi, ptId: "0BCE4DB7-B207-445D-8D03-0C54B7688252" });
		return { query, sanksi };
	}

	toggleModal = (value = true) => {
		if (!value) {
			this.setState({ modal: false });
		} else {
			this.setState({ modal: !this.state.modal });
		}
	};

	render() {
		const { sanksi } = this.props;
		console.log(sanksi);
		return (
			<ContentWrapper unwrap>
				<ModalPermohonan toggleModal={this.toggleModal} modal={this.state.modal} query={this.props.query} />
				<Header />
				<div className="p-3">
					<div className="content-heading">
						<div>Permohonan Keberatan</div>
						<div className="ml-auto">
							<Link href="/app/pt/keberatan">
								<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}>
											<DetailSanksi data={sanksi.data[0]} />
											<p>Setelah membaca surat keputusan sanksi tersebut, jika Perguruan Tinggi bermaksud mengajukan permohonan keberatan maka dapat menekan tombol di bawah ini (21 Hari Kerja)</p>
											<Button color="primary" onClick={this.toggleModal} disabled={sanksi.data[0].sanksi.keberatan || false}>
												Ajukan Permohonan Keberatan
											</Button>
										</Col>
									</Row>
								</CardBody>
							</Card>
						</Col>
						<Col xl="3">
							<DetailPT />
						</Col>
					</Row>
					<Row>
						<Col>
							<Riwayat data={sanksi.data[0]} />
						</Col>
					</Row>
				</div>
			</ContentWrapper>
		);
	}
}

export default Keberatan;
