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

import { Apis } from '@/gen/Apis';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { Form, Space } from 'antd';
import ApprovalRecord from './ApprovalRecord';
import ArchiveBorrowInfo from './ArchiveBorrowInfo';
import ChargeStandardInfo from './ChargeStandardInfo';
import ContractInfo from './ContractInfo';
import ContractPaymentInfo from './ContractPaymentInfo';
import ContractTerminationInfo from './ContractTerminationInfo';
import RefundInfo from './RefundInfo';
import SealInfo from './SealInfo';
import {
  default as BillUpdateInfo,
  default as TemporaryBillUpdateInfo,
} from './TemporaryBillUpdateInfo';

export default function AuditShow(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  const navigate = useNavigate();

  return (
    <BetaSchemaForm<ApiTypes.Approval.ApprovalInstances.Show>
      {...MyModalFormProps.props}
      title={props.title}
      trigger={<MyButtons.Default title="查看" type="primary" />}
      wrapperCol={{ span: 24 }}
      width="600px"
      key={new Date().getTime()}
      form={form}
      onOpenChange={() => {
        if (props?.item?.id) {
          Apis.Approval.ApprovalInstances.Show({
            id: props.item?.id,
          }).then((res) => {
            form.setFieldsValue({
              info_display: res?.data,
            });
          });
        }
      }}
      columns={[
        {
          // title: '登记信息',
          dataIndex: 'info_display',
          valueType: 'text',
          renderFormItem: (_, config) => (
            <Space direction="vertical" style={{ width: '100%' }}>
              {config?.value?.type === 'Contract' && (
                <ContractInfo item={config?.value} />
              )}
              {config?.value?.type === 'ContractTermination' && (
                <ContractTerminationInfo item={config?.value} />
              )}
              {config?.value?.type === 'ContractPayment' && (
                <ContractPaymentInfo item={config?.value} />
              )}
              {config?.value?.type === 'Refund' && (
                <RefundInfo item={config?.value} />
              )}
              {config?.value?.type === 'ContractBorrow' && (
                <ArchiveBorrowInfo item={config?.value} />
              )}
              {config?.value?.type === 'OtherContractSeal' && (
                <SealInfo item={config?.value} />
              )}
              {config?.value?.type === 'HouseBillUpdate' && (
                <BillUpdateInfo item={config?.value} />
              )}
              {config?.value?.type === 'ChargeStandardModification' && (
                <ChargeStandardInfo item={config?.value} />
              )}
              {config?.value?.type === 'BillUpdate' && (
                <TemporaryBillUpdateInfo item={config?.value} />
              )}
              <ApprovalRecord item={config?.value} />
            </Space>
          ),
          colProps: { span: 24 },
        },
      ]}
    />
  );
}
