import React, { Component } from "react";
import Link from "next/link";
import { getSanksi } from "@/actions/sanksi";
import Header from "@/components/Main/Header";
import DetailPT from "@/components/Main/DetailPT";
import DetailSanksi from "@/components/Main/DetailSanksi";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import Scrollable from "@/components/Common/Scrollable";
import { Row, Col, Card, CardBody, FormGroup } from "reactstrap";

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

	render() {
		const { sanksi } = this.props;
		const { jawaban } = sanksi.data[0].sanksi.cabut_sanksi;
		return (
			<ContentWrapper unwrap>
				<Header />
				<div className="p-3">
					<div className="content-heading">
						<div>Jawaban Permohonan Pencabutan Sanksi</div>
						<div className="ml-auto">
							<Link href="/app/pt/jawaban-pencabutan-sanksi">
								<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 className="lead bb">Jawaban Permohonan Pencabutan Sanksi</p>
											<form className="form-horizontal">
												<FormGroup>
													<label md="4">Jawaban:</label>
													<div md="8">
														<h3>{jawaban.status}</h3>
													</div>
												</FormGroup>
												<FormGroup>
													<label md="4">Keterangan:</label>
													<div md="8">
														<p>{jawaban.description}</p>
													</div>
												</FormGroup>
												<FormGroup>
													<label md="4">Dokumen Jawaban:</label>
													<div md="8">
														<Scrollable height="120px" className="list-group">
															<table className="table table-bordered bg-transparent">
																<tbody>
																	{jawaban.files.map((e) => (
																		<tr>
																			<td>
																				<em className="fa-lg far fa-file-code"></em>
																			</td>
																			<td>
																				<a className="text-muted" href={`data:${e.type};base64, ${Buffer.from(e.data).toString("base64")}`} download={e.name}>
																					{e.name}
																				</a>
																			</td>
																		</tr>
																	))}
																</tbody>
															</table>
														</Scrollable>
													</div>
												</FormGroup>
											</form>
										</Col>
									</Row>
								</CardBody>
							</Card>
						</Col>
						<Col xl="3">
							<DetailPT />
						</Col>
					</Row>
				</div>
			</ContentWrapper>
		);
	}
}

export default DetailJawabanPencabutanSanksi;
