<script setup lang="ts">
import { Handle, Position } from '@vue-flow/core'
import { ref } from 'vue'

interface InputOutput {
  id: string
  name: string
  type: string
  value?: any
}

interface Props {
  data: {
    label: string
    description?: string
    inputs?: InputOutput[]
    outputs?: InputOutput[]
  }
}

const props = withDefaults(defineProps<Props>(), {
  data: () => ({ 
    label: '结束',
    inputs: [
      { id: 'end_input', name: '最终结果', type: 'any', value: null }
    ],
    outputs: []
  })
})
</script>

<template>
  <div class="workflow-node end-node">
    <!-- 节点头部 -->
    <div class="node-header">
      <div class="node-icon">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none">
          <circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="2" fill="currentColor"/>
          <path d="M15 9l-6 6m0-6l6 6" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
        </svg>
      </div>
      <span class="node-title">{{ data.label }}</span>
    </div>
    
    <!-- 节点描述 -->
    <div v-if="data.description" class="node-description">
      {{ data.description }}
    </div>
    
    <!-- 输入参数区域 -->
    <div v-if="data.inputs && data.inputs.length" class="node-params">
      <div class="params-title">输入</div>
      <div 
        v-for="(input, index) in data.inputs" 
        :key="input.id"
        class="param-item input-param"
      >
        <Handle 
          :id="input.id"
          :position="Position.Left" 
          type="target" 
          class="param-handle param-handle-input"
          :style="{ top: `${60 + index * 28}px` }"
        />
        <div class="param-info">
          <div class="param-name">{{ input.name }}</div>
          <div class="param-type">{{ input.type }}</div>
        </div>
      </div>
    </div>
    
    <!-- 结果显示区域 -->
    <div class="result-section">
      <div class="params-title">输出</div>
      <div class="result-info">
        <div class="result-text">工作流执行完成</div>
        <div class="result-status">状态: 已完成</div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.workflow-node {
  background: white;
  border: 2px solid #e1e5e9;
  border-radius: 8px;
  min-width: 200px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: relative;
  font-size: 12px;
}

.end-node {
  border-color: #ff4d4f;
}

.end-node .node-header {
  background: linear-gradient(135deg, #ff4d4f, #d9363e);
  color: white;
}

.node-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px 6px 0 0;
  background: #f5f5f5;
}

.node-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
}

.node-title {
  font-weight: 600;
  font-size: 13px;
}

.node-description {
  padding: 8px 12px;
  font-size: 11px;
  color: #666;
  border-bottom: 1px solid #f0f0f0;
}

.node-params {
  padding: 8px 12px;
}

.result-section {
  padding: 8px 12px;
}

.params-title {
  font-size: 10px;
  color: #999;
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.param-item {
  display: flex;
  align-items: center;
  padding: 4px 0;
  min-height: 24px;
  position: relative;
}

.input-param {
  padding-left: 12px;
}

.param-info {
  flex: 1;
}

.param-name {
  font-size: 11px;
  font-weight: 500;
  color: #333;
  line-height: 1.2;
}

.param-type {
  font-size: 10px;
  color: #999;
  line-height: 1.2;
}

.result-info {
  background: #f6ffed;
  border: 1px solid #b7eb8f;
  border-radius: 4px;
  padding: 8px;
}

.result-text {
  font-size: 11px;
  font-weight: 500;
  color: #389e0d;
  line-height: 1.2;
}

.result-status {
  font-size: 10px;
  color: #52c41a;
  line-height: 1.2;
  margin-top: 2px;
}

.param-handle {
  width: 8px;
  height: 8px;
  border: 2px solid #fff;
  border-radius: 50%;
  position: absolute !important;
}

.param-handle-input {
  background: #1890ff;
  left: -6px;
}

.param-handle:hover {
  transform: scale(1.2);
  transition: transform 0.2s ease;
}

/* 连接状态 */
.param-handle.connected {
  background: #722ed1;
  box-shadow: 0 0 0 2px rgba(114, 46, 209, 0.2);
}
</style>