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

const MaterialPreview = defineAsyncComponent(() => import('@/components/MaterialPreview.vue'))

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

const role = inject('role') as string

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

const operateList = ref([{ label: '推送视频号视频', value: '0' }])

const { materialList } = useMaterial('4')

const { connectionList } = useConnection(10)

const material = computed(() => materialList.value.find(item => item.id === form.material_id))

watch(material, () => {
  if (material.value) {
    form.message = material.value.content
  }
})
</script>

<template>
  <ConfigTemplate :model="form" :node="node" :stepNum="2">
    <template #default="{ step }: { step: number }">
      <template v-if="step === 0">
        <el-form-item>
          <el-radio-group v-model="form.operate" v-if="step === 0">
            <el-radio v-for="item in operateList" :key="item.value" :value="item.value">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </template>
      <template v-else-if="step === 1">
        <el-form-item>
          <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>
        </el-form-item>
      </template>
      <template v-else-if="step === 2">
        <el-form-item>
          <el-select placeholder="请选择资料内容" v-model="form.material_id" style="width: 100%">
            <el-option v-for="item in materialList" :key="item.id" :value="item.id" :label="item.name"></el-option>
          </el-select>
          <MaterialPreview :data="material" v-if="material"></MaterialPreview>
        </el-form-item>
        <!-- <el-form-item prop="message">
          <el-input v-model="form.message" :rows="3" type="textarea" placeholder="请输入短信内容"></el-input>
        </el-form-item> -->
      </template>
    </template>
  </ConfigTemplate>
</template>
