<template>
  <div class="question-view">
    <div class="question-body" v-html="question.body"></div>
    <!-- <div class="ops">
      <div class="stu-answer"> {{stuAnswer}}</div>
      <i-button @click="resetQuestion(examQuestion.id)">重置</i-button>
      <div class="score">({{question.questionScore}}分)</div>
    </div>
    <div v-for="(option, index) in question.options" :key="option.id" class="option" @click="toggleAnswer(index)">
      <input type="checkbox" name="question" value="optionName[index]" :checked="stuAnswer.includes(optionName[index])" />
      <span>{{optionName[index]}}: </span>
      <span class="question-options" v-html="option.content"></span>
    </div> -->
    <template v-if="subQuestion.questionType === 'SINGLE_ANSWER_QUESTION'">
      <single-question-view :question="subQuestion" :examQuestion="examQuestion" />
    </template>
    <template v-if="subQuestion.questionType === 'MULTIPLE_ANSWER_QUESTION'">
      <multiple-question-view :question="subQuestion" :examQuestion="examQuestion" />
    </template>
    <template v-if="subQuestion.questionType === 'BOOL_ANSWER_QUESTION'">
      <boolean-question-view :question="subQuestion" :examQuestion="examQuestion" />
    </template>
    <template v-if="subQuestion.questionType === 'FILL_BLANK_QUESTION'">
      <fill-blank-question-view :question="subQuestion" :examQuestion="examQuestion" />
    </template>
    <template v-if="subQuestion.questionType === 'TEXT_ANSWER_QUESTION'">
      <text-question-view :question="subQuestion" :examQuestion="examQuestion" />
    </template>
  </div>
</template>

<script>
import SingleQuestionView from "./SingleQuestionView";
import MultipleQuestionView from "./MultipleQuestionView";
import BooleanQuestionView from "./BooleanQuestionView";
import FillBlankQuestionView from "./FillBlankQuestionView";
import TextQuestionView from "./TextQuestionView";

export default {
  name: "NestedQuestionView",
  data() {
    return {
      subQuestion: this.question.subQuestionList[
        this.examQuestion.subNumber - 1
      ]
    };
  },
  props: {
    question: Object,
    examQuestion: Object
  },
  methods: {
    answerQuestion: function() {
      this.$http.put("/api/exam_question/" + this.examQuestion.id, {
        stuAnswer: this.stuAnswer
      });
    },
    resetQuestion: function(examQuestionId) {
      this.stuAnswer = "";
      this.$http.put("/api/exam_question/" + examQuestionId, {
        stuAnswer: null
      });
    }
  },
  watch: {},
  components: {
    SingleQuestionView,
    MultipleQuestionView,
    BooleanQuestionView,
    FillBlankQuestionView,
    TextQuestionView
  }
};
</script>

<style scoped>
.question-view {
  display: block;
}

.ops {
  display: flex;
  align-items: flex-end;
}

.stu-answer {
  width: 100px;
  border-bottom: 1px solid black;
}

.option {
  display: flex;
}
.question-options {
  text-align: left;
  padding-left: 10px;
}
</style>
