<!-- $spo=Supplier::class -->
@use(App\Models\Supplier)

<div class="row">
	<div class="col-5 col-sm-2">
		<div class="nav flex-column nav-tabs h-100"  role="tablist" aria-orientation="vertical">
			@foreach(Supplier::offeringTypes($spo) as $key => $offering)
				<a class="nav-link @if($loop->first)active @endif" id="products-{{ $key }}-tab"  data-toggle="pill" href="#products-{{ $key }}-profile" role="tab" aria-controls="products-{{ $key }}-tab" aria-selected="true">{{ $offering->type }}</a>
			@endforeach
		</div>
	</div>

	<div class="col-7 col-sm-10">
		<div class="tab-content">
			@foreach(Supplier::offeringTypes($spo) as $key => $offering)
				<div class="tab-pane text-left fade show @if($loop->first)active @endif" id="products-{{ $key }}-profile" role="tabpanel" aria-labelledby="products-{{ $key }}-tab">
					<table class="table table-sm table-bordered w-100" id="products-{{ $key }}-table">
						<thead>
						<tr>
							<th colspan="7">Product</th>
							<th colspan="4">Services</th>
						</tr>
						<tr>
							<th>ID</th>
							<th>Product ID</th>
							<th>Product Name</th>
							<th>Active</th>
							<th>Default Billing</th>
							<th class="text-right">Setup Cost</th>
							<th class="text-right">Base Cost</th>
							<th class="text-right">Setup Charge</th>
							<th class="text-right">Base Charge</th>
							<th class="text-right">Sold</th>
							<th class="text-right">Active</th>
						</tr>
						</thead>

						<tbody>
						@foreach($xx=$offering->items->with(['products.products.services','products.products.type.supplied.supplier_detail','products.products.translate'])->get() as $oo)
							@foreach($oo->products->pluck('products')->flatten()->filter() as $po)
								<tr>
									<td><a href="{{ route('product',['pdo'=>$po->id]) }}">{{ $po->lid }}</a></td>
									<td>{{ $po->pid }} <small>[<a href="{{ route('supplier.product.type',['id'=>$po->supplied->id,'spo'=>$po->supplier->id,'type'=>$po->category_lc]) }}">{{ $po->supplied->name }}</a>]</small></td>
									<td>{{ $po->name }}</td>
									<td class="text-right">{{ $po->active ? 'YES' : 'NO' }}</td>
									<td class="text-right">{{ $po->billing_interval_name }}</td>
									<td class="text-right">{{ number_format($site->taxed($po->setup_cost),2) }}</td>
									<td class="text-right">{{ number_format($site->taxed($po->base_cost),2) }}</td>
									<td class="text-right">{{ number_format($site->taxed($po->setup_charge()),2) }}</td>
									<td class="text-right">{{ number_format($site->taxed($po->base_charge()),2) }}</td>
									<td class="text-right">{{ number_format($po->services->count()) }}</td>
									<td class="text-right">{{ number_format($po->services->where('active')->count()) }}</td>
								</tr>
							@endforeach
						@endforeach
						</tbody>

						<tfoot>
						<tr>
							<th colspan="3">TOTALS</th>
							<td class="text-right">{{ $xx->where('active',TRUE)->count() }}</td>
							<th colspan="5">&nbsp;</th>
							<td class="text-right">{{ number_format(($xxx=$xx->pluck('products')->flatten()->pluck('products')->flatten()->pluck('services')->flatten()->filter())->count()) }}</td>
							<td class="text-right">{{ number_format($xxx->where('active')->count()) }}</td>
						</tr>
						</tfoot>
					</table>
				</div>
			@endforeach
		</div>
	</div>
</div>

@pa(datatables)

@section('page-scripts')
	<script type="text/javascript">
		$(document).ready(function() {
			@foreach(Supplier::offeringTypes($spo) as $key => $offering)
			$('#products-{{ $key }}-table').DataTable();

			$('#products-{{ $key }}-table tbody').on('click','tr', function () {
				$(this).toggleClass('selected');
			});
			@endforeach
		});
	</script>
@append