<?php

declare(strict_types=1);

require_once __DIR__ . '/helpers.php';

awards_module_boot();

$pageTitle = 'Awards';
$awards = awards_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">Awards management</h2>
        </div>
        <a class="btn btn-jlfc" href="<?php echo e(base_url('app/modules/awards/create.php')); ?>"><i class="bi bi-trophy"></i> Add award</a>
    </div>
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
                <tr>
                    <th>Award</th>
                    <th>Recipient</th>
                    <th>Scope</th>
                    <th>Type</th>
                    <th class="text-end">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($awards === []): ?>
                    <tr>
                        <td colspan="5" class="text-center text-muted py-4">No awards recorded yet.</td>
                    </tr>
                <?php endif; ?>
                <?php foreach ($awards as $award): ?>
                    <tr>
                        <td>
                            <strong><?php echo e($award['title']); ?></strong>
                            <div class="small text-muted"><?php echo e(date('d M Y', strtotime((string) $award['created_at']))); ?></div>
                        </td>
                        <td><?php echo e(award_recipient_name($award)); ?></td>
                        <td>
                            <?php echo e($award['season_name']); ?>
                            <div class="small text-muted"><?php echo e($award['competition_name'] ?: 'Season-wide'); ?></div>
                        </td>
                        <td><?php echo e(award_type_label((string) $award['award_type'])); ?></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/awards/view.php?id=' . (int) $award['id'])); ?>">View</a>
                                <a class="btn btn-outline-secondary" href="<?php echo e(base_url('app/modules/awards/edit.php?id=' . (int) $award['id'])); ?>">Edit</a>
                                <a class="btn btn-outline-danger" href="<?php echo e(base_url('app/modules/awards/delete.php?id=' . (int) $award['id'])); ?>">Delete</a>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>
<?php require dirname(__DIR__, 2) . '/includes/footer.php'; ?>