<?php
session_start();
require_once '../config/database.php';
require_once '../includes/access_control.php';

// Check if user is logged in and is a teacher
require_teacher();

$user_role = $_SESSION['user_role'];
$user_id = $_SESSION['user_id'];
$user_name = $_SESSION['user_name'] ?? $_SESSION['username'] ?? 'শিক্ষক';

// Get teacher ID
$teacher_id = null;
if ($user_role == 'teacher') {
    $stmt = $pdo->prepare("SELECT id FROM teachers WHERE user_id = ?");
    $stmt->execute([$user_id]);
    $teacher = $stmt->fetch();
    if ($teacher) {
        $teacher_id = $teacher['id'];
    }
}

// Redirect if not a teacher
if (!$teacher_id) {
    header('Location: ../index.php');
    exit();
}

$success_message = '';
$error_message = '';

// Get all subjects
$stmt = $pdo->query("SELECT id, name, code FROM subjects WHERE status = 'active' ORDER BY name");
$subjects = $stmt->fetchAll();

// Get filter parameters
$subject_id = isset($_GET['subject_id']) ? (int)$_GET['subject_id'] : 0;
$chapter_topic = isset($_GET['chapter_topic']) ? trim($_GET['chapter_topic']) : '';
$question_type = isset($_GET['question_type']) ? $_GET['question_type'] : '';
$difficulty_level = isset($_GET['difficulty_level']) ? $_GET['difficulty_level'] : '';
$is_starred = isset($_GET['is_starred']) ? (int)$_GET['is_starred'] : -1; // -1 = all, 0 = not starred, 1 = starred

// Build query for question bank
$sql = "SELECT qb.*, s.name as subject_name FROM question_bank qb JOIN subjects s ON qb.subject_id = s.id WHERE 1=1";
$params = [];

if ($subject_id > 0) {
    $sql .= " AND qb.subject_id = ?";
    $params[] = $subject_id;
}

if (!empty($chapter_topic)) {
    $sql .= " AND qb.chapter_topic LIKE ?";
    $params[] = "%$chapter_topic%";
}

if (!empty($question_type)) {
    $sql .= " AND qb.question_type = ?";
    $params[] = $question_type;
}

if (!empty($difficulty_level)) {
    $sql .= " AND qb.difficulty_level = ?";
    $params[] = $difficulty_level;
}

if ($is_starred >= 0) {
    $sql .= " AND qb.is_starred = ?";
    $params[] = $is_starred;
}

$sql .= " ORDER BY qb.created_at DESC";

$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$questions = $stmt->fetchAll();

// Get distinct chapter topics for filter
$chapter_topics = [];
if ($subject_id > 0) {
    $stmt = $pdo->prepare("SELECT DISTINCT chapter_topic FROM question_bank WHERE subject_id = ? AND chapter_topic IS NOT NULL ORDER BY chapter_topic");
    $stmt->execute([$subject_id]);
    $chapter_topics = $stmt->fetchAll(PDO::FETCH_COLUMN);
}

