<template>
  <div class="switch-props">
    <FormItem label="开启提示">
      <Input v-model="info.form.open" placeholder="请输入开启提示"></Input>
    </FormItem>
    <FormItem label="关闭提示">
      <Input v-model="info.form.close" placeholder="请输入关闭提示"></Input>
    </FormItem>
    <FormItem label="开启值">
      <Input v-model="info.form.trueValue" placeholder="请输入开启值"></Input>
    </FormItem>
    <FormItem label="关闭值">
      <Input v-model="info.form.falseValue" placeholder="请输入关闭值"></Input>
    </FormItem>
  </div>
</template>

<script>
const DEFAULT_LIST = [
  { key: 'trueValue', default: 'true' },
  { key: 'falseValue', default: 'false' },
  { key: 'trueColor', default: '' },
  { key: 'falseColor', default: '' },
]

export default {
  name: 'SwitchProp',
  props: {
    info: {
      type: Object,
      default() {
        return {
          form: {
            options: [],
          },
        }
      },
    },
  },
  watch: {
    'info.form': {
      handler() {
        const { form } = this.info
        if (Object.keys(form).length) { return }
        for (const val of DEFAULT_LIST) {
          if (!form[val.key] && form[val.key] !== 0) {
            this.$set(form, val.key, val.default)
          }
        }
      },
      deep: true,
      immediate: true,
    },
  },
}
</script>
