<?php
include 'config.php';
checkAdminAuth();

header('Content-Type: application/json');

if (isset($_GET['meal_id'])) {
    $meal_id = intval($_GET['meal_id']);
    
    // Get meal data
    $meal_result = $conn->query("SELECT * FROM meals WHERE id = '$meal_id'");
    $meal = $meal_result->fetch_assoc();
    
    // Get portions
    $portions_result = $conn->query("SELECT * FROM meal_portions WHERE meal_id = '$meal_id' ORDER BY price");
    $portions = [];
    while ($row = $portions_result->fetch_assoc()) {
        $portions[] = $row;
    }
    
    echo json_encode([
        'meal' => $meal,
        'portions' => $portions
    ]);
} else {
    echo json_encode(['error' => 'No meal ID provided']);
}
?>