<?php $bp = defined('BASE_PATH') ? BASE_PATH : '/gmind'; $courses = $courses ?? []; ?>
<div class="admin-section">
    <div style="margin-bottom:14px;"><a href="<?= $bp ?>/branch/exams" style="color:#16a085;text-decoration:none;font-size:0.85rem;">← Back to Exams</a></div>
    <form method="POST" action="<?= $bp ?>/branch/exams" style="max-width:680px;">
        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken ?? '', ENT_QUOTES, 'UTF-8') ?>">
        <div style="background:#fff;border-radius:12px;padding:24px;box-shadow:0 2px 8px rgba(0,0,0,0.06);margin-bottom:16px;">
            <h2 style="margin:0 0 16px;font-size:1.1rem;color:#0d3b3b;">📝 Exam Details</h2>

            <div style="margin-bottom:12px;">
                <label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Exam Title (English) *</label>
                <input type="text" name="title" required style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;" placeholder="e.g. Basic Computer Knowledge Test">
            </div>

            <div style="margin-bottom:12px;">
                <label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Exam Title (Hindi) <span style="color:#999;font-weight:400;">— required if language is Hindi or Both</span></label>
                <input type="text" name="title_hindi" style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;font-family:'Noto Sans Devanagari',sans-serif;" placeholder="जैसे — बेसिक कंप्यूटर ज्ञान परीक्षा">
            </div>

            <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:12px;">
                <div>
                    <label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Language *</label>
                    <select name="language" id="langSelect" style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;">
                        <option value="en">English only</option>
                        <option value="hi">Hindi only (केवल हिंदी)</option>
                        <option value="both">Both (English + Hindi)</option>
                    </select>
                </div>
                <div>
                    <label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Course (optional)</label>
                    <select name="course_id" style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;">
                        <option value="">— None —</option>
                        <?php foreach ($courses as $c): ?>
                            <option value="<?= (int)$c['id'] ?>"><?= htmlspecialchars($c['name'], ENT_QUOTES, 'UTF-8') ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:12px;margin-bottom:12px;">
                <div><label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Duration (min)</label><input type="number" name="duration_minutes" value="60" min="1" style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;"></div>
                <div><label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Total Marks</label><input type="number" name="total_marks" value="100" style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;"></div>
                <div><label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Pass Marks</label><input type="number" name="pass_marks" value="40" style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;"></div>
            </div>

            <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:12px;">
                <div>
                    <label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Start Date &amp; Time <span style="color:#999;font-weight:400;">(validity window)</span></label>
                    <input type="datetime-local" name="start_time" style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;">
                </div>
                <div>
                    <label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">End Date &amp; Time</label>
                    <input type="datetime-local" name="end_time" style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;">
                </div>
            </div>
            <p style="margin:0 0 12px;font-size:0.74rem;color:#999;">ℹ If start/end times are set, the exam is only attemptable inside that window (same-day, same-time validity). Leave both blank for always-available.</p>

            <div style="margin-bottom:8px;">
                <label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Instructions (English)</label>
                <textarea name="instructions" rows="2" style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;resize:vertical;" placeholder="Read each question carefully..."></textarea>
            </div>
            <div style="margin-bottom:12px;">
                <label style="display:block;font-size:0.84rem;font-weight:600;color:#0d3b3b;margin-bottom:4px;">Instructions (Hindi)</label>
                <textarea name="instructions_hindi" rows="2" style="width:100%;padding:10px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;resize:vertical;font-family:'Noto Sans Devanagari',sans-serif;" placeholder="हर सवाल ध्यान से पढ़ें..."></textarea>
            </div>
        </div>

        <div style="background:#fff;border-radius:12px;padding:24px;box-shadow:0 2px 8px rgba(0,0,0,0.06);margin-bottom:16px;">
            <h2 style="margin:0 0 12px;font-size:1.05rem;color:#0d3b3b;">⚙️ Toggles &amp; Scheduling</h2>
            <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:14px;">
                <label style="display:flex;align-items:center;gap:8px;padding:12px;background:#f9f9f9;border-radius:8px;cursor:pointer;">
                    <input type="checkbox" name="is_active" value="1" checked style="width:18px;height:18px;cursor:pointer;">
                    <span style="font-size:0.84rem;color:#0d3b3b;font-weight:600;">Active<br><small style="color:#999;font-weight:400;">Inactive = hidden from students</small></span>
                </label>
                <label style="display:flex;align-items:center;gap:8px;padding:12px;background:#f9f9f9;border-radius:8px;cursor:pointer;">
                    <input type="checkbox" name="is_published" value="1" style="width:18px;height:18px;cursor:pointer;">
                    <span style="font-size:0.84rem;color:#0d3b3b;font-weight:600;">Published<br><small style="color:#999;font-weight:400;">Visible to students</small></span>
                </label>
                <label style="display:flex;align-items:center;gap:8px;padding:12px;background:#f9f9f9;border-radius:8px;cursor:pointer;">
                    <input type="checkbox" name="show_result" value="1" checked style="width:18px;height:18px;cursor:pointer;">
                    <span style="font-size:0.84rem;color:#0d3b3b;font-weight:600;">Show Result<br><small style="color:#999;font-weight:400;">After submit. OFF = "later"</small></span>
                </label>
            </div>
            <p style="margin:12px 0 0;font-size:0.74rem;color:#999;">ℹ <strong>Show Result = OFF</strong> means after submitting, the student sees a "Thank you, results will be published later" page instead of their score.</p>
        </div>

        <div style="display:flex;gap:12px;justify-content:flex-end;">
            <a href="<?= $bp ?>/branch/exams" style="padding:14px 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:14px 32px;background:linear-gradient(135deg,#16a085,#117a65);color:#fff;border:none;border-radius:8px;font-weight:600;font-size:0.9rem;cursor:pointer;">Create Exam &amp; Add Questions →</button>
        </div>
    </form>
</div>
