(SELECT COUNT(*) FROM sa_disciplines WHERE is_active = 1) as active_disciplines,
(SELECT COUNT(*) FROM sa_players WHERE is_archived = 0) as total_players,
(SELECT COUNT(*) FROM sa_facilities WHERE is_active = 1 AND is_archived = 0) as active_facilities,
(SELECT COUNT(*) FROM sa_facility_units WHERE is_active = 1) as active_units,
(SELECT COUNT(*) FROM sa_coaches WHERE is_active = 1 AND is_archived = 0) as active_coaches,
(SELECT COUNT(*) FROM sa_players WHERE is_archived = 0{$branchScope}) as total_players,
(SELECT COUNT(*) FROM sa_groups WHERE status = 'active' AND is_archived = 0) as active_groups,
(SELECT COUNT(*) FROM sa_groups WHERE status = 'active' AND is_archived = 0) as active_groups,
(SELECT COUNT(*) FROM sa_group_players WHERE status = 'active') as enrolled_players,
(SELECT COUNT(*) FROM sa_group_players WHERE status = 'active') as enrolled_players,
(SELECT COUNT(*) FROM sa_bookings WHERE booking_date = ? AND status NOT IN ('cancelled','no_show'){$branchScope}) as today_bookings,
(SELECT COUNT(*) FROM sa_coaches WHERE is_active = 1 AND is_archived = 0) as active_coaches,
(SELECT COUNT(*) FROM sa_player_documents WHERE document_type = 'medical_cert' AND approval_status = 'pending') as pending_medical,
(SELECT COUNT(*) FROM sa_bookings WHERE booking_date = ? AND status NOT IN ('cancelled','no_show')) as today_bookings,
(SELECT COUNT(*) FROM sa_subscriptions WHERE payment_status IN ('unpaid','overdue') AND period_end < ?) as overdue_subscriptions
(SELECT COUNT(*) FROM sa_bookings WHERE booking_date = ? AND booking_type = 'training' AND status NOT IN ('cancelled','no_show')) as today_training_sessions,
(SELECT COUNT(*) FROM sa_bookings WHERE booking_date = ? AND booking_type = 'hourly' AND status NOT IN ('cancelled','no_show')) as today_hourly_bookings
"SELECT COUNT(*) as c FROM sa_player_documents WHERE document_type = 'medical_cert' AND approval_status = 'pending'"
)['c'];
if($pendingMedical>0){
$alerts[]=['type'=>'warning','icon'=>'heart-pulse','text'=>$pendingMedical.' شهادة طبية بانتظار الموافقة','link'=>'/sa/players','count'=>$pendingMedical];
}
$overdueSubscriptions=(int)$db->selectOne(
"SELECT COUNT(*) as c FROM sa_subscriptions WHERE payment_status IN ('unpaid','overdue') AND period_end < ?",
<h3style="margin:0;font-size:16px;font-weight:600;"><idata-lucide="map-pin"style="width:18px;height:18px;vertical-align:middle;margin-left:6px;"></i> اختيار المرفق</h3>
<h3style="margin:0;font-size:16px;font-weight:600;"><idata-lucide="map-pin"style="width:18px;height:18px;vertical-align:middle;margin-left:6px;"></i> اختيار المرفق</h3>
</div>
</div>
<divstyle="padding:20px;">
<divstyle="padding:20px;">
<divstyle="margin-bottom:12px;">
<inputtype="text"id="unitSearchInput"class="form-input"placeholder="ابحث عن مرفق أو ملعب..."style="padding:12px;font-size:14px;border-radius:10px;">
<divstyle="font-size:12px;color:#6B7280;">حجوزات اليوم (<?=(int)$counts['today_training_sessions']?> تدريب / <?=(int)$counts['today_hourly_bookings']?> ساعي)</div>
<h3style="margin:0;font-size:16px;font-weight:600;"><idata-lucide="trophy"style="width:18px;height:18px;vertical-align:middle;margin-left:6px;"></i> اختيار النشاط والمجموعة</h3>
<h3style="margin:0;font-size:16px;font-weight:600;"><idata-lucide="trophy"style="width:18px;height:18px;vertical-align:middle;margin-left:6px;"></i> اختيار النشاط والمجموعة</h3>
# Sports Activity Module — Smart Filtering & Search Plan
## المشكلة
الـ dropdowns في الموديل كله مفيش فيها filtering ذكي ولا search. لو اخترت نشاط رياضي معين، المجموعات والمدربين مش بيتفلترو. ولو عندي 500+ لاعب في dropdown مقدرش أدور فيها.
---
## الحل: مكونين أساسيين
### 1. Searchable Select Component
كل dropdown فيها أكتر من 10 عناصر أو فيها أسماء (لاعبين/مدربين) لازم تبقى searchable. هنعمل component واحد `searchable-select` يشتغل بـ vanilla JS.
### 2. Cascading/Dependent Filtering
لو اخترت parent field، الـ child fields لازم تتفلتر. ده موجود جزئياً في Groups create فقط، محتاج يتعمم.
---
## Edge Cases بالتفصيل (حسب الشاشة)
---
### A. Groups (المجموعات) — `Views/groups/`
| # | الشاشة | الحقل | المشكلة | الحل |
|---|--------|-------|---------|------|
| A1 | create/edit | `program_id` | ✅ بيتفلتر من discipline (موجود) | لا يحتاج تغيير |
| A2 | create/edit | `coach_id` | ✅ بيتفلتر من discipline (موجود) | لا يحتاج تغيير — بس محتاج يبقى searchable |
| A3 | show (enrolled players) | عرض اللاعبين | لو المجموعة فيها 50+ لاعب مفيش search | إضافة filter/search في الجدول |
| A4 | show (add player) | `player_id` dropdown | بيجيب كل اللاعبين الغير مسجلين في المجموعة دي — لو 1000 لاعب الdropdown بطيئة | **Searchable select + AJAX search** بدل ما يجيبهم كلهم |
| A5 | index (filters) | `program_id` filter | مفيش فلتر بالنشاط الرياضي — لازم discipline → program cascading | إضافة discipline filter + cascading |
| A6 | index (filters) | `coach_id` filter | مفيش فلتر بالمدرب | إضافة coach filter (searchable) |
---
### B. Subscriptions (الاشتراكات) — `Views/subscriptions/`
| # | الشاشة | الحقل | المشكلة | الحل |
|---|--------|-------|---------|------|
| B1 | index | `group_id` filter | بيجيب كل المجموعات بدون cascading من النشاط | إضافة discipline filter قبلها + cascading |
| B2 | index | لاعب معين | مفيش search بالاسم أو الرقم القومي | إضافة search field |
---
### C. Bookings Wizard (معالج الحجز) — `Views/bookings/wizard.php`