<?php
use App\Models\ClientCarePlanFlagUpdate;

$recentClientCarePlanFlags = ClientCarePlanFlagUpdate::where('client_id', $patient->id)->orderBy('created_at', 'DESC')->limit(5)->get();
?>
@if(count($recentClientCarePlanFlags))
<div moe relative wide center class="ml-2 mr-2">
	<a start show title="View Care Plan Flag History"><i class="fas fa-history fa-fw on-hover-opaque"></i></a>
	<form url="" class="mcp-theme-1">
		<div>
			<div class="d-flex align-items-center justify-content-between pb-2 mb-1">
				<h5 class="mb-0 font-weight-bold">Recent Care Plan Flags</h5>
				<button cancel class="btn btn-sm btn-default border">
					<i class="fas fa-times"></i>
				</button>
			</div>
			<table class="table table-sm table-striped table-bordered">
				<thead class="bg-light">
					<tr>
						<th class="border-bottom-0">Date</th>
						<th class="border-bottom-0">Flag Memo</th>
						<th class="border-bottom-0">Ack. Memo</th>
					</tr>
				</thead>
				<tbody>
					@foreach($recentClientCarePlanFlags as $bf)
					<tr>
						<td>{{ friendly_date_time($bf->created_at) }}</td>
						<td>
							<div class="d-flex flex-column">
								<small class="text-sm text-muted"><?= $bf->memo ?></small>
								@if($bf->carePlanFlaggedBy)
								<div class="d-flex align-items-center">
									<span class="text-sm">By: {{ $bf->carePlanFlaggedBy->displayName() }}</span>
									<span class="text-sm ml-2">At: {{ friendly_date_time($bf->flagged_at) }}</span>
								</div>
								@endif
							</div>
						</td>
						<td>
							<div class="d-flex flex-column">
								<small class="text-sm text-muted"><?= $bf->flag_acknowledgement_memo ?></small>
								@if($bf->carePlanFlagAcknowledgedBy)
								<div class="d-flex align-items-center">
									<span class="text-sm">By: {{ $bf->carePlanFlagAcknowledgedBy->displayName() }}</span>
									<span class="text-sm ml-2">At: {{ friendly_date_time($bf->flag_acknowledged_at) }}</span>
								</div>
								@endif
							</div>
						</td>
					</tr>
					@endforeach
					@if(!count($recentClientCarePlanFlags))
						<tr>
							<td colspan="3">No records found</td>
						</tr>
					@endif
				</tbody>
			</table>
		</div>
	</form>
</div>
@endif