<?php $pageTitle='Users'; ?>
<div class="panel">
<?php $title='User Access & Portals';$eyebrow='Administration';$searchAction=url('/users');$createUrl=url('/users/create');$createText='Add User';require app_path('Views/components/search_header.php'); ?>
<div class="table-wrap"><table><thead><tr><th>User</th><th>Portal / Department</th><th>Linked Profile</th><th>Status</th><th>Last Login</th><th class="text-right">Actions</th></tr></thead><tbody>
<?php foreach($users as $record): ?><tr><td><strong><?= e($record['name']) ?></strong><br><small><?= e($record['email']) ?><?= !empty($record['phone'])?' · '.e($record['phone']):'' ?></small></td><td><strong><?= e(readable_status($record['role'])) ?> Portal</strong><br><small><?= e($record['department']??'-') ?></small></td><td><?php if(!empty($record['driver_name'])): ?>Driver: <?= e($record['driver_name']) ?><?php elseif(!empty($record['carrier_name'])): ?>Carrier: <?= e($record['carrier_name']) ?><?php else: ?>-<?php endif; ?></td><td><span class="badge badge-<?= status_class($record['status']) ?>"><?= e(readable_status($record['status'])) ?></span></td><td><?= e(datetime_display($record['last_login_at']??null)) ?></td><td class="text-right table-actions"><a class="btn btn-light btn-sm" href="<?= url('/users/edit?id='.$record['id']) ?>">Edit</a><?php if((int)$record['id']!==(int)($_SESSION['user_id']??0)): ?><form method="post" action="<?= url('/users/delete') ?>" onsubmit="return confirm('Delete this user?')"><?= csrf_field() ?><input type="hidden" name="id" value="<?= e((string)$record['id']) ?>"><button class="btn btn-danger btn-sm" type="submit">Delete</button></form><?php endif; ?></td></tr><?php endforeach; ?><?php if(!$users): ?><tr><td colspan="6" class="empty">No users found.</td></tr><?php endif; ?></tbody></table></div>
</div>
