<div class="d-flex justify-content-between align-items-center mb-3">
    <h5 class="fw-bold mb-0"><i class="fas fa-list-check me-2 text-primary"></i>Asset Types</h5>
    <a class="btn btn-sm btn-primary" href="<?= url('/AssetTypes/create') ?>"><i class="fas fa-plus me-1"></i>New Type</a>
</div>

<p class="text-muted small">Each type defines its own custom fields — the form users fill out when creating an asset of this type.</p>

<?php if (!empty($flash)): ?><div class="alert alert-info py-2 small"><?= e($flash) ?></div><?php endif; ?>

<div class="rs-card p-3">
<?php if (empty($types)): ?>
    <p class="text-muted small mb-0">No asset types yet.</p>
<?php else: ?>
    <table class="table table-sm table-hover mb-0">
        <thead><tr><th>Name</th><th>Code</th><th class="text-end">Fields</th><th class="text-end">Assets</th><th>Status</th><th></th></tr></thead>
        <tbody>
            <?php foreach ($types as $t): ?>
                <tr>
                    <td><span class="rs-swatch" style="background: <?= e($t['color'] ?? '#0f172a') ?>"></span><a href="<?= url('/AssetTypes/show/' . (int) $t['asset_type_id']) ?>" class="fw-semibold text-decoration-none"><?= e($t['name']) ?></a></td>
                    <td class="small"><code><?= e($t['code']) ?></code></td>
                    <td class="text-end"><?= (int) $t['field_count'] ?></td>
                    <td class="text-end"><?= (int) $t['asset_count'] ?></td>
                    <td><span class="badge bg-secondary text-uppercase"><?= e($t['status']) ?></span></td>
                    <td class="text-end"><a href="<?= url('/AssetTypes/edit/' . (int) $t['asset_type_id']) ?>" class="btn btn-sm btn-outline-primary"><i class="fas fa-pen"></i></a></td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
<?php endif; ?>
</div>
