<?php
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
$student = $student ?? []; $courses = $courses ?? [];
?>
<div class="admin-section">
    <div style="margin-bottom:16px;"><a href="<?= $bp ?>/branch/students/<?= (int)($student['id']??0) ?>" style="color:#16a085;text-decoration:none;font-size:0.85rem;">← Back to Student</a></div>
    <form method="POST" action="<?= $bp ?>/branch/students/<?= (int)($student['id']??0) ?>" enctype="multipart/form-data" style="max-width:800px;">
        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken ?? '', ENT_QUOTES, 'UTF-8') ?>">
        <div style="background:#fff;border-radius:12px;padding:24px;margin-bottom:16px;box-shadow:0 2px 8px rgba(0,0,0,0.06);">
            <h2 style="margin:0 0 16px;font-size:1.1rem;color:#0d3b3b;">Edit Student</h2>
            <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:12px;">
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Name *</label><input type="text" name="name" required value="<?= htmlspecialchars($student['name'] ?? '', ENT_QUOTES, 'UTF-8') ?>" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Email *</label><input type="email" name="email" required value="<?= htmlspecialchars($student['email'] ?? '', ENT_QUOTES, 'UTF-8') ?>" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Phone</label><input type="tel" name="phone" value="<?= htmlspecialchars($student['phone'] ?? '', ENT_QUOTES, 'UTF-8') ?>" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">New Password <span style="color:#999;">(blank = keep)</span></label><input type="text" name="password" value="" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Course</label><select name="course_id" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"><?php foreach ($courses as $c): ?><option value="<?= (int)$c['id'] ?>" <?= ($student['course_id']??0)==$c['id']?'selected':'' ?>><?= htmlspecialchars($c['name'], ENT_QUOTES, 'UTF-8') ?></option><?php endforeach; ?></select></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Status</label><select name="status" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"><option value="active" <?= ($student['status']??'')==='active'?'selected':'' ?>>Active</option><option value="completed" <?= ($student['status']??'')==='completed'?'selected':'' ?>>Completed</option><option value="dropped" <?= ($student['status']??'')==='dropped'?'selected':'' ?>>Dropped</option></select></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">DOB</label><input type="date" name="dob" value="<?= htmlspecialchars($student['dob'] ?? '', ENT_QUOTES, 'UTF-8') ?>" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Gender</label><select name="gender" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"><option value="">—</option><option value="male" <?= ($student['gender']??'')==='male'?'selected':'' ?>>Male</option><option value="female" <?= ($student['gender']??'')==='female'?'selected':'' ?>>Female</option></select></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Father's Name</label><input type="text" name="father_name" value="<?= htmlspecialchars($student['father_name'] ?? '', ENT_QUOTES, 'UTF-8') ?>" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Mother's Name</label><input type="text" name="mother_name" value="<?= htmlspecialchars($student['mother_name'] ?? '', ENT_QUOTES, 'UTF-8') ?>" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Guardian Phone</label><input type="tel" name="guardian_phone" value="<?= htmlspecialchars($student['guardian_phone'] ?? '', ENT_QUOTES, 'UTF-8') ?>" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"></div>
                <div><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Admission Date</label><input type="date" name="admission_date" value="<?= htmlspecialchars($student['admission_date'] ?? '', ENT_QUOTES, 'UTF-8') ?>" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;"></div>
            </div>
            <div style="margin-top:10px;"><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Address</label><textarea name="address" rows="2" style="width:100%;padding:8px 10px;border:1px solid #ddd;border-radius:6px;font-size:0.84rem;resize:vertical;"><?= htmlspecialchars($student['address'] ?? '', ENT_QUOTES, 'UTF-8') ?></textarea></div>
            <div style="margin-top:10px;"><label style="display:block;font-size:0.82rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Update Photo</label><input type="file" name="photo" accept="image/jpeg,image/png" style="width:100%;font-size:0.8rem;padding:6px;border:1px solid #ddd;border-radius:6px;"></div>
        </div>
        <div style="display:flex;gap:12px;justify-content:flex-end;">
            <a href="<?= $bp ?>/branch/students/<?= (int)($student['id']??0) ?>" style="padding:12px 24px;border:1px solid #ddd;border-radius:8px;text-decoration:none;color:#666;font-weight:600;font-size:0.9rem;">Cancel</a>
            <button type="submit" style="padding:12px 28px;background:linear-gradient(135deg,#16a085,#117a65);color:#fff;border:none;border-radius:8px;font-weight:600;font-size:0.9rem;cursor:pointer;">Save Changes</button>
        </div>
    </form>
</div>
