@extends('layouts.app') @php $locale = app()->getLocale(); // Handle name: could be JSON {"en":"..","ar":".."} or plain string $rawName = $plan->name ?? ''; if (is_string($rawName)) { $decoded = json_decode($rawName, true); $planName = is_array($decoded) ? ($decoded[$locale] ?? $decoded['en'] ?? $rawName) : $rawName; } elseif (is_array($rawName)) { $planName = $rawName[$locale] ?? $rawName['en'] ?? ''; } else { $planName = (string) $rawName; } $planName = $planName ?: 'Meal Plan'; // Handle description: same logic $rawDesc = $plan->description ?? ''; if (is_string($rawDesc)) { $decoded = json_decode($rawDesc, true); $planDesc = is_array($decoded) ? ($decoded[$locale] ?? $decoded['en'] ?? $rawDesc) : $rawDesc; } elseif (is_array($rawDesc)) { $planDesc = $rawDesc[$locale] ?? $rawDesc['en'] ?? ''; } else { $planDesc = (string) $rawDesc; } // Get image URL — API returns full URL $planImage = $plan->image_url ?? ''; $planImageUrl = (str_starts_with($planImage, 'http')) ? $planImage : ($planImage ? asset($planImage) : asset('assets/images/plan-1.png')); $images = $plan->images ?? [$planImageUrl]; if (empty($images[0])) { $images = [$planImageUrl]; } // Meal types $mealTypes = [ ['id' => 'breakfast', 'name' => __('Breakfast')], ['id' => 'lunch', 'name' => __('Lunch')], ['id' => 'dinner', 'name' => __('Dinner')], ['id' => 'snack', 'name' => __('Snack')], ]; // Calorie options — prefer API data, fallback to program data if (!empty($apiCalories)) { $calorieOptions = array_map(function ($cal) { $min = $cal['min_amount'] ?? 0; $max = $cal['max_amount'] ?? 0; $range = $min && $max ? "{$min}-{$max}" : ($max ?: $min); return ['range' => $range, 'label' => $range . ' ' . __('kcal'), 'id' => $cal['id'] ?? 0, 'macros' => $cal['macros'] ?? null]; }, $apiCalories); } elseif (!empty($plan->calorie_options)) { $calorieOptions = $plan->calorie_options; } else { $calorieOptions = [ ['range' => ($plan->calories_min ?? 700) . '-' . ($plan->calories_max ?? 800), 'label' => ($plan->calories_min ?? 700) . '-' . ($plan->calories_max ?? 800) . ' ' . __('kcal')], ]; } // Nutritional info — build from first calorie option macros or API program data $firstMacros = $calorieOptions[0]['macros'] ?? null; if ($firstMacros) { $totalMacros = ($firstMacros['protein'] ?? 0) + ($firstMacros['carbs'] ?? 0) + ($firstMacros['fats'] ?? $firstMacros['fat'] ?? 0); $nutrition = [ 'carbs' => [ 'amount' => ($firstMacros['carbs'] ?? 0) . 'g', 'percent' => $totalMacros > 0 ? round(($firstMacros['carbs'] ?? 0) / $totalMacros * 100) : 33, 'color' => 'bg-green', ], 'protein' => [ 'amount' => ($firstMacros['protein'] ?? 0) . 'g', 'percent' => $totalMacros > 0 ? round(($firstMacros['protein'] ?? 0) / $totalMacros * 100) : 33, 'color' => 'bg-yellow', ], 'fat' => [ 'amount' => ($firstMacros['fats'] ?? $firstMacros['fat'] ?? 0) . 'g', 'percent' => $totalMacros > 0 ? round(($firstMacros['fats'] ?? $firstMacros['fat'] ?? 0) / $totalMacros * 100) : 33, 'color' => 'bg-red', ], ]; } else { $nutrition = $plan->nutrition ?? [ 'carbs' => ['amount' => '—', 'percent' => 33, 'color' => 'bg-green'], 'protein' => ['amount' => '—', 'percent' => 33, 'color' => 'bg-yellow'], 'fat' => ['amount' => '—', 'percent' => 33, 'color' => 'bg-red'], ]; } // Default meal includes based on type $mealIncludes = [ 'breakfast' => [ __('Fresh breakfast dish (protein + carbs)'), __('Healthy side (fruit or grains)'), __('Low-calorie sauce or spread'), ], 'lunch' => [ __('Main protein dish'), __('Side salad or vegetables'), __('Healthy carbohydrate portion'), ], 'dinner' => [ __('Lean protein main course'), __('Steamed vegetables'), __('Light carbohydrate serving'), ], 'snack' => [ __('Healthy snack portion'), __('Protein-rich option'), __('Fresh fruit or nuts'), ], ]; // Calculate start date (next day) $startDate = now()->addDay()->format('Y-m-d'); $startDateDisplay = now()->addDay()->format('D d M'); // Prices from API are already VAT-inclusive (like mobile app) $planPrice = $plan->price ?? 2200; $offerPrice = $plan->offer_price ?? 0; $vatRate = (float) \App\Models\Settings\Setting::getValue('vat_rate', 15) / 100; // Price is already inclusive of VAT — extract VAT for display $planPriceInclVat = $planPrice; $vatInPrice = round($planPrice - ($planPrice / (1 + $vatRate)), 2); $deliveryFee = 0; // delivery included in plan subscription $totalPrice = $planPriceInclVat; @endphp @section('title', $planName . ' | ' . $siteName) @section('description', Str::limit(strip_tags($planDesc), 160)) @section('content')
{{-- Breadcrumb --}}
{{-- Image Gallery --}}
{{-- Plan Details & Options --}}
{{-- Plan Title --}}

{{ $planName }}

{{ $planDesc ?: __('Nutritionist-designed meal plans for safe, sustainable weight loss.') }}

{{-- Meal Type Selection --}}

{{ __('Choose your meal type') }}

@foreach($mealTypes as $type)
first ? 'checked' : '' }}>
@endforeach
{{-- Dynamic Includes based on meal type --}}
{{-- Start Date --}}

{{ __('Start your plan as soon as') }}

{{-- Calories Selection --}}

{{ __('Choose calories') }}

@foreach($calorieOptions as $option)
first ? 'checked' : '' }}>
@endforeach
{{-- Nutritional Info (dynamic based on selected calorie) --}}

{{ __('Nutritional info') }}

{{ __('Carbs') }}

{{ __('Protein') }}

{{ __('Fat') }}

{{-- Duration Selection --}}

{{ __('Choose Duration') }}

{{-- Payment Summary --}}

{{ __('Payment Summary') }}

{{ __('Plan Price') }} ({{ __('Incl. VAT') }})

SAR

{{ __('VAT included') }} ({{ (int)(\App\Models\Settings\Setting::getValue('vat_rate', 15)) }}%)

SAR

{{ __('Total') }}

SAR

{{-- Accordions --}}
{{-- Description --}}
@if($planDesc) {!! nl2br(e($planDesc)) !!} @else

{{ __('A calorie-controlled meal plan designed by nutritionists to support safe, sustainable weight loss. Enjoy balanced, portioned meals delivered daily to help you stay consistent and reach your goals with ease.') }}

@endif
{{-- Ingredients --}}
{{-- Benefits --}}
@endsection @push('styles') @endpush @push('scripts') @endpush