<template>
  <div class="condition-node" :class="{ selected: data.selected }">
    <Handle type="target" :position="Position.Left" id="input" />
    <div class="diamond-shape">
      <div class="diamond-content">
        <BranchesOutlined class="node-icon" />
        <span class="node-title">{{ data.label }}</span>
      </div>
    </div>
    <div v-if="data.config?.expression" class="condition-expr">
      {{ data.config.expression }}
    </div>
    <Handle type="source" :position="Position.Top" id="yes" class="handle-yes" />
    <Handle type="source" :position="Position.Bottom" id="no" class="handle-no" />
    <div class="handle-labels">
      <span class="label-yes">是</span>
      <span class="label-no">否</span>
    </div>
  </div>
</template>

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

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

<style scoped>
.condition-node {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 140px;
}

.diamond-shape {
  background: #fff;
  border: 2px solid #faad14;
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transform: none;
  transition: box-shadow 0.2s;
}

.condition-node:hover .diamond-shape {
  box-shadow: 0 4px 12px rgba(250, 173, 20, 0.25);
}

.condition-node.selected .diamond-shape {
  border-color: #d48806;
  box-shadow: 0 0 0 3px rgba(250, 173, 20, 0.2);
}

.diamond-content {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

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

.condition-expr {
  margin-top: 4px;
  padding: 2px 8px;
  background: #fffbe6;
  border: 1px solid #ffe58f;
  border-radius: 4px;
  font-size: 11px;
  color: #8c6900;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.handle-yes {
  background: #52c41a;
}

.handle-no {
  background: #ff4d4f;
}

.handle-labels {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 2px;
  padding: 0 4px;
}

.label-yes {
  color: #52c41a;
  font-size: 11px;
  font-weight: 600;
}

.label-no {
  color: #ff4d4f;
  font-size: 11px;
  font-weight: 600;
}
</style>
