<?php
$pageTitle = 'Rent Report';
include __DIR__ . '/../layouts/header.php';
?>

<div class="d-flex justify-content-between mb-4">
    <h2><i class="bi bi-house me-2"></i>Rent Collection Report</h2>
    <a href="<?= $this->baseUrl('/reports') ?>" class="btn btn-outline-secondary">Back to Reports</a>
</div>

<form class="row g-3 mb-4">
    <div class="col-md-3"><label class="form-label">From</label><input type="date" name="from" class="form-control" value="<?= htmlspecialchars($fromDate) ?>"></div>
    <div class="col-md-3"><label class="form-label">To</label><input type="date" name="to" class="form-control" value="<?= htmlspecialchars($toDate) ?>"></div>
    <div class="col-md-2 align-self-end"><button type="submit" class="btn btn-primary">Filter</button></div>
    <div class="col-md-4 text-end align-self-end"><h4>Total Collected: <span class="text-success"><?= number_format($total, 2) ?> KES</span></h4></div>
</form>

<div class="card">
    <div class="card-body p-0">
        <table class="table table-hover mb-0">
            <thead class="table-light">
                <tr><th>Property</th><th>Tenant</th><th>Payments</th><th class="text-end">Total Collected</th></tr>
            </thead>
            <tbody>
                <?php foreach ($rentData as $r): ?>
                <tr>
                    <td><?= htmlspecialchars($r['property']) ?></td>
                    <td><?= htmlspecialchars($r['tenant_name'] ?? '—') ?></td>
                    <td><?= $r['payments'] ?></td>
                    <td class="text-end fw-bold"><?= number_format($r['total_collected'], 2) ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

<?php include __DIR__ . '/../layouts/footer.php'; ?>