<?php
session_start();
header('Content-Type: application/json');

$ingredient_id = $_POST['ingredient'];
$name = $_POST['name'];
$unit = $_POST['unit'];
$cost_price = $_POST['cost_price'];
$quantity = $_POST['quantity'];

// Check if session variable exists
if (!isset($_SESSION['food_items'])) {
    $_SESSION['food_items'] = [];
}

// Add ingredient to session
$_SESSION['food_items'][] = [
    'ingredient_id' => $ingredient_id,
    'name' => $name,
    'unit' => $unit,
    'cost_price' => $cost_price,
    'quantity_required' => $quantity
];

$response = [
    'status' => 'success',
    'food_items' => $_SESSION['food_items']
];

echo json_encode($response);
?>
