<script setup lang="ts">
import { ref, watch } from 'vue';

import { $t } from '@vben/locales';

import { ElForm, ElFormItem, ElInput } from 'element-plus';

import ConfirmModeSelect from '../components/ConfirmModeSelect.vue';
import SmartInput from '../components/SmartInput.vue';

const props = defineProps<{ data: any; nodeId: string }>();
const emit = defineEmits(['update']);

const form = ref({
  label: $t('ai-platform.workflow.panels.appDesign.label'),
  design_content: '',
  design_title: $t(
    'ai-platform.workflow.panels.appDesign.designTitlePlaceholder',
  ),
  require_confirmation: true,
  ...props.data,
});

watch(
  form,
  (val) => {
    emit('update', val);
  },
  { deep: true },
);
</script>

<template>
  <ElForm label-position="top">
    <ElFormItem :label="$t('ai-platform.workflow.panels.common.nodeName')">
      <ElInput
        v-model="form.label"
        :placeholder="$t('ai-platform.workflow.panels.appDesign.placeholder')"
      />
    </ElFormItem>

    <ElFormItem>
      <template #label>
        <div class="flex items-center gap-2">
          <span>{{
            $t('ai-platform.workflow.panels.appDesign.designContent')
          }}</span>
          <span class="text-red-500">*</span>
        </div>
      </template>
      <SmartInput
        v-model="form.design_content"
        :current-node-id="nodeId"
        type="textarea"
        :rows="6"
        :placeholder="
          $t('ai-platform.workflow.panels.appDesign.designContentPlaceholder')
        "
      />
      <div class="text-muted-foreground mt-1 text-xs">
        {{ $t('ai-platform.workflow.panels.appDesign.designContentHint')
        }}<code v-pre>{{llm-1.output}}</code>
      </div>
    </ElFormItem>

    <ElFormItem
      :label="$t('ai-platform.workflow.panels.appDesign.designTitle')"
    >
      <SmartInput
        v-model="form.design_title"
        :current-node-id="nodeId"
        :placeholder="
          $t('ai-platform.workflow.panels.appDesign.designTitlePlaceholder')
        "
      />
    </ElFormItem>

    <ElFormItem :label="$t('ai-platform.workflow.panels.common.confirmMode')">
      <ConfirmModeSelect
        v-model="form.require_confirmation"
        :current-node-id="nodeId"
      />
    </ElFormItem>

    <!-- 输出变量说明 -->
    <div
      class="mt-4 rounded border border-green-200 bg-green-50 p-3 dark:border-green-800 dark:bg-green-950"
    >
      <div class="mb-2 font-medium text-green-700 dark:text-green-300">
        {{ $t('ai-platform.workflow.panels.common.outputVars') }}
      </div>
      <div class="text-muted-foreground space-y-1 text-xs">
        <div class="flex justify-between">
          <span class="font-mono">design_content</span>
          <span>{{
            $t('ai-platform.workflow.panels.appDesign.designContentOutput')
          }}</span>
        </div>
        <div class="flex justify-between">
          <span class="font-mono">design_title</span>
          <span>{{
            $t('ai-platform.workflow.panels.appDesign.designTitleOutput')
          }}</span>
        </div>
        <div class="flex justify-between">
          <span class="font-mono">confirmed</span>
          <span>{{
            $t('ai-platform.workflow.panels.appDesign.confirmedOutput')
          }}</span>
        </div>
      </div>
    </div>
  </ElForm>
</template>
