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

import { useVbenModal } from '@vben/common-ui';

import { message } from 'ant-design-vue';

import formDesign from './index.vue';

const emit = defineEmits(['success']);
const modelRef = ref<Record<string, any>>({});
const isUpdate = ref(true);

const [Modal, { close, setState, getData }] = useVbenModal({
  fullscreenButton: false,
  fullscreen: true,
  draggable: false,
  onCancel() {
    close();
  },
  onConfirm: async () => {
    try {
      close();
      emit('success');
    } catch {
      message.error('操作失败');
    } finally {
      setState({ confirmLoading: false });
    }
  },
  onOpenChange: async (isOpen: boolean) => {
    if (isOpen) {
      setState({ loading: true });
      const data = getData<Record<string, any>>();
      isUpdate.value = !!data.isUpdate;
      modelRef.value = { ...data.baseData };
      setState({ title: unref(isUpdate) ? '表单设计' : '表单设计' });

      setState({ loading: false });
    }
  },
  title: '表单设计',
});

onMounted(async () => {});
</script>
<template>
  <Modal>
    <formDesign />
  </Modal>
</template>
