<?php use App\Helpers\Helper; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
  <h1 class="admin-page-title">Tenant List Report</h1>
  <div class="d-flex gap-2">
    <form method="GET" class="d-flex gap-2">
      <select name="status" class="form-select form-select-sm" style="width:130px">
        <?php foreach (['active','inactive','blacklisted'] as $s): ?><option value="<?= $s ?>" <?= $status===$s?'selected':'' ?>><?= ucfirst($s) ?></option><?php endforeach; ?>
      </select>
      <button class="btn btn-sm btn-primary">Filter</button>
    </form>
    <button onclick="window.print()" class="btn btn-outline-primary btn-sm"><i class="bi bi-printer me-1"></i>Print</button>
    <a href="<?= APP_URL ?>/admin/reports" class="btn btn-outline-secondary btn-sm"><i class="bi bi-arrow-left me-1"></i>Back</a>
  </div>
</div>
<div class="data-card">
  <div class="table-responsive">
    <table class="table mb-0" style="font-size:0.82rem">
      <thead><tr><th>#</th><th>Code</th><th>Name</th><th>Phone</th><th>Unit</th><th>Property</th><th>Lease Start</th><th>Lease End</th><th>Monthly Rent</th><th>Status</th></tr></thead>
      <tbody>
        <?php foreach ($tenants as $i=>$t): ?>
        <tr>
          <td><?= $i+1 ?></td>
          <td class="fw-600 text-primary"><?= Helper::e($t['tenant_code']) ?></td>
          <td class="fw-600"><?= Helper::e($t['first_name'].' '.$t['last_name']) ?></td>
          <td><?= Helper::e($t['phone']) ?></td>
          <td><?= Helper::e($t['unit_number']??'—') ?></td>
          <td class="text-muted"><?= Helper::e($t['property_name']??'—') ?></td>
          <td><?= $t['start_date'] ? Helper::date($t['start_date']) : '—' ?></td>
          <td><?= $t['end_date'] ? Helper::date($t['end_date']) : '—' ?></td>
          <td><?= $t['monthly_rent'] ? Helper::money($t['monthly_rent']) : '—' ?></td>
          <td><?= Helper::statusBadge($t['status']) ?></td>
        </tr>
        <?php endforeach; ?>
        <?php if(empty($tenants)): ?><tr><td colspan="10" class="text-center text-muted py-4">No tenants found.</td></tr><?php endif; ?>
      </tbody>
    </table>
  </div>
</div>
<style>@media print{.admin-topbar,.admin-sidebar,.d-flex.mb-4{display:none!important}.admin-main{margin:0}}</style>
