<?php
require_once("models/res_order.class.php");
$msg = "";
if(isset($_POST['delete_id'])) {
  $id = $_POST['delete_id'];
  $msg = ResOrders::delete($id);
}




?>
<h1>Manage Orders</h1>
<a href="menu" class="btn btn-primary mb-3">Add New</a>

<?php if($msg) { ?>
<div class="alert alert-info alert-dismissible fade show" role="alert">
  <?php echo $msg; ?>
  <button type="button" class="btn-close" data-dismiss="alert" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php } ?>

<table class="table table-striped">
  <thead>
  <tr>
    <th>Id</th>
    <!-- <th>Order Id</th> -->
    <th>Table Id</th>
    <th>Total Amount</th>
    <!-- <th>Special Request</th> -->
    <th>Order Status Id</th>
    <th>Actions</th>
  </tr>
  </thead>
  <tbody>
<?php
$items = ResOrders::readAll();
foreach($items as $item){
    echo "<tr>";
    echo "<td>".$item['id']."</td>";
    echo "<td>".$item['table_name']."</td>";
    echo "<td>".$item['total_amount']."</td>";
    // echo "<td>".$item['special_request']."</td>";
    echo "<td><span class='badge bg-warning text-dark'>".$item['order_status']."</span></td>";


?>

    <td>
      <form action="invoice" method="get">
        <input type="hidden" name="id" value="<?php echo $item['id']; ?>">
        <input type="submit" class="btn btn-info" value="Invoice">
      </form>
      <form action="orders-edit.php" method="get">
        <input type="hidden" name="id" value="<?php echo $item['id']; ?>">
        <input type="submit" class="btn btn-primary" value="Edit">
      </form>
      <form method="post">
        <input type="hidden" name="delete_id" value="<?php echo $item['id']; ?>">
        <input type="submit" class="btn btn-danger" value="Delete">
      </form>
    </td>
  <?php
      echo "</tr>";
    }
  ?>
  </tbody>
</table>
