<?php

use App\Models\Point;

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

$highSugarBeverages = Point::getOnlyPointOfCategory($patient, 'HIGH_SUGAR_BEVERAGES');
$waterIntake = Point::getOnlyPointOfCategory($patient, 'WATER_INTAKE');
$fastFood = Point::getOnlyPointOfCategory($patient, 'FAST_FOOD');
$snacks = Point::getOnlyPointOfCategory($patient, 'SNACKS');
$vegetables = Point::getOnlyPointOfCategory($patient, 'VEGETABLES');
$portionSizes = Point::getOnlyPointOfCategory($patient, 'PORTION_SIZES');
$dailyIntakeCarbohydrates = Point::getOnlyPointOfCategory($patient, 'DAILY_INTAKE_CARBOHYDRATES');
$dailyIntakeCalories = Point::getOnlyPointOfCategory($patient, 'DAILY_INTAKE_CALORIES');

$points = [
    ["category" => 'HIGH_SUGAR_BEVERAGES', "name" => 'Beverages', "point" => $highSugarBeverages],
    ["category" => 'WATER_INTAKE', "name" => 'Water Intake', "point" => $waterIntake],
    ["category" => 'FAST_FOOD', "name" => 'Fast Food', "point" => $fastFood],
    ["category" => 'SNACKS', "name" => 'Snacks', "point" => $snacks],
    ["category" => 'VEGETABLES', "name" => 'Vegetables', "point" => $vegetables],
    ["category" => 'PORTION_SIZES', "name" => 'Portion Sizes', "point" => $portionSizes],
    ["category" => 'DAILY_INTAKE_CARBOHYDRATES', "name" => 'Daily Intake Carbohydrates', "point" => $dailyIntakeCarbohydrates],
    ["category" => 'DAILY_INTAKE_CALORIES', "name" => 'Daily Intake Calories', "point" => $dailyIntakeCalories],
];
?>

<?php if(!count($points)): ?>
    <span>-</span>
<?php endif ?>
<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">
                <span>{!! $plan->data->value ? strip_tags($plan->data->value) : '-' !!}</span>
            </div>
            <?php endif; ?>
        </td>
        <td></td>
    </tr>
    <?php endif; ?>
    <?php endforeach; ?>
</table>
