<?php
include("../config/db.php");

$where = "WHERE 1";

if (!empty($_GET['search']))
    $where .= " AND item_name LIKE '%".$_GET['search']."%'";

if (!empty($_GET['type']))
    $where .= " AND type='".$_GET['type']."'";

$data = $conn->query("
    SELECT m.*, c.name AS category 
    FROM menu_items m 
    JOIN categories c ON m.category_id = c.id
    $where
");
?>
<!DOCTYPE html>
<html>
<body>
<h2>Our Menu</h2>

<form method="get">
    <input name="search" placeholder="Search item">
    <select name="type">
        <option value="">All</option>
        <option value="veg">Veg</option>
        <option value="nonveg">Non Veg</option>
    </select>
    <button>Search</button>
</form>

<hr>


<div class="row">
<?php while($row = $data->fetch_assoc()): ?>
    <div class="col-md-4 mb-4">
        <div class="card shadow h-100">
            <img src="../uploads/menu/<?= $row['image'] ?>" class="card-img-top">
            <div class="card-body">
                <h5>
                    <?= $row['item_name'] ?>
                    <?= $row['type'] == 'veg' ? '🥬' : '🍗' ?>
                </h5>
                <p><?= $row['category'] ?></p>
                <strong>₹<?= $row['price'] ?></strong>
            </div>
        </div>
    </div>


<hr>
<?php endwhile; ?>
</body>
</html>
