
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2 class="mb-0">Log crona</h2>
    <span class="badge text-bg-secondary">Kanał: publish</span>
</div>

<form class="row g-2 mb-3" method="get" action="">
    <div class="col-auto">
        <select name="level" class="form-select">
            <option value="">Wszystkie poziomy</option>
            <option value="INFO" <?= $level === 'INFO' ? 'selected' : '' ?>>INFO</option>
            <option value="WARNING" <?= $level === 'WARNING' ? 'selected' : '' ?>>WARNING</option>
            <option value="ERROR" <?= $level === 'ERROR' ? 'selected' : '' ?>>ERROR</option>
        </select>
    </div>
    <div class="col-auto">
        <input type="date" name="date_from" class="form-control" value="<?= htmlspecialchars($dateFrom) ?>" placeholder="Od">
    </div>
    <div class="col-auto">
        <input type="date" name="date_to" class="form-control" value="<?= htmlspecialchars($dateTo) ?>" placeholder="Do">
    </div>
    <div class="col-auto">
        <button type="submit" class="btn btn-primary">Filtruj</button>
    </div>
</form>

<div class="card">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover mb-0 align-middle">
                <thead>
                    <tr>
                        <th style="width: 190px;">Data zdarzenia</th>
                        <th style="width: 110px;">Poziom</th>
                        <th>Zdarzenie</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (empty($events)): ?>
                        <tr>
                            <td colspan="3" class="text-center text-muted py-4">Brak zdarzeń w logach crona.</td>
                        </tr>
                    <?php else: ?>
                        <?php foreach ($events as $event): ?>
                            <tr>
                                <td class="text-nowrap"><?= htmlspecialchars($event['datetime']) ?></td>
                                <td>
                                    <?php if ($event['level'] === 'ERROR'): ?>
                                        <span class="badge text-bg-danger">ERROR</span>
                                    <?php elseif ($event['level'] === 'WARNING'): ?>
                                        <span class="badge text-bg-warning">WARNING</span>
                                    <?php else: ?>
                                        <span class="badge text-bg-success">INFO</span>
                                    <?php endif; ?>
                                </td>
                                <td><?= htmlspecialchars($event['message']) ?></td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?php if ($pages > 1): ?>
<nav class="mt-3">
    <ul class="pagination justify-content-center">
        <?php for ($i = 1; $i <= $pages; $i++): ?>
            <li class="page-item<?= $i === $page ? ' active' : '' ?>">
                <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $i])) ?>"><?= $i ?></a>
            </li>
        <?php endfor; ?>
    </ul>
</nav>
<?php endif; ?>
