<!--components/my-quiz/my-quiz.wxml-->
<view class="quiz-container">
    <block wx:for="{{renderQuestions}}" wx:key="id" wx:for-item="q" wx:for-index="qi">
    <view class="question-card">
      <view class="question-title">
        <text class="tag">{{qi + 1}}.</text>
        <text class="tag" wx:if="{{q.type == 2}}">[ 多选题 ]</text>
        <text class="tag" wx:else>[ 单选题 ]</text>
        {{q.question}}
      </view>
      <view class="options">
        <!-- 单选题使用 radio-group -->
        <radio-group
          wx:if="{{q.type == 1}}"
          bindchange="handleRadioChange"
          data-question-id="{{q.id}}"
          value="{{getSelectedAnswer(q.id, 0)}}"
        >
          <block wx:for="{{q.options}}" wx:key="key" wx:for-item="op" wx:if="{{op.value}}">
            <label class="option-item {{isCorrect(q.id, op.key) ? 'correct' : isWrong(q.id, op.key) ? 'wrong' : ''}} {{getSelectedAnswer(q.id, 0) === op.key ? 'selected' : ''}}">
              <radio
                value="{{op.key}}"
                checked="{{getSelectedAnswer(q.id, 0) === op.key}}"
               />
              <text>{{op.key}}. {{op.value}}</text>
            </label>
          </block>
        </radio-group>

        <!-- 多选题使用 checkbox-group -->
        <checkbox-group
          wx:if="{{q.type == 2}}"
          bindchange="handleCheckboxChange"
          data-question-id="{{q.id}}"
          value="{{selectedAnswers[q.id] || []}}"
        >
          <block wx:for="{{q.options}}" wx:key="key" wx:for-item="op" wx:if="{{op.value}}">
            <label class="option-item {{isCorrect(q.id, op.key) ? 'correct' : isWrong(q.id, op.key) ? 'wrong' : ''}} {{isSelected(q.id, op.key) ? 'selected' : ''}}">
              <checkbox
                value="{{op.key}}"
                checked="{{isSelected(q.id, op.key)}}"
              />
              <text>{{op.key}}. {{op.value}}</text>
            </label>
          </block>
        </checkbox-group>
      </view>
    </view>
  </block>
</view>
