<template>
  <div>
    <el-form :model="property" label-width="72px" label-position="left">
      <SerialNumber :property="property" />

      <el-form-item label="排列">
        <el-radio-group v-model="property.arrange_type">
          <el-radio v-for="{ value, label } in arrangeTypeList" :key="value" :label="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="填空方式">
        <el-radio-group v-model="property.fill_type">
          <el-radio v-for="{ value, label } in fillTypeList" :key="value" :label="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="音频位置">
        <el-radio-group v-model="property.audio_position">
          <el-radio v-for="{ value, label } in audioPositionList" :key="value" :label="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-divider />
      <el-form-item label="读音">
        <el-select v-model="property.audio_generation_method" placeholder="请选择">
          <el-option v-for="{ value, label } in audioGenerationMethodList" :key="value" :label="label" :value="value" />
        </el-select>
      </el-form-item>

      <template v-if="property.audio_generation_method === 'auto'">
        <el-form-item label="音色">
          <el-select v-model="property.voice_type" placeholder="请选择">
            <el-option
              v-for="{ voice_type, name } in voice_type_list"
              :key="voice_type"
              :label="name"
              :value="voice_type"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="风格情感">
          <el-select v-model="property.emotion">
            <el-option v-for="{ emotion, name } in emotion_list" :key="emotion" :label="name" :value="emotion" />
          </el-select>
        </el-form-item>
        <el-form-item label="语速">
          <el-select v-model="property.speed_ratio">
            <el-option v-for="{ value, label } in speedRatioList" :key="value" :label="label" :value="value" />
          </el-select>
        </el-form-item>
      </template>
      <el-form-item label="填空字体">
        <el-select v-model="property.fill_font" placeholder="请选择">
          <el-option v-for="{ value, label } in fontList" :key="value" :label="label" :value="value" />
        </el-select>
      </el-form-item>
      <el-form-item label="横线长度">
        <el-input v-model="property.input_default_width" type="number" placeholder="请输入">
          <template slot="append">px</template>
        </el-input>
      </el-form-item>
      <el-divider />
      <el-form-item label="语音作答">
        <el-radio-group v-model="property.is_enable_voice_answer">
          <el-radio v-for="{ value, label } in switchOption" :key="value" :label="value" :value="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="拼音">
        <el-switch v-model="property.view_pinyin" active-value="true" inactive-value="false" />
      </el-form-item>
      <el-form-item v-show="isEnable(property.view_pinyin)" label="拼音位置">
        <el-radio
          v-for="{ value, label } in pinyinPositionList"
          :key="value"
          v-model="property.pinyin_position"
          :label="value"
          :disabled="!isEnable(property.view_pinyin)"
        >
          {{ label }}
        </el-radio>
      </el-form-item>
      <el-form-item v-show="isEnable(property.view_pinyin)" label="">
        <el-checkbox
          v-model="property.is_first_sentence_first_hz_pinyin_first_char_upper_case"
          :disabled="!isEnable(property.view_pinyin)"
          true-label="true"
          false-label="false"
          >句首大写</el-checkbox
        >
      </el-form-item>

      <AddAnswer />
    </el-form>
  </div>
</template>

<script>
import SettingMixin from '@/views/book/courseware/create/components/common/SettingMixin';

import {
  getFillProperty,
  arrangeTypeList,
  audioPositionList,
  audioGenerationMethodList,
  switchOption,
  fillTypeList,
} from '@/views/book/courseware/data/fill';

import { GetTextToAudioConfParamList } from '@/api/app';
import { speedRatioList, fontList } from '@/views/book/courseware/data/common';

export default {
  name: 'FillSetting',
  mixins: [SettingMixin],
  data() {
    return {
      property: getFillProperty(),
      arrangeTypeList,
      audioPositionList,
      audioGenerationMethodList,
      fontList,
      switchOption,
      fillTypeList,
      voice_type_list: [],
      emotion_list: [],
      speedRatioList,
    };
  },
  created() {
    this.getTextToAudioConfParamList();
  },
  methods: {
    // 得到文本转音频的配置参数列表
    getTextToAudioConfParamList() {
      GetTextToAudioConfParamList()
        .then(({ status, voice_type_list, emotion_list }) => {
          if (status === 1) {
            this.voice_type_list = voice_type_list;
            this.emotion_list = emotion_list;
          }
        })
        .catch(() => {});
    },
  },
};
</script>

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

.el-form {
  @include setting-base;
}
</style>
