<script setup>
import { computed } from 'vue'

const props = defineProps(['id', 'type', 'label', 'selected', 'data'])
const emit = defineEmits(['node-click'])

const shapeStyle = computed(() => {
  return {
    width: `${props.data?.width || 200}px`,
    height: `${props.data?.height || 80}px`,
    '--node-bg-color': props.data?.backgroundColor || '#fffbeb',
    '--node-border-color': props.data?.borderColor || '#fbbf24',
    '--node-text-color': props.data?.textColor || '#92400e',
    backgroundColor: props.data?.backgroundColor || '#fffbeb',
    border: `2px dashed ${props.data?.borderColor || '#fbbf24'}`,
    borderRadius: '4px',
    position: 'relative',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    color: props.data?.textColor || '#92400e',
    fontSize: '12px',
    fontWeight: '400',
    cursor: 'move',
    zIndex: -10, // Behind process nodes
    fontStyle: 'italic'
  }
})

const displayLabel = computed(() => props.label || props.data?.label || '')
const displayDescription = computed(() => props.data?.description || '')

const onClick = () => emit('node-click', props.id)
</script>

<template>
  <div 
    :class="['shape-node', 'text-annotation', { 'selected': selected }]"
    :style="shapeStyle"
    @click="onClick"
  >
    <div class="shape-content" v-if="displayLabel || displayDescription">
      <div class="shape-label" v-if="displayLabel">{{ displayLabel }}</div>
      <div class="shape-description" v-if="displayDescription">{{ displayDescription }}</div>
    </div>
  </div>
</template>

<style scoped>
.text-annotation {
  border-style: dashed !important;
  background: rgba(255, 251, 235, 0.8) !important;
  font-style: italic !important;
}

.text-annotation.selected {
  border-color: #3b82f6 !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}

.text-annotation:hover {
  border-color: #94a3b8 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}

.shape-content {
  position: relative;
  z-index: 1;
  text-align: center;
  overflow: hidden;
  padding: 8px;
}

.shape-label {
  font-weight: 500;
  margin-bottom: 4px;
  user-select: none;
  word-wrap: break-word;
}

.shape-description {
  font-size: 12px;
  opacity: 0.7;
  user-select: none;
  word-wrap: break-word;
}

/* Ensure shapes don't interfere with node connections */
.shape-content * {
  pointer-events: none;
}

.text-annotation {
  pointer-events: all;
}

/* Resize handles for shapes when selected */
.text-annotation.selected::after {
  content: '';
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 8px;
  height: 8px;
  background: #3b82f6;
  border: 2px solid white;
  border-radius: 50%;
  cursor: nw-resize;
  pointer-events: all;
}
</style> 