<?php

use App\Models\Point;

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

$selfMonitoring = Point::getOnlyPointOfCategory($patient, 'SELF_MONITORING');
$foodTriggers = Point::getOnlyPointOfCategory($patient, 'FOOD_TRIGGERS');
$cravings = Point::getOnlyPointOfCategory($patient, 'CRAVINGS');
$sleepHabits = Point::getOnlyPointOfCategory($patient, 'SLEEP_HABITS');

$points = [
    ["category" => 'SELF_MONITORING', "name" => 'Self Monitoring', "point" => $selfMonitoring],
    ["category" => 'FOOD_TRIGGERS', "name" => 'Food Triggers', "point" => $foodTriggers],
    ["category" => 'CRAVINGS', "name" => 'Cravings', "point" => $cravings],
    ["category" => 'SLEEP_HABITS', "name" => 'Sleep Habits', "point" => $sleepHabits],
];
?>
<table class="table table-bordered table-sm mb-0 table-cage">
    <?php foreach ($points as $p): ?>
    <?php $point = $p['point']; ?>
    <?php if(!!$point): ?>
    <?php $plan = $point->lastChildPlan; ?>
    <?php if ($plan && @($plan->data)) $plan->data = json_decode($plan->data); ?>
    <tr>
        <td class="width-300px">
            <?= $p['name'] ?>
        </td>
        <td class="width-300px">
            <?php if(!!$plan): ?>
            <div class="ml-3 inline-html-container">
                <?php $plan = $plan->data; ?>
                <?php include(resource_path('views/app/patient/segment-templates/_child_plan/behavior/' . $p['category'] . '/view-plan.php')); ?>
            </div>
            <?php endif; ?>
        </td>
        <td></td>
    </tr>
    <?php endif; ?>
    <?php endforeach; ?>
</table>
