<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.frame_type">
          <el-radio v-for="{ value, label } in frameList" :key="value" :label="value" :value="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="框颜色">
        <el-color-picker v-model="property.frame_color" />
      </el-form-item>
      <el-form-item label="框大小">
        <el-radio-group v-model="property.frame_size">
          <el-radio v-for="{ value, label } in frameSizeList" :key="value" :label="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>

      <el-divider />
      <el-form-item v-if="property.model === 'miao'" label="描红格">
        <el-input-number v-model="property.miao_number" :min="0" :step="1" />
      </el-form-item>
      <el-form-item v-if="property.model === 'miao'" label="书写格">
        <el-input-number v-model="property.write_number" :min="0" :step="1" />
      </el-form-item>
      <el-divider v-if="property.model === 'miao'" />
      <el-form-item v-if="property.model === 'miao'" label="错误提示">
        <el-radio-group v-model="property.is_enable_error">
          <el-radio v-for="{ value, label } in showList" :key="value" :label="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="笔迹回放">
        <el-radio-group v-model="property.is_enable_play_back">
          <el-radio v-for="{ value, label } in showList" :key="value" :label="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="笔画动画">
        <el-radio-group v-model="property.is_enable_stroke">
          <el-radio v-for="{ value, label } in showList" :key="value" :label="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="拼音">
        <el-radio-group v-model="property.view_pinyin">
          <el-radio v-for="{ value, label } in showList" :key="value" :label="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="释义">
        <el-radio-group v-model="property.is_enable_shiyi">
          <el-radio v-for="{ value, label } in showList" :key="value" :label="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="读音">
        <el-radio-group v-model="property.is_enable_voice">
          <el-radio v-for="{ value, label } in showList" :key="value" :label="value">
            {{ label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item v-if="property.is_enable_voice === 'true'" 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-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>
      <AddAnswer />
    </el-form>
  </div>
</template>

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

import {
  getCharacterProperty,
  switchOption,
  funList,
  showList,
  isEnable,
  frameList,
  audioGenerationMethodList,
  frameSizeList,
} from '@/views/book/courseware/data/character';
import { GetTextToAudioConfParamList } from '@/api/app';
import { speedRatioList } from '@/views/book/courseware/data/common';

export default {
  name: 'CharacterSetting',
  mixins: [SettingMixin],
  data() {
    return {
      audioGenerationMethodList,
      property: getCharacterProperty(),
      switchOption,
      isEnable,
      funList,
      showList,
      frameList,
      voice_type_list: [],
      emotion_list: [],
      speedRatioList,
      frameSizeList,
    };
  },
  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>
