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

import BaseNode from './BaseNode.vue';

defineProps(['selected', 'data', 'id']);

const getFunctionLabel = (func: string) => {
  const map: Record<string, string> = {
    complete: $t('ai-platform.workflow.nodes.snowflake_cortex_llm.complete'),
    summarize: $t('ai-platform.workflow.nodes.snowflake_cortex_llm.summarize'),
    translate: $t('ai-platform.workflow.nodes.snowflake_cortex_llm.translate'),
    sentiment: $t('ai-platform.workflow.nodes.snowflake_cortex_llm.sentiment'),
    extract_answer: $t(
      'ai-platform.workflow.nodes.snowflake_cortex_llm.extractAnswer',
    ),
  };
  return map[func] || func;
};
</script>

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

    <div class="space-y-2">
      <div
        class="flex items-center justify-between rounded bg-cyan-50 px-2 py-1 text-cyan-700 dark:bg-cyan-950 dark:text-cyan-300"
      >
        <span class="font-medium">{{
          $t('ai-platform.workflow.nodes.snowflake_cortex_llm.function')
        }}</span>
        <span>{{
          getFunctionLabel(data.function) ||
          $t('ai-platform.workflow.nodes.snowflake_cortex_llm.selectFunction')
        }}</span>
      </div>

      <div
        v-if="data.function === 'complete'"
        class="text-muted-foreground space-y-1 text-xs"
      >
        <div class="flex justify-between">
          <span>{{
            $t('ai-platform.workflow.nodes.snowflake_cortex_llm.model')
          }}</span>
          <span>{{ data.complete?.model || 'mistral-large' }}</span>
        </div>
        <div class="flex justify-between">
          <span>{{
            $t('ai-platform.workflow.nodes.snowflake_cortex_llm.prompt')
          }}</span>
          <span>{{
            data.complete?.prompt
              ? $t('ai-platform.workflow.nodes.common.configured')
              : '-'
          }}</span>
        </div>
      </div>

      <div
        v-else-if="data.function === 'translate'"
        class="text-muted-foreground space-y-1 text-xs"
      >
        <div class="flex justify-between">
          <span>{{
            $t('ai-platform.workflow.nodes.snowflake_cortex_llm.translateLabel')
          }}</span>
          <span>{{ data.translate?.source_language || 'en' }} →
            {{ data.translate?.target_language || 'zh' }}</span>
        </div>
      </div>

      <div v-else class="text-muted-foreground text-xs">
        <div class="flex justify-between">
          <span>{{
            $t('ai-platform.workflow.nodes.snowflake_cortex_llm.inputText')
          }}</span>
          <span>{{
            data[data.function]?.text
              ? $t('ai-platform.workflow.nodes.common.configured')
              : '-'
          }}</span>
        </div>
      </div>

      <div class="rounded bg-green-50 px-2 py-1 text-xs dark:bg-green-950">
        <div
          class="flex items-center justify-between text-green-700 dark:text-green-300"
        >
          <span>{{
            $t('ai-platform.workflow.nodes.common.outputVariable')
          }}</span>
          <span class="font-mono">{{
            data.output_variable || 'cortex_result'
          }}</span>
        </div>
      </div>
    </div>
  </BaseNode>
</template>
