<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.dashboardDesign.label'),
  dashboard_code: '',
  design_title: $t('ai-platform.workflow.panels.dashboardDesign.designTitle'),
  design_suggestion: '',
  require_confirmation: true,
  ...props.data,
});

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

<template>
  <div class="space-y-4">
    <ElForm :model="form" label-position="top" size="small">
      <ElFormItem :label="$t('ai-platform.workflow.panels.common.nodeName')">
        <ElInput
          v-model="form.label"
          :placeholder="
            $t('ai-platform.workflow.panels.dashboardDesign.placeholder')
          "
        />
      </ElFormItem>

      <ElFormItem
        :label="$t('ai-platform.workflow.panels.dashboardDesign.dashboardCode')"
      >
        <SmartInput
          v-model="form.dashboard_code"
          :placeholder="
            $t(
              'ai-platform.workflow.panels.dashboardDesign.dashboardCodePlaceholder',
            )
          "
          :current-node-id="nodeId"
        />
      </ElFormItem>

      <ElFormItem
        :label="
          $t('ai-platform.workflow.panels.dashboardDesign.designTitleLabel')
        "
      >
        <ElInput
          v-model="form.design_title"
          :placeholder="
            $t('ai-platform.workflow.panels.dashboardDesign.placeholder')
          "
        />
      </ElFormItem>

      <ElFormItem
        :label="
          $t('ai-platform.workflow.panels.dashboardDesign.designSuggestion')
        "
      >
        <SmartInput
          v-model="form.design_suggestion"
          type="textarea"
          :placeholder="
            $t(
              'ai-platform.workflow.panels.dashboardDesign.designSuggestionPlaceholder',
            )
          "
          :current-node-id="nodeId"
        />
      </ElFormItem>

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

    <div class="bg-muted/50 rounded-lg p-3">
      <div class="text-muted-foreground text-xs">
        <p class="mb-2 font-medium">
          {{ $t('ai-platform.workflow.panels.common.usage') }}:
        </p>
        <ul class="list-inside list-disc space-y-1">
          <li>
            {{ $t('ai-platform.workflow.panels.dashboardDesign.usageTip1') }}
          </li>
          <li>
            {{ $t('ai-platform.workflow.panels.dashboardDesign.usageTip2') }}
          </li>
          <li>
            {{ $t('ai-platform.workflow.panels.dashboardDesign.usageTip3') }}
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
