<?php

declare(strict_types=1);

require_once __DIR__ . '/helpers.php';

$disciplineModuleBoot = 'discipline_module_boot';
$findDisciplinaryCaseOrAbort = 'find_disciplinary_case_or_abort';
$canManageDisciplineCases = 'can_manage_discipline_cases';
$disciplinaryCaseStatusOptions = 'disciplinary_case_status_options';

$disciplineModuleBoot();

$case = $findDisciplinaryCaseOrAbort((int) ($_GET['id'] ?? 0));
$pageTitle = 'Review Disciplinary Case';

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>
            <p class="eyebrow mb-1">Case review</p>
            <h2 class="h4 mb-0"><?php echo e($case['case_type']); ?></h2>
        </div>
    </div>
    <div class="row g-3 mb-4">
        <div class="col-md-6">
            <div class="feature-tile"><i class="bi bi-file-text"></i>
                <div>
                    <h4>Description</h4>
                    <p><?php echo e($case['description']); ?></p>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="feature-tile"><i class="bi bi-person"></i>
                <div>
                    <h4>Player</h4>
                    <p><?php echo e(trim(((string) ($case['first_name'] ?? '')) . ' ' . ((string) ($case['last_name'] ?? '')))); ?></p>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="feature-tile"><i class="bi bi-building"></i>
                <div>
                    <h4>Club</h4>
                    <p><?php echo e($case['club_name'] ?: 'N/A'); ?></p>
                </div>
            </div>
        </div>
    </div>
    <?php if ($canManageDisciplineCases()): ?>
        <form method="post" action="<?php echo e(base_url('app/modules/discipline/actions.php')); ?>">
            <?php echo csrf_input(); ?>
            <input type="hidden" name="action" value="update_case">
            <input type="hidden" name="id" value="<?php echo e((string) $case['id']); ?>">
            <div class="row g-3">
                <div class="col-12">
                    <label class="form-label" for="decision">Decision</label>
                    <textarea class="form-control" id="decision" name="decision" rows="4"><?php echo e((string) ($case['decision'] ?? '')); ?></textarea>
                </div>
                <div class="col-md-4">
                    <label class="form-label" for="fine_amount">Fine amount</label>
                    <input class="form-control" id="fine_amount" name="fine_amount" type="number" min="0" step="0.01" value="<?php echo e((string) $case['fine_amount']); ?>">
                </div>
                <div class="col-md-4">
                    <label class="form-label" for="status">Status</label>
                    <select class="form-select" id="status" name="status">
                        <?php foreach ($disciplinaryCaseStatusOptions() as $status): ?>
                            <option value="<?php echo e($status); ?>" <?php echo $case['status'] === $status ? 'selected' : ''; ?>><?php echo e(ucfirst($status)); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="d-flex gap-2 mt-4">
                <button class="btn btn-jlfc" type="submit">Save case review</button>
                <a class="btn btn-outline-jlfc" href="<?php echo e(base_url('app/modules/discipline/index.php')); ?>">Back</a>
            </div>
        </form>
    <?php endif; ?>
</section>
<?php require dirname(__DIR__, 2) . '/includes/footer.php'; ?>