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

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

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

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.appUpdate.label'),
  settings: '',
  application_id: '',
  ...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.appUpdate.placeholder')"
      />
    </ElFormItem>

    <ElFormItem>
      <template #label>
        <div class="flex items-center gap-2">
          <span>{{
            $t('ai-platform.workflow.panels.appUpdate.appSettingsLabel')
          }}</span>
          <span class="text-red-500">*</span>
        </div>
      </template>
      <SmartInput
        v-model="form.settings"
        :current-node-id="nodeId"
        :placeholder="
          $t('ai-platform.workflow.panels.appUpdate.appSettingsPlaceholder')
        "
      />
      <div class="text-muted-foreground mt-1 text-xs">
        {{ $t('ai-platform.workflow.panels.appUpdate.appSettingsHint')
        }}<code v-pre>{{app_settings-1.settings}}</code>
      </div>
    </ElFormItem>

    <ElFormItem :label="$t('ai-platform.workflow.panels.appUpdate.appId')">
      <SmartInput
        v-model="form.application_id"
        :current-node-id="nodeId"
        :placeholder="
          $t('ai-platform.workflow.panels.appUpdate.appIdPlaceholder')
        "
      />
      <div class="text-muted-foreground mt-1 text-xs">
        {{ $t('ai-platform.workflow.panels.appUpdate.appIdHint')
        }}<code v-pre>{{ application_id }}</code>
      </div>
    </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">update_success</span>
          <span>{{
            $t('ai-platform.workflow.panels.appUpdate.updateSuccess')
          }}</span>
        </div>
        <div class="flex justify-between">
          <span class="font-mono">config_id</span>
          <span>{{
            $t('ai-platform.workflow.panels.appUpdate.configId')
          }}</span>
        </div>
        <div class="flex justify-between">
          <span class="font-mono">update_message</span>
          <span>{{
            $t('ai-platform.workflow.panels.appUpdate.updateMessage')
          }}</span>
        </div>
      </div>
    </div>
  </ElForm>
</template>
