<?php

$contentData = [
    "items" => []
];
if($patient->canvas_data) {
    $canvasData = json_decode($patient->canvas_data, true);
    if(isset($canvasData["rx"])) {
        $contentData = $canvasData["rx"];
        if(!isset($contentData['items'])){
            $contentData['items'] = [];
        }
    }
}

if(count($contentData['items'])) {
    for ($i = 0; $i < count($contentData['items']); $i++) {
        $item = $contentData['items'][$i];
?>
        <div class="mb-2">
            <div class="">
                <?php if(isset($item["title"]) && !empty($item["title"])): ?>
                    <b class="<?= isset($item["is_currently_active"]) && $item["is_currently_active"] === false ? 'text-secondary' : '' ?>">
                        <?= $item["title"] ?>
                    </b>
                <?php endif; ?>
                <?= !!$item["strength"] ? '/&nbsp;' . $item["strength"] : '' ?>
                <?= !!$item["frequency"] ? '/&nbsp;' . $item["frequency"] : '' ?>
            </div>
            <?php
            $detailPlain = isset($item["detail"]) ? $item["detail"] : '';
            $detailPlain = trim(strip_tags($detailPlain));
            if(!empty($detailPlain)):
            ?>
                <div class="text-secondary"><?= $detailPlain ?></div>
            <?php endif; ?>
            <?php if(isset($item["is_currently_active"]) && $item["is_currently_active"] === false): ?>
                <span class="pl-3 text-secondary text-sm mr-2 font-weight-bold">(CURRENTLY INACTIVE)</span>
            <?php endif; ?>
            <?php if(isset($item["notes"]) && count($item["notes"])): ?>
                <div class="pl-3">
                <?php foreach($item["notes"] as $rxNote): ?>
                    <div>
                        <span class="text-secondary text-sm mr-2"><?= $rxNote["date"] ?></span>
                        <span class="text-secondary"><?= $rxNote["text"] ?></span>
                    </div>
                <?php endforeach; ?>
                </div>
            <?php endif; ?>
        </div>
<?php
    }
}
else {
    ?>
    <div class="text-secondary">Nothing here yet!</div>
    <?php
}
?>
