@use(App\Models\Service)

@extends('adminlte::layouts.app')

@section('htmlheader_title')
	Product List
@endsection
@section('page_title')
	Product List
@endsection

@section('contentheader_title')
	Product List
@endsection
@section('contentheader_description')
@endsection

@section('main-content')
	<div class="col-md-12">
		<div class="card">
			<div class="card-body">
				<table class="table table-sm table-striped" id="table">
					<thead>
					<tr>
						<th>ID</th>
						<th>Type</th>
						<th>PID</th>
						<th>Product</th>
						<th class="text-right">Services</th>
					</tr>
					</thead>

					<tbody>
					@foreach (Service::ServiceActive()->with(['product.translate'])->get()->groupBy('product_id') as $s)
						<tr>
							<td><a href="{{ url('a/product/details',[($x=$s->first())->product_id]) }}">{{ $x->id }}</a></td>
							<td>{{ $x->product->category_name }}</td>
							<td>{{ $x->product->pid }}</td>
							<td>{{ $x->product->name }}</td>
							<td class="text-right">{{ $s->count() }}</td>
						</tr>
					@endforeach
					</tbody>
				</table>
			</div>
		</div>
	</div>
@endsection

@pa(datatables,rowgroup)

@section('page-scripts')
	<script type="text/javascript">
		$(document).ready(function() {
			$('#table').DataTable({
				aLengthMenu: [
					[25, 50, 100, 200, -1],
					[25, 50, 100, 200, "All"]
				],
				paging: true,
				pageLength: 25,
				lengthChange: true,
				searching: true,
				ordering: true,
				info: true,
				autoWidth: false,
				fixedHeader: true,
				order: [
					[1,'asc'],
					[3,'asc'],
				],
				rowGroup: {
					dataSrc: [1],
				},
				columnDefs: [
					{
						targets: [1],
						visible: false,
					},
				],
			});
		});
	</script>
@append