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

$query = $_GET['query'] ?? '';
$dishes = [];

if ($query) {
    $like = '%' . $conn->real_escape_string($query) . '%';
    $sql = "SELECT id, name, price, image, dish_description FROM menu_items WHERE name LIKE ? OR dish_description LIKE ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("ss", $like, $like);
    $stmt->execute();
    $result = $stmt->get_result();
    while ($row = $result->fetch_assoc()) {
        $dishes[] = $row;
    }
    $stmt->close();
}

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