<div class="row mt-2 mb-4">
	<div class="col">
		<h3>Browse</h3>
		<div class="row mt-4">
			<div class="col">
				<table id="table_queries" class="table table-striped table-bordered table-hover nowrap">
					<thead class="thead-light">
						<tr>
							<th>BGC</th>
							<th>class</th>
							<th>length (kb)</th>
							<th>completeness</th>
							<th>best hit</th>
							<th>distance</th>
							<th>details</th>
						</tr>
					</thead>
					<tbody class="tbody">
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		$("#table_queries").DataTable({
			searching: false,
			ordering:  false,
			responsive: true,
			serverSide: true,
			ajax: {
				url: "/api/reports/module/query/bgc_list",
				type: "GET",
				data: {
					"report_id": $("#report_id").val(),
					"run_id": $("#run_id").val()
				}
			},
			columnDefs: [
				{
					"targets": 1, // chem_class
					render: function(data, type, row, meta) {
						let html_text = "<ul class='list-unstyled'>";
						data.forEach(function(value, index) {
							html_text += "<li>" + value[0] + ":" + value[1] + "</li>";
						});
						html_text += "</ul>"
						return html_text;
					}
				},
				{
					"targets": 4, // gcf
					render: function(data, type, row, meta) {
						return "<a class='btn btn-info' href='/run/" + meta.settings.json.run_id + "/gcf/" + data[0] + "'>" + data[1] + "</a>";
					}
				},
				{
					"targets": 6, // details
					render: function(data, type, row, meta) {
						return "<a href='/reports/view/query/" + meta.settings.json.report_id + "/bgc/" + data + "'><button type='button' class='btn btn-sm btn-info'>view</button></a>";
					}
				},
				{ className: "text-right", "targets": [2, 5] },
				{ className: "text-center", "targets": [4, 6] }
			],
			drawCallBack: function(settings) {
				// --
			},
			createdRow: function(row, data, dataIndex) {
			    if (data[5] <= parseFloat($("#threshold").val())) {
			    	$(row).addClass("table-success");
			    } else {
			    	$(row).addClass("table-danger");
			    }
			},

		});
	});
</script>