// Handle form submission for adding question to bank
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_to_bank'])) {
    $subject_id = (int)$_POST['subject_id'];
    $question_text = trim($_POST['question_text']);
    $question_type = $_POST['question_type'];
    $marks = (int)$_POST['marks'];
    $chapter_topic = trim($_POST['chapter_topic']);
    $difficulty_level = $_POST['difficulty_level'];
    $is_starred = isset($_POST['is_starred']) ? 1 : 0;
    
    if (empty($subject_id) || empty($question_text) || empty($question_type) || $marks <= 0) {
        $error_message = 'সকল প্রয়োজনীয় তথ্য পূরণ করুন';
    } else {
        try {
            if ($question_type === 'mcq') {
                $option_a = trim($_POST['option_a']);
                $option_b = trim($_POST['option_b']);
                $option_c = trim($_POST['option_c']);
                $option_d = trim($_POST['option_d']);
                $correct_answer = $_POST['correct_answer'];
                
                if (empty($option_a) || empty($option_b) || empty($option_c) || empty($option_d) || empty($correct_answer)) {
                    $error_message = 'MCQ প্রশ্নের জন্য সকল অপশন এবং সঠিক উত্তর প্রদান করুন';
                } else {
                    // Insert MCQ question
                    $stmt = $pdo->prepare("
                        INSERT INTO question_bank (subject_id, question_text, question_type, option_a, option_b, option_c, option_d, correct_answer, marks, chapter_topic, difficulty_level, is_starred, created_by)
                        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
                    ");
                    $stmt->execute([
                        $subject_id, 
                        $question_text, 
                        $question_type, 
                        $option_a, 
                        $option_b, 
                        $option_c, 
                        $option_d, 
                        $correct_answer, 
                        $marks,
                        $chapter_topic,
                        $difficulty_level,
                        $is_starred,
                        $user_id
                    ]);
                    $success_message = 'MCQ প্রশ্ন সফলভাবে যোগ করা হয়েছে';
                }
            } else {
                // Insert short or long question
                $stmt = $pdo->prepare("
                    INSERT INTO question_bank (subject_id, question_text, question_type, marks, chapter_topic, difficulty_level, is_starred, created_by)
                    VALUES (?, ?, ?, ?, ?, ?, ?, ?)
                ");
                $stmt->execute([
                    $subject_id, 
                    $question_text, 
                    $question_type, 
                    $marks,
                    $chapter_topic,
                    $difficulty_level,
                    $is_starred,
                    $user_id
                ]);
                $success_message = 'প্রশ্ন সফলভাবে যোগ করা হয়েছে';
            }
            
            // Refresh the page to show updated data
            header("Location: question_bank.php?subject_id=$subject_id&chapter_topic=" . urlencode($chapter_topic));
            exit();
            
        } catch (Exception $e) {
            $error_message = 'প্রশ্ন যোগ করতে সমস্যা হয়েছে: ' . $e->getMessage();
        }
    }
}

// Handle starring/unstarring questions
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['toggle_star'])) {
    $question_id = (int)$_POST['question_id'];
    $is_starred = (int)$_POST['is_starred'];
    
    try {
        $stmt = $pdo->prepare("UPDATE question_bank SET is_starred = ? WHERE id = ?");
        $stmt->execute([$is_starred, $question_id]);
        $success_message = $is_starred ? 'প্রশ্ন সফলভাবে স্টার করা হয়েছে' : 'প্রশ্ন সফলভাবে আনস্টার করা হয়েছে';
    } catch (Exception $e) {
        $error_message = 'প্রশ্ন স্টার করতে সমস্যা হয়েছে: ' . $e->getMessage();
    }
}

// Handle question deletion
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['delete_question'])) {
    $question_id = (int)$_POST['question_id'];
    
    try {
        $stmt = $pdo->prepare("DELETE FROM question_bank WHERE id = ?");
        $stmt->execute([$question_id]);
        $success_message = 'প্রশ্ন সফলভাবে মুছে ফেলা হয়েছে';
    } catch (Exception $e) {
        $error_message = 'প্রশ্ন মুছে ফেলতে সমস্যা হয়েছে: ' . $e->getMessage();
    }
}
?>

<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>প্রশ্ন ব্যাংক - শিক্ষক প্যানেল</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <link href="../assets/css/jessoreboard-theme.css" rel="stylesheet">
    <style>
        .question-item {
            border: 1px solid #e0e0e0;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
            background-color: #f8f9fa;
        }
        
        .question-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }
        
        .question-text {
            font-weight: 500;
            margin-bottom: 10px;
        }
        
        .question-meta {
            display: flex;
            gap: 15px;
            font-size: 0.9rem;
            color: #666;
        }
        
        .mcq-options {
            background-color: #e9ecef;
            border-radius: 5px;
            padding: 10px;
            margin-top: 10px;
        }
        
        .option-item {
            margin-bottom: 5px;
        }
        
        .correct-answer {
            font-weight: bold;
            color: #155724;
        }
        
        .starred {
            color: #ffc107;
        }
        
        .filter-card {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 4px 15px rgba(0,103,71,0.1);
            margin-bottom: 20px;
            border-top: 3px solid #006747;
        }
        
        .form-card {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 4px 15px rgba(0,103,71,0.1);
            margin-bottom: 20px;
            border-top: 3px solid #006747;
        }
    </style>
