<?php

declare(strict_types=1);

require_once __DIR__ . '/helpers.php';

venue_module_boot();

$pageTitle = 'Venues';
$venues = venue_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">Venue management</h2>
        </div>
        <a class="btn btn-jlfc" href="<?php echo e(base_url('app/modules/venues/create.php')); ?>"><i class="bi bi-building-add"></i> Add venue</a>
    </div>
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
                <tr>
                    <th>Venue</th>
                    <th>Location</th>
                    <th>Capacity</th>
                    <th>Pitch type</th>
                    <th>Status</th>
                    <th>Fixtures</th>
                    <th class="text-end">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($venues === []): ?>
                    <tr>
                        <td colspan="7" class="text-center text-muted py-4">No venues found.</td>
                    </tr>
                <?php endif; ?>
                <?php foreach ($venues as $venue): ?>
                    <tr>
                        <td><strong><?php echo e($venue['name']); ?></strong></td>
                        <td><?php echo e($venue['location']); ?></td>
                        <td><?php echo e((string) ($venue['capacity'] ?? 0)); ?></td>
                        <td><?php echo e($venue['pitch_type'] ?: 'Not set'); ?></td>
                        <td><span class="badge <?php echo e(venue_badge_class($venue['status'])); ?>"><?php echo e(ucwords(str_replace('_', ' ', $venue['status']))); ?></span></td>
                        <td><?php echo e((string) $venue['fixtures_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/venues/view.php?id=' . (int) $venue['id'])); ?>">View</a>
                                <a class="btn btn-outline-secondary" href="<?php echo e(base_url('app/modules/venues/edit.php?id=' . (int) $venue['id'])); ?>">Edit</a>
                                <a class="btn btn-outline-danger" href="<?php echo e(base_url('app/modules/venues/delete.php?id=' . (int) $venue['id'])); ?>">Delete</a>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>
<?php require dirname(__DIR__, 2) . '/includes/footer.php'; ?>