<?php

use App\Models\Point;

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

$points = Point::getPlanPointsOfCategory($patient, 'CARE_TEAM_MEMBER', $note);
$numRelevant = 0;
$numVisible = 0;
$plural = 'Care team members';
?>

<?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 if($point->is_removed && $point->is_removed_due_to_entry_error) continue; ?>
        <?php $rel = $point->relevanceToNote($note); ?>
        <?php $plan = $point->lastChildPlan; ?>
        <?php if($plan && @($plan->data)) $plan->data = json_decode($plan->data); ?>
        <?php $numVisible++; ?>
        <tr>
            <td class="width-40px px-2 {{ $rel ? 'font-weight-bold text-info':'' }}">
                @if($rel)
                    <?php $numRelevant++; ?>
                    {{ $j }}.*
                @else
                    {{ $j }}.
                @endif
            </td>
            <td class="px-2 width-300px">
                <div class="<?= $point->is_removed ? 'strike-through' : '' ?>">
                    <b><?= !!@($point->data->name) ? @($point->data->name) : '-' ?></b>
                    <?= !!@($point->data->specialty) ? '/&nbsp;' . @($point->data->specialty) . '' : '' ?>
                    <?= !!@($point->data->organization) ? '/&nbsp;' . @($point->data->organization) . '' : '' ?><br>
                    <?= !!@($point->data->phone) ? 'Ph: ' . @($point->data->phone) . '' : '' ?>
                    <?= !!@($point->data->fax) ? '&nbsp;/&nbsp;Fax: ' . @($point->data->fax) . '<br>' : '' ?>
                    <?= !!@($point->data->date) ? '&nbsp;/&nbsp;Date: ' . @($point->data->date) : '' ?>
                </div>
            </td>
            <td class="px-2 width-300px">
                <div class="pl-3">
                    <?php if(!!$plan): ?>
                        <div class="mt-1 d-flex align-items-baseline">
                            <span>{!! $plan->data->value !!}</span>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="pl-3 d-flex align-items-baseline">
                    <?php if ($point->is_removed): ?>
                        @if($point->removal_reason_category === 'DURING_VISIT')
                            <span class="mt-1 text-sm text-secondary">Removed during visit</span>
                        @elseif($point->removal_reason_category === 'ON_INTAKE')
                            <span class="mt-1 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="mt-1 text-sm text-success">* Added during visit</span>
                        <?php else: ?>
                            <span class="mt-1 text-sm text-info">* Added on intake</span>
                        <?php endif;?>
                    <?php endif; ?>
                </div>
            </td>
            <td></td>
        </tr>
    <?php endforeach; ?>
    </table>
    @if(!$numVisible)
        <div class="d-flex align-items-baseline mr-1">
            <span class="text-secondary">-</span>
        </div>
    @endif
<?php endif; ?>
