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

<?php $__template->section('page_actions'); ?>
<a href="/sa/training-attendance/report" class="btn btn-outline"><i data-lucide="bar-chart-2" 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" style="display:flex;gap:10px;align-items:end;flex-wrap:wrap;">
        <div style="min-width:160px;">
            <label class="form-label" style="font-size:12px;">التاريخ</label>
            <input type="date" name="date" class="form-control" value="<?= e($date) ?>">
        </div>
        <div style="min-width:160px;">
            <label class="form-label" style="font-size:12px;">النشاط</label>
            <select name="discipline_id" class="form-select">
                <option value="">-- الكل --</option>
                <?php foreach ($disciplines as $d): ?>
                <option value="<?= (int) $d['id'] ?>" <?= ($filters['discipline_id'] ?? '') == $d['id'] ? 'selected' : '' ?>><?= e($d['name_ar']) ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <button type="submit" class="btn btn-outline"><i data-lucide="filter" style="width:14px;height:14px;vertical-align:middle;"></i> عرض</button>
    </form>
</div>

<div class="card" style="margin-bottom:15px;padding:15px;background:#F0FDF4;border-right:4px solid #059669;">
    <strong>مجموعات التدريب ليوم:</strong> <?= e($date) ?>
    <span style="color:#6B7280;margin-right:10px;">(<?= ['الأحد','الإثنين','الثلاثاء','الأربعاء','الخميس','الجمعة','السبت'][(int)date('w', strtotime($date))] ?>)</span>
</div>

<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>الوقت</th>
                    <th>المجموعة</th>
                    <th>النشاط</th>
                    <th>المدرب</th>
                    <th>المرفق</th>
                    <th>اللاعبين</th>
                    <th>الحضور</th>
                    <th>إجراءات</th>
                </tr>
            </thead>
            <tbody>
                <?php if (!empty($groups)): ?>
                <?php foreach ($groups as $g): ?>
                <tr>
                    <td style="font-weight:600;white-space:nowrap;"><?= e($g['start_time'] ?? '') ?> - <?= e($g['end_time'] ?? '') ?></td>
                    <td><?= e($g['name_ar'] ?? '') ?></td>
                    <td><span style="background:#EFF6FF;color:#1D4ED8;padding:2px 8px;border-radius:8px;font-size:11px;"><?= e($g['discipline_name'] ?? '') ?></span></td>
                    <td><?= e($g['coach_name'] ?? '—') ?></td>
                    <td><?= e($g['unit_name'] ?? '—') ?></td>
                    <td style="text-align:center;"><?= (int) ($g['current_count'] ?? 0) ?></td>
                    <td style="text-align:center;">
                        <?php if ((int)($g['attendance_recorded'] ?? 0) > 0): ?>
                        <span style="background:#ECFDF5;color:#059669;padding:3px 10px;border-radius:10px;font-size:12px;">✓ مسجل (<?= (int)$g['attendance_recorded'] ?>)</span>
                        <?php else: ?>
                        <span style="background:#FEF3C7;color:#92400E;padding:3px 10px;border-radius:10px;font-size:12px;">لم يسجل</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if (can('sa.attendance.manage')): ?>
                        <a href="/sa/training-attendance/record/<?= (int) $g['id'] ?>?date=<?= e($date) ?>" class="btn btn-sm btn-primary" style="font-size:12px;padding:4px 12px;">
                            <i data-lucide="clipboard-check" style="width:13px;height:13px;vertical-align:middle;margin-left:4px;"></i> تسجيل
                        </a>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php else: ?>
                <tr>
                    <td colspan="8" style="text-align:center;padding:40px;color:#6B7280;">
                        <i data-lucide="calendar-x" style="width:36px;height:36px;color:#D1D5DB;display:block;margin:0 auto 10px;"></i>
                        لا توجد مجموعات تدريب في هذا اليوم
                    </td>
                </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

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