<template>
  <QuestionBase>
    <template #content>
      <div class="stem">
        <RichText v-model="data.stem" placeholder="输入题干" />

        <RichText
          v-if="isEnable(data.property.is_enable_description)"
          v-model="data.description"
          placeholder="输入提示"
        />
        <el-input
          v-if="isEnable(data.property.is_enable_reference_answer)"
          v-model="data.reference_answer"
          type="textarea"
          rows="3"
          placeholder="输入参考答案"
        />
      </div>
    </template>

    <template #property>
      <el-form :model="data.property">
        <el-form-item label="题号">
          <el-input v-model="data.property.question_number" />
        </el-form-item>
        <el-form-item label-width="45px">
          <el-radio
            v-for="{ value, label } in questionNumberTypeList"
            :key="value"
            v-model="data.other.question_number_type"
            :label="value"
          >
            {{ label }}
          </el-radio>
        </el-form-item>
        <el-form-item label="提示">
          <el-radio
            v-for="{ value, label } in switchOption"
            :key="value"
            v-model="data.property.is_enable_description"
            :label="value"
          >
            {{ label }}
          </el-radio>
        </el-form-item>
        <el-form-item label="参考答案">
          <el-radio
            v-for="{ value, label } in switchOption"
            :key="value"
            v-model="data.property.is_enable_reference_answer"
            :label="value"
          >
            {{ label }}
          </el-radio>
        </el-form-item>

        <el-form-item label="分值">
          <el-radio
            v-for="{ value, label } in scoreTypeList"
            :key="value"
            v-model="data.property.score_type"
            :label="value"
          >
            {{ label }}
          </el-radio>
        </el-form-item>
        <el-form-item label-width="45px">
          <el-input-number
            v-model="data.property.score"
            :min="0"
            :step="data.property.score_type === scoreTypeList[0].value ? 1 : 0.1"
          />
        </el-form-item>
      </el-form>
    </template>
  </QuestionBase>
</template>

<script>
import QuestionMixin from '../common/QuestionMixin.js';

import { essayQuestionData } from '@/views/exercise_questions/data/essayQuestion';

export default {
  name: 'EssayQuestion',
  mixins: [QuestionMixin],
  data() {
    return {
      data: JSON.parse(JSON.stringify(essayQuestionData)),
    };
  },
  methods: {
    /**
     * 智能识别
     * @param {String} text 识别数据
     */
    recognition(text) {
      let arr = text
        .split(/[\r\n]/)
        .map((item) => item.trim())
        .filter((item) => item);

      if (arr.length > 0) {
        this.data.stem = arr[0];
        this.data.reference_answer = arr[1] ? arr[1] : '';
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.stem {
  border-bottom-width: 0 !important;
}
</style>
