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

function TableLaporan({ listData, to, linkName }) {
	return (
		<div className="card b">
			<div className="card-body">
				{listData && (
					<Datatable options={{ responsive: false }}>
						<table className="table w-100">
							<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 className="text-nowrap">
												<div className="media align-items-center">
													<div className="media-body d-flex">
														<div>
															<h4 className="m-0">{data.pt.nama}</h4>
															<p>{data.keterangan.length > 35 ? data.keterangan.substring(0, 35) + "..." : data.keterangan}</p>
														</div>
													</div>
												</div>
											</td>

											<td>
												{data.level == 3 ? <div className="badge badge-success">Tinggi</div> : data.level == 2 ? <div className="badge badge-info">Sedang</div> : <div className="badge badge-warning">Rendah</div>}
												{data.jadwal ? <div className="badge badge-info">Ada Jadwal</div> : <div className="badge badge-danger">Tidak ada jadwal</div>}
											</td>

											<td>{moment(data.createdAt).fromNow()}</td>
											<td>
												<div className="ml-auto">
													<Link
														href={{
															pathname: to,
															query: { id: data._id },
														}}
													>
														<Button color="primary" size="sm">
															{linkName}
														</Button>
													</Link>
												</div>
											</td>
										</tr>
									);
								})}
							</tbody>
						</table>
					</Datatable>
				)}
			</div>
		</div>
	);
}

export default TableLaporan;
