<?php

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

$items = $patient->pages('medication', true, $note);

if($items && count($items)) {
    for ($i = 0; $i < count($items); $i++) {
        $page = $items[$i];
        $parsed = $page->data ? json_decode($page->data) : false;
        if(!!$parsed) {
        ?>
            <div class="mt-2 <?= !!@$parsed->removed_during_note_uid ? 'on-hover-opaque' : '' ?>">
                <div class="">
                    <b><?= $page->key ?></b>
                    <?= !!@$parsed->strength ? '/&nbsp;' . @$parsed->strength : '' ?>
                    <?= !!@$parsed->frequency ? '/&nbsp;' . @$parsed->frequency : '' ?>
                    <?php if(!!@$parsed->removed_during_note_uid): ?>
                        /&nbsp;<span class="text-warning-mellow text-sm mr-2 font-weight-bold">(Removed<?= @$parsed->removed_during_note_uid === $note->uid ? ' during this visit' : '' ?>)</span>
                        <?php if(!!@$parsed->removal_memo): ?>
                            <div class="text-sm text-secondary font-italic mt-1"><?= $parsed->removal_memo ?></div>
                        <?php endif; ?>
                    <?php elseif(!!@$parsed->was_existing_at_visit_start): ?>
                        /&nbsp;<span class="text-secondary text-sm mr-2 font-weight-bold">(Existing)</span>
                    <?php endif; ?>
                </div>
                <?php
                if (!@$parsed->removed_during_note_uid):
                    $detailPlain = @$parsed->detail ? $parsed->detail : '';
                    if(!!$detailPlain): ?>
                    <div class="text-secondary"><?= $detailPlain ?></div>
                    <?php endif; ?>
                <?php endif; ?>
            </div>
        <?php
        }
    }
}
else {
    echo '<div class="text-secondary">Nothing here yet!</div>';
}
?>
