<script lang="ts" setup>
import { useVbenModal } from '@vben/common-ui';

import { ElMessage } from 'element-plus';

import { useVbenForm } from '#/adapter/form';
import { cdcmRuleAPI } from '#/cdcm/api/api';
import req from '#/cdcm/api/req_code';

const [Modal, modalApi] = useVbenModal();

const [BaseForm] = useVbenForm({
  commonConfig: {
    componentProps: {
      class: 'w-full',
    },
  },
  handleSubmit: onSubmit,
  layout: 'horizontal',
  schema: [
    {
      component: 'Input',
      componentProps: {
        placeholder: '请输入规则名称',
      },
      fieldName: 'label',
      label: '规则名称',
    },
    {
      component: 'Input',
      componentProps: {
        placeholder: '请输入规则描述',
      },
      fieldName: 'info',
      label: '规则描述',
    },
  ],
  wrapperClass: 'grid-cols-1',
});

async function onSubmit(values: Record<string, any>) {
  const res = await cdcmRuleAPI(values, req.CruleAddFlow);
  ElMessage.success(res);
  modalApi.close();
}
</script>

<template>
  <Modal title="新增规则" :footer="false">
    <BaseForm />
  </Modal>
</template>
