<?php $this->extend("layouts/main"); $this->section("content"); $title = "Recycle Bin"; ?>
<div class="d-flex justify-content-between align-items-center mb-3">
    <form method="GET" class="d-flex gap-2">
        <select name="entity_type" class="form-select form-select-sm" style="width:150px"><option value="">All Types</option><?php foreach (["job","customer","quote","invoice"] as $et): ?><option value="<?php echo $et ?>" <?php echo ($entityType??"")===$et?"selected":"" ?>><?php echo ucfirst($et) ?></option><?php endforeach; ?></select>
        <button type="submit" class="btn btn-sm btn-outline-secondary">Filter</button>
    </form>
    <?php if (!empty($items)): ?>
    <form method="POST" action="/fieldly/public/index.php/bin/purge-all" data-confirm="Permanently delete ALL items in the recycle bin? This cannot be undone."><?php echo csrf_field() ?><button type="submit" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash3 me-1"></i> Empty Bin</button></form>
    <?php endif; ?>
</div>
<div class="card"><div class="card-body p-0"><table class="table table-hover mb-0">
<thead><tr><th>Type</th><th>Reference</th><th>Summary</th><th>Deleted</th><th></th></tr></thead>
<tbody>
<?php foreach ($items as $item): ?>
<tr>
    <td><span class="badge bg-light text-dark"><?php echo ucfirst(esc($item["entity_type"])) ?></span></td>
    <td style="font-size:13px"><?php echo esc($item["entity_ref"]) ?></td>
    <td style="font-size:13px"><?php echo esc($item["entity_summary"]) ?></td>
    <td style="font-size:12px"><?php echo date("d M Y H:i",strtotime($item["deleted_at"])) ?></td>
    <td>
        <div class="table-actions">
            <form method="POST" action="/fieldly/public/index.php/bin/<?php echo $item["id"] ?>/restore" class="d-inline"><?php echo csrf_field() ?><button class="btn btn-sm btn-outline-success"><i class="bi bi-arrow-counterclockwise me-1"></i> Restore</button></form>
            <form method="POST" action="/fieldly/public/index.php/bin/<?php echo $item["id"] ?>" data-confirm="Permanently delete this item? This cannot be undone." class="d-inline"><?php echo csrf_field() ?><button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash3"></i></button></form>
        </div>
    </td>
</tr>
<?php endforeach; ?>
<?php if (empty($items)): ?><tr><td colspan="5" class="text-center text-muted py-4"><i class="bi bi-trash3 d-block mb-2" style="font-size:24px"></i>Recycle bin is empty</td></tr><?php endif; ?>
</tbody>
</table></div></div>
<?php $this->endSection(); ?>