import {
  MyBetaModalFormProps,
  MyButtons,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
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.Asset.AssetBuildings.Store>
      {...MyModalFormProps.props}
      form={form}
      title={`${props.title}`}
      wrapperCol={{ span: 24 }}
      width="500px"
      trigger={
        <MyButtons.Create
          title={`${props.title}`}
          size={props?.item?.size || 'small'}
        />
      }
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      key={new Date().getTime()}
      onFinish={async (values) =>
        Apis.Asset.AssetBuildings.Store({
          ...values,
          asset_projects_id: props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          key: 'name',
          title: '楼栋名称',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
        },
        {
          key: 'alias_name',
          title: '楼栋别名',
          colProps: { span: 24 },
        },
      ]}
    />
  );
}
