<?php

use App\Models\Point;

/** @var \App\Models\Client $patient */

$points = Point::getIntakePointsOfCategory($patient, 'MEDICATION', $note);
$tracker = Point::getGlobalSingletonOfCategory($patient, 'NO_KNOWN_TRACKER');
$numRelevant = 0;
$plural = 'Medications';
?>

<?php if($tracker && @($tracker->data->no_known_medications)): ?>
    <div class="text-secondary"><span>-</span></div>
<?php endif; ?>
<?php if(!$tracker || !@($tracker->data->no_known_medications)): ?>
<?php if (!count($points)): ?>
    <div class="text-secondary">-</div>
<?php else: ?>
	<table class="table table-bordered table-xs table-cage mb-0">
    <?php $j = 0; foreach ($points as $point): $j++; ?>
        <?php $rel = $point->relevanceToNote($note); ?>
	<tr>
		<td class="width-40px pl-0 pr-2 {{ $rel ? ' text-info':'' }}">
			@if($rel)
				<?php $numRelevant++; ?>
				{{ $j }}.*
			@else
				{{ $j }}.
			@endif
		</td>
		<td class="px-2 width-300px">
			<div class=" <?= $point->is_removed ? 'strike-through' : '' ?>">
				<?= !!@($point->data->name) ? @($point->data->name) : '-' ?>
			</div>
		</td>
		<td class="width-300px">
			<div class="d-flex align-items-baseline pl-2">
				<?php $review = $point->childReviewAddedInNote($note); ?>
				<?php if(!!$review && @$review->data->value): ?>
					<span class="pr-2">{!! $review->data->value !!}</span>
				<?php endif; ?>
				<span class="text-nowrap">
					<?php if ($point->is_removed): ?>
				@if($point->removal_reason_category === 'DURING_VISIT')
					<span class="text-sm text-secondary">Removed during visit</span>
				@elseif($point->removal_reason_category === 'ON_INTAKE')
					<span class="text-sm text-secondary">Historic</span>
				@endif
				<?php elseif ($point->added_in_note_id === $note->id): ?>
				<?php if ($point->addition_reason_category === 'DURING_VISIT'): ?>
					<span class="text-sm text-success">* Addeded during visit</span>
				<?php else: ?>
					<span class="text-sm text-info">* Added on intake</span>
				<?php endif;?>
				<?php endif; ?>
				</span>
			</div>
		</td>
		<td></td>
	</tr>
    <?php endforeach; ?>
	</table>
<?php endif; ?>
<?php endif; ?>
