<?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><?= $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; ?>
        </div>
<?php
    }
}
else {
    ?>
    <div class="text-secondary">Nothing here yet!</div>
    <?php
}
?>
