<div class="d-flex justify-content-between align-items-center mb-3">
    <h4 class="mb-0"><i class="fas fa-futbol me-2"></i><?= e($sport['name_en']) ?></h4>
    <div>
        <?php if (auth_can('sports.manage')): ?>
        <a href="/sports/<?= $sport['id'] ?>/edit" class="btn btn-warning btn-sm"><i class="fas fa-edit me-1"></i>Edit</a>
        <?php endif; ?>
        <a href="/sports" class="btn btn-secondary btn-sm"><i class="fas fa-arrow-left me-1"></i>Back</a>
    </div>
</div>

<div class="row g-3">
    <div class="col-md-4">
        <div class="card">
            <div class="card-body text-center">
                <?php if ($sport['image_path']): ?>
                <img src="<?= e($sport['image_path']) ?>" class="img-fluid rounded mb-3" style="max-height:200px">
                <?php else: ?>
                <i class="fas fa-futbol fa-5x text-muted my-3"></i>
                <?php endif; ?>
                <h5><?= e($sport['name_en']) ?></h5>
                <p class="text-muted mb-1"><?= e($sport['name_ar'] ?? '') ?></p>
                <p><span class="badge bg-info"><?= e($sport['category_name'] ?? '') ?></span></p>
                <table class="table table-sm text-start">
                    <tr><th>Code</th><td><?= e($sport['sport_code']) ?></td></tr>
                    <tr><th>Type</th><td><?= $sport['team_sport'] ? 'Team Sport' : 'Individual' ?></td></tr>
                    <tr><th>Gender</th><td><?= ucfirst($sport['gender_restriction']) ?></td></tr>
                    <?php if ($sport['min_players'] || $sport['max_players']): ?>
                    <tr><th>Players</th><td><?= $sport['min_players'] ?? '?' ?> - <?= $sport['max_players'] ?? '?' ?></td></tr>
                    <?php endif; ?>
                    <tr><th>Active</th><td><?= $sport['is_active'] ? '<span class="badge bg-success">Yes</span>' : '<span class="badge bg-secondary">No</span>' ?></td></tr>
                </table>
            </div>
        </div>
    </div>
    <div class="col-md-8">
        <ul class="nav nav-tabs" id="sportTabs">
            <li class="nav-item"><a class="nav-link active" data-bs-toggle="tab" href="#tab-classes">Classes (<?= count($classes) ?>)</a></li>
            <li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#tab-teams">Teams (<?= count($teams) ?>)</a></li>
            <li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#tab-seasons">Seasons</a></li>
            <li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#tab-rules">Rules</a></li>
        </ul>
        <div class="tab-content border border-top-0 p-3">
            <div class="tab-pane fade show active" id="tab-classes">
                <?php if (empty($classes)): ?>
                <p class="text-muted">No active classes</p>
                <?php else: ?>
                <div class="table-responsive">
                <table class="table table-sm table-hover">
                    <thead><tr><th>Code</th><th>Name</th><th>Coach</th><th>Type</th><th>Status</th><th></th></tr></thead>
                    <tbody>
                    <?php foreach ($classes as $cl): ?>
                    <tr>
                        <td><?= e($cl['class_code']) ?></td>
                        <td><?= e($cl['name_en']) ?></td>
                        <td><?= e($cl['coach_name'] ?? '-') ?></td>
                        <td><?= ucfirst(str_replace('_',' ',$cl['class_type'])) ?></td>
                        <td><?= status_badge($cl['status']) ?></td>
                        <td><a href="/sports/classes/<?= $cl['id'] ?>" class="btn btn-sm btn-outline-info"><i class="fas fa-eye"></i></a></td>
                    </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
                </div>
                <?php endif; ?>
            </div>
            <div class="tab-pane fade" id="tab-teams">
                <?php if (empty($teams)): ?><p class="text-muted">No active teams</p>
                <?php else: ?>
                <div class="table-responsive">
                <table class="table table-sm table-hover">
                    <thead><tr><th>Code</th><th>Name</th><th>Type</th><th>Players</th><th>W-L-D</th><th></th></tr></thead>
                    <tbody>
                    <?php foreach ($teams as $t): ?>
                    <tr>
                        <td><?= e($t['team_code']) ?></td><td><?= e($t['name_en']) ?></td>
                        <td><?= ucfirst($t['team_type']) ?></td>
                        <td><?= $t['current_players'] ?>/<?= $t['max_players'] ?: '∞' ?></td>
                        <td><?= $t['wins'] ?>-<?= $t['losses'] ?>-<?= $t['draws'] ?></td>
                        <td><a href="/sports/teams/<?= $t['id'] ?>" class="btn btn-sm btn-outline-info"><i class="fas fa-eye"></i></a></td>
                    </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
                </div>
                <?php endif; ?>
            </div>
            <div class="tab-pane fade" id="tab-seasons">
                <?php if (empty($seasons)): ?><p class="text-muted">No seasons</p>
                <?php else: ?>
                <table class="table table-sm">
                    <thead><tr><th>Code</th><th>Name</th><th>Dates</th><th>Status</th></tr></thead>
                    <tbody>
                    <?php foreach ($seasons as $s): ?>
                    <tr><td><?= e($s['season_code']) ?></td><td><?= e($s['name_en']) ?></td><td><?= format_date($s['start_date']) ?> — <?= format_date($s['end_date']) ?></td><td><?= status_badge($s['status']) ?></td></tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
                <?php endif; ?>
            </div>
            <div class="tab-pane fade" id="tab-rules">
                <?php if (empty($rules)): ?><p class="text-muted">No rules defined</p>
                <?php else: ?>
                <?php foreach ($rules as $rule): ?>
                <div class="mb-3">
                    <h6><?= e($rule['title_en']) ?></h6>
                    <p class="text-muted small"><?= nl2br(e($rule['description_en'])) ?></p>
                </div>
                <?php endforeach; ?>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>