<?= $this->extend('tipster/layout') ?>

<?= $this->section('content') ?>
<div class="container-fluid">
    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
        <h1 class="h2">My Tips</h1>
        <div class="btn-toolbar mb-2 mb-md-0">
            <a href="<?= site_url('tipster/add-tip') ?>" class="btn btn-primary">
                <i class="bi bi-plus-circle me-2"></i>Add New Tip
            </a>
        </div>
    </div>

    <?php if (empty($tips)): ?>
        <div class="card">
            <div class="card-body text-center py-5">
                <i class="bi bi-inbox" style="font-size: 3rem; color: #ccc;"></i>
                <p class="text-muted mt-3">No tips found. Create your first tip!</p>
                <a href="<?= site_url('tipster/add-tip') ?>" class="btn btn-primary">
                    <i class="bi bi-plus-circle me-2"></i>Add New Tip
                </a>
            </div>
        </div>
    <?php else: ?>
        <div class="card">
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Title</th>
                                <th>Tag</th>
                                <th>Category</th>
                                <th>Amount</th>
                                <th>Match Time</th>
                                <th>Created</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($tips as $tip): ?>
                                <?php
                                $matchTime = !empty($tip['match_time']) ? strtotime($tip['match_time']) : null;
                                $now = time();
                                $canEdit = $matchTime === null || $matchTime > $now;
                                ?>
                                <tr>
                                    <td><?= esc($tip['id']) ?></td>
                                    <td><?= esc($tip['title']) ?></td>
                                    <td>
                                        <span class="badge bg-<?= $tip['tag'] === 'paid' ? 'success' : 'info' ?>">
                                            <?= ucfirst($tip['tag']) ?>
                                        </span>
                                    </td>
                                    <td><?= esc($tip['category']) ?></td>
                                    <td><?= number_format($tip['amount'], 2) ?> UGX</td>
                                    <td>
                                        <?php if (!empty($tip['match_time'])): ?>
                                            <?= date('M d, Y H:i', strtotime($tip['match_time'])) ?>
                                        <?php else: ?>
                                            <span class="text-muted">Not set</span>
                                        <?php endif; ?>
                                    </td>
                                    <td><?= date('M d, Y', strtotime($tip['created_at'])) ?></td>
                                    <td>
                                        <?php if ($canEdit): ?>
                                            <a href="<?= site_url('tipster/edit-tip/' . $tip['id']) ?>" class="btn btn-sm btn-outline-primary">
                                                <i class="bi bi-pencil"></i> Edit
                                            </a>
                                        <?php else: ?>
                                            <span class="text-muted small">Kick-off passed</span>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    <?php endif; ?>
</div>
<?= $this->endSection() ?>

