import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
  rulesHelper,
} from '@/common';

import { Apis } from '@/gen/Apis';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { Form, message } from 'antd';
import { AuditEnum } from '../../AuditEnum';
export default function Update(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Archive.HouseRegisters.Update>
      {...MyModalFormProps.props}
      title={props.title}
      trigger={<MyButtons.Default title="审核" type="primary" />}
      wrapperCol={{ span: 24 }}
      width="600px"
      form={form}
      onFinish={async (values: any) =>
        Apis.Archive.HouseRegisters.Audit({
          id: props.item?.id ?? 0,
          ...values,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        MyFormItems.EnumRadio({
          key: 'status',
          title: '审核',
          colProps: { span: 24 },
          valueEnum: AuditEnum,
          required: true,
        }),
        {
          valueType: 'dependency',
          name: ['status'],
          columns: ({ status }) => {
            return status === 'Rejected'
              ? [
                  {
                    title: '驳回原因',
                    dataIndex: 'reason',
                    valueType: 'textarea',
                    formItemProps: { ...rulesHelper.text },
                  },
                ]
              : [];
          },
        },
      ]}
    />
  );
}