</head>
<body>
    <!-- Navigation -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container-fluid">
            <a class="navbar-brand" href="dashboard.php">
                <i class="fas fa-graduation-cap"></i> স্কুল ম্যানেজমেন্ট সিস্টেম
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="dashboard.php">
                            <i class="fas fa-home"></i> হোম
                        </a>
                    </li>
                    
                    <!-- Teacher Menu Dropdown -->
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="teacherMenuDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fas fa-chalkboard-teacher"></i> শিক্ষক মেনু
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="teacherMenuDropdown">
                            <li><a class="dropdown-item" href="dashboard.php"><i class="fas fa-tachometer-alt"></i> শিক্ষক ড্যাসবোর্ড</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="my_students.php"><i class="fas fa-user-graduate"></i> আমার ছাত্র-ছাত্রী</a></li>
                            <li><a class="dropdown-item" href="add_student.php"><i class="fas fa-user-plus"></i> নতুন ছাত্র ভর্তি</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="marks_entry.php"><i class="fas fa-edit"></i> মার্কস এন্ট্রি</a></li>
                            <li><a class="dropdown-item" href="my_reports.php"><i class="fas fa-chart-bar"></i> রিপোর্ট দেখুন</a></li>
                            <li><a class="dropdown-item" href="my_reports.php?report_type=tabulation"><i class="fas fa-table"></i> টেবুলেশন শীট</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="create_question_paper.php"><i class="fas fa-file-alt"></i> প্রশ্নপত্র তৈরি</a></li>
                            <li><a class="dropdown-item" href="question_bank.php"><i class="fas fa-book"></i> প্রশ্ন ব্যাংক</a></li>
                            <li><a class="dropdown-item" href="attendance.php"><i class="fas fa-calendar-check"></i> উপস্থিতি নিন</a></li>
                            <li><a class="dropdown-item" href="routine.php"><i class="fas fa-calendar-alt"></i> ক্লাস রুটিন</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="../subjects/subject_selection.php"><i class="fas fa-book"></i> বিষয় নির্বাচন</a></li>
                            <li><a class="dropdown-item" href="bulk_upload_students.php"><i class="fas fa-upload"></i> বাল্ক আপলোড</a></li>
                        </ul>
                    </li>
                    
                    <li class="nav-item">
                        <a class="nav-link" href="../logout.php" onclick="return confirm('আপনি কি লগআউট করতে চান?')">
                            <i class="fas fa-sign-out-alt"></i> লগআউট
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container-fluid mt-4">
        <!-- Content Header -->
        <div class="content-header mb-4">
            <h1 class="content-title">
                <i class="fas fa-book me-2"></i>
                প্রশ্ন ব্যাংক
            </h1>
            <p class="content-breadcrumb">
                <i class="fas fa-home me-1"></i>
                হোম / শিক্ষক প্যানেল / প্রশ্ন ব্যাংক
            </p>
        </div>
        
        <?php if ($success_message): ?>
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <i class="fas fa-check-circle me-2"></i><?php echo $success_message; ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        <?php endif; ?>
        
        <?php if ($error_message): ?>
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <i class="fas fa-exclamation-circle me-2"></i><?php echo $error_message; ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        <?php endif; ?>
        
        <div class="row">
            <div class="col-md-12">
                <div class="filter-card">
                    <h4 class="mb-4"><i class="fas fa-filter me-2"></i>ফিল্টার</h4>
                    
                    <form method="GET" action="">
                        <div class="row">
                            <div class="col-md-3">
                                <div class="mb-3">
                                    <label class="form-label">বিষয়</label>
                                    <select class="form-select" name="subject_id" onchange="this.form.submit()">
                                        <option value="">সব বিষয়</option>
                                        <?php foreach ($subjects as $subject): ?>
                                            <option value="<?php echo $subject['id']; ?>" <?php echo $subject_id == $subject['id'] ? 'selected' : ''; ?>>
                                                <?php echo htmlspecialchars($subject['name']); ?>
                                            </option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            
                            <?php if ($subject_id > 0): ?>
                            <div class="col-md-3">
                                <div class="mb-3">
                                    <label class="form-label">অধ্যায়/টপিক</label>
                                    <select class="form-select" name="chapter_topic" onchange="this.form.submit()">
                                        <option value="">সব অধ্যায়</option>
                                        <?php foreach ($chapter_topics as $topic): ?>
                                            <option value="<?php echo htmlspecialchars($topic); ?>" <?php echo $chapter_topic == $topic ? 'selected' : ''; ?>>
                                                <?php echo htmlspecialchars($topic); ?>
                                            </option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <?php endif; ?>
                            
                            <div class="col-md-2">
                                <div class="mb-3">
                                    <label class="form-label">প্রশ্ন ধরন</label>
                                    <select class="form-select" name="question_type" onchange="this.form.submit()">
                                        <option value="">সব ধরন</option>
                                        <option value="mcq" <?php echo $question_type == 'mcq' ? 'selected' : ''; ?>>MCQ</option>
                                        <option value="short" <?php echo $question_type == 'short' ? 'selected' : ''; ?>>সংক্ষিপ্ত</option>
                                        <option value="long" <?php echo $question_type == 'long' ? 'selected' : ''; ?>>বিস্তারিত</option>
                                    </select>
                                </div>
                            </div>
                            
                            <div class="col-md-2">
                                <div class="mb-3">
                                    <label class="form-label">কঠিনতা স্তর</label>
                                    <select class="form-select" name="difficulty_level" onchange="this.form.submit()">
                                        <option value="">সব স্তর</option>
                                        <option value="easy" <?php echo $difficulty_level == 'easy' ? 'selected' : ''; ?>>সহজ</option>
                                        <option value="medium" <?php echo $difficulty_level == 'medium' ? 'selected' : ''; ?>>মাঝারি</option>
                                        <option value="hard" <?php echo $difficulty_level == 'hard' ? 'selected' : ''; ?>>কঠিন</option>
                                    </select>
                                </div>
                            </div>
                            
                            <div class="col-md-2">
                                <div class="mb-3">
                                    <label class="form-label">স্টার করা</label>
                                    <select class="form-select" name="is_starred" onchange="this.form.submit()">
                                        <option value="-1">সব</option>
                                        <option value="1" <?php echo $is_starred == 1 ? 'selected' : ''; ?>>হ্যাঁ</option>
                                        <option value="0" <?php echo $is_starred == 0 ? 'selected' : ''; ?>>না</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        
        <div class="row">
            <div class="col-md-8">
                <div class="form-card">
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <h4 class="mb-0"><i class="fas fa-list me-2"></i>প্রশ্নসমূহ (<?php echo count($questions); ?> টি)</h4>
                        <a href="#addQuestionForm" class="btn btn-primary">
                            <i class="fas fa-plus-circle me-2"></i>নতুন প্রশ্ন যোগ
                        </a>
                    </div>
                    
                    <?php if (count($questions) > 0): ?>
                        <div class="question-list">
                            <?php foreach ($questions as $index => $question): ?>
                                <div class="question-item">
                                    <div class="question-header">
                                        <div>
                                            <strong>প্রশ্ন #<?php echo $index + 1; ?></strong>
                                            <?php if ($question['is_starred']): ?>
                                                <i class="fas fa-star starred ms-2"></i>
                                            <?php endif; ?>
                                        </div>
                                        <div>
                                            <form method="POST" class="d-inline">
                                                <input type="hidden" name="question_id" value="<?php echo $question['id']; ?>">
                                                <input type="hidden" name="is_starred" value="<?php echo $question['is_starred'] ? 0 : 1; ?>">
                                                <button type="submit" name="toggle_star" class="btn btn-sm btn-outline-warning me-1" title="<?php echo $question['is_starred'] ? 'আনস্টার' : 'স্টার'; ?>">
                                                    <i class="fas fa-<?php echo $question['is_starred'] ? 'star' : 'star'; ?>"></i>
                                                </button>
                                            </form>
                                            <button class="btn btn-sm btn-outline-primary me-1" onclick="editQuestion(<?php echo $question['id']; ?>)">
                                                <i class="fas fa-edit"></i>
                                            </button>
                                            <form method="POST" class="d-inline">
                                                <input type="hidden" name="question_id" value="<?php echo $question['id']; ?>">
                                                <button type="submit" name="delete_question" class="btn btn-sm btn-outline-danger" onclick="return confirm('আপনি কি নিশ্চিত যে আপনি এই প্রশ্ন মুছে ফেলতে চান?')">
                                                    <i class="fas fa-trash"></i>
                                                </button>
                                            </form>
                                        </div>
                                    </div>
                                    <div class="question-text">
                                        <?php echo htmlspecialchars($question['question_text']); ?>
                                    </div>
                                    <div class="question-meta">
                                        <span><i class="fas fa-book me-1"></i> <?php echo htmlspecialchars($question['subject_name']); ?></span>
                                        <span><i class="fas fa-star me-1"></i> <?php echo htmlspecialchars($question['chapter_topic'] ?? 'অনির্দিষ্ট'); ?></span>
                                        <span><i class="fas fa-star me-1"></i> <?php echo $question['difficulty_level'] == 'easy' ? 'সহজ' : ($question['difficulty_level'] == 'hard' ? 'কঠিন' : 'মাঝারি'); ?></span>
                                        <span><i class="fas fa-star me-1"></i> <?php echo $question['marks']; ?> নম্বর</span>
                                        <span>
                                            <i class="fas fa-question-circle me-1"></i> 
                                            <?php echo $question['question_type'] == 'mcq' ? 'MCQ' : ($question['question_type'] == 'short' ? 'সংক্ষিপ্ত' : 'বিস্তারিত'); ?>
                                        </span>
                                    </div>
                                    
                                    <?php if ($question['question_type'] === 'mcq'): ?>
                                        <div class="mcq-options">
                                            <div class="option-item <?php echo $question['correct_answer'] === 'A' ? 'correct-answer' : ''; ?>">
                                                A. <?php echo htmlspecialchars($question['option_a']); ?>
                                                <?php echo $question['correct_answer'] === 'A' ? '<i class="fas fa-check-circle ms-2"></i>' : ''; ?>
                                            </div>
                                            <div class="option-item <?php echo $question['correct_answer'] === 'B' ? 'correct-answer' : ''; ?>">
                                                B. <?php echo htmlspecialchars($question['option_b']); ?>
                                                <?php echo $question['correct_answer'] === 'B' ? '<i class="fas fa-check-circle ms-2"></i>' : ''; ?>
                                            </div>
                                            <div class="option-item <?php echo $question['correct_answer'] === 'C' ? 'correct-answer' : ''; ?>">
                                                C. <?php echo htmlspecialchars($question['option_c']); ?>
                                                <?php echo $question['correct_answer'] === 'C' ? '<i class="fas fa-check-circle ms-2"></i>' : ''; ?>
                                            </div>
                                            <div class="option-item <?php echo $question['correct_answer'] === 'D' ? 'correct-answer' : ''; ?>">
                                                D. <?php echo htmlspecialchars($question['option_d']); ?>
                                                <?php echo $question['correct_answer'] === 'D' ? '<i class="fas fa-check-circle ms-2"></i>' : ''; ?>
                                            </div>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php else: ?>
                        <div class="alert alert-info">
                            <i class="fas fa-info-circle me-2"></i>কোন প্রশ্ন পাওয়া যায়নি। ফিল্টার পরিবর্তন করুন বা নতুন প্রশ্ন যোগ করুন।
                        </div>
                    <?php endif; ?>
                </div>
            </div>
            
            <div class="col-md-4">
                <div class="form-card" id="addQuestionForm">
                    <h4 class="mb-4"><i class="fas fa-plus-circle me-2"></i>নতুন প্রশ্ন যোগ করুন</h4>
                    
                    <form method="POST" action="">
                        <input type="hidden" name="add_to_bank" value="1">
                        
                        <div class="mb-3">
                            <label class="form-label">বিষয় <span class="text-danger">*</span></label>
                            <select class="form-select" name="subject_id" required>
                                <option value="">বিষয় নির্বাচন করুন</option>
                                <?php foreach ($subjects as $subject): ?>
                                    <option value="<?php echo $subject['id']; ?>">
                                        <?php echo htmlspecialchars($subject['name']); ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        
                        <div class="mb-3">
                            <label class="form-label">প্রশ্ন টাইপ</label>
                            <select class="form-select" id="questionType" name="question_type" required>
                                <option value="mcq">MCQ</option>
                                <option value="short">সংক্ষিপ্ত প্রশ্ন</option>
                                <option value="long">বিস্তারিত প্রশ্ন</option>
                            </select>
                        </div>
                        
                        <div class="mb-3">
                            <label class="form-label">প্রশ্ন</label>
                            <textarea class="form-control" name="question_text" rows="3" placeholder="প্রশ্ন লিখুন" required></textarea>
                        </div>
                        
                        <div id="mcqOptions">
                            <div class="mb-3">
                                <label class="form-label">অপশনসমূহ</label>
                                <div class="mb-2">
                                    <input type="text" class="form-control mb-1" name="option_a" placeholder="অপশন A">
                                </div>
                                <div class="mb-2">
                                    <input type="text" class="form-control mb-1" name="option_b" placeholder="অপশন B">
                                </div>
                                <div class="mb-2">
                                    <input type="text" class="form-control mb-1" name="option_c" placeholder="অপশন C">
                                </div>
                                <div class="mb-2">
                                    <input type="text" class="form-control mb-1" name="option_d" placeholder="অপশন D">
                                </div>
                                <div class="mb-2">
                                    <label class="form-label">সঠিক উত্তর</label>
                                    <select class="form-select" name="correct_answer">
                                        <option value="A">A</option>
                                        <option value="B">B</option>
                                        <option value="C">C</option>
                                        <option value="D">D</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        
                        <div class="row">
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label class="form-label">নম্বর</label>
                                    <input type="number" class="form-control" name="marks" value="1" min="1" required>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label class="form-label">অধ্যায়/টপিক</label>
                                    <input type="text" class="form-control" name="chapter_topic" placeholder="অধ্যায় বা টপিক">
                                </div>
                            </div>
                        </div>
                        
                        <div class="row">
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label class="form-label">কঠিনতা স্তর</label>
                                    <select class="form-select" name="difficulty_level">
                                        <option value="easy">সহজ</option>
                                        <option value="medium" selected>মাঝারি</option>
                                        <option value="hard">কঠিন</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label class="form-label">স্টার করা</label>
                                    <div class="form-check mt-2">
                                        <input class="form-check-input" type="checkbox" name="is_starred" id="isStarred">
                                        <label class="form-check-label" for="isStarred">
                                            গুরুত্বপূর্ণ প্রশ্ন
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <button type="submit" class="btn btn-primary w-100">
                            <i class="fas fa-plus me-2"></i>প্রশ্ন যোগ করুন
                        </button>
                    </form>
                </div>
                
                <div class="form-card">
                    <h4 class="mb-4"><i class="fas fa-lightbulb me-2"></i>পরামর্শ</h4>
                    <ul class="list-group list-group-flush">
                        <li class="list-group-item">
                            <i class="fas fa-check-circle text-success me-2"></i>
                            বিভিন্ন অধ্যায় অনুযায়ী প্রশ্ন সংরক্ষণ করুন
                        </li>
                        <li class="list-group-item">
                            <i class="fas fa-check-circle text-success me-2"></i>
                            গুরুত্বপূর্ণ প্রশ্নগুলো স্টার চিহ্নিত করুন
                        </li>
                        <li class="list-group-item">
                            <i class="fas fa-check-circle text-success me-2"></i>
                            প্রশ্নের কঠিনতার স্তর নির্ধারণ করুন
                        </li>
                        <li class="list-group-item">
                            <i class="fas fa-check-circle text-success me-2"></i>
                            প্রয়োজনে ফিল্টার ব্যবহার করে প্রশ্ন খুঁজুন
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Toggle MCQ options based on question type
        document.getElementById('questionType').addEventListener('change', function() {
            const mcqOptions = document.getElementById('mcqOptions');
            if (this.value === 'mcq') {
                mcqOptions.style.display = 'block';
            } else {
                mcqOptions.style.display = 'none';
            }
        });
        
        // Initialize question type toggle
        document.addEventListener('DOMContentLoaded', function() {
            // Set initial state for MCQ options
            if (document.getElementById('questionType').value !== 'mcq') {
                document.getElementById('mcqOptions').style.display = 'none';
            }
        });
        
        // Edit question function (to be implemented)
        function editQuestion(questionId) {
            alert('প্রশ্ন সম্পাদনার জন্য আপডেট করুন। এই ফিচারটি পরবর্তী আপডেটে সংযুক্ত হবে।');
        }
    </script>
</body>
</html>