import { MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import { HouseBillsBillStatusEnum, HouseBillsTypeEnum } from '@/gen/Enums';
import BillUpdate from '@/pages/bills/list/modals/BillUpdate';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import { useEffect, useRef } from 'react';

export default function Index({ ...rest }) {
  const actionLooks = useRef<any>();
  useEffect(() => {
    actionLooks?.current.reloadAndRest();
  }, [rest.loadmore]);

  return (
    <>
      <ProTable<Record<any, any>>
        {...MyProTableProps.props}
        actionRef={actionLooks}
        request={async (params, sort) =>
          MyProTableProps.request(
            {
              ...params,
              asset_houses_id: rest.item?.asset_houses_id,
              bill_status: [
                HouseBillsBillStatusEnum.PendingPayment.value,
                HouseBillsBillStatusEnum.PartiallyPaid.value,
                HouseBillsBillStatusEnum.Overdue.value,
              ],
            },
            sort,
            Apis.Bill.HouseBills.List,
          )
        }
        search={false}
        columns={[
          MyColumns.ID(),
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: 'bill_status',
            valueEnum: HouseBillsBillStatusEnum,
          }),
          MyColumns.EnumTag({
            title: '类型',
            dataIndex: 'type',
            valueEnum: HouseBillsTypeEnum,
          }),
          {
            title: '账单月份',
            render: (_, record) => {
              return `${record.year}-${String(record.month).padStart(2, '0')}`;
            },
          },
          {
            title: '应付金额',
            dataIndex: 'total_payable_amount',
            search: false,
          },
          {
            title: '计费开始日期',
            dataIndex: 'start_date',
            search: false,
          },
          {
            title: '计费结束日期',
            dataIndex: 'end_date',
            search: false,
          },
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <BillUpdate item={item} reload={action?.reload} title="编辑" />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
