<script setup lang="ts">
import { Trash2 } from '@vben/icons';
import { $t } from '@vben/locales';

import DbNodeConnectionBadge from '../components/DbNodeConnectionBadge.vue';
import BaseNode from './BaseNode.vue';

defineProps(['selected', 'data', 'id']);
</script>

<template>
  <BaseNode
    :selected="selected"
    :execution-status="data.executionStatus"
    :execution-result="data.executionResult"
    :label="data.label || $t('ai-platform.workflow.nodes.db_delete.label')"
    :inputs="[{ id: 'target' }]"
    :outputs="[{ id: 'source' }]"
    :node-id="id"
    node-type="db_delete"
  >
    <template #icon><Trash2 class="size-5 text-red-600" /></template>
    <template #desc>
      {{ $t('ai-platform.workflow.nodes.db_delete.desc') }}
    </template>

    <div class="space-y-2">
      <DbNodeConnectionBadge
        :db-config="data.db_config"
        show-default-badge
      />

      <!-- 表名 -->
      <div class="flex items-center gap-2">
        <span
          class="rounded border border-red-200 bg-red-50 px-1.5 py-0.5 text-[10px] font-bold text-red-600"
        >
          DELETE
        </span>
        <span
          class="text-foreground flex-1 truncate font-mono text-xs"
          :title="data.table"
        >
          {{ data.table || $t('ai-platform.workflow.nodes.db_delete.noTable') }}
        </span>
      </div>

      <!-- 条件预览 -->
      <div
        v-if="data.where_conditions && data.where_conditions.length > 0"
        class="rounded bg-red-50 px-2 py-1.5"
      >
        <div class="text-[10px] text-red-700">
          {{
            $t('ai-platform.workflow.nodes.common.conditions', {
              count: data.where_conditions.length,
            })
          }}
        </div>
      </div>
      <div v-else class="rounded bg-red-100 px-2 py-1.5">
        <div class="text-[10px] font-medium text-red-600">
          {{ $t('ai-platform.workflow.nodes.db_delete.mustSetCondition') }}
        </div>
      </div>
    </div>
  </BaseNode>
</template>
