import Datatable from "@/components/Tables/Datatable";
import moment from "moment";
import { Card, CardHeader, CardBody, CardTitle } from "reactstrap";

function Riwayat({ data }) {
	const jawaban = data.sanksi.keberatan.jawaban;
	return (
		<Card className="card-default">
			<CardHeader>
				<CardTitle>Riwayat</CardTitle>
			</CardHeader>
			<CardBody>
				<Datatable options={{ responsive: true }}>
					<table className="table table-striped my-4 w-100">
						<thead>
							<tr>
								<th>Tanggal</th>
								<th>Status</th>
								<th>Keterangan Jawaban</th>
								<th>Dokumen Jawaban</th>
							</tr>
						</thead>
						<tbody>
							{jawaban ? (
								<tr>
									<td>{moment(jawaban.createAt).format("DD MMMM YYYY")}</td>
									<td>{jawaban.status}</td>
									<td>{jawaban.description}</td>
									<td>
										{jawaban.files.map((e) => (
											<>
												<em className="fa-lg far fa-file-code"></em>
												<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>
				</Datatable>
			</CardBody>
		</Card>
	);
}

export default Riwayat;
