<template>
  <div>
    <el-form :model="property" :label-position="labelPosition" label-width="72px">
      <el-form-item label="序号" class="serial-number">
        <el-input v-model="property.serial_number" />
        <SvgIcon icon-class="switch" size="14" @click="switchSerialNumber(property)" />
      </el-form-item>
      <el-form-item>
        <el-radio
          v-for="{ value, label } in snGenerationMethodList"
          :key="value"
          v-model="property.sn_generation_method"
          :label="value"
        >
          {{ label }}
        </el-radio>
      </el-form-item>
      <el-form-item label="序号样式">
        <SelectSerialNumberStyle
          :serial-number="property.serial_number"
          :sn-style="property.sn_style"
          :sn-background-color="property.sn_background_color"
          @changeSerialNumberStyle="changeSerialNumberStyle"
        />
      </el-form-item>
      <el-form-item label="序号位置">
        <SerialNumberPosition :position="property.sn_position" @changeNumberPosition="changeNumberPosition" />
      </el-form-item>
      <el-divider />
      <el-form-item label="标签颜色" :style="cssVars">
        <el-select v-model="property.label_color" class="label-color">
          <el-option
            v-for="(color, i) in labelColorList"
            :key="i"
            :label="color.label"
            :value="color.value"
            :style="{ color: color.value === 'random' ? '#000' : color.value }"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="标签字体">
        <el-select v-model="property.label_font">
          <el-option label="中文" value="chinese" />
        </el-select>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import SettingMixin from '@/views/book/courseware/create/components/common/SettingMixin';
import { snGenerationMethodList } from '@/views/book/courseware/data/common';
import { getLabelProperty, labelColorList } from '@/views/book/courseware/data/label';

export default {
  name: 'LabelSetting',
  mixins: [SettingMixin],
  data() {
    return {
      snGenerationMethodList,
      labelColorList,
      labelPosition: 'left',
      property: getLabelProperty(),
    };
  },
  computed: {
    cssVars() {
      let _color = this.property.label_color;
      return {
        '--color1': _color === 'random' ? '#000' : _color,
      };
    },
  },
  methods: {},
};
</script>

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

.el-form {
  @include setting-base;

  .label-color {
    :deep .el-input__inner {
      color: var(--color1) !important;
    }
  }
}
</style>
