<?php

declare(strict_types=1);

require_once __DIR__ . '/helpers.php';

protest_module_boot();

$protestRecord = find_protest_or_abort((int) ($_GET['id'] ?? 0));
$pageTitle = 'View Protest';

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 mb-4">
    <div class="panel-card-header mb-3">
        <div>
            <p class="eyebrow mb-1">Protest profile</p>
            <h2 class="h4 mb-0"><?php echo e($protestRecord['title']); ?></h2>
        </div>
        <div class="d-flex gap-2">
            <a class="btn btn-outline-jlfc" href="<?php echo e(base_url('app/modules/protests/edit.php?id=' . (int) $protestRecord['id'])); ?>">Edit</a>
            <a class="btn btn-outline-danger" href="<?php echo e(base_url('app/modules/protests/delete.php?id=' . (int) $protestRecord['id'])); ?>">Delete</a>
        </div>
    </div>
    <div class="row g-3">
        <div class="col-md-4">
            <div class="feature-tile"><i class="bi bi-building"></i>
                <div>
                    <h4>Protesting club</h4>
                    <p><?php echo e($protestRecord['protesting_club_name']); ?></p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="feature-tile"><i class="bi bi-building-x"></i>
                <div>
                    <h4>Against club</h4>
                    <p><?php echo e($protestRecord['against_club_name']); ?></p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="feature-tile"><i class="bi bi-flag"></i>
                <div>
                    <h4>Status</h4>
                    <p><span class="badge <?php echo e(protest_status_badge_class($protestRecord['status'])); ?>"><?php echo e(ucwords(str_replace('_', ' ', $protestRecord['status']))); ?></span></p>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="feature-tile"><i class="bi bi-trophy"></i>
                <div>
                    <h4>Competition</h4>
                    <p><?php echo e($protestRecord['competition_name']); ?> (<?php echo e($protestRecord['season_name']); ?>)</p>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="feature-tile"><i class="bi bi-calendar-event"></i>
                <div>
                    <h4>Fixture</h4>
                    <p>Matchday <?php echo e((string) $protestRecord['matchday']); ?><?php echo $protestRecord['match_date'] ? ' - ' . e($protestRecord['match_date']) : ''; ?></p>
                </div>
            </div>
        </div>
    </div>
</section>

<section class="panel-card mb-4">
    <div class="panel-card-header mb-3">
        <div>
            <p class="eyebrow mb-1">Complaint</p>
            <h3 class="h5 mb-0">Submitted protest details</h3>
        </div>
    </div>
    <p class="mb-0"><?php echo nl2br(e($protestRecord['complaint'])); ?></p>
    <?php if ($protestRecord['evidence_file']): ?>
        <div class="mt-3"><a class="btn btn-outline-jlfc btn-sm" href="<?php echo e(base_url($protestRecord['evidence_file'])); ?>" target="_blank">Open evidence file</a></div>
    <?php endif; ?>
</section>

<?php if (can_decide_protests()): ?>
    <section class="panel-card">
        <div class="panel-card-header mb-3">
            <div>
                <p class="eyebrow mb-1">Decision</p>
                <h3 class="h5 mb-0">League review outcome</h3>
            </div>
        </div>
        <form method="post" action="<?php echo e(base_url('app/modules/protests/actions.php')); ?>">
            <?php echo csrf_input(); ?>
            <input type="hidden" name="action" value="decide">
            <input type="hidden" name="id" value="<?php echo e((string) $protestRecord['id']); ?>">
            <div class="row g-3">
                <div class="col-md-4">
                    <label class="form-label" for="status">Status</label>
                    <select class="form-select" id="status" name="status">
                        <?php foreach (protest_status_options() as $status): ?>
                            <option value="<?php echo e($status); ?>" <?php echo $protestRecord['status'] === $status ? 'selected' : ''; ?>><?php echo e(ucwords(str_replace('_', ' ', $status))); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="col-12">
                    <label class="form-label" for="decision">Decision</label>
                    <textarea class="form-control" id="decision" name="decision" rows="5"><?php echo e((string) ($protestRecord['decision'] ?? '')); ?></textarea>
                </div>
            </div>
            <button class="btn btn-jlfc mt-4" type="submit">Save decision</button>
        </form>
    </section>
<?php endif; ?>
<?php require dirname(__DIR__, 2) . '/includes/footer.php'; ?>