<div class="d-flex justify-content-between align-items-center mb-3"><h4 class="mb-0"><i class="fas fa-trophy me-2"></i><?=e($league['name_en'])?></h4>
<div><?php if(auth_can('sports.manage')):?><a href="/sports/leagues/<?=$league['id']?>/edit" class="btn btn-warning btn-sm"><i class="fas fa-edit me-1"></i>Edit</a><?php endif;?> <a href="/sports/leagues" class="btn btn-secondary btn-sm">Back</a></div></div>
<div class="row g-3">
<div class="col-md-4"><div class="card"><div class="card-body">
<table class="table table-sm mb-0"><tr><th>Code</th><td><?=e($league['league_code'])?></td></tr><tr><th>Sport</th><td><?=e($league['sport_name']??'')?></td></tr><tr><th>Season</th><td><?=e($league['season_name']??'')?></td></tr><tr><th>Type</th><td><?=ucfirst(str_replace('_',' ',$league['league_type']))?></td></tr><tr><th>Dates</th><td><?=format_date($league['start_date'])?> — <?=format_date($league['end_date'])?></td></tr><tr><th>Status</th><td><?=status_badge($league['status'])?></td></tr></table>
<?php if(!empty($availableTeams) && auth_can('sports.manage')):?>
<hr><form method="POST" action="/sports/leagues/<?=$league['id']?>/register-team" data-ajax="true"><?=csrf_field()?>
<div class="row g-2"><div class="col-8"><select name="team_id" class="form-select form-select-sm" required><option value="">-- Add Team --</option><?php foreach($availableTeams as $t):?><option value="<?=$t['id']?>"><?=e($t['name_en'])?></option><?php endforeach;?></select></div>
<div class="col-4"><button type="submit" class="btn btn-primary btn-sm w-100">Add</button></div></div></form>
<?php endif;?>
</div></div></div>
<div class="col-md-8">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" data-bs-toggle="tab" href="#tab-standings">Standings</a></li><li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#tab-fixtures">Fixtures</a></li></ul>
<div class="tab-content border border-top-0 p-3">
<div class="tab-pane fade show active" id="tab-standings">
<table class="table table-sm table-hover"><thead><tr><th>#</th><th>Team</th><th>P</th><th>W</th><th>D</th><th>L</th><th>GF</th><th>GA</th><th>GD</th><th>Pts</th></tr></thead><tbody>
<?php foreach($standings as $i=>$s):?>
<tr><td><?=$i+1?></td><td><?=e($s['team_name']??'')?></td><td><?=$s['played']?></td><td><?=$s['won']?></td><td><?=$s['drawn']?></td><td><?=$s['lost']?></td><td><?=$s['goals_for']?></td><td><?=$s['goals_against']?></td><td><?=$s['goal_difference']?></td><td><strong><?=$s['points']?></strong></td></tr>
<?php endforeach;?>
<?php if(empty($standings)):?><tr><td colspan="10" class="text-muted text-center">No teams registered</td></tr><?php endif;?>
</tbody></table>
</div>
<div class="tab-pane fade" id="tab-fixtures">
<table class="table table-sm"><thead><tr><th>Date</th><th>Home</th><th>Score</th><th>Away</th><th>Status</th></tr></thead><tbody>
<?php foreach($matches as $m):?>
<tr><td><?=format_date($m['match_date'])?></td><td><?=e($m['home_name']??'TBD')?></td><td><?=$m['status']==='completed'?$m['home_score'].' - '.$m['away_score']:'-'?></td><td><?=e($m['away_name']??'TBD')?></td><td><?=status_badge($m['status'])?></td></tr>
<?php endforeach;?>
<?php if(empty($matches)):?><tr><td colspan="5" class="text-muted text-center">No fixtures</td></tr><?php endif;?>
</tbody></table>
</div></div></div></div>