import { MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import {
  ContractBillsCostTypeEnum,
  HouseOrdersOrderStatusEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { Space } from 'antd';

export default function Index({ ...rest }) {
  const navigate = useNavigate();
  return (
    <>
      <ProTable<Record<any, any>>
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            {
              ...params,
              company_suppliers_id: rest.item?.company_suppliers_id,
            },
            sort,
            Apis.Contract.ContractBills.List,
          )
        }
        search={false}
        columns={[
          {
            title: '合同',
            dataIndex: ['contract', 'name'],
            render: (_, item: any) => (
              <a
                onClick={() => {
                  navigate(`/contract/contracts/show/${item.contracts_id}`);
                }}
              >
                {item?.contract?.name || ''}
              </a>
            ),
            search: false,
          },
          // {
          //   title: '合同ID',
          //   dataIndex: 'contracts_id',
          //   render: (_, item: any) => (
          //     <a
          //       onClick={() => {
          //         navigate(`/contract/contracts/show/${item.contracts_id}`);
          //       }}
          //     >
          //       {item?.contracts_id}
          //     </a>
          //   ),
          // },
          MyColumns.EnumTag({
            title: '费用类型',
            dataIndex: 'cost_type',
            valueEnum: ContractBillsCostTypeEnum,
          }),
          {
            title: '年月',
            search: false,
            render: (_, item: any) => {
              return `${item?.year || 0}-${
                item?.month < 10 ? `0${item?.month}` : item?.month
              }`;
            },
          },
          MyColumns.EnumTag({
            title: '支付状态',
            dataIndex: 'payment_status',
            valueEnum: HouseOrdersOrderStatusEnum,
          }),

          {
            title: '账单金额',
            search: false,
            render: (_, item: any) => {
              return `¥${item?.amount || 0}`;
            },
          },
          {
            title: '交易方',
            render: (_, item: any) => {
              const payeeText = item?.payee?.includes('：')
                ? item?.payee?.split('：')?.[1]
                : item?.payee || '';
              const payerText = item?.payer?.includes('：')
                ? item?.payer?.split('：')?.[1]
                : item?.payer || '';
              return (
                <Space>
                  <div>{payeeText}</div>||
                  <div>{payerText}</div>
                </Space>
              );
            },
          },
          MyColumns.CreatedAt(),
        ]}
      />
    </>
  );
}
