<?php

// HUMONGOUS FIX! This CRITICAL "if" was never there till now!
if(!@$contentData) {

    /** @var \App\Models\Pro $hcpPro */
    /** @var \App\Models\Pro $pro */
    /** @var \App\Models\Note $note */

    if(!@$hcpPro) {
        if(@$note) {
            $hcpPro = $note->hcpPro;
        }
        else {
            $hcpPro = $pro; // should never get here
        }
    }

    $contentData = false;
    if ($patient->canvas_data) {
        $canvasData = json_decode($patient->canvas_data, true);
        if(isset($canvasData["next_fu"]) && isset($canvasData["next_fu"][$hcpPro->id])) {
            $contentData = $canvasData["next_fu"][$hcpPro->id];
        }
    }

}

if($contentData === false) {
    ?>
    <div class="text-secondary">No data in this section yet</div>
    <?php
}
else {
    if(!$contentData['next_fu']['active']) {
        ?>
        <div class="text-secondary">No follow-up scheduled</div>
        <?php
    }
    else {
        ?>
        <label class="d-flex align-items-center">
            <span class="mr-2">Date:</span>
            <b><?= $contentData['next_fu']['date'] ?></b>
        </label>
        <div class="mb-2">
            <span class="font-weight-bold">Next CC</span>
        </div>
        <table class="table table-sm table-bordered table-edit-sheet">
            <thead>
            <tr class="bg-light">
                <th class="px-2 text-secondary border-bottom-0 width-30px text-center">#</th>
                <th class="px-2 text-secondary border-bottom-0">Category</th>
                <th class="px-2 text-secondary border-bottom-0">Title</th>
                <th class="px-2 text-secondary border-bottom-0">ICD</th>
                <th class="px-2 text-secondary border-bottom-0 w-35">Memo</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($contentData['next_cc']['list'] as $i => $line): ?>
                <tr>
                    <td class="bg-white px-2 py-1 text-center text-sm font-weight-bold"><?= ++$i ?></td>
                    <td class="bg-white px-2 py-1"><?= ucwords($line['category']) ?></td>
                    <td class="bg-white px-2 py-1"><?= $line['name'] ?></td>
                    <td class="bg-white px-2 py-1"><?= @$line['icd'] ?></td>
                    <td class="bg-white px-2 py-1"><?= @$line['memo'] ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        <?php
    }
}
?>
