<?php $this->extend("layouts/main"); $this->section("content"); $title = "Activity Log"; ?>
<form method="GET" class="row g-2 mb-3">
    <div class="col-md-3"><select name="user_id" class="form-select"><option value="">All Users</option><?php foreach ($users as $u): ?><option value="<?php echo $u["id"] ?>" <?php echo ($userId??"")===$u["id"]?"selected":"" ?>><?php echo esc($u["first_name"]." ".$u["last_name"]) ?></option><?php endforeach; ?></select></div>
    <div class="col-md-2"><select name="entity_type" class="form-select"><option value="">All Types</option><?php foreach (["job","customer","invoice","quote","payment"] as $et): ?><option value="<?php echo $et ?>" <?php echo ($entityType??"")===$et?"selected":"" ?>><?php echo ucfirst($et) ?></option><?php endforeach; ?></select></div>
    <div class="col-md-2"><input type="date" name="date_from" class="form-control" value="<?php echo esc($dateFrom??"") ?>"/></div>
    <div class="col-md-2"><input type="date" name="date_to" class="form-control" value="<?php echo esc($dateTo??"") ?>"/></div>
    <div class="col-md-2"><input type="text" name="search" class="form-control" placeholder="Search..." value="<?php echo esc($search??"") ?>"/></div>
    <div class="col-md-1"><button type="submit" class="btn btn-outline-secondary w-100"><i class="bi bi-search"></i></button></div>
</form>
<div class="card"><div class="card-body p-0"><table class="table table-hover mb-0">
<thead><tr><th>Time</th><th>User</th><th>Action</th><th>Entity</th></tr></thead>
<tbody>
<?php foreach ($activity as $a): ?>
<tr>
    <td style="font-size:12px;white-space:nowrap"><?php echo date("d M Y H:i",strtotime($a["created_at"])) ?></td>
    <td style="font-size:13px"><?php echo esc($a["user_name"]) ?></td>
    <td style="font-size:13px"><?php echo esc($a["description"]) ?></td>
    <td><span class="badge bg-light text-dark"><?php echo esc($a["entity_type"]) ?></span></td>
</tr>
<?php endforeach; ?>
<?php if (empty($activity)): ?><tr><td colspan="4" class="text-center text-muted py-4">No activity</td></tr><?php endif; ?>
</tbody>
</table></div></div>
<?php $this->endSection(); ?>