import Datatable from "@/components/Tables/Datatable";
import { Button } from "reactstrap";
import Link from "next/link";
import moment from "moment";

function TableLaporan({ listData }) {
	return (
		<div className="card b">
			<div className="card-body card-over">
				{listData && (
					<Datatable options={{ responsive: false }}>
						<table className="table w-100" data-order='[[2, "asc"], [3, "desc"]]'>
							<thead>
								<tr>
									<th>No.Laporan</th>
									<th>Deskripsi Laporan</th>
									<th>Status</th>
									{/* <th>Created</th> */}
									<th></th>
								</tr>
							</thead>
							<tbody>
								{listData.map((data) => {
									return (
										<tr key={data._id}>
											{/* <td>{data.no_laporan}</td> */}
											<td>
												<div className="media align-items-center">
													<div className="media-body d-flex">
														<div>
															<h4>{data.no_laporan}</h4>
															<p>{moment(data.createdAt).format("DD-MM-YYYY")}</p>
														</div>
													</div>
												</div>
											</td>
											<td>
												<div className="table-desc">
													<div className="media align-items-center">
														<div className="media-body d-flex">
															<div>
																<h4 className="m-0">{data.pt.nama.length > 65 ? data.pt.nama.substring(0, 65) + "..." : data.pt.nama}</h4>
																{/* <h4 className="m-0">{data.pt.nama}</h4> */}
																{/* <p>{data.keterangan.length > 200 ? data.keterangan.substring(0, 200) + "..." : data.keterangan}</p> */}
																<p className="w-105">{data.keterangan}</p>
															</div>
														</div>
													</div>
												</div>
											</td>
											<td>{data.sanksi ? <div className="badge badge-green">Sudah ditetapkan</div> : <div className="badge badge-red">Belum ditetapkan</div>}</td>
											{/* <td>{moment(data.createdAt).format("MM-DD-YYYY")}</td> */}
											<td>
												<div className="ml-auto">
													<Link
														href={{
															pathname: data.sanksi ? "/app/sanksi/detail" : "/app/sanksi/proses",
															query: { id: data.sanksi?._id || data._id },
														}}
													>
														<Button className="btn-login" color>
															<span className="font-color-white">
																{data.sanksi ? "Detail" : "Proses Sanksi"}
															</span>
														</Button>
													</Link>
												</div>
											</td>
										</tr>
									);
								})}
							</tbody>
						</table>
					</Datatable>
				)}
			</div>
		</div>
	);
}

export default TableLaporan;
