<!-- eslint-disable vue/no-v-html -->
<template>
  <div class="repeat-preview">
    <div class="stem">
      <span class="question-number">{{ data.property.question_number }}.</span>
      <span v-html="sanitizeHTML(data.stem)"></span>
    </div>
    <div v-if="isEnable(data.property.is_enable_description)" class="description">{{ data.description }}</div>
    <div class="option-list">
      <li v-for="(item, i) in answer_list" :key="i" :class="['option-item']">
        <span>{{ computeOptionMethods[data.option_number_show_mode](i) }}. </span>
        <AudioPlay v-if="data.option_list[i].audio_file_id" :file-id="data.option_list[i].audio_file_id" />
        <div class="option-content" v-html="sanitizeHTML(data.option_list[i].content)"></div>
        <div class="sound-box">
          <SoundRecordPreview :wav-blob.sync="item.audio_file_id" :type="'small'" />
        </div>
      </li>
    </div>
  </div>
</template>

<script>
import PreviewMixin from './components/PreviewMixin';
import { computeOptionMethods } from '@/views/exercise_questions/data/common';
import SoundRecordPreview from './components/common/SoundRecordPreview.vue';

export default {
  name: 'RepeatPreview',
  components: {
    SoundRecordPreview,
  },
  mixins: [PreviewMixin],
  data() {
    return {
      computeOptionMethods,
      answer_list: [],
    };
  },
  created() {
    this.handleData();
  },
  methods: {
    // 初始化数据
    handleData() {
      this.answer_list = [];
      this.data.option_list.forEach((item) => {
        let obj = {
          mark: item.mark,
          audio_file_id: '',
        };
        this.answer_list.push(obj);
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@use '@/styles/mixin.scss' as *;

.repeat-preview {
  @include preview;

  .option-list {
    display: flex;
    flex-wrap: wrap;
    row-gap: 16px;

    .option-item {
      display: flex;
      column-gap: 16px;
      align-items: center;
      min-width: 40%;
      max-width: 50%;
      padding-right: 24px;

      .option-content {
        flex: 1;
        max-width: 306px;
        padding: 8px 16px;
        color: #706f78;
        background-color: #f9f8f9;
        border-radius: 40px;
      }

      .sound-box {
        padding: 4px;
        background: #f9f8f9;
        border-radius: 40px;
      }
    }
  }
}
</style>
