<?php use App\Helpers\Helper; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
  <div>
    <h1 class="admin-page-title">Maintenance Report</h1>
    <p class="text-muted small">Total Cost: <strong class="text-primary"><?= Helper::money($summary['total_cost']) ?></strong></p>
  </div>
  <div class="d-flex gap-2">
    <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="form-card mb-4">
  <form method="GET" class="row g-2 align-items-end">
    <div class="col-md-3"><label class="form-label">From</label><input type="date" name="from" class="form-control" value="<?= $from ?>"></div>
    <div class="col-md-3"><label class="form-label">To</label><input type="date" name="to" class="form-control" value="<?= $to ?>"></div>
    <div class="col-md-2"><button class="btn btn-primary w-100">Generate</button></div>
  </form>
</div>
<div class="row g-3 mb-4">
  <div class="col-md-4"><div class="admin-stat-card"><div class="stat-icon-wrap blue"><i class="bi bi-tools"></i></div><div><div class="stat-val"><?= $summary['total'] ?></div><div class="stat-lbl">Total Requests</div></div></div></div>
  <div class="col-md-4"><div class="admin-stat-card"><div class="stat-icon-wrap green"><i class="bi bi-check-circle"></i></div><div><div class="stat-val"><?= $summary['completed'] ?></div><div class="stat-lbl">Completed</div></div></div></div>
  <div class="col-md-4"><div class="admin-stat-card"><div class="stat-icon-wrap orange"><i class="bi bi-cash"></i></div><div><div class="stat-val" style="font-size:1.1rem"><?= Helper::money($summary['total_cost']) ?></div><div class="stat-lbl">Total Cost</div></div></div></div>
</div>
<div class="data-card">
  <div class="table-responsive">
    <table class="table mb-0" style="font-size:0.82rem">
      <thead><tr><th>Ref</th><th>Issue</th><th>Property/Unit</th><th>Tenant</th><th>Priority</th><th>Status</th><th>Actual Cost</th><th>Date</th></tr></thead>
      <tbody>
        <?php foreach ($data as $r): ?>
        <tr>
          <td class="fw-600 text-primary"><?= Helper::e($r['request_number']) ?></td>
          <td><?= Helper::e($r['title']) ?></td>
          <td class="text-muted"><?= Helper::e($r['property_name']) ?> / <?= Helper::e($r['unit_number']) ?></td>
          <td><?= Helper::e($r['tenant_name']??'—') ?></td>
          <td><?= Helper::statusBadge($r['priority']) ?></td>
          <td><?= Helper::statusBadge($r['status']) ?></td>
          <td class="fw-600"><?= Helper::money($r['actual_cost']??0) ?></td>
          <td class="text-muted"><?= Helper::date($r['created_at']) ?></td>
        </tr>
        <?php endforeach; ?>
        <?php if(empty($data)): ?><tr><td colspan="8" class="text-center text-muted py-4">No data in selected period.</td></tr><?php endif; ?>
      </tbody>
    </table>
  </div>
</div>
<style>@media print{.admin-topbar,.admin-sidebar,.form-card,.d-flex.mb-4{display:none!important}.admin-main{margin:0}}</style>
