<?php

use App\Models\Client;
use App\Models\Point;
use App\Models\Note;
/** @var Client $patient */
/** @var Note $note */

if(!@$note) {
    $note = $patient->coreNote;
}
if(!@$sessionKey) {
    $sessionKey = request()->cookie('sessionKey');
}

$point = Point::getOrCreateOnlyTopLevelPointOfCategory($note, 'SCREENINGS_HISTORY', $sessionKey, true);

$contentData = $parsed = false;

if ($point->lastChildReview && $point->lastChildReview->data) {
    $point->lastChildReview->data = json_decode($point->lastChildReview->data, true);
    $contentData = $parsed = $point->lastChildReview->data;
    ?>
    <table class="table table-bordered table-sm mb-0 table-cage">
        <?php
        for ($i = 0; $i < $contentData['count']; $i++) {
        ?>
        <tr>
            <td class="width-300px">
                <?= isset($contentData['items'][$i]['screening']) ? $contentData['items'][$i]['screening'] : '--' ?>
            </td>
            <td class="width-300px pl-3">
                <?php if(isset($contentData['items'][$i]['comments']) && !empty($contentData['items'][$i]['comments'])): ?>
                <span class="ml-1 text-secondary">(<?= $contentData['items'][$i]['comments'] ?>)</span>
                <?php endif; ?>
            </td>
            <td></td>
        </tr>
        <?php
        }
        ?>
    </table>
    <?php
}
else {
?>
<div class="text-secondary">-</div>
<?php
}
?>
