<div class="container mt-3">

    <h3>Attendance Logs</h3>

    <table class="table table-bordered table-striped">
        <thead class="table-light">
            <tr>
                <th>#</th>
                <th>User ID</th>
                <th>Timestamp</th>
                <th>Device ID</th>
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
        <?php if (!empty($attendance)): $i=1; foreach ($attendance as $row): ?>
            <tr>
                <td><?= $i++ ?></td>
                <td><?= htmlspecialchars($row->user_id) ?></td>
                <td><?= htmlspecialchars($row->timestamp) ?></td>
                <td><?= htmlspecialchars($row->device_id) ?></td>
                <td><?= htmlspecialchars($row->status) ?></td>
            </tr>
        <?php endforeach; else: ?>
            <tr><td colspan="5" class="text-center">No records found.</td></tr>
        <?php endif; ?>
        </tbody>
    </table>

    <hr>

    <h3>
        Distinct Users 
        <small class="text-muted">(<?= isset($user_count) ? $user_count : 0; ?>)</small>
    </h3>

    <table class="table table-bordered table-striped">
        <thead class="table-light">
            <tr>
                <th>#</th>
                <th>User ID</th>
            </tr>
        </thead>
        <tbody>
        <?php if (!empty($users)): $i=1; foreach ($users as $u): ?>
            <tr>
                <td><?= $i++ ?></td>
                <td><?= htmlspecialchars($u->user_id) ?></td>
            </tr>
        <?php endforeach; else: ?>
            <tr><td colspan="2" class="text-center">No users found.</td></tr>
        <?php endif; ?>
        </tbody>
    </table>

</div>
