<?php
$logs = isset($logs) ? $logs : array();
?>

<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="fw-bold mb-1"><i class="fa-solid fa-clock-rotate-left text-primary me-2"></i>Audit Logs &amp; Activity Trail</h4>
            <p class="text-muted mb-0">Immutable records of all mobile check-ins, routine executions, and administrative events.</p>
        </div>
    </div>

    <div class="card border-0 shadow-sm rounded-4">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="table-light">
                        <tr>
                            <th class="ps-4">Event / Routine</th>
                            <th>Staff ID</th>
                            <th>Store ID</th>
                            <th>Timestamp</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (empty($logs)): ?>
                            <tr>
                                <td colspan="5" class="text-center py-5 text-muted">No audit logs recorded yet.</td>
                            </tr>
                        <?php else: ?>
                            <?php foreach ($logs as $lId => $l): ?>
                                <tr>
                                    <td class="ps-4">
                                        <div class="fw-semibold text-dark"><i class="fa-solid fa-shield-halved text-success me-2"></i>Check-In Routine Completed</div>
                                        <div class="small text-muted font-monospace">Schedule: <?php echo htmlspecialchars(isset($l['scheduleId']) ? $l['scheduleId'] : '-'); ?></div>
                                    </td>
                                    <td>
                                        <span class="badge bg-light text-dark border"><?php echo htmlspecialchars(isset($l['staffId']) ? $l['staffId'] : 'N/A'); ?></span>
                                    </td>
                                    <td class="font-monospace small text-muted">
                                        <?php echo htmlspecialchars(isset($l['storeId']) ? $l['storeId'] : '-'); ?>
                                    </td>
                                    <td class="small text-muted">
                                        <?php echo isset($l['submittedAt']) ? date('M d, Y h:i:s A', $l['submittedAt'] / 1000) : '-'; ?>
                                    </td>
                                    <td>
                                        <span class="badge bg-success bg-opacity-10 text-success rounded-pill px-3 py-1"><?php echo ucfirst(isset($l['status']) ? $l['status'] : 'completed'); ?></span>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
