<script setup lang="ts">
import ConfigTemplate from '../../ConfigTemplate.vue'
import { useConnection } from '../../../composables/useAllData'

const props = defineProps<{ node: any }>()

const role = inject('role') as string

const form = reactive({
  operate: '',
  operate_name: '',
  connection_id: '',
  connection_name: ''
})
watchEffect(() => {
  Object.assign(form, props.node.data[role])
})

const { connectionList } = useConnection(1)

const operateList = ref([{ label: '关注中', value: '0' }])

watchEffect(() => {
  form.operate_name = operateList.value.find(item => item.value === form.operate)?.label || ''
})

watchEffect(() => {
  form.connection_name = connectionList.value.find(item => item.id === form.connection_id)?.name || ''
})
</script>

<template>
  <ConfigTemplate :model="form" :node="node" :stepNum="1">
    <template #default="{ step }: { step: number }">
      <el-form-item>
        <template v-if="step === 0">
          <el-radio-group v-model="form.operate" v-if="step === 0">
            <el-radio v-for="item in operateList" :key="item.value" :value="item.value" style="width: 105px">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </template>
        <template v-else-if="step === 1">
          <el-select placeholder="请选择关联使用公众号" style="width: 100%" v-model="form.connection_id">
            <el-option v-for="item in connectionList" :key="item.id" :value="item.id" :label="item.name"></el-option>
          </el-select>
        </template>
      </el-form-item>
    </template>
  </ConfigTemplate>
</template>
