	<table class="table table-striped p-0 m-0 table-sm border-top border-bottom ">
		<thead class="bg-light">
			<tr>
				<th class="border-0">Device Type</th>
				<th class="border-0">IMEI</th>
				<th class="border-0">Issued Yet?</th>
				<th class="border-0">Client</th>
				<th class="border-0">Used?</th>
				<th class="border-0">MCP</th>
				<th class="border-0">Issue Date</th>
				<th class="border-0">Supply Order Status</th>
				<th class="border-0">Last Meas. Date</th>
				<th class="border-0">Last Meas. Days Ago</th>
				<th class="border-0"># Days with Remote Meas. this Month</th>
				<th class="border-0"># Days with Remote Meas. last Month</th>
				<th class="border-0">Client Engagement Status Category</th>
				<th class="border-0">Admin Engagement Assessment Status</th>
				<th class="border-0">Mcp Engagement Assessment Status</th>
				<th class="border-0">Default Na Engagement Assessment Status</th>
			</tr>
		</thead>
		<tbody>
			@foreach($bdtDevices as $bdtDevice)
			<tr>
				<td>{{$bdtDevice->category}}</td>
				<td>{{$bdtDevice->imei}}</td>
				<td>{{$bdtDevice->clientBDTDevice ? 'Yes': 'No'}}</td>
				<td>
					@if($bdtDevice->clientBDTDevice)
					<a native target="_blank" href="{{route('patients.view.dashboard',$bdtDevice->clientBDTDevice->client)}}">
						{{$bdtDevice->clientBDTDevice->client->displayName()}}
					</a>
					@else 
						-
					@endif 
				</td>
				<td>{{@$bdtDevice->clientBDTDevice->mostRecentMeasurement ? 'Yes': 'No'}}</td>
				<td>
					@if($bdtDevice->clientBDTDevice && $bdtDevice->clientBDTDevice->client && $bdtDevice->clientBDTDevice->client->mcp)
						{{$bdtDevice->clientBDTDevice->client->mcp->name_first}} {{$bdtDevice->clientBDTDevice->client->mcp->name_last}}
					@else 
						-
					@endif 
				</td>
				<td>
					@if($bdtDevice->clientBDTDevice)
						{{friendly_date_time($bdtDevice->clientBDTDevice->created_at)}}
					@else 
						-
					@endif 
				</td>
				<td>
					@if($bdtDevice->clientBDTDevice)
						@foreach($bdtDevice->clientBDTDevice->supplyOrders as $so)
							<div class="card p-2 shadow m-2 border">
								<div>Product: {{$so->product->title}}</div>
								<div>Is signed by pro: {{$so->is_signed_by_pro ? 'Yes' : 'No'}}</div>
								@if($so->is_signed_by_pro)
									<div>Signed by: {{$so->signedPro->name_first}} {{$so->signedPro->name_last}}</div>
								@endif
								<div>
									Has shippiment: {{$so->shipment? 'Yes': 'No'}}
								</div>
							</div>
						@endforeach
					@else 
						-
					@endif 	
				</td>
				<td>
					@if($bdtDevice->clientBDTDevice)
						@if($bdtDevice->clientBDTDevice->mostRecentMeasurement)
							{{friendly_date_time($bdtDevice->clientBDTDevice->mostRecentMeasurement->measurement->ts_date_time)}}
						@else 
							-
						@endif
					@else 
						-
					@endif 	
				</td>
				<td>
					@if($bdtDevice->clientBDTDevice)
						@if($bdtDevice->clientBDTDevice->mostRecentMeasurement)
							{{date_diff(date_create($bdtDevice->clientBDTDevice->mostRecentMeasurement->measurement->ts_date_time), date_create('now'))->days}}
						@else 
							-
						@endif
					@else 
						-
					@endif 	
				</td>
				<td>
					@if($bdtDevice->clientBDTDevice)
						{{$bdtDevice->clientBDTDevice->client->currentCareMonth()->number_of_days_with_remote_measurements}}
					@endif
				</td>
				<td>
					@if($bdtDevice->clientBDTDevice)
						{{$bdtDevice->clientBDTDevice->client->previousCareMonth()->number_of_days_with_remote_measurements}}
					@endif
				</td>
				<td>{{@$bdtDevice->clientBDTDevice->client->client_engagement_status_category}}
				<td>{{@$bdtDevice->clientBDTDevice->client->adminEngagementAssessmentStatus->status_category}}
				<td>{{@$bdtDevice->clientBDTDevice->client->mcpEngagementAssessmentStatus->status_category}}
				<td>{{@$bdtDevice->clientBDTDevice->client->defaultNaEngagementAssessmentStatus->status_category}}
			</tr>
			@endforeach
		
			@if(count($bdtDevices) === 0)
			<tr>
				<td colspan="24">No records found!</td>
			</tr>
			@endif
		</tbody>

	</table>
</div>
<div class="p-3">
	{{$bdtDevices->withQueryString()->links()}}
</div>
