import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  MyTableActions,
} from '@/common';
import { Apis } from '@/gen/Apis';
import {
  CompanyReceiptAccountsPayChannelEnum,
  ContractBillPaymentsStatusEnum,
  ContractBillsCostTypeEnum,
  HouseOrdersOrderStatusEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';

export default function Index({ title = '登记审核' }) {
  const navigate = useNavigate();

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="contract_types"
      tabLabel={title}
    >
      <ProTable<Record<any, any>>
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Contract.ContractBillPayments.List,
          )
        }
        params={{
          status: 'Pending',
        }}
        headerTitle="登记审核"
        columns={[
          MyColumns.ID({ search: false }),
          // {
          //   title: '合同ID',
          //   dataIndex: 'contracts_id',
          // },
          {
            title: '账单ID',
            dataIndex: 'contract_bills_id',
            hidden: true,
          },
          {
            title: '付款方',
            dataIndex: 'payer',
          },
          {
            title: '收款方',
            dataIndex: 'payee',
          },
          {
            title: '支付金额',
            search: false,
            render: (_, item: any) => {
              return `¥${item?.amount || 0}`;
            },
          },
          {
            title: '年月',
            search: false,
            render: (_, item: any) => {
              return `${item?.contract_bill?.year || 0}-${
                item?.contract_bill?.month < 10
                  ? `0${item?.contract_bill?.month}`
                  : item?.contract_bill?.month
              }`;
            },
          },
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: 'status',
            valueEnum: ContractBillPaymentsStatusEnum,
          }),
          MyColumns.EnumTag({
            title: '支付状态',
            dataIndex: 'payment_status',
            valueEnum: HouseOrdersOrderStatusEnum,
          }),
          MyColumns.EnumTag({
            title: '费用类型',
            dataIndex: 'cost_type',
            valueEnum: ContractBillsCostTypeEnum,
          }),

          MyColumns.EnumTag({
            title: '支付方式',
            dataIndex: 'payment_method',
            valueEnum: CompanyReceiptAccountsPayChannelEnum,
          }),
          // {
          //   title: '支付单号',
          //   dataIndex: 'payment_no',
          // },
          {
            title: '交易账号',
            dataIndex: 'accept_account_number',
          },
          {
            title: '交易流水号',
            dataIndex: 'accept_serial_number',
          },
          MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any) => (
              <MyTableActions
                actions={{
                  audit: (
                    <MyButtons.Default
                      key="Audit"
                      size="small"
                      type="primary"
                      disabled={item.status !== 'Pending'}
                      onClick={() => {
                        navigate(
                          `/contract/contract_bill_payments/pages/review?id=${item.id}`,
                        );
                      }}
                      title="查看并审核"
                    />
                  ),
                }}
              />
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
