@extends('layouts.portal') @php // Every menu renders as recipe cards; one built from the recipe library // (RecipeMenuService) also has a whole dish per meal and can be re-rolled. $isRecipeMenu = ($menu->generation_input['source'] ?? null) === \App\Services\RecipeMenuService::SOURCE; @endphp @push('head') @include('portal.menus._recipe-styles') @endpush @section('title', ($menu->title ?? __('menus.title')) . ' — ' . config('app.name')) @section('page_title', $menu->title ?? $menu->dietType?->name) @section('page_subtitle', $menu->patient?->full_name . ' · ' . $menu->starts_on?->format('Y-m-d') . ' · ' . $menu->duration_days . ' ' . __('common.days')) @section('page_actions') @unless ($menu->isIssued()) @if ($isRecipeMenu)
@csrf
@endif
@csrf
@endunless {{ __('common.back') }} @endsection @section('content') {{-- Calorie & macro preview — editable after generation. Daily EER (target_calories) and the protein/carbs/fat split can be nudged by the consultant without regenerating the whole meal structure; the split is entered as percentages and must add up to 100%, mirroring the onsite-consultation wizard's macro sliders. Grams shown here and saved to the menu are recomputed from calories × percent (protein/carbs at 4 kcal/g, fat at 9 kcal/g) — same formulas as NutritionCalculator::macros(). --}} @php $proteinPercent = $menu->target_calories > 0 ? round(($menu->protein_g * 4 / $menu->target_calories) * 100) : 25; $carbsPercent = $menu->target_calories > 0 ? round(($menu->carbs_g * 4 / $menu->target_calories) * 100) : 45; $fatPercent = $menu->target_calories > 0 ? round(($menu->fat_g * 9 / $menu->target_calories) * 100) : 30; @endphp

{{ __('patients.nutrition_preview') }}

@error('macro_percent')

{{ $message }}

@enderror {{-- Read-only view --}}

{{ __('patients.target_calories') }}

{{ number_format($menu->target_calories) }}

@foreach ([['protein', $menu->protein_g, $proteinPercent], ['carbs', $menu->carbs_g, $carbsPercent], ['fat', $menu->fat_g, $fatPercent]] as [$label, $value, $pct])

{{ __('patients.' . $label) }}

{{ $value }}{{ __('common.grams') }}

{{ $pct }}%

@endforeach
{{-- Edit form --}}
{{-- Day by day --}}
@foreach ($days as $index => $day) @php $total = $totals[$index] ?? null; @endphp {{-- Meals are cards of their own, so the day isn't boxed. --}}

{{ __('common.day') }} {{ $day['day'] }} {{ $menu->starts_on?->copy()->addDays($day['day'] - 1)->format('D, d M') }}

@if ($total) {{-- Only the figures are LTR; each label stays in the page's direction so Arabic reads "136.5 جم بروتين", not reversed. --}}
{{ number_format($total['calories']) }} {{ __('common.kcal') }} @foreach (['protein', 'carbs', 'fat'] as $macro) {{ $total[$macro . '_g'] }}{{ __('common.grams') }} {{ __('patients.' . $macro) }} @endforeach {{ round(collect($day['meals'])->flatMap(fn ($m) => $m['items'])->sum('fiber_g'), 1) }}{{ __('common.grams') }} {{ __('menus.recipes.fiber') }}
@endif
@once @include('portal.menus._recipe-icons') @endonce @if (! empty($day['warnings']))
@foreach ($day['warnings'] as $warning)

{{ $warning }}

@endforeach
@endif
@foreach ($day['meals'] as $meal) @include('portal.menus._recipe-meal', ['meal' => $meal, 'menu' => $menu, 'isRecipeMenu' => $isRecipeMenu]) @endforeach
@endforeach
{{-- Email the full menu (targets, per-day totals, every meal with its component breakdown and a calorie bar) straight to the visitor. --}}

{{ __('menus.email_menu') }}

@csrf
@error('email')

{{ $message }}

@enderror
@can('delete', $menu->patient)
@csrf @method('DELETE')
@endcan @endsection