import { MyBetaModalFormProps, MyButtons, MyModalFormProps } 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.Archive.HouseRegisters.Update>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      wrapperCol={{ span: 24 }}
      width="500px"
      form={form}
      onOpenChange={(open: any) => {
        if (open && props.item) {
          form.setFieldsValue(props.item);
        }
      }}
      trigger={
        <MyButtons.Default title={props.title} size="small" type="link" />
      }
      onFinish={async (values) =>
        Apis.Archive.HouseRegisters.Update({
          ...values,
          id: props?.item?.id ?? 0,
          is_live_in: 1,
          customer_info: props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          title: '入住日期',
          valueType: 'date',
          dataIndex: 'move_in_date',
          colProps: { span: 24 },
          fieldProps: {
            maxLength: 11,
            style: {
              width: '100%',
            },
          },
        },
      ]}
    />
  );
}
