<template>
  <div class="node-config">
    <el-divider content-position="left">工具选择</el-divider>
    
    <el-form-item label="工具类型">
      <el-select :model-value="modelValue.tool_type" @change="update('tool_type', $event)" placeholder="选择工具类型">
        <el-option label="企微消息" value="wecom_message" />
        <el-option label="任务管理" value="task_management" />
        <el-option label="文档处理" value="document_processing" />
        <el-option label="格式处理" value="format_processing" />
        <el-option label="数据查询" value="data_query" />
        <el-option label="报表生成" value="report_generation" />
        <el-option label="HTTP请求" value="http_request" />
      </el-select>
    </el-form-item>
    
    <el-form-item label="工具名称">
      <el-select :model-value="modelValue.tool_name" @change="update('tool_name', $event)" placeholder="选择具体工具">
        <template v-if="modelValue.tool_type === 'wecom_message'">
          <el-option label="发送企微通知" value="send_notification" />
          <el-option label="查询企微用户" value="query_wecom_user" />
          <el-option label="推送任务至企微" value="push_task_to_wecom" />
          <el-option label="查询下属" value="list_subordinates" />
        </template>
        <template v-else-if="modelValue.tool_type === 'task_management'">
          <el-option label="查询任务列表" value="list_tasks" />
          <el-option label="创建任务" value="create_task" />
          <el-option label="查询任务详情" value="get_task" />
          <el-option label="更新任务" value="update_task" />
        </template>
        <template v-else-if="modelValue.tool_type === 'document_processing'">
          <el-option label="解析文档" value="parse_document" />
        </template>
        <template v-else-if="modelValue.tool_type === 'format_processing'">
          <el-option label="修正格式" value="format_correction" />
        </template>
        <template v-else-if="modelValue.tool_type === 'report_generation'">
          <el-option label="生成效率报告" value="generate_efficiency_report" />
          <el-option label="任务统计" value="get_task_statistics" />
          <el-option label="员工看板" value="get_employee_dashboard" />
        </template>
        <template v-else-if="modelValue.tool_type === 'http_request'">
          <el-option label="自定义HTTP请求" value="custom_http_request" />
        </template>
      </el-select>
    </el-form-item>
    
    <el-divider content-position="left">参数配置</el-divider>
    
    <el-form-item label="参数映射">
      <el-input :model-value="modelValue.param_mapping || '{}'" type="textarea" :rows="3" @input="(e: any) => update('param_mapping', e)" placeholder='{"input_key": "output_key"}' />
    </el-form-item>
    
    <el-form-item label="超时时间(秒)">
      <el-input-number :model-value="modelValue.timeout ?? 30" :min="1" :max="300" :step="10" @change="update('timeout', $event)" />
    </el-form-item>
    
    <el-form-item label="重试次数">
      <el-input-number :model-value="modelValue.retry_count ?? 0" :min="0" :max="5" :step="1" @change="update('retry_count', $event)" />
    </el-form-item>
    
    <el-form-item label="错误处理">
      <el-select :model-value="modelValue.error_handling || 'throw'" @change="update('error_handling', $event)">
        <el-option label="抛出错误" value="throw" />
        <el-option label="返回默认值" value="default" />
        <el-option label="跳过继续" value="skip" />
      </el-select>
    </el-form-item>
  </div>
</template>

<script setup lang="ts">
const props = defineProps<{
  modelValue: any
}>()

const emit = defineEmits(['change', 'update:modelValue'])

function update(key: string, val: any) {
  emit('change')
  emit('update:modelValue', { ...props.modelValue, [key]: val })
}
</script>
