<?php

declare(strict_types=1);

require_once __DIR__ . '/helpers.php';

referee_module_boot();

$pageTitle = 'Referees';
$referees = referee_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">Referee management</h2>
        </div>
        <a class="btn btn-jlfc" href="<?php echo e(base_url('app/modules/referees/create.php')); ?>"><i class="bi bi-person-plus-fill"></i> Add referee</a>
    </div>
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
                <tr>
                    <th>Referee</th>
                    <th>Level</th>
                    <th>Phone</th>
                    <th>Email</th>
                    <th>Status</th>
                    <th>Assignments</th>
                    <th class="text-end">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($referees === []): ?>
                    <tr>
                        <td colspan="7" class="text-center text-muted py-4">No referees found.</td>
                    </tr>
                <?php endif; ?>
                <?php foreach ($referees as $referee): ?>
                    <tr>
                        <td><strong><?php echo e($referee['full_name']); ?></strong></td>
                        <td><?php echo e(ucfirst($referee['level'])); ?></td>
                        <td><?php echo e($referee['phone'] ?: 'Not set'); ?></td>
                        <td><?php echo e($referee['email'] ?: 'Not set'); ?></td>
                        <td><span class="badge <?php echo e(referee_badge_class($referee['status'])); ?>"><?php echo e(ucfirst($referee['status'])); ?></span></td>
                        <td><?php echo e((string) $referee['assignments_count']); ?></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/referees/view.php?id=' . (int) $referee['id'])); ?>">View</a>
                                <a class="btn btn-outline-secondary" href="<?php echo e(base_url('app/modules/referees/edit.php?id=' . (int) $referee['id'])); ?>">Edit</a>
                                <a class="btn btn-outline-danger" href="<?php echo e(base_url('app/modules/referees/delete.php?id=' . (int) $referee['id'])); ?>">Delete</a>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>
<?php require dirname(__DIR__, 2) . '/includes/footer.php'; ?>