<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تقرير حضور التدريب<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/training-attendance" class="btn btn-outline"><i data-lucide="arrow-right" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> العودة</a>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<div class="card" style="margin-bottom:15px;padding:12px 15px;">
    <form method="GET" action="/sa/training-attendance/report" style="display:flex;gap:10px;align-items:end;flex-wrap:wrap;">
        <div style="min-width:180px;">
            <label class="form-label" style="font-size:12px;">المجموعة</label>
            <select name="group_id" class="form-select" data-searchable="true" data-placeholder="-- اختر مجموعة --">
                <option value="">-- الكل --</option>
                <?php foreach ($groups as $g): ?>
                <option value="<?= (int)$g['id'] ?>" <?= ($filters['group_id'] ?? '') == $g['id'] ? 'selected' : '' ?>><?= e($g['name_ar']) ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <div style="min-width:120px;">
            <label class="form-label" style="font-size:12px;">من</label>
            <input type="date" name="date_from" class="form-control" value="<?= e($filters['date_from'] ?? '') ?>">
        </div>
        <div style="min-width:120px;">
            <label class="form-label" style="font-size:12px;">إلى</label>
            <input type="date" name="date_to" class="form-control" value="<?= e($filters['date_to'] ?? '') ?>">
        </div>
        <button type="submit" class="btn btn-primary"><i data-lucide="search" style="width:14px;height:14px;vertical-align:middle;"></i> بحث</button>
    </form>
</div>

<?php if ($summary): ?>
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:10px;margin-bottom:15px;">
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:24px;font-weight:700;color:#1F2937;"><?= (int)$summary['total'] ?></div>
        <div style="font-size:12px;color:#6B7280;">إجمالي السجلات</div>
    </div>
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:24px;font-weight:700;color:#059669;"><?= (int)$summary['present_count'] ?></div>
        <div style="font-size:12px;color:#6B7280;">حاضر</div>
    </div>
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:24px;font-weight:700;color:#DC2626;"><?= (int)$summary['absent_count'] ?></div>
        <div style="font-size:12px;color:#6B7280;">غائب</div>
    </div>
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:24px;font-weight:700;color:#D97706;"><?= (int)$summary['late_count'] ?></div>
        <div style="font-size:12px;color:#6B7280;">متأخر</div>
    </div>
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:24px;font-weight:700;color:#6B7280;"><?= (int)$summary['excused_count'] ?></div>
        <div style="font-size:12px;color:#6B7280;">عذر</div>
    </div>
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:24px;font-weight:700;color:#7C3AED;"><?= (int)$summary['makeup_count'] ?></div>
        <div style="font-size:12px;color:#6B7280;">تعويضي</div>
    </div>
</div>
<?php endif; ?>

<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>التاريخ</th>
                    <th>اللاعب</th>
                    <th>المجموعة</th>
                    <th>الحالة</th>
                </tr>
            </thead>
            <tbody>
                <?php if (!empty($records)): ?>
                <?php foreach ($records as $r): ?>
                <tr>
                    <td><?= e($r['session_date']) ?></td>
                    <td><?= e($r['player_name'] ?? '') ?></td>
                    <td><?= e($r['group_name'] ?? '') ?></td>
                    <td>
                        <?php
                        $statusBadge = match($r['status']) {
                            'present' => '<span style="background:#ECFDF5;color:#059669;padding:2px 8px;border-radius:8px;font-size:11px;">حاضر</span>',
                            'absent'  => '<span style="background:#FEF2F2;color:#DC2626;padding:2px 8px;border-radius:8px;font-size:11px;">غائب</span>',
                            'late'    => '<span style="background:#FEF3C7;color:#D97706;padding:2px 8px;border-radius:8px;font-size:11px;">متأخر</span>',
                            'excused' => '<span style="background:#F3F4F6;color:#6B7280;padding:2px 8px;border-radius:8px;font-size:11px;">عذر</span>',
                            'makeup'  => '<span style="background:#EDE9FE;color:#7C3AED;padding:2px 8px;border-radius:8px;font-size:11px;">تعويضي</span>',
                            default   => '<span style="background:#F3F4F6;color:#6B7280;padding:2px 8px;border-radius:8px;font-size:11px;">' . e($r['status']) . '</span>',
                        };
                        echo $statusBadge;
                        ?>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php else: ?>
                <tr><td colspan="4" style="text-align:center;padding:40px;color:#6B7280;">اختر مجموعة أو لاعب لعرض التقرير</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<script>document.addEventListener('DOMContentLoaded', function() { if (typeof lucide !== 'undefined') lucide.createIcons(); });</script>
<?php $__template->endSection(); ?>
