<div class="table-responsive">
	<table class="table table-striped p-0 m-0 table-sm border-top border-bottom text-nowrap table-bordered">
		<thead class="bg-light">
			<tr>
				<th class="border-0 text-secondary">#</th>
				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Name', 'key' => 'name_first'])</th>
				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'DOB', 'key' => 'dob'])</th>
				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Age', 'key' => 'age_in_years'])</th>
				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Sex', 'key' => 'sex'])</th>
				<th class="border-0 text-secondary">Insurance</th>
				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Last Visit', 'key' => 'most_recent_completed_mcp_note_date'])</th>
				<th class="border-0 text-secondary">Next Appt.</th>
				<th class="border-0 text-secondary">Status</th>

				<th class="border-0 text-secondary">BP</th>
				<th class="border-0 text-nowrap">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => '<i class="fa fa-heartbeat text-secondary"></i>', 'key' => 'most_recent_cellular_bp_value_irregular'])</th>
				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Pulse', 'key' => 'most_recent_cellular_bp_value_pulse'])</th>
				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'BP/Pulse Timestamp', 'key' => 'most_recent_cellular_bp_measurement_at'])</th>
				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Weight', 'key' => 'most_recent_cellular_weight_value'])</th>
				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Weight Timestamp', 'key' => 'most_recent_cellular_weight_measurement_at'])</th>

				{{-- <th>Scale <i class="fa fa-battery"></i></th>--}}
				{{-- <th class="border-0">RPM</th>--}}
				{{-- <th class="border-0 d-none">Last Weight-In</th>--}}
				{{-- <th class="border-0 d-none">Last BP</th>--}}
				<th class="border-0 text-secondary">Assigned On</th>

				@if($pro->pro_type == 'ADMIN')
				<th class="border-0 text-secondary">MCP</th>
				<th class="border-0 text-secondary">Initiative</th>
				@endif
			</tr>
		</thead>
		<tbody>
			@foreach($patients as $patient)
			<tr>
				<td>
					<a native target="_blank" href="{{route('patients.view.dashboard', $patient)}}">
						{{$patient->chart_number}}
					</a>
				</td>
				<td>
					{{$patient->displayName()}}
				</td>
				<td>{{ friendly_date_time($patient->dob, false) }}</td>
				<td>{{ $patient->age_in_years ?  $patient->age_in_years : '-' }}</td>
				<td>{{ $patient->sex }}</td>
				<td>
					@include('app.patient.coverage_column_renderer', ['patient'=>$patient])
				</td>
				<td>
					{{ friendly_date($patient->most_recent_completed_mcp_note_date) }}
					{{-- {{$patient->lastMcpAppointment ? friendly_date_time($patient->lastMcpAppointment->raw_date.' '.$patient->lastMcpAppointment->raw_start_time) : '-'}}--}}
				</td>
				<td>{{$patient->nextMcpAppointment ? friendly_date_time($patient->nextMcpAppointment->raw_date.' '.$patient->nextMcpAppointment->raw_start_time) : '-'}}</td>
				<td>{{$patient->nextMcpAppointment ? $patient->nextMcpAppointment->status : '-'}}</td>

				<td>
					@if($patient->most_recent_cellular_bp_measurement_at)
					{{ $patient->most_recent_cellular_bp_sbp_mm_hg }} / {{ $patient->most_recent_cellular_bp_dbp_mm_hg }}
					@endif
				</td>

				<td><?= $patient->most_recent_cellular_bp_value_irregular ? '<i class="fa fa-heartbeat"></i>' : '' ?></td>

				<td>{{ $patient->most_recent_cellular_bp_value_pulse }}</td>

				<td>{{ friendlier_date_time($patient->most_recent_cellular_bp_measurement_at, false) }}</td>

				<td>{{ $patient->most_recent_cellular_weight_value ? round($patient->most_recent_cellular_weight_value, 2) : '--' }}</td>

				<td>{{ friendlier_date_time($patient->most_recent_cellular_weight_measurement_at, false) }}</td>

				<td class="d-none text-nowrap">
					<?php $m = $patient->lastMeasurementOfType('Wt. (lbs.)'); ?>
					{{$m && $m->value ? round($m->value, 2) : '-'}}
				</td>
				<td class="d-none text-nowrap">
					<?php $m = $patient->lastMeasurementOfType('BP'); ?>
					{{$m && $m->value ? $m->value : '-'}}
				</td>
				<td>{{$patient->getMcpAssignedOn()}}</td>
				@if($pro->pro_type == 'ADMIN')
				<td>{{$patient->mcp->display_name ?? '--'}}</td>
				<td>{{$patient->initiative}}</td>
				@endif
			</tr>
			@endforeach

			@if(count($patients) === 0)
			<tr>
				<td colspan="24">No records found!</td>
			</tr>
			@endif
		</tbody>

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