import {
  MyBetaModalFormProps,
  MyButtons,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { MomentSelect } from '@/components/MomentCategories';
import { Apis } from '@/gen/Apis';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { Form, message } from 'antd';
export default function Create(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Customer.CustomerMomentCategories.Store>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      wrapperCol={{ span: 24 }}
      width="500px"
      trigger={<MyButtons.Create title={`添加${props.title}`} />}
      key={new Date().getTime()}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      onFinish={async (values) =>
        Apis.Customer.CustomerMomentCategories.Store(values)
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        MomentSelect.MomentCategoriesTree(),
        {
          key: 'name',
          title: '分类名称',
          formItemProps: { ...rulesHelper.text },
        },
      ]}
    />
  );
}
