<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>مدرب: <?= e($coach['full_name_ar']) ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/swimming/coaches/<?= (int) $coach['id'] ?>/edit" class="btn btn-outline"><i data-lucide="edit" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> تعديل</a>
<a href="/sa/swimming/coaches" class="btn btn-outline"><i data-lucide="arrow-right" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> العودة</a>
<?php $__template->endSection(); ?>

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

<!-- Coach Info -->
<div class="card" style="margin-bottom:16px;">
    <div style="padding:20px;">
        <div style="display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:16px;">
            <div>
                <div style="font-size:12px;color:#6B7280;">الكود</div>
                <div style="font-size:15px;font-weight:600;direction:ltr;text-align:right;"><?= e($coach['code']) ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;">الهاتف</div>
                <div style="font-size:15px;font-weight:600;direction:ltr;text-align:right;"><?= e($coach['phone'] ?? '—') ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;">نوع التوظيف</div>
                <?php $types = ['freelance' => 'مستقل', 'staff' => 'موظف', 'contract' => 'تعاقد']; ?>
                <div style="font-size:15px;font-weight:600;"><?= $types[$coach['employment_type'] ?? ''] ?? ($coach['employment_type'] ?? '—') ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;">الرقم القومي</div>
                <div style="font-size:15px;font-weight:600;direction:ltr;text-align:right;"><?= e($coach['national_id'] ?? '—') ?></div>
            </div>
        </div>
    </div>
</div>

<!-- Active Groups -->
<div class="card" style="margin-bottom:16px;">
    <div style="padding:14px 16px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;font-size:15px;font-weight:600;"><i data-lucide="users" style="width:16px;height:16px;vertical-align:middle;margin-left:6px;color:#0D7377;"></i> المجموعات النشطة</h3>
    </div>
    <?php if (empty($groups)): ?>
    <div style="padding:24px;text-align:center;color:#6B7280;font-size:13px;">لا يوجد مجموعات نشطة</div>
    <?php else: ?>
    <div style="padding:0;">
        <?php foreach ($groups as $g): ?>
        <div style="padding:12px 16px;border-bottom:1px solid #F3F4F6;display:flex;align-items:center;justify-content:space-between;">
            <div>
                <div style="font-weight:600;font-size:14px;"><?= e($g['name_ar']) ?></div>
                <div style="font-size:12px;color:#6B7280;"><?= e($g['code']) ?></div>
            </div>
            <span style="padding:3px 8px;border-radius:6px;font-size:11px;font-weight:600;background:#ECFDF5;color:#059669;"><?= e($g['role'] ?? 'مدرب') ?></span>
        </div>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>
</div>

<!-- Lane Bookings -->
<div class="card">
    <div style="padding:14px 16px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;font-size:15px;font-weight:600;"><i data-lucide="calendar" style="width:16px;height:16px;vertical-align:middle;margin-left:6px;color:#0D7377;"></i> حجوزات الحارات</h3>
    </div>
    <?php if (empty($laneBookings)): ?>
    <div style="padding:24px;text-align:center;color:#6B7280;font-size:13px;">لا توجد حجوزات</div>
    <?php else: ?>
    <div style="overflow-x:auto;">
        <table style="width:100%;border-collapse:collapse;font-size:13px;">
            <thead>
                <tr style="background:#F9FAFB;">
                    <th style="padding:10px 14px;text-align:right;">المرفق</th>
                    <th style="padding:10px 14px;text-align:right;">التاريخ</th>
                    <th style="padding:10px 14px;text-align:right;">الوقت</th>
                    <th style="padding:10px 14px;text-align:center;">الإشغال</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($laneBookings as $b): ?>
                <tr style="border-bottom:1px solid #F3F4F6;">
                    <td style="padding:10px 14px;"><?= e($b['facility_name'] ?? '—') ?></td>
                    <td style="padding:10px 14px;direction:ltr;text-align:right;"><?= e($b['booking_date'] ?? '') ?></td>
                    <td style="padding:10px 14px;direction:ltr;text-align:right;"><?= e(substr($b['start_time'] ?? '', 0, 5)) ?> - <?= e(substr($b['end_time'] ?? '', 0, 5)) ?></td>
                    <td style="padding:10px 14px;text-align:center;"><?= (int) ($b['current_occupancy'] ?? 0) ?>/<?= (int) ($b['max_occupancy'] ?? 0) ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>
</div>

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