<div class="page-title">
    <h2><i class="bi bi-shield-lock"></i> Login Logs</h2>
</div>

<div class="card">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover table-sm">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>User</th>
                        <th>Role</th>
                        <th>IP Address</th>
                        <th>Browser</th>
                        <th>Device</th>
                        <th>Status</th>
                        <th>Date/Time</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (!empty($logs)): ?>
                        <?php foreach ($logs as $log): ?>
                            <tr>
                                <td><?= $log->id ?></td>
                                <td><?= $log->username ?? 'Unknown' ?></td>
                                <td><?= isset($log->role) ? ucfirst($log->role) : '-' ?></td>
                                <td><?= $log->ip_address ?></td>
                                <td><?= $log->browser ?></td>
                                <td><?= $log->device ?></td>
                                <td>
                                    <?php if ($log->status == 'success'): ?>
                                        <span class="badge bg-success">Success</span>
                                    <?php else: ?>
                                        <span class="badge bg-danger" title="<?= $log->failure_reason ?>">Failed</span>
                                    <?php endif; ?>
                                </td>
                                <td><?= date('M d, Y h:i A', strtotime($log->created_at)) ?></td>
                            </tr>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <tr>
                            <td colspan="8" class="text-center">No logs found</td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
