<?php

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

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

if($point) {
    ?> <div class="popup-content-container px-3"> <?php
    foreach ($point->childReviews as $childReview) {
        $contentData = $parsed = false;
        if ($childReview->data) {
            $childReview->data = json_decode($childReview->data, true);
            $contentData = $parsed = $childReview->data;

            if($contentData && $contentData['count']) {
                ?>
                    <div class="mb-1 font-weight-bold">{{$childReview->creatorPro->displayName()}} - {{friendly_date($childReview->note->effective_dateest)}}</div>
                    <div class="pl-3 bg-light border p-3 mb-3">
                    <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
            }
        }
    }
    ?> </div> <?php
}