<?php $this->extend('admin/layout'); ?>
<?php $this->section('content'); ?>
<div class="container mt-4">
    <h2>Predictions for Ticket: <?= esc($tip['title']) ?> (ID: <?= esc($tip['id']) ?>)</h2>
    <a href="<?= site_url('admin/author-tickets/' . urlencode($tip['author'])) ?>" class="btn btn-secondary mb-3">&larr; Back to Author Tickets</a>
    <div class="card">
        <div class="card-header">Predictions</div>
        <div class="card-body">
            <?php if (empty($predictions)): ?>
                <div class="alert alert-info">No predictions found for this ticket.</div>
            <?php else: ?>
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Match</th>
                                <th>Prediction</th>
                                <th>Odds</th>
                                <th>Outcome</th>
                                <th>Actual Score</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($predictions as $p): ?>
                                <tr>
                                    <td><?= esc($p['id']) ?></td>
                                    <td>
                                        <?php if (is_array($p['match_data'])): ?>
                                            <?= esc($p['match_data']['team1'] ?? '') ?> vs <?= esc($p['match_data']['team2'] ?? '') ?>
                                        <?php endif; ?>
                                    </td>
                                    <td><?= esc($p['match_data']['prediction'] ?? '') ?></td>
                                    <td><?= esc($p['match_data']['odds'] ?? '') ?></td>
                                    <td>
                                        <span class="badge bg-<?= $p['prediction_outcome'] === 'correct' ? 'success' : ($p['prediction_outcome'] === 'wrong' ? 'danger' : 'warning') ?>">
                                            <?= ucfirst($p['prediction_outcome']) ?>
                                        </span>
                                    </td>
                                    <td><?= esc($p['actual_score'] ?? '') ?></td>
                                    <td>
                                        <?php if ($p['prediction_outcome'] === 'pending'): ?>
                                            <form method="post" action="<?= site_url('admin/mark-prediction/' . $p['id']) ?>" style="display:inline-block;">
                                                <?= csrf_field() ?>
                                                <input type="hidden" name="outcome" value="correct">
                                                <input type="text" name="actual_score" placeholder="Score (e.g. 2-1)" class="form-control form-control-sm mb-1" required>
                                                <button type="submit" class="btn btn-sm btn-success">Mark Correct</button>
                                            </form>
                                            <form method="post" action="<?= site_url('admin/mark-prediction/' . $p['id']) ?>" style="display:inline-block;">
                                                <?= csrf_field() ?>
                                                <input type="hidden" name="outcome" value="wrong">
                                                <input type="text" name="actual_score" placeholder="Score (e.g. 0-1)" class="form-control form-control-sm mb-1" required>
                                                <button type="submit" class="btn btn-sm btn-danger">Mark Wrong</button>
                                            </form>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>
<?php $this->endSection(); ?> 