<?php

use App\Models\Point;

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

list($supplements, $counts) = Point::getPointsOfCategoryExtended($patient, 'SUPPLEMENT', $note);

$numRelevant = 0;
$numVisible = 0;
?>

<?php if (!count($supplements)): ?>
    <div class="text-secondary">No supplements</div>
<?php else: ?>
    <?php foreach ($supplements as $supplement): ?>
        <?php if($supplement->is_removed && $supplement->is_removed_due_to_entry_error) continue; ?>
        <?php $rel = $supplement->relevanceToNote($note); ?>
        <?php $review = $supplement->childPlanAddedInNote($note); ?>

        <!--show only if: relevant || added-in-note || removed-in-note || added-plan-in-note-->
        @if($rel ||
            (!$supplement->is_removed && $supplement->added_in_note_id === $note->id) ||
            ($supplement->is_removed && $supplement->removed_in_note_id === $note->id) ||
            !!$review
            )

            <?php $numVisible++; ?>

        <div class="mb-2">
            <div class="d-flex align-items-baseline">
                @if($rel)
                    <span class="text-info mr-1">
                        <i class="fa fa-star"></i>
                    </span>
                    <?php $numRelevant++; ?>
                @endif
                <div class="<?= $supplement->is_removed ? 'strike-through' : '' ?>">
                    <b><?= !!@($supplement->data->name) ? @($supplement->data->name) : '-' ?></b>
                </div>
                <?php if ($supplement->is_removed): ?>
                    @if($supplement->removal_reason_category === 'DURING_VISIT')
                        <span class="ml-2 text-sm text-secondary">Removed during visit</span>
                    @elseif($supplement->removal_reason_category === 'ON_INTAKE')
                        <span class="ml-2 text-sm text-secondary">Historic</span>
                    @endif
                <?php elseif ($supplement->added_in_note_id === $note->id): ?>
                    <?php if ($supplement->addition_reason_category === 'DURING_VISIT'): ?>
                        <span class="ml-2 text-sm text-success">* Added during visit</span>
                    <?php else: ?>
                        <span class="ml-2 text-sm text-info">* Added on intake</span>
                    <?php endif;?>
                <?php endif; ?>
            </div>
            <?php $review = $supplement->childPlanAddedInNote($note); ?>
            <?php if(!!$review): ?>
            <div class="pl-3 mt-1">
                <div class="text-secondary font-weight-bold">Plan</div>
                <div>{!! $review->data->value !!}</div>
            </div>
            <?php endif; ?>
        </div>

        @endif

    <?php endforeach; ?>
    @if(!$numVisible)
        <div class="d-flex align-items-baseline mr-1">
            <span class="text-secondary">No supplements</span>
        </div>
    @endif
    @if($numRelevant)
        <div class="d-flex align-items-baseline text-info mr-1 mt-3">
            <span class="text-sm mr-1"><i class="fa fa-star text-sm"></i></span>
            <span class="text-sm">Supplements relevant to this note</span>
        </div>
    @endif
<?php endif; ?>

