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 MoveOut(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Archive.HouseRegisters.MoveOut>
      {...MyModalFormProps.props}
      title={`设置${props.title}`}
      wrapperCol={{ span: 24 }}
      width="500px"
      trigger={
        <MyButtons.Default title={props.title} size="small" type="link" />
      }
      key={new Date().getTime()}
      form={form}
      onFinish={async (values) =>
        Apis.Archive.HouseRegisters.MoveIn({
          ...values,
          house_occupants_id: 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: {
            style: {
              width: '100%',
            },
          },
          formItemProps: { ...rulesHelper.text },
        },
        {
          title: '入住原因',
          valueType: 'textarea',
          dataIndex: 'unbound_reason',
          colProps: { span: 24 },
          // formItemProps: { ...rulesHelper.text },
        },
      ]}
    />
  );
}
