<?php

declare(strict_types=1);

require_once __DIR__ . '/helpers.php';

staff_module_boot();

$pageTitle = 'Club Staff';
$staffList = staff_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">Club staff management</h2>
        </div><a class="btn btn-jlfc" href="<?php echo e(base_url('app/modules/staff/create.php' . (isset($_GET['club_id']) ? '?club_id=' . (int) $_GET['club_id'] : ''))); ?>"><i class="bi bi-person-plus-fill"></i> Add staff</a>
    </div>
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Club</th>
                    <th>Role</th>
                    <th>Status</th>
                    <th class="text-end">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($staffList === []): ?><tr>
                        <td colspan="5" class="text-center text-muted py-4">No staff records found.</td>
                    </tr><?php endif; ?>
                <?php foreach ($staffList as $staff): ?>
                    <tr>
                        <td><strong><?php echo e($staff['full_name']); ?></strong>
                            <div class="small text-muted"><?php echo e($staff['email'] ?: 'No email'); ?></div>
                        </td>
                        <td><?php echo e($staff['club_name']); ?></td>
                        <td><?php echo e(ucwords(str_replace('_', ' ', $staff['role']))); ?></td>
                        <td><?php echo e(ucfirst($staff['status'])); ?></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/staff/view.php?id=' . (int) $staff['id'])); ?>">View</a><a class="btn btn-outline-secondary" href="<?php echo e(base_url('app/modules/staff/edit.php?id=' . (int) $staff['id'])); ?>">Edit</a><a class="btn btn-outline-danger" href="<?php echo e(base_url('app/modules/staff/delete.php?id=' . (int) $staff['id'])); ?>">Delete</a></div>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>
<?php require dirname(__DIR__, 2) . '/includes/footer.php'; ?>