<template>
  <div class="parallel-node" :class="[data.selected ? 'selected' : '', data.status ? `status-${data.status}` : '']">
    <Handle type="target" :position="Position.Top" id="input" />
    <div class="node-header">
      <PartitionOutlined class="node-icon" />
      <span class="node-title">{{ data.label }}</span>
    </div>
    <div class="node-body">
      <div v-if="data.config?.max_parallel" class="node-detail">
        <span class="detail-label">最大并行数:</span>
        <span class="detail-value">{{ data.config.max_parallel }}</span>
      </div>
    </div>
    <div v-if="data.status" class="status-indicator">
      <LoadingOutlined v-if="data.status === 'running'" class="status-icon running-icon" />
      <CheckCircleFilled v-else-if="data.status === 'completed'" class="status-icon completed-icon" />
      <CloseCircleFilled v-else-if="data.status === 'failed'" class="status-icon failed-icon" />
      <ClockCircleFilled v-else-if="data.status === 'waiting_approval'" class="status-icon waiting-icon" />
    </div>
    <Handle type="source" :position="Position.Bottom" id="output" />
  </div>
</template>

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

defineProps<{
  data: WorkflowNodeData
}>()
</script>

<style scoped>
.parallel-node {
  background: var(--bg-primary);
  border: 2px solid var(--color-success);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 160px;
  font-size: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.3s, box-shadow 0.3s;
  position: relative;
}

.parallel-node:hover {
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.parallel-node.selected {
  border-color: var(--color-success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Execution status styles */
.parallel-node.status-running {
  border-color: var(--color-info);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.5);
  animation: pulse 1.5s ease-in-out infinite;
}

.parallel-node.status-completed {
  border-color: var(--color-success);
}

.parallel-node.status-failed {
  border-color: var(--color-error);
}

.parallel-node.status-waiting_approval {
  border-color: var(--color-warning);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 4px rgba(59, 130, 246, 0.3); }
  50% { box-shadow: 0 0 12px rgba(59, 130, 246, 0.7); }
}

/* Status indicator icon */
.status-indicator {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.status-icon {
  font-size: 14px;
}

.running-icon {
  color: var(--color-info);
  animation: spin 1s linear infinite;
}

.completed-icon {
  color: var(--color-success);
}

.failed-icon {
  color: var(--color-error);
}

.waiting-icon {
  color: var(--color-warning);
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

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

.node-icon {
  color: var(--color-success);
  font-size: 14px;
}

.node-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 13px;
}

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

.node-detail {
  display: flex;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 11px;
}

.detail-label {
  color: var(--text-placeholder);
}

.detail-value {
  color: var(--text-secondary);
}
</style>
