<?php

declare(strict_types=1);

require_once __DIR__ . '/bootstrap.php';

$clubs = [];

try {
    $clubs = db_fetch_all(
        'SELECT name, short_name, stadium_name, contact_person, license_status, payment_status
         FROM clubs
         ORDER BY name ASC
         LIMIT 50'
    );
} catch (Throwable) {
}

render_public_page('Clubs', 'Registered clubs managed by the JLFC league engine.', static function () use ($clubs): void {
?>
    <section class="row g-3">
        <?php if ($clubs === []): ?>
            <div class="col-12">
                <div class="panel-card">
                    <p class="text-muted mb-0">No clubs have been registered yet.</p>
                </div>
            </div>
        <?php else: ?>
            <?php foreach ($clubs as $club): ?>
                <div class="col-md-6 col-xl-4">
                    <div class="panel-card h-100">
                        <p class="eyebrow mb-1"><?php echo e($club['short_name']); ?></p>
                        <h2 class="h4 mb-2"><?php echo e($club['name']); ?></h2>
                        <p class="text-muted mb-3"><?php echo e($club['stadium_name'] ?? 'Venue not set'); ?></p>
                        <div class="d-flex gap-2 flex-wrap">
                            <span class="badge badge-soft-success"><?php echo e(ucfirst($club['license_status'])); ?></span>
                            <span class="badge text-bg-light"><?php echo e(ucfirst($club['payment_status'])); ?></span>
                        </div>
                        <p class="small text-muted mt-3 mb-0">Contact: <?php echo e($club['contact_person'] ?? 'Not set'); ?></p>
                    </div>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
    </section>
<?php
});
