<?php
if(!@$sessionKey) {
    $sessionKey = request()->cookie('sessionKey');
}
$point = App\Models\Point::getOrCreateOnlyTopLevelPointOfCategory($note, 'TYPICAL_DAY_LIFESTYLE', $sessionKey, true);
$contentData = [
    "lines" => [
        [
            "S" => '',
            "I" => '',
            "P" => '',
        ]
    ],
    "estimated_daily_calories" => [
        "S" => '',
        "P" => '',
    ],
    "estimated_daily_protein_grams" => [
        "S" => '',
        "P" => '',
    ],
    "estimated_daily_vegetable_servings" => [
        "S" => '',
        "P" => '',
    ],
    "estimated_daily_hours_of_sleep" => [
        "S" => '',
        "P" => '',
    ]
];
if ($point->lastChildReview && $point->lastChildReview->data) {
    $point->lastChildReview->data = json_decode($point->lastChildReview->data, true);
    $contentData = $point->lastChildReview->data;
}
$hasTypicalDayData = false;
if(@$contentData["lines"] && count($contentData["lines"])) {
    foreach(@$contentData["lines"] as $line) {
        if(!!@$line['S']) {
            $hasTypicalDayData = true;
            break;
        }
    }
}
$hasDailyAggregates = (
    @$contentData["estimated_daily_calories"]["S"] ||
    @$contentData["estimated_daily_calories"]["P"] ||
    @$contentData["estimated_daily_protein_grams"]["S"] ||
    @$contentData["estimated_daily_protein_grams"]["P"] ||
    @$contentData["estimated_daily_vegetable_servings"]["S"] ||
    @$contentData["estimated_daily_vegetable_servings"]["P"] ||
    @$contentData["estimated_daily_hours_of_sleep"]["S"] ||
    @$contentData["estimated_daily_hours_of_sleep"]["P"]
);
?>
<div class="events-none form-read-mode">
    @if($hasTypicalDayData)
        <div class="mb-1 font-weight-bold">Typical Day</div>
        <table class="table table-sm table-bordered mb-3">
            <tbody>
            @foreach(@$contentData["lines"] as $line)
                @if($line['S'])
                <tr>
                    <td><pre class="m-0">{{$line['S']}}&nbsp;</pre></td>
                </tr>
                @endif
            @endforeach
            </tbody>
        </table>
    @endif

    @if($hasDailyAggregates)
        <div class="mb-1 font-weight-bold">Daily Aggregates</div>
        <table class="table table-sm table-bordered mb-2">
            <thead class="bg-light">
            <tr>
                <th class="border-bottom-0 text-secondary width-200px">Subject</th>
                <th class="border-bottom-0 text-secondary">Current</th>
                <th class="border-bottom-0 text-secondary w-50">Target</th>
            </tr>
            </thead>
            <tbody>
            @if(@$contentData["estimated_daily_calories"]["S"] || @$contentData["estimated_daily_calories"]["P"])
            <tr>
                <td class="pl-1 align-middle bg-light">Est. Daily Calories</td>
                <td><pre class="m-0">{{@$contentData["estimated_daily_calories"]["S"]}}</pre></td>
                <td><pre class="m-0">{{@$contentData["estimated_daily_calories"]["P"]}}</pre></td>
            </tr>
            @endif
            @if(@$contentData["estimated_daily_protein_grams"]["S"] || @$contentData["estimated_daily_protein_grams"]["P"])
            <tr>
                <td class="pl-1 align-middle bg-light">Est. Daily Protein Grams</td>
                <td><pre class="m-0">{{@$contentData["estimated_daily_protein_grams"]["S"]}}</pre></td>
                <td><pre class="m-0">{{@$contentData["estimated_daily_protein_grams"]["P"]}}</pre></td>
            </tr>
            @endif
            @if(@$contentData["estimated_daily_vegetable_servings"]["S"] || @$contentData["estimated_daily_vegetable_servings"]["P"])
            <tr>
                <td class="pl-1 align-middle bg-light">Est. Daily Vegetable Servings</td>
                <td><pre class="m-0">{{@$contentData["estimated_daily_vegetable_servings"]["S"]}}</pre></td>
                <td><pre class="m-0">{{@$contentData["estimated_daily_vegetable_servings"]["P"]}}</pre></td>
            </tr>
            @endif
            @if(@$contentData["estimated_daily_hours_of_sleep"]["S"] || @$contentData["estimated_daily_hours_of_sleep"]["P"])
            <tr>
                <td class="pl-1 align-middle bg-light">Est. Daily Hours Of Sleep</td>
                <td><pre class="m-0">{{@$contentData["estimated_daily_hours_of_sleep"]["S"]}}</pre></td>
                <td><pre class="m-0">{{@$contentData["estimated_daily_hours_of_sleep"]["P"]}}</pre></td>
            </tr>
            @endif
            </tbody>
        </table>
    @endif

    @if(!$hasTypicalDayData && !$hasDailyAggregates)
        -
    @endif
</div>
