<template>
  <div class="approval-node" :class="{ selected: data.selected, paused: isPaused }">
    <Handle type="target" :position="Position.Left" id="input" />
    <div class="node-header">
      <UserOutlined class="node-icon" />
      <span class="node-title">{{ data.label }}</span>
      <a-tag v-if="isPaused" color="orange" class="pause-tag">等待审批</a-tag>
    </div>
    <div class="node-body">
      <div v-if="data.config?.approver" class="node-detail">
        <span class="detail-label">审批人:</span>
        <span class="detail-value">{{ data.config.approver }}</span>
      </div>
      <div v-if="data.config?.timeout" class="node-detail">
        <span class="detail-label">超时:</span>
        <span class="detail-value">{{ data.config.timeout }}s</span>
      </div>
    </div>
    <Handle type="source" :position="Position.Right" id="output" />
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { Handle, Position } from '@vue-flow/core'
import { UserOutlined } from '@ant-design/icons-vue'
import type { WorkflowNodeData } from '@/utils/workflowSerializer'

const props = defineProps<{
  data: WorkflowNodeData
}>()

const isPaused = computed(() => {
  return props.data.config?.status === 'paused'
})
</script>

<style scoped>
.approval-node {
  background: #fff;
  border: 2px solid #722ed1;
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 160px;
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: box-shadow 0.2s;
}

.approval-node:hover {
  box-shadow: 0 4px 12px rgba(114, 46, 209, 0.25);
}

.approval-node.selected {
  border-color: #531dab;
  box-shadow: 0 0 0 3px rgba(114, 46, 209, 0.2);
}

.approval-node.paused {
  border-color: #fa8c16;
  animation: pulse-border 2s ease-in-out infinite;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); }
  50% { box-shadow: 0 0 0 4px rgba(250, 140, 22, 0.3); }
}

.node-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.node-icon {
  color: #722ed1;
  font-size: 14px;
}

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

.pause-tag {
  font-size: 10px;
  line-height: 16px;
  padding: 0 4px;
  margin-left: auto;
}

.node-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.node-detail {
  display: flex;
  gap: 4px;
  color: #666;
  font-size: 11px;
}

.detail-label {
  color: #999;
}

.detail-value {
  color: #666;
}
</style>
