<script setup lang="ts">
import ConfigTemplate from '../../ConfigTemplate.vue'

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

const role = inject('role') as string

const form = reactive({
  time_type: '0',
  time_num: '',
  time_unit: '0',
  time_unit_name: '',
  time: '',
  time_name: ''
})
watchEffect(() => {
  Object.assign(form, props.node.data[role])
})

const timeUnitList = ref([
  { label: '分钟', value: '0' },
  { label: '小时', value: '1' },
  { label: '日', value: '2' },
  { label: '周', value: '3' }
])

watchEffect(() => {
  form.time_unit_name = timeUnitList.value.find(item => item.value === form.time_unit)?.label || ''
})

watchEffect(() => {
  form.time_name = form.time_type === '0' ? `延时${form.time_num}${form.time_unit_name}` : `延时至 ${form.time}`
})
</script>

<template>
  <ConfigTemplate :model="form" :node="node">
    <el-form-item>
      <el-radio-group v-model="form.time_type" style="display: block">
        <el-radio value="0" size="large" style="display: block">
          <span>延时 </span>
          <el-input :disabled="form.time_type !== '0'" v-model="form.time_num" placeholder="请输入" class="input-with-select">
            <template #append>
              <el-select v-model="form.time_unit" placeholder="请选择" style="width: 115px" :disabled="form.time_type !== '0'">
                <el-option v-for="item in timeUnitList" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </template>
          </el-input>
        </el-radio>
        <el-radio value="1" size="large" style="display: block">
          <span>延时至 </span>
          <el-date-picker :disabled="form.time_type !== '1'" v-model="form.time" type="datetime" placeholder="请选择" value-format="YYYY-MM-DD HH:mm:ss" />
        </el-radio>
      </el-radio-group>
    </el-form-item>
  </ConfigTemplate>
</template>
