<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>مدربين السباحة<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/swimming/coaches/create" class="btn btn-primary"><i data-lucide="plus" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> إضافة مدرب</a>
<?php $__template->endSection(); ?>

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

<!-- Filters -->
<div class="card" style="margin-bottom:16px;padding:14px 16px;">
    <form method="GET" action="/sa/swimming/coaches" style="display:flex;gap:10px;align-items:end;flex-wrap:wrap;">
        <div style="flex:1;min-width:200px;">
            <input type="text" name="search" value="<?= e($search) ?>" class="form-input" placeholder="بحث بالاسم أو الهاتف..." style="padding:10px 14px;">
        </div>
        <select name="filter" class="form-select" style="min-width:150px;padding:10px 14px;">
            <option value="">— جميع الأنواع —</option>
            <option value="freelance" <?= $filter === 'freelance' ? 'selected' : '' ?>>مستقل (freelance)</option>
            <option value="staff" <?= $filter === 'staff' ? 'selected' : '' ?>>موظف (staff)</option>
            <option value="contract" <?= $filter === 'contract' ? 'selected' : '' ?>>تعاقد (contract)</option>
        </select>
        <button type="submit" class="btn btn-outline" style="padding:10px 18px;">
            <i data-lucide="search" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> بحث
        </button>
    </form>
</div>

<!-- Coaches List -->
<div class="card">
    <div style="padding:14px 16px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
        <i data-lucide="waves" style="width:18px;height:18px;color:#0D7377;"></i>
        <h3 style="margin:0;font-size:15px;color:#0D7377;">مدربين السباحة</h3>
        <span style="margin-right:auto;background:#EFF6FF;color:#2563EB;padding:3px 10px;border-radius:12px;font-size:12px;font-weight:700;"><?= count($coaches) ?></span>
    </div>
    <?php if (empty($coaches)): ?>
    <div style="padding:50px 24px;text-align:center;color:#6B7280;">
        <i data-lucide="waves" style="width:48px;height:48px;color:#D1D5DB;display:block;margin:0 auto 15px;"></i>
        <div style="font-size:15px;">لا يوجد مدربين سباحة</div>
    </div>
    <?php else: ?>
    <div style="overflow-x:auto;">
        <table style="width:100%;border-collapse:collapse;font-size:14px;">
            <thead>
                <tr style="background:#F9FAFB;border-bottom:1px solid #E5E7EB;">
                    <th style="padding:12px 16px;text-align:right;font-weight:600;">الكود</th>
                    <th style="padding:12px 16px;text-align:right;font-weight:600;">الاسم</th>
                    <th style="padding:12px 16px;text-align:right;font-weight:600;">الهاتف</th>
                    <th style="padding:12px 16px;text-align:right;font-weight:600;">نوع التوظيف</th>
                    <th style="padding:12px 16px;text-align:center;font-weight:600;">مجموعات نشطة</th>
                    <th style="padding:12px 16px;text-align:center;font-weight:600;">إجراءات</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($coaches as $c): ?>
                <tr style="border-bottom:1px solid #F3F4F6;">
                    <td style="padding:12px 16px;font-size:12px;direction:ltr;text-align:right;color:#6B7280;"><?= e($c['code']) ?></td>
                    <td style="padding:12px 16px;font-weight:600;"><?= e($c['full_name_ar']) ?></td>
                    <td style="padding:12px 16px;direction:ltr;text-align:right;color:#6B7280;"><?= e($c['phone'] ?? '—') ?></td>
                    <td style="padding:12px 16px;">
                        <?php
                        $types = ['freelance' => 'مستقل', 'staff' => 'موظف', 'contract' => 'تعاقد'];
                        $colors = ['freelance' => '#7C3AED', 'staff' => '#059669', 'contract' => '#D97706'];
                        $t = $c['employment_type'] ?? 'freelance';
                        ?>
                        <span style="padding:3px 8px;border-radius:6px;font-size:11px;font-weight:600;background:<?= $colors[$t] ?? '#6B7280' ?>15;color:<?= $colors[$t] ?? '#6B7280' ?>;">
                            <?= $types[$t] ?? $t ?>
                        </span>
                    </td>
                    <td style="padding:12px 16px;text-align:center;font-weight:600;"><?= (int) ($c['active_groups'] ?? 0) ?></td>
                    <td style="padding:12px 16px;text-align:center;">
                        <a href="/sa/swimming/coaches/<?= (int) $c['id'] ?>" class="btn btn-sm btn-outline" style="padding:6px 12px;font-size:12px;">عرض</a>
                        <a href="/sa/swimming/coaches/<?= (int) $c['id'] ?>/edit" class="btn btn-sm btn-outline" style="padding:6px 12px;font-size:12px;margin-right:4px;">تعديل</a>
                    </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(); ?>
