<div class="container-fluid py-4">

    <div class="card border-0 shadow-sm">

        <div class="card-body">

            <h2 class="mb-4">
                <i class="fa-solid fa-triangle-exclamation text-warning"></i>
                Governance Alert Center
            </h2>

            <?php if (empty($alerts)): ?>

                <div class="alert alert-info">
                    No governance alerts found.
                </div>

            <?php else: ?>

                <div class="table-responsive">

                    <table class="table table-bordered table-hover align-middle">

                        <thead class="table-dark">

                        <tr>

                            <th width="80">ID</th>

                            <th width="120">Conference</th>

                            <th>Status</th>

                            <th>Message</th>

                            <th width="120">Severity</th>

                            <th width="120">State</th>

                            <th width="180">Created</th>

                        </tr>

                        </thead>

                        <tbody>

                        <?php foreach ($alerts as $a): ?>

                            <tr>

                                <td>
                                    <?= (int)($a['id'] ?? 0) ?>
                                </td>

                                <td>
                                    <?= (int)($a['conference_id'] ?? 0) ?>
                                </td>

                                <td>
                                    <?= htmlspecialchars($a['status'] ?? '') ?>
                                </td>

                                <td>
                                    <?= htmlspecialchars($a['message'] ?? '') ?>
                                </td>

                                <td>

                                    <?php
                                    $severity =
                                        strtolower(
                                            (string)($a['severity'] ?? 'low')
                                        );
                                    ?>

                                    <?php if ($severity === 'critical'): ?>

                                        <span class="badge bg-danger">
                                            Critical
                                        </span>

                                    <?php elseif ($severity === 'high'): ?>

                                        <span class="badge bg-warning text-dark">
                                            High
                                        </span>

                                    <?php elseif ($severity === 'medium'): ?>

                                        <span class="badge bg-info text-dark">
                                            Medium
                                        </span>

                                    <?php else: ?>

                                        <span class="badge bg-secondary">
                                            Low
                                        </span>

                                    <?php endif; ?>

                                </td>

                                <td>

                                    <?php if (!empty($a['is_resolved'])): ?>

                                        <span class="badge bg-success">
                                            Resolved
                                        </span>

                                    <?php else: ?>

                                        <span class="badge bg-danger">
                                            Open
                                        </span>

                                    <?php endif; ?>

                                </td>

                                <td>
                                    <?= htmlspecialchars($a['created_at'] ?? '') ?>
                                </td>

                            </tr>

                        <?php endforeach; ?>

                        </tbody>

                    </table>

                </div>

            <?php endif; ?>

        </div>

    </div>

</div>
