<?= $this->include('/Styles/header'); ?>

<main class="p-6">
  <div class="bg-white shadow rounded-lg p-6">
      <h2 class="text-2xl font-bold mb-4">Admin Orders Report</h2>

      <!-- Date Filter Form -->
      <form method="get" class="flex gap-2 mb-4">
        <input type="date" name="from_date" value="<?= esc($from_date) ?>" class="border p-2 rounded">
        <input type="date" name="to_date" value="<?= esc($to_date) ?>" class="border p-2 rounded">
        <button type="submit" class="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700">Filter</button>
      </form>

      <!-- Status Filter Buttons -->
      <div class="mb-4 flex gap-2">
        <a href="<?= base_url('admin-report') ?>" class="bg-gray-600 text-white px-3 py-1 rounded hover:bg-gray-700">All</a>
        <a href="<?= base_url('admin-report/filter/Pending') ?>" class="bg-yellow-500 text-white px-3 py-1 rounded hover:bg-yellow-600">Pending</a>
        <a href="<?= base_url('admin-report/filter/Confirmed') ?>" class="bg-green-600 text-white px-3 py-1 rounded hover:bg-green-700">Confirmed</a>
        <a href="<?= base_url('admin-report/filter/Delivered') ?>" class="bg-blue-600 text-white px-3 py-1 rounded hover:bg-blue-700">Delivered</a>
      </div>

      <!-- Orders Table -->
      <table class="w-full border-collapse">
        <thead>
          <tr class="bg-gray-200">
            <th class="border px-4 py-2">Order ID</th>
            <th class="border px-4 py-2">Customer Name</th>
            <th class="border px-4 py-2">Phone</th>
            <th class="border px-4 py-2">Apartment</th>
            <th class="border px-4 py-2">Address</th>
            <th class="border px-4 py-2">Total Amount</th>
            <th class="border px-4 py-2">Payment Method</th>
            <th class="border px-4 py-2">Status</th>
            <th class="border px-4 py-2">Date</th>
          </tr>
        </thead>
        <tbody>
          <?php foreach($orders as $order): ?>
            <tr>
              <td class="border px-4 py-2"><?= $order['id'] ?></td>
              <td class="border px-4 py-2"><?= $order['customer_name'] ?></td>
              <td class="border px-4 py-2"><?= $order['phone'] ?></td>
              <td class="border px-4 py-2"><?= $order['apartName'] ?? 'N/A' ?></td>
              <td class="border px-4 py-2"><?= $order['apartAddress'] ?? 'N/A' ?></td>
              <td class="border px-4 py-2">₹<?= $order['total_amount'] ?></td>
              <td class="border px-4 py-2"><?= $order['payment_method'] ?></td>
              <td class="border px-4 py-2"><?= $order['status'] ?></td>
              <td class="border px-4 py-2"><?= $order['created_at'] ?></td>
            </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
  </div>
</main>

<?= $this->include('/Styles/footer'); ?>
