<div class="row justify-content-center"><div class="col-lg-10">
<div class="card"><div class="card-header"><h5 class="mb-0"><i class="fas fa-plus me-2"></i>New Class</h5></div>
<div class="card-body">
<form method="POST" action="/sports/classes" data-ajax="true">
<?= csrf_field() ?>
<div class="row g-3">
    <div class="col-md-3"><label class="form-label">Code <span class="text-danger">*</span></label><input type="text" name="class_code" class="form-control" required><div class="invalid-feedback" data-field="class_code"></div></div>
    <div class="col-md-3"><label class="form-label">Sport <span class="text-danger">*</span></label><select name="sport_id" class="form-select" required><option value="">--</option><?php foreach($sports as $s): ?><option value="<?=$s['id']?>"><?=e($s['name_en'])?></option><?php endforeach; ?></select></div>
    <div class="col-md-3"><label class="form-label">Coach</label><select name="coach_id" class="form-select"><option value="">--</option><?php foreach($coaches as $c): ?><option value="<?=$c['id']?>"><?=e($c['name'])?></option><?php endforeach; ?></select></div>
    <div class="col-md-3"><label class="form-label">Facility</label><select name="facility_id" class="form-select"><option value="">--</option><?php foreach($facilities as $f): ?><option value="<?=$f['id']?>"><?=e($f['name_en'])?></option><?php endforeach; ?></select></div>
    <div class="col-md-6"><label class="form-label">Name (EN) <span class="text-danger">*</span></label><input type="text" name="name_en" class="form-control" required></div>
    <div class="col-md-6"><label class="form-label">Name (AR)</label><input type="text" name="name_ar" class="form-control" dir="rtl"></div>
    <div class="col-md-3"><label class="form-label">Level</label><select name="class_type" class="form-select"><?php foreach(['all_levels','beginner','intermediate','advanced','kids','youth','adult','senior'] as $t): ?><option value="<?=$t?>"><?=ucfirst(str_replace('_',' ',$t))?></option><?php endforeach; ?></select></div>
    <div class="col-md-3"><label class="form-label">Max Participants <span class="text-danger">*</span></label><input type="number" name="max_participants" class="form-control" value="20" required></div>
    <div class="col-md-3"><label class="form-label">Fee/Month</label><input type="number" name="fee_per_month" class="form-control" step="0.01" value="0"></div>
    <div class="col-md-3"><label class="form-label">Session Duration (min)</label><input type="number" name="session_duration_minutes" class="form-control" value="60"></div>
    <div class="col-md-3"><label class="form-label">Gender</label><select name="gender_restriction" class="form-select"><option value="both">Both</option><option value="male">Male</option><option value="female">Female</option></select></div>
    <div class="col-md-3"><label class="form-label">Min Age</label><input type="number" name="min_age" class="form-control"></div>
    <div class="col-md-3"><label class="form-label">Max Age</label><input type="number" name="max_age" class="form-control"></div>
    <div class="col-md-3"><label class="form-label">Status</label><select name="status" class="form-select"><option value="planned">Planned</option><option value="enrollment_open">Enrollment Open</option><option value="active">Active</option></select></div>
    <div class="col-md-3"><label class="form-label">Start Date</label><input type="date" name="start_date" class="form-control datepicker"></div>
    <div class="col-md-3"><label class="form-label">End Date</label><input type="date" name="end_date" class="form-control datepicker"></div>
    <div class="col-md-3"><label class="form-label">Season</label><select name="season_id" class="form-select"><option value="">--</option><?php foreach($seasons as $ss): ?><option value="<?=$ss['id']?>"><?=e($ss['name'])?></option><?php endforeach; ?></select></div>
</div>
<hr>
<h6>Weekly Schedule</h6>
<div id="scheduleRows">
    <div class="row g-2 mb-2 schedule-row">
        <div class="col-md-3"><select name="schedule_day[]" class="form-select form-select-sm"><option value="">Day</option><option value="1">Monday</option><option value="2">Tuesday</option><option value="3">Wednesday</option><option value="4">Thursday</option><option value="5">Friday</option><option value="6">Saturday</option><option value="7">Sunday</option></select></div>
        <div class="col-md-3"><input type="time" name="schedule_start[]" class="form-control form-control-sm" placeholder="Start"></div>
        <div class="col-md-3"><input type="time" name="schedule_end[]" class="form-control form-control-sm" placeholder="End"></div>
        <div class="col-md-3"><button type="button" class="btn btn-sm btn-outline-danger" onclick="this.closest('.schedule-row').remove()"><i class="fas fa-trash"></i></button></div>
    </div>
</div>
<button type="button" class="btn btn-sm btn-outline-secondary mb-3" onclick="addScheduleRow()"><i class="fas fa-plus me-1"></i>Add Schedule</button>
<div class="mt-3 d-flex gap-2"><button type="submit" class="btn btn-primary"><i class="fas fa-save me-1"></i>Save</button><a href="/sports/classes" class="btn btn-secondary">Cancel</a></div>
</form></div></div></div></div>
<script>
function addScheduleRow(){const c=document.querySelector('.schedule-row').cloneNode(true);c.querySelectorAll('input,select').forEach(i=>i.value='');document.getElementById('scheduleRows').appendChild(c);}
</script>