<?php
header('Content-Type: application/json');
require_once 'config.php';

$customer_id = isset($_GET['customer_id']) ? intval($_GET['customer_id']) : 0;
$favorites = [];

if ($customer_id > 0) {
    $sql = "SELECT m.id, m.name, m.price, m.image 
            FROM favorites f
            JOIN menu_items m ON f.menu_item_id = m.id
            WHERE f.fav_customer_id = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("i", $customer_id);
    $stmt->execute();
    $result = $stmt->get_result();
    while ($row = $result->fetch_assoc()) {
        $favorites[] = $row;
    }
    $stmt->close();
}

echo json_encode(['success' => true, 'favorites' => $favorites]);
