<?php

declare(strict_types=1);

require_once __DIR__ . '/helpers.php';

protest_module_boot();

$pageTitle = 'Protests';
$protests = protest_list();

require dirname(__DIR__, 2) . '/includes/header.php';
require dirname(__DIR__, 2) . '/includes/sidebar.php';
require dirname(__DIR__, 2) . '/includes/topbar.php';
require dirname(__DIR__, 2) . '/includes/flash.php';
?>
<section class="panel-card">
    <div class="panel-card-header mb-3">
        <div>
            <h2 class="h4 mb-0">Protests management</h2>
        </div>
        <a class="btn btn-jlfc" href="<?php echo e(base_url('app/modules/protests/create.php')); ?>"><i class="bi bi-file-earmark-plus"></i> Add protest</a>
    </div>
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
                <tr>
                    <th>Protest</th>
                    <th>Fixture</th>
                    <th>Competition</th>
                    <th>Status</th>
                    <th>Evidence</th>
                    <th class="text-end">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($protests === []): ?>
                    <tr>
                        <td colspan="6" class="text-center text-muted py-4">No protest records found.</td>
                    </tr>
                <?php endif; ?>
                <?php foreach ($protests as $protest): ?>
                    <tr>
                        <td>
                            <strong><?php echo e($protest['title']); ?></strong>
                            <div class="small text-muted"><?php echo e($protest['protesting_club_name']); ?> vs <?php echo e($protest['against_club_name']); ?></div>
                        </td>
                        <td>
                            Matchday <?php echo e((string) $protest['matchday']); ?>
                            <div class="small text-muted"><?php echo e($protest['match_date'] ?: 'TBD'); ?></div>
                        </td>
                        <td>
                            <?php echo e($protest['competition_name']); ?>
                            <div class="small text-muted"><?php echo e($protest['season_name']); ?></div>
                        </td>
                        <td><span class="badge <?php echo e(protest_status_badge_class($protest['status'])); ?>"><?php echo e(ucwords(str_replace('_', ' ', $protest['status']))); ?></span></td>
                        <td><?php echo $protest['evidence_file'] ? '<a class="btn btn-outline-jlfc btn-sm" href="' . e(base_url($protest['evidence_file'])) . '" target="_blank">View file</a>' : '<span class="text-muted">None</span>'; ?></td>
                        <td class="text-end">
                            <div class="btn-group btn-group-sm">
                                <a class="btn btn-outline-secondary" href="<?php echo e(base_url('app/modules/protests/view.php?id=' . (int) $protest['id'])); ?>">View</a>
                                <a class="btn btn-outline-secondary" href="<?php echo e(base_url('app/modules/protests/edit.php?id=' . (int) $protest['id'])); ?>">Edit</a>
                                <a class="btn btn-outline-danger" href="<?php echo e(base_url('app/modules/protests/delete.php?id=' . (int) $protest['id'])); ?>">Delete</a>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>
<?php require dirname(__DIR__, 2) . '/includes/footer.php'; ?>