<?php $question = $question ?? []; ?>
<div class="modal fade" id="viewModal<?= $question['id'] ?? '' ?>" tabindex="-1" aria-labelledby="viewModalLabel<?= $question['id'] ?? '' ?>" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header bg-info text-white">
        <h5 class="modal-title" id="viewModalLabel<?= $question['id'] ?? '' ?>">Question Details</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>

      <div class="modal-body">
        <p><strong>Exam:</strong> <?= htmlspecialchars($question['exam_label'] ?? '', ENT_QUOTES, 'UTF-8') ?></p>
        <p><strong>Type:</strong> <?= strtoupper($question['question_type'] ?? '') ?></p>
        <p><strong>Marks:</strong> <?= htmlspecialchars($question['marks'] ?? '', ENT_QUOTES, 'UTF-8') ?></p>
        <p><strong>Question:</strong><br><?= nl2br(htmlspecialchars($question['question_text'] ?? '', ENT_QUOTES, 'UTF-8')) ?></p>

        <?php if (($question['question_type'] ?? '') === 'mcq'): ?>
          <hr>
          <h6>Options:</h6>
          <ul>
            <li><strong>A:</strong> <?= htmlspecialchars($question['option_a'] ?? '', ENT_QUOTES, 'UTF-8') ?></li>
            <li><strong>B:</strong> <?= htmlspecialchars($question['option_b'] ?? '', ENT_QUOTES, 'UTF-8') ?></li>
            <li><strong>C:</strong> <?= htmlspecialchars($question['option_c'] ?? '', ENT_QUOTES, 'UTF-8') ?></li>
            <li><strong>D:</strong> <?= htmlspecialchars($question['option_d'] ?? '', ENT_QUOTES, 'UTF-8') ?></li>
          </ul>
          <p><strong>Correct Answer:</strong> <?= htmlspecialchars($question['correct_answer'] ?? '', ENT_QUOTES, 'UTF-8') ?></p>
        <?php endif; ?>

        <?php if (!empty($question['question_image'])): ?>
          <hr>
          <p><strong>Image:</strong><br>
            <img src="../<?= htmlspecialchars($question['question_image'], ENT_QUOTES, 'UTF-8') ?>" width="200" alt="Question Image" class="img-thumbnail">
          </p>
        <?php endif; ?>
      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
