<?php

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

$labels = [
    'general_no_health_concern' => 'No health concern',
    'general_arthritis' => 'Arthritis',
    'general_asthma' => 'Asthma',
    'general_bleeding_disorder' => 'Bleeding disorder',
    'general_cad_lt_age_55' => 'CAD &gt; age 55',
    'general_copd' => 'COPD',
    'general_diabetes' => 'Diabetes',
    'general_heart_attack' => 'Heart attack',
    'general_heart_disease' => 'Heart disease',
    'general_high_cholesterol' => 'High cholesterol',
    'general_hypertension' => 'Hypertension',
    'general_mental_illness' => 'Mental illness',
    'general_osteoporosis' => 'Osteoporosis',
    'general_stroke' => 'Stroke',
    'cancer_breast_ca' => 'Breast cancer',
    'cancer_colon_ca' => 'Colon cancer',
    'cancer_other_ca' => 'Other cancer',
    'cancer_ovarian_ca' => 'Ovarian cancer',
    'cancer_uterine_ca' => 'Uterine cancer',
];

$point = Point::getOnlyTopLevelPointOfCategory($note, 'FAMILY_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['unknown'] && !!$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">
                <?php
                for ($i = 0; $i < $contentData['count']; $i++) {
                    ?>
                    <div class="<?= $i > 0 ? 'mt-2' : '' ?>">
                        <div class="">
                            <b><?= isset($contentData['items'][$i]['relationship']) ? $contentData['items'][$i]['relationship'] : '--' ?></b>
                            <?php if(isset($contentData['items'][$i]['status']) && !empty($contentData['items'][$i]['status'])): ?>
                            <span class="ml-1 text-secondary">(<?= $contentData['items'][$i]['status'] ?>)</span>
                            <?php endif; ?>
                        </div>
                        <div class="ml-3">
                            <?php
                            $positives = [];
                            $negatives = [];
                            foreach ($labels as $k => $v) {
                                if(isset($contentData['items'][$i][$k])) {
                                    if(strtolower($contentData['items'][$i][$k]) === 'yes') {
                                        $positives[] = $v;
                                    }
                                    else {
                                        $negatives[] = $v;
                                    }
                                }
                            }
                            ?>
                            @if(count($positives))
                                <div class="pt-1"><b>Positive for</b>: {!!  implode(', ', $positives) !!}</div>
                            @endif
                            @if(count($negatives))
                                <div class="pt-1"><b>Negative for</b>: {!!  implode(', ', $negatives) !!}</div>
                            @endif
                        </div>
                        <?php if(isset($contentData['items'][$i]['comments']) && !empty($contentData['items'][$i]['comments'])): ?>
                        <div class="ml-3 pt-1 client-rs-contents">
                            <b>Comments: </b><?= $contentData['items'][$i]['comments'] ?>
                        </div>
                        <?php endif; ?>
                    </div>
                    <?php
                }
                ?>
                </div>
                <?php
            }
        }
    }
    ?> </div> <?php
}