<?php
include 'db.php';

$action = $_POST['action'] ?? '';
$meal_id = intval($_POST['meal_id'] ?? 0);

if($action=='remove'){
    $recipe_id = intval($_POST['recipe_id'] ?? 0);
    $conn->query("DELETE FROM meal_recipes_assigned WHERE meal_id=$meal_id AND recipe_id=$recipe_id");
    exit('Recipe removed successfully.');
}

if($action=='add'){
    $recipe_id = intval($_POST['recipe_id'] ?? 0);
    $conn->query("INSERT INTO meal_recipes_assigned (meal_id, recipe_id) VALUES ($meal_id, $recipe_id)");
    exit('Recipe added successfully.');
}
