<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>لوحة الرياضة — <?= e($discipline['name_ar'] ?? '') ?><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<div style="margin-bottom:20px;display:flex;align-items:center;gap:15px;">
    <a href="/sports-dashboard?period=<?= e($period) ?>&from=<?= e($from) ?>&to=<?= e($to) ?>" class="btn btn-outline" style="padding:6px 12px;font-size:13px;">
        <i data-lucide="arrow-right" style="width:14px;height:14px;display:inline;vertical-align:middle;"></i>
        العودة للوحة الرئيسية
    </a>
    <div>
        <h2 style="margin:0 0 5px;font-size:22px;"><?= e($discipline['name_ar'] ?? '') ?></h2>
        <p style="color:#6B7280;font-size:14px;margin:0;">لوحة معلومات الرياضة</p>
    </div>
</div>

<?php $__template->include('Shared.Views._partials.time_filter', [
    'period'  => $period,
    'from'    => $from,
    'to'      => $to,
    'baseUrl' => $baseUrl,
    'export'  => $export,
]); ?>

<!-- KPI Cards -->
<div style="display:grid;grid-template-columns:repeat(auto-fit, minmax(200px, 1fr));gap:15px;margin-bottom:25px;">
    <!-- Revenue -->
    <div class="card" style="padding:20px;text-align:center;border-top:3px solid #059669;">
        <div style="font-size:24px;font-weight:700;color:#059669;"><?= money($revenueComparison['current'] ?? 0) ?></div>
        <div style="font-size:13px;color:#6B7280;margin-top:4px;">الإيرادات</div>
        <?php if (($revenueComparison['change_pct'] ?? 0) != 0): ?>
        <div style="margin-top:6px;font-size:12px;color:<?= $revenueComparison['direction'] === 'up' ? '#059669' : '#DC2626' ?>;">
            <i data-lucide="<?= $revenueComparison['direction'] === 'up' ? 'trending-up' : 'trending-down' ?>" style="width:14px;height:14px;display:inline;vertical-align:middle;"></i>
            <?= $revenueComparison['change_pct'] ?>%
        </div>
        <?php endif; ?>
    </div>

    <!-- Players -->
    <div class="card" style="padding:20px;text-align:center;border-top:3px solid #2563EB;">
        <div style="font-size:24px;font-weight:700;color:#2563EB;"><?= number_format($demographics['total'] ?? 0) ?></div>
        <div style="font-size:13px;color:#6B7280;margin-top:4px;">اللاعبين المسجلين</div>
        <div style="font-size:11px;color:#9CA3AF;margin-top:4px;"><?= $demographics['members'] ?? 0 ?> أعضاء | <?= $demographics['non_members'] ?? 0 ?> غير أعضاء</div>
    </div>

    <!-- Coaches -->
    <div class="card" style="padding:20px;text-align:center;border-top:3px solid #7C3AED;">
        <div style="font-size:24px;font-weight:700;color:#7C3AED;"><?= count($coaches) ?></div>
        <div style="font-size:13px;color:#6B7280;margin-top:4px;">المدربين</div>
    </div>

    <!-- Sessions -->
    <div class="card" style="padding:20px;text-align:center;border-top:3px solid #D97706;">
        <div style="font-size:24px;font-weight:700;color:#D97706;"><?= number_format($sessionCount) ?></div>
        <div style="font-size:13px;color:#6B7280;margin-top:4px;">الحصص التدريبية</div>
    </div>
</div>

<!-- Coach Performance Table -->
<?php if (!empty($coaches)): ?>
<div class="card" style="padding:20px;margin-bottom:25px;">
    <h3 style="margin:0 0 15px;font-size:17px;">أداء المدربين</h3>
    <div class="table-responsive">
        <table class="data-table" style="width:100%;">
            <thead>
                <tr>
                    <th>#</th>
                    <th>المدرب</th>
                    <th>عدد الحصص</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($coaches as $i => $coach): ?>
                <tr>
                    <td><?= $i + 1 ?></td>
                    <td style="font-weight:600;"><?= e($coach['name_ar'] ?? '') ?></td>
                    <td><?= (int) ($coach['session_count'] ?? 0) ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
<?php endif; ?>

<!-- Academies -->
<?php if (!empty($academies)): ?>
<div class="card" style="padding:20px;margin-bottom:25px;">
    <h3 style="margin:0 0 15px;font-size:17px;">الأكاديميات المرتبطة</h3>
    <div class="table-responsive">
        <table class="data-table" style="width:100%;">
            <thead>
                <tr>
                    <th>الأكاديمية</th>
                    <th>عدد اللاعبين</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($academies as $academy): ?>
                <tr>
                    <td style="font-weight:600;"><?= e($academy['name_ar'] ?? '') ?></td>
                    <td><?= (int) ($academy['player_count'] ?? 0) ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
<?php endif; ?>

<?php $__template->endSection(); ?>
