<?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 $review = $point->lastChildReview; ?>
<?php if ($review && @($review->data)) $review->data = json_decode($review->data); ?>
<tr>
<td class="width-300px">
	<?= $p['name'] ?>
</td>
<td class="width-300px">
<?php if(!!$review): ?>
    <div class="pl-3 d-flex align-items-baseline">
        <div>
            <?php if($p['category'] === 'FAST_FOOD'): ?>
                <div class=""><span class="text-sm">Meals per week:</span> <?= @$review->data->mealsPerWeek ? strip_tags($review->data->mealsPerWeek) : '' ?></div>
                <div class=""><span class="text-sm">Self-prepared meals per week:</span> <?= @$review->data->selfPrepMealsPerWeek ? strip_tags($review->data->selfPrepMealsPerWeek) : '' ?></div>
            <?php elseif ($p['category'] === 'SNACKS'): ?>
                <div class=""><span class="text-sm">Unhealthy snacks:</span> <?= @$review->data->unhealthySnacks ? strip_tags($review->data->unhealthySnacks) : '' ?></div>
                <div class=""><span class="text-sm">Healthy snacks:</span> <?= @$review->data->healthySnacks ? strip_tags($review->data->healthySnacks) : '' ?></div>
            <?php else: ?>
                <span>{!! $review->data->value ? strip_tags($review->data->value) : '-' !!}</span>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>
</td>
<td></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</table>